[WebAssembly][MC] Allow empty assembly functions
Differential Revision: https://reviews.llvm.org/D66434 llvm-svn: 369292
This commit is contained in:
parent
1a3fdaf6a6
commit
19bf637eb1
|
@ -489,6 +489,7 @@ public:
|
||||||
if (pop(Name, Block))
|
if (pop(Name, Block))
|
||||||
return true;
|
return true;
|
||||||
} else if (Name == "end_function") {
|
} else if (Name == "end_function") {
|
||||||
|
ensureLocals(getStreamer());
|
||||||
CurrentState = EndFunction;
|
CurrentState = EndFunction;
|
||||||
if (pop(Name, Function) || ensureEmptyNestingStack())
|
if (pop(Name, Function) || ensureEmptyNestingStack())
|
||||||
return true;
|
return true;
|
||||||
|
@ -758,6 +759,19 @@ public:
|
||||||
return true; // We didn't process this directive.
|
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*/,
|
bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned & /*Opcode*/,
|
||||||
OperandVector &Operands, MCStreamer &Out,
|
OperandVector &Operands, MCStreamer &Out,
|
||||||
uint64_t &ErrorInfo,
|
uint64_t &ErrorInfo,
|
||||||
|
@ -768,15 +782,7 @@ public:
|
||||||
MatchInstructionImpl(Operands, Inst, ErrorInfo, MatchingInlineAsm);
|
MatchInstructionImpl(Operands, Inst, ErrorInfo, MatchingInlineAsm);
|
||||||
switch (MatchResult) {
|
switch (MatchResult) {
|
||||||
case Match_Success: {
|
case Match_Success: {
|
||||||
if (CurrentState == FunctionStart) {
|
ensureLocals(Out);
|
||||||
// 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>());
|
|
||||||
}
|
|
||||||
// Fix unknown p2align operands.
|
// Fix unknown p2align operands.
|
||||||
auto Align = WebAssembly::GetDefaultP2AlignAny(Inst.getOpcode());
|
auto Align = WebAssembly::GetDefaultP2AlignAny(Inst.getOpcode());
|
||||||
if (Align != -1U) {
|
if (Align != -1U) {
|
||||||
|
|
|
@ -2,6 +2,11 @@
|
||||||
# Check that it converts to .o without errors, but don't check any output:
|
# 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
|
# 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:
|
test0:
|
||||||
# Test all types:
|
# Test all types:
|
||||||
.functype test0 (i32, i64) -> (i32)
|
.functype test0 (i32, i64) -> (i32)
|
||||||
|
@ -111,6 +116,9 @@ test0:
|
||||||
.globaltype __stack_pointer, i32
|
.globaltype __stack_pointer, i32
|
||||||
|
|
||||||
# CHECK: .text
|
# CHECK: .text
|
||||||
|
# CHECK-LABEL: empty_func:
|
||||||
|
# CHECK-NEXT: .functype empty_func () -> ()
|
||||||
|
# CHECK-NEXT: end_function
|
||||||
# CHECK-LABEL: test0:
|
# CHECK-LABEL: test0:
|
||||||
# CHECK-NEXT: .functype test0 (i32, i64) -> (i32)
|
# CHECK-NEXT: .functype test0 (i32, i64) -> (i32)
|
||||||
# CHECK-NEXT: .eventtype __cpp_exception i32
|
# CHECK-NEXT: .eventtype __cpp_exception i32
|
||||||
|
|
Loading…
Reference in New Issue