When you do ``` cargo run -- --simplify-cfg --irviz test.png test.c ``` The `kecc` first tries to visualize the IR, then apply optimizations. This should not be intended, as right now there's no way to visualize the IR after optimizations.
KECC User's Manual
Usage
cargo run --features=build-bin -- [OPTIONS] <INPUT>
Command Line Options
Stage Selection Options
-
-p,--printRun the C AST printer, print the generated C AST from the input C file.
-
-i,--irgenRun the IRgen, print the generated IR from the input C file.
-
no stage selection option
If no stage selection option is specified, print the generated Assembly from the input C or IR file.
IR Optimization Options
-
-OEnable all optimizations (simpilfy-cfg, mem2reg, gvn, deadcode) supported in KECC.
-
--simplify-cfgPerform simplify-cfg.
-
--mem2regPerform mem2reg.
-
--gvnPerform global value numbering.
-
--deadcodePerform deadcode elimination.
Driver Options
-
-h,--helpDisplay available options.
-
-o,--output<FILE>Write output to <FILE>.
-
--parseParse the input C file. If parse failed, it returns the error message.
-
--iroutputPrint the output IR.
-
--irparseParse the input IR file. If parse failed, it returns the error message.
-
--irprintPrint the input IR AST.
-
--irrunExecute the input IR file and print the return value.
-
--irviz<FILE>Save visualized IR file to <FILE>.
graphvizpackage need to be installed. -
-V,--versionPrint the version information.
Examples
Homework 1
-
Print the generated C AST from
examples/c/fibonacci.ccargo run --features=build-bin -- -p examples/c/fibonacci.c
Homework 2
-
Print the generated IR from
examples/c/fibonacci.ccargo run --features=build-bin -- -i examples/c/fibonacci.c -
Save the IR visualization of generated IR from
examples/c/fibonacci.ctofibonacci.pngcargo run --features=build-bin -- --irviz fibonacci.png examples/c/fibonacci.c -
Interpret generated IR from
examples/c/fibonacci.ccargo run --features=build-bin -- --irrun examples/c/fibonacci.c
Homework 3
-
Perform simplify-cfg to
examples/simplify_cfg/const_prop.input.irand print the optimized IRcargo run --features=build-bin -- --iroutput --simplify-cfg examples/simplify_cfg/const_prop.input.ir
Homework 4
-
Perform mem2reg to
examples/mem2reg/mem2reg.input.irand print the optimized IRcargo run --features=build-bin -- --iroutput --mem2reg examples/mem2reg/mem2reg.input.ir
Homework 5
-
Perform global value numbering to
examples/gvn/gvn.input.irand print the optimized IRcargo run --features=build-bin -- --iroutput --gvn examples/gvn/gvn.input.ir
Homework 6
-
Perform deadcode elimination to
examples/deadcode/deadcode.input.irand print the optimized IRcargo run --features=build-bin -- --iroutput --deadcode examples/deadcode/deadcode.input.ir
Homework 7
-
Print the generated Assembly from
examples/c/fibonacci.candexamples/ir0/fibonacci.ircargo run --features=build-bin -- examples/c/fibonacci.c # Generate Assembly from `examples/c/fibonacci.c` cargo run --features=build-bin -- examples/ir0/fibonacci.ir # Generate Assembly from `examples/ir0/fibonacci.ir` -
Print the generated Assembly from
examples/c/fibonacci.candexamples/ir0/fibonacci.irwith all IR optimizations enabledcargo run --features=build-bin -- -O examples/c/fibonacci.c # Generate Assembly from `examples/c/fibonacci.c` cargo run --features=build-bin -- -O examples/ir0/fibonacci.ir # Generate Assembly from `examples/ir0/fibonacci.ir`