cordillera 0.1.2

IR generation library for Sierra
Documentation
pub mod context;
pub mod builder;
pub mod entities;
pub mod inst;
pub mod ir;

#[cfg(test)]
#[allow(dead_code)]
mod tests {
    use super::{
        context::Context, 
        inst, 
        builder::Builder, 
        entities::Type
    };

    /// Test 1 - Generating `(5 + 6) * 2` IR
    pub fn test1() {
        let mut context = Context::create();
        let mut builder = Builder::new(&mut context);
        
        builder
            .create_function("main", 0, Type::Int)
            .assign("v0", inst::iconst(5), Type::Int)
            .assign("v1", inst::iconst(6), Type::Int
            )
            .assign("v2", inst::iadd(
                inst::v("v0"), 
                inst::v("v1")
            ), Type::Int)
            .assign("v2", inst::iadd(
                inst::v("v0"), 
                inst::v("v1")
                ), Type::Int
            )
            .assign("v3", inst::iconst(2), Type::Int)
            .assign(
                "v4", 
                inst::imul(
                    inst::v("v2"), 
                    inst::v("v3")
                ), 
                Type::Int
            )
            .ret(inst::v("v4"))
            .close_function("main");

        let result = builder.finalize_program();
        println!("{}", result);
    }
}