Skip to content

Commit

Permalink
Update to latest spec
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewScheidecker committed Dec 21, 2016
1 parent c3a6186 commit 96b41e2
Show file tree
Hide file tree
Showing 62 changed files with 53,260 additions and 38,597 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4091")
# disable warning: 'inline': used more than once
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4141")
# disable warning: cast truncates constant value
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4310")
else()
# Use C++11
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
Expand Down
7 changes: 4 additions & 3 deletions Include/Core/Serialization.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ namespace Serialization

// Ensure that the input does not encode more than maxBits of data.
enum { numUsedBitsInHighestByte = maxBits - (maxBytes-1) * 7 };
enum { highestByteUsedBitmask = uint8(1<<numUsedBitsInHighestByte)-1 };
enum { highestByteSignedBitmask = ~uint8(highestByteUsedBitmask) & ~uint8(0x80) };
enum { highestByteUsedBitmask = uint8(1<<numUsedBitsInHighestByte)-uint8(1) };
enum { highestByteSignedBitmask = uint8(~uint8(highestByteUsedBitmask) & ~uint8(0x80)) };
if((bytes[maxBytes-1] & ~highestByteUsedBitmask) != 0
&& ((bytes[maxBytes-1] & ~highestByteUsedBitmask) != uint8(highestByteSignedBitmask) || !std::is_signed<Value>::value))
{ throw FatalSerializationException("Invalid LEB encoding: invalid final byte"); }
Expand All @@ -198,7 +198,7 @@ namespace Serialization

// Sign extend the output integer to the full size of Value.
if(std::is_signed<Value>::value && signExtendShift > 0)
{ value = (value << signExtendShift) >> signExtendShift; }
{ value = Value(value << signExtendShift) >> signExtendShift; }

// Check that the output integer is in the expected range.
if(value < minValue || value > maxValue)
Expand All @@ -210,6 +210,7 @@ namespace Serialization
template<typename Stream,typename Value> void serializeVarUInt7(Stream& stream,Value& value) { serializeVarInt<Value,7>(stream,value,0,127); }
template<typename Stream,typename Value> void serializeVarUInt32(Stream& stream,Value& value) { serializeVarInt<Value,32>(stream,value,0,UINT32_MAX); }
template<typename Stream,typename Value> void serializeVarUInt64(Stream& stream,Value& value) { serializeVarInt<Value,64>(stream,value,0,UINT64_MAX); }
template<typename Stream,typename Value> void serializeVarInt7(Stream& stream,Value& value) { serializeVarInt<Value,7>(stream,value,-64,63); }
template<typename Stream,typename Value> void serializeVarInt32(Stream& stream,Value& value) { serializeVarInt<Value,32>(stream,value,INT32_MIN,INT32_MAX); }
template<typename Stream,typename Value> void serializeVarInt64(Stream& stream,Value& value) { serializeVarInt<Value,64>(stream,value,INT64_MIN,INT64_MAX); }

Expand Down
16 changes: 6 additions & 10 deletions Include/Runtime/Linker.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ namespace Runtime
}
};

// An exception that is thrown by linkModule/linkAndInstantiateModule if any imports were missing.
struct LinkException
// Links a module using the given resolver, returning an array mapping import indices to objects.
// If the resolver fails to resolve any imports, throws a LinkException.
struct LinkResult
{
struct MissingImport
{
Expand All @@ -70,14 +71,9 @@ namespace Runtime
};

std::vector<MissingImport> missingImports;
std::vector<Object*> resolvedImports;
bool success;
};

// Links a module using the given resolver, returning an array mapping import indices to objects.
// If the resolver fails to resolve any imports, throws a LinkException.
RUNTIME_API std::vector<Object*> linkModule(const WebAssembly::Module& module,Resolver& resolver);

// Links and instantiates a module using the given resolver.
// If the resolver fails to resolve any imports, throws a LinkException.
// Calls Runtime::instantiateModule, so may also throw an InstantiationException.
RUNTIME_API ModuleInstance* linkAndInstantiateModule(const WebAssembly::Module& module,Resolver& resolver);
RUNTIME_API LinkResult linkModule(const WebAssembly::Module& module,Resolver& resolver);
}
18 changes: 5 additions & 13 deletions Include/Runtime/Runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ namespace Runtime
indirectCallSignatureMismatch,
undefinedTableElement,
calledAbort,
calledUnimplementedIntrinsic
calledUnimplementedIntrinsic,
outOfMemory,
invalidSegmentOffset
};

Cause cause;
Expand All @@ -54,25 +56,15 @@ namespace Runtime
case Exception::Cause::undefinedTableElement: return "undefined function table element";
case Exception::Cause::calledAbort: return "called abort";
case Exception::Cause::calledUnimplementedIntrinsic: return "called unimplemented intrinsic";
case Exception::Cause::outOfMemory: return "out of memory";
case Exception::Cause::invalidSegmentOffset: return "invalid segment offset";
default: return "unknown";
}
}

// Causes a runtime exception.
[[noreturn]] RUNTIME_API void causeException(Exception::Cause cause);

// An exception that may be thrown during module instantiation.
struct InstantiationException
{
enum Cause
{
outOfMemory,
invalidSegmentOffset
};
const Cause cause;
InstantiationException(Cause inCause): cause(inCause) {}
};

// These are subclasses of Object, but are only defined within Runtime, so other modules must
// use these forward declarations as opaque pointers.
struct FunctionInstance;
Expand Down
Loading

0 comments on commit 96b41e2

Please sign in to comment.