static cl::opt<bool>
AsmVerbose("asm-verbose", cl::Hidden, cl::desc("Add comments to directives."));
+char AsmPrinter::ID = 0;
AsmPrinter::AsmPrinter(std::ostream &o, TargetMachine &tm,
const TargetAsmInfo *T)
-: FunctionNumber(0), O(o), TM(tm), TAI(T)
+ : MachineFunctionPass((intptr_t)&ID), FunctionNumber(0), O(o), TM(tm), TAI(T)
{}
std::string AsmPrinter::getSectionForFunction(const Function &F) const {
bool AsmPrinter::doFinalization(Module &M) {
if (TAI->getWeakRefDirective()) {
- if (ExtWeakSymbols.begin() != ExtWeakSymbols.end())
+ if (!ExtWeakSymbols.empty())
SwitchToDataSection("");
for (std::set<const GlobalValue*>::iterator i = ExtWeakSymbols.begin(),
}
}
+ if (TAI->getSetDirective()) {
+ if (!M.alias_empty())
+ SwitchToTextSection(TAI->getTextSection());
+
+ O << "\n";
+ for (Module::const_alias_iterator I = M.alias_begin(), E = M.alias_end();
+ I!=E; ++I) {
+ std::string Name = Mang->getValueName(I);
+ std::string Target;
+
+ if (const GlobalValue *GV = I->getAliasedGlobal())
+ Target = Mang->getValueName(GV);
+ else
+ assert(0 && "Unsupported aliasee");
+
+ if (I->hasExternalLinkage())
+ O << "\t.globl\t" << Name << "\n";
+ else if (I->hasWeakLinkage())
+ O << TAI->getWeakRefDirective() << Name << "\n";
+ else if (!I->hasInternalLinkage())
+ assert(0 && "Invalid alias linkage");
+
+ O << TAI->getSetDirective() << Name << ", " << Target << "\n";
+ }
+ }
+
delete Mang; Mang = 0;
return false;
}
return LinkName;
}
+/// EmitExternalGlobal - Emit the external reference to a global variable.
+/// Should be overridden if an indirect reference should be used.
+void AsmPrinter::EmitExternalGlobal(const GlobalVariable *GV) {
+ O << getGlobalLinkName(GV);
+}
+
+
+
//===----------------------------------------------------------------------===//
/// LEB 128 number encoding.
/// EOL - Print a newline character to asm stream. If a comment is present
/// then it will be printed first. Comments should not contain '\n'.
+void AsmPrinter::EOL() const {
+ O << "\n";
+}
void AsmPrinter::EOL(const std::string &Comment) const {
if (AsmVerbose && !Comment.empty()) {
O << "\t"
/// Special characters are emitted properly.
/// \literal (Eg. '\t') \endliteral
void AsmPrinter::EmitString(const std::string &String) const {
- O << TAI->getAsciiDirective()
- << "\"";
+ const char* AscizDirective = TAI->getAscizDirective();
+ if (AscizDirective)
+ O << AscizDirective;
+ else
+ O << TAI->getAsciiDirective();
+ O << "\"";
for (unsigned i = 0, N = String.size(); i < N; ++i) {
unsigned char C = String[i];
printStringChar(O, C);
}
- O << "\\0\"";
+ if (AscizDirective)
+ O << "\"";
+ else
+ O << "\\0\"";
}
//===----------------------------------------------------------------------===//
// EmitAlignment - Emit an alignment directive to the specified power of two.
+// Use the maximum of the specified alignment and the alignment from the
+// specified GlobalValue (if any).
void AsmPrinter::EmitAlignment(unsigned NumBits, const GlobalValue *GV) const {
if (GV && GV->getAlignment())
- NumBits = Log2_32(GV->getAlignment());
+ NumBits = std::max(NumBits, Log2_32(GV->getAlignment()));
if (NumBits == 0) return; // No need to emit alignment.
if (TAI->getAlignmentIsInBytes()) NumBits = 1 << NumBits;
O << TAI->getAlignDirective() << NumBits << "\n";
}
+
/// EmitZeros - Emit a block of zeros.
///
void AsmPrinter::EmitZeros(uint64_t NumZeros) const {
}
case '\n':
++LastEmitted; // Consume newline character.
- O << "\n\t"; // Indent code with newline.
+ O << "\n"; // Indent code with newline.
break;
case '$': {
++LastEmitted; // Consume '$' character.
void AsmPrinter::printLabel(const MachineInstr *MI) const {
O << "\n"
<< TAI->getPrivateGlobalPrefix()
- << "label_"
+ << "label"
<< MI->getOperand(0).getImmedValue()
<< ":\n";
}