Add an as_u32() member to entity_impl types.

This allows us to avoid a lot of casting indices back to u32.
This commit is contained in:
Dan Gohman
2018-11-30 16:16:35 -08:00
parent 954573440d
commit 91477d21c8
6 changed files with 16 additions and 9 deletions

View File

@@ -266,7 +266,7 @@ impl UFEntry {
/// Encode a link entry.
fn encode_link(v: Value) -> i32 {
!(v.index() as i32)
!(v.as_u32() as i32)
}
}

View File

@@ -98,6 +98,13 @@ macro_rules! entity_impl {
$entity($crate::__core::u32::MAX)
}
}
impl $entity {
/// Return the underlying index value as a `u32`.
pub fn as_u32(self) -> u32 {
self.0
}
}
};
// Include basic `Display` impl using the given display prefix.

View File

@@ -473,7 +473,7 @@ where
let signature = in_func.import_signature(decl.signature.clone());
let colocated = decl.linkage.is_final();
in_func.import_function(ir::ExtFuncData {
name: ir::ExternalName::user(0, func.index() as u32),
name: ir::ExternalName::user(0, func.as_u32()),
signature,
colocated,
})
@@ -486,7 +486,7 @@ where
let decl = &self.contents.data_objects[data].decl;
let colocated = decl.linkage.is_final();
func.create_global_value(ir::GlobalValueData::Symbol {
name: ir::ExternalName::user(1, data.index() as u32),
name: ir::ExternalName::user(1, data.as_u32()),
offset: ir::immediates::Imm64::new(0),
colocated,
})
@@ -494,12 +494,12 @@ where
/// TODO: Same as above.
pub fn declare_func_in_data(&self, func: FuncId, ctx: &mut DataContext) -> ir::FuncRef {
ctx.import_function(ir::ExternalName::user(0, func.index() as u32))
ctx.import_function(ir::ExternalName::user(0, func.as_u32()))
}
/// TODO: Same as above.
pub fn declare_data_in_data(&self, data: DataId, ctx: &mut DataContext) -> ir::GlobalValue {
ctx.import_global_value(ir::ExternalName::user(1, data.index() as u32))
ctx.import_global_value(ir::ExternalName::user(1, data.as_u32()))
}
/// Define a function, producing the function body from the given `Context`.

View File

@@ -27,7 +27,7 @@ fn main() {
.unwrap();
ctx.func.signature = sig_a;
ctx.func.name = ExternalName::user(0, func_a.index() as u32);
ctx.func.name = ExternalName::user(0, func_a.as_u32());
{
let mut bcx: FunctionBuilder = FunctionBuilder::new(&mut ctx.func, &mut func_ctx);
let ebb = bcx.create_ebb();
@@ -45,7 +45,7 @@ fn main() {
module.clear_context(&mut ctx);
ctx.func.signature = sig_b;
ctx.func.name = ExternalName::user(0, func_b.index() as u32);
ctx.func.name = ExternalName::user(0, func_b.as_u32());
{
let mut bcx: FunctionBuilder = FunctionBuilder::new(&mut ctx.func, &mut func_ctx);
let ebb = bcx.create_ebb();

View File

@@ -42,7 +42,7 @@ fn define_simple_function(module: &mut Module<SimpleJITBackend>) -> FuncId {
.unwrap();
let mut ctx = Context::new();
ctx.func = Function::with_name_signature(ExternalName::user(0, func_id.index() as u32), sig);
ctx.func = Function::with_name_signature(ExternalName::user(0, func_id.as_u32()), sig);
let mut func_ctx = FunctionBuilderContext::new();
{
let mut bcx: FunctionBuilder = FunctionBuilder::new(&mut ctx.func, &mut func_ctx);

View File

@@ -18,7 +18,7 @@ use translation_utils::{
/// Compute a `ir::ExternalName` for a given wasm function index.
fn get_func_name(func_index: FuncIndex) -> ir::ExternalName {
ir::ExternalName::user(0, func_index.index() as u32)
ir::ExternalName::user(0, func_index.as_u32())
}
/// A collection of names under which a given entity is exported.