1 // =================================
 2 // Copyright (c) 2021 Seppo Laakko
 3 // Distributed under the MIT license
 4 // =================================
 5 
 6 #include <cmajor/codegen/CodeGenerator.hpp>
 7 #include <cmajor/cmmid/Interface.hpp>
 8 #ifdef _WIN32
 9 #include <cmajor/codegenwin/WindowsCodeGenerator.hpp>
10 #include <cmajor/codegensx/SystemXCodeGenerator.hpp>
11 #else
12 #include <cmajor/codegenlinux/LinuxCodeGenerator.hpp>
13 #endif
14 #include <cmajor/codegencpp/CmCppCodeGenerator.hpp>
15 
16 namespace cmajor { namespace codegen {
17 
18 cmajor::codegenbase::CodeGenerator* CreateCodeGenerator(cmajor::ir::EmittingContext& emittingContext)
19 {
20     cmajor::mid::BackEndKind backEnd = GetBackEnd();
21     switch (backEnd)
22     {
23         case cmajor::mid::BackEndKind::llvmBackEnd:
24         {
25 #ifdef _WIN32
26 
27 #else
28             return new cmajor::codegenlinux::LinuxCodeGenerator(emittingContext);
29 #endif
30         }
31 #ifdef _WIN32
32 
33 
34 
35 
36 #endif
37         case cmajor::mid::BackEndKind::cmcppBackEnd:
38         {
39             return new cmajor::codegencpp::CmCppCodeGenerator(emittingContext);
40         }
41     }
42     return nullptr;
43 }
44 
45 void DestroyCodeGenerator(cmajor::codegenbase::CodeGenerator* codeGenerator)
46 {
47     delete codeGenerator;
48 }
49 
50 CodeGenerator::CodeGenerator(cmajor::ir::EmittingContext& emittingContext) : baseCodeGenerator(CreateCodeGenerator(emittingContext))
51 {
52 }
53 
54 CodeGenerator::~CodeGenerator()
55 {
56     DestroyCodeGenerator(baseCodeGenerator);
57 }
58 
59 } } // namespace cmajor::codegen