diff options
author | Reid Spencer <rspencer@reidspencer.com> | 2005-01-23 03:52:14 +0000 |
---|---|---|
committer | Reid Spencer <rspencer@reidspencer.com> | 2005-01-23 03:52:14 +0000 |
commit | 5dc81f63d1ad701fe03a8fadab6053094fd80fa2 (patch) | |
tree | beafcd890f689b9aa19aa460b545ff6bccd9e52a /lib/Target | |
parent | a328c51bb99666ee0c045a57ea6d6ce2b0198f9b (diff) |
Support Cygwin assembly generation. The cygwin version of Gnu ASsembler
doesn't support certain directives and symbols on cygwin are prefixed with
an underscore. This patch makes the necessary adjustments to the output.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19775 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target')
-rw-r--r-- | lib/Target/X86/X86AsmPrinter.cpp | 48 |
1 files changed, 37 insertions, 11 deletions
diff --git a/lib/Target/X86/X86AsmPrinter.cpp b/lib/Target/X86/X86AsmPrinter.cpp index b0d27888fc..ce6d26e7d0 100644 --- a/lib/Target/X86/X86AsmPrinter.cpp +++ b/lib/Target/X86/X86AsmPrinter.cpp @@ -43,10 +43,12 @@ namespace { struct X86SharedAsmPrinter : public AsmPrinter { X86SharedAsmPrinter(std::ostream &O, TargetMachine &TM) - : AsmPrinter(O, TM) { } + : AsmPrinter(O, TM), forCygwin(false) { } + bool doInitialization(Module &M); void printConstantPool(MachineConstantPool *MCP); bool doFinalization(Module &M); + bool forCygwin; }; } @@ -77,6 +79,24 @@ static void SwitchSection(std::ostream &OS, std::string &CurSection, } } +/// doInitialization - determine +bool X86SharedAsmPrinter::doInitialization(Module& M) { + forCygwin = false; + const std::string& TT = M.getTargetTriple(); + if (TT.length() > 5) + forCygwin = TT.find("cygwin") != std::string::npos; + else if (TT.empty()) { +#ifdef __CYGWIN__ + forCygwin = true; +#else + forCygwin = false; +#endif + } + if (forCygwin) + GlobalPrefix = "_"; + 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 @@ -114,11 +134,12 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) { (I->hasLinkOnceLinkage() || I->hasInternalLinkage() || I->hasWeakLinkage() /* FIXME: Verify correct */)) { SwitchSection(O, CurSection, ".data"); - if (I->hasInternalLinkage()) + if (!forCygwin && I->hasInternalLinkage()) O << "\t.local " << name << "\n"; - O << "\t.comm " << name << "," << TD.getTypeSize(C->getType()) - << "," << (1 << Align); + O << "\t.comm " << name << "," << TD.getTypeSize(C->getType()); + if (!forCygwin) + O << "," << (1 << Align); O << "\t\t# "; WriteAsOperand(O, I, true, true, &M); O << "\n"; @@ -150,8 +171,10 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) { } emitAlignment(Align); - O << "\t.type " << name << ",@object\n"; - O << "\t.size " << name << "," << Size << "\n"; + if (!forCygwin) { + O << "\t.type " << name << ",@object\n"; + O << "\t.size " << name << "," << Size << "\n"; + } O << name << ":\t\t\t\t# "; WriteAsOperand(O, I, true, true, &M); O << " = "; @@ -239,7 +262,8 @@ bool X86IntelAsmPrinter::runOnMachineFunction(MachineFunction &MF) { O << "\t.text\n"; emitAlignment(4); O << "\t.globl\t" << CurrentFnName << "\n"; - O << "\t.type\t" << CurrentFnName << ", @function\n"; + if (!forCygwin) + O << "\t.type\t" << CurrentFnName << ", @function\n"; O << CurrentFnName << ":\n"; // Print out code for the function. @@ -306,7 +330,7 @@ void X86IntelAsmPrinter::printOp(const MachineOperand &MO, return; } case MachineOperand::MO_ExternalSymbol: - O << MO.getSymbolName(); + O << GlobalPrefix << MO.getSymbolName(); return; default: O << "<unknown operand type>"; return; @@ -462,7 +486,8 @@ bool X86ATTAsmPrinter::runOnMachineFunction(MachineFunction &MF) { O << "\t.text\n"; emitAlignment(4); O << "\t.globl\t" << CurrentFnName << "\n"; - O << "\t.type\t" << CurrentFnName << ", @function\n"; + if (!forCygwin) + O << "\t.type\t" << CurrentFnName << ", @function\n"; O << CurrentFnName << ":\n"; // Print out code for the function. @@ -523,7 +548,7 @@ void X86ATTAsmPrinter::printOp(const MachineOperand &MO, bool isCallOp) { } case MachineOperand::MO_ExternalSymbol: if (!isCallOp) O << '$'; - O << MO.getSymbolName(); + O << GlobalPrefix << MO.getSymbolName(); return; default: O << "<unknown operand type>"; return; @@ -600,7 +625,8 @@ void X86ATTAsmPrinter::printMachineInstruction(const MachineInstr *MI) { /// FunctionPass *llvm::createX86CodePrinterPass(std::ostream &o,TargetMachine &tm){ switch (AsmWriterFlavor) { - default: assert(0 && "Unknown asm flavor!"); + default: + assert(0 && "Unknown asm flavor!"); case intel: return new X86IntelAsmPrinter(o, tm); case att: |