summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Target/WebAssembly/InstPrinter
diff options
context:
space:
mode:
authorDerek Schuff <dschuff@google.com>2018-03-20 20:06:35 +0000
committerDerek Schuff <dschuff@google.com>2018-03-20 20:06:35 +0000
commite4825975d83ce596ddcd385ec91fab5b8caf4bc4 (patch)
tree1c3737f99284e3fbd5a0b4a18cd10b11775fefc3 /llvm/lib/Target/WebAssembly/InstPrinter
parent36afbee1d81905d9b6d3a5e1868c7c8be2c3d877 (diff)
downloadbcm5719-llvm-e4825975d83ce596ddcd385ec91fab5b8caf4bc4.tar.gz
bcm5719-llvm-e4825975d83ce596ddcd385ec91fab5b8caf4bc4.zip
[WebAssembly] Added initial AsmParser implementation.
It uses the MC framework and the tablegen matcher to do the heavy lifting. Can handle both explicit and implicit locals (-disable-wasm-explicit-locals). Comes with a small regression test. This is a first basic implementation that can parse most llvm .s output and round-trips most instructions succesfully, but in order to keep the commit small, does not address all issues. There are a fair number of mismatches between what MC / assembly matcher think a "CPU" should look like and what WASM provides, some already have workarounds in this commit (e.g. the way it deals with register operands) and some that require further work. Some of that further work may involve changing what the Disassembler outputs (and what s2wasm parses), so are probably best left to followups. Some known things missing: - Many directives are ignored and not emitted. - Vararg calls are parsed but extra args not emitted. - Loop signatures are likely incorrect. - $drop= is not emitted. - Disassembler does not output SIMD types correctly, so assembler can't test them. Patch by Wouter van Oortmerssen Differential Revision: https://reviews.llvm.org/D44329 llvm-svn: 328028
Diffstat (limited to 'llvm/lib/Target/WebAssembly/InstPrinter')
-rw-r--r--llvm/lib/Target/WebAssembly/InstPrinter/WebAssemblyInstPrinter.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/llvm/lib/Target/WebAssembly/InstPrinter/WebAssemblyInstPrinter.cpp b/llvm/lib/Target/WebAssembly/InstPrinter/WebAssemblyInstPrinter.cpp
index 639dd639f6e..74a166a4cc3 100644
--- a/llvm/lib/Target/WebAssembly/InstPrinter/WebAssemblyInstPrinter.cpp
+++ b/llvm/lib/Target/WebAssembly/InstPrinter/WebAssemblyInstPrinter.cpp
@@ -82,10 +82,12 @@ void WebAssemblyInstPrinter::printInst(const MCInst *MI, raw_ostream &OS,
ControlFlowStack.push_back(std::make_pair(ControlFlowCounter++, false));
break;
case WebAssembly::END_LOOP:
- ControlFlowStack.pop_back();
+ // Have to guard against an empty stack, in case of mismatched pairs
+ // in assembly parsing.
+ if (!ControlFlowStack.empty()) ControlFlowStack.pop_back();
break;
case WebAssembly::END_BLOCK:
- printAnnotation(
+ if (!ControlFlowStack.empty()) printAnnotation(
OS, "label" + utostr(ControlFlowStack.pop_back_val().first) + ':');
break;
}
OpenPOWER on IntegriCloud