Finish support for Microsoft ML/MASM. May still be a few rough edges.
llvm-svn: 28045
This commit is contained in:
parent
24a62a9bc1
commit
bfe9ffb449
|
@ -26,10 +26,12 @@ namespace llvm {
|
||||||
class GlobalVariable;
|
class GlobalVariable;
|
||||||
|
|
||||||
class AsmPrinter : public MachineFunctionPass {
|
class AsmPrinter : public MachineFunctionPass {
|
||||||
|
protected:
|
||||||
/// CurrentSection - The current section we are emitting to. This is
|
/// CurrentSection - The current section we are emitting to. This is
|
||||||
/// controlled and used by the SwitchSection method.
|
/// controlled and used by the SwitchSection method.
|
||||||
std::string CurrentSection;
|
std::string CurrentSection;
|
||||||
|
|
||||||
|
private:
|
||||||
/// FunctionNumber - This provides a unique ID for each function emitted in
|
/// FunctionNumber - This provides a unique ID for each function emitted in
|
||||||
/// this translation unit. It is autoincremented by SetupMachineFunction,
|
/// this translation unit. It is autoincremented by SetupMachineFunction,
|
||||||
/// and can be accessed with getFunctionNumber() and
|
/// and can be accessed with getFunctionNumber() and
|
||||||
|
@ -185,7 +187,7 @@ namespace llvm {
|
||||||
/// If the new section is an empty string, this method forgets what the
|
/// If the new section is an empty string, this method forgets what the
|
||||||
/// current section is, but does not emit a .section directive.
|
/// current section is, but does not emit a .section directive.
|
||||||
///
|
///
|
||||||
void SwitchSection(const char *NewSection, const GlobalValue *GV);
|
virtual void SwitchSection(const char *NewSection, const GlobalValue *GV);
|
||||||
|
|
||||||
/// getPreferredAlignmentLog - Return the preferred alignment of the
|
/// getPreferredAlignmentLog - Return the preferred alignment of the
|
||||||
/// specified global, returned in log form. This includes an explicitly
|
/// specified global, returned in log form. This includes an explicitly
|
||||||
|
|
|
@ -36,8 +36,6 @@ X86IntelAsmPrinter::X86IntelAsmPrinter(std::ostream &O, X86TargetMachine &TM)
|
||||||
Data32bitsDirective = "\t.dd\t";
|
Data32bitsDirective = "\t.dd\t";
|
||||||
Data64bitsDirective = "\t.dq\t";
|
Data64bitsDirective = "\t.dq\t";
|
||||||
HasDotTypeDotSizeDirective = false;
|
HasDotTypeDotSizeDirective = false;
|
||||||
|
|
||||||
O << "\t.686\n\t.model flat\n\toption dotname\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// runOnMachineFunction - This uses the printMachineInstruction()
|
/// runOnMachineFunction - This uses the printMachineInstruction()
|
||||||
|
@ -57,7 +55,7 @@ bool X86IntelAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
|
||||||
EmitConstantPool(MF.getConstantPool());
|
EmitConstantPool(MF.getConstantPool());
|
||||||
|
|
||||||
// Print out labels for the function.
|
// Print out labels for the function.
|
||||||
SwitchSection(".code\n", MF.getFunction());
|
SwitchSection(".code", MF.getFunction());
|
||||||
EmitAlignment(4);
|
EmitAlignment(4);
|
||||||
if (MF.getFunction()->getLinkage() == GlobalValue::ExternalLinkage)
|
if (MF.getFunction()->getLinkage() == GlobalValue::ExternalLinkage)
|
||||||
O << "\tpublic " << CurrentFnName << "\n";
|
O << "\tpublic " << CurrentFnName << "\n";
|
||||||
|
@ -424,9 +422,56 @@ void X86IntelAsmPrinter::printMachineInstruction(const MachineInstr *MI) {
|
||||||
bool X86IntelAsmPrinter::doInitialization(Module &M) {
|
bool X86IntelAsmPrinter::doInitialization(Module &M) {
|
||||||
X86SharedAsmPrinter::doInitialization(M);
|
X86SharedAsmPrinter::doInitialization(M);
|
||||||
Mang->markCharUnacceptable('.');
|
Mang->markCharUnacceptable('.');
|
||||||
|
PrivateGlobalPrefix = "$"; // need this here too :(
|
||||||
|
O << "\t.686\n\t.model flat\n\n";
|
||||||
|
|
||||||
|
// Emit declarations for external functions.
|
||||||
|
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
|
||||||
|
if (I->isExternal())
|
||||||
|
O << "\textern " << Mang->getValueName(I) << ":near\n";
|
||||||
|
|
||||||
|
// Emit declarations for external globals.
|
||||||
|
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";
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool X86IntelAsmPrinter::doFinalization(Module &M) {
|
||||||
|
X86SharedAsmPrinter::doFinalization(M);
|
||||||
|
if (CurrentSection != "")
|
||||||
|
O << CurrentSection << "\tends\n";
|
||||||
|
O << "\tend\n";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void X86IntelAsmPrinter::SwitchSection(const char *NewSection,
|
||||||
|
const GlobalValue *GV) {
|
||||||
|
if (*NewSection == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
std::string NS;
|
||||||
|
bool isData = strcmp(NewSection , ".data") == 0;
|
||||||
|
|
||||||
|
if (GV && GV->hasSection())
|
||||||
|
NS = GV->getSection();
|
||||||
|
else if (isData)
|
||||||
|
NS = "_data";
|
||||||
|
else
|
||||||
|
NS = "_text";
|
||||||
|
|
||||||
|
if (CurrentSection != NS) {
|
||||||
|
if (CurrentSection != "")
|
||||||
|
O << CurrentSection << "\tends\n";
|
||||||
|
CurrentSection = NS;
|
||||||
|
O << CurrentSection << (isData ? "\tsegment 'DATA'\n"
|
||||||
|
: "\tsegment 'CODE'\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void X86IntelAsmPrinter::EmitZeros(uint64_t NumZeros) const {
|
void X86IntelAsmPrinter::EmitZeros(uint64_t NumZeros) const {
|
||||||
if (NumZeros) {
|
if (NumZeros) {
|
||||||
O << "\tdb " << NumZeros << " dup(0)\n";
|
O << "\tdb " << NumZeros << " dup(0)\n";
|
||||||
|
|
|
@ -90,7 +90,9 @@ struct X86IntelAsmPrinter : public X86SharedAsmPrinter {
|
||||||
void printPICLabel(const MachineInstr *MI, unsigned Op);
|
void printPICLabel(const MachineInstr *MI, unsigned Op);
|
||||||
bool runOnMachineFunction(MachineFunction &F);
|
bool runOnMachineFunction(MachineFunction &F);
|
||||||
bool doInitialization(Module &M);
|
bool doInitialization(Module &M);
|
||||||
|
bool doFinalization(Module &M);
|
||||||
|
|
||||||
|
virtual void SwitchSection(const char *NewSection, const GlobalValue *GV);
|
||||||
virtual void EmitZeros(uint64_t NumZeros) const;
|
virtual void EmitZeros(uint64_t NumZeros) const;
|
||||||
virtual void EmitString(const ConstantArray *CVA) const;
|
virtual void EmitString(const ConstantArray *CVA) const;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue