Add a new kind of GlobalVar for symbolic addresses.

These addresses will allow referencing C/C++/Rust-style global variables
by name directly.
This commit is contained in:
Dan Gohman
2017-10-27 13:27:10 -07:00
parent c2665385b1
commit 6fc45b070a
5 changed files with 48 additions and 7 deletions

View File

@@ -1,6 +1,6 @@
//! Global variables.
use ir::GlobalVar;
use ir::{ExternalName, GlobalVar};
use ir::immediates::Offset32;
use std::fmt;
@@ -25,6 +25,14 @@ pub enum GlobalVarData {
/// Byte offset to be added to the pointer loaded from `base`.
offset: Offset32,
},
/// Variable is at an address identified by a symbolic name. Cretonne itself
/// does not interpret this name; it's used by embedders to link with other
/// data structures.
Sym {
/// The symbolic name.
name: ExternalName,
},
}
impl fmt::Display for GlobalVarData {
@@ -32,6 +40,7 @@ impl fmt::Display for GlobalVarData {
match *self {
GlobalVarData::VmCtx { offset } => write!(f, "vmctx{}", offset),
GlobalVarData::Deref { base, offset } => write!(f, "deref({}){}", base, offset),
GlobalVarData::Sym { ref name } => write!(f, "globalsym {}", name),
}
}
}

View File

@@ -21,6 +21,7 @@ pub fn expand_global_addr(inst: ir::Inst, func: &mut ir::Function, _cfg: &mut Co
match func.global_vars[gv] {
ir::GlobalVarData::VmCtx { offset } => vmctx_addr(inst, func, offset.into()),
ir::GlobalVarData::Deref { base, offset } => deref_addr(inst, func, base, offset.into()),
ir::GlobalVarData::Sym { .. } => (),
}
}