https://github.com/appcypher/opto
An optimizer and compiler generator for SSA WebAssembly
https://github.com/appcypher/opto
Last synced: 5 months ago
JSON representation
An optimizer and compiler generator for SSA WebAssembly
- Host: GitHub
- URL: https://github.com/appcypher/opto
- Owner: appcypher
- Created: 2019-10-26T21:52:08.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-04-22T02:05:39.000Z (about 6 years ago)
- Last Synced: 2025-04-04T18:16:40.659Z (about 1 year ago)
- Homepage:
- Size: 2.93 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
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
```bash
./optogen --target-triple=x86-none-darwin --optfile=rules.opto -o compiler
```
- Optimize wasm file and generate x86 executable code
```bash
./compiler add.wasm
./add
```
### DESIGN REFERENCES
- Binaryen
- Cranelift
- LLVM
--------------
### LINKS
- https://www.sciencedirect.com/science/article/pii/S1571066108001473