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
75 lines (62 loc) · 1.7 KB
/
python_evaluator.cpp
File metadata and controls
75 lines (62 loc) · 1.7 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
#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 LFortran {
class LLVMEvaluator {};
}
#endif
namespace LFortran {
/* ------------------------------------------------------------------------- */
// 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, diag::Diagnostics &diagnostics
#else
ASR::TranslationUnit_t &/*asr*/, diag::Diagnostics &/*diagnostics*/
#endif
)
{
#ifdef HAVE_LFORTRAN_LLVM
eval_count++;
run_fn = "__lfortran_evaluate_" + std::to_string(eval_count);
// ASR -> LLVM
std::unique_ptr<LFortran::LLVMModule> m;
Result<std::unique_ptr<LFortran::LLVMModule>> res
= asr_to_llvm(asr, diagnostics,
e->get_context(), al, compiler_options.platform,
compiler_options.fast, get_runtime_library_dir(),
run_fn);
if (res.ok) {
m = std::move(res.result);
} else {
LFORTRAN_ASSERT(diagnostics.has_error())
return res.error;
}
if (compiler_options.fast) {
e->opt(*m->m_m);
}
return m;
#else
throw LFortranException("LLVM is not enabled");
#endif
}
} // namespace LFortran