Change GlobalVar to GlobalValue

This commit is contained in:
Lachlan Sneff
2018-06-14 01:07:27 -04:00
committed by Dan Gohman
parent 49cc693d64
commit 5c320a0d30
44 changed files with 324 additions and 237 deletions

View File

@@ -84,7 +84,7 @@ where
&mut self,
data: &mut Self::CompiledData,
offset: usize,
what: ir::GlobalVar,
what: ir::GlobalValue,
addend: binemit::Addend,
);

View File

@@ -52,11 +52,11 @@ pub struct DataDescription {
/// External function declarations.
pub function_decls: PrimaryMap<ir::FuncRef, ir::ExternalName>,
/// External data object declarations.
pub data_decls: PrimaryMap<ir::GlobalVar, ir::ExternalName>,
pub data_decls: PrimaryMap<ir::GlobalValue, ir::ExternalName>,
/// Function addresses to write at specified offsets.
pub function_relocs: Vec<(CodeOffset, ir::FuncRef)>,
/// Data addresses to write at specified offsets.
pub data_relocs: Vec<(CodeOffset, ir::GlobalVar, Addend)>,
pub data_relocs: Vec<(CodeOffset, ir::GlobalValue, Addend)>,
}
/// This is to data objects what cretonne_codegen::Context is to functions.
@@ -114,14 +114,14 @@ impl DataContext {
self.description.function_decls.push(name)
}
/// Declares a global variable import.
/// Declares a global valueiable import.
///
/// TODO: Rename to import_data?
///
/// Users of the `Module` API generally should call
/// `Module::declare_data_in_data` instead, as it takes care of generating
/// the appropriate `ExternalName`.
pub fn import_global_var(&mut self, name: ir::ExternalName) -> ir::GlobalVar {
pub fn import_global_value(&mut self, name: ir::ExternalName) -> ir::GlobalValue {
self.description.data_decls.push(name)
}
@@ -131,7 +131,7 @@ impl DataContext {
}
/// Write the address of `data` into the data at offset `offset`.
pub fn write_data_addr(&mut self, offset: CodeOffset, data: ir::GlobalVar, addend: Addend) {
pub fn write_data_addr(&mut self, offset: CodeOffset, data: ir::GlobalValue, addend: Addend) {
self.description.data_relocs.push((offset, data, addend))
}
@@ -168,8 +168,8 @@ mod tests {
let _func_a = data_ctx.import_function(ir::ExternalName::user(0, 0));
let func_b = data_ctx.import_function(ir::ExternalName::user(0, 1));
let func_c = data_ctx.import_function(ir::ExternalName::user(1, 0));
let _data_a = data_ctx.import_global_var(ir::ExternalName::user(2, 2));
let data_b = data_ctx.import_global_var(ir::ExternalName::user(2, 3));
let _data_a = data_ctx.import_global_value(ir::ExternalName::user(2, 2));
let data_b = data_ctx.import_global_value(ir::ExternalName::user(2, 3));
data_ctx.write_function_addr(8, func_b);
data_ctx.write_function_addr(16, func_c);

View File

@@ -2,7 +2,7 @@
// TODO: Should `ir::Function` really have a `name`?
// TODO: Factor out `ir::Function`'s `ext_funcs` and `global_vars` into a struct
// TODO: Factor out `ir::Function`'s `ext_funcs` and `global_values` into a struct
// shared with `DataContext`?
use cretonne_codegen::entity::{EntityRef, PrimaryMap};
@@ -440,10 +440,10 @@ where
/// Use this when you're building the IR of a function to reference a data object.
///
/// TODO: Same as above.
pub fn declare_data_in_func(&self, data: DataId, func: &mut ir::Function) -> ir::GlobalVar {
pub fn declare_data_in_func(&self, data: DataId, func: &mut ir::Function) -> ir::GlobalValue {
let decl = &self.contents.data_objects[data].decl;
let colocated = decl.linkage.is_final();
func.create_global_var(ir::GlobalVarData::Sym {
func.create_global_value(ir::GlobalValueData::Sym {
name: ir::ExternalName::user(1, data.index() as u32),
colocated,
})
@@ -455,8 +455,8 @@ where
}
/// TODO: Same as above.
pub fn declare_data_in_data(&self, data: DataId, ctx: &mut DataContext) -> ir::GlobalVar {
ctx.import_global_var(ir::ExternalName::user(1, data.index() as u32))
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))
}
/// Define a function, producing the function body from the given `Context`.
@@ -536,7 +536,7 @@ where
&mut self,
data: DataId,
offset: usize,
what: ir::GlobalVar,
what: ir::GlobalValue,
addend: binemit::Addend,
) {
let info = &mut self.contents.data_objects[data];