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;
};
}
}
}
+/// 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
(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";
}
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 << " = ";
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.
return;
}
case MachineOperand::MO_ExternalSymbol:
- O << MO.getSymbolName();
+ O << GlobalPrefix << MO.getSymbolName();
return;
default:
O << "<unknown operand type>"; return;
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.
}
case MachineOperand::MO_ExternalSymbol:
if (!isCallOp) O << '$';
- O << MO.getSymbolName();
+ O << GlobalPrefix << MO.getSymbolName();
return;
default:
O << "<unknown operand type>"; return;
///
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: