Sign in

    qbe

    Download zip
    Author
    Version
    0.8.0
    License
    Apache-2.0
    Last updated
    last month
    Downloads
    61

    #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

    • (TODO) Add JIT interface (copy-and-patch approach)
    • (TODO) Add IR Debugger
    • (FIX) rv64 backend: data segment and floating-point constant rodata output, reference differential verification

    #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_debug

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

    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) -> 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
    ]