summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Smith <binjimin@gmail.com>2018-08-07 08:49:49 -0700
committerGitHub <noreply@github.com>2018-08-07 08:49:49 -0700
commit221a39bb62a8984f894331aa5081957d332fd353 (patch)
tree6da5a05c588e23866d154e353d4340561a4e903f
parentea279ce6f5e02411528344ddb1fdb227adf296e8 (diff)
downloadwabt-221a39bb62a8984f894331aa5081957d332fd353.tar.gz
wabt-221a39bb62a8984f894331aa5081957d332fd353.tar.bz2
wabt-221a39bb62a8984f894331aa5081957d332fd353.zip
Pass Option structs by const reference (#888)
-rw-r--r--src/binary-reader-interp.cc4
-rw-r--r--src/binary-reader-interp.h2
-rw-r--r--src/binary-reader-ir.cc7
-rw-r--r--src/binary-reader-ir.h2
-rw-r--r--src/binary-reader-objdump.cc6
-rw-r--r--src/binary-reader-opcnt.cc2
-rw-r--r--src/binary-reader-opcnt.h2
-rw-r--r--src/binary-reader.cc42
-rw-r--r--src/binary-reader.h2
-rw-r--r--src/binary-writer-spec.cc10
-rw-r--r--src/binary-writer-spec.h4
-rw-r--r--src/binary-writer.cc18
-rw-r--r--src/binary-writer.h2
-rw-r--r--src/c-writer.cc6
-rw-r--r--src/c-writer.h2
-rw-r--r--src/emscripten-helpers.cc12
-rw-r--r--src/test-interp.cc2
-rw-r--r--src/tools/spectest-interp.cc6
-rw-r--r--src/tools/wasm-interp.cc4
-rw-r--r--src/tools/wasm-opcodecnt.cc2
-rw-r--r--src/tools/wasm-validate.cc6
-rw-r--r--src/tools/wasm2c.cc8
-rw-r--r--src/tools/wasm2wat.cc8
-rw-r--r--src/tools/wast2json.cc4
-rw-r--r--src/tools/wat-desugar.cc2
-rw-r--r--src/tools/wat2wasm.cc5
-rw-r--r--src/validator.cc24
-rw-r--r--src/validator.h6
-rw-r--r--src/wast-parser.cc2
-rw-r--r--src/wat-writer.cc26
-rw-r--r--src/wat-writer.h2
31 files changed, 114 insertions, 116 deletions
diff --git a/src/binary-reader-interp.cc b/src/binary-reader-interp.cc
index 5e19720a..efcb6721 100644
--- a/src/binary-reader-interp.cc
+++ b/src/binary-reader-interp.cc
@@ -1631,7 +1631,7 @@ wabt::Result BinaryReaderInterp::EndModule() {
wabt::Result ReadBinaryInterp(Environment* env,
const void* data,
size_t size,
- const ReadBinaryOptions* options,
+ const ReadBinaryOptions& options,
ErrorHandler* error_handler,
DefinedModule** out_module) {
// Need to mark before taking ownership of env->istream.
@@ -1642,7 +1642,7 @@ wabt::Result ReadBinaryInterp(Environment* env,
DefinedModule* module = new DefinedModule();
BinaryReaderInterp reader(env, module, std::move(istream), error_handler,
- options->features);
+ options.features);
env->EmplaceBackModule(module);
wabt::Result result = ReadBinary(data, size, &reader, options);
diff --git a/src/binary-reader-interp.h b/src/binary-reader-interp.h
index 18058d2f..82043ce5 100644
--- a/src/binary-reader-interp.h
+++ b/src/binary-reader-interp.h
@@ -34,7 +34,7 @@ struct ReadBinaryOptions;
Result ReadBinaryInterp(interp::Environment* env,
const void* data,
size_t size,
- const ReadBinaryOptions* options,
+ const ReadBinaryOptions& options,
ErrorHandler*,
interp::DefinedModule** out_module);
diff --git a/src/binary-reader-ir.cc b/src/binary-reader-ir.cc
index 3207fc07..ec033960 100644
--- a/src/binary-reader-ir.cc
+++ b/src/binary-reader-ir.cc
@@ -1114,12 +1114,11 @@ Result BinaryReaderIR::OnExceptionType(Index index, TypeVector& sig) {
Result ReadBinaryIr(const char* filename,
const void* data,
size_t size,
- const ReadBinaryOptions* options,
+ const ReadBinaryOptions& options,
ErrorHandler* error_handler,
- struct Module* out_module) {
+ Module* out_module) {
BinaryReaderIR reader(out_module, filename, error_handler);
- Result result = ReadBinary(data, size, &reader, options);
- return result;
+ return ReadBinary(data, size, &reader, options);
}
} // namespace wabt
diff --git a/src/binary-reader-ir.h b/src/binary-reader-ir.h
index 7c4e4244..92de88cd 100644
--- a/src/binary-reader-ir.h
+++ b/src/binary-reader-ir.h
@@ -28,7 +28,7 @@ struct ReadBinaryOptions;
Result ReadBinaryIr(const char* filename,
const void* data,
size_t size,
- const ReadBinaryOptions* options,
+ const ReadBinaryOptions& options,
ErrorHandler*,
Module* out_module);
diff --git a/src/binary-reader-objdump.cc b/src/binary-reader-objdump.cc
index a9752920..0377ec50 100644
--- a/src/binary-reader-objdump.cc
+++ b/src/binary-reader-objdump.cc
@@ -1499,15 +1499,15 @@ Result ReadBinaryObjdump(const uint8_t* data,
switch (options->mode) {
case ObjdumpMode::Prepass: {
BinaryReaderObjdumpPrepass reader(data, size, options, state);
- return ReadBinary(data, size, &reader, &read_options);
+ return ReadBinary(data, size, &reader, read_options);
}
case ObjdumpMode::Disassemble: {
BinaryReaderObjdumpDisassemble reader(data, size, options, state);
- return ReadBinary(data, size, &reader, &read_options);
+ return ReadBinary(data, size, &reader, read_options);
}
default: {
BinaryReaderObjdump reader(data, size, options, state);
- return ReadBinary(data, size, &reader, &read_options);
+ return ReadBinary(data, size, &reader, read_options);
}
}
}
diff --git a/src/binary-reader-opcnt.cc b/src/binary-reader-opcnt.cc
index a5f041d5..0bdfe431 100644
--- a/src/binary-reader-opcnt.cc
+++ b/src/binary-reader-opcnt.cc
@@ -281,7 +281,7 @@ Result BinaryReaderOpcnt::OnEndFunc() {
Result ReadBinaryOpcnt(const void* data,
size_t size,
- const struct ReadBinaryOptions* options,
+ const ReadBinaryOptions& options,
OpcodeInfoCounts* counts) {
BinaryReaderOpcnt reader(counts);
return ReadBinary(data, size, &reader, options);
diff --git a/src/binary-reader-opcnt.h b/src/binary-reader-opcnt.h
index 912271ed..cfdd570c 100644
--- a/src/binary-reader-opcnt.h
+++ b/src/binary-reader-opcnt.h
@@ -85,7 +85,7 @@ typedef std::map<OpcodeInfo, size_t> OpcodeInfoCounts;
Result ReadBinaryOpcnt(const void* data,
size_t size,
- const struct ReadBinaryOptions* options,
+ const ReadBinaryOptions& options,
OpcodeInfoCounts* opcode_counts);
} // namespace wabt
diff --git a/src/binary-reader.cc b/src/binary-reader.cc
index 736e2099..3687b08f 100644
--- a/src/binary-reader.cc
+++ b/src/binary-reader.cc
@@ -44,11 +44,11 @@
} \
} while (0)
-#define ERROR_UNLESS_OPCODE_ENABLED(opcode) \
- do { \
- if (!opcode.IsEnabled(options_->features)) { \
- return ReportUnexpectedOpcode(opcode); \
- } \
+#define ERROR_UNLESS_OPCODE_ENABLED(opcode) \
+ do { \
+ if (!opcode.IsEnabled(options_.features)) { \
+ return ReportUnexpectedOpcode(opcode); \
+ } \
} while (0)
#define CALLBACK0(member) \
@@ -67,7 +67,7 @@ class BinaryReader {
BinaryReader(const void* data,
size_t size,
BinaryReaderDelegate* delegate,
- const ReadBinaryOptions* options);
+ const ReadBinaryOptions& options);
Result ReadModule();
@@ -147,7 +147,7 @@ class BinaryReader {
TypeVector param_types_;
TypeVector result_types_;
std::vector<Index> target_depths_;
- const ReadBinaryOptions* options_ = nullptr;
+ const ReadBinaryOptions& options_;
BinarySection last_known_section_ = BinarySection::Invalid;
bool did_read_names_section_ = false;
bool reading_custom_section_ = false;
@@ -173,11 +173,11 @@ class BinaryReader {
BinaryReader::BinaryReader(const void* data,
size_t size,
BinaryReaderDelegate* delegate,
- const ReadBinaryOptions* options)
+ const ReadBinaryOptions& options)
: read_end_(size),
state_(static_cast<const uint8_t*>(data), size),
- logging_delegate_(options->log_stream, delegate),
- delegate_(options->log_stream ? &logging_delegate_ : delegate),
+ logging_delegate_(options.log_stream, delegate),
+ delegate_(options.log_stream ? &logging_delegate_ : delegate),
options_(options),
last_known_section_(BinarySection::Invalid) {
delegate->OnSetState(&state_);
@@ -186,7 +186,7 @@ BinaryReader::BinaryReader(const void* data,
void WABT_PRINTF_FORMAT(2, 3) BinaryReader::PrintError(const char* format,
...) {
ErrorLevel error_level =
- reading_custom_section_ && !options_->fail_on_custom_section_error
+ reading_custom_section_ && !options_.fail_on_custom_section_error
? ErrorLevel::Warning
: ErrorLevel::Error;
@@ -373,7 +373,7 @@ bool BinaryReader::IsConcreteType(Type type) {
return true;
case Type::V128:
- return options_->features.simd_enabled();
+ return options_.features.simd_enabled();
default:
return false;
@@ -385,7 +385,7 @@ bool BinaryReader::IsBlockType(Type type) {
return true;
}
- if (!(options_->features.multi_value_enabled() && IsTypeIndex(type))) {
+ if (!(options_.features.multi_value_enabled() && IsTypeIndex(type))) {
return false;
}
@@ -1611,7 +1611,7 @@ Result BinaryReader::ReadCustomSection(Offset section_size) {
ValueRestoreGuard<bool, &BinaryReader::reading_custom_section_> guard(this);
reading_custom_section_ = true;
- if (options_->read_debug_names && section_name == WABT_BINARY_SECTION_NAME) {
+ if (options_.read_debug_names && section_name == WABT_BINARY_SECTION_NAME) {
CHECK_RESULT(ReadNameSection(section_size));
did_read_names_section_ = true;
} else if (section_name.rfind(WABT_BINARY_SECTION_RELOC, 0) == 0) {
@@ -1619,7 +1619,7 @@ Result BinaryReader::ReadCustomSection(Offset section_size) {
CHECK_RESULT(ReadRelocSection(section_size));
} else if (section_name == WABT_BINARY_SECTION_LINKING) {
CHECK_RESULT(ReadLinkingSection(section_size));
- } else if (options_->features.exceptions_enabled() &&
+ } else if (options_.features.exceptions_enabled() &&
section_name == WABT_BINARY_SECTION_EXCEPTION) {
CHECK_RESULT(ReadExceptionSection(section_size));
} else {
@@ -1658,7 +1658,7 @@ Result BinaryReader::ReadTypeSection(Offset section_size) {
Index num_results;
CHECK_RESULT(ReadCount(&num_results, "function result count"));
- ERROR_UNLESS(num_results <= 1 || options_->features.multi_value_enabled(),
+ ERROR_UNLESS(num_results <= 1 || options_.features.multi_value_enabled(),
"result count must be 0 or 1");
result_types_.resize(num_results);
@@ -1739,7 +1739,7 @@ Result BinaryReader::ReadImportSection(Offset section_size) {
}
case ExternalKind::Except: {
- ERROR_UNLESS(options_->features.exceptions_enabled(),
+ ERROR_UNLESS(options_.features.exceptions_enabled(),
"invalid import exception kind: exceptions not allowed");
TypeVector sig;
CHECK_RESULT(ReadExceptionType(sig));
@@ -1857,7 +1857,7 @@ Result BinaryReader::ReadExportSection(Offset section_size) {
break;
case ExternalKind::Except:
// Note: Can't check if index valid, exceptions section comes later.
- ERROR_UNLESS(options_->features.exceptions_enabled(),
+ ERROR_UNLESS(options_.features.exceptions_enabled(),
"invalid export exception kind: exceptions not allowed");
break;
}
@@ -2007,12 +2007,12 @@ Result BinaryReader::ReadSections() {
CALLBACK(BeginSection, section, section_size);
- bool stop_on_first_error = options_->stop_on_first_error;
+ bool stop_on_first_error = options_.stop_on_first_error;
Result section_result = Result::Error;
switch (section) {
case BinarySection::Custom:
section_result = ReadCustomSection(section_size);
- if (options_->fail_on_custom_section_error) {
+ if (options_.fail_on_custom_section_error) {
result |= section_result;
} else {
stop_on_first_error = false;
@@ -2110,7 +2110,7 @@ Result BinaryReader::ReadModule() {
Result ReadBinary(const void* data,
size_t size,
BinaryReaderDelegate* delegate,
- const ReadBinaryOptions* options) {
+ const ReadBinaryOptions& options) {
BinaryReader reader(data, size, delegate, options);
return reader.ReadModule();
}
diff --git a/src/binary-reader.h b/src/binary-reader.h
index c64b490e..c3506aa3 100644
--- a/src/binary-reader.h
+++ b/src/binary-reader.h
@@ -363,7 +363,7 @@ class BinaryReaderDelegate {
Result ReadBinary(const void* data,
size_t size,
BinaryReaderDelegate* reader,
- const ReadBinaryOptions* options);
+ const ReadBinaryOptions& options);
size_t ReadU32Leb128(const uint8_t* ptr,
const uint8_t* end,
diff --git a/src/binary-writer-spec.cc b/src/binary-writer-spec.cc
index a2d8845c..ded6fa2f 100644
--- a/src/binary-writer-spec.cc
+++ b/src/binary-writer-spec.cc
@@ -39,7 +39,7 @@ class BinaryWriterSpec {
WriteBinarySpecStreamFactory module_stream_factory,
string_view source_filename,
string_view module_filename_noext,
- const WriteBinaryOptions* options);
+ const WriteBinaryOptions& options);
Result WriteScript(const Script& script);
@@ -68,7 +68,7 @@ class BinaryWriterSpec {
WriteBinarySpecStreamFactory module_stream_factory_;
std::string source_filename_;
std::string module_filename_noext_;
- const WriteBinaryOptions* options_ = nullptr;
+ const WriteBinaryOptions& options_;
Result result_ = Result::Ok;
size_t num_modules_ = 0;
};
@@ -78,7 +78,7 @@ BinaryWriterSpec::BinaryWriterSpec(
WriteBinarySpecStreamFactory module_stream_factory,
string_view source_filename,
string_view module_filename_noext,
- const WriteBinaryOptions* options)
+ const WriteBinaryOptions& options)
: json_stream_(json_stream),
module_stream_factory_(module_stream_factory),
source_filename_(source_filename),
@@ -514,7 +514,7 @@ Result WriteBinarySpecScript(Stream* json_stream,
Script* script,
string_view source_filename,
string_view module_filename_noext,
- const WriteBinaryOptions* options) {
+ const WriteBinaryOptions& options) {
BinaryWriterSpec binary_writer_spec(json_stream, module_stream_factory,
source_filename, module_filename_noext,
options);
@@ -526,7 +526,7 @@ Result WriteBinarySpecScript(
Script* script,
string_view source_filename,
string_view module_filename_noext,
- const WriteBinaryOptions* options,
+ const WriteBinaryOptions& options,
std::vector<FilenameMemoryStreamPair>* out_module_streams,
Stream* log_stream) {
WriteBinarySpecStreamFactory module_stream_factory =
diff --git a/src/binary-writer-spec.h b/src/binary-writer-spec.h
index 464b0e5e..197d6f2c 100644
--- a/src/binary-writer-spec.h
+++ b/src/binary-writer-spec.h
@@ -43,7 +43,7 @@ Result WriteBinarySpecScript(Stream* json_stream,
Script*,
string_view source_filename,
string_view module_filename_noext,
- const WriteBinaryOptions*);
+ const WriteBinaryOptions&);
// Convenience function for producing MemoryStream outputs all modules.
Result WriteBinarySpecScript(
@@ -51,7 +51,7 @@ Result WriteBinarySpecScript(
Script*,
string_view source_filename,
string_view module_filename_noext,
- const WriteBinaryOptions*,
+ const WriteBinaryOptions&,
std::vector<FilenameMemoryStreamPair>* out_module_streams,
Stream* log_stream = nullptr);
diff --git a/src/binary-writer.cc b/src/binary-writer.cc
index 24543da2..d1cb052c 100644
--- a/src/binary-writer.cc
+++ b/src/binary-writer.cc
@@ -107,7 +107,7 @@ class BinaryWriter {
public:
BinaryWriter(Stream*,
- const WriteBinaryOptions* options,
+ const WriteBinaryOptions& options,
const Module* module);
Result WriteModule();
@@ -148,7 +148,7 @@ class BinaryWriter {
void WriteLinkingSection();
Stream* stream_;
- const WriteBinaryOptions* options_;
+ const WriteBinaryOptions& options_;
const Module* module_;
std::unordered_map<std::string, Index> symtab_;
@@ -177,7 +177,7 @@ static uint8_t log2_u32(uint32_t x) {
}
BinaryWriter::BinaryWriter(Stream* stream,
- const WriteBinaryOptions* options,
+ const WriteBinaryOptions& options,
const Module* module)
: stream_(stream), options_(options), module_(module) {}
@@ -198,7 +198,7 @@ Offset BinaryWriter::WriteU32Leb128Space(Offset leb_size_guess,
uint8_t data[MAX_U32_LEB128_BYTES] = {0};
Offset result = stream_->offset();
Offset bytes_to_write =
- options_->canonicalize_lebs ? leb_size_guess : MAX_U32_LEB128_BYTES;
+ options_.canonicalize_lebs ? leb_size_guess : MAX_U32_LEB128_BYTES;
stream_->WriteData(data, bytes_to_write, desc);
return result;
}
@@ -206,7 +206,7 @@ Offset BinaryWriter::WriteU32Leb128Space(Offset leb_size_guess,
Offset BinaryWriter::WriteFixupU32Leb128Size(Offset offset,
Offset leb_size_guess,
const char* desc) {
- if (options_->canonicalize_lebs) {
+ if (options_.canonicalize_lebs) {
Offset size = stream_->offset() - offset - leb_size_guess;
Offset leb_size = U32Leb128Length(size);
Offset delta = leb_size - leb_size_guess;
@@ -348,7 +348,7 @@ void BinaryWriter::AddReloc(RelocType reloc_type, Index index) {
void BinaryWriter::WriteU32Leb128WithReloc(Index index,
const char* desc,
RelocType reloc_type) {
- if (options_->relocatable) {
+ if (options_.relocatable) {
AddReloc(reloc_type, index);
WriteFixedU32Leb128(stream_, index, desc);
} else {
@@ -969,7 +969,7 @@ Result BinaryWriter::WriteModule() {
EndSection();
}
- if (options_->write_debug_names) {
+ if (options_.write_debug_names) {
std::vector<std::string> index_to_name;
char desc[100];
@@ -1041,7 +1041,7 @@ Result BinaryWriter::WriteModule() {
EndSection();
}
- if (options_->relocatable) {
+ if (options_.relocatable) {
WriteLinkingSection();
for (RelocSection& section : reloc_sections_) {
WriteRelocSection(&section);
@@ -1055,7 +1055,7 @@ Result BinaryWriter::WriteModule() {
Result WriteBinaryModule(Stream* stream,
const Module* module,
- const WriteBinaryOptions* options) {
+ const WriteBinaryOptions& options) {
BinaryWriter binary_writer(stream, options, module);
return binary_writer.WriteModule();
}
diff --git a/src/binary-writer.h b/src/binary-writer.h
index aae02d3c..dc571f46 100644
--- a/src/binary-writer.h
+++ b/src/binary-writer.h
@@ -32,7 +32,7 @@ struct WriteBinaryOptions {
bool write_debug_names = false;
};
-Result WriteBinaryModule(Stream*, const Module*, const WriteBinaryOptions*);
+Result WriteBinaryModule(Stream*, const Module*, const WriteBinaryOptions&);
void WriteType(Stream* stream, Type type);
diff --git a/src/c-writer.cc b/src/c-writer.cc
index 0c969d52..46f06463 100644
--- a/src/c-writer.cc
+++ b/src/c-writer.cc
@@ -124,7 +124,7 @@ class CWriter {
CWriter(Stream* c_stream,
Stream* h_stream,
const char* header_name,
- const WriteCOptions* options)
+ const WriteCOptions& options)
: options_(options),
c_stream_(c_stream),
h_stream_(h_stream),
@@ -266,7 +266,7 @@ class CWriter {
void Write(const SimdLaneOpExpr&);
void Write(const SimdShuffleOpExpr&);
- const WriteCOptions* options_ = nullptr;
+ const WriteCOptions& options_;
const Module* module_ = nullptr;
const Func* func_ = nullptr;
Stream* stream_ = nullptr;
@@ -2286,7 +2286,7 @@ Result WriteC(Stream* c_stream,
Stream* h_stream,
const char* header_name,
const Module* module,
- const WriteCOptions* options) {
+ const WriteCOptions& options) {
CWriter c_writer(c_stream, h_stream, header_name, options);
return c_writer.WriteModule(*module);
}
diff --git a/src/c-writer.h b/src/c-writer.h
index 3b4278aa..8b3b44d2 100644
--- a/src/c-writer.h
+++ b/src/c-writer.h
@@ -30,7 +30,7 @@ Result WriteC(Stream* c_stream,
Stream* h_stream,
const char* header_name,
const Module*,
- const WriteCOptions*);
+ const WriteCOptions&);
} // namespace wabt
diff --git a/src/emscripten-helpers.cc b/src/emscripten-helpers.cc
index 75afcf22..a61069fc 100644
--- a/src/emscripten-helpers.cc
+++ b/src/emscripten-helpers.cc
@@ -115,7 +115,7 @@ WabtReadBinaryResult* wabt_read_binary(
// TODO(binji): Pass through from wabt_read_binary parameter.
const char* filename = "<binary>";
result->result =
- wabt::ReadBinaryIr(filename, data, size, &options, error_handler, module);
+ wabt::ReadBinaryIr(filename, data, size, options, error_handler, module);
result->module.reset(module);
return result;
}
@@ -132,7 +132,7 @@ wabt::Result::Enum wabt_validate_module(
wabt::Module* module,
wabt::ErrorHandlerBuffer* error_handler) {
wabt::ValidateOptions options;
- return ValidateModule(lexer, module, error_handler, &options);
+ return ValidateModule(lexer, module, error_handler, options);
}
wabt::Result::Enum wabt_validate_script(
@@ -140,7 +140,7 @@ wabt::Result::Enum wabt_validate_script(
wabt::Script* script,
wabt::ErrorHandlerBuffer* error_handler) {
wabt::ValidateOptions options;
- return ValidateScript(lexer, script, error_handler, &options);
+ return ValidateScript(lexer, script, error_handler, options);
}
WabtWriteScriptResult* wabt_write_binary_spec_script(
@@ -168,7 +168,7 @@ WabtWriteScriptResult* wabt_write_binary_spec_script(
WabtWriteScriptResult* result = new WabtWriteScriptResult();
result->result = WriteBinarySpecScript(&json_stream, script, source_filename,
- module_filename_noext, &options,
+ module_filename_noext, options,
&module_streams, log_stream_p);
if (result->result == wabt::Result::Ok) {
@@ -205,7 +205,7 @@ WabtWriteModuleResult* wabt_write_binary_module(wabt::Module* module,
wabt::MemoryStream stream(log ? &log_stream : nullptr);
WabtWriteModuleResult* result = new WabtWriteModuleResult();
- result->result = WriteBinaryModule(&stream, module, &options);
+ result->result = WriteBinaryModule(&stream, module, options);
if (result->result == wabt::Result::Ok) {
result->buffer = stream.ReleaseOutputBuffer();
result->log_buffer = log ? log_stream.ReleaseOutputBuffer() : nullptr;
@@ -222,7 +222,7 @@ WabtWriteModuleResult* wabt_write_text_module(wabt::Module* module,
wabt::MemoryStream stream;
WabtWriteModuleResult* result = new WabtWriteModuleResult();
- result->result = WriteWat(&stream, module, &options);
+ result->result = WriteWat(&stream, module, options);
if (result->result == wabt::Result::Ok) {
result->buffer = stream.ReleaseOutputBuffer();
}
diff --git a/src/test-interp.cc b/src/test-interp.cc
index 9fb0430d..fdae50ba 100644
--- a/src/test-interp.cc
+++ b/src/test-interp.cc
@@ -84,7 +84,7 @@ class HostTrapTest : public ::testing::Test {
ErrorHandlerFile error_handler(Location::Type::Binary);
interp::DefinedModule* module = nullptr;
ReadBinaryOptions options;
- Result result = ReadBinaryInterp(&env_, data.data(), data.size(), &options,
+ Result result = ReadBinaryInterp(&env_, data.data(), data.size(), options,
&error_handler, &module);
EXPECT_EQ(Result::Ok, result);
diff --git a/src/tools/spectest-interp.cc b/src/tools/spectest-interp.cc
index 8d211d22..d7ff4e4c 100644
--- a/src/tools/spectest-interp.cc
+++ b/src/tools/spectest-interp.cc
@@ -1073,7 +1073,7 @@ wabt::Result CommandRunner::ReadInvalidTextModule(string_view module_filename,
ValidateOptions options(s_features);
// Don't do a full validation, just validate the function signatures.
result =
- ValidateFuncSignatures(lexer.get(), module, error_handler, &options);
+ ValidateFuncSignatures(lexer.get(), module, error_handler, options);
}
}
return result;
@@ -1095,8 +1095,8 @@ static wabt::Result ReadModule(string_view module_filename,
const bool kFailOnCustomSectionError = true;
ReadBinaryOptions options(s_features, s_log_stream.get(), kReadDebugNames,
kStopOnFirstError, kFailOnCustomSectionError);
- result = ReadBinaryInterp(env, file_data.data(), file_data.size(),
- &options, error_handler, out_module);
+ result = ReadBinaryInterp(env, file_data.data(), file_data.size(), options,
+ error_handler, out_module);
if (Succeeded(result)) {
if (s_verbose) {
diff --git a/src/tools/wasm-interp.cc b/src/tools/wasm-interp.cc
index 3f3cda4c..160952ce 100644
--- a/src/tools/wasm-interp.cc
+++ b/src/tools/wasm-interp.cc
@@ -142,8 +142,8 @@ static wabt::Result ReadModule(const char* module_filename,
const bool kFailOnCustomSectionError = true;
ReadBinaryOptions options(s_features, s_log_stream.get(), kReadDebugNames,
kStopOnFirstError, kFailOnCustomSectionError);
- result = ReadBinaryInterp(env, file_data.data(), file_data.size(),
- &options, error_handler, out_module);
+ result = ReadBinaryInterp(env, file_data.data(), file_data.size(), options,
+ error_handler, out_module);
if (Succeeded(result)) {
if (s_verbose) {
diff --git a/src/tools/wasm-opcodecnt.cc b/src/tools/wasm-opcodecnt.cc
index af418c88..087f4e63 100644
--- a/src/tools/wasm-opcodecnt.cc
+++ b/src/tools/wasm-opcodecnt.cc
@@ -156,7 +156,7 @@ int ProgramMain(int argc, char** argv) {
if (Succeeded(result)) {
OpcodeInfoCounts counts;
result = ReadBinaryOpcnt(file_data.data(), file_data.size(),
- &s_read_binary_options, &counts);
+ s_read_binary_options, &counts);
if (Succeeded(result)) {
stream.Writef("Opcode counts:\n");
WriteCounts(stream, counts);
diff --git a/src/tools/wasm-validate.cc b/src/tools/wasm-validate.cc
index 8b42dfae..4cbd5605 100644
--- a/src/tools/wasm-validate.cc
+++ b/src/tools/wasm-validate.cc
@@ -82,12 +82,12 @@ int ProgramMain(int argc, char** argv) {
ReadBinaryOptions options(s_features, s_log_stream.get(),
s_read_debug_names, kStopOnFirstError,
s_fail_on_custom_section_error);
- result = ReadBinaryIr(s_infile.c_str(), file_data.data(),
- file_data.size(), &options, &error_handler, &module);
+ result = ReadBinaryIr(s_infile.c_str(), file_data.data(), file_data.size(),
+ options, &error_handler, &module);
if (Succeeded(result)) {
WastLexer* lexer = nullptr;
ValidateOptions options(s_features);
- result = ValidateModule(lexer, &module, &error_handler, &options);
+ result = ValidateModule(lexer, &module, &error_handler, options);
}
}
return result != Result::Ok;
diff --git a/src/tools/wasm2c.cc b/src/tools/wasm2c.cc
index 0d6654cb..6748cf0c 100644
--- a/src/tools/wasm2c.cc
+++ b/src/tools/wasm2c.cc
@@ -121,12 +121,12 @@ int ProgramMain(int argc, char** argv) {
s_read_debug_names, kStopOnFirstError,
kFailOnCustomSectionError);
result = ReadBinaryIr(s_infile.c_str(), file_data.data(), file_data.size(),
- &options, &error_handler, &module);
+ options, &error_handler, &module);
if (Succeeded(result)) {
if (Succeeded(result)) {
ValidateOptions options(s_features);
WastLexer* lexer = nullptr;
- result = ValidateModule(lexer, &module, &error_handler, &options);
+ result = ValidateModule(lexer, &module, &error_handler, options);
result |= GenerateNames(&module);
}
@@ -144,11 +144,11 @@ int ProgramMain(int argc, char** argv) {
FileStream c_stream(s_outfile.c_str());
FileStream h_stream(header_name);
result = WriteC(&c_stream, &h_stream, header_name.c_str(), &module,
- &s_write_c_options);
+ s_write_c_options);
} else {
FileStream stream(stdout);
result =
- WriteC(&stream, &stream, "wasm.h", &module, &s_write_c_options);
+ WriteC(&stream, &stream, "wasm.h", &module, s_write_c_options);
}
}
}
diff --git a/src/tools/wasm2wat.cc b/src/tools/wasm2wat.cc
index 0263f2c5..03a68e1c 100644
--- a/src/tools/wasm2wat.cc
+++ b/src/tools/wasm2wat.cc
@@ -113,13 +113,13 @@ int ProgramMain(int argc, char** argv) {
ReadBinaryOptions options(s_features, s_log_stream.get(),
s_read_debug_names, kStopOnFirstError,
s_fail_on_custom_section_error);
- result = ReadBinaryIr(s_infile.c_str(), file_data.data(),
- file_data.size(), &options, &error_handler, &module);
+ result = ReadBinaryIr(s_infile.c_str(), file_data.data(), file_data.size(),
+ options, &error_handler, &module);
if (Succeeded(result)) {
if (Succeeded(result) && s_validate) {
WastLexer* lexer = nullptr;
ValidateOptions options(s_features);
- result = ValidateModule(lexer, &module, &error_handler, &options);
+ result = ValidateModule(lexer, &module, &error_handler, options);
}
if (s_generate_names) {
@@ -136,7 +136,7 @@ int ProgramMain(int argc, char** argv) {
if (Succeeded(result)) {
FileStream stream(!s_outfile.empty() ? FileStream(s_outfile)
: FileStream(stdout));
- result = WriteWat(&stream, &module, &s_write_wat_options);
+ result = WriteWat(&stream, &module, s_write_wat_options);
}
}
}
diff --git a/src/tools/wast2json.cc b/src/tools/wast2json.cc
index aa200136..ca047ec3 100644
--- a/src/tools/wast2json.cc
+++ b/src/tools/wast2json.cc
@@ -112,7 +112,7 @@ int ProgramMain(int argc, char** argv) {
if (Succeeded(result) && s_validate) {
ValidateOptions options(s_features);
result =
- ValidateScript(lexer.get(), script.get(), &error_handler, &options);
+ ValidateScript(lexer.get(), script.get(), &error_handler, options);
}
if (Succeeded(result)) {
@@ -123,7 +123,7 @@ int ProgramMain(int argc, char** argv) {
StripExtension(s_outfile ? s_outfile : s_infile).to_string();
result = WriteBinarySpecScript(
&json_stream, script.get(), s_infile, module_filename_noext,
- &s_write_binary_options, &module_streams, s_log_stream.get());
+ s_write_binary_options, &module_streams, s_log_stream.get());
if (s_outfile) {
json_stream.WriteToFile(s_outfile);
diff --git a/src/tools/wat-desugar.cc b/src/tools/wat-desugar.cc
index 01125093..9594f537 100644
--- a/src/tools/wat-desugar.cc
+++ b/src/tools/wat-desugar.cc
@@ -108,7 +108,7 @@ int ProgramMain(int argc, char** argv) {
if (Succeeded(result)) {
FileStream stream(s_outfile ? FileStream(s_outfile) : FileStream(stdout));
- result = WriteWat(&stream, module, &s_write_wat_options);
+ result = WriteWat(&stream, module, s_write_wat_options);
}
}
diff --git a/src/tools/wat2wasm.cc b/src/tools/wat2wasm.cc
index 0268011f..c9f554c2 100644
--- a/src/tools/wat2wasm.cc
+++ b/src/tools/wat2wasm.cc
@@ -143,13 +143,12 @@ int ProgramMain(int argc, char** argv) {
if (Succeeded(result) && s_validate) {
ValidateOptions options(s_features);
result =
- ValidateModule(lexer.get(), module.get(), &error_handler, &options);
+ ValidateModule(lexer.get(), module.get(), &error_handler, options);
}
if (Succeeded(result)) {
MemoryStream stream(s_log_stream.get());
- result =
- WriteBinaryModule(&stream, module.get(), &s_write_binary_options);
+ result = WriteBinaryModule(&stream, module.get(), s_write_binary_options);
if (Succeeded(result)) {
if (s_outfile.empty()) {
diff --git a/src/validator.cc b/src/validator.cc
index 880caca9..d63e6a3c 100644
--- a/src/validator.cc
+++ b/src/validator.cc
@@ -41,7 +41,7 @@ class Validator : public ExprVisitor::Delegate {
Validator(ErrorHandler*,
WastLexer*,
const Script*,
- const ValidateOptions* options);
+ const ValidateOptions& options);
Result CheckModule(const Module* module);
Result CheckScript(const Script* script);
@@ -199,7 +199,7 @@ class Validator : public ExprVisitor::Delegate {
void CheckExcept(const Location* loc, const Exception* Except);
Result CheckExceptVar(const Var* var, const Exception** out_except);
- const ValidateOptions* options_ = nullptr;
+ const ValidateOptions& options_;
ErrorHandler* error_handler_ = nullptr;
WastLexer* lexer_ = nullptr;
const Script* script_ = nullptr;
@@ -219,7 +219,7 @@ class Validator : public ExprVisitor::Delegate {
Validator::Validator(ErrorHandler* error_handler,
WastLexer* lexer,
const Script* script,
- const ValidateOptions* options)
+ const ValidateOptions& options)
: options_(options),
error_handler_(error_handler),
lexer_(lexer),
@@ -492,11 +492,11 @@ void Validator::CheckBlockDeclaration(const Location* loc,
Opcode opcode,
const BlockDeclaration* decl) {
if (decl->sig.GetNumParams() > 0 &&
- !options_->features.multi_value_enabled()) {
+ !options_.features.multi_value_enabled()) {
PrintError(loc, "%s params not currently supported.", opcode.GetName());
}
if (decl->sig.GetNumResults() > 1 &&
- !options_->features.multi_value_enabled()) {
+ !options_.features.multi_value_enabled()) {
PrintError(loc, "multiple %s results not currently supported.",
opcode.GetName());
}
@@ -869,7 +869,7 @@ void Validator::CheckFuncSignature(const Location* loc,
void Validator::CheckFunc(const Location* loc, const Func* func) {
current_func_ = func;
CheckFuncSignature(loc, func->decl);
- if (!options_->features.multi_value_enabled() && func->GetNumResults() > 1) {
+ if (!options_.features.multi_value_enabled() && func->GetNumResults() > 1) {
PrintError(loc, "multiple result values not currently supported.");
// Don't run any other checks, the won't test the result_type properly.
return;
@@ -1004,7 +1004,7 @@ void Validator::CheckMemory(const Location* loc, const Memory* memory) {
CheckLimits(loc, &memory->page_limits, WABT_MAX_PAGES, "pages");
if (memory->page_limits.is_shared) {
- if (!options_->features.threads_enabled()) {
+ if (!options_.features.threads_enabled()) {
PrintError(loc, "memories may not be shared");
} else if (!memory->page_limits.has_max) {
PrintError(loc, "shared memories must have max sizes");
@@ -1055,7 +1055,7 @@ void Validator::CheckImport(const Location* loc, const Import* import) {
case ExternalKind::Global: {
auto* global_import = cast<GlobalImport>(import);
if (global_import->global.mutable_ &&
- !options_->features.mutable_globals_enabled()) {
+ !options_.features.mutable_globals_enabled()) {
PrintError(loc, "mutable globals cannot be imported");
}
++num_imported_globals_;
@@ -1082,7 +1082,7 @@ void Validator::CheckExport(const Location* loc, const Export* export_) {
case ExternalKind::Global: {
const Global* global;
if (Succeeded(CheckGlobalVar(&export_->var, &global, nullptr))) {
- if (global->mutable_ && !options_->features.mutable_globals_enabled()) {
+ if (global->mutable_ && !options_.features.mutable_globals_enabled()) {
PrintError(&export_->var.loc, "mutable globals cannot be exported");
}
}
@@ -1435,7 +1435,7 @@ Result Validator::CheckAllFuncSignatures(const Module* module) {
Result ValidateScript(WastLexer* lexer,
const Script* script,
ErrorHandler* error_handler,
- const ValidateOptions* options) {
+ const ValidateOptions& options) {
Validator validator(error_handler, lexer, script, options);
return validator.CheckScript(script);
@@ -1444,7 +1444,7 @@ Result ValidateScript(WastLexer* lexer,
Result ValidateModule(WastLexer* lexer,
const Module* module,
ErrorHandler* error_handler,
- const ValidateOptions* options) {
+ const ValidateOptions& options) {
Validator validator(error_handler, lexer, nullptr, options);
return validator.CheckModule(module);
@@ -1453,7 +1453,7 @@ Result ValidateModule(WastLexer* lexer,
Result ValidateFuncSignatures(WastLexer* lexer,
const Module* module,
ErrorHandler* error_handler,
- const ValidateOptions* options) {
+ const ValidateOptions& options) {
Validator validator(error_handler, lexer, nullptr, options);
return validator.CheckAllFuncSignatures(module);
diff --git a/src/validator.h b/src/validator.h
index 6250aa94..14cf8988 100644
--- a/src/validator.h
+++ b/src/validator.h
@@ -38,11 +38,11 @@ struct ValidateOptions {
Result ValidateScript(WastLexer*,
const Script*,
ErrorHandler*,
- const ValidateOptions*);
+ const ValidateOptions&);
Result ValidateModule(WastLexer*,
const Module*,
ErrorHandler*,
- const ValidateOptions*);
+ const ValidateOptions&);
// Validate that all functions that have an explicit function signature and a
// function type use match.
@@ -54,7 +54,7 @@ Result ValidateModule(WastLexer*,
Result ValidateFuncSignatures(WastLexer*,
const Module*,
ErrorHandler*,
- const ValidateOptions*);
+ const ValidateOptions&);
} // namespace wabt
diff --git a/src/wast-parser.cc b/src/wast-parser.cc
index 2e1d1f1d..1bb5229b 100644
--- a/src/wast-parser.cc
+++ b/src/wast-parser.cc
@@ -2208,7 +2208,7 @@ Result WastParser::ParseModuleCommand(Script* script, CommandPtr* out_command) {
ReadBinaryOptions options;
BinaryErrorHandlerModule error_handler(&bsm->loc, this);
const char* filename = "<text>";
- ReadBinaryIr(filename, bsm->data.data(), bsm->data.size(), &options,
+ ReadBinaryIr(filename, bsm->data.data(), bsm->data.size(), options,
&error_handler, &module);
module.name = bsm->name;
module.loc = bsm->loc;
diff --git a/src/wat-writer.cc b/src/wat-writer.cc
index 0987c617..3306e8a3 100644
--- a/src/wat-writer.cc
+++ b/src/wat-writer.cc
@@ -111,7 +111,7 @@ struct Label {
class WatWriter {
public:
- WatWriter(Stream* stream, const WriteWatOptions* options)
+ WatWriter(Stream* stream, const WriteWatOptions& options)
: options_(options), stream_(stream) {}
Result WriteModule(const Module& module);
@@ -196,7 +196,7 @@ class WatWriter {
void BuildInlineImportMap();
void WriteInlineImport(ExternalKind, Index);
- const WriteWatOptions* options_ = nullptr;
+ const WriteWatOptions& options_;
const Module* module_ = nullptr;
const Func* current_func_ = nullptr;
Stream* stream_ = nullptr;
@@ -1290,7 +1290,7 @@ void WatWriter::WriteBeginFunc(const Func& func) {
//
// Note that the text format does not allow including the param/result
// explicitly when using the "(import..." syntax (#1 and #2).
- if (options_->inline_import || !func.decl.has_func_type) {
+ if (options_.inline_import || !func.decl.has_func_type) {
WriteFuncSigSpace(func.decl.sig);
}
}
@@ -1311,7 +1311,7 @@ void WatWriter::WriteFunc(const Func& func) {
label_stack_.emplace_back(LabelType::Func, std::string(), TypeVector(),
func.decl.sig.result_types);
current_func_ = &func;
- if (options_->fold_exprs) {
+ if (options_.fold_exprs) {
WriteFoldedExprList(func.exprs);
FlushExprTreeStack();
} else {
@@ -1404,7 +1404,7 @@ void WatWriter::WriteDataSegment(const DataSegment& segment) {
}
void WatWriter::WriteImport(const Import& import) {
- if (!options_->inline_import) {
+ if (!options_.inline_import) {
WriteOpenSpace("import");
WriteQuotedString(import.module_name, NextChar::Space);
WriteQuotedString(import.field_name, NextChar::Space);
@@ -1435,7 +1435,7 @@ void WatWriter::WriteImport(const Import& import) {
break;
}
- if (options_->inline_import) {
+ if (options_.inline_import) {
WriteNewline(NO_FORCE_NEWLINE);
} else {
WriteCloseNewline();
@@ -1443,7 +1443,7 @@ void WatWriter::WriteImport(const Import& import) {
}
void WatWriter::WriteExport(const Export& export_) {
- if (options_->inline_export && IsInlineExport(export_)) {
+ if (options_.inline_export && IsInlineExport(export_)) {
return;
}
WriteOpenSpace("export");
@@ -1523,7 +1523,7 @@ Result WatWriter::WriteModule(const Module& module) {
}
void WatWriter::BuildInlineExportMap() {
- if (!options_->inline_export) {
+ if (!options_.inline_export) {
return;
}
@@ -1540,7 +1540,7 @@ void WatWriter::BuildInlineExportMap() {
//
// (func (export "e") (import "module" "field"))
//
- if (!options_->inline_import && module_->IsImport(*export_)) {
+ if (!options_.inline_import && module_->IsImport(*export_)) {
continue;
}
@@ -1574,7 +1574,7 @@ void WatWriter::BuildInlineExportMap() {
}
void WatWriter::WriteInlineExports(ExternalKind kind, Index index) {
- if (!options_->inline_export) {
+ if (!options_.inline_export) {
return;
}
@@ -1616,7 +1616,7 @@ bool WatWriter::IsInlineExport(const Export& export_) {
}
void WatWriter::BuildInlineImportMap() {
- if (!options_->inline_import) {
+ if (!options_.inline_import) {
return;
}
@@ -1627,7 +1627,7 @@ void WatWriter::BuildInlineImportMap() {
}
void WatWriter::WriteInlineImport(ExternalKind kind, Index index) {
- if (!options_->inline_import) {
+ if (!options_.inline_import) {
return;
}
@@ -1648,7 +1648,7 @@ void WatWriter::WriteInlineImport(ExternalKind kind, Index index) {
Result WriteWat(Stream* stream,
const Module* module,
- const WriteWatOptions* options) {
+ const WriteWatOptions& options) {
WatWriter wat_writer(stream, options);
return wat_writer.WriteModule(*module);
}
diff --git a/src/wat-writer.h b/src/wat-writer.h
index f29fa129..ec8a3eeb 100644
--- a/src/wat-writer.h
+++ b/src/wat-writer.h
@@ -30,7 +30,7 @@ struct WriteWatOptions {
bool inline_import = false;
};
-Result WriteWat(Stream*, const Module*, const WriteWatOptions*);
+Result WriteWat(Stream*, const Module*, const WriteWatOptions&);
} // namespace wabt