Not logged inOpenClonk Forum
Up Topic Development / Developer's Corner / c4script jit compiler through llvm
- - By ker Date 2014-09-07 12:37
Hi everyone,

I'm writing a jit compiler at work. If interest is large enough, I'd port the c4script compiler to llvm (or at least a c4-assembler to machine code compiler and execution engine).
The only forum-quote about llvm that i found is from 2010

> Isilkor: I have actually already looked at and built LLVM, but the resulting libraries are too large for my taste (we're talking about roughly doubling of the size of the executable). url to quote


this might actually be an issue, but a lot of stuff can probably be optimized away with link time optimizations. Can't say for sure what'll happen there.

Another issue is windows. I can only promise msvc-built llvm libraries. I have not gotten llvm to work under mingw.
Running this stuff on linux is trivial, and should be on mac.

greetings

/ker
Parent - - By PeterW [de] Date 2014-09-07 15:26
Nice work! Had a stab at it once, but got stuck thinking about the design decisions. Do you generate code for type checks? Can you support stack traces?
Parent - By ker [de] Date 2014-09-10 17:55
type checks are possible with llvm, but stuff like overloading and similar needs to be done manually.
stack traces on the other hand are trivial, ever single assembler instruction allows you to have a filename, line number and column index.
the only issue I see is killing the whole application through bugs, i haven't worked with lldb as a library yet, but it should be able to run the code safely.
Parent - By Caesar [de] Date 2014-09-11 17:48 Edited 2014-09-11 17:55
Definitely interesting. I once fooled around with llvm and c4script a little, and the largest problem is definitely our type system.

If you realize all access to variables as calls to C4Value, you can save yourself the trouble of using llvm. Compiling all the type conversions to llvm, on the other hand side, will probably result in bloat code. What I did was to have a check that makes sure types are equal and handles the rest of the magic with a call to C++ code.

Another thing I noticed was that LLVM didn't optimize out those checks quite as often as I'd be comfortable with. That might be a nice reason to play with abstract interpretation.

https://github.com/jcaesar/C4C/blob/master/main.cpp
What I did there was merely to translate some kind of representation (I'm hesitant to call it a syntax tree, it's more of a semantics tree) to llvm. I did run into llvm SEGVing or giving up without a real error message a lot. Is that normal, or am I just too dumb to use it right?

Another thing: If you're doing llvm, you may want a few new keywords to declare variables and maybe even locals and globals that can only hold one type.

(At some point of thinking I was just like "Why the hell write more for C4Script? Better write a C4Script / Haskell interface and be done with it.)
(Also, please don't look at the register naming schema from my code. It sucks. It would have been better to generate a name for all instructions that belong to a group (c4script line maybe) and then just number them.)

Ah, right, Isilceur had something that converted C4Script to a syntax tree and compiled it from that. Might be of interest to you.
Up Topic Development / Developer's Corner / c4script jit compiler through llvm

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill