Skip to content
/ opto Public

An optimizer and compiler generator for SSA WebAssembly

Notifications You must be signed in to change notification settings

appcypher/opto

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 

Repository files navigation

OPTO


DESCRIPTION

Opto is an optimizer and compiler generator for transforming SSA WebAssembly and compiling it to machine code. Opto comes with a term rewriting language.

For now the focus will be on interpreting the term rewriting language.


PROJECT STRUCTURE

- interpreter
- terms
    - wat_to_wat
    - wat_to_x86

A SINGLE TERM REWRITING LANGUAGE

The goal is to be less academic and more high-level. Term rewriting is all about pattern matching.

Constant Propagation Example
// wat -> wat

@ignore_spaces() // Special pattern directive.
val := \d+ // Pattern.

allow_constants = 1 // Double. The only supported primitive type.
constants = {} // Hashmap. The only supported DS.

constant_fold := // Mapping Pattern.
    "(#ty.const :val) (local.set #name)" => {
        constants[#name] = (:val, #ty)
    }

constant_propagation :=
    "(local.get #name)" => {
        (#val, #ty) = constants[#name]
        "(#ty.const #val)"
    }

apply_constants (:expr) { // Functions. They take patterns as arguments.
    proof (allow_constants = 0) { // A proof statement.
        constant_fold()
        constant_propagation()
    }
}

apply_constants()

// Checking if a rewrite is a result of constant_propagation
proof (:constant_propagation) {
    @print("There is a constant here", :constant_propagation)
}

FUTURE CLI

  • Generate an x86 optimizer and compiler
./optogen --target-triple=x86-none-darwin --optfile=rules.opto -o compiler
  • Optimize wasm file and generate x86 executable code
./compiler add.wasm
./add

DESIGN REFERENCES

  • Binaryen
  • Cranelift
  • LLVM

LINKS

About

An optimizer and compiler generator for SSA WebAssembly

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published