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