Skip to main content

Crate wazabin_qcode_macro

Crate wazabin_qcode_macro 

Source
Expand description

The qcode! macro.

At compile time, this crate parses QCode source with wazabin_qcode_parser and validates its syntax. At run time, the emitted code lowers that source into the caller’s qcode::Context through qcode::lower::lower_str_with_externals. It also binds each declared name (functions, blocks, SSA values, varnodes, and block parameters) to a Rust let, so callers can reference it after the invocation. {capture} atoms are resolved from the surrounding Rust scope.

§Usage

Depend on qcode, which re-exports this macro; there is no reason to depend on this crate directly.

use qcode::{context::Context, qcode};

let mut ctx = Context::new();
let addend: u64 = 3;

qcode!(
    ctx,
    "
    fn f:
    <entry>
        %sum = i64 0x2 + {addend};
        goto <exit @r=%sum>;
    <exit @r:i64>
        goto <0x1001>;
    "
);

// `f`, `entry`, `exit`, `sum` and `r` are now Rust bindings.
assert_eq!(ctx.get_value(sum.into()).is_some(), true);

The example is not compiled here: qcode depends on this crate, so this crate cannot depend back on it even for a test. The macro’s behaviour is covered by qcode’s own test suite.

Macros§

qcode