Skip to content

Commit

Permalink
Compile fixes for WASM
Browse files Browse the repository at this point in the history
The issues are all are due to 'long' types being 32 bits on WASM.

- class members redeclared errors
- << with StringBuilder and unsigned long is ambiguous

This helps to address issue shader-slang#5115.
  • Loading branch information
aleino-nv committed Sep 24, 2024
1 parent ef3552d commit 39ceb42
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
4 changes: 3 additions & 1 deletion source/core/slang-io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
# include <shellapi.h>
#endif

#if defined(__linux__) || defined(__CYGWIN__) || SLANG_APPLE_FAMILY
#if defined(__linux__) || defined(__CYGWIN__) || SLANG_APPLE_FAMILY || SLANG_WASM
# include <fcntl.h>
# include <unistd.h>
// For Path::find
# include <fnmatch.h>
Expand Down Expand Up @@ -1012,6 +1013,7 @@ namespace Slang
}
return SLANG_FAIL;
#else
SLANG_UNUSED(outPath);
return SLANG_E_NOT_IMPLEMENTED;
#endif
}
Expand Down
4 changes: 2 additions & 2 deletions source/slang/slang-ast-dump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,9 @@ struct ASTDumpContext

void dump(uint32_t v)
{
m_writer->emit(UInt(v));
m_writer->emit((uint64_t)v);
}
void dump(UInt v)
void dump(uint64_t v)
{
m_writer->emit(v);
}
Expand Down
2 changes: 1 addition & 1 deletion source/slang/slang-parameter-binding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3748,7 +3748,7 @@ static void _appendRange(Index start, LayoutSize size, StringBuilder& ioBuf)
ioBuf << "[ " << start << " ... ";
if (size.isFinite())
{
ioBuf << start + size.getFiniteValue() << ")";
ioBuf << start + (Index)size.getFiniteValue() << ")";
}
else
{
Expand Down
10 changes: 5 additions & 5 deletions source/slang/slang-workspace-version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ ArrayView<Index> DocumentVersion::getUTF8Boundaries(Index line)
}

void DocumentVersion::oneBasedUTF8LocToZeroBasedUTF16Loc(
Index inLine, Index inCol, Index& outLine, Index& outCol)
Index inLine, Index inCol, int64_t& outLine, int64_t& outCol)
{
if (inLine <= 0)
{
Expand All @@ -472,12 +472,12 @@ void DocumentVersion::oneBasedUTF8LocToZeroBasedUTF16Loc(
}

void DocumentVersion::oneBasedUTF8LocToZeroBasedUTF16Loc(
Index inLine, Index inCol, int& outLine, int& outCol)
Index inLine, Index inCol, int32_t& outLine, int32_t& outCol)
{
Index ioutLine, ioutCol;
int64_t ioutLine, ioutCol;
oneBasedUTF8LocToZeroBasedUTF16Loc(inLine, inCol, ioutLine, ioutCol);
outLine = (int)ioutLine;
outCol = (int)ioutCol;
outLine = (int32_t)ioutLine;
outCol = (int32_t)ioutCol;
}

void DocumentVersion::zeroBasedUTF16LocToOneBasedUTF8Loc(
Expand Down
4 changes: 2 additions & 2 deletions source/slang/slang-workspace-version.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ namespace Slang
ArrayView<Index> getUTF8Boundaries(Index line);

void oneBasedUTF8LocToZeroBasedUTF16Loc(
Index inLine, Index inCol, Index& outLine, Index& outCol);
Index inLine, Index inCol, int64_t& outLine, int64_t& outCol);
void oneBasedUTF8LocToZeroBasedUTF16Loc(
Index inLine, Index inCol, int& outLine, int& outCol);
Index inLine, Index inCol, int32_t& outLine, int32_t& outCol);
void zeroBasedUTF16LocToOneBasedUTF8Loc(
Index inLine, Index inCol, Index& outLine, Index& outCol);

Expand Down

0 comments on commit 39ceb42

Please sign in to comment.