[M68k] Fix printing of immediate in `M68kOperand::print`
authorIan Douglas Scott <ian@iandouglasscott.com>
Sun, 16 Apr 2023 22:43:27 +0000 (15:43 -0700)
committerMin-Yih Hsu <minyihh@uci.edu>
Sun, 16 Apr 2023 22:44:18 +0000 (15:44 -0700)
The `Imm` union variant wasn't initialized anywhere. This fixes what is
printed by `llvm-mc -arch m68k --show-inst-operands`.

Differential Revision: https://reviews.llvm.org/D148302

llvm/lib/Target/M68k/AsmParser/M68kAsmParser.cpp
llvm/test/MC/M68k/operand.s [new file with mode: 0644]

index c606eaa..8d6abe8 100644 (file)
@@ -133,7 +133,6 @@ class M68kOperand : public MCParsedAsmOperand {
   SMLoc Start, End;
   union {
     StringRef Token;
-    int64_t Imm;
     const MCExpr *Expr;
     M68kMemOp MemOp;
   };
@@ -1069,9 +1068,12 @@ void M68kOperand::print(raw_ostream &OS) const {
     OS << "token '" << Token << "'";
     break;
 
-  case KindTy::Imm:
-    OS << "immediate " << Imm;
+  case KindTy::Imm: {
+    int64_t Value;
+    Expr->evaluateAsAbsolute(Value);
+    OS << "immediate " << Value;
     break;
+  }
 
   case KindTy::MemOp:
     MemOp.print(OS);
diff --git a/llvm/test/MC/M68k/operand.s b/llvm/test/MC/M68k/operand.s
new file mode 100644 (file)
index 0000000..b8946bd
--- /dev/null
@@ -0,0 +1,5 @@
+# RUN: llvm-mc -triple=m68k -show-inst-operands %s 2> %t0
+# RUN: FileCheck %s < %t0
+
+; CHECK:       parsed instruction: [token 'move.l', immediate 123, %24]
+move.l #123, %d0