[llvm-commits] CVS: llvm/lib/CodeGen/AsmPrinter.cpp
Chris Lattner
lattner at cs.uiuc.edu
Mon Aug 16 16:15:33 PDT 2004
Changes in directory llvm/lib/CodeGen:
AsmPrinter.cpp added (r1.1)
---
Log message:
Initial implementation of the asmprinter base class
---
Diffs of the changes: (+110 -0)
Index: llvm/lib/CodeGen/AsmPrinter.cpp
diff -c /dev/null llvm/lib/CodeGen/AsmPrinter.cpp:1.1
*** /dev/null Mon Aug 16 18:15:32 2004
--- llvm/lib/CodeGen/AsmPrinter.cpp Mon Aug 16 18:15:22 2004
***************
*** 0 ****
--- 1,110 ----
+ //===-- AsmPrinter.cpp - Common AsmPrinter code ---------------------------===//
+ //
+ // The LLVM Compiler Infrastructure
+ //
+ // This file was developed by the LLVM research group and is distributed under
+ // the University of Illinois Open Source License. See LICENSE.TXT for details.
+ //
+ //===----------------------------------------------------------------------===//
+ //
+ // This file implements the AsmPrinter class.
+ //
+ //===----------------------------------------------------------------------===//
+
+ #include "llvm/CodeGen/AsmPrinter.h"
+ #include "llvm/Constants.h"
+ #include "llvm/Instruction.h"
+ #include "llvm/Support/Mangler.h"
+ #include "llvm/Target/TargetMachine.h"
+ using namespace llvm;
+
+ bool AsmPrinter::doInitialization(Module &M) {
+ Mang = new Mangler(M);
+ return false;
+ }
+
+ bool AsmPrinter::doFinalization(Module &M) {
+ delete Mang; Mang = 0;
+ return false;
+ }
+
+ void AsmPrinter::setupMachineFunction(MachineFunction &MF) {
+ // What's my mangled name?
+ CurrentFnName = Mang->getValueName((Value*)MF.getFunction());
+
+ }
+
+
+
+ // Print out the specified constant, without a storage class. Only the
+ // constants valid in constant expressions can occur here.
+ void AsmPrinter::emitConstantValueOnly(const Constant *CV) {
+ if (CV->isNullValue())
+ O << "0";
+ else if (const ConstantBool *CB = dyn_cast<ConstantBool>(CV)) {
+ assert(CB == ConstantBool::True);
+ O << "1";
+ } else if (const ConstantSInt *CI = dyn_cast<ConstantSInt>(CV))
+ if (((CI->getValue() << 32) >> 32) == CI->getValue())
+ O << CI->getValue();
+ else
+ O << (unsigned long long)CI->getValue();
+ else if (const ConstantUInt *CI = dyn_cast<ConstantUInt>(CV))
+ O << CI->getValue();
+ else if (isa<GlobalValue>((Value*)CV))
+ // This is a constant address for a global variable or function. Use the
+ // name of the variable or function as the address value.
+ O << Mang->getValueName(CV);
+ else if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV)) {
+ const TargetData &TD = TM.getTargetData();
+ switch(CE->getOpcode()) {
+ case Instruction::GetElementPtr: {
+ // generate a symbolic expression for the byte address
+ const Constant *ptrVal = CE->getOperand(0);
+ std::vector<Value*> idxVec(CE->op_begin()+1, CE->op_end());
+ if (unsigned Offset = TD.getIndexedOffset(ptrVal->getType(), idxVec)) {
+ O << "(";
+ emitConstantValueOnly(ptrVal);
+ O << ") + " << Offset;
+ } else {
+ emitConstantValueOnly(ptrVal);
+ }
+ break;
+ }
+ case Instruction::Cast: {
+ // Support only non-converting or widening casts for now, that is, ones
+ // that do not involve a change in value. This assertion is really gross,
+ // and may not even be a complete check.
+ Constant *Op = CE->getOperand(0);
+ const Type *OpTy = Op->getType(), *Ty = CE->getType();
+
+ // Remember, kids, pointers can be losslessly converted back and forth
+ // into 32-bit or wider integers, regardless of signedness. :-P
+ assert(((isa<PointerType>(OpTy)
+ && (Ty == Type::LongTy || Ty == Type::ULongTy
+ || Ty == Type::IntTy || Ty == Type::UIntTy))
+ || (isa<PointerType>(Ty)
+ && (OpTy == Type::LongTy || OpTy == Type::ULongTy
+ || OpTy == Type::IntTy || OpTy == Type::UIntTy))
+ || (((TD.getTypeSize(Ty) >= TD.getTypeSize(OpTy))
+ && OpTy->isLosslesslyConvertibleTo(Ty))))
+ && "FIXME: Don't yet support this kind of constant cast expr");
+ O << "(";
+ emitConstantValueOnly(Op);
+ O << ")";
+ break;
+ }
+ case Instruction::Add:
+ O << "(";
+ emitConstantValueOnly(CE->getOperand(0));
+ O << ") + (";
+ emitConstantValueOnly(CE->getOperand(1));
+ O << ")";
+ break;
+ default:
+ assert(0 && "Unsupported operator!");
+ }
+ } else {
+ assert(0 && "Unknown constant value!");
+ }
+ }
More information about the llvm-commits
mailing list