diff --git a/llvm/include/llvm/MC/MCInstPrinter.h b/llvm/include/llvm/MC/MCInstPrinter.h --- a/llvm/include/llvm/MC/MCInstPrinter.h +++ b/llvm/include/llvm/MC/MCInstPrinter.h @@ -54,6 +54,9 @@ /// True if we are printing marked up assembly. bool UseMarkup = false; + /// True if we prefer aliases (e.g. nop) to raw mnemonics. + bool PrintAliases = true; + /// True if we are printing immediates as hex. bool PrintImmHex = false; diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVInstPrinter.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVInstPrinter.cpp --- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVInstPrinter.cpp +++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVInstPrinter.cpp @@ -39,11 +39,11 @@ cl::desc("Disable the emission of assembler pseudo instructions"), cl::init(false), cl::Hidden); -static cl::opt - ArchRegNames("riscv-arch-reg-names", - cl::desc("Print architectural register names rather than the " - "ABI names (such as x2 instead of sp)"), - cl::init(false), cl::Hidden); +// Print architectural register names rather than the ABI names (such as x2 +// instead of sp). +// TODO: Make RISCVInstPrinter::getRegisterName non-static so that this can a +// member. +static bool ArchRegNames; // The command-line flags above are used by llvm-mc and llc. They can be used by // `llvm-objdump`, but we override their values here to handle options passed to @@ -52,7 +52,7 @@ // this way. bool RISCVInstPrinter::applyTargetSpecificCLOption(StringRef Opt) { if (Opt == "no-aliases") { - NoAliases = true; + PrintAliases = false; return true; } if (Opt == "numeric") { @@ -69,11 +69,11 @@ bool Res = false; const MCInst *NewMI = MI; MCInst UncompressedMI; - if (!NoAliases) + if (PrintAliases && !NoAliases) Res = uncompressInst(UncompressedMI, *MI, MRI, STI); if (Res) NewMI = const_cast(&UncompressedMI); - if (NoAliases || !printAliasInstr(NewMI, Address, STI, O)) + if (!PrintAliases || NoAliases || !printAliasInstr(NewMI, Address, STI, O)) printInstruction(NewMI, Address, STI, O); printAnnotation(O, Annot); } diff --git a/llvm/test/MC/RISCV/numeric-reg-names-d.s b/llvm/test/MC/RISCV/numeric-reg-names-d.s --- a/llvm/test/MC/RISCV/numeric-reg-names-d.s +++ b/llvm/test/MC/RISCV/numeric-reg-names-d.s @@ -1,4 +1,4 @@ -# RUN: llvm-mc -triple riscv32 -mattr=+f,+d < %s -riscv-arch-reg-names \ +# RUN: llvm-mc -triple riscv32 -mattr=+f,+d -M numeric < %s \ # RUN: | FileCheck -check-prefix=CHECK-NUMERIC %s # RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+f,+d < %s \ # RUN: | llvm-objdump --mattr=+f,+d -d -M numeric - \ diff --git a/llvm/test/MC/RISCV/numeric-reg-names-f.s b/llvm/test/MC/RISCV/numeric-reg-names-f.s --- a/llvm/test/MC/RISCV/numeric-reg-names-f.s +++ b/llvm/test/MC/RISCV/numeric-reg-names-f.s @@ -1,4 +1,4 @@ -# RUN: llvm-mc -triple riscv32 -mattr=+f < %s -riscv-arch-reg-names \ +# RUN: llvm-mc -triple riscv32 -mattr=+f -M numeric < %s \ # RUN: | FileCheck -check-prefix=CHECK-NUMERIC %s # RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+f < %s \ # RUN: | llvm-objdump --mattr=+f -d -M numeric - \ diff --git a/llvm/test/MC/RISCV/numeric-reg-names.s b/llvm/test/MC/RISCV/numeric-reg-names.s --- a/llvm/test/MC/RISCV/numeric-reg-names.s +++ b/llvm/test/MC/RISCV/numeric-reg-names.s @@ -1,4 +1,4 @@ -# RUN: llvm-mc -triple riscv32 < %s -riscv-arch-reg-names \ +# RUN: llvm-mc -triple riscv32 -M numeric %s \ # RUN: | FileCheck -check-prefix=CHECK-NUMERIC %s # RUN: llvm-mc -filetype=obj -triple riscv32 < %s \ # RUN: | llvm-objdump -d -M numeric - \ diff --git a/llvm/test/MC/RISCV/rvi-aliases-valid.s b/llvm/test/MC/RISCV/rvi-aliases-valid.s --- a/llvm/test/MC/RISCV/rvi-aliases-valid.s +++ b/llvm/test/MC/RISCV/rvi-aliases-valid.s @@ -1,8 +1,8 @@ -# RUN: llvm-mc %s -triple=riscv32 -riscv-no-aliases \ +# RUN: llvm-mc %s -triple=riscv32 -M no-aliases \ # RUN: | FileCheck -check-prefixes=CHECK-S-NOALIAS,CHECK-S-OBJ-NOALIAS %s # RUN: llvm-mc %s -triple=riscv32 \ # RUN: | FileCheck -check-prefixes=CHECK-S,CHECK-S-OBJ %s -# RUN: llvm-mc %s -triple=riscv64 -riscv-no-aliases\ +# RUN: llvm-mc %s -triple=riscv64 -M no-aliases \ # RUN: | FileCheck -check-prefixes=CHECK-S-NOALIAS,CHECK-S-OBJ-NOALIAS %s # RUN: llvm-mc %s -triple=riscv64 \ # RUN: | FileCheck -check-prefixes=CHECK-S,CHECK-S-OBJ %s diff --git a/llvm/test/tools/llvm-mc/disassembler-options.test b/llvm/test/tools/llvm-mc/disassembler-options.test new file mode 100644 --- /dev/null +++ b/llvm/test/tools/llvm-mc/disassembler-options.test @@ -0,0 +1,3 @@ +# RUN: not llvm-mc -M invalid /dev/null 2>&1 | FileCheck %s + +# CHECK: error: invalid disassembler option 'invalid' diff --git a/llvm/tools/llvm-mc/llvm-mc.cpp b/llvm/tools/llvm-mc/llvm-mc.cpp --- a/llvm/tools/llvm-mc/llvm-mc.cpp +++ b/llvm/tools/llvm-mc/llvm-mc.cpp @@ -46,6 +46,9 @@ static cl::opt InputFilename(cl::Positional, cl::desc(""), cl::init("-")); +static cl::list + DisassemblerOptions("M", cl::desc("Disassembler options")); + static cl::opt OutputFilename("o", cl::desc("Output filename"), cl::value_desc("filename"), cl::init("-")); @@ -496,6 +499,12 @@ return 1; } + for (StringRef Opt : DisassemblerOptions) + if (!IP->applyTargetSpecificCLOption(Opt)) { + WithColor::error() << "invalid disassembler option '" << Opt << "'\n"; + return 1; + } + // Set the display preference for hex vs. decimal immediates. IP->setPrintImmHex(PrintImmHex);