Skip to content

Commit 43f81e1

Browse files
committed
make wasm-as emit the names section/debug info only with -g
1 parent 4497831 commit 43f81e1

9 files changed

+1240
-19
lines changed

auto_update_tests.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -93,19 +93,23 @@
9393

9494
for wast in sorted(os.listdir('test')):
9595
if wast.endswith('.wast') and not wast in []: # blacklist some known failures
96-
cmd = [os.path.join('bin', 'wasm-as'), os.path.join('test', wast), '-o', 'a.wasm']
97-
print ' '.join(cmd)
98-
if os.path.exists('a.wasm'): os.unlink('a.wasm')
99-
subprocess.check_call(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
100-
assert os.path.exists('a.wasm')
101-
102-
cmd = [os.path.join('bin', 'wasm-dis'), 'a.wasm', '-o', 'a.wast']
103-
print ' '.join(cmd)
104-
if os.path.exists('a.wast'): os.unlink('a.wast')
105-
subprocess.check_call(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
106-
assert os.path.exists('a.wast')
107-
actual = open('a.wast').read()
108-
with open(os.path.join('test', wast + '.fromBinary'), 'w') as o: o.write(actual)
96+
for debug_info in [0, 1]:
97+
cmd = [os.path.join('bin', 'wasm-as'), os.path.join('test', wast), '-o', 'a.wasm']
98+
if debug_info: cmd += ['-g']
99+
print ' '.join(cmd)
100+
if os.path.exists('a.wasm'): os.unlink('a.wasm')
101+
subprocess.check_call(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
102+
assert os.path.exists('a.wasm')
103+
104+
cmd = [os.path.join('bin', 'wasm-dis'), 'a.wasm', '-o', 'a.wast']
105+
print ' '.join(cmd)
106+
if os.path.exists('a.wast'): os.unlink('a.wast')
107+
subprocess.check_call(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
108+
assert os.path.exists('a.wast')
109+
actual = open('a.wast').read()
110+
binary_name = wast + '.fromBinary'
111+
if not debug_info: binary_name += '.noDebugInfo'
112+
with open(os.path.join('test', binary_name), 'w') as o: o.write(actual)
109113

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

check.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,11 @@ def fail_if_not_contained(actual, expected):
186186

187187
# check utilities
188188

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

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

210210
if verify_final_result:
211-
expected = open(wast + '.fromBinary').read()
211+
expected = open(wast + binary_suffix).read()
212212
actual = open('ab.wast').read()
213213
if actual != expected:
214214
fail(actual, expected)
@@ -306,7 +306,7 @@ def minify_check(wast, verify_final_result=True):
306306
if actual != expected:
307307
fail(actual, expected)
308308

309-
binary_format_check(wasm, verify_final_result=False)
309+
binary_format_check(wasm, verify_final_result = False)
310310

311311
# verify in wasm
312312
if interpreter:
@@ -360,7 +360,9 @@ def minify_check(wast, verify_final_result=True):
360360
if actual != expected:
361361
fail(actual, expected)
362362

363-
binary_format_check(t)
363+
binary_format_check(t, wasm_as_args = ['-g']) # test with debuginfo
364+
binary_format_check(t, wasm_as_args = [], binary_suffix='.fromBinary.noDebugInfo') # test without debuginfo
365+
364366
minify_check(t)
365367

366368
print '\n[ checking wasm-shell spec testcases... ]\n'

src/tools/wasm-as.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ using namespace cashew;
2828
using namespace wasm;
2929

3030
int main(int argc, const char *argv[]) {
31+
bool debugInfo = false;
3132
Options options("wasm-as", "Assemble a .wast (WebAssembly text format) into a .wasm (WebAssembly binary format)");
3233
options.extra["validate"] = "wasm";
3334
options
@@ -46,6 +47,9 @@ int main(int argc, const char *argv[]) {
4647
}
4748
o->extra["validate"] = argument;
4849
})
50+
.add("--debuginfo", "-g", "Emit names section and debug info",
51+
Options::Arguments::Zero,
52+
[&](Options *o, const std::string &arguments) { debugInfo = true; })
4953
.add_positional("INFILE", Options::Arguments::One,
5054
[](Options *o, const std::string &argument) {
5155
o->extra["infile"] = argument;
@@ -78,6 +82,7 @@ int main(int argc, const char *argv[]) {
7882
if (options.debug) std::cerr << "binarification..." << std::endl;
7983
BufferWithRandomAccess buffer(options.debug);
8084
WasmBinaryWriter writer(&wasm, buffer, options.debug);
85+
writer.setDebugInfo(debugInfo);
8186
writer.write();
8287

8388
if (options.debug) std::cerr << "writing to output..." << std::endl;

src/wasm-binary.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,7 @@ class WasmBinaryWriter : public Visitor<WasmBinaryWriter, void> {
466466
Module* wasm;
467467
BufferWithRandomAccess& o;
468468
bool debug;
469+
bool debugInfo = true;
469470

470471
MixedArena allocator;
471472

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

488+
void setDebugInfo(bool set) {
489+
debugInfo = set;
490+
}
491+
487492
void write() {
488493
writeHeader();
489494

@@ -497,7 +502,7 @@ class WasmBinaryWriter : public Visitor<WasmBinaryWriter, void> {
497502
writeStart();
498503
writeFunctions();
499504
writeDataSegments();
500-
writeNames();
505+
if (debugInfo) writeNames();
501506

502507
finishUp();
503508
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
(module
2+
(memory 256 256)
3+
(type $0 (func (param i32 i32) (result i32)))
4+
(export "add" (func $0))
5+
(func $0 (type $0) (param $var$0 i32) (param $var$1 i32) (result i32)
6+
(i32.add
7+
(get_local $var$0)
8+
(get_local $var$1)
9+
)
10+
)
11+
)
12+

0 commit comments

Comments
 (0)