#include "SparcInternals.h"
#include "llvm/CodeGen/MachineInstr.h"
-#include "llvm/CodeGen/MachineCodeForBasicBlock.h"
-#include "llvm/CodeGen/MachineCodeForMethod.h"
-#include "llvm/GlobalVariable.h"
+#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
#include "llvm/Module.h"
#include "llvm/Pass.h"
#include "llvm/Assembly/Writer.h"
#include "Support/StringExtras.h"
-#include <iostream>
using std::string;
namespace {
toAsm << "\n";
}
- static std::string getValidSymbolName(const string &S) {
+ static string getValidSymbolName(const string &S) {
string Result;
// Symbol names in Sparc assembly language have these rules:
// (a) Must match { letter | _ | . | $ } { letter | _ | . | $ | digit }*
// (b) A name beginning in "." is treated as a local name.
- // (c) Names beginning with "_" are reserved by ANSI C and shd not be used.
//
- if (S[0] == '_' || isdigit(S[0]))
- Result += "ll";
+ if (isdigit(S[0]))
+ Result = "ll";
for (unsigned i = 0; i < S.size(); ++i)
{
//
string getID(const Value *V, const char *Prefix, const char *FPrefix = 0) {
string Result = FPrefix ? FPrefix : ""; // "Forced prefix"
-
+
Result += V->hasName() ? V->getName() : string(Prefix);
-
+
// Qualify all internal names with a unique id.
if (!isExternal(V)) {
int valId = idTable->Table.getValSlot(V);
valId = I->second;
}
Result = Result + "_" + itostr(valId);
+
+ // Replace or prefix problem characters in the name
+ Result = getValidSymbolName(Result);
}
-
- return getValidSymbolName(Result);
+
+ return Result;
}
// getID Wrappers - Ensure consistent usage...
// ConstantExprToString() - Convert a ConstantExpr to an asm expression
// and return this as a string.
- std::string ConstantExprToString(const ConstantExpr* CE,
- const TargetMachine& target) {
- std::string S;
-
+ string ConstantExprToString(const ConstantExpr* CE,
+ const TargetMachine& target) {
+ string S;
switch(CE->getOpcode()) {
case Instruction::GetElementPtr:
{ // generate a symbolic expression for the byte address
// valToExprString - Helper function for ConstantExprToString().
// Appends result to argument string S.
//
- std::string valToExprString(const Value* V, const TargetMachine& target) {
- std::string S;
+ string valToExprString(const Value* V, const TargetMachine& target) {
+ string S;
bool failed = false;
if (const Constant* CV = dyn_cast<Constant>(V)) { // symbolic or known
if (const ConstantBool *CB = dyn_cast<ConstantBool>(CV))
- S += std::string(CB == ConstantBool::True ? "1" : "0");
+ S += string(CB == ConstantBool::True ? "1" : "0");
else if (const ConstantSInt *CI = dyn_cast<ConstantSInt>(CV))
S += itostr(CI->getValue());
else if (const ConstantUInt *CI = dyn_cast<ConstantUInt>(CV))
void emitFunction(const Function &F);
private :
- void emitBasicBlock(const BasicBlock *BB);
+ void emitBasicBlock(const MachineBasicBlock &MBB);
void emitMachineInst(const MachineInstr *MI);
unsigned int printOperands(const MachineInstr *MI, unsigned int opNum);
else
needBitsFlag = false;
- switch (mop.getOperandType())
+ switch (mop.getType())
{
case MachineOperand::MO_VirtualRegister:
case MachineOperand::MO_CCRegister:
{
unsigned Opcode = MI->getOpCode();
- if (TargetInstrDescriptors[Opcode].iclass & M_DUMMY_PHI_FLAG)
+ if (Target.getInstrInfo().isDummyPhiInstr(Opcode))
return; // IGNORE PHI NODES
- toAsm << "\t" << TargetInstrDescriptors[Opcode].opCodeString << "\t";
+ toAsm << "\t" << Target.getInstrInfo().getName(Opcode) << "\t";
unsigned Mask = getOperandMask(Opcode);
if (NeedComma) toAsm << ", "; // Handle comma outputing
NeedComma = true;
N = printOperands(MI, OpNum);
- }
- else
- N = 1;
+ } else
+ N = 1;
toAsm << "\n";
}
void
-SparcFunctionAsmPrinter::emitBasicBlock(const BasicBlock *BB)
+SparcFunctionAsmPrinter::emitBasicBlock(const MachineBasicBlock &MBB)
{
// Emit a label for the basic block
- toAsm << getID(BB) << ":\n";
-
- // Get the vector of machine instructions corresponding to this bb.
- const MachineCodeForBasicBlock &MIs = MachineCodeForBasicBlock::get(BB);
- MachineCodeForBasicBlock::const_iterator MII = MIs.begin(), MIE = MIs.end();
+ toAsm << getID(MBB.getBasicBlock()) << ":\n";
// Loop over all of the instructions in the basic block...
- for (; MII != MIE; ++MII)
+ for (MachineBasicBlock::const_iterator MII = MBB.begin(), MIE = MBB.end();
+ MII != MIE; ++MII)
emitMachineInst(*MII);
toAsm << "\n"; // Seperate BB's with newlines
}
toAsm << methName << ":\n";
// Output code for all of the basic blocks in the function...
- for (Function::const_iterator I = F.begin(), E = F.end(); I != E; ++I)
- emitBasicBlock(I);
+ MachineFunction &MF = MachineFunction::get(&F);
+ for (MachineFunction::const_iterator I = MF.begin(), E = MF.end(); I != E; ++I)
+ emitBasicBlock(*I);
// Output a .size directive so the debugger knows the extents of the function
toAsm << ".EndOf_" << methName << ":\n\t.size "
void PrintZeroBytesToPad (int numBytes);
void printSingleConstantValue (const Constant* CV);
void printConstantValueOnly (const Constant* CV, int numPadBytes = 0);
- void printConstant (const Constant* CV, std::string valID = "");
+ void printConstant (const Constant* CV, string valID = "");
static void FoldConstants (const Module &M,
hash_set<const Constant*> &moduleConstants);
if (C == '"') {
Result += "\\\"";
+ } else if (C == '\\') {
+ Result += "\\\\";
} else if (isprint(C)) {
Result += C;
} else {
for (Module::const_iterator I = M.begin(), E = M.end(); I != E; ++I)
if (!I->isExternal()) {
const hash_set<const Constant*> &pool =
- MachineCodeForMethod::get(I).getConstantPoolValues();
+ MachineFunction::get(I).getConstantPoolValues();
MC.insert(pool.begin(), pool.end());
}
}