diff options
author | Jeff Cohen <jeffc@jolt-lang.org> | 2006-05-06 21:27:14 +0000 |
---|---|---|
committer | Jeff Cohen <jeffc@jolt-lang.org> | 2006-05-06 21:27:14 +0000 |
commit | d43b18d9e47326cb83b11d684d569ee9050ebefa (patch) | |
tree | 9ab7984a986c6365ccb2d9418f25145dadd3a3e8 /lib | |
parent | a0aec0a61dbc47d15190cb229dba3f82496756aa (diff) | |
download | external_llvm-d43b18d9e47326cb83b11d684d569ee9050ebefa.zip external_llvm-d43b18d9e47326cb83b11d684d569ee9050ebefa.tar.gz external_llvm-d43b18d9e47326cb83b11d684d569ee9050ebefa.tar.bz2 |
Fix some loose ends in MASM support.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@28148 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/CodeGen/AsmPrinter.cpp | 10 | ||||
-rw-r--r-- | lib/Target/X86/X86AsmPrinter.cpp | 3 | ||||
-rwxr-xr-x | lib/Target/X86/X86IntelAsmPrinter.cpp | 129 |
3 files changed, 77 insertions, 65 deletions
diff --git a/lib/CodeGen/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter.cpp index 4f72a75..9aca4e2 100644 --- a/lib/CodeGen/AsmPrinter.cpp +++ b/lib/CodeGen/AsmPrinter.cpp @@ -71,9 +71,9 @@ void AsmPrinter::SwitchSection(const char *NewSection, const GlobalValue *GV) { if (MLSections) { if (*NewSection == 0) { // Simply end the current section, if any. - if (CurrentSection != "") { - O << CurrentSection << "\tends\n"; - CurrentSection = ""; + if (!CurrentSection.empty()) { + O << CurrentSection << "\tends\n\n"; + CurrentSection.clear(); } return; } @@ -88,8 +88,8 @@ void AsmPrinter::SwitchSection(const char *NewSection, const GlobalValue *GV) { NS = "_text"; if (CurrentSection != NS) { - if (CurrentSection != "") - O << CurrentSection << "\tends\n"; + if (!CurrentSection.empty()) + O << CurrentSection << "\tends\n\n"; CurrentSection = NS; O << CurrentSection << (isData ? "\tsegment 'DATA'\n" : "\tsegment 'CODE'\n"); diff --git a/lib/Target/X86/X86AsmPrinter.cpp b/lib/Target/X86/X86AsmPrinter.cpp index 07035f6..3ac322b 100644 --- a/lib/Target/X86/X86AsmPrinter.cpp +++ b/lib/Target/X86/X86AsmPrinter.cpp @@ -90,6 +90,9 @@ bool X86SharedAsmPrinter::doInitialization(Module &M) { } bool X86SharedAsmPrinter::doFinalization(Module &M) { + // Note: this code is not shared by the Intel printer as it is too different + // from how MASM does things. When making changes here don't forget to look + // at X86IntelAsmPrinter::doFinalization(). const TargetData *TD = TM.getTargetData(); // Print out module-level global variables here. diff --git a/lib/Target/X86/X86IntelAsmPrinter.cpp b/lib/Target/X86/X86IntelAsmPrinter.cpp index a63be04..fc42797 100755 --- a/lib/Target/X86/X86IntelAsmPrinter.cpp +++ b/lib/Target/X86/X86IntelAsmPrinter.cpp @@ -30,12 +30,6 @@ X86IntelAsmPrinter::X86IntelAsmPrinter(std::ostream &O, X86TargetMachine &TM) /// method to print assembly for each instruction. /// bool X86IntelAsmPrinter::runOnMachineFunction(MachineFunction &MF) { - if (forDarwin) { - // Let PassManager know we need debug information and relay - // the MachineDebugInfo address on to DwarfWriter. - DW.SetDebugInfo(&getAnalysis<MachineDebugInfo>()); - } - SetupMachineFunction(MF); O << "\n\n"; @@ -49,11 +43,6 @@ bool X86IntelAsmPrinter::runOnMachineFunction(MachineFunction &MF) { O << "\tpublic " << CurrentFnName << "\n"; O << CurrentFnName << "\tproc near\n"; - if (forDarwin) { - // Emit pre-function debug information. - DW.BeginFunction(&MF); - } - // Print out code for the function. for (MachineFunction::const_iterator I = MF.begin(), E = MF.end(); I != E; ++I) { @@ -70,11 +59,6 @@ bool X86IntelAsmPrinter::runOnMachineFunction(MachineFunction &MF) { } } - if (forDarwin) { - // Emit post-function debug information. - DW.EndFunction(); - } - O << CurrentFnName << "\tendp\n"; // We didn't modify anything. @@ -124,8 +108,6 @@ void X86IntelAsmPrinter::printOp(const MachineOperand &MO, if (!isMemOp) O << "OFFSET "; O << "[" << PrivateGlobalPrefix << "CPI" << getFunctionNumber() << "_" << MO.getConstantPoolIndex(); - if (forDarwin && TM.getRelocationModel() == Reloc::PIC) - O << "-\"L" << getFunctionNumber() << "$pb\""; int Offset = MO.getOffset(); if (Offset > 0) O << " + " << Offset; @@ -138,29 +120,7 @@ void X86IntelAsmPrinter::printOp(const MachineOperand &MO, bool isCallOp = Modifier && !strcmp(Modifier, "call"); bool isMemOp = Modifier && !strcmp(Modifier, "mem"); if (!isMemOp && !isCallOp) O << "OFFSET "; - if (forDarwin && TM.getRelocationModel() != Reloc::Static) { - GlobalValue *GV = MO.getGlobal(); - std::string Name = Mang->getValueName(GV); - if (!isMemOp && !isCallOp) O << '$'; - // Link-once, External, or Weakly-linked global variables need - // non-lazily-resolved stubs - if (GV->isExternal() || GV->hasWeakLinkage() || - GV->hasLinkOnceLinkage()) { - // Dynamically-resolved functions need a stub for the function. - if (isCallOp && isa<Function>(GV) && cast<Function>(GV)->isExternal()) { - FnStubs.insert(Name); - O << "L" << Name << "$stub"; - } else { - GVStubs.insert(Name); - O << "L" << Name << "$non_lazy_ptr"; - } - } else { - O << Mang->getValueName(GV); - } - if (!isCallOp && TM.getRelocationModel() == Reloc::PIC) - O << "-\"L" << getFunctionNumber() << "$pb\""; - } else - O << Mang->getValueName(MO.getGlobal()); + O << Mang->getValueName(MO.getGlobal()); int Offset = MO.getOffset(); if (Offset > 0) O << " + " << Offset; @@ -170,13 +130,6 @@ void X86IntelAsmPrinter::printOp(const MachineOperand &MO, } case MachineOperand::MO_ExternalSymbol: { bool isCallOp = Modifier && !strcmp(Modifier, "call"); - if (isCallOp && forDarwin && TM.getRelocationModel() != Reloc::Static) { - std::string Name(GlobalPrefix); - Name += MO.getSymbolName(); - FnStubs.insert(Name); - O << "L" << Name << "$stub"; - return; - } if (!isCallOp) O << "OFFSET "; O << GlobalPrefix << MO.getSymbolName(); return; @@ -330,20 +283,22 @@ void X86IntelAsmPrinter::printMachineInstruction(const MachineInstr *MI) { } bool X86IntelAsmPrinter::doInitialization(Module &M) { - X86SharedAsmPrinter::doInitialization(M); - CommentString = ";"; + MLSections = true; GlobalPrefix = "_"; + CommentString = ";"; + + X86SharedAsmPrinter::doInitialization(M); + PrivateGlobalPrefix = "$"; AlignDirective = "\talign\t"; - MLSections = true; ZeroDirective = "\tdb\t"; ZeroDirectiveSuffix = " dup(0)"; AsciiDirective = "\tdb\t"; AscizDirective = 0; - Data8bitsDirective = "\t.db\t"; - Data16bitsDirective = "\t.dw\t"; - Data32bitsDirective = "\t.dd\t"; - Data64bitsDirective = "\t.dq\t"; + Data8bitsDirective = "\tdb\t"; + Data16bitsDirective = "\tdw\t"; + Data32bitsDirective = "\tdd\t"; + Data64bitsDirective = "\tdq\t"; HasDotTypeDotSizeDirective = false; Mang->markCharUnacceptable('.'); @@ -354,23 +309,77 @@ bool X86IntelAsmPrinter::doInitialization(Module &M) { if (I->isExternal()) O << "\textern " << Mang->getValueName(I) << ":near\n"; - // Emit declarations for external globals. + // Emit declarations for external globals. Note that VC++ always declares + // external globals to have type byte, and if that's good enough for VC++... for (Module::const_global_iterator I = M.global_begin(), E = M.global_end(); I != E; ++I) { if (I->isExternal()) O << "\textern " << Mang->getValueName(I) << ":byte\n"; - else if (I->getLinkage() == GlobalValue::ExternalLinkage) - O << "\tpublic " << Mang->getValueName(I) << "\n"; } return false; } bool X86IntelAsmPrinter::doFinalization(Module &M) { - X86SharedAsmPrinter::doFinalization(M); + const TargetData *TD = TM.getTargetData(); + + // 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->isExternal()) continue; // External global require no code + + // Check to see if this is a special global used by LLVM, if so, emit it. + if (EmitSpecialLLVMGlobal(I)) + continue; + + std::string name = Mang->getValueName(I); + Constant *C = I->getInitializer(); + unsigned Size = TD->getTypeSize(C->getType()); + unsigned Align = getPreferredAlignmentLog(I); + bool bCustomSegment = false; + + switch (I->getLinkage()) { + case GlobalValue::LinkOnceLinkage: + case GlobalValue::WeakLinkage: + SwitchSection("", 0); + O << name << "?\tsegment common 'COMMON'\n"; + bCustomSegment = true; + // FIXME: the default alignment is 16 bytes, but 1, 2, 4, and 256 + // are also available. + break; + case GlobalValue::AppendingLinkage: + SwitchSection("", 0); + O << name << "?\tsegment public 'DATA'\n"; + bCustomSegment = true; + // FIXME: the default alignment is 16 bytes, but 1, 2, 4, and 256 + // are also available. + break; + case GlobalValue::ExternalLinkage: + O << "\tpublic " << name << "\n"; + // FALL THROUGH + case GlobalValue::InternalLinkage: + SwitchSection(".data", I); + break; + default: + assert(0 && "Unknown linkage type!"); + } + + if (!bCustomSegment) + EmitAlignment(Align, I); + + O << name << ":\t\t\t\t" << CommentString << " " << I->getName() << '\n'; + + EmitGlobalConstant(C); + + if (bCustomSegment) + O << name << "?\tends\n"; + } + + // Bypass X86SharedAsmPrinter::doFinalization(). + AsmPrinter::doFinalization(M); SwitchSection("", 0); O << "\tend\n"; - return false; + return false; // success } void X86IntelAsmPrinter::EmitString(const ConstantArray *CVA) const { |