Change GlobalVar to GlobalValue
This commit is contained in:
committed by
Dan Gohman
parent
49cc693d64
commit
5c320a0d30
@@ -82,18 +82,18 @@ impl StackSlot {
|
||||
}
|
||||
}
|
||||
|
||||
/// An opaque reference to a global variable.
|
||||
/// An opaque reference to a global valueiable.
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct GlobalVar(u32);
|
||||
entity_impl!(GlobalVar, "gv");
|
||||
pub struct GlobalValue(u32);
|
||||
entity_impl!(GlobalValue, "gv");
|
||||
|
||||
impl GlobalVar {
|
||||
/// Create a new global variable reference from its number.
|
||||
impl GlobalValue {
|
||||
/// Create a new global valueiable reference from its number.
|
||||
///
|
||||
/// This method is for use by the parser.
|
||||
pub fn with_number(n: u32) -> Option<Self> {
|
||||
if n < u32::MAX {
|
||||
Some(GlobalVar(n))
|
||||
Some(GlobalValue(n))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@@ -186,7 +186,7 @@ pub enum AnyEntity {
|
||||
/// A stack slot.
|
||||
StackSlot(StackSlot),
|
||||
/// A Global variable.
|
||||
GlobalVar(GlobalVar),
|
||||
GlobalValue(GlobalValue),
|
||||
/// A jump table.
|
||||
JumpTable(JumpTable),
|
||||
/// An external function.
|
||||
@@ -205,7 +205,7 @@ impl fmt::Display for AnyEntity {
|
||||
AnyEntity::Inst(r) => r.fmt(f),
|
||||
AnyEntity::Value(r) => r.fmt(f),
|
||||
AnyEntity::StackSlot(r) => r.fmt(f),
|
||||
AnyEntity::GlobalVar(r) => r.fmt(f),
|
||||
AnyEntity::GlobalValue(r) => r.fmt(f),
|
||||
AnyEntity::JumpTable(r) => r.fmt(f),
|
||||
AnyEntity::FuncRef(r) => r.fmt(f),
|
||||
AnyEntity::SigRef(r) => r.fmt(f),
|
||||
@@ -244,9 +244,9 @@ impl From<StackSlot> for AnyEntity {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<GlobalVar> for AnyEntity {
|
||||
fn from(r: GlobalVar) -> Self {
|
||||
AnyEntity::GlobalVar(r)
|
||||
impl From<GlobalValue> for AnyEntity {
|
||||
fn from(r: GlobalValue) -> Self {
|
||||
AnyEntity::GlobalValue(r)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -284,7 +284,7 @@ pub enum ArgumentPurpose {
|
||||
/// A VM context pointer.
|
||||
///
|
||||
/// This is a pointer to a context struct containing details about the current sandbox. It is
|
||||
/// used as a base pointer for `vmctx` global variables.
|
||||
/// used as a base pointer for `vmctx` global valueiables.
|
||||
VMContext,
|
||||
|
||||
/// A signature identifier.
|
||||
|
||||
@@ -7,7 +7,7 @@ use binemit::CodeOffset;
|
||||
use entity::{EntityMap, PrimaryMap};
|
||||
use ir;
|
||||
use ir::{DataFlowGraph, ExternalName, Layout, Signature};
|
||||
use ir::{Ebb, ExtFuncData, FuncRef, GlobalVar, GlobalVarData, Heap, HeapData, JumpTable,
|
||||
use ir::{Ebb, ExtFuncData, FuncRef, GlobalValue, GlobalValueData, Heap, HeapData, JumpTable,
|
||||
JumpTableData, SigRef, StackSlot, StackSlotData};
|
||||
use ir::{EbbOffsets, InstEncodings, JumpTables, SourceLocs, StackSlots, ValueLocations};
|
||||
use isa::{EncInfo, Encoding, Legalize, TargetIsa};
|
||||
@@ -32,10 +32,10 @@ pub struct Function {
|
||||
|
||||
/// If not `None`, represents the address that the stack pointer should
|
||||
/// be checked against.
|
||||
pub stack_limit: Option<ir::GlobalVar>,
|
||||
pub stack_limit: Option<ir::GlobalValue>,
|
||||
|
||||
/// Global variables referenced.
|
||||
pub global_vars: PrimaryMap<ir::GlobalVar, ir::GlobalVarData>,
|
||||
pub global_values: PrimaryMap<ir::GlobalValue, ir::GlobalValueData>,
|
||||
|
||||
/// Heaps referenced.
|
||||
pub heaps: PrimaryMap<ir::Heap, ir::HeapData>,
|
||||
@@ -78,7 +78,7 @@ impl Function {
|
||||
signature: sig,
|
||||
stack_slots: StackSlots::new(),
|
||||
stack_limit: None,
|
||||
global_vars: PrimaryMap::new(),
|
||||
global_values: PrimaryMap::new(),
|
||||
heaps: PrimaryMap::new(),
|
||||
jump_tables: PrimaryMap::new(),
|
||||
dfg: DataFlowGraph::new(),
|
||||
@@ -94,7 +94,7 @@ impl Function {
|
||||
pub fn clear(&mut self) {
|
||||
self.signature.clear(CallConv::Fast);
|
||||
self.stack_slots.clear();
|
||||
self.global_vars.clear();
|
||||
self.global_values.clear();
|
||||
self.heaps.clear();
|
||||
self.jump_tables.clear();
|
||||
self.dfg.clear();
|
||||
@@ -129,7 +129,7 @@ impl Function {
|
||||
/// Sets the stack limit for the function.
|
||||
///
|
||||
/// Returns previous one if any.
|
||||
pub fn set_stack_limit(&mut self, stack_limit: Option<GlobalVar>) -> Option<GlobalVar> {
|
||||
pub fn set_stack_limit(&mut self, stack_limit: Option<GlobalValue>) -> Option<GlobalValue> {
|
||||
let prev = self.stack_limit.take();
|
||||
self.stack_limit = stack_limit;
|
||||
prev
|
||||
@@ -145,9 +145,9 @@ impl Function {
|
||||
self.dfg.ext_funcs.push(data)
|
||||
}
|
||||
|
||||
/// Declares a global variable accessible to the function.
|
||||
pub fn create_global_var(&mut self, data: GlobalVarData) -> GlobalVar {
|
||||
self.global_vars.push(data)
|
||||
/// Declares a global valueiable accessible to the function.
|
||||
pub fn create_global_value(&mut self, data: GlobalValueData) -> GlobalValue {
|
||||
self.global_values.push(data)
|
||||
}
|
||||
|
||||
/// Declares a heap accessible to the function.
|
||||
|
||||
70
lib/codegen/src/ir/globalvalue.rs
Normal file
70
lib/codegen/src/ir/globalvalue.rs
Normal file
@@ -0,0 +1,70 @@
|
||||
//! Global variables.
|
||||
|
||||
use ir::immediates::Offset32;
|
||||
use ir::{ExternalName, GlobalValue};
|
||||
use std::fmt;
|
||||
|
||||
/// Information about a global valueiable declaration.
|
||||
#[derive(Clone)]
|
||||
pub enum GlobalValueData {
|
||||
/// Variable is part of the VM context struct, it's address is a constant offset from the VM
|
||||
/// context pointer.
|
||||
VMContext {
|
||||
/// Offset from the `vmctx` pointer to this global.
|
||||
offset: Offset32,
|
||||
},
|
||||
|
||||
/// Variable is part of a struct pointed to by another global valueiable.
|
||||
///
|
||||
/// The `base` global valueiable is assumed to contain a pointer to a struct. This global
|
||||
/// variable lives at an offset into the struct. The memory must be accessible, and
|
||||
/// naturally aligned to hold a pointer value.
|
||||
Deref {
|
||||
/// The base pointer global valueiable.
|
||||
base: GlobalValue,
|
||||
|
||||
/// 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,
|
||||
|
||||
/// Will this variable be defined nearby, such that it will always be a certain distance
|
||||
/// away, after linking? If so, references to it can avoid going through a GOT. Note that
|
||||
/// symbols meant to be preemptible cannot be colocated.
|
||||
colocated: bool,
|
||||
},
|
||||
}
|
||||
|
||||
impl GlobalValueData {
|
||||
/// Assume that `self` is an `GlobalValueData::Sym` and return its name.
|
||||
pub fn symbol_name(&self) -> &ExternalName {
|
||||
match *self {
|
||||
GlobalValueData::Sym { ref name, .. } => name,
|
||||
_ => panic!("only symbols have names"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for GlobalValueData {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
GlobalValueData::VMContext { offset } => write!(f, "vmctx{}", offset),
|
||||
GlobalValueData::Deref { base, offset } => write!(f, "deref({}){}", base, offset),
|
||||
GlobalValueData::Sym {
|
||||
ref name,
|
||||
colocated,
|
||||
} => {
|
||||
if colocated {
|
||||
write!(f, "colocated ")?;
|
||||
}
|
||||
write!(f, "globalsym {}", name)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
//! Global variables.
|
||||
|
||||
use ir::immediates::Offset32;
|
||||
use ir::{ExternalName, GlobalVar};
|
||||
use ir::{ExternalName, GlobalValue};
|
||||
use std::fmt;
|
||||
|
||||
/// Information about a global variable declaration.
|
||||
/// Information about a global valueiable declaration.
|
||||
#[derive(Clone)]
|
||||
pub enum GlobalVarData {
|
||||
pub enum GlobalValueData {
|
||||
/// Variable is part of the VM context struct, it's address is a constant offset from the VM
|
||||
/// context pointer.
|
||||
VMContext {
|
||||
@@ -14,14 +14,14 @@ pub enum GlobalVarData {
|
||||
offset: Offset32,
|
||||
},
|
||||
|
||||
/// Variable is part of a struct pointed to by another global variable.
|
||||
/// Variable is part of a struct pointed to by another global valueiable.
|
||||
///
|
||||
/// The `base` global variable is assumed to contain a pointer to a struct. This global
|
||||
/// The `base` global valueiable is assumed to contain a pointer to a struct. This global
|
||||
/// variable lives at an offset into the struct. The memory must be accessible, and
|
||||
/// naturally aligned to hold a pointer value.
|
||||
Deref {
|
||||
/// The base pointer global variable.
|
||||
base: GlobalVar,
|
||||
/// The base pointer global valueiable.
|
||||
base: GlobalValue,
|
||||
|
||||
/// Byte offset to be added to the pointer loaded from `base`.
|
||||
offset: Offset32,
|
||||
@@ -41,22 +41,22 @@ pub enum GlobalVarData {
|
||||
},
|
||||
}
|
||||
|
||||
impl GlobalVarData {
|
||||
/// Assume that `self` is an `GlobalVarData::Sym` and return its name.
|
||||
impl GlobalValueData {
|
||||
/// Assume that `self` is an `GlobalValueData::Sym` and return its name.
|
||||
pub fn symbol_name(&self) -> &ExternalName {
|
||||
match *self {
|
||||
GlobalVarData::Sym { ref name, .. } => name,
|
||||
GlobalValueData::Sym { ref name, .. } => name,
|
||||
_ => panic!("only symbols have names"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for GlobalVarData {
|
||||
impl fmt::Display for GlobalValueData {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
GlobalVarData::VMContext { offset } => write!(f, "vmctx{}", offset),
|
||||
GlobalVarData::Deref { base, offset } => write!(f, "deref({}){}", base, offset),
|
||||
GlobalVarData::Sym {
|
||||
GlobalValueData::VMContext { offset } => write!(f, "vmctx{}", offset),
|
||||
GlobalValueData::Deref { base, offset } => write!(f, "deref({}){}", base, offset),
|
||||
GlobalValueData::Sym {
|
||||
ref name,
|
||||
colocated,
|
||||
} => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//! Heaps.
|
||||
|
||||
use ir::immediates::Imm64;
|
||||
use ir::GlobalVar;
|
||||
use ir::GlobalValue;
|
||||
use std::fmt;
|
||||
|
||||
/// Information about a heap declaration.
|
||||
@@ -29,9 +29,9 @@ pub enum HeapBase {
|
||||
/// This feature is not yet implemented.
|
||||
ReservedReg,
|
||||
|
||||
/// The heap base is in a global variable. The variable must be accessible and naturally
|
||||
/// The heap base is in a global valueiable. The variable must be accessible and naturally
|
||||
/// aligned for a pointer.
|
||||
GlobalVar(GlobalVar),
|
||||
GlobalValue(GlobalValue),
|
||||
}
|
||||
|
||||
/// Style of heap including style-specific information.
|
||||
@@ -41,7 +41,7 @@ pub enum HeapStyle {
|
||||
Dynamic {
|
||||
/// Global variable holding the current bound of the heap in bytes. It is
|
||||
/// required to be accessible and naturally aligned for a pointer-sized integer.
|
||||
bound_gv: GlobalVar,
|
||||
bound_gv: GlobalValue,
|
||||
},
|
||||
|
||||
/// A static heap has a fixed base address and a number of not-yet-allocated pages before the
|
||||
@@ -61,7 +61,7 @@ impl fmt::Display for HeapData {
|
||||
|
||||
match self.base {
|
||||
HeapBase::ReservedReg => write!(f, " reserved_reg")?,
|
||||
HeapBase::GlobalVar(gv) => write!(f, " {}", gv)?,
|
||||
HeapBase::GlobalValue(gv) => write!(f, " {}", gv)?,
|
||||
}
|
||||
|
||||
write!(f, ", min {}", self.min_size)?;
|
||||
|
||||
@@ -7,7 +7,7 @@ pub mod entities;
|
||||
mod extfunc;
|
||||
mod extname;
|
||||
pub mod function;
|
||||
mod globalvar;
|
||||
mod globalvalue;
|
||||
mod heap;
|
||||
pub mod immediates;
|
||||
pub mod instructions;
|
||||
@@ -24,11 +24,11 @@ mod valueloc;
|
||||
|
||||
pub use ir::builder::{InsertBuilder, InstBuilder, InstBuilderBase, InstInserterBase};
|
||||
pub use ir::dfg::{DataFlowGraph, ValueDef};
|
||||
pub use ir::entities::{Ebb, FuncRef, GlobalVar, Heap, Inst, JumpTable, SigRef, StackSlot, Value};
|
||||
pub use ir::entities::{Ebb, FuncRef, GlobalValue, Heap, Inst, JumpTable, SigRef, StackSlot, Value};
|
||||
pub use ir::extfunc::{AbiParam, ArgumentExtension, ArgumentPurpose, ExtFuncData, Signature};
|
||||
pub use ir::extname::ExternalName;
|
||||
pub use ir::function::Function;
|
||||
pub use ir::globalvar::GlobalVarData;
|
||||
pub use ir::globalvalue::GlobalValueData;
|
||||
pub use ir::heap::{HeapBase, HeapData, HeapStyle};
|
||||
pub use ir::instructions::{InstructionData, Opcode, ValueList, ValueListPool, VariableArgs};
|
||||
pub use ir::jumptable::JumpTableData;
|
||||
|
||||
Reference in New Issue
Block a user