NewLang Project
Yet another programm language
Loading...
Searching...
No Matches
jit.h
Go to the documentation of this file.
1#ifndef INCLUDED_JIT_H_
2#define INCLUDED_JIT_H_
3
4#include "warning_push.h"
5
6#include <clang/AST/ASTConcept.h>
7#include <clang/Sema/SemaConcept.h>
8#include <clang/Frontend/TextDiagnosticPrinter.h>
9#include <clang/CodeGen/CodeGenAction.h>
10#include <clang/Frontend/CompilerInstance.h>
11
12#include <clang/AST/Mangle.h>
13#include <clang/ASTMatchers/ASTMatchFinder.h>
14#include <clang/ASTMatchers/ASTMatchers.h>
15
16#include <llvm-c/Core.h>
17#include <llvm-c/Support.h>
18#include <llvm-c/TargetMachine.h>
19#include <llvm-c/ExecutionEngine.h>
20#include <llvm-c/Analysis.h>
21
22#include <llvm/Support/InitLLVM.h>
23#include <llvm/Support/TargetSelect.h>
24
25#include <llvm/InitializePasses.h>
26#include <llvm/Passes/PassBuilder.h>
27#include <llvm/ExecutionEngine/Orc/LLJIT.h>
28
29#include <llvm/IR/LegacyPassManagers.h>
30#include <llvm/Transforms/Scalar.h>
31
32
33
34#include <llvm/Bitcode/BitcodeWriter.h>
35#include <llvm/LinkAllIR.h>
36#include <llvm/LinkAllPasses.h>
37
38#include "clang/Driver/Driver.h"
39#include "clang/Driver/Compilation.h"
40
41#include "llvm-c/Core.h"
42#include "llvm-c/Target.h"
43#include "llvm-c/TargetMachine.h"
44
45#include "llvm/IR/LegacyPassManager.h"
46#include "llvm/MC/TargetRegistry.h"
47#include "llvm/Support/CodeGen.h"
48
49#include "llvm/Support/InitLLVM.h"
50
51#include "llvm/Target/TargetMachine.h"
52
53#include "clang/Frontend/CompilerInstance.h"
54#include "clang/CodeGen/CodeGenAction.h"
55
56#include "warning_pop.h"
57
58#include "nlc-rt.h"
59
60#include "runtime.h"
61#include "macro.h"
62#include "analysis.h"
63#include "module.h"
64
65
66
67namespace newlang {
68
69#define NEWLANG_INDENT_OP " "
70#define NEWLANG_PREFIX "newlang"
71#define NEWLANG_NS "newlang"
72
73 bool Tranliterate(const wchar_t c, std::wstring &str);
74 std::string MangleName(const char * name);
75
76 std::string MangaledFuncCPP(const char *name, const char *space = nullptr);
77 std::string MangaledFunc(const std::string name);
78
79
80// LLVMGenericValueRef GetGenericValueRef(Obj &obj, LLVMTypeRef type);
81// ObjPtr CreateFromGenericValue(ObjType type, LLVMGenericValueRef ref, LLVMTypeRef llvm_type);
82// LLVMTypeRef toLLVMType(ObjType t, bool none_if_error = false);
83// ObjPtr JitLastResult(ObjPtr val);
84
85
86 class JIT : public RunTime {
87 public:
88
91
92 // RuntimePtr m_rt;
95
96 std::vector<ModulePtr> m_module;
97 std::vector<std::shared_ptr<Context>> m_ctx;
98
99 inline TermPtrConst & GetAst() {
100 return (*m_module.begin())->m_ast;
101 }
102
103 inline Context & GetCtx() {
104 ASSERT(m_ctx.size());
105 return *(*m_ctx.begin());
106 }
107
108 clang::IntrusiveRefCntPtr<clang::DiagnosticOptions> DiagOpts;
109 clang::TextDiagnosticPrinter *textDiagPrinter;
110 clang::IntrusiveRefCntPtr<clang::DiagnosticIDs> pDiagIDs;
111 clang::DiagnosticsEngine *pDiagnosticsEngine;
112
113
114 JIT(const StringArray &args = {});
115
116 virtual ~JIT() {
117
118 delete pDiagnosticsEngine;
119 pDiagnosticsEngine = nullptr;
120 pDiagIDs.reset();
121
122 // delete textDiagPrinter;
123 // textDiagPrinter = nullptr;
124 DiagOpts.reset();
125 LLVMShutdown();
126 }
127
128
129 static JIT * m_instance;
130
131 void Clear() override {
133 if (m_instance) {
134 delete m_instance;
135 }
136 m_instance = nullptr;
137 //void LLVMGetVersion(unsigned *Major, unsigned *Minor, unsigned *Patch);
138
139 }
140
141 static JIT * ReCreate(const StringArray &args = {}) {
142 Instance()->Clear();
143 return Instance(args);
144 }
145
146 static JIT * Instance(const StringArray &args = {}) { //RuntimePtr rt
147 // ASSERT(rt);
148 if (m_instance == nullptr) { // || (rt && &m_instance->m_rt != rt)) {
149 // ASSERT(rt);
150 // if (m_instance) {
151 // delete m_instance;
152 // }
153 m_instance = new JIT(args);
154 }
156 // m_instance->m_rt = rt;
157 return m_instance;
158 }
159
160 JIT(const JIT&) = delete;
161 const JIT& operator=(const JIT&) = delete;
162
163 bool CreateMacro(const std::string_view text);
164
165 // void PrepareContext(Context &ctx, Module &module);
166
167 /*
168 * Корневая область имен C++ для генерации кода namespace nlc::gen { }, но все функции определяются как extern "C"
169 * Тело модуля - это тело головной функции __init__, которая выполняется при его загрузке (выполнении).
170 * Функцию можно определить в любом блоке кода, но это влияет только на ее доступность в NewLang,
171 * так как в коде C++ она все равно создается в корневой области имен.
172 *
173 *
174 * Если в теле модуля разрешить только определения и инициализацию переменных и функций,
175 * тогда отвалятся простые приложения без главной функции (скриптовые приложения)
176 *
177 * Если разрешить скриптовые приложения (код и определение функций вперемежку),
178 * тогда сложно анализировать и сложнее отлажиать,
179 * так как не полуится сгенерировать итоговый код на C++ один в один.
180 *
181 *
182 */
183 static bool LLVMInitialize() {
184
185 if (LLVMInitializeNativeTarget() || LLVMInitializeNativeAsmParser() || LLVMInitializeNativeAsmPrinter()) {
186 LOG_RUNTIME("Fail LLVM initialize!");
187 }
188 return true;
189 }
190
191 static bool LLVMInitializeJIT() {
192 LLVMInitializeAllTargetInfos();
193 LLVMInitializeAllTargets();
194 LLVMInitializeAllTargetMCs();
195 LLVMInitializeAllAsmParsers();
196 LLVMInitializeAllAsmPrinters();
197 return true;
198 }
199
200// TermPtr MakeAst(const std::string_view src, bool skip_analize = false);
201// TermPtr MakeAstParser(const std::string_view src, bool skip_analize = false);
203
204
205 // Выполняет одну строку в контексте главного модуля программы
206 // При первом вызове в m_main_ast создается AST как BLOCK
207 // При повторнвых вызовах в m_main_ast->m_block добавляется новая строка
208
209 ObjPtr Run(const std::string_view str, Obj* args = nullptr);
210
211 // Выполняет скопилированное AST как главный модуль программы
212 // При повторном вызове m_main_ast заменяется на новый AST
213 // ObjPtr Run(TermPtr ast, Obj* args = nullptr);
214 ObjPtr Run(Module *module, Obj* args = nullptr);
215 ObjPtr RunFile(std::string file, Obj* args = nullptr);
216
217 bool ModuleCreate(FileModule &data, const std::string_view source);
218 static bool ModuleCreate(FileModule &data, const std::string_view module_name, const TermPtr &include, const std::string_view source, llvm::Module *bc = nullptr);
219
220 std::string MakeCodeModule(const TermPtr &term, std::string_view name, bool is_main);
221 std::string MakeCodeFunction(const TermPtr &term);
222 std::string MakeFuncDeclarations_(const TermPtr &term);
223 std::string MakeCodeRepl(const std::string_view source, const std::string_view name);
224
225 void MakeFunctionRecursive_(const TermPtr &term, std::string &output, const std::string_view module);
226
227 std::unique_ptr<llvm::Module> MakeLLVMModule(std::string_view source, const std::vector<std::string> opts, std::string temp_dir = "");
228 bool MakeObjFile(const std::string_view filename, llvm::Module &module, const std::vector<std::string> opts);
229 bool LinkObjToExec(const std::string_view filename, std::vector<std::string> objs, std::vector<std::string> opts = {});
230
231 static std::string ExtractFunctionDecls(const TermPtr &ast, const std::string_view module);
232 static std::string ExtractStaticVars(const TermPtr &ast, const std::string_view module);
233 static std::string MakeBodyFunction(const TermPtr &ast);
234 static std::string MakeFunctionPrototype(const TermPtr &func, const std::string_view module);
235 // static std::string MakeFunctionArgs(const TermPtr &args);
236 static std::string RegExpInlineComment(const std::string_view src);
237 static std::string MakeCommentPlace(const TermPtr &term);
238
239
240 static std::string ReplaceObjectInEmbedSource(const std::string_view embed, std::vector<std::string> &include, const TermPtr args = nullptr);
241 bool MakeCppExec(const std::string_view source, const std::string_view filename, std::vector<std::string> opts = {});
242
243 std::string MakeApplicationSource(const TermPtr &ast);
244
245 static std::string MakeMain(const std::vector<std::string> &include);
246 static std::string MakeMainEmbed(const std::string_view embed_source, const std::vector<std::string> &include);
247
248 static TermPtr MainArgs();
249
250 //
251 //
252 // ObjPtr EvalCreate_(TermPtr & op);
253 // ObjPtr AssignVars_(ArrayTermType &l_vars, const TermPtr &r_term, bool is_pure);
254 //
255 // ObjPtr GetIndexValue(TermPtr &term, ObjPtr &obj, Context * runner);
256 // ObjPtr GetFieldValue(TermPtr &term, ObjPtr &value, Context * runner);
257 // ObjPtr SetIndexValue(TermPtr &term, ObjPtr &value, Context * runner);
258 // ObjPtr SetFieldValue(TermPtr &term, ObjPtr &value, Context * runner);
259
260 std::vector<std::string> m_includes;
261
262
263 };
264
265
266 struct CompileInfo;
267
268 struct CompileInfo {
269 // BuiltInTorchDirect * m_builtin_direct;
270
272 indent = 0;
273 if (rt) {
274 // rt->ReadBuiltInProto(builtin);
275 }
276
277 // m_builtin_direct = new BuiltInTorchDirect();
278 }
279
280 virtual ~CompileInfo() {
281
282 // delete m_builtin_direct;
283 }
284
285 // ProtoType arguments; //< Аргументы функции
286 // ProtoType functions; //< Локальные функции
287 // ProtoType variables; //< Локальные переменные
288 // ProtoType consts; //< Локальные константы
289 // ProtoType builtin;
290 std::set<std::string> iterators; //< Текущие итреаторы
291
292 std::string last_type; //< Тип последней операции
293
297 TermPtr findObject(std::string name);
298
300
301 size_t indent;
302
303 std::string GetIndent(int64_t offset = 0);
304
305 class Indent {
306 public:
307
309
310 info.indent++;
311 }
312
314
315 info.indent--;
316 }
318 };
319
321
322 return Indent(*this);
323 }
324
325 // BuiltInInfo m_builtin_info;
326 //private:
327 // Context * m_ctx;
328 };
329
330 class Compiler {
331 public:
332
333 // ObjPtr Run(const char *source, void *context);
334 //
335 // ObjPtr RunFile(const char *filename) {
336 //
337 // return Obj::CreateNone();
338 // }
339 //
340 // void Free();
341
342 /*
343 *
344 */
345 static bool MakeFunctionCpp(CompileInfo &ci, std::string func_name, TermPtr &func_define, std::ostream &out);
346 static bool MakeCppFile(TermPtr list, std::ostream &out, const char *source = nullptr, Context *ctx = nullptr);
347
348 // Преобразуют последовательность команд в эквивалентный код на С++ и возвращают результат выполнения последенй команды (или nullptr если не применимо)
349 static std::string MakeFunctionBodyCpp(CompileInfo &ci, TermPtr ast);
350 static std::string MakeSequenceOpsCpp(CompileInfo &ci, TermPtr elem, bool top_level);
351 // Преобразуют один термин в эквивалентый код на C++
352 static std::string GetImpl(CompileInfo &ci, TermPtr term, std::string &output);
353 static std::string BeginIterators(CompileInfo &ci, TermPtr args, std::string &output, std::vector<std::string> &iters);
354
355 static void ReplaceSourceVariable(CompileInfo &ci, size_t count, std::string &body);
356
357 static void MakeCppFileFunctions(CompileInfo &ci, TermPtr elem, std::ostream &out);
358 static void MakeCppFileConstants(CompileInfo &ci, TermPtr elem, std::ostream &out);
359 static void MakeCppFileCallTerm(CompileInfo &ci, TermPtr ast, std::ostream &out, size_t deep);
360 static std::string MakeCppFileCallArgs(CompileInfo &ci, TermPtr &args, TermPtr proto);
361 static std::string MakeIteratorCallArgs_(CompileInfo &ci, TermPtr args, std::vector<std::string> &iters);
362 static std::string MakeCppFileVariable(CompileInfo &ci, TermPtr &args, std::ostream &out);
363
364
365 static bool Execute(const char *exec, std::string *out = nullptr, int *exit_code = nullptr);
366 static bool GccMakeModule(const char * file, const char * module, const char * opts = nullptr, std::string *out = nullptr, int *exit_code = nullptr);
367
368 static std::string EncodeNonAsciiCharacters(const char * text);
369
370
371 static bool CompileModule(const char *filename, const char *output);
372 // static ObjPtr ExecModule(const char *module, const char *output, bool cached, Context *ctx);
373
374 // std::string MakeFunctionsSourceForJIT(TermPtr ast, Context *ctx);
375 // llvm::ExecutionEngine * JITCompileCPP(const char* source, const char* file_name = nullptr);
376
377 // bool LoadModule(const char *name, bool init = true, Context *ctx = nullptr, const char *module_name = nullptr);
378 // bool UnLoadModule(const char *name = nullptr, bool deinit = true);
379
380 // bool SaveContext(const char *name);
381 // static bool LoadContext(Context *ctx, const char *name);
382
383
384 // static ObjPtr Eval(Context *ctx, const char *text, bool make_function = false);
385 // static ObjPtr Eval(Context *ctx, TermPtr calc, bool make_function = false);
386 static ObjPtr GetIndexField(Context *ctx, ObjPtr obj, TermPtr term, bool create_field = false);
387
388 static bool ExecFunc(FunctionType * func, Obj *def_arg, Context *ctx, Obj &in, ObjPtr & out);
389
390 static bool StringTemplate(std::string &format, Context * ctx);
391
393
394 virtual ~Compiler() {
395
396 }
397
398 static void WriteIncludeFiles_(std::ostream & out) {
399
400 out << "#include \"pch.h\"\n";
401 out << "#include \"newlang.h\"\n";
402 out << "#include \"builtin.h\"\n";
403 out << "\n\n";
404 out << "using namespace " NEWLANG_NS ";\n";
405 out << "\n\n";
406 }
407
408 static void WriteDeclarationFunctions_(CompileInfo &ci, TermPtr &func, std::ostream & out, std::vector<std::string> &func_list);
409
415
416 typedef std::string WriteFunctionOp(CompileInfo &ci, TermPtr &op, FunctionStep step);
417
418 static std::string WriteFunctionCheckOp_(CompileInfo &ci, TermPtr &op, const char *check_true, const char *check_false);
419
420 // static std::string WriteSimpleBodyAND_(CompileInfo &ci, TermPtr &op, FunctionStep step = FunctionStep::OPERATION) {
421 // auto indent = ci.NewIndent();
422 // switch (step) {
423 // case FunctionStep::PREPARE:
424 // return "";
425 // case FunctionStep::COMPLETE:
426 // return ci.GetIndent() + "return " NEWLANG_NS "::Obj::Yes();\n";
427 //
428 // case FunctionStep::OPERATION:
429 // return WriteFunctionCheckOp_(ci, op, "", "return " NEWLANG_NS "::Obj::No()");
430 // }
431 // LOG_RUNTIME("Unknown function step %d", (int) step);
432 // }
433 //
434 // static std::string WriteSimpleBodyOR_(CompileInfo &ci, TermPtr &op, FunctionStep step = FunctionStep::OPERATION) {
435 // auto indent = ci.NewIndent();
436 // switch (step) {
437 // case FunctionStep::PREPARE:
438 // return "";
439 // case FunctionStep::COMPLETE:
440 // return ci.GetIndent() + "return " NEWLANG_NS "::Obj::No();\n";
441 //
442 // case FunctionStep::OPERATION:
443 // return WriteFunctionCheckOp_(ci, op, "return " NEWLANG_NS "::Obj::Yes()", "");
444 // }
445 // LOG_RUNTIME("Unknown function step %d", (int) step);
446 // }
447 //
448 // static std::string WriteSimpleBodyXOR_(CompileInfo &ci, TermPtr &op, FunctionStep step = FunctionStep::OPERATION) {
449 // auto indent = ci.NewIndent();
450 // switch (step) {
451 // case FunctionStep::PREPARE:
452 // return ci.GetIndent() + "size_t xor_counter = 0;\n";
453 // case FunctionStep::COMPLETE:
454 // // Результат равен 0, если нет операндов, равных 1, либо их чётное количество.
455 // return ci.GetIndent() + "return (xor_counter & 1) ? " NEWLANG_NS "::Obj::Yes() : " NEWLANG_NS "::Obj::No();\n";
456 //
457 // case FunctionStep::OPERATION:
458 // return WriteFunctionCheckOp_(ci, op, "xor_counter++", "");
459 // }
460 // LOG_RUNTIME("Unknown function step %d", (int) step);
461 // }
462
464 auto indent = ci.NewIndent();
465 switch (step) {
467 return "";
469 return ci.GetIndent(-1) + "return nullptr; // default return from function\n";
470 default: // FunctionStep::OPERATION
471 break;
472 }
473 std::string str;
474 GetImpl(ci, op, str);
475
476 return str + "\n";
477 }
478
480 auto indent = ci.NewIndent();
481 switch (step) {
483 return WriteArgsForCall_(ci, op);
485 return ci.GetIndent() + "return nullptr; // default return from function\n";
486 default: // FunctionStep::OPERATION
487 break;
488 }
489 std::string str;
490 GetImpl(ci, op, str);
491
492 return str + ";\n";
493 }
494
495 static std::string WriteArgsForCall_(CompileInfo &ci, TermPtr & func);
496
497 static void SelectTerms_(TermPtr &obj, std::vector<TermPtr> &terms);
498
499 static bool WriteFunctionName_(TermPtr &func, std::ostream & out, bool is_transparent = false);
500
501 static void ReplaceFuncArgs(TermPtr &func_define, std::string & str);
502
503 static std::string MakeCommentLine(std::string comment);
504
505 static std::string WriteSimpleBody_(CompileInfo &ci, TermPtr &func);
506
507
508 public:
509 // cppjit::CppJIT *m_jit;
510
511 protected:
512
514
515 };
516
517}
518
519
520#endif //INCLUDED_JIT_H_
Indent(CompileInfo &i)
Definition jit.h:308
CompileInfo & info
Definition jit.h:317
static ObjPtr GetIndexField(Context *ctx, ObjPtr obj, TermPtr term, bool create_field=false)
static void SelectTerms_(TermPtr &obj, std::vector< TermPtr > &terms)
static std::string BeginIterators(CompileInfo &ci, TermPtr args, std::string &output, std::vector< std::string > &iters)
std::string WriteFunctionOp(CompileInfo &ci, TermPtr &op, FunctionStep step)
Definition jit.h:416
static std::string MakeCommentLine(std::string comment)
static bool StringTemplate(std::string &format, Context *ctx)
static std::string WriteArgsForCall_(CompileInfo &ci, TermPtr &func)
static bool WriteFunctionName_(TermPtr &func, std::ostream &out, bool is_transparent=false)
static std::string MakeSequenceOpsCpp(CompileInfo &ci, TermPtr elem, bool top_level)
static bool Execute(const char *exec, std::string *out=nullptr, int *exit_code=nullptr)
virtual ~Compiler()
Definition jit.h:394
static void MakeCppFileCallTerm(CompileInfo &ci, TermPtr ast, std::ostream &out, size_t deep)
static bool GccMakeModule(const char *file, const char *module, const char *opts=nullptr, std::string *out=nullptr, int *exit_code=nullptr)
static bool MakeFunctionCpp(CompileInfo &ci, std::string func_name, TermPtr &func_define, std::ostream &out)
static std::string MakeCppFileVariable(CompileInfo &ci, TermPtr &args, std::ostream &out)
static void WriteDeclarationFunctions_(CompileInfo &ci, TermPtr &func, std::ostream &out, std::vector< std::string > &func_list)
static bool CompileModule(const char *filename, const char *output)
static void ReplaceFuncArgs(TermPtr &func_define, std::string &str)
static std::string WriteFunctionCheckOp_(CompileInfo &ci, TermPtr &op, const char *check_true, const char *check_false)
static std::string GetImpl(CompileInfo &ci, TermPtr term, std::string &output)
static std::string WriteFunctionBodyOTHER_(CompileInfo &ci, TermPtr &op, FunctionStep step=FunctionStep::OPERATION)
Definition jit.h:479
static std::string WriteFunctionBodyCLEAN_(CompileInfo &ci, TermPtr &op, FunctionStep step=FunctionStep::OPERATION)
Definition jit.h:463
static std::string WriteSimpleBody_(CompileInfo &ci, TermPtr &func)
static void WriteIncludeFiles_(std::ostream &out)
Definition jit.h:398
static std::string MakeCppFileCallArgs(CompileInfo &ci, TermPtr &args, TermPtr proto)
static std::string MakeFunctionBodyCpp(CompileInfo &ci, TermPtr ast)
static void MakeCppFileConstants(CompileInfo &ci, TermPtr elem, std::ostream &out)
static bool ExecFunc(FunctionType *func, Obj *def_arg, Context *ctx, Obj &in, ObjPtr &out)
static void ReplaceSourceVariable(CompileInfo &ci, size_t count, std::string &body)
static std::string EncodeNonAsciiCharacters(const char *text)
Compiler(RuntimePtr rt)
RuntimePtr m_runtime
Definition jit.h:513
static void MakeCppFileFunctions(CompileInfo &ci, TermPtr elem, std::ostream &out)
static bool MakeCppFile(TermPtr list, std::ostream &out, const char *source=nullptr, Context *ctx=nullptr)
static std::string MakeIteratorCallArgs_(CompileInfo &ci, TermPtr args, std::vector< std::string > &iters)
StorageTerm::ModuleMapType m_external
Definition jit.h:89
static std::string ExtractStaticVars(const TermPtr &ast, const std::string_view module)
Definition jit.cpp:913
static std::string ReplaceObjectInEmbedSource(const std::string_view embed, std::vector< std::string > &include, const TermPtr args=nullptr)
Definition jit.cpp:792
std::string MakeCodeFunction(const TermPtr &term)
Definition jit.cpp:917
static std::string MakeCommentPlace(const TermPtr &term)
Definition jit.cpp:695
static std::string MakeMain(const std::vector< std::string > &include)
Definition jit.cpp:749
bool LinkObjToExec(const std::string_view filename, std::vector< std::string > objs, std::vector< std::string > opts={})
Definition jit.cpp:624
std::vector< std::string > m_includes
Definition jit.h:260
JIT(const StringArray &args={})
Definition jit.cpp:2656
std::string MakeCodeModule(const TermPtr &term, std::string_view name, bool is_main)
Definition jit.cpp:822
clang::IntrusiveRefCntPtr< clang::DiagnosticIDs > pDiagIDs
Definition jit.h:110
void MakeFunctionRecursive_(const TermPtr &term, std::string &output, const std::string_view module)
Definition jit.cpp:929
ObjPtr Run(const std::string_view str, Obj *args=nullptr)
Definition jit.cpp:2558
static bool LLVMInitializeJIT()
Definition jit.h:191
std::vector< ModulePtr > m_module
Definition jit.h:96
clang::IntrusiveRefCntPtr< clang::DiagnosticOptions > DiagOpts
Definition jit.h:108
clang::TextDiagnosticPrinter * textDiagPrinter
Definition jit.h:109
static JIT * Instance(const StringArray &args={})
Definition jit.h:146
static JIT * m_instance
Definition jit.h:129
Context & GetCtx()
Definition jit.h:103
TermPtrConst & GetAst()
Definition jit.h:99
static JIT * ReCreate(const StringArray &args={})
Definition jit.h:141
MacroPtr m_macro
Definition jit.h:93
static std::string RegExpInlineComment(const std::string_view src)
Definition jit.cpp:704
std::unique_ptr< llvm::Module > MakeLLVMModule(std::string_view source, const std::vector< std::string > opts, std::string temp_dir="")
Definition jit.cpp:362
static std::string ExtractFunctionDecls(const TermPtr &ast, const std::string_view module)
Definition jit.cpp:665
const JIT & operator=(const JIT &)=delete
std::vector< std::shared_ptr< Context > > m_ctx
Definition jit.h:97
virtual ~JIT()
Definition jit.h:116
ParserPtr GetParser()
Definition jit.cpp:2535
size_t m_repl_count
Definition jit.h:94
ObjPtr RunFile(std::string file, Obj *args=nullptr)
Definition jit.cpp:2540
clang::DiagnosticsEngine * pDiagnosticsEngine
Definition jit.h:111
std::string MakeApplicationSource(const TermPtr &ast)
Definition jit.cpp:722
void Clear() override
Definition jit.h:131
static std::string MakeFunctionPrototype(const TermPtr &func, const std::string_view module)
Definition jit.cpp:684
NameLookupStack m_stack
Definition jit.h:90
bool MakeObjFile(const std::string_view filename, llvm::Module &module, const std::vector< std::string > opts)
Definition jit.cpp:584
static std::string MakeMainEmbed(const std::string_view embed_source, const std::vector< std::string > &include)
Definition jit.cpp:755
static bool LLVMInitialize()
Definition jit.h:183
static TermPtr MainArgs()
Definition jit.cpp:711
JIT(const JIT &)=delete
std::string MakeFuncDeclarations_(const TermPtr &term)
Definition jit.cpp:921
std::string MakeCodeRepl(const std::string_view source, const std::string_view name)
Definition jit.cpp:868
static std::string MakeBodyFunction(const TermPtr &ast)
Definition jit.cpp:925
bool ModuleCreate(FileModule &data, const std::string_view source)
Definition jit.cpp:2638
bool MakeCppExec(const std::string_view source, const std::string_view filename, std::vector< std::string > opts={})
bool CreateMacro(const std::string_view text)
Definition jit.cpp:2783
virtual void Clear()
Definition runtime.cpp:74
std::map< std::string, StorageTerm > ModuleMapType
Definition term.h:172
#define NEWLANG_NS
Definition jit.h:71
yylloc step()
#define LOG_RUNTIME(format,...)
Definition logger.h:26
#define ASSERT(condition)
Definition logger.h:60
Definition nlc.h:59
std::shared_ptr< Parser > ParserPtr
Definition types.h:245
std::string MangaledFuncCPP(const char *name, const char *space=nullptr)
Definition jit.cpp:188
std::shared_ptr< Term > TermPtr
Definition variable.h:33
std::shared_ptr< Obj > ObjPtr
Definition variable.h:28
std::shared_ptr< RunTime > RuntimePtr
Definition types.h:242
std::vector< std::string > StringArray
Definition types.h:148
bool Tranliterate(const wchar_t c, std::wstring &str)
Definition jit.cpp:44
std::string MangaledFunc(const std::string name)
Definition jit.cpp:201
std::shared_ptr< const Term > TermPtrConst
Definition variable.h:34
std::shared_ptr< Macro > MacroPtr
Definition types.h:244
std::string MangleName(const char *name)
Definition jit.cpp:209
ObjPtr FunctionType(Context *ctx, Obj &in)
Definition types.h:248
virtual ~CompileInfo()
Definition jit.h:280
CompileInfo(RuntimePtr rt)
Definition jit.h:271
TermPtr isFunction(TermPtr term)
TermPtr findObject(std::string name)
TermPtr isArgument(TermPtr term)
TermPtr isVariable(TermPtr term)
std::set< std::string > iterators
Definition jit.h:290
bool isLocalAccess(TermPtr term)
std::string last_type
Definition jit.h:292
std::string GetIndent(int64_t offset=0)
Definition jit.cpp:952
Indent NewIndent()
Definition jit.h:320