opnsense-src/contrib/llvm/lib/Target/Alpha/AlphaAsmPrinter.cpp

167 lines
5.4 KiB
C++
Raw Normal View History

2009-06-02 13:52:33 -04:00
//===-- AlphaAsmPrinter.cpp - Alpha LLVM assembly writer ------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file contains a printer that converts from our internal representation
// of machine-dependent LLVM code to GAS-format Alpha assembly language.
//
//===----------------------------------------------------------------------===//
#define DEBUG_TYPE "asm-printer"
#include "Alpha.h"
#include "AlphaInstrInfo.h"
#include "AlphaTargetMachine.h"
#include "llvm/Module.h"
#include "llvm/Type.h"
#include "llvm/Assembly/Writer.h"
#include "llvm/CodeGen/AsmPrinter.h"
2009-10-14 13:57:32 -04:00
#include "llvm/MC/MCStreamer.h"
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/MC/MCSymbol.h"
2010-03-16 12:51:38 -04:00
#include "llvm/Target/Mangler.h"
2009-10-14 13:57:32 -04:00
#include "llvm/Target/TargetLoweringObjectFile.h"
2009-06-02 13:52:33 -04:00
#include "llvm/Target/TargetMachine.h"
2009-10-14 13:57:32 -04:00
#include "llvm/Target/TargetRegistry.h"
2010-04-06 11:52:58 -04:00
#include "llvm/ADT/SmallString.h"
#include "llvm/Support/raw_ostream.h"
2009-06-02 13:52:33 -04:00
using namespace llvm;
namespace {
2009-11-04 09:58:56 -05:00
struct AlphaAsmPrinter : public AsmPrinter {
2009-06-02 13:52:33 -04:00
/// Unique incrementer for label values for referencing Global values.
///
2010-04-06 11:52:58 -04:00
explicit AlphaAsmPrinter(TargetMachine &tm, MCStreamer &Streamer)
: AsmPrinter(tm, Streamer) {}
2009-06-02 13:52:33 -04:00
virtual const char *getPassName() const {
return "Alpha Assembly Printer";
}
2010-04-06 11:52:58 -04:00
void printInstruction(const MachineInstr *MI, raw_ostream &O);
2010-02-16 04:30:23 -05:00
void EmitInstruction(const MachineInstr *MI) {
2010-04-06 11:52:58 -04:00
SmallString<128> Str;
raw_svector_ostream OS(Str);
printInstruction(MI, OS);
OutStreamer.EmitRawText(OS.str());
2010-02-16 04:30:23 -05:00
}
2009-10-14 13:57:32 -04:00
static const char *getRegisterName(unsigned RegNo);
2010-04-06 11:52:58 -04:00
void printOp(const MachineOperand &MO, raw_ostream &O);
void printOperand(const MachineInstr *MI, int opNum, raw_ostream &O);
2010-02-16 04:30:23 -05:00
virtual void EmitFunctionBodyStart();
virtual void EmitFunctionBodyEnd();
2009-10-14 13:57:32 -04:00
void EmitStartOfAsmFile(Module &M);
2009-06-02 13:52:33 -04:00
bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
2010-04-06 11:52:58 -04:00
unsigned AsmVariant, const char *ExtraCode,
raw_ostream &O);
2009-06-02 13:52:33 -04:00
bool PrintAsmMemoryOperand(const MachineInstr *MI,
2010-04-06 11:52:58 -04:00
unsigned OpNo, unsigned AsmVariant,
const char *ExtraCode, raw_ostream &O);
2009-06-02 13:52:33 -04:00
};
} // end of anonymous namespace
#include "AlphaGenAsmWriter.inc"
2010-04-06 11:52:58 -04:00
void AlphaAsmPrinter::printOperand(const MachineInstr *MI, int opNum,
raw_ostream &O) {
2009-06-02 13:52:33 -04:00
const MachineOperand &MO = MI->getOperand(opNum);
2010-05-04 12:11:02 -04:00
if (MO.isReg()) {
2009-06-02 13:52:33 -04:00
assert(TargetRegisterInfo::isPhysicalRegister(MO.getReg()) &&
"Not physreg??");
2009-10-14 13:57:32 -04:00
O << getRegisterName(MO.getReg());
2009-06-02 13:52:33 -04:00
} else if (MO.isImm()) {
O << MO.getImm();
assert(MO.getImm() < (1 << 30));
} else {
2010-04-06 11:52:58 -04:00
printOp(MO, O);
2009-06-02 13:52:33 -04:00
}
}
2010-04-06 11:52:58 -04:00
void AlphaAsmPrinter::printOp(const MachineOperand &MO, raw_ostream &O) {
2009-06-02 13:52:33 -04:00
switch (MO.getType()) {
case MachineOperand::MO_Register:
2009-10-14 13:57:32 -04:00
O << getRegisterName(MO.getReg());
2009-06-02 13:52:33 -04:00
return;
case MachineOperand::MO_Immediate:
assert(0 && "printOp() does not handle immediate values");
2009-06-02 13:52:33 -04:00
return;
case MachineOperand::MO_MachineBasicBlock:
2010-03-16 12:51:38 -04:00
O << *MO.getMBB()->getSymbol();
2009-06-02 13:52:33 -04:00
return;
case MachineOperand::MO_ConstantPoolIndex:
2009-10-14 13:57:32 -04:00
O << MAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber() << "_"
2009-06-02 13:52:33 -04:00
<< MO.getIndex();
return;
case MachineOperand::MO_ExternalSymbol:
O << MO.getSymbolName();
return;
2009-10-14 13:57:32 -04:00
case MachineOperand::MO_GlobalAddress:
2010-03-16 12:51:38 -04:00
O << *Mang->getSymbol(MO.getGlobal());
2009-06-02 13:52:33 -04:00
return;
case MachineOperand::MO_JumpTableIndex:
2009-10-14 13:57:32 -04:00
O << MAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
2009-06-02 13:52:33 -04:00
<< '_' << MO.getIndex();
return;
default:
O << "<unknown operand type: " << MO.getType() << ">";
return;
}
}
2010-02-16 04:30:23 -05:00
/// EmitFunctionBodyStart - Targets can override this to emit stuff before
/// the first basic block in the function.
void AlphaAsmPrinter::EmitFunctionBodyStart() {
2010-04-06 11:52:58 -04:00
OutStreamer.EmitRawText("\t.ent " + Twine(CurrentFnSym->getName()));
2010-02-16 04:30:23 -05:00
}
2009-06-02 13:52:33 -04:00
2010-02-16 04:30:23 -05:00
/// EmitFunctionBodyEnd - Targets can override this to emit stuff after
/// the last basic block in the function.
void AlphaAsmPrinter::EmitFunctionBodyEnd() {
2010-04-06 11:52:58 -04:00
OutStreamer.EmitRawText("\t.end " + Twine(CurrentFnSym->getName()));
2009-06-02 13:52:33 -04:00
}
2009-10-14 13:57:32 -04:00
void AlphaAsmPrinter::EmitStartOfAsmFile(Module &M) {
2010-04-06 11:52:58 -04:00
OutStreamer.EmitRawText(StringRef("\t.arch ev6"));
OutStreamer.EmitRawText(StringRef("\t.set noat"));
2009-06-02 13:52:33 -04:00
}
/// PrintAsmOperand - Print out an operand for an inline asm expression.
///
bool AlphaAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
unsigned AsmVariant,
2010-04-06 11:52:58 -04:00
const char *ExtraCode, raw_ostream &O) {
printOperand(MI, OpNo, O);
2009-06-02 13:52:33 -04:00
return false;
}
bool AlphaAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
2010-04-06 11:52:58 -04:00
unsigned OpNo, unsigned AsmVariant,
const char *ExtraCode,
raw_ostream &O) {
2009-06-02 13:52:33 -04:00
if (ExtraCode && ExtraCode[0])
return true; // Unknown modifier.
O << "0(";
2010-04-06 11:52:58 -04:00
printOperand(MI, OpNo, O);
2009-06-02 13:52:33 -04:00
O << ")";
return false;
}
2009-06-22 04:08:12 -04:00
2009-06-27 06:44:33 -04:00
// Force static initialization.
2009-10-14 13:57:32 -04:00
extern "C" void LLVMInitializeAlphaAsmPrinter() {
RegisterAsmPrinter<AlphaAsmPrinter> X(TheAlphaTarget);
2009-06-22 04:08:12 -04:00
}