blob: 24a2ba316e7f89d3ab81650a006ef033b8f502d1 [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//
28class LTOCodeGenerator {
29public:
30 static const char* getVersionString();
31
32 LTOCodeGenerator();
33 ~LTOCodeGenerator();
34
35 bool addModule(class LTOModule*, std::string& errMsg);
36 bool setDebugInfo(lto_debug_model, std::string& errMsg);
37 bool setCodePICModel(lto_codegen_model, std::string& errMsg);
38 void addMustPreserveSymbol(const char* sym);
Nick Kledzikef194ed2008-02-27 22:25:36 +000039 bool writeMergedModules(const char* path,
40 std::string& errMsg);
41 const void* compile(size_t* length, std::string& errMsg);
Devang Patela93ae712008-07-03 22:53:14 +000042 void setCodeGenDebugOptions(const char *opts) {
43 _codegenOptions.push_back(std::string(opts));
44 }
Nick Kledzik77595fc2008-02-26 20:26:43 +000045private:
46 bool generateAssemblyCode(std::ostream& out,
47 std::string& errMsg);
48 bool assemble(const std::string& asmPath,
49 const std::string& objPath, std::string& errMsg);
50 void applyScopeRestrictions();
51 bool determineTarget(std::string& errMsg);
52
53 typedef llvm::StringMap<uint8_t> StringSet;
54
55 llvm::Linker _linker;
56 llvm::TargetMachine* _target;
57 bool _emitDwarfDebugInfo;
58 bool _scopeRestrictionsDone;
59 lto_codegen_model _codeModel;
60 StringSet _mustPreserveSymbols;
Nick Kledzikef194ed2008-02-27 22:25:36 +000061 llvm::MemoryBuffer* _nativeObjectFile;
Devang Patela93ae712008-07-03 22:53:14 +000062 llvm::SmallVector<std::string, 4> _codegenOptions;
Nick Kledzik77595fc2008-02-26 20:26:43 +000063};
64
65#endif // LTO_CODE_GENERATOR_H
66