Optimization in Generators

What is the best practice for defining optimization rules for the generator of a language?


I have several ideas for this:


(1) The optimization rules could be implemented in the pre-processing scripts of the generator.

(2) Or another lower-level language could be defined, with the generator targeting this language, and some transformations could be done for optimization.

(3) Or the generator could generate complete external format outputs, e.g. in JSON, and the optimization is done in other tools. This seems suboptimal as a lot of information could be lost in the external format.


Thanks in advance.

1 comment
Comment actions Permalink

I don't know of anybody doing optimizations in their generator so I'm not aware of any practice, let alone a best practice :-) However, e.g. the closures language (jetbrains.mps.baseLanguage.closures) has a non-trivial generator so you might want to look at how it's implemented.

A preprocessing script could work if the optimization rule is simple.

If it's something more complex, I would use a separate mapping configuration for optimizations, because I find that using a DSL such as the generator language would make the transformations easier to write.

Generating JSON to feed an external tool seems like a lot of work. I would only do it if there already was a great external tool that expects JSON input and produces the final code. In that case though your problem changes from defining optimization rules to simply defining a generator from your language to JSON.


Please sign in to leave a comment.