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));
|
||||
|
||||
@@ -653,7 +653,7 @@ where
|
||||
mod tests {
|
||||
|
||||
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 frontend::{ILBuilder, FunctionBuilder};
|
||||
use cretonne::verifier::verify_function;
|
||||
@@ -687,7 +687,7 @@ mod tests {
|
||||
sig.params.push(AbiParam::new(I32));
|
||||
|
||||
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);
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
//! extern crate cton_frontend;
|
||||
//!
|
||||
//! 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::settings;
|
||||
//! use cton_frontend::{ILBuilder, FunctionBuilder};
|
||||
@@ -67,7 +67,7 @@
|
||||
//! sig.returns.push(AbiParam::new(I32));
|
||||
//! sig.params.push(AbiParam::new(I32));
|
||||
//! 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);
|
||||
//!
|
||||
|
||||
@@ -9,7 +9,7 @@ use std::collections::HashMap;
|
||||
use std::str::FromStr;
|
||||
use std::{u16, u32};
|
||||
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,
|
||||
SigRef, FuncRef, StackSlot, ValueLoc, ArgumentLoc, MemFlags, GlobalVar,
|
||||
GlobalVarData, Heap, HeapData, HeapStyle, HeapBase};
|
||||
@@ -872,7 +872,7 @@ impl<'a> Parser<'a> {
|
||||
fn parse_function_spec(
|
||||
&mut self,
|
||||
unique_isa: Option<&TargetIsa>,
|
||||
) -> Result<(Location, FunctionName, Signature)> {
|
||||
) -> Result<(Location, ExternalName, Signature)> {
|
||||
self.match_identifier("function", "expected 'function'")?;
|
||||
let location = self.loc;
|
||||
|
||||
@@ -889,11 +889,11 @@ impl<'a> Parser<'a> {
|
||||
//
|
||||
// function ::= "function" * name signature { ... }
|
||||
//
|
||||
fn parse_function_name(&mut self) -> Result<FunctionName> {
|
||||
fn parse_function_name(&mut self) -> Result<ExternalName> {
|
||||
match self.token() {
|
||||
Some(Token::Name(s)) => {
|
||||
self.consume();
|
||||
Ok(FunctionName::new(s))
|
||||
Ok(ExternalName::new(s))
|
||||
}
|
||||
Some(Token::HexSequence(s)) => {
|
||||
if s.len() % 2 != 0 {
|
||||
@@ -910,7 +910,7 @@ impl<'a> Parser<'a> {
|
||||
i += 2;
|
||||
}
|
||||
self.consume();
|
||||
Ok(FunctionName::new(bin_name))
|
||||
Ok(ExternalName::new(bin_name))
|
||||
}
|
||||
_ => err!(self.loc, "expected function name"),
|
||||
}
|
||||
|
||||
@@ -9,9 +9,9 @@ use cretonne::settings;
|
||||
use wasmparser;
|
||||
use std::error::Error;
|
||||
|
||||
/// Compute a `ir::FunctionName` for a given wasm function index.
|
||||
fn get_func_name(func_index: FunctionIndex) -> ir::FunctionName {
|
||||
ir::FunctionName::new(format!("wasm_0x{:x}", func_index))
|
||||
/// Compute a `ir::ExternalName` for a given wasm function index.
|
||||
fn get_func_name(func_index: FunctionIndex) -> ir::ExternalName {
|
||||
ir::ExternalName::new(format!("wasm_0x{:x}", func_index))
|
||||
}
|
||||
|
||||
/// 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 {
|
||||
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)
|
||||
}
|
||||
|
||||
|
||||
@@ -151,7 +151,7 @@ pub trait FuncEnvironment {
|
||||
/// by the user, they are only for `cretonne-wasm` internal use.
|
||||
pub trait ModuleEnvironment<'data> {
|
||||
/// 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.
|
||||
fn declare_signature(&mut self, sig: &ir::Signature);
|
||||
|
||||
@@ -255,7 +255,7 @@ mod tests {
|
||||
let runtime = DummyEnvironment::default();
|
||||
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.returns.push(ir::AbiParam::new(I32));
|
||||
|
||||
@@ -286,7 +286,7 @@ mod tests {
|
||||
let runtime = DummyEnvironment::default();
|
||||
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.returns.push(ir::AbiParam::new(I32));
|
||||
|
||||
@@ -326,7 +326,7 @@ mod tests {
|
||||
let runtime = DummyEnvironment::default();
|
||||
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));
|
||||
|
||||
trans
|
||||
|
||||
Reference in New Issue
Block a user