Nutzt jemand Runtime kompilierung per libclang/LLVM?
-
Ich brauche für ein Projekt eine schnelle/einfache "Scriptsprache" d.h. die Sprache-Features werden wohl sehr eingeschränkt sein - möglichweise sogar eine einfache grafische Programmierung mit If/Else/Loop-Knoten in einem Graph. Damit soll ein System für 2D/3D Daten Vearbeitung flexibler werden - aber trotzdem noch sehr performant (ich werde aber noch Benchmarks machen um den Einfluss der "Programmierbarkeit" in dem System zu beurteilen)
jetzt stellt sich mir die Frage ob es wohl sinnvoll sein könnte mit LLVM/libclang diese "Sprache" in C auszudrücken und diese dann zur Laufzeit zu kompilieren und auszuführen
Es gibt viele Beispiele im Internet zur Nutzung von libclang und LLVM für sowas
z.B.
https://weliveindetail.github.io/blog/post/2017/07/25/compile-with-clang-at-runtime-simple.html
https://github.com/weliveindetail/JitFromScratch/blob/jit-from-source/cpp-clang/JitFromScratch.cpp
https://stackoverflow.com/questions/34828480/generate-assembly-from-c-code-in-memory-using-libclang
http://fdiv.net/2012/08/15/compiling-code-clang-apiLua, Chaiscript usw. schließe ich nicht kategorisch aus - aber jetzt interessiert mich für die Sondierung erstmal nur die LLVM-Welt (oder vergleichbares)
Hat jemand damit Erfahrung und möchte ein bisschen aus dem Nähkästchen plaudern?
Kann man z.B. einen normalen Debugger auf dem erzeugten Code nutzen, oder was sind gute Strategien für den Datenaustausch zwischen dem statischen Code dynamischen System, Stackprobleme, Kompilier/Codegenerierzeiten, usw...
-
Ich kann dir nicht direkt antworten leider, aber ich kann 2 Dinge sagen:
Ich hatte ChaiScript ausprobieren wollen und es ist nicht im Debugmodus mit g++ compilierbar. Vielleicht hat sich das geändert, war damals aber so, wegen der dummen idee ein so fettes Teil Header Only zu machen. Es ist ein Monster.
Ich habe mal TinyCC benutzt, ein C Compiler, der blitzschnell übersetzt und sich direkt einbinden lässt. https://github.com/TinyCC/tinycc
Das kann ich auf jeden Fall empfehlen (hab tinycc auch mit mingw übersetzt bekommen)
-
In diesem Zusammenhang möchte ich auch einmal auf die Datenanalysesoftware ROOT bzw. den enthaltenen C++-Interpreter Cling hinweisen.
-
Chaiscript könnte vielleicht von der Performanz noch passen - an TCC hatte ich auch schon gedacht, schön wäres es eben wenn ich nicht unbedingt übers Dateisystem mit Dll-Loading arbeiten müsste
Cling und ROOT kenne ich - möchte aber eigentlich bei der Stufe - "Führ das mal aus" stehen bleiben und nicht auch noch in ein On-the-fly Ändern reinlaufen, ich denke das sind tolle Features aber ist mir in meinem Einsatzfeld zu kritisch, klar kann ich dieses "Änderbar zur Laufzeit" Feature nicht nutzen - habe aber dann immer noch den Overhead der sich wegen dieser Forderung ergibt, speziell Cling ist ja gezielt für Sofort-anpassbarkeit entworfen
im Bereich Hot-Reloading oder On-the-fly Veränderbarkeit gibt es ja noch:
https://github.com/RuntimeCompiledCPlusPlus/RuntimeCompiledCPlusPlus
und viele andere dieser Art:
https://github.com/RuntimeCompiledCPlusPlus/RuntimeCompiledCPlusPlus/wiki/Alternatives
-
https://github.com/jmmartinez/easy-just-in-time sieht auch ganz interessant aus
https://vtalks.net/talk/easyjit-just-in-time-compilation-for-c/