Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 1 | //===-LTOCodeGenerator.h - LLVM Link Time Optimizer -----------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file declares the LTOCodeGenerator class. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | |
| 15 | #ifndef LTO_CODE_GENERATOR_H |
| 16 | #define LTO_CODE_GENERATOR_H |
| 17 | |
| 18 | #include "llvm/Linker.h" |
Owen Anderson | 8b477ed | 2009-07-01 16:58:40 +0000 | [diff] [blame] | 19 | #include "llvm/LLVMContext.h" |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/StringMap.h" |
Devang Patel | a93ae71 | 2008-07-03 22:53:14 +0000 | [diff] [blame] | 21 | #include "llvm/ADT/SmallVector.h" |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 22 | |
Nick Kledzik | ef194ed | 2008-02-27 22:25:36 +0000 | [diff] [blame] | 23 | #include <string> |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 24 | |
| 25 | |
| 26 | // |
| 27 | // C++ class which implements the opaque lto_code_gen_t |
| 28 | // |
Owen Anderson | cb37188 | 2008-08-21 00:14:44 +0000 | [diff] [blame] | 29 | |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 30 | class LTOCodeGenerator { |
| 31 | public: |
| 32 | static const char* getVersionString(); |
| 33 | |
Owen Anderson | 0e7a546 | 2009-07-02 00:31:14 +0000 | [diff] [blame^] | 34 | LTOCodeGenerator(); |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 35 | ~LTOCodeGenerator(); |
| 36 | |
| 37 | bool addModule(class LTOModule*, std::string& errMsg); |
| 38 | bool setDebugInfo(lto_debug_model, std::string& errMsg); |
| 39 | bool setCodePICModel(lto_codegen_model, std::string& errMsg); |
Nick Lewycky | 195bea3 | 2009-04-30 15:24:09 +0000 | [diff] [blame] | 40 | void setGccPath(const char* path); |
Nick Kledzik | cbad586 | 2009-06-04 00:28:45 +0000 | [diff] [blame] | 41 | void setAssemblerPath(const char* path); |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 42 | void addMustPreserveSymbol(const char* sym); |
Nick Kledzik | ef194ed | 2008-02-27 22:25:36 +0000 | [diff] [blame] | 43 | bool writeMergedModules(const char* path, |
| 44 | std::string& errMsg); |
| 45 | const void* compile(size_t* length, std::string& errMsg); |
Nick Kledzik | 920ae98 | 2008-07-08 21:14:10 +0000 | [diff] [blame] | 46 | void setCodeGenDebugOptions(const char *opts); |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 47 | private: |
Owen Anderson | cb37188 | 2008-08-21 00:14:44 +0000 | [diff] [blame] | 48 | bool generateAssemblyCode(llvm::raw_ostream& out, |
| 49 | std::string& errMsg); |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 50 | bool assemble(const std::string& asmPath, |
| 51 | const std::string& objPath, std::string& errMsg); |
| 52 | void applyScopeRestrictions(); |
| 53 | bool determineTarget(std::string& errMsg); |
| 54 | |
| 55 | typedef llvm::StringMap<uint8_t> StringSet; |
| 56 | |
Owen Anderson | 4434ed4 | 2009-07-01 23:13:44 +0000 | [diff] [blame] | 57 | llvm::LLVMContext& _context; |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 58 | llvm::Linker _linker; |
| 59 | llvm::TargetMachine* _target; |
| 60 | bool _emitDwarfDebugInfo; |
| 61 | bool _scopeRestrictionsDone; |
| 62 | lto_codegen_model _codeModel; |
| 63 | StringSet _mustPreserveSymbols; |
Nick Kledzik | ef194ed | 2008-02-27 22:25:36 +0000 | [diff] [blame] | 64 | llvm::MemoryBuffer* _nativeObjectFile; |
Nick Kledzik | 920ae98 | 2008-07-08 21:14:10 +0000 | [diff] [blame] | 65 | std::vector<const char*> _codegenOptions; |
Nick Lewycky | 195bea3 | 2009-04-30 15:24:09 +0000 | [diff] [blame] | 66 | llvm::sys::Path* _gccPath; |
Nick Kledzik | cbad586 | 2009-06-04 00:28:45 +0000 | [diff] [blame] | 67 | llvm::sys::Path* _assemblerPath; |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 68 | }; |
| 69 | |
| 70 | #endif // LTO_CODE_GENERATOR_H |
| 71 | |