+} // End anonymous namespace
+
+Pass *UltraSparc::getMethodAsmPrinterPass(PassManager &PM, std::ostream &Out) {
+ return new SparcMethodAsmPrinter(Out, *this);
+}
+
+
+
+
+
+//===----------------------------------------------------------------------===//
+// SparcMethodAsmPrinter Code
+//===----------------------------------------------------------------------===//
+
+namespace {
+
+class SparcModuleAsmPrinter : public Pass, public AsmPrinter {
+public:
+ SparcModuleAsmPrinter(ostream &os, UltraSparc &t) : AsmPrinter(os, t) {}
+
+ virtual bool run(Module *M) {
+ startModule(M);
+ emitGlobalsAndConstants(M);
+ endModule();
+ return false;
+ }
+
+ void emitGlobalsAndConstants(const Module *M);
+
+ void printGlobalVariable(const GlobalVariable *GV);
+ void printSingleConstant( const Constant* CV);
+ void printConstantValueOnly(const Constant* CV);
+ void printConstant( const Constant* CV, std::string valID = "");
+
+ static void FoldConstants(const Module *M,
+ std::hash_set<const Constant*> &moduleConstants);
+
+};
+
+
+// Can we treat the specified array as a string? Only if it is an array of
+// ubytes or non-negative sbytes.
+//
+static bool isStringCompatible(ConstantArray *CPA) {
+ const Type *ETy = cast<ArrayType>(CPA->getType())->getElementType();
+ if (ETy == Type::UByteTy) return true;
+ if (ETy != Type::SByteTy) return false;
+
+ for (unsigned i = 0; i < CPA->getNumOperands(); ++i)
+ if (cast<ConstantSInt>(CPA->getOperand(i))->getValue() < 0)
+ return false;
+
+ return true;
+}
+
+// toOctal - Convert the low order bits of X into an octal letter
+static inline char toOctal(int X) {
+ return (X&7)+'0';
+}
+
+// getAsCString - Return the specified array as a C compatible string, only if
+// the predicate isStringCompatible is true.
+//
+static string getAsCString(ConstantArray *CPA) {
+ if (isStringCompatible(CPA)) {
+ string Result;
+ const Type *ETy = cast<ArrayType>(CPA->getType())->getElementType();
+ Result = "\"";
+ for (unsigned i = 0; i < CPA->getNumOperands(); ++i) {
+ unsigned char C = (ETy == Type::SByteTy) ?
+ (unsigned char)cast<ConstantSInt>(CPA->getOperand(i))->getValue() :
+ (unsigned char)cast<ConstantUInt>(CPA->getOperand(i))->getValue();
+
+ if (isprint(C)) {
+ Result += C;
+ } else {
+ switch(C) {
+ case '\a': Result += "\\a"; break;
+ case '\b': Result += "\\b"; break;
+ case '\f': Result += "\\f"; break;
+ case '\n': Result += "\\n"; break;
+ case '\r': Result += "\\r"; break;
+ case '\t': Result += "\\t"; break;
+ case '\v': Result += "\\v"; break;
+ default:
+ Result += '\\';
+ Result += toOctal(C >> 6);
+ Result += toOctal(C >> 3);
+ Result += toOctal(C >> 0);
+ break;
+ }
+ }
+ }
+ Result += "\"";
+
+ return Result;
+ } else {
+ return CPA->getStrValue();
+ }