1 //===-- AlphaAsmPrinter.cpp - Alpha LLVM assembly writer ------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains a printer that converts from our internal representation
11 // of machine-dependent LLVM code to GAS-format Alpha assembly language.
13 //===----------------------------------------------------------------------===//
15 #define DEBUG_TYPE "asm-printer"
17 #include "AlphaInstrInfo.h"
18 #include "AlphaTargetMachine.h"
19 #include "llvm/Module.h"
20 #include "llvm/Type.h"
21 #include "llvm/Assembly/Writer.h"
22 #include "llvm/CodeGen/AsmPrinter.h"
23 #include "llvm/MC/MCStreamer.h"
24 #include "llvm/MC/MCAsmInfo.h"
25 #include "llvm/MC/MCSymbol.h"
26 #include "llvm/Target/Mangler.h"
27 #include "llvm/Target/TargetLoweringObjectFile.h"
28 #include "llvm/Target/TargetMachine.h"
29 #include "llvm/Target/TargetRegistry.h"
30 #include "llvm/ADT/SmallString.h"
31 #include "llvm/Support/raw_ostream.h"
35 struct AlphaAsmPrinter
: public AsmPrinter
{
36 /// Unique incrementer for label values for referencing Global values.
39 explicit AlphaAsmPrinter(TargetMachine
&tm
, MCStreamer
&Streamer
)
40 : AsmPrinter(tm
, Streamer
) {}
42 virtual const char *getPassName() const {
43 return "Alpha Assembly Printer";
45 void printInstruction(const MachineInstr
*MI
, raw_ostream
&O
);
46 void EmitInstruction(const MachineInstr
*MI
) {
48 raw_svector_ostream
OS(Str
);
49 printInstruction(MI
, OS
);
50 OutStreamer
.EmitRawText(OS
.str());
52 static const char *getRegisterName(unsigned RegNo
);
54 void printOp(const MachineOperand
&MO
, raw_ostream
&O
);
55 void printOperand(const MachineInstr
*MI
, int opNum
, raw_ostream
&O
);
56 virtual void EmitFunctionBodyStart();
57 virtual void EmitFunctionBodyEnd();
58 void EmitStartOfAsmFile(Module
&M
);
60 bool PrintAsmOperand(const MachineInstr
*MI
, unsigned OpNo
,
61 unsigned AsmVariant
, const char *ExtraCode
,
63 bool PrintAsmMemoryOperand(const MachineInstr
*MI
,
64 unsigned OpNo
, unsigned AsmVariant
,
65 const char *ExtraCode
, raw_ostream
&O
);
67 } // end of anonymous namespace
69 #include "AlphaGenAsmWriter.inc"
71 void AlphaAsmPrinter::printOperand(const MachineInstr
*MI
, int opNum
,
73 const MachineOperand
&MO
= MI
->getOperand(opNum
);
75 assert(TargetRegisterInfo::isPhysicalRegister(MO
.getReg()) &&
77 O
<< getRegisterName(MO
.getReg());
78 } else if (MO
.isImm()) {
80 assert(MO
.getImm() < (1 << 30));
87 void AlphaAsmPrinter::printOp(const MachineOperand
&MO
, raw_ostream
&O
) {
88 switch (MO
.getType()) {
89 case MachineOperand::MO_Register
:
90 O
<< getRegisterName(MO
.getReg());
93 case MachineOperand::MO_Immediate
:
94 assert(0 && "printOp() does not handle immediate values");
97 case MachineOperand::MO_MachineBasicBlock
:
98 O
<< *MO
.getMBB()->getSymbol();
101 case MachineOperand::MO_ConstantPoolIndex
:
102 O
<< MAI
->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber() << "_"
106 case MachineOperand::MO_ExternalSymbol
:
107 O
<< MO
.getSymbolName();
110 case MachineOperand::MO_GlobalAddress
:
111 O
<< *Mang
->getSymbol(MO
.getGlobal());
114 case MachineOperand::MO_JumpTableIndex
:
115 O
<< MAI
->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
116 << '_' << MO
.getIndex();
120 O
<< "<unknown operand type: " << MO
.getType() << ">";
125 /// EmitFunctionBodyStart - Targets can override this to emit stuff before
126 /// the first basic block in the function.
127 void AlphaAsmPrinter::EmitFunctionBodyStart() {
128 OutStreamer
.EmitRawText("\t.ent " + Twine(CurrentFnSym
->getName()));
131 /// EmitFunctionBodyEnd - Targets can override this to emit stuff after
132 /// the last basic block in the function.
133 void AlphaAsmPrinter::EmitFunctionBodyEnd() {
134 OutStreamer
.EmitRawText("\t.end " + Twine(CurrentFnSym
->getName()));
137 void AlphaAsmPrinter::EmitStartOfAsmFile(Module
&M
) {
138 OutStreamer
.EmitRawText(StringRef("\t.arch ev6"));
139 OutStreamer
.EmitRawText(StringRef("\t.set noat"));
142 /// PrintAsmOperand - Print out an operand for an inline asm expression.
144 bool AlphaAsmPrinter::PrintAsmOperand(const MachineInstr
*MI
, unsigned OpNo
,
146 const char *ExtraCode
, raw_ostream
&O
) {
147 printOperand(MI
, OpNo
, O
);
151 bool AlphaAsmPrinter::PrintAsmMemoryOperand(const MachineInstr
*MI
,
152 unsigned OpNo
, unsigned AsmVariant
,
153 const char *ExtraCode
,
155 if (ExtraCode
&& ExtraCode
[0])
156 return true; // Unknown modifier.
158 printOperand(MI
, OpNo
, O
);
163 // Force static initialization.
164 extern "C" void LLVMInitializeAlphaAsmPrinter() {
165 RegisterAsmPrinter
<AlphaAsmPrinter
> X(TheAlphaTarget
);