Split up miri into the librustc_mir and bin parts

This commit is contained in:
Oliver Schneider 2017-07-21 13:39:06 +02:00
parent 6d3c88c061
commit 11e30a65e6
No known key found for this signature in database
GPG Key ID: A69F8D225B3AD7D9
25 changed files with 248 additions and 168 deletions

View File

@ -15,10 +15,10 @@ script:
xargo/build.sh
- |
# Test plain miri
cd src/librustc_mir/ && cargo build &&
cd miri/ && cargo build &&
cargo test &&
cargo install &&
cd ../..
cd ..
- |
# Test cargo miri
cd cargo-miri-test &&
@ -27,7 +27,7 @@ script:
cd ..
- |
# and run all tests with full mir
cd src/librustc_mir/ && MIRI_SYSROOT=~/.xargo/HOST cargo test && cd ../..
cd miri/ && MIRI_SYSROOT=~/.xargo/HOST cargo test && cd ..
notifications:
email:
on_success: never

76
Cargo.lock generated
View File

@ -1,13 +1,10 @@
[root]
name = "miri"
name = "rustc_miri"
version = "0.1.0"
dependencies = [
"byteorder 1.0.0 (git+https://github.com/BurntSushi/byteorder)",
"cargo_metadata 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"compiletest_rs 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
"env_logger 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
"byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
"log_settings 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -30,16 +27,16 @@ dependencies = [
[[package]]
name = "byteorder"
version = "1.0.0"
source = "git+https://github.com/BurntSushi/byteorder#f8e7685b3a81c52f5448fd77fb4e0535bc92f880"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "cargo_metadata"
version = "0.2.1"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"serde 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -48,7 +45,7 @@ name = "compiletest_rs"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -62,7 +59,7 @@ name = "env_logger"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 0.1.80 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -87,12 +84,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "libc"
version = "0.2.22"
version = "0.2.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "log"
version = "0.3.7"
version = "0.3.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
@ -108,7 +105,7 @@ name = "memchr"
version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.26 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -116,12 +113,25 @@ name = "memchr"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.26 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "miri"
version = "0.1.0"
dependencies = [
"byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cargo_metadata 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"compiletest_rs 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
"env_logger 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
"log_settings 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc_miri 0.1.0",
]
[[package]]
name = "num-traits"
version = "0.1.37"
version = "0.1.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
@ -170,22 +180,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "serde"
version = "1.0.2"
version = "1.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "serde_derive"
version = "1.0.2"
version = "1.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive_internals 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive_internals 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "serde_derive_internals"
version = "0.15.0"
version = "0.15.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)",
@ -199,8 +209,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"dtoa 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"itoa 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"num-traits 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -227,7 +237,7 @@ version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.26 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -288,29 +298,29 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[metadata]
"checksum aho-corasick 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ca972c2ea5f742bfce5687b9aef75506a764f61d37f8f649047846a9686ddb66"
"checksum aho-corasick 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "500909c4f87a9e52355b26626d890833e9e1d53ac566db76c36faa984b889699"
"checksum byteorder 1.0.0 (git+https://github.com/BurntSushi/byteorder)" = "<none>"
"checksum cargo_metadata 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5d84cb53c78e573aa126a4b9f963fdb2629f8183b26e235da08bb36dc7381162"
"checksum byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff81738b726f5d099632ceaffe7fb65b90212e8dce59d518729e7e8634032d3d"
"checksum cargo_metadata 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "be1057b8462184f634c3a208ee35b0f935cfd94b694b26deadccd98732088d7b"
"checksum compiletest_rs 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "617b23d0ed4f57b3bcff6b5fe0a78f0010f1efb636298317665a960b6dbc0533"
"checksum dtoa 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "80c8b71fd71146990a9742fc06dcbbde19161a267e0ad4e572c35162f4578c90"
"checksum env_logger 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "15abd780e45b3ea4f76b4e9a26ff4843258dd8a3eed2775a0e7368c2e7936c2f"
"checksum itoa 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "eb2f404fbc66fd9aac13e998248505e7ecb2ad8e44ab6388684c5fb11c6c251c"
"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
"checksum lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3b37545ab726dd833ec6420aaba8231c5b320814b9029ad585555d2a03e94fbf"
"checksum libc 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)" = "babb8281da88cba992fa1f4ddec7d63ed96280a1a53ec9b919fd37b53d71e502"
"checksum log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "5141eca02775a762cc6cd564d8d2c50f67c0ea3a372cbf1c51592b3e029e10ad"
"checksum libc 0.2.26 (registry+https://github.com/rust-lang/crates.io-index)" = "30885bcb161cf67054244d10d4a7f4835ffd58773bc72e07d35fecf472295503"
"checksum log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "880f77541efa6e5cc74e76910c9884d9859683118839d6a1dc3b11e63512565b"
"checksum log_settings 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3d382732ea0fbc09790c4899db3255bdea0fc78b54bf234bd18a63bb603915b6"
"checksum memchr 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d8b629fb514376c675b98c1421e80b151d3817ac42d7c667717d282761418d20"
"checksum memchr 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1dbccc0e46f1ea47b9f17e6d67c5a96bd27030519c519c9c91327e31275a47b4"
"checksum num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "e1cbfa3781f3fe73dc05321bed52a06d2d491eaa764c52335cf4399f046ece99"
"checksum num-traits 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "99843c856d68d8b4313b03a17e33c4bb42ae8f6610ea81b28abe076ac721b9b0"
"checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a"
"checksum regex 0.1.80 (registry+https://github.com/rust-lang/crates.io-index)" = "4fd4ace6a8cf7860714a2c2280d6c1f7e6a413486c13298bbc86fd3da019402f"
"checksum regex 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1731164734096285ec2a5ec7fea5248ae2f5485b3feeb0115af4fda2183b2d1b"
"checksum regex-syntax 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "f9ec002c35e86791825ed294b50008eea9ddfc8def4420124fbc6b08db834957"
"checksum regex-syntax 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ad890a5eef7953f55427c50575c680c42841653abd2b028b68cd223d157f62db"
"checksum rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)" = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda"
"checksum serde 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3b46a59dd63931010fdb1d88538513f3279090d88b5c22ef4fe8440cfffcc6e3"
"checksum serde_derive 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6c06b68790963518008b8ae0152d48be4bbbe77015d2c717f6282eea1824be9a"
"checksum serde_derive_internals 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "021c338d22c7e30f957a6ab7e388cb6098499dda9fd4ba1661ee074ca7a180d1"
"checksum serde 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)" = "433d7d9f8530d5a939ad5e0e72a6243d2e42a24804f70bf592c679363dcacb2f"
"checksum serde_derive 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)" = "7b707cf0d4cab852084f573058def08879bb467fda89d99052485e7d00edd624"
"checksum serde_derive_internals 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)" = "37aee4e0da52d801acfbc0cc219eb1eda7142112339726e427926a6f6ee65d3a"
"checksum serde_json 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "48b04779552e92037212c3615370f6bd57a40ebba7f20e554ff9f55e41a69a7b"
"checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad"
"checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6"

37
Cargo.toml Normal file
View File

@ -0,0 +1,37 @@
[package]
authors = ["Scott Olson <scott@solson.me>"]
description = "An experimental interpreter for Rust MIR."
license = "MIT/Apache-2.0"
name = "miri"
repository = "https://github.com/solson/miri"
version = "0.1.0"
[[bin]]
doc = false
name = "miri"
test = false
path = "miri/bin/miri.rs"
[[bin]]
doc = false
name = "cargo-miri"
test = false
path = "miri/bin/cargo-miri.rs"
[lib]
test = false
path = "miri/lib.rs"
[dependencies]
byteorder = { version = "1.1", features = ["i128"]}
env_logger = "0.3.3"
log = "0.3.6"
log_settings = "0.1.1"
cargo_metadata = "0.2"
rustc_miri = { path = "src/librustc_mir" }
[dev-dependencies]
compiletest_rs = "0.2.6"
[workspace]
members = ["src/librustc_mir"]

3
miri/lib.rs Normal file
View File

@ -0,0 +1,3 @@
extern crate rustc_miri;
pub use rustc_miri::interpret::*;

View File

@ -4,4 +4,4 @@ version = "0.1.0"
authors = ["Oliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>"]
[dependencies]
miri = { path = ".." }
miri = { path = "../miri" }

View File

@ -2,38 +2,17 @@
authors = ["Scott Olson <scott@solson.me>"]
description = "An experimental interpreter for Rust MIR."
license = "MIT/Apache-2.0"
name = "miri"
name = "rustc_miri"
repository = "https://github.com/solson/miri"
version = "0.1.0"
[[bin]]
doc = false
name = "miri"
path = "interpret/bin/miri.rs"
test = false
[[bin]]
doc = false
name = "cargo-miri"
path = "interpret/bin/cargo-miri.rs"
test = false
[lib]
test = false
path = "interpret/mod.rs"
[[test]]
name = "compiletest"
path = "../../tests/compiletest.rs"
path = "lib.rs"
[dependencies]
byteorder = { version = "1.1", features = ["i128"]}
env_logger = "0.3.3"
log = "0.3.6"
log_settings = "0.1.1"
cargo_metadata = "0.2"
regex = "0.2.2"
lazy_static = "0.2.8"
[dev-dependencies]
compiletest_rs = "0.2.6"
regex = "0.2.2"

View File

@ -1,10 +1,13 @@
use rustc::ty::{self, Ty};
use syntax::ast::{FloatTy, IntTy, UintTy};
use error::{EvalResult, EvalError};
use eval_context::EvalContext;
use value::PrimVal;
use memory::{MemoryPointer, PointerArithmetic};
use super::{
PrimVal,
EvalContext,
EvalResult,
EvalError,
MemoryPointer, PointerArithmetic,
};
impl<'a, 'tcx> EvalContext<'a, 'tcx> {
pub(super) fn cast_primval(
@ -19,7 +22,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
PrimVal::Undef => Ok(PrimVal::Undef),
PrimVal::Ptr(ptr) => self.cast_from_ptr(ptr, dest_ty),
val @ PrimVal::Bytes(_) => {
use value::PrimValKind::*;
use super::PrimValKind::*;
match src_kind {
F32 => self.cast_from_float(val.to_f32()? as f64, dest_ty),
F64 => self.cast_from_float(val.to_f64()?, dest_ty),

View File

@ -2,17 +2,20 @@ use rustc::traits::Reveal;
use rustc::ty::{self, TyCtxt, Ty, Instance};
use syntax::ast::Mutability;
use error::{EvalError, EvalResult};
use lvalue::{Global, GlobalId, Lvalue};
use value::PrimVal;
use super::{
EvalError, EvalResult,
Global, GlobalId, Lvalue,
PrimVal,
EvalContext, StackPopCleanup,
};
use rustc_const_math::ConstInt;
use eval_context::{EvalContext, StackPopCleanup};
pub fn eval_body_as_primval<'a, 'tcx>(
tcx: TyCtxt<'a, 'tcx, 'tcx>,
instance: Instance<'tcx>,
) -> EvalResult<'tcx, (PrimVal, Ty<'tcx>)> {
let limits = ::ResourceLimits::default();
let limits = super::ResourceLimits::default();
let mut ecx = EvalContext::new(tcx, limits);
let cid = GlobalId { instance, promoted: None };
if ecx.tcx.has_attr(instance.def_id(), "linkage") {

View File

@ -2,7 +2,11 @@ use std::error::Error;
use std::fmt;
use rustc::mir;
use rustc::ty::{FnSig, Ty, layout};
use memory::{MemoryPointer, LockInfo, AccessKind, Kind};
use super::{
MemoryPointer, Kind, LockInfo, AccessKind
};
use rustc_const_math::ConstMathErr;
use syntax::codemap::Span;
@ -101,7 +105,7 @@ pub type EvalResult<'tcx, T = ()> = Result<T, EvalError<'tcx>>;
impl<'tcx> Error for EvalError<'tcx> {
fn description(&self) -> &str {
use EvalError::*;
use self::EvalError::*;
match *self {
FunctionPointerTyMismatch(..) =>
"tried to call a function through a function pointer of a different type",
@ -223,7 +227,7 @@ impl<'tcx> Error for EvalError<'tcx> {
impl<'tcx> fmt::Display for EvalError<'tcx> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use EvalError::*;
use self::EvalError::*;
match *self {
PointerOutOfBounds { ptr, access, allocation_size } => {
write!(f, "{} at offset {}, outside bounds of allocation {} which has size {}",

View File

@ -16,13 +16,15 @@ use syntax::codemap::{self, DUMMY_SP, Span};
use syntax::ast::{self, Mutability};
use syntax::abi::Abi;
use error::{EvalError, EvalResult};
use lvalue::{Global, GlobalId, Lvalue, LvalueExtra};
use memory::{Memory, MemoryPointer, TlsKey, HasMemory};
use memory::Kind as MemoryKind;
use operator;
use value::{PrimVal, PrimValKind, Value, Pointer};
use validation::ValidationQuery;
use super::{
EvalError, EvalResult,
Global, GlobalId, Lvalue, LvalueExtra,
Memory, MemoryPointer, TlsKey, HasMemory,
Kind as MemoryKind,
operator,
PrimVal, PrimValKind, Value, Pointer,
ValidationQuery,
};
pub struct EvalContext<'a, 'tcx: 'a> {
/// The results of the type checker, from rustc.

View File

@ -4,10 +4,12 @@ use rustc::ty::{self, Ty};
use rustc_data_structures::indexed_vec::Idx;
use syntax::ast::Mutability;
use error::{EvalError, EvalResult};
use eval_context::EvalContext;
use memory::MemoryPointer;
use value::{PrimVal, Pointer, Value};
use super::{
EvalError, EvalResult,
EvalContext,
MemoryPointer,
PrimVal, Value, Pointer,
};
#[derive(Copy, Clone, Debug)]
pub enum Lvalue<'tcx> {

View File

@ -8,9 +8,11 @@ use rustc::ty::layout::{self, TargetDataLayout, HasDataLayout};
use syntax::ast::Mutability;
use rustc::middle::region::CodeExtent;
use error::{EvalError, EvalResult};
use value::{PrimVal, Pointer};
use eval_context::{EvalContext, DynamicLifetime};
use super::{
EvalError, EvalResult,
PrimVal, Pointer,
EvalContext, DynamicLifetime,
};
////////////////////////////////////////////////////////////////////////////////
// Locks

View File

@ -1,25 +1,3 @@
#![feature(
i128_type,
rustc_private,
conservative_impl_trait,
)]
// From rustc.
#[macro_use]
extern crate log;
extern crate log_settings;
#[macro_use]
extern crate rustc;
extern crate rustc_const_math;
extern crate rustc_data_structures;
extern crate syntax;
// From crates.io.
extern crate byteorder;
#[macro_use]
extern crate lazy_static;
extern crate regex;
mod cast;
mod const_eval;
mod error;
@ -33,37 +11,54 @@ mod terminator;
mod traits;
mod value;
pub use error::{
pub use self::error::{
EvalError,
EvalResult,
};
pub use eval_context::{
pub use self::eval_context::{
EvalContext,
Frame,
ResourceLimits,
StackPopCleanup,
eval_main,
DynamicLifetime,
TyAndPacked,
};
pub use lvalue::{
pub use self::lvalue::{
Lvalue,
LvalueExtra,
Global,
GlobalId,
};
pub use memory::{
pub use self::memory::{
AllocId,
Memory,
MemoryPointer,
Kind,
TlsKey,
};
pub use value::{
use self::memory::{
HasMemory,
PointerArithmetic,
LockInfo,
AccessKind,
};
pub use self::value::{
PrimVal,
PrimValKind,
Value,
Pointer,
};
pub use const_eval::{
pub use self::const_eval::{
eval_body_as_integer,
};
pub use self::validation::{
ValidationQuery,
};

View File

@ -1,11 +1,14 @@
use rustc::mir;
use rustc::ty::{self, Ty};
use error::{EvalError, EvalResult};
use eval_context::EvalContext;
use memory::MemoryPointer;
use lvalue::Lvalue;
use value::{
use super::{
EvalError, EvalResult,
EvalContext,
MemoryPointer,
Lvalue,
};
use super::value::{
PrimVal,
PrimValKind,
Value,
@ -72,7 +75,7 @@ macro_rules! int_arithmetic {
($kind:expr, $int_op:ident, $l:expr, $r:expr) => ({
let l = $l;
let r = $r;
use value::PrimValKind::*;
use super::PrimValKind::*;
match $kind {
I8 => overflow!($int_op, l as i8, r as i8),
I16 => overflow!($int_op, l as i16, r as i16),
@ -142,7 +145,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
right_ty: Ty<'tcx>,
) -> EvalResult<'tcx, (PrimVal, bool)> {
use rustc::mir::BinOp::*;
use value::PrimValKind::*;
use super::PrimValKind::*;
let left_kind = self.ty_to_primval_kind(left_ty)?;
let right_kind = self.ty_to_primval_kind(right_ty)?;
@ -344,7 +347,7 @@ pub fn unary_op<'tcx>(
val_kind: PrimValKind,
) -> EvalResult<'tcx, PrimVal> {
use rustc::mir::UnOp::*;
use value::PrimValKind::*;
use super::PrimValKind::*;
let bytes = val.to_bytes()?;

View File

@ -11,15 +11,17 @@ use rustc::ty;
use rustc::ty::layout::Layout;
use rustc::ty::subst::Substs;
use super::{
EvalResult, EvalError,
EvalContext, StackPopCleanup, TyAndPacked,
Global, GlobalId, Lvalue,
Value, PrimVal,
HasMemory,
};
use syntax::codemap::Span;
use syntax::ast::Mutability;
use error::{EvalResult, EvalError};
use eval_context::{EvalContext, StackPopCleanup, TyAndPacked};
use lvalue::{Global, GlobalId, Lvalue};
use value::{Value, PrimVal};
use memory::HasMemory;
impl<'a, 'tcx> EvalContext<'a, 'tcx> {
pub fn inc_step_counter_and_check_limit(&mut self, n: u64) -> EvalResult<'tcx> {
self.steps_remaining = self.steps_remaining.saturating_sub(n);

View File

@ -2,11 +2,12 @@ use rustc::mir;
use rustc::ty::{self, Ty};
use syntax::codemap::Span;
use error::EvalResult;
use eval_context::{EvalContext, StackPopCleanup};
use lvalue::{Lvalue, LvalueExtra};
use value::PrimVal;
use value::Value;
use interpret::{
EvalResult,
EvalContext, StackPopCleanup,
Lvalue, LvalueExtra,
PrimVal, Value,
};
impl<'a, 'tcx> EvalContext<'a, 'tcx> {
pub(crate) fn drop_lvalue(&mut self, lval: Lvalue<'tcx>, instance: ty::Instance<'tcx>, ty: Ty<'tcx>, span: Span) -> EvalResult<'tcx> {

View File

@ -4,11 +4,13 @@ use rustc::ty::layout::{Layout, Size, Align};
use rustc::ty::subst::Substs;
use rustc::ty::{self, Ty};
use error::{EvalError, EvalResult};
use eval_context::EvalContext;
use lvalue::{Lvalue, LvalueExtra};
use value::{PrimVal, PrimValKind, Value, Pointer};
use memory::HasMemory;
use interpret::{
EvalError, EvalResult,
EvalContext,
Lvalue, LvalueExtra,
PrimVal, PrimValKind, Value, Pointer,
HasMemory,
};
impl<'a, 'tcx> EvalContext<'a, 'tcx> {
pub(super) fn call_intrinsic(
@ -584,7 +586,7 @@ fn numeric_intrinsic<'tcx>(
) -> EvalResult<'tcx, PrimVal> {
macro_rules! integer_intrinsic {
($method:ident) => ({
use value::PrimValKind::*;
use interpret::PrimValKind::*;
let result_bytes = match kind {
I8 => (bytes as i8).$method() as u128,
U8 => (bytes as u8).$method() as u128,

View File

@ -6,13 +6,18 @@ use syntax::codemap::Span;
use syntax::attr;
use syntax::abi::Abi;
use error::{EvalError, EvalResult};
use eval_context::{EvalContext, IntegerExt, StackPopCleanup, TyAndPacked, is_inhabited, self};
use lvalue::Lvalue;
use memory::{MemoryPointer, TlsKey, Kind, HasMemory};
use value::{PrimVal, Value};
use super::{
EvalError, EvalResult,
EvalContext, StackPopCleanup, eval_context, TyAndPacked,
Lvalue, GlobalId,
MemoryPointer, TlsKey, Kind,
PrimVal, Value,
const_eval,
HasMemory,
};
use super::eval_context::IntegerExt;
use rustc_data_structures::indexed_vec::Idx;
use const_eval;
use std::mem;
@ -221,7 +226,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
_ => return Err(EvalError::Unreachable),
};
let ty = sig.output();
if !is_inhabited(self.tcx, ty) {
if !eval_context::is_inhabited(self.tcx, ty) {
return Err(EvalError::Unreachable);
}
let layout = self.type_layout(ty)?;
@ -867,7 +872,6 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
let mut result = None;
for &(path, path_value) in paths {
if let Ok(instance) = self.resolve_path(path) {
use lvalue::GlobalId;
let cid = GlobalId { instance, promoted: None };
// compute global if not cached
let val = match self.globals.get(&cid).map(|glob| glob.value) {

View File

@ -1,16 +1,16 @@
use rustc::traits::{self, Reveal};
use eval_context::{EvalContext, self};
use memory::{MemoryPointer, Kind};
use value::{Value, PrimVal};
use rustc::hir::def_id::DefId;
use rustc::ty::subst::Substs;
use rustc::ty::{self, Ty};
use syntax::codemap::DUMMY_SP;
use syntax::ast::{self, Mutability};
use error::{EvalResult, EvalError};
use super::{
EvalResult, EvalError,
EvalContext, eval_context,
MemoryPointer, Kind,
Value, PrimVal,
};
impl<'a, 'tcx> EvalContext<'a, 'tcx> {

View File

@ -10,11 +10,13 @@ use rustc::traits::Reveal;
use rustc::infer::TransNormalize;
use rustc::middle::region::CodeExtent;
use error::{EvalError, EvalResult};
use eval_context::{EvalContext, DynamicLifetime};
use memory::{AccessKind, LockInfo};
use value::{PrimVal, Value};
use lvalue::{Lvalue, LvalueExtra};
use super::{
EvalError, EvalResult,
EvalContext, DynamicLifetime,
AccessKind, LockInfo,
PrimVal, Value,
Lvalue, LvalueExtra,
};
// FIXME remove this once it lands in rustc
#[derive(Copy, Clone, PartialEq, Eq)]

View File

@ -1,10 +1,13 @@
#![allow(unknown_lints)]
#![allow(float_cmp)]
use error::{EvalError, EvalResult};
use memory::{Memory, MemoryPointer, HasMemory, PointerArithmetic};
use rustc::ty::layout::HasDataLayout;
use super::{
EvalError, EvalResult,
Memory, MemoryPointer, HasMemory, PointerArithmetic
};
pub(super) fn bytes_to_f32(bytes: u128) -> f32 {
f32::from_bits(bytes as u32)
}

23
src/librustc_mir/lib.rs Normal file
View File

@ -0,0 +1,23 @@
#![feature(
i128_type,
rustc_private,
conservative_impl_trait,
)]
// From rustc.
#[macro_use]
extern crate log;
extern crate log_settings;
#[macro_use]
extern crate rustc;
extern crate rustc_const_math;
extern crate rustc_data_structures;
extern crate syntax;
// From crates.io.
extern crate byteorder;
#[macro_use]
extern crate lazy_static;
extern crate regex;
pub mod interpret;

View File

@ -130,16 +130,16 @@ fn run_pass_miri() {
for &opt in [false, true].iter() {
for_all_targets(&sysroot, |target| {
miri_pass("../../tests/run-pass", &target, &host, false, opt);
miri_pass("tests/run-pass", &target, &host, false, opt);
});
miri_pass("../../tests/run-pass-fullmir", &host, &host, true, opt);
miri_pass("tests/run-pass-fullmir", &host, &host, true, opt);
}
}
#[test]
fn run_pass_rustc() {
run_pass("../../tests/run-pass");
run_pass("../../tests/run-pass-fullmir");
run_pass("tests/run-pass");
run_pass("tests/run-pass-fullmir");
}
#[test]
@ -148,7 +148,7 @@ fn compile_fail_miri() {
let host = get_host();
for_all_targets(&sysroot, |target| {
compile_fail(&sysroot, "../../tests/compile-fail", &target, &host, false);
compile_fail(&sysroot, "tests/compile-fail", &target, &host, false);
});
compile_fail(&sysroot, "../../tests/compile-fail-fullmir", &host, &host, true);
compile_fail(&sysroot, "tests/compile-fail-fullmir", &host, &host, true);
}