Generate a Builder data type. WIP.
The Builder provides a convenient interface for inserting instructions into an extended basic block. The bulk of the builder methods are generated automatically from the meta language instruction descriptions. Still TODO: Keep track of an insertion position.
This commit is contained in:
27
src/libcretonne/ir/builder.rs
Normal file
27
src/libcretonne/ir/builder.rs
Normal file
@@ -0,0 +1,27 @@
|
||||
//! Cretonne instruction builder.
|
||||
//!
|
||||
//! A `Builder` provides a convenient interface for inserting instructions into a Cretonne
|
||||
//! function. Many of its methods are generated from the meta language instruction definitions.
|
||||
|
||||
use ir::{types, instructions};
|
||||
use ir::{InstructionData, DataFlowGraph};
|
||||
use ir::{Opcode, Type, Inst, Value, Ebb, JumpTable, VariableArgs, FuncRef};
|
||||
use ir::immediates::{Imm64, Uimm8, Ieee32, Ieee64, ImmVector};
|
||||
use ir::condcodes::{IntCC, FloatCC};
|
||||
|
||||
pub struct Builder<'a> {
|
||||
dfg: &'a mut DataFlowGraph,
|
||||
}
|
||||
|
||||
impl<'a> Builder<'a> {
|
||||
// Create and insert an instruction.
|
||||
// This method is used by the generated format-specific methods.
|
||||
fn insert_inst(&mut self, data: InstructionData) -> Inst {
|
||||
let inst = self.dfg.make_inst(data);
|
||||
inst
|
||||
}
|
||||
}
|
||||
|
||||
// Include code generated by `meta/gen_instr.py`. This file includes `Builder` methods per
|
||||
// instruction format and per opcode for inserting instructions.
|
||||
include!(concat!(env!("OUT_DIR"), "/builder.rs"));
|
||||
@@ -12,14 +12,16 @@ pub mod layout;
|
||||
pub mod function;
|
||||
mod funcname;
|
||||
mod extfunc;
|
||||
mod builder;
|
||||
|
||||
pub use ir::funcname::FunctionName;
|
||||
pub use ir::extfunc::{Signature, ArgumentType, ArgumentExtension};
|
||||
pub use ir::types::Type;
|
||||
pub use ir::entities::{Ebb, Inst, Value, StackSlot, JumpTable, FuncRef, SigRef};
|
||||
pub use ir::instructions::{Opcode, InstructionData};
|
||||
pub use ir::instructions::{Opcode, InstructionData, VariableArgs};
|
||||
pub use ir::stackslot::StackSlotData;
|
||||
pub use ir::jumptable::JumpTableData;
|
||||
pub use ir::dfg::{DataFlowGraph, ValueDef};
|
||||
pub use ir::layout::Layout;
|
||||
pub use ir::function::Function;
|
||||
pub use ir::builder::Builder;
|
||||
|
||||
Reference in New Issue
Block a user