Move lvalue data structures out of eval_context.
This commit is contained in:
parent
4702d97093
commit
fe19a014ff
6 changed files with 82 additions and 67 deletions
|
@ -13,6 +13,7 @@ use rustc_data_structures::indexed_vec::Idx;
|
||||||
use syntax::codemap::{self, DUMMY_SP};
|
use syntax::codemap::{self, DUMMY_SP};
|
||||||
|
|
||||||
use error::{EvalError, EvalResult};
|
use error::{EvalError, EvalResult};
|
||||||
|
use lvalue::{Global, GlobalId, Lvalue, LvalueExtra};
|
||||||
use memory::{Memory, Pointer};
|
use memory::{Memory, Pointer};
|
||||||
use primval::{self, PrimVal, PrimValKind};
|
use primval::{self, PrimVal, PrimValKind};
|
||||||
|
|
||||||
|
@ -96,67 +97,6 @@ pub struct Frame<'tcx> {
|
||||||
pub stmt: usize,
|
pub stmt: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
|
||||||
pub enum Lvalue<'tcx> {
|
|
||||||
/// An lvalue referring to a value allocated in the `Memory` system.
|
|
||||||
Ptr {
|
|
||||||
ptr: Pointer,
|
|
||||||
extra: LvalueExtra,
|
|
||||||
},
|
|
||||||
|
|
||||||
/// An lvalue referring to a value on the stack. Represented by a stack frame index paired with
|
|
||||||
/// a Mir local index.
|
|
||||||
Local {
|
|
||||||
frame: usize,
|
|
||||||
local: mir::Local,
|
|
||||||
},
|
|
||||||
|
|
||||||
Global(GlobalId<'tcx>),
|
|
||||||
|
|
||||||
// TODO(solson): None/Never?
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
|
||||||
pub enum LvalueExtra {
|
|
||||||
None,
|
|
||||||
Length(u64),
|
|
||||||
Vtable(Pointer),
|
|
||||||
DowncastVariant(usize),
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
|
|
||||||
/// Uniquely identifies a specific constant or static
|
|
||||||
pub struct GlobalId<'tcx> {
|
|
||||||
/// the def id of the constant/static or in case of promoteds, the def id of the function they belong to
|
|
||||||
pub(super) def_id: DefId,
|
|
||||||
|
|
||||||
/// In case of statics and constants this is `Substs::empty()`, so only promoteds and associated
|
|
||||||
/// constants actually have something useful here. We could special case statics and constants,
|
|
||||||
/// but that would only require more branching when working with constants, and not bring any
|
|
||||||
/// real benefits.
|
|
||||||
pub(super) substs: &'tcx Substs<'tcx>,
|
|
||||||
|
|
||||||
/// The promoted index for this global, if it is a promoted.
|
|
||||||
pub(super) promoted: Option<mir::Promoted>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug)]
|
|
||||||
pub struct Global<'tcx> {
|
|
||||||
data: Option<Value>,
|
|
||||||
mutable: bool,
|
|
||||||
ty: Ty<'tcx>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'tcx> Global<'tcx> {
|
|
||||||
pub(super) fn uninitialized(ty: Ty<'tcx>) -> Self {
|
|
||||||
Global {
|
|
||||||
data: None,
|
|
||||||
mutable: true,
|
|
||||||
ty: ty,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
|
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
|
||||||
pub enum StackPopCleanup {
|
pub enum StackPopCleanup {
|
||||||
/// The stackframe existed to compute the initial value of a static/constant, make sure it
|
/// The stackframe existed to compute the initial value of a static/constant, make sure it
|
||||||
|
|
|
@ -25,6 +25,7 @@ extern crate byteorder;
|
||||||
mod cast;
|
mod cast;
|
||||||
mod error;
|
mod error;
|
||||||
mod eval_context;
|
mod eval_context;
|
||||||
|
mod lvalue;
|
||||||
mod memory;
|
mod memory;
|
||||||
mod primval;
|
mod primval;
|
||||||
mod step;
|
mod step;
|
||||||
|
@ -32,7 +33,6 @@ mod terminator;
|
||||||
mod value;
|
mod value;
|
||||||
mod vtable;
|
mod vtable;
|
||||||
|
|
||||||
|
|
||||||
pub use error::{
|
pub use error::{
|
||||||
EvalError,
|
EvalError,
|
||||||
EvalResult,
|
EvalResult,
|
||||||
|
@ -41,8 +41,6 @@ pub use error::{
|
||||||
pub use eval_context::{
|
pub use eval_context::{
|
||||||
EvalContext,
|
EvalContext,
|
||||||
Frame,
|
Frame,
|
||||||
Lvalue,
|
|
||||||
LvalueExtra,
|
|
||||||
ResourceLimits,
|
ResourceLimits,
|
||||||
StackPopCleanup,
|
StackPopCleanup,
|
||||||
Value,
|
Value,
|
||||||
|
@ -50,6 +48,11 @@ pub use eval_context::{
|
||||||
run_mir_passes,
|
run_mir_passes,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub use lvalue::{
|
||||||
|
Lvalue,
|
||||||
|
LvalueExtra,
|
||||||
|
};
|
||||||
|
|
||||||
pub use memory::{
|
pub use memory::{
|
||||||
Memory,
|
Memory,
|
||||||
Pointer,
|
Pointer,
|
||||||
|
|
69
src/lvalue.rs
Normal file
69
src/lvalue.rs
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
use rustc::hir::def_id::DefId;
|
||||||
|
use rustc::mir;
|
||||||
|
use rustc::ty::Ty;
|
||||||
|
use rustc::ty::subst::Substs;
|
||||||
|
|
||||||
|
use memory::Pointer;
|
||||||
|
use eval_context::Value;
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
||||||
|
pub enum Lvalue<'tcx> {
|
||||||
|
/// An lvalue referring to a value allocated in the `Memory` system.
|
||||||
|
Ptr {
|
||||||
|
ptr: Pointer,
|
||||||
|
extra: LvalueExtra,
|
||||||
|
},
|
||||||
|
|
||||||
|
/// An lvalue referring to a value on the stack. Represented by a stack frame index paired with
|
||||||
|
/// a Mir local index.
|
||||||
|
Local {
|
||||||
|
frame: usize,
|
||||||
|
local: mir::Local,
|
||||||
|
},
|
||||||
|
|
||||||
|
/// An lvalue referring to a global
|
||||||
|
Global(GlobalId<'tcx>),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
||||||
|
pub enum LvalueExtra {
|
||||||
|
None,
|
||||||
|
Length(u64),
|
||||||
|
Vtable(Pointer),
|
||||||
|
DowncastVariant(usize),
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Uniquely identifies a specific constant or static.
|
||||||
|
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
|
||||||
|
pub struct GlobalId<'tcx> {
|
||||||
|
/// For a constant or static, the `DefId` of the item itself.
|
||||||
|
/// For a promoted global, the `DefId` of the function they belong to.
|
||||||
|
pub(super) def_id: DefId,
|
||||||
|
|
||||||
|
/// For statics and constants this is `Substs::empty()`, so only promoteds and associated
|
||||||
|
/// constants actually have something useful here. We could special case statics and constants,
|
||||||
|
/// but that would only require more branching when working with constants, and not bring any
|
||||||
|
/// real benefits.
|
||||||
|
pub(super) substs: &'tcx Substs<'tcx>,
|
||||||
|
|
||||||
|
/// The index for promoted globals within their function's `Mir`.
|
||||||
|
pub(super) promoted: Option<mir::Promoted>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug)]
|
||||||
|
pub struct Global<'tcx> {
|
||||||
|
pub(super) data: Option<Value>,
|
||||||
|
pub(super) mutable: bool,
|
||||||
|
pub(super) ty: Ty<'tcx>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'tcx> Global<'tcx> {
|
||||||
|
pub(super) fn uninitialized(ty: Ty<'tcx>) -> Self {
|
||||||
|
Global {
|
||||||
|
data: None,
|
||||||
|
mutable: true,
|
||||||
|
ty: ty,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -11,7 +11,8 @@ use rustc::mir;
|
||||||
use rustc::ty::{subst, self};
|
use rustc::ty::{subst, self};
|
||||||
|
|
||||||
use error::{EvalResult, EvalError};
|
use error::{EvalResult, EvalError};
|
||||||
use eval_context::{GlobalId, EvalContext, Lvalue, StackPopCleanup, Global, MirRef};
|
use eval_context::{EvalContext, StackPopCleanup, MirRef};
|
||||||
|
use lvalue::{Global, GlobalId, Lvalue};
|
||||||
use syntax::codemap::Span;
|
use syntax::codemap::Span;
|
||||||
|
|
||||||
impl<'a, 'tcx> EvalContext<'a, 'tcx> {
|
impl<'a, 'tcx> EvalContext<'a, 'tcx> {
|
||||||
|
|
|
@ -5,7 +5,8 @@ use rustc::ty::subst::Substs;
|
||||||
use rustc::ty::{self, Ty};
|
use rustc::ty::{self, Ty};
|
||||||
|
|
||||||
use error::{EvalError, EvalResult};
|
use error::{EvalError, EvalResult};
|
||||||
use eval_context::{EvalContext, Lvalue, LvalueExtra};
|
use eval_context::EvalContext;
|
||||||
|
use lvalue::{Lvalue, LvalueExtra};
|
||||||
use primval::{self, PrimVal, PrimValKind};
|
use primval::{self, PrimVal, PrimValKind};
|
||||||
use value::Value;
|
use value::Value;
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,8 @@ use syntax::codemap::{DUMMY_SP, Span};
|
||||||
use syntax::{ast, attr};
|
use syntax::{ast, attr};
|
||||||
|
|
||||||
use error::{EvalError, EvalResult};
|
use error::{EvalError, EvalResult};
|
||||||
use eval_context::{EvalContext, Lvalue, IntegerExt, StackPopCleanup, LvalueExtra, monomorphize_field_ty};
|
use eval_context::{EvalContext, IntegerExt, StackPopCleanup, monomorphize_field_ty};
|
||||||
|
use lvalue::{Lvalue, LvalueExtra};
|
||||||
use memory::Pointer;
|
use memory::Pointer;
|
||||||
use primval::PrimVal;
|
use primval::PrimVal;
|
||||||
use value::Value;
|
use value::Value;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue