Rename FunctionName to ExternalName.

This commit is contained in:
Dan Gohman
2017-10-27 13:05:49 -07:00
parent fae5ffb556
commit c2665385b1
11 changed files with 56 additions and 55 deletions

View File

@@ -5,7 +5,7 @@
//! //!
//! This module declares the data types used to represent external functions and call signatures. //! 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 isa::{RegInfo, RegUnit};
use std::cmp; use std::cmp;
use std::fmt; use std::fmt;
@@ -323,7 +323,7 @@ impl FromStr for ArgumentPurpose {
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct ExtFuncData { pub struct ExtFuncData {
/// Name of the external function. /// Name of the external function.
pub name: FunctionName, pub name: ExternalName,
/// Call signature of function. /// Call signature of function.
pub signature: SigRef, pub signature: SigRef,
} }

View File

@@ -1,39 +1,40 @@
//! Function names. //! External names.
//! //!
//! The name of a function doesn't have any meaning to Cretonne which compiles functions //! These are identifiers for declaring entities defined outside the current
//! independently. //! 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::fmt::{self, Write};
use std::ascii::AsciiExt; 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 /// External names are primarily used as keys by code using Cretonne to map
/// from a cretonne::ir::Function to additional associated data. /// 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 /// In particular, many `.cton` test files use function names to identify
/// functions. /// functions.
#[derive(Debug, Clone, PartialEq, Eq, Default)] #[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct FunctionName(NameRepr); pub struct ExternalName(NameRepr);
impl FunctionName { impl ExternalName {
/// Creates a new function name from a sequence of bytes. /// Creates a new external name from a sequence of bytes.
/// ///
/// # Examples /// # Examples
/// ///
/// ```rust /// ```rust
/// # use cretonne::ir::FunctionName; /// # use cretonne::ir::ExternalName;
/// // Create `FunctionName` from a string. /// // Create `ExternalName` from a string.
/// let name = FunctionName::new("hello"); /// let name = ExternalName::new("hello");
/// assert_eq!(name.to_string(), "%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 bytes: &[u8] = &[10, 9, 8];
/// let name = FunctionName::new(bytes); /// let name = ExternalName::new(bytes);
/// assert_eq!(name.to_string(), "#0a0908"); /// assert_eq!(name.to_string(), "#0a0908");
/// ``` /// ```
pub fn new<T>(v: T) -> FunctionName pub fn new<T>(v: T) -> ExternalName
where where
T: Into<Vec<u8>>, T: Into<Vec<u8>>,
{ {
@@ -43,12 +44,12 @@ impl FunctionName {
for (i, &byte) in vec.iter().enumerate() { for (i, &byte) in vec.iter().enumerate() {
bytes[i] = byte; bytes[i] = byte;
} }
FunctionName(NameRepr::Short { ExternalName(NameRepr::Short {
length: vec.len() as u8, length: vec.len() as u8,
bytes: bytes, bytes: bytes,
}) })
} else { } 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] { fn as_ref(&self) -> &[u8] {
self.0.as_ref() 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 { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
if let Some(name) = try_as_name(self.0.as_ref()) { if let Some(name) = try_as_name(self.0.as_ref()) {
write!(f, "%{}", name) write!(f, "%{}", name)
@@ -117,24 +118,24 @@ impl fmt::Display for FunctionName {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::FunctionName; use super::ExternalName;
#[test] #[test]
fn displaying() { fn displaying() {
assert_eq!(FunctionName::new("").to_string(), "%"); assert_eq!(ExternalName::new("").to_string(), "%");
assert_eq!(FunctionName::new("x").to_string(), "%x"); assert_eq!(ExternalName::new("x").to_string(), "%x");
assert_eq!(FunctionName::new("x_1").to_string(), "%x_1"); assert_eq!(ExternalName::new("x_1").to_string(), "%x_1");
assert_eq!(FunctionName::new(" ").to_string(), "#20"); assert_eq!(ExternalName::new(" ").to_string(), "#20");
assert_eq!( assert_eq!(
FunctionName::new("кретон").to_string(), ExternalName::new("кретон").to_string(),
"#d0bad180d0b5d182d0bed0bd" "#d0bad180d0b5d182d0bed0bd"
); );
assert_eq!( assert_eq!(
FunctionName::new("印花棉布").to_string(), ExternalName::new("印花棉布").to_string(),
"#e58db0e88ab1e6a389e5b883" "#e58db0e88ab1e6a389e5b883"
); );
assert_eq!( 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" "#000102030405"
); );
} }

View File

@@ -5,7 +5,7 @@
use entity::{PrimaryMap, EntityMap}; use entity::{PrimaryMap, EntityMap};
use ir; 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::{InstEncodings, ValueLocations, JumpTables, StackSlots, EbbOffsets, SourceLocs};
use ir::{Ebb, JumpTableData, JumpTable, StackSlotData, StackSlot, SigRef, ExtFuncData, FuncRef, use ir::{Ebb, JumpTableData, JumpTable, StackSlotData, StackSlot, SigRef, ExtFuncData, FuncRef,
GlobalVarData, GlobalVar, HeapData, Heap}; GlobalVarData, GlobalVar, HeapData, Heap};
@@ -20,7 +20,7 @@ use write::write_function;
#[derive(Clone)] #[derive(Clone)]
pub struct Function { pub struct Function {
/// Name of this function. Mostly used by `.cton` files. /// Name of this function. Mostly used by `.cton` files.
pub name: FunctionName, pub name: ExternalName,
/// Signature of this function. /// Signature of this function.
pub signature: Signature, pub signature: Signature,
@@ -66,7 +66,7 @@ pub struct Function {
impl Function { impl Function {
/// Create a function with the given name and signature. /// 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 { Function {
name, name,
signature: sig, signature: sig,
@@ -100,7 +100,7 @@ impl Function {
/// Create a new empty, anonymous function with a native calling convention. /// Create a new empty, anonymous function with a native calling convention.
pub fn new() -> Function { 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. /// Creates a jump table in the function, to be used by `br_table` instructions.

View File

@@ -12,7 +12,7 @@ pub mod layout;
pub mod function; pub mod function;
mod builder; mod builder;
mod extfunc; mod extfunc;
mod funcname; mod extname;
mod globalvar; mod globalvar;
mod heap; mod heap;
mod memflags; 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::entities::{Ebb, Inst, Value, StackSlot, GlobalVar, JumpTable, FuncRef, SigRef, Heap};
pub use ir::extfunc::{Signature, CallConv, AbiParam, ArgumentExtension, ArgumentPurpose, pub use ir::extfunc::{Signature, CallConv, AbiParam, ArgumentExtension, ArgumentPurpose,
ExtFuncData}; ExtFuncData};
pub use ir::funcname::FunctionName; pub use ir::extname::ExternalName;
pub use ir::function::Function; pub use ir::function::Function;
pub use ir::globalvar::GlobalVarData; pub use ir::globalvar::GlobalVarData;
pub use ir::heap::{HeapData, HeapStyle, HeapBase}; pub use ir::heap::{HeapData, HeapStyle, HeapBase};

View File

@@ -441,7 +441,7 @@ impl<'a> fmt::Display for DisplayValues<'a> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use ir::{Function, FunctionName, StackSlotData, StackSlotKind}; use ir::{Function, ExternalName, StackSlotData, StackSlotKind};
use ir::types; use ir::types;
#[test] #[test]
@@ -449,7 +449,7 @@ mod tests {
let mut f = Function::new(); let mut f = Function::new();
assert_eq!(f.to_string(), "function %() native {\n}\n"); 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"); assert_eq!(f.to_string(), "function %foo() native {\n}\n");
f.create_stack_slot(StackSlotData::new(StackSlotKind::Local, 4)); f.create_stack_slot(StackSlotData::new(StackSlotKind::Local, 4));

View File

@@ -653,7 +653,7 @@ where
mod tests { mod tests {
use cretonne::entity::EntityRef; use cretonne::entity::EntityRef;
use cretonne::ir::{FunctionName, Function, CallConv, Signature, AbiParam, InstBuilder}; use cretonne::ir::{ExternalName, Function, CallConv, Signature, AbiParam, InstBuilder};
use cretonne::ir::types::*; use cretonne::ir::types::*;
use frontend::{ILBuilder, FunctionBuilder}; use frontend::{ILBuilder, FunctionBuilder};
use cretonne::verifier::verify_function; use cretonne::verifier::verify_function;
@@ -687,7 +687,7 @@ mod tests {
sig.params.push(AbiParam::new(I32)); sig.params.push(AbiParam::new(I32));
let mut il_builder = ILBuilder::<Variable>::new(); let mut il_builder = ILBuilder::<Variable>::new();
let mut func = Function::with_name_signature(FunctionName::new("sample_function"), sig); let mut func = Function::with_name_signature(ExternalName::new("sample_function"), sig);
{ {
let mut builder = FunctionBuilder::<Variable>::new(&mut func, &mut il_builder); let mut builder = FunctionBuilder::<Variable>::new(&mut func, &mut il_builder);

View File

@@ -36,7 +36,7 @@
//! extern crate cton_frontend; //! extern crate cton_frontend;
//! //!
//! use cretonne::entity::EntityRef; //! use cretonne::entity::EntityRef;
//! use cretonne::ir::{FunctionName, CallConv, Function, Signature, AbiParam, InstBuilder}; //! use cretonne::ir::{ExternalName, CallConv, Function, Signature, AbiParam, InstBuilder};
//! use cretonne::ir::types::*; //! use cretonne::ir::types::*;
//! use cretonne::settings; //! use cretonne::settings;
//! use cton_frontend::{ILBuilder, FunctionBuilder}; //! use cton_frontend::{ILBuilder, FunctionBuilder};
@@ -67,7 +67,7 @@
//! sig.returns.push(AbiParam::new(I32)); //! sig.returns.push(AbiParam::new(I32));
//! sig.params.push(AbiParam::new(I32)); //! sig.params.push(AbiParam::new(I32));
//! let mut il_builder = ILBuilder::<Variable>::new(); //! let mut il_builder = ILBuilder::<Variable>::new();
//! let mut func = Function::with_name_signature(FunctionName::new("sample_function"), sig); //! let mut func = Function::with_name_signature(ExternalName::new("sample_function"), sig);
//! { //! {
//! let mut builder = FunctionBuilder::<Variable>::new(&mut func, &mut il_builder); //! let mut builder = FunctionBuilder::<Variable>::new(&mut func, &mut il_builder);
//! //!

View File

@@ -9,7 +9,7 @@ use std::collections::HashMap;
use std::str::FromStr; use std::str::FromStr;
use std::{u16, u32}; use std::{u16, u32};
use std::mem; use std::mem;
use cretonne::ir::{Function, Ebb, Opcode, Value, Type, FunctionName, CallConv, StackSlotData, use cretonne::ir::{Function, Ebb, Opcode, Value, Type, ExternalName, CallConv, StackSlotData,
JumpTable, JumpTableData, Signature, AbiParam, ArgumentExtension, ExtFuncData, JumpTable, JumpTableData, Signature, AbiParam, ArgumentExtension, ExtFuncData,
SigRef, FuncRef, StackSlot, ValueLoc, ArgumentLoc, MemFlags, GlobalVar, SigRef, FuncRef, StackSlot, ValueLoc, ArgumentLoc, MemFlags, GlobalVar,
GlobalVarData, Heap, HeapData, HeapStyle, HeapBase}; GlobalVarData, Heap, HeapData, HeapStyle, HeapBase};
@@ -872,7 +872,7 @@ impl<'a> Parser<'a> {
fn parse_function_spec( fn parse_function_spec(
&mut self, &mut self,
unique_isa: Option<&TargetIsa>, unique_isa: Option<&TargetIsa>,
) -> Result<(Location, FunctionName, Signature)> { ) -> Result<(Location, ExternalName, Signature)> {
self.match_identifier("function", "expected 'function'")?; self.match_identifier("function", "expected 'function'")?;
let location = self.loc; let location = self.loc;
@@ -889,11 +889,11 @@ impl<'a> Parser<'a> {
// //
// function ::= "function" * name signature { ... } // function ::= "function" * name signature { ... }
// //
fn parse_function_name(&mut self) -> Result<FunctionName> { fn parse_function_name(&mut self) -> Result<ExternalName> {
match self.token() { match self.token() {
Some(Token::Name(s)) => { Some(Token::Name(s)) => {
self.consume(); self.consume();
Ok(FunctionName::new(s)) Ok(ExternalName::new(s))
} }
Some(Token::HexSequence(s)) => { Some(Token::HexSequence(s)) => {
if s.len() % 2 != 0 { if s.len() % 2 != 0 {
@@ -910,7 +910,7 @@ impl<'a> Parser<'a> {
i += 2; i += 2;
} }
self.consume(); self.consume();
Ok(FunctionName::new(bin_name)) Ok(ExternalName::new(bin_name))
} }
_ => err!(self.loc, "expected function name"), _ => err!(self.loc, "expected function name"),
} }

View File

@@ -9,9 +9,9 @@ use cretonne::settings;
use wasmparser; use wasmparser;
use std::error::Error; use std::error::Error;
/// Compute a `ir::FunctionName` for a given wasm function index. /// Compute a `ir::ExternalName` for a given wasm function index.
fn get_func_name(func_index: FunctionIndex) -> ir::FunctionName { fn get_func_name(func_index: FunctionIndex) -> ir::ExternalName {
ir::FunctionName::new(format!("wasm_0x{:x}", func_index)) ir::ExternalName::new(format!("wasm_0x{:x}", func_index))
} }
/// A collection of names under which a given entity is exported. /// A collection of names under which a given entity is exported.
@@ -196,7 +196,7 @@ impl<'dummy_environment> FuncEnvironment for DummyFuncEnvironment<'dummy_environ
} }
impl<'data> ModuleEnvironment<'data> for DummyEnvironment { impl<'data> ModuleEnvironment<'data> for DummyEnvironment {
fn get_func_name(&self, func_index: FunctionIndex) -> ir::FunctionName { fn get_func_name(&self, func_index: FunctionIndex) -> ir::ExternalName {
get_func_name(func_index) get_func_name(func_index)
} }

View File

@@ -151,7 +151,7 @@ pub trait FuncEnvironment {
/// by the user, they are only for `cretonne-wasm` internal use. /// by the user, they are only for `cretonne-wasm` internal use.
pub trait ModuleEnvironment<'data> { pub trait ModuleEnvironment<'data> {
/// Return the name for the given function index. /// Return the name for the given function index.
fn get_func_name(&self, func_index: FunctionIndex) -> ir::FunctionName; fn get_func_name(&self, func_index: FunctionIndex) -> ir::ExternalName;
/// Declares a function signature to the environment. /// Declares a function signature to the environment.
fn declare_signature(&mut self, sig: &ir::Signature); fn declare_signature(&mut self, sig: &ir::Signature);

View File

@@ -255,7 +255,7 @@ mod tests {
let runtime = DummyEnvironment::default(); let runtime = DummyEnvironment::default();
let mut ctx = Context::new(); let mut ctx = Context::new();
ctx.func.name = ir::FunctionName::new("small1"); ctx.func.name = ir::ExternalName::new("small1");
ctx.func.signature.params.push(ir::AbiParam::new(I32)); ctx.func.signature.params.push(ir::AbiParam::new(I32));
ctx.func.signature.returns.push(ir::AbiParam::new(I32)); ctx.func.signature.returns.push(ir::AbiParam::new(I32));
@@ -286,7 +286,7 @@ mod tests {
let runtime = DummyEnvironment::default(); let runtime = DummyEnvironment::default();
let mut ctx = Context::new(); let mut ctx = Context::new();
ctx.func.name = ir::FunctionName::new("small2"); ctx.func.name = ir::ExternalName::new("small2");
ctx.func.signature.params.push(ir::AbiParam::new(I32)); ctx.func.signature.params.push(ir::AbiParam::new(I32));
ctx.func.signature.returns.push(ir::AbiParam::new(I32)); ctx.func.signature.returns.push(ir::AbiParam::new(I32));
@@ -326,7 +326,7 @@ mod tests {
let runtime = DummyEnvironment::default(); let runtime = DummyEnvironment::default();
let mut ctx = Context::new(); let mut ctx = Context::new();
ctx.func.name = ir::FunctionName::new("infloop"); ctx.func.name = ir::ExternalName::new("infloop");
ctx.func.signature.returns.push(ir::AbiParam::new(I32)); ctx.func.signature.returns.push(ir::AbiParam::new(I32));
trans trans