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.cc678
1 files changed, 339 insertions, 339 deletions
diff --git a/src/binary-reader-interpreter.cc b/src/binary-reader-interpreter.cc
index 95508acc..0c2396ff 100644
--- a/src/binary-reader-interpreter.cc
+++ b/src/binary-reader-interpreter.cc
@@ -38,221 +38,225 @@ namespace wabt {
namespace {
-typedef std::vector<uint32_t> Uint32Vector;
-typedef std::vector<Uint32Vector> Uint32VectorVector;
+typedef std::vector<Index> IndexVector;
+typedef std::vector<IstreamOffset> IstreamOffsetVector;
+typedef std::vector<IstreamOffsetVector> IstreamOffsetVectorVector;
struct Label {
- Label(uint32_t offset, uint32_t fixup_offset);
+ Label(IstreamOffset offset, IstreamOffset fixup_offset);
- uint32_t offset; /* branch location in the istream */
- uint32_t fixup_offset;
+ IstreamOffset offset;
+ IstreamOffset fixup_offset;
};
-Label::Label(uint32_t offset, uint32_t fixup_offset)
+Label::Label(IstreamOffset offset, IstreamOffset fixup_offset)
: offset(offset), fixup_offset(fixup_offset) {}
struct ElemSegmentInfo {
- ElemSegmentInfo(uint32_t* dst, uint32_t func_index)
+ ElemSegmentInfo(Index* dst, Index func_index)
: dst(dst), func_index(func_index) {}
- uint32_t* dst;
- uint32_t func_index;
+ Index* dst;
+ Index func_index;
};
struct DataSegmentInfo {
- DataSegmentInfo(void* dst_data, const void* src_data, uint32_t size)
+ DataSegmentInfo(void* dst_data, const void* src_data, IstreamOffset size)
: dst_data(dst_data), src_data(src_data), size(size) {}
void* dst_data; // Not owned.
const void* src_data; // Not owned.
- uint32_t size;
+ IstreamOffset size;
};
class BinaryReaderInterpreter : public BinaryReaderNop {
public:
BinaryReaderInterpreter(InterpreterEnvironment* env,
DefinedInterpreterModule* module,
- size_t istream_offset,
+ IstreamOffset istream_offset,
BinaryErrorHandler* error_handler);
std::unique_ptr<OutputBuffer> ReleaseOutputBuffer();
- size_t get_istream_offset() { return istream_offset; }
+ IstreamOffset get_istream_offset() { return istream_offset; }
// Implement BinaryReader.
- virtual bool OnError(const char* message);
-
- virtual Result EndModule();
-
- virtual Result OnTypeCount(uint32_t count);
- virtual Result OnType(uint32_t index,
- uint32_t param_count,
- Type* param_types,
- uint32_t result_count,
- Type* result_types);
-
- virtual Result OnImportCount(uint32_t count);
- virtual Result OnImport(uint32_t index,
- StringSlice module_name,
- StringSlice field_name);
- virtual Result OnImportFunc(uint32_t import_index,
- StringSlice module_name,
- StringSlice field_name,
- uint32_t func_index,
- uint32_t sig_index);
- virtual Result OnImportTable(uint32_t import_index,
- StringSlice module_name,
- StringSlice field_name,
- uint32_t table_index,
- Type elem_type,
- const Limits* elem_limits);
- virtual Result OnImportMemory(uint32_t import_index,
- StringSlice module_name,
- StringSlice field_name,
- uint32_t memory_index,
- const Limits* page_limits);
- virtual Result OnImportGlobal(uint32_t import_index,
- StringSlice module_name,
- StringSlice field_name,
- uint32_t global_index,
- Type type,
- bool mutable_);
-
- virtual Result OnFunctionCount(uint32_t count);
- virtual Result OnFunction(uint32_t index, uint32_t sig_index);
-
- virtual Result OnTable(uint32_t index,
- Type elem_type,
- const Limits* elem_limits);
-
- virtual Result OnMemory(uint32_t index, const Limits* limits);
-
- virtual Result OnGlobalCount(uint32_t count);
- virtual Result BeginGlobal(uint32_t index, Type type, bool mutable_);
- virtual Result EndGlobalInitExpr(uint32_t index);
-
- virtual Result OnExport(uint32_t index,
- ExternalKind kind,
- uint32_t item_index,
- StringSlice name);
-
- virtual Result OnStartFunction(uint32_t func_index);
-
- virtual Result BeginFunctionBody(uint32_t index);
- virtual Result OnLocalDeclCount(uint32_t count);
- virtual Result OnLocalDecl(uint32_t decl_index, uint32_t count, Type type);
-
- virtual Result OnBinaryExpr(Opcode opcode);
- virtual Result OnBlockExpr(uint32_t num_types, Type* sig_types);
- virtual Result OnBrExpr(uint32_t depth);
- virtual Result OnBrIfExpr(uint32_t depth);
- virtual Result OnBrTableExpr(uint32_t num_targets,
- uint32_t* target_depths,
- uint32_t default_target_depth);
- virtual Result OnCallExpr(uint32_t func_index);
- virtual Result OnCallIndirectExpr(uint32_t sig_index);
- virtual Result OnCompareExpr(Opcode opcode);
- virtual Result OnConvertExpr(Opcode opcode);
- virtual Result OnCurrentMemoryExpr();
- virtual Result OnDropExpr();
- virtual Result OnElseExpr();
- virtual Result OnEndExpr();
- virtual Result OnF32ConstExpr(uint32_t value_bits);
- virtual Result OnF64ConstExpr(uint64_t value_bits);
- virtual Result OnGetGlobalExpr(uint32_t global_index);
- virtual Result OnGetLocalExpr(uint32_t local_index);
- virtual Result OnGrowMemoryExpr();
- virtual Result OnI32ConstExpr(uint32_t value);
- virtual Result OnI64ConstExpr(uint64_t value);
- virtual Result OnIfExpr(uint32_t num_types, Type* sig_types);
- virtual Result OnLoadExpr(Opcode opcode,
- uint32_t alignment_log2,
- uint32_t offset);
- virtual Result OnLoopExpr(uint32_t num_types, Type* sig_types);
- virtual Result OnNopExpr();
- virtual Result OnReturnExpr();
- virtual Result OnSelectExpr();
- virtual Result OnSetGlobalExpr(uint32_t global_index);
- virtual Result OnSetLocalExpr(uint32_t local_index);
- virtual Result OnStoreExpr(Opcode opcode,
- uint32_t alignment_log2,
- uint32_t offset);
- virtual Result OnTeeLocalExpr(uint32_t local_index);
- virtual Result OnUnaryExpr(Opcode opcode);
- virtual Result OnUnreachableExpr();
- virtual Result EndFunctionBody(uint32_t index);
-
- virtual Result EndElemSegmentInitExpr(uint32_t index);
- virtual Result OnElemSegmentFunctionIndex(uint32_t index,
- uint32_t func_index);
-
- virtual Result OnDataSegmentData(uint32_t index,
- const void* data,
- uint32_t size);
-
- virtual Result OnInitExprF32ConstExpr(uint32_t index, uint32_t value);
- virtual Result OnInitExprF64ConstExpr(uint32_t index, uint64_t value);
- virtual Result OnInitExprGetGlobalExpr(uint32_t index, uint32_t global_index);
- virtual Result OnInitExprI32ConstExpr(uint32_t index, uint32_t value);
- virtual Result OnInitExprI64ConstExpr(uint32_t index, uint64_t value);
+ 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,
+ 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;
private:
- Label* GetLabel(uint32_t depth);
+ Label* GetLabel(Index depth);
Label* TopLabel();
- void PushLabel(uint32_t offset, uint32_t fixup_offset);
+ void PushLabel(IstreamOffset offset, IstreamOffset fixup_offset);
void PopLabel();
- bool HandleError(uint32_t offset, const char* message);
+ bool HandleError(Offset offset, const char* message);
void PrintError(const char* format, ...);
static void OnTypecheckerError(const char* msg, void* user_data);
- uint32_t TranslateSigIndexToEnv(uint32_t sig_index);
- InterpreterFuncSignature* GetSignatureByEnvIndex(uint32_t sig_index);
- InterpreterFuncSignature* GetSignatureByModuleIndex(uint32_t sig_index);
- uint32_t TranslateFuncIndexToEnv(uint32_t func_index);
- uint32_t TranslateModuleFuncIndexToDefined(uint32_t func_index);
- InterpreterFunc* GetFuncByEnvIndex(uint32_t func_index);
- InterpreterFunc* GetFuncByModuleIndex(uint32_t func_index);
- uint32_t TranslateGlobalIndexToEnv(uint32_t global_index);
- InterpreterGlobal* GetGlobalByEnvIndex(uint32_t global_index);
- InterpreterGlobal* GetGlobalByModuleIndex(uint32_t global_index);
- Type GetGlobalTypeByModuleIndex(uint32_t global_index);
- uint32_t TranslateLocalIndex(uint32_t local_index);
- Type GetLocalTypeByIndex(InterpreterFunc* func, uint32_t local_index);
-
- uint32_t GetIstreamOffset();
-
- Result EmitDataAt(size_t offset, const void* data, size_t size);
- Result EmitData(const void* data, size_t size);
+ Index TranslateSigIndexToEnv(Index sig_index);
+ InterpreterFuncSignature* GetSignatureByEnvIndex(Index sig_index);
+ InterpreterFuncSignature* GetSignatureByModuleIndex(Index sig_index);
+ Index TranslateFuncIndexToEnv(Index func_index);
+ Index TranslateModuleFuncIndexToDefined(Index func_index);
+ InterpreterFunc* GetFuncByEnvIndex(Index func_index);
+ InterpreterFunc* GetFuncByModuleIndex(Index func_index);
+ Index TranslateGlobalIndexToEnv(Index global_index);
+ InterpreterGlobal* GetGlobalByEnvIndex(Index global_index);
+ InterpreterGlobal* GetGlobalByModuleIndex(Index global_index);
+ Type GetGlobalTypeByModuleIndex(Index global_index);
+ Index TranslateLocalIndex(Index local_index);
+ Type GetLocalTypeByIndex(InterpreterFunc* 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(uint32_t offset, uint32_t value);
+ Result EmitI32At(IstreamOffset offset, uint32_t value);
Result EmitDropKeep(uint32_t drop, uint8_t keep);
- Result AppendFixup(Uint32VectorVector* fixups_vector, uint32_t index);
- Result EmitBrOffset(uint32_t depth, uint32_t offset);
- Result GetBrDropKeepCount(uint32_t depth,
- uint32_t* out_drop_count,
- uint32_t* out_keep_count);
- Result GetReturnDropKeepCount(uint32_t* out_drop_count,
- uint32_t* out_keep_count);
- Result EmitBr(uint32_t depth, uint32_t drop_count, uint32_t keep_count);
- Result EmitBrTableOffset(uint32_t depth);
+ 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, uint32_t func_index);
+ Result EmitFuncOffset(DefinedInterpreterFunc* func, Index func_index);
- Result CheckLocal(uint32_t local_index);
- Result CheckGlobal(uint32_t global_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, uint32_t natural_alignment);
+ Result CheckAlign(uint32_t alignment_log2, Address natural_alignment);
Result AppendExport(InterpreterModule* module,
ExternalKind kind,
- uint32_t item_index,
+ Index item_index,
StringSlice name);
PrintErrorCallback MakePrintErrorCallback();
@@ -265,18 +269,18 @@ class BinaryReaderInterpreter : public BinaryReaderNop {
TypeCheckerErrorHandler tc_error_handler;
TypeChecker typechecker;
std::vector<Label> label_stack;
- Uint32VectorVector func_fixups;
- Uint32VectorVector depth_fixups;
+ IstreamOffsetVectorVector func_fixups;
+ IstreamOffsetVectorVector depth_fixups;
MemoryWriter istream_writer;
- uint32_t istream_offset = 0;
+ IstreamOffset istream_offset = 0;
/* mappings from module index space to env index space; this won't just be a
* translation, because imported values will be resolved as well */
- Uint32Vector sig_index_mapping;
- Uint32Vector func_index_mapping;
- Uint32Vector global_index_mapping;
+ IndexVector sig_index_mapping;
+ IndexVector func_index_mapping;
+ IndexVector global_index_mapping;
- uint32_t num_func_imports = 0;
- uint32_t num_global_imports = 0;
+ Index num_func_imports = 0;
+ Index num_global_imports = 0;
// Changes to linear memory and tables should not apply if a validation error
// occurs; these vectors cache the changes that must be applied after we know
@@ -286,16 +290,16 @@ class BinaryReaderInterpreter : public BinaryReaderNop {
/* values cached so they can be shared between callbacks */
InterpreterTypedValue init_expr_value;
- uint32_t table_offset = 0;
+ IstreamOffset table_offset = 0;
bool is_host_import = false;
HostInterpreterModule* host_import_module = nullptr;
- uint32_t import_env_index = 0;
+ Index import_env_index = 0;
};
BinaryReaderInterpreter::BinaryReaderInterpreter(
InterpreterEnvironment* env,
DefinedInterpreterModule* module,
- size_t istream_offset,
+ IstreamOffset istream_offset,
BinaryErrorHandler* error_handler)
: error_handler(error_handler),
env(env),
@@ -311,7 +315,7 @@ std::unique_ptr<OutputBuffer> BinaryReaderInterpreter::ReleaseOutputBuffer() {
return istream_writer.ReleaseOutputBuffer();
}
-Label* BinaryReaderInterpreter::GetLabel(uint32_t depth) {
+Label* BinaryReaderInterpreter::GetLabel(Index depth) {
assert(depth < label_stack.size());
return &label_stack[label_stack.size() - depth - 1];
}
@@ -320,15 +324,14 @@ Label* BinaryReaderInterpreter::TopLabel() {
return GetLabel(0);
}
-bool BinaryReaderInterpreter::HandleError(uint32_t offset,
- const char* message) {
+bool BinaryReaderInterpreter::HandleError(Offset offset, const char* message) {
return error_handler->OnError(offset, message);
}
void WABT_PRINTF_FORMAT(2, 3)
BinaryReaderInterpreter::PrintError(const char* format, ...) {
WABT_SNPRINTF_ALLOCA(buffer, length, format);
- HandleError(WABT_INVALID_OFFSET, buffer);
+ HandleError(kInvalidOffset, buffer);
}
// static
@@ -337,79 +340,77 @@ void BinaryReaderInterpreter::OnTypecheckerError(const char* msg,
static_cast<BinaryReaderInterpreter*>(user_data)->PrintError("%s", msg);
}
-uint32_t BinaryReaderInterpreter::TranslateSigIndexToEnv(uint32_t sig_index) {
+Index BinaryReaderInterpreter::TranslateSigIndexToEnv(Index sig_index) {
assert(sig_index < sig_index_mapping.size());
return sig_index_mapping[sig_index];
}
InterpreterFuncSignature* BinaryReaderInterpreter::GetSignatureByEnvIndex(
- uint32_t sig_index) {
+ Index sig_index) {
return &env->sigs[sig_index];
}
InterpreterFuncSignature* BinaryReaderInterpreter::GetSignatureByModuleIndex(
- uint32_t sig_index) {
+ Index sig_index) {
return GetSignatureByEnvIndex(TranslateSigIndexToEnv(sig_index));
}
-uint32_t BinaryReaderInterpreter::TranslateFuncIndexToEnv(uint32_t func_index) {
+Index BinaryReaderInterpreter::TranslateFuncIndexToEnv(Index func_index) {
assert(func_index < func_index_mapping.size());
return func_index_mapping[func_index];
}
-uint32_t BinaryReaderInterpreter::TranslateModuleFuncIndexToDefined(
- uint32_t func_index) {
+Index BinaryReaderInterpreter::TranslateModuleFuncIndexToDefined(
+ Index func_index) {
assert(func_index >= num_func_imports);
return func_index - num_func_imports;
}
InterpreterFunc* BinaryReaderInterpreter::GetFuncByEnvIndex(
- uint32_t func_index) {
+ Index func_index) {
return env->funcs[func_index].get();
}
InterpreterFunc* BinaryReaderInterpreter::GetFuncByModuleIndex(
- uint32_t func_index) {
+ Index func_index) {
return GetFuncByEnvIndex(TranslateFuncIndexToEnv(func_index));
}
-uint32_t BinaryReaderInterpreter::TranslateGlobalIndexToEnv(
- uint32_t global_index) {
+Index BinaryReaderInterpreter::TranslateGlobalIndexToEnv(Index global_index) {
return global_index_mapping[global_index];
}
InterpreterGlobal* BinaryReaderInterpreter::GetGlobalByEnvIndex(
- uint32_t global_index) {
+ Index global_index) {
return &env->globals[global_index];
}
InterpreterGlobal* BinaryReaderInterpreter::GetGlobalByModuleIndex(
- uint32_t global_index) {
+ Index global_index) {
return GetGlobalByEnvIndex(TranslateGlobalIndexToEnv(global_index));
}
-Type BinaryReaderInterpreter::GetGlobalTypeByModuleIndex(
- uint32_t global_index) {
+Type BinaryReaderInterpreter::GetGlobalTypeByModuleIndex(Index global_index) {
return GetGlobalByModuleIndex(global_index)->typed_value.type;
}
Type BinaryReaderInterpreter::GetLocalTypeByIndex(InterpreterFunc* func,
- uint32_t local_index) {
+ Index local_index) {
assert(!func->is_host);
return func->as_defined()->param_and_local_types[local_index];
}
-uint32_t BinaryReaderInterpreter::GetIstreamOffset() {
+IstreamOffset BinaryReaderInterpreter::GetIstreamOffset() {
return istream_offset;
}
-Result BinaryReaderInterpreter::EmitDataAt(size_t offset,
+Result BinaryReaderInterpreter::EmitDataAt(IstreamOffset offset,
const void* data,
- size_t size) {
+ IstreamOffset size) {
return istream_writer.WriteData(offset, data, size);
}
-Result BinaryReaderInterpreter::EmitData(const void* data, size_t size) {
+Result BinaryReaderInterpreter::EmitData(const void* data, IstreamOffset size) {
CHECK_RESULT(EmitDataAt(istream_offset, data, size));
istream_offset += size;
return Result::Ok;
@@ -435,7 +436,8 @@ Result BinaryReaderInterpreter::EmitI64(uint64_t value) {
return EmitData(&value, sizeof(value));
}
-Result BinaryReaderInterpreter::EmitI32At(uint32_t offset, uint32_t value) {
+Result BinaryReaderInterpreter::EmitI32At(IstreamOffset offset,
+ uint32_t value) {
return EmitDataAt(offset, &value, sizeof(value));
}
@@ -454,16 +456,18 @@ Result BinaryReaderInterpreter::EmitDropKeep(uint32_t drop, uint8_t keep) {
return Result::Ok;
}
-Result BinaryReaderInterpreter::AppendFixup(Uint32VectorVector* fixups_vector,
- uint32_t index) {
+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;
}
-Result BinaryReaderInterpreter::EmitBrOffset(uint32_t depth, uint32_t offset) {
- if (offset == WABT_INVALID_OFFSET) {
+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. */
depth = label_stack.size() - 1 - depth;
@@ -473,9 +477,9 @@ Result BinaryReaderInterpreter::EmitBrOffset(uint32_t depth, uint32_t offset) {
return Result::Ok;
}
-Result BinaryReaderInterpreter::GetBrDropKeepCount(uint32_t depth,
- uint32_t* out_drop_count,
- uint32_t* out_keep_count) {
+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 =
@@ -490,9 +494,8 @@ Result BinaryReaderInterpreter::GetBrDropKeepCount(uint32_t depth,
return Result::Ok;
}
-Result BinaryReaderInterpreter::GetReturnDropKeepCount(
- uint32_t* out_drop_count,
- uint32_t* out_keep_count) {
+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;
@@ -502,17 +505,17 @@ Result BinaryReaderInterpreter::GetReturnDropKeepCount(
return Result::Ok;
}
-Result BinaryReaderInterpreter::EmitBr(uint32_t depth,
- uint32_t drop_count,
- uint32_t keep_count) {
+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(EmitBrOffset(depth, GetLabel(depth)->offset));
return Result::Ok;
}
-Result BinaryReaderInterpreter::EmitBrTableOffset(uint32_t depth) {
- uint32_t drop_count, keep_count;
+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));
@@ -521,24 +524,24 @@ Result BinaryReaderInterpreter::EmitBrTableOffset(uint32_t depth) {
}
Result BinaryReaderInterpreter::FixupTopLabel() {
- uint32_t offset = GetIstreamOffset();
- uint32_t top = label_stack.size() - 1;
+ IstreamOffset offset = GetIstreamOffset();
+ Index top = label_stack.size() - 1;
if (top >= depth_fixups.size()) {
/* nothing to fixup */
return Result::Ok;
}
- Uint32Vector& fixups = depth_fixups[top];
- for (uint32_t fixup : fixups)
+ IstreamOffsetVector& fixups = depth_fixups[top];
+ for (IstreamOffset fixup : fixups)
CHECK_RESULT(EmitI32At(fixup, offset));
fixups.clear();
return Result::Ok;
}
Result BinaryReaderInterpreter::EmitFuncOffset(DefinedInterpreterFunc* func,
- uint32_t func_index) {
- if (func->offset == WABT_INVALID_OFFSET) {
- uint32_t defined_index = TranslateModuleFuncIndexToDefined(func_index);
+ 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));
@@ -549,18 +552,18 @@ bool BinaryReaderInterpreter::OnError(const char* message) {
return HandleError(state->offset, message);
}
-Result BinaryReaderInterpreter::OnTypeCount(uint32_t count) {
+Result BinaryReaderInterpreter::OnTypeCount(Index count) {
sig_index_mapping.resize(count);
- for (uint32_t i = 0; i < count; ++i)
+ 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;
}
-Result BinaryReaderInterpreter::OnType(uint32_t index,
- uint32_t param_count,
+Result BinaryReaderInterpreter::OnType(Index index,
+ Index param_count,
Type* param_types,
- uint32_t result_count,
+ Index result_count,
Type* result_types) {
InterpreterFuncSignature* sig = GetSignatureByModuleIndex(index);
sig->param_types.insert(sig->param_types.end(), param_types,
@@ -570,12 +573,12 @@ Result BinaryReaderInterpreter::OnType(uint32_t index,
return Result::Ok;
}
-Result BinaryReaderInterpreter::OnImportCount(uint32_t count) {
+Result BinaryReaderInterpreter::OnImportCount(Index count) {
module->imports.resize(count);
return Result::Ok;
}
-Result BinaryReaderInterpreter::OnImport(uint32_t index,
+Result BinaryReaderInterpreter::OnImport(Index index,
StringSlice module_name,
StringSlice field_name) {
InterpreterImport* import = &module->imports[index];
@@ -612,21 +615,21 @@ Result BinaryReaderInterpreter::OnImport(uint32_t index,
return Result::Ok;
}
-Result BinaryReaderInterpreter::CheckLocal(uint32_t local_index) {
- uint32_t max_local_index = current_func->param_and_local_types.size();
+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: %d (max %d)", local_index,
- max_local_index);
+ PrintError("invalid local_index: %" PRIindex " (max %" PRIindex ")",
+ local_index, max_local_index);
return Result::Error;
}
return Result::Ok;
}
-Result BinaryReaderInterpreter::CheckGlobal(uint32_t global_index) {
- uint32_t max_global_index = global_index_mapping.size();
+Result BinaryReaderInterpreter::CheckGlobal(Index global_index) {
+ Index max_global_index = global_index_mapping.size();
if (global_index >= max_global_index) {
- PrintError("invalid global_index: %d (max %d)", global_index,
- max_global_index);
+ PrintError("invalid global_index: %" PRIindex " (max %" PRIindex ")",
+ global_index, max_global_index);
return Result::Error;
}
return Result::Ok;
@@ -670,7 +673,7 @@ Result BinaryReaderInterpreter::CheckImportLimits(const Limits* declared_limits,
Result BinaryReaderInterpreter::AppendExport(InterpreterModule* module,
ExternalKind kind,
- uint32_t item_index,
+ Index item_index,
StringSlice name) {
if (module->export_bindings.find_index(name) != -1) {
PrintError("duplicate export \"" PRIstringslice "\"",
@@ -699,15 +702,15 @@ PrintErrorCallback BinaryReaderInterpreter::MakePrintErrorCallback() {
return result;
}
-Result BinaryReaderInterpreter::OnImportFunc(uint32_t import_index,
+Result BinaryReaderInterpreter::OnImportFunc(Index import_index,
StringSlice module_name,
StringSlice field_name,
- uint32_t func_index,
- uint32_t sig_index) {
+ Index func_index,
+ Index sig_index) {
InterpreterImport* import = &module->imports[import_index];
import->func.sig_index = TranslateSigIndexToEnv(sig_index);
- uint32_t func_env_index;
+ Index func_env_index;
if (is_host_import) {
HostInterpreterFunc* func = new HostInterpreterFunc(
import->module_name, import->field_name, import->func.sig_index);
@@ -740,13 +743,13 @@ Result BinaryReaderInterpreter::OnImportFunc(uint32_t import_index,
return Result::Ok;
}
-Result BinaryReaderInterpreter::OnImportTable(uint32_t import_index,
+Result BinaryReaderInterpreter::OnImportTable(Index import_index,
StringSlice module_name,
StringSlice field_name,
- uint32_t table_index,
+ Index table_index,
Type elem_type,
const Limits* elem_limits) {
- if (module->table_index != WABT_INVALID_INDEX) {
+ if (module->table_index != kInvalidIndex) {
PrintError("only one table allowed");
return Result::Error;
}
@@ -778,12 +781,12 @@ Result BinaryReaderInterpreter::OnImportTable(uint32_t import_index,
return Result::Ok;
}
-Result BinaryReaderInterpreter::OnImportMemory(uint32_t import_index,
+Result BinaryReaderInterpreter::OnImportMemory(Index import_index,
StringSlice module_name,
StringSlice field_name,
- uint32_t memory_index,
+ Index memory_index,
const Limits* page_limits) {
- if (module->memory_index != WABT_INVALID_INDEX) {
+ if (module->memory_index != kInvalidIndex) {
PrintError("only one memory allowed");
return Result::Error;
}
@@ -815,15 +818,15 @@ Result BinaryReaderInterpreter::OnImportMemory(uint32_t import_index,
return Result::Ok;
}
-Result BinaryReaderInterpreter::OnImportGlobal(uint32_t import_index,
+Result BinaryReaderInterpreter::OnImportGlobal(Index import_index,
StringSlice module_name,
StringSlice field_name,
- uint32_t global_index,
+ Index global_index,
Type type,
bool mutable_) {
InterpreterImport* import = &module->imports[import_index];
- uint32_t global_env_index = env->globals.size() - 1;
+ Index global_env_index = env->globals.size() - 1;
if (is_host_import) {
env->globals.emplace_back(InterpreterTypedValue(type), mutable_);
InterpreterGlobal* global = &env->globals.back();
@@ -848,25 +851,25 @@ Result BinaryReaderInterpreter::OnImportGlobal(uint32_t import_index,
return Result::Ok;
}
-Result BinaryReaderInterpreter::OnFunctionCount(uint32_t count) {
- for (uint32_t i = 0; i < count; ++i)
+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;
}
-Result BinaryReaderInterpreter::OnFunction(uint32_t index, uint32_t sig_index) {
+Result BinaryReaderInterpreter::OnFunction(Index index, Index sig_index) {
DefinedInterpreterFunc* func =
new DefinedInterpreterFunc(TranslateSigIndexToEnv(sig_index));
env->funcs.emplace_back(func);
return Result::Ok;
}
-Result BinaryReaderInterpreter::OnTable(uint32_t index,
+Result BinaryReaderInterpreter::OnTable(Index index,
Type elem_type,
const Limits* elem_limits) {
- if (module->table_index != WABT_INVALID_INDEX) {
+ if (module->table_index != kInvalidIndex) {
PrintError("only one table allowed");
return Result::Error;
}
@@ -875,9 +878,9 @@ Result BinaryReaderInterpreter::OnTable(uint32_t index,
return Result::Ok;
}
-Result BinaryReaderInterpreter::OnMemory(uint32_t index,
+Result BinaryReaderInterpreter::OnMemory(Index index,
const Limits* page_limits) {
- if (module->memory_index != WABT_INVALID_INDEX) {
+ if (module->memory_index != kInvalidIndex) {
PrintError("only one memory allowed");
return Result::Error;
}
@@ -886,14 +889,14 @@ Result BinaryReaderInterpreter::OnMemory(uint32_t index,
return Result::Ok;
}
-Result BinaryReaderInterpreter::OnGlobalCount(uint32_t count) {
- for (uint32_t i = 0; i < count; ++i)
+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;
}
-Result BinaryReaderInterpreter::BeginGlobal(uint32_t index,
+Result BinaryReaderInterpreter::BeginGlobal(Index index,
Type type,
bool mutable_) {
InterpreterGlobal* global = GetGlobalByModuleIndex(index);
@@ -903,7 +906,7 @@ Result BinaryReaderInterpreter::BeginGlobal(uint32_t index,
return Result::Ok;
}
-Result BinaryReaderInterpreter::EndGlobalInitExpr(uint32_t index) {
+Result BinaryReaderInterpreter::EndGlobalInitExpr(Index index) {
InterpreterGlobal* global = GetGlobalByModuleIndex(index);
if (init_expr_value.type != global->typed_value.type) {
PrintError("type mismatch in global, expected %s but got %s.",
@@ -915,22 +918,22 @@ Result BinaryReaderInterpreter::EndGlobalInitExpr(uint32_t index) {
return Result::Ok;
}
-Result BinaryReaderInterpreter::OnInitExprF32ConstExpr(uint32_t index,
+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;
}
-Result BinaryReaderInterpreter::OnInitExprF64ConstExpr(uint32_t index,
+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;
}
-Result BinaryReaderInterpreter::OnInitExprGetGlobalExpr(uint32_t index,
- uint32_t global_index) {
+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;
@@ -944,23 +947,23 @@ Result BinaryReaderInterpreter::OnInitExprGetGlobalExpr(uint32_t index,
return Result::Ok;
}
-Result BinaryReaderInterpreter::OnInitExprI32ConstExpr(uint32_t index,
+Result BinaryReaderInterpreter::OnInitExprI32ConstExpr(Index index,
uint32_t value) {
init_expr_value.type = Type::I32;
init_expr_value.value.i32 = value;
return Result::Ok;
}
-Result BinaryReaderInterpreter::OnInitExprI64ConstExpr(uint32_t index,
+Result BinaryReaderInterpreter::OnInitExprI64ConstExpr(Index index,
uint64_t value) {
init_expr_value.type = Type::I64;
init_expr_value.value.i64 = value;
return Result::Ok;
}
-Result BinaryReaderInterpreter::OnExport(uint32_t index,
+Result BinaryReaderInterpreter::OnExport(Index index,
ExternalKind kind,
- uint32_t item_index,
+ Index item_index,
StringSlice name) {
switch (kind) {
case ExternalKind::Func:
@@ -988,8 +991,8 @@ Result BinaryReaderInterpreter::OnExport(uint32_t index,
return AppendExport(module, kind, item_index, name);
}
-Result BinaryReaderInterpreter::OnStartFunction(uint32_t func_index) {
- uint32_t start_func_index = TranslateFuncIndexToEnv(func_index);
+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);
if (sig->param_types.size() != 0) {
@@ -1004,7 +1007,7 @@ Result BinaryReaderInterpreter::OnStartFunction(uint32_t func_index) {
return Result::Ok;
}
-Result BinaryReaderInterpreter::EndElemSegmentInitExpr(uint32_t index) {
+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));
@@ -1014,11 +1017,9 @@ Result BinaryReaderInterpreter::EndElemSegmentInitExpr(uint32_t index) {
return Result::Ok;
}
-Result BinaryReaderInterpreter::OnElemSegmentFunctionIndex(
-
- uint32_t index,
- uint32_t func_index) {
- assert(module->table_index != WABT_INVALID_INDEX);
+Result BinaryReaderInterpreter::OnElemSegmentFunctionIndex(Index index,
+ Index func_index) {
+ assert(module->table_index != kInvalidIndex);
InterpreterTable* 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,
@@ -1026,9 +1027,10 @@ Result BinaryReaderInterpreter::OnElemSegmentFunctionIndex(
return Result::Error;
}
- uint32_t max_func_index = func_index_mapping.size();
+ Index max_func_index = func_index_mapping.size();
if (func_index >= max_func_index) {
- PrintError("invalid func_index: %d (max %d)", func_index, max_func_index);
+ PrintError("invalid func_index: %" PRIindex " (max %" PRIindex ")",
+ func_index, max_func_index);
return Result::Error;
}
@@ -1037,21 +1039,21 @@ Result BinaryReaderInterpreter::OnElemSegmentFunctionIndex(
return Result::Ok;
}
-Result BinaryReaderInterpreter::OnDataSegmentData(uint32_t index,
+Result BinaryReaderInterpreter::OnDataSegmentData(Index index,
const void* src_data,
- uint32_t size) {
- assert(module->memory_index != WABT_INVALID_INDEX);
+ Address size) {
+ assert(module->memory_index != kInvalidIndex);
InterpreterMemory* 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;
}
- uint32_t address = init_expr_value.value.i32;
+ Address address = init_expr_value.value.i32;
uint64_t end_address =
static_cast<uint64_t>(address) + static_cast<uint64_t>(size);
if (end_address > memory->data.size()) {
- PrintError("data segment is out of bounds: [%u, %" PRIu64
+ PrintError("data segment is out of bounds: [%" PRIaddress ", %" PRIu64
") >= max value %" PRIzd,
address, end_address, memory->data.size());
return Result::Error;
@@ -1063,8 +1065,8 @@ Result BinaryReaderInterpreter::OnDataSegmentData(uint32_t index,
return Result::Ok;
}
-void BinaryReaderInterpreter::PushLabel(uint32_t offset,
- uint32_t fixup_offset) {
+void BinaryReaderInterpreter::PushLabel(IstreamOffset offset,
+ IstreamOffset fixup_offset) {
label_stack.emplace_back(offset, fixup_offset);
}
@@ -1078,7 +1080,7 @@ void BinaryReaderInterpreter::PopLabel() {
}
}
-Result BinaryReaderInterpreter::BeginFunctionBody(uint32_t index) {
+Result BinaryReaderInterpreter::BeginFunctionBody(Index index) {
DefinedInterpreterFunc* func = GetFuncByModuleIndex(index)->as_defined();
InterpreterFuncSignature* sig = GetSignatureByEnvIndex(func->sig_index);
@@ -1091,9 +1093,9 @@ Result BinaryReaderInterpreter::BeginFunctionBody(uint32_t index) {
label_stack.clear();
/* fixup function references */
- uint32_t defined_index = TranslateModuleFuncIndexToDefined(index);
- Uint32Vector& fixups = func_fixups[defined_index];
- for (uint32_t fixup : fixups)
+ Index defined_index = TranslateModuleFuncIndexToDefined(index);
+ IstreamOffsetVector& fixups = func_fixups[defined_index];
+ for (IstreamOffset fixup : fixups)
CHECK_RESULT(EmitI32At(fixup, func->offset));
/* append param types */
@@ -1103,13 +1105,13 @@ Result BinaryReaderInterpreter::BeginFunctionBody(uint32_t index) {
CHECK_RESULT(typechecker_begin_function(&typechecker, &sig->result_types));
/* push implicit func label (equivalent to return) */
- PushLabel(WABT_INVALID_OFFSET, WABT_INVALID_OFFSET);
+ PushLabel(kInvalidIstreamOffset, kInvalidIstreamOffset);
return Result::Ok;
}
-Result BinaryReaderInterpreter::EndFunctionBody(uint32_t index) {
+Result BinaryReaderInterpreter::EndFunctionBody(Index index) {
FixupTopLabel();
- uint32_t drop_count, keep_count;
+ 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));
@@ -1119,17 +1121,17 @@ Result BinaryReaderInterpreter::EndFunctionBody(uint32_t index) {
return Result::Ok;
}
-Result BinaryReaderInterpreter::OnLocalDeclCount(uint32_t count) {
+Result BinaryReaderInterpreter::OnLocalDeclCount(Index count) {
current_func->local_decl_count = count;
return Result::Ok;
}
-Result BinaryReaderInterpreter::OnLocalDecl(uint32_t decl_index,
- uint32_t count,
+Result BinaryReaderInterpreter::OnLocalDecl(Index decl_index,
+ Index count,
Type type) {
current_func->local_count += count;
- for (uint32_t i = 0; i < count; ++i)
+ for (Index i = 0; i < count; ++i)
current_func->param_and_local_types.push_back(type);
if (decl_index == current_func->local_decl_count - 1) {
@@ -1141,7 +1143,7 @@ Result BinaryReaderInterpreter::OnLocalDecl(uint32_t decl_index,
}
Result BinaryReaderInterpreter::CheckHasMemory(Opcode opcode) {
- if (module->memory_index == WABT_INVALID_INDEX) {
+ if (module->memory_index == kInvalidIndex) {
PrintError("%s requires an imported or defined memory.",
get_opcode_name(opcode));
return Result::Error;
@@ -1150,7 +1152,7 @@ Result BinaryReaderInterpreter::CheckHasMemory(Opcode opcode) {
}
Result BinaryReaderInterpreter::CheckAlign(uint32_t alignment_log2,
- uint32_t natural_alignment) {
+ Address natural_alignment) {
if (alignment_log2 >= 32 || (1U << alignment_log2) > natural_alignment) {
PrintError("alignment must not be larger than natural alignment (%u)",
natural_alignment);
@@ -1171,39 +1173,37 @@ Result BinaryReaderInterpreter::OnBinaryExpr(Opcode opcode) {
return Result::Ok;
}
-Result BinaryReaderInterpreter::OnBlockExpr(uint32_t num_types,
- Type* sig_types) {
+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(WABT_INVALID_OFFSET, WABT_INVALID_OFFSET);
+ PushLabel(kInvalidIstreamOffset, kInvalidIstreamOffset);
return Result::Ok;
}
-Result BinaryReaderInterpreter::OnLoopExpr(uint32_t num_types,
- Type* sig_types) {
+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(), WABT_INVALID_OFFSET);
+ PushLabel(GetIstreamOffset(), kInvalidIstreamOffset);
return Result::Ok;
}
-Result BinaryReaderInterpreter::OnIfExpr(uint32_t num_types, Type* sig_types) {
+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));
- uint32_t fixup_offset = GetIstreamOffset();
- CHECK_RESULT(EmitI32(WABT_INVALID_OFFSET));
- PushLabel(WABT_INVALID_OFFSET, fixup_offset);
+ IstreamOffset fixup_offset = GetIstreamOffset();
+ CHECK_RESULT(EmitI32(kInvalidIstreamOffset));
+ PushLabel(kInvalidIstreamOffset, fixup_offset);
return Result::Ok;
}
Result BinaryReaderInterpreter::OnElseExpr() {
CHECK_RESULT(typechecker_on_else(&typechecker));
Label* label = TopLabel();
- uint32_t fixup_cond_offset = label->fixup_offset;
+ IstreamOffset fixup_cond_offset = label->fixup_offset;
CHECK_RESULT(EmitOpcode(InterpreterOpcode::Br));
label->fixup_offset = GetIstreamOffset();
- CHECK_RESULT(EmitI32(WABT_INVALID_OFFSET));
+ CHECK_RESULT(EmitI32(kInvalidIstreamOffset));
CHECK_RESULT(EmitI32At(fixup_cond_offset, GetIstreamOffset()));
return Result::Ok;
}
@@ -1221,43 +1221,43 @@ Result BinaryReaderInterpreter::OnEndExpr() {
return Result::Ok;
}
-Result BinaryReaderInterpreter::OnBrExpr(uint32_t depth) {
- uint32_t drop_count, keep_count;
+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;
}
-Result BinaryReaderInterpreter::OnBrIfExpr(uint32_t depth) {
- uint32_t drop_count, keep_count;
+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));
- uint32_t fixup_br_offset = GetIstreamOffset();
- CHECK_RESULT(EmitI32(WABT_INVALID_OFFSET));
+ 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;
}
-Result BinaryReaderInterpreter::OnBrTableExpr(uint32_t num_targets,
- uint32_t* target_depths,
- uint32_t default_target_depth) {
+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(EmitI32(num_targets));
- uint32_t fixup_table_offset = GetIstreamOffset();
- CHECK_RESULT(EmitI32(WABT_INVALID_OFFSET));
+ 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(EmitI32((num_targets + 1) * WABT_TABLE_ENTRY_SIZE));
CHECK_RESULT(EmitI32At(fixup_table_offset, GetIstreamOffset()));
- for (uint32_t i = 0; i <= num_targets; ++i) {
- uint32_t depth = i != num_targets ? target_depths[i] : default_target_depth;
+ for (Index i = 0; i <= num_targets; ++i) {
+ Index depth = i != num_targets ? target_depths[i] : default_target_depth;
CHECK_RESULT(typechecker_on_br_table_target(&typechecker, depth));
CHECK_RESULT(EmitBrTableOffset(depth));
}
@@ -1266,7 +1266,7 @@ Result BinaryReaderInterpreter::OnBrTableExpr(uint32_t num_targets,
return Result::Ok;
}
-Result BinaryReaderInterpreter::OnCallExpr(uint32_t func_index) {
+Result BinaryReaderInterpreter::OnCallExpr(Index func_index) {
InterpreterFunc* func = GetFuncByModuleIndex(func_index);
InterpreterFuncSignature* sig = GetSignatureByEnvIndex(func->sig_index);
CHECK_RESULT(
@@ -1283,8 +1283,8 @@ Result BinaryReaderInterpreter::OnCallExpr(uint32_t func_index) {
return Result::Ok;
}
-Result BinaryReaderInterpreter::OnCallIndirectExpr(uint32_t sig_index) {
- if (module->table_index == WABT_INVALID_INDEX) {
+Result BinaryReaderInterpreter::OnCallIndirectExpr(Index sig_index) {
+ if (module->table_index == kInvalidIndex) {
PrintError("found call_indirect operator, but no table");
return Result::Error;
}
@@ -1340,7 +1340,7 @@ Result BinaryReaderInterpreter::OnF64ConstExpr(uint64_t value_bits) {
return Result::Ok;
}
-Result BinaryReaderInterpreter::OnGetGlobalExpr(uint32_t global_index) {
+Result BinaryReaderInterpreter::OnGetGlobalExpr(Index global_index) {
CHECK_RESULT(CheckGlobal(global_index));
Type type = GetGlobalTypeByModuleIndex(global_index);
CHECK_RESULT(typechecker_on_get_global(&typechecker, type));
@@ -1349,11 +1349,11 @@ Result BinaryReaderInterpreter::OnGetGlobalExpr(uint32_t global_index) {
return Result::Ok;
}
-Result BinaryReaderInterpreter::OnSetGlobalExpr(uint32_t global_index) {
+Result BinaryReaderInterpreter::OnSetGlobalExpr(Index global_index) {
CHECK_RESULT(CheckGlobal(global_index));
InterpreterGlobal* global = GetGlobalByModuleIndex(global_index);
if (!global->mutable_) {
- PrintError("can't set_global on immutable global at index %u.",
+ PrintError("can't set_global on immutable global at index %" PRIindex ".",
global_index);
return Result::Error;
}
@@ -1364,25 +1364,25 @@ Result BinaryReaderInterpreter::OnSetGlobalExpr(uint32_t global_index) {
return Result::Ok;
}
-uint32_t BinaryReaderInterpreter::TranslateLocalIndex(uint32_t local_index) {
+Index BinaryReaderInterpreter::TranslateLocalIndex(Index local_index) {
return typechecker.type_stack.size() +
current_func->param_and_local_types.size() - local_index;
}
-Result BinaryReaderInterpreter::OnGetLocalExpr(uint32_t local_index) {
+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
* because it will update the type stack size. We need the index to be
* relative to the old stack size. */
- uint32_t translated_local_index = TranslateLocalIndex(local_index);
+ Index translated_local_index = TranslateLocalIndex(local_index);
CHECK_RESULT(typechecker_on_get_local(&typechecker, type));
CHECK_RESULT(EmitOpcode(InterpreterOpcode::GetLocal));
CHECK_RESULT(EmitI32(translated_local_index));
return Result::Ok;
}
-Result BinaryReaderInterpreter::OnSetLocalExpr(uint32_t local_index) {
+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));
@@ -1391,7 +1391,7 @@ Result BinaryReaderInterpreter::OnSetLocalExpr(uint32_t local_index) {
return Result::Ok;
}
-Result BinaryReaderInterpreter::OnTeeLocalExpr(uint32_t local_index) {
+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));
@@ -1410,7 +1410,7 @@ Result BinaryReaderInterpreter::OnGrowMemoryExpr() {
Result BinaryReaderInterpreter::OnLoadExpr(Opcode opcode,
uint32_t alignment_log2,
- uint32_t offset) {
+ Address offset) {
CHECK_RESULT(CheckHasMemory(opcode));
CHECK_RESULT(CheckAlign(alignment_log2, get_opcode_memory_size(opcode)));
CHECK_RESULT(typechecker_on_load(&typechecker, opcode));
@@ -1422,7 +1422,7 @@ Result BinaryReaderInterpreter::OnLoadExpr(Opcode opcode,
Result BinaryReaderInterpreter::OnStoreExpr(Opcode opcode,
uint32_t alignment_log2,
- uint32_t offset) {
+ Address offset) {
CHECK_RESULT(CheckHasMemory(opcode));
CHECK_RESULT(CheckAlign(alignment_log2, get_opcode_memory_size(opcode)));
CHECK_RESULT(typechecker_on_store(&typechecker, opcode));
@@ -1445,7 +1445,7 @@ Result BinaryReaderInterpreter::OnNopExpr() {
}
Result BinaryReaderInterpreter::OnReturnExpr() {
- uint32_t drop_count, keep_count;
+ 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));
@@ -1483,7 +1483,7 @@ Result read_binary_interpreter(InterpreterEnvironment* env,
const ReadBinaryOptions* options,
BinaryErrorHandler* error_handler,
DefinedInterpreterModule** out_module) {
- size_t istream_offset = env->istream->data.size();
+ IstreamOffset istream_offset = env->istream->data.size();
DefinedInterpreterModule* module =
new DefinedInterpreterModule(istream_offset);