From e7aa2bf095f6377ac9e13876470e56997d6dd5bf Mon Sep 17 00:00:00 2001 From: "Vikram S. Adve" Date: Thu, 5 Sep 2002 18:28:10 +0000 Subject: [PATCH] -- Bug fix: use byte offsets not typed offsets in output assembly! -- Add support for ConstantExpr constants (only cast and add operators so far) -- Avoid generating label Bbss.bss, which sometimes came out twice. llvm-svn: 3578 --- lib/Target/Sparc/EmitAssembly.cpp | 43 +++++++++++++++++-------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/lib/Target/Sparc/EmitAssembly.cpp b/lib/Target/Sparc/EmitAssembly.cpp index f3de79d1016..c3849217257 100644 --- a/lib/Target/Sparc/EmitAssembly.cpp +++ b/lib/Target/Sparc/EmitAssembly.cpp @@ -107,7 +107,7 @@ public: case Text: toAsm << "\".text\""; break; case ReadOnlyData: toAsm << "\".rodata\",#alloc"; break; case InitRWData: toAsm << "\".data\",#alloc,#write"; break; - case UninitRWData: toAsm << "\".bss\",#alloc,#write\nBbss.bss:"; break; + case UninitRWData: toAsm << "\".bss\",#alloc,#write"; break; } toAsm << "\n"; } @@ -186,30 +186,36 @@ public: return ""; } - // ConstantExprToString() - Convert a ConstantExpr to a C expression, and - // return this as a string. - // + // 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; switch(CE->getOpcode()) { case Instruction::GetElementPtr: - { + { // generate a symbolic expression for the byte address const Value* ptrVal = CE->getOperand(0); - valToExprString(ptrVal, target, S); std::vector idxVec(CE->op_begin()+1, CE->op_end()); - uint64_t byteOffset = - target.DataLayout.getIndexedOffset(ptrVal->getType(), idxVec); - - const Type *PtrElTy = - cast(ptrVal->getType())->getElementType(); - uint64_t eltSize = target.DataLayout.getTypeSize(PtrElTy); - - S += " + " + utostr(byteOffset / eltSize); + S += "(" + valToExprString(ptrVal, target) + ") + (" + + utostr(target.DataLayout.getIndexedOffset(ptrVal->getType(),idxVec)) + + ")"; break; } + case Instruction::Cast: + // Support only non-converting casts for now, i.e., a no-op. + // This assertion is not a complete check. + assert(target.DataLayout.getTypeSize(CE->getType()) == + target.DataLayout.getTypeSize(CE->getOperand(0)->getType())); + S += "(" + valToExprString(CE->getOperand(0), target) + ")"; + break; + + case Instruction::Add: + S += "(" + valToExprString(CE->getOperand(0), target) + ") + (" + + valToExprString(CE->getOperand(1), target) + ")"; + break; + default: assert(0 && "Unsupported operator in ConstantExprToString()"); break; @@ -221,8 +227,8 @@ public: // valToExprString - Helper function for ConstantExprToString(). // Appends result to argument string S. // - void valToExprString(const Value* V, const TargetMachine& target, - std::string& S) { + std::string valToExprString(const Value* V, const TargetMachine& target) { + std::string S; bool failed = false; if (const Constant* CV = dyn_cast(V)) { // symbolic or known @@ -237,7 +243,7 @@ public: else if (isa(CV)) S += "0"; else if (const ConstantPointerRef *CPR = dyn_cast(CV)) - valToExprString(CPR->getValue(), target, S); + S += valToExprString(CPR->getValue(), target); else if (const ConstantExpr *CE = dyn_cast(CV)) S += ConstantExprToString(CE, target); else @@ -253,6 +259,7 @@ public: assert(0 && "Cannot convert value to string"); S += ""; } + return S; } }; @@ -860,8 +867,6 @@ void SparcModuleAsmPrinter::emitGlobalsAndConstants(const Module &M) { for (Module::const_giterator GI = M.gbegin(), GE = M.gend(); GI != GE; ++GI) { if (GI->hasInitializer() && GI->isConstant()) { enterSection(AsmPrinter::ReadOnlyData); // read-only, initialized data - } else if (GI->hasInitializer() && !GI->isConstant()) { // read-write data - enterSection(AsmPrinter::ReadOnlyData); // read-only, initialized data } else if (GI->hasInitializer() && !GI->isConstant()) { // read-write data enterSection(AsmPrinter::InitRWData); } else {