[PATCH] D66434: [WebAssembly][MC] Allow empty assembly functions
Sam Clegg via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 19 11:51:39 PDT 2019
sbc100 created this revision.
Herald added subscribers: llvm-commits, sunfish, aheejin, hiraditya, jgravelle-google, dschuff.
Herald added a project: LLVM.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D66434
Files:
llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
llvm/test/MC/WebAssembly/basic-assembly.s
Index: llvm/test/MC/WebAssembly/basic-assembly.s
===================================================================
--- llvm/test/MC/WebAssembly/basic-assembly.s
+++ llvm/test/MC/WebAssembly/basic-assembly.s
@@ -2,6 +2,11 @@
# Check that it converts to .o without errors, but don't check any output:
# RUN: llvm-mc -triple=wasm32-unknown-unknown -filetype=obj -mattr=+atomics,+unimplemented-simd128,+nontrapping-fptoint,+exception-handling -o %t.o < %s
+
+empty_func:
+ .functype empty_func () -> ()
+ end_function
+
test0:
# Test all types:
.functype test0 (i32, i64) -> (i32)
Index: llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
===================================================================
--- llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
+++ llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
@@ -489,6 +489,7 @@
if (pop(Name, Block))
return true;
} else if (Name == "end_function") {
+ ensureLocals(getStreamer());
CurrentState = EndFunction;
if (pop(Name, Function) || ensureEmptyNestingStack())
return true;
@@ -758,6 +759,19 @@
return true; // We didn't process this directive.
}
+ // Called either when the first instruction is parsed of the function ends.
+ void ensureLocals(MCStreamer &Out) {
+ if (CurrentState == FunctionStart) {
+ // We haven't seen a .local directive yet. The streamer requires locals to
+ // be encoded as a prelude to the instructions, so emit an empty list of
+ // locals here.
+ auto &TOut = reinterpret_cast<WebAssemblyTargetStreamer &>(
+ *Out.getTargetStreamer());
+ TOut.emitLocal(SmallVector<wasm::ValType, 0>());
+ CurrentState = FunctionLocals;
+ }
+ }
+
bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned & /*Opcode*/,
OperandVector &Operands, MCStreamer &Out,
uint64_t &ErrorInfo,
@@ -768,15 +782,7 @@
MatchInstructionImpl(Operands, Inst, ErrorInfo, MatchingInlineAsm);
switch (MatchResult) {
case Match_Success: {
- if (CurrentState == FunctionStart) {
- // This is the first instruction in a function, but we haven't seen
- // a .local directive yet. The streamer requires locals to be encoded
- // as a prelude to the instructions, so emit an empty list of locals
- // here.
- auto &TOut = reinterpret_cast<WebAssemblyTargetStreamer &>(
- *Out.getTargetStreamer());
- TOut.emitLocal(SmallVector<wasm::ValType, 0>());
- }
+ ensureLocals(Out);
// Fix unknown p2align operands.
auto Align = WebAssembly::GetDefaultP2AlignAny(Inst.getOpcode());
if (Align != -1U) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66434.215961.patch
Type: text/x-patch
Size: 2769 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190819/1cb89294/attachment.bin>
More information about the llvm-commits
mailing list