2004-12-16 17:47:03 +01:00
|
|
|
//===-- SparcV9AsmPrinter.cpp - Emit SparcV9 Specific .s File --------------==//
|
2005-04-22 01:30:14 +02:00
|
|
|
//
|
2003-10-20 21:43:21 +02:00
|
|
|
// 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.
|
2005-04-22 01:30:14 +02:00
|
|
|
//
|
2003-10-20 21:43:21 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
2001-09-19 15:47:27 +02:00
|
|
|
//
|
2003-08-18 16:43:39 +02:00
|
|
|
// This file implements all of the stuff necessary to output a .s file from
|
2001-09-19 15:47:27 +02:00
|
|
|
// LLVM. The code in this file assumes that the specified module has already
|
|
|
|
// been compiled into the internal data structures of the Module.
|
|
|
|
//
|
2002-04-27 08:56:12 +02:00
|
|
|
// This code largely consists of two LLVM Pass's: a FunctionPass and a Pass.
|
|
|
|
// The FunctionPass is pipelined together with all of the rest of the code
|
|
|
|
// generation stages, and the Pass runs at the end to emit code for global
|
|
|
|
// variables and such.
|
2001-09-19 15:47:27 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2002-04-28 21:55:58 +02:00
|
|
|
#include "llvm/Constants.h"
|
2001-10-28 22:38:52 +01:00
|
|
|
#include "llvm/DerivedTypes.h"
|
2001-09-19 15:47:27 +02:00
|
|
|
#include "llvm/Module.h"
|
2002-04-28 22:40:59 +02:00
|
|
|
#include "llvm/Pass.h"
|
2002-04-18 20:15:38 +02:00
|
|
|
#include "llvm/Assembly/Writer.h"
|
2003-12-17 23:06:28 +01:00
|
|
|
#include "llvm/CodeGen/MachineConstantPool.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
|
|
|
#include "llvm/CodeGen/MachineInstr.h"
|
2004-01-15 23:44:19 +01:00
|
|
|
#include "llvm/Support/Mangler.h"
|
2004-09-02 00:55:40 +02:00
|
|
|
#include "llvm/ADT/StringExtras.h"
|
|
|
|
#include "llvm/ADT/Statistic.h"
|
2004-02-25 19:44:15 +01:00
|
|
|
#include "SparcV9Internals.h"
|
2004-08-16 23:55:02 +02:00
|
|
|
#include "MachineFunctionInfo.h"
|
2003-08-05 18:01:50 +02:00
|
|
|
#include <string>
|
2003-11-13 01:22:19 +01:00
|
|
|
using namespace llvm;
|
|
|
|
|
2001-09-19 15:47:27 +02:00
|
|
|
namespace {
|
2003-11-13 01:22:19 +01:00
|
|
|
Statistic<> EmittedInsts("asm-printer", "Number of machine instrs printed");
|
2004-09-10 20:01:45 +02:00
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Utility functions
|
|
|
|
|
|
|
|
/// getAsCString - Return the specified array as a C compatible string, only
|
|
|
|
/// if the predicate isString() is true.
|
|
|
|
///
|
|
|
|
std::string getAsCString(const ConstantArray *CVA) {
|
|
|
|
assert(CVA->isString() && "Array is not string compatible!");
|
|
|
|
|
|
|
|
std::string Result = "\"";
|
|
|
|
for (unsigned i = 0; i != CVA->getNumOperands(); ++i) {
|
|
|
|
unsigned char C = cast<ConstantInt>(CVA->getOperand(i))->getRawValue();
|
|
|
|
|
|
|
|
if (C == '"') {
|
|
|
|
Result += "\\\"";
|
|
|
|
} else if (C == '\\') {
|
|
|
|
Result += "\\\\";
|
|
|
|
} else if (isprint(C)) {
|
|
|
|
Result += C;
|
|
|
|
} else {
|
|
|
|
Result += '\\'; // print all other chars as octal value
|
|
|
|
// Convert C to octal representation
|
|
|
|
Result += ((C >> 6) & 7) + '0';
|
|
|
|
Result += ((C >> 3) & 7) + '0';
|
|
|
|
Result += ((C >> 0) & 7) + '0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Result += "\"";
|
|
|
|
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool ArrayTypeIsString(const ArrayType* arrayType) {
|
|
|
|
return (arrayType->getElementType() == Type::UByteTy ||
|
|
|
|
arrayType->getElementType() == Type::SByteTy);
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned findOptimalStorageSize(const TargetMachine &TM, const Type *Ty) {
|
|
|
|
// All integer types smaller than ints promote to 4 byte integers.
|
|
|
|
if (Ty->isIntegral() && Ty->getPrimitiveSize() < 4)
|
|
|
|
return 4;
|
|
|
|
|
|
|
|
return TM.getTargetData().getTypeSize(Ty);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline const std::string
|
|
|
|
TypeToDataDirective(const Type* type) {
|
|
|
|
switch(type->getTypeID()) {
|
|
|
|
case Type::BoolTyID: case Type::UByteTyID: case Type::SByteTyID:
|
|
|
|
return ".byte";
|
|
|
|
case Type::UShortTyID: case Type::ShortTyID:
|
|
|
|
return ".half";
|
|
|
|
case Type::UIntTyID: case Type::IntTyID:
|
|
|
|
return ".word";
|
|
|
|
case Type::ULongTyID: case Type::LongTyID: case Type::PointerTyID:
|
|
|
|
return ".xword";
|
|
|
|
case Type::FloatTyID:
|
|
|
|
return ".word";
|
|
|
|
case Type::DoubleTyID:
|
|
|
|
return ".xword";
|
|
|
|
case Type::ArrayTyID:
|
|
|
|
if (ArrayTypeIsString((ArrayType*) type))
|
|
|
|
return ".ascii";
|
|
|
|
else
|
|
|
|
return "<InvaliDataTypeForPrinting>";
|
|
|
|
default:
|
|
|
|
return "<InvaliDataTypeForPrinting>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Get the size of the constant for the given target.
|
|
|
|
/// If this is an unsized array, return 0.
|
2005-04-22 01:30:14 +02:00
|
|
|
///
|
2004-09-10 20:01:45 +02:00
|
|
|
inline unsigned int
|
|
|
|
ConstantToSize(const Constant* CV, const TargetMachine& target) {
|
|
|
|
if (const ConstantArray* CVA = dyn_cast<ConstantArray>(CV)) {
|
|
|
|
const ArrayType *aty = cast<ArrayType>(CVA->getType());
|
|
|
|
if (ArrayTypeIsString(aty))
|
|
|
|
return 1 + CVA->getNumOperands();
|
|
|
|
}
|
2005-04-22 01:30:14 +02:00
|
|
|
|
2004-09-10 20:01:45 +02:00
|
|
|
return findOptimalStorageSize(target, CV->getType());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Align data larger than one L1 cache line on L1 cache line boundaries.
|
|
|
|
/// Align all smaller data on the next higher 2^x boundary (4, 8, ...).
|
2005-04-22 01:30:14 +02:00
|
|
|
///
|
2004-09-10 20:01:45 +02:00
|
|
|
inline unsigned int
|
|
|
|
SizeToAlignment(unsigned int size, const TargetMachine& target) {
|
|
|
|
const unsigned short cacheLineSize = 16;
|
|
|
|
if (size > (unsigned) cacheLineSize / 2)
|
|
|
|
return cacheLineSize;
|
|
|
|
else
|
|
|
|
for (unsigned sz=1; /*no condition*/; sz *= 2)
|
|
|
|
if (sz >= size)
|
|
|
|
return sz;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Get the size of the type and then use SizeToAlignment.
|
2005-04-22 01:30:14 +02:00
|
|
|
///
|
2004-09-10 20:01:45 +02:00
|
|
|
inline unsigned int
|
|
|
|
TypeToAlignment(const Type* type, const TargetMachine& target) {
|
|
|
|
return SizeToAlignment(findOptimalStorageSize(target, type), target);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Get the size of the constant and then use SizeToAlignment.
|
|
|
|
/// Handles strings as a special case;
|
|
|
|
inline unsigned int
|
|
|
|
ConstantToAlignment(const Constant* CV, const TargetMachine& target) {
|
|
|
|
if (const ConstantArray* CVA = dyn_cast<ConstantArray>(CV))
|
|
|
|
if (ArrayTypeIsString(cast<ArrayType>(CVA->getType())))
|
|
|
|
return SizeToAlignment(1 + CVA->getNumOperands(), target);
|
2005-04-22 01:30:14 +02:00
|
|
|
|
2004-09-10 20:01:45 +02:00
|
|
|
return TypeToAlignment(CV->getType(), target);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // End anonymous namespace
|
2003-11-13 01:22:19 +01:00
|
|
|
|
|
|
|
namespace {
|
2004-09-10 20:01:45 +02:00
|
|
|
enum Sections {
|
|
|
|
Unknown,
|
|
|
|
Text,
|
|
|
|
ReadOnlyData,
|
|
|
|
InitRWData,
|
|
|
|
ZeroInitRWData,
|
|
|
|
};
|
|
|
|
|
|
|
|
class AsmPrinter {
|
|
|
|
// Mangle symbol names appropriately
|
|
|
|
Mangler *Mang;
|
|
|
|
|
2003-11-13 01:22:19 +01:00
|
|
|
public:
|
2004-09-10 20:01:45 +02:00
|
|
|
std::ostream &O;
|
|
|
|
const TargetMachine &TM;
|
|
|
|
|
|
|
|
enum Sections CurSection;
|
|
|
|
|
|
|
|
AsmPrinter(std::ostream &os, const TargetMachine &T)
|
|
|
|
: /* idTable(0), */ O(os), TM(T), CurSection(Unknown) {}
|
2005-04-22 01:30:14 +02:00
|
|
|
|
2004-09-10 20:01:45 +02:00
|
|
|
~AsmPrinter() {
|
|
|
|
delete Mang;
|
2003-11-07 18:45:28 +01:00
|
|
|
}
|
|
|
|
|
2004-09-10 20:01:45 +02:00
|
|
|
// (start|end)(Module|Function) - Callback methods invoked by subclasses
|
|
|
|
void startModule(Module &M) {
|
|
|
|
Mang = new Mangler(M);
|
2003-11-13 01:22:19 +01:00
|
|
|
}
|
2003-11-07 18:45:28 +01:00
|
|
|
|
2004-09-10 20:01:45 +02:00
|
|
|
void PrintZeroBytesToPad(int numBytes) {
|
|
|
|
//
|
|
|
|
// Always use single unsigned bytes for padding. We don't know upon
|
|
|
|
// what data size the beginning address is aligned, so using anything
|
|
|
|
// other than a byte may cause alignment errors in the assembler.
|
|
|
|
//
|
|
|
|
while (numBytes--)
|
|
|
|
printSingleConstantValue(Constant::getNullValue(Type::UByteTy));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Print a single constant value.
|
|
|
|
///
|
|
|
|
void printSingleConstantValue(const Constant* CV);
|
|
|
|
|
|
|
|
/// Print a constant value or values (it may be an aggregate).
|
|
|
|
/// Uses printSingleConstantValue() to print each individual value.
|
|
|
|
///
|
|
|
|
void printConstantValueOnly(const Constant* CV, int numPadBytesAfter = 0);
|
|
|
|
|
2003-11-13 01:22:19 +01:00
|
|
|
// Print a constant (which may be an aggregate) prefixed by all the
|
|
|
|
// appropriate directives. Uses printConstantValueOnly() to print the
|
|
|
|
// value or values.
|
2004-09-10 20:01:45 +02:00
|
|
|
void printConstant(const Constant* CV, std::string valID = "") {
|
|
|
|
if (valID.length() == 0)
|
|
|
|
valID = getID(CV);
|
2005-04-22 01:30:14 +02:00
|
|
|
|
2004-09-10 20:01:45 +02:00
|
|
|
O << "\t.align\t" << ConstantToAlignment(CV, TM) << "\n";
|
2005-04-22 01:30:14 +02:00
|
|
|
|
2004-09-10 20:01:45 +02:00
|
|
|
// Print .size and .type only if it is not a string.
|
|
|
|
if (const ConstantArray *CVA = dyn_cast<ConstantArray>(CV))
|
|
|
|
if (CVA->isString()) {
|
|
|
|
// print it as a string and return
|
|
|
|
O << valID << ":\n";
|
|
|
|
O << "\t" << ".ascii" << "\t" << getAsCString(CVA) << "\n";
|
|
|
|
return;
|
|
|
|
}
|
2005-04-22 01:30:14 +02:00
|
|
|
|
2004-08-18 07:29:08 +02:00
|
|
|
O << "\t.type" << "\t" << valID << ",#object\n";
|
2003-11-07 18:45:28 +01:00
|
|
|
|
2004-09-10 20:01:45 +02:00
|
|
|
unsigned int constSize = ConstantToSize(CV, TM);
|
|
|
|
if (constSize)
|
|
|
|
O << "\t.size" << "\t" << valID << "," << constSize << "\n";
|
2005-04-22 01:30:14 +02:00
|
|
|
|
2004-08-18 07:29:08 +02:00
|
|
|
O << valID << ":\n";
|
2005-04-22 01:30:14 +02:00
|
|
|
|
2004-09-10 20:01:45 +02:00
|
|
|
printConstantValueOnly(CV);
|
2003-11-13 01:22:19 +01:00
|
|
|
}
|
2003-11-07 18:45:28 +01:00
|
|
|
|
2003-11-13 01:22:19 +01:00
|
|
|
// enterSection - Use this method to enter a different section of the output
|
|
|
|
// executable. This is used to only output necessary section transitions.
|
|
|
|
//
|
|
|
|
void enterSection(enum Sections S) {
|
|
|
|
if (S == CurSection) return; // Only switch section if necessary
|
|
|
|
CurSection = S;
|
|
|
|
|
2004-08-18 07:29:08 +02:00
|
|
|
O << "\n\t.section ";
|
2003-11-13 01:22:19 +01:00
|
|
|
switch (S)
|
2003-05-31 09:27:17 +02:00
|
|
|
{
|
|
|
|
default: assert(0 && "Bad section name!");
|
2004-08-18 07:29:08 +02:00
|
|
|
case Text: O << "\".text\""; break;
|
|
|
|
case ReadOnlyData: O << "\".rodata\",#alloc"; break;
|
|
|
|
case InitRWData: O << "\".data\",#alloc,#write"; break;
|
|
|
|
case ZeroInitRWData: O << "\".bss\",#alloc,#write"; break;
|
2003-05-31 09:27:17 +02:00
|
|
|
}
|
2004-08-18 07:29:08 +02:00
|
|
|
O << "\n";
|
2003-11-13 01:22:19 +01:00
|
|
|
}
|
2001-09-19 15:47:27 +02:00
|
|
|
|
2004-01-15 23:44:19 +01:00
|
|
|
// getID Wrappers - Ensure consistent usage
|
2004-02-25 19:44:15 +01:00
|
|
|
// Symbol names in SparcV9 assembly language have these rules:
|
2004-01-15 23:44:19 +01:00
|
|
|
// (a) Must match { letter | _ | . | $ } { letter | _ | . | $ | digit }*
|
|
|
|
// (b) A name beginning in "." is treated as a local name.
|
2003-11-13 01:22:19 +01:00
|
|
|
std::string getID(const Function *F) {
|
2004-01-15 23:44:19 +01:00
|
|
|
return Mang->getValueName(F);
|
2003-11-13 01:22:19 +01:00
|
|
|
}
|
|
|
|
std::string getID(const BasicBlock *BB) {
|
2004-01-15 23:44:19 +01:00
|
|
|
return ".L_" + getID(BB->getParent()) + "_" + Mang->getValueName(BB);
|
2003-11-13 01:22:19 +01:00
|
|
|
}
|
|
|
|
std::string getID(const GlobalVariable *GV) {
|
2004-01-15 23:44:19 +01:00
|
|
|
return Mang->getValueName(GV);
|
2003-11-13 01:22:19 +01:00
|
|
|
}
|
|
|
|
std::string getID(const Constant *CV) {
|
2004-01-15 23:44:19 +01:00
|
|
|
return ".C_" + Mang->getValueName(CV);
|
2003-11-13 01:22:19 +01:00
|
|
|
}
|
|
|
|
std::string getID(const GlobalValue *GV) {
|
|
|
|
if (const GlobalVariable *V = dyn_cast<GlobalVariable>(GV))
|
|
|
|
return getID(V);
|
|
|
|
else if (const Function *F = dyn_cast<Function>(GV))
|
|
|
|
return getID(F);
|
|
|
|
assert(0 && "Unexpected type of GlobalValue!");
|
|
|
|
return "";
|
|
|
|
}
|
2002-08-22 04:58:36 +02:00
|
|
|
|
2005-04-22 01:30:14 +02:00
|
|
|
// Combines expressions
|
2004-09-10 20:01:45 +02:00
|
|
|
inline std::string ConstantArithExprToString(const ConstantExpr* CE,
|
|
|
|
const TargetMachine &TM,
|
|
|
|
const std::string &op) {
|
|
|
|
return "(" + valToExprString(CE->getOperand(0), TM) + op
|
|
|
|
+ valToExprString(CE->getOperand(1), TM) + ")";
|
|
|
|
}
|
|
|
|
|
|
|
|
/// ConstantExprToString() - Convert a ConstantExpr to an asm expression
|
|
|
|
/// and return this as a string.
|
|
|
|
///
|
|
|
|
std::string ConstantExprToString(const ConstantExpr* CE,
|
|
|
|
const TargetMachine& target);
|
|
|
|
|
|
|
|
/// valToExprString - Helper function for ConstantExprToString().
|
|
|
|
/// Appends result to argument string S.
|
2005-04-22 01:30:14 +02:00
|
|
|
///
|
2004-09-10 20:01:45 +02:00
|
|
|
std::string valToExprString(const Value* V, const TargetMachine& target);
|
|
|
|
};
|
|
|
|
} // End anonymous namespace
|
|
|
|
|
|
|
|
|
|
|
|
/// Print a single constant value.
|
|
|
|
///
|
|
|
|
void AsmPrinter::printSingleConstantValue(const Constant* CV) {
|
|
|
|
assert(CV->getType() != Type::VoidTy &&
|
|
|
|
CV->getType() != Type::LabelTy &&
|
|
|
|
"Unexpected type for Constant");
|
2005-04-22 01:30:14 +02:00
|
|
|
|
2004-09-10 20:01:45 +02:00
|
|
|
assert((!isa<ConstantArray>(CV) && ! isa<ConstantStruct>(CV))
|
|
|
|
&& "Aggregate types should be handled outside this function");
|
2005-04-22 01:30:14 +02:00
|
|
|
|
2004-09-10 20:01:45 +02:00
|
|
|
O << "\t" << TypeToDataDirective(CV->getType()) << "\t";
|
2005-04-22 01:30:14 +02:00
|
|
|
|
2004-09-10 20:01:45 +02:00
|
|
|
if (const GlobalValue* GV = dyn_cast<GlobalValue>(CV)) {
|
|
|
|
O << getID(GV) << "\n";
|
2004-10-16 20:14:10 +02:00
|
|
|
} else if (isa<ConstantPointerNull>(CV) || isa<UndefValue>(CV)) {
|
2004-09-10 20:01:45 +02:00
|
|
|
// Null pointer value
|
|
|
|
O << "0\n";
|
2005-04-22 01:30:14 +02:00
|
|
|
} else if (const ConstantExpr* CE = dyn_cast<ConstantExpr>(CV)) {
|
2004-09-10 20:01:45 +02:00
|
|
|
// Constant expression built from operators, constants, and symbolic addrs
|
|
|
|
O << ConstantExprToString(CE, TM) << "\n";
|
|
|
|
} else if (CV->getType()->isPrimitiveType()) {
|
|
|
|
// Check primitive types last
|
2004-10-17 04:44:45 +02:00
|
|
|
if (isa<UndefValue>(CV)) {
|
|
|
|
O << "0\n";
|
|
|
|
} else if (CV->getType()->isFloatingPoint()) {
|
2004-09-10 20:01:45 +02:00
|
|
|
// FP Constants are printed as integer constants to avoid losing
|
|
|
|
// precision...
|
|
|
|
double Val = cast<ConstantFP>(CV)->getValue();
|
|
|
|
if (CV->getType() == Type::FloatTy) {
|
|
|
|
float FVal = (float)Val;
|
|
|
|
char *ProxyPtr = (char*)&FVal; // Abide by C TBAA rules
|
2005-04-22 01:30:14 +02:00
|
|
|
O << *(unsigned int*)ProxyPtr;
|
2004-09-10 20:01:45 +02:00
|
|
|
} else if (CV->getType() == Type::DoubleTy) {
|
|
|
|
char *ProxyPtr = (char*)&Val; // Abide by C TBAA rules
|
2005-04-22 01:30:14 +02:00
|
|
|
O << *(uint64_t*)ProxyPtr;
|
2004-09-10 20:01:45 +02:00
|
|
|
} else {
|
|
|
|
assert(0 && "Unknown floating point type!");
|
|
|
|
}
|
2005-04-22 01:30:14 +02:00
|
|
|
|
2004-09-10 20:01:45 +02:00
|
|
|
O << "\t! " << CV->getType()->getDescription()
|
|
|
|
<< " value: " << Val << "\n";
|
|
|
|
} else if (const ConstantBool *CB = dyn_cast<ConstantBool>(CV)) {
|
|
|
|
O << (int)CB->getValue() << "\n";
|
|
|
|
} else {
|
|
|
|
WriteAsOperand(O, CV, false, false) << "\n";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
assert(0 && "Unknown elementary type for constant");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Print a constant value or values (it may be an aggregate).
|
|
|
|
/// Uses printSingleConstantValue() to print each individual value.
|
|
|
|
///
|
|
|
|
void AsmPrinter::printConstantValueOnly(const Constant* CV,
|
|
|
|
int numPadBytesAfter) {
|
|
|
|
if (const ConstantArray *CVA = dyn_cast<ConstantArray>(CV)) {
|
|
|
|
if (CVA->isString()) {
|
|
|
|
// print the string alone and return
|
|
|
|
O << "\t" << ".ascii" << "\t" << getAsCString(CVA) << "\n";
|
|
|
|
} else {
|
|
|
|
// Not a string. Print the values in successive locations
|
|
|
|
for (unsigned i = 0, e = CVA->getNumOperands(); i != e; ++i)
|
|
|
|
printConstantValueOnly(CVA->getOperand(i));
|
|
|
|
}
|
|
|
|
} else if (const ConstantStruct *CVS = dyn_cast<ConstantStruct>(CV)) {
|
|
|
|
// Print the fields in successive locations. Pad to align if needed!
|
|
|
|
const StructLayout *cvsLayout =
|
|
|
|
TM.getTargetData().getStructLayout(CVS->getType());
|
|
|
|
unsigned sizeSoFar = 0;
|
|
|
|
for (unsigned i = 0, e = CVS->getNumOperands(); i != e; ++i) {
|
|
|
|
const Constant* field = CVS->getOperand(i);
|
|
|
|
|
|
|
|
// Check if padding is needed and insert one or more 0s.
|
|
|
|
unsigned fieldSize =
|
|
|
|
TM.getTargetData().getTypeSize(field->getType());
|
|
|
|
int padSize = ((i == e-1? cvsLayout->StructSize
|
|
|
|
: cvsLayout->MemberOffsets[i+1])
|
|
|
|
- cvsLayout->MemberOffsets[i]) - fieldSize;
|
|
|
|
sizeSoFar += (fieldSize + padSize);
|
|
|
|
|
|
|
|
// Now print the actual field value
|
|
|
|
printConstantValueOnly(field, padSize);
|
|
|
|
}
|
|
|
|
assert(sizeSoFar == cvsLayout->StructSize &&
|
|
|
|
"Layout of constant struct may be incorrect!");
|
2004-10-17 04:44:45 +02:00
|
|
|
} else if (isa<ConstantAggregateZero>(CV) || isa<UndefValue>(CV)) {
|
2004-09-10 20:01:45 +02:00
|
|
|
PrintZeroBytesToPad(TM.getTargetData().getTypeSize(CV->getType()));
|
|
|
|
} else
|
|
|
|
printSingleConstantValue(CV);
|
|
|
|
|
|
|
|
if (numPadBytesAfter)
|
|
|
|
PrintZeroBytesToPad(numPadBytesAfter);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// ConstantExprToString() - Convert a ConstantExpr to an asm expression
|
|
|
|
/// and return this as a string.
|
|
|
|
///
|
|
|
|
std::string AsmPrinter::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);
|
|
|
|
std::vector<Value*> idxVec(CE->op_begin()+1, CE->op_end());
|
|
|
|
const TargetData &TD = target.getTargetData();
|
|
|
|
S += "(" + valToExprString(ptrVal, target) + ") + ("
|
|
|
|
+ utostr(TD.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.getTargetData().getTypeSize(CE->getType()) ==
|
|
|
|
target.getTargetData().getTypeSize(CE->getOperand(0)->getType()));
|
|
|
|
S += "(" + valToExprString(CE->getOperand(0), target) + ")";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Instruction::Add:
|
|
|
|
S += ConstantArithExprToString(CE, target, ") + (");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Instruction::Sub:
|
|
|
|
S += ConstantArithExprToString(CE, target, ") - (");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Instruction::Mul:
|
|
|
|
S += ConstantArithExprToString(CE, target, ") * (");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Instruction::Div:
|
|
|
|
S += ConstantArithExprToString(CE, target, ") / (");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Instruction::Rem:
|
|
|
|
S += ConstantArithExprToString(CE, target, ") % (");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Instruction::And:
|
|
|
|
// Logical && for booleans; bitwise & otherwise
|
|
|
|
S += ConstantArithExprToString(CE, target,
|
|
|
|
((CE->getType() == Type::BoolTy)? ") && (" : ") & ("));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Instruction::Or:
|
|
|
|
// Logical || for booleans; bitwise | otherwise
|
|
|
|
S += ConstantArithExprToString(CE, target,
|
|
|
|
((CE->getType() == Type::BoolTy)? ") || (" : ") | ("));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Instruction::Xor:
|
|
|
|
// Bitwise ^ for all types
|
|
|
|
S += ConstantArithExprToString(CE, target, ") ^ (");
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
assert(0 && "Unsupported operator in ConstantExprToString()");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// valToExprString - Helper function for ConstantExprToString().
|
|
|
|
/// Appends result to argument string S.
|
2005-04-22 01:30:14 +02:00
|
|
|
///
|
2004-09-10 20:01:45 +02:00
|
|
|
std::string AsmPrinter::valToExprString(const Value* V,
|
|
|
|
const TargetMachine& target) {
|
|
|
|
std::string S;
|
|
|
|
bool failed = false;
|
|
|
|
if (const GlobalValue* GV = dyn_cast<GlobalValue>(V)) {
|
|
|
|
S += getID(GV);
|
|
|
|
} else 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");
|
|
|
|
else if (const ConstantSInt *CI = dyn_cast<ConstantSInt>(CV))
|
|
|
|
S += itostr(CI->getValue());
|
|
|
|
else if (const ConstantUInt *CI = dyn_cast<ConstantUInt>(CV))
|
|
|
|
S += utostr(CI->getValue());
|
|
|
|
else if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV))
|
|
|
|
S += ftostr(CFP->getValue());
|
2004-10-16 20:14:10 +02:00
|
|
|
else if (isa<ConstantPointerNull>(CV) || isa<UndefValue>(CV))
|
2004-09-10 20:01:45 +02:00
|
|
|
S += "0";
|
|
|
|
else if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV))
|
|
|
|
S += ConstantExprToString(CE, target);
|
|
|
|
else
|
|
|
|
failed = true;
|
|
|
|
} else
|
|
|
|
failed = true;
|
|
|
|
|
|
|
|
if (failed) {
|
|
|
|
assert(0 && "Cannot convert value to string");
|
|
|
|
S += "<illegal-value>";
|
|
|
|
}
|
|
|
|
return S;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
struct SparcV9AsmPrinter : public FunctionPass, public AsmPrinter {
|
|
|
|
inline SparcV9AsmPrinter(std::ostream &os, const TargetMachine &t)
|
|
|
|
: AsmPrinter(os, t) {}
|
|
|
|
|
|
|
|
const Function *currFunction;
|
|
|
|
|
|
|
|
const char *getPassName() const {
|
|
|
|
return "Output SparcV9 Assembly for Functions";
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool doInitialization(Module &M) {
|
|
|
|
startModule(M);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool runOnFunction(Function &F) {
|
|
|
|
currFunction = &F;
|
|
|
|
emitFunction(F);
|
2003-11-13 01:22:19 +01:00
|
|
|
return false;
|
|
|
|
}
|
2002-04-28 23:27:06 +02:00
|
|
|
|
2003-11-13 01:22:19 +01:00
|
|
|
virtual bool doFinalization(Module &M) {
|
|
|
|
emitGlobals(M);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2004-09-10 20:01:45 +02:00
|
|
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
|
|
|
AU.setPreservesAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
void emitFunction(const Function &F);
|
2003-11-13 01:22:19 +01:00
|
|
|
private :
|
|
|
|
void emitBasicBlock(const MachineBasicBlock &MBB);
|
|
|
|
void emitMachineInst(const MachineInstr *MI);
|
2005-04-22 01:30:14 +02:00
|
|
|
|
2003-11-13 01:22:19 +01:00
|
|
|
unsigned int printOperands(const MachineInstr *MI, unsigned int opNum);
|
|
|
|
void printOneOperand(const MachineOperand &Op, MachineOpCode opCode);
|
2002-02-04 00:41:08 +01:00
|
|
|
|
2003-11-13 01:22:19 +01:00
|
|
|
bool OpIsBranchTargetLabel(const MachineInstr *MI, unsigned int opNum);
|
|
|
|
bool OpIsMemoryAddressBase(const MachineInstr *MI, unsigned int opNum);
|
2005-04-22 01:30:14 +02:00
|
|
|
|
2003-11-13 01:22:19 +01:00
|
|
|
unsigned getOperandMask(unsigned Opcode) {
|
|
|
|
switch (Opcode) {
|
|
|
|
case V9::SUBccr:
|
|
|
|
case V9::SUBcci: return 1 << 3; // Remove CC argument
|
|
|
|
default: return 0; // By default, don't hack operands...
|
|
|
|
}
|
2002-02-04 00:41:08 +01:00
|
|
|
}
|
2003-11-13 01:22:19 +01:00
|
|
|
|
|
|
|
void emitGlobals(const Module &M);
|
|
|
|
void printGlobalVariable(const GlobalVariable *GV);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // End anonymous namespace
|
2001-11-27 01:03:19 +01:00
|
|
|
|
2001-10-28 22:38:52 +01:00
|
|
|
inline bool
|
2004-02-25 19:44:15 +01:00
|
|
|
SparcV9AsmPrinter::OpIsBranchTargetLabel(const MachineInstr *MI,
|
2003-11-13 01:22:19 +01:00
|
|
|
unsigned int opNum) {
|
2004-02-11 21:47:34 +01:00
|
|
|
switch (MI->getOpcode()) {
|
2003-05-28 00:35:43 +02:00
|
|
|
case V9::JMPLCALLr:
|
|
|
|
case V9::JMPLCALLi:
|
|
|
|
case V9::JMPLRETr:
|
|
|
|
case V9::JMPLRETi:
|
2003-05-20 22:32:24 +02:00
|
|
|
return (opNum == 0);
|
|
|
|
default:
|
|
|
|
return false;
|
2001-10-15 21:21:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-10-28 22:38:52 +01:00
|
|
|
inline bool
|
2004-02-25 19:44:15 +01:00
|
|
|
SparcV9AsmPrinter::OpIsMemoryAddressBase(const MachineInstr *MI,
|
2003-11-13 01:22:19 +01:00
|
|
|
unsigned int opNum) {
|
2004-08-18 07:29:08 +02:00
|
|
|
if (TM.getInstrInfo()->isLoad(MI->getOpcode()))
|
2001-10-28 22:38:52 +01:00
|
|
|
return (opNum == 0);
|
2004-08-18 07:29:08 +02:00
|
|
|
else if (TM.getInstrInfo()->isStore(MI->getOpcode()))
|
2001-10-28 22:38:52 +01:00
|
|
|
return (opNum == 1);
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
2001-09-19 15:47:27 +02:00
|
|
|
|
2001-10-28 22:38:52 +01:00
|
|
|
unsigned int
|
2004-08-18 07:29:08 +02:00
|
|
|
SparcV9AsmPrinter::printOperands(const MachineInstr *MI, unsigned opNum) {
|
2002-07-10 23:41:21 +02:00
|
|
|
const MachineOperand& mop = MI->getOperand(opNum);
|
2003-11-13 01:22:19 +01:00
|
|
|
if (OpIsBranchTargetLabel(MI, opNum)) {
|
2004-08-18 07:29:08 +02:00
|
|
|
printOneOperand(mop, MI->getOpcode());
|
|
|
|
O << "+";
|
|
|
|
printOneOperand(MI->getOperand(opNum+1), MI->getOpcode());
|
2003-11-13 01:22:19 +01:00
|
|
|
return 2;
|
|
|
|
} else if (OpIsMemoryAddressBase(MI, opNum)) {
|
2004-08-18 07:29:08 +02:00
|
|
|
O << "[";
|
|
|
|
printOneOperand(mop, MI->getOpcode());
|
|
|
|
O << "+";
|
|
|
|
printOneOperand(MI->getOperand(opNum+1), MI->getOpcode());
|
|
|
|
O << "]";
|
2003-11-13 01:22:19 +01:00
|
|
|
return 2;
|
|
|
|
} else {
|
2004-02-11 21:47:34 +01:00
|
|
|
printOneOperand(mop, MI->getOpcode());
|
2003-11-13 01:22:19 +01:00
|
|
|
return 1;
|
|
|
|
}
|
2001-10-28 22:38:52 +01:00
|
|
|
}
|
2001-10-25 00:05:34 +02:00
|
|
|
|
2001-10-28 22:38:52 +01:00
|
|
|
void
|
2004-02-25 19:44:15 +01:00
|
|
|
SparcV9AsmPrinter::printOneOperand(const MachineOperand &mop,
|
2004-08-18 07:29:08 +02:00
|
|
|
MachineOpCode opCode)
|
2001-10-28 22:38:52 +01:00
|
|
|
{
|
2002-07-10 23:41:21 +02:00
|
|
|
bool needBitsFlag = true;
|
2005-04-22 01:30:14 +02:00
|
|
|
|
2003-12-14 14:24:17 +01:00
|
|
|
if (mop.isHiBits32())
|
2004-08-18 07:29:08 +02:00
|
|
|
O << "%lm(";
|
2003-12-14 14:24:17 +01:00
|
|
|
else if (mop.isLoBits32())
|
2004-08-18 07:29:08 +02:00
|
|
|
O << "%lo(";
|
2003-12-14 14:24:17 +01:00
|
|
|
else if (mop.isHiBits64())
|
2004-08-18 07:29:08 +02:00
|
|
|
O << "%hh(";
|
2003-12-14 14:24:17 +01:00
|
|
|
else if (mop.isLoBits64())
|
2004-08-18 07:29:08 +02:00
|
|
|
O << "%hm(";
|
2002-07-10 23:41:21 +02:00
|
|
|
else
|
|
|
|
needBitsFlag = false;
|
2005-04-22 01:30:14 +02:00
|
|
|
|
2002-10-28 05:45:29 +01:00
|
|
|
switch (mop.getType())
|
2003-05-31 09:27:17 +02:00
|
|
|
{
|
2003-07-06 22:13:59 +02:00
|
|
|
case MachineOperand::MO_VirtualRegister:
|
2003-07-10 21:42:11 +02:00
|
|
|
case MachineOperand::MO_CCRegister:
|
2003-05-31 09:27:17 +02:00
|
|
|
case MachineOperand::MO_MachineRegister:
|
|
|
|
{
|
2004-02-13 22:01:20 +01:00
|
|
|
int regNum = (int)mop.getReg();
|
2005-04-22 01:30:14 +02:00
|
|
|
|
2004-08-18 07:29:08 +02:00
|
|
|
if (regNum == TM.getRegInfo()->getInvalidRegNum()) {
|
2003-05-31 09:27:17 +02:00
|
|
|
// better to print code with NULL registers than to die
|
2004-08-18 07:29:08 +02:00
|
|
|
O << "<NULL VALUE>";
|
2003-05-31 09:27:17 +02:00
|
|
|
} else {
|
2004-08-18 07:29:08 +02:00
|
|
|
O << "%" << TM.getRegInfo()->getUnifiedRegName(regNum);
|
2003-05-31 09:27:17 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2005-04-22 01:30:14 +02:00
|
|
|
|
2003-11-07 18:45:28 +01:00
|
|
|
case MachineOperand::MO_ConstantPoolIndex:
|
|
|
|
{
|
2004-09-10 20:01:45 +02:00
|
|
|
O << ".CPI_" << getID(currFunction)
|
|
|
|
<< "_" << mop.getConstantPoolIndex();
|
2003-11-07 18:45:28 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-05-31 09:27:17 +02:00
|
|
|
case MachineOperand::MO_PCRelativeDisp:
|
|
|
|
{
|
|
|
|
const Value *Val = mop.getVRegValue();
|
2004-02-25 19:44:15 +01:00
|
|
|
assert(Val && "\tNULL Value in SparcV9AsmPrinter");
|
2005-04-22 01:30:14 +02:00
|
|
|
|
2003-07-23 17:30:06 +02:00
|
|
|
if (const BasicBlock *BB = dyn_cast<BasicBlock>(Val))
|
2004-08-18 07:29:08 +02:00
|
|
|
O << getID(BB);
|
2004-05-04 23:09:02 +02:00
|
|
|
else if (const Function *F = dyn_cast<Function>(Val))
|
2004-08-18 07:29:08 +02:00
|
|
|
O << getID(F);
|
2003-05-31 09:27:17 +02:00
|
|
|
else if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(Val))
|
2004-08-18 07:29:08 +02:00
|
|
|
O << getID(GV);
|
2003-05-31 09:27:17 +02:00
|
|
|
else if (const Constant *CV = dyn_cast<Constant>(Val))
|
2004-08-18 07:29:08 +02:00
|
|
|
O << getID(CV);
|
2003-05-31 09:27:17 +02:00
|
|
|
else
|
2004-02-25 19:44:15 +01:00
|
|
|
assert(0 && "Unrecognized value in SparcV9AsmPrinter");
|
2003-05-31 09:27:17 +02:00
|
|
|
break;
|
|
|
|
}
|
2005-04-22 01:30:14 +02:00
|
|
|
|
2003-05-31 09:27:17 +02:00
|
|
|
case MachineOperand::MO_SignExtendedImmed:
|
2004-08-18 07:29:08 +02:00
|
|
|
O << mop.getImmedValue();
|
2003-05-31 09:27:17 +02:00
|
|
|
break;
|
2002-05-19 17:25:51 +02:00
|
|
|
|
2003-05-31 09:27:17 +02:00
|
|
|
case MachineOperand::MO_UnextendedImmed:
|
2004-08-18 07:29:08 +02:00
|
|
|
O << (uint64_t) mop.getImmedValue();
|
2003-05-31 09:27:17 +02:00
|
|
|
break;
|
2005-04-22 01:30:14 +02:00
|
|
|
|
2003-05-31 09:27:17 +02:00
|
|
|
default:
|
2004-08-18 07:29:08 +02:00
|
|
|
O << mop; // use dump field
|
2003-05-31 09:27:17 +02:00
|
|
|
break;
|
|
|
|
}
|
2005-04-22 01:30:14 +02:00
|
|
|
|
2002-07-10 23:41:21 +02:00
|
|
|
if (needBitsFlag)
|
2004-08-18 07:29:08 +02:00
|
|
|
O << ")";
|
2001-10-28 22:38:52 +01:00
|
|
|
}
|
2001-10-25 00:05:34 +02:00
|
|
|
|
2004-02-25 19:44:15 +01:00
|
|
|
void SparcV9AsmPrinter::emitMachineInst(const MachineInstr *MI) {
|
2004-02-11 21:47:34 +01:00
|
|
|
unsigned Opcode = MI->getOpcode();
|
2001-10-25 00:05:34 +02:00
|
|
|
|
2004-08-18 22:04:24 +02:00
|
|
|
if (Opcode == V9::PHI)
|
|
|
|
return; // Ignore Machine-PHI nodes.
|
2001-10-25 00:05:34 +02:00
|
|
|
|
2004-08-18 07:29:08 +02:00
|
|
|
O << "\t" << TM.getInstrInfo()->getName(Opcode) << "\t";
|
2001-10-25 00:05:34 +02:00
|
|
|
|
2001-09-19 15:47:27 +02:00
|
|
|
unsigned Mask = getOperandMask(Opcode);
|
2005-04-22 01:30:14 +02:00
|
|
|
|
2001-09-19 15:47:27 +02:00
|
|
|
bool NeedComma = false;
|
2001-10-28 22:38:52 +01:00
|
|
|
unsigned N = 1;
|
|
|
|
for (unsigned OpNum = 0; OpNum < MI->getNumOperands(); OpNum += N)
|
|
|
|
if (! ((1 << OpNum) & Mask)) { // Ignore this operand?
|
2004-08-18 07:29:08 +02:00
|
|
|
if (NeedComma) O << ", "; // Handle comma outputting
|
2001-10-28 22:38:52 +01:00
|
|
|
NeedComma = true;
|
|
|
|
N = printOperands(MI, OpNum);
|
2002-11-17 23:57:23 +01:00
|
|
|
} else
|
|
|
|
N = 1;
|
2005-04-22 01:30:14 +02:00
|
|
|
|
2004-08-18 07:29:08 +02:00
|
|
|
O << "\n";
|
2003-10-06 17:41:21 +02:00
|
|
|
++EmittedInsts;
|
2001-09-19 15:47:27 +02:00
|
|
|
}
|
|
|
|
|
2004-02-25 19:44:15 +01:00
|
|
|
void SparcV9AsmPrinter::emitBasicBlock(const MachineBasicBlock &MBB) {
|
2001-09-19 15:47:27 +02:00
|
|
|
// Emit a label for the basic block
|
2004-08-18 07:29:08 +02:00
|
|
|
O << getID(MBB.getBasicBlock()) << ":\n";
|
2001-09-19 15:47:27 +02:00
|
|
|
|
|
|
|
// Loop over all of the instructions in the basic block...
|
2002-10-28 21:01:13 +01:00
|
|
|
for (MachineBasicBlock::const_iterator MII = MBB.begin(), MIE = MBB.end();
|
2002-10-28 02:41:47 +01:00
|
|
|
MII != MIE; ++MII)
|
2004-02-12 03:27:10 +01:00
|
|
|
emitMachineInst(MII);
|
2004-08-18 07:29:08 +02:00
|
|
|
O << "\n"; // Separate BB's with newlines
|
2001-09-19 15:47:27 +02:00
|
|
|
}
|
|
|
|
|
2004-09-10 20:01:45 +02:00
|
|
|
void SparcV9AsmPrinter::emitFunction(const Function &F) {
|
|
|
|
std::string CurrentFnName = getID(&F);
|
|
|
|
MachineFunction &MF = MachineFunction::get(&F);
|
2004-08-18 07:29:08 +02:00
|
|
|
O << "!****** Outputing Function: " << CurrentFnName << " ******\n";
|
2003-11-07 18:45:28 +01:00
|
|
|
|
|
|
|
// Emit constant pool for this function
|
2004-08-18 07:29:08 +02:00
|
|
|
const MachineConstantPool *MCP = MF.getConstantPool();
|
2003-11-07 18:45:28 +01:00
|
|
|
const std::vector<Constant*> &CP = MCP->getConstants();
|
|
|
|
|
2004-08-18 07:29:08 +02:00
|
|
|
enterSection(ReadOnlyData);
|
2003-11-07 18:45:28 +01:00
|
|
|
for (unsigned i = 0, e = CP.size(); i != e; ++i) {
|
2004-08-18 07:29:08 +02:00
|
|
|
std::string cpiName = ".CPI_" + CurrentFnName + "_" + utostr(i);
|
2003-11-07 18:45:28 +01:00
|
|
|
printConstant(CP[i], cpiName);
|
|
|
|
}
|
|
|
|
|
2004-08-18 07:29:08 +02:00
|
|
|
enterSection(Text);
|
|
|
|
O << "\t.align\t4\n\t.global\t" << CurrentFnName << "\n";
|
|
|
|
//O << "\t.type\t" << CurrentFnName << ",#function\n";
|
|
|
|
O << "\t.type\t" << CurrentFnName << ", 2\n";
|
|
|
|
O << CurrentFnName << ":\n";
|
2001-09-19 15:47:27 +02:00
|
|
|
|
2002-04-07 22:49:59 +02:00
|
|
|
// Output code for all of the basic blocks in the function...
|
2002-12-28 21:15:01 +01:00
|
|
|
for (MachineFunction::const_iterator I = MF.begin(), E = MF.end(); I != E;++I)
|
2002-10-28 21:01:13 +01:00
|
|
|
emitBasicBlock(*I);
|
2001-09-19 15:47:27 +02:00
|
|
|
|
|
|
|
// Output a .size directive so the debugger knows the extents of the function
|
2004-08-18 07:29:08 +02:00
|
|
|
O << ".EndOf_" << CurrentFnName << ":\n\t.size "
|
|
|
|
<< CurrentFnName << ", .EndOf_"
|
|
|
|
<< CurrentFnName << "-" << CurrentFnName << "\n";
|
2001-09-19 15:47:27 +02:00
|
|
|
|
2002-04-07 22:49:59 +02:00
|
|
|
// Put some spaces between the functions
|
2004-08-18 07:29:08 +02:00
|
|
|
O << "\n\n";
|
2002-02-04 00:41:08 +01:00
|
|
|
}
|
2001-09-19 15:47:27 +02:00
|
|
|
|
2004-02-25 19:44:15 +01:00
|
|
|
void SparcV9AsmPrinter::printGlobalVariable(const GlobalVariable* GV) {
|
2002-09-16 17:54:02 +02:00
|
|
|
if (GV->hasExternalLinkage())
|
2004-08-18 07:29:08 +02:00
|
|
|
O << "\t.global\t" << getID(GV) << "\n";
|
2005-04-22 01:30:14 +02:00
|
|
|
|
2004-10-16 20:14:10 +02:00
|
|
|
if (GV->hasInitializer() &&
|
|
|
|
!(GV->getInitializer()->isNullValue() ||
|
|
|
|
isa<UndefValue>(GV->getInitializer()))) {
|
2001-10-28 22:38:52 +01:00
|
|
|
printConstant(GV->getInitializer(), getID(GV));
|
2003-11-13 01:22:19 +01:00
|
|
|
} else {
|
2004-09-10 20:01:45 +02:00
|
|
|
O << "\t.align\t" << TypeToAlignment(GV->getType()->getElementType(),
|
|
|
|
TM) << "\n";
|
2004-08-18 07:29:08 +02:00
|
|
|
O << "\t.type\t" << getID(GV) << ",#object\n";
|
|
|
|
O << "\t.reserve\t" << getID(GV) << ","
|
2004-09-10 20:01:45 +02:00
|
|
|
<< findOptimalStorageSize(TM, GV->getType()->getElementType())
|
2004-08-18 07:29:08 +02:00
|
|
|
<< "\n";
|
2001-10-28 22:38:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-02-25 19:44:15 +01:00
|
|
|
void SparcV9AsmPrinter::emitGlobals(const Module &M) {
|
2002-08-07 23:39:48 +02:00
|
|
|
// Output global variables...
|
2005-03-15 05:54:21 +01:00
|
|
|
for (Module::const_global_iterator GI = M.global_begin(), GE = M.global_end(); GI != GE; ++GI)
|
2002-10-13 02:32:18 +02:00
|
|
|
if (! GI->isExternal()) {
|
|
|
|
assert(GI->hasInitializer());
|
|
|
|
if (GI->isConstant())
|
2004-08-18 07:29:08 +02:00
|
|
|
enterSection(ReadOnlyData); // read-only, initialized data
|
2004-10-16 20:14:10 +02:00
|
|
|
else if (GI->getInitializer()->isNullValue() ||
|
|
|
|
isa<UndefValue>(GI->getInitializer()))
|
2004-08-18 07:29:08 +02:00
|
|
|
enterSection(ZeroInitRWData); // read-write zero data
|
2002-10-13 02:32:18 +02:00
|
|
|
else
|
2004-08-18 07:29:08 +02:00
|
|
|
enterSection(InitRWData); // read-write non-zero data
|
2002-10-13 02:32:18 +02:00
|
|
|
|
|
|
|
printGlobalVariable(GI);
|
2002-08-07 23:39:48 +02:00
|
|
|
}
|
|
|
|
|
2004-08-18 07:29:08 +02:00
|
|
|
O << "\n";
|
2001-10-28 22:38:52 +01:00
|
|
|
}
|
|
|
|
|
2004-08-18 07:29:08 +02:00
|
|
|
FunctionPass *llvm::createAsmPrinterPass(std::ostream &Out, TargetMachine &TM) {
|
2004-02-25 19:44:15 +01:00
|
|
|
return new SparcV9AsmPrinter(Out, TM);
|
2001-09-19 15:47:27 +02:00
|
|
|
}
|