[llvm-commits] CVS: llvm/lib/Target/X86/X86ATTAsmPrinter.cpp X86AsmPrinter.cpp X86AsmPrinter.h
Nate Begeman
natebegeman at mac.com
Thu Jul 7 17:23:38 PDT 2005
Changes in directory llvm/lib/Target/X86:
X86ATTAsmPrinter.cpp updated: 1.1 -> 1.2
X86AsmPrinter.cpp updated: 1.140 -> 1.141
X86AsmPrinter.h updated: 1.1 -> 1.2
---
Log message:
Add support for assembling .s files on mac os x for intel
Add support for running bugpoint on mac os x for intel
---
Diffs of the changes: (+502 -413)
X86ATTAsmPrinter.cpp | 379 ++++++++++++++++++++++++++-----------------------
X86AsmPrinter.cpp | 393 ++++++++++++++++++++++++++++-----------------------
X86AsmPrinter.h | 143 +++++++++---------
3 files changed, 502 insertions(+), 413 deletions(-)
Index: llvm/lib/Target/X86/X86ATTAsmPrinter.cpp
diff -u llvm/lib/Target/X86/X86ATTAsmPrinter.cpp:1.1 llvm/lib/Target/X86/X86ATTAsmPrinter.cpp:1.2
--- llvm/lib/Target/X86/X86ATTAsmPrinter.cpp:1.1 Fri Jul 1 17:44:09 2005
+++ llvm/lib/Target/X86/X86ATTAsmPrinter.cpp Thu Jul 7 19:23:26 2005
@@ -1,171 +1,208 @@
-//===-- X86ATTAsmPrinter.cpp - Convert X86 LLVM code to Intel assembly ----===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file was developed by the LLVM research group and 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 AT&T format assembly
-// language. This printer is the output mechanism used by `llc'.
-//
-//===----------------------------------------------------------------------===//
-
-#include "X86ATTAsmPrinter.h"
-#include "X86.h"
-#include "X86TargetMachine.h"
-#include "llvm/Module.h"
-#include "llvm/Support/Mangler.h"
-using namespace llvm;
-using namespace x86;
-
-/// runOnMachineFunction - This uses the printMachineInstruction()
-/// method to print assembly for each instruction.
-///
-bool X86ATTAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
- setupMachineFunction(MF);
- O << "\n\n";
-
- // Print out constants referenced by the function
- printConstantPool(MF.getConstantPool());
-
- // Print out labels for the function.
- O << "\t.text\n";
- emitAlignment(4);
- O << "\t.globl\t" << CurrentFnName << "\n";
- if (!forCygwin && !forDarwin)
- O << "\t.type\t" << CurrentFnName << ", @function\n";
- O << CurrentFnName << ":\n";
-
- // Print out code for the function.
- for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
- I != E; ++I) {
- // Print a label for the basic block.
- if (I->pred_begin() != I->pred_end())
- O << ".LBB" << CurrentFnName << "_" << I->getNumber() << ":\t"
- << CommentString << " " << I->getBasicBlock()->getName() << "\n";
- for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
- II != E; ++II) {
- // Print the assembly for the instruction.
- O << "\t";
- printMachineInstruction(II);
- }
- }
-
- // We didn't modify anything.
- return false;
-}
-
-void X86ATTAsmPrinter::printOp(const MachineOperand &MO, bool isCallOp) {
- const MRegisterInfo &RI = *TM.getRegisterInfo();
- switch (MO.getType()) {
- case MachineOperand::MO_VirtualRegister:
- case MachineOperand::MO_MachineRegister:
- assert(MRegisterInfo::isPhysicalRegister(MO.getReg()) &&
- "Virtual registers should not make it this far!");
- O << '%';
- for (const char *Name = RI.get(MO.getReg()).Name; *Name; ++Name)
- O << (char)tolower(*Name);
- return;
-
- case MachineOperand::MO_SignExtendedImmed:
- case MachineOperand::MO_UnextendedImmed:
- O << '$' << (int)MO.getImmedValue();
- return;
- case MachineOperand::MO_MachineBasicBlock: {
- MachineBasicBlock *MBBOp = MO.getMachineBasicBlock();
- O << ".LBB" << Mang->getValueName(MBBOp->getParent()->getFunction())
- << "_" << MBBOp->getNumber () << "\t# "
- << MBBOp->getBasicBlock ()->getName ();
- return;
- }
- case MachineOperand::MO_PCRelativeDisp:
- std::cerr << "Shouldn't use addPCDisp() when building X86 MachineInstrs";
- abort ();
- return;
- case MachineOperand::MO_GlobalAddress: {
- if (!isCallOp) O << '$';
- O << Mang->getValueName(MO.getGlobal());
- int Offset = MO.getOffset();
- if (Offset > 0)
- O << "+" << Offset;
- else if (Offset < 0)
- O << Offset;
- return;
- }
- case MachineOperand::MO_ExternalSymbol:
- if (!isCallOp) O << '$';
- O << GlobalPrefix << MO.getSymbolName();
- return;
- default:
- O << "<unknown operand type>"; return;
- }
-}
-
-void X86ATTAsmPrinter::printMemReference(const MachineInstr *MI, unsigned Op){
- assert(isMem(MI, Op) && "Invalid memory reference!");
-
- const MachineOperand &BaseReg = MI->getOperand(Op);
- int ScaleVal = MI->getOperand(Op+1).getImmedValue();
- const MachineOperand &IndexReg = MI->getOperand(Op+2);
- const MachineOperand &DispSpec = MI->getOperand(Op+3);
-
- if (BaseReg.isFrameIndex()) {
- O << "[frame slot #" << BaseReg.getFrameIndex();
- if (DispSpec.getImmedValue())
- O << " + " << DispSpec.getImmedValue();
- O << "]";
- return;
- } else if (BaseReg.isConstantPoolIndex()) {
- O << ".CPI" << CurrentFnName << "_"
- << BaseReg.getConstantPoolIndex();
- if (DispSpec.getImmedValue())
- O << "+" << DispSpec.getImmedValue();
- if (IndexReg.getReg()) {
- O << "(,";
- printOp(IndexReg);
- if (ScaleVal != 1)
- O << "," << ScaleVal;
- O << ")";
- }
- return;
- }
-
- if (DispSpec.isGlobalAddress()) {
- printOp(DispSpec, true);
- } else {
- int DispVal = DispSpec.getImmedValue();
- if (DispVal || (!IndexReg.getReg() && !BaseReg.getReg()))
- O << DispVal;
- }
-
- if (IndexReg.getReg() || BaseReg.getReg()) {
- O << "(";
- if (BaseReg.getReg())
- printOp(BaseReg);
-
- if (IndexReg.getReg()) {
- O << ",";
- printOp(IndexReg);
- if (ScaleVal != 1)
- O << "," << ScaleVal;
- }
-
- O << ")";
- }
-}
-
-/// printMachineInstruction -- Print out a single X86 LLVM instruction
-/// MI in Intel syntax to the current output stream.
-///
-void X86ATTAsmPrinter::printMachineInstruction(const MachineInstr *MI) {
- ++EmittedInsts;
- // Call the autogenerated instruction printer routines.
- printInstruction(MI);
-}
-
-// Include the auto-generated portion of the assembly writer.
-#include "X86GenAsmWriter.inc"
-
+//===-- X86ATTAsmPrinter.cpp - Convert X86 LLVM code to Intel assembly ----===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file was developed by the LLVM research group and 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 AT&T format assembly
+// language. This printer is the output mechanism used by `llc'.
+//
+//===----------------------------------------------------------------------===//
+
+#include "X86ATTAsmPrinter.h"
+#include "X86.h"
+#include "X86TargetMachine.h"
+#include "llvm/Module.h"
+#include "llvm/Support/Mangler.h"
+using namespace llvm;
+using namespace x86;
+
+/// runOnMachineFunction - This uses the printMachineInstruction()
+/// method to print assembly for each instruction.
+///
+bool X86ATTAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
+ setupMachineFunction(MF);
+ O << "\n\n";
+
+ // Print out constants referenced by the function
+ printConstantPool(MF.getConstantPool());
+
+ // Print out labels for the function.
+ O << "\t.text\n";
+ emitAlignment(4);
+ O << "\t.globl\t" << CurrentFnName << "\n";
+ if (!forCygwin && !forDarwin)
+ O << "\t.type\t" << CurrentFnName << ", @function\n";
+ O << CurrentFnName << ":\n";
+
+ // Print out code for the function.
+ for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
+ I != E; ++I) {
+ // Print a label for the basic block.
+ if (I->pred_begin() != I->pred_end())
+ O << ".LBB" << CurrentFnName << "_" << I->getNumber() << ":\t"
+ << CommentString << " " << I->getBasicBlock()->getName() << "\n";
+ for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
+ II != E; ++II) {
+ // Print the assembly for the instruction.
+ O << "\t";
+ printMachineInstruction(II);
+ }
+ }
+
+ // We didn't modify anything.
+ return false;
+}
+
+void X86ATTAsmPrinter::printOp(const MachineOperand &MO, bool isCallOp) {
+ const MRegisterInfo &RI = *TM.getRegisterInfo();
+ switch (MO.getType()) {
+ case MachineOperand::MO_VirtualRegister:
+ case MachineOperand::MO_MachineRegister:
+ assert(MRegisterInfo::isPhysicalRegister(MO.getReg()) &&
+ "Virtual registers should not make it this far!");
+ O << '%';
+ for (const char *Name = RI.get(MO.getReg()).Name; *Name; ++Name)
+ O << (char)tolower(*Name);
+ return;
+
+ case MachineOperand::MO_SignExtendedImmed:
+ case MachineOperand::MO_UnextendedImmed:
+ O << '$' << (int)MO.getImmedValue();
+ return;
+ case MachineOperand::MO_MachineBasicBlock: {
+ MachineBasicBlock *MBBOp = MO.getMachineBasicBlock();
+ O << ".LBB" << Mang->getValueName(MBBOp->getParent()->getFunction())
+ << "_" << MBBOp->getNumber () << "\t# "
+ << MBBOp->getBasicBlock ()->getName ();
+ return;
+ }
+ case MachineOperand::MO_PCRelativeDisp:
+ std::cerr << "Shouldn't use addPCDisp() when building X86 MachineInstrs";
+ abort ();
+ return;
+ case MachineOperand::MO_GlobalAddress: {
+ // Darwin block shameless ripped from PowerPCAsmPrinter.cpp
+ if (forDarwin) {
+ if (!isCallOp) O << '$';
+ GlobalValue *GV = MO.getGlobal();
+ std::string Name = Mang->getValueName(GV);
+
+ // Dynamically-resolved functions need a stub for the function. Be
+ // wary however not to output $stub for external functions whose addresses
+ // are taken. Those should be emitted as $non_lazy_ptr below.
+ Function *F = dyn_cast<Function>(GV);
+ if (F && isCallOp && F->isExternal()) {
+ FnStubs.insert(Name);
+ O << "L" << Name << "$stub";
+ return;
+ }
+
+ // Link-once, External, or Weakly-linked global variables need
+ // non-lazily-resolved stubs
+ if (GV->hasLinkOnceLinkage()) {
+ LinkOnceStubs.insert(Name);
+ O << "L" << Name << "$non_lazy_ptr";
+ return;
+ }
+ if (GV->isExternal() || GV->hasWeakLinkage()) {
+ GVStubs.insert(Name);
+ O << "L" << Name << "$non_lazy_ptr";
+ return;
+ }
+ O << Mang->getValueName(GV);
+ return;
+ }
+ if (!isCallOp) O << '$';
+ O << Mang->getValueName(MO.getGlobal());
+ int Offset = MO.getOffset();
+ if (Offset > 0)
+ O << "+" << Offset;
+ else if (Offset < 0)
+ O << Offset;
+ return;
+ }
+ case MachineOperand::MO_ExternalSymbol:
+ if (isCallOp && forDarwin) {
+ std::string Name(GlobalPrefix); Name += MO.getSymbolName();
+ FnStubs.insert(Name);
+ O << "L" << Name << "$stub";
+ return;
+ }
+ if (!isCallOp) O << '$';
+ O << GlobalPrefix << MO.getSymbolName();
+ return;
+ default:
+ O << "<unknown operand type>"; return;
+ }
+}
+
+void X86ATTAsmPrinter::printMemReference(const MachineInstr *MI, unsigned Op){
+ assert(isMem(MI, Op) && "Invalid memory reference!");
+
+ const MachineOperand &BaseReg = MI->getOperand(Op);
+ int ScaleVal = MI->getOperand(Op+1).getImmedValue();
+ const MachineOperand &IndexReg = MI->getOperand(Op+2);
+ const MachineOperand &DispSpec = MI->getOperand(Op+3);
+
+ if (BaseReg.isFrameIndex()) {
+ O << "[frame slot #" << BaseReg.getFrameIndex();
+ if (DispSpec.getImmedValue())
+ O << " + " << DispSpec.getImmedValue();
+ O << "]";
+ return;
+ } else if (BaseReg.isConstantPoolIndex()) {
+ O << ".CPI" << CurrentFnName << "_"
+ << BaseReg.getConstantPoolIndex();
+ if (DispSpec.getImmedValue())
+ O << "+" << DispSpec.getImmedValue();
+ if (IndexReg.getReg()) {
+ O << "(,";
+ printOp(IndexReg);
+ if (ScaleVal != 1)
+ O << "," << ScaleVal;
+ O << ")";
+ }
+ return;
+ }
+
+ if (DispSpec.isGlobalAddress()) {
+ printOp(DispSpec, true);
+ } else {
+ int DispVal = DispSpec.getImmedValue();
+ if (DispVal || (!IndexReg.getReg() && !BaseReg.getReg()))
+ O << DispVal;
+ }
+
+ if (IndexReg.getReg() || BaseReg.getReg()) {
+ O << "(";
+ if (BaseReg.getReg())
+ printOp(BaseReg);
+
+ if (IndexReg.getReg()) {
+ O << ",";
+ printOp(IndexReg);
+ if (ScaleVal != 1)
+ O << "," << ScaleVal;
+ }
+
+ O << ")";
+ }
+}
+
+/// printMachineInstruction -- Print out a single X86 LLVM instruction
+/// MI in Intel syntax to the current output stream.
+///
+void X86ATTAsmPrinter::printMachineInstruction(const MachineInstr *MI) {
+ ++EmittedInsts;
+ // Call the autogenerated instruction printer routines.
+ printInstruction(MI);
+}
+
+// Include the auto-generated portion of the assembly writer.
+#include "X86GenAsmWriter.inc"
+
Index: llvm/lib/Target/X86/X86AsmPrinter.cpp
diff -u llvm/lib/Target/X86/X86AsmPrinter.cpp:1.140 llvm/lib/Target/X86/X86AsmPrinter.cpp:1.141
--- llvm/lib/Target/X86/X86AsmPrinter.cpp:1.140 Fri Jul 1 18:56:38 2005
+++ llvm/lib/Target/X86/X86AsmPrinter.cpp Thu Jul 7 19:23:26 2005
@@ -1,173 +1,220 @@
-//===-- X86AsmPrinter.cpp - Convert X86 LLVM IR to X86 assembly -----------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file was developed by the LLVM research group and is distributed under
-// the University of Illinois Open Source License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file the shared super class printer that converts from our internal
-// representation of machine-dependent LLVM code to Intel and AT&T format
-// assembly language.
-// This printer is the output mechanism used by `llc'.
-//
-//===----------------------------------------------------------------------===//
-
-#include "X86ATTAsmPrinter.h"
-#include "X86IntelAsmPrinter.h"
-#include "X86.h"
-#include "llvm/Module.h"
-#include "llvm/Assembly/Writer.h"
-#include "llvm/CodeGen/MachineConstantPool.h"
-#include "llvm/Support/Mangler.h"
-#include "llvm/Support/CommandLine.h"
-using namespace llvm;
-using namespace x86;
-
-Statistic<> llvm::x86::EmittedInsts("asm-printer",
- "Number of machine instrs printed");
-
-enum AsmWriterFlavorTy { att, intel };
-cl::opt<AsmWriterFlavorTy>
-AsmWriterFlavor("x86-asm-syntax",
- cl::desc("Choose style of code to emit from X86 backend:"),
- cl::values(
- clEnumVal(att, " Emit AT&T-style assembly"),
- clEnumVal(intel, " Emit Intel-style assembly"),
- clEnumValEnd),
- cl::init(att));
-
-/// doInitialization
-bool X86SharedAsmPrinter::doInitialization(Module& M) {
- bool leadingUnderscore = false;
- forCygwin = false;
- const std::string& TT = M.getTargetTriple();
- if (TT.length() > 5) {
- forCygwin = TT.find("cygwin") != std::string::npos ||
- TT.find("mingw") != std::string::npos;
- forDarwin = TT.find("darwin") != std::string::npos;
- } else if (TT.empty()) {
- #if defined(__CYGWIN__) || defined(__MINGW32__)
- forCygwin = true;
- #elif defined(__MACOSX__)
- forDarwin = true;
- #elif defined(_WIN32)
- leadingUnderscore = true;
- #else
- leadingUnderscore = false;
- #endif
- }
- if (leadingUnderscore || forCygwin || forDarwin)
- GlobalPrefix = "_";
-
- if (forDarwin)
- AlignmentIsInBytes = false;
-
- return AsmPrinter::doInitialization(M);
-}
-
-/// printConstantPool - Print to the current output stream assembly
-/// representations of the constants in the constant pool MCP. This is
-/// used to print out constants which have been "spilled to memory" by
-/// the code generator.
-///
-void X86SharedAsmPrinter::printConstantPool(MachineConstantPool *MCP) {
- const std::vector<Constant*> &CP = MCP->getConstants();
- const TargetData &TD = TM.getTargetData();
-
- if (CP.empty()) return;
-
- for (unsigned i = 0, e = CP.size(); i != e; ++i) {
- O << "\t.section .rodata\n";
- emitAlignment(TD.getTypeAlignmentShift(CP[i]->getType()));
- O << ".CPI" << CurrentFnName << "_" << i << ":\t\t\t\t\t" << CommentString
- << *CP[i] << "\n";
- emitGlobalConstant(CP[i]);
- }
-}
-
-bool X86SharedAsmPrinter::doFinalization(Module &M) {
- const TargetData &TD = TM.getTargetData();
- std::string CurSection;
-
- // Print out module-level global variables here.
- for (Module::const_global_iterator I = M.global_begin(), E = M.global_end(); I != E; ++I)
- if (I->hasInitializer()) { // External global require no code
- O << "\n\n";
- std::string name = Mang->getValueName(I);
- Constant *C = I->getInitializer();
- unsigned Size = TD.getTypeSize(C->getType());
- unsigned Align = TD.getTypeAlignmentShift(C->getType());
-
- if (C->isNullValue() &&
- (I->hasLinkOnceLinkage() || I->hasInternalLinkage() ||
- I->hasWeakLinkage() /* FIXME: Verify correct */)) {
- SwitchSection(O, CurSection, ".data");
- if (!forCygwin && I->hasInternalLinkage())
- O << "\t.local " << name << "\n";
- O << "\t.comm " << name << "," << TD.getTypeSize(C->getType());
- if (!forCygwin)
- O << "," << (1 << Align);
- O << "\t\t# ";
- WriteAsOperand(O, I, true, true, &M);
- O << "\n";
- } else {
- switch (I->getLinkage()) {
- case GlobalValue::LinkOnceLinkage:
- case GlobalValue::WeakLinkage: // FIXME: Verify correct for weak.
- // Nonnull linkonce -> weak
- O << "\t.weak " << name << "\n";
- SwitchSection(O, CurSection, "");
- O << "\t.section\t.llvm.linkonce.d." << name << ",\"aw\", at progbits\n";
- break;
- case GlobalValue::AppendingLinkage:
- // FIXME: appending linkage variables should go into a section of
- // their name or something. For now, just emit them as external.
- case GlobalValue::ExternalLinkage:
- // If external or appending, declare as a global symbol
- O << "\t.globl " << name << "\n";
- // FALL THROUGH
- case GlobalValue::InternalLinkage:
- if (C->isNullValue())
- SwitchSection(O, CurSection, ".bss");
- else
- SwitchSection(O, CurSection, ".data");
- break;
- case GlobalValue::GhostLinkage:
- std::cerr << "GhostLinkage cannot appear in X86AsmPrinter!\n";
- abort();
- }
-
- emitAlignment(Align);
- if (!forCygwin && !forDarwin) {
- O << "\t.type " << name << ", at object\n";
- O << "\t.size " << name << "," << Size << "\n";
- }
- O << name << ":\t\t\t\t# ";
- WriteAsOperand(O, I, true, true, &M);
- O << " = ";
- WriteAsOperand(O, C, false, false, &M);
- O << "\n";
- emitGlobalConstant(C);
- }
- }
-
- AsmPrinter::doFinalization(M);
- return false; // success
-}
-
-/// createX86CodePrinterPass - Returns a pass that prints the X86 assembly code
-/// for a MachineFunction to the given output stream, using the given target
-/// machine description.
-///
-FunctionPass *llvm::createX86CodePrinterPass(std::ostream &o,TargetMachine &tm){
- switch (AsmWriterFlavor) {
- default:
- assert(0 && "Unknown asm flavor!");
- case intel:
- return new X86IntelAsmPrinter(o, tm);
- case att:
- return new X86ATTAsmPrinter(o, tm);
- }
-}
+//===-- X86AsmPrinter.cpp - Convert X86 LLVM IR to X86 assembly -----------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file was developed by the LLVM research group and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file the shared super class printer that converts from our internal
+// representation of machine-dependent LLVM code to Intel and AT&T format
+// assembly language.
+// This printer is the output mechanism used by `llc'.
+//
+//===----------------------------------------------------------------------===//
+
+#include "X86ATTAsmPrinter.h"
+#include "X86IntelAsmPrinter.h"
+#include "X86.h"
+#include "llvm/Module.h"
+#include "llvm/Assembly/Writer.h"
+#include "llvm/CodeGen/MachineConstantPool.h"
+#include "llvm/Support/Mangler.h"
+#include "llvm/Support/CommandLine.h"
+using namespace llvm;
+using namespace x86;
+
+Statistic<> llvm::x86::EmittedInsts("asm-printer",
+ "Number of machine instrs printed");
+
+enum AsmWriterFlavorTy { att, intel };
+cl::opt<AsmWriterFlavorTy>
+AsmWriterFlavor("x86-asm-syntax",
+ cl::desc("Choose style of code to emit from X86 backend:"),
+ cl::values(
+ clEnumVal(att, " Emit AT&T-style assembly"),
+ clEnumVal(intel, " Emit Intel-style assembly"),
+ clEnumValEnd),
+ cl::init(att));
+
+/// doInitialization
+bool X86SharedAsmPrinter::doInitialization(Module& M) {
+ bool leadingUnderscore = false;
+ forCygwin = false;
+ const std::string& TT = M.getTargetTriple();
+ if (TT.length() > 5) {
+ forCygwin = TT.find("cygwin") != std::string::npos ||
+ TT.find("mingw") != std::string::npos;
+ forDarwin = TT.find("darwin") != std::string::npos;
+ } else if (TT.empty()) {
+ #if defined(__CYGWIN__) || defined(__MINGW32__)
+ forCygwin = true;
+ #elif defined(__APPLE__)
+ forDarwin = true;
+ #elif defined(_WIN32)
+ leadingUnderscore = true;
+ #else
+ leadingUnderscore = false;
+ #endif
+ }
+ if (leadingUnderscore || forCygwin || forDarwin)
+ GlobalPrefix = "_";
+
+ if (forDarwin)
+ AlignmentIsInBytes = false;
+
+ return AsmPrinter::doInitialization(M);
+}
+
+/// printConstantPool - Print to the current output stream assembly
+/// representations of the constants in the constant pool MCP. This is
+/// used to print out constants which have been "spilled to memory" by
+/// the code generator.
+///
+void X86SharedAsmPrinter::printConstantPool(MachineConstantPool *MCP) {
+ const std::vector<Constant*> &CP = MCP->getConstants();
+ const TargetData &TD = TM.getTargetData();
+
+ if (CP.empty()) return;
+
+ for (unsigned i = 0, e = CP.size(); i != e; ++i) {
+ if (forDarwin)
+ O << "\t.data\n";
+ else
+ O << "\t.section .rodata\n";
+ emitAlignment(TD.getTypeAlignmentShift(CP[i]->getType()));
+ O << ".CPI" << CurrentFnName << "_" << i << ":\t\t\t\t\t" << CommentString
+ << *CP[i] << "\n";
+ emitGlobalConstant(CP[i]);
+ }
+}
+
+bool X86SharedAsmPrinter::doFinalization(Module &M) {
+ const TargetData &TD = TM.getTargetData();
+ std::string CurSection;
+
+ // Print out module-level global variables here.
+ for (Module::const_global_iterator I = M.global_begin(), E = M.global_end(); I != E; ++I)
+ if (I->hasInitializer()) { // External global require no code
+ O << "\n\n";
+ std::string name = Mang->getValueName(I);
+ Constant *C = I->getInitializer();
+ unsigned Size = TD.getTypeSize(C->getType());
+ unsigned Align = TD.getTypeAlignmentShift(C->getType());
+
+ if (C->isNullValue() &&
+ (I->hasLinkOnceLinkage() || I->hasInternalLinkage() ||
+ I->hasWeakLinkage() /* FIXME: Verify correct */)) {
+ SwitchSection(O, CurSection, ".data");
+ if (!forCygwin && !forDarwin && I->hasInternalLinkage())
+ O << "\t.local " << name << "\n";
+ if (forDarwin && I->hasInternalLinkage())
+ O << "\t.lcomm " << name << "," << Size << "," << Align;
+ else
+ O << "\t.comm " << name << "," << Size;
+ if (!forCygwin && !forDarwin)
+ O << "," << (1 << Align);
+ O << "\t\t# ";
+ WriteAsOperand(O, I, true, true, &M);
+ O << "\n";
+ } else {
+ switch (I->getLinkage()) {
+ case GlobalValue::LinkOnceLinkage:
+ case GlobalValue::WeakLinkage: // FIXME: Verify correct for weak.
+ // Nonnull linkonce -> weak
+ O << "\t.weak " << name << "\n";
+ SwitchSection(O, CurSection, "");
+ O << "\t.section\t.llvm.linkonce.d." << name << ",\"aw\", at progbits\n";
+ break;
+ case GlobalValue::AppendingLinkage:
+ // FIXME: appending linkage variables should go into a section of
+ // their name or something. For now, just emit them as external.
+ case GlobalValue::ExternalLinkage:
+ // If external or appending, declare as a global symbol
+ O << "\t.globl " << name << "\n";
+ // FALL THROUGH
+ case GlobalValue::InternalLinkage:
+ if (C->isNullValue())
+ SwitchSection(O, CurSection, ".bss");
+ else
+ SwitchSection(O, CurSection, ".data");
+ break;
+ case GlobalValue::GhostLinkage:
+ std::cerr << "GhostLinkage cannot appear in X86AsmPrinter!\n";
+ abort();
+ }
+
+ emitAlignment(Align);
+ if (!forCygwin && !forDarwin) {
+ O << "\t.type " << name << ", at object\n";
+ O << "\t.size " << name << "," << Size << "\n";
+ }
+ O << name << ":\t\t\t\t# ";
+ WriteAsOperand(O, I, true, true, &M);
+ O << " = ";
+ WriteAsOperand(O, C, false, false, &M);
+ O << "\n";
+ emitGlobalConstant(C);
+ }
+ }
+
+ if (forDarwin) {
+ // Output stubs for dynamically-linked functions
+ unsigned j = 1;
+ for (std::set<std::string>::iterator i = FnStubs.begin(), e = FnStubs.end();
+ i != e; ++i, ++j)
+ {
+ O << "\t.symbol_stub\n";
+ O << "L" << *i << "$stub:\n";
+ O << "\t.indirect_symbol " << *i << "\n";
+ O << "\tjmp\t*L" << j << "$lz\n";
+ O << "L" << *i << "$stub_binder:\n";
+ O << "\tpushl\t$L" << j << "$lz\n";
+ O << "\tjmp\tdyld_stub_binding_helper\n";
+ O << "\t.section __DATA, __la_sym_ptr3,lazy_symbol_pointers\n";
+ O << "L" << j << "$lz:\n";
+ O << "\t.indirect_symbol " << *i << "\n";
+ O << "\t.long\tL" << *i << "$stub_binder\n";
+ }
+
+ O << "\n";
+
+ // Output stubs for external global variables
+ if (GVStubs.begin() != GVStubs.end())
+ O << ".data\n.non_lazy_symbol_pointer\n";
+ for (std::set<std::string>::iterator i = GVStubs.begin(), e = GVStubs.end();
+ i != e; ++i) {
+ O << "L" << *i << "$non_lazy_ptr:\n";
+ O << "\t.indirect_symbol " << *i << "\n";
+ O << "\t.long\t0\n";
+ }
+
+ // Output stubs for link-once variables
+ if (LinkOnceStubs.begin() != LinkOnceStubs.end())
+ O << ".data\n.align 2\n";
+ for (std::set<std::string>::iterator i = LinkOnceStubs.begin(),
+ e = LinkOnceStubs.end(); i != e; ++i) {
+ O << "L" << *i << "$non_lazy_ptr:\n"
+ << "\t.long\t" << *i << '\n';
+ }
+ }
+
+ AsmPrinter::doFinalization(M);
+ return false; // success
+}
+
+/// createX86CodePrinterPass - Returns a pass that prints the X86 assembly code
+/// for a MachineFunction to the given output stream, using the given target
+/// machine description.
+///
+FunctionPass *llvm::createX86CodePrinterPass(std::ostream &o,TargetMachine &tm){
+ switch (AsmWriterFlavor) {
+ default:
+ assert(0 && "Unknown asm flavor!");
+ case intel:
+ return new X86IntelAsmPrinter(o, tm);
+ case att:
+ return new X86ATTAsmPrinter(o, tm);
+ }
+}
Index: llvm/lib/Target/X86/X86AsmPrinter.h
diff -u llvm/lib/Target/X86/X86AsmPrinter.h:1.1 llvm/lib/Target/X86/X86AsmPrinter.h:1.2
--- llvm/lib/Target/X86/X86AsmPrinter.h:1.1 Fri Jul 1 17:44:09 2005
+++ llvm/lib/Target/X86/X86AsmPrinter.h Thu Jul 7 19:23:26 2005
@@ -1,69 +1,74 @@
-//===-- X86AsmPrinter.h - Convert X86 LLVM code to Intel assembly ---------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file was developed by the LLVM research group and is distributed under
-// the University of Illinois Open Source License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file the shared super class printer that converts from our internal
-// representation of machine-dependent LLVM code to Intel and AT&T format
-// assembly language. This printer is the output mechanism used by `llc'.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef X86ASMPRINTER_H
-#define X86ASMPRINTER_H
-
-#include "X86.h"
-#include "llvm/CodeGen/AsmPrinter.h"
-#include "llvm/ADT/Statistic.h"
-
-namespace llvm {
-namespace x86 {
-
-extern Statistic<> EmittedInsts;
-
-struct X86SharedAsmPrinter : public AsmPrinter {
- X86SharedAsmPrinter(std::ostream &O, TargetMachine &TM)
- : AsmPrinter(O, TM), forCygwin(false), forDarwin(false) { }
-
- bool doInitialization(Module &M);
- void printConstantPool(MachineConstantPool *MCP);
- bool doFinalization(Module &M);
-
- bool forCygwin;
- bool forDarwin;
-
- inline static bool isScale(const MachineOperand &MO) {
- return MO.isImmediate() &&
- (MO.getImmedValue() == 1 || MO.getImmedValue() == 2 ||
- MO.getImmedValue() == 4 || MO.getImmedValue() == 8);
- }
-
- inline static bool isMem(const MachineInstr *MI, unsigned Op) {
- if (MI->getOperand(Op).isFrameIndex()) return true;
- if (MI->getOperand(Op).isConstantPoolIndex()) return true;
- return Op+4 <= MI->getNumOperands() &&
- MI->getOperand(Op ).isRegister() && isScale(MI->getOperand(Op+1)) &&
- MI->getOperand(Op+2).isRegister() && (MI->getOperand(Op+3).isImmediate()||
- MI->getOperand(Op+3).isGlobalAddress());
- }
-
- // SwitchSection - Switch to the specified section of the executable if we are
- // not already in it!
- inline static void SwitchSection(std::ostream &OS, std::string &CurSection,
- const char *NewSection) {
- if (CurSection != NewSection) {
- CurSection = NewSection;
- if (!CurSection.empty())
- OS << "\t" << NewSection << "\n";
- }
- }
-};
-
-} // end namespace x86
-} // end namespace llvm
-
-#endif
+//===-- X86AsmPrinter.h - Convert X86 LLVM code to Intel assembly ---------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file was developed by the LLVM research group and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file the shared super class printer that converts from our internal
+// representation of machine-dependent LLVM code to Intel and AT&T format
+// assembly language. This printer is the output mechanism used by `llc'.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef X86ASMPRINTER_H
+#define X86ASMPRINTER_H
+
+#include "X86.h"
+#include "llvm/CodeGen/AsmPrinter.h"
+#include "llvm/ADT/Statistic.h"
+#include <set>
+
+
+namespace llvm {
+namespace x86 {
+
+extern Statistic<> EmittedInsts;
+
+struct X86SharedAsmPrinter : public AsmPrinter {
+ X86SharedAsmPrinter(std::ostream &O, TargetMachine &TM)
+ : AsmPrinter(O, TM), forCygwin(false), forDarwin(false) { }
+
+ bool doInitialization(Module &M);
+ void printConstantPool(MachineConstantPool *MCP);
+ bool doFinalization(Module &M);
+
+ bool forCygwin;
+ bool forDarwin;
+
+ // Necessary for Darwin to print out the apprioriate types of linker stubs
+ std::set<std::string> FnStubs, GVStubs, LinkOnceStubs;
+
+ inline static bool isScale(const MachineOperand &MO) {
+ return MO.isImmediate() &&
+ (MO.getImmedValue() == 1 || MO.getImmedValue() == 2 ||
+ MO.getImmedValue() == 4 || MO.getImmedValue() == 8);
+ }
+
+ inline static bool isMem(const MachineInstr *MI, unsigned Op) {
+ if (MI->getOperand(Op).isFrameIndex()) return true;
+ if (MI->getOperand(Op).isConstantPoolIndex()) return true;
+ return Op+4 <= MI->getNumOperands() &&
+ MI->getOperand(Op ).isRegister() && isScale(MI->getOperand(Op+1)) &&
+ MI->getOperand(Op+2).isRegister() && (MI->getOperand(Op+3).isImmediate()||
+ MI->getOperand(Op+3).isGlobalAddress());
+ }
+
+ // SwitchSection - Switch to the specified section of the executable if we are
+ // not already in it!
+ inline static void SwitchSection(std::ostream &OS, std::string &CurSection,
+ const char *NewSection) {
+ if (CurSection != NewSection) {
+ CurSection = NewSection;
+ if (!CurSection.empty())
+ OS << "\t" << NewSection << "\n";
+ }
+ }
+};
+
+} // end namespace x86
+} // end namespace llvm
+
+#endif
More information about the llvm-commits
mailing list