summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/binary-reader-interpreter.cc420
-rw-r--r--src/binary-reader-ir.cc164
-rw-r--r--src/binary-reader-logging.cc150
-rw-r--r--src/binary-reader-logging.h6
-rw-r--r--src/binary-reader-objdump.cc151
-rw-r--r--src/wat-writer.cc2
6 files changed, 445 insertions, 448 deletions
diff --git a/src/binary-reader-interpreter.cc b/src/binary-reader-interpreter.cc
index 8cf4effa..6c9f5a52 100644
--- a/src/binary-reader-interpreter.cc
+++ b/src/binary-reader-interpreter.cc
@@ -257,34 +257,34 @@ class BinaryReaderInterpreter : public BinaryReaderNop {
HostImportDelegate::ErrorCallback MakePrintErrorCallback();
- ErrorHandler* error_handler = nullptr;
- Environment* env = nullptr;
- DefinedModule* module = nullptr;
- DefinedFunc* current_func = nullptr;
- TypeChecker typechecker;
- std::vector<Label> label_stack;
- IstreamOffsetVectorVector func_fixups;
- IstreamOffsetVectorVector depth_fixups;
+ ErrorHandler* error_handler_ = nullptr;
+ Environment* env_ = nullptr;
+ DefinedModule* module_ = nullptr;
+ DefinedFunc* current_func_ = nullptr;
+ TypeChecker typechecker_;
+ std::vector<Label> label_stack_;
+ IstreamOffsetVectorVector func_fixups_;
+ IstreamOffsetVectorVector depth_fixups_;
MemoryStream istream_;
- IstreamOffset 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 */
- IndexVector sig_index_mapping;
- IndexVector func_index_mapping;
- IndexVector global_index_mapping;
+ IndexVector sig_index_mapping_;
+ IndexVector func_index_mapping_;
+ IndexVector global_index_mapping_;
- Index num_func_imports = 0;
- Index 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
// that there are no validation errors.
- std::vector<ElemSegmentInfo> elem_segment_infos;
- std::vector<DataSegmentInfo> data_segment_infos;
+ std::vector<ElemSegmentInfo> elem_segment_infos_;
+ std::vector<DataSegmentInfo> data_segment_infos_;
// Values cached so they can be shared between callbacks.
- TypedValue init_expr_value;
- IstreamOffset table_offset = 0;
+ TypedValue init_expr_value_;
+ IstreamOffset table_offset_ = 0;
};
BinaryReaderInterpreter::BinaryReaderInterpreter(
@@ -292,12 +292,12 @@ BinaryReaderInterpreter::BinaryReaderInterpreter(
DefinedModule* module,
std::unique_ptr<OutputBuffer> istream,
ErrorHandler* error_handler)
- : error_handler(error_handler),
- env(env),
- module(module),
+ : error_handler_(error_handler),
+ env_(env),
+ module_(module),
istream_(std::move(istream)),
- istream_offset(istream_.output_buffer().size()) {
- typechecker.set_error_callback(
+ istream_offset_(istream_.output_buffer().size()) {
+ typechecker_.set_error_callback(
[this](const char* msg) { PrintError("%s", msg); });
}
@@ -306,8 +306,8 @@ std::unique_ptr<OutputBuffer> BinaryReaderInterpreter::ReleaseOutputBuffer() {
}
Label* BinaryReaderInterpreter::GetLabel(Index depth) {
- assert(depth < label_stack.size());
- return &label_stack[label_stack.size() - depth - 1];
+ assert(depth < label_stack_.size());
+ return &label_stack_[label_stack_.size() - depth - 1];
}
Label* BinaryReaderInterpreter::TopLabel() {
@@ -315,7 +315,7 @@ Label* BinaryReaderInterpreter::TopLabel() {
}
bool BinaryReaderInterpreter::HandleError(Offset offset, const char* message) {
- return error_handler->OnError(offset, message);
+ return error_handler_->OnError(offset, message);
}
void WABT_PRINTF_FORMAT(2, 3)
@@ -325,36 +325,36 @@ void WABT_PRINTF_FORMAT(2, 3)
}
Index BinaryReaderInterpreter::TranslateSigIndexToEnv(Index sig_index) {
- assert(sig_index < sig_index_mapping.size());
- return sig_index_mapping[sig_index];
+ assert(sig_index < sig_index_mapping_.size());
+ return sig_index_mapping_[sig_index];
}
FuncSignature* BinaryReaderInterpreter::GetSignatureByModuleIndex(
Index sig_index) {
- return env->GetFuncSignature(TranslateSigIndexToEnv(sig_index));
+ return env_->GetFuncSignature(TranslateSigIndexToEnv(sig_index));
}
Index BinaryReaderInterpreter::TranslateFuncIndexToEnv(Index func_index) {
- assert(func_index < func_index_mapping.size());
- return func_index_mapping[func_index];
+ assert(func_index < func_index_mapping_.size());
+ return func_index_mapping_[func_index];
}
Index BinaryReaderInterpreter::TranslateModuleFuncIndexToDefined(
Index func_index) {
- assert(func_index >= num_func_imports);
- return func_index - num_func_imports;
+ assert(func_index >= num_func_imports_);
+ return func_index - num_func_imports_;
}
Func* BinaryReaderInterpreter::GetFuncByModuleIndex(Index func_index) {
- return env->GetFunc(TranslateFuncIndexToEnv(func_index));
+ return env_->GetFunc(TranslateFuncIndexToEnv(func_index));
}
Index BinaryReaderInterpreter::TranslateGlobalIndexToEnv(Index global_index) {
- return global_index_mapping[global_index];
+ return global_index_mapping_[global_index];
}
Global* BinaryReaderInterpreter::GetGlobalByModuleIndex(Index global_index) {
- return env->GetGlobal(TranslateGlobalIndexToEnv(global_index));
+ return env_->GetGlobal(TranslateGlobalIndexToEnv(global_index));
}
Type BinaryReaderInterpreter::GetGlobalTypeByModuleIndex(Index global_index) {
@@ -368,7 +368,7 @@ Type BinaryReaderInterpreter::GetLocalTypeByIndex(Func* func,
}
IstreamOffset BinaryReaderInterpreter::GetIstreamOffset() {
- return istream_offset;
+ return istream_offset_;
}
wabt::Result BinaryReaderInterpreter::EmitDataAt(IstreamOffset offset,
@@ -380,8 +380,8 @@ wabt::Result BinaryReaderInterpreter::EmitDataAt(IstreamOffset offset,
wabt::Result BinaryReaderInterpreter::EmitData(const void* data,
IstreamOffset size) {
- CHECK_RESULT(EmitDataAt(istream_offset, data, size));
- istream_offset += size;
+ CHECK_RESULT(EmitDataAt(istream_offset_, data, size));
+ istream_offset_ += size;
return wabt::Result::Ok;
}
@@ -438,10 +438,10 @@ wabt::Result BinaryReaderInterpreter::AppendFixup(
wabt::Result BinaryReaderInterpreter::EmitBrOffset(Index depth,
IstreamOffset offset) {
if (offset == kInvalidIstreamOffset) {
- /* depth_fixups stores the depth counting up from zero, where zero is the
+ /* depth_fixups_ stores the depth counting up from zero, where zero is the
* top-level function scope. */
- depth = label_stack.size() - 1 - depth;
- CHECK_RESULT(AppendFixup(&depth_fixups, depth));
+ depth = label_stack_.size() - 1 - depth;
+ CHECK_RESULT(AppendFixup(&depth_fixups_, depth));
}
CHECK_RESULT(EmitI32(offset));
return wabt::Result::Ok;
@@ -452,14 +452,14 @@ wabt::Result BinaryReaderInterpreter::GetBrDropKeepCount(
Index* out_drop_count,
Index* out_keep_count) {
TypeChecker::Label* label;
- CHECK_RESULT(typechecker.GetLabel(depth, &label));
+ CHECK_RESULT(typechecker_.GetLabel(depth, &label));
*out_keep_count =
label->label_type != LabelType::Loop ? label->sig.size() : 0;
- if (typechecker.IsUnreachable()) {
+ if (typechecker_.IsUnreachable()) {
*out_drop_count = 0;
} else {
*out_drop_count =
- (typechecker.type_stack_size() - label->type_stack_limit) -
+ (typechecker_.type_stack_size() - label->type_stack_limit) -
*out_keep_count;
}
return wabt::Result::Ok;
@@ -468,9 +468,9 @@ wabt::Result BinaryReaderInterpreter::GetBrDropKeepCount(
wabt::Result BinaryReaderInterpreter::GetReturnDropKeepCount(
Index* out_drop_count,
Index* out_keep_count) {
- CHECK_RESULT(GetBrDropKeepCount(label_stack.size() - 1, out_drop_count,
+ CHECK_RESULT(GetBrDropKeepCount(label_stack_.size() - 1, out_drop_count,
out_keep_count));
- *out_drop_count += current_func->param_and_local_types.size();
+ *out_drop_count += current_func_->param_and_local_types.size();
return wabt::Result::Ok;
}
@@ -494,13 +494,13 @@ wabt::Result BinaryReaderInterpreter::EmitBrTableOffset(Index depth) {
wabt::Result BinaryReaderInterpreter::FixupTopLabel() {
IstreamOffset offset = GetIstreamOffset();
- Index top = label_stack.size() - 1;
- if (top >= depth_fixups.size()) {
+ Index top = label_stack_.size() - 1;
+ if (top >= depth_fixups_.size()) {
/* nothing to fixup */
return wabt::Result::Ok;
}
- IstreamOffsetVector& fixups = depth_fixups[top];
+ IstreamOffsetVector& fixups = depth_fixups_[top];
for (IstreamOffset fixup : fixups)
CHECK_RESULT(EmitI32At(fixup, offset));
fixups.clear();
@@ -511,7 +511,7 @@ 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(AppendFixup(&func_fixups_, defined_index));
}
CHECK_RESULT(EmitI32(func->offset));
return wabt::Result::Ok;
@@ -522,10 +522,10 @@ bool BinaryReaderInterpreter::OnError(const char* message) {
}
wabt::Result BinaryReaderInterpreter::OnTypeCount(Index count) {
- Index sig_count = env->GetFuncSignatureCount();
- sig_index_mapping.resize(count);
+ Index sig_count = env_->GetFuncSignatureCount();
+ sig_index_mapping_.resize(count);
for (Index i = 0; i < count; ++i)
- sig_index_mapping[i] = sig_count + i;
+ sig_index_mapping_[i] = sig_count + i;
return wabt::Result::Ok;
}
@@ -534,14 +534,14 @@ wabt::Result BinaryReaderInterpreter::OnType(Index index,
Type* param_types,
Index result_count,
Type* result_types) {
- assert(TranslateSigIndexToEnv(index) == env->GetFuncSignatureCount());
- env->EmplaceBackFuncSignature(param_count, param_types, result_count,
- result_types);
+ assert(TranslateSigIndexToEnv(index) == env_->GetFuncSignatureCount());
+ env_->EmplaceBackFuncSignature(param_count, param_types, result_count,
+ result_types);
return wabt::Result::Ok;
}
wabt::Result BinaryReaderInterpreter::CheckLocal(Index local_index) {
- Index max_local_index = current_func->param_and_local_types.size();
+ 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);
@@ -551,7 +551,7 @@ wabt::Result BinaryReaderInterpreter::CheckLocal(Index local_index) {
}
wabt::Result BinaryReaderInterpreter::CheckGlobal(Index global_index) {
- Index max_global_index = global_index_mapping.size();
+ 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);
@@ -619,7 +619,7 @@ wabt::Result BinaryReaderInterpreter::AppendExport(Module* module,
wabt::Result BinaryReaderInterpreter::FindRegisteredModule(
string_view module_name,
Module** out_module) {
- Module* module = env->FindRegisteredModule(module_name);
+ Module* module = env_->FindRegisteredModule(module_name);
if (!module) {
PrintError("unknown import module \"" PRIstringview "\"",
WABT_PRINTF_STRING_VIEW_ARG(module_name));
@@ -654,8 +654,8 @@ wabt::Result BinaryReaderInterpreter::OnImportFunc(Index import_index,
string_view field_name,
Index func_index,
Index sig_index) {
- module->func_imports.emplace_back(module_name, field_name);
- FuncImport* import = &module->func_imports.back();
+ module_->func_imports.emplace_back(module_name, field_name);
+ FuncImport* import = &module_->func_imports.back();
import->sig_index = TranslateSigIndexToEnv(sig_index);
Module* import_module;
@@ -665,14 +665,14 @@ wabt::Result BinaryReaderInterpreter::OnImportFunc(Index import_index,
if (auto* host_import_module = dyn_cast<HostModule>(import_module)) {
HostFunc* func = new HostFunc(import->module_name, import->field_name,
import->sig_index);
- env->EmplaceBackFunc(func);
+ env_->EmplaceBackFunc(func);
- FuncSignature* sig = env->GetFuncSignature(func->sig_index);
+ FuncSignature* sig = env_->GetFuncSignature(func->sig_index);
CHECK_RESULT(host_import_module->import_delegate->ImportFunc(
import, func, sig, MakePrintErrorCallback()));
assert(func->callback);
- func_env_index = env->GetFuncCount() - 1;
+ func_env_index = env_->GetFuncCount() - 1;
AppendExport(host_import_module, ExternalKind::Func, func_env_index,
import->field_name);
} else {
@@ -680,16 +680,16 @@ wabt::Result BinaryReaderInterpreter::OnImportFunc(Index import_index,
CHECK_RESULT(GetModuleExport(import_module, import->field_name, &export_));
CHECK_RESULT(CheckImportKind(import, export_->kind));
- Func* func = env->GetFunc(export_->index);
- if (!env->FuncSignaturesAreEqual(import->sig_index, func->sig_index)) {
+ Func* func = env_->GetFunc(export_->index);
+ if (!env_->FuncSignaturesAreEqual(import->sig_index, func->sig_index)) {
PrintError("import signature mismatch");
return wabt::Result::Error;
}
func_env_index = export_->index;
}
- func_index_mapping.push_back(func_env_index);
- num_func_imports++;
+ func_index_mapping_.push_back(func_env_index);
+ num_func_imports_++;
return wabt::Result::Ok;
}
@@ -699,38 +699,38 @@ wabt::Result BinaryReaderInterpreter::OnImportTable(Index import_index,
Index table_index,
Type elem_type,
const Limits* elem_limits) {
- if (module->table_index != kInvalidIndex) {
+ if (module_->table_index != kInvalidIndex) {
PrintError("only one table allowed");
return wabt::Result::Error;
}
- module->table_imports.emplace_back(module_name, field_name);
- TableImport* import = &module->table_imports.back();
+ module_->table_imports.emplace_back(module_name, field_name);
+ TableImport* import = &module_->table_imports.back();
Module* import_module;
CHECK_RESULT(FindRegisteredModule(import->module_name, &import_module));
if (auto* host_import_module = dyn_cast<HostModule>(import_module)) {
- Table* table = env->EmplaceBackTable(*elem_limits);
+ Table* table = env_->EmplaceBackTable(*elem_limits);
CHECK_RESULT(host_import_module->import_delegate->ImportTable(
import, table, MakePrintErrorCallback()));
CHECK_RESULT(CheckImportLimits(elem_limits, &table->limits));
- module->table_index = env->GetTableCount() - 1;
- AppendExport(host_import_module, ExternalKind::Table, module->table_index,
+ module_->table_index = env_->GetTableCount() - 1;
+ AppendExport(host_import_module, ExternalKind::Table, module_->table_index,
import->field_name);
} else {
Export* export_;
CHECK_RESULT(GetModuleExport(import_module, import->field_name, &export_));
CHECK_RESULT(CheckImportKind(import, export_->kind));
- Table* table = env->GetTable(export_->index);
+ Table* table = env_->GetTable(export_->index);
CHECK_RESULT(CheckImportLimits(elem_limits, &table->limits));
import->limits = *elem_limits;
- module->table_index = export_->index;
+ module_->table_index = export_->index;
}
return wabt::Result::Ok;
}
@@ -741,38 +741,38 @@ wabt::Result BinaryReaderInterpreter::OnImportMemory(
string_view field_name,
Index memory_index,
const Limits* page_limits) {
- if (module->memory_index != kInvalidIndex) {
+ if (module_->memory_index != kInvalidIndex) {
PrintError("only one memory allowed");
return wabt::Result::Error;
}
- module->memory_imports.emplace_back(module_name, field_name);
- MemoryImport* import = &module->memory_imports.back();
+ module_->memory_imports.emplace_back(module_name, field_name);
+ MemoryImport* import = &module_->memory_imports.back();
Module* import_module;
CHECK_RESULT(FindRegisteredModule(import->module_name, &import_module));
if (auto* host_import_module = dyn_cast<HostModule>(import_module)) {
- Memory* memory = env->EmplaceBackMemory();
+ Memory* memory = env_->EmplaceBackMemory();
CHECK_RESULT(host_import_module->import_delegate->ImportMemory(
import, memory, MakePrintErrorCallback()));
CHECK_RESULT(CheckImportLimits(page_limits, &memory->page_limits));
- module->memory_index = env->GetMemoryCount() - 1;
- AppendExport(host_import_module, ExternalKind::Memory, module->memory_index,
- import->field_name);
+ module_->memory_index = env_->GetMemoryCount() - 1;
+ AppendExport(host_import_module, ExternalKind::Memory,
+ module_->memory_index, import->field_name);
} else {
Export* export_;
CHECK_RESULT(GetModuleExport(import_module, import->field_name, &export_));
CHECK_RESULT(CheckImportKind(import, export_->kind));
- Memory* memory = env->GetMemory(export_->index);
+ Memory* memory = env_->GetMemory(export_->index);
CHECK_RESULT(CheckImportLimits(page_limits, &memory->page_limits));
import->limits = *page_limits;
- module->memory_index = export_->index;
+ module_->memory_index = export_->index;
}
return wabt::Result::Ok;
}
@@ -783,20 +783,20 @@ wabt::Result BinaryReaderInterpreter::OnImportGlobal(Index import_index,
Index global_index,
Type type,
bool mutable_) {
- module->global_imports.emplace_back(module_name, field_name);
- GlobalImport* import = &module->global_imports.back();
+ module_->global_imports.emplace_back(module_name, field_name);
+ GlobalImport* import = &module_->global_imports.back();
Module* import_module;
CHECK_RESULT(FindRegisteredModule(import->module_name, &import_module));
- Index global_env_index = env->GetGlobalCount() - 1;
+ Index global_env_index = env_->GetGlobalCount() - 1;
if (auto* host_import_module = dyn_cast<HostModule>(import_module)) {
- Global* global = env->EmplaceBackGlobal(TypedValue(type), mutable_);
+ Global* global = env_->EmplaceBackGlobal(TypedValue(type), mutable_);
CHECK_RESULT(host_import_module->import_delegate->ImportGlobal(
import, global, MakePrintErrorCallback()));
- global_env_index = env->GetGlobalCount() - 1;
+ global_env_index = env_->GetGlobalCount() - 1;
AppendExport(host_import_module, ExternalKind::Global, global_env_index,
import->field_name);
} else {
@@ -809,93 +809,93 @@ wabt::Result BinaryReaderInterpreter::OnImportGlobal(Index import_index,
import->mutable_ = mutable_;
global_env_index = export_->index;
}
- global_index_mapping.push_back(global_env_index);
- num_global_imports++;
+ global_index_mapping_.push_back(global_env_index);
+ num_global_imports_++;
return wabt::Result::Ok;
}
wabt::Result BinaryReaderInterpreter::OnFunctionCount(Index count) {
for (Index i = 0; i < count; ++i)
- func_index_mapping.push_back(env->GetFuncCount() + i);
- func_fixups.resize(count);
+ func_index_mapping_.push_back(env_->GetFuncCount() + i);
+ func_fixups_.resize(count);
return wabt::Result::Ok;
}
wabt::Result BinaryReaderInterpreter::OnFunction(Index index, Index sig_index) {
- env->EmplaceBackFunc(new DefinedFunc(TranslateSigIndexToEnv(sig_index)));
+ env_->EmplaceBackFunc(new DefinedFunc(TranslateSigIndexToEnv(sig_index)));
return wabt::Result::Ok;
}
wabt::Result BinaryReaderInterpreter::OnTable(Index index,
Type elem_type,
const Limits* elem_limits) {
- if (module->table_index != kInvalidIndex) {
+ if (module_->table_index != kInvalidIndex) {
PrintError("only one table allowed");
return wabt::Result::Error;
}
- env->EmplaceBackTable(*elem_limits);
- module->table_index = env->GetTableCount() - 1;
+ env_->EmplaceBackTable(*elem_limits);
+ module_->table_index = env_->GetTableCount() - 1;
return wabt::Result::Ok;
}
wabt::Result BinaryReaderInterpreter::OnMemory(Index index,
const Limits* page_limits) {
- if (module->memory_index != kInvalidIndex) {
+ if (module_->memory_index != kInvalidIndex) {
PrintError("only one memory allowed");
return wabt::Result::Error;
}
- env->EmplaceBackMemory(*page_limits);
- module->memory_index = env->GetMemoryCount() - 1;
+ env_->EmplaceBackMemory(*page_limits);
+ module_->memory_index = env_->GetMemoryCount() - 1;
return wabt::Result::Ok;
}
wabt::Result BinaryReaderInterpreter::OnGlobalCount(Index count) {
for (Index i = 0; i < count; ++i)
- global_index_mapping.push_back(env->GetGlobalCount() + i);
+ global_index_mapping_.push_back(env_->GetGlobalCount() + i);
return wabt::Result::Ok;
}
wabt::Result BinaryReaderInterpreter::BeginGlobal(Index index,
Type type,
bool mutable_) {
- assert(TranslateGlobalIndexToEnv(index) == env->GetGlobalCount());
- env->EmplaceBackGlobal(TypedValue(type), mutable_);
- init_expr_value.type = Type::Void;
+ assert(TranslateGlobalIndexToEnv(index) == env_->GetGlobalCount());
+ env_->EmplaceBackGlobal(TypedValue(type), mutable_);
+ init_expr_value_.type = Type::Void;
return wabt::Result::Ok;
}
wabt::Result BinaryReaderInterpreter::EndGlobalInitExpr(Index index) {
Global* global = GetGlobalByModuleIndex(index);
- if (init_expr_value.type != global->typed_value.type) {
+ if (init_expr_value_.type != global->typed_value.type) {
PrintError("type mismatch in global, expected %s but got %s.",
GetTypeName(global->typed_value.type),
- GetTypeName(init_expr_value.type));
+ GetTypeName(init_expr_value_.type));
return wabt::Result::Error;
}
- global->typed_value = init_expr_value;
+ global->typed_value = init_expr_value_;
return wabt::Result::Ok;
}
wabt::Result BinaryReaderInterpreter::OnInitExprF32ConstExpr(
Index index,
uint32_t value_bits) {
- init_expr_value.type = Type::F32;
- init_expr_value.value.f32_bits = value_bits;
+ init_expr_value_.type = Type::F32;
+ init_expr_value_.value.f32_bits = value_bits;
return wabt::Result::Ok;
}
wabt::Result BinaryReaderInterpreter::OnInitExprF64ConstExpr(
Index index,
uint64_t value_bits) {
- init_expr_value.type = Type::F64;
- init_expr_value.value.f64_bits = value_bits;
+ init_expr_value_.type = Type::F64;
+ init_expr_value_.value.f64_bits = value_bits;
return wabt::Result::Ok;
}
wabt::Result BinaryReaderInterpreter::OnInitExprGetGlobalExpr(
Index index,
Index global_index) {
- if (global_index >= num_global_imports) {
+ if (global_index >= num_global_imports_) {
PrintError("initializer expression can only reference an imported global");
return wabt::Result::Error;
}
@@ -904,21 +904,21 @@ wabt::Result BinaryReaderInterpreter::OnInitExprGetGlobalExpr(
PrintError("initializer expression cannot reference a mutable global");
return wabt::Result::Error;
}
- init_expr_value = ref_global->typed_value;
+ init_expr_value_ = ref_global->typed_value;
return wabt::Result::Ok;
}
wabt::Result BinaryReaderInterpreter::OnInitExprI32ConstExpr(Index index,
uint32_t value) {
- init_expr_value.type = Type::I32;
- init_expr_value.value.i32 = value;
+ init_expr_value_.type = Type::I32;
+ init_expr_value_.value.i32 = value;
return wabt::Result::Ok;
}
wabt::Result BinaryReaderInterpreter::OnInitExprI64ConstExpr(Index index,
uint64_t value) {
- init_expr_value.type = Type::I64;
- init_expr_value.value.i64 = value;
+ init_expr_value_.type = Type::I64;
+ init_expr_value_.value.i64 = value;
return wabt::Result::Ok;
}
@@ -932,16 +932,16 @@ wabt::Result BinaryReaderInterpreter::OnExport(Index index,
break;
case ExternalKind::Table:
- item_index = module->table_index;
+ item_index = module_->table_index;
break;
case ExternalKind::Memory:
- item_index = module->memory_index;
+ item_index = module_->memory_index;
break;
case ExternalKind::Global: {
item_index = TranslateGlobalIndexToEnv(item_index);
- Global* global = env->GetGlobal(item_index);
+ Global* global = env_->GetGlobal(item_index);
if (global->mutable_) {
PrintError("mutable globals cannot be exported");
return wabt::Result::Error;
@@ -954,13 +954,13 @@ wabt::Result BinaryReaderInterpreter::OnExport(Index index,
WABT_FATAL("BinaryReaderInterpreter::OnExport(except) not implemented");
break;
}
- return AppendExport(module, kind, item_index, name);
+ return AppendExport(module_, kind, item_index, name);
}
wabt::Result BinaryReaderInterpreter::OnStartFunction(Index func_index) {
Index start_func_index = TranslateFuncIndexToEnv(func_index);
- Func* start_func = env->GetFunc(start_func_index);
- FuncSignature* sig = env->GetFuncSignature(start_func->sig_index);
+ Func* start_func = env_->GetFunc(start_func_index);
+ FuncSignature* sig = env_->GetFuncSignature(start_func->sig_index);
if (sig->param_types.size() != 0) {
PrintError("start function must be nullary");
return wabt::Result::Error;
@@ -969,46 +969,46 @@ wabt::Result BinaryReaderInterpreter::OnStartFunction(Index func_index) {
PrintError("start function must not return anything");
return wabt::Result::Error;
}
- module->start_func_index = start_func_index;
+ module_->start_func_index = start_func_index;
return wabt::Result::Ok;
}
wabt::Result BinaryReaderInterpreter::EndElemSegmentInitExpr(Index index) {
- assert(init_expr_value.type == Type::I32);
- table_offset = init_expr_value.value.i32;
+ assert(init_expr_value_.type == Type::I32);
+ table_offset_ = init_expr_value_.value.i32;
return wabt::Result::Ok;
}
wabt::Result BinaryReaderInterpreter::OnElemSegmentFunctionIndex(
Index index,
Index func_index) {
- assert(module->table_index != kInvalidIndex);
- Table* table = env->GetTable(module->table_index);
- if (table_offset >= table->func_indexes.size()) {
+ assert(module_->table_index != kInvalidIndex);
+ Table* table = env_->GetTable(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());
+ table_offset_, table->func_indexes.size());
return wabt::Result::Error;
}
- Index 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: %" PRIindex " (max %" PRIindex ")",
func_index, max_func_index);
return wabt::Result::Error;
}
- elem_segment_infos.emplace_back(&table->func_indexes[table_offset++],
- TranslateFuncIndexToEnv(func_index));
+ elem_segment_infos_.emplace_back(&table->func_indexes[table_offset_++],
+ TranslateFuncIndexToEnv(func_index));
return wabt::Result::Ok;
}
wabt::Result BinaryReaderInterpreter::OnDataSegmentData(Index index,
const void* src_data,
Address size) {
- assert(module->memory_index != kInvalidIndex);
- Memory* memory = env->GetMemory(module->memory_index);
- assert(init_expr_value.type == Type::I32);
- Address address = init_expr_value.value.i32;
+ assert(module_->memory_index != kInvalidIndex);
+ Memory* memory = env_->GetMemory(module_->memory_index);
+ assert(init_expr_value_.type == Type::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()) {
@@ -1019,41 +1019,41 @@ wabt::Result BinaryReaderInterpreter::OnDataSegmentData(Index index,
}
if (size > 0)
- data_segment_infos.emplace_back(&memory->data[address], src_data, size);
+ data_segment_infos_.emplace_back(&memory->data[address], src_data, size);
return wabt::Result::Ok;
}
void BinaryReaderInterpreter::PushLabel(IstreamOffset offset,
IstreamOffset fixup_offset) {
- label_stack.emplace_back(offset, fixup_offset);
+ label_stack_.emplace_back(offset, fixup_offset);
}
void BinaryReaderInterpreter::PopLabel() {
- label_stack.pop_back();
- /* reduce the depth_fixups stack as well, but it may be smaller than
- * label_stack so only do it conditionally. */
- if (depth_fixups.size() > label_stack.size()) {
- depth_fixups.erase(depth_fixups.begin() + label_stack.size(),
- depth_fixups.end());
+ label_stack_.pop_back();
+ /* reduce the depth_fixups_ stack as well, but it may be smaller than
+ * label_stack_ so only do it conditionally. */
+ if (depth_fixups_.size() > label_stack_.size()) {
+ depth_fixups_.erase(depth_fixups_.begin() + label_stack_.size(),
+ depth_fixups_.end());
}
}
wabt::Result BinaryReaderInterpreter::BeginFunctionBody(Index index) {
auto* func = cast<DefinedFunc>(GetFuncByModuleIndex(index));
- FuncSignature* sig = env->GetFuncSignature(func->sig_index);
+ FuncSignature* sig = env_->GetFuncSignature(func->sig_index);
func->offset = GetIstreamOffset();
func->local_decl_count = 0;
func->local_count = 0;
- current_func = func;
- depth_fixups.clear();
- label_stack.clear();
+ current_func_ = func;
+ depth_fixups_.clear();
+ label_stack_.clear();
/* fixup function references */
Index defined_index = TranslateModuleFuncIndexToDefined(index);
- IstreamOffsetVector& fixups = func_fixups[defined_index];
+ IstreamOffsetVector& fixups = func_fixups_[defined_index];
for (IstreamOffset fixup : fixups)
CHECK_RESULT(EmitI32At(fixup, func->offset));
@@ -1061,7 +1061,7 @@ wabt::Result BinaryReaderInterpreter::BeginFunctionBody(Index index) {
for (Type param_type : sig->param_types)
func->param_and_local_types.push_back(param_type);
- CHECK_RESULT(typechecker.BeginFunction(&sig->result_types));
+ CHECK_RESULT(typechecker_.BeginFunction(&sig->result_types));
/* push implicit func label (equivalent to return) */
PushLabel(kInvalidIstreamOffset, kInvalidIstreamOffset);
@@ -1072,37 +1072,37 @@ wabt::Result BinaryReaderInterpreter::EndFunctionBody(Index index) {
FixupTopLabel();
Index drop_count, keep_count;
CHECK_RESULT(GetReturnDropKeepCount(&drop_count, &keep_count));
- CHECK_RESULT(typechecker.EndFunction());
+ CHECK_RESULT(typechecker_.EndFunction());
CHECK_RESULT(EmitDropKeep(drop_count, keep_count));
CHECK_RESULT(EmitOpcode(interpreter::Opcode::Return));
PopLabel();
- current_func = nullptr;
+ current_func_ = nullptr;
return wabt::Result::Ok;
}
wabt::Result BinaryReaderInterpreter::OnLocalDeclCount(Index count) {
- current_func->local_decl_count = count;
+ current_func_->local_decl_count = count;
return wabt::Result::Ok;
}
wabt::Result BinaryReaderInterpreter::OnLocalDecl(Index decl_index,
Index count,
Type type) {
- current_func->local_count += count;
+ current_func_->local_count += count;
for (Index i = 0; i < count; ++i)
- current_func->param_and_local_types.push_back(type);
+ current_func_->param_and_local_types.push_back(type);
- if (decl_index == current_func->local_decl_count - 1) {
+ if (decl_index == current_func_->local_decl_count - 1) {
/* last local declaration, allocate space for all locals. */
CHECK_RESULT(EmitOpcode(interpreter::Opcode::Alloca));
- CHECK_RESULT(EmitI32(current_func->local_count));
+ CHECK_RESULT(EmitI32(current_func_->local_count));
}
return wabt::Result::Ok;
}
wabt::Result BinaryReaderInterpreter::CheckHasMemory(wabt::Opcode opcode) {
- if (module->memory_index == kInvalidIndex) {
+ if (module_->memory_index == kInvalidIndex) {
PrintError("%s requires an imported or defined memory.", opcode.GetName());
return wabt::Result::Error;
}
@@ -1120,13 +1120,13 @@ wabt::Result BinaryReaderInterpreter::CheckAlign(uint32_t alignment_log2,
}
wabt::Result BinaryReaderInterpreter::OnUnaryExpr(wabt::Opcode opcode) {
- CHECK_RESULT(typechecker.OnUnary(opcode));
+ CHECK_RESULT(typechecker_.OnUnary(opcode));
CHECK_RESULT(EmitOpcode(opcode));
return wabt::Result::Ok;
}
wabt::Result BinaryReaderInterpreter::OnBinaryExpr(wabt::Opcode opcode) {
- CHECK_RESULT(typechecker.OnBinary(opcode));
+ CHECK_RESULT(typechecker_.OnBinary(opcode));
CHECK_RESULT(EmitOpcode(opcode));
return wabt::Result::Ok;
}
@@ -1134,7 +1134,7 @@ wabt::Result BinaryReaderInterpreter::OnBinaryExpr(wabt::Opcode opcode) {
wabt::Result BinaryReaderInterpreter::OnBlockExpr(Index num_types,
Type* sig_types) {
TypeVector sig(sig_types, sig_types + num_types);
- CHECK_RESULT(typechecker.OnBlock(&sig));
+ CHECK_RESULT(typechecker_.OnBlock(&sig));
PushLabel(kInvalidIstreamOffset, kInvalidIstreamOffset);
return wabt::Result::Ok;
}
@@ -1142,7 +1142,7 @@ wabt::Result BinaryReaderInterpreter::OnBlockExpr(Index num_types,
wabt::Result BinaryReaderInterpreter::OnLoopExpr(Index num_types,
Type* sig_types) {
TypeVector sig(sig_types, sig_types + num_types);
- CHECK_RESULT(typechecker.OnLoop(&sig));
+ CHECK_RESULT(typechecker_.OnLoop(&sig));
PushLabel(GetIstreamOffset(), kInvalidIstreamOffset);
return wabt::Result::Ok;
}
@@ -1150,7 +1150,7 @@ wabt::Result BinaryReaderInterpreter::OnLoopExpr(Index num_types,
wabt::Result BinaryReaderInterpreter::OnIfExpr(Index num_types,
Type* sig_types) {
TypeVector sig(sig_types, sig_types + num_types);
- CHECK_RESULT(typechecker.OnIf(&sig));
+ CHECK_RESULT(typechecker_.OnIf(&sig));
CHECK_RESULT(EmitOpcode(interpreter::Opcode::BrUnless));
IstreamOffset fixup_offset = GetIstreamOffset();
CHECK_RESULT(EmitI32(kInvalidIstreamOffset));
@@ -1159,7 +1159,7 @@ wabt::Result BinaryReaderInterpreter::OnIfExpr(Index num_types,
}
wabt::Result BinaryReaderInterpreter::OnElseExpr() {
- CHECK_RESULT(typechecker.OnElse());
+ CHECK_RESULT(typechecker_.OnElse());
Label* label = TopLabel();
IstreamOffset fixup_cond_offset = label->fixup_offset;
CHECK_RESULT(EmitOpcode(interpreter::Opcode::Br));
@@ -1171,9 +1171,9 @@ wabt::Result BinaryReaderInterpreter::OnElseExpr() {
wabt::Result BinaryReaderInterpreter::OnEndExpr() {
TypeChecker::Label* label;
- CHECK_RESULT(typechecker.GetLabel(0, &label));
+ CHECK_RESULT(typechecker_.GetLabel(0, &label));
LabelType label_type = label->label_type;
- CHECK_RESULT(typechecker.OnEnd());
+ CHECK_RESULT(typechecker_.OnEnd());
if (label_type == LabelType::If || label_type == LabelType::Else) {
CHECK_RESULT(EmitI32At(TopLabel()->fixup_offset, GetIstreamOffset()));
}
@@ -1185,14 +1185,14 @@ wabt::Result BinaryReaderInterpreter::OnEndExpr() {
wabt::Result BinaryReaderInterpreter::OnBrExpr(Index depth) {
Index drop_count, keep_count;
CHECK_RESULT(GetBrDropKeepCount(depth, &drop_count, &keep_count));
- CHECK_RESULT(typechecker.OnBr(depth));
+ CHECK_RESULT(typechecker_.OnBr(depth));
CHECK_RESULT(EmitBr(depth, drop_count, keep_count));
return wabt::Result::Ok;
}
wabt::Result BinaryReaderInterpreter::OnBrIfExpr(Index depth) {
Index drop_count, keep_count;
- CHECK_RESULT(typechecker.OnBrIf(depth));
+ CHECK_RESULT(typechecker_.OnBrIf(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(interpreter::Opcode::BrUnless));
@@ -1207,7 +1207,7 @@ wabt::Result BinaryReaderInterpreter::OnBrTableExpr(
Index num_targets,
Index* target_depths,
Index default_target_depth) {
- CHECK_RESULT(typechecker.BeginBrTable());
+ CHECK_RESULT(typechecker_.BeginBrTable());
CHECK_RESULT(EmitOpcode(interpreter::Opcode::BrTable));
CHECK_RESULT(EmitI32(num_targets));
IstreamOffset fixup_table_offset = GetIstreamOffset();
@@ -1220,19 +1220,18 @@ wabt::Result BinaryReaderInterpreter::OnBrTableExpr(
for (Index i = 0; i <= num_targets; ++i) {
Index depth = i != num_targets ? target_depths[i] : default_target_depth;
- CHECK_RESULT(typechecker.OnBrTableTarget(depth));
+ CHECK_RESULT(typechecker_.OnBrTableTarget(depth));
CHECK_RESULT(EmitBrTableOffset(depth));
}
- CHECK_RESULT(typechecker.EndBrTable());
+ CHECK_RESULT(typechecker_.EndBrTable());
return wabt::Result::Ok;
}
wabt::Result BinaryReaderInterpreter::OnCallExpr(Index func_index) {
Func* func = GetFuncByModuleIndex(func_index);
- FuncSignature* sig = env->GetFuncSignature(func->sig_index);
- CHECK_RESULT(
- typechecker.OnCall(&sig->param_types, &sig->result_types));
+ FuncSignature* sig = env_->GetFuncSignature(func->sig_index);
+ CHECK_RESULT(typechecker_.OnCall(&sig->param_types, &sig->result_types));
if (func->is_host) {
CHECK_RESULT(EmitOpcode(interpreter::Opcode::CallHost));
@@ -1246,16 +1245,16 @@ wabt::Result BinaryReaderInterpreter::OnCallExpr(Index func_index) {
}
wabt::Result BinaryReaderInterpreter::OnCallIndirectExpr(Index sig_index) {
- if (module->table_index == kInvalidIndex) {
+ if (module_->table_index == kInvalidIndex) {
PrintError("found call_indirect operator, but no table");
return wabt::Result::Error;
}
FuncSignature* sig = GetSignatureByModuleIndex(sig_index);
- CHECK_RESULT(typechecker.OnCallIndirect(&sig->param_types,
- &sig->result_types));
+ CHECK_RESULT(
+ typechecker_.OnCallIndirect(&sig->param_types, &sig->result_types));
CHECK_RESULT(EmitOpcode(interpreter::Opcode::CallIndirect));
- CHECK_RESULT(EmitI32(module->table_index));
+ CHECK_RESULT(EmitI32(module_->table_index));
CHECK_RESULT(EmitI32(TranslateSigIndexToEnv(sig_index)));
return wabt::Result::Ok;
}
@@ -1269,34 +1268,34 @@ wabt::Result BinaryReaderInterpreter::OnConvertExpr(wabt::Opcode opcode) {
}
wabt::Result BinaryReaderInterpreter::OnDropExpr() {
- CHECK_RESULT(typechecker.OnDrop());
+ CHECK_RESULT(typechecker_.OnDrop());
CHECK_RESULT(EmitOpcode(interpreter::Opcode::Drop));
return wabt::Result::Ok;
}
wabt::Result BinaryReaderInterpreter::OnI32ConstExpr(uint32_t value) {
- CHECK_RESULT(typechecker.OnConst(Type::I32));
+ CHECK_RESULT(typechecker_.OnConst(Type::I32));
CHECK_RESULT(EmitOpcode(interpreter::Opcode::I32Const));
CHECK_RESULT(EmitI32(value));
return wabt::Result::Ok;
}
wabt::Result BinaryReaderInterpreter::OnI64ConstExpr(uint64_t value) {
- CHECK_RESULT(typechecker.OnConst(Type::I64));
+ CHECK_RESULT(typechecker_.OnConst(Type::I64));
CHECK_RESULT(EmitOpcode(interpreter::Opcode::I64Const));
CHECK_RESULT(EmitI64(value));
return wabt::Result::Ok;
}
wabt::Result BinaryReaderInterpreter::OnF32ConstExpr(uint32_t value_bits) {
- CHECK_RESULT(typechecker.OnConst(Type::F32));
+ CHECK_RESULT(typechecker_.OnConst(Type::F32));
CHECK_RESULT(EmitOpcode(interpreter::Opcode::F32Const));
CHECK_RESULT(EmitI32(value_bits));
return wabt::Result::Ok;
}
wabt::Result BinaryReaderInterpreter::OnF64ConstExpr(uint64_t value_bits) {
- CHECK_RESULT(typechecker.OnConst(Type::F64));
+ CHECK_RESULT(typechecker_.OnConst(Type::F64));
CHECK_RESULT(EmitOpcode(interpreter::Opcode::F64Const));
CHECK_RESULT(EmitI64(value_bits));
return wabt::Result::Ok;
@@ -1305,7 +1304,7 @@ wabt::Result BinaryReaderInterpreter::OnF64ConstExpr(uint64_t value_bits) {
wabt::Result BinaryReaderInterpreter::OnGetGlobalExpr(Index global_index) {
CHECK_RESULT(CheckGlobal(global_index));
Type type = GetGlobalTypeByModuleIndex(global_index);
- CHECK_RESULT(typechecker.OnGetGlobal(type));
+ CHECK_RESULT(typechecker_.OnGetGlobal(type));
CHECK_RESULT(EmitOpcode(interpreter::Opcode::GetGlobal));
CHECK_RESULT(EmitI32(TranslateGlobalIndexToEnv(global_index)));
return wabt::Result::Ok;
@@ -1319,26 +1318,25 @@ wabt::Result BinaryReaderInterpreter::OnSetGlobalExpr(Index global_index) {
global_index);
return wabt::Result::Error;
}
- CHECK_RESULT(
- typechecker.OnSetGlobal(global->typed_value.type));
+ CHECK_RESULT(typechecker_.OnSetGlobal(global->typed_value.type));
CHECK_RESULT(EmitOpcode(interpreter::Opcode::SetGlobal));
CHECK_RESULT(EmitI32(TranslateGlobalIndexToEnv(global_index)));
return wabt::Result::Ok;
}
Index BinaryReaderInterpreter::TranslateLocalIndex(Index local_index) {
- return typechecker.type_stack_size() +
- current_func->param_and_local_types.size() - local_index;
+ return typechecker_.type_stack_size() +
+ current_func_->param_and_local_types.size() - 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.OnGetLocal because it
+ Type type = GetLocalTypeByIndex(current_func_, local_index);
+ // Get the translated index before calling typechecker_.OnGetLocal because it
// will update the type stack size. We need the index to be relative to the
// old stack size.
Index translated_local_index = TranslateLocalIndex(local_index);
- CHECK_RESULT(typechecker.OnGetLocal(type));
+ CHECK_RESULT(typechecker_.OnGetLocal(type));
CHECK_RESULT(EmitOpcode(interpreter::Opcode::GetLocal));
CHECK_RESULT(EmitI32(translated_local_index));
return wabt::Result::Ok;
@@ -1346,8 +1344,8 @@ wabt::Result BinaryReaderInterpreter::OnGetLocalExpr(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.OnSetLocal(type));
+ Type type = GetLocalTypeByIndex(current_func_, local_index);
+ CHECK_RESULT(typechecker_.OnSetLocal(type));
CHECK_RESULT(EmitOpcode(interpreter::Opcode::SetLocal));
CHECK_RESULT(EmitI32(TranslateLocalIndex(local_index)));
return wabt::Result::Ok;
@@ -1355,8 +1353,8 @@ wabt::Result BinaryReaderInterpreter::OnSetLocalExpr(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.OnTeeLocal(type));
+ Type type = GetLocalTypeByIndex(current_func_, local_index);
+ CHECK_RESULT(typechecker_.OnTeeLocal(type));
CHECK_RESULT(EmitOpcode(interpreter::Opcode::TeeLocal));
CHECK_RESULT(EmitI32(TranslateLocalIndex(local_index)));
return wabt::Result::Ok;
@@ -1364,9 +1362,9 @@ wabt::Result BinaryReaderInterpreter::OnTeeLocalExpr(Index local_index) {
wabt::Result BinaryReaderInterpreter::OnGrowMemoryExpr() {
CHECK_RESULT(CheckHasMemory(wabt::Opcode::GrowMemory));
- CHECK_RESULT(typechecker.OnGrowMemory());
+ CHECK_RESULT(typechecker_.OnGrowMemory());
CHECK_RESULT(EmitOpcode(interpreter::Opcode::GrowMemory));
- CHECK_RESULT(EmitI32(module->memory_index));
+ CHECK_RESULT(EmitI32(module_->memory_index));
return wabt::Result::Ok;
}
@@ -1375,9 +1373,9 @@ wabt::Result BinaryReaderInterpreter::OnLoadExpr(wabt::Opcode opcode,
Address offset) {
CHECK_RESULT(CheckHasMemory(opcode));
CHECK_RESULT(CheckAlign(alignment_log2, opcode.GetMemorySize()));
- CHECK_RESULT(typechecker.OnLoad(opcode));
+ CHECK_RESULT(typechecker_.OnLoad(opcode));
CHECK_RESULT(EmitOpcode(opcode));
- CHECK_RESULT(EmitI32(module->memory_index));
+ CHECK_RESULT(EmitI32(module_->memory_index));
CHECK_RESULT(EmitI32(offset));
return wabt::Result::Ok;
}
@@ -1387,18 +1385,18 @@ wabt::Result BinaryReaderInterpreter::OnStoreExpr(wabt::Opcode opcode,
Address offset) {
CHECK_RESULT(CheckHasMemory(opcode));
CHECK_RESULT(CheckAlign(alignment_log2, opcode.GetMemorySize()));
- CHECK_RESULT(typechecker.OnStore(opcode));
+ CHECK_RESULT(typechecker_.OnStore(opcode));
CHECK_RESULT(EmitOpcode(opcode));
- CHECK_RESULT(EmitI32(module->memory_index));
+ CHECK_RESULT(EmitI32(module_->memory_index));
CHECK_RESULT(EmitI32(offset));
return wabt::Result::Ok;
}
wabt::Result BinaryReaderInterpreter::OnCurrentMemoryExpr() {
CHECK_RESULT(CheckHasMemory(wabt::Opcode::CurrentMemory));
- CHECK_RESULT(typechecker.OnCurrentMemory());
+ CHECK_RESULT(typechecker_.OnCurrentMemory());
CHECK_RESULT(EmitOpcode(interpreter::Opcode::CurrentMemory));
- CHECK_RESULT(EmitI32(module->memory_index));
+ CHECK_RESULT(EmitI32(module_->memory_index));
return wabt::Result::Ok;
}
@@ -1409,29 +1407,29 @@ wabt::Result BinaryReaderInterpreter::OnNopExpr() {
wabt::Result BinaryReaderInterpreter::OnReturnExpr() {
Index drop_count, keep_count;
CHECK_RESULT(GetReturnDropKeepCount(&drop_count, &keep_count));
- CHECK_RESULT(typechecker.OnReturn());
+ CHECK_RESULT(typechecker_.OnReturn());
CHECK_RESULT(EmitDropKeep(drop_count, keep_count));
CHECK_RESULT(EmitOpcode(interpreter::Opcode::Return));
return wabt::Result::Ok;
}
wabt::Result BinaryReaderInterpreter::OnSelectExpr() {
- CHECK_RESULT(typechecker.OnSelect());
+ CHECK_RESULT(typechecker_.OnSelect());
CHECK_RESULT(EmitOpcode(interpreter::Opcode::Select));
return wabt::Result::Ok;
}
wabt::Result BinaryReaderInterpreter::OnUnreachableExpr() {
- CHECK_RESULT(typechecker.OnUnreachable());
+ CHECK_RESULT(typechecker_.OnUnreachable());
CHECK_RESULT(EmitOpcode(interpreter::Opcode::Unreachable));
return wabt::Result::Ok;
}
wabt::Result BinaryReaderInterpreter::EndModule() {
- for (ElemSegmentInfo& info : elem_segment_infos) {
+ for (ElemSegmentInfo& info : elem_segment_infos_) {
*info.dst = info.func_index;
}
- for (DataSegmentInfo& info : data_segment_infos) {
+ for (DataSegmentInfo& info : data_segment_infos_) {
memcpy(info.dst_data, info.src_data, info.size);
}
return wabt::Result::Ok;
diff --git a/src/binary-reader-ir.cc b/src/binary-reader-ir.cc
index b7fa271c..70dc4fbf 100644
--- a/src/binary-reader-ir.cc
+++ b/src/binary-reader-ir.cc
@@ -208,19 +208,19 @@ class BinaryReaderIR : public BinaryReaderNop {
Result AppendExpr(std::unique_ptr<Expr> expr);
Result AppendCatch(Catch&& catch_);
- ErrorHandler* error_handler = nullptr;
- Module* module = nullptr;
+ ErrorHandler* error_handler_ = nullptr;
+ Module* module_ = nullptr;
- Func* current_func = nullptr;
- std::vector<LabelNode> label_stack;
- ExprList* current_init_expr = nullptr;
+ Func* current_func_ = nullptr;
+ std::vector<LabelNode> label_stack_;
+ ExprList* current_init_expr_ = nullptr;
const char* filename_;
};
BinaryReaderIR::BinaryReaderIR(Module* out_module,
const char* filename,
ErrorHandler* error_handler)
- : error_handler(error_handler), module(out_module), filename_(filename) {}
+ : error_handler_(error_handler), module_(out_module), filename_(filename) {}
Location BinaryReaderIR::GetLocation() const {
Location loc;
@@ -238,27 +238,27 @@ void WABT_PRINTF_FORMAT(2, 3) BinaryReaderIR::PrintError(const char* format,
void BinaryReaderIR::PushLabel(LabelType label_type,
ExprList* first,
Expr* context) {
- label_stack.emplace_back(label_type, first, context);
+ label_stack_.emplace_back(label_type, first, context);
}
Result BinaryReaderIR::PopLabel() {
- if (label_stack.size() == 0) {
+ if (label_stack_.size() == 0) {
PrintError("popping empty label stack");
return Result::Error;
}
- label_stack.pop_back();
+ label_stack_.pop_back();
return Result::Ok;
}
Result BinaryReaderIR::GetLabelAt(LabelNode** label, Index depth) {
- if (depth >= label_stack.size()) {
+ if (depth >= label_stack_.size()) {
PrintError("accessing stack depth: %" PRIindex " >= max: %" PRIzd, depth,
- label_stack.size());
+ label_stack_.size());
return Result::Error;
}
- *label = &label_stack[label_stack.size() - depth - 1];
+ *label = &label_stack_[label_stack_.size() - depth - 1];
return Result::Ok;
}
@@ -274,7 +274,7 @@ Result BinaryReaderIR::AppendExpr(std::unique_ptr<Expr> expr) {
}
bool BinaryReaderIR::HandleError(Offset offset, const char* message) {
- return error_handler->OnError(offset, message);
+ return error_handler_->OnError(offset, message);
}
bool BinaryReaderIR::OnError(const char* message) {
@@ -282,7 +282,7 @@ bool BinaryReaderIR::OnError(const char* message) {
}
Result BinaryReaderIR::OnTypeCount(Index count) {
- module->func_types.reserve(count);
+ module_->func_types.reserve(count);
return Result::Ok;
}
@@ -295,12 +295,12 @@ Result BinaryReaderIR::OnType(Index index,
FuncType& func_type = field->func_type;
func_type.sig.param_types.assign(param_types, param_types + param_count);
func_type.sig.result_types.assign(result_types, result_types + result_count);
- module->AppendField(std::move(field));
+ module_->AppendField(std::move(field));
return Result::Ok;
}
Result BinaryReaderIR::OnImportCount(Index count) {
- module->imports.reserve(count);
+ module_->imports.reserve(count);
return Result::Ok;
}
@@ -314,8 +314,8 @@ Result BinaryReaderIR::OnImportFunc(Index import_index,
import->field_name = field_name.to_string();
import->func.decl.has_func_type = true;
import->func.decl.type_var = Var(sig_index, GetLocation());
- import->func.decl.sig = module->func_types[sig_index]->sig;
- module->AppendField(
+ import->func.decl.sig = module_->func_types[sig_index]->sig;
+ module_->AppendField(
MakeUnique<ImportModuleField>(std::move(import), GetLocation()));
return Result::Ok;
}
@@ -330,7 +330,7 @@ Result BinaryReaderIR::OnImportTable(Index import_index,
import->module_name = module_name.to_string();
import->field_name = field_name.to_string();
import->table.elem_limits = *elem_limits;
- module->AppendField(
+ module_->AppendField(
MakeUnique<ImportModuleField>(std::move(import), GetLocation()));
return Result::Ok;
}
@@ -344,7 +344,7 @@ Result BinaryReaderIR::OnImportMemory(Index import_index,
import->module_name = module_name.to_string();
import->field_name = field_name.to_string();
import->memory.page_limits = *page_limits;
- module->AppendField(
+ module_->AppendField(
MakeUnique<ImportModuleField>(std::move(import), GetLocation()));
return Result::Ok;
}
@@ -360,7 +360,7 @@ Result BinaryReaderIR::OnImportGlobal(Index import_index,
import->field_name = field_name.to_string();
import->global.type = type;
import->global.mutable_ = mutable_;
- module->AppendField(
+ module_->AppendField(
MakeUnique<ImportModuleField>(std::move(import), GetLocation()));
return Result::Ok;
}
@@ -374,13 +374,13 @@ Result BinaryReaderIR::OnImportException(Index import_index,
import->module_name = module_name.to_string();
import->field_name = field_name.to_string();
import->except.sig = sig;
- module->AppendField(
+ module_->AppendField(
MakeUnique<ImportModuleField>(std::move(import), GetLocation()));
return Result::Ok;
}
Result BinaryReaderIR::OnFunctionCount(Index count) {
- module->funcs.reserve(module->num_func_imports + count);
+ module_->funcs.reserve(module_->num_func_imports + count);
return Result::Ok;
}
@@ -389,13 +389,13 @@ Result BinaryReaderIR::OnFunction(Index index, Index sig_index) {
Func& func = field->func;
func.decl.has_func_type = true;
func.decl.type_var = Var(sig_index, GetLocation());
- func.decl.sig = module->func_types[sig_index]->sig;
- module->AppendField(std::move(field));
+ func.decl.sig = module_->func_types[sig_index]->sig;
+ module_->AppendField(std::move(field));
return Result::Ok;
}
Result BinaryReaderIR::OnTableCount(Index count) {
- module->tables.reserve(module->num_table_imports + count);
+ module_->tables.reserve(module_->num_table_imports + count);
return Result::Ok;
}
@@ -405,12 +405,12 @@ Result BinaryReaderIR::OnTable(Index index,
auto field = MakeUnique<TableModuleField>(GetLocation());
Table& table = field->table;
table.elem_limits = *elem_limits;
- module->AppendField(std::move(field));
+ module_->AppendField(std::move(field));
return Result::Ok;
}
Result BinaryReaderIR::OnMemoryCount(Index count) {
- module->memories.reserve(module->num_memory_imports + count);
+ module_->memories.reserve(module_->num_memory_imports + count);
return Result::Ok;
}
@@ -418,12 +418,12 @@ Result BinaryReaderIR::OnMemory(Index index, const Limits* page_limits) {
auto field = MakeUnique<MemoryModuleField>(GetLocation());
Memory& memory = field->memory;
memory.page_limits = *page_limits;
- module->AppendField(std::move(field));
+ module_->AppendField(std::move(field));
return Result::Ok;
}
Result BinaryReaderIR::OnGlobalCount(Index count) {
- module->globals.reserve(module->num_global_imports + count);
+ module_->globals.reserve(module_->num_global_imports + count);
return Result::Ok;
}
@@ -432,24 +432,24 @@ Result BinaryReaderIR::BeginGlobal(Index index, Type type, bool mutable_) {
Global& global = field->global;
global.type = type;
global.mutable_ = mutable_;
- module->AppendField(std::move(field));
+ module_->AppendField(std::move(field));
return Result::Ok;
}
Result BinaryReaderIR::BeginGlobalInitExpr(Index index) {
- assert(index == module->globals.size() - 1);
- Global* global = module->globals[index];
- current_init_expr = &global->init_expr;
+ assert(index == module_->globals.size() - 1);
+ Global* global = module_->globals[index];
+ current_init_expr_ = &global->init_expr;
return Result::Ok;
}
Result BinaryReaderIR::EndGlobalInitExpr(Index index) {
- current_init_expr = nullptr;
+ current_init_expr_ = nullptr;
return Result::Ok;
}
Result BinaryReaderIR::OnExportCount(Index count) {
- module->exports.reserve(count);
+ module_->exports.reserve(count);
return Result::Ok;
}
@@ -462,16 +462,16 @@ Result BinaryReaderIR::OnExport(Index index,
export_.name = name.to_string();
switch (kind) {
case ExternalKind::Func:
- assert(item_index < module->funcs.size());
+ assert(item_index < module_->funcs.size());
break;
case ExternalKind::Table:
- assert(item_index < module->tables.size());
+ assert(item_index < module_->tables.size());
break;
case ExternalKind::Memory:
- assert(item_index < module->memories.size());
+ assert(item_index < module_->memories.size());
break;
case ExternalKind::Global:
- assert(item_index < module->globals.size());
+ assert(item_index < module_->globals.size());
break;
case ExternalKind::Except:
// Note: Can't check if index valid, exceptions section comes later.
@@ -479,30 +479,30 @@ Result BinaryReaderIR::OnExport(Index index,
}
export_.var = Var(item_index, GetLocation());
export_.kind = kind;
- module->AppendField(std::move(field));
+ module_->AppendField(std::move(field));
return Result::Ok;
}
Result BinaryReaderIR::OnStartFunction(Index func_index) {
- assert(func_index < module->funcs.size());
+ assert(func_index < module_->funcs.size());
Var start(func_index, GetLocation());
- module->AppendField(MakeUnique<StartModuleField>(start, GetLocation()));
+ module_->AppendField(MakeUnique<StartModuleField>(start, GetLocation()));
return Result::Ok;
}
Result BinaryReaderIR::OnFunctionBodyCount(Index count) {
- assert(module->num_func_imports + count == module->funcs.size());
+ assert(module_->num_func_imports + count == module_->funcs.size());
return Result::Ok;
}
Result BinaryReaderIR::BeginFunctionBody(Index index) {
- current_func = module->funcs[index];
- PushLabel(LabelType::Func, &current_func->exprs);
+ current_func_ = module_->funcs[index];
+ PushLabel(LabelType::Func, &current_func_->exprs);
return Result::Ok;
}
Result BinaryReaderIR::OnLocalDecl(Index decl_index, Index count, Type type) {
- TypeVector& types = current_func->local_types;
+ TypeVector& types = current_func_->local_types;
types.reserve(types.size() + count);
for (size_t i = 0; i < count; ++i)
types.push_back(type);
@@ -543,12 +543,12 @@ Result BinaryReaderIR::OnBrTableExpr(Index num_targets,
}
Result BinaryReaderIR::OnCallExpr(Index func_index) {
- assert(func_index < module->funcs.size());
+ assert(func_index < module_->funcs.size());
return AppendExpr(MakeUnique<CallExpr>(Var(func_index, GetLocation())));
}
Result BinaryReaderIR::OnCallIndirectExpr(Index sig_index) {
- assert(sig_index < module->func_types.size());
+ assert(sig_index < module_->func_types.size());
return AppendExpr(
MakeUnique<CallIndirectExpr>(Var(sig_index, GetLocation())));
}
@@ -727,12 +727,12 @@ Result BinaryReaderIR::OnUnreachableExpr() {
Result BinaryReaderIR::EndFunctionBody(Index index) {
CHECK_RESULT(PopLabel());
- current_func = nullptr;
+ current_func_ = nullptr;
return Result::Ok;
}
Result BinaryReaderIR::OnElemSegmentCount(Index count) {
- module->elem_segments.reserve(count);
+ module_->elem_segments.reserve(count);
return Result::Ok;
}
@@ -740,34 +740,34 @@ Result BinaryReaderIR::BeginElemSegment(Index index, Index table_index) {
auto field = MakeUnique<ElemSegmentModuleField>(GetLocation());
ElemSegment& elem_segment = field->elem_segment;
elem_segment.table_var = Var(table_index, GetLocation());
- module->AppendField(std::move(field));
+ module_->AppendField(std::move(field));
return Result::Ok;
}
Result BinaryReaderIR::BeginElemSegmentInitExpr(Index index) {
- assert(index == module->elem_segments.size() - 1);
- ElemSegment* segment = module->elem_segments[index];
- current_init_expr = &segment->offset;
+ assert(index == module_->elem_segments.size() - 1);
+ ElemSegment* segment = module_->elem_segments[index];
+ current_init_expr_ = &segment->offset;
return Result::Ok;
}
Result BinaryReaderIR::EndElemSegmentInitExpr(Index index) {
- current_init_expr = nullptr;
+ current_init_expr_ = nullptr;
return Result::Ok;
}
Result BinaryReaderIR::OnElemSegmentFunctionIndexCount(Index index,
Index count) {
- assert(index == module->elem_segments.size() - 1);
- ElemSegment* segment = module->elem_segments[index];
+ assert(index == module_->elem_segments.size() - 1);
+ ElemSegment* segment = module_->elem_segments[index];
segment->vars.reserve(count);
return Result::Ok;
}
Result BinaryReaderIR::OnElemSegmentFunctionIndex(Index segment_index,
Index func_index) {
- assert(segment_index == module->elem_segments.size() - 1);
- ElemSegment* segment = module->elem_segments[segment_index];
+ assert(segment_index == module_->elem_segments.size() - 1);
+ ElemSegment* segment = module_->elem_segments[segment_index];
segment->vars.emplace_back();
Var* var = &segment->vars.back();
*var = Var(func_index, GetLocation());
@@ -775,7 +775,7 @@ Result BinaryReaderIR::OnElemSegmentFunctionIndex(Index segment_index,
}
Result BinaryReaderIR::OnDataSegmentCount(Index count) {
- module->data_segments.reserve(count);
+ module_->data_segments.reserve(count);
return Result::Ok;
}
@@ -783,27 +783,27 @@ Result BinaryReaderIR::BeginDataSegment(Index index, Index memory_index) {
auto field = MakeUnique<DataSegmentModuleField>(GetLocation());
DataSegment& data_segment = field->data_segment;
data_segment.memory_var = Var(memory_index, GetLocation());
- module->AppendField(std::move(field));
+ module_->AppendField(std::move(field));
return Result::Ok;
}
Result BinaryReaderIR::BeginDataSegmentInitExpr(Index index) {
- assert(index == module->data_segments.size() - 1);
- DataSegment* segment = module->data_segments[index];
- current_init_expr = &segment->offset;
+ assert(index == module_->data_segments.size() - 1);
+ DataSegment* segment = module_->data_segments[index];
+ current_init_expr_ = &segment->offset;
return Result::Ok;
}
Result BinaryReaderIR::EndDataSegmentInitExpr(Index index) {
- current_init_expr = nullptr;
+ current_init_expr_ = nullptr;
return Result::Ok;
}
Result BinaryReaderIR::OnDataSegmentData(Index index,
const void* data,
Address size) {
- assert(index == module->data_segments.size() - 1);
- DataSegment* segment = module->data_segments[index];
+ assert(index == module_->data_segments.size() - 1);
+ DataSegment* segment = module_->data_segments[index];
segment->data.resize(size);
if (size > 0)
memcpy(segment->data.data(), data, size);
@@ -811,10 +811,10 @@ Result BinaryReaderIR::OnDataSegmentData(Index index,
}
Result BinaryReaderIR::OnFunctionNamesCount(Index count) {
- if (count > module->funcs.size()) {
+ if (count > module_->funcs.size()) {
PrintError("expected function name count (%" PRIindex
") <= function count (%" PRIzd ")",
- count, module->funcs.size());
+ count, module_->funcs.size());
return Result::Error;
}
return Result::Ok;
@@ -824,21 +824,21 @@ Result BinaryReaderIR::OnFunctionName(Index index, string_view name) {
if (name.empty())
return Result::Ok;
- Func* func = module->funcs[index];
+ Func* func = module_->funcs[index];
std::string dollar_name = std::string("$") + name.to_string();
int counter = 1;
std::string orig_name = dollar_name;
- while (module->func_bindings.count(dollar_name) != 0) {
+ while (module_->func_bindings.count(dollar_name) != 0) {
dollar_name = orig_name + "." + std::to_string(counter++);
}
func->name = dollar_name;
- module->func_bindings.emplace(dollar_name, Binding(index));
+ module_->func_bindings.emplace(dollar_name, Binding(index));
return Result::Ok;
}
Result BinaryReaderIR::OnLocalNameLocalCount(Index index, Index count) {
- assert(index < module->funcs.size());
- Func* func = module->funcs[index];
+ assert(index < module_->funcs.size());
+ Func* func = module_->funcs[index];
Index num_params_and_locals = func->GetNumParamsAndLocals();
if (count > num_params_and_locals) {
PrintError("expected local name count (%" PRIindex
@@ -851,14 +851,14 @@ Result BinaryReaderIR::OnLocalNameLocalCount(Index index, Index count) {
Result BinaryReaderIR::OnInitExprF32ConstExpr(Index index, uint32_t value) {
Location loc = GetLocation();
- current_init_expr->push_back(
+ current_init_expr_->push_back(
MakeUnique<ConstExpr>(Const::F32(value, loc), loc));
return Result::Ok;
}
Result BinaryReaderIR::OnInitExprF64ConstExpr(Index index, uint64_t value) {
Location loc = GetLocation();
- current_init_expr->push_back(
+ current_init_expr_->push_back(
MakeUnique<ConstExpr>(Const::F64(value, loc), loc));
return Result::Ok;
}
@@ -866,21 +866,21 @@ Result BinaryReaderIR::OnInitExprF64ConstExpr(Index index, uint64_t value) {
Result BinaryReaderIR::OnInitExprGetGlobalExpr(Index index,
Index global_index) {
Location loc = GetLocation();
- current_init_expr->push_back(
+ current_init_expr_->push_back(
MakeUnique<GetGlobalExpr>(Var(global_index, loc), loc));
return Result::Ok;
}
Result BinaryReaderIR::OnInitExprI32ConstExpr(Index index, uint32_t value) {
Location loc = GetLocation();
- current_init_expr->push_back(
+ current_init_expr_->push_back(
MakeUnique<ConstExpr>(Const::I32(value, loc), loc));
return Result::Ok;
}
Result BinaryReaderIR::OnInitExprI64ConstExpr(Index index, uint64_t value) {
Location loc = GetLocation();
- current_init_expr->push_back(
+ current_init_expr_->push_back(
MakeUnique<ConstExpr>(Const::I64(value, loc), loc));
return Result::Ok;
}
@@ -891,7 +891,7 @@ Result BinaryReaderIR::OnLocalName(Index func_index,
if (name.empty())
return Result::Ok;
- Func* func = module->funcs[func_index];
+ Func* func = module_->funcs[func_index];
Index num_params = func->GetNumParams();
BindingHash* bindings;
Index index;
@@ -912,7 +912,7 @@ Result BinaryReaderIR::OnExceptionType(Index index, TypeVector& sig) {
auto field = MakeUnique<ExceptionModuleField>(GetLocation());
Exception& except = field->except;
except.sig = sig;
- module->AppendField(std::move(field));
+ module_->AppendField(std::move(field));
return Result::Ok;
}
diff --git a/src/binary-reader-logging.cc b/src/binary-reader-logging.cc
index 2d0ada8f..71352611 100644
--- a/src/binary-reader-logging.cc
+++ b/src/binary-reader-logging.cc
@@ -24,7 +24,7 @@ namespace wabt {
#define INDENT_SIZE 2
-#define LOGF_NOINDENT(...) stream->Writef(__VA_ARGS__)
+#define LOGF_NOINDENT(...) stream_->Writef(__VA_ARGS__)
#define LOGF(...) \
do { \
@@ -50,15 +50,15 @@ void SPrintLimits(char* dst, size_t size, const Limits* limits) {
BinaryReaderLogging::BinaryReaderLogging(Stream* stream,
BinaryReaderDelegate* forward)
- : stream(stream), reader(forward), indent(0) {}
+ : stream_(stream), reader_(forward), indent_(0) {}
void BinaryReaderLogging::Indent() {
- indent += INDENT_SIZE;
+ indent_ += INDENT_SIZE;
}
void BinaryReaderLogging::Dedent() {
- indent -= INDENT_SIZE;
- assert(indent >= 0);
+ indent_ -= INDENT_SIZE;
+ assert(indent_ >= 0);
}
void BinaryReaderLogging::WriteIndent() {
@@ -66,13 +66,13 @@ void BinaryReaderLogging::WriteIndent() {
" "
" ";
static const size_t s_indent_len = sizeof(s_indent) - 1;
- size_t i = indent;
+ size_t i = indent_;
while (i > s_indent_len) {
- stream->WriteData(s_indent, s_indent_len);
+ stream_->WriteData(s_indent, s_indent_len);
i -= s_indent_len;
}
if (i > 0) {
- stream->WriteData(s_indent, indent);
+ stream_->WriteData(s_indent, indent_);
}
}
@@ -91,23 +91,23 @@ void BinaryReaderLogging::LogTypes(TypeVector& types) {
}
bool BinaryReaderLogging::OnError(const char* message) {
- return reader->OnError(message);
+ return reader_->OnError(message);
}
void BinaryReaderLogging::OnSetState(const State* s) {
BinaryReaderDelegate::OnSetState(s);
- reader->OnSetState(s);
+ reader_->OnSetState(s);
}
Result BinaryReaderLogging::BeginModule(uint32_t version) {
LOGF("BeginModule(version: %u)\n", version);
Indent();
- return reader->BeginModule(version);
+ return reader_->BeginModule(version);
}
Result BinaryReaderLogging::BeginSection(BinarySection section_type,
Offset size) {
- return reader->BeginSection(section_type, size);
+ return reader_->BeginSection(section_type, size);
}
Result BinaryReaderLogging::BeginCustomSection(Offset size,
@@ -115,7 +115,7 @@ Result BinaryReaderLogging::BeginCustomSection(Offset size,
LOGF("BeginCustomSection('" PRIstringview "', size: %" PRIzd ")\n",
WABT_PRINTF_STRING_VIEW_ARG(section_name), size);
Indent();
- return reader->BeginCustomSection(size, section_name);
+ return reader_->BeginCustomSection(size, section_name);
}
Result BinaryReaderLogging::OnType(Index index,
@@ -128,8 +128,8 @@ Result BinaryReaderLogging::OnType(Index index,
LOGF_NOINDENT(", results: ");
LogTypes(result_count, result_types);
LOGF_NOINDENT(")\n");
- return reader->OnType(index, param_count, param_types, result_count,
- result_types);
+ return reader_->OnType(index, param_count, param_types, result_count,
+ result_types);
}
Result BinaryReaderLogging::OnImport(Index index,
@@ -139,7 +139,7 @@ Result BinaryReaderLogging::OnImport(Index index,
"\", field: \"" PRIstringview "\")\n",
index, WABT_PRINTF_STRING_VIEW_ARG(module_name),
WABT_PRINTF_STRING_VIEW_ARG(field_name));
- return reader->OnImport(index, module_name, field_name);
+ return reader_->OnImport(index, module_name, field_name);
}
Result BinaryReaderLogging::OnImportFunc(Index import_index,
@@ -150,8 +150,8 @@ Result BinaryReaderLogging::OnImportFunc(Index import_index,
LOGF("OnImportFunc(import_index: %" PRIindex ", func_index: %" PRIindex
", sig_index: %" PRIindex ")\n",
import_index, func_index, sig_index);
- return reader->OnImportFunc(import_index, module_name, field_name, func_index,
- sig_index);
+ return reader_->OnImportFunc(import_index, module_name, field_name,
+ func_index, sig_index);
}
Result BinaryReaderLogging::OnImportTable(Index import_index,
@@ -165,8 +165,8 @@ Result BinaryReaderLogging::OnImportTable(Index import_index,
LOGF("OnImportTable(import_index: %" PRIindex ", table_index: %" PRIindex
", elem_type: %s, %s)\n",
import_index, table_index, GetTypeName(elem_type), buf);
- return reader->OnImportTable(import_index, module_name, field_name,
- table_index, elem_type, elem_limits);
+ return reader_->OnImportTable(import_index, module_name, field_name,
+ table_index, elem_type, elem_limits);
}
Result BinaryReaderLogging::OnImportMemory(Index import_index,
@@ -179,8 +179,8 @@ Result BinaryReaderLogging::OnImportMemory(Index import_index,
LOGF("OnImportMemory(import_index: %" PRIindex ", memory_index: %" PRIindex
", %s)\n",
import_index, memory_index, buf);
- return reader->OnImportMemory(import_index, module_name, field_name,
- memory_index, page_limits);
+ return reader_->OnImportMemory(import_index, module_name, field_name,
+ memory_index, page_limits);
}
Result BinaryReaderLogging::OnImportGlobal(Index import_index,
@@ -194,8 +194,8 @@ Result BinaryReaderLogging::OnImportGlobal(Index import_index,
"%s)\n",
import_index, global_index, GetTypeName(type),
mutable_ ? "true" : "false");
- return reader->OnImportGlobal(import_index, module_name, field_name,
- global_index, type, mutable_);
+ return reader_->OnImportGlobal(import_index, module_name, field_name,
+ global_index, type, mutable_);
}
Result BinaryReaderLogging::OnImportException(Index import_index,
@@ -208,8 +208,8 @@ Result BinaryReaderLogging::OnImportException(Index import_index,
import_index, except_index);
LogTypes(sig);
LOGF_NOINDENT(")\n");
- return reader->OnImportException(import_index, module_name, field_name,
- except_index, sig);
+ return reader_->OnImportException(import_index, module_name, field_name,
+ except_index, sig);
}
Result BinaryReaderLogging::OnTable(Index index,
@@ -219,20 +219,20 @@ Result BinaryReaderLogging::OnTable(Index index,
SPrintLimits(buf, sizeof(buf), elem_limits);
LOGF("OnTable(index: %" PRIindex ", elem_type: %s, %s)\n", index,
GetTypeName(elem_type), buf);
- return reader->OnTable(index, elem_type, elem_limits);
+ return reader_->OnTable(index, elem_type, elem_limits);
}
Result BinaryReaderLogging::OnMemory(Index index, const Limits* page_limits) {
char buf[100];
SPrintLimits(buf, sizeof(buf), page_limits);
LOGF("OnMemory(index: %" PRIindex ", %s)\n", index, buf);
- return reader->OnMemory(index, page_limits);
+ return reader_->OnMemory(index, page_limits);
}
Result BinaryReaderLogging::BeginGlobal(Index index, Type type, bool mutable_) {
LOGF("BeginGlobal(index: %" PRIindex ", type: %s, mutable: %s)\n", index,
GetTypeName(type), mutable_ ? "true" : "false");
- return reader->BeginGlobal(index, type, mutable_);
+ return reader_->BeginGlobal(index, type, mutable_);
}
Result BinaryReaderLogging::OnExport(Index index,
@@ -242,7 +242,7 @@ Result BinaryReaderLogging::OnExport(Index index,
LOGF("OnExport(index: %" PRIindex ", kind: %s, item_index: %" PRIindex
", name: \"" PRIstringview "\")\n",
index, GetKindName(kind), item_index, WABT_PRINTF_STRING_VIEW_ARG(name));
- return reader->OnExport(index, kind, item_index, name);
+ return reader_->OnExport(index, kind, item_index, name);
}
Result BinaryReaderLogging::OnLocalDecl(Index decl_index,
@@ -250,24 +250,24 @@ Result BinaryReaderLogging::OnLocalDecl(Index decl_index,
Type type) {
LOGF("OnLocalDecl(index: %" PRIindex ", count: %" PRIindex ", type: %s)\n",
decl_index, count, GetTypeName(type));
- return reader->OnLocalDecl(decl_index, count, type);
+ return reader_->OnLocalDecl(decl_index, count, type);
}
Result BinaryReaderLogging::OnBlockExpr(Index num_types, Type* sig_types) {
LOGF("OnBlockExpr(sig: ");
LogTypes(num_types, sig_types);
LOGF_NOINDENT(")\n");
- return reader->OnBlockExpr(num_types, sig_types);
+ return reader_->OnBlockExpr(num_types, sig_types);
}
Result BinaryReaderLogging::OnBrExpr(Index depth) {
LOGF("OnBrExpr(depth: %" PRIindex ")\n", depth);
- return reader->OnBrExpr(depth);
+ return reader_->OnBrExpr(depth);
}
Result BinaryReaderLogging::OnBrIfExpr(Index depth) {
LOGF("OnBrIfExpr(depth: %" PRIindex ")\n", depth);
- return reader->OnBrIfExpr(depth);
+ return reader_->OnBrIfExpr(depth);
}
Result BinaryReaderLogging::OnBrTableExpr(Index num_targets,
@@ -280,46 +280,46 @@ Result BinaryReaderLogging::OnBrTableExpr(Index num_targets,
LOGF_NOINDENT(", ");
}
LOGF_NOINDENT("], default: %" PRIindex ")\n", default_target_depth);
- return reader->OnBrTableExpr(num_targets, target_depths,
- default_target_depth);
+ return reader_->OnBrTableExpr(num_targets, target_depths,
+ default_target_depth);
}
Result BinaryReaderLogging::OnExceptionType(Index index, TypeVector& sig) {
LOGF("OnType(index: %" PRIindex ", values: ", index);
LogTypes(sig);
LOGF_NOINDENT(")\n");
- return reader->OnExceptionType(index, sig);
+ return reader_->OnExceptionType(index, sig);
}
Result BinaryReaderLogging::OnF32ConstExpr(uint32_t value_bits) {
float value;
memcpy(&value, &value_bits, sizeof(value));
LOGF("OnF32ConstExpr(%g (0x04%x))\n", value, value_bits);
- return reader->OnF32ConstExpr(value_bits);
+ return reader_->OnF32ConstExpr(value_bits);
}
Result BinaryReaderLogging::OnF64ConstExpr(uint64_t value_bits) {
double value;
memcpy(&value, &value_bits, sizeof(value));
LOGF("OnF64ConstExpr(%g (0x08%" PRIx64 "))\n", value, value_bits);
- return reader->OnF64ConstExpr(value_bits);
+ return reader_->OnF64ConstExpr(value_bits);
}
Result BinaryReaderLogging::OnI32ConstExpr(uint32_t value) {
LOGF("OnI32ConstExpr(%u (0x%x))\n", value, value);
- return reader->OnI32ConstExpr(value);
+ return reader_->OnI32ConstExpr(value);
}
Result BinaryReaderLogging::OnI64ConstExpr(uint64_t value) {
LOGF("OnI64ConstExpr(%" PRIu64 " (0x%" PRIx64 "))\n", value, value);
- return reader->OnI64ConstExpr(value);
+ return reader_->OnI64ConstExpr(value);
}
Result BinaryReaderLogging::OnIfExpr(Index num_types, Type* sig_types) {
LOGF("OnIfExpr(sig: ");
LogTypes(num_types, sig_types);
LOGF_NOINDENT(")\n");
- return reader->OnIfExpr(num_types, sig_types);
+ return reader_->OnIfExpr(num_types, sig_types);
}
Result BinaryReaderLogging::OnLoadExpr(Opcode opcode,
@@ -328,14 +328,14 @@ Result BinaryReaderLogging::OnLoadExpr(Opcode opcode,
LOGF("OnLoadExpr(opcode: \"%s\" (%u), align log2: %u, offset: %" PRIaddress
")\n",
opcode.GetName(), opcode.GetCode(), alignment_log2, offset);
- return reader->OnLoadExpr(opcode, alignment_log2, offset);
+ return reader_->OnLoadExpr(opcode, alignment_log2, offset);
}
Result BinaryReaderLogging::OnLoopExpr(Index num_types, Type* sig_types) {
LOGF("OnLoopExpr(sig: ");
LogTypes(num_types, sig_types);
LOGF_NOINDENT(")\n");
- return reader->OnLoopExpr(num_types, sig_types);
+ return reader_->OnLoopExpr(num_types, sig_types);
}
Result BinaryReaderLogging::OnStoreExpr(Opcode opcode,
@@ -344,14 +344,14 @@ Result BinaryReaderLogging::OnStoreExpr(Opcode opcode,
LOGF("OnStoreExpr(opcode: \"%s\" (%u), align log2: %u, offset: %" PRIaddress
")\n",
opcode.GetName(), opcode.GetCode(), alignment_log2, offset);
- return reader->OnStoreExpr(opcode, alignment_log2, offset);
+ return reader_->OnStoreExpr(opcode, alignment_log2, offset);
}
Result BinaryReaderLogging::OnTryExpr(Index num_types, Type* sig_types) {
LOGF("OnTryExpr(sig: ");
LogTypes(num_types, sig_types);
LOGF_NOINDENT(")\n");
- return reader->OnTryExpr(num_types, sig_types);
+ return reader_->OnTryExpr(num_types, sig_types);
}
Result BinaryReaderLogging::OnDataSegmentData(Index index,
@@ -359,7 +359,7 @@ Result BinaryReaderLogging::OnDataSegmentData(Index index,
Address size) {
LOGF("OnDataSegmentData(index:%" PRIindex ", size:%" PRIaddress ")\n", index,
size);
- return reader->OnDataSegmentData(index, data, size);
+ return reader_->OnDataSegmentData(index, data, size);
}
Result BinaryReaderLogging::OnFunctionNameSubsection(Index index,
@@ -368,13 +368,13 @@ Result BinaryReaderLogging::OnFunctionNameSubsection(Index index,
LOGF("OnFunctionNameSubsection(index:%" PRIindex ", nametype:%u, size:%" PRIzd
")\n",
index, name_type, subsection_size);
- return reader->OnFunctionNameSubsection(index, name_type, subsection_size);
+ return reader_->OnFunctionNameSubsection(index, name_type, subsection_size);
}
Result BinaryReaderLogging::OnFunctionName(Index index, string_view name) {
LOGF("OnFunctionName(index: %" PRIindex ", name: \"" PRIstringview "\")\n",
index, WABT_PRINTF_STRING_VIEW_ARG(name));
- return reader->OnFunctionName(index, name);
+ return reader_->OnFunctionName(index, name);
}
Result BinaryReaderLogging::OnLocalNameSubsection(Index index,
@@ -383,7 +383,7 @@ Result BinaryReaderLogging::OnLocalNameSubsection(Index index,
LOGF("OnLocalNameSubsection(index:%" PRIindex ", nametype:%u, size:%" PRIzd
")\n",
index, name_type, subsection_size);
- return reader->OnLocalNameSubsection(index, name_type, subsection_size);
+ return reader_->OnLocalNameSubsection(index, name_type, subsection_size);
}
Result BinaryReaderLogging::OnLocalName(Index func_index,
@@ -392,7 +392,7 @@ Result BinaryReaderLogging::OnLocalName(Index func_index,
LOGF("OnLocalName(func_index: %" PRIindex ", local_index: %" PRIindex
", name: \"" PRIstringview "\")\n",
func_index, local_index, WABT_PRINTF_STRING_VIEW_ARG(name));
- return reader->OnLocalName(func_index, local_index, name);
+ return reader_->OnLocalName(func_index, local_index, name);
}
Result BinaryReaderLogging::OnInitExprF32ConstExpr(Index index,
@@ -401,7 +401,7 @@ Result BinaryReaderLogging::OnInitExprF32ConstExpr(Index index,
memcpy(&value, &value_bits, sizeof(value));
LOGF("OnInitExprF32ConstExpr(index: %" PRIindex ", value: %g (0x04%x))\n",
index, value, value_bits);
- return reader->OnInitExprF32ConstExpr(index, value_bits);
+ return reader_->OnInitExprF32ConstExpr(index, value_bits);
}
Result BinaryReaderLogging::OnInitExprF64ConstExpr(Index index,
@@ -411,21 +411,21 @@ Result BinaryReaderLogging::OnInitExprF64ConstExpr(Index index,
LOGF("OnInitExprF64ConstExpr(index: %" PRIindex " value: %g (0x08%" PRIx64
"))\n",
index, value, value_bits);
- return reader->OnInitExprF64ConstExpr(index, value_bits);
+ return reader_->OnInitExprF64ConstExpr(index, value_bits);
}
Result BinaryReaderLogging::OnInitExprI32ConstExpr(Index index,
uint32_t value) {
LOGF("OnInitExprI32ConstExpr(index: %" PRIindex ", value: %u)\n", index,
value);
- return reader->OnInitExprI32ConstExpr(index, value);
+ return reader_->OnInitExprI32ConstExpr(index, value);
}
Result BinaryReaderLogging::OnInitExprI64ConstExpr(Index index,
uint64_t value) {
LOGF("OnInitExprI64ConstExpr(index: %" PRIindex ", value: %" PRIu64 ")\n",
index, value);
- return reader->OnInitExprI64ConstExpr(index, value);
+ return reader_->OnInitExprI64ConstExpr(index, value);
}
Result BinaryReaderLogging::OnRelocCount(Index count,
@@ -435,7 +435,7 @@ Result BinaryReaderLogging::OnRelocCount(Index count,
", section: %s, section_name: " PRIstringview ")\n",
count, GetSectionName(section_code),
WABT_PRINTF_STRING_VIEW_ARG(section_name));
- return reader->OnRelocCount(count, section_code, section_name);
+ return reader_->OnRelocCount(count, section_code, section_name);
}
Result BinaryReaderLogging::OnReloc(RelocType type,
@@ -446,58 +446,58 @@ Result BinaryReaderLogging::OnReloc(RelocType type,
LOGF("OnReloc(type: %s, offset: %" PRIzd ", index: %" PRIindex
", addend: %d)\n",
GetRelocTypeName(type), offset, index, signed_addend);
- return reader->OnReloc(type, offset, index, addend);
+ return reader_->OnReloc(type, offset, index, addend);
}
Result BinaryReaderLogging::OnSymbolInfo(string_view name, uint32_t flags) {
LOGF("(OnSymbolInfo name: " PRIstringview ", flags: 0x%x)\n",
WABT_PRINTF_STRING_VIEW_ARG(name), flags);
- return reader->OnSymbolInfo(name, flags);
+ return reader_->OnSymbolInfo(name, flags);
}
#define DEFINE_BEGIN(name) \
Result BinaryReaderLogging::name(Offset size) { \
LOGF(#name "(%" PRIzd ")\n", size); \
Indent(); \
- return reader->name(size); \
+ return reader_->name(size); \
}
#define DEFINE_END(name) \
Result BinaryReaderLogging::name() { \
Dedent(); \
LOGF(#name "\n"); \
- return reader->name(); \
+ return reader_->name(); \
}
#define DEFINE_INDEX(name) \
Result BinaryReaderLogging::name(Index value) { \
LOGF(#name "(%" PRIindex ")\n", value); \
- return reader->name(value); \
+ return reader_->name(value); \
}
#define DEFINE_INDEX_DESC(name, desc) \
Result BinaryReaderLogging::name(Index value) { \
LOGF(#name "(" desc ": %" PRIindex ")\n", value); \
- return reader->name(value); \
+ return reader_->name(value); \
}
#define DEFINE_INDEX_INDEX(name, desc0, desc1) \
Result BinaryReaderLogging::name(Index value0, Index value1) { \
LOGF(#name "(" desc0 ": %" PRIindex ", " desc1 ": %" PRIindex ")\n", \
value0, value1); \
- return reader->name(value0, value1); \
+ return reader_->name(value0, value1); \
}
#define DEFINE_OPCODE(name) \
Result BinaryReaderLogging::name(Opcode opcode) { \
LOGF(#name "(\"%s\" (%u))\n", opcode.GetName(), opcode.GetCode()); \
- return reader->name(opcode); \
+ return reader_->name(opcode); \
}
#define DEFINE0(name) \
Result BinaryReaderLogging::name() { \
LOGF(#name "\n"); \
- return reader->name(); \
+ return reader_->name(); \
}
DEFINE_END(EndModule)
@@ -614,44 +614,44 @@ DEFINE_END(EndExceptionSection);
// We don't need to log these (the individual opcodes are logged instead), but
// we still need to forward the calls.
Result BinaryReaderLogging::OnOpcode(Opcode opcode) {
- return reader->OnOpcode(opcode);
+ return reader_->OnOpcode(opcode);
}
Result BinaryReaderLogging::OnOpcodeBare() {
- return reader->OnOpcodeBare();
+ return reader_->OnOpcodeBare();
}
Result BinaryReaderLogging::OnOpcodeIndex(Index value) {
- return reader->OnOpcodeIndex(value);
+ return reader_->OnOpcodeIndex(value);
}
Result BinaryReaderLogging::OnOpcodeUint32(uint32_t value) {
- return reader->OnOpcodeUint32(value);
+ return reader_->OnOpcodeUint32(value);
}
Result BinaryReaderLogging::OnOpcodeUint32Uint32(uint32_t value,
uint32_t value2) {
- return reader->OnOpcodeUint32Uint32(value, value2);
+ return reader_->OnOpcodeUint32Uint32(value, value2);
}
Result BinaryReaderLogging::OnOpcodeUint64(uint64_t value) {
- return reader->OnOpcodeUint64(value);
+ return reader_->OnOpcodeUint64(value);
}
Result BinaryReaderLogging::OnOpcodeF32(uint32_t value) {
- return reader->OnOpcodeF32(value);
+ return reader_->OnOpcodeF32(value);
}
Result BinaryReaderLogging::OnOpcodeF64(uint64_t value) {
- return reader->OnOpcodeF64(value);
+ return reader_->OnOpcodeF64(value);
}
Result BinaryReaderLogging::OnOpcodeBlockSig(Index num_types, Type* sig_types) {
- return reader->OnOpcodeBlockSig(num_types, sig_types);
+ return reader_->OnOpcodeBlockSig(num_types, sig_types);
}
Result BinaryReaderLogging::OnEndFunc() {
- return reader->OnEndFunc();
+ return reader_->OnEndFunc();
}
} // namespace wabt
diff --git a/src/binary-reader-logging.h b/src/binary-reader-logging.h
index 6726ed07..813501fd 100644
--- a/src/binary-reader-logging.h
+++ b/src/binary-reader-logging.h
@@ -258,9 +258,9 @@ class BinaryReaderLogging : public BinaryReaderDelegate {
void LogTypes(Index type_count, Type* types);
void LogTypes(TypeVector& types);
- Stream* stream;
- BinaryReaderDelegate* reader;
- int indent;
+ Stream* stream_;
+ BinaryReaderDelegate* reader_;
+ int indent_;
};
} // namespace wabt
diff --git a/src/binary-reader-objdump.cc b/src/binary-reader-objdump.cc
index 9baf3938..80196ce6 100644
--- a/src/binary-reader-objdump.cc
+++ b/src/binary-reader-objdump.cc
@@ -48,38 +48,38 @@ class BinaryReaderObjdumpBase : public BinaryReaderNop {
const char* GetFunctionName(Index index) const;
void PrintRelocation(const Reloc& reloc, Offset offset) const;
Offset GetSectionStart(BinarySection section_code) const {
- return section_starts[static_cast<size_t>(section_code)];
+ return section_starts_[static_cast<size_t>(section_code)];
}
- ObjdumpOptions* options;
- ObjdumpState* objdump_state;
- const uint8_t* data;
- size_t size;
- bool print_details = false;
- BinarySection reloc_section = BinarySection::Invalid;
- Offset section_starts[kBinarySectionCount];
- bool section_found = false;
+ ObjdumpOptions* options_;
+ ObjdumpState* objdump_state_;
+ const uint8_t* data_;
+ size_t size_;
+ bool print_details_ = false;
+ BinarySection reloc_section_ = BinarySection::Invalid;
+ Offset section_starts_[kBinarySectionCount];
+ bool section_found_ = false;
};
BinaryReaderObjdumpBase::BinaryReaderObjdumpBase(const uint8_t* data,
size_t size,
ObjdumpOptions* options,
ObjdumpState* objdump_state)
- : options(options),
- objdump_state(objdump_state),
- data(data),
- size(size) {
- ZeroMemory(section_starts);
+ : options_(options),
+ objdump_state_(objdump_state),
+ data_(data),
+ size_(size) {
+ ZeroMemory(section_starts_);
}
Result BinaryReaderObjdumpBase::BeginSection(BinarySection section_code,
Offset size) {
- section_starts[static_cast<size_t>(section_code)] = state->offset;
+ section_starts_[static_cast<size_t>(section_code)] = state->offset;
return Result::Ok;
}
Result BinaryReaderObjdumpBase::BeginModule(uint32_t version) {
- switch (options->mode) {
+ switch (options_->mode) {
case ObjdumpMode::Headers:
printf("\n");
printf("Sections:\n\n");
@@ -93,8 +93,8 @@ Result BinaryReaderObjdumpBase::BeginModule(uint32_t version) {
printf("Code Disassembly:\n\n");
break;
case ObjdumpMode::Prepass: {
- const char* last_slash = strrchr(options->filename, '/');
- const char* last_backslash = strrchr(options->filename, '\\');
+ const char* last_slash = strrchr(options_->filename, '/');
+ const char* last_backslash = strrchr(options_->filename, '\\');
const char* basename;
if (last_slash && last_backslash) {
basename = std::max(last_slash, last_backslash) + 1;
@@ -103,7 +103,7 @@ Result BinaryReaderObjdumpBase::BeginModule(uint32_t version) {
} else if (last_backslash) {
basename = last_backslash + 1;
} else {
- basename = options->filename;
+ basename = options_->filename;
}
printf("%s:\tfile format wasm %#x\n", basename, version);
@@ -117,11 +117,11 @@ Result BinaryReaderObjdumpBase::BeginModule(uint32_t version) {
}
const char* BinaryReaderObjdumpBase::GetFunctionName(Index index) const {
- if (index >= objdump_state->function_names.size() ||
- objdump_state->function_names[index].empty())
+ if (index >= objdump_state_->function_names.size() ||
+ objdump_state_->function_names[index].empty())
return nullptr;
- return objdump_state->function_names[index].c_str();
+ return objdump_state_->function_names[index].c_str();
}
void BinaryReaderObjdumpBase::PrintRelocation(const Reloc& reloc,
@@ -147,7 +147,7 @@ void BinaryReaderObjdumpBase::PrintRelocation(const Reloc& reloc,
Result BinaryReaderObjdumpBase::OnRelocCount(Index count,
BinarySection section_code,
string_view section_name) {
- reloc_section = section_code;
+ reloc_section_ = section_code;
return Result::Ok;
}
@@ -165,8 +165,8 @@ class BinaryReaderObjdumpPrepass : public BinaryReaderObjdumpBase {
Result BinaryReaderObjdumpPrepass::OnFunctionName(Index index,
string_view name) {
- objdump_state->function_names.resize(index + 1);
- objdump_state->function_names[index] = name.to_string();
+ objdump_state_->function_names.resize(index + 1);
+ objdump_state_->function_names[index] = name.to_string();
return Result::Ok;
}
@@ -175,10 +175,10 @@ Result BinaryReaderObjdumpPrepass::OnReloc(RelocType type,
Index index,
uint32_t addend) {
BinaryReaderObjdumpBase::OnReloc(type, offset, index, addend);
- if (reloc_section == BinarySection::Code) {
- objdump_state->code_relocations.emplace_back(type, offset, index, addend);
- } else if (reloc_section == BinarySection::Data) {
- objdump_state->data_relocations.emplace_back(type, offset, index, addend);
+ if (reloc_section_ == BinarySection::Code) {
+ objdump_state_->code_relocations.emplace_back(type, offset, index, addend);
+ } else if (reloc_section_ == BinarySection::Data) {
+ objdump_state_->data_relocations.emplace_back(type, offset, index, addend);
}
return Result::Ok;
}
@@ -216,19 +216,19 @@ class BinaryReaderObjdumpDisassemble : public BinaryReaderObjdumpBase {
};
Result BinaryReaderObjdumpDisassemble::OnOpcode(Opcode opcode) {
- if (options->debug) {
+ if (options_->debug) {
const char* opcode_name = opcode.GetName();
printf("on_opcode: %#" PRIzx ": %s\n", state->offset, opcode_name);
}
if (last_opcode_end) {
if (state->offset != last_opcode_end + opcode.GetLength()) {
- Opcode missing_opcode = Opcode::FromCode(data[last_opcode_end]);
+ Opcode missing_opcode = Opcode::FromCode(data_[last_opcode_end]);
const char* opcode_name = missing_opcode.GetName();
fprintf(stderr,
"warning: %#" PRIzx " missing opcode callback at %#" PRIzx
" (%#02x=%s)\n",
- state->offset, last_opcode_end + 1, data[last_opcode_end],
+ state->offset, last_opcode_end + 1, data_[last_opcode_end],
opcode_name);
return Result::Error;
}
@@ -290,8 +290,9 @@ void BinaryReaderObjdumpDisassemble::LogOpcode(const uint8_t* data,
last_opcode_end = current_opcode_offset + data_size;
- if (options->relocs && next_reloc < objdump_state->code_relocations.size()) {
- const Reloc& reloc = objdump_state->code_relocations[next_reloc];
+ if (options_->relocs &&
+ next_reloc < objdump_state_->code_relocations.size()) {
+ const Reloc& reloc = objdump_state_->code_relocations[next_reloc];
Offset code_start = GetSectionStart(BinarySection::Code);
Offset abs_offset = code_start + reloc.offset;
if (last_opcode_end > abs_offset) {
@@ -302,36 +303,36 @@ void BinaryReaderObjdumpDisassemble::LogOpcode(const uint8_t* data,
}
Result BinaryReaderObjdumpDisassemble::OnOpcodeBare() {
- LogOpcode(data, 0, nullptr);
+ LogOpcode(data_, 0, nullptr);
return Result::Ok;
}
Result BinaryReaderObjdumpDisassemble::OnOpcodeIndex(Index value) {
Offset immediate_len = state->offset - current_opcode_offset;
- const char *name;
+ const char* name;
if (current_opcode == Opcode::Call && (name = GetFunctionName(value)))
- LogOpcode(data, immediate_len, "%d <%s>", value, name);
+ LogOpcode(data_, immediate_len, "%d <%s>", value, name);
else
- LogOpcode(data, immediate_len, "%d", value);
+ LogOpcode(data_, immediate_len, "%d", value);
return Result::Ok;
}
Result BinaryReaderObjdumpDisassemble::OnOpcodeUint32(uint32_t value) {
Offset immediate_len = state->offset - current_opcode_offset;
- LogOpcode(data, immediate_len, "%u", value);
+ LogOpcode(data_, immediate_len, "%u", value);
return Result::Ok;
}
Result BinaryReaderObjdumpDisassemble::OnOpcodeUint32Uint32(uint32_t value,
- uint32_t value2) {
+ uint32_t value2) {
Offset immediate_len = state->offset - current_opcode_offset;
- LogOpcode(data, immediate_len, "%lu %lu", value, value2);
+ LogOpcode(data_, immediate_len, "%lu %lu", value, value2);
return Result::Ok;
}
Result BinaryReaderObjdumpDisassemble::OnOpcodeUint64(uint64_t value) {
Offset immediate_len = state->offset - current_opcode_offset;
- LogOpcode(data, immediate_len, "%" PRId64, value);
+ LogOpcode(data_, immediate_len, "%" PRId64, value);
return Result::Ok;
}
@@ -339,7 +340,7 @@ Result BinaryReaderObjdumpDisassemble::OnOpcodeF32(uint32_t value) {
Offset immediate_len = state->offset - current_opcode_offset;
char buffer[WABT_MAX_FLOAT_HEX];
WriteFloatHex(buffer, sizeof(buffer), value);
- LogOpcode(data, immediate_len, buffer);
+ LogOpcode(data_, immediate_len, buffer);
return Result::Ok;
}
@@ -347,7 +348,7 @@ Result BinaryReaderObjdumpDisassemble::OnOpcodeF64(uint64_t value) {
Offset immediate_len = state->offset - current_opcode_offset;
char buffer[WABT_MAX_DOUBLE_HEX];
WriteDoubleHex(buffer, sizeof(buffer), value);
- LogOpcode(data, immediate_len, buffer);
+ LogOpcode(data_, immediate_len, buffer);
return Result::Ok;
}
@@ -357,7 +358,7 @@ Result BinaryReaderObjdumpDisassemble::OnBrTableExpr(
Index default_target_depth) {
Offset immediate_len = state->offset - current_opcode_offset;
/* TODO(sbc): Print targets */
- LogOpcode(data, immediate_len, nullptr);
+ LogOpcode(data_, immediate_len, nullptr);
return Result::Ok;
}
@@ -407,9 +408,9 @@ const char* type_name(Type type) {
Result BinaryReaderObjdumpDisassemble::OnOpcodeBlockSig(Index num_types,
Type* sig_types) {
if (num_types)
- LogOpcode(data, 1, "%s", type_name(*sig_types));
+ LogOpcode(data_, 1, "%s", type_name(*sig_types));
else
- LogOpcode(data, 1, nullptr);
+ LogOpcode(data_, 1, nullptr);
indent_level++;
return Result::Ok;
}
@@ -480,7 +481,6 @@ class BinaryReaderObjdump : public BinaryReaderObjdumpBase {
Index except_index,
TypeVector& sig) override;
-
Result OnFunctionCount(Index count) override;
Result OnFunction(Index index, Index sig_index) override;
@@ -551,12 +551,12 @@ class BinaryReaderObjdump : public BinaryReaderObjdumpBase {
Result OnDataAlignment(uint32_t data_alignment) override;
Result OnExceptionCount(Index count) override;
- Result OnExceptionType(Index index, TypeVector& sig) override;
+ Result OnExceptionType(Index index, TypeVector& sig) override;
private:
bool ShouldPrintDetails();
void PrintDetails(const char* fmt, ...);
- void PrintInitExpr(const InitExpr &expr);
+ void PrintInitExpr(const InitExpr& expr);
Result OnCount(Index count);
std::unique_ptr<FileStream> out_stream_;
@@ -577,7 +577,7 @@ Result BinaryReaderObjdump::BeginCustomSection(Offset size,
string_view section_name) {
PrintDetails(" - name: \"" PRIstringview "\"\n",
WABT_PRINTF_STRING_VIEW_ARG(section_name));
- if (options->mode == ObjdumpMode::Headers) {
+ if (options_->mode == ObjdumpMode::Headers) {
printf("\"" PRIstringview "\"\n",
WABT_PRINTF_STRING_VIEW_ARG(section_name));
}
@@ -591,29 +591,29 @@ Result BinaryReaderObjdump::BeginSection(BinarySection section_code,
const char* name = GetSectionName(section_code);
bool section_match =
- !options->section_name || !strcasecmp(options->section_name, name);
+ !options_->section_name || !strcasecmp(options_->section_name, name);
if (section_match)
- section_found = true;
+ section_found_ = true;
- switch (options->mode) {
+ switch (options_->mode) {
case ObjdumpMode::Headers:
- printf("%9s start=%#010" PRIzx " end=%#010" PRIzx
- " (size=%#010" PRIoffset ") ",
+ printf("%9s start=%#010" PRIzx " end=%#010" PRIzx " (size=%#010" PRIoffset
+ ") ",
name, state->offset, state->offset + size, size);
break;
case ObjdumpMode::Details:
if (section_match) {
if (section_code != BinarySection::Code)
printf("%s:\n", name);
- print_details = true;
+ print_details_ = true;
} else {
- print_details = false;
+ print_details_ = false;
}
break;
case ObjdumpMode::RawData:
if (section_match) {
printf("\nContents of section %s:\n", name);
- out_stream_->WriteMemoryDump(data + state->offset, size, state->offset,
+ out_stream_->WriteMemoryDump(data_ + state->offset, size, state->offset,
PrintChars::Yes);
}
break;
@@ -625,13 +625,13 @@ Result BinaryReaderObjdump::BeginSection(BinarySection section_code,
}
bool BinaryReaderObjdump::ShouldPrintDetails() {
- if (options->mode != ObjdumpMode::Details)
+ if (options_->mode != ObjdumpMode::Details)
return false;
- return print_details;
+ return print_details_;
}
-void WABT_PRINTF_FORMAT(2, 3)
- BinaryReaderObjdump::PrintDetails(const char* fmt, ...) {
+void WABT_PRINTF_FORMAT(2, 3) BinaryReaderObjdump::PrintDetails(const char* fmt,
+ ...) {
if (!ShouldPrintDetails())
return;
va_list args;
@@ -641,20 +641,20 @@ void WABT_PRINTF_FORMAT(2, 3)
}
Result BinaryReaderObjdump::OnCount(Index count) {
- if (options->mode == ObjdumpMode::Headers) {
+ if (options_->mode == ObjdumpMode::Headers) {
printf("count: %" PRIindex "\n", count);
}
return Result::Ok;
}
Result BinaryReaderObjdump::EndModule() {
- if (options->section_name && !section_found) {
- fprintf(stderr, "Section not found: %s\n", options->section_name);
+ if (options_->section_name && !section_found_) {
+ fprintf(stderr, "Section not found: %s\n", options_->section_name);
return Result::Error;
}
- if (options->relocs) {
- if (next_data_reloc_ != objdump_state->data_relocations.size()) {
+ if (options_->relocs) {
+ if (next_data_reloc_ != objdump_state_->data_relocations.size()) {
fprintf(stderr, "Data reloctions outside of segments\n");
return Result::Error;
}
@@ -707,7 +707,7 @@ Result BinaryReaderObjdump::OnFunctionBodyCount(Index count) {
}
Result BinaryReaderObjdump::OnStartFunction(Index func_index) {
- if (options->mode == ObjdumpMode::Headers) {
+ if (options_->mode == ObjdumpMode::Headers) {
printf("start: %" PRIindex "\n", func_index);
} else {
PrintDetails(" - start function: %" PRIindex "\n", func_index);
@@ -983,7 +983,7 @@ Result BinaryReaderObjdump::OnDataSegmentCount(Index count) {
Result BinaryReaderObjdump::BeginDataSegment(Index index, Index memory_index) {
// TODO(sbc): Display memory_index once multiple memories become a thing
- //PrintDetails(" - memory[%" PRIindex "]", memory_index);
+ // PrintDetails(" - memory[%" PRIindex "]", memory_index);
return Result::Ok;
}
@@ -1015,14 +1015,14 @@ Result BinaryReaderObjdump::OnDataSegmentData(Index index,
" - ");
// Print relocations from this segment.
- if (!options->relocs)
+ if (!options_->relocs)
return Result::Ok;
Offset data_start = GetSectionStart(BinarySection::Data);
Offset segment_start = state->offset - size;
Offset segment_offset = segment_start - data_start;
- while (next_data_reloc_ < objdump_state->data_relocations.size()) {
- const Reloc& reloc = objdump_state->data_relocations[next_data_reloc_];
+ while (next_data_reloc_ < objdump_state_->data_relocations.size()) {
+ const Reloc& reloc = objdump_state_->data_relocations[next_data_reloc_];
Offset abs_offset = data_start + reloc.offset;
if (abs_offset > state->offset)
break;
@@ -1045,7 +1045,7 @@ Result BinaryReaderObjdump::OnReloc(RelocType type,
Offset offset,
Index index,
uint32_t addend) {
- Offset total_offset = GetSectionStart(reloc_section) + offset;
+ Offset total_offset = GetSectionStart(reloc_section_) + offset;
PrintDetails(" - %-18s offset=%#08" PRIoffset "(file=%#08" PRIoffset
") index=%" PRIindex,
GetRelocTypeName(type), offset, total_offset, index);
@@ -1097,8 +1097,7 @@ Result BinaryReaderObjdump::OnExceptionCount(Index count) {
return OnCount(count);
}
-Result BinaryReaderObjdump::OnExceptionType(
- Index index, TypeVector& sig) {
+Result BinaryReaderObjdump::OnExceptionType(Index index, TypeVector& sig) {
if (!ShouldPrintDetails())
return Result::Ok;
printf(" - except[%" PRIindex "] (", index);
diff --git a/src/wat-writer.cc b/src/wat-writer.cc
index 47c60d3c..6bdb611e 100644
--- a/src/wat-writer.cc
+++ b/src/wat-writer.cc
@@ -174,7 +174,7 @@ class WatWriter {
const WriteWatOptions* options_ = nullptr;
const Module* module_ = nullptr;
const Func* current_func_ = nullptr;
- Stream* stream_;
+ Stream* stream_ = nullptr;
Result result_ = Result::Ok;
int indent_ = 0;
NextChar next_char_ = NextChar::None;