LTOModule.cpp: Fix numerous style issues.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@110751 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Daniel Dunbar
2010-08-10 23:46:39 +00:00
parent af08a36bd6
commit b06913dd18

View File

@@ -36,41 +36,36 @@
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)
== llvm::sys::Bitcode_FileType;
}
bool LTOModule::isBitcodeFile(const char* path)
{
bool LTOModule::isBitcodeFile(const char *path) {
return llvm::sys::Path(path).isBitcodeFile();
}
bool LTOModule::isBitcodeFileForTarget(const void* mem, size_t length,
const char* triplePrefix)
{
MemoryBuffer* buffer = makeBuffer(mem, length);
bool LTOModule::isBitcodeFileForTarget(const void *mem, size_t length,
const char *triplePrefix) {
MemoryBuffer *buffer = makeBuffer(mem, length);
if (!buffer)
return false;
return isTargetMatch(buffer, triplePrefix);
}
bool LTOModule::isBitcodeFileForTarget(const char* path,
const char* triplePrefix)
{
bool LTOModule::isBitcodeFileForTarget(const char *path,
const char *triplePrefix) {
MemoryBuffer *buffer = MemoryBuffer::getFile(path);
if (buffer == NULL)
return false;
return isTargetMatch(buffer, triplePrefix);
}
// takes ownership of buffer
bool LTOModule::isTargetMatch(MemoryBuffer* buffer, const char* triplePrefix)
{
// Takes ownership of buffer.
bool LTOModule::isTargetMatch(MemoryBuffer *buffer, const char *triplePrefix) {
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) {
delete buffer;
return false;
@@ -81,26 +76,24 @@ bool LTOModule::isTargetMatch(MemoryBuffer* buffer, const char* triplePrefix)
}
LTOModule::LTOModule(Module* m, TargetMachine* t)
LTOModule::LTOModule(Module *m, TargetMachine *t)
: _module(m), _target(t), _symbolsParsed(false)
{
}
LTOModule* LTOModule::makeLTOModule(const char* path,
std::string& errMsg)
{
LTOModule *LTOModule::makeLTOModule(const char *path,
std::string &errMsg) {
OwningPtr<MemoryBuffer> buffer(MemoryBuffer::getFile(path, &errMsg));
if (!buffer)
return NULL;
return makeLTOModule(buffer.get(), errMsg);
}
/// makeBuffer - create a MemoryBuffer from a memory range.
/// MemoryBuffer requires the byte past end of the buffer to be a zero.
/// We might get lucky and already be that way, otherwise make a copy.
/// Also if next byte is on a different page, don't assume it is readable.
MemoryBuffer* LTOModule::makeBuffer(const void* mem, size_t length)
{
/// makeBuffer - Create a MemoryBuffer from a memory range. MemoryBuffer
/// requires the byte past end of the buffer to be a zero. We might get lucky
/// and already be that way, otherwise make a copy. Also if next byte is on a
/// different page, don't assume it is readable.
MemoryBuffer *LTOModule::makeBuffer(const void *mem, size_t length) {
const char *startPtr = (char*)mem;
const char *endPtr = startPtr+length;
if (((uintptr_t)endPtr & (sys::Process::GetPageSize()-1)) == 0 ||
@@ -111,18 +104,16 @@ MemoryBuffer* LTOModule::makeBuffer(const void* mem, size_t length)
}
LTOModule* LTOModule::makeLTOModule(const void* mem, size_t length,
std::string& errMsg)
{
LTOModule *LTOModule::makeLTOModule(const void *mem, size_t length,
std::string &errMsg) {
OwningPtr<MemoryBuffer> buffer(makeBuffer(mem, length));
if (!buffer)
return NULL;
return makeLTOModule(buffer.get(), errMsg);
}
LTOModule* LTOModule::makeLTOModule(MemoryBuffer* buffer,
std::string& errMsg)
{
LTOModule *LTOModule::makeLTOModule(MemoryBuffer *buffer,
std::string &errMsg) {
InitializeAllTargets();
// parse bitcode buffer
@@ -135,7 +126,7 @@ LTOModule* LTOModule::makeLTOModule(MemoryBuffer* buffer,
Triple = sys::getHostTriple();
// find machine architecture for this module
const Target* march = TargetRegistry::lookupTarget(Triple, errMsg);
const Target *march = TargetRegistry::lookupTarget(Triple, errMsg);
if (!march)
return NULL;
@@ -143,23 +134,20 @@ LTOModule* LTOModule::makeLTOModule(MemoryBuffer* buffer,
SubtargetFeatures Features;
Features.getDefaultSubtargetFeatures("" /* cpu */, llvm::Triple(Triple));
std::string FeatureStr = Features.getString();
TargetMachine* target = march->createTargetMachine(Triple, FeatureStr);
TargetMachine *target = march->createTargetMachine(Triple, FeatureStr);
return new LTOModule(m.take(), target);
}
const char* LTOModule::getTargetTriple()
{
const char *LTOModule::getTargetTriple() {
return _module->getTargetTriple().c_str();
}
void LTOModule::setTargetTriple(const char *triple)
{
void LTOModule::setTargetTriple(const char *triple) {
_module->setTargetTriple(triple);
}
void LTOModule::addDefinedFunctionSymbol(Function* f, Mangler &mangler)
{
void LTOModule::addDefinedFunctionSymbol(Function *f, Mangler &mangler) {
// add to list of defined symbols
addDefinedSymbol(f, mangler, true);
@@ -174,14 +162,13 @@ void LTOModule::addDefinedFunctionSymbol(Function* f, Mangler &mangler)
}
}
// get string that data pointer points to
bool LTOModule::objcClassNameFromExpression(Constant* c, std::string& name)
{
if (ConstantExpr* ce = dyn_cast<ConstantExpr>(c)) {
Constant* op = ce->getOperand(0);
if (GlobalVariable* gvn = dyn_cast<GlobalVariable>(op)) {
Constant* cn = gvn->getInitializer();
if (ConstantArray* ca = dyn_cast<ConstantArray>(cn)) {
// Get string that data pointer points to.
bool LTOModule::objcClassNameFromExpression(Constant *c, std::string &name) {
if (ConstantExpr *ce = dyn_cast<ConstantExpr>(c)) {
Constant *op = ce->getOperand(0);
if (GlobalVariable *gvn = dyn_cast<GlobalVariable>(op)) {
Constant *cn = gvn->getInitializer();
if (ConstantArray *ca = dyn_cast<ConstantArray>(cn)) {
if (ca->isCString()) {
name = ".objc_class_name_" + ca->getAsString();
return true;
@@ -192,16 +179,15 @@ bool LTOModule::objcClassNameFromExpression(Constant* c, std::string& name)
return false;
}
// parse i386/ppc ObjC class data structure
void LTOModule::addObjCClass(GlobalVariable* clgv)
{
if (ConstantStruct* c = dyn_cast<ConstantStruct>(clgv->getInitializer())) {
// Parse i386/ppc ObjC class data structure.
void LTOModule::addObjCClass(GlobalVariable *clgv) {
if (ConstantStruct *c = dyn_cast<ConstantStruct>(clgv->getInitializer())) {
// second slot in __OBJC,__class is pointer to superclass name
std::string superclassName;
if (objcClassNameFromExpression(c->getOperand(1), superclassName)) {
NameAndAttributes info;
if (_undefines.find(superclassName.c_str()) == _undefines.end()) {
const char* symbolName = ::strdup(superclassName.c_str());
const char *symbolName = ::strdup(superclassName.c_str());
info.name = ::strdup(symbolName);
info.attributes = LTO_SYMBOL_DEFINITION_UNDEFINED;
// string is owned by _undefines
@@ -211,7 +197,7 @@ void LTOModule::addObjCClass(GlobalVariable* clgv)
// third slot in __OBJC,__class is pointer to class name
std::string className;
if (objcClassNameFromExpression(c->getOperand(2), className)) {
const char* symbolName = ::strdup(className.c_str());
const char *symbolName = ::strdup(className.c_str());
NameAndAttributes info;
info.name = symbolName;
info.attributes = (lto_symbol_attributes)
@@ -225,16 +211,15 @@ void LTOModule::addObjCClass(GlobalVariable* clgv)
}
// parse i386/ppc ObjC category data structure
void LTOModule::addObjCCategory(GlobalVariable* clgv)
{
if (ConstantStruct* c = dyn_cast<ConstantStruct>(clgv->getInitializer())) {
// Parse i386/ppc ObjC category data structure.
void LTOModule::addObjCCategory(GlobalVariable *clgv) {
if (ConstantStruct *c = dyn_cast<ConstantStruct>(clgv->getInitializer())) {
// second slot in __OBJC,__category is pointer to target class name
std::string targetclassName;
if (objcClassNameFromExpression(c->getOperand(1), targetclassName)) {
NameAndAttributes info;
if (_undefines.find(targetclassName.c_str()) == _undefines.end()) {
const char* symbolName = ::strdup(targetclassName.c_str());
const char *symbolName = ::strdup(targetclassName.c_str());
info.name = ::strdup(symbolName);
info.attributes = LTO_SYMBOL_DEFINITION_UNDEFINED;
// string is owned by _undefines
@@ -245,14 +230,13 @@ void LTOModule::addObjCCategory(GlobalVariable* clgv)
}
// parse i386/ppc ObjC class list data structure
void LTOModule::addObjCClassRef(GlobalVariable* clgv)
{
// Parse i386/ppc ObjC class list data structure.
void LTOModule::addObjCClassRef(GlobalVariable *clgv) {
std::string targetclassName;
if (objcClassNameFromExpression(clgv->getInitializer(), targetclassName)) {
NameAndAttributes info;
if (_undefines.find(targetclassName.c_str()) == _undefines.end()) {
const char* symbolName = ::strdup(targetclassName.c_str());
const char *symbolName = ::strdup(targetclassName.c_str());
info.name = ::strdup(symbolName);
info.attributes = LTO_SYMBOL_DEFINITION_UNDEFINED;
// string is owned by _undefines
@@ -262,9 +246,8 @@ void LTOModule::addObjCClassRef(GlobalVariable* clgv)
}
void LTOModule::addDefinedDataSymbol(GlobalValue* v, Mangler& mangler)
{
// add to list of defined symbols
void LTOModule::addDefinedDataSymbol(GlobalValue *v, Mangler &mangler) {
// Add to list of defined symbols.
addDefinedSymbol(v, mangler, false);
// Special case i386/ppc ObjC data structures in magic sections:
@@ -289,21 +272,21 @@ void LTOModule::addDefinedDataSymbol(GlobalValue* v, Mangler& mangler)
if (v->hasSection() /* && isTargetDarwin */) {
// special case if this data blob is an ObjC class definition
if (v->getSection().compare(0, 15, "__OBJC,__class,") == 0) {
if (GlobalVariable* gv = dyn_cast<GlobalVariable>(v)) {
if (GlobalVariable *gv = dyn_cast<GlobalVariable>(v)) {
addObjCClass(gv);
}
}
// special case if this data blob is an ObjC category definition
else if (v->getSection().compare(0, 18, "__OBJC,__category,") == 0) {
if (GlobalVariable* gv = dyn_cast<GlobalVariable>(v)) {
if (GlobalVariable *gv = dyn_cast<GlobalVariable>(v)) {
addObjCCategory(gv);
}
}
// special case if this data blob is the list of referenced classes
else if (v->getSection().compare(0, 18, "__OBJC,__cls_refs,") == 0) {
if (GlobalVariable* gv = dyn_cast<GlobalVariable>(v)) {
if (GlobalVariable *gv = dyn_cast<GlobalVariable>(v)) {
addObjCClassRef(gv);
}
}
@@ -317,15 +300,14 @@ void LTOModule::addDefinedDataSymbol(GlobalValue* v, Mangler& mangler)
}
void LTOModule::addDefinedSymbol(GlobalValue* def, Mangler &mangler,
bool isFunction)
{
void LTOModule::addDefinedSymbol(GlobalValue *def, Mangler &mangler,
bool isFunction) {
// ignore all llvm.* symbols
if (def->getName().startswith("llvm."))
return;
// string is owned by _defines
const char* symbolName = ::strdup(mangler.getNameWithPrefix(def).c_str());
const char *symbolName = ::strdup(mangler.getNameWithPrefix(def).c_str());
// set alignment part log2() can have rounding errors
uint32_t align = def->getAlignment();
@@ -335,7 +317,7 @@ void LTOModule::addDefinedSymbol(GlobalValue* def, Mangler &mangler,
if (isFunction)
attr |= LTO_SYMBOL_PERMISSIONS_CODE;
else {
GlobalVariable* gv = dyn_cast<GlobalVariable>(def);
GlobalVariable *gv = dyn_cast<GlobalVariable>(def);
if (gv && gv->isConstant())
attr |= LTO_SYMBOL_PERMISSIONS_RODATA;
else
@@ -388,8 +370,8 @@ void LTOModule::addAsmGlobalSymbol(const char *name) {
_defines[info.name] = 1;
}
void LTOModule::addPotentialUndefinedSymbol(GlobalValue* decl, Mangler &mangler)
{
void LTOModule::addPotentialUndefinedSymbol(GlobalValue *decl,
Mangler &mangler) {
// ignore all llvm.* symbols
if (decl->getName().startswith("llvm."))
return;
@@ -417,9 +399,8 @@ void LTOModule::addPotentialUndefinedSymbol(GlobalValue* decl, Mangler &mangler)
// Find external symbols referenced by VALUE. This is a recursive function.
void LTOModule::findExternalRefs(Value* value, Mangler &mangler) {
if (GlobalValue* gv = dyn_cast<GlobalValue>(value)) {
void LTOModule::findExternalRefs(Value *value, Mangler &mangler) {
if (GlobalValue *gv = dyn_cast<GlobalValue>(value)) {
if (!gv->hasExternalLinkage())
addPotentialUndefinedSymbol(gv, mangler);
// If this is a variable definition, do not recursively process
@@ -431,15 +412,14 @@ void LTOModule::findExternalRefs(Value* value, Mangler &mangler) {
// GlobalValue, even with InternalLinkage type, may have operands with
// ExternalLinkage type. Do not ignore these operands.
if (Constant* c = dyn_cast<Constant>(value)) {
if (Constant *c = dyn_cast<Constant>(value)) {
// Handle ConstantExpr, ConstantStruct, ConstantArry etc.
for (unsigned i = 0, e = c->getNumOperands(); i != e; ++i)
findExternalRefs(c->getOperand(i), mangler);
}
}
void LTOModule::lazyParseSymbols()
{
void LTOModule::lazyParseSymbols() {
if (!_symbolsParsed) {
_symbolsParsed = true;
@@ -504,15 +484,13 @@ void LTOModule::lazyParseSymbols()
}
uint32_t LTOModule::getSymbolCount()
{
uint32_t LTOModule::getSymbolCount() {
lazyParseSymbols();
return _symbols.size();
}
lto_symbol_attributes LTOModule::getSymbolAttributes(uint32_t index)
{
lto_symbol_attributes LTOModule::getSymbolAttributes(uint32_t index) {
lazyParseSymbols();
if (index < _symbols.size())
return _symbols[index].attributes;
@@ -520,8 +498,7 @@ lto_symbol_attributes LTOModule::getSymbolAttributes(uint32_t index)
return lto_symbol_attributes(0);
}
const char* LTOModule::getSymbolName(uint32_t index)
{
const char *LTOModule::getSymbolName(uint32_t index) {
lazyParseSymbols();
if (index < _symbols.size())
return _symbols[index].name;