summaryrefslogtreecommitdiff
path: root/src/binary-reader-interpreter.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/binary-reader-interpreter.cc')
-rw-r--r--src/binary-reader-interpreter.cc1047
1 files changed, 527 insertions, 520 deletions
diff --git a/src/binary-reader-interpreter.cc b/src/binary-reader-interpreter.cc
index 0c2396ff..cbac7668 100644
--- a/src/binary-reader-interpreter.cc
+++ b/src/binary-reader-interpreter.cc
@@ -28,14 +28,16 @@
#include "type-checker.h"
#include "writer.h"
-#define CHECK_RESULT(expr) \
- do { \
- if (WABT_FAILED(expr)) \
- return Result::Error; \
+#define CHECK_RESULT(expr) \
+ do { \
+ if (WABT_FAILED(expr)) \
+ return wabt::Result::Error; \
} while (0)
namespace wabt {
+using namespace interpreter;
+
namespace {
typedef std::vector<Index> IndexVector;
@@ -71,8 +73,8 @@ struct DataSegmentInfo {
class BinaryReaderInterpreter : public BinaryReaderNop {
public:
- BinaryReaderInterpreter(InterpreterEnvironment* env,
- DefinedInterpreterModule* module,
+ BinaryReaderInterpreter(Environment* env,
+ DefinedModule* module,
IstreamOffset istream_offset,
BinaryErrorHandler* error_handler);
@@ -82,120 +84,120 @@ class BinaryReaderInterpreter : public BinaryReaderNop {
// Implement BinaryReader.
bool OnError(const char* message) override;
- Result EndModule() override;
-
- Result OnTypeCount(Index count) override;
- Result OnType(Index index,
- Index param_count,
- Type* param_types,
- Index result_count,
- Type* result_types) override;
-
- Result OnImportCount(Index count) override;
- Result OnImport(Index index,
- StringSlice module_name,
- StringSlice field_name) override;
- Result OnImportFunc(Index import_index,
- StringSlice module_name,
- StringSlice field_name,
- Index func_index,
- Index sig_index) override;
- Result OnImportTable(Index import_index,
- StringSlice module_name,
- StringSlice field_name,
- Index table_index,
+ wabt::Result EndModule() override;
+
+ wabt::Result OnTypeCount(Index count) override;
+ wabt::Result OnType(Index index,
+ Index param_count,
+ Type* param_types,
+ Index result_count,
+ Type* result_types) override;
+
+ wabt::Result OnImportCount(Index count) override;
+ wabt::Result OnImport(Index index,
+ StringSlice module_name,
+ StringSlice field_name) override;
+ wabt::Result OnImportFunc(Index import_index,
+ StringSlice module_name,
+ StringSlice field_name,
+ Index func_index,
+ Index sig_index) override;
+ wabt::Result OnImportTable(Index import_index,
+ StringSlice module_name,
+ StringSlice field_name,
+ Index table_index,
+ Type elem_type,
+ const Limits* elem_limits) override;
+ wabt::Result OnImportMemory(Index import_index,
+ StringSlice module_name,
+ StringSlice field_name,
+ Index memory_index,
+ const Limits* page_limits) override;
+ wabt::Result OnImportGlobal(Index import_index,
+ StringSlice module_name,
+ StringSlice field_name,
+ Index global_index,
+ Type type,
+ bool mutable_) override;
+
+ wabt::Result OnFunctionCount(Index count) override;
+ wabt::Result OnFunction(Index index, Index sig_index) override;
+
+ wabt::Result OnTable(Index index,
Type elem_type,
const Limits* elem_limits) override;
- Result OnImportMemory(Index import_index,
- StringSlice module_name,
- StringSlice field_name,
- Index memory_index,
- const Limits* page_limits) override;
- Result OnImportGlobal(Index import_index,
- StringSlice module_name,
- StringSlice field_name,
- Index global_index,
- Type type,
- bool mutable_) override;
-
- Result OnFunctionCount(Index count) override;
- Result OnFunction(Index index, Index sig_index) override;
-
- Result OnTable(Index index,
- Type elem_type,
- const Limits* elem_limits) override;
-
- Result OnMemory(Index index, const Limits* limits) override;
-
- Result OnGlobalCount(Index count) override;
- Result BeginGlobal(Index index, Type type, bool mutable_) override;
- Result EndGlobalInitExpr(Index index) override;
-
- Result OnExport(Index index,
- ExternalKind kind,
- Index item_index,
- StringSlice name) override;
-
- Result OnStartFunction(Index func_index) override;
-
- Result BeginFunctionBody(Index index) override;
- Result OnLocalDeclCount(Index count) override;
- Result OnLocalDecl(Index decl_index, Index count, Type type) override;
-
- Result OnBinaryExpr(Opcode opcode) override;
- Result OnBlockExpr(Index num_types, Type* sig_types) override;
- Result OnBrExpr(Index depth) override;
- Result OnBrIfExpr(Index depth) override;
- Result OnBrTableExpr(Index num_targets,
- Index* target_depths,
- Index default_target_depth) override;
- Result OnCallExpr(Index func_index) override;
- Result OnCallIndirectExpr(Index sig_index) override;
- Result OnCompareExpr(Opcode opcode) override;
- Result OnConvertExpr(Opcode opcode) override;
- Result OnCurrentMemoryExpr() override;
- Result OnDropExpr() override;
- Result OnElseExpr() override;
- Result OnEndExpr() override;
- Result OnF32ConstExpr(uint32_t value_bits) override;
- Result OnF64ConstExpr(uint64_t value_bits) override;
- Result OnGetGlobalExpr(Index global_index) override;
- Result OnGetLocalExpr(Index local_index) override;
- Result OnGrowMemoryExpr() override;
- Result OnI32ConstExpr(uint32_t value) override;
- Result OnI64ConstExpr(uint64_t value) override;
- Result OnIfExpr(Index num_types, Type* sig_types) override;
- Result OnLoadExpr(Opcode opcode,
- uint32_t alignment_log2,
- Address offset) override;
- Result OnLoopExpr(Index num_types, Type* sig_types) override;
- Result OnNopExpr() override;
- Result OnReturnExpr() override;
- Result OnSelectExpr() override;
- Result OnSetGlobalExpr(Index global_index) override;
- Result OnSetLocalExpr(Index local_index) override;
- Result OnStoreExpr(Opcode opcode,
- uint32_t alignment_log2,
- Address offset) override;
- Result OnTeeLocalExpr(Index local_index) override;
- Result OnUnaryExpr(Opcode opcode) override;
- Result OnUnreachableExpr() override;
- Result EndFunctionBody(Index index) override;
-
- Result EndElemSegmentInitExpr(Index index) override;
- Result OnElemSegmentFunctionIndex(Index index,
- Index func_index) override;
-
- Result OnDataSegmentData(Index index,
- const void* data,
- Address size) override;
-
- Result OnInitExprF32ConstExpr(Index index, uint32_t value) override;
- Result OnInitExprF64ConstExpr(Index index, uint64_t value) override;
- Result OnInitExprGetGlobalExpr(Index index,
- Index global_index) override;
- Result OnInitExprI32ConstExpr(Index index, uint32_t value) override;
- Result OnInitExprI64ConstExpr(Index index, uint64_t value) override;
+
+ wabt::Result OnMemory(Index index, const Limits* limits) override;
+
+ wabt::Result OnGlobalCount(Index count) override;
+ wabt::Result BeginGlobal(Index index, Type type, bool mutable_) override;
+ wabt::Result EndGlobalInitExpr(Index index) override;
+
+ wabt::Result OnExport(Index index,
+ ExternalKind kind,
+ Index item_index,
+ StringSlice name) override;
+
+ wabt::Result OnStartFunction(Index func_index) override;
+
+ wabt::Result BeginFunctionBody(Index index) override;
+ wabt::Result OnLocalDeclCount(Index count) override;
+ wabt::Result OnLocalDecl(Index decl_index, Index count, Type type) override;
+
+ wabt::Result OnBinaryExpr(wabt::Opcode opcode) override;
+ wabt::Result OnBlockExpr(Index num_types, Type* sig_types) override;
+ wabt::Result OnBrExpr(Index depth) override;
+ wabt::Result OnBrIfExpr(Index depth) override;
+ wabt::Result OnBrTableExpr(Index num_targets,
+ Index* target_depths,
+ Index default_target_depth) override;
+ wabt::Result OnCallExpr(Index func_index) override;
+ wabt::Result OnCallIndirectExpr(Index sig_index) override;
+ wabt::Result OnCompareExpr(wabt::Opcode opcode) override;
+ wabt::Result OnConvertExpr(wabt::Opcode opcode) override;
+ wabt::Result OnCurrentMemoryExpr() override;
+ wabt::Result OnDropExpr() override;
+ wabt::Result OnElseExpr() override;
+ wabt::Result OnEndExpr() override;
+ wabt::Result OnF32ConstExpr(uint32_t value_bits) override;
+ wabt::Result OnF64ConstExpr(uint64_t value_bits) override;
+ wabt::Result OnGetGlobalExpr(Index global_index) override;
+ wabt::Result OnGetLocalExpr(Index local_index) override;
+ wabt::Result OnGrowMemoryExpr() override;
+ wabt::Result OnI32ConstExpr(uint32_t value) override;
+ wabt::Result OnI64ConstExpr(uint64_t value) override;
+ wabt::Result OnIfExpr(Index num_types, Type* sig_types) override;
+ wabt::Result OnLoadExpr(wabt::Opcode opcode,
+ uint32_t alignment_log2,
+ Address offset) override;
+ wabt::Result OnLoopExpr(Index num_types, Type* sig_types) override;
+ wabt::Result OnNopExpr() override;
+ wabt::Result OnReturnExpr() override;
+ wabt::Result OnSelectExpr() override;
+ wabt::Result OnSetGlobalExpr(Index global_index) override;
+ wabt::Result OnSetLocalExpr(Index local_index) override;
+ wabt::Result OnStoreExpr(wabt::Opcode opcode,
+ uint32_t alignment_log2,
+ Address offset) override;
+ wabt::Result OnTeeLocalExpr(Index local_index) override;
+ wabt::Result OnUnaryExpr(wabt::Opcode opcode) override;
+ wabt::Result OnUnreachableExpr() override;
+ wabt::Result EndFunctionBody(Index index) override;
+
+ wabt::Result EndElemSegmentInitExpr(Index index) override;
+ wabt::Result OnElemSegmentFunctionIndex(Index index,
+ Index func_index) override;
+
+ wabt::Result OnDataSegmentData(Index index,
+ const void* data,
+ Address size) override;
+
+ wabt::Result OnInitExprF32ConstExpr(Index index, uint32_t value) override;
+ wabt::Result OnInitExprF64ConstExpr(Index index, uint64_t value) override;
+ wabt::Result OnInitExprGetGlobalExpr(Index index,
+ Index global_index) override;
+ wabt::Result OnInitExprI32ConstExpr(Index index, uint32_t value) override;
+ wabt::Result OnInitExprI64ConstExpr(Index index, uint64_t value) override;
private:
Label* GetLabel(Index depth);
@@ -208,64 +210,65 @@ class BinaryReaderInterpreter : public BinaryReaderNop {
static void OnTypecheckerError(const char* msg, void* user_data);
Index TranslateSigIndexToEnv(Index sig_index);
- InterpreterFuncSignature* GetSignatureByEnvIndex(Index sig_index);
- InterpreterFuncSignature* GetSignatureByModuleIndex(Index sig_index);
+ FuncSignature* GetSignatureByEnvIndex(Index sig_index);
+ FuncSignature* GetSignatureByModuleIndex(Index sig_index);
Index TranslateFuncIndexToEnv(Index func_index);
Index TranslateModuleFuncIndexToDefined(Index func_index);
- InterpreterFunc* GetFuncByEnvIndex(Index func_index);
- InterpreterFunc* GetFuncByModuleIndex(Index func_index);
+ Func* GetFuncByEnvIndex(Index func_index);
+ Func* GetFuncByModuleIndex(Index func_index);
Index TranslateGlobalIndexToEnv(Index global_index);
- InterpreterGlobal* GetGlobalByEnvIndex(Index global_index);
- InterpreterGlobal* GetGlobalByModuleIndex(Index global_index);
+ Global* GetGlobalByEnvIndex(Index global_index);
+ Global* GetGlobalByModuleIndex(Index global_index);
Type GetGlobalTypeByModuleIndex(Index global_index);
Index TranslateLocalIndex(Index local_index);
- Type GetLocalTypeByIndex(InterpreterFunc* func, Index local_index);
+ Type GetLocalTypeByIndex(Func* func, Index local_index);
IstreamOffset GetIstreamOffset();
- Result EmitDataAt(IstreamOffset offset,
- const void* data,
- IstreamOffset size);
- Result EmitData(const void* data, IstreamOffset size);
- Result EmitOpcode(Opcode opcode);
- Result EmitOpcode(InterpreterOpcode opcode);
- Result EmitI8(uint8_t value);
- Result EmitI32(uint32_t value);
- Result EmitI64(uint64_t value);
- Result EmitI32At(IstreamOffset offset, uint32_t value);
- Result EmitDropKeep(uint32_t drop, uint8_t keep);
- Result AppendFixup(IstreamOffsetVectorVector* fixups_vector, Index index);
- Result EmitBrOffset(Index depth, IstreamOffset offset);
- Result GetBrDropKeepCount(Index depth,
- Index* out_drop_count,
- Index* out_keep_count);
- Result GetReturnDropKeepCount(Index* out_drop_count,
- Index* out_keep_count);
- Result EmitBr(Index depth, Index drop_count, Index keep_count);
- Result EmitBrTableOffset(Index depth);
- Result FixupTopLabel();
- Result EmitFuncOffset(DefinedInterpreterFunc* func, Index func_index);
-
- Result CheckLocal(Index local_index);
- Result CheckGlobal(Index global_index);
- Result CheckImportKind(InterpreterImport* import, ExternalKind expected_kind);
- Result CheckImportLimits(const Limits* declared_limits,
- const Limits* actual_limits);
- Result CheckHasMemory(Opcode opcode);
- Result CheckAlign(uint32_t alignment_log2, Address natural_alignment);
-
- Result AppendExport(InterpreterModule* module,
- ExternalKind kind,
- Index item_index,
- StringSlice name);
+ wabt::Result EmitDataAt(IstreamOffset offset,
+ const void* data,
+ IstreamOffset size);
+ wabt::Result EmitData(const void* data, IstreamOffset size);
+ wabt::Result EmitOpcode(wabt::Opcode opcode);
+ wabt::Result EmitOpcode(interpreter::Opcode opcode);
+ wabt::Result EmitI8(uint8_t value);
+ wabt::Result EmitI32(uint32_t value);
+ wabt::Result EmitI64(uint64_t value);
+ wabt::Result EmitI32At(IstreamOffset offset, uint32_t value);
+ wabt::Result EmitDropKeep(uint32_t drop, uint8_t keep);
+ wabt::Result AppendFixup(IstreamOffsetVectorVector* fixups_vector,
+ Index index);
+ wabt::Result EmitBrOffset(Index depth, IstreamOffset offset);
+ wabt::Result GetBrDropKeepCount(Index depth,
+ Index* out_drop_count,
+ Index* out_keep_count);
+ wabt::Result GetReturnDropKeepCount(Index* out_drop_count,
+ Index* out_keep_count);
+ wabt::Result EmitBr(Index depth, Index drop_count, Index keep_count);
+ wabt::Result EmitBrTableOffset(Index depth);
+ wabt::Result FixupTopLabel();
+ wabt::Result EmitFuncOffset(DefinedFunc* func, Index func_index);
+
+ wabt::Result CheckLocal(Index local_index);
+ wabt::Result CheckGlobal(Index global_index);
+ wabt::Result CheckImportKind(Import* import, ExternalKind expected_kind);
+ wabt::Result CheckImportLimits(const Limits* declared_limits,
+ const Limits* actual_limits);
+ wabt::Result CheckHasMemory(wabt::Opcode opcode);
+ wabt::Result CheckAlign(uint32_t alignment_log2, Address natural_alignment);
+
+ wabt::Result AppendExport(Module* module,
+ ExternalKind kind,
+ Index item_index,
+ StringSlice name);
PrintErrorCallback MakePrintErrorCallback();
static void OnHostImportPrintError(const char* msg, void* user_data);
BinaryErrorHandler* error_handler = nullptr;
- InterpreterEnvironment* env = nullptr;
- DefinedInterpreterModule* module = nullptr;
- DefinedInterpreterFunc* current_func = nullptr;
+ Environment* env = nullptr;
+ DefinedModule* module = nullptr;
+ DefinedFunc* current_func = nullptr;
TypeCheckerErrorHandler tc_error_handler;
TypeChecker typechecker;
std::vector<Label> label_stack;
@@ -289,16 +292,16 @@ class BinaryReaderInterpreter : public BinaryReaderNop {
std::vector<DataSegmentInfo> data_segment_infos;
/* values cached so they can be shared between callbacks */
- InterpreterTypedValue init_expr_value;
+ TypedValue init_expr_value;
IstreamOffset table_offset = 0;
bool is_host_import = false;
- HostInterpreterModule* host_import_module = nullptr;
+ HostModule* host_import_module = nullptr;
Index import_env_index = 0;
};
BinaryReaderInterpreter::BinaryReaderInterpreter(
- InterpreterEnvironment* env,
- DefinedInterpreterModule* module,
+ Environment* env,
+ DefinedModule* module,
IstreamOffset istream_offset,
BinaryErrorHandler* error_handler)
: error_handler(error_handler),
@@ -345,12 +348,12 @@ Index BinaryReaderInterpreter::TranslateSigIndexToEnv(Index sig_index) {
return sig_index_mapping[sig_index];
}
-InterpreterFuncSignature* BinaryReaderInterpreter::GetSignatureByEnvIndex(
+FuncSignature* BinaryReaderInterpreter::GetSignatureByEnvIndex(
Index sig_index) {
return &env->sigs[sig_index];
}
-InterpreterFuncSignature* BinaryReaderInterpreter::GetSignatureByModuleIndex(
+FuncSignature* BinaryReaderInterpreter::GetSignatureByModuleIndex(
Index sig_index) {
return GetSignatureByEnvIndex(TranslateSigIndexToEnv(sig_index));
}
@@ -366,13 +369,11 @@ Index BinaryReaderInterpreter::TranslateModuleFuncIndexToDefined(
return func_index - num_func_imports;
}
-InterpreterFunc* BinaryReaderInterpreter::GetFuncByEnvIndex(
- Index func_index) {
+Func* BinaryReaderInterpreter::GetFuncByEnvIndex(Index func_index) {
return env->funcs[func_index].get();
}
-InterpreterFunc* BinaryReaderInterpreter::GetFuncByModuleIndex(
- Index func_index) {
+Func* BinaryReaderInterpreter::GetFuncByModuleIndex(Index func_index) {
return GetFuncByEnvIndex(TranslateFuncIndexToEnv(func_index));
}
@@ -380,13 +381,11 @@ Index BinaryReaderInterpreter::TranslateGlobalIndexToEnv(Index global_index) {
return global_index_mapping[global_index];
}
-InterpreterGlobal* BinaryReaderInterpreter::GetGlobalByEnvIndex(
- Index global_index) {
+Global* BinaryReaderInterpreter::GetGlobalByEnvIndex(Index global_index) {
return &env->globals[global_index];
}
-InterpreterGlobal* BinaryReaderInterpreter::GetGlobalByModuleIndex(
- Index global_index) {
+Global* BinaryReaderInterpreter::GetGlobalByModuleIndex(Index global_index) {
return GetGlobalByEnvIndex(TranslateGlobalIndexToEnv(global_index));
}
@@ -394,7 +393,7 @@ Type BinaryReaderInterpreter::GetGlobalTypeByModuleIndex(Index global_index) {
return GetGlobalByModuleIndex(global_index)->typed_value.type;
}
-Type BinaryReaderInterpreter::GetLocalTypeByIndex(InterpreterFunc* func,
+Type BinaryReaderInterpreter::GetLocalTypeByIndex(Func* func,
Index local_index) {
assert(!func->is_host);
return func->as_defined()->param_and_local_types[local_index];
@@ -404,69 +403,71 @@ IstreamOffset BinaryReaderInterpreter::GetIstreamOffset() {
return istream_offset;
}
-Result BinaryReaderInterpreter::EmitDataAt(IstreamOffset offset,
- const void* data,
- IstreamOffset size) {
+wabt::Result BinaryReaderInterpreter::EmitDataAt(IstreamOffset offset,
+ const void* data,
+ IstreamOffset size) {
return istream_writer.WriteData(offset, data, size);
}
-Result BinaryReaderInterpreter::EmitData(const void* data, IstreamOffset size) {
+wabt::Result BinaryReaderInterpreter::EmitData(const void* data,
+ IstreamOffset size) {
CHECK_RESULT(EmitDataAt(istream_offset, data, size));
istream_offset += size;
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::EmitOpcode(Opcode opcode) {
+wabt::Result BinaryReaderInterpreter::EmitOpcode(wabt::Opcode opcode) {
return EmitData(&opcode, sizeof(uint8_t));
}
-Result BinaryReaderInterpreter::EmitOpcode(InterpreterOpcode opcode) {
+wabt::Result BinaryReaderInterpreter::EmitOpcode(interpreter::Opcode opcode) {
return EmitData(&opcode, sizeof(uint8_t));
}
-Result BinaryReaderInterpreter::EmitI8(uint8_t value) {
+wabt::Result BinaryReaderInterpreter::EmitI8(uint8_t value) {
return EmitData(&value, sizeof(value));
}
-Result BinaryReaderInterpreter::EmitI32(uint32_t value) {
+wabt::Result BinaryReaderInterpreter::EmitI32(uint32_t value) {
return EmitData(&value, sizeof(value));
}
-Result BinaryReaderInterpreter::EmitI64(uint64_t value) {
+wabt::Result BinaryReaderInterpreter::EmitI64(uint64_t value) {
return EmitData(&value, sizeof(value));
}
-Result BinaryReaderInterpreter::EmitI32At(IstreamOffset offset,
- uint32_t value) {
+wabt::Result BinaryReaderInterpreter::EmitI32At(IstreamOffset offset,
+ uint32_t value) {
return EmitDataAt(offset, &value, sizeof(value));
}
-Result BinaryReaderInterpreter::EmitDropKeep(uint32_t drop, uint8_t keep) {
+wabt::Result BinaryReaderInterpreter::EmitDropKeep(uint32_t drop,
+ uint8_t keep) {
assert(drop != UINT32_MAX);
assert(keep <= 1);
if (drop > 0) {
if (drop == 1 && keep == 0) {
- CHECK_RESULT(EmitOpcode(InterpreterOpcode::Drop));
+ CHECK_RESULT(EmitOpcode(interpreter::Opcode::Drop));
} else {
- CHECK_RESULT(EmitOpcode(InterpreterOpcode::DropKeep));
+ CHECK_RESULT(EmitOpcode(interpreter::Opcode::DropKeep));
CHECK_RESULT(EmitI32(drop));
CHECK_RESULT(EmitI8(keep));
}
}
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::AppendFixup(
+wabt::Result BinaryReaderInterpreter::AppendFixup(
IstreamOffsetVectorVector* fixups_vector,
Index index) {
if (index >= fixups_vector->size())
fixups_vector->resize(index + 1);
(*fixups_vector)[index].push_back(GetIstreamOffset());
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::EmitBrOffset(Index depth,
- IstreamOffset offset) {
+wabt::Result BinaryReaderInterpreter::EmitBrOffset(Index depth,
+ IstreamOffset offset) {
if (offset == kInvalidIstreamOffset) {
/* depth_fixups stores the depth counting up from zero, where zero is the
* top-level function scope. */
@@ -474,12 +475,13 @@ Result BinaryReaderInterpreter::EmitBrOffset(Index depth,
CHECK_RESULT(AppendFixup(&depth_fixups, depth));
}
CHECK_RESULT(EmitI32(offset));
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::GetBrDropKeepCount(Index depth,
- Index* out_drop_count,
- Index* out_keep_count) {
+wabt::Result BinaryReaderInterpreter::GetBrDropKeepCount(
+ Index depth,
+ Index* out_drop_count,
+ Index* out_keep_count) {
TypeCheckerLabel* label;
CHECK_RESULT(typechecker_get_label(&typechecker, depth, &label));
*out_keep_count =
@@ -491,97 +493,98 @@ Result BinaryReaderInterpreter::GetBrDropKeepCount(Index depth,
(typechecker.type_stack.size() - label->type_stack_limit) -
*out_keep_count;
}
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::GetReturnDropKeepCount(Index* out_drop_count,
- Index* out_keep_count) {
+wabt::Result BinaryReaderInterpreter::GetReturnDropKeepCount(
+ Index* out_drop_count,
+ Index* out_keep_count) {
if (WABT_FAILED(GetBrDropKeepCount(label_stack.size() - 1, out_drop_count,
out_keep_count))) {
- return Result::Error;
+ return wabt::Result::Error;
}
*out_drop_count += current_func->param_and_local_types.size();
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::EmitBr(Index depth,
- Index drop_count,
- Index keep_count) {
+wabt::Result BinaryReaderInterpreter::EmitBr(Index depth,
+ Index drop_count,
+ Index keep_count) {
CHECK_RESULT(EmitDropKeep(drop_count, keep_count));
- CHECK_RESULT(EmitOpcode(InterpreterOpcode::Br));
+ CHECK_RESULT(EmitOpcode(interpreter::Opcode::Br));
CHECK_RESULT(EmitBrOffset(depth, GetLabel(depth)->offset));
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::EmitBrTableOffset(Index depth) {
+wabt::Result BinaryReaderInterpreter::EmitBrTableOffset(Index depth) {
Index drop_count, keep_count;
CHECK_RESULT(GetBrDropKeepCount(depth, &drop_count, &keep_count));
CHECK_RESULT(EmitBrOffset(depth, GetLabel(depth)->offset));
CHECK_RESULT(EmitI32(drop_count));
CHECK_RESULT(EmitI8(keep_count));
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::FixupTopLabel() {
+wabt::Result BinaryReaderInterpreter::FixupTopLabel() {
IstreamOffset offset = GetIstreamOffset();
Index top = label_stack.size() - 1;
if (top >= depth_fixups.size()) {
/* nothing to fixup */
- return Result::Ok;
+ return wabt::Result::Ok;
}
IstreamOffsetVector& fixups = depth_fixups[top];
for (IstreamOffset fixup : fixups)
CHECK_RESULT(EmitI32At(fixup, offset));
fixups.clear();
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::EmitFuncOffset(DefinedInterpreterFunc* func,
- Index func_index) {
+wabt::Result BinaryReaderInterpreter::EmitFuncOffset(DefinedFunc* func,
+ Index func_index) {
if (func->offset == kInvalidIstreamOffset) {
Index defined_index = TranslateModuleFuncIndexToDefined(func_index);
CHECK_RESULT(AppendFixup(&func_fixups, defined_index));
}
CHECK_RESULT(EmitI32(func->offset));
- return Result::Ok;
+ return wabt::Result::Ok;
}
bool BinaryReaderInterpreter::OnError(const char* message) {
return HandleError(state->offset, message);
}
-Result BinaryReaderInterpreter::OnTypeCount(Index count) {
+wabt::Result BinaryReaderInterpreter::OnTypeCount(Index count) {
sig_index_mapping.resize(count);
for (Index i = 0; i < count; ++i)
sig_index_mapping[i] = env->sigs.size() + i;
env->sigs.resize(env->sigs.size() + count);
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::OnType(Index index,
- Index param_count,
- Type* param_types,
- Index result_count,
- Type* result_types) {
- InterpreterFuncSignature* sig = GetSignatureByModuleIndex(index);
+wabt::Result BinaryReaderInterpreter::OnType(Index index,
+ Index param_count,
+ Type* param_types,
+ Index result_count,
+ Type* result_types) {
+ FuncSignature* sig = GetSignatureByModuleIndex(index);
sig->param_types.insert(sig->param_types.end(), param_types,
param_types + param_count);
sig->result_types.insert(sig->result_types.end(), result_types,
result_types + result_count);
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::OnImportCount(Index count) {
+wabt::Result BinaryReaderInterpreter::OnImportCount(Index count) {
module->imports.resize(count);
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::OnImport(Index index,
- StringSlice module_name,
- StringSlice field_name) {
- InterpreterImport* import = &module->imports[index];
+wabt::Result BinaryReaderInterpreter::OnImport(Index index,
+ StringSlice module_name,
+ StringSlice field_name) {
+ Import* import = &module->imports[index];
import->module_name = dup_string_slice(module_name);
import->field_name = dup_string_slice(field_name);
int module_index =
@@ -589,10 +592,10 @@ Result BinaryReaderInterpreter::OnImport(Index index,
if (module_index < 0) {
PrintError("unknown import module \"" PRIstringslice "\"",
WABT_PRINTF_STRING_SLICE_ARG(import->module_name));
- return Result::Error;
+ return wabt::Result::Error;
}
- InterpreterModule* module = env->modules[module_index].get();
+ Module* module = env->modules[module_index].get();
if (module->is_host) {
/* We don't yet know the kind of a host import module, so just assume it
* exists for now. We'll fail later (in on_import_* below) if it doesn't
@@ -600,93 +603,94 @@ Result BinaryReaderInterpreter::OnImport(Index index,
is_host_import = true;
host_import_module = module->as_host();
} else {
- InterpreterExport* export_ =
- get_interpreter_export_by_name(module, &import->field_name);
+ Export* export_ = get_export_by_name(module, &import->field_name);
if (!export_) {
PrintError("unknown module field \"" PRIstringslice "\"",
WABT_PRINTF_STRING_SLICE_ARG(import->field_name));
- return Result::Error;
+ return wabt::Result::Error;
}
import->kind = export_->kind;
is_host_import = false;
import_env_index = export_->index;
}
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::CheckLocal(Index local_index) {
+wabt::Result BinaryReaderInterpreter::CheckLocal(Index local_index) {
Index max_local_index = current_func->param_and_local_types.size();
if (local_index >= max_local_index) {
PrintError("invalid local_index: %" PRIindex " (max %" PRIindex ")",
local_index, max_local_index);
- return Result::Error;
+ return wabt::Result::Error;
}
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::CheckGlobal(Index global_index) {
+wabt::Result BinaryReaderInterpreter::CheckGlobal(Index global_index) {
Index max_global_index = global_index_mapping.size();
if (global_index >= max_global_index) {
PrintError("invalid global_index: %" PRIindex " (max %" PRIindex ")",
global_index, max_global_index);
- return Result::Error;
+ return wabt::Result::Error;
}
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::CheckImportKind(InterpreterImport* import,
- ExternalKind expected_kind) {
+wabt::Result BinaryReaderInterpreter::CheckImportKind(
+ Import* import,
+ ExternalKind expected_kind) {
if (import->kind != expected_kind) {
PrintError("expected import \"" PRIstringslice "." PRIstringslice
"\" to have kind %s, not %s",
WABT_PRINTF_STRING_SLICE_ARG(import->module_name),
WABT_PRINTF_STRING_SLICE_ARG(import->field_name),
get_kind_name(expected_kind), get_kind_name(import->kind));
- return Result::Error;
+ return wabt::Result::Error;
}
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::CheckImportLimits(const Limits* declared_limits,
- const Limits* actual_limits) {
+wabt::Result BinaryReaderInterpreter::CheckImportLimits(
+ const Limits* declared_limits,
+ const Limits* actual_limits) {
if (actual_limits->initial < declared_limits->initial) {
PrintError("actual size (%" PRIu64 ") smaller than declared (%" PRIu64 ")",
actual_limits->initial, declared_limits->initial);
- return Result::Error;
+ return wabt::Result::Error;
}
if (declared_limits->has_max) {
if (!actual_limits->has_max) {
PrintError("max size (unspecified) larger than declared (%" PRIu64 ")",
declared_limits->max);
- return Result::Error;
+ return wabt::Result::Error;
} else if (actual_limits->max > declared_limits->max) {
PrintError("max size (%" PRIu64 ") larger than declared (%" PRIu64 ")",
actual_limits->max, declared_limits->max);
- return Result::Error;
+ return wabt::Result::Error;
}
}
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::AppendExport(InterpreterModule* module,
- ExternalKind kind,
- Index item_index,
- StringSlice name) {
+wabt::Result BinaryReaderInterpreter::AppendExport(Module* module,
+ ExternalKind kind,
+ Index item_index,
+ StringSlice name) {
if (module->export_bindings.find_index(name) != -1) {
PrintError("duplicate export \"" PRIstringslice "\"",
WABT_PRINTF_STRING_SLICE_ARG(name));
- return Result::Error;
+ return wabt::Result::Error;
}
module->exports.emplace_back(dup_string_slice(name), kind, item_index);
- InterpreterExport* export_ = &module->exports.back();
+ Export* export_ = &module->exports.back();
module->export_bindings.emplace(string_slice_to_string(export_->name),
Binding(module->exports.size() - 1));
- return Result::Ok;
+ return wabt::Result::Ok;
}
// static
@@ -702,24 +706,23 @@ PrintErrorCallback BinaryReaderInterpreter::MakePrintErrorCallback() {
return result;
}
-Result BinaryReaderInterpreter::OnImportFunc(Index import_index,
- StringSlice module_name,
- StringSlice field_name,
- Index func_index,
- Index sig_index) {
- InterpreterImport* import = &module->imports[import_index];
+wabt::Result BinaryReaderInterpreter::OnImportFunc(Index import_index,
+ StringSlice module_name,
+ StringSlice field_name,
+ Index func_index,
+ Index sig_index) {
+ Import* import = &module->imports[import_index];
import->func.sig_index = TranslateSigIndexToEnv(sig_index);
Index func_env_index;
if (is_host_import) {
- HostInterpreterFunc* func = new HostInterpreterFunc(
- import->module_name, import->field_name, import->func.sig_index);
+ HostFunc* func = new HostFunc(import->module_name, import->field_name,
+ import->func.sig_index);
env->funcs.emplace_back(func);
- InterpreterHostImportDelegate* host_delegate =
- &host_import_module->import_delegate;
- InterpreterFuncSignature* sig = &env->sigs[func->sig_index];
+ HostImportDelegate* host_delegate = &host_import_module->import_delegate;
+ FuncSignature* sig = &env->sigs[func->sig_index];
CHECK_RESULT(host_delegate->import_func(
import, func, sig, MakePrintErrorCallback(), host_delegate->user_data));
assert(func->callback);
@@ -729,39 +732,38 @@ Result BinaryReaderInterpreter::OnImportFunc(Index import_index,
import->field_name);
} else {
CHECK_RESULT(CheckImportKind(import, ExternalKind::Func));
- InterpreterFunc* func = env->funcs[import_env_index].get();
+ Func* func = env->funcs[import_env_index].get();
if (!func_signatures_are_equal(env, import->func.sig_index,
func->sig_index)) {
PrintError("import signature mismatch");
- return Result::Error;
+ return wabt::Result::Error;
}
func_env_index = import_env_index;
}
func_index_mapping.push_back(func_env_index);
num_func_imports++;
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::OnImportTable(Index import_index,
- StringSlice module_name,
- StringSlice field_name,
- Index table_index,
- Type elem_type,
- const Limits* elem_limits) {
+wabt::Result BinaryReaderInterpreter::OnImportTable(Index import_index,
+ StringSlice module_name,
+ StringSlice field_name,
+ Index table_index,
+ Type elem_type,
+ const Limits* elem_limits) {
if (module->table_index != kInvalidIndex) {
PrintError("only one table allowed");
- return Result::Error;
+ return wabt::Result::Error;
}
- InterpreterImport* import = &module->imports[import_index];
+ Import* import = &module->imports[import_index];
if (is_host_import) {
env->tables.emplace_back(*elem_limits);
- InterpreterTable* table = &env->tables.back();
+ Table* table = &env->tables.back();
- InterpreterHostImportDelegate* host_delegate =
- &host_import_module->import_delegate;
+ HostImportDelegate* host_delegate = &host_import_module->import_delegate;
CHECK_RESULT(host_delegate->import_table(
import, table, MakePrintErrorCallback(), host_delegate->user_data));
@@ -772,33 +774,33 @@ Result BinaryReaderInterpreter::OnImportTable(Index import_index,
import->field_name);
} else {
CHECK_RESULT(CheckImportKind(import, ExternalKind::Table));
- InterpreterTable* table = &env->tables[import_env_index];
+ Table* table = &env->tables[import_env_index];
CHECK_RESULT(CheckImportLimits(elem_limits, &table->limits));
import->table.limits = *elem_limits;
module->table_index = import_env_index;
}
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::OnImportMemory(Index import_index,
- StringSlice module_name,
- StringSlice field_name,
- Index memory_index,
- const Limits* page_limits) {
+wabt::Result BinaryReaderInterpreter::OnImportMemory(
+ Index import_index,
+ StringSlice module_name,
+ StringSlice field_name,
+ Index memory_index,
+ const Limits* page_limits) {
if (module->memory_index != kInvalidIndex) {
PrintError("only one memory allowed");
- return Result::Error;
+ return wabt::Result::Error;
}
- InterpreterImport* import = &module->imports[import_index];
+ Import* import = &module->imports[import_index];
if (is_host_import) {
env->memories.emplace_back();
- InterpreterMemory* memory = &env->memories.back();
+ Memory* memory = &env->memories.back();
- InterpreterHostImportDelegate* host_delegate =
- &host_import_module->import_delegate;
+ HostImportDelegate* host_delegate = &host_import_module->import_delegate;
CHECK_RESULT(host_delegate->import_memory(
import, memory, MakePrintErrorCallback(), host_delegate->user_data));
@@ -809,30 +811,29 @@ Result BinaryReaderInterpreter::OnImportMemory(Index import_index,
import->field_name);
} else {
CHECK_RESULT(CheckImportKind(import, ExternalKind::Memory));
- InterpreterMemory* memory = &env->memories[import_env_index];
+ Memory* memory = &env->memories[import_env_index];
CHECK_RESULT(CheckImportLimits(page_limits, &memory->page_limits));
import->memory.limits = *page_limits;
module->memory_index = import_env_index;
}
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::OnImportGlobal(Index import_index,
- StringSlice module_name,
- StringSlice field_name,
- Index global_index,
- Type type,
- bool mutable_) {
- InterpreterImport* import = &module->imports[import_index];
+wabt::Result BinaryReaderInterpreter::OnImportGlobal(Index import_index,
+ StringSlice module_name,
+ StringSlice field_name,
+ Index global_index,
+ Type type,
+ bool mutable_) {
+ Import* import = &module->imports[import_index];
Index global_env_index = env->globals.size() - 1;
if (is_host_import) {
- env->globals.emplace_back(InterpreterTypedValue(type), mutable_);
- InterpreterGlobal* global = &env->globals.back();
+ env->globals.emplace_back(TypedValue(type), mutable_);
+ Global* global = &env->globals.back();
- InterpreterHostImportDelegate* host_delegate =
- &host_import_module->import_delegate;
+ HostImportDelegate* host_delegate = &host_import_module->import_delegate;
CHECK_RESULT(host_delegate->import_global(
import, global, MakePrintErrorCallback(), host_delegate->user_data));
@@ -848,123 +849,125 @@ Result BinaryReaderInterpreter::OnImportGlobal(Index import_index,
}
global_index_mapping.push_back(global_env_index);
num_global_imports++;
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::OnFunctionCount(Index count) {
+wabt::Result BinaryReaderInterpreter::OnFunctionCount(Index count) {
for (Index i = 0; i < count; ++i)
func_index_mapping.push_back(env->funcs.size() + i);
env->funcs.reserve(env->funcs.size() + count);
func_fixups.resize(count);
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::OnFunction(Index index, Index sig_index) {
- DefinedInterpreterFunc* func =
- new DefinedInterpreterFunc(TranslateSigIndexToEnv(sig_index));
+wabt::Result BinaryReaderInterpreter::OnFunction(Index index, Index sig_index) {
+ DefinedFunc* func = new DefinedFunc(TranslateSigIndexToEnv(sig_index));
env->funcs.emplace_back(func);
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::OnTable(Index index,
- Type elem_type,
- const Limits* elem_limits) {
+wabt::Result BinaryReaderInterpreter::OnTable(Index index,
+ Type elem_type,
+ const Limits* elem_limits) {
if (module->table_index != kInvalidIndex) {
PrintError("only one table allowed");
- return Result::Error;
+ return wabt::Result::Error;
}
env->tables.emplace_back(*elem_limits);
module->table_index = env->tables.size() - 1;
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::OnMemory(Index index,
- const Limits* page_limits) {
+wabt::Result BinaryReaderInterpreter::OnMemory(Index index,
+ const Limits* page_limits) {
if (module->memory_index != kInvalidIndex) {
PrintError("only one memory allowed");
- return Result::Error;
+ return wabt::Result::Error;
}
env->memories.emplace_back(*page_limits);
module->memory_index = env->memories.size() - 1;
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::OnGlobalCount(Index count) {
+wabt::Result BinaryReaderInterpreter::OnGlobalCount(Index count) {
for (Index i = 0; i < count; ++i)
global_index_mapping.push_back(env->globals.size() + i);
env->globals.resize(env->globals.size() + count);
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::BeginGlobal(Index index,
- Type type,
- bool mutable_) {
- InterpreterGlobal* global = GetGlobalByModuleIndex(index);
+wabt::Result BinaryReaderInterpreter::BeginGlobal(Index index,
+ Type type,
+ bool mutable_) {
+ Global* global = GetGlobalByModuleIndex(index);
global->typed_value.type = type;
global->mutable_ = mutable_;
init_expr_value.type = Type::Void;
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::EndGlobalInitExpr(Index index) {
- InterpreterGlobal* global = GetGlobalByModuleIndex(index);
+wabt::Result BinaryReaderInterpreter::EndGlobalInitExpr(Index index) {
+ Global* global = GetGlobalByModuleIndex(index);
if (init_expr_value.type != global->typed_value.type) {
PrintError("type mismatch in global, expected %s but got %s.",
get_type_name(global->typed_value.type),
get_type_name(init_expr_value.type));
- return Result::Error;
+ return wabt::Result::Error;
}
global->typed_value = init_expr_value;
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::OnInitExprF32ConstExpr(Index index,
- uint32_t value_bits) {
+wabt::Result BinaryReaderInterpreter::OnInitExprF32ConstExpr(
+ Index index,
+ uint32_t value_bits) {
init_expr_value.type = Type::F32;
init_expr_value.value.f32_bits = value_bits;
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::OnInitExprF64ConstExpr(Index index,
- uint64_t value_bits) {
+wabt::Result BinaryReaderInterpreter::OnInitExprF64ConstExpr(
+ Index index,
+ uint64_t value_bits) {
init_expr_value.type = Type::F64;
init_expr_value.value.f64_bits = value_bits;
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::OnInitExprGetGlobalExpr(Index index,
- Index global_index) {
+wabt::Result BinaryReaderInterpreter::OnInitExprGetGlobalExpr(
+ Index index,
+ Index global_index) {
if (global_index >= num_global_imports) {
PrintError("initializer expression can only reference an imported global");
- return Result::Error;
+ return wabt::Result::Error;
}
- InterpreterGlobal* ref_global = GetGlobalByModuleIndex(global_index);
+ Global* ref_global = GetGlobalByModuleIndex(global_index);
if (ref_global->mutable_) {
PrintError("initializer expression cannot reference a mutable global");
- return Result::Error;
+ return wabt::Result::Error;
}
init_expr_value = ref_global->typed_value;
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::OnInitExprI32ConstExpr(Index index,
- uint32_t value) {
+wabt::Result BinaryReaderInterpreter::OnInitExprI32ConstExpr(Index index,
+ uint32_t value) {
init_expr_value.type = Type::I32;
init_expr_value.value.i32 = value;
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::OnInitExprI64ConstExpr(Index index,
- uint64_t value) {
+wabt::Result BinaryReaderInterpreter::OnInitExprI64ConstExpr(Index index,
+ uint64_t value) {
init_expr_value.type = Type::I64;
init_expr_value.value.i64 = value;
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::OnExport(Index index,
- ExternalKind kind,
- Index item_index,
- StringSlice name) {
+wabt::Result BinaryReaderInterpreter::OnExport(Index index,
+ ExternalKind kind,
+ Index item_index,
+ StringSlice name) {
switch (kind) {
case ExternalKind::Func:
item_index = TranslateFuncIndexToEnv(item_index);
@@ -980,10 +983,10 @@ Result BinaryReaderInterpreter::OnExport(Index index,
case ExternalKind::Global: {
item_index = TranslateGlobalIndexToEnv(item_index);
- InterpreterGlobal* global = &env->globals[item_index];
+ Global* global = &env->globals[item_index];
if (global->mutable_) {
PrintError("mutable globals cannot be exported");
- return Result::Error;
+ return wabt::Result::Error;
}
break;
}
@@ -991,63 +994,64 @@ Result BinaryReaderInterpreter::OnExport(Index index,
return AppendExport(module, kind, item_index, name);
}
-Result BinaryReaderInterpreter::OnStartFunction(Index func_index) {
+wabt::Result BinaryReaderInterpreter::OnStartFunction(Index func_index) {
Index start_func_index = TranslateFuncIndexToEnv(func_index);
- InterpreterFunc* start_func = GetFuncByEnvIndex(start_func_index);
- InterpreterFuncSignature* sig = GetSignatureByEnvIndex(start_func->sig_index);
+ Func* start_func = GetFuncByEnvIndex(start_func_index);
+ FuncSignature* sig = GetSignatureByEnvIndex(start_func->sig_index);
if (sig->param_types.size() != 0) {
PrintError("start function must be nullary");
- return Result::Error;
+ return wabt::Result::Error;
}
if (sig->result_types.size() != 0) {
PrintError("start function must not return anything");
- return Result::Error;
+ return wabt::Result::Error;
}
module->start_func_index = start_func_index;
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::EndElemSegmentInitExpr(Index index) {
+wabt::Result BinaryReaderInterpreter::EndElemSegmentInitExpr(Index index) {
if (init_expr_value.type != Type::I32) {
PrintError("type mismatch in elem segment, expected i32 but got %s",
get_type_name(init_expr_value.type));
- return Result::Error;
+ return wabt::Result::Error;
}
table_offset = init_expr_value.value.i32;
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::OnElemSegmentFunctionIndex(Index index,
- Index func_index) {
+wabt::Result BinaryReaderInterpreter::OnElemSegmentFunctionIndex(
+ Index index,
+ Index func_index) {
assert(module->table_index != kInvalidIndex);
- InterpreterTable* table = &env->tables[module->table_index];
+ Table* table = &env->tables[module->table_index];
if (table_offset >= table->func_indexes.size()) {
PrintError("elem segment offset is out of bounds: %u >= max value %" PRIzd,
table_offset, table->func_indexes.size());
- return Result::Error;
+ return wabt::Result::Error;
}
Index max_func_index = func_index_mapping.size();
if (func_index >= max_func_index) {
PrintError("invalid func_index: %" PRIindex " (max %" PRIindex ")",
func_index, max_func_index);
- return Result::Error;
+ return wabt::Result::Error;
}
elem_segment_infos.emplace_back(&table->func_indexes[table_offset++],
TranslateFuncIndexToEnv(func_index));
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::OnDataSegmentData(Index index,
- const void* src_data,
- Address size) {
+wabt::Result BinaryReaderInterpreter::OnDataSegmentData(Index index,
+ const void* src_data,
+ Address size) {
assert(module->memory_index != kInvalidIndex);
- InterpreterMemory* memory = &env->memories[module->memory_index];
+ Memory* memory = &env->memories[module->memory_index];
if (init_expr_value.type != Type::I32) {
PrintError("type mismatch in data segment, expected i32 but got %s",
get_type_name(init_expr_value.type));
- return Result::Error;
+ return wabt::Result::Error;
}
Address address = init_expr_value.value.i32;
uint64_t end_address =
@@ -1056,13 +1060,13 @@ Result BinaryReaderInterpreter::OnDataSegmentData(Index index,
PrintError("data segment is out of bounds: [%" PRIaddress ", %" PRIu64
") >= max value %" PRIzd,
address, end_address, memory->data.size());
- return Result::Error;
+ return wabt::Result::Error;
}
if (size > 0)
data_segment_infos.emplace_back(&memory->data[address], src_data, size);
- return Result::Ok;
+ return wabt::Result::Ok;
}
void BinaryReaderInterpreter::PushLabel(IstreamOffset offset,
@@ -1080,9 +1084,9 @@ void BinaryReaderInterpreter::PopLabel() {
}
}
-Result BinaryReaderInterpreter::BeginFunctionBody(Index index) {
- DefinedInterpreterFunc* func = GetFuncByModuleIndex(index)->as_defined();
- InterpreterFuncSignature* sig = GetSignatureByEnvIndex(func->sig_index);
+wabt::Result BinaryReaderInterpreter::BeginFunctionBody(Index index) {
+ DefinedFunc* func = GetFuncByModuleIndex(index)->as_defined();
+ FuncSignature* sig = GetSignatureByEnvIndex(func->sig_index);
func->offset = GetIstreamOffset();
func->local_decl_count = 0;
@@ -1106,29 +1110,29 @@ Result BinaryReaderInterpreter::BeginFunctionBody(Index index) {
/* push implicit func label (equivalent to return) */
PushLabel(kInvalidIstreamOffset, kInvalidIstreamOffset);
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::EndFunctionBody(Index index) {
+wabt::Result BinaryReaderInterpreter::EndFunctionBody(Index index) {
FixupTopLabel();
Index drop_count, keep_count;
CHECK_RESULT(GetReturnDropKeepCount(&drop_count, &keep_count));
CHECK_RESULT(typechecker_end_function(&typechecker));
CHECK_RESULT(EmitDropKeep(drop_count, keep_count));
- CHECK_RESULT(EmitOpcode(InterpreterOpcode::Return));
+ CHECK_RESULT(EmitOpcode(interpreter::Opcode::Return));
PopLabel();
current_func = nullptr;
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::OnLocalDeclCount(Index count) {
+wabt::Result BinaryReaderInterpreter::OnLocalDeclCount(Index count) {
current_func->local_decl_count = count;
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::OnLocalDecl(Index decl_index,
- Index count,
- Type type) {
+wabt::Result BinaryReaderInterpreter::OnLocalDecl(Index decl_index,
+ Index count,
+ Type type) {
current_func->local_count += count;
for (Index i = 0; i < count; ++i)
@@ -1136,79 +1140,82 @@ Result BinaryReaderInterpreter::OnLocalDecl(Index decl_index,
if (decl_index == current_func->local_decl_count - 1) {
/* last local declaration, allocate space for all locals. */
- CHECK_RESULT(EmitOpcode(InterpreterOpcode::Alloca));
+ CHECK_RESULT(EmitOpcode(interpreter::Opcode::Alloca));
CHECK_RESULT(EmitI32(current_func->local_count));
}
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::CheckHasMemory(Opcode opcode) {
+wabt::Result BinaryReaderInterpreter::CheckHasMemory(wabt::Opcode opcode) {
if (module->memory_index == kInvalidIndex) {
PrintError("%s requires an imported or defined memory.",
get_opcode_name(opcode));
- return Result::Error;
+ return wabt::Result::Error;
}
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::CheckAlign(uint32_t alignment_log2,
- Address natural_alignment) {
+wabt::Result BinaryReaderInterpreter::CheckAlign(uint32_t alignment_log2,
+ Address natural_alignment) {
if (alignment_log2 >= 32 || (1U << alignment_log2) > natural_alignment) {
PrintError("alignment must not be larger than natural alignment (%u)",
natural_alignment);
- return Result::Error;
+ return wabt::Result::Error;
}
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::OnUnaryExpr(Opcode opcode) {
+wabt::Result BinaryReaderInterpreter::OnUnaryExpr(wabt::Opcode opcode) {
CHECK_RESULT(typechecker_on_unary(&typechecker, opcode));
CHECK_RESULT(EmitOpcode(opcode));
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::OnBinaryExpr(Opcode opcode) {
+wabt::Result BinaryReaderInterpreter::OnBinaryExpr(wabt::Opcode opcode) {
CHECK_RESULT(typechecker_on_binary(&typechecker, opcode));
CHECK_RESULT(EmitOpcode(opcode));
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::OnBlockExpr(Index num_types, Type* sig_types) {
+wabt::Result BinaryReaderInterpreter::OnBlockExpr(Index num_types,
+ Type* sig_types) {
TypeVector sig(sig_types, sig_types + num_types);
CHECK_RESULT(typechecker_on_block(&typechecker, &sig));
PushLabel(kInvalidIstreamOffset, kInvalidIstreamOffset);
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::OnLoopExpr(Index num_types, Type* sig_types) {
+wabt::Result BinaryReaderInterpreter::OnLoopExpr(Index num_types,
+ Type* sig_types) {
TypeVector sig(sig_types, sig_types + num_types);
CHECK_RESULT(typechecker_on_loop(&typechecker, &sig));
PushLabel(GetIstreamOffset(), kInvalidIstreamOffset);
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::OnIfExpr(Index num_types, Type* sig_types) {
+wabt::Result BinaryReaderInterpreter::OnIfExpr(Index num_types,
+ Type* sig_types) {
TypeVector sig(sig_types, sig_types + num_types);
CHECK_RESULT(typechecker_on_if(&typechecker, &sig));
- CHECK_RESULT(EmitOpcode(InterpreterOpcode::BrUnless));
+ CHECK_RESULT(EmitOpcode(interpreter::Opcode::BrUnless));
IstreamOffset fixup_offset = GetIstreamOffset();
CHECK_RESULT(EmitI32(kInvalidIstreamOffset));
PushLabel(kInvalidIstreamOffset, fixup_offset);
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::OnElseExpr() {
+wabt::Result BinaryReaderInterpreter::OnElseExpr() {
CHECK_RESULT(typechecker_on_else(&typechecker));
Label* label = TopLabel();
IstreamOffset fixup_cond_offset = label->fixup_offset;
- CHECK_RESULT(EmitOpcode(InterpreterOpcode::Br));
+ CHECK_RESULT(EmitOpcode(interpreter::Opcode::Br));
label->fixup_offset = GetIstreamOffset();
CHECK_RESULT(EmitI32(kInvalidIstreamOffset));
CHECK_RESULT(EmitI32At(fixup_cond_offset, GetIstreamOffset()));
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::OnEndExpr() {
+wabt::Result BinaryReaderInterpreter::OnEndExpr() {
TypeCheckerLabel* label;
CHECK_RESULT(typechecker_get_label(&typechecker, 0, &label));
LabelType label_type = label->label_type;
@@ -1218,41 +1225,42 @@ Result BinaryReaderInterpreter::OnEndExpr() {
}
FixupTopLabel();
PopLabel();
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::OnBrExpr(Index depth) {
+wabt::Result BinaryReaderInterpreter::OnBrExpr(Index depth) {
Index drop_count, keep_count;
CHECK_RESULT(GetBrDropKeepCount(depth, &drop_count, &keep_count));
CHECK_RESULT(typechecker_on_br(&typechecker, depth));
CHECK_RESULT(EmitBr(depth, drop_count, keep_count));
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::OnBrIfExpr(Index depth) {
+wabt::Result BinaryReaderInterpreter::OnBrIfExpr(Index depth) {
Index drop_count, keep_count;
CHECK_RESULT(typechecker_on_br_if(&typechecker, depth));
CHECK_RESULT(GetBrDropKeepCount(depth, &drop_count, &keep_count));
/* flip the br_if so if <cond> is true it can drop values from the stack */
- CHECK_RESULT(EmitOpcode(InterpreterOpcode::BrUnless));
+ CHECK_RESULT(EmitOpcode(interpreter::Opcode::BrUnless));
IstreamOffset fixup_br_offset = GetIstreamOffset();
CHECK_RESULT(EmitI32(kInvalidIstreamOffset));
CHECK_RESULT(EmitBr(depth, drop_count, keep_count));
CHECK_RESULT(EmitI32At(fixup_br_offset, GetIstreamOffset()));
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::OnBrTableExpr(Index num_targets,
- Index* target_depths,
- Index default_target_depth) {
+wabt::Result BinaryReaderInterpreter::OnBrTableExpr(
+ Index num_targets,
+ Index* target_depths,
+ Index default_target_depth) {
CHECK_RESULT(typechecker_begin_br_table(&typechecker));
- CHECK_RESULT(EmitOpcode(InterpreterOpcode::BrTable));
+ CHECK_RESULT(EmitOpcode(interpreter::Opcode::BrTable));
CHECK_RESULT(EmitI32(num_targets));
IstreamOffset fixup_table_offset = GetIstreamOffset();
CHECK_RESULT(EmitI32(kInvalidIstreamOffset));
/* not necessary for the interpreter, but it makes it easier to disassemble.
* This opcode specifies how many bytes of data follow. */
- CHECK_RESULT(EmitOpcode(InterpreterOpcode::Data));
+ CHECK_RESULT(EmitOpcode(interpreter::Opcode::Data));
CHECK_RESULT(EmitI32((num_targets + 1) * WABT_TABLE_ENTRY_SIZE));
CHECK_RESULT(EmitI32At(fixup_table_offset, GetIstreamOffset()));
@@ -1263,105 +1271,105 @@ Result BinaryReaderInterpreter::OnBrTableExpr(Index num_targets,
}
CHECK_RESULT(typechecker_end_br_table(&typechecker));
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::OnCallExpr(Index func_index) {
- InterpreterFunc* func = GetFuncByModuleIndex(func_index);
- InterpreterFuncSignature* sig = GetSignatureByEnvIndex(func->sig_index);
+wabt::Result BinaryReaderInterpreter::OnCallExpr(Index func_index) {
+ Func* func = GetFuncByModuleIndex(func_index);
+ FuncSignature* sig = GetSignatureByEnvIndex(func->sig_index);
CHECK_RESULT(
typechecker_on_call(&typechecker, &sig->param_types, &sig->result_types));
if (func->is_host) {
- CHECK_RESULT(EmitOpcode(InterpreterOpcode::CallHost));
+ CHECK_RESULT(EmitOpcode(interpreter::Opcode::CallHost));
CHECK_RESULT(EmitI32(TranslateFuncIndexToEnv(func_index)));
} else {
- CHECK_RESULT(EmitOpcode(InterpreterOpcode::Call));
+ CHECK_RESULT(EmitOpcode(interpreter::Opcode::Call));
CHECK_RESULT(EmitFuncOffset(func->as_defined(), func_index));
}
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::OnCallIndirectExpr(Index sig_index) {
+wabt::Result BinaryReaderInterpreter::OnCallIndirectExpr(Index sig_index) {
if (module->table_index == kInvalidIndex) {
PrintError("found call_indirect operator, but no table");
- return Result::Error;
+ return wabt::Result::Error;
}
- InterpreterFuncSignature* sig = GetSignatureByModuleIndex(sig_index);
+ FuncSignature* sig = GetSignatureByModuleIndex(sig_index);
CHECK_RESULT(typechecker_on_call_indirect(&typechecker, &sig->param_types,
&sig->result_types));
- CHECK_RESULT(EmitOpcode(InterpreterOpcode::CallIndirect));
+ CHECK_RESULT(EmitOpcode(interpreter::Opcode::CallIndirect));
CHECK_RESULT(EmitI32(module->table_index));
CHECK_RESULT(EmitI32(TranslateSigIndexToEnv(sig_index)));
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::OnCompareExpr(Opcode opcode) {
+wabt::Result BinaryReaderInterpreter::OnCompareExpr(wabt::Opcode opcode) {
return OnBinaryExpr(opcode);
}
-Result BinaryReaderInterpreter::OnConvertExpr(Opcode opcode) {
+wabt::Result BinaryReaderInterpreter::OnConvertExpr(wabt::Opcode opcode) {
return OnUnaryExpr(opcode);
}
-Result BinaryReaderInterpreter::OnDropExpr() {
+wabt::Result BinaryReaderInterpreter::OnDropExpr() {
CHECK_RESULT(typechecker_on_drop(&typechecker));
- CHECK_RESULT(EmitOpcode(InterpreterOpcode::Drop));
- return Result::Ok;
+ CHECK_RESULT(EmitOpcode(interpreter::Opcode::Drop));
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::OnI32ConstExpr(uint32_t value) {
+wabt::Result BinaryReaderInterpreter::OnI32ConstExpr(uint32_t value) {
CHECK_RESULT(typechecker_on_const(&typechecker, Type::I32));
- CHECK_RESULT(EmitOpcode(InterpreterOpcode::I32Const));
+ CHECK_RESULT(EmitOpcode(interpreter::Opcode::I32Const));
CHECK_RESULT(EmitI32(value));
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::OnI64ConstExpr(uint64_t value) {
+wabt::Result BinaryReaderInterpreter::OnI64ConstExpr(uint64_t value) {
CHECK_RESULT(typechecker_on_const(&typechecker, Type::I64));
- CHECK_RESULT(EmitOpcode(InterpreterOpcode::I64Const));
+ CHECK_RESULT(EmitOpcode(interpreter::Opcode::I64Const));
CHECK_RESULT(EmitI64(value));
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::OnF32ConstExpr(uint32_t value_bits) {
+wabt::Result BinaryReaderInterpreter::OnF32ConstExpr(uint32_t value_bits) {
CHECK_RESULT(typechecker_on_const(&typechecker, Type::F32));
- CHECK_RESULT(EmitOpcode(InterpreterOpcode::F32Const));
+ CHECK_RESULT(EmitOpcode(interpreter::Opcode::F32Const));
CHECK_RESULT(EmitI32(value_bits));
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::OnF64ConstExpr(uint64_t value_bits) {
+wabt::Result BinaryReaderInterpreter::OnF64ConstExpr(uint64_t value_bits) {
CHECK_RESULT(typechecker_on_const(&typechecker, Type::F64));
- CHECK_RESULT(EmitOpcode(InterpreterOpcode::F64Const));
+ CHECK_RESULT(EmitOpcode(interpreter::Opcode::F64Const));
CHECK_RESULT(EmitI64(value_bits));
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::OnGetGlobalExpr(Index global_index) {
+wabt::Result BinaryReaderInterpreter::OnGetGlobalExpr(Index global_index) {
CHECK_RESULT(CheckGlobal(global_index));
Type type = GetGlobalTypeByModuleIndex(global_index);
CHECK_RESULT(typechecker_on_get_global(&typechecker, type));
- CHECK_RESULT(EmitOpcode(InterpreterOpcode::GetGlobal));
+ CHECK_RESULT(EmitOpcode(interpreter::Opcode::GetGlobal));
CHECK_RESULT(EmitI32(TranslateGlobalIndexToEnv(global_index)));
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::OnSetGlobalExpr(Index global_index) {
+wabt::Result BinaryReaderInterpreter::OnSetGlobalExpr(Index global_index) {
CHECK_RESULT(CheckGlobal(global_index));
- InterpreterGlobal* global = GetGlobalByModuleIndex(global_index);
+ Global* global = GetGlobalByModuleIndex(global_index);
if (!global->mutable_) {
PrintError("can't set_global on immutable global at index %" PRIindex ".",
global_index);
- return Result::Error;
+ return wabt::Result::Error;
}
CHECK_RESULT(
typechecker_on_set_global(&typechecker, global->typed_value.type));
- CHECK_RESULT(EmitOpcode(InterpreterOpcode::SetGlobal));
+ CHECK_RESULT(EmitOpcode(interpreter::Opcode::SetGlobal));
CHECK_RESULT(EmitI32(TranslateGlobalIndexToEnv(global_index)));
- return Result::Ok;
+ return wabt::Result::Ok;
}
Index BinaryReaderInterpreter::TranslateLocalIndex(Index local_index) {
@@ -1369,7 +1377,7 @@ Index BinaryReaderInterpreter::TranslateLocalIndex(Index local_index) {
current_func->param_and_local_types.size() - local_index;
}
-Result BinaryReaderInterpreter::OnGetLocalExpr(Index local_index) {
+wabt::Result BinaryReaderInterpreter::OnGetLocalExpr(Index local_index) {
CHECK_RESULT(CheckLocal(local_index));
Type type = GetLocalTypeByIndex(current_func, local_index);
/* Get the translated index before calling typechecker_on_get_local
@@ -1377,130 +1385,129 @@ Result BinaryReaderInterpreter::OnGetLocalExpr(Index local_index) {
* relative to the old stack size. */
Index translated_local_index = TranslateLocalIndex(local_index);
CHECK_RESULT(typechecker_on_get_local(&typechecker, type));
- CHECK_RESULT(EmitOpcode(InterpreterOpcode::GetLocal));
+ CHECK_RESULT(EmitOpcode(interpreter::Opcode::GetLocal));
CHECK_RESULT(EmitI32(translated_local_index));
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::OnSetLocalExpr(Index local_index) {
+wabt::Result BinaryReaderInterpreter::OnSetLocalExpr(Index local_index) {
CHECK_RESULT(CheckLocal(local_index));
Type type = GetLocalTypeByIndex(current_func, local_index);
CHECK_RESULT(typechecker_on_set_local(&typechecker, type));
- CHECK_RESULT(EmitOpcode(InterpreterOpcode::SetLocal));
+ CHECK_RESULT(EmitOpcode(interpreter::Opcode::SetLocal));
CHECK_RESULT(EmitI32(TranslateLocalIndex(local_index)));
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::OnTeeLocalExpr(Index local_index) {
+wabt::Result BinaryReaderInterpreter::OnTeeLocalExpr(Index local_index) {
CHECK_RESULT(CheckLocal(local_index));
Type type = GetLocalTypeByIndex(current_func, local_index);
CHECK_RESULT(typechecker_on_tee_local(&typechecker, type));
- CHECK_RESULT(EmitOpcode(InterpreterOpcode::TeeLocal));
+ CHECK_RESULT(EmitOpcode(interpreter::Opcode::TeeLocal));
CHECK_RESULT(EmitI32(TranslateLocalIndex(local_index)));
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::OnGrowMemoryExpr() {
- CHECK_RESULT(CheckHasMemory(Opcode::GrowMemory));
+wabt::Result BinaryReaderInterpreter::OnGrowMemoryExpr() {
+ CHECK_RESULT(CheckHasMemory(wabt::Opcode::GrowMemory));
CHECK_RESULT(typechecker_on_grow_memory(&typechecker));
- CHECK_RESULT(EmitOpcode(InterpreterOpcode::GrowMemory));
+ CHECK_RESULT(EmitOpcode(interpreter::Opcode::GrowMemory));
CHECK_RESULT(EmitI32(module->memory_index));
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::OnLoadExpr(Opcode opcode,
- uint32_t alignment_log2,
- Address offset) {
+wabt::Result BinaryReaderInterpreter::OnLoadExpr(wabt::Opcode opcode,
+ uint32_t alignment_log2,
+ Address offset) {
CHECK_RESULT(CheckHasMemory(opcode));
CHECK_RESULT(CheckAlign(alignment_log2, get_opcode_memory_size(opcode)));
CHECK_RESULT(typechecker_on_load(&typechecker, opcode));
CHECK_RESULT(EmitOpcode(opcode));
CHECK_RESULT(EmitI32(module->memory_index));
CHECK_RESULT(EmitI32(offset));
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::OnStoreExpr(Opcode opcode,
- uint32_t alignment_log2,
- Address offset) {
+wabt::Result BinaryReaderInterpreter::OnStoreExpr(wabt::Opcode opcode,
+ uint32_t alignment_log2,
+ Address offset) {
CHECK_RESULT(CheckHasMemory(opcode));
CHECK_RESULT(CheckAlign(alignment_log2, get_opcode_memory_size(opcode)));
CHECK_RESULT(typechecker_on_store(&typechecker, opcode));
CHECK_RESULT(EmitOpcode(opcode));
CHECK_RESULT(EmitI32(module->memory_index));
CHECK_RESULT(EmitI32(offset));
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::OnCurrentMemoryExpr() {
- CHECK_RESULT(CheckHasMemory(Opcode::CurrentMemory));
+wabt::Result BinaryReaderInterpreter::OnCurrentMemoryExpr() {
+ CHECK_RESULT(CheckHasMemory(wabt::Opcode::CurrentMemory));
CHECK_RESULT(typechecker_on_current_memory(&typechecker));
- CHECK_RESULT(EmitOpcode(InterpreterOpcode::CurrentMemory));
+ CHECK_RESULT(EmitOpcode(interpreter::Opcode::CurrentMemory));
CHECK_RESULT(EmitI32(module->memory_index));
- return Result::Ok;
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::OnNopExpr() {
- return Result::Ok;
+wabt::Result BinaryReaderInterpreter::OnNopExpr() {
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::OnReturnExpr() {
+wabt::Result BinaryReaderInterpreter::OnReturnExpr() {
Index drop_count, keep_count;
CHECK_RESULT(GetReturnDropKeepCount(&drop_count, &keep_count));
CHECK_RESULT(typechecker_on_return(&typechecker));
CHECK_RESULT(EmitDropKeep(drop_count, keep_count));
- CHECK_RESULT(EmitOpcode(InterpreterOpcode::Return));
- return Result::Ok;
+ CHECK_RESULT(EmitOpcode(interpreter::Opcode::Return));
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::OnSelectExpr() {
+wabt::Result BinaryReaderInterpreter::OnSelectExpr() {
CHECK_RESULT(typechecker_on_select(&typechecker));
- CHECK_RESULT(EmitOpcode(InterpreterOpcode::Select));
- return Result::Ok;
+ CHECK_RESULT(EmitOpcode(interpreter::Opcode::Select));
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::OnUnreachableExpr() {
+wabt::Result BinaryReaderInterpreter::OnUnreachableExpr() {
CHECK_RESULT(typechecker_on_unreachable(&typechecker));
- CHECK_RESULT(EmitOpcode(InterpreterOpcode::Unreachable));
- return Result::Ok;
+ CHECK_RESULT(EmitOpcode(interpreter::Opcode::Unreachable));
+ return wabt::Result::Ok;
}
-Result BinaryReaderInterpreter::EndModule() {
+wabt::Result BinaryReaderInterpreter::EndModule() {
for (ElemSegmentInfo& info : elem_segment_infos) {
*info.dst = info.func_index;
}
for (DataSegmentInfo& info : data_segment_infos) {
memcpy(info.dst_data, info.src_data, info.size);
}
- return Result::Ok;
+ return wabt::Result::Ok;
}
} // namespace
-Result read_binary_interpreter(InterpreterEnvironment* env,
- const void* data,
- size_t size,
- const ReadBinaryOptions* options,
- BinaryErrorHandler* error_handler,
- DefinedInterpreterModule** out_module) {
+wabt::Result read_binary_interpreter(Environment* env,
+ const void* data,
+ size_t size,
+ const ReadBinaryOptions* options,
+ BinaryErrorHandler* error_handler,
+ DefinedModule** out_module) {
IstreamOffset istream_offset = env->istream->data.size();
- DefinedInterpreterModule* module =
- new DefinedInterpreterModule(istream_offset);
+ DefinedModule* module = new DefinedModule(istream_offset);
// Need to mark before constructing the reader since it takes ownership of
// env->istream, which makes env->istream == nullptr.
- InterpreterEnvironmentMark mark = mark_interpreter_environment(env);
+ EnvironmentMark mark = mark_environment(env);
BinaryReaderInterpreter reader(env, module, istream_offset, error_handler);
env->modules.emplace_back(module);
- Result result = read_binary(data, size, &reader, options);
+ wabt::Result result = read_binary(data, size, &reader, options);
env->istream = reader.ReleaseOutputBuffer();
if (WABT_SUCCEEDED(result)) {
env->istream->data.resize(reader.get_istream_offset());
module->istream_end = env->istream->data.size();
*out_module = module;
} else {
- reset_interpreter_environment_to_mark(env, mark);
+ reset_environment_to_mark(env, mark);
*out_module = nullptr;
}
return result;