1 // =================================
 2 // Copyright (c) 2021 Seppo Laakko
 3 // Distributed under the MIT license
 4 // =================================
 5 
 6 #ifndef CMAJOR_CMLLVM_EMITTING_CONTEXT_INCLUDED
 7 #define CMAJOR_CMLLVM_EMITTING_CONTEXT_INCLUDED
 8 #include <cmajor/ir/EmittingContext.hpp>
 9 #include <llvm/Support/TargetSelect.h>
10 #include <llvm/Support/TargetRegistry.h>
11 #include <llvm/Support/FileSystem.h>
12 #include <llvm/Support/Host.h>
13 #include <llvm/Support/raw_os_ostream.h>
14 #include <llvm/Support/CommandLine.h>
15 #include <llvm/Target/TargetMachine.h>
16 #include <llvm/Target/TargetOptions.h>
17 #include <llvm/IR/Module.h>
18 #include <llvm/IR/LegacyPassManager.h>
19 #include <llvm/IR/DataLayout.h>
20 #include <llvm/IR/Verifier.h>
21 #include <llvm/Analysis/Passes.h>
22 #include <llvm/Transforms/IPO/PassManagerBuilder.h>
23 #include <llvm/Transforms/IPO.h>
24 #include <llvm/Analysis/TargetTransformInfo.h>
25 #include <llvm/Analysis/TargetLibraryInfo.h>
26 #include <llvm/Object/ObjectFile.h>
27 #include <llvm/CodeGen/TargetPassConfig.h>
28 
29 #if (LLVM_VERSION_MAJOR >= 10)
30 
31 #include <llvm/InitializePasses.h>
32 
33 #endif
34 
35 namespace cmllvm {
36 
37 class EmittingContext public cmajor::ir::EmittingContext
38 {
39 public:
40     EmittingContext(int optimizationLevel);
41     llvm::LLVMContext& Context() { return context; }
42     const std::string& TargetTriple() const override { return targetTriple; }
43     void* DataLayout() override { return dataLayout.get(); }
44     void* TargetMachine() override { return targetMachine.get(); }
45     int OptimizationLevel() const override { return optimizationLevel; }
46 private:
47     llvm::LLVMContext context;
48     std::string targetTriple;
49     int optimizationLevel;
50     std::unique_ptr<llvm::TargetMachine> targetMachine;
51     std::unique_ptr<llvm::DataLayout> dataLayout;
52 };
53 
54 } // namespace cmllvm
55 
56 #endif // CMAJOR_CMLLVM_EMITTING_CONTEXT_INCLUDED