ezrosent / frawk

an efficient awk-like language
Apache License 2.0
1.25k stars 35 forks source link

Is AOT compilation supported/planned? #99

Open fwip opened 1 year ago

fwip commented 1 year ago

If possible, I'd like to pre-compile frawk scripts to binary executables. This would make it easier for me to distribute the scripts I've written to places where it is difficult for me to get frawk installed. I've previously used awka, but it can be a little tough to get compiling and doesn't have as many nice features as frawk.

I've used frawk --dump-llvm to get LLVM IR for a given awk script, but I'm not sure if there's an easy way to get from here to a binary I can distribute - it looks like the generated IR still relies on the frawk runtime.

ezrosent commented 1 year ago

You're right about the --dump-llvm command not giving you runnable LLVM on its own. The LLVM frawk generates both relies on a runtime pointer being passed in and includes pointers to frawk's heap for string literals. frawk also generates different code based on the value of command-line flags.

The "simple" version of compiling frawk scripts ahead of time by simply packaging up a pre-built frawk and running it with the script could be annoying but doable. The issue there is that frawk will often try and use machine-specific instructions, so compiling on the source machine really can help performance.

The nicer, more awka-esque model would be for frawk to generate a small binary customized to a specific script would be a good deal harder. frawk would have to avoid some of its "tricks" around allocations, and more fundamentally we would have to split the runtime out into its own crate and link in its (say) LLVM with the awk program. That's something that would require a good deal more effort, though it's not impossible. I'm afraid it's unlikely that I'd get to it any time soon.

jemma-nelson commented 1 year ago

Thank for the reply and clear explanation!