blob: e02a7ab1159f1b6ed267e3970e49ed80db067f44 [file] [log] [blame]
Nick Kledzik77595fc2008-02-26 20:26:43 +00001//===-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"
19#include "llvm/ADT/StringMap.h"
Devang Patela93ae712008-07-03 22:53:14 +000020#include "llvm/ADT/SmallVector.h"
Nick Kledzik77595fc2008-02-26 20:26:43 +000021
Nick Kledzikef194ed2008-02-27 22:25:36 +000022#include <string>
Nick Kledzik77595fc2008-02-26 20:26:43 +000023
24
25//
26// C++ class which implements the opaque lto_code_gen_t
27//
Owen Andersoncb371882008-08-21 00:14:44 +000028
Nick Kledzik77595fc2008-02-26 20:26:43 +000029class LTOCodeGenerator {
30public:
31 static const char* getVersionString();
32
33 LTOCodeGenerator();
34 ~LTOCodeGenerator();
35
36 bool addModule(class LTOModule*, std::string& errMsg);
37 bool setDebugInfo(lto_debug_model, std::string& errMsg);
38 bool setCodePICModel(lto_codegen_model, std::string& errMsg);
Nick Lewycky195bea32009-04-30 15:24:09 +000039 void setGccPath(const char* path);
Nick Kledzikcbad5862009-06-04 00:28:45 +000040 void setAssemblerPath(const char* path);
Nick Kledzik77595fc2008-02-26 20:26:43 +000041 void addMustPreserveSymbol(const char* sym);
Nick Kledzikef194ed2008-02-27 22:25:36 +000042 bool writeMergedModules(const char* path,
43 std::string& errMsg);
44 const void* compile(size_t* length, std::string& errMsg);
Nick Kledzik920ae982008-07-08 21:14:10 +000045 void setCodeGenDebugOptions(const char *opts);
Nick Kledzik77595fc2008-02-26 20:26:43 +000046private:
Owen Andersoncb371882008-08-21 00:14:44 +000047 bool generateAssemblyCode(llvm::raw_ostream& out,
48 std::string& errMsg);
Nick Kledzik77595fc2008-02-26 20:26:43 +000049 bool assemble(const std::string& asmPath,
50 const std::string& objPath, std::string& errMsg);
51 void applyScopeRestrictions();
52 bool determineTarget(std::string& errMsg);
53
54 typedef llvm::StringMap<uint8_t> StringSet;
55
56 llvm::Linker _linker;
57 llvm::TargetMachine* _target;
58 bool _emitDwarfDebugInfo;
59 bool _scopeRestrictionsDone;
60 lto_codegen_model _codeModel;
61 StringSet _mustPreserveSymbols;
Nick Kledzikef194ed2008-02-27 22:25:36 +000062 llvm::MemoryBuffer* _nativeObjectFile;
Nick Kledzik920ae982008-07-08 21:14:10 +000063 std::vector<const char*> _codegenOptions;
Nick Lewycky195bea32009-04-30 15:24:09 +000064 llvm::sys::Path* _gccPath;
Nick Kledzikcbad5862009-06-04 00:28:45 +000065 llvm::sys::Path* _assemblerPath;
Nick Kledzik77595fc2008-02-26 20:26:43 +000066};
67
68#endif // LTO_CODE_GENERATOR_H
69