From 319c87d94fd5529406adf004bc0d98ecab991fa4 Mon Sep 17 00:00:00 2001 From: Wouter van Oortmerssen Date: Fri, 28 Jun 2019 22:20:33 +0000 Subject: [PATCH] [WebAssembly] Assembler: support .int16/32/64 directives. Reviewers: sbc100 Subscribers: dschuff, jgravelle-google, aheejin, sunfish, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D63959 llvm-svn: 364689 --- .../WebAssembly/AsmParser/WebAssemblyAsmParser.cpp | 17 +++++++++++------ llvm/test/MC/WebAssembly/basic-assembly.s | 8 +++++++- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp index c0abd11..e22ed8e 100644 --- a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp +++ b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp @@ -665,13 +665,18 @@ public: return expect(AsmToken::EndOfStatement, "EOL"); } - if (DirectiveID.getString() == ".int8") { + if (DirectiveID.getString() == ".int8" || + DirectiveID.getString() == ".int16" || + DirectiveID.getString() == ".int32" || + DirectiveID.getString() == ".int64") { if (CheckDataSection()) return true; - int64_t V; - if (Parser.parseAbsoluteExpression(V)) - return error("Cannot parse int8 constant: ", Lexer.getTok()); - // TODO: error if value doesn't fit? - Out.EmitIntValue(static_cast(V), 1); + const MCExpr *Val; + SMLoc End; + if (Parser.parseExpression(Val, End)) + return error("Cannot parse .int expression: ", Lexer.getTok()); + size_t NumBits = 0; + DirectiveID.getString().drop_front(4).getAsInteger(10, NumBits); + Out.EmitValue(Val, NumBits / 8, End); return expect(AsmToken::EndOfStatement, "EOL"); } diff --git a/llvm/test/MC/WebAssembly/basic-assembly.s b/llvm/test/MC/WebAssembly/basic-assembly.s index 40c50d5..7514731 100644 --- a/llvm/test/MC/WebAssembly/basic-assembly.s +++ b/llvm/test/MC/WebAssembly/basic-assembly.s @@ -95,7 +95,10 @@ test0: .L.str: .int8 'H' .asciz "ello, World!" - .size .L.str, 14 + .int16 1234 + .int64 5000000000 + .int32 2000000000 + .size .L.str, 28 .ident "clang version 9.0.0 (trunk 364502) (llvm/trunk 364571)" .globaltype __stack_pointer, i32 @@ -185,5 +188,8 @@ test0: # CHECK-NEXT: .L.str: # CHECK-NEXT: .int8 72 # CHECK-NEXT: .asciz "ello, World!" +# CHECK-NEXT: .int16 1234 +# CHECK-NEXT: .int64 5000000000 +# CHECK-NEXT: .int32 2000000000 # CHECK: .globaltype __stack_pointer, i32 -- 2.7.4