LTOModule.cpp: Fix numerous style issues.

llvm-svn: 110751
This commit is contained in:
Daniel Dunbar 2010-08-10 23:46:39 +00:00
parent e18c2d6f99
commit 5657e7b667
1 changed files with 416 additions and 439 deletions

View File

@ -36,20 +36,17 @@
using namespace llvm; using namespace llvm;
bool LTOModule::isBitcodeFile(const void* mem, size_t length) bool LTOModule::isBitcodeFile(const void *mem, size_t length) {
{
return llvm::sys::IdentifyFileType((char*)mem, length) return llvm::sys::IdentifyFileType((char*)mem, length)
== llvm::sys::Bitcode_FileType; == llvm::sys::Bitcode_FileType;
} }
bool LTOModule::isBitcodeFile(const char* path) bool LTOModule::isBitcodeFile(const char *path) {
{
return llvm::sys::Path(path).isBitcodeFile(); return llvm::sys::Path(path).isBitcodeFile();
} }
bool LTOModule::isBitcodeFileForTarget(const void *mem, size_t length, bool LTOModule::isBitcodeFileForTarget(const void *mem, size_t length,
const char* triplePrefix) const char *triplePrefix) {
{
MemoryBuffer *buffer = makeBuffer(mem, length); MemoryBuffer *buffer = makeBuffer(mem, length);
if (!buffer) if (!buffer)
return false; return false;
@ -58,19 +55,17 @@ bool LTOModule::isBitcodeFileForTarget(const void* mem, size_t length,
bool LTOModule::isBitcodeFileForTarget(const char *path, bool LTOModule::isBitcodeFileForTarget(const char *path,
const char* triplePrefix) const char *triplePrefix) {
{
MemoryBuffer *buffer = MemoryBuffer::getFile(path); MemoryBuffer *buffer = MemoryBuffer::getFile(path);
if (buffer == NULL) if (buffer == NULL)
return false; return false;
return isTargetMatch(buffer, triplePrefix); return isTargetMatch(buffer, triplePrefix);
} }
// takes ownership of buffer // Takes ownership of buffer.
bool LTOModule::isTargetMatch(MemoryBuffer* buffer, const char* triplePrefix) bool LTOModule::isTargetMatch(MemoryBuffer *buffer, const char *triplePrefix) {
{
OwningPtr<Module> m(getLazyBitcodeModule(buffer, getGlobalContext())); OwningPtr<Module> m(getLazyBitcodeModule(buffer, getGlobalContext()));
// on success, m owns buffer and both are deleted at end of this method // On success, m owns buffer and both are deleted at end of this method.
if (!m) { if (!m) {
delete buffer; delete buffer;
return false; return false;
@ -87,20 +82,18 @@ LTOModule::LTOModule(Module* m, TargetMachine* t)
} }
LTOModule *LTOModule::makeLTOModule(const char *path, LTOModule *LTOModule::makeLTOModule(const char *path,
std::string& errMsg) std::string &errMsg) {
{
OwningPtr<MemoryBuffer> buffer(MemoryBuffer::getFile(path, &errMsg)); OwningPtr<MemoryBuffer> buffer(MemoryBuffer::getFile(path, &errMsg));
if (!buffer) if (!buffer)
return NULL; return NULL;
return makeLTOModule(buffer.get(), errMsg); return makeLTOModule(buffer.get(), errMsg);
} }
/// makeBuffer - create a MemoryBuffer from a memory range. /// makeBuffer - Create a MemoryBuffer from a memory range. MemoryBuffer
/// MemoryBuffer requires the byte past end of the buffer to be a zero. /// requires the byte past end of the buffer to be a zero. We might get lucky
/// We might get lucky and already be that way, otherwise make a copy. /// and already be that way, otherwise make a copy. Also if next byte is on a
/// Also if next byte is on a different page, don't assume it is readable. /// different page, don't assume it is readable.
MemoryBuffer* LTOModule::makeBuffer(const void* mem, size_t length) MemoryBuffer *LTOModule::makeBuffer(const void *mem, size_t length) {
{
const char *startPtr = (char*)mem; const char *startPtr = (char*)mem;
const char *endPtr = startPtr+length; const char *endPtr = startPtr+length;
if (((uintptr_t)endPtr & (sys::Process::GetPageSize()-1)) == 0 || if (((uintptr_t)endPtr & (sys::Process::GetPageSize()-1)) == 0 ||
@ -112,8 +105,7 @@ MemoryBuffer* LTOModule::makeBuffer(const void* mem, size_t length)
LTOModule *LTOModule::makeLTOModule(const void *mem, size_t length, LTOModule *LTOModule::makeLTOModule(const void *mem, size_t length,
std::string& errMsg) std::string &errMsg) {
{
OwningPtr<MemoryBuffer> buffer(makeBuffer(mem, length)); OwningPtr<MemoryBuffer> buffer(makeBuffer(mem, length));
if (!buffer) if (!buffer)
return NULL; return NULL;
@ -121,8 +113,7 @@ LTOModule* LTOModule::makeLTOModule(const void* mem, size_t length,
} }
LTOModule *LTOModule::makeLTOModule(MemoryBuffer *buffer, LTOModule *LTOModule::makeLTOModule(MemoryBuffer *buffer,
std::string& errMsg) std::string &errMsg) {
{
InitializeAllTargets(); InitializeAllTargets();
// parse bitcode buffer // parse bitcode buffer
@ -148,18 +139,15 @@ LTOModule* LTOModule::makeLTOModule(MemoryBuffer* buffer,
} }
const char* LTOModule::getTargetTriple() const char *LTOModule::getTargetTriple() {
{
return _module->getTargetTriple().c_str(); return _module->getTargetTriple().c_str();
} }
void LTOModule::setTargetTriple(const char *triple) void LTOModule::setTargetTriple(const char *triple) {
{
_module->setTargetTriple(triple); _module->setTargetTriple(triple);
} }
void LTOModule::addDefinedFunctionSymbol(Function* f, Mangler &mangler) void LTOModule::addDefinedFunctionSymbol(Function *f, Mangler &mangler) {
{
// add to list of defined symbols // add to list of defined symbols
addDefinedSymbol(f, mangler, true); addDefinedSymbol(f, mangler, true);
@ -174,9 +162,8 @@ void LTOModule::addDefinedFunctionSymbol(Function* f, Mangler &mangler)
} }
} }
// get string that data pointer points to // Get string that data pointer points to.
bool LTOModule::objcClassNameFromExpression(Constant* c, std::string& name) bool LTOModule::objcClassNameFromExpression(Constant *c, std::string &name) {
{
if (ConstantExpr *ce = dyn_cast<ConstantExpr>(c)) { if (ConstantExpr *ce = dyn_cast<ConstantExpr>(c)) {
Constant *op = ce->getOperand(0); Constant *op = ce->getOperand(0);
if (GlobalVariable *gvn = dyn_cast<GlobalVariable>(op)) { if (GlobalVariable *gvn = dyn_cast<GlobalVariable>(op)) {
@ -192,9 +179,8 @@ bool LTOModule::objcClassNameFromExpression(Constant* c, std::string& name)
return false; return false;
} }
// parse i386/ppc ObjC class data structure // Parse i386/ppc ObjC class data structure.
void LTOModule::addObjCClass(GlobalVariable* clgv) void LTOModule::addObjCClass(GlobalVariable *clgv) {
{
if (ConstantStruct *c = dyn_cast<ConstantStruct>(clgv->getInitializer())) { if (ConstantStruct *c = dyn_cast<ConstantStruct>(clgv->getInitializer())) {
// second slot in __OBJC,__class is pointer to superclass name // second slot in __OBJC,__class is pointer to superclass name
std::string superclassName; std::string superclassName;
@ -225,9 +211,8 @@ void LTOModule::addObjCClass(GlobalVariable* clgv)
} }
// parse i386/ppc ObjC category data structure // Parse i386/ppc ObjC category data structure.
void LTOModule::addObjCCategory(GlobalVariable* clgv) void LTOModule::addObjCCategory(GlobalVariable *clgv) {
{
if (ConstantStruct *c = dyn_cast<ConstantStruct>(clgv->getInitializer())) { if (ConstantStruct *c = dyn_cast<ConstantStruct>(clgv->getInitializer())) {
// second slot in __OBJC,__category is pointer to target class name // second slot in __OBJC,__category is pointer to target class name
std::string targetclassName; std::string targetclassName;
@ -245,9 +230,8 @@ void LTOModule::addObjCCategory(GlobalVariable* clgv)
} }
// parse i386/ppc ObjC class list data structure // Parse i386/ppc ObjC class list data structure.
void LTOModule::addObjCClassRef(GlobalVariable* clgv) void LTOModule::addObjCClassRef(GlobalVariable *clgv) {
{
std::string targetclassName; std::string targetclassName;
if (objcClassNameFromExpression(clgv->getInitializer(), targetclassName)) { if (objcClassNameFromExpression(clgv->getInitializer(), targetclassName)) {
NameAndAttributes info; NameAndAttributes info;
@ -262,9 +246,8 @@ void LTOModule::addObjCClassRef(GlobalVariable* clgv)
} }
void LTOModule::addDefinedDataSymbol(GlobalValue* v, Mangler& mangler) void LTOModule::addDefinedDataSymbol(GlobalValue *v, Mangler &mangler) {
{ // Add to list of defined symbols.
// add to list of defined symbols
addDefinedSymbol(v, mangler, false); addDefinedSymbol(v, mangler, false);
// Special case i386/ppc ObjC data structures in magic sections: // Special case i386/ppc ObjC data structures in magic sections:
@ -318,8 +301,7 @@ void LTOModule::addDefinedDataSymbol(GlobalValue* v, Mangler& mangler)
void LTOModule::addDefinedSymbol(GlobalValue *def, Mangler &mangler, void LTOModule::addDefinedSymbol(GlobalValue *def, Mangler &mangler,
bool isFunction) bool isFunction) {
{
// ignore all llvm.* symbols // ignore all llvm.* symbols
if (def->getName().startswith("llvm.")) if (def->getName().startswith("llvm."))
return; return;
@ -388,8 +370,8 @@ void LTOModule::addAsmGlobalSymbol(const char *name) {
_defines[info.name] = 1; _defines[info.name] = 1;
} }
void LTOModule::addPotentialUndefinedSymbol(GlobalValue* decl, Mangler &mangler) void LTOModule::addPotentialUndefinedSymbol(GlobalValue *decl,
{ Mangler &mangler) {
// ignore all llvm.* symbols // ignore all llvm.* symbols
if (decl->getName().startswith("llvm.")) if (decl->getName().startswith("llvm."))
return; return;
@ -418,7 +400,6 @@ void LTOModule::addPotentialUndefinedSymbol(GlobalValue* decl, Mangler &mangler)
// Find external symbols referenced by VALUE. This is a recursive function. // Find external symbols referenced by VALUE. This is a recursive function.
void LTOModule::findExternalRefs(Value *value, Mangler &mangler) { void LTOModule::findExternalRefs(Value *value, Mangler &mangler) {
if (GlobalValue *gv = dyn_cast<GlobalValue>(value)) { if (GlobalValue *gv = dyn_cast<GlobalValue>(value)) {
if (!gv->hasExternalLinkage()) if (!gv->hasExternalLinkage())
addPotentialUndefinedSymbol(gv, mangler); addPotentialUndefinedSymbol(gv, mangler);
@ -438,8 +419,7 @@ void LTOModule::findExternalRefs(Value* value, Mangler &mangler) {
} }
} }
void LTOModule::lazyParseSymbols() void LTOModule::lazyParseSymbols() {
{
if (!_symbolsParsed) { if (!_symbolsParsed) {
_symbolsParsed = true; _symbolsParsed = true;
@ -504,15 +484,13 @@ void LTOModule::lazyParseSymbols()
} }
uint32_t LTOModule::getSymbolCount() uint32_t LTOModule::getSymbolCount() {
{
lazyParseSymbols(); lazyParseSymbols();
return _symbols.size(); return _symbols.size();
} }
lto_symbol_attributes LTOModule::getSymbolAttributes(uint32_t index) lto_symbol_attributes LTOModule::getSymbolAttributes(uint32_t index) {
{
lazyParseSymbols(); lazyParseSymbols();
if (index < _symbols.size()) if (index < _symbols.size())
return _symbols[index].attributes; return _symbols[index].attributes;
@ -520,8 +498,7 @@ lto_symbol_attributes LTOModule::getSymbolAttributes(uint32_t index)
return lto_symbol_attributes(0); return lto_symbol_attributes(0);
} }
const char* LTOModule::getSymbolName(uint32_t index) const char *LTOModule::getSymbolName(uint32_t index) {
{
lazyParseSymbols(); lazyParseSymbols();
if (index < _symbols.size()) if (index < _symbols.size())
return _symbols[index].name; return _symbols[index].name;