├── .github ├── brilck-matcher.json ├── tap-matcher.json └── workflows │ ├── build.yaml │ ├── docs.yaml │ ├── python.yaml │ └── rust.yaml ├── .gitignore ├── .zed └── settings.json ├── LICENSE ├── Makefile ├── README.md ├── benchmarks ├── .gitignore ├── Makefile ├── README.md ├── core │ ├── ackermann.bril │ ├── ackermann.out │ ├── ackermann.prof │ ├── armstrong.bril │ ├── armstrong.out │ ├── armstrong.prof │ ├── bbs.bril │ ├── bbs.out │ ├── bbs.prof │ ├── binary-fmt.bril │ ├── binary-fmt.out │ ├── binary-fmt.prof │ ├── binpow.bril │ ├── binpow.out │ ├── binpow.prof │ ├── bitshift.bril │ ├── bitshift.out │ ├── bitshift.prof │ ├── bitwise-ops.bril │ ├── bitwise-ops.out │ ├── bitwise-ops.prof │ ├── catalan.bril │ ├── catalan.out │ ├── catalan.prof │ ├── check-primes.bril │ ├── check-primes.out │ ├── check-primes.prof │ ├── collatz.bril │ ├── collatz.out │ ├── collatz.prof │ ├── combination.bril │ ├── combination.out │ ├── combination.prof │ ├── delannoy.bril │ ├── delannoy.out │ ├── delannoy.prof │ ├── digital-root.bril │ ├── digital-root.out │ ├── digital-root.prof │ ├── euclid.bril │ ├── euclid.out │ ├── euclid.prof │ ├── fact.bril │ ├── fact.out │ ├── fact.prof │ ├── factors.bril │ ├── factors.out │ ├── factors.prof │ ├── fib_recursive.bril │ ├── fib_recursive.out │ ├── fib_recursive.prof │ ├── fitsinside.bril │ ├── fitsinside.out │ ├── fitsinside.prof │ ├── fizz-buzz.bril │ ├── fizz-buzz.out │ ├── fizz-buzz.prof │ ├── gcd.bril │ ├── gcd.out │ ├── gcd.prof │ ├── gebmm.bril │ ├── gebmm.out │ ├── gebmm.prof │ ├── geometric-sum.bril │ ├── geometric-sum.out │ ├── geometric-sum.prof │ ├── hamming.bril │ ├── hamming.out │ ├── hamming.prof │ ├── hanoi.bril │ ├── hanoi.out │ ├── hanoi.prof │ ├── is-decreasing.bril │ ├── is-decreasing.out │ ├── is-decreasing.prof │ ├── karatsuba.bril │ ├── karatsuba.out │ ├── karatsuba.prof │ ├── lcm.bril │ ├── lcm.out │ ├── lcm.prof │ ├── loopfact.bril │ ├── loopfact.out │ ├── loopfact.prof │ ├── mccarthy91.bril │ ├── mccarthy91.out │ ├── mccarthy91.prof │ ├── mod_inv.bril │ ├── mod_inv.out │ ├── mod_inv.prof │ ├── mod_pow.bril │ ├── mod_pow.out │ ├── mod_pow.prof │ ├── montgomery.bril │ ├── montgomery.out │ ├── montgomery.prof │ ├── orders.bril │ ├── orders.out │ ├── orders.prof │ ├── palindrome.bril │ ├── palindrome.out │ ├── palindrome.prof │ ├── pascals-row.bril │ ├── pascals-row.out │ ├── pascals-row.prof │ ├── perfect.bril │ ├── perfect.out │ ├── perfect.prof │ ├── permutation.bril │ ├── permutation.out │ ├── permutation.prof │ ├── primes-between.bril │ ├── primes-between.out │ ├── primes-between.prof │ ├── pythagorean_triple.bril │ ├── pythagorean_triple.out │ ├── pythagorean_triple.prof │ ├── quadratic.bril │ ├── quadratic.out │ ├── quadratic.prof │ ├── recfact.bril │ ├── recfact.out │ ├── recfact.prof │ ├── rectangles-area-difference.bril │ ├── rectangles-area-difference.out │ ├── rectangles-area-difference.prof │ ├── relative-primes.bril │ ├── relative-primes.out │ ├── relative-primes.prof │ ├── reverse.bril │ ├── reverse.out │ ├── reverse.prof │ ├── rot13.bril │ ├── rot13.out │ ├── rot13.prof │ ├── sqrt_bin_search.bril │ ├── sqrt_bin_search.out │ ├── sqrt_bin_search.prof │ ├── sum-bits.bril │ ├── sum-bits.out │ ├── sum-bits.prof │ ├── sum-check.bril │ ├── sum-check.out │ ├── sum-check.prof │ ├── sum-digits.bril │ ├── sum-digits.out │ ├── sum-digits.prof │ ├── sum-divisors.bril │ ├── sum-divisors.out │ ├── sum-divisors.prof │ ├── sum-sq-diff.bril │ ├── sum-sq-diff.out │ ├── sum-sq-diff.prof │ ├── totient.bril │ ├── totient.out │ ├── totient.prof │ ├── up-arrow.bril │ ├── up-arrow.out │ └── up-arrow.prof ├── float │ ├── birthday.bril │ ├── birthday.out │ ├── birthday.prof │ ├── conjugate-gradient.bril │ ├── conjugate-gradient.out │ ├── conjugate-gradient.prof │ ├── cordic.bril │ ├── cordic.out │ ├── cordic.prof │ ├── euler.bril │ ├── euler.out │ ├── euler.prof │ ├── exponentiation-by-squaring.bril │ ├── exponentiation-by-squaring.out │ ├── exponentiation-by-squaring.prof │ ├── leibniz.bril │ ├── leibniz.out │ ├── leibniz.prof │ ├── logistic.bril │ ├── logistic.out │ ├── logistic.prof │ ├── mandelbrot.bril │ ├── mandelbrot.out │ ├── mandelbrot.prof │ ├── n_root.bril │ ├── n_root.out │ ├── n_root.prof │ ├── newton.bril │ ├── newton.out │ ├── newton.prof │ ├── norm.bril │ ├── norm.out │ ├── norm.prof │ ├── pow.bril │ ├── pow.out │ ├── pow.prof │ ├── ray-bbox-intersection.bril │ ├── ray-bbox-intersection.out │ ├── ray-bbox-intersection.prof │ ├── ray-sphere-intersection.bril │ ├── ray-sphere-intersection.out │ ├── ray-sphere-intersection.prof │ ├── riemann.bril │ ├── riemann.out │ ├── riemann.prof │ ├── sqrt.bril │ ├── sqrt.out │ ├── sqrt.prof │ └── sqrt.ts ├── long │ ├── dead-branch.bril │ ├── dead-branch.out │ ├── dead-branch.prof │ └── function_call.bril ├── mem │ ├── 1dconv.bril │ ├── 1dconv.out │ ├── 1dconv.prof │ ├── 2dconvol.bril │ ├── 2dconvol.out │ ├── 2dconvol.prof │ ├── adj2csr.bril │ ├── adj2csr.out │ ├── adj2csr.prof │ ├── adler32.bril │ ├── adler32.out │ ├── adler32.prof │ ├── binary-search.bril │ ├── binary-search.out │ ├── binary-search.prof │ ├── bubblesort.bril │ ├── bubblesort.out │ ├── bubblesort.prof │ ├── char-poly.bril │ ├── char-poly.out │ ├── char-poly.prof │ ├── connected-components.bril │ ├── connected-components.out │ ├── connected-components.prof │ ├── cordic.bril │ ├── cordic.out │ ├── cordic.prof │ ├── csrmv.bril │ ├── csrmv.out │ ├── csrmv.prof │ ├── dot-product.bril │ ├── dot-product.out │ ├── dot-product.prof │ ├── eight-queens.bril │ ├── eight-queens.out │ ├── eight-queens.prof │ ├── fib.bril │ ├── fib.out │ ├── fib.prof │ ├── fnv1-hash.bril │ ├── fnv1-hash.out │ ├── fnv1-hash.prof │ ├── major-elm.bril │ ├── major-elm.out │ ├── major-elm.prof │ ├── mat-mul.bril │ ├── mat-mul.out │ ├── mat-mul.prof │ ├── max-subarray.bril │ ├── max-subarray.out │ ├── max-subarray.prof │ ├── primitive-root.bril │ ├── primitive-root.out │ ├── primitive-root.prof │ ├── quickselect.bril │ ├── quickselect.out │ ├── quickselect.prof │ ├── quicksort-hoare.bril │ ├── quicksort-hoare.out │ ├── quicksort-hoare.prof │ ├── quicksort.bril │ ├── quicksort.out │ ├── quicksort.prof │ ├── shufflesort.bril │ ├── shufflesort.out │ ├── shufflesort.prof │ ├── sieve.bril │ ├── sieve.out │ ├── sieve.prof │ ├── sorting-network-five.bril │ ├── sorting-network-five.out │ ├── sorting-network-five.prof │ ├── two-sum.bril │ ├── two-sum.out │ ├── two-sum.prof │ ├── vsmul.bril │ ├── vsmul.out │ └── vsmul.prof ├── mixed │ ├── brilirs-only │ │ ├── fast-inverse-sqrt.bril │ │ ├── fast-inverse-sqrt.out │ │ └── fast-inverse-sqrt.prof │ ├── cholesky.bril │ ├── cholesky.out │ ├── cholesky.prof │ ├── gol.bril │ ├── gol.out │ ├── gol.prof │ ├── mat-inv.bril │ ├── mat-inv.out │ ├── mat-inv.prof │ ├── random_walk.bril │ ├── random_walk.out │ └── random_walk.prof ├── plot.vl.json ├── summarize.py └── turnt.toml ├── book.toml ├── brench ├── .gitignore ├── brench.py ├── example.toml └── pyproject.toml ├── bril-llvm ├── README.md ├── brilc ├── brilpy.py ├── dom.py ├── linkedlist.bril ├── point.bril └── ssa.py ├── bril-ocaml ├── .gitignore ├── .ocamlformat ├── bril.opam ├── count │ ├── count.ml │ └── dune ├── dune-project ├── dune-workspace ├── lib │ ├── bril.ml │ ├── bril.mli │ ├── bril_type.ml │ ├── bril_type.mli │ ├── common.ml │ ├── common.mli │ ├── const.ml │ ├── const.mli │ ├── dest.ml │ ├── dest.mli │ ├── dune │ ├── func.ml │ ├── func.mli │ ├── instr.ml │ ├── instr.mli │ ├── op.ml │ └── op.mli └── test │ └── count │ ├── bools.bril │ ├── bools.out │ ├── empty.bril │ ├── empty.out │ ├── floats.bril │ ├── floats.out │ ├── funcs.bril │ ├── funcs.out │ ├── ints.bril │ ├── ints.out │ ├── ptr.bril │ ├── ptr.out │ └── turnt.toml ├── bril-rs ├── .gitignore ├── Cargo.toml ├── Makefile ├── README.md ├── bril2json │ ├── .gitignore │ ├── Cargo.toml │ ├── README.md │ ├── build.rs │ └── src │ │ ├── bril_grammar.lalrpop │ │ ├── cli.rs │ │ ├── lib.rs │ │ └── main.rs ├── brild │ ├── Cargo.toml │ ├── README.md │ └── src │ │ ├── cli.rs │ │ ├── error.rs │ │ ├── lib.rs │ │ └── main.rs ├── brillvm │ ├── .gitignore │ ├── Cargo.toml │ ├── Makefile │ ├── README.md │ ├── runtime │ │ ├── Cargo.toml │ │ ├── build.rs │ │ └── src │ │ │ └── main.rs │ └── src │ │ ├── cli.rs │ │ ├── lib.rs │ │ ├── llvm.rs │ │ └── main.rs ├── examples │ └── bril2txt.rs ├── rs2bril │ ├── Cargo.toml │ ├── README.md │ ├── example.rs │ └── src │ │ ├── cli.rs │ │ ├── lib.rs │ │ └── main.rs └── src │ ├── abstract_program.rs │ ├── conversion.rs │ ├── lib.rs │ └── program.rs ├── bril-swift ├── .gitignore ├── Package.swift ├── Sources │ └── Bril │ │ ├── Argument.swift │ │ ├── BrilParseError.swift │ │ ├── Code.swift │ │ ├── Function.swift │ │ ├── Instruction.swift │ │ ├── Operations │ │ ├── ConstantOperation.swift │ │ ├── EffectOperation.swift │ │ ├── Operation.swift │ │ └── ValueOperation.swift │ │ ├── Program.swift │ │ └── Type.swift └── Tests │ └── BrilTests │ └── BrilTests.swift ├── bril-ts ├── bril.ts ├── builder.ts ├── mem.d.ts ├── types.ts └── util.ts ├── bril-txt ├── briltxt.py └── pyproject.toml ├── bril-vim ├── ftdetect │ └── bril.vim ├── ftplugin │ └── bril.vim └── syntax │ └── bril.vim ├── bril2json-rs ├── .gitignore ├── Cargo.lock ├── Cargo.toml ├── README.md ├── parse-error.bril ├── src │ ├── lib.rs │ └── main.rs └── test.py ├── brilck.ts ├── brili.ts ├── brilift ├── .gitignore ├── Cargo.lock ├── Cargo.toml ├── Makefile ├── rt.c ├── run.sh └── src │ ├── lib.rs │ ├── main.rs │ ├── rt.rs │ └── translator.rs ├── brilirs ├── .gitignore ├── .rustfmt.toml ├── Cargo.toml ├── Makefile ├── README.md ├── build.rs ├── pgo.sh ├── plot.vl.json ├── src │ ├── basic_block.rs │ ├── check.rs │ ├── cli.rs │ ├── error.rs │ ├── interp.rs │ ├── lib.rs │ └── main.rs ├── todo_list.txt └── turnt.toml ├── docs ├── SUMMARY.md ├── intro.md ├── lang │ ├── README.md │ ├── bitcast.md │ ├── char.md │ ├── core.md │ ├── dynamic.md │ ├── float.md │ ├── import.md │ ├── memory.md │ ├── spec.md │ ├── ssa.md │ ├── ssa2.md │ ├── syntax.md │ └── wellformed.md └── tools │ ├── README.md │ ├── bench.md │ ├── brench.md │ ├── brilck.md │ ├── brilift.md │ ├── brilirs.md │ ├── flat-bril.md │ ├── infer.md │ ├── interp.md │ ├── ocaml.md │ ├── plugin.md │ ├── rust.md │ ├── swift.md │ ├── text.md │ ├── ts.md │ ├── ts2bril.md │ └── web-playground.md ├── examples ├── .gitignore ├── Makefile ├── README.md ├── cfg.py ├── cfg_dot.py ├── df.py ├── dom.py ├── form_blocks.py ├── from_ssa.py ├── is_ssa.py ├── lvn.py ├── normalize.py ├── ssa_brench.toml ├── ssa_plot.json ├── tdce.py ├── test │ ├── df │ │ ├── cond-args.bril │ │ ├── cond-args.cprop.out │ │ ├── cond-args.defined.out │ │ ├── cond-args.live.out │ │ ├── cond.bril │ │ ├── cond.cprop.out │ │ ├── cond.defined.out │ │ ├── cond.live.out │ │ ├── fact.bril │ │ ├── fact.cprop.out │ │ ├── fact.defined.out │ │ ├── fact.live.out │ │ └── turnt.toml │ ├── dom │ │ ├── loopcond.bril │ │ ├── loopcond.dom.json │ │ ├── loopcond.front.json │ │ ├── loopcond.tree.json │ │ ├── loopcond.ts │ │ ├── turnt.toml │ │ ├── while.bril │ │ ├── while.dom.json │ │ ├── while.front.json │ │ └── while.tree.json │ ├── from_ssa │ │ ├── basic.bril │ │ ├── basic.out │ │ ├── dead-set.bril │ │ ├── dead-set.out │ │ ├── ssa-simple.bril │ │ ├── ssa-simple.out │ │ ├── swap-problem.bril │ │ ├── swap-problem.out │ │ └── turnt.toml │ ├── lvn │ │ ├── clobber-arg.bril │ │ ├── clobber-arg.out │ │ ├── clobber-fold.bril │ │ ├── clobber-fold.out │ │ ├── clobber.bril │ │ ├── clobber.out │ │ ├── commute.bril │ │ ├── commute.out │ │ ├── divide-by-zero.bril │ │ ├── divide-by-zero.out │ │ ├── fold-comparisons.bril │ │ ├── fold-comparisons.out │ │ ├── idchain-nonlocal.bril │ │ ├── idchain-nonlocal.out │ │ ├── idchain-prop.bril │ │ ├── idchain-prop.out │ │ ├── idchain.bril │ │ ├── idchain.out │ │ ├── logical-operators.bril │ │ ├── logical-operators.out │ │ ├── nonlocal-clobber.bril │ │ ├── nonlocal-clobber.out │ │ ├── nonlocal.bril │ │ ├── nonlocal.out │ │ ├── reassign.bril │ │ ├── reassign.out │ │ ├── redundant-dce.bril │ │ ├── redundant-dce.out │ │ ├── redundant.bril │ │ ├── redundant.out │ │ ├── rename-fold.bril │ │ ├── rename-fold.out │ │ └── turnt.toml │ ├── ssa │ │ ├── if-orig.bril │ │ ├── if-orig.out │ │ ├── if-ssa.bril │ │ ├── if-ssa.out │ │ ├── loop-orig.bril │ │ ├── loop-orig.out │ │ ├── loop-ssa.bril │ │ ├── loop-ssa.out │ │ └── turnt.toml │ ├── ssa_roundtrip │ │ ├── argwrite.bril │ │ ├── argwrite.out │ │ ├── if-const.bril │ │ ├── if-const.out │ │ ├── if-ssa.bril.BROKEN │ │ ├── if-ssa.out │ │ ├── if.bril │ │ ├── if.out │ │ ├── loop-branch.bril │ │ ├── loop-branch.out │ │ ├── loop.bril │ │ ├── loop.out │ │ ├── selfloop.bril │ │ ├── selfloop.out │ │ ├── turnt.toml │ │ ├── while.bril │ │ └── while.out │ ├── tdce │ │ ├── combo.bril │ │ ├── combo.out │ │ ├── diamond.bril │ │ ├── diamond.out │ │ ├── double-pass.bril │ │ ├── double-pass.out │ │ ├── double.bril │ │ ├── double.out │ │ ├── reassign-dkp.bril │ │ ├── reassign-dkp.out │ │ ├── reassign.bril │ │ ├── reassign.out │ │ ├── simple.bril │ │ ├── simple.out │ │ ├── skipped.bril │ │ ├── skipped.out │ │ └── turnt.toml │ └── to_ssa │ │ ├── argwrite.bril │ │ ├── argwrite.crude │ │ ├── argwrite.full │ │ ├── if-const.bril │ │ ├── if-const.crude │ │ ├── if-const.full │ │ ├── if.bril │ │ ├── if.crude │ │ ├── if.full │ │ ├── loop-branch.bril │ │ ├── loop-branch.crude │ │ ├── loop-branch.full │ │ ├── loop.bril │ │ ├── loop.crude │ │ ├── loop.full │ │ ├── selfloop.bril │ │ ├── selfloop.crude │ │ ├── selfloop.full │ │ ├── turnt.toml │ │ ├── while.bril │ │ ├── while.crude │ │ └── while.full ├── to_ssa.py ├── to_ssa_crude.py └── util.py ├── fastbril ├── .gitignore ├── Makefile ├── README.md ├── bytecode.txt ├── config │ ├── base.cf │ ├── float.cf │ ├── mem.cf │ ├── ssa.cf │ └── types.cf ├── doc │ ├── .gitignore │ ├── auto │ │ └── main.el │ └── main.tex ├── docgen.awk ├── docgen.sh ├── lib │ └── lib.c ├── src │ ├── .gitignore │ ├── asm │ │ ├── armv8.h │ │ ├── asm.c │ │ ├── asm.h │ │ ├── linear-scan.c │ │ ├── linear-scan.h │ │ ├── to_abstract_asm.c │ │ ├── to_abstract_asm.h │ │ ├── trivial-regalloc.c │ │ └── trivial-regalloc.h │ ├── bril-insns │ │ ├── base.h │ │ ├── float.h │ │ ├── instrs.c │ │ ├── instrs.h │ │ ├── mem.h │ │ ├── ssa.h │ │ └── types.h │ ├── byte-io.c │ ├── byte-io.h │ ├── interp │ │ ├── interp.c │ │ └── interp.h │ ├── libs │ │ ├── hashmap.c │ │ ├── hashmap.h │ │ └── json.h │ ├── main.c │ ├── parser.c │ ├── parser.h │ ├── pretty-printer.c │ └── pretty-printer.h └── srcgen.awk ├── flat-bril ├── .gitignore ├── Cargo.lock ├── Cargo.toml ├── README.md ├── rustfmt.toml └── src │ ├── flatten.rs │ ├── interp.rs │ ├── json_roundtrip.rs │ ├── main.rs │ ├── memfile.rs │ ├── types.rs │ └── unflatten.rs ├── test ├── README.md ├── check │ ├── argtype.bril │ ├── argtype.err │ ├── badcall.bril │ ├── badcall.err │ ├── badconst.bril │ ├── badconst.err │ ├── badid.bril │ ├── badid.err │ ├── badmem.bril │ ├── badmem.err │ ├── char.bril │ ├── char.err │ ├── extra.bril │ ├── extra.err │ ├── labels.bril │ ├── labels.err │ ├── main-args.bril │ ├── main-args.err │ ├── mainret.bril │ ├── mainret.err │ ├── mem.bril │ ├── mem.err │ ├── missarg.bril │ ├── missarg.err │ ├── missdest.bril │ ├── missdest.err │ ├── printres.bril │ ├── printres.err │ ├── ptr.bril │ ├── ptr.err │ ├── speculate.bril │ ├── speculate.err │ ├── ssa.bril │ ├── ssa.err │ ├── tiny.bril │ ├── tiny.err │ ├── turnt.toml │ ├── typeconflict.bril │ ├── typeconflict.err │ ├── undef.bril │ └── undef.err ├── interp-error │ ├── char-error │ │ ├── badconversion.bril │ │ └── badconversion.err │ ├── core-error │ │ ├── call-nonvoid-return-nothing-error.bril │ │ ├── call-nonvoid-return-nothing-error.err │ │ ├── call-return-nothing-error.bril │ │ ├── call-return-nothing-error.err │ │ ├── call-return-wrong-type.bril │ │ ├── call-return-wrong-type.err │ │ ├── call-void-return-error.bril │ │ ├── call-void-return-error.err │ │ ├── call-wrong-argument-types.bril │ │ ├── call-wrong-argument-types.err │ │ ├── call-wrong-arity.bril │ │ ├── call-wrong-arity.err │ │ ├── call-wrong-declared-type.bril │ │ ├── call-wrong-declared-type.err │ │ ├── divide_by_zero.bril │ │ ├── divide_by_zero.err │ │ ├── duplicate_function.bril │ │ ├── duplicate_function.err │ │ ├── duplicate_main.bril │ │ ├── duplicate_main.err │ │ ├── undefined-func.bril │ │ └── undefined-func.err │ ├── dynamic-error │ │ ├── dynamic_error_simple.bril │ │ └── dynamic_error_simple.err │ ├── mem-error │ │ ├── double_free.bril │ │ ├── double_free.err │ │ ├── free_offset.bril │ │ ├── free_offset.err │ │ ├── leak.bril │ │ ├── leak.err │ │ ├── out_of_bounds.bril │ │ ├── out_of_bounds.err │ │ ├── out_of_bounds_2.bril │ │ ├── out_of_bounds_2.err │ │ ├── uninit_read.bril │ │ ├── uninit_read.err │ │ ├── wrong_write.bril │ │ └── wrong_write.err │ ├── spec-error │ │ ├── spec-call.bril │ │ ├── spec-call.err │ │ ├── spec-double-commit.bril │ │ ├── spec-double-commit.err │ │ ├── spec-nonspec-abort.bril │ │ ├── spec-nonspec-abort.err │ │ ├── spec-return-implicit.bril │ │ ├── spec-return-implicit.err │ │ ├── spec-return.bril │ │ └── spec-return.err │ ├── ssa-error │ │ ├── double-phi.err │ │ ├── missing-set.bril │ │ ├── missing-set.err │ │ ├── undef-add.bril │ │ ├── undef-add.err │ │ ├── undef-print.bril │ │ └── undef-print.err │ └── turnt.toml ├── interp │ ├── bitcast │ │ ├── float_and_int.bril │ │ └── float_and_int.out │ ├── char │ │ ├── char.bril │ │ ├── char.out │ │ ├── char_args.bril │ │ ├── char_args.out │ │ ├── char_ops.bril │ │ ├── char_ops.out │ │ ├── control_char.bril │ │ ├── control_char.out │ │ ├── conversions.bril │ │ └── conversions.out │ ├── core │ │ ├── add-overflow.bril │ │ ├── add-overflow.out │ │ ├── br.bril │ │ ├── br.out │ │ ├── call-with-args.bril │ │ ├── call-with-args.out │ │ ├── call.bril │ │ ├── call.out │ │ ├── dead_block.bril │ │ ├── dead_block.out │ │ ├── div.bril │ │ ├── div.out │ │ ├── jmp.bril │ │ ├── jmp.out │ │ ├── main-args.bril │ │ ├── main-args.out │ │ ├── main-bool-args.bril │ │ ├── main-bool-args.out │ │ ├── non_linear_control_flow.bril │ │ ├── non_linear_control_flow.out │ │ ├── nop.bril │ │ ├── nop.out │ │ ├── ret.bril │ │ ├── ret.out │ │ ├── tiny.bril │ │ └── tiny.out │ ├── dynamic │ │ ├── float_dynamic.bril │ │ ├── float_dynamic.out │ │ ├── mem_dynamic_dispatch.bril │ │ ├── mem_dynamic_dispatch.out │ │ ├── mem_dynamic_enum.bril │ │ ├── mem_dynamic_enum.out │ │ ├── mem_dynamic_struct.bril │ │ └── mem_dynamic_struct.out │ ├── float │ │ ├── float.bril │ │ ├── float.out │ │ ├── float_args.bril │ │ ├── float_args.out │ │ ├── float_divide_by_zero.bril │ │ ├── float_divide_by_zero.out │ │ ├── float_special.bril │ │ └── float_special.out │ ├── mem │ │ ├── access.bril │ │ ├── access.out │ │ ├── access_many.bril │ │ ├── access_many.out │ │ ├── access_ptr.bril │ │ ├── access_ptr.out │ │ ├── alloc.bril │ │ ├── alloc.out │ │ ├── alloc_large.bril │ │ ├── alloc_large.out │ │ ├── alloc_many.bril │ │ ├── alloc_many.out │ │ ├── fib.bril │ │ ├── fib.out │ │ ├── mem_id.bril │ │ ├── mem_id.out │ │ ├── ptr_call.bril │ │ ├── ptr_call.out │ │ ├── ptr_ret.bril │ │ └── ptr_ret.out │ ├── mixed │ │ ├── store-char.bril │ │ ├── store-char.out │ │ ├── store-float.bril │ │ └── store-float.out │ ├── spec │ │ ├── spec-abort.bril │ │ ├── spec-abort.out │ │ ├── spec-commit.bril │ │ ├── spec-commit.out │ │ ├── spec-nested.bril │ │ ├── spec-nested.out │ │ ├── spec-noabort.bril │ │ └── spec-noabort.out │ ├── ssa │ │ ├── ssa-simple.bril │ │ ├── ssa-simple.out │ │ ├── ssa-two-phi.bril │ │ ├── ssa-two-phi.out │ │ ├── ssu-regression.bril │ │ ├── ssu-regression.out │ │ ├── swap-problem.bril │ │ ├── swap-problem.out │ │ ├── undef.bril │ │ └── undef.out │ └── turnt.toml ├── linking │ ├── diamond.bril │ ├── diamond.out │ ├── link_ops.bril │ ├── link_ops.out │ ├── nested.bril │ ├── nested.out │ ├── recursive.bril │ ├── recursive.out │ └── turnt.toml ├── parse │ ├── add.bril │ ├── add.json │ ├── char.bril │ ├── char.json │ ├── comment.bril │ ├── comment.json │ ├── float.bril │ ├── float.json │ ├── mem.bril │ ├── mem.json │ ├── positions.bril │ ├── positions.json │ ├── print.bril │ ├── print.json │ └── turnt.toml ├── print │ ├── add.bril │ ├── add.json │ ├── call.bril │ ├── call.json │ ├── char.bril │ ├── char.json │ ├── eight-queens.bril │ ├── eight-queens.json │ ├── ptr.bril │ ├── ptr.json │ ├── spec-abort.bril │ ├── spec-abort.json │ └── turnt.toml ├── rs │ ├── ackermann.out │ ├── ackermann.rs │ ├── boolvar.out │ ├── boolvar.rs │ ├── call-explicit.out │ ├── call-explicit.rs │ ├── cholesky.out │ ├── cholesky.rs │ ├── cond.out │ ├── cond.rs │ ├── factorial.out │ ├── factorial.rs │ ├── float-add.out │ ├── float-add.rs │ ├── loopfact.out │ ├── loopfact.rs │ ├── nested_call.out │ ├── nested_call.rs │ ├── riemann.out │ ├── riemann.rs │ └── turnt.toml ├── ts-error │ ├── call-nonvoid-return-nothing.err │ ├── call-nonvoid-return-nothing.out │ ├── call-nonvoid-return-nothing.ts │ ├── call-return-nothing.err │ ├── call-return-nothing.out │ ├── call-return-nothing.ts │ ├── call-void-return.err │ ├── call-void-return.out │ ├── call-void-return.ts │ ├── call-wrong-arity.err │ ├── call-wrong-arity.out │ ├── call-wrong-arity.ts │ ├── call-wrong-declared-type.err │ ├── call-wrong-declared-type.out │ ├── call-wrong-declared-type.ts │ └── turnt.toml └── ts │ ├── boolvar.out │ ├── boolvar.ts │ ├── call-explicit-void.out │ ├── call-explicit-void.ts │ ├── call.out │ ├── call.ts │ ├── cond.out │ ├── cond.ts │ ├── factorial.out │ ├── factorial.ts │ ├── float-add.out │ ├── float-add.ts │ ├── loopfact.out │ ├── loopfact.ts │ ├── main.out │ ├── main.ts │ ├── memory-call.out │ ├── memory-call.ts │ ├── memory-loop.out │ ├── memory-loop.ts │ ├── memory-matrix.out │ ├── memory-matrix.ts │ ├── nested-call.out │ ├── nested-call.ts │ ├── printvar.out │ ├── printvar.ts │ ├── return.out │ ├── return.ts │ ├── simplified.out │ ├── simplified.ts │ └── turnt.toml ├── ts2bril.ts └── type-infer ├── Makefile ├── infer.py └── tests ├── fail-infer ├── arith_ops.bril ├── assign_label.bril ├── br.bril ├── comp_ops.bril ├── control_ops.bril ├── div.bril ├── idchain.bril ├── jmp.bril ├── logic_ops.bril ├── many_functions.bril ├── tricky-jump.bril └── turnt.toml ├── fail-typecheck ├── add.bril ├── arith_ops.bril ├── br.bril ├── comp_ops.bril ├── control_ops.bril ├── div.bril ├── idchain.bril ├── jmp.bril ├── logic_ops.bril ├── many_functions.bril ├── nop.bril ├── ret.bril ├── tiny.bril ├── tricky-jump.bril └── turnt.toml ├── infer ├── addarg.bril ├── addarg.tbril ├── arith_ops.bril ├── arith_ops.tbril ├── br.bril ├── br.tbril ├── comp_ops.bril ├── comp_ops.tbril ├── control_ops.bril ├── control_ops.tbril ├── div.bril ├── div.tbril ├── idchain.bril ├── idchain.tbril ├── jmp.bril ├── jmp.tbril ├── logic_ops.bril ├── logic_ops.tbril ├── many_functions.bril ├── many_functions.tbril ├── nop.bril ├── nop.tbril ├── ret.bril ├── ret.tbril ├── tiny.bril ├── tiny.tbril ├── tricky-jump.bril ├── tricky-jump.tbril └── turnt.toml ├── parse ├── add.bril ├── add.json ├── div.bril ├── div.json ├── partial.bril ├── partial.json └── turnt.toml ├── print ├── add.bril ├── add.json ├── div.bril ├── div.json ├── partial.bril ├── partial.json └── turnt.toml └── typecheck ├── arith_ops.bril ├── arith_ops.tbril ├── br.bril ├── br.tbril ├── comp_ops.bril ├── comp_ops.tbril ├── control_ops.bril ├── control_ops.tbril ├── div.bril ├── div.tbril ├── idchain.bril ├── idchain.tbril ├── jmp.bril ├── jmp.tbril ├── logic_ops.bril ├── logic_ops.tbril ├── many_functions.bril ├── many_functions.tbril ├── nop.bril ├── nop.tbril ├── ret.bril ├── ret.tbril ├── tiny.bril ├── tiny.tbril ├── tricky-jump.bril ├── tricky-jump.tbril └── turnt.toml /.github/brilck-matcher.json: -------------------------------------------------------------------------------- 1 | { 2 | "problemMatcher": [ 3 | { 4 | "owner": "brilck", 5 | "pattern": [{ 6 | "regexp": "^([^:]+):(\\d+):(\\d+): (.*)$", 7 | "file": 1, 8 | "line": 2, 9 | "column": 3, 10 | "message": "4" 11 | }] 12 | } 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /.github/workflows/python.yaml: -------------------------------------------------------------------------------- 1 | on: 2 | push: 3 | branches: 4 | - main 5 | pull_request: 6 | branches: 7 | - main 8 | 9 | jobs: 10 | ruff: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/checkout@v4 14 | 15 | - name: ruff check 16 | uses: astral-sh/ruff-action@v3 17 | 18 | - name: ruff format 19 | uses: astral-sh/ruff-action@v3 20 | with: 21 | args: "format --check --diff" 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | book/ 3 | venv/ 4 | node_modules/ 5 | .hypothesis/ 6 | .pytest_cache/ 7 | hypothesis_* 8 | __pycache__ 9 | .vscode 10 | 11 | **/*.o 12 | .DS_Store 13 | 14 | # vim swap files 15 | *.swp 16 | *.swo 17 | -------------------------------------------------------------------------------- /.zed/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "lsp": { 3 | "deno": { 4 | "settings": { 5 | "deno": { 6 | "enable": true 7 | } 8 | } 9 | } 10 | }, 11 | "languages": { 12 | "TypeScript": { 13 | "language_servers": [ 14 | "deno", 15 | "!typescript-language-server", 16 | "!vtsls", 17 | "!eslint" 18 | ], 19 | "formatter": "language_server" 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /benchmarks/.gitignore: -------------------------------------------------------------------------------- 1 | *.json 2 | bench.csv 3 | plot.svg 4 | -------------------------------------------------------------------------------- /benchmarks/Makefile: -------------------------------------------------------------------------------- 1 | BENCHMARKS := core/*.bril \ 2 | float/*.bril \ 3 | mem/*.bril \ 4 | mixed/*.bril 5 | 6 | .PHONY: bench clean plot 7 | bench: 8 | turnt -e bench --save $(BENCHMARKS) 9 | clean: 10 | rm -f **/*.bench.json plot.svg bench.csv bench.json 11 | plot: plot.svg 12 | 13 | bench.csv: $(wildcard **/*.bench.json) 14 | python3 summarize.py $^ > $@ 15 | 16 | %.svg: %.vl.json bench.csv 17 | npx --yes -p vega -p vega-lite vl2svg $*.vl.json > $@ 18 | -------------------------------------------------------------------------------- /benchmarks/core/ackermann.out: -------------------------------------------------------------------------------- 1 | 509 2 | -------------------------------------------------------------------------------- /benchmarks/core/ackermann.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 1464231 2 | -------------------------------------------------------------------------------- /benchmarks/core/armstrong.out: -------------------------------------------------------------------------------- 1 | true 2 | -------------------------------------------------------------------------------- /benchmarks/core/armstrong.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 133 2 | -------------------------------------------------------------------------------- /benchmarks/core/bbs.out: -------------------------------------------------------------------------------- 1 | 1 2 | 1 3 | 0 4 | 0 5 | 1 6 | 0 7 | -------------------------------------------------------------------------------- /benchmarks/core/bbs.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 137 2 | -------------------------------------------------------------------------------- /benchmarks/core/binary-fmt.out: -------------------------------------------------------------------------------- 1 | 1 2 | 0 3 | 0 4 | 0 5 | 0 6 | 0 7 | 0 8 | 0 9 | -------------------------------------------------------------------------------- /benchmarks/core/binary-fmt.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 100 2 | -------------------------------------------------------------------------------- /benchmarks/core/binpow.out: -------------------------------------------------------------------------------- 1 | 2048 2 | -------------------------------------------------------------------------------- /benchmarks/core/binpow.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 105 2 | -------------------------------------------------------------------------------- /benchmarks/core/bitshift.out: -------------------------------------------------------------------------------- 1 | 96 2 | 625 3 | -------------------------------------------------------------------------------- /benchmarks/core/bitshift.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 167 2 | -------------------------------------------------------------------------------- /benchmarks/core/bitwise-ops.out: -------------------------------------------------------------------------------- 1 | 7 2 | -------------------------------------------------------------------------------- /benchmarks/core/bitwise-ops.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 1690 2 | -------------------------------------------------------------------------------- /benchmarks/core/catalan.out: -------------------------------------------------------------------------------- 1 | 16796 2 | -------------------------------------------------------------------------------- /benchmarks/core/catalan.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 659378 2 | -------------------------------------------------------------------------------- /benchmarks/core/check-primes.out: -------------------------------------------------------------------------------- 1 | 0 2 | 1 3 | 1 4 | 0 5 | 1 6 | 0 7 | 1 8 | 0 9 | 0 10 | 0 11 | 1 12 | 0 13 | 1 14 | 0 15 | 0 16 | 0 17 | 1 18 | 0 19 | 1 20 | 0 21 | 0 22 | 0 23 | 1 24 | 0 25 | 0 26 | 0 27 | 0 28 | 0 29 | 1 30 | 0 31 | 1 32 | 0 33 | 0 34 | 0 35 | 0 36 | 0 37 | 1 38 | 0 39 | 0 40 | 0 41 | 1 42 | 0 43 | 1 44 | 0 45 | 0 46 | 0 47 | 1 48 | 0 49 | 0 50 | -------------------------------------------------------------------------------- /benchmarks/core/check-primes.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 8468 2 | -------------------------------------------------------------------------------- /benchmarks/core/collatz.out: -------------------------------------------------------------------------------- 1 | 7 2 | 22 3 | 11 4 | 34 5 | 17 6 | 52 7 | 26 8 | 13 9 | 40 10 | 20 11 | 10 12 | 5 13 | 16 14 | 8 15 | 4 16 | 2 17 | 1 18 | -------------------------------------------------------------------------------- /benchmarks/core/collatz.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 169 2 | -------------------------------------------------------------------------------- /benchmarks/core/combination.out: -------------------------------------------------------------------------------- 1 | 220 2 | -------------------------------------------------------------------------------- /benchmarks/core/combination.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 178 2 | -------------------------------------------------------------------------------- /benchmarks/core/delannoy.out: -------------------------------------------------------------------------------- 1 | 265729 2 | -------------------------------------------------------------------------------- /benchmarks/core/delannoy.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 5748752 2 | -------------------------------------------------------------------------------- /benchmarks/core/digital-root.out: -------------------------------------------------------------------------------- 1 | 4 2 | 9 3 | 15 4 | 6 5 | 10 6 | 1 7 | 4 8 | 10 9 | 1 10 | 6 11 | 10 12 | 1 13 | 7 14 | 7 15 | -------------------------------------------------------------------------------- /benchmarks/core/digital-root.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 247 2 | -------------------------------------------------------------------------------- /benchmarks/core/euclid.out: -------------------------------------------------------------------------------- 1 | 2 2 | -------------------------------------------------------------------------------- /benchmarks/core/euclid.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 563 2 | -------------------------------------------------------------------------------- /benchmarks/core/fact.out: -------------------------------------------------------------------------------- 1 | 2432902008176640000 2 | -------------------------------------------------------------------------------- /benchmarks/core/fact.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 229 2 | -------------------------------------------------------------------------------- /benchmarks/core/factors.out: -------------------------------------------------------------------------------- 1 | 2 2 | 2 3 | 3 4 | 5 5 | -------------------------------------------------------------------------------- /benchmarks/core/factors.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 72 2 | -------------------------------------------------------------------------------- /benchmarks/core/fib_recursive.out: -------------------------------------------------------------------------------- 1 | 55 2 | -------------------------------------------------------------------------------- /benchmarks/core/fib_recursive.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 2693 2 | -------------------------------------------------------------------------------- /benchmarks/core/fitsinside.out: -------------------------------------------------------------------------------- 1 | true 2 | -------------------------------------------------------------------------------- /benchmarks/core/fitsinside.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 10 2 | -------------------------------------------------------------------------------- /benchmarks/core/fizz-buzz.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 3652 2 | -------------------------------------------------------------------------------- /benchmarks/core/gcd.out: -------------------------------------------------------------------------------- 1 | 4 2 | -------------------------------------------------------------------------------- /benchmarks/core/gcd.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 46 2 | -------------------------------------------------------------------------------- /benchmarks/core/gebmm.out: -------------------------------------------------------------------------------- 1 | 188 2 | -------------------------------------------------------------------------------- /benchmarks/core/gebmm.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 3011 2 | -------------------------------------------------------------------------------- /benchmarks/core/geometric-sum.out: -------------------------------------------------------------------------------- 1 | 242 2 | -------------------------------------------------------------------------------- /benchmarks/core/geometric-sum.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 35 2 | -------------------------------------------------------------------------------- /benchmarks/core/hamming.out: -------------------------------------------------------------------------------- 1 | 2 2 | -------------------------------------------------------------------------------- /benchmarks/core/hamming.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 117 2 | -------------------------------------------------------------------------------- /benchmarks/core/hanoi.out: -------------------------------------------------------------------------------- 1 | 0 2 2 | 0 1 3 | 2 1 4 | 0 2 5 | 1 0 6 | 1 2 7 | 0 2 8 | -------------------------------------------------------------------------------- /benchmarks/core/hanoi.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 99 2 | -------------------------------------------------------------------------------- /benchmarks/core/is-decreasing.out: -------------------------------------------------------------------------------- 1 | true 2 | -------------------------------------------------------------------------------- /benchmarks/core/is-decreasing.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 127 2 | -------------------------------------------------------------------------------- /benchmarks/core/karatsuba.out: -------------------------------------------------------------------------------- 1 | 4267635650 2 | -------------------------------------------------------------------------------- /benchmarks/core/karatsuba.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 1548 2 | -------------------------------------------------------------------------------- /benchmarks/core/lcm.out: -------------------------------------------------------------------------------- 1 | 192 2 | -------------------------------------------------------------------------------- /benchmarks/core/lcm.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 2326 2 | -------------------------------------------------------------------------------- /benchmarks/core/loopfact.out: -------------------------------------------------------------------------------- 1 | 40320 2 | -------------------------------------------------------------------------------- /benchmarks/core/loopfact.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 116 2 | -------------------------------------------------------------------------------- /benchmarks/core/mccarthy91.out: -------------------------------------------------------------------------------- 1 | 91 2 | -------------------------------------------------------------------------------- /benchmarks/core/mccarthy91.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 1385 2 | -------------------------------------------------------------------------------- /benchmarks/core/mod_inv.out: -------------------------------------------------------------------------------- 1 | 2393 2 | -------------------------------------------------------------------------------- /benchmarks/core/mod_inv.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 558 2 | -------------------------------------------------------------------------------- /benchmarks/core/mod_pow.out: -------------------------------------------------------------------------------- 1 | 445 2 | -------------------------------------------------------------------------------- /benchmarks/core/mod_pow.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 243 2 | -------------------------------------------------------------------------------- /benchmarks/core/montgomery.out: -------------------------------------------------------------------------------- 1 | 11 2 | -------------------------------------------------------------------------------- /benchmarks/core/montgomery.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 17 2 | -------------------------------------------------------------------------------- /benchmarks/core/orders.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 5352 2 | -------------------------------------------------------------------------------- /benchmarks/core/palindrome.out: -------------------------------------------------------------------------------- 1 | true 2 | -------------------------------------------------------------------------------- /benchmarks/core/palindrome.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 298 2 | -------------------------------------------------------------------------------- /benchmarks/core/pascals-row.out: -------------------------------------------------------------------------------- 1 | 1 2 | 6 3 | 30 4 | 120 5 | 360 6 | 720 7 | -------------------------------------------------------------------------------- /benchmarks/core/pascals-row.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 146 2 | -------------------------------------------------------------------------------- /benchmarks/core/perfect.out: -------------------------------------------------------------------------------- 1 | 0 2 | -------------------------------------------------------------------------------- /benchmarks/core/perfect.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 232 2 | -------------------------------------------------------------------------------- /benchmarks/core/permutation.out: -------------------------------------------------------------------------------- 1 | 120 2 | -------------------------------------------------------------------------------- /benchmarks/core/permutation.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 130 2 | -------------------------------------------------------------------------------- /benchmarks/core/primes-between.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 574100 2 | -------------------------------------------------------------------------------- /benchmarks/core/pythagorean_triple.out: -------------------------------------------------------------------------------- 1 | 75 100 2 | 44 117 3 | 35 120 4 | -------------------------------------------------------------------------------- /benchmarks/core/pythagorean_triple.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 61518 2 | -------------------------------------------------------------------------------- /benchmarks/core/quadratic.out: -------------------------------------------------------------------------------- 1 | -1 2 | 3 3 | -------------------------------------------------------------------------------- /benchmarks/core/quadratic.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 785 2 | -------------------------------------------------------------------------------- /benchmarks/core/recfact.out: -------------------------------------------------------------------------------- 1 | 40320 2 | -------------------------------------------------------------------------------- /benchmarks/core/recfact.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 104 2 | -------------------------------------------------------------------------------- /benchmarks/core/rectangles-area-difference.out: -------------------------------------------------------------------------------- 1 | 50 2 | 78 3 | 28 4 | -------------------------------------------------------------------------------- /benchmarks/core/rectangles-area-difference.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 14 2 | -------------------------------------------------------------------------------- /benchmarks/core/relative-primes.out: -------------------------------------------------------------------------------- 1 | 19 2 | 17 3 | 13 4 | 11 5 | 9 6 | 7 7 | 3 8 | 1 9 | -------------------------------------------------------------------------------- /benchmarks/core/relative-primes.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 1923 2 | -------------------------------------------------------------------------------- /benchmarks/core/reverse.out: -------------------------------------------------------------------------------- 1 | 321 2 | -------------------------------------------------------------------------------- /benchmarks/core/reverse.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 46 2 | -------------------------------------------------------------------------------- /benchmarks/core/rot13.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 10 2 | # Compute the char shifted forward by 13 (0-indexed) 3 | @main(input: int) { 4 | aed: int = call @rot input; 5 | print aed; 6 | } 7 | @rot(n: int):int{ 8 | thirteen: int = const 13; 9 | twenty_six: int = const 26; 10 | shifted: int = add n thirteen; 11 | over: bool = ge shifted twenty_six; 12 | br over .if .else; 13 | .if: 14 | shifted: int = sub shifted twenty_six; 15 | .else: 16 | ret shifted; 17 | } 18 | -------------------------------------------------------------------------------- /benchmarks/core/rot13.out: -------------------------------------------------------------------------------- 1 | 23 2 | -------------------------------------------------------------------------------- /benchmarks/core/rot13.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 8 2 | -------------------------------------------------------------------------------- /benchmarks/core/sqrt_bin_search.out: -------------------------------------------------------------------------------- 1 | 6120 2 | -------------------------------------------------------------------------------- /benchmarks/core/sqrt_bin_search.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 744 2 | -------------------------------------------------------------------------------- /benchmarks/core/sum-bits.out: -------------------------------------------------------------------------------- 1 | 3 2 | -------------------------------------------------------------------------------- /benchmarks/core/sum-bits.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 73 2 | -------------------------------------------------------------------------------- /benchmarks/core/sum-check.out: -------------------------------------------------------------------------------- 1 | 500500 2 | 500500 3 | true 4 | -------------------------------------------------------------------------------- /benchmarks/core/sum-check.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 5018 2 | -------------------------------------------------------------------------------- /benchmarks/core/sum-digits.out: -------------------------------------------------------------------------------- 1 | 45 2 | -------------------------------------------------------------------------------- /benchmarks/core/sum-digits.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 219 2 | -------------------------------------------------------------------------------- /benchmarks/core/sum-divisors.out: -------------------------------------------------------------------------------- 1 | 1 2 | 100 3 | 2 4 | 50 5 | 4 6 | 25 7 | 5 8 | 20 9 | 10 10 | 217 11 | -------------------------------------------------------------------------------- /benchmarks/core/sum-divisors.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 159 2 | -------------------------------------------------------------------------------- /benchmarks/core/sum-sq-diff.out: -------------------------------------------------------------------------------- 1 | 25164150 2 | -------------------------------------------------------------------------------- /benchmarks/core/sum-sq-diff.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 3038 2 | -------------------------------------------------------------------------------- /benchmarks/core/totient.out: -------------------------------------------------------------------------------- 1 | 2023 2 | 1632 3 | -------------------------------------------------------------------------------- /benchmarks/core/totient.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 253 2 | -------------------------------------------------------------------------------- /benchmarks/core/up-arrow.out: -------------------------------------------------------------------------------- 1 | 65536 2 | -------------------------------------------------------------------------------- /benchmarks/core/up-arrow.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 252 2 | -------------------------------------------------------------------------------- /benchmarks/float/birthday.out: -------------------------------------------------------------------------------- 1 | 0.50729723432398566 2 | -------------------------------------------------------------------------------- /benchmarks/float/birthday.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 484 2 | -------------------------------------------------------------------------------- /benchmarks/float/conjugate-gradient.out: -------------------------------------------------------------------------------- 1 | 5.00000000000000000 2 | 3.00000000000000000 3 | 2.33333333333333348 4 | -------------------------------------------------------------------------------- /benchmarks/float/conjugate-gradient.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 1999 2 | -------------------------------------------------------------------------------- /benchmarks/float/cordic.out: -------------------------------------------------------------------------------- 1 | 0.86369602123419631 2 | -------------------------------------------------------------------------------- /benchmarks/float/cordic.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 517 2 | -------------------------------------------------------------------------------- /benchmarks/float/euler.out: -------------------------------------------------------------------------------- 1 | 2.71828182845904553 2 | -------------------------------------------------------------------------------- /benchmarks/float/euler.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 1908 2 | -------------------------------------------------------------------------------- /benchmarks/float/exponentiation-by-squaring.out: -------------------------------------------------------------------------------- 1 | 3.08394593452957709e+53 2 | 1.42202344098973190e+137 3 | -------------------------------------------------------------------------------- /benchmarks/float/exponentiation-by-squaring.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 187 2 | -------------------------------------------------------------------------------- /benchmarks/float/leibniz.out: -------------------------------------------------------------------------------- 1 | 3.14159365359077425 2 | -------------------------------------------------------------------------------- /benchmarks/float/leibniz.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 12499997 2 | -------------------------------------------------------------------------------- /benchmarks/float/logistic.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 1110 2 | -------------------------------------------------------------------------------- /benchmarks/float/mandelbrot.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 2720947 2 | -------------------------------------------------------------------------------- /benchmarks/float/n_root.out: -------------------------------------------------------------------------------- 1 | 1.51571786995120950 2 | -------------------------------------------------------------------------------- /benchmarks/float/n_root.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 733 2 | -------------------------------------------------------------------------------- /benchmarks/float/newton.out: -------------------------------------------------------------------------------- 1 | 316.22618487405497945 2 | -------------------------------------------------------------------------------- /benchmarks/float/newton.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 217 2 | -------------------------------------------------------------------------------- /benchmarks/float/norm.out: -------------------------------------------------------------------------------- 1 | 110.55285076250027032 2 | -------------------------------------------------------------------------------- /benchmarks/float/norm.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 505 2 | -------------------------------------------------------------------------------- /benchmarks/float/pow.out: -------------------------------------------------------------------------------- 1 | 10.24000000000000199 2 | -------------------------------------------------------------------------------- /benchmarks/float/pow.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 36 2 | -------------------------------------------------------------------------------- /benchmarks/float/ray-bbox-intersection.out: -------------------------------------------------------------------------------- 1 | true 2 | -------------------------------------------------------------------------------- /benchmarks/float/ray-bbox-intersection.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 33 2 | -------------------------------------------------------------------------------- /benchmarks/float/ray-sphere-intersection.out: -------------------------------------------------------------------------------- 1 | true 2 | -------------------------------------------------------------------------------- /benchmarks/float/ray-sphere-intersection.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 142 2 | -------------------------------------------------------------------------------- /benchmarks/float/riemann.out: -------------------------------------------------------------------------------- 1 | 284.00000000000000000 2 | 330.00000000000000000 3 | 380.00000000000000000 4 | -------------------------------------------------------------------------------- /benchmarks/float/riemann.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 298 2 | -------------------------------------------------------------------------------- /benchmarks/float/sqrt.out: -------------------------------------------------------------------------------- 1 | 18.08314132002512409 2 | -------------------------------------------------------------------------------- /benchmarks/float/sqrt.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 322 2 | -------------------------------------------------------------------------------- /benchmarks/long/dead-branch.out: -------------------------------------------------------------------------------- 1 | 50 2 | -------------------------------------------------------------------------------- /benchmarks/long/dead-branch.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 1196 2 | -------------------------------------------------------------------------------- /benchmarks/mem/1dconv.out: -------------------------------------------------------------------------------- 1 | 54.00000000000000000 2 | 54.00000000000000000 3 | 54.00000000000000000 4 | 54.00000000000000000 5 | 54.00000000000000000 6 | -------------------------------------------------------------------------------- /benchmarks/mem/1dconv.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 391 2 | -------------------------------------------------------------------------------- /benchmarks/mem/2dconvol.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 21709 2 | -------------------------------------------------------------------------------- /benchmarks/mem/adj2csr.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 56629 2 | -------------------------------------------------------------------------------- /benchmarks/mem/adler32.out: -------------------------------------------------------------------------------- 1 | 1794899728 2 | -------------------------------------------------------------------------------- /benchmarks/mem/adler32.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 6851 2 | -------------------------------------------------------------------------------- /benchmarks/mem/binary-search.out: -------------------------------------------------------------------------------- 1 | 3 2 | -------------------------------------------------------------------------------- /benchmarks/mem/binary-search.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 78 2 | -------------------------------------------------------------------------------- /benchmarks/mem/bubblesort.out: -------------------------------------------------------------------------------- 1 | 1 2 | 3 3 | 7 4 | 9 5 | 10 6 | -------------------------------------------------------------------------------- /benchmarks/mem/bubblesort.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 253 2 | -------------------------------------------------------------------------------- /benchmarks/mem/char-poly.out: -------------------------------------------------------------------------------- 1 | -1 2 | 8 3 | -11 4 | -156 5 | -------------------------------------------------------------------------------- /benchmarks/mem/char-poly.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 383 2 | -------------------------------------------------------------------------------- /benchmarks/mem/connected-components.out: -------------------------------------------------------------------------------- 1 | 5 2 | 0 3 | 4 | 3 5 | 4 6 | 2 7 | 1 8 | 9 | 7 10 | 6 11 | 12 | 3 13 | -------------------------------------------------------------------------------- /benchmarks/mem/connected-components.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 1978 2 | -------------------------------------------------------------------------------- /benchmarks/mem/cordic.out: -------------------------------------------------------------------------------- 1 | 0.76616737005754065 2 | -------------------------------------------------------------------------------- /benchmarks/mem/cordic.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 1062 2 | -------------------------------------------------------------------------------- /benchmarks/mem/csrmv.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 121202 2 | -------------------------------------------------------------------------------- /benchmarks/mem/dot-product.out: -------------------------------------------------------------------------------- 1 | 17050 2 | -------------------------------------------------------------------------------- /benchmarks/mem/dot-product.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 88 2 | -------------------------------------------------------------------------------- /benchmarks/mem/eight-queens.out: -------------------------------------------------------------------------------- 1 | 92 2 | -------------------------------------------------------------------------------- /benchmarks/mem/eight-queens.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 1006454 2 | -------------------------------------------------------------------------------- /benchmarks/mem/fib.out: -------------------------------------------------------------------------------- 1 | 34 2 | -------------------------------------------------------------------------------- /benchmarks/mem/fib.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 121 2 | -------------------------------------------------------------------------------- /benchmarks/mem/fnv1-hash.out: -------------------------------------------------------------------------------- 1 | 8573363309 2 | -------------------------------------------------------------------------------- /benchmarks/mem/fnv1-hash.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 1768440 2 | -------------------------------------------------------------------------------- /benchmarks/mem/major-elm.out: -------------------------------------------------------------------------------- 1 | 3 2 | -------------------------------------------------------------------------------- /benchmarks/mem/major-elm.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 47 2 | -------------------------------------------------------------------------------- /benchmarks/mem/mat-mul.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 1990407 2 | -------------------------------------------------------------------------------- /benchmarks/mem/max-subarray.out: -------------------------------------------------------------------------------- 1 | 100 2 | -------------------------------------------------------------------------------- /benchmarks/mem/max-subarray.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 193 2 | -------------------------------------------------------------------------------- /benchmarks/mem/primitive-root.out: -------------------------------------------------------------------------------- 1 | 17 2 | -------------------------------------------------------------------------------- /benchmarks/mem/primitive-root.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 11029 2 | -------------------------------------------------------------------------------- /benchmarks/mem/quickselect.out: -------------------------------------------------------------------------------- 1 | 108 2 | -------------------------------------------------------------------------------- /benchmarks/mem/quickselect.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 279 2 | -------------------------------------------------------------------------------- /benchmarks/mem/quicksort-hoare.out: -------------------------------------------------------------------------------- 1 | true 2 | true 3 | true 4 | true 5 | true 6 | -------------------------------------------------------------------------------- /benchmarks/mem/quicksort-hoare.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 27333 2 | -------------------------------------------------------------------------------- /benchmarks/mem/quicksort.out: -------------------------------------------------------------------------------- 1 | 5 2 | 6 3 | 21 4 | 46 5 | 82 6 | 94 7 | -------------------------------------------------------------------------------- /benchmarks/mem/quicksort.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 264 2 | -------------------------------------------------------------------------------- /benchmarks/mem/shufflesort.out: -------------------------------------------------------------------------------- 1 | 12 2 | 123 3 | 234 4 | 525 5 | 873 6 | -------------------------------------------------------------------------------- /benchmarks/mem/shufflesort.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 36564 2 | -------------------------------------------------------------------------------- /benchmarks/mem/sieve.out: -------------------------------------------------------------------------------- 1 | 2 2 | 3 3 | 5 4 | 7 5 | 11 6 | 13 7 | 17 8 | 19 9 | 23 10 | 29 11 | 31 12 | 37 13 | 41 14 | 43 15 | 47 16 | 53 17 | 59 18 | 61 19 | 67 20 | 71 21 | 73 22 | 79 23 | 83 24 | 89 25 | 97 26 | -------------------------------------------------------------------------------- /benchmarks/mem/sieve.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 3482 2 | -------------------------------------------------------------------------------- /benchmarks/mem/sorting-network-five.out: -------------------------------------------------------------------------------- 1 | 1 2 | 3 3 | 7 4 | 9 5 | 10 6 | -------------------------------------------------------------------------------- /benchmarks/mem/sorting-network-five.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 284 2 | -------------------------------------------------------------------------------- /benchmarks/mem/two-sum.out: -------------------------------------------------------------------------------- 1 | 0 2 | 1 3 | -------------------------------------------------------------------------------- /benchmarks/mem/two-sum.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 98 2 | -------------------------------------------------------------------------------- /benchmarks/mem/vsmul.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sampsyo/bril/b006a86ff9ba07cfccf85f2e0120398b2f284db7/benchmarks/mem/vsmul.out -------------------------------------------------------------------------------- /benchmarks/mem/vsmul.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 86036 2 | -------------------------------------------------------------------------------- /benchmarks/mixed/brilirs-only/fast-inverse-sqrt.out: -------------------------------------------------------------------------------- 1 | 0.70692965079546399 2 | -------------------------------------------------------------------------------- /benchmarks/mixed/brilirs-only/fast-inverse-sqrt.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 28 2 | -------------------------------------------------------------------------------- /benchmarks/mixed/cholesky.out: -------------------------------------------------------------------------------- 1 | 65.00000000000000000 2 | 0.00000000000000000 3 | 0.00000000000000000 4 | 0.00000000000000000 5 | 137.43076923076924345 6 | 55.16143280081702471 7 | 0.00000000000000000 8 | 0.00000000000000000 9 | 148.46153846153845279 10 | 22.60304899166557746 11 | 44.73559850849774477 12 | 0.00000000000000000 13 | 432.26153846153846416 14 | 250.01098702698598686 15 | 374.19363889460623795 16 | 548.34440759751453243 17 | -------------------------------------------------------------------------------- /benchmarks/mixed/cholesky.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 3761 2 | -------------------------------------------------------------------------------- /benchmarks/mixed/gol.out: -------------------------------------------------------------------------------- 1 | 13 0 1 2 | 13 1 1 3 | 13 2 1 4 | 13 3 1 5 | 13 4 0 6 | 13 5 1 7 | 13 6 1 8 | 13 7 0 9 | 13 8 0 10 | 3 11 | 13 0 1 12 | 13 1 0 13 | 13 2 1 14 | 13 3 1 15 | 13 4 0 16 | 13 5 1 17 | 13 6 0 18 | 13 7 1 19 | 13 8 0 20 | -------------------------------------------------------------------------------- /benchmarks/mixed/gol.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 1425 2 | -------------------------------------------------------------------------------- /benchmarks/mixed/mat-inv.out: -------------------------------------------------------------------------------- 1 | -20.00000000000000000 2 | 0.25000000000000000 3 | -1.14999999999999991 4 | 0.80000000000000004 5 | -0.75000000000000000 6 | 2.45000000000000018 7 | -1.39999999999999991 8 | 0.25000000000000000 9 | -0.34999999999999998 10 | 0.20000000000000001 11 | -------------------------------------------------------------------------------- /benchmarks/mixed/mat-inv.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 1044 2 | -------------------------------------------------------------------------------- /benchmarks/mixed/random_walk.prof: -------------------------------------------------------------------------------- 1 | total_dyn_inst: 516754 2 | -------------------------------------------------------------------------------- /book.toml: -------------------------------------------------------------------------------- 1 | [book] 2 | title = "Bril: A Compiler Intermediate Representation for Learning" 3 | authors = ["Adrian Sampson"] 4 | src = "docs" 5 | language = "en" 6 | 7 | [output.html] 8 | preferred-dark-theme = "ayu" 9 | curly-quotes = true 10 | git-repository-url = "https://github.com/sampsyo/bril" 11 | site-url = "https://capra.cs.cornell.edu/bril/" 12 | edit-url-template = "https://github.com/sampsyo/bril/edit/main/{path}" 13 | -------------------------------------------------------------------------------- /brench/.gitignore: -------------------------------------------------------------------------------- 1 | dist/ 2 | -------------------------------------------------------------------------------- /brench/pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = ["flit_core >=2,<4"] 3 | build-backend = "flit_core.buildapi" 4 | 5 | [tool.flit.metadata] 6 | module = "brench" 7 | author = "Adrian Sampson" 8 | author-email = "asampson@cs.cornell.edu" 9 | home-page = "https://github.com/sampsyo/bril" 10 | requires-python = ">=3.4" 11 | requires = [ 12 | "click", 13 | "tomlkit", 14 | ] 15 | 16 | [tool.flit.scripts] 17 | brench = "brench:brench" 18 | -------------------------------------------------------------------------------- /bril-llvm/README.md: -------------------------------------------------------------------------------- 1 | Bril-to-LLVM Compiler 2 | ===================== 3 | 4 | The program `brilc` implements a Bril-to-LLVM compiler that supports the [struct 5 | extension][struct]. 6 | It is originally by Mark Moeller. 7 | 8 | [struct]: https://www.cs.cornell.edu/courses/cs6120/2020fa/blog/brilc/ 9 | -------------------------------------------------------------------------------- /bril-ocaml/.gitignore: -------------------------------------------------------------------------------- 1 | .merlin 2 | _build/ 3 | -------------------------------------------------------------------------------- /bril-ocaml/bril.opam: -------------------------------------------------------------------------------- 1 | opam-version: "2.0" 2 | version: "1.2.0" 3 | homepage: "https://github.com/sampsyo/bril/tree/master/bril-ocaml" 4 | bug-reports: "https://github.com/sampsyo/bril/tree/master/bril-ocaml" 5 | authors: "6120" 6 | maintainer: "6120" 7 | synopsis: "Bril wrapper" 8 | build: [ 9 | ["dune" "subst"] {pinned} 10 | ["dune" "build" "-p" name "-j" jobs] 11 | ] 12 | depends: [ 13 | "core" 14 | "ocaml" 15 | "yojson" 16 | "dune" {>= "2.7"} 17 | ] -------------------------------------------------------------------------------- /bril-ocaml/count/dune: -------------------------------------------------------------------------------- 1 | (executable 2 | (name count) 3 | (libraries bril core yojson) 4 | (preprocess (pps ppx_jane))) 5 | -------------------------------------------------------------------------------- /bril-ocaml/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 2.7) 2 | (name bril) -------------------------------------------------------------------------------- /bril-ocaml/dune-workspace: -------------------------------------------------------------------------------- 1 | (lang dune 2.7) -------------------------------------------------------------------------------- /bril-ocaml/lib/bril.mli: -------------------------------------------------------------------------------- 1 | open! Core 2 | open! Common 3 | module Bril_type = Bril_type 4 | module Const = Const 5 | module Dest = Dest 6 | module Func = Func 7 | module Instr = Instr 8 | module Op = Op 9 | 10 | type t = Func.t list [@@deriving compare, equal, sexp_of] 11 | 12 | val from_json : Yojson.Basic.t -> t 13 | val to_json : t -> Yojson.Basic.t 14 | val to_string : t -> string 15 | -------------------------------------------------------------------------------- /bril-ocaml/lib/bril_type.mli: -------------------------------------------------------------------------------- 1 | open! Core 2 | 3 | type t = 4 | | IntType 5 | | BoolType 6 | | FloatType 7 | | PtrType of t 8 | [@@deriving compare, equal, sexp_of] 9 | 10 | val of_json : Yojson.Basic.t -> t 11 | val of_json_opt : Yojson.Basic.t -> t option 12 | val to_json : t -> Yojson.Basic.t 13 | val to_string : t -> string 14 | -------------------------------------------------------------------------------- /bril-ocaml/lib/common.ml: -------------------------------------------------------------------------------- 1 | open! Core 2 | 3 | let has_key json key = 4 | let open Yojson.Basic.Util in 5 | match json |> member key with 6 | | `Null -> false 7 | | _ -> true 8 | 9 | let to_list_nonnull = 10 | let open Yojson.Basic.Util in 11 | function 12 | | `Null -> [] 13 | | json -> to_list json 14 | -------------------------------------------------------------------------------- /bril-ocaml/lib/common.mli: -------------------------------------------------------------------------------- 1 | open! Core 2 | 3 | val has_key : Yojson.Basic.t -> string -> bool 4 | val to_list_nonnull : Yojson.Basic.t -> Yojson.Basic.t list 5 | -------------------------------------------------------------------------------- /bril-ocaml/lib/const.ml: -------------------------------------------------------------------------------- 1 | open! Core 2 | open! Common 3 | 4 | type t = 5 | | Int of int 6 | | Bool of bool 7 | | Float of float 8 | [@@deriving compare, equal, sexp_of] 9 | 10 | let to_string = function 11 | | Int i -> Int.to_string i 12 | | Bool b -> Bool.to_string b 13 | | Float f -> Float.to_string f 14 | -------------------------------------------------------------------------------- /bril-ocaml/lib/const.mli: -------------------------------------------------------------------------------- 1 | open! Core 2 | open! Common 3 | 4 | type t = 5 | | Int of int 6 | | Bool of bool 7 | | Float of float 8 | [@@deriving compare, equal, sexp_of] 9 | 10 | val to_string : t -> string 11 | -------------------------------------------------------------------------------- /bril-ocaml/lib/dest.ml: -------------------------------------------------------------------------------- 1 | open! Core 2 | open! Common 3 | 4 | type t = string * Bril_type.t [@@deriving compare, equal, sexp_of] 5 | -------------------------------------------------------------------------------- /bril-ocaml/lib/dest.mli: -------------------------------------------------------------------------------- 1 | open! Core 2 | open! Common 3 | 4 | type t = string * Bril_type.t [@@deriving compare, equal, sexp_of] 5 | -------------------------------------------------------------------------------- /bril-ocaml/lib/dune: -------------------------------------------------------------------------------- 1 | (library 2 | (name bril) 3 | (public_name bril) 4 | (libraries core yojson) 5 | (preprocess (pps ppx_jane))) 6 | -------------------------------------------------------------------------------- /bril-ocaml/test/count/bools.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | a: int = const 0; 3 | b: bool = eq a a; 4 | c: bool = le a a; 5 | } 6 | -------------------------------------------------------------------------------- /bril-ocaml/test/count/bools.out: -------------------------------------------------------------------------------- 1 | Ints: 1 Bools: 2 Floats: 0 Pointers: 0 2 | -------------------------------------------------------------------------------- /bril-ocaml/test/count/empty.bril: -------------------------------------------------------------------------------- 1 | @main {} 2 | -------------------------------------------------------------------------------- /bril-ocaml/test/count/empty.out: -------------------------------------------------------------------------------- 1 | Ints: 0 Bools: 0 Floats: 0 Pointers: 0 2 | -------------------------------------------------------------------------------- /bril-ocaml/test/count/floats.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | a: float = const 2; 3 | b: float = const 3; 4 | x: int = const 4; 5 | y: bool = eq x x; 6 | print a; 7 | } 8 | -------------------------------------------------------------------------------- /bril-ocaml/test/count/floats.out: -------------------------------------------------------------------------------- 1 | Ints: 1 Bools: 1 Floats: 2 Pointers: 0 2 | -------------------------------------------------------------------------------- /bril-ocaml/test/count/funcs.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | a: int = const 2; 3 | b: int = id a; 4 | c: bool = eq a b; 5 | d: bool = id c; 6 | } 7 | 8 | @f(i: int): bool { 9 | zero: int = const 0; 10 | b: bool = eq i zero; 11 | ret b; 12 | } 13 | -------------------------------------------------------------------------------- /bril-ocaml/test/count/funcs.out: -------------------------------------------------------------------------------- 1 | Ints: 3 Bools: 3 Floats: 0 Pointers: 0 2 | -------------------------------------------------------------------------------- /bril-ocaml/test/count/ints.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | a: int = const 2; 3 | b: int = const 3; 4 | } 5 | -------------------------------------------------------------------------------- /bril-ocaml/test/count/ints.out: -------------------------------------------------------------------------------- 1 | Ints: 2 Bools: 0 Floats: 0 Pointers: 0 2 | -------------------------------------------------------------------------------- /bril-ocaml/test/count/ptr.out: -------------------------------------------------------------------------------- 1 | Ints: 6 Bools: 0 Floats: 0 Pointers: 9 2 | -------------------------------------------------------------------------------- /bril-ocaml/test/count/turnt.toml: -------------------------------------------------------------------------------- 1 | command = "bril2json < {filename} | dune exec ../../count/count.exe" 2 | -------------------------------------------------------------------------------- /bril-rs/.gitignore: -------------------------------------------------------------------------------- 1 | **/target 2 | Cargo.lock 3 | .idea/** 4 | -------------------------------------------------------------------------------- /bril-rs/bril2json/.gitignore: -------------------------------------------------------------------------------- 1 | src/bril_grammar.rs -------------------------------------------------------------------------------- /bril-rs/bril2json/README.md: -------------------------------------------------------------------------------- 1 | # Bril2json 2 | 3 | This project is a Rust implementation of the Bril2json tool. 4 | 5 | View the interface with `cargo doc --open` or install with `make install` using the Makefile in `bril/bril_rs`. Then use `bril2json --help` to get the help page for `bril2json` with all of the supported flags. 6 | -------------------------------------------------------------------------------- /bril-rs/bril2json/build.rs: -------------------------------------------------------------------------------- 1 | use std::error::Error; 2 | 3 | fn main() -> Result<(), Box> { 4 | let mut config = lalrpop::Configuration::new(); 5 | config.emit_rerun_directives(true); 6 | config.generate_in_source_tree(); 7 | config.process_current_dir() 8 | } 9 | -------------------------------------------------------------------------------- /bril-rs/bril2json/src/main.rs: -------------------------------------------------------------------------------- 1 | use bril_rs::output_abstract_program; 2 | use bril2json::cli::Cli; 3 | use bril2json::parse_abstract_program; 4 | use clap::Parser; 5 | 6 | fn main() { 7 | let args = Cli::parse(); 8 | output_abstract_program(&parse_abstract_program( 9 | args.position >= 1, 10 | args.position >= 2, 11 | args.file, 12 | )) 13 | } 14 | -------------------------------------------------------------------------------- /bril-rs/brillvm/.gitignore: -------------------------------------------------------------------------------- 1 | *.bc 2 | *.ll -------------------------------------------------------------------------------- /bril-rs/brillvm/runtime/build.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | #[cfg(target_os = "linux")] 3 | println!("cargo:rustc-link-arg=-nostdlib"); 4 | #[cfg(target_os = "macos")] 5 | println!("cargo:rustc-link-arg=-undefined"); 6 | #[cfg(target_os = "macos")] 7 | println!("cargo:rustc-link-arg=dynamic_lookup"); 8 | 9 | #[cfg(not(any(target_os = "linux", target_os = "macos")))] 10 | assert!(false) 11 | } 12 | -------------------------------------------------------------------------------- /bril-rs/examples/bril2txt.rs: -------------------------------------------------------------------------------- 1 | use bril_rs::load_abstract_program; 2 | 3 | fn main() { 4 | print!("{}", load_abstract_program()); 5 | } 6 | -------------------------------------------------------------------------------- /bril-rs/rs2bril/src/cli.rs: -------------------------------------------------------------------------------- 1 | use clap::Parser; 2 | 3 | #[derive(Parser)] 4 | #[command(about, version, author)] // keeps the cli synced with Cargo.toml 5 | pub struct Cli { 6 | /// The bril file to statically link. stdin is assumed if file is not provided. 7 | #[arg(short, long, action)] 8 | pub file: Option, 9 | /// Flag for whether position information should be included 10 | #[arg(short, action)] 11 | pub position: bool, 12 | } 13 | -------------------------------------------------------------------------------- /bril-swift/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | /.build 3 | /Packages 4 | /*.xcodeproj 5 | xcuserdata/ 6 | DerivedData/ 7 | .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata 8 | -------------------------------------------------------------------------------- /bril-swift/Sources/Bril/Argument.swift: -------------------------------------------------------------------------------- 1 | public struct Argument: Equatable, Decodable { 2 | public var name: String 3 | public var type: Type 4 | 5 | public init(name: String, type: Type) { 6 | self.name = name 7 | self.type = type 8 | } 9 | } 10 | 11 | extension Argument: CustomStringConvertible { 12 | public var description: String { "\(name): \(type)" } 13 | } 14 | -------------------------------------------------------------------------------- /bril-swift/Sources/Bril/BrilParseError.swift: -------------------------------------------------------------------------------- 1 | public struct BrilParseError: Error { 2 | let message: String 3 | } 4 | -------------------------------------------------------------------------------- /bril-swift/Sources/Bril/Program.swift: -------------------------------------------------------------------------------- 1 | public struct Program: Equatable, Decodable { 2 | public var functions: [Function] 3 | 4 | public init(functions: [Function]) { 5 | self.functions = functions 6 | } 7 | } 8 | 9 | extension Program: CustomStringConvertible { 10 | public var description: String { 11 | functions.map(String.init).joined(separator: "\n\n") 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /bril-ts/mem.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * https://capra.cs.cornell.edu/bril/lang/memory.html 3 | */ 4 | // deno-lint-ignore no-empty-interface 5 | export interface Pointer {} 6 | export function alloc(size: bigint): Pointer; 7 | export function store(pointer: Pointer, value: T): void; 8 | export function load(pointer: Pointer): T; 9 | export function free(pointer: Pointer): void; 10 | export function ptradd(pointer: Pointer, offset: bigint): Pointer; 11 | -------------------------------------------------------------------------------- /bril-ts/util.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Read all the data from stdin as a string. 3 | */ 4 | export async function readStdin(): Promise { 5 | let buf = ""; 6 | const dec = new TextDecoder(); 7 | for await (const chunk of Deno.stdin.readable) { 8 | buf += dec.decode(chunk); 9 | } 10 | return buf; 11 | } 12 | 13 | export function unreachable(_: never): never { 14 | throw "impossible case reached"; 15 | } 16 | -------------------------------------------------------------------------------- /bril-vim/ftdetect/bril.vim: -------------------------------------------------------------------------------- 1 | " ftdetect/bril.vim 2 | autocmd BufNewFile,BufRead *.bril set filetype=bril 3 | -------------------------------------------------------------------------------- /bril-vim/ftplugin/bril.vim: -------------------------------------------------------------------------------- 1 | " ftplugin/bril.vim 2 | setlocal commentstring=\#\ %s 3 | setlocal tabstop=2 4 | setlocal softtabstop=2 5 | setlocal shiftwidth=2 6 | setlocal nospell 7 | -------------------------------------------------------------------------------- /bril2json-rs/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | -------------------------------------------------------------------------------- /bril2json-rs/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "bril2json" 3 | description = "Convert textual Bril to JSON" 4 | authors = ["Ethan Uppal"] 5 | version = "0.1.0" 6 | edition = "2021" 7 | readme = "README.md" 8 | license = "MIT" 9 | 10 | [dependencies] 11 | bril-frontend = "0.2.2" 12 | annotate-snippets = "0.11.5" 13 | snafu = "0.8.5" 14 | argh = "0.1.13" 15 | serde_json = "1.0.138" 16 | -------------------------------------------------------------------------------- /bril2json-rs/parse-error.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | v0: int = const 1; 3 | v1: int = const 2; 4 | v2: int = add v0 v1; 5 | prinft v2; 6 | } 7 | -------------------------------------------------------------------------------- /brilift/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | -------------------------------------------------------------------------------- /brilirs/.rustfmt.toml: -------------------------------------------------------------------------------- 1 | tab_spaces = 2 2 | -------------------------------------------------------------------------------- /docs/tools/README.md: -------------------------------------------------------------------------------- 1 | Bril Tools 2 | ========== 3 | 4 | These sections describe tools for dealing with Bril programs. 5 | -------------------------------------------------------------------------------- /docs/tools/web-playground.md: -------------------------------------------------------------------------------- 1 | Web Playground 2 | ============== 3 | 4 | [Web playground](https://agentcooper.github.io/bril-playground/) is available for Bril. 5 | 6 | Features: 7 | - Code evaluation using the [reference interpreter](interp.md) 8 | - CFG visualization 9 | - Dominator visualization 10 | - SSA transformation 11 | 12 | Source code 13 | ----------- 14 | 15 | [https://github.com/agentcooper/bril-playground](https://github.com/agentcooper/bril-playground) -------------------------------------------------------------------------------- /examples/.gitignore: -------------------------------------------------------------------------------- 1 | *.norm.csv 2 | ssa_results.csv 3 | ssa_plot.png 4 | ssa_plot.pdf 5 | -------------------------------------------------------------------------------- /examples/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: all 2 | all: ssa_plot.svg 3 | 4 | ssa_results.csv: ssa_brench.toml 5 | brench $^ > $@ 6 | 7 | %.norm.csv: %.csv 8 | python normalize.py < $^ > $@ 9 | 10 | ssa_plot.svg: ssa_plot.json ssa_results.norm.csv 11 | npx vl2svg $< > $@ 12 | -------------------------------------------------------------------------------- /examples/README.md: -------------------------------------------------------------------------------- 1 | Bril Examples 2 | ============= 3 | 4 | This directory contains assorted examples showing how to do interesting analyses and transformations on Bril programs. They are intentionally under-documented because you should be figuring this stuff out yourself, not reading my half-baked code! 5 | -------------------------------------------------------------------------------- /examples/test/df/cond-args.bril: -------------------------------------------------------------------------------- 1 | @main(cond: bool) { 2 | a: int = const 47; 3 | b: int = const 42; 4 | br cond .left .right; 5 | .left: 6 | b: int = const 1; 7 | c: int = const 5; 8 | jmp .end; 9 | .right: 10 | a: int = const 2; 11 | c: int = const 10; 12 | jmp .end; 13 | .end: 14 | d: int = sub a c; 15 | print d; 16 | } 17 | -------------------------------------------------------------------------------- /examples/test/df/cond-args.cprop.out: -------------------------------------------------------------------------------- 1 | b1: 2 | in: ∅ 3 | out: a: 47, b: 42 4 | left: 5 | in: a: 47, b: 42 6 | out: a: 47, b: 1, c: 5 7 | right: 8 | in: a: 47, b: 42 9 | out: a: 2, b: 42, c: 10 10 | end: 11 | in: a: ?, b: ?, c: ? 12 | out: a: ?, b: ?, c: ?, d: ? 13 | -------------------------------------------------------------------------------- /examples/test/df/cond-args.defined.out: -------------------------------------------------------------------------------- 1 | b1: 2 | in: ∅ 3 | out: a, b 4 | left: 5 | in: a, b 6 | out: a, b, c 7 | right: 8 | in: a, b 9 | out: a, b, c 10 | end: 11 | in: a, b, c 12 | out: a, b, c, d 13 | -------------------------------------------------------------------------------- /examples/test/df/cond-args.live.out: -------------------------------------------------------------------------------- 1 | b1: 2 | in: cond 3 | out: a 4 | left: 5 | in: a 6 | out: a, c 7 | right: 8 | in: ∅ 9 | out: a, c 10 | end: 11 | in: a, c 12 | out: ∅ 13 | -------------------------------------------------------------------------------- /examples/test/df/cond.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | a: int = const 47; 3 | b: int = const 42; 4 | cond: bool = const true; 5 | br cond .left .right; 6 | .left: 7 | b: int = const 1; 8 | c: int = const 5; 9 | jmp .end; 10 | .right: 11 | a: int = const 2; 12 | c: int = const 10; 13 | jmp .end; 14 | .end: 15 | d: int = sub a c; 16 | print d; 17 | } 18 | -------------------------------------------------------------------------------- /examples/test/df/cond.cprop.out: -------------------------------------------------------------------------------- 1 | b1: 2 | in: ∅ 3 | out: a: 47, b: 42, cond: True 4 | left: 5 | in: a: 47, b: 42, cond: True 6 | out: a: 47, b: 1, c: 5, cond: True 7 | right: 8 | in: a: 47, b: 42, cond: True 9 | out: a: 2, b: 42, c: 10, cond: True 10 | end: 11 | in: a: ?, b: ?, c: ?, cond: True 12 | out: a: ?, b: ?, c: ?, cond: True, d: ? 13 | -------------------------------------------------------------------------------- /examples/test/df/cond.defined.out: -------------------------------------------------------------------------------- 1 | b1: 2 | in: ∅ 3 | out: a, b, cond 4 | left: 5 | in: a, b, cond 6 | out: a, b, c, cond 7 | right: 8 | in: a, b, cond 9 | out: a, b, c, cond 10 | end: 11 | in: a, b, c, cond 12 | out: a, b, c, cond, d 13 | -------------------------------------------------------------------------------- /examples/test/df/cond.live.out: -------------------------------------------------------------------------------- 1 | b1: 2 | in: ∅ 3 | out: a 4 | left: 5 | in: a 6 | out: a, c 7 | right: 8 | in: ∅ 9 | out: a, c 10 | end: 11 | in: a, c 12 | out: ∅ 13 | -------------------------------------------------------------------------------- /examples/test/df/fact.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | result: int = const 1; 3 | i: int = const 8; 4 | 5 | .header: 6 | # Enter body if i >= 0. 7 | zero: int = const 0; 8 | cond: bool = gt i zero; 9 | br cond .body .end; 10 | 11 | .body: 12 | result: int = mul result i; 13 | 14 | # i-- 15 | one: int = const 1; 16 | i: int = sub i one; 17 | 18 | jmp .header; 19 | 20 | .end: 21 | print result; 22 | } 23 | -------------------------------------------------------------------------------- /examples/test/df/fact.cprop.out: -------------------------------------------------------------------------------- 1 | b1: 2 | in: ∅ 3 | out: i: 8, result: 1 4 | header: 5 | in: cond: ?, i: ?, one: 1, result: ?, zero: 0 6 | out: cond: ?, i: ?, one: 1, result: ?, zero: 0 7 | body: 8 | in: cond: ?, i: ?, one: 1, result: ?, zero: 0 9 | out: cond: ?, i: ?, one: 1, result: ?, zero: 0 10 | end: 11 | in: cond: ?, i: ?, one: 1, result: ?, zero: 0 12 | out: cond: ?, i: ?, one: 1, result: ?, zero: 0 13 | -------------------------------------------------------------------------------- /examples/test/df/fact.defined.out: -------------------------------------------------------------------------------- 1 | b1: 2 | in: ∅ 3 | out: i, result 4 | header: 5 | in: cond, i, one, result, zero 6 | out: cond, i, one, result, zero 7 | body: 8 | in: cond, i, one, result, zero 9 | out: cond, i, one, result, zero 10 | end: 11 | in: cond, i, one, result, zero 12 | out: cond, i, one, result, zero 13 | -------------------------------------------------------------------------------- /examples/test/df/fact.live.out: -------------------------------------------------------------------------------- 1 | b1: 2 | in: ∅ 3 | out: i, result 4 | header: 5 | in: i, result 6 | out: i, result 7 | body: 8 | in: i, result 9 | out: i, result 10 | end: 11 | in: result 12 | out: ∅ 13 | -------------------------------------------------------------------------------- /examples/test/df/turnt.toml: -------------------------------------------------------------------------------- 1 | [envs.defined] 2 | command = "bril2json < {filename} | python3 ../../df.py defined" 3 | output."defined.out" = "-" 4 | 5 | [envs.live] 6 | command = "bril2json < {filename} | python3 ../../df.py live" 7 | output."live.out" = "-" 8 | 9 | [envs.cprop] 10 | command = "bril2json < {filename} | python3 ../../df.py cprop" 11 | output."cprop.out" = "-" 12 | -------------------------------------------------------------------------------- /examples/test/dom/loopcond.front.json: -------------------------------------------------------------------------------- 1 | { 2 | "body": [ 3 | "loop" 4 | ], 5 | "endif": [ 6 | "loop" 7 | ], 8 | "entry": [], 9 | "exit": [], 10 | "loop": [ 11 | "loop" 12 | ], 13 | "then": [ 14 | "endif" 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /examples/test/dom/loopcond.tree.json: -------------------------------------------------------------------------------- 1 | { 2 | "body": [ 3 | "endif", 4 | "then" 5 | ], 6 | "endif": [], 7 | "entry": [ 8 | "loop" 9 | ], 10 | "exit": [], 11 | "loop": [ 12 | "body", 13 | "exit" 14 | ], 15 | "then": [] 16 | } 17 | -------------------------------------------------------------------------------- /examples/test/dom/loopcond.ts: -------------------------------------------------------------------------------- 1 | let x = 0; 2 | for (let i = 0; i < 10; i = i + 1) { 3 | if (i < 5) { 4 | x = x + 1; 5 | } 6 | x = x * 2; 7 | } 8 | console.log(x); 9 | -------------------------------------------------------------------------------- /examples/test/dom/turnt.toml: -------------------------------------------------------------------------------- 1 | [envs.dom] 2 | command = "bril2json < {filename} | python3 ../../dom.py dom" 3 | output."dom.json" = "-" 4 | 5 | [envs.front] 6 | command = "bril2json < {filename} | python3 ../../dom.py front" 7 | output."front.json" = "-" 8 | 9 | [envs.tree] 10 | command = "bril2json < {filename} | python3 ../../dom.py tree" 11 | output."tree.json" = "-" 12 | -------------------------------------------------------------------------------- /examples/test/dom/while.bril: -------------------------------------------------------------------------------- 1 | @main(a: int) { 2 | .while.cond: 3 | zero: int = const 0; 4 | is_term: bool = eq a zero; 5 | br is_term .while.finish .while.body; 6 | .while.body: 7 | one: int = const 1; 8 | a: int = sub a one; 9 | jmp .while.cond; 10 | .while.finish: 11 | print a; 12 | } 13 | -------------------------------------------------------------------------------- /examples/test/dom/while.dom.json: -------------------------------------------------------------------------------- 1 | { 2 | "entry1": [ 3 | "entry1" 4 | ], 5 | "while.body": [ 6 | "entry1", 7 | "while.body", 8 | "while.cond" 9 | ], 10 | "while.cond": [ 11 | "entry1", 12 | "while.cond" 13 | ], 14 | "while.finish": [ 15 | "entry1", 16 | "while.cond", 17 | "while.finish" 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /examples/test/dom/while.front.json: -------------------------------------------------------------------------------- 1 | { 2 | "entry1": [], 3 | "while.body": [ 4 | "while.cond" 5 | ], 6 | "while.cond": [ 7 | "while.cond" 8 | ], 9 | "while.finish": [] 10 | } 11 | -------------------------------------------------------------------------------- /examples/test/dom/while.tree.json: -------------------------------------------------------------------------------- 1 | { 2 | "entry1": [ 3 | "while.cond" 4 | ], 5 | "while.body": [], 6 | "while.cond": [ 7 | "while.body", 8 | "while.finish" 9 | ], 10 | "while.finish": [] 11 | } 12 | -------------------------------------------------------------------------------- /examples/test/from_ssa/basic.bril: -------------------------------------------------------------------------------- 1 | @main() { 2 | y: int = const 42; 3 | set x y; 4 | x: int = get; 5 | print x; 6 | } 7 | -------------------------------------------------------------------------------- /examples/test/from_ssa/basic.out: -------------------------------------------------------------------------------- 1 | 42 2 | -------------------------------------------------------------------------------- /examples/test/from_ssa/dead-set.bril: -------------------------------------------------------------------------------- 1 | @main() { 2 | y: int = const 4; 3 | x: int = const 2; 4 | set x y; 5 | print x; 6 | x: int = get; 7 | } 8 | -------------------------------------------------------------------------------- /examples/test/from_ssa/dead-set.out: -------------------------------------------------------------------------------- 1 | 2 2 | -------------------------------------------------------------------------------- /examples/test/from_ssa/ssa-simple.bril: -------------------------------------------------------------------------------- 1 | # ARGS: true 2 | @main(cond: bool) { 3 | .top: 4 | a: int = const 5; 5 | set c a; 6 | br cond .here .there; 7 | .here: 8 | b: int = const 7; 9 | set c b; 10 | .there: 11 | c: int = get; 12 | print c; 13 | } 14 | -------------------------------------------------------------------------------- /examples/test/from_ssa/ssa-simple.out: -------------------------------------------------------------------------------- 1 | 7 2 | -------------------------------------------------------------------------------- /examples/test/from_ssa/swap-problem.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | i: int = const 5; 3 | one: int = const 1; 4 | zero: int = const 0; 5 | 6 | .l0: 7 | x0: int = const 0; 8 | y0: int = const 1; 9 | set x1 x0; 10 | set y1 y0; 11 | jmp .l1; 12 | 13 | .l1: 14 | x1: int = get; 15 | y1: int = get; 16 | print x1 y1; 17 | 18 | cond: bool = gt i zero; 19 | i: int = sub i one; 20 | 21 | set x1 y1; 22 | set y1 x1; 23 | br cond .l1 .end; 24 | 25 | .end: 26 | } 27 | -------------------------------------------------------------------------------- /examples/test/from_ssa/swap-problem.out: -------------------------------------------------------------------------------- 1 | 0 1 2 | 1 0 3 | 0 1 4 | 1 0 5 | 0 1 6 | 1 0 7 | -------------------------------------------------------------------------------- /examples/test/from_ssa/turnt.toml: -------------------------------------------------------------------------------- 1 | [envs.orig] 2 | command = "bril2json < {filename} | brili {args}" 3 | 4 | [envs.from_ssa] 5 | command = "bril2json < {filename} | python3 ../../from_ssa.py | brili {args}" 6 | -------------------------------------------------------------------------------- /examples/test/lvn/clobber-arg.bril: -------------------------------------------------------------------------------- 1 | @main() { 2 | a: int = const 1; 3 | b: int = const 2; 4 | .lbl: 5 | b: int = add a b; 6 | } 7 | -------------------------------------------------------------------------------- /examples/test/lvn/clobber-arg.out: -------------------------------------------------------------------------------- 1 | @main { 2 | a: int = const 1; 3 | b: int = const 2; 4 | .lbl: 5 | b: int = add a b; 6 | } 7 | -------------------------------------------------------------------------------- /examples/test/lvn/clobber-fold.out: -------------------------------------------------------------------------------- 1 | @main { 2 | prod2: int = const 36; 3 | print prod2; 4 | } 5 | -------------------------------------------------------------------------------- /examples/test/lvn/clobber.out: -------------------------------------------------------------------------------- 1 | @main { 2 | a: int = const 4; 3 | b: int = const 2; 4 | lvn.2: int = add a b; 5 | prod1: int = mul lvn.2 lvn.2; 6 | print prod1; 7 | } 8 | -------------------------------------------------------------------------------- /examples/test/lvn/commute.bril: -------------------------------------------------------------------------------- 1 | # ARGS: -c 2 | # (a + b) * (b + a) 3 | @main { 4 | a: int = const 4; 5 | b: int = const 2; 6 | sum1: int = add a b; 7 | sum2: int = add b a; 8 | prod: int = mul sum1 sum2; 9 | print prod; 10 | } 11 | -------------------------------------------------------------------------------- /examples/test/lvn/commute.out: -------------------------------------------------------------------------------- 1 | @main { 2 | a: int = const 4; 3 | b: int = const 2; 4 | sum1: int = add a b; 5 | sum2: int = id sum1; 6 | prod: int = mul sum1 sum1; 7 | print prod; 8 | } 9 | -------------------------------------------------------------------------------- /examples/test/lvn/divide-by-zero.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | .entry: 3 | zero : int = const 0; 4 | one : int = const 1; 5 | baddiv : int = div one zero; 6 | print baddiv; 7 | } 8 | -------------------------------------------------------------------------------- /examples/test/lvn/divide-by-zero.out: -------------------------------------------------------------------------------- 1 | @main { 2 | .entry: 3 | zero: int = const 0; 4 | one: int = const 1; 5 | baddiv: int = div one zero; 6 | print baddiv; 7 | } 8 | -------------------------------------------------------------------------------- /examples/test/lvn/idchain-nonlocal.bril: -------------------------------------------------------------------------------- 1 | # ARGS: -p 2 | @main { 3 | x: int = const 4; 4 | jmp .label; 5 | .label: 6 | copy1: int = id x; 7 | copy2: int = id copy1; 8 | copy3: int = id copy2; 9 | print copy3; 10 | } 11 | -------------------------------------------------------------------------------- /examples/test/lvn/idchain-nonlocal.out: -------------------------------------------------------------------------------- 1 | @main { 2 | x: int = const 4; 3 | jmp .label; 4 | .label: 5 | copy1: int = id x; 6 | copy2: int = id x; 7 | copy3: int = id x; 8 | print x; 9 | } 10 | -------------------------------------------------------------------------------- /examples/test/lvn/idchain-prop.bril: -------------------------------------------------------------------------------- 1 | # ARGS: -p 2 | @main { 3 | x: int = const 4; 4 | copy1: int = id x; 5 | copy2: int = id copy1; 6 | copy3: int = id copy2; 7 | print copy3; 8 | } 9 | -------------------------------------------------------------------------------- /examples/test/lvn/idchain-prop.out: -------------------------------------------------------------------------------- 1 | @main { 2 | x: int = const 4; 3 | copy1: int = const 4; 4 | copy2: int = const 4; 5 | copy3: int = const 4; 6 | print x; 7 | } 8 | -------------------------------------------------------------------------------- /examples/test/lvn/idchain.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | x: int = const 4; 3 | copy1: int = id x; 4 | copy2: int = id copy1; 5 | copy3: int = id copy2; 6 | print copy3; 7 | } 8 | -------------------------------------------------------------------------------- /examples/test/lvn/idchain.out: -------------------------------------------------------------------------------- 1 | @main { 2 | x: int = const 4; 3 | copy1: int = id x; 4 | copy2: int = id copy1; 5 | copy3: int = id copy2; 6 | print copy3; 7 | } 8 | -------------------------------------------------------------------------------- /examples/test/lvn/nonlocal-clobber.bril: -------------------------------------------------------------------------------- 1 | # ARGS: -p 2 | @main { 3 | x: int = const 1; 4 | .lb: 5 | y: int = id x; 6 | x: int = add x x; 7 | print y; 8 | } 9 | -------------------------------------------------------------------------------- /examples/test/lvn/nonlocal-clobber.out: -------------------------------------------------------------------------------- 1 | @main { 2 | x: int = const 1; 3 | .lb: 4 | y: int = id x; 5 | x: int = add x x; 6 | print y; 7 | } 8 | -------------------------------------------------------------------------------- /examples/test/lvn/nonlocal.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | a: int = const 4; 3 | b: int = const 2; 4 | sum1: int = add a b; 5 | sum2: int = add a b; 6 | jmp .label; 7 | .label: 8 | prod: int = mul sum1 sum2; 9 | print prod; 10 | } 11 | -------------------------------------------------------------------------------- /examples/test/lvn/nonlocal.out: -------------------------------------------------------------------------------- 1 | @main { 2 | a: int = const 4; 3 | b: int = const 2; 4 | sum1: int = add a b; 5 | sum2: int = id sum1; 6 | jmp .label; 7 | .label: 8 | prod: int = mul sum1 sum2; 9 | print prod; 10 | } 11 | -------------------------------------------------------------------------------- /examples/test/lvn/reassign.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | a: int = const 100; 3 | a: int = const 42; 4 | print a; 5 | } 6 | -------------------------------------------------------------------------------- /examples/test/lvn/reassign.out: -------------------------------------------------------------------------------- 1 | @main { 2 | lvn.0: int = const 100; 3 | a: int = const 42; 4 | print a; 5 | } 6 | -------------------------------------------------------------------------------- /examples/test/lvn/redundant-dce.bril: -------------------------------------------------------------------------------- 1 | # CMD: bril2json < {filename} | python3 ../../lvn.py | python3 ../../tdce.py tdce | bril2txt 2 | 3 | @main { 4 | a: int = const 4; 5 | b: int = const 2; 6 | sum1: int = add a b; 7 | sum2: int = add a b; 8 | prod: int = mul sum1 sum2; 9 | print prod; 10 | } 11 | -------------------------------------------------------------------------------- /examples/test/lvn/redundant-dce.out: -------------------------------------------------------------------------------- 1 | @main { 2 | a: int = const 4; 3 | b: int = const 2; 4 | sum1: int = add a b; 5 | prod: int = mul sum1 sum1; 6 | print prod; 7 | } 8 | -------------------------------------------------------------------------------- /examples/test/lvn/redundant.bril: -------------------------------------------------------------------------------- 1 | # (a + b) * (a + b) 2 | @main { 3 | a: int = const 4; 4 | b: int = const 2; 5 | sum1: int = add a b; 6 | sum2: int = add a b; 7 | prod: int = mul sum1 sum2; 8 | print prod; 9 | } 10 | -------------------------------------------------------------------------------- /examples/test/lvn/redundant.out: -------------------------------------------------------------------------------- 1 | @main { 2 | a: int = const 4; 3 | b: int = const 2; 4 | sum1: int = add a b; 5 | sum2: int = id sum1; 6 | prod: int = mul sum1 sum1; 7 | print prod; 8 | } 9 | -------------------------------------------------------------------------------- /examples/test/lvn/rename-fold.bril: -------------------------------------------------------------------------------- 1 | # CMD: bril2json < {filename} | python3 ../../lvn.py -f | python3 ../../tdce.py tdce | bril2txt 2 | @main { 3 | v1: int = const 4; 4 | v2: int = const 0; 5 | mul1: int = mul v1 v2; 6 | add1: int = add v1 v2; 7 | v2: int = const 3; 8 | print mul1; 9 | print add1; 10 | } 11 | -------------------------------------------------------------------------------- /examples/test/lvn/rename-fold.out: -------------------------------------------------------------------------------- 1 | @main { 2 | mul1: int = const 0; 3 | add1: int = const 4; 4 | print mul1; 5 | print add1; 6 | } 7 | -------------------------------------------------------------------------------- /examples/test/lvn/turnt.toml: -------------------------------------------------------------------------------- 1 | command = "bril2json < {filename} | python3 ../../lvn.py {args} | bril2txt" 2 | -------------------------------------------------------------------------------- /examples/test/ssa/if-orig.bril: -------------------------------------------------------------------------------- 1 | @main(cond: bool) { 2 | .entry: 3 | a: int = const 47; 4 | br cond .left .right; 5 | .left: 6 | a: int = add a a; 7 | jmp .exit; 8 | .right: 9 | a: int = mul a a; 10 | jmp .exit; 11 | .exit: 12 | print a; 13 | } 14 | -------------------------------------------------------------------------------- /examples/test/ssa/if-orig.out: -------------------------------------------------------------------------------- 1 | no 2 | -------------------------------------------------------------------------------- /examples/test/ssa/if-ssa.out: -------------------------------------------------------------------------------- 1 | yes 2 | -------------------------------------------------------------------------------- /examples/test/ssa/loop-orig.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | .entry: 3 | i: int = const 1; 4 | jmp .loop; 5 | .loop: 6 | max: int = const 10; 7 | cond: bool = lt i max; 8 | br cond .body .exit; 9 | .body: 10 | i: int = add i i; 11 | jmp .loop; 12 | .exit: 13 | print i; 14 | } 15 | -------------------------------------------------------------------------------- /examples/test/ssa/loop-orig.out: -------------------------------------------------------------------------------- 1 | no 2 | -------------------------------------------------------------------------------- /examples/test/ssa/loop-ssa.out: -------------------------------------------------------------------------------- 1 | yes 2 | -------------------------------------------------------------------------------- /examples/test/ssa/turnt.toml: -------------------------------------------------------------------------------- 1 | [envs.is_ssa] 2 | command = "bril2json < {filename} | python3 ../../is_ssa.py" 3 | 4 | [envs.crude] 5 | command = "bril2json < {filename} | python3 ../../to_ssa_crude.py | bril2txt" 6 | output."ssa.bril" = "-" 7 | default = false 8 | -------------------------------------------------------------------------------- /examples/test/ssa_roundtrip/argwrite.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 3 2 | @main(a: int) { 3 | cond: bool = const true; 4 | br cond .here .there; 5 | .here: 6 | a: int = const 5; 7 | .there: 8 | print a; 9 | } 10 | -------------------------------------------------------------------------------- /examples/test/ssa_roundtrip/argwrite.out: -------------------------------------------------------------------------------- 1 | 5 2 | -------------------------------------------------------------------------------- /examples/test/ssa_roundtrip/if-const.bril: -------------------------------------------------------------------------------- 1 | @main() { 2 | cond: bool = const true; 3 | br cond .true .false; 4 | .true: 5 | a: int = const 0; 6 | jmp .zexit; 7 | .false: 8 | b: int = const 1; 9 | jmp .zexit; 10 | # zexit to trigger a bug in to_ssa.py that depends on 11 | # the order that basic blocks get renamed. 12 | .zexit: 13 | print a; 14 | } 15 | -------------------------------------------------------------------------------- /examples/test/ssa_roundtrip/if-const.out: -------------------------------------------------------------------------------- 1 | 0 2 | -------------------------------------------------------------------------------- /examples/test/ssa_roundtrip/if-ssa.bril.BROKEN: -------------------------------------------------------------------------------- 1 | # ARGS: true 2 | @main(cond: bool) { 3 | .entry: 4 | a.1: int = const 47; 5 | br cond .left .right; 6 | .left: 7 | a.2: int = add a.1 a.1; 8 | jmp .zexit; 9 | .right: 10 | a.3: int = mul a.1 a.1; 11 | jmp .zexit; 12 | # zexit to trigger a bug in to_ssa.py that depends on 13 | # the order that basic blocks get renamed. 14 | .zexit: 15 | a.4: int = phi .left a.2 .right a.3; 16 | print a.4; 17 | } -------------------------------------------------------------------------------- /examples/test/ssa_roundtrip/if-ssa.out: -------------------------------------------------------------------------------- 1 | 94 2 | -------------------------------------------------------------------------------- /examples/test/ssa_roundtrip/if.bril: -------------------------------------------------------------------------------- 1 | # ARGS: false 2 | @main(cond: bool) { 3 | .entry: 4 | a: int = const 47; 5 | br cond .left .right; 6 | .left: 7 | a: int = add a a; 8 | jmp .exit; 9 | .right: 10 | a: int = mul a a; 11 | jmp .exit; 12 | .exit: 13 | print a; 14 | } 15 | -------------------------------------------------------------------------------- /examples/test/ssa_roundtrip/if.out: -------------------------------------------------------------------------------- 1 | 2209 2 | -------------------------------------------------------------------------------- /examples/test/ssa_roundtrip/loop-branch.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sampsyo/bril/b006a86ff9ba07cfccf85f2e0120398b2f284db7/examples/test/ssa_roundtrip/loop-branch.out -------------------------------------------------------------------------------- /examples/test/ssa_roundtrip/loop.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | .entry: 3 | i: int = const 1; 4 | jmp .loop; 5 | .loop: 6 | max: int = const 10; 7 | cond: bool = lt i max; 8 | br cond .body .exit; 9 | .body: 10 | i: int = add i i; 11 | jmp .loop; 12 | .exit: 13 | print i; 14 | } 15 | -------------------------------------------------------------------------------- /examples/test/ssa_roundtrip/loop.out: -------------------------------------------------------------------------------- 1 | 16 2 | -------------------------------------------------------------------------------- /examples/test/ssa_roundtrip/selfloop.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | .entry: 3 | one: int = const 1; 4 | zero: int = const 0; 5 | x: int = const 5; 6 | .loop: 7 | x: int = sub x one; 8 | done: bool = eq x zero; 9 | .br: 10 | br done .exit .loop; 11 | .exit: 12 | print x; 13 | ret; 14 | } 15 | -------------------------------------------------------------------------------- /examples/test/ssa_roundtrip/selfloop.out: -------------------------------------------------------------------------------- 1 | 0 2 | -------------------------------------------------------------------------------- /examples/test/ssa_roundtrip/turnt.toml: -------------------------------------------------------------------------------- 1 | [envs.crude] 2 | command = "bril2json < {filename} | python3 ../../to_ssa_crude.py | python3 ../../from_ssa.py | brili {args}" 3 | 4 | [envs.full] 5 | command = "bril2json < {filename} | python3 ../../to_ssa.py | python3 ../../from_ssa.py | brili {args}" 6 | -------------------------------------------------------------------------------- /examples/test/ssa_roundtrip/while.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 5 2 | @main(a: int) { 3 | .while.cond: 4 | zero: int = const 0; 5 | is_term: bool = eq a zero; 6 | br is_term .while.finish .while.body; 7 | .while.body: 8 | one: int = const 1; 9 | a: int = sub a one; 10 | jmp .while.cond; 11 | .while.finish: 12 | print a; 13 | } 14 | -------------------------------------------------------------------------------- /examples/test/ssa_roundtrip/while.out: -------------------------------------------------------------------------------- 1 | 0 2 | -------------------------------------------------------------------------------- /examples/test/tdce/combo.bril: -------------------------------------------------------------------------------- 1 | # ARGS: tdce+ 2 | @main { 3 | a: int = const 1; 4 | b: int = const 2; 5 | c: int = add a b; 6 | b: int = const 3; 7 | d: int = add a b; 8 | print d; 9 | } 10 | -------------------------------------------------------------------------------- /examples/test/tdce/combo.out: -------------------------------------------------------------------------------- 1 | @main { 2 | a: int = const 1; 3 | b: int = const 3; 4 | d: int = add a b; 5 | print d; 6 | } 7 | -------------------------------------------------------------------------------- /examples/test/tdce/diamond.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | a: int = const 47; 3 | cond: bool = const true; 4 | br cond .left .right; 5 | .left: 6 | a: int = const 1; 7 | jmp .end; 8 | .right: 9 | a: int = const 2; 10 | jmp .end; 11 | .end: 12 | print a; 13 | } 14 | -------------------------------------------------------------------------------- /examples/test/tdce/diamond.out: -------------------------------------------------------------------------------- 1 | @main { 2 | a: int = const 47; 3 | cond: bool = const true; 4 | br cond .left .right; 5 | .left: 6 | a: int = const 1; 7 | jmp .end; 8 | .right: 9 | a: int = const 2; 10 | jmp .end; 11 | .end: 12 | print a; 13 | } 14 | -------------------------------------------------------------------------------- /examples/test/tdce/double-pass.bril: -------------------------------------------------------------------------------- 1 | # ARGS: tdcep 2 | @main { 3 | a: int = const 4; 4 | b: int = const 2; 5 | c: int = const 1; 6 | d: int = add a b; 7 | e: int = add c d; 8 | print d; 9 | } 10 | -------------------------------------------------------------------------------- /examples/test/tdce/double-pass.out: -------------------------------------------------------------------------------- 1 | @main { 2 | a: int = const 4; 3 | b: int = const 2; 4 | c: int = const 1; 5 | d: int = add a b; 6 | print d; 7 | } 8 | -------------------------------------------------------------------------------- /examples/test/tdce/double.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | a: int = const 4; 3 | b: int = const 2; 4 | c: int = const 1; 5 | d: int = add a b; 6 | e: int = add c d; 7 | print d; 8 | } 9 | -------------------------------------------------------------------------------- /examples/test/tdce/double.out: -------------------------------------------------------------------------------- 1 | @main { 2 | a: int = const 4; 3 | b: int = const 2; 4 | d: int = add a b; 5 | print d; 6 | } 7 | -------------------------------------------------------------------------------- /examples/test/tdce/reassign-dkp.bril: -------------------------------------------------------------------------------- 1 | # ARGS: dkp 2 | @main { 3 | a: int = const 100; 4 | a: int = const 42; 5 | print a; 6 | } 7 | -------------------------------------------------------------------------------- /examples/test/tdce/reassign-dkp.out: -------------------------------------------------------------------------------- 1 | @main { 2 | a: int = const 42; 3 | print a; 4 | } 5 | -------------------------------------------------------------------------------- /examples/test/tdce/reassign.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | a: int = const 100; 3 | a: int = const 42; 4 | print a; 5 | } 6 | -------------------------------------------------------------------------------- /examples/test/tdce/reassign.out: -------------------------------------------------------------------------------- 1 | @main { 2 | a: int = const 100; 3 | a: int = const 42; 4 | print a; 5 | } 6 | -------------------------------------------------------------------------------- /examples/test/tdce/simple.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | a: int = const 4; 3 | b: int = const 2; 4 | c: int = const 1; 5 | d: int = add a b; 6 | print d; 7 | } 8 | -------------------------------------------------------------------------------- /examples/test/tdce/simple.out: -------------------------------------------------------------------------------- 1 | @main { 2 | a: int = const 4; 3 | b: int = const 2; 4 | d: int = add a b; 5 | print d; 6 | } 7 | -------------------------------------------------------------------------------- /examples/test/tdce/skipped.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | a: int = const 4; 3 | b: int = const 2; 4 | jmp .end; 5 | print b; 6 | .end: 7 | print a; 8 | } 9 | -------------------------------------------------------------------------------- /examples/test/tdce/skipped.out: -------------------------------------------------------------------------------- 1 | @main { 2 | a: int = const 4; 3 | b: int = const 2; 4 | jmp .end; 5 | print b; 6 | .end: 7 | print a; 8 | } 9 | -------------------------------------------------------------------------------- /examples/test/tdce/turnt.toml: -------------------------------------------------------------------------------- 1 | command = "bril2json < {filename} | python3 ../../tdce.py {args} | bril2txt" 2 | -------------------------------------------------------------------------------- /examples/test/to_ssa/argwrite.bril: -------------------------------------------------------------------------------- 1 | @main(a: int) { 2 | cond: bool = const true; 3 | br cond .here .there; 4 | .here: 5 | a: int = const 5; 6 | .there: 7 | print a; 8 | } 9 | -------------------------------------------------------------------------------- /examples/test/to_ssa/argwrite.full: -------------------------------------------------------------------------------- 1 | @main(a: int) { 2 | .b1: 3 | cond.0: bool = const true; 4 | set a.1 a; 5 | br cond.0 .here .there; 6 | .here: 7 | a.0: int = const 5; 8 | set a.1 a.0; 9 | jmp .there; 10 | .there: 11 | a.1: int = get; 12 | print a.1; 13 | ret; 14 | } 15 | -------------------------------------------------------------------------------- /examples/test/to_ssa/if-const.bril: -------------------------------------------------------------------------------- 1 | @main() { 2 | cond: bool = const true; 3 | br cond .true .false; 4 | .true: 5 | a: int = const 0; 6 | jmp .zexit; 7 | .false: 8 | b: int = const 1; 9 | jmp .zexit; 10 | # zexit to trigger a bug in to_ssa.py that depends on 11 | # the order that basic blocks get renamed. 12 | .zexit: 13 | print a; 14 | } -------------------------------------------------------------------------------- /examples/test/to_ssa/if-const.full: -------------------------------------------------------------------------------- 1 | @main { 2 | .b1: 3 | b.init: int = undef; 4 | a.init: int = undef; 5 | cond.0: bool = const true; 6 | br cond.0 .true .false; 7 | .true: 8 | a.0: int = const 0; 9 | set a.1 a.0; 10 | set b.1 b.init; 11 | jmp .zexit; 12 | .false: 13 | b.0: int = const 1; 14 | set a.1 a.init; 15 | set b.1 b.0; 16 | jmp .zexit; 17 | .zexit: 18 | b.1: int = get; 19 | a.1: int = get; 20 | print a.1; 21 | ret; 22 | } 23 | -------------------------------------------------------------------------------- /examples/test/to_ssa/if.bril: -------------------------------------------------------------------------------- 1 | @main(cond: bool) { 2 | .entry: 3 | a: int = const 47; 4 | br cond .left .right; 5 | .left: 6 | a: int = add a a; 7 | jmp .exit; 8 | .right: 9 | a: int = mul a a; 10 | jmp .exit; 11 | .exit: 12 | print a; 13 | } 14 | -------------------------------------------------------------------------------- /examples/test/to_ssa/if.full: -------------------------------------------------------------------------------- 1 | @main(cond: bool) { 2 | .entry: 3 | a.0: int = const 47; 4 | br cond .left .right; 5 | .left: 6 | a.2: int = add a.0 a.0; 7 | set a.1 a.2; 8 | jmp .exit; 9 | .right: 10 | a.3: int = mul a.0 a.0; 11 | set a.1 a.3; 12 | jmp .exit; 13 | .exit: 14 | a.1: int = get; 15 | print a.1; 16 | ret; 17 | } 18 | -------------------------------------------------------------------------------- /examples/test/to_ssa/loop.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | .entry: 3 | i: int = const 1; 4 | jmp .loop; 5 | .loop: 6 | max: int = const 10; 7 | cond: bool = lt i max; 8 | br cond .body .exit; 9 | .body: 10 | i: int = add i i; 11 | jmp .loop; 12 | .exit: 13 | print i; 14 | } 15 | -------------------------------------------------------------------------------- /examples/test/to_ssa/selfloop.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | .entry: 3 | one: int = const 1; 4 | zero: int = const 0; 5 | x: int = const 5; 6 | .loop: 7 | x: int = sub x one; 8 | done: bool = eq x zero; 9 | .br: 10 | br done .exit .loop; 11 | .exit: 12 | print x; 13 | ret; 14 | } 15 | -------------------------------------------------------------------------------- /examples/test/to_ssa/turnt.toml: -------------------------------------------------------------------------------- 1 | [envs.crude] 2 | command = "bril2json < {filename} | python3 ../../to_ssa_crude.py | bril2txt" 3 | output.crude = "-" 4 | 5 | [envs.full] 6 | command = "bril2json < {filename} | python3 ../../to_ssa.py | bril2txt" 7 | output.full = "-" 8 | -------------------------------------------------------------------------------- /examples/test/to_ssa/while.bril: -------------------------------------------------------------------------------- 1 | @main(a: int) { 2 | .while.cond: 3 | zero: int = const 0; 4 | is_term: bool = eq a zero; 5 | br is_term .while.finish .while.body; 6 | .while.body: 7 | one: int = const 1; 8 | a: int = sub a one; 9 | jmp .while.cond; 10 | .while.finish: 11 | print a; 12 | } 13 | -------------------------------------------------------------------------------- /examples/util.py: -------------------------------------------------------------------------------- 1 | import itertools 2 | 3 | 4 | def flatten(ll): 5 | """Flatten an iterable of iterable to a single list.""" 6 | return list(itertools.chain(*ll)) 7 | 8 | 9 | def fresh(seed, names): 10 | """Generate a new name that is not in `names` starting with `seed`.""" 11 | i = 1 12 | while True: 13 | name = seed + str(i) 14 | if name not in names: 15 | return name 16 | i += 1 17 | -------------------------------------------------------------------------------- /fastbril/.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | *~ 3 | \#*\# 4 | *.o -------------------------------------------------------------------------------- /fastbril/config/base.cf: -------------------------------------------------------------------------------- 1 | CONST 1 2 | ADD 2 3 | MUL 3 4 | SUB 4 5 | DIV 5 6 | EQ 6 7 | LT 7 8 | GT 8 9 | LE 9 10 | GE 10 11 | NOT 11 12 | AND 12 13 | OR 13 14 | JMP 14 15 | BR 15 16 | CALL 16 17 | RET 17 18 | PRINT 18 19 | LCONST 19 20 | NOP 20 21 | ID 21 22 | 23 | -------------------------------------------------------------------------------- /fastbril/config/float.cf: -------------------------------------------------------------------------------- 1 | FADD 28 2 | FMUL 29 3 | FSUB 30 4 | FDIV 31 5 | FEQ 32 6 | FLT 33 7 | FLE 34 8 | FGT 35 9 | FGE 36 10 | -------------------------------------------------------------------------------- /fastbril/config/mem.cf: -------------------------------------------------------------------------------- 1 | ALLOC 23 2 | FREE 24 3 | STORE 25 4 | LOAD 26 5 | PTRADD 27 6 | -------------------------------------------------------------------------------- /fastbril/config/ssa.cf: -------------------------------------------------------------------------------- 1 | PHI 22 2 | 3 | -------------------------------------------------------------------------------- /fastbril/config/types.cf: -------------------------------------------------------------------------------- 1 | BRILINT 0 2 | BRILBOOL 1 3 | BRILFLOAT 2 4 | BRILVOID 3 5 | -------------------------------------------------------------------------------- /fastbril/doc/.gitignore: -------------------------------------------------------------------------------- 1 | *.aux 2 | *.out 3 | *.log 4 | base.tex 5 | float.tex 6 | mem.tex 7 | ssa.tex 8 | types.tex 9 | brb.pdf 10 | -------------------------------------------------------------------------------- /fastbril/docgen.awk: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | printf "\\begin{tabular}{|r|l|}\\hline\n\\multicolumn{2}{|c|}{%s}\\\\ \\hline\n", header 3 | } 4 | { 5 | if($0 != "") 6 | print $1 " & " $2 " \\\\ \\hline" 7 | } 8 | END { 9 | print "\\end{tabular}" 10 | } 11 | -------------------------------------------------------------------------------- /fastbril/docgen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | 4 | CORE=$(echo $1 | awk -F'[/.]' '{print $2}') 5 | IF=$(echo $1 | awk -F'[/.]' '{printf "config/%s.cf", $2}') 6 | if [[ $CORE == "types" ]]; then 7 | CORE="Types" 8 | else 9 | CORE="$CORE Instructions" 10 | fi 11 | awk -v header="$CORE" -f docgen.awk $IF > $1 12 | -------------------------------------------------------------------------------- /fastbril/src/.gitignore: -------------------------------------------------------------------------------- 1 | base.h 2 | float.h 3 | mem.h 4 | ssa.h 5 | types.h 6 | -------------------------------------------------------------------------------- /fastbril/src/asm/linear-scan.h: -------------------------------------------------------------------------------- 1 | #ifndef LINEAR_SCAN_H 2 | #define LINEAR_SCAN_H 3 | #include "asm.h" 4 | 5 | 6 | asm_prog_t linear_scan(asm_prog_t prog); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /fastbril/src/asm/to_abstract_asm.h: -------------------------------------------------------------------------------- 1 | #ifndef TO_ABS_H 2 | #define TO_ABS_H 3 | 4 | #include "../bril-insns/instrs.h" 5 | #include "asm.h" 6 | 7 | 8 | //#define __ARM_ARCH 9 | #ifdef __ARM_ARCH 10 | #include "armv8.h" 11 | #endif 12 | 13 | asm_prog_t bytecode_to_abs_asm(program_t *prog); 14 | 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /fastbril/src/asm/trivial-regalloc.h: -------------------------------------------------------------------------------- 1 | #ifndef TRIVREG_H 2 | #define TRIVREG_H 3 | #include "asm.h" 4 | 5 | asm_prog_t triv_allocate(asm_prog_t prog); 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /fastbril/src/bril-insns/base.h: -------------------------------------------------------------------------------- 1 | #define CONST 1 2 | #define ADD 2 3 | #define MUL 3 4 | #define SUB 4 5 | #define DIV 5 6 | #define EQ 6 7 | #define LT 7 8 | #define GT 8 9 | #define LE 9 10 | #define GE 10 11 | #define NOT 11 12 | #define AND 12 13 | #define OR 13 14 | #define JMP 14 15 | #define BR 15 16 | #define CALL 16 17 | #define RET 17 18 | #define PRINT 18 19 | #define LCONST 19 20 | #define NOP 20 21 | #define ID 21 22 | -------------------------------------------------------------------------------- /fastbril/src/bril-insns/float.h: -------------------------------------------------------------------------------- 1 | #define FADD 28 2 | #define FMUL 29 3 | #define FSUB 30 4 | #define FDIV 31 5 | #define FEQ 32 6 | #define FLT 33 7 | #define FLE 34 8 | #define FGT 35 9 | #define FGE 36 10 | -------------------------------------------------------------------------------- /fastbril/src/bril-insns/mem.h: -------------------------------------------------------------------------------- 1 | #define ALLOC 23 2 | #define FREE 24 3 | #define STORE 25 4 | #define LOAD 26 5 | #define PTRADD 27 6 | -------------------------------------------------------------------------------- /fastbril/src/bril-insns/ssa.h: -------------------------------------------------------------------------------- 1 | #define PHI 22 2 | -------------------------------------------------------------------------------- /fastbril/src/bril-insns/types.h: -------------------------------------------------------------------------------- 1 | #define BRILINT 0 2 | #define BRILBOOL 1 3 | #define BRILFLOAT 2 4 | #define BRILVOID 3 5 | -------------------------------------------------------------------------------- /fastbril/src/byte-io.h: -------------------------------------------------------------------------------- 1 | #ifndef BYTE_OUTPUT_H 2 | #define BYTE_OUTPUT_H 3 | #include "bril-insns/instrs.h" 4 | #include 5 | 6 | /** 7 | * emit prog as bytecode to dest 8 | */ 9 | void output_program(program_t *prog, FILE *dest); 10 | 11 | /** 12 | * read source as bytecode and return a program 13 | */ 14 | program_t *read_program(FILE *source); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /fastbril/src/parser.h: -------------------------------------------------------------------------------- 1 | #ifndef PARSER_H 2 | #define PARSER_H 3 | 4 | #include "libs/json.h" 5 | #include "bril-insns/instrs.h" 6 | 7 | /** 8 | * parses a program... 9 | */ 10 | program_t *parse_program(struct json_object_s *json); 11 | #endif 12 | -------------------------------------------------------------------------------- /fastbril/srcgen.awk: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env -S awk -f 2 | 3 | { 4 | if($0 != "") 5 | print "#define " $1 " " $2; 6 | } 7 | -------------------------------------------------------------------------------- /flat-bril/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | /target 3 | *.fbril 4 | 5 | -------------------------------------------------------------------------------- /flat-bril/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "flat-bril" 3 | version = "0.1.0" 4 | edition = "2024" 5 | 6 | [dependencies] 7 | clap = "4.5.37" 8 | memmap2 = "0.9.5" 9 | num-derive = "0.4.2" 10 | num-traits = "0.2.19" 11 | serde = {version = "1.0.219", features = ["derive"]} 12 | serde_json = "1.0.140" 13 | strum = "0.27.1" 14 | strum_macros = "0.27.1" 15 | zerocopy = {version = "0.8.25", features = ["derive"]} 16 | -------------------------------------------------------------------------------- /flat-bril/rustfmt.toml: -------------------------------------------------------------------------------- 1 | max_width = 80 -------------------------------------------------------------------------------- /test/check/argtype.bril: -------------------------------------------------------------------------------- 1 | @main(a: int, b: bool) { 2 | c: int = add a b; 3 | } 4 | -------------------------------------------------------------------------------- /test/check/argtype.err: -------------------------------------------------------------------------------- 1 | 2:3: b has type bool, but arg 1 for add should have type int 2 | -------------------------------------------------------------------------------- /test/check/badcall.bril: -------------------------------------------------------------------------------- 1 | @nothing { 2 | } 3 | 4 | @retint(): int { 5 | x: int = const 5; 6 | ret x; 7 | } 8 | 9 | @argint(x: int) { 10 | } 11 | 12 | @noret { 13 | x: int = const 5; 14 | ret x; 15 | } 16 | 17 | @yesret(): int { 18 | ret; 19 | } 20 | 21 | @main { 22 | call @foo; 23 | a: int = call @nothing; 24 | call @nothing @nothing; 25 | b: bool = call @retint; 26 | call @argint b; 27 | call @argint; 28 | call @argint a a; 29 | } 30 | -------------------------------------------------------------------------------- /test/check/badcall.err: -------------------------------------------------------------------------------- 1 | 14:3: returning value in function without a return type 2 | 18:3: missing return value in function with return type 3 | 22:3: function @foo undefined 4 | 23:3: @nothing should have no result type 5 | 24:3: call should have one function, not 2 6 | 25:3: result type of @retint should be int, but found bool 7 | 26:3: b has type bool, but arg 0 for @argint should have type int 8 | 27:3: @argint expects 1 args, not 0 9 | 28:3: @argint expects 1 args, not 2 10 | -------------------------------------------------------------------------------- /test/check/badconst.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | a: bool = const 4; 3 | b: int = const true; 4 | c: ptr = const 2; 5 | d: blah = const 0; 6 | } 7 | -------------------------------------------------------------------------------- /test/check/badconst.err: -------------------------------------------------------------------------------- 1 | 2:3: const value 4 does not match type bool 2 | 3:3: const value true does not match type int 3 | 4:3: const of non-primitive type ptr 4 | 5:3: unknown const type blah 5 | -------------------------------------------------------------------------------- /test/check/badid.bril: -------------------------------------------------------------------------------- 1 | @main(a: int) { 2 | b: bool = id a; 3 | id a; 4 | c: int = id; 5 | } 6 | -------------------------------------------------------------------------------- /test/check/badid.err: -------------------------------------------------------------------------------- 1 | 2:3: a has type int, but arg 0 for id should have type bool 2 | 3:3: missing result type T for id 3 | 4:3: id expects 1 args, not 0 4 | -------------------------------------------------------------------------------- /test/check/badmem.bril: -------------------------------------------------------------------------------- 1 | @main(i: int, f: float) { 2 | p: ptr = alloc f; 3 | p2: int = alloc i; 4 | 5 | store p f; 6 | store i p; 7 | 8 | j: float = load p; 9 | i: int = load i; 10 | 11 | q: ptr = ptradd p i; 12 | q2: ptr = ptradd i p; 13 | 14 | free i; 15 | } 16 | -------------------------------------------------------------------------------- /test/check/char.bril: -------------------------------------------------------------------------------- 1 | @main() { 2 | c: char = const 'a'; 3 | n: int = id c; 4 | 5 | b1: bool = ceq c c; 6 | b2: bool = clt c b1; 7 | b3: bool = cle n c; 8 | b4: bool = cgt c; 9 | b5: char = cge c c; 10 | 11 | c2: char = int2char c; 12 | i2: int = char2int b1; 13 | } -------------------------------------------------------------------------------- /test/check/char.err: -------------------------------------------------------------------------------- 1 | 3:3: c has type char, but arg 0 for id should have type int 2 | 6:3: b1 has type bool, but arg 1 for clt should have type char 3 | 7:3: n has type int, but arg 0 for cle should have type char 4 | 8:3: cgt expects 2 args, not 1 5 | 9:3: result type of cge should be bool, but found char 6 | 11:3: c has type char, but arg 0 for int2char should have type int 7 | 12:3: b1 has type bool, but arg 0 for char2int should have type char 8 | -------------------------------------------------------------------------------- /test/check/extra.bril: -------------------------------------------------------------------------------- 1 | @main(a: int, b: int) { 2 | c: int = add a b a; 3 | } 4 | -------------------------------------------------------------------------------- /test/check/extra.err: -------------------------------------------------------------------------------- 1 | 2:3: add expects 2 args, not 3 2 | -------------------------------------------------------------------------------- /test/check/labels.bril: -------------------------------------------------------------------------------- 1 | @main(b: bool) { 2 | jmp .bad; 3 | br b .foo; 4 | br b .foo .foo .foo; 5 | c: bool = not b .foo; 6 | .foo: 7 | .bar: 8 | .bar: 9 | } 10 | -------------------------------------------------------------------------------- /test/check/labels.err: -------------------------------------------------------------------------------- 1 | 8:1: multiply defined label .bar 2 | 2:3: label .bad undefined 3 | 3:3: br needs 2 labels; found 1 4 | 4:3: br needs 2 labels; found 3 5 | 5:3: not needs 0 labels; found 1 6 | -------------------------------------------------------------------------------- /test/check/main-args.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 1 2 2 | # RETURN: 0 3 | @main(x: int, y: int) { 4 | v: int = add x y; 5 | print v; 6 | } 7 | -------------------------------------------------------------------------------- /test/check/main-args.err: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sampsyo/bril/b006a86ff9ba07cfccf85f2e0120398b2f284db7/test/check/main-args.err -------------------------------------------------------------------------------- /test/check/mainret.bril: -------------------------------------------------------------------------------- 1 | @main(x: int): int { 2 | ret x; 3 | } 4 | -------------------------------------------------------------------------------- /test/check/mainret.err: -------------------------------------------------------------------------------- 1 | 1:1: @main must have no return type; found int 2 | -------------------------------------------------------------------------------- /test/check/mem.bril: -------------------------------------------------------------------------------- 1 | # RETURN: 0 2 | @main(i: int) { 3 | p: ptr = alloc i; 4 | r: ptr = alloc i; 5 | store p i; 6 | j: int = load p; 7 | q: ptr = ptradd p i; 8 | free p; 9 | } 10 | -------------------------------------------------------------------------------- /test/check/mem.err: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sampsyo/bril/b006a86ff9ba07cfccf85f2e0120398b2f284db7/test/check/mem.err -------------------------------------------------------------------------------- /test/check/missarg.bril: -------------------------------------------------------------------------------- 1 | @main(a: int, b: int) { 2 | c: int = add a; 3 | } 4 | -------------------------------------------------------------------------------- /test/check/missarg.err: -------------------------------------------------------------------------------- 1 | 2:3: add expects 2 args, not 1 2 | -------------------------------------------------------------------------------- /test/check/missdest.bril: -------------------------------------------------------------------------------- 1 | @main(a: int, b: int) { 2 | add a b; 3 | } 4 | -------------------------------------------------------------------------------- /test/check/missdest.err: -------------------------------------------------------------------------------- 1 | 2:3: missing result type int for add 2 | -------------------------------------------------------------------------------- /test/check/printres.bril: -------------------------------------------------------------------------------- 1 | @main(a: int) { 2 | b: int = print a; 3 | } 4 | -------------------------------------------------------------------------------- /test/check/printres.err: -------------------------------------------------------------------------------- 1 | 2:3: print should have no result type 2 | -------------------------------------------------------------------------------- /test/check/ptr.bril: -------------------------------------------------------------------------------- 1 | @main(a: ptr) { 2 | b: ptr = id a; 3 | c: ptr = id a; 4 | } 5 | -------------------------------------------------------------------------------- /test/check/ptr.err: -------------------------------------------------------------------------------- 1 | 3:3: a has type ptr, but arg 0 for id should have type ptr 2 | -------------------------------------------------------------------------------- /test/check/speculate.bril: -------------------------------------------------------------------------------- 1 | @main(x: int, b: bool) { 2 | speculate; 3 | commit; 4 | guard b .l; 5 | 6 | speculate x; 7 | y: int = speculate; 8 | 9 | commit x; 10 | y: int = commit; 11 | 12 | guard .l; 13 | guard b; 14 | y: int = guard b .l; 15 | 16 | .l: 17 | } 18 | -------------------------------------------------------------------------------- /test/check/speculate.err: -------------------------------------------------------------------------------- 1 | 6:3: speculate expects 0 args, not 1 2 | 7:3: speculate should have no result type 3 | 9:3: commit expects 0 args, not 1 4 | 10:3: commit should have no result type 5 | 12:3: guard expects 1 args, not 0 6 | 13:3: guard needs 1 labels; found 0 7 | 14:3: guard should have no result type 8 | -------------------------------------------------------------------------------- /test/check/ssa.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | .a: 3 | x: int = const 4; 4 | set z x; 5 | jmp .c; 6 | .b: 7 | y: int = const 2; 8 | set z y; 9 | jmp .c; 10 | .c: 11 | z: int = get; 12 | z: float = get; 13 | z: int = get x; 14 | } 15 | 16 | @more { 17 | b: int = const 1; 18 | c: int = const 2; 19 | d: float = const 3.14; 20 | 21 | set; 22 | a: int = set b c; 23 | set b d; 24 | } 25 | -------------------------------------------------------------------------------- /test/check/ssa.err: -------------------------------------------------------------------------------- 1 | 12:3: new type float for z conflicts with old type int 2 | 13:3: get expects 0 args, not 1 3 | 21:3: set expects 2 args, not 0 4 | 22:3: set should have no result type 5 | 23:3: d has type float, but arg 1 for set should have type int 6 | -------------------------------------------------------------------------------- /test/check/tiny.bril: -------------------------------------------------------------------------------- 1 | # RETURN: 0 2 | @main { 3 | v: int = const 5; 4 | print v; 5 | } 6 | -------------------------------------------------------------------------------- /test/check/tiny.err: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sampsyo/bril/b006a86ff9ba07cfccf85f2e0120398b2f284db7/test/check/tiny.err -------------------------------------------------------------------------------- /test/check/turnt.toml: -------------------------------------------------------------------------------- 1 | [envs.brilck] 2 | command = "bril2json -p < {filename} | brilck" 3 | return_code = 1 4 | output.err = "2" 5 | 6 | [envs.brilirs] 7 | default = false 8 | command = "cargo run --manifest-path ../../brilirs/Cargo.toml -- --check --file {filename} --text {args}" 9 | return_code = 2 10 | output = {} 11 | -------------------------------------------------------------------------------- /test/check/typeconflict.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | a: bool = const true; 3 | a: int = const 4; 4 | } 5 | -------------------------------------------------------------------------------- /test/check/typeconflict.err: -------------------------------------------------------------------------------- 1 | 3:3: new type int for a conflicts with old type bool 2 | -------------------------------------------------------------------------------- /test/check/undef.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | b: int = add a b; 3 | } 4 | -------------------------------------------------------------------------------- /test/check/undef.err: -------------------------------------------------------------------------------- 1 | 2:3: a (arg 0) undefined 2 | -------------------------------------------------------------------------------- /test/interp-error/char-error/badconversion.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | i: int = const 56193; 3 | 4 | c: char = int2char i; 5 | 6 | print c; 7 | } 8 | -------------------------------------------------------------------------------- /test/interp-error/char-error/badconversion.err: -------------------------------------------------------------------------------- 1 | error: value 56193 cannot be converted to char 2 | -------------------------------------------------------------------------------- /test/interp-error/core-error/call-nonvoid-return-nothing-error.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | x: int = const 2; 3 | y: int = const 2; 4 | z: int = call @add2 x y; 5 | print y; 6 | print z; 7 | } 8 | @add2(x: int, y: int): int { 9 | w: int = add x y; 10 | y: int = const 5; 11 | print w; 12 | ret; 13 | } 14 | -------------------------------------------------------------------------------- /test/interp-error/core-error/call-nonvoid-return-nothing-error.err: -------------------------------------------------------------------------------- 1 | error: non-void function (type: int) doesn't return anything 2 | -------------------------------------------------------------------------------- /test/interp-error/core-error/call-return-nothing-error.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | v: int = call @print4; 3 | } 4 | @print4: int { 5 | ret; 6 | } 7 | -------------------------------------------------------------------------------- /test/interp-error/core-error/call-return-nothing-error.err: -------------------------------------------------------------------------------- 1 | error: non-void function (type: int) doesn't return anything 2 | -------------------------------------------------------------------------------- /test/interp-error/core-error/call-return-wrong-type.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | v: int = call @print4; 3 | } 4 | @print4: int { 5 | b: bool = const false; 6 | ret b; 7 | } 8 | -------------------------------------------------------------------------------- /test/interp-error/core-error/call-return-wrong-type.err: -------------------------------------------------------------------------------- 1 | error: type of value returned by function does not match destination type 2 | -------------------------------------------------------------------------------- /test/interp-error/core-error/call-void-return-error.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | call @print4; 3 | } 4 | @print4 { 5 | v: int = const 4; 6 | ret v; 7 | } 8 | -------------------------------------------------------------------------------- /test/interp-error/core-error/call-void-return-error.err: -------------------------------------------------------------------------------- 1 | error: unexpected value returned without destination 2 | -------------------------------------------------------------------------------- /test/interp-error/core-error/call-wrong-argument-types.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | x: int = const 1; 3 | call @add2 x; 4 | } 5 | @add2(x: bool): int { 6 | z: int = const 2; 7 | w: int = add x z; 8 | print w; 9 | } 10 | -------------------------------------------------------------------------------- /test/interp-error/core-error/call-wrong-argument-types.err: -------------------------------------------------------------------------------- 1 | error: function argument type mismatch 2 | -------------------------------------------------------------------------------- /test/interp-error/core-error/call-wrong-arity.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | x: int = const 1; 3 | y: int = const 2; 4 | z: int = const 3; 5 | call @addboth x y z; 6 | } 7 | @addboth(x: int, y: int) { 8 | w: int = add x y; 9 | print w; 10 | } 11 | -------------------------------------------------------------------------------- /test/interp-error/core-error/call-wrong-arity.err: -------------------------------------------------------------------------------- 1 | error: function expected 2 arguments, got 3 2 | -------------------------------------------------------------------------------- /test/interp-error/core-error/call-wrong-declared-type.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | x: int = const 2; 3 | y: int = const 2; 4 | z: int = call @add2 x y; 5 | print y; 6 | print z; 7 | } 8 | @add2(x: int, y: int): bool { 9 | w: int = add x y; 10 | y: int = const 5; 11 | print w; 12 | ret w; 13 | } 14 | -------------------------------------------------------------------------------- /test/interp-error/core-error/call-wrong-declared-type.err: -------------------------------------------------------------------------------- 1 | error: type of value returned by function does not match declaration 2 | -------------------------------------------------------------------------------- /test/interp-error/core-error/divide_by_zero.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | v0: int = const -1; 3 | zero: int = const 0; 4 | res: int = div v0 zero; 5 | print res; 6 | } 7 | -------------------------------------------------------------------------------- /test/interp-error/core-error/divide_by_zero.err: -------------------------------------------------------------------------------- 1 | error: division by zero 2 | -------------------------------------------------------------------------------- /test/interp-error/core-error/duplicate_function.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | call @f; 3 | } 4 | @f { 5 | v: int = const 1; 6 | print v; 7 | } 8 | @f { 9 | v: int = const 2; 10 | print v; 11 | } 12 | -------------------------------------------------------------------------------- /test/interp-error/core-error/duplicate_function.err: -------------------------------------------------------------------------------- 1 | error: multiple functions of name f found 2 | -------------------------------------------------------------------------------- /test/interp-error/core-error/duplicate_main.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | v: int = const 1; 3 | print v; 4 | } 5 | @main { 6 | v: int = const 2; 7 | print v; 8 | } 9 | -------------------------------------------------------------------------------- /test/interp-error/core-error/duplicate_main.err: -------------------------------------------------------------------------------- 1 | error: multiple functions of name main found 2 | -------------------------------------------------------------------------------- /test/interp-error/core-error/undefined-func.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | call @notafun; 3 | } 4 | -------------------------------------------------------------------------------- /test/interp-error/core-error/undefined-func.err: -------------------------------------------------------------------------------- 1 | error: no function of name notafun found 2 | -------------------------------------------------------------------------------- /test/interp-error/dynamic-error/dynamic_error_simple.bril: -------------------------------------------------------------------------------- 1 | @main() { 2 | v: any = const 4; 3 | b: bool = and v v; 4 | } -------------------------------------------------------------------------------- /test/interp-error/dynamic-error/dynamic_error_simple.err: -------------------------------------------------------------------------------- 1 | error: and argument 0 must be a bool 2 | -------------------------------------------------------------------------------- /test/interp-error/mem-error/double_free.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | one: int = const 1; 3 | p: ptr = alloc one; 4 | free p; 5 | free p; 6 | } 7 | -------------------------------------------------------------------------------- /test/interp-error/mem-error/double_free.err: -------------------------------------------------------------------------------- 1 | error: Tried to free illegal memory location base: 0, offset: 0. Offset must be 0. 2 | -------------------------------------------------------------------------------- /test/interp-error/mem-error/free_offset.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | one: int = const 1; 3 | two: int = const 2; 4 | p: ptr = alloc two; 5 | p1: ptr = ptradd p one; 6 | free p1; 7 | } 8 | -------------------------------------------------------------------------------- /test/interp-error/mem-error/free_offset.err: -------------------------------------------------------------------------------- 1 | error: Tried to free illegal memory location base: 0, offset: 1. Offset must be 0. 2 | -------------------------------------------------------------------------------- /test/interp-error/mem-error/leak.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | two: int = const 2; 3 | p: ptr = alloc two; 4 | } 5 | -------------------------------------------------------------------------------- /test/interp-error/mem-error/leak.err: -------------------------------------------------------------------------------- 1 | error: Some memory locations have not been freed by end of execution. 2 | -------------------------------------------------------------------------------- /test/interp-error/mem-error/out_of_bounds.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | two: int = const 2; 3 | p: ptr = alloc two; 4 | p1: ptr = ptradd p two; 5 | store p1 two; 6 | free p; 7 | } 8 | -------------------------------------------------------------------------------- /test/interp-error/mem-error/out_of_bounds.err: -------------------------------------------------------------------------------- 1 | error: Uninitialized heap location 0 and/or illegal offset 2 2 | -------------------------------------------------------------------------------- /test/interp-error/mem-error/out_of_bounds_2.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | two: int = const 2; 3 | negone: int = const -1; 4 | p: ptr = alloc two; 5 | p1: ptr = ptradd p negone; 6 | store p1 two; 7 | free p; 8 | } 9 | -------------------------------------------------------------------------------- /test/interp-error/mem-error/out_of_bounds_2.err: -------------------------------------------------------------------------------- 1 | error: Uninitialized heap location 0 and/or illegal offset -1 2 | -------------------------------------------------------------------------------- /test/interp-error/mem-error/uninit_read.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | two: int = const 2; 3 | p: ptr = alloc two; 4 | tmp: int = load p; 5 | print tmp; 6 | free p; 7 | } 8 | -------------------------------------------------------------------------------- /test/interp-error/mem-error/uninit_read.err: -------------------------------------------------------------------------------- 1 | error: Pointer p points to uninitialized data 2 | -------------------------------------------------------------------------------- /test/interp-error/mem-error/wrong_write.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | two: int = const 2; 3 | p: ptr = alloc two; 4 | btrue: bool = const true; 5 | store p btrue; 6 | free p; 7 | } 8 | -------------------------------------------------------------------------------- /test/interp-error/mem-error/wrong_write.err: -------------------------------------------------------------------------------- 1 | error: store argument 1 must be a int 2 | -------------------------------------------------------------------------------- /test/interp-error/spec-error/spec-call.bril: -------------------------------------------------------------------------------- 1 | @foo { 2 | } 3 | 4 | @main { 5 | speculate; 6 | call @foo; 7 | commit; 8 | } 9 | -------------------------------------------------------------------------------- /test/interp-error/spec-error/spec-call.err: -------------------------------------------------------------------------------- 1 | error: call not allowed during speculation 2 | -------------------------------------------------------------------------------- /test/interp-error/spec-error/spec-double-commit.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | speculate; 3 | commit; 4 | commit; 5 | } 6 | -------------------------------------------------------------------------------- /test/interp-error/spec-error/spec-double-commit.err: -------------------------------------------------------------------------------- 1 | error: commit in non-speculative state 2 | -------------------------------------------------------------------------------- /test/interp-error/spec-error/spec-nonspec-abort.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | speculate; 3 | commit; 4 | f: bool = const false; 5 | guard f .lbl; 6 | .lbl: 7 | } 8 | -------------------------------------------------------------------------------- /test/interp-error/spec-error/spec-nonspec-abort.err: -------------------------------------------------------------------------------- 1 | error: abort in non-speculative state 2 | -------------------------------------------------------------------------------- /test/interp-error/spec-error/spec-return-implicit.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | speculate; 3 | } 4 | -------------------------------------------------------------------------------- /test/interp-error/spec-error/spec-return-implicit.err: -------------------------------------------------------------------------------- 1 | error: implicit return in speculative state 2 | -------------------------------------------------------------------------------- /test/interp-error/spec-error/spec-return.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | speculate; 3 | ret; 4 | } 5 | -------------------------------------------------------------------------------- /test/interp-error/spec-error/spec-return.err: -------------------------------------------------------------------------------- 1 | error: ret not allowed during speculation 2 | -------------------------------------------------------------------------------- /test/interp-error/ssa-error/double-phi.err: -------------------------------------------------------------------------------- 1 | error: get without corresponding set for x 2 | -------------------------------------------------------------------------------- /test/interp-error/ssa-error/missing-set.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | x: int = get; 3 | } 4 | -------------------------------------------------------------------------------- /test/interp-error/ssa-error/missing-set.err: -------------------------------------------------------------------------------- 1 | error: get without corresponding set for x 2 | -------------------------------------------------------------------------------- /test/interp-error/ssa-error/undef-add.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | x: int = undef; 3 | y: int = const 2; 4 | z: int = add x y; 5 | } 6 | -------------------------------------------------------------------------------- /test/interp-error/ssa-error/undef-add.err: -------------------------------------------------------------------------------- 1 | error: add argument 0 must be a int 2 | -------------------------------------------------------------------------------- /test/interp-error/ssa-error/undef-print.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | x: int = undef; 3 | print x; 4 | } 5 | -------------------------------------------------------------------------------- /test/interp-error/ssa-error/undef-print.err: -------------------------------------------------------------------------------- 1 | error: print of undefined value 2 | -------------------------------------------------------------------------------- /test/interp-error/turnt.toml: -------------------------------------------------------------------------------- 1 | [envs.brili] 2 | command = "bril2json < {filename} | brili {args}" 3 | return_code = 2 4 | output.err = "2" 5 | 6 | [envs.brilirs] 7 | default = false 8 | command = "cargo run --manifest-path ../../brilirs/Cargo.toml -- --file {filename} --text {args}" 9 | return_code = 2 10 | output = {} 11 | -------------------------------------------------------------------------------- /test/interp/bitcast/float_and_int.bril: -------------------------------------------------------------------------------- 1 | @main() { 2 | as_int: int = const 4591870180066957722; 3 | as_float: float = bits2float as_int; 4 | back_to_int: int = float2bits as_float; 5 | print as_int as_float back_to_int; 6 | } 7 | -------------------------------------------------------------------------------- /test/interp/bitcast/float_and_int.out: -------------------------------------------------------------------------------- 1 | 4591870180066957722 0.10000000000000001 4591870180066957722 2 | -------------------------------------------------------------------------------- /test/interp/char/char.bril: -------------------------------------------------------------------------------- 1 | @main() { 2 | c1: char = const 'h'; 3 | c2: char = const 'e'; 4 | c3: char = const 'y'; 5 | c4: char = const '🐶'; 6 | print c1 c2 c3 c4; 7 | } -------------------------------------------------------------------------------- /test/interp/char/char.out: -------------------------------------------------------------------------------- 1 | h e y 🐶 2 | -------------------------------------------------------------------------------- /test/interp/char/char_args.bril: -------------------------------------------------------------------------------- 1 | # ARGS: h e y 🐱 2 | @main(c1: char, c2: char, c3: char, c4: char) { 3 | print c1 c2 c3 c4; 4 | } -------------------------------------------------------------------------------- /test/interp/char/char_args.out: -------------------------------------------------------------------------------- 1 | h e y 🐱 2 | -------------------------------------------------------------------------------- /test/interp/char/char_ops.bril: -------------------------------------------------------------------------------- 1 | @main() { 2 | c1: char = const 'a'; 3 | c2: char = const 'b'; 4 | 5 | b1: bool = ceq c1 c2; 6 | b2: bool = clt c1 c2; 7 | b3: bool = cle c1 c2; 8 | b4: bool = cgt c1 c2; 9 | b5: bool = cge c1 c2; 10 | 11 | print b1 b2 b3 b4 b5; 12 | } -------------------------------------------------------------------------------- /test/interp/char/char_ops.out: -------------------------------------------------------------------------------- 1 | false true true false false 2 | -------------------------------------------------------------------------------- /test/interp/char/control_char.bril: -------------------------------------------------------------------------------- 1 | @main() { 2 | 3 | c1: char = const '\a'; 4 | c2: char = const '\b'; 5 | c3: char = const '\f'; 6 | c4: char = const '\n'; 7 | c5: char = const '\r'; 8 | c6: char = const '\t'; 9 | c7: char = const '\v'; 10 | c8: char = const '\0'; 11 | 12 | print c1 c2 c3 c4 c5 c6 c7 c8; 13 | } -------------------------------------------------------------------------------- /test/interp/char/control_char.out: -------------------------------------------------------------------------------- 1 |   2 | 3 | -------------------------------------------------------------------------------- /test/interp/char/conversions.bril: -------------------------------------------------------------------------------- 1 | @main() { 2 | c1: char = const 'A'; 3 | c2: char = const '𝛀'; 4 | i1: int = const 65; 5 | i2: int = const 120512; 6 | 7 | c3: char = int2char i1; 8 | i3: int = char2int c1; 9 | c4: char = int2char i2; 10 | i4: int = char2int c2; 11 | 12 | print c3 i3 c4 i4; 13 | } -------------------------------------------------------------------------------- /test/interp/char/conversions.out: -------------------------------------------------------------------------------- 1 | A 65 𝛀 120512 2 | -------------------------------------------------------------------------------- /test/interp/core/add-overflow.out: -------------------------------------------------------------------------------- 1 | 4611686018427387904 2 | 9223372036854775807 3 | -9223372036854775808 4 | -------------------------------------------------------------------------------- /test/interp/core/br.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | v: int = const 4; 3 | b: bool = const false; 4 | br b .there .here; 5 | .here: 6 | v: int = const 2; 7 | .there: 8 | print v; 9 | } 10 | -------------------------------------------------------------------------------- /test/interp/core/br.out: -------------------------------------------------------------------------------- 1 | 2 2 | -------------------------------------------------------------------------------- /test/interp/core/call-with-args.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | x: int = const 2; 3 | y: int = const 2; 4 | z: int = call @add2 x y; 5 | print y; 6 | print z; 7 | } 8 | 9 | @add2(x: int, y: int): int { 10 | w: int = add x y; 11 | y: int = const 5; 12 | print w; 13 | ret w; 14 | } 15 | -------------------------------------------------------------------------------- /test/interp/core/call-with-args.out: -------------------------------------------------------------------------------- 1 | 4 2 | 2 3 | 4 4 | -------------------------------------------------------------------------------- /test/interp/core/call.bril: -------------------------------------------------------------------------------- 1 | @main() { 2 | v: int = const 2; 3 | call @print4; 4 | print v; 5 | } 6 | @print4 { 7 | v: int = const 4; 8 | print v; 9 | ret; 10 | } 11 | -------------------------------------------------------------------------------- /test/interp/core/call.out: -------------------------------------------------------------------------------- 1 | 4 2 | 2 3 | -------------------------------------------------------------------------------- /test/interp/core/dead_block.bril: -------------------------------------------------------------------------------- 1 | @abs(x: int): int { 2 | ret x; 3 | .label435: 4 | } 5 | 6 | @main() { 7 | x : int = const 42; 8 | y : int = call @abs x; 9 | print y; 10 | } -------------------------------------------------------------------------------- /test/interp/core/dead_block.out: -------------------------------------------------------------------------------- 1 | 42 2 | -------------------------------------------------------------------------------- /test/interp/core/div.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | v0: int = const 9; 3 | v1: int = const -20; 4 | res: int = div v0 v1; 5 | print res; 6 | } 7 | -------------------------------------------------------------------------------- /test/interp/core/div.out: -------------------------------------------------------------------------------- 1 | 0 2 | -------------------------------------------------------------------------------- /test/interp/core/jmp.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | v: int = const 4; 3 | jmp .somewhere; 4 | v: int = const 2; 5 | .somewhere: 6 | print v; 7 | } 8 | -------------------------------------------------------------------------------- /test/interp/core/jmp.out: -------------------------------------------------------------------------------- 1 | 4 2 | -------------------------------------------------------------------------------- /test/interp/core/main-args.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 1 2 2 | @main(x: int, y: int) { 3 | v: int = add x y; 4 | print v; 5 | } 6 | -------------------------------------------------------------------------------- /test/interp/core/main-args.out: -------------------------------------------------------------------------------- 1 | 3 2 | -------------------------------------------------------------------------------- /test/interp/core/main-bool-args.bril: -------------------------------------------------------------------------------- 1 | # ARGS: true 2 | @main(b: bool) { 3 | br b .here .there; 4 | .here: 5 | v: int = const 1; 6 | print v; 7 | ret; 8 | .there: 9 | v: int = const 2; 10 | print v; 11 | ret; 12 | } 13 | -------------------------------------------------------------------------------- /test/interp/core/main-bool-args.out: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /test/interp/core/non_linear_control_flow.out: -------------------------------------------------------------------------------- 1 | 2 2 | 0 3 | -------------------------------------------------------------------------------- /test/interp/core/nop.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | nop; 3 | v: int = const 5; 4 | nop; 5 | print v; 6 | nop; 7 | } 8 | -------------------------------------------------------------------------------- /test/interp/core/nop.out: -------------------------------------------------------------------------------- 1 | 5 2 | -------------------------------------------------------------------------------- /test/interp/core/ret.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | v: int = const 4; 3 | print v; 4 | ret; 5 | print v; 6 | } 7 | -------------------------------------------------------------------------------- /test/interp/core/ret.out: -------------------------------------------------------------------------------- 1 | 4 2 | -------------------------------------------------------------------------------- /test/interp/core/tiny.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | v: int = const 5; 3 | print v; 4 | } 5 | -------------------------------------------------------------------------------- /test/interp/core/tiny.out: -------------------------------------------------------------------------------- 1 | 5 2 | -------------------------------------------------------------------------------- /test/interp/dynamic/float_dynamic.bril: -------------------------------------------------------------------------------- 1 | @main() { 2 | i: int = const 4; 3 | a: any = const 4; 4 | f: float = const 4; 5 | print i a f; # `4 4 4.00000000000000000` 6 | } -------------------------------------------------------------------------------- /test/interp/dynamic/float_dynamic.out: -------------------------------------------------------------------------------- 1 | 4 4 4.00000000000000000 2 | -------------------------------------------------------------------------------- /test/interp/dynamic/mem_dynamic_dispatch.out: -------------------------------------------------------------------------------- 1 | 1 1 2 | 2.00000000000000000 3 | 2.00000000000000000 4 | -------------------------------------------------------------------------------- /test/interp/dynamic/mem_dynamic_enum.out: -------------------------------------------------------------------------------- 1 | 42 42.00000000000000000 2 | -------------------------------------------------------------------------------- /test/interp/dynamic/mem_dynamic_struct.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | v: int = const 2; 3 | o1: int = const 1; 4 | bp: ptr = alloc v; 5 | bp2: ptr = ptradd bp o1; 6 | b: bool = const true; 7 | i: int = const 0; 8 | store bp b; 9 | store bp2 i; 10 | b: bool = load bp; 11 | i: int = load bp2; 12 | print b i; 13 | free bp; 14 | } 15 | -------------------------------------------------------------------------------- /test/interp/dynamic/mem_dynamic_struct.out: -------------------------------------------------------------------------------- 1 | true 0 2 | -------------------------------------------------------------------------------- /test/interp/float/float.bril: -------------------------------------------------------------------------------- 1 | @main() { 2 | v0: float = const 9.0; 3 | v1: float = const -20.0; 4 | res: float = fdiv v0 v1; 5 | print res; 6 | 7 | v2: float = const .1; 8 | v3: float = const 0.1; 9 | add1: float = fadd v2 v3; 10 | dres: float = fadd add1 v2; 11 | print dres; 12 | 13 | v4: float = const .1; 14 | add2: float = fadd v4 v4; 15 | fres: float = fadd add2 v4; 16 | print fres; 17 | } 18 | -------------------------------------------------------------------------------- /test/interp/float/float.out: -------------------------------------------------------------------------------- 1 | -0.45000000000000001 2 | 0.30000000000000004 3 | 0.30000000000000004 4 | -------------------------------------------------------------------------------- /test/interp/float/float_args.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 3 3.0 -0.3 2 | @main(float_one : float, float_two : float, float_three : float) { 3 | print float_one float_two float_three; 4 | } -------------------------------------------------------------------------------- /test/interp/float/float_args.out: -------------------------------------------------------------------------------- 1 | 3.00000000000000000 3.00000000000000000 -0.29999999999999999 2 | -------------------------------------------------------------------------------- /test/interp/float/float_divide_by_zero.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | v0: float = const -1.0; 3 | v1: float = const 1.0; 4 | zero: float = const 0.0; 5 | res: float = fdiv v0 zero; 6 | print res; 7 | res: float = fdiv v1 zero; 8 | print res; 9 | res: float = fdiv zero zero; 10 | print res; 11 | } 12 | -------------------------------------------------------------------------------- /test/interp/float/float_divide_by_zero.out: -------------------------------------------------------------------------------- 1 | -Infinity 2 | Infinity 3 | NaN 4 | -------------------------------------------------------------------------------- /test/interp/float/float_special.out: -------------------------------------------------------------------------------- 1 | 0.00000000000000000 2 | -0.00000000000000000 3 | true 4 | 1000000.00000000000000000 5 | 0.00000100000000000 6 | -1000000.00000000000000000 7 | 1.10000000000000000e+11 8 | 1.00000000000000000e+21 9 | 9.99999999999999908e-22 10 | 100000.00000000000000000 11 | -------------------------------------------------------------------------------- /test/interp/mem/access.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | inc: int = const 1; 3 | v: int = const 1000000; 4 | max: int = const 1000000; 5 | p: ptr = alloc v; 6 | count: int = const 0; 7 | .lbl: 8 | count: int = add count inc; 9 | store p v; 10 | val: int = load p; 11 | loop: bool = ge count max; 12 | br loop .end .lbl; 13 | .end: 14 | free p; 15 | print count; 16 | } 17 | -------------------------------------------------------------------------------- /test/interp/mem/access.out: -------------------------------------------------------------------------------- 1 | 1000000 2 | -------------------------------------------------------------------------------- /test/interp/mem/access_many.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | inc: int = const 1; 3 | v: int = const 1000000; 4 | max: int = const 1000000; 5 | p: ptr = alloc v; 6 | count: int = const 0; 7 | p2: ptr = ptradd p count; 8 | .lbl: 9 | count: int = add count inc; 10 | store p2 v; 11 | val: int = load p2; 12 | loop: bool = ge count max; 13 | br loop .end .lbl; 14 | .end: 15 | free p; 16 | print count; 17 | } 18 | -------------------------------------------------------------------------------- /test/interp/mem/access_many.out: -------------------------------------------------------------------------------- 1 | 1000000 2 | -------------------------------------------------------------------------------- /test/interp/mem/access_ptr.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | inc: int = const 1; 3 | v: int = const 1000; 4 | max: int = const 1000000; 5 | count: int = const 0; 6 | pi: ptr = alloc v; 7 | pp: ptr> = alloc v; 8 | .lbl: 9 | count: int = add count inc; 10 | store pp pi; 11 | pi: ptr = load pp; 12 | loop: bool = ge count max; 13 | br loop .end .lbl; 14 | .end: 15 | free pi; 16 | free pp; 17 | print count; 18 | } 19 | -------------------------------------------------------------------------------- /test/interp/mem/access_ptr.out: -------------------------------------------------------------------------------- 1 | 1000000 2 | -------------------------------------------------------------------------------- /test/interp/mem/alloc.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | v: int = const 4; 3 | o1: int = const 1; 4 | bp: ptr = alloc v; 5 | bp2: ptr = ptradd bp o1; 6 | b: bool = const true; 7 | store bp b; 8 | store bp2 b; 9 | b: bool = load bp2; 10 | print b; 11 | free bp; 12 | } 13 | -------------------------------------------------------------------------------- /test/interp/mem/alloc.out: -------------------------------------------------------------------------------- 1 | true 2 | -------------------------------------------------------------------------------- /test/interp/mem/alloc_large.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | inc: int = const 1; 3 | v: int = const 1000; 4 | max: int = const 1000000; 5 | count: int = const 0; 6 | .lbl: 7 | count: int = add count inc; 8 | p: ptr = alloc v; 9 | free p; 10 | loop: bool = ge count max; 11 | br loop .end .lbl; 12 | .end: 13 | print count; 14 | } 15 | -------------------------------------------------------------------------------- /test/interp/mem/alloc_large.out: -------------------------------------------------------------------------------- 1 | 1000000 2 | -------------------------------------------------------------------------------- /test/interp/mem/alloc_many.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | v: int = const 1; 3 | max: int = const 1000000; 4 | count: int = const 0; 5 | .lbl: 6 | count: int = add count v; 7 | p: ptr = alloc v; 8 | free p; 9 | loop: bool = ge count max; 10 | br loop .end .lbl; 11 | .end: 12 | print count; 13 | } 14 | -------------------------------------------------------------------------------- /test/interp/mem/alloc_many.out: -------------------------------------------------------------------------------- 1 | 1000000 2 | -------------------------------------------------------------------------------- /test/interp/mem/fib.out: -------------------------------------------------------------------------------- 1 | 34 2 | -------------------------------------------------------------------------------- /test/interp/mem/mem_id.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | v: int = const 4; 3 | bp: ptr = alloc v; 4 | bp2: ptr = id bp; 5 | b: bool = const true; 6 | store bp2 b; 7 | b: bool = load bp2; 8 | print b; 9 | free bp; 10 | } 11 | -------------------------------------------------------------------------------- /test/interp/mem/mem_id.out: -------------------------------------------------------------------------------- 1 | true 2 | -------------------------------------------------------------------------------- /test/interp/mem/ptr_call.bril: -------------------------------------------------------------------------------- 1 | @funcA(p: ptr) { 2 | ret; 3 | } 4 | 5 | @main { 6 | five: int = const 5; 7 | x: ptr = alloc five; 8 | call @funcA x; 9 | free x; 10 | } 11 | -------------------------------------------------------------------------------- /test/interp/mem/ptr_call.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sampsyo/bril/b006a86ff9ba07cfccf85f2e0120398b2f284db7/test/interp/mem/ptr_call.out -------------------------------------------------------------------------------- /test/interp/mem/ptr_ret.bril: -------------------------------------------------------------------------------- 1 | @ident(p: ptr): ptr { 2 | ret p; 3 | } 4 | @main { 5 | a: int = const 9; 6 | b: ptr = alloc a; 7 | c: ptr = call @ident b; 8 | free b; 9 | } 10 | -------------------------------------------------------------------------------- /test/interp/mem/ptr_ret.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sampsyo/bril/b006a86ff9ba07cfccf85f2e0120398b2f284db7/test/interp/mem/ptr_ret.out -------------------------------------------------------------------------------- /test/interp/mixed/store-char.out: -------------------------------------------------------------------------------- 1 | o 2 | i 3 | . 4 | -------------------------------------------------------------------------------- /test/interp/mixed/store-float.bril: -------------------------------------------------------------------------------- 1 | @main() { 2 | one: int = const 1; 3 | seed: float = const 109658.0; 4 | rng: ptr = alloc one; 5 | store rng seed; 6 | x: float = load rng; 7 | print x; 8 | free rng; 9 | } -------------------------------------------------------------------------------- /test/interp/mixed/store-float.out: -------------------------------------------------------------------------------- 1 | 109658.00000000000000000 2 | -------------------------------------------------------------------------------- /test/interp/spec/spec-abort.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | v: int = const 4; 3 | speculate; 4 | v: int = const 2; 5 | b: bool = const false; 6 | guard b .failed; 7 | commit; 8 | print v; 9 | ret; 10 | .failed: 11 | y: int = const 0; 12 | print y; 13 | } 14 | -------------------------------------------------------------------------------- /test/interp/spec/spec-abort.out: -------------------------------------------------------------------------------- 1 | 0 2 | -------------------------------------------------------------------------------- /test/interp/spec/spec-commit.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | v: int = const 4; 3 | speculate; 4 | v: int = const 2; 5 | commit; 6 | print v; 7 | } 8 | -------------------------------------------------------------------------------- /test/interp/spec/spec-commit.out: -------------------------------------------------------------------------------- 1 | 2 2 | -------------------------------------------------------------------------------- /test/interp/spec/spec-nested.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | v: int = const 4; 3 | speculate; 4 | v: int = const 2; 5 | speculate; 6 | v: int = const 7; 7 | b1: bool = const false; 8 | guard b1 .failed1; 9 | ret; 10 | .failed1: 11 | y: int = const 0; 12 | b2: bool = const true; 13 | guard b2 .failed2; 14 | commit; 15 | print v; 16 | print y; 17 | ret; 18 | .failed2: 19 | ret; 20 | } 21 | -------------------------------------------------------------------------------- /test/interp/spec/spec-nested.out: -------------------------------------------------------------------------------- 1 | 2 2 | 0 3 | -------------------------------------------------------------------------------- /test/interp/spec/spec-noabort.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | v: int = const 4; 3 | speculate; 4 | v: int = const 2; 5 | b: bool = const true; 6 | guard b .failed; 7 | commit; 8 | print v; 9 | ret; 10 | .failed: 11 | y: int = const 0; 12 | print y; 13 | } 14 | -------------------------------------------------------------------------------- /test/interp/spec/spec-noabort.out: -------------------------------------------------------------------------------- 1 | 2 2 | -------------------------------------------------------------------------------- /test/interp/ssa/ssa-simple.bril: -------------------------------------------------------------------------------- 1 | # ARGS: true 2 | @main(cond: bool) { 3 | .top: 4 | a: int = const 5; 5 | set c a; 6 | br cond .here .there; 7 | .here: 8 | b: int = const 7; 9 | set c b; 10 | .there: 11 | c: int = get; 12 | print c; 13 | } 14 | -------------------------------------------------------------------------------- /test/interp/ssa/ssa-simple.out: -------------------------------------------------------------------------------- 1 | 7 2 | -------------------------------------------------------------------------------- /test/interp/ssa/ssa-two-phi.bril: -------------------------------------------------------------------------------- 1 | # ARGS: true 2 | @main(cond: bool) { 3 | .top: 4 | a: int = const 5; 5 | set c a; 6 | set d a; 7 | br cond .here .there; 8 | .here: 9 | b: int = const 7; 10 | set c b; 11 | set d b; 12 | .there: 13 | c: int = get; 14 | d: int = get; 15 | print c; 16 | print d; 17 | } 18 | -------------------------------------------------------------------------------- /test/interp/ssa/ssa-two-phi.out: -------------------------------------------------------------------------------- 1 | 7 2 | 7 3 | -------------------------------------------------------------------------------- /test/interp/ssa/ssu-regression.bril: -------------------------------------------------------------------------------- 1 | @main() { 2 | one: int = const 1; 3 | set shadow one; 4 | main.cond: bool = const true; 5 | set cond main.cond; 6 | .test: 7 | cond: bool = get; 8 | shadow: int = get; 9 | br cond .false .end; 10 | .false: 11 | false.cond: bool = const false; 12 | set cond false.cond; 13 | jmp .test; 14 | .end: 15 | print shadow; 16 | } 17 | -------------------------------------------------------------------------------- /test/interp/ssa/ssu-regression.out: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /test/interp/ssa/swap-problem.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | i: int = const 5; 3 | one: int = const 1; 4 | zero: int = const 0; 5 | 6 | .l0: 7 | x0: int = const 0; 8 | y0: int = const 1; 9 | set x1 x0; 10 | set y1 y0; 11 | jmp .l1; 12 | 13 | .l1: 14 | x1: int = get; 15 | y1: int = get; 16 | print x1 y1; 17 | 18 | cond: bool = gt i zero; 19 | i: int = sub i one; 20 | 21 | set x1 y1; 22 | set y1 x1; 23 | br cond .l1 .end; 24 | 25 | .end: 26 | } 27 | -------------------------------------------------------------------------------- /test/interp/ssa/swap-problem.out: -------------------------------------------------------------------------------- 1 | 0 1 2 | 1 0 3 | 0 1 4 | 1 0 5 | 0 1 6 | 1 0 7 | -------------------------------------------------------------------------------- /test/interp/ssa/undef.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | z: int = const 42; 3 | x: int = undef; 4 | y: int = id x; 5 | print z; 6 | } 7 | -------------------------------------------------------------------------------- /test/interp/ssa/undef.out: -------------------------------------------------------------------------------- 1 | 42 2 | -------------------------------------------------------------------------------- /test/linking/diamond.bril: -------------------------------------------------------------------------------- 1 | # ARGS: ../linking ../../benchmarks/core 2 | from "link_ops.bril" import @main as @inner_main; 3 | from "nested.bril" import @main as @nested_main; 4 | 5 | 6 | @main(){ 7 | call @nested_main; 8 | call @inner_main; 9 | } -------------------------------------------------------------------------------- /test/linking/diamond.out: -------------------------------------------------------------------------------- 1 | 0 2 | 1 3 | 0 4 | 0 5 | 1 6 | 0 7 | -------------------------------------------------------------------------------- /test/linking/link_ops.out: -------------------------------------------------------------------------------- 1 | 0 2 | 1 3 | 0 4 | -------------------------------------------------------------------------------- /test/linking/nested.bril: -------------------------------------------------------------------------------- 1 | # ARGS: ../linking ../../benchmarks/core 2 | from "link_ops.bril" import @main as @nested_main; 3 | 4 | @main(){ 5 | call @nested_main; 6 | } -------------------------------------------------------------------------------- /test/linking/nested.out: -------------------------------------------------------------------------------- 1 | 0 2 | 1 3 | 0 4 | -------------------------------------------------------------------------------- /test/linking/recursive.bril: -------------------------------------------------------------------------------- 1 | # ARGS: ../linking 2 | from "recursive.bril" import @test as @recursive_test; 3 | 4 | @test(a:int){ 5 | zero : int = const 0; 6 | cond : bool = eq a zero; 7 | br cond .end .recurse; 8 | .end: 9 | print zero; 10 | ret; 11 | .recurse: 12 | one : int = const 1; 13 | new_a : int = sub a one; 14 | call @recursive_test new_a; 15 | } 16 | 17 | @main(){ 18 | one : int = const 1; 19 | call @test one; 20 | } -------------------------------------------------------------------------------- /test/linking/recursive.out: -------------------------------------------------------------------------------- 1 | 0 2 | -------------------------------------------------------------------------------- /test/linking/turnt.toml: -------------------------------------------------------------------------------- 1 | [envs.bril-rs] 2 | command = "cargo run --manifest-path ../../bril-rs/brild/Cargo.toml -- --file {filename} --libs {args} | cargo run --manifest-path ../../brilirs/Cargo.toml" 3 | -------------------------------------------------------------------------------- /test/parse/add.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | v0: int = const 1; 3 | v1: int = const 2; 4 | v2: int = add v0 v1; 5 | print v2; 6 | } 7 | -------------------------------------------------------------------------------- /test/parse/char.bril: -------------------------------------------------------------------------------- 1 | @main() { 2 | c1: char = const '6'; 3 | c2: char = const ';'; 4 | 5 | b1: bool = ceq c1 c2; 6 | b2: bool = clt c1 c2; 7 | b3: bool = cle c1 c2; 8 | b4: bool = cgt c1 c2; 9 | b5: bool = cge c1 c2; 10 | } -------------------------------------------------------------------------------- /test/parse/comment.bril: -------------------------------------------------------------------------------- 1 | # This is an awesome program! 2 | @main { 3 | v: int = const 42; # More comments! 4 | # v2: whatever = const 47; 5 | } 6 | -------------------------------------------------------------------------------- /test/parse/comment.json: -------------------------------------------------------------------------------- 1 | { 2 | "functions": [ 3 | { 4 | "instrs": [ 5 | { 6 | "dest": "v", 7 | "op": "const", 8 | "type": "int", 9 | "value": 42 10 | } 11 | ], 12 | "name": "main" 13 | } 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /test/parse/float.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | v0: float = const 1.1; 3 | v1: float = const .02; 4 | v2: float = const 0.3; 5 | v3: float = fadd v0 v1; 6 | v4: float = fmul v2 v2; 7 | v5: float = const 1.; 8 | v6: float = const 1e6; 9 | # v7: float = const 1E-6; 10 | v8: float = const -1E+6; 11 | v9: float = const +.11e12; 12 | } 13 | -------------------------------------------------------------------------------- /test/parse/positions.bril: -------------------------------------------------------------------------------- 1 | # ARGS: -p 2 | @main { 3 | v0: int = const 1; 4 | v1: int = const 2; 5 | jmp .label; 6 | .label: 7 | v2: int = add v0 v1; 8 | print v2; 9 | } 10 | -------------------------------------------------------------------------------- /test/parse/print.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | v: int = const 42; 3 | print v; 4 | } 5 | -------------------------------------------------------------------------------- /test/parse/print.json: -------------------------------------------------------------------------------- 1 | { 2 | "functions": [ 3 | { 4 | "instrs": [ 5 | { 6 | "dest": "v", 7 | "op": "const", 8 | "type": "int", 9 | "value": 42 10 | }, 11 | { 12 | "args": [ 13 | "v" 14 | ], 15 | "op": "print" 16 | } 17 | ], 18 | "name": "main" 19 | } 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /test/parse/turnt.toml: -------------------------------------------------------------------------------- 1 | [envs.bril-txt] 2 | command = "bril2json {args} < {filename}" 3 | output.json = "-" 4 | 5 | [envs.bril-rs] 6 | default = false 7 | command = "cargo run --manifest-path ../../bril-rs/bril2json/Cargo.toml -- {args} < {filename}" 8 | output.json = "-" 9 | -------------------------------------------------------------------------------- /test/print/add.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | v0: int = const 1; 3 | v1: int = const 2; 4 | v2: int = add v0 v1; 5 | print v2; 6 | } 7 | -------------------------------------------------------------------------------- /test/print/add.json: -------------------------------------------------------------------------------- 1 | { 2 | "functions": [ 3 | { 4 | "name": "main", 5 | "instrs": [ 6 | { "op": "const", "type": "int", "dest": "v0", "value": 1 }, 7 | { "op": "const", "type": "int", "dest": "v1", "value": 2 }, 8 | { "op": "add", "type": "int", "dest": "v2", 9 | "args": ["v0", "v1"] }, 10 | { "op": "print", "args": ["v2"] } 11 | ], 12 | "args": [] 13 | } 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /test/print/call.bril: -------------------------------------------------------------------------------- 1 | @add5(n: int): int { 2 | five: int = const 5; 3 | sum: int = add n five; 4 | ret sum; 5 | } 6 | @main { 7 | a: int = const 9; 8 | b: int = call @add5 a; 9 | print b; 10 | } 11 | -------------------------------------------------------------------------------- /test/print/char.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | c1: char = const '7'; 3 | c2: char = const 'a'; 4 | c2: char = const '\n'; 5 | } 6 | -------------------------------------------------------------------------------- /test/print/char.json: -------------------------------------------------------------------------------- 1 | { 2 | "functions": [ 3 | { 4 | "name": "main", 5 | "instrs": [ 6 | { "op": "const", "type": "char", "dest": "c1", "value": "7" }, 7 | { "op": "const", "type": "char", "dest": "c2", "value": "a" }, 8 | { "op": "const", "type": "char", "dest": "c2", "value": "\n" } 9 | ], 10 | "args": [] 11 | } 12 | ] 13 | } -------------------------------------------------------------------------------- /test/print/ptr.bril: -------------------------------------------------------------------------------- 1 | @ident(p: ptr): ptr { 2 | ret p; 3 | } 4 | @main { 5 | a: int = const 9; 6 | b: ptr = alloc a; 7 | c: ptr = call @ident b; 8 | free b; 9 | } 10 | -------------------------------------------------------------------------------- /test/print/spec-abort.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | v: int = const 4; 3 | speculate; 4 | v: int = const 2; 5 | b: bool = const false; 6 | guard b .failed; 7 | commit; 8 | print v; 9 | ret; 10 | .failed: 11 | y: int = const 0; 12 | print y; 13 | } 14 | -------------------------------------------------------------------------------- /test/print/turnt.toml: -------------------------------------------------------------------------------- 1 | [envs.bril-txt] 2 | command = "bril2txt < {filename}" 3 | output.bril = "-" 4 | 5 | [envs.bril-rs] 6 | default = false 7 | command = "cargo run --example bril2txt --manifest-path ../../bril-rs/Cargo.toml < {filename}" 8 | output.bril = "-" 9 | -------------------------------------------------------------------------------- /test/rs/ackermann.out: -------------------------------------------------------------------------------- 1 | 509 2 | -------------------------------------------------------------------------------- /test/rs/boolvar.out: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /test/rs/boolvar.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | let x: bool = true; 3 | if x { 4 | let one:i64 = 1; 5 | println!("{:?}", one); 6 | } else { 7 | let two:i64 = 2; 8 | println!("{:?}", two); 9 | } 10 | } -------------------------------------------------------------------------------- /test/rs/call-explicit.out: -------------------------------------------------------------------------------- 1 | 5 2 | -------------------------------------------------------------------------------- /test/rs/call-explicit.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | let x :i64 = 5; 3 | call_print(x); 4 | } 5 | 6 | fn call_print(x:i64) { 7 | println!("{:?}", x) 8 | } -------------------------------------------------------------------------------- /test/rs/cholesky.out: -------------------------------------------------------------------------------- 1 | 65.00000000000000000 2 | 0.00000000000000000 3 | 0.00000000000000000 4 | 0.00000000000000000 5 | 137.43076923076924345 6 | 55.16143280081702471 7 | 0.00000000000000000 8 | 0.00000000000000000 9 | 148.46153846153845279 10 | 22.60304899166557746 11 | 44.73559850849774477 12 | 0.00000000000000000 13 | 432.26153846153846416 14 | 250.01098702698598686 15 | 374.19363889460623795 16 | 548.34440759751453243 17 | -------------------------------------------------------------------------------- /test/rs/cond.out: -------------------------------------------------------------------------------- 1 | 2 2 | -------------------------------------------------------------------------------- /test/rs/cond.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | let value:i64 = 5; 3 | if value + 3 < 6 { 4 | let one:i64 = 1; 5 | println!("{:?}", one); 6 | } else { 7 | let two:i64 = 2; 8 | println!("{:?}", two); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /test/rs/factorial.out: -------------------------------------------------------------------------------- 1 | 120 2 | -------------------------------------------------------------------------------- /test/rs/factorial.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | let x:i64 = 5; 3 | let f:i64 = fac(x); 4 | println!("{:?}", f); 5 | } 6 | 7 | fn fac(x:i64) -> i64 { 8 | if x <= 1 { 9 | return 1; 10 | } 11 | let result: i64 = x * fac(x -1); 12 | return result; 13 | } 14 | -------------------------------------------------------------------------------- /test/rs/float-add.out: -------------------------------------------------------------------------------- 1 | 42.00000000000000000 2 | -------------------------------------------------------------------------------- /test/rs/float-add.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | let x: f64 = 40.2 + 1.8; 3 | println!("{:.17}", x); 4 | } 5 | -------------------------------------------------------------------------------- /test/rs/loopfact.out: -------------------------------------------------------------------------------- 1 | 40320 2 | -------------------------------------------------------------------------------- /test/rs/loopfact.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | let value:i64 = 8; 3 | let mut result:i64 = 1; 4 | let mut i:i64 = value; 5 | while i > 0 { 6 | result *= i; 7 | i-= 1; 8 | } 9 | println!("{:?}", result); 10 | } 11 | -------------------------------------------------------------------------------- /test/rs/nested_call.out: -------------------------------------------------------------------------------- 1 | 3 2 | -------------------------------------------------------------------------------- /test/rs/nested_call.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | let y:i64 = 1 + get_two(); 3 | println!("{}", y); 4 | } 5 | 6 | fn get_two() -> i64 { 7 | return 2; 8 | } 9 | -------------------------------------------------------------------------------- /test/rs/riemann.out: -------------------------------------------------------------------------------- 1 | 284.00000000000000000 2 | 330.00000000000000000 3 | 380.00000000000000000 4 | -------------------------------------------------------------------------------- /test/rs/turnt.toml: -------------------------------------------------------------------------------- 1 | [envs.bril-rs] 2 | command = "cargo run --manifest-path ../../bril-rs/rs2bril/Cargo.toml < {filename} | cargo run --manifest-path ../../brilirs/Cargo.toml -- {args}" 3 | output.out = "-" 4 | 5 | [envs.rustc] 6 | default = false 7 | command = "rustc {filename} --crate-type bin -o ../../bril-rs/target/a.out && ../../bril-rs/target/a.out {args}" 8 | output.out = "-" -------------------------------------------------------------------------------- /test/ts-error/call-nonvoid-return-nothing.err: -------------------------------------------------------------------------------- 1 | error: non-void function (type: int) doesn't return anything 2 | -------------------------------------------------------------------------------- /test/ts-error/call-nonvoid-return-nothing.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sampsyo/bril/b006a86ff9ba07cfccf85f2e0120398b2f284db7/test/ts-error/call-nonvoid-return-nothing.out -------------------------------------------------------------------------------- /test/ts-error/call-nonvoid-return-nothing.ts: -------------------------------------------------------------------------------- 1 | var x = 1n; 2 | var y = 2n; 3 | var z = add2(x, y); 4 | 5 | function add2(x: bigint, y: bigint): bigint { 6 | return; 7 | } 8 | -------------------------------------------------------------------------------- /test/ts-error/call-return-nothing.err: -------------------------------------------------------------------------------- 1 | error: non-void function (type: int) doesn't return anything 2 | -------------------------------------------------------------------------------- /test/ts-error/call-return-nothing.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sampsyo/bril/b006a86ff9ba07cfccf85f2e0120398b2f284db7/test/ts-error/call-return-nothing.out -------------------------------------------------------------------------------- /test/ts-error/call-return-nothing.ts: -------------------------------------------------------------------------------- 1 | var x = 1n; 2 | var y = 2n; 3 | add2(x, y); 4 | 5 | function add2(x: bigint, y: bigint): bigint { 6 | return; 7 | } 8 | -------------------------------------------------------------------------------- /test/ts-error/call-void-return.err: -------------------------------------------------------------------------------- 1 | error: function with void return type used in value call 2 | -------------------------------------------------------------------------------- /test/ts-error/call-void-return.out: -------------------------------------------------------------------------------- 1 | 4 2 | -------------------------------------------------------------------------------- /test/ts-error/call-void-return.ts: -------------------------------------------------------------------------------- 1 | var x : number = print4(); 2 | 3 | function print4() : void { 4 | var x : number = 4; 5 | console.log(4); 6 | return x; 7 | } -------------------------------------------------------------------------------- /test/ts-error/call-wrong-arity.err: -------------------------------------------------------------------------------- 1 | error: function expected 2 arguments, got 3 2 | -------------------------------------------------------------------------------- /test/ts-error/call-wrong-arity.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sampsyo/bril/b006a86ff9ba07cfccf85f2e0120398b2f284db7/test/ts-error/call-wrong-arity.out -------------------------------------------------------------------------------- /test/ts-error/call-wrong-arity.ts: -------------------------------------------------------------------------------- 1 | var x : number = 1; 2 | var y : number = 2; 3 | var z : number = 3; 4 | addboth(x, y, z); 5 | 6 | function addboth(x : number, y : number) : void { 7 | var z : number = x + y; 8 | console.log(z); 9 | } -------------------------------------------------------------------------------- /test/ts-error/call-wrong-declared-type.err: -------------------------------------------------------------------------------- 1 | error: type of value returned by function does not match declaration 2 | -------------------------------------------------------------------------------- /test/ts-error/call-wrong-declared-type.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sampsyo/bril/b006a86ff9ba07cfccf85f2e0120398b2f284db7/test/ts-error/call-wrong-declared-type.out -------------------------------------------------------------------------------- /test/ts-error/call-wrong-declared-type.ts: -------------------------------------------------------------------------------- 1 | var x : number = 1; 2 | var y : number = 2; 3 | var z : number = addboth(x, y); 4 | 5 | function addboth(x : number, y : number) : boolean { 6 | var w : number = x + y; 7 | return w; 8 | } -------------------------------------------------------------------------------- /test/ts-error/turnt.toml: -------------------------------------------------------------------------------- 1 | command = "ts2bril {filename} | brili" 2 | return_code = 2 3 | output.err = "2" 4 | -------------------------------------------------------------------------------- /test/ts/boolvar.out: -------------------------------------------------------------------------------- 1 | @main { 2 | v0: bool = const true; 3 | x: bool = id v0; 4 | v2: bool = id x; 5 | br v2 .then.1 .else.1; 6 | .then.1: 7 | v3: int = const 1; 8 | print v3; 9 | v4: int = const 0; 10 | jmp .endif.1; 11 | .else.1: 12 | v5: int = const 2; 13 | print v5; 14 | v6: int = const 0; 15 | .endif.1: 16 | } 17 | -------------------------------------------------------------------------------- /test/ts/boolvar.ts: -------------------------------------------------------------------------------- 1 | let x: boolean = true; 2 | if (x) { 3 | console.log(1n); 4 | } else { 5 | console.log(2n); 6 | } 7 | -------------------------------------------------------------------------------- /test/ts/call-explicit-void.out: -------------------------------------------------------------------------------- 1 | @main { 2 | v0: int = const 5; 3 | x: int = id v0; 4 | v1: int = id x; 5 | call @callPrint v1; 6 | v2: int = const 0; 7 | } 8 | @callPrint(x: int) { 9 | v0: int = id x; 10 | print v0; 11 | v1: int = const 0; 12 | } 13 | -------------------------------------------------------------------------------- /test/ts/call-explicit-void.ts: -------------------------------------------------------------------------------- 1 | var x: bigint = 5n; 2 | callPrint(x); 3 | 4 | function callPrint(x: bigint): void { 5 | console.log(x); 6 | } 7 | -------------------------------------------------------------------------------- /test/ts/call.out: -------------------------------------------------------------------------------- 1 | @main { 2 | v0: int = const 5; 3 | x: int = id v0; 4 | v1: int = id x; 5 | call @callPrint v1; 6 | v2: int = const 0; 7 | } 8 | @callPrint(x: int) { 9 | v0: int = id x; 10 | print v0; 11 | v1: int = const 0; 12 | } 13 | -------------------------------------------------------------------------------- /test/ts/call.ts: -------------------------------------------------------------------------------- 1 | var x: bigint = 5n; 2 | callPrint(x); 3 | 4 | function callPrint(x: bigint) { 5 | console.log(x); 6 | } 7 | -------------------------------------------------------------------------------- /test/ts/cond.out: -------------------------------------------------------------------------------- 1 | @main { 2 | v0: int = const 5; 3 | value: int = id v0; 4 | v2: int = id value; 5 | v3: int = const 3; 6 | v4: int = add v2 v3; 7 | v5: int = const 6; 8 | v6: bool = lt v4 v5; 9 | br v6 .then.1 .else.1; 10 | .then.1: 11 | v7: int = const 1; 12 | print v7; 13 | v8: int = const 0; 14 | jmp .endif.1; 15 | .else.1: 16 | v9: int = const 2; 17 | print v9; 18 | v10: int = const 0; 19 | .endif.1: 20 | } 21 | -------------------------------------------------------------------------------- /test/ts/cond.ts: -------------------------------------------------------------------------------- 1 | var value = 5n; 2 | if (value + 3n < 6n) { 3 | console.log(1n); 4 | } else { 5 | console.log(2n); 6 | } 7 | -------------------------------------------------------------------------------- /test/ts/factorial.ts: -------------------------------------------------------------------------------- 1 | var x: bigint = 5n; 2 | var f: bigint = fac(x); 3 | console.log(f); 4 | 5 | function fac(x: bigint): bigint { 6 | if (x <= 1n) { 7 | return 1n; 8 | } 9 | var result = x * fac(x - 1n); 10 | return result; 11 | } 12 | -------------------------------------------------------------------------------- /test/ts/float-add.out: -------------------------------------------------------------------------------- 1 | @main { 2 | v0: float = const 40.2; 3 | v1: float = const 1.8; 4 | v2: float = fadd v0 v1; 5 | print v2; 6 | v3: int = const 0; 7 | } 8 | -------------------------------------------------------------------------------- /test/ts/float-add.ts: -------------------------------------------------------------------------------- 1 | console.log(40.2 + 1.8); 2 | -------------------------------------------------------------------------------- /test/ts/loopfact.ts: -------------------------------------------------------------------------------- 1 | let value = 8n; 2 | let result = 1n; 3 | for (let i = value; i > 0n; i = i - 1n) { 4 | result = result * i; 5 | } 6 | console.log(result); 7 | -------------------------------------------------------------------------------- /test/ts/main.out: -------------------------------------------------------------------------------- 1 | @main { 2 | v: int = call @getThree; 3 | v: int = id v; 4 | v1: int = id v; 5 | print v1; 6 | v2: int = const 0; 7 | } 8 | @getThree: int { 9 | v0: int = const 3; 10 | ret v0; 11 | } 12 | -------------------------------------------------------------------------------- /test/ts/main.ts: -------------------------------------------------------------------------------- 1 | function getThree(): bigint { 2 | return 3n; 3 | } 4 | 5 | var v = getThree(); 6 | console.log(v); 7 | -------------------------------------------------------------------------------- /test/ts/memory-call.ts: -------------------------------------------------------------------------------- 1 | import * as mem from "../../bril-ts/mem"; 2 | 3 | function update(p: mem.Pointer): mem.Pointer { 4 | mem.store(p, 42n); 5 | return p; 6 | } 7 | 8 | let p1 = mem.alloc(1n); 9 | let p2 = update(p1); 10 | console.log(mem.load(p2)); 11 | 12 | mem.free(p1); -------------------------------------------------------------------------------- /test/ts/memory-loop.ts: -------------------------------------------------------------------------------- 1 | import * as mem from "../../bril-ts/mem"; 2 | 3 | let size = 100n; 4 | let arr = mem.alloc(size); 5 | 6 | for (let i = 0n; i < size; i = i + 1n) { 7 | mem.store(mem.ptradd(arr, i), i); // arr[i] = i 8 | } 9 | 10 | let sum = 0n; 11 | for (let i = 0n; i < size; i = i + 1n) { 12 | sum = sum + mem.load(mem.ptradd(arr, i)); // sum += arr[i] 13 | } 14 | console.log(sum); 15 | 16 | mem.free(arr); -------------------------------------------------------------------------------- /test/ts/nested-call.out: -------------------------------------------------------------------------------- 1 | @main { 2 | v0: int = const 1; 3 | v1: int = call @getTwo; 4 | v2: int = add v0 v1; 5 | y: int = id v2; 6 | v3: int = id y; 7 | print v3; 8 | v4: int = const 0; 9 | } 10 | @getTwo: int { 11 | v0: int = const 2; 12 | ret v0; 13 | } 14 | -------------------------------------------------------------------------------- /test/ts/nested-call.ts: -------------------------------------------------------------------------------- 1 | var y = 1n + getTwo(); 2 | console.log(y); 3 | 4 | function getTwo(): bigint { 5 | return 2n; 6 | } 7 | -------------------------------------------------------------------------------- /test/ts/printvar.out: -------------------------------------------------------------------------------- 1 | @main { 2 | v0: int = const 5; 3 | x: int = id v0; 4 | v1: int = id x; 5 | print v1; 6 | v2: int = const 0; 7 | } 8 | -------------------------------------------------------------------------------- /test/ts/printvar.ts: -------------------------------------------------------------------------------- 1 | var x = 5n; 2 | console.log(x); 3 | -------------------------------------------------------------------------------- /test/ts/return.out: -------------------------------------------------------------------------------- 1 | @main { 2 | v0: int = const 1; 3 | x: int = id v0; 4 | v1: int = const 2; 5 | y: int = id v1; 6 | v2: int = id x; 7 | v3: int = id y; 8 | v: int = call @add2 v2 v3; 9 | v: int = id v; 10 | v4: int = id v; 11 | print v4; 12 | v5: int = const 0; 13 | } 14 | @add2(x: int, y: int): int { 15 | v0: int = id x; 16 | v1: int = id y; 17 | v2: int = add v0 v1; 18 | ret v2; 19 | } 20 | -------------------------------------------------------------------------------- /test/ts/return.ts: -------------------------------------------------------------------------------- 1 | var x = 1n; 2 | var y = 2n; 3 | var v = add2(x, y); 4 | console.log(v); 5 | 6 | function add2(x: bigint, y: bigint): bigint { 7 | return x + y; 8 | } 9 | -------------------------------------------------------------------------------- /test/ts/simplified.out: -------------------------------------------------------------------------------- 1 | @main { 2 | v0: int = const 1; 3 | call @erronious v0; 4 | v1: int = const 0; 5 | } 6 | @erronious(x: int): int { 7 | v1: bool = const true; 8 | br v1 .then.0 .else.0; 9 | .then.0: 10 | v2: int = id x; 11 | ret v2; 12 | .else.0: 13 | } 14 | -------------------------------------------------------------------------------- /test/ts/simplified.ts: -------------------------------------------------------------------------------- 1 | erronious(1n); 2 | 3 | // This snippet checks that the ts compiler doesn't try to create an unreachable else branch 4 | function erronious(x: bigint): bigint { 5 | if (true) { 6 | return x; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /test/ts/turnt.toml: -------------------------------------------------------------------------------- 1 | command = "ts2bril {filename} | bril2txt" 2 | -------------------------------------------------------------------------------- /type-infer/Makefile: -------------------------------------------------------------------------------- 1 | TESTS := tests/parse/*.bril \ 2 | tests/print/*.json \ 3 | tests/infer/*.bril \ 4 | tests/typecheck/*.bril 5 | 6 | .PHONY: test 7 | test: 8 | turnt $(TESTS) 9 | -------------------------------------------------------------------------------- /type-infer/tests/fail-infer/arith_ops.bril: -------------------------------------------------------------------------------- 1 | # RETURN: 1 2 | @main { 3 | a1 = const false; 4 | b1 = const 2; 5 | c1 = add a1 b1; 6 | d1 = mul c1 b1; 7 | e1 = sub d1 c1; 8 | f1 = div e1 d1; 9 | a2 = const 1; 10 | b2: int = const 2; 11 | c2 = add a2 b2; 12 | d2: int = mul c2 b2; 13 | e2: int = sub d2 c2; 14 | f2 = div e2 d2; 15 | } 16 | -------------------------------------------------------------------------------- /type-infer/tests/fail-infer/assign_label.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | .label: 3 | x: int = const 5; 4 | label = const 5; 5 | } 6 | -------------------------------------------------------------------------------- /type-infer/tests/fail-infer/br.bril: -------------------------------------------------------------------------------- 1 | # RETURN: 1 2 | @main { 3 | v: int = const 4; 4 | b: bool = const 1; 5 | br b .there .here; 6 | .here: 7 | v: int = const 2; 8 | .there: 9 | print v; 10 | } 11 | -------------------------------------------------------------------------------- /type-infer/tests/fail-infer/comp_ops.bril: -------------------------------------------------------------------------------- 1 | # RETURN: 1 2 | @main { 3 | a1 = const 1; 4 | b1 = const 2; 5 | c1 = eq a1 b1; 6 | d1 = lt a1 b1; 7 | e1 = gt a1 b1; 8 | f1 = le a1 b1; 9 | g1 = ge a1 b1; 10 | 11 | a2 = const 1; 12 | b2 = const 2; 13 | c2: bool = and a2 b2; 14 | d2 = lt a2 b2; 15 | e2: bool = gt a2 b2; 16 | f2: bool = le a2 b2; 17 | g2 = ge a2 b2; 18 | } 19 | -------------------------------------------------------------------------------- /type-infer/tests/fail-infer/control_ops.bril: -------------------------------------------------------------------------------- 1 | # RETURN: 1 2 | @main { 3 | one = const true; 4 | n = const 5; 5 | res = const 1; 6 | i = id n; 7 | .cond: 8 | b = gt i one; 9 | br b .body .end; 10 | .body: 11 | res = mul res i; 12 | i = sub i one; 13 | jmp .cond; 14 | .end: 15 | print res; 16 | ret; 17 | } 18 | -------------------------------------------------------------------------------- /type-infer/tests/fail-infer/div.bril: -------------------------------------------------------------------------------- 1 | # RETURN: 1 2 | @main { 3 | v0: int = const false; 4 | v1: int = const -20; 5 | res: int = div v0 v1; 6 | print res; 7 | } 8 | -------------------------------------------------------------------------------- /type-infer/tests/fail-infer/idchain.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | jmp .l1; 3 | .l5: 4 | d: bool = id c; 5 | ret; 6 | .l4: 7 | c = id b; 8 | jmp .l5; 9 | .l3: 10 | b = id a; 11 | jmp .l4; 12 | .l2: 13 | a = id z; 14 | jmp .l3; 15 | .l1: 16 | z = const 0; 17 | jmp .l2; 18 | } 19 | -------------------------------------------------------------------------------- /type-infer/tests/fail-infer/jmp.bril: -------------------------------------------------------------------------------- 1 | # RETURN: 1 2 | @main { 3 | v: int = const false; 4 | jmp .somewhere; 5 | v: int = const 2; 6 | .somewhere: 7 | print v; 8 | } 9 | -------------------------------------------------------------------------------- /type-infer/tests/fail-infer/logic_ops.bril: -------------------------------------------------------------------------------- 1 | # RETURN: 1 2 | @main { 3 | F1 = const false; 4 | T1 = const 1; 5 | a1 = not F1; 6 | b1 = and a1 T1; 7 | c1 = or a1 b1; 8 | F2: bool = const 999; 9 | T2 = const true; 10 | a2: bool = not F2; 11 | b2 = and a2 T2; 12 | c2: bool = or a2 b2; 13 | } 14 | -------------------------------------------------------------------------------- /type-infer/tests/fail-infer/many_functions.bril: -------------------------------------------------------------------------------- 1 | # RETURN: 1 2 | @foo { 3 | a = const 1; 4 | b = const false; 5 | c = add a b; 6 | } 7 | @main { 8 | f = const false; 9 | t = const true; 10 | b = or f t; 11 | print f t b; 12 | } 13 | -------------------------------------------------------------------------------- /type-infer/tests/fail-infer/tricky-jump.bril: -------------------------------------------------------------------------------- 1 | # RETURN: 0 2 | @main { 3 | jmp x; 4 | .earlier: 5 | x = id y; 6 | ret; 7 | .later: 8 | y = const 5; 9 | jmp .earlier; 10 | } 11 | -------------------------------------------------------------------------------- /type-infer/tests/fail-infer/turnt.toml: -------------------------------------------------------------------------------- 1 | command = "cat {filename} | bril2json | python ../../infer.py" 2 | -------------------------------------------------------------------------------- /type-infer/tests/fail-typecheck/add.bril: -------------------------------------------------------------------------------- 1 | # RETURN: 1 2 | # OUT: err 2 3 | @main { 4 | v0: bool = const 1; 5 | v1 = const 2; 6 | v2 = add v0 v1; 7 | print v2; 8 | } 9 | -------------------------------------------------------------------------------- /type-infer/tests/fail-typecheck/arith_ops.bril: -------------------------------------------------------------------------------- 1 | # RETURN: 1 2 | # 3 | @main { 4 | a1 = const 1; 5 | b1 = const 2; 6 | c1 = add a1 b1; 7 | d1 = mul c1 b1; 8 | e1 = sub d1 c1; 9 | f1 = div e1 d1; 10 | a2 = const 1; 11 | b2: int = const 2; 12 | c2 = add a2 b2; 13 | d2: bool = mul c2 b2; 14 | e2: int = sub d2 c2; 15 | f2 = div e2 d2; 16 | } 17 | -------------------------------------------------------------------------------- /type-infer/tests/fail-typecheck/br.bril: -------------------------------------------------------------------------------- 1 | # RETURN: 1 2 | # 3 | @main { 4 | v: int = const 4; 5 | b: int = const false; 6 | br b .there .here; 7 | .here: 8 | v: int = const 2; 9 | .there: 10 | print v; 11 | } 12 | -------------------------------------------------------------------------------- /type-infer/tests/fail-typecheck/comp_ops.bril: -------------------------------------------------------------------------------- 1 | # RETURN: 1 2 | # 3 | @main { 4 | a1 = const 1; 5 | b1 = const 2; 6 | c1 = eq a1 b1; 7 | d1 = lt a1 b1; 8 | e1 = gt a1 b1; 9 | f1 = le a1 b1; 10 | g1 = ge a1 b1; 11 | 12 | a2 = const 1; 13 | b2 = const 2; 14 | c2: int = eq a2 b2; 15 | d2 = lt a2 b2; 16 | e2: bool = gt a2 b2; 17 | f2: bool = le a2 b2; 18 | g2 = ge a2 b2; 19 | } 20 | -------------------------------------------------------------------------------- /type-infer/tests/fail-typecheck/control_ops.bril: -------------------------------------------------------------------------------- 1 | # RETURN: 1 2 | # 3 | @main { 4 | one = const 1; 5 | n = const 5; 6 | res = const 1; 7 | i = id n; 8 | .cond: 9 | b = gt i one; 10 | br b .body .end; 11 | .body: 12 | res: bool = mul res i; 13 | i = sub i one; 14 | jmp .cond; 15 | .end: 16 | print res; 17 | ret; 18 | } 19 | -------------------------------------------------------------------------------- /type-infer/tests/fail-typecheck/div.bril: -------------------------------------------------------------------------------- 1 | # RETURN: 1 2 | # 3 | @main { 4 | v0: int = const 9; 5 | v1: int = const -20; 6 | res: bool = div v0 v1; 7 | print res; 8 | } 9 | -------------------------------------------------------------------------------- /type-infer/tests/fail-typecheck/idchain.bril: -------------------------------------------------------------------------------- 1 | # RETURN: 1 2 | @main { 3 | jmp .l1; 4 | .l5: 5 | d: bool = id c; 6 | ret; 7 | .l4: 8 | c = id b; 9 | jmp .l5; 10 | .l3: 11 | b = id a; 12 | jmp .l4; 13 | .l2: 14 | a = id z; 15 | jmp .l3; 16 | .l1: 17 | z = const 0; 18 | jmp .l2; 19 | } 20 | -------------------------------------------------------------------------------- /type-infer/tests/fail-typecheck/jmp.bril: -------------------------------------------------------------------------------- 1 | # RETURN: 1 2 | # 3 | @main { 4 | v: int = const 4; 5 | jmp .somewhere; 6 | v: bool = const 2; 7 | .somewhere: 8 | print v; 9 | } 10 | -------------------------------------------------------------------------------- /type-infer/tests/fail-typecheck/logic_ops.bril: -------------------------------------------------------------------------------- 1 | # RETURN: 1 2 | # 3 | @main { 4 | F1 = const false; 5 | T1 = const true; 6 | a1 = not F1; 7 | b1 = and a1 T1; 8 | c1 = or a1 b1; 9 | F2: int = const false; 10 | T2 = const true; 11 | a2: int = not F2; 12 | b2 = and a2 T2; 13 | c2: bool = or a2 b2; 14 | } 15 | -------------------------------------------------------------------------------- /type-infer/tests/fail-typecheck/many_functions.bril: -------------------------------------------------------------------------------- 1 | # RETURN: 1 2 | # 3 | @foo { 4 | a: bool = const 1; 5 | b = const 2; 6 | c = add a b; 7 | } 8 | @main { 9 | f = const false; 10 | t = const true; 11 | b = or f t; 12 | print f t b; 13 | } 14 | -------------------------------------------------------------------------------- /type-infer/tests/fail-typecheck/nop.bril: -------------------------------------------------------------------------------- 1 | # RETURN: 1 2 | # 3 | @main { 4 | nop; 5 | v: bool = const 5; 6 | nop; 7 | print v; 8 | nop; 9 | } 10 | -------------------------------------------------------------------------------- /type-infer/tests/fail-typecheck/ret.bril: -------------------------------------------------------------------------------- 1 | # RETURN: 1 2 | # 3 | @main { 4 | v: bool = const 4; 5 | print v; 6 | ret; 7 | print v; 8 | } 9 | -------------------------------------------------------------------------------- /type-infer/tests/fail-typecheck/tiny.bril: -------------------------------------------------------------------------------- 1 | # RETURN: 1 2 | # 3 | @main { 4 | v: bool = const 5; 5 | print v; 6 | } 7 | -------------------------------------------------------------------------------- /type-infer/tests/fail-typecheck/tricky-jump.bril: -------------------------------------------------------------------------------- 1 | # RETURN: 1 2 | @main { 3 | jmp x; 4 | .earlier: 5 | x = id y; 6 | ret; 7 | .later: 8 | y = const 5; 9 | jmp .earlier; 10 | } 11 | -------------------------------------------------------------------------------- /type-infer/tests/fail-typecheck/turnt.toml: -------------------------------------------------------------------------------- 1 | command = "cat {filename} | bril2json | python ../../infer.py -t" 2 | -------------------------------------------------------------------------------- /type-infer/tests/infer/addarg.bril: -------------------------------------------------------------------------------- 1 | @main(arg: int) { 2 | five = const 5; 3 | ten = const 10; 4 | res = add arg five; 5 | cond = le res ten; 6 | br cond .then .else; 7 | .then: 8 | print res; 9 | .else: 10 | } 11 | -------------------------------------------------------------------------------- /type-infer/tests/infer/addarg.tbril: -------------------------------------------------------------------------------- 1 | @main(arg: int) { 2 | five: int = const 5; 3 | ten: int = const 10; 4 | res: int = add arg five; 5 | cond: bool = le res ten; 6 | br cond .then .else; 7 | .then: 8 | print res; 9 | .else: 10 | } 11 | -------------------------------------------------------------------------------- /type-infer/tests/infer/arith_ops.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | a1 = const 1; 3 | b1 = const 2; 4 | c1 = add a1 b1; 5 | d1 = mul c1 b1; 6 | e1 = sub d1 c1; 7 | f1 = div e1 d1; 8 | a2 = const 1; 9 | b2: int = const 2; 10 | c2 = add a2 b2; 11 | d2: int = mul c2 b2; 12 | e2: int = sub d2 c2; 13 | f2 = div e2 d2; 14 | } 15 | -------------------------------------------------------------------------------- /type-infer/tests/infer/arith_ops.tbril: -------------------------------------------------------------------------------- 1 | @main { 2 | a1: int = const 1; 3 | b1: int = const 2; 4 | c1: int = add a1 b1; 5 | d1: int = mul c1 b1; 6 | e1: int = sub d1 c1; 7 | f1: int = div e1 d1; 8 | a2: int = const 1; 9 | b2: int = const 2; 10 | c2: int = add a2 b2; 11 | d2: int = mul c2 b2; 12 | e2: int = sub d2 c2; 13 | f2: int = div e2 d2; 14 | } 15 | -------------------------------------------------------------------------------- /type-infer/tests/infer/br.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | v: int = const 4; 3 | b: bool = const false; 4 | br b .there .here; 5 | .here: 6 | v: int = const 2; 7 | .there: 8 | print v; 9 | } 10 | -------------------------------------------------------------------------------- /type-infer/tests/infer/br.tbril: -------------------------------------------------------------------------------- 1 | @main { 2 | v: int = const 4; 3 | b: bool = const false; 4 | br b .there .here; 5 | .here: 6 | v: int = const 2; 7 | .there: 8 | print v; 9 | } 10 | -------------------------------------------------------------------------------- /type-infer/tests/infer/comp_ops.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | a1 = const 1; 3 | b1 = const 2; 4 | c1 = eq a1 b1; 5 | d1 = lt a1 b1; 6 | e1 = gt a1 b1; 7 | f1 = le a1 b1; 8 | g1 = ge a1 b1; 9 | 10 | a2 = const 1; 11 | b2 = const 2; 12 | c2: bool = eq a2 b2; 13 | d2 = lt a2 b2; 14 | e2: bool = gt a2 b2; 15 | f2: bool = le a2 b2; 16 | g2 = ge a2 b2; 17 | } 18 | -------------------------------------------------------------------------------- /type-infer/tests/infer/comp_ops.tbril: -------------------------------------------------------------------------------- 1 | @main { 2 | a1: int = const 1; 3 | b1: int = const 2; 4 | c1: bool = eq a1 b1; 5 | d1: bool = lt a1 b1; 6 | e1: bool = gt a1 b1; 7 | f1: bool = le a1 b1; 8 | g1: bool = ge a1 b1; 9 | a2: int = const 1; 10 | b2: int = const 2; 11 | c2: bool = eq a2 b2; 12 | d2: bool = lt a2 b2; 13 | e2: bool = gt a2 b2; 14 | f2: bool = le a2 b2; 15 | g2: bool = ge a2 b2; 16 | } 17 | -------------------------------------------------------------------------------- /type-infer/tests/infer/control_ops.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | one = const 1; 3 | n = const 5; 4 | res = const 1; 5 | i = id n; 6 | .cond: 7 | b = gt i one; 8 | br b .body .end; 9 | .body: 10 | res = mul res i; 11 | i = sub i one; 12 | jmp .cond; 13 | .end: 14 | print res; 15 | ret; 16 | } 17 | -------------------------------------------------------------------------------- /type-infer/tests/infer/control_ops.tbril: -------------------------------------------------------------------------------- 1 | @main { 2 | one: int = const 1; 3 | n: int = const 5; 4 | res: int = const 1; 5 | i: int = id n; 6 | .cond: 7 | b: bool = gt i one; 8 | br b .body .end; 9 | .body: 10 | res: int = mul res i; 11 | i: int = sub i one; 12 | jmp .cond; 13 | .end: 14 | print res; 15 | ret; 16 | } 17 | -------------------------------------------------------------------------------- /type-infer/tests/infer/div.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | v0: int = const 9; 3 | v1: int = const -20; 4 | res: int = div v0 v1; 5 | print res; 6 | } 7 | -------------------------------------------------------------------------------- /type-infer/tests/infer/div.tbril: -------------------------------------------------------------------------------- 1 | @main { 2 | v0: int = const 9; 3 | v1: int = const -20; 4 | res: int = div v0 v1; 5 | print res; 6 | } 7 | -------------------------------------------------------------------------------- /type-infer/tests/infer/idchain.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | jmp .l1; 3 | .l5: 4 | d = id c; 5 | ret; 6 | .l4: 7 | c = id b; 8 | jmp .l5; 9 | .l3: 10 | b = id a; 11 | jmp .l4; 12 | .l2: 13 | a = id z; 14 | jmp .l3; 15 | .l1: 16 | z = const 0; 17 | jmp .l2; 18 | } 19 | -------------------------------------------------------------------------------- /type-infer/tests/infer/idchain.tbril: -------------------------------------------------------------------------------- 1 | @main { 2 | jmp .l1; 3 | .l5: 4 | d: int = id c; 5 | ret; 6 | .l4: 7 | c: int = id b; 8 | jmp .l5; 9 | .l3: 10 | b: int = id a; 11 | jmp .l4; 12 | .l2: 13 | a: int = id z; 14 | jmp .l3; 15 | .l1: 16 | z: int = const 0; 17 | jmp .l2; 18 | } 19 | -------------------------------------------------------------------------------- /type-infer/tests/infer/jmp.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | v: int = const 4; 3 | jmp .somewhere; 4 | v: int = const 2; 5 | .somewhere: 6 | print v; 7 | } 8 | -------------------------------------------------------------------------------- /type-infer/tests/infer/jmp.tbril: -------------------------------------------------------------------------------- 1 | @main { 2 | v: int = const 4; 3 | jmp .somewhere; 4 | v: int = const 2; 5 | .somewhere: 6 | print v; 7 | } 8 | -------------------------------------------------------------------------------- /type-infer/tests/infer/logic_ops.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | F1 = const false; 3 | T1 = const true; 4 | a1 = not F1; 5 | b1 = and a1 T1; 6 | c1 = or a1 b1; 7 | F2: bool = const false; 8 | T2 = const true; 9 | a2: bool = not F2; 10 | b2 = and a2 T2; 11 | c2: bool = or a2 b2; 12 | } 13 | -------------------------------------------------------------------------------- /type-infer/tests/infer/logic_ops.tbril: -------------------------------------------------------------------------------- 1 | @main { 2 | F1: bool = const false; 3 | T1: bool = const true; 4 | a1: bool = not F1; 5 | b1: bool = and a1 T1; 6 | c1: bool = or a1 b1; 7 | F2: bool = const false; 8 | T2: bool = const true; 9 | a2: bool = not F2; 10 | b2: bool = and a2 T2; 11 | c2: bool = or a2 b2; 12 | } 13 | -------------------------------------------------------------------------------- /type-infer/tests/infer/many_functions.bril: -------------------------------------------------------------------------------- 1 | @foo { 2 | a = const 1; 3 | b = const 2; 4 | c = add a b; 5 | } 6 | @main { 7 | f = const false; 8 | t = const true; 9 | b = or f t; 10 | print f t b; 11 | } 12 | -------------------------------------------------------------------------------- /type-infer/tests/infer/many_functions.tbril: -------------------------------------------------------------------------------- 1 | @foo { 2 | a: int = const 1; 3 | b: int = const 2; 4 | c: int = add a b; 5 | } 6 | @main { 7 | f: bool = const false; 8 | t: bool = const true; 9 | b: bool = or f t; 10 | print f t b; 11 | } 12 | -------------------------------------------------------------------------------- /type-infer/tests/infer/nop.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | nop; 3 | v: int = const 5; 4 | nop; 5 | print v; 6 | nop; 7 | } 8 | -------------------------------------------------------------------------------- /type-infer/tests/infer/nop.tbril: -------------------------------------------------------------------------------- 1 | @main { 2 | nop; 3 | v: int = const 5; 4 | nop; 5 | print v; 6 | nop; 7 | } 8 | -------------------------------------------------------------------------------- /type-infer/tests/infer/ret.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | v: int = const 4; 3 | print v; 4 | ret; 5 | print v; 6 | } 7 | -------------------------------------------------------------------------------- /type-infer/tests/infer/ret.tbril: -------------------------------------------------------------------------------- 1 | @main { 2 | v: int = const 4; 3 | print v; 4 | ret; 5 | print v; 6 | } 7 | -------------------------------------------------------------------------------- /type-infer/tests/infer/tiny.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | v: int = const 5; 3 | print v; 4 | } 5 | -------------------------------------------------------------------------------- /type-infer/tests/infer/tiny.tbril: -------------------------------------------------------------------------------- 1 | @main { 2 | v: int = const 5; 3 | print v; 4 | } 5 | -------------------------------------------------------------------------------- /type-infer/tests/infer/tricky-jump.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | jmp .later; 3 | .earlier: 4 | x = id y; 5 | ret; 6 | .later: 7 | y = const 5; 8 | jmp .earlier; 9 | } 10 | -------------------------------------------------------------------------------- /type-infer/tests/infer/tricky-jump.tbril: -------------------------------------------------------------------------------- 1 | @main { 2 | jmp .later; 3 | .earlier: 4 | x: int = id y; 5 | ret; 6 | .later: 7 | y: int = const 5; 8 | jmp .earlier; 9 | } 10 | -------------------------------------------------------------------------------- /type-infer/tests/infer/turnt.toml: -------------------------------------------------------------------------------- 1 | command = "cat {filename} | bril2json | python ../../infer.py | bril2txt" 2 | output.tbril = "-" 3 | -------------------------------------------------------------------------------- /type-infer/tests/parse/add.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | v0 = const 1; 3 | v1 = const 2; 4 | v2 = add v0 v1; 5 | print v2; 6 | } 7 | -------------------------------------------------------------------------------- /type-infer/tests/parse/div.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | v0: int = const 9; 3 | v1: int = const -20; 4 | res: int = div v0 v1; 5 | print res; 6 | } 7 | -------------------------------------------------------------------------------- /type-infer/tests/parse/partial.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | v0 = const 1; 3 | v1: int = const 2; 4 | v2 = add v0 v1; 5 | print v2; 6 | } 7 | -------------------------------------------------------------------------------- /type-infer/tests/parse/turnt.toml: -------------------------------------------------------------------------------- 1 | command = "bril2json < {filename}" 2 | output.json = "-" 3 | -------------------------------------------------------------------------------- /type-infer/tests/print/add.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | v0 = const 1; 3 | v1 = const 2; 4 | v2 = add v0 v1; 5 | print v2; 6 | } 7 | -------------------------------------------------------------------------------- /type-infer/tests/print/div.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | v0: int = const 9; 3 | v1: int = const -20; 4 | res: int = div v0 v1; 5 | print res; 6 | } 7 | -------------------------------------------------------------------------------- /type-infer/tests/print/partial.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | v0 = const 1; 3 | v1: int = const 2; 4 | v2 = add v0 v1; 5 | print v2; 6 | } 7 | -------------------------------------------------------------------------------- /type-infer/tests/print/turnt.toml: -------------------------------------------------------------------------------- 1 | command = "bril2txt < {filename}" 2 | output.bril = "-" 3 | -------------------------------------------------------------------------------- /type-infer/tests/typecheck/arith_ops.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | a1 = const 1; 3 | b1 = const 2; 4 | c1 = add a1 b1; 5 | d1 = mul c1 b1; 6 | e1 = sub d1 c1; 7 | f1 = div e1 d1; 8 | a2 = const 1; 9 | b2: int = const 2; 10 | c2 = add a2 b2; 11 | d2: int = mul c2 b2; 12 | e2: int = sub d2 c2; 13 | f2 = div e2 d2; 14 | } 15 | -------------------------------------------------------------------------------- /type-infer/tests/typecheck/arith_ops.tbril: -------------------------------------------------------------------------------- 1 | @main { 2 | a1: int = const 1; 3 | b1: int = const 2; 4 | c1: int = add a1 b1; 5 | d1: int = mul c1 b1; 6 | e1: int = sub d1 c1; 7 | f1: int = div e1 d1; 8 | a2: int = const 1; 9 | b2: int = const 2; 10 | c2: int = add a2 b2; 11 | d2: int = mul c2 b2; 12 | e2: int = sub d2 c2; 13 | f2: int = div e2 d2; 14 | } 15 | -------------------------------------------------------------------------------- /type-infer/tests/typecheck/br.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | v: int = const 4; 3 | b: bool = const false; 4 | br b .there .here; 5 | .here: 6 | v: int = const 2; 7 | .there: 8 | print v; 9 | } 10 | -------------------------------------------------------------------------------- /type-infer/tests/typecheck/br.tbril: -------------------------------------------------------------------------------- 1 | @main { 2 | v: int = const 4; 3 | b: bool = const false; 4 | br b .there .here; 5 | .here: 6 | v: int = const 2; 7 | .there: 8 | print v; 9 | } 10 | -------------------------------------------------------------------------------- /type-infer/tests/typecheck/comp_ops.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | a1 = const 1; 3 | b1 = const 2; 4 | c1 = eq a1 b1; 5 | d1 = lt a1 b1; 6 | e1 = gt a1 b1; 7 | f1 = le a1 b1; 8 | g1 = ge a1 b1; 9 | 10 | a2 = const 1; 11 | b2 = const 2; 12 | c2: bool = eq a2 b2; 13 | d2 = lt a2 b2; 14 | e2: bool = gt a2 b2; 15 | f2: bool = le a2 b2; 16 | g2 = ge a2 b2; 17 | } 18 | -------------------------------------------------------------------------------- /type-infer/tests/typecheck/comp_ops.tbril: -------------------------------------------------------------------------------- 1 | @main { 2 | a1: int = const 1; 3 | b1: int = const 2; 4 | c1: bool = eq a1 b1; 5 | d1: bool = lt a1 b1; 6 | e1: bool = gt a1 b1; 7 | f1: bool = le a1 b1; 8 | g1: bool = ge a1 b1; 9 | a2: int = const 1; 10 | b2: int = const 2; 11 | c2: bool = eq a2 b2; 12 | d2: bool = lt a2 b2; 13 | e2: bool = gt a2 b2; 14 | f2: bool = le a2 b2; 15 | g2: bool = ge a2 b2; 16 | } 17 | -------------------------------------------------------------------------------- /type-infer/tests/typecheck/control_ops.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | one = const 1; 3 | n = const 5; 4 | res = const 1; 5 | i = id n; 6 | .cond: 7 | b = gt i one; 8 | br b .body .end; 9 | .body: 10 | res = mul res i; 11 | i = sub i one; 12 | jmp .cond; 13 | .end: 14 | print res; 15 | ret; 16 | } 17 | -------------------------------------------------------------------------------- /type-infer/tests/typecheck/control_ops.tbril: -------------------------------------------------------------------------------- 1 | @main { 2 | one: int = const 1; 3 | n: int = const 5; 4 | res: int = const 1; 5 | i: int = id n; 6 | .cond: 7 | b: bool = gt i one; 8 | br b .body .end; 9 | .body: 10 | res: int = mul res i; 11 | i: int = sub i one; 12 | jmp .cond; 13 | .end: 14 | print res; 15 | ret; 16 | } 17 | -------------------------------------------------------------------------------- /type-infer/tests/typecheck/div.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | v0: int = const 9; 3 | v1: int = const -20; 4 | res: int = div v0 v1; 5 | print res; 6 | } 7 | -------------------------------------------------------------------------------- /type-infer/tests/typecheck/div.tbril: -------------------------------------------------------------------------------- 1 | @main { 2 | v0: int = const 9; 3 | v1: int = const -20; 4 | res: int = div v0 v1; 5 | print res; 6 | } 7 | -------------------------------------------------------------------------------- /type-infer/tests/typecheck/idchain.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | jmp .l1; 3 | .l5: 4 | d = id c; 5 | ret; 6 | .l4: 7 | c = id b; 8 | jmp .l5; 9 | .l3: 10 | b = id a; 11 | jmp .l4; 12 | .l2: 13 | a = id z; 14 | jmp .l3; 15 | .l1: 16 | z = const 0; 17 | jmp .l2; 18 | } 19 | -------------------------------------------------------------------------------- /type-infer/tests/typecheck/idchain.tbril: -------------------------------------------------------------------------------- 1 | @main { 2 | jmp .l1; 3 | .l5: 4 | d: int = id c; 5 | ret; 6 | .l4: 7 | c: int = id b; 8 | jmp .l5; 9 | .l3: 10 | b: int = id a; 11 | jmp .l4; 12 | .l2: 13 | a: int = id z; 14 | jmp .l3; 15 | .l1: 16 | z: int = const 0; 17 | jmp .l2; 18 | } 19 | -------------------------------------------------------------------------------- /type-infer/tests/typecheck/jmp.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | v: int = const 4; 3 | jmp .somewhere; 4 | v: int = const 2; 5 | .somewhere: 6 | print v; 7 | } 8 | -------------------------------------------------------------------------------- /type-infer/tests/typecheck/jmp.tbril: -------------------------------------------------------------------------------- 1 | @main { 2 | v: int = const 4; 3 | jmp .somewhere; 4 | v: int = const 2; 5 | .somewhere: 6 | print v; 7 | } 8 | -------------------------------------------------------------------------------- /type-infer/tests/typecheck/logic_ops.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | F1 = const false; 3 | T1 = const true; 4 | a1 = not F1; 5 | b1 = and a1 T1; 6 | c1 = or a1 b1; 7 | F2: bool = const false; 8 | T2 = const true; 9 | a2: bool = not F2; 10 | b2 = and a2 T2; 11 | c2: bool = or a2 b2; 12 | } 13 | -------------------------------------------------------------------------------- /type-infer/tests/typecheck/logic_ops.tbril: -------------------------------------------------------------------------------- 1 | @main { 2 | F1: bool = const false; 3 | T1: bool = const true; 4 | a1: bool = not F1; 5 | b1: bool = and a1 T1; 6 | c1: bool = or a1 b1; 7 | F2: bool = const false; 8 | T2: bool = const true; 9 | a2: bool = not F2; 10 | b2: bool = and a2 T2; 11 | c2: bool = or a2 b2; 12 | } 13 | -------------------------------------------------------------------------------- /type-infer/tests/typecheck/many_functions.bril: -------------------------------------------------------------------------------- 1 | @foo { 2 | a = const 1; 3 | b = const 2; 4 | c = add a b; 5 | } 6 | @main { 7 | f = const false; 8 | t = const true; 9 | b = or f t; 10 | print f t b; 11 | } 12 | -------------------------------------------------------------------------------- /type-infer/tests/typecheck/many_functions.tbril: -------------------------------------------------------------------------------- 1 | @foo { 2 | a: int = const 1; 3 | b: int = const 2; 4 | c: int = add a b; 5 | } 6 | @main { 7 | f: bool = const false; 8 | t: bool = const true; 9 | b: bool = or f t; 10 | print f t b; 11 | } 12 | -------------------------------------------------------------------------------- /type-infer/tests/typecheck/nop.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | nop; 3 | v: int = const 5; 4 | nop; 5 | print v; 6 | nop; 7 | } 8 | -------------------------------------------------------------------------------- /type-infer/tests/typecheck/nop.tbril: -------------------------------------------------------------------------------- 1 | @main { 2 | nop; 3 | v: int = const 5; 4 | nop; 5 | print v; 6 | nop; 7 | } 8 | -------------------------------------------------------------------------------- /type-infer/tests/typecheck/ret.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | v: int = const 4; 3 | print v; 4 | ret; 5 | print v; 6 | } 7 | -------------------------------------------------------------------------------- /type-infer/tests/typecheck/ret.tbril: -------------------------------------------------------------------------------- 1 | @main { 2 | v: int = const 4; 3 | print v; 4 | ret; 5 | print v; 6 | } 7 | -------------------------------------------------------------------------------- /type-infer/tests/typecheck/tiny.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | v: int = const 5; 3 | print v; 4 | } 5 | -------------------------------------------------------------------------------- /type-infer/tests/typecheck/tiny.tbril: -------------------------------------------------------------------------------- 1 | @main { 2 | v: int = const 5; 3 | print v; 4 | } 5 | -------------------------------------------------------------------------------- /type-infer/tests/typecheck/tricky-jump.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | jmp .later; 3 | .earlier: 4 | x = id y; 5 | ret; 6 | .later: 7 | y = const 5; 8 | jmp .earlier; 9 | } 10 | -------------------------------------------------------------------------------- /type-infer/tests/typecheck/tricky-jump.tbril: -------------------------------------------------------------------------------- 1 | @main { 2 | jmp .later; 3 | .earlier: 4 | x: int = id y; 5 | ret; 6 | .later: 7 | y: int = const 5; 8 | jmp .earlier; 9 | } 10 | -------------------------------------------------------------------------------- /type-infer/tests/typecheck/turnt.toml: -------------------------------------------------------------------------------- 1 | command = "cat {filename} | bril2json | python ../../infer.py -t | bril2txt" 2 | output.tbril = "-" 3 | --------------------------------------------------------------------------------