forked from lcompilers/lpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_evaluator.cpp
More file actions
76 lines (63 loc) · 1.79 KB
/
python_evaluator.cpp
File metadata and controls
76 lines (63 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <iostream>
#include <fstream>
#include <lpython/python_evaluator.h>
#include <libasr/codegen/asr_to_cpp.h>
#include <libasr/exception.h>
#include <libasr/asr.h>
#ifdef HAVE_LFORTRAN_LLVM
#include <libasr/codegen/evaluator.h>
#include <libasr/codegen/asr_to_llvm.h>
#else
namespace LCompilers {
class LLVMEvaluator {};
}
#endif
namespace LCompilers {
/* ------------------------------------------------------------------------- */
// PythonEvaluator
PythonCompiler::PythonCompiler(CompilerOptions compiler_options)
:
al{1024*1024},
#ifdef HAVE_LFORTRAN_LLVM
e{std::make_unique<LLVMEvaluator>()},
eval_count{0},
#endif
compiler_options{compiler_options}
// symbol_table{nullptr}
{
}
PythonCompiler::~PythonCompiler() = default;
Result<std::unique_ptr<LLVMModule>> PythonCompiler::get_llvm3(
#ifdef HAVE_LFORTRAN_LLVM
ASR::TranslationUnit_t &asr, LCompilers::PassManager& lpm,
diag::Diagnostics &diagnostics, const std::string &infile
#else
ASR::TranslationUnit_t &/*asr*/, LCompilers::PassManager&/*lpm*/,
diag::Diagnostics &/*diagnostics*/,const std::string &/*infile*/
#endif
)
{
#ifdef HAVE_LFORTRAN_LLVM
eval_count++;
run_fn = "__lfortran_evaluate_" + std::to_string(eval_count);
// ASR -> LLVM
std::unique_ptr<LCompilers::LLVMModule> m;
Result<std::unique_ptr<LCompilers::LLVMModule>> res
= asr_to_llvm(asr, diagnostics,
e->get_context(), al, lpm, compiler_options,
run_fn, infile);
if (res.ok) {
m = std::move(res.result);
} else {
LCOMPILERS_ASSERT(diagnostics.has_error())
return res.error;
}
if (compiler_options.fast) {
e->opt(*m->m_m);
}
return m;
#else
throw LCompilersException("LLVM is not enabled");
#endif
}
} // namespace LCompilers::LPython