Chromium Code Reviews| Index: src/IceGlobalInits.cpp |
| diff --git a/src/IceGlobalInits.cpp b/src/IceGlobalInits.cpp |
| index 4d9dadb4c076de53fdf2f8d1b57ddd2701ed102e..366d56376558c827381ca070e65b51cd00615e7b 100644 |
| --- a/src/IceGlobalInits.cpp |
| +++ b/src/IceGlobalInits.cpp |
| @@ -17,18 +17,82 @@ |
| #include "llvm/IR/Value.h" |
| #include "IceDefs.h" |
| +#include "IceGlobalContext.h" |
| #include "IceGlobalInits.h" |
| #include "IceTypes.h" |
| namespace { |
| char hexdigit(unsigned X) { return X < 10 ? '0' + X : 'A' + X - 10; } |
| + |
| +void dumpLinkage(Ice::Ostream &Stream, |
| + llvm::GlobalValue::LinkageTypes Linkage) { |
| + switch (Linkage) { |
| + case llvm::GlobalValue::ExternalLinkage: |
| + Stream << "external"; |
| + return; |
| + case llvm::GlobalValue::InternalLinkage: |
| + Stream << "internal"; |
| + return; |
| + default: |
| + break; |
| + } |
| + std::string Buffer; |
| + llvm::raw_string_ostream StrBuf(Buffer); |
| + StrBuf << "Unknown linkage value: " << Linkage; |
| + llvm::report_fatal_error(StrBuf.str()); |
| +} |
| + |
| +void dumpCallingConv(Ice::Ostream &, llvm::CallingConv::ID CallingConv) { |
| + if (CallingConv == llvm::CallingConv::C) |
| + return; |
| + std::string Buffer; |
| + llvm::raw_string_ostream StrBuf(Buffer); |
| + StrBuf << "Unknown calling convention: " << CallingConv; |
| + llvm::report_fatal_error(StrBuf.str()); |
| +} |
| } |
|
Jim Stichnoth
2014/10/10 13:15:00
// end of anonymous namespace
Karl
2014/10/10 20:17:30
Done.
|
| namespace Ice { |
| -GlobalAddress::~GlobalAddress() { llvm::DeleteContainerPointers(Initializers); } |
| +IceString GlobalAddress::mangleName(GlobalContext *Ctx) const { |
| + return (getIsExternal() && !hasInitializer()) ? Name : Ctx->mangleName(Name); |
| +} |
| -void GlobalAddress::dumpType(Ostream &Stream) const { |
| +Function *Function::create(GlobalContext *Ctx, const FuncSigType &Signature, |
| + llvm::CallingConv::ID CallingConv, |
| + llvm::GlobalValue::LinkageTypes Linkage, |
| + bool IsProto) { |
| + return Ctx->newFunction(&Signature, CallingConv, Linkage, IsProto); |
| +} |
| + |
| +void Function::dumpType(Ostream &Stream) const { Stream << Signature; } |
| + |
| +void Function::dump(Ostream &Stream) const { |
| + if (IsProto) |
| + Stream << "declare "; |
| + ::dumpLinkage(Stream, Linkage); |
| + ::dumpCallingConv(Stream, CallingConv); |
| + Stream << Signature.getReturnType() << " @" << Name << "("; |
| + bool IsFirst = true; |
| + for (Type ArgTy : Signature.getArgList()) { |
| + if (IsFirst) |
| + IsFirst = false; |
| + else |
| + Stream << ", "; |
| + Stream << ArgTy; |
| + } |
| + Stream << ")"; |
| +} |
| + |
| +GlobalVariable *GlobalVariable::create(GlobalContext *Ctx) { |
| + return Ctx->newGlobalVariable(); |
| +} |
| + |
| +GlobalVariable::~GlobalVariable() { |
| + llvm::DeleteContainerPointers(Initializers); |
| +} |
| + |
| +void GlobalVariable::dumpType(Ostream &Stream) const { |
| if (Initializers.size() == 1) { |
| Initializers.front()->dumpType(Stream); |
| } else { |
| @@ -46,8 +110,8 @@ void GlobalAddress::dumpType(Ostream &Stream) const { |
| } |
| } |
| -void GlobalAddress::dump(Ostream &Stream) const { |
| - Stream << "@" << getName() << " = internal " |
| +void GlobalVariable::dump(Ostream &Stream) const { |
| + Stream << "@" << Name << " = internal " |
| << (IsConstant ? "constant" : "global") << " "; |
| // Add initializer. |
| @@ -74,11 +138,11 @@ void GlobalAddress::dump(Ostream &Stream) const { |
| Stream << "\n"; |
| } |
| -void GlobalAddress::Initializer::dumpType(Ostream &Stream) const { |
| +void GlobalVariable::Initializer::dumpType(Ostream &Stream) const { |
| Stream << "[" << getNumBytes() << " x " << Ice::IceType_i8 << "]"; |
| } |
| -void GlobalAddress::DataInitializer::dump(Ostream &Stream) const { |
| +void GlobalVariable::DataInitializer::dump(Ostream &Stream) const { |
| dumpType(Stream); |
| Stream << " c\""; |
| // Code taken from PrintEscapedString() in AsmWriter.cpp. Keep |
| @@ -93,41 +157,24 @@ void GlobalAddress::DataInitializer::dump(Ostream &Stream) const { |
| Stream << "\""; |
| } |
| -void GlobalAddress::ZeroInitializer::dump(Ostream &Stream) const { |
| +void GlobalVariable::ZeroInitializer::dump(Ostream &Stream) const { |
| dumpType(Stream); |
| Stream << " zeroinitializer"; |
| } |
| -IceString GlobalAddress::RelocInitializer::getName() const { |
| - switch (Address.getKind()) { |
| - case FunctionRelocation: |
| - return Address.getFunction()->getName(); |
| - case GlobalAddressRelocation: |
| - return Address.getGlobalAddr()->getName(); |
| - default: |
| - llvm::report_fatal_error("Malformed relocation address!"); |
| - } |
| -} |
| - |
| -void GlobalAddress::RelocInitializer::dumpType(Ostream &Stream) const { |
| +void GlobalVariable::RelocInitializer::dumpType(Ostream &Stream) const { |
| Stream << Ice::IceType_i32; |
| } |
| -void GlobalAddress::RelocInitializer::dump(Ostream &Stream) const { |
| +void GlobalVariable::RelocInitializer::dump(Ostream &Stream) const { |
| if (Offset != 0) { |
| dumpType(Stream); |
| Stream << " add ("; |
| } |
| dumpType(Stream); |
| Stream << " ptrtoint ("; |
| - if (Address.getKind() == FunctionRelocation) { |
| - Stream << *Address.getFunction()->getType() << " @" |
| - << Address.getFunction()->getName(); |
| - } else { |
| - Address.getGlobalAddr()->dumpType(Stream); |
| - Stream << "* @" << Address.getGlobalAddr()->getName(); |
| - } |
| - Stream << " to "; |
| + Address->dumpType(Stream); |
| + Stream << "* @" << Address->getName() << " to "; |
| dumpType(Stream); |
| Stream << ")"; |
| if (Offset != 0) { |