diff --git a/cranelift/src/libcretonne/ir/function.rs b/cranelift/src/libcretonne/ir/function.rs new file mode 100644 index 0000000000..2f8344d801 --- /dev/null +++ b/cranelift/src/libcretonne/ir/function.rs @@ -0,0 +1,64 @@ +//! Intermediate representation of a function. +//! +//! The `Function` struct defined in this module owns all of its extended basic blocks and +//! instructions. + +use ir::{FunctionName, Signature, StackSlot, StackSlotData, JumpTable, JumpTableData, + DataFlowGraph, Layout}; +use entity_map::{EntityMap, PrimaryEntityData}; +use std::fmt::{self, Debug, Formatter}; + +/// A function. +pub struct Function { + /// Name of this function. Mostly used by `.cton` files. + pub name: FunctionName, + + /// Signature of this function. + signature: Signature, + + /// Stack slots allocated in this function. + pub stack_slots: EntityMap, + + /// Jump tables used in this function. + pub jump_tables: EntityMap, + + /// Data flow graph containing the primary definition of all instructions, EBBs and values. + pub dfg: DataFlowGraph, + + /// Layout of EBBs and instructions in the function body. + pub layout: Layout, +} + +impl PrimaryEntityData for StackSlotData {} +impl PrimaryEntityData for JumpTableData {} + +impl Function { + /// Create a function with the given name and signature. + pub fn with_name_signature(name: FunctionName, sig: Signature) -> Function { + Function { + name: name, + signature: sig, + stack_slots: EntityMap::new(), + jump_tables: EntityMap::new(), + dfg: DataFlowGraph::new(), + layout: Layout::new(), + } + } + + /// Create a new empty, anomymous function. + pub fn new() -> Function { + Self::with_name_signature(FunctionName::new(), Signature::new()) + } + + /// Get the signature of this function. + pub fn own_signature(&self) -> &Signature { + &self.signature + } +} + +impl Debug for Function { + fn fmt(&self, fmt: &mut Formatter) -> fmt::Result { + use write::function_to_string; + fmt.write_str(&function_to_string(self)) + } +} diff --git a/cranelift/src/libcretonne/ir/mod.rs b/cranelift/src/libcretonne/ir/mod.rs index 806466a90b..91f8b2516c 100644 --- a/cranelift/src/libcretonne/ir/mod.rs +++ b/cranelift/src/libcretonne/ir/mod.rs @@ -9,6 +9,7 @@ pub mod stackslot; pub mod jumptable; pub mod dfg; pub mod layout; +pub mod function; pub use ir::types::{Type, FunctionName, Signature}; pub use ir::entities::{Ebb, Inst, Value, StackSlot, JumpTable}; @@ -17,61 +18,4 @@ pub use ir::stackslot::StackSlotData; pub use ir::jumptable::JumpTableData; pub use ir::dfg::DataFlowGraph; pub use ir::layout::Layout; - -use std::fmt::{self, Debug, Formatter}; -use entity_map::{EntityMap, PrimaryEntityData}; - -/// A function. -pub struct Function { - /// Name of this function. Mostly used by `.cton` files. - pub name: FunctionName, - - /// Signature of this function. - signature: Signature, - - /// Stack slots allocated in this function. - pub stack_slots: EntityMap, - - /// Jump tables used in this function. - pub jump_tables: EntityMap, - - /// Data flow graph containing the primary definition of all instructions, EBBs and values. - pub dfg: DataFlowGraph, - - /// Layout of EBBs and instructions in the function body. - pub layout: Layout, -} - -impl PrimaryEntityData for StackSlotData {} -impl PrimaryEntityData for JumpTableData {} - -impl Function { - /// Create a function with the given name and signature. - pub fn with_name_signature(name: FunctionName, sig: Signature) -> Function { - Function { - name: name, - signature: sig, - stack_slots: EntityMap::new(), - jump_tables: EntityMap::new(), - dfg: DataFlowGraph::new(), - layout: Layout::new(), - } - } - - /// Create a new empty, anomymous function. - pub fn new() -> Function { - Self::with_name_signature(FunctionName::new(), Signature::new()) - } - - /// Get the signature of this function. - pub fn own_signature(&self) -> &Signature { - &self.signature - } -} - -impl Debug for Function { - fn fmt(&self, fmt: &mut Formatter) -> fmt::Result { - use write::function_to_string; - fmt.write_str(&function_to_string(self)) - } -} +pub use ir::function::Function;