llvm-project/llvm/lib/Target/X86/MCTargetDesc/X86InstPrinterCommon.h
Fangrui Song 1d5758705d
X86: Support dollar symbol for AT&T syntax and add output-asm-variant to llc
'$' indicates immediate values in AT&T syntax, so symbol names starting
with '$' need to be quoted or wrapped in parentheses. Parentheses are
preferred to support expressions with relocation specifiers without
modifying MCExpr internals, aligning with GCC (https://gcc.gnu.org/PR91298).

Add `-output-asm-variant` to llc for testing Intel syntax, avoiding
`-x86-asm-syntax` which affects MCAsmInfo used by input assembly
(-x86-asm-syntax=intel doesn't work with AT&T module asm)

Note: In these positions the symbol name cannot be quoted: `$var:`
`.globl $var` `.type $var, @object`

Close #147587

Pull Request: https://github.com/llvm/llvm-project/pull/147876
2025-07-11 20:51:48 -07:00

49 lines
2.0 KiB
C++

//===-- X86InstPrinterCommon.cpp - X86 assembly instruction printing ------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file includes code common for rendering MCInst instances as AT&T-style
// and Intel-style assembly.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIB_TARGET_X86_MCTARGETDESC_X86INSTPRINTERCOMMON_H
#define LLVM_LIB_TARGET_X86_MCTARGETDESC_X86INSTPRINTERCOMMON_H
#include "llvm/MC/MCInstPrinter.h"
namespace llvm {
class MCExpr;
class X86InstPrinterCommon : public MCInstPrinter {
public:
using MCInstPrinter::MCInstPrinter;
virtual void printExprOperand(raw_ostream &OS, const MCExpr &E);
virtual void printOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O) = 0;
void printCondCode(const MCInst *MI, unsigned Op, raw_ostream &OS);
void printCondFlags(const MCInst *MI, unsigned Op, raw_ostream &OS);
void printSSEAVXCC(const MCInst *MI, unsigned Op, raw_ostream &OS);
void printVPCOMMnemonic(const MCInst *MI, raw_ostream &OS);
void printVPCMPMnemonic(const MCInst *MI, raw_ostream &OS);
void printCMPMnemonic(const MCInst *MI, bool IsVCmp, raw_ostream &OS);
void printRoundingControl(const MCInst *MI, unsigned Op, raw_ostream &O);
void printPCRelImm(const MCInst *MI, uint64_t Address, unsigned OpNo,
raw_ostream &O);
protected:
void printInstFlags(const MCInst *MI, raw_ostream &O,
const MCSubtargetInfo &STI);
void printOptionalSegReg(const MCInst *MI, unsigned OpNo, raw_ostream &O);
void printVKPair(const MCInst *MI, unsigned OpNo, raw_ostream &OS);
void printTILEPair(const MCInst *MI, unsigned OpNo, raw_ostream &OS);
};
} // end namespace llvm
#endif // LLVM_LIB_TARGET_X86_MCTARGETDESC_X86INSTPRINTERCOMMON_H