drewrip / rascal

1 stars 0 forks source link

Add option to emit IR and C code #8

Closed drewrip closed 1 month ago

drewrip commented 1 month ago

I came up with a pretty simple IR that I'm hoping to use for both backends. This was in hope of creating an easier representation to translate to the target. It is simple a vector of IRNode's (see src/ir.rs). Basically the idea is that it should be read from top to bottom to produce code even though it also contains a notion of scope. Anyways, that's not super important, but just some background.

What I'd like to do is to add a command line option --emit that lets you specify which intermediate representations to dump on the way to the final target. This would be similar to how the Rust --emit flag works.

For instance:

rascalc fib.ras -o fib --emit=ir

should dump a representation of the IR to a file. Or --emit=ir,C, should dump both the IR and the C source code. Currently we always dump the C source code, however this shouldn't be the default.

In essence we want to be able to serialize the state.build_stack here (which is a Vec<IRNode>) into a <outfile>.ir file.

Then after we can produce these representations, we'll want to create the ability to start the compilation directly from the IR file, but thats a follow up for sure.

drewrip commented 1 month ago

@THE-COB Let me know if this looks interesting!

drewrip commented 1 month ago

Currently the code uses the Clap library, so the CLI arguments are represented here.

THE-COB commented 1 month ago

@THE-COB Let me know if this looks interesting!

This looks excellent

drewrip commented 1 month ago

Implemented by #9