From 3fbae879fc1b678e748ab3f8c24148e1c3818f45 Mon Sep 17 00:00:00 2001 From: JF Bastien Date: Thu, 4 Feb 2016 05:18:07 -0800 Subject: Support start As spec'd in: https://github.com/WebAssembly/design/pull/495 And discussed in: https://github.com/WebAssembly/spec/issues/231 This will make it simpler and more uniform to add a start entry point. s2wasm is the right place to add start because it'll eventually need to do other basic setup, e.g. put code in start to setup the stack, as dschuff is doing in: https://github.com/WebAssembly/binaryen/pull/179 Or rather, the linker is the right place and s2wasm happens to act as our linker right now. --- check.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'check.py') diff --git a/check.py b/check.py index 22acc0228..10093a3cc 100755 --- a/check.py +++ b/check.py @@ -408,7 +408,9 @@ for dot_s_dir in ['dot_s', 'llvm_autogenerated']: print '..', s wasm = s.replace('.s', '.wast') full = os.path.join('test', dot_s_dir, s) - actual, err = subprocess.Popen([os.path.join('bin', 's2wasm'), full], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() + start = ['--start'] if s.startswith('start_') else [] + cmd = [os.path.join('bin', 's2wasm'), full] + start + actual, err = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() assert err == '', 'bad err:' + err # verify output -- cgit v1.2.3 From 31409184708b04bae830869c7b6ce61726020444 Mon Sep 17 00:00:00 2001 From: JF Bastien Date: Fri, 5 Feb 2016 01:25:56 -0800 Subject: Review comments. --- check.py | 5 +++-- src/s2wasm.h | 16 ++++++++-------- 2 files changed, 11 insertions(+), 10 deletions(-) (limited to 'check.py') diff --git a/check.py b/check.py index 10093a3cc..495abfe50 100755 --- a/check.py +++ b/check.py @@ -408,8 +408,9 @@ for dot_s_dir in ['dot_s', 'llvm_autogenerated']: print '..', s wasm = s.replace('.s', '.wast') full = os.path.join('test', dot_s_dir, s) - start = ['--start'] if s.startswith('start_') else [] - cmd = [os.path.join('bin', 's2wasm'), full] + start + cmd = [os.path.join('bin', 's2wasm'), full] + if s.startswith('start_'): + cmd.append('--start') actual, err = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() assert err == '', 'bad err:' + err diff --git a/src/s2wasm.h b/src/s2wasm.h index 5f8ba850f..275cf6a9c 100644 --- a/src/s2wasm.h +++ b/src/s2wasm.h @@ -39,12 +39,12 @@ class S2WasmBuilder { const char* s; bool debug; bool ignoreUnknownSymbols; - const std::string &startFunction; + Name startFunction; public: S2WasmBuilder(AllocatingModule& wasm, const char* input, bool debug, size_t globalBase, size_t stackAllocation, - bool ignoreUnknownSymbols, const std::string& startFunction) + bool ignoreUnknownSymbols, Name startFunction) : wasm(wasm), allocator(wasm.allocator), debug(debug), @@ -80,7 +80,7 @@ class S2WasmBuilder { }; std::vector relocations; - std::map implementedFunctions; + std::set implementedFunctions; std::map aliasedFunctions; std::map addressSegments; // address => segment index @@ -367,7 +367,7 @@ class S2WasmBuilder { if (match(".hidden")) mustMatch(name.str); mustMatch(name.str); if (match(":")) { - implementedFunctions.insert({name, nullptr}); + implementedFunctions.insert(name); } else if (match("=")) { Name alias = getAtSeparated(); mustMatch("@FUNCTION"); @@ -487,7 +487,6 @@ class S2WasmBuilder { }; auto func = allocator.alloc(); - implementedFunctions[name] = func; func->name = name; std::map localTypes; // params and result @@ -1174,9 +1173,10 @@ class S2WasmBuilder { if (functionIndexes.count(name) == 0) { functionIndexes[name] = wasm.table.names.size(); wasm.table.names.push_back(name); - if (debug) + if (debug) { std::cerr << "function index: " << name << ": " << functionIndexes[name] << '\n'; + } } }; for (auto& relocation : relocations) { @@ -1198,12 +1198,12 @@ class S2WasmBuilder { } } } - if (startFunction.size()) { + if (!!startFunction) { if (implementedFunctions.count(startFunction) == 0) { std::cerr << "Unknown start function: `" << startFunction << "`\n"; abort(); } - const auto *target = implementedFunctions[startFunction]; + const auto *target = wasm.functionsMap[startFunction]; Name start("_start"); if (implementedFunctions.count(start) != 0) { std::cerr << "Start function already present: `" << start << "`\n"; -- cgit v1.2.3