Rename FunctionName to ExternalName.
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
//!
|
||||
//! This module declares the data types used to represent external functions and call signatures.
|
||||
|
||||
use ir::{Type, FunctionName, SigRef, ArgumentLoc};
|
||||
use ir::{Type, ExternalName, SigRef, ArgumentLoc};
|
||||
use isa::{RegInfo, RegUnit};
|
||||
use std::cmp;
|
||||
use std::fmt;
|
||||
@@ -323,7 +323,7 @@ impl FromStr for ArgumentPurpose {
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ExtFuncData {
|
||||
/// Name of the external function.
|
||||
pub name: FunctionName,
|
||||
pub name: ExternalName,
|
||||
/// Call signature of function.
|
||||
pub signature: SigRef,
|
||||
}
|
||||
|
||||
@@ -1,39 +1,40 @@
|
||||
//! Function names.
|
||||
//! External names.
|
||||
//!
|
||||
//! The name of a function doesn't have any meaning to Cretonne which compiles functions
|
||||
//! independently.
|
||||
//! These are identifiers for declaring entities defined outside the current
|
||||
//! function. The name of an external declaration doesn't have any meaning to
|
||||
//! Cretonne, which compiles functions independently.
|
||||
|
||||
use std::fmt::{self, Write};
|
||||
use std::ascii::AsciiExt;
|
||||
|
||||
/// The name of a function can be any sequence of bytes.
|
||||
/// The name of an external can be any sequence of bytes.
|
||||
///
|
||||
/// Function names are primarily used as keys by code using Cretonne to map
|
||||
/// from a cretonne::ir::Function to additional associated data.
|
||||
/// External names are primarily used as keys by code using Cretonne to map
|
||||
/// from a cretonne::ir::FuncRef or similar to additional associated data.
|
||||
///
|
||||
/// Function names can also serve as a primitive testing and debugging tool.
|
||||
/// External names can also serve as a primitive testing and debugging tool.
|
||||
/// In particular, many `.cton` test files use function names to identify
|
||||
/// functions.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Default)]
|
||||
pub struct FunctionName(NameRepr);
|
||||
pub struct ExternalName(NameRepr);
|
||||
|
||||
impl FunctionName {
|
||||
/// Creates a new function name from a sequence of bytes.
|
||||
impl ExternalName {
|
||||
/// Creates a new external name from a sequence of bytes.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust
|
||||
/// # use cretonne::ir::FunctionName;
|
||||
/// // Create `FunctionName` from a string.
|
||||
/// let name = FunctionName::new("hello");
|
||||
/// # use cretonne::ir::ExternalName;
|
||||
/// // Create `ExternalName` from a string.
|
||||
/// let name = ExternalName::new("hello");
|
||||
/// assert_eq!(name.to_string(), "%hello");
|
||||
///
|
||||
/// // Create `FunctionName` from a sequence of bytes.
|
||||
/// // Create `ExternalName` from a sequence of bytes.
|
||||
/// let bytes: &[u8] = &[10, 9, 8];
|
||||
/// let name = FunctionName::new(bytes);
|
||||
/// let name = ExternalName::new(bytes);
|
||||
/// assert_eq!(name.to_string(), "#0a0908");
|
||||
/// ```
|
||||
pub fn new<T>(v: T) -> FunctionName
|
||||
pub fn new<T>(v: T) -> ExternalName
|
||||
where
|
||||
T: Into<Vec<u8>>,
|
||||
{
|
||||
@@ -43,12 +44,12 @@ impl FunctionName {
|
||||
for (i, &byte) in vec.iter().enumerate() {
|
||||
bytes[i] = byte;
|
||||
}
|
||||
FunctionName(NameRepr::Short {
|
||||
ExternalName(NameRepr::Short {
|
||||
length: vec.len() as u8,
|
||||
bytes: bytes,
|
||||
})
|
||||
} else {
|
||||
FunctionName(NameRepr::Long(vec))
|
||||
ExternalName(NameRepr::Long(vec))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -86,7 +87,7 @@ impl AsRef<[u8]> for NameRepr {
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<[u8]> for FunctionName {
|
||||
impl AsRef<[u8]> for ExternalName {
|
||||
fn as_ref(&self) -> &[u8] {
|
||||
self.0.as_ref()
|
||||
}
|
||||
@@ -101,7 +102,7 @@ impl Default for NameRepr {
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for FunctionName {
|
||||
impl fmt::Display for ExternalName {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
if let Some(name) = try_as_name(self.0.as_ref()) {
|
||||
write!(f, "%{}", name)
|
||||
@@ -117,24 +118,24 @@ impl fmt::Display for FunctionName {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::FunctionName;
|
||||
use super::ExternalName;
|
||||
|
||||
#[test]
|
||||
fn displaying() {
|
||||
assert_eq!(FunctionName::new("").to_string(), "%");
|
||||
assert_eq!(FunctionName::new("x").to_string(), "%x");
|
||||
assert_eq!(FunctionName::new("x_1").to_string(), "%x_1");
|
||||
assert_eq!(FunctionName::new(" ").to_string(), "#20");
|
||||
assert_eq!(ExternalName::new("").to_string(), "%");
|
||||
assert_eq!(ExternalName::new("x").to_string(), "%x");
|
||||
assert_eq!(ExternalName::new("x_1").to_string(), "%x_1");
|
||||
assert_eq!(ExternalName::new(" ").to_string(), "#20");
|
||||
assert_eq!(
|
||||
FunctionName::new("кретон").to_string(),
|
||||
ExternalName::new("кретон").to_string(),
|
||||
"#d0bad180d0b5d182d0bed0bd"
|
||||
);
|
||||
assert_eq!(
|
||||
FunctionName::new("印花棉布").to_string(),
|
||||
ExternalName::new("印花棉布").to_string(),
|
||||
"#e58db0e88ab1e6a389e5b883"
|
||||
);
|
||||
assert_eq!(
|
||||
FunctionName::new(vec![0, 1, 2, 3, 4, 5]).to_string(),
|
||||
ExternalName::new(vec![0, 1, 2, 3, 4, 5]).to_string(),
|
||||
"#000102030405"
|
||||
);
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
use entity::{PrimaryMap, EntityMap};
|
||||
use ir;
|
||||
use ir::{FunctionName, CallConv, Signature, DataFlowGraph, Layout};
|
||||
use ir::{ExternalName, CallConv, Signature, DataFlowGraph, Layout};
|
||||
use ir::{InstEncodings, ValueLocations, JumpTables, StackSlots, EbbOffsets, SourceLocs};
|
||||
use ir::{Ebb, JumpTableData, JumpTable, StackSlotData, StackSlot, SigRef, ExtFuncData, FuncRef,
|
||||
GlobalVarData, GlobalVar, HeapData, Heap};
|
||||
@@ -20,7 +20,7 @@ use write::write_function;
|
||||
#[derive(Clone)]
|
||||
pub struct Function {
|
||||
/// Name of this function. Mostly used by `.cton` files.
|
||||
pub name: FunctionName,
|
||||
pub name: ExternalName,
|
||||
|
||||
/// Signature of this function.
|
||||
pub signature: Signature,
|
||||
@@ -66,7 +66,7 @@ pub struct Function {
|
||||
|
||||
impl Function {
|
||||
/// Create a function with the given name and signature.
|
||||
pub fn with_name_signature(name: FunctionName, sig: Signature) -> Function {
|
||||
pub fn with_name_signature(name: ExternalName, sig: Signature) -> Function {
|
||||
Function {
|
||||
name,
|
||||
signature: sig,
|
||||
@@ -100,7 +100,7 @@ impl Function {
|
||||
|
||||
/// Create a new empty, anonymous function with a native calling convention.
|
||||
pub fn new() -> Function {
|
||||
Self::with_name_signature(FunctionName::default(), Signature::new(CallConv::Native))
|
||||
Self::with_name_signature(ExternalName::default(), Signature::new(CallConv::Native))
|
||||
}
|
||||
|
||||
/// Creates a jump table in the function, to be used by `br_table` instructions.
|
||||
|
||||
@@ -12,7 +12,7 @@ pub mod layout;
|
||||
pub mod function;
|
||||
mod builder;
|
||||
mod extfunc;
|
||||
mod funcname;
|
||||
mod extname;
|
||||
mod globalvar;
|
||||
mod heap;
|
||||
mod memflags;
|
||||
@@ -26,7 +26,7 @@ pub use ir::dfg::{DataFlowGraph, ValueDef};
|
||||
pub use ir::entities::{Ebb, Inst, Value, StackSlot, GlobalVar, JumpTable, FuncRef, SigRef, Heap};
|
||||
pub use ir::extfunc::{Signature, CallConv, AbiParam, ArgumentExtension, ArgumentPurpose,
|
||||
ExtFuncData};
|
||||
pub use ir::funcname::FunctionName;
|
||||
pub use ir::extname::ExternalName;
|
||||
pub use ir::function::Function;
|
||||
pub use ir::globalvar::GlobalVarData;
|
||||
pub use ir::heap::{HeapData, HeapStyle, HeapBase};
|
||||
|
||||
@@ -441,7 +441,7 @@ impl<'a> fmt::Display for DisplayValues<'a> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use ir::{Function, FunctionName, StackSlotData, StackSlotKind};
|
||||
use ir::{Function, ExternalName, StackSlotData, StackSlotKind};
|
||||
use ir::types;
|
||||
|
||||
#[test]
|
||||
@@ -449,7 +449,7 @@ mod tests {
|
||||
let mut f = Function::new();
|
||||
assert_eq!(f.to_string(), "function %() native {\n}\n");
|
||||
|
||||
f.name = FunctionName::new("foo");
|
||||
f.name = ExternalName::new("foo");
|
||||
assert_eq!(f.to_string(), "function %foo() native {\n}\n");
|
||||
|
||||
f.create_stack_slot(StackSlotData::new(StackSlotKind::Local, 4));
|
||||
|
||||
Reference in New Issue
Block a user