aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/LLVMTargetMachine.cpp
diff options
context:
space:
mode:
authorFangrui Song <i@maskray.me>2024-09-24 15:59:33 -0700
committerGitHub <noreply@github.com>2024-09-24 15:59:33 -0700
commit4a9da96dc68d878893399210888a03117b39b802 (patch)
tree55da41c8468f2aadae9d244762379b1484ecb36c /llvm/lib/CodeGen/LLVMTargetMachine.cpp
parent4c4fb6ada7a168e5129a22efb4d604bb6fc60b17 (diff)
downloadllvm-4a9da96dc68d878893399210888a03117b39b802.zip
llvm-4a9da96dc68d878893399210888a03117b39b802.tar.gz
llvm-4a9da96dc68d878893399210888a03117b39b802.tar.bz2
[clang] Add cc1 --output-asm-variant= to set output syntax
2fcaa549a824efeb56e807fcf750a56bf985296b (2010) added cc1as option `-output-asm-variant` (untested) to set the output syntax. `clang -cc1as -filetype asm -output-asm-variant 1` allows AT&T input and Intel output (`AssemblerDialect` is also used by non-x86 targets). This patch renames the cc1as option (to avoid collision with -o) and makes it available for cc1 to set output syntax. This allows different input & output syntax: ``` echo 'asm("mov $1, %eax");' | clang -xc - -S -o - -Xclang --output-asm-variant=1 ``` Note: `AsmWriterFlavor` (with a misleading name), used to initialize MCAsmInfo::AssemblerDialect, is primarily used for assembly input, not for output. Therefore, `echo 'asm("mov $1, %eax");' | clang -x c - -mllvm --x86-asm-syntax=intel -S -o -`, which achieves a similar goal before Clang 19, was unintended. Close #109157 Pull Request: https://github.com/llvm/llvm-project/pull/109360
Diffstat (limited to 'llvm/lib/CodeGen/LLVMTargetMachine.cpp')
-rw-r--r--llvm/lib/CodeGen/LLVMTargetMachine.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/llvm/lib/CodeGen/LLVMTargetMachine.cpp b/llvm/lib/CodeGen/LLVMTargetMachine.cpp
index 4ff2205..ea36fed 100644
--- a/llvm/lib/CodeGen/LLVMTargetMachine.cpp
+++ b/llvm/lib/CodeGen/LLVMTargetMachine.cpp
@@ -160,7 +160,9 @@ Expected<std::unique_ptr<MCStreamer>> LLVMTargetMachine::createMCStreamer(
switch (FileType) {
case CodeGenFileType::AssemblyFile: {
MCInstPrinter *InstPrinter = getTarget().createMCInstPrinter(
- getTargetTriple(), MAI.getAssemblerDialect(), MAI, MII, MRI);
+ getTargetTriple(),
+ Options.MCOptions.OutputAsmVariant.value_or(MAI.getAssemblerDialect()),
+ MAI, MII, MRI);
// Create a code emitter if asked to show the encoding.
std::unique_ptr<MCCodeEmitter> MCE;