NewLang Project
Yet another programm language
Loading...
Searching...
No Matches
jit_test.cpp
Go to the documentation of this file.
1//#ifdef BUILD_UNITTEST
2//
3//#include "warning_push.h"
4//#include <gtest/gtest.h>
5//#include "warning_pop.h"
6//
7//
8//
9//#include "jit.h"
10//#include "term.h"
11//#include "runtime.h"
12//
13//using namespace newlang;
14//
15//TEST(JIT, ReCreate) {
16// JIT *jit = JIT::ReCreate();
17// ASSERT_TRUE(jit);
18// ASSERT_TRUE(jit->m_assert_enable);
19//
20// JIT *jit2 = JIT::ReCreate({"--nlc-no-assert"});
21// ASSERT_TRUE(jit2);
22// ASSERT_FALSE(jit2->m_assert_enable);
23//}
24//
25//TEST(JIT, Function) {
26// // std::filesystem::create_directories("temp");
27// // ASSERT_TRUE(std::filesystem::is_directory("temp"));
28// // //std::remove("temp/brother.sh.temp.nlm");
29//
30// TermPtr term = Parser::ParseString("func():Int32");
31// term->m_normalized = "func::";
32// std::string src;
33// src = JIT::MakeFunctionPrototype(term, "");
34// ASSERT_STREQ("newlang::ObjPtr _$$_func$$(newlang::Context *ctx, newlang::Obj &args)", src.c_str()) << src;
35// src = JIT::MakeFunctionPrototype(term, "\\\\dir\\module");
36// ASSERT_STREQ("newlang::ObjPtr _$$$dir$module$_func$$(newlang::Context *ctx, newlang::Obj &args)", src.c_str()) << src;
37//
38// term->push_back(Term::CreateName("arg"));
39// term->push_back(Term::CreateName("arg2"));
40// src = JIT::MakeFunctionPrototype(term, "");
41// ASSERT_STREQ("newlang::ObjPtr _$$_func$$(newlang::Context *ctx, newlang::Obj &args)", src.c_str()) << src;
42// src = JIT::MakeFunctionPrototype(term, "\\\\dir\\module2");
43// ASSERT_STREQ("newlang::ObjPtr _$$$dir$module2$_func$$(newlang::Context *ctx, newlang::Obj &args)", src.c_str()) << src;
44//}
45//
46//void writeModuleToFile(llvm::Module *module) {
47// auto TargetTriple = LLVMGetDefaultTargetTriple();
48// llvm::InitializeAllTargetInfos();
49// llvm::InitializeAllTargets();
50// llvm::InitializeAllTargetMCs();
51// llvm::InitializeAllAsmParsers();
52// llvm::InitializeAllAsmPrinters();
53//
54// std::string Error;
55// auto Target = llvm::TargetRegistry::lookupTarget(TargetTriple, Error);
56// auto CPU = "generic";
57// auto Features = "";
58//
59// llvm::TargetOptions opt;
60// auto RM = std::optional<llvm::Reloc::Model>();
61// auto TargetMachine = Target->createTargetMachine(TargetTriple, CPU, Features, opt, RM);
62//
63// module->setDataLayout(TargetMachine->createDataLayout());
64// module->setTargetTriple(TargetTriple);
65//
66// auto Filename = "output.o";
67// std::error_code EC;
68// llvm::raw_fd_ostream dest(Filename, EC, llvm::sys::fs::OF_None);
69//
70// llvm::legacy::PassManager pass;
71// auto FileType = llvm::CodeGenFileType::ObjectFile;
72//
73// if (TargetMachine->addPassesToEmitFile(pass, dest, nullptr, FileType)) {
74// llvm::errs() << "TargetMachine can't emit a file of this type";
75// return;
76// }
77// pass.run(*module);
78// dest.flush();
79//
80// llvm::IntrusiveRefCntPtr<clang::DiagnosticOptions> DiagOpts = new clang::DiagnosticOptions;
81// clang::TextDiagnosticPrinter *DiagClient = new clang::TextDiagnosticPrinter(llvm::errs(), &*DiagOpts);
82// llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs> DiagID(new clang::DiagnosticIDs());
83// clang::DiagnosticsEngine Diags(DiagID, &*DiagOpts, DiagClient);
84// clang::driver::Driver TheDriver("/uslkjhklhjkr/bin/clang++-12ssss", TargetTriple, Diags);
85//
86// auto args = llvm::ArrayRef<const char *>{"-g", "output.o", "-o", "xxxxxxxxxxxxxxxxxxxxx"};
87//
88// std::unique_ptr<clang::driver::Compilation> C(TheDriver.BuildCompilation(args));
89//
90// if (C && !C->containsError()) {
91// llvm::SmallVector<std::pair<int, const clang::driver::Command *>, 4> FailingCommands;
92// TheDriver.ExecuteCompilation(*C, FailingCommands);
93// }
94//
95// // remove(Filename);
96//}
97//
98//std::unique_ptr<llvm::Module> CompileCpp2(std::string source, std::vector<std::string> opts, std::string *asm_code = nullptr) {
99// clang::CompilerInstance compilerInstance;
100// auto& compilerInvocation = compilerInstance.getInvocation();
101//
102//
103// // Диагностика работы Clang
104// clang::IntrusiveRefCntPtr<clang::DiagnosticOptions> DiagOpts = new clang::DiagnosticOptions;
105// clang::TextDiagnosticPrinter *textDiagPrinter =
106// new clang::TextDiagnosticPrinter(llvm::outs(), &*DiagOpts);
107//
108// clang::IntrusiveRefCntPtr<clang::DiagnosticIDs> pDiagIDs;
109//
110// clang::DiagnosticsEngine *pDiagnosticsEngine =
111// new clang::DiagnosticsEngine(pDiagIDs, &*DiagOpts, textDiagPrinter);
112//
113//
114// // Целевая платформа
115// std::string triple = LLVMGetDefaultTargetTriple();
116//
117// std::vector<std::string> itemstrs;
118// itemstrs.push_back(triple.insert(0, "-triple="));
119// itemstrs.push_back("-xc++");
120// itemstrs.push_back("-std=c++23");
121//
122// itemstrs.insert(itemstrs.end(), opts.begin(), opts.end());
123//
124// // itemstrs.push_back("-fno-exceptions");
125// // itemstrs.push_back("-funwind-tables");
126//
127// std::vector<const char*> itemcstrs;
128// for (unsigned idx = 0; idx < itemstrs.size(); idx++) {
129// // note: if itemstrs is modified after this, itemcstrs will be full
130// // of invalid pointers! Could make copies, but would have to clean up then...
131// itemcstrs.push_back(itemstrs[idx].c_str());
132// std::cout << itemcstrs.back() << "\n";
133// }
134//
135// // Компиляция из памяти
136// // Send code through a pipe to stdin
137// int codeInPipe[2];
138// pipe2(codeInPipe, O_NONBLOCK);
139// write(codeInPipe[1], source.c_str(), source.size());
140// close(codeInPipe[1]); // We need to close the pipe to send an EOF
141// dup2(codeInPipe[0], STDIN_FILENO);
142//
143// itemcstrs.push_back("-"); // Read code from stdin
144//
145// clang::CompilerInvocation::CreateFromArgs(compilerInvocation,
146// llvm::ArrayRef<const char *>(itemcstrs.data(),
147// itemcstrs.size()), *pDiagnosticsEngine);
148//
149// auto& languageOptions = compilerInvocation.getLangOpts();
150// auto& preprocessorOptions = compilerInvocation.getPreprocessorOpts();
151// auto& targetOptions = compilerInvocation.getTargetOpts();
152//
153// auto& frontEndOptions = compilerInvocation.getFrontendOpts();
154// // frontEndOptions.ShowStats = true;
155//
156// auto& headerSearchOptions = compilerInvocation.getHeaderSearchOpts();
157// // headerSearchOptions.Verbose = true;
158//
159// auto& codeGenOptions = compilerInvocation.getCodeGenOpts();
160//
161//
162// targetOptions.Triple = LLVMGetDefaultTargetTriple();
163// compilerInstance.createDiagnostics(textDiagPrinter, false);
164//
165// std::cout << "Using target triple: " << triple;
166//
167// LLVMContextRef ctx = LLVMContextCreate();
168// std::unique_ptr<clang::CodeGenAction> action = std::make_unique<clang::EmitLLVMOnlyAction>((llvm::LLVMContext *)ctx);
169//
170// assert(compilerInstance.ExecuteAction(*action));
171//
172// // Runtime LLVM Module
173// std::unique_ptr<llvm::Module> module = action->takeModule();
174//
175// assert(module);
176//
177//
178// if (asm_code) {
179// llvm::raw_string_ostream asm_stream(*asm_code);
180// module->print(asm_stream, 0, false);
181// }
182// //AssemblyWriter
183//
184//
185//
186//
187// // LLVMContextRef context = LLVMContextCreate();
188// // LLVMModuleRef module = LLVMModuleCreateWithNameInContext("test", context);
189//
190// // LLVMTypeRef f32 = LLVMFloatTypeInContext(context);
191// // LLVMTypeRef ftype = LLVMFunctionType(f32, 0, 0, 0);
192// // LLVMValueRef ftest = LLVMAddFunction(module, "ftest", ftype);
193// // LLVMBasicBlockRef bb = LLVMAppendBasicBlockInContext(context, ftest, "ftest");
194// // LLVMBuilderRef builder = LLVMCreateBuilderInContext(context);
195// // LLVMPositionBuilderAtEnd(builder, bb);
196// // LLVMValueRef v1 = LLVMConstReal(f32, 2.5);
197// // LLVMValueRef v2 = LLVMConstReal(f32, 4.3);
198// // LLVMValueRef result = LLVMBuildFAdd(builder, v1, v2, "f-add");
199// // LLVMBuildRet(builder, result);
200// // LLVMVerifyFunction(ftest, LLVMPrintMessageAction);
201//
202// char* errors = 0;
203// // LLVMPrintModuleToFile((LLVMModuleRef)&*module, "include_h_i_function_test.s", &errors);
204// // printf("error: %s\n", errors);
205// // LLVMDisposeMessage(errors);
206//
207// // LLVMInitializeAllTargetInfos();
208// // LLVMInitializeAllTargets();
209// // LLVMInitializeAllTargetMCs();
210// // LLVMInitializeAllAsmParsers(); // Для использования ассемблерных вставок!!! (комменатрие в коде)
211// // LLVMInitializeAllAsmPrinters();
212//
213// // LLVMTargetRef target;
214// // LLVMGetTargetFromTriple(LLVMGetDefaultTargetTriple(), &target, &errors);
215// // // printf("error: %s\n", errors);
216// // LLVMDisposeMessage(errors);
217// // // printf("target: %s, [%s], %d, %d\n", LLVMGetTargetName(target), LLVMGetTargetDescription(target), LLVMTargetHasJIT(target), LLVMTargetHasTargetMachine(target));
218// // // printf("triple: %s\n", LLVMGetDefaultTargetTriple());
219// // // printf("features: %s\n", LLVMGetHostCPUFeatures());
220// // LLVMTargetMachineRef machine = LLVMCreateTargetMachine(target, LLVMGetDefaultTargetTriple(), "generic", LLVMGetHostCPUFeatures(), LLVMCodeGenLevelDefault, LLVMRelocDefault, LLVMCodeModelDefault);
221// //
222// // LLVMSetTarget((LLVMModuleRef)&*module, LLVMGetDefaultTargetTriple());
223// // LLVMTargetDataRef datalayout = LLVMCreateTargetDataLayout(machine);
224// // char* datalayout_str = LLVMCopyStringRepOfTargetData(datalayout);
225// // // printf("datalayout: %s\n", datalayout_str);
226// // LLVMSetDataLayout((LLVMModuleRef)&*module, datalayout_str);
227// // LLVMDisposeMessage(datalayout_str);
228// //
229// // LLVMTargetMachineEmitToFile(machine, (LLVMModuleRef)&*module, "include_h_i_function_test.o", LLVMObjectFile, &errors);
230// // // printf("error: %s\n", errors);
231// // LLVMDisposeMessage(errors);
232//
233//
234// // Оптимизация IR
235// // llvm::PassBuilder passBuilder;
236// // llvm::LoopAnalysisManager loopAnalysisManager;
237// // llvm::FunctionAnalysisManager functionAnalysisManager;
238// // llvm::CGSCCAnalysisManager cGSCCAnalysisManager;
239// // llvm::ModuleAnalysisManager moduleAnalysisManager;
240// //
241// // passBuilder.registerModuleAnalyses(moduleAnalysisManager);
242// // passBuilder.registerCGSCCAnalyses(cGSCCAnalysisManager);
243// // passBuilder.registerFunctionAnalyses(functionAnalysisManager);
244// // passBuilder.registerLoopAnalyses(loopAnalysisManager);
245// // passBuilder.crossRegisterProxies(loopAnalysisManager, functionAnalysisManager, cGSCCAnalysisManager, moduleAnalysisManager);
246// //
247// // llvm::ModulePassManager modulePassManager = passBuilder.buildPerModuleDefaultPipeline(llvm::OptimizationLevel::O0);
248// // modulePassManager.run(*module, moduleAnalysisManager);
249//
250// return module;
251//}
252//
253//const char * source = ""
254// "#include <stdio.h>\n"
255// "#include \"sys/time.h\"\n"
256// "\n"
257// "\n"
258// "int main(int argc, char* argv[], char* envp[]) {\n"
259// "\n"
260// " // disable unused warning\n"
261// " ((void)(argc)); ((void)(argv)); ((void)(envp));\n"
262// " printf(\"Hello, world!!!!!!!!!!!!!!!!!!\\n\");\n"
263// "\n"
264// " return 0;\n"
265// "};";
266//
267//TEST(JIT, Embed) {
268//
269// std::vector<std::string> argsX{
270// // "-std=c++23", "-stdlib=libc++",
271// // "--print-supported-cpus",
272// "-I", "/usr/include",
273// "-I", "/usr/local/include",
274// "-I", "/usr/include/x86_64-linux-gnu/",
275// "-I", "/usr/lib/gcc/x86_64-linux-gnu/11/include",
276// // "-o", "hello_embeddddddddddddddddddddd",
277// // "-x", "c++",
278// // "hello_embed.cpp"
279// };
280//
281// auto module = CompileCpp2(source, argsX);
282//
283// writeModuleToFile(module.get());
284//
285//}
286//
287//TEST(JIT, MakeEmbed) {
288//
289//
290// std::filesystem::path path = std::filesystem::path("../examples/hello_embed.src");
291// ASSERT_TRUE(std::filesystem::exists(path));
292//
293// std::ifstream file(path, std::ios::in | std::ios::binary);
294//
295// const auto sz = std::filesystem::file_size(path);
296// ASSERT_TRUE(sz);
297//
298// std::string source(sz, '\0');
299// file.read(source.data(), sz);
300// ASSERT_TRUE(file) << "error: only " << file.gcount() << " could be read";
301// file.close();
302//
303// TermPtr ast = Parser::ParseString(source);
304//
305// JIT *jit = JIT::ReCreate();
306// ASSERT(jit);
307//
308// std::string hello_embed = jit->MakeApplicationSource(ast);
309//
310// if (!std::filesystem::exists(std::filesystem::path("temp"))) {
311// std::filesystem::create_directories(std::filesystem::path("temp"));
312// }
313// ASSERT_TRUE(std::filesystem::exists(std::filesystem::path("temp")));
314// ASSERT_TRUE(std::filesystem::is_directory(std::filesystem::path("temp")));
315//
316// std::ofstream ofile(std::filesystem::path("temp/hello_embed.cpp"), std::ios::out | std::ios::trunc);
317// ofile << hello_embed;
318// ofile.close();
319//
320// std::string bin_out;
321//
322// std::vector<std::string> argsX{
323// "-I", "/usr/include",
324// "-I", "/usr/local/include",
325// "-I", "/usr/include/x86_64-linux-gnu/",
326// "-I", "/usr/lib/gcc/x86_64-linux-gnu/11/include",};
327//
328// // auto module = CompileCpp2(source, argsX);
329//
330//
331// // ASSERT_TRUE(jit->MakeCppExec(hello_embed, "temp/hello_embed", argsX)) << hello_embed;
332//
333// std::unique_ptr<llvm::Module> module = jit->MakeLLVMModule(hello_embed, argsX, "temp");
334// ASSERT_TRUE(module);
335// ASSERT_TRUE(jit->MakeObjFile("temp/hello_embed.o", *module,{}));
336//
337// ASSERT_TRUE(jit->LinkObjToExec("temp/hello_embed",{"temp/hello_embed.o"}));
338//
339// ASSERT_TRUE(std::filesystem::exists(std::filesystem::path("temp/hello_embed")));
340//
341//
342//}
343//
344//TEST(JIT, MakeModule) {
345//
346//
347//
348//
349// std::filesystem::path path = std::filesystem::path("../examples/hello.src");
350// ASSERT_TRUE(std::filesystem::exists(path));
351//
352// std::ifstream file(path, std::ios::in | std::ios::binary);
353//
354// const auto sz = std::filesystem::file_size(path);
355// ASSERT_TRUE(sz);
356//
357// std::string source(sz, '\0');
358// file.read(source.data(), sz);
359// ASSERT_TRUE(file) << "error: only " << file.gcount() << " could be read";
360// file.close();
361//
362// TermPtr ast = Parser::ParseString(source);
363//
364// JIT *jit = JIT::ReCreate();
365// ASSERT(jit);
366//
367// std::string hello = jit->MakeCodeModule(ast, "hello", true);
368//
369// if (!std::filesystem::exists(std::filesystem::path("temp"))) {
370// std::filesystem::create_directories(std::filesystem::path("temp"));
371// }
372// ASSERT_TRUE(std::filesystem::exists(std::filesystem::path("temp")));
373// ASSERT_TRUE(std::filesystem::is_directory(std::filesystem::path("temp")));
374//
375// std::ofstream ofile(std::filesystem::path("temp/hello.cpp"), std::ios::out | std::ios::trunc);
376// ofile << hello;
377// ofile.close();
378//
379// std::string bin_out;
380//
381//
382// std::string opt_str = ReadFile("../build_options.txt");
383// ASSERT_TRUE(opt_str.size() > 100);
384//
385//
386//
387// std::vector<std::string> opts = RunTime::SplitChar(opt_str, " \t\r\n");
388//
389// opts.push_back("-I../lib");
390// opts.push_back("-DBUILD_UNITTEST");
391// opts.push_back("-DBUILD_DEBUG ");
392// opts.push_back("-DLOG_LEVEL_NORMAL=LOG_LEVEL_DEBUG");
393//
394// // opts.push_back("-triple");
395// // opts.push_back("x86_64-pc-linux-gnu");
396// // opts.push_back("-emit-obj");
397// //
398// // opts.push_back("-mrelocation-model");
399// // opts.push_back("pic");
400// // opts.push_back("-pic-level");
401// // opts.push_back("2");
402// // opts.push_back("-pic-is-pie");
403// //
404// // opts.push_back("-discard-value-names");
405// // opts.push_back("-disable-llvm-verifier");
406// //
407// // opts.push_back("-mrelax-all");
408// // opts.push_back("-disable-free");
409// // opts.push_back("-clear-ast-before-backend");
410// //
411// // opts.push_back("-mframe-pointer=all");
412// // opts.push_back("-fmath-errno");
413// // opts.push_back("-ffp-contract=on");
414// // opts.push_back("-fno-rounding-math");
415// // opts.push_back("-mconstructor-aliases");
416// //
417// // opts.push_back("-fcolor-diagnostics");
418// // opts.push_back("-faddrsig");
419// //
420// // opts.push_back("-fskip-odr-check-in-gmf");
421// //
422// // opts.push_back("-tune-cpu");
423// // opts.push_back("generic");
424// // opts.push_back("-target-cpu");
425// // opts.push_back("x86-64");
426// //
427// // opts.push_back("-cc1");
428// //
429// // opts.push_back("-funwind-tables=2");
430// // opts.push_back("-fdeprecated-macro");
431// // opts.push_back("-fgnuc-version=4.2.1");
432// // opts.push_back("-D__GCC_HAVE_DWARF2_CFI_ASM=1");
433//
434// for (auto &elem : opts) {
435// if (elem.find("-D") == 0) {
436// elem += " ";
437// }
438// std::cout << elem << "\n";
439// }
440//
441// ASSERT_TRUE(opts.size() > 20);
442//
443// std::vector<std::string> argsX{
444// // "-I", "/usr/include",
445// // "-I", "/usr/local/include",
446// // "-I", "/usr/include/c++/11",
447// // "-I", "/usr/include/x86_64-linux-gnu/c++/11",
448// // "-I", "/usr/include/x86_64-linux-gnu/",
449// // "-I", "/usr/lib/gcc/x86_64-linux-gnu/11/include",
450// };
451//
452// argsX.insert(argsX.end(), opts.begin(), opts.end());
453// // auto module = CompileCpp2(source, argsX);
454//
455//
456// std::string main_src = jit->MakeMain({});
457// std::ofstream omain(std::filesystem::path("temp/main.cpp"), std::ios::out | std::ios::trunc);
458// omain << main_src;
459// omain.close();
460//
461// std::unique_ptr<llvm::Module> main = jit->MakeLLVMModule(main_src, argsX, "temp");
462// ASSERT_TRUE(main);
463// ASSERT_TRUE(jit->MakeObjFile("temp/main.o", *main, argsX));
464//
465// std::unique_ptr<llvm::Module> module = jit->MakeLLVMModule(hello, argsX, "temp");
466// ASSERT_TRUE(module);
467// ASSERT_TRUE(jit->MakeObjFile("temp/hello.o", *module, argsX));
468//
469// std::vector<std::string> libs{
470// // "-L."
471// "-L/usr/lib/x86_64-linux-gnu",
472// "libnlc-rt.so",
473// "libc10.so",
474// "libtorch.so",
475// "libtorch_cpu.so",
476// "-lcrypt",
477// "-lzip",
478// "-lcurl",
479// "-lstdc++",
480//
481// // "-lm",
482// // "-lgcc_s",
483// // "-lgcc",
484// // "-lc",
485// // "-lgcc_s",
486// // "-lgcc",
487//
488// "-no-pie",
489// // "-dynamic-linker",
490// // "-Wl,-dynamic-linker",
491// // "-pie --eh-frame-hdr -m elf_x86_64 -dynamic-linker"
492// "-Wl,-rpath,./",
493// "-Wl,-rpath,/usr/lib/x86_64-linux-gnu",
494// ""};
495// ASSERT_TRUE(jit->LinkObjToExec("hello_rt",{"temp/main.o", "temp/hello.o"}, libs));
496//
497// // MakeLLVMModule
498// // ASSERT_NO_THROW(
499// // ASSERT_TRUE(jit->MakeCppExec(hello, "temp/hello", argsX));
500// // ) << hello;
501//
502// ASSERT_TRUE(std::filesystem::exists(std::filesystem::path("hello_rt")));
503//
504//
505//}
506//
507//TEST(JIT, REPL) {
508//
509//
510// std::filesystem::path path = std::filesystem::path("../examples/hello.src");
511// ASSERT_TRUE(std::filesystem::exists(path));
512//
513// std::ifstream file(path, std::ios::in | std::ios::binary);
514//
515// const auto sz = std::filesystem::file_size(path);
516// ASSERT_TRUE(sz);
517//
518// std::string source(sz, '\0');
519// file.read(source.data(), sz);
520// ASSERT_TRUE(file) << "error: only " << file.gcount() << " could be read";
521// file.close();
522//
523// TermPtr ast = Parser::ParseString(source);
524//
525// JIT *jit = JIT::ReCreate();
526// ASSERT(jit);
527//
528// std::string hello = jit->MakeCodeModule(ast, "hello", true);
529//
530// if (!std::filesystem::exists(std::filesystem::path("temp"))) {
531// std::filesystem::create_directories(std::filesystem::path("temp"));
532// }
533// ASSERT_TRUE(std::filesystem::exists(std::filesystem::path("temp")));
534// ASSERT_TRUE(std::filesystem::is_directory(std::filesystem::path("temp")));
535//
536// std::ofstream ofile(std::filesystem::path("temp/hello.cpp"), std::ios::out | std::ios::trunc);
537// ofile << hello;
538// ofile.close();
539//
540// std::string bin_out;
541//
542//
543// std::string opt_str = ReadFile("../build_options.txt");
544// ASSERT_TRUE(opt_str.size() > 100);
545//
546//
547//
548// std::vector<std::string> opts = RunTime::SplitChar(opt_str, " \t\r\n");
549//
550// opts.push_back("-I../lib");
551// opts.push_back("-DBUILD_UNITTEST");
552// opts.push_back("-DBUILD_DEBUG ");
553// opts.push_back("-DLOG_LEVEL_NORMAL=LOG_LEVEL_DEBUG");
554//
555// // opts.push_back("-triple");
556// // opts.push_back("x86_64-pc-linux-gnu");
557// // opts.push_back("-emit-obj");
558// //
559// // opts.push_back("-mrelocation-model");
560// // opts.push_back("pic");
561// // opts.push_back("-pic-level");
562// // opts.push_back("2");
563// // opts.push_back("-pic-is-pie");
564// //
565// // opts.push_back("-discard-value-names");
566// // opts.push_back("-disable-llvm-verifier");
567// //
568// // opts.push_back("-mrelax-all");
569// // opts.push_back("-disable-free");
570// // opts.push_back("-clear-ast-before-backend");
571// //
572// // opts.push_back("-mframe-pointer=all");
573// // opts.push_back("-fmath-errno");
574// // opts.push_back("-ffp-contract=on");
575// // opts.push_back("-fno-rounding-math");
576// // opts.push_back("-mconstructor-aliases");
577// //
578// // opts.push_back("-fcolor-diagnostics");
579// // opts.push_back("-faddrsig");
580// //
581// // opts.push_back("-fskip-odr-check-in-gmf");
582// //
583// // opts.push_back("-tune-cpu");
584// // opts.push_back("generic");
585// // opts.push_back("-target-cpu");
586// // opts.push_back("x86-64");
587// //
588// // opts.push_back("-cc1");
589// //
590// // opts.push_back("-funwind-tables=2");
591// // opts.push_back("-fdeprecated-macro");
592// // opts.push_back("-fgnuc-version=4.2.1");
593// // opts.push_back("-D__GCC_HAVE_DWARF2_CFI_ASM=1");
594//
595// for (auto &elem : opts) {
596// if (elem.find("-D") == 0) {
597// elem += " ";
598// }
599// std::cout << elem << "\n";
600// }
601//
602// ASSERT_TRUE(opts.size() > 20);
603//
604// std::vector<std::string> argsX{
605// // "-I", "/usr/include",
606// // "-I", "/usr/local/include",
607// // "-I", "/usr/include/c++/11",
608// // "-I", "/usr/include/x86_64-linux-gnu/c++/11",
609// // "-I", "/usr/include/x86_64-linux-gnu/",
610// // "-I", "/usr/lib/gcc/x86_64-linux-gnu/11/include",
611// };
612//
613// argsX.insert(argsX.end(), opts.begin(), opts.end());
614// // auto module = CompileCpp2(source, argsX);
615//
616//
617// std::string main_src = jit->MakeMain({});
618// std::ofstream omain(std::filesystem::path("temp/main.cpp"), std::ios::out | std::ios::trunc);
619// omain << main_src;
620// omain.close();
621//
622// std::unique_ptr<llvm::Module> main = jit->MakeLLVMModule(main_src, argsX, "temp");
623// ASSERT_TRUE(main);
624// ASSERT_TRUE(jit->MakeObjFile("temp/main.o", *main, argsX));
625//
626// std::unique_ptr<llvm::Module> module = jit->MakeLLVMModule(hello, argsX, "temp");
627// ASSERT_TRUE(module);
628// ASSERT_TRUE(jit->MakeObjFile("temp/hello.o", *module, argsX));
629//
630// std::vector<std::string> libs{
631// // "-L."
632// "-L/usr/lib/x86_64-linux-gnu",
633// "libnlc-rt.so",
634// "libc10.so",
635// "libtorch.so",
636// "libtorch_cpu.so",
637// "-lcrypt",
638// "-lzip",
639// "-lcurl",
640// "-lstdc++",
641//
642// // "-lm",
643// // "-lgcc_s",
644// // "-lgcc",
645// // "-lc",
646// // "-lgcc_s",
647// // "-lgcc",
648//
649// "-no-pie",
650// // "-dynamic-linker",
651// // "-Wl,-dynamic-linker",
652// // "-pie --eh-frame-hdr -m elf_x86_64 -dynamic-linker"
653// "-Wl,-rpath,./",
654// "-Wl,-rpath,/usr/lib/x86_64-linux-gnu",
655// ""};
656// ASSERT_TRUE(jit->LinkObjToExec("hello_rt",{"temp/main.o", "temp/hello.o"}, libs));
657//
658// // MakeLLVMModule
659// // ASSERT_NO_THROW(
660// // ASSERT_TRUE(jit->MakeCppExec(hello, "temp/hello", argsX));
661// // ) << hello;
662//
663// ASSERT_TRUE(std::filesystem::exists(std::filesystem::path("hello_rt")));
664//
665//
666//}
667//
668//
669//
670//
671//
672//
673//
1122//
1123//#endif // BUILD_UNITTEST