Add FunctionName, Signature to repr::Function.

Simplify the uses in parser.rs to avoid too many module qualifiers.
This commit is contained in:
Jakob Stoklund Olesen
2016-04-28 14:02:16 -07:00
parent 41d95c0342
commit 021bde1191
3 changed files with 55 additions and 24 deletions

View File

@@ -1,7 +1,7 @@
//! Representation of Cretonne IL functions.
use types::Type;
use types::{Type, FunctionName, Signature};
use immediates::*;
use std::fmt::{self, Display, Formatter, Write};
use std::u32;
@@ -39,6 +39,12 @@ pub const NO_VALUE: Value = Value(u32::MAX);
/// container for those objects by implementing both `Index<Inst>` and `Index<Ebb>`.
///
pub struct Function {
/// Name of this function. Mostly used by `.cton` files.
name: FunctionName,
/// Signature of this function.
signature: Signature,
/// Data about all of the instructions in the function. The instructions in this vector is not
/// necessarily in program order. The `Inst` reference indexes into this vector.
instructions: Vec<InstructionData>,
@@ -269,9 +275,11 @@ impl InstructionData {
}
impl Function {
/// Create a new empty function.
pub fn new() -> 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,
instructions: Vec::new(),
extended_basic_blocks: Vec::new(),
extended_values: Vec::new(),
@@ -279,6 +287,11 @@ impl Function {
}
}
/// Create a new empty, anomymous function.
pub fn new() -> Function {
Self::with_name_signature(FunctionName::new(), Signature::new())
}
/// Resolve an instruction reference.
pub fn inst(&self, i: Inst) -> &InstructionData {
&self.instructions[i.0 as usize]

View File

@@ -194,6 +194,12 @@ impl Display for Type {
//
// ====--------------------------------------------------------------------------------------====//
/// The name of a function can be any UTF-8 string.
///
/// Function names are mostly a testing and debugging tool. In partucular, `.cton` files use
/// function names to identify functions.
pub type FunctionName = String;
/// Function argument extension options.
///
/// On some architectures, small integer function arguments are extended to the width of a