qbe

    Download zip
    Author
    Version
    0.13.0
    License
    Apache-2.0
    Last updated
    6 hours ago
    Downloads
    32

    Dependencies

    #Qbe.mbt

    Rewrite Qbe in MoonBit with additional features

    #What we implement (same as upstream Qbe)

    • IR optimizer
    • RISC-V 64 backend
    • amd64 (x86-64) backend
    • arm64 (AArch64) backend — byte-exact output compared against vendor/qbe/qbe -t arm64 (IR: 5684/5684, assembly: 406/406)

    #Extended features

    • LoongArch64 backend
    • WASM backend
    • IR Interpreter

    #Plan

    • Self-contained JIT / object emission for macOS-aarch64 (object/, target_arm64/emit/): --emit obj writes a Mach-O arm64 .o and --run-asm FUNC[,ARG] maps and calls the code in-process, both with no clang in the path (self-contained by default; --clang keeps the clang fallback). python tools/check_route_b.py shows byte-identical output to clang on all 336 compilable arm64 tests
    • --run-wasm FUNC[,ARG] runs the WASM backend end-to-end (node + moon-wasm-opt): loops/phi via a br_table dispatch loop, internal calls and recursion, floating-point comparisons, and data segments
    • (TODO) Add IR Debugger
    • (WIP) align with the frozen vendor/qbe reference (661ceb2): data segment and floating-point constant rodata output are byte-identical to vendor/qbe on amd64/arm64/rv64; the debug-dump differential suite (python compare.py) passes 12096/12096 cases (12 debug flags x 3 targets) and the emitted assembly is byte-identical on every compilable test (336/336 per target, 1008/1008 total)

    #Contributors

    #Quick start

    Clone and bootstrap on macOS or Linux:

    git clone https://github.com/azhzx/qbe.mbt.git cd qbe.mbt ./scripts/bootstrap.sh

    If MoonBit is already installed, use --skip-install to avoid installation attempts while still running smoke checks:

    ./scripts/bootstrap.sh --skip-install

    To allow automatic MoonBit installation when moon is missing:

    ./scripts/bootstrap.sh --install-moon

    Documentation:

    BSet

    using @azhzx/qbe/types { type BSet }

    Blk

    using @azhzx/qbe/types { type Blk }

    Class

    using @azhzx/qbe/types { type Class }

    Class - corresponds to enum Class in all.h

    Con

    using @azhzx/qbe/types { type Con }

    Dat

    using @azhzx/qbe/types { type Dat }

    using @azhzx/qbe/types { type Fn }

    Ins

    using @azhzx/qbe/types { type Ins }

    InterpValue

    Jump

    using @azhzx/qbe/types { type Jump }

    using @azhzx/qbe/types { type Op }

    Ref

    using @azhzx/qbe/types { type Ref }

    ADT replacing C bit-field (uint type:3; uint val:29)

    Tmp

    using @azhzx/qbe/types { type Tmp }

    Typ

    using @azhzx/qbe/types { type Typ }

    Target

    pub(all) enum Target {
    Amd64Sysv
    Wasm32
    Rv64
    La64
    Arm64
    }

    compile

    fn compile(text : String, gas? : String) -> Result[String,
    QbeError
    ]

    compile_arm64

    fn compile_arm64(text : String, gas? : String) -> Result[String,
    QbeError
    ]

    compile_arm64_bin

    fn compile_arm64_bin(text : String) -> Array[Array[Int]] raise

    compile_arm64_bin_module

    fn compile_arm64_bin_module(text : String) ->
    Arm64BinModule
    raise

    compile_arm64_debug

    fn compile_arm64_debug(text : String, flags : String) -> Result[String,
    QbeError
    ]

    compile_arm64_object

    fn compile_arm64_object(text : String) -> Bytes raise

    compile_debug

    fn compile_debug(text : String, flags : String) -> Result[String,
    QbeError
    ]

    compile_la64

    fn compile_la64(text : String, gas? : String) -> Result[String,
    QbeError
    ]

    compile_la64_debug

    fn compile_la64_debug(text : String, flags : String) -> Result[String,
    QbeError
    ]

    compile_rv64

    fn compile_rv64(text : String, gas? : String) -> Result[String,
    QbeError
    ]

    compile_rv64_debug

    fn compile_rv64_debug(text : String, flags : String) -> Result[String,
    QbeError
    ]

    compile_target

    fn compile_target(text : String, target : Target, gas? : String) -> Result[String,
    QbeError
    ]

    compile_target_debug

    fn compile_target_debug(text : String, target : Target, flags : String) -> Result[String,
    QbeError
    ]

    compile_wasm

    fn compile_wasm(text : String) -> Result[String,
    QbeError
    ]

    compile_wasm_debug

    fn compile_wasm_debug(text : String, flags : String) -> Result[String,
    QbeError
    ]

    interpret

    fn interpret(src : String, entry? : String, args? : Array[
    InterpValue
    ], max_steps? : Int, max_depth? : Int, hook? : (String, Array[
    InterpValue
    ]) ->
    InterpValue
    ??) -> Result[(
    InterpValue
    , String),
    QbeError
    ]