summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/binary-reader-linker.cc4
-rw-r--r--src/binary-reader-linker.h8
-rw-r--r--src/binary-reader-objdump.cc1
-rw-r--r--src/binary-reader-objdump.h1
-rw-r--r--src/binary-reader.cc15
-rw-r--r--src/tools/wasm-link.cc31
-rw-r--r--src/tools/wasmdump.cc19
7 files changed, 50 insertions, 29 deletions
diff --git a/src/binary-reader-linker.cc b/src/binary-reader-linker.cc
index b83a2690..c0e3f933 100644
--- a/src/binary-reader-linker.cc
+++ b/src/binary-reader-linker.cc
@@ -289,7 +289,8 @@ static Result on_function_name(uint32_t index,
return Result::Ok;
}
-Result read_binary_linker(LinkerInputBinary* input_info) {
+Result read_binary_linker(LinkerInputBinary* input_info,
+ LinkOptions* options) {
Context context;
WABT_ZERO_MEMORY(context);
context.binary = input_info;
@@ -324,6 +325,7 @@ Result read_binary_linker(LinkerInputBinary* input_info) {
ReadBinaryOptions read_options = WABT_READ_BINARY_OPTIONS_DEFAULT;
read_options.read_debug_names = true;
+ read_options.log_stream = options->log_stream;
return read_binary(input_info->data, input_info->size, &reader, 1,
&read_options);
}
diff --git a/src/binary-reader-linker.h b/src/binary-reader-linker.h
index 930cbe52..d2c04344 100644
--- a/src/binary-reader-linker.h
+++ b/src/binary-reader-linker.h
@@ -22,9 +22,15 @@
namespace wabt {
+struct Stream;
struct LinkerInputBinary;
-Result read_binary_linker(struct LinkerInputBinary* input_info);
+struct LinkOptions {
+ struct Stream* log_stream;
+};
+
+Result read_binary_linker(struct LinkerInputBinary* input_info,
+ struct LinkOptions* options);
} // namespace wabt
diff --git a/src/binary-reader-objdump.cc b/src/binary-reader-objdump.cc
index 60c65918..a34965f2 100644
--- a/src/binary-reader-objdump.cc
+++ b/src/binary-reader-objdump.cc
@@ -773,6 +773,7 @@ Result read_binary_objdump(const uint8_t* data,
ReadBinaryOptions read_options = WABT_READ_BINARY_OPTIONS_DEFAULT;
read_options.read_debug_names = true;
+ read_options.log_stream = options->log_stream;
return read_binary(data, size, &reader, 1, &read_options);
}
diff --git a/src/binary-reader-objdump.h b/src/binary-reader-objdump.h
index e6167ae3..884ac761 100644
--- a/src/binary-reader-objdump.h
+++ b/src/binary-reader-objdump.h
@@ -43,6 +43,7 @@ enum class ObjdumpMode {
};
struct ObjdumpOptions {
+ Stream* log_stream;
bool headers;
bool details;
bool raw;
diff --git a/src/binary-reader.cc b/src/binary-reader.cc
index 44d2dfbc..396d633c 100644
--- a/src/binary-reader.cc
+++ b/src/binary-reader.cc
@@ -466,13 +466,11 @@ static void write_indent(LoggingContext* ctx) {
LOGF_NOINDENT(__VA_ARGS__); \
} while (0)
-static void logging_on_error(BinaryReaderContext* ctx, const char* message) {
- LoggingContext* logging_ctx = static_cast<LoggingContext*>(ctx->user_data);
- if (logging_ctx->reader->on_error) {
- BinaryReaderContext new_ctx = *ctx;
- new_ctx.user_data = logging_ctx->reader->user_data;
- logging_ctx->reader->on_error(&new_ctx, message);
- }
+static Result logging_begin_section(BinaryReaderContext* context,
+ BinarySection section_type,
+ uint32_t size) {
+ LoggingContext* ctx = static_cast<LoggingContext*>(context->user_data);
+ FORWARD_CTX(begin_section, section_type, size);
}
static Result logging_begin_custom_section(BinaryReaderContext* context,
@@ -2031,7 +2029,8 @@ Result read_binary(const void* data,
WABT_ZERO_MEMORY(logging_reader);
logging_reader.user_data = &logging_context;
- logging_reader.on_error = logging_on_error;
+ logging_reader.on_error = reader->on_error;
+ logging_reader.begin_section = logging_begin_section;
logging_reader.begin_module = logging_begin_module;
logging_reader.end_module = logging_end_module;
diff --git a/src/tools/wasm-link.cc b/src/tools/wasm-link.cc
index 0db4276a..08b03c87 100644
--- a/src/tools/wasm-link.cc
+++ b/src/tools/wasm-link.cc
@@ -32,7 +32,7 @@
using namespace wabt;
-enum { FLAG_VERBOSE, FLAG_OUTPUT, FLAG_RELOCATABLE, FLAG_HELP, NUM_FLAGS };
+enum { FLAG_DEBUG, FLAG_OUTPUT, FLAG_RELOCATABLE, FLAG_HELP, NUM_FLAGS };
static const char s_description[] =
" link one or more wasm binary modules into a single binary module."
@@ -40,8 +40,8 @@ static const char s_description[] =
" $ wasm-link m1.wasm m2.wasm -o out.wasm\n";
static Option s_options[] = {
- {FLAG_VERBOSE, 'v', "verbose", nullptr, NOPE,
- "use multiple times for more info"},
+ {FLAG_DEBUG, '\0', "debug", nullptr, NOPE,
+ "log extra information when reading and writing wasm files"},
{FLAG_OUTPUT, 'o', "output", "FILE", YEP, "output wasm binary file"},
{FLAG_RELOCATABLE, 'r', "relocatable", nullptr, NOPE,
"output a relocatable object file"},
@@ -52,7 +52,7 @@ WABT_STATIC_ASSERT(NUM_FLAGS == WABT_ARRAY_SIZE(s_options));
typedef const char* String;
WABT_DEFINE_VECTOR(string, String);
-static int s_verbose;
+static bool s_debug;
static bool s_relocatable;
static const char* s_outfile = "a.wasm";
static StringVector s_infiles;
@@ -69,8 +69,8 @@ static void on_option(struct OptionParser* parser,
struct Option* option,
const char* argument) {
switch (option->id) {
- case FLAG_VERBOSE:
- s_verbose++;
+ case FLAG_DEBUG:
+ s_debug = true;
init_file_writer_existing(&s_log_stream_writer, stdout);
init_stream(&s_log_stream, &s_log_stream_writer.base, nullptr);
break;
@@ -141,7 +141,7 @@ static uint32_t relocate_func_index(LinkerInputBinary* binary,
if (function_index >= binary->function_imports.size) {
/* locally declared function call */
offset = binary->function_index_offset;
- if (s_verbose)
+ if (s_debug)
writef(&s_log_stream, "func reloc %d + %d\n", function_index, offset);
} else {
/* imported function call */
@@ -150,7 +150,7 @@ static uint32_t relocate_func_index(LinkerInputBinary* binary,
if (!import->active) {
function_index = import->foreign_index;
offset = import->foreign_binary->function_index_offset;
- if (s_verbose)
+ if (s_debug)
writef(&s_log_stream,
"reloc for disabled import. new index = %d + %d\n",
function_index, offset);
@@ -201,7 +201,7 @@ static void apply_relocations(Section* section) {
if (!section->relocations.size)
return;
- if (s_verbose)
+ if (s_debug)
writef(&s_log_stream, "apply_relocations: %s\n",
get_section_name(section->section_code));
@@ -760,7 +760,7 @@ static void write_binary(Context* ctx) {
}
static void dump_reloc_offsets(Context* ctx) {
- if (s_verbose) {
+ if (s_debug) {
uint32_t i;
for (i = 0; i < ctx->inputs.size; i++) {
LinkerInputBinary* binary = &ctx->inputs.data[i];
@@ -788,10 +788,10 @@ static Result perform_link(Context* ctx) {
WABT_FATAL("unable to open memory writer for writing\n");
Stream* log_stream = nullptr;
- if (s_verbose)
+ if (s_debug)
log_stream = &s_log_stream;
- if (s_verbose)
+ if (s_debug)
writef(&s_log_stream, "writing file: %s\n", s_outfile);
calculate_reloc_offsets(ctx);
@@ -820,7 +820,7 @@ int main(int argc, char** argv) {
size_t i;
for (i = 0; i < s_infiles.size; i++) {
const char* input_filename = s_infiles.data[i];
- if (s_verbose)
+ if (s_debug)
writef(&s_log_stream, "reading file: %s\n", input_filename);
char* data;
size_t size;
@@ -831,7 +831,10 @@ int main(int argc, char** argv) {
b->data = reinterpret_cast<uint8_t*>(data);
b->size = size;
b->filename = input_filename;
- result = read_binary_linker(b);
+ LinkOptions options = { NULL };
+ if (s_debug)
+ options.log_stream = &s_log_stream;
+ result = read_binary_linker(b, &options);
if (WABT_FAILED(result))
WABT_FATAL("error parsing file: %s\n", input_filename);
}
diff --git a/src/tools/wasmdump.cc b/src/tools/wasmdump.cc
index 1293c5a7..bcbec058 100644
--- a/src/tools/wasmdump.cc
+++ b/src/tools/wasmdump.cc
@@ -57,7 +57,7 @@ static Option s_options[] = {
"print raw section contents"},
{FLAG_DISASSEMBLE, 'd', "disassemble", nullptr, NOPE,
"disassemble function bodies"},
- {FLAG_DEBUG, '\0', "debug", nullptr, NOPE, "disassemble function bodies"},
+ {FLAG_DEBUG, '\0', "debug", nullptr, NOPE, "print extra debug information"},
{FLAG_DETAILS, 'x', "details", nullptr, NOPE, "Show section details"},
{FLAG_RELOCS, 'r', "reloc", nullptr, NOPE,
"show relocations inline with disassembly"},
@@ -67,6 +67,8 @@ static Option s_options[] = {
WABT_STATIC_ASSERT(NUM_FLAGS == WABT_ARRAY_SIZE(s_options));
static ObjdumpOptions s_objdump_options;
+static FileWriter s_log_stream_writer;
+static Stream s_log_stream;
static void on_argument(struct OptionParser* parser, const char* argument) {
s_objdump_options.infile = argument;
@@ -86,6 +88,10 @@ static void on_option(struct OptionParser* parser,
case FLAG_DEBUG:
s_objdump_options.debug = true;
+ init_file_writer_existing(&s_log_stream_writer, stdout);
+ init_stream(&s_log_stream, &s_log_stream_writer.base, nullptr);
+ s_objdump_options.log_stream = &s_log_stream;
+ break;
case FLAG_DISASSEMBLE:
s_objdump_options.disassemble = true;
@@ -155,7 +161,7 @@ int main(int argc, char** argv) {
// Perform serveral passed over the binary in order to print out different
// types of information.
- s_objdump_options.print_header = 1;
+ s_objdump_options.print_header = true;
if (!s_objdump_options.headers && !s_objdump_options.details &&
!s_objdump_options.disassemble && !s_objdump_options.raw) {
printf("At least one of the following switches must be given:\n");
@@ -177,7 +183,8 @@ int main(int argc, char** argv) {
result = read_binary_objdump(data, size, &s_objdump_options);
if (WABT_FAILED(result))
goto done;
- s_objdump_options.print_header = 0;
+ s_objdump_options.print_header = false;
+ s_objdump_options.log_stream = nullptr;
}
// Pass 2: Print extra information based on section type
if (s_objdump_options.details) {
@@ -185,14 +192,16 @@ int main(int argc, char** argv) {
result = read_binary_objdump(data, size, &s_objdump_options);
if (WABT_FAILED(result))
goto done;
- s_objdump_options.print_header = 0;
+ s_objdump_options.print_header = false;
+ s_objdump_options.log_stream = nullptr;
}
if (s_objdump_options.disassemble) {
s_objdump_options.mode = ObjdumpMode::Disassemble;
result = read_binary_objdump(data, size, &s_objdump_options);
if (WABT_FAILED(result))
goto done;
- s_objdump_options.print_header = 0;
+ s_objdump_options.print_header = false;
+ s_objdump_options.log_stream = nullptr;
}
// Pass 3: Dump to raw contents of the sections
if (s_objdump_options.raw) {