This repo contains optimizer for lama byte code.
This repo is using cabal toolchain for haskell code compilation and nix to
override some of hackage packages. Although it's should be possible to build project without nix
with cabal.project overrides (see build-without-nix branch) it's not guaranteed and highly
recommended to use nix since it will guarantee concrete ghc, hackage packages and hls versions.
To enter devenv you should use
$ nix develop
or install direnv and use
$ direnv allow
to automatically enter into nix shell in project directory. After that
$ cabal build optimizer-exe
will be available.
Main use case has form of
$ optimizer-exe compile --target <filename>.sm --dep <dep_1>.sm ... --dep <dep_n>.sm
which will produce <filename>.osm file that can be consumed by lama compiler.
For examples files and samples directory can be used. For the rest of available flags use
$ optimizer-exe compile --help.
Entry point to optimizer is StackMachine module which contains parser of .sm files.
Transition to register machine happens in StackRegTrans module and optimization IR build
in RegisterMachine.BasicBlock and RegisterMachine.FlowGraph modules.
Since most of optimizations work on IR build upon register machine, they could be found under
RegisterMachine namespace. Optimization pipeline can be found in RegisterMachine.Optimization
module. Building and optimization pass of additional codegen IR can found under RegisterMachine.FlatFlowGraph. After all optimization passes RegisterMachine.Lowering module is responsible for compiling IR back to stack machine code.
For debugging optimizations --dump-dot flag available under compile command. It will dump
.dot files than can be rendered by graphviz dot utility. render.sh can be used to render
dot files and open it in reader of choice (set by SVG_READER env, firefox by default).