Skip to content

Make wasm-as emit the names section/debug info only with -g #705

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions auto_update_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,23 @@

for wast in sorted(os.listdir('test')):
if wast.endswith('.wast') and not wast in []: # blacklist some known failures
cmd = [os.path.join('bin', 'wasm-as'), os.path.join('test', wast), '-o', 'a.wasm']
print ' '.join(cmd)
if os.path.exists('a.wasm'): os.unlink('a.wasm')
subprocess.check_call(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
assert os.path.exists('a.wasm')

cmd = [os.path.join('bin', 'wasm-dis'), 'a.wasm', '-o', 'a.wast']
print ' '.join(cmd)
if os.path.exists('a.wast'): os.unlink('a.wast')
subprocess.check_call(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
assert os.path.exists('a.wast')
actual = open('a.wast').read()
with open(os.path.join('test', wast + '.fromBinary'), 'w') as o: o.write(actual)
for debug_info in [0, 1]:
cmd = [os.path.join('bin', 'wasm-as'), os.path.join('test', wast), '-o', 'a.wasm']
if debug_info: cmd += ['-g']
print ' '.join(cmd)
if os.path.exists('a.wasm'): os.unlink('a.wasm')
subprocess.check_call(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
assert os.path.exists('a.wasm')

cmd = [os.path.join('bin', 'wasm-dis'), 'a.wasm', '-o', 'a.wast']
print ' '.join(cmd)
if os.path.exists('a.wast'): os.unlink('a.wast')
subprocess.check_call(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
assert os.path.exists('a.wast')
actual = open('a.wast').read()
binary_name = wast + '.fromBinary'
if not debug_info: binary_name += '.noDebugInfo'
with open(os.path.join('test', binary_name), 'w') as o: o.write(actual)

print '\n[ checking example testcases... ]\n'

Expand Down
10 changes: 6 additions & 4 deletions check.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,11 @@ def fail_if_not_contained(actual, expected):

# check utilities

def binary_format_check(wast, verify_final_result=True):
def binary_format_check(wast, verify_final_result=True, wasm_as_args=['-g'], binary_suffix='.fromBinary'):
# checks we can convert the wast to binary and back

print ' (binary format check)'
cmd = [os.path.join('bin', 'wasm-as'), wast, '-o', 'a.wasm']
cmd = [os.path.join('bin', 'wasm-as'), wast, '-o', 'a.wasm'] + wasm_as_args
print ' ', ' '.join(cmd)
if os.path.exists('a.wasm'): os.unlink('a.wasm')
subprocess.check_call(cmd, stdout=subprocess.PIPE)
Expand All @@ -208,7 +208,7 @@ def binary_format_check(wast, verify_final_result=True):
subprocess.check_call(cmd, stdout=subprocess.PIPE)

if verify_final_result:
expected = open(wast + '.fromBinary').read()
expected = open(wast + binary_suffix).read()
actual = open('ab.wast').read()
if actual != expected:
fail(actual, expected)
Expand Down Expand Up @@ -360,7 +360,9 @@ def minify_check(wast, verify_final_result=True):
if actual != expected:
fail(actual, expected)

binary_format_check(t)
binary_format_check(t, wasm_as_args=['-g']) # test with debuginfo
binary_format_check(t, wasm_as_args=[], binary_suffix='.fromBinary.noDebugInfo') # test without debuginfo

minify_check(t)

print '\n[ checking wasm-shell spec testcases... ]\n'
Expand Down
5 changes: 5 additions & 0 deletions src/tools/wasm-as.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ using namespace cashew;
using namespace wasm;

int main(int argc, const char *argv[]) {
bool debugInfo = false;
Options options("wasm-as", "Assemble a .wast (WebAssembly text format) into a .wasm (WebAssembly binary format)");
options.extra["validate"] = "wasm";
options
Expand All @@ -46,6 +47,9 @@ int main(int argc, const char *argv[]) {
}
o->extra["validate"] = argument;
})
.add("--debuginfo", "-g", "Emit names section and debug info",
Options::Arguments::Zero,
[&](Options *o, const std::string &arguments) { debugInfo = true; })
.add_positional("INFILE", Options::Arguments::One,
[](Options *o, const std::string &argument) {
o->extra["infile"] = argument;
Expand Down Expand Up @@ -78,6 +82,7 @@ int main(int argc, const char *argv[]) {
if (options.debug) std::cerr << "binarification..." << std::endl;
BufferWithRandomAccess buffer(options.debug);
WasmBinaryWriter writer(&wasm, buffer, options.debug);
writer.setDebugInfo(debugInfo);
writer.write();

if (options.debug) std::cerr << "writing to output..." << std::endl;
Expand Down
7 changes: 6 additions & 1 deletion src/wasm-binary.h
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ class WasmBinaryWriter : public Visitor<WasmBinaryWriter, void> {
Module* wasm;
BufferWithRandomAccess& o;
bool debug;
bool debugInfo = true;

MixedArena allocator;

Expand All @@ -484,6 +485,10 @@ class WasmBinaryWriter : public Visitor<WasmBinaryWriter, void> {
prepare();
}

void setDebugInfo(bool set) {
debugInfo = set;
}

void write() {
writeHeader();

Expand All @@ -497,7 +502,7 @@ class WasmBinaryWriter : public Visitor<WasmBinaryWriter, void> {
writeStart();
writeFunctions();
writeDataSegments();
writeNames();
if (debugInfo) writeNames();

finishUp();
}
Expand Down
12 changes: 12 additions & 0 deletions test/hello_world.wast.fromBinary.noDebugInfo
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(module
(memory 256 256)
(type $0 (func (param i32 i32) (result i32)))
(export "add" (func $0))
(func $0 (type $0) (param $var$0 i32) (param $var$1 i32) (result i32)
(i32.add
(get_local $var$0)
(get_local $var$1)
)
)
)

Loading