2009-06-19 00:47:59 +00:00
|
|
|
//===-- X86ATTInstPrinter.cpp - AT&T assembly instruction printing --------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file includes code for rendering MCInst instances as AT&T-style
|
|
|
|
// assembly.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#define DEBUG_TYPE "asm-printer"
|
2009-09-13 19:30:11 +00:00
|
|
|
#include "X86ATTInstPrinter.h"
|
2009-06-19 00:47:59 +00:00
|
|
|
#include "llvm/MC/MCInst.h"
|
2009-08-22 20:48:53 +00:00
|
|
|
#include "llvm/MC/MCAsmInfo.h"
|
2009-08-31 08:08:38 +00:00
|
|
|
#include "llvm/MC/MCExpr.h"
|
2009-07-08 18:01:40 +00:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2009-07-14 20:18:05 +00:00
|
|
|
#include "llvm/Support/FormattedStream.h"
|
2009-09-18 20:35:59 +00:00
|
|
|
#include "X86GenInstrNames.inc"
|
2009-06-19 00:47:59 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
2009-06-19 23:59:57 +00:00
|
|
|
// Include the auto-generated portion of the assembly writer.
|
|
|
|
#define MachineInstr MCInst
|
|
|
|
#define NO_ASM_WRITER_BOILERPLATE
|
|
|
|
#include "X86GenAsmWriter.inc"
|
|
|
|
#undef MachineInstr
|
|
|
|
|
2009-09-14 01:49:26 +00:00
|
|
|
void X86ATTInstPrinter::printInst(const MCInst *MI) { printInstruction(MI); }
|
|
|
|
|
2009-09-13 19:30:11 +00:00
|
|
|
void X86ATTInstPrinter::printSSECC(const MCInst *MI, unsigned Op) {
|
2009-06-20 07:03:18 +00:00
|
|
|
switch (MI->getOperand(Op).getImm()) {
|
2009-07-14 16:55:14 +00:00
|
|
|
default: llvm_unreachable("Invalid ssecc argument!");
|
2009-06-20 00:49:26 +00:00
|
|
|
case 0: O << "eq"; break;
|
|
|
|
case 1: O << "lt"; break;
|
|
|
|
case 2: O << "le"; break;
|
|
|
|
case 3: O << "unord"; break;
|
|
|
|
case 4: O << "neq"; break;
|
|
|
|
case 5: O << "nlt"; break;
|
|
|
|
case 6: O << "nle"; break;
|
|
|
|
case 7: O << "ord"; break;
|
2009-06-19 23:59:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-20 19:34:09 +00:00
|
|
|
/// print_pcrel_imm - This is used to print an immediate value that ends up
|
|
|
|
/// being encoded as a pc-relative value. These print slightly differently, for
|
|
|
|
/// example, a $ is not emitted.
|
2009-09-13 19:30:11 +00:00
|
|
|
void X86ATTInstPrinter::print_pcrel_imm(const MCInst *MI, unsigned OpNo) {
|
2009-06-20 19:34:09 +00:00
|
|
|
const MCOperand &Op = MI->getOperand(OpNo);
|
|
|
|
if (Op.isImm())
|
|
|
|
O << Op.getImm();
|
2009-09-14 01:34:40 +00:00
|
|
|
else {
|
|
|
|
assert(Op.isExpr() && "unknown pcrel immediate operand");
|
2009-09-14 01:49:26 +00:00
|
|
|
Op.getExpr()->print(O, &MAI);
|
2009-09-14 01:34:40 +00:00
|
|
|
}
|
2009-06-20 19:34:09 +00:00
|
|
|
}
|
|
|
|
|
2009-09-13 19:30:11 +00:00
|
|
|
void X86ATTInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
|
2009-09-14 01:34:40 +00:00
|
|
|
const char *Modifier) {
|
2009-06-20 07:03:18 +00:00
|
|
|
assert(Modifier == 0 && "Modifiers should not be used");
|
2009-06-20 00:49:26 +00:00
|
|
|
|
|
|
|
const MCOperand &Op = MI->getOperand(OpNo);
|
|
|
|
if (Op.isReg()) {
|
2009-09-13 20:15:16 +00:00
|
|
|
O << '%' << getRegisterName(Op.getReg());
|
2009-06-20 00:49:26 +00:00
|
|
|
} else if (Op.isImm()) {
|
2009-09-09 00:40:31 +00:00
|
|
|
O << '$' << Op.getImm();
|
2009-09-14 01:34:40 +00:00
|
|
|
} else {
|
|
|
|
assert(Op.isExpr() && "unknown operand kind in printOperand");
|
2009-08-14 03:42:12 +00:00
|
|
|
O << '$';
|
2009-09-14 01:49:26 +00:00
|
|
|
Op.getExpr()->print(O, &MAI);
|
2009-06-20 00:49:26 +00:00
|
|
|
}
|
2009-06-19 23:59:57 +00:00
|
|
|
}
|
|
|
|
|
2009-09-13 19:30:11 +00:00
|
|
|
void X86ATTInstPrinter::printLeaMemReference(const MCInst *MI, unsigned Op) {
|
2009-06-20 00:49:26 +00:00
|
|
|
const MCOperand &BaseReg = MI->getOperand(Op);
|
|
|
|
const MCOperand &IndexReg = MI->getOperand(Op+2);
|
|
|
|
const MCOperand &DispSpec = MI->getOperand(Op+3);
|
|
|
|
|
|
|
|
if (DispSpec.isImm()) {
|
|
|
|
int64_t DispVal = DispSpec.getImm();
|
|
|
|
if (DispVal || (!IndexReg.getReg() && !BaseReg.getReg()))
|
|
|
|
O << DispVal;
|
|
|
|
} else {
|
2009-09-09 00:40:31 +00:00
|
|
|
assert(DispSpec.isExpr() && "non-immediate displacement for LEA?");
|
2009-09-14 01:49:26 +00:00
|
|
|
DispSpec.getExpr()->print(O, &MAI);
|
2009-06-20 00:49:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (IndexReg.getReg() || BaseReg.getReg()) {
|
|
|
|
O << '(';
|
|
|
|
if (BaseReg.getReg())
|
2009-06-20 07:59:10 +00:00
|
|
|
printOperand(MI, Op);
|
2009-06-20 00:49:26 +00:00
|
|
|
|
|
|
|
if (IndexReg.getReg()) {
|
|
|
|
O << ',';
|
2009-06-20 07:59:10 +00:00
|
|
|
printOperand(MI, Op+2);
|
2009-06-20 08:13:12 +00:00
|
|
|
unsigned ScaleVal = MI->getOperand(Op+1).getImm();
|
|
|
|
if (ScaleVal != 1)
|
2009-06-20 00:49:26 +00:00
|
|
|
O << ',' << ScaleVal;
|
|
|
|
}
|
|
|
|
O << ')';
|
|
|
|
}
|
2009-06-19 23:59:57 +00:00
|
|
|
}
|
|
|
|
|
2009-09-13 19:30:11 +00:00
|
|
|
void X86ATTInstPrinter::printMemReference(const MCInst *MI, unsigned Op) {
|
2009-09-14 01:34:40 +00:00
|
|
|
// If this has a segment register, print it.
|
|
|
|
if (MI->getOperand(Op+4).getReg()) {
|
2009-06-20 07:03:18 +00:00
|
|
|
printOperand(MI, Op+4);
|
2009-06-20 00:49:26 +00:00
|
|
|
O << ':';
|
|
|
|
}
|
2009-06-20 07:03:18 +00:00
|
|
|
printLeaMemReference(MI, Op);
|
2009-06-19 23:59:57 +00:00
|
|
|
}
|