#include "llvm/CallingConv.h"
#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
+#include "llvm/InlineAsm.h"
#include "llvm/Instruction.h"
#include "llvm/Instructions.h"
#include "llvm/Module.h"
}
}
+// PrintEscapedString - Print each character of the specified string, escaping
+// it if it is not printable or if it is an escape char.
+static void PrintEscapedString(const std::string &Str, std::ostream &Out) {
+ for (unsigned i = 0, e = Str.size(); i != e; ++i) {
+ unsigned char C = Str[i];
+ if (isprint(C) && C != '"' && C != '\\') {
+ Out << C;
+ } else {
+ Out << '\\'
+ << (char) ((C/16 < 10) ? ( C/16 +'0') : ( C/16 -10+'A'))
+ << (char)(((C&15) < 10) ? ((C&15)+'0') : ((C&15)-10+'A'));
+ }
+ }
+}
+
/// @brief Internal constant writer.
static void WriteConstantInt(std::ostream &Out, const Constant *CV,
bool PrintName,
// ubytes or an array of sbytes with positive values.
//
const Type *ETy = CA->getType()->getElementType();
- bool isString = (ETy == Type::SByteTy || ETy == Type::UByteTy);
-
- if (ETy == Type::SByteTy)
- for (unsigned i = 0; i < CA->getNumOperands(); ++i)
- if (cast<ConstantSInt>(CA->getOperand(i))->getValue() < 0) {
- isString = false;
- break;
- }
-
- if (isString) {
+ if (CA->isString()) {
Out << "c\"";
- for (unsigned i = 0; i < CA->getNumOperands(); ++i) {
- unsigned char C =
- (unsigned char)cast<ConstantInt>(CA->getOperand(i))->getRawValue();
-
- if (isprint(C) && C != '"' && C != '\\') {
- Out << C;
- } else {
- Out << '\\'
- << (char) ((C/16 < 10) ? ( C/16 +'0') : ( C/16 -10+'A'))
- << (char)(((C&15) < 10) ? ((C&15)+'0') : ((C&15)-10+'A'));
- }
- }
+ PrintEscapedString(CA->getAsString(), Out);
Out << "\"";
} else { // Cannot output in string format...
Out << getLLVMName(V->getName());
else {
const Constant *CV = dyn_cast<Constant>(V);
- if (CV && !isa<GlobalValue>(CV))
+ if (CV && !isa<GlobalValue>(CV)) {
WriteConstantInt(Out, CV, PrintName, TypeTable, Machine);
- else {
+ } else if (const InlineAsm *IA = dyn_cast<InlineAsm>(V)) {
+ Out << "asm ";
+ if (IA->hasSideEffects())
+ Out << "sideeffect ";
+ Out << '"';
+ PrintEscapedString(IA->getAsmString(), Out);
+ Out << "\", \"";
+ PrintEscapedString(IA->getConstraintString(), Out);
+ Out << '"';
+ } else {
int Slot;
if (Machine) {
Slot = Machine->getSlot(V);
if (!M->getTargetTriple().empty())
Out << "target triple = \"" << M->getTargetTriple() << "\"\n";
+ if (!M->getModuleInlineAsm().empty()) {
+ // Split the string into lines, to make it easier to read the .ll file.
+ std::string Asm = M->getModuleInlineAsm();
+ size_t CurPos = 0;
+ size_t NewLine = Asm.find_first_of('\n', CurPos);
+ while (NewLine != std::string::npos) {
+ // We found a newline, print the portion of the asm string from the
+ // last newline up to this newline.
+ Out << "module asm \"";
+ PrintEscapedString(std::string(Asm.begin()+CurPos, Asm.begin()+NewLine),
+ Out);
+ Out << "\"\n";
+ CurPos = NewLine+1;
+ NewLine = Asm.find_first_of('\n', CurPos);
+ }
+ Out << "module asm \"";
+ PrintEscapedString(std::string(Asm.begin()+CurPos, Asm.end()), Out);
+ Out << "\"\n";
+ }
+
// Loop over the dependent libraries and emit them.
Module::lib_iterator LI = M->lib_begin();
Module::lib_iterator LE = M->lib_end();
assert(C && "GlobalVar initializer isn't constant?");
writeOperand(GV->getInitializer(), false, isa<GlobalValue>(C));
}
-
+
+ if (GV->hasSection())
+ Out << ", section \"" << GV->getSection() << '"';
+ if (GV->getAlignment())
+ Out << ", align " << GV->getAlignment();
+
printInfoComment(*GV);
Out << "\n";
}
}
Out << ')';
+ if (F->hasSection())
+ Out << " section \"" << F->getSection() << '"';
+ if (F->getAlignment())
+ Out << " align " << F->getAlignment();
+
if (F->isExternal()) {
Out << "\n";
} else {
writeOperand(AI->getArraySize(), true);
}
if (AI->getAlignment()) {
- Out << ", " << AI->getAlignment();
+ Out << ", align " << AI->getAlignment();
}
} else if (isa<CastInst>(I)) {
if (Operand) writeOperand(Operand, true); // Work with broken code
W.write(this);
}
+void InlineAsm::print(std::ostream &o, AssemblyAnnotationWriter *AAW) const {
+ WriteAsOperand(o, this, true, true, 0);
+}
+
void BasicBlock::print(std::ostream &o, AssemblyAnnotationWriter *AAW) const {
SlotMachine SlotTable(getParent());
AssemblyWriter W(o, SlotTable,