Convertor from LLVM to Yul
If you want to build using LLVM frontend, please use corresponding language standard library.
- Rust: patine
Many platfrom can't get prebuilt binary library for LLVM. So we suggested compile LLVM manually. Please refer llvm-sys documentation to build it.
export LLVM_SYS_170_PREFIX=<path-to-llvm-directory>
cargo build
Use rust example. Follow these instructions to build testable LLVM IR file.
- Clone patine repo
git clone https://github.com/tiannian/patine
- Build store example
RUSTFLAGS="--emit=llvm-ir" cargo build --release --example=store
- Link llvm
llvm-link target/release/deps/patine_core-*.ll \
target/release/deps/patine_std-*.ll \
target/release/examples/store-*.ll \
-o store.dc
llvm-dis store.dc
-
Copy
store.dc.ll
tollvm2yul
directory. -
Compile this repo.
export LLVM_SYS_170_PREFIX=<path-to-llvm-directory>
RUST_LOG=llvm2yul=debug cargo r --example=compiler
- Iterate object's all function.
- Compile function
- Compile Header
- Compile Block.
- Compile Termiantor
- Compile Body
In this step, llvm2yul will flat struct.
- Compile phi instruction
- Compile call instruction. struct will be flatten
- Compile load
- Compile store
- Compile select
- Compile Ret
- Compile Br
- Compile CondBr
- Compile Switch
- Compile Unreachable
Replace function call into builtin
- 64 / 32 bit with 256 align as primitive type. Primitive type use parameter and return value directly.
- Map LLVM IR instruction to yul
- ExtractValue
- InsertValue
- Alloca
- Load
- Store
- GetElementPtr
- PtrToInt
- IntToPtr
- Phi
- Select
- Call
- Map LLVM IR Type to yul
- Void
- Integer
- Pointer
- Array
- Struct
- NamedStruct
- Map LLVM IR Constant to yul
- Int
- Null
- AggregateZero
- Struct
- Array
- GlobalReference
- Poison
- Ptr2Int
- Int2Ptr
- Flatten LLVM IR Struct or Array
- Map LLVM IR function call to yul.
- Use FFI function to map yul builtin function.
- allocate function as builtin function
- Map block termiantor to control flow.
- Ret (leave)
- Br
- CondBr
- Switch (switch)
- Unreachable (invaild)
- Map LLVM IR funtion to yul
- Primitive parameter type
- Primitive return type
- Nested struct parameter and return support.
- Make unsupported display clearily