llvm.org GIT mirror llvm / 3bb1738
Cleanup some whitespaces. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153612 91177308-0d34-0410-b5e6-96231b3b80d8 Bill Wendling 7 years ago
2 changed file(s) with 119 addition(s) and 123 deletion(s). Raw diff Collapse all Expand all
157157 TargetMachine *target = march->createTargetMachine(Triple, CPU, FeatureStr,
158158 Options);
159159 LTOModule *Ret = new LTOModule(m.take(), target);
160 if (Ret->ParseSymbols(errMsg)) {
160 if (Ret->parseSymbols(errMsg)) {
161161 delete Ret;
162162 return NULL;
163163 }
661661 return V.isDeclaration();
662662 }
663663
664 /// ParseSymbols - Parse the symbols from the module and model-level ASM and add
664 /// parseSymbols - Parse the symbols from the module and model-level ASM and add
665665 /// them to either the defined or undefined lists.
666 bool LTOModule::ParseSymbols(std::string &errMsg) {
666 bool LTOModule::parseSymbols(std::string &errMsg) {
667667 // add functions
668668 for (Module::iterator f = _module->begin(); f != _module->end(); ++f) {
669669 if (isDeclaration(*f))
2626 #include
2727
2828
29 // forward references to llvm classes
29 // Forward references to llvm classes.
3030 namespace llvm {
3131 class Function;
3232 class GlobalValue;
3535 }
3636
3737 //
38 // C++ class which implements the opaque lto_module_t
38 // C++ class which implements the opaque lto_module_t type.
3939 //
4040 struct LTOModule {
4141 private:
42 typedef llvm::StringMap StringSet;
42 typedef llvm::StringMap StringSet;
4343
44 struct NameAndAttributes {
45 enum name_type { IsFunction, IsData };
46 const char* name;
47 lto_symbol_attributes attributes;
48 };
44 struct NameAndAttributes {
45 enum name_type { IsFunction, IsData };
46 const char* name;
47 lto_symbol_attributes attributes;
48 };
4949
50 llvm::OwningPtr _module;
51 llvm::OwningPtr _target;
52 std::vector _symbols;
50 llvm::OwningPtr _module;
51 llvm::OwningPtr _target;
52 std::vector _symbols;
5353
54 // _defines and _undefines only needed to disambiguate tentative definitions
55 StringSet _defines;
56 llvm::StringMap _undefines;
57 std::vector _asm_undefines;
58 llvm::MCContext _context;
54 // _defines and _undefines only needed to disambiguate tentative definitions
55 StringSet _defines;
56 llvm::StringMap _undefines;
57 std::vector _asm_undefines;
58 llvm::MCContext _context;
5959
60 // Use mangler to add GlobalPrefix to names to match linker names.
61 llvm::Mangler _mangler;
60 // Use mangler to add GlobalPrefix to names to match linker names.
61 llvm::Mangler _mangler;
6262
63 LTOModule(llvm::Module *m, llvm::TargetMachine *t);
63 LTOModule(llvm::Module *m, llvm::TargetMachine *t);
6464 public:
65 /// isBitcodeFile - Returns 'true' if the file or memory contents is LLVM
66 /// bitcode.
67 static bool isBitcodeFile(const void *mem, size_t length);
68 static bool isBitcodeFile(const char *path);
65 /// isBitcodeFile - Returns 'true' if the file or memory contents is LLVM
66 /// bitcode.
67 static bool isBitcodeFile(const void *mem, size_t length);
68 static bool isBitcodeFile(const char *path);
6969
70 /// isBitcodeFileForTarget - Returns 'true' if the file or memory contents
71 /// is LLVM bitcode for the specified triple.
72 static bool isBitcodeFileForTarget(const void *mem,
73 size_t length,
74 const char *triplePrefix);
75 static bool isBitcodeFileForTarget(const char *path,
76 const char *triplePrefix);
70 /// isBitcodeFileForTarget - Returns 'true' if the file or memory contents
71 /// is LLVM bitcode for the specified triple.
72 static bool isBitcodeFileForTarget(const void *mem,
73 size_t length,
74 const char *triplePrefix);
75 static bool isBitcodeFileForTarget(const char *path,
76 const char *triplePrefix);
7777
78 /// makeLTOModule - Create an LTOModule. N.B. These methods take ownership
79 /// of the buffer.
80 static LTOModule* makeLTOModule(const char* path,
81 std::string &errMsg);
82 static LTOModule* makeLTOModule(int fd, const char *path,
83 size_t size,
84 std::string &errMsg);
85 static LTOModule* makeLTOModule(int fd, const char *path,
86 size_t file_size,
87 size_t map_size,
88 off_t offset,
89 std::string& errMsg);
90 static LTOModule* makeLTOModule(const void *mem, size_t length,
91 std::string &errMsg);
78 /// makeLTOModule - Create an LTOModule. N.B. These methods take ownership
79 /// of the buffer.
80 static LTOModule *makeLTOModule(const char* path,
81 std::string &errMsg);
82 static LTOModule *makeLTOModule(int fd, const char *path,
83 size_t size, std::string &errMsg);
84 static LTOModule *makeLTOModule(int fd, const char *path,
85 size_t file_size,
86 size_t map_size,
87 off_t offset,
88 std::string& errMsg);
89 static LTOModule *makeLTOModule(const void *mem, size_t length,
90 std::string &errMsg);
9291
93 /// getTargetTriple - Return the Module's target triple.
94 const char* getTargetTriple() {
95 return _module->getTargetTriple().c_str();
96 }
92 /// getTargetTriple - Return the Module's target triple.
93 const char *getTargetTriple() {
94 return _module->getTargetTriple().c_str();
95 }
9796
98 /// setTargetTriple - Set the Module's target triple.
99 void setTargetTriple(const char *triple) {
100 _module->setTargetTriple(triple);
101 }
97 /// setTargetTriple - Set the Module's target triple.
98 void setTargetTriple(const char *triple) {
99 _module->setTargetTriple(triple);
100 }
102101
103 /// getSymbolCount - Get the number of symbols
104 uint32_t getSymbolCount() {
105 return _symbols.size();
106 }
102 /// getSymbolCount - Get the number of symbols
103 uint32_t getSymbolCount() {
104 return _symbols.size();
105 }
107106
108 /// getSymbolAttributes - Get the attributes for a symbol at the specified
109 /// index.
110 lto_symbol_attributes getSymbolAttributes(uint32_t index) {
111 if (index < _symbols.size())
112 return _symbols[index].attributes;
113 else
114 return lto_symbol_attributes(0);
115 }
107 /// getSymbolAttributes - Get the attributes for a symbol at the specified
108 /// index.
109 lto_symbol_attributes getSymbolAttributes(uint32_t index) {
110 if (index < _symbols.size())
111 return _symbols[index].attributes;
112 else
113 return lto_symbol_attributes(0);
114 }
116115
117 /// getSymbolName - Get the name of the symbol at the specified index.
118 const char* getSymbolName(uint32_t index) {
119 if (index < _symbols.size())
120 return _symbols[index].name;
121 else
122 return NULL;
123 }
116 /// getSymbolName - Get the name of the symbol at the specified index.
117 const char *getSymbolName(uint32_t index) {
118 if (index < _symbols.size())
119 return _symbols[index].name;
120 else
121 return NULL;
122 }
124123
125 /// getLLVVMModule - Return the Module.
126 llvm::Module * getLLVVMModule() { return _module.get(); }
124 /// getLLVVMModule - Return the Module.
125 llvm::Module *getLLVVMModule() { return _module.get(); }
127126
128 /// getAsmUndefinedRefs -
129 const std::vector &getAsmUndefinedRefs() {
130 return _asm_undefines;
131 }
127 /// getAsmUndefinedRefs -
128 const std::vector &getAsmUndefinedRefs() {
129 return _asm_undefines;
130 }
132131
133132 private:
134 /// ParseSymbols - Parse the symbols from the module and model-level ASM and
135 /// add them to either the defined or undefined lists.
136 bool ParseSymbols(std::string &errMsg);
133 /// parseSymbols - Parse the symbols from the module and model-level ASM and
134 /// add them to either the defined or undefined lists.
135 bool parseSymbols(std::string &errMsg);
137136
138 /// addPotentialUndefinedSymbol - Add a symbol which isn't defined just yet
139 /// to a list to be resolved later.
140 void addPotentialUndefinedSymbol(llvm::GlobalValue *dcl);
137 /// addPotentialUndefinedSymbol - Add a symbol which isn't defined just yet
138 /// to a list to be resolved later.
139 void addPotentialUndefinedSymbol(llvm::GlobalValue *dcl);
141140
142 /// addDefinedSymbol - Add a defined symbol to the list.
143 void addDefinedSymbol(llvm::GlobalValue *def,
144 bool isFunction);
141 /// addDefinedSymbol - Add a defined symbol to the list.
142 void addDefinedSymbol(llvm::GlobalValue *def, bool isFunction);
145143
146 /// addDefinedFunctionSymbol - Add a function symbol as defined to the list.
147 void addDefinedFunctionSymbol(llvm::Function *f);
144 /// addDefinedFunctionSymbol - Add a function symbol as defined to the list.
145 void addDefinedFunctionSymbol(llvm::Function *f);
148146
149 /// addDefinedDataSymbol - Add a data symbol as defined to the list.
150 void addDefinedDataSymbol(llvm::GlobalValue *v);
147 /// addDefinedDataSymbol - Add a data symbol as defined to the list.
148 void addDefinedDataSymbol(llvm::GlobalValue *v);
151149
152 /// addAsmGlobalSymbols - Add global symbols from module-level ASM to the
153 /// defined or undefined lists.
154 bool addAsmGlobalSymbols(std::string &errMsg);
150 /// addAsmGlobalSymbols - Add global symbols from module-level ASM to the
151 /// defined or undefined lists.
152 bool addAsmGlobalSymbols(std::string &errMsg);
155153
156 /// addAsmGlobalSymbol - Add a global symbol from module-level ASM to the
157 /// defined list.
158 void addAsmGlobalSymbol(const char *,
159 lto_symbol_attributes scope);
154 /// addAsmGlobalSymbol - Add a global symbol from module-level ASM to the
155 /// defined list.
156 void addAsmGlobalSymbol(const char *, lto_symbol_attributes scope);
160157
161 /// addAsmGlobalSymbolUndef - Add a global symbol from module-level ASM to
162 /// the undefined list.
163 void addAsmGlobalSymbolUndef(const char *);
158 /// addAsmGlobalSymbolUndef - Add a global symbol from module-level ASM to
159 /// the undefined list.
160 void addAsmGlobalSymbolUndef(const char *);
164161
165 /// addObjCClass - Parse i386/ppc ObjC class data structure.
166 void addObjCClass(llvm::GlobalVariable *clgv);
162 /// addObjCClass - Parse i386/ppc ObjC class data structure.
163 void addObjCClass(llvm::GlobalVariable *clgv);
167164
168 /// addObjCCategory - Parse i386/ppc ObjC category data structure.
169 void addObjCCategory(llvm::GlobalVariable *clgv);
165 /// addObjCCategory - Parse i386/ppc ObjC category data structure.
166 void addObjCCategory(llvm::GlobalVariable *clgv);
170167
171 /// addObjCClassRef - Parse i386/ppc ObjC class list data structure.
172 void addObjCClassRef(llvm::GlobalVariable *clgv);
168 /// addObjCClassRef - Parse i386/ppc ObjC class list data structure.
169 void addObjCClassRef(llvm::GlobalVariable *clgv);
173170
174 /// objcClassNameFromExpression - Get string that the data pointer points
175 /// to.
176 bool objcClassNameFromExpression(llvm::Constant* c,
177 std::string &name);
171 /// objcClassNameFromExpression - Get string that the data pointer points
172 /// to.
173 bool objcClassNameFromExpression(llvm::Constant* c, std::string &name);
178174
179 /// isTargetMatch - Returns 'true' if the memory buffer is for the specified
180 /// target triple.
181 static bool isTargetMatch(llvm::MemoryBuffer *memBuffer,
182 const char *triplePrefix);
175 /// isTargetMatch - Returns 'true' if the memory buffer is for the specified
176 /// target triple.
177 static bool isTargetMatch(llvm::MemoryBuffer *memBuffer,
178 const char *triplePrefix);
183179
184 /// makeLTOModule - Create an LTOModule (private version). N.B. This
185 /// method takes ownership of the buffer.
186 static LTOModule* makeLTOModule(llvm::MemoryBuffer *buffer,
187 std::string &errMsg);
180 /// makeLTOModule - Create an LTOModule (private version). N.B. This
181 /// method takes ownership of the buffer.
182 static LTOModule *makeLTOModule(llvm::MemoryBuffer *buffer,
183 std::string &errMsg);
188184
189 /// makeBuffer - Create a MemoryBuffer from a memory range.
190 static llvm::MemoryBuffer *makeBuffer(const void *mem, size_t length);
185 /// makeBuffer - Create a MemoryBuffer from a memory range.
186 static llvm::MemoryBuffer *makeBuffer(const void *mem, size_t length);
191187 };
192188
193189 #endif // LTO_MODULE_H