Commit beb9d46a authored by Isaac Oscar Gariano's avatar Isaac Oscar Gariano

Deleting local changes to tests.

parent 49e961dd
macro_rules! typedef {
// int, floating point
(($vm: expr) $name: ident = mu_int($len: expr)) => {
let $name = $vm.declare_type($vm.next_id(), MuType_::int($len));
$vm.set_name($name.as_entity(), Mu(stringify!($name)));
};
(($vm: expr) $name: ident = mu_double) => {
let $name = $vm.declare_type($vm.next_id(), MuType_::double());
$vm.set_name($name.as_entity(), Mu(stringify!($name)));
};
// ref, iref, ptr
(($vm: expr) $name: ident = mu_ref($ty: ident)) => {
let $name = $vm.declare_type($vm.next_id(), MuType_::muref($ty.clone()));
$vm.set_name($name.as_entity(), Mu(stringify!($name)));
};
(($vm: expr) $name: ident = mu_iref($ty: ident)) => {
let $name = $vm.declare_type($vm.next_id(), MuType_::iref($ty.clone()));
$vm.set_name($name.as_entity(), Mu(stringify!($name)));
};
(($vm: expr) $name: ident = mu_uptr($ty: ident)) => {
let $name = $vm.declare_type($vm.next_id(), MuType_::uptr($ty.clone()));
$vm.set_name($name.as_entity(), Mu(stringify!($name)));
};
// struct
(($vm: expr) $name: ident = mu_struct($($ty: ident), *)) => {
let $name = $vm.declare_type($vm.next_id(), MuType_::mustruct(Mu(stringify!($name)), vec![$($ty.clone()),*]));
$vm.set_name($name.as_entity(), Mu(stringify!($name)));
};
(($vm: expr) $name: ident = mu_struct()) => {
let $name = $vm.declare_type($vm.next_id(), MuType_::mustruct(Mu(stringify!($name)), vec![]));
$vm.set_name($name.as_entity(), Mu(stringify!($name)));
};
(($vm: expr) $name: ident = mu_struct_placeholder()) => {
let $name = $vm.declare_type($vm.next_id(), MuType_::mustruct_empty(Mu(stringify!($name))));
$vm.set_name($name.as_entity(), Mu(stringify!($name)));
};
(($vm: expr) mu_struct_put($name: ident, $($ty: ident), *)) => {
MuType_::mustruct_put(&Mu(stringify!($name)), vec![$($ty.clone()), *])
};
// hybrid
(($vm: expr) $name: ident = mu_hybrid($($ty: ident), *); $var_ty: ident) => {
let $name = $vm.declare_type($vm.next_id(), MuType_::hybrid(Mu(stringify!($name)), vec![$($ty.clone()), *], $var_ty.clone()));
$vm.set_name($name.as_entity(), Mu(stringify!($name)));
};
(($vm: expr) $name: ident = mu_hybrid(none; $var_ty: ident)) => {
let $name = $vm.declare_type($vm.next_id(), MuType_::hybrid(Mu(stringify!($name)), vec![], $var_ty.clone()));
$vm.set_name($name.as_entity(), Mu(stringify!($name)));
};
// funcref
(($vm: expr) $name: ident = mu_funcref($sig: ident)) => {
let $name = $vm.declare_type($vm.next_id(), MuType_::funcref($sig.clone()));
$vm.set_name($name.as_entity(), Mu(stringify!($name)));
}
}
macro_rules! constdef {
(($vm: expr) <$ty: ident> $name: ident = $val: expr) => {
let $name = $vm.declare_const($vm.next_id(), $ty.clone(), $val);
$vm.set_name($name.as_entity(), Mu(stringify!($name)));
}
}
macro_rules! globaldef {
(($vm: expr) <$ty: ident> $name: ident) => {
let $name = $vm.declare_global($vm.next_id(), $ty.clone());
$vm.set_name($name.as_entity(), Mu(stringify!($name)));
}
}
macro_rules! funcsig {
(($vm: expr) $name: ident = ($($arg_ty: ident),*) -> ($($ret_ty: ident),*)) => {
let $name = $vm.declare_func_sig($vm.next_id(), vec![$($ret_ty.clone()),*], vec![$($arg_ty.clone()),*]);
$vm.set_name($name.as_entity(), Mu(stringify!($name)));
}
}
macro_rules! funcdecl {
(($vm: expr) <$sig: ident> $name: ident) => {
let func = MuFunction::new($vm.next_id(), $sig.clone());
$vm.set_name(func.as_entity(), Mu(stringify!($name)));
let $name = func.id();
$vm.declare_func(func);
}
}
macro_rules! funcdef {
(($vm: expr) <$sig: ident> $func: ident VERSION $version: ident) => {
let mut $version = MuFunctionVersion::new($vm.next_id(), $func, $sig.clone());
$vm.set_name($version.as_entity(), Mu(stringify!($version)));
}
}
macro_rules! define_func_ver {
(($vm: expr) $fv: ident (entry: $entry: ident){$($blk: ident), *}) => {
$fv.define(FunctionContent::new($entry.id(), {
let mut ret = LinkedHashMap::new();
$ (ret.insert($blk.id(), $blk); )*
ret
}));
$vm.define_func_version($fv);
}
}
macro_rules! block {
(($vm: expr, $fv: ident) $name: ident) => {
let mut $name = Block::new($vm.next_id());
$vm.set_name($name.as_entity(), Mu(stringify!($name)));
}
}
macro_rules! define_block {
(($vm: expr, $fv: ident) $name: ident ($($arg: ident), *) {$($inst: ident), *}) => {
$name.content = Some(BlockContent{
args: vec![$($arg.clone_value()), *],
exn_arg: None,
body: vec![$($inst), *],
keepalives: None
});
};
(($vm: expr, $fv: ident) $name: ident ($($arg: ident), *) [$exn_arg: ident] {$($inst: ident), *}) => {
$name.content = Some(BlockContent{
args: vec![$($arg.clone_value()), *],
exn_arg: Some($exn_arg.clone_value()),
body: vec![$($inst), *],
keepalives: None
});
}
}
macro_rules! ssa {
(($vm: expr, $fv: ident) <$ty: ident> $name: ident) => {
let $name = $fv.new_ssa($vm.next_id(), $ty.clone());
$vm.set_name($name.as_entity(), Mu(stringify!($name)));
}
}
macro_rules! consta {
(($vm: expr, $fv: ident) $name: ident = $c: ident) => {
let $name = $fv.new_constant($c.clone());
}
}
macro_rules! global {
(($vm: expr, $fv: ident) $name: ident = $g: ident) => {
let $name = $fv.new_global($g.clone());
}
}
macro_rules! inst {
// NEW
(($vm: expr, $fv: ident) $name: ident: $value: ident = NEW <$ty: ident>) => {
let $name = $fv.new_inst(Instruction{
hdr: MuEntityHeader::unnamed($vm.next_id()),
value: Some(vec![$value.clone_value()]),
ops: RwLock::new(vec![]),
v: Instruction_::New($ty.clone())
});
};
// GETIREF
(($vm: expr, $fv: ident) $name: ident: $value: ident = GETIREF $op: ident) => {
let $name = $fv.new_inst(Instruction{
hdr: MuEntityHeader::unnamed($vm.next_id()),
value: Some(vec![$value.clone_value()]),
ops: RwLock::new(vec![$op.clone()]),
v: Instruction_::GetIRef(0)
});
};
// GETFIELDIREF
(($vm: expr, $fv: ident) $name: ident: $value: ident = GETFIELDIREF $op: ident (is_ptr: $is_ptr: expr, index: $index: expr)) => {
let $name = $fv.new_inst(Instruction{
hdr: MuEntityHeader::unnamed($vm.next_id()),
value: Some(vec![$value.clone_value()]),
ops: RwLock::new(vec![$op.clone()]),
v: Instruction_::GetFieldIRef {
is_ptr: $is_ptr,
base: 0,
index: $index
}
});
};
// GETVARPARTIREF
(($vm: expr, $fv: ident) $name: ident: $value: ident = GETVARPARTIREF $op: ident (is_ptr: $is_ptr: expr)) => {
let $name = $fv.new_inst(Instruction{
hdr: MuEntityHeader::unnamed($vm.next_id()),
value: Some(vec![$value.clone_value()]),
ops: RwLock::new(vec![$op.clone()]),
v: Instruction_::GetVarPartIRef {
is_ptr: $is_ptr,
base: 0
}
});
};
// SHIFTIREF
(($vm: expr, $fv: ident) $name: ident: $value: ident = SHIFTIREF $op: ident $offset: ident (is_ptr: $is_ptr: expr)) => {
let $name = $fv.new_inst(Instruction{
hdr: MuEntityHeader::unnamed($vm.next_id()),
value: Some(vec![$value.clone_value()]),
ops: RwLock::new(vec![$op.clone(), $offset.clone()]),
v: Instruction_::ShiftIRef {
is_ptr: $is_ptr,
base: 0,
offset: 1
}
});
};
// STORE
(($vm: expr, $fv: ident) $name: ident: STORE $loc: ident $val: ident (is_ptr: $is_ptr: expr, order: $order: expr)) => {
let $name = $fv.new_inst(Instruction{
hdr: MuEntityHeader::unnamed($vm.next_id()),
value: None,
ops: RwLock::new(vec![$loc.clone(), $val.clone()]),
v: Instruction_::Store {
is_ptr: $is_ptr,
order: $order,
mem_loc: 0,
value: 1
}
});
};
// LOAD
(($vm: expr, $fv: ident) $name: ident: $value: ident = LOAD $loc: ident (is_ptr: $is_ptr: expr, order: $order: expr)) => {
let $name = $fv.new_inst(Instruction{
hdr: MuEntityHeader::unnamed($vm.next_id()),
value: Some(vec![$value.clone_value()]),
ops: RwLock::new(vec![$loc.clone()]),
v: Instruction_::Load {
is_ptr: $is_ptr,
order: $order,
mem_loc: 0
}
});
};
// BINOP
(($vm: expr, $fv: ident) $name: ident: $value: ident = BINOP ($op: expr) $op1: ident $op2: ident) => {
let $name = $fv.new_inst(Instruction{
hdr: MuEntityHeader::unnamed($vm.next_id()),
value: Some(vec![$value.clone_value()]),
ops: RwLock::new(vec![$op1.clone(), $op2.clone()]),
v: Instruction_::BinOp($op, 0, 1)
});
};
// BINOP with status
(($vm: expr, $fv: ident) $name: ident: $value: ident, $($flag: ident), * = BINOP_STATUS ($op: expr) ($flags: expr) $op1: ident $op2: ident) => {
let $name = $fv.new_inst(Instruction{
hdr: MuEntityHeader::unnamed($vm.next_id()),
value: Some(vec![$value.clone_value(), $($flag.clone_value()), *]),
ops: RwLock::new(vec![$op1.clone(), $op2.clone()]),
v: Instruction_::BinOpWithStatus($op, $flags, 0, 1)
});
};
// CMPOP
(($vm: expr, $fv: ident) $name: ident: $value: ident = CMPOP ($op: expr) $op1: ident $op2: ident) => {
let $name = $fv.new_inst(Instruction{
hdr: MuEntityHeader::unnamed($vm.next_id()),
value: Some(vec![$value.clone_value()]),
ops: RwLock::new(vec![$op1.clone(), $op2.clone()]),
v: Instruction_::CmpOp($op, 0, 1)
});
};
// CONVOP
(($vm: expr, $fv: ident) $name: ident: $value: ident = CONVOP ($operation: expr) <$ty1: ident $ty2: ident> $operand: ident) => {
let $name = $fv.new_inst(Instruction{
hdr: MuEntityHeader::unnamed($vm.next_id()),
value: Some(vec![$value.clone_value()]),
ops: RwLock::new(vec![$operand.clone()]),
v: Instruction_::ConvOp{
operation: $operation,
from_ty: $ty1.clone(),
to_ty: $ty2.clone(),
operand: 0
}
});
};
// SELECT
(($vm: expr, $fv: ident) $name: ident: $value: ident = SELECT $cond: ident $op_true: ident $op_false:ident) => {
let $name = $fv.new_inst(Instruction{
hdr: MuEntityHeader::unnamed($vm.next_id()),
value: Some(vec![$value.clone_value()]),
ops: RwLock::new(vec![$cond.clone(), $op_true.clone(), $op_false.clone()]),
v: Instruction_::Select{
cond: 0,
true_val: 1,
false_val: 2
}
});
};
// BRANCH
(($vm: expr, $fv: ident) $name: ident: BRANCH $dest: ident ($($arg: ident), *)) => {
let $name = $fv.new_inst(Instruction{
hdr: MuEntityHeader::unnamed($vm.next_id()),
value: None,
ops: RwLock::new(vec![$($arg.clone()),*]),
v: Instruction_::Branch1(Destination{
target: $dest.id(),
args: {
let mut i =0;
vec![$($arg.clone()),*].iter().map(|_| {let ret = DestArg::Normal(i); i+=1; ret}).collect()
}
})
});
};
// BRANCH2
// list all operands first
// then use vector expr to list operands for each destination
// (we cannot have two repetition list of different lengths in a macro)
(($vm: expr, $fv: ident) $name: ident:
BRANCH2 ($($op: ident), *)
IF (OP $cond: expr)
THEN $true_dest : ident ($true_args: expr) WITH $prob: expr,
ELSE $false_dest: ident ($false_args: expr)
) => {
let $name = $fv.new_inst(Instruction{
hdr: MuEntityHeader::unnamed($vm.next_id()),
value: None,
ops: RwLock::new(vec![$($op.clone()),*]),
v: {
let true_args = {
$true_args.iter().map(|x| DestArg::Normal(*x)).collect()
};
let false_args = {
$false_args.iter().map(|x| DestArg::Normal(*x)).collect()
};
Instruction_::Branch2{
cond: $cond,
true_dest: Destination {
target: $true_dest.id(),
args: true_args
},
false_dest: Destination {
target: $false_dest.id(),
args: false_args
},
true_prob: $prob
}
}
});
};
// EXPRCALL
(($vm: expr, $fv: ident) $name: ident: $res: ident = EXPRCALL ($cc: expr, is_abort: $is_abort: expr) $func: ident ($($val: ident), *)) => {
let ops = vec![$func.clone(), $($val.clone()), *];
let ops_len = ops.len();
let $name = $fv.new_inst(Instruction{
hdr: MuEntityHeader::unnamed($vm.next_id()),
value: Some(vec![$res.clone_value()]),
ops: RwLock::new(ops),
v: Instruction_::ExprCall {
data: CallData {
func: 0,
args: (1..ops_len).collect(),
convention: $cc
},
is_abort: $is_abort
}
});
};
(($vm: expr, $fv: ident) $name: ident: EXPRCALL ($cc: expr, is_abort: $is_abort: expr) $func: ident ($($val: ident), *)) => {
let ops = vec![$func.clone(), $($val.clone()), *];
let ops_len = ops.len();
let $name = $fv.new_inst(Instruction{
hdr: MuEntityHeader::unnamed($vm.next_id()),
value: Some(vec![]),
ops: RwLock::new(ops),
v: Instruction_::ExprCall {
data: CallData {
func: 0,
args: (1..ops_len).collect(),
convention: $cc
},
is_abort: $is_abort
}
});
};
// CALL (1 return result)
(($vm: expr, $fv: ident) $name: ident:
$res: ident = CALL ($($op: ident), *) FUNC($func: expr) ($args: expr) $cc: expr,
normal: $norm_dest: ident ($norm_args: expr),
exc: $exc_dest: ident ($exc_args: expr)) => {
let $name = $fv.new_inst(Instruction {
hdr : MuEntityHeader::unnamed($vm.next_id()),
value: Some(vec![$res.clone_value()]),
ops : RwLock::new(vec![$($op.clone()),*]),
v : Instruction_::Call {
data: CallData {
func: $func,
args: $args,
convention: $cc
},
resume: ResumptionData {
normal_dest: Destination {
target: $norm_dest.id(),
args : $norm_args
},
exn_dest: Destination {
target: $exc_dest.id(),
args : $exc_args
}
}
}
});
};
// CALL (no return value)
(($vm: expr, $fv: ident) $name: ident:
CALL ($($op: ident), *) FUNC($func: expr) ($args: expr) $cc: expr,
normal: $norm_dest: ident ($norm_args: expr),
exc: $exc_dest: ident ($exc_args: expr)) => {
let $name = $fv.new_inst(Instruction {
hdr : MuEntityHeader::unnamed($vm.next_id()),
value: None,
ops : RwLock::new(vec![$($op.clone()),*]),
v : Instruction_::Call {
data: CallData {
func: $func,
args: $args,
convention: $cc
},
resume: ResumptionData {
normal_dest: Destination {
target: $norm_dest.id(),
args : $norm_args
},
exn_dest: Destination {
target: $exc_dest.id(),
args : $exc_args
}
}
}
});
};
// RET
(($vm: expr, $fv: ident) $name: ident: RET ($($val: ident), +)) => {
let $name = $fv.new_inst(Instruction{
hdr: MuEntityHeader::unnamed($vm.next_id()),
value: None,
ops: RwLock::new(vec![$($val.clone()), *]),
v: Instruction_::Return({
let mut i = 0;
vec![$($val.clone()), *].iter().map(|_| {let ret = i; i+= 1; ret}).collect()
})
});
};
// RET (no value)
(($vm: expr, $fv: ident) $name: ident: RET) => {
let $name = $fv.new_inst(Instruction{
hdr: MuEntityHeader::unnamed($vm.next_id()),
value: None,
ops: RwLock::new(vec![]),
v: Instruction_::Return(vec![])
});
};
// THREADEXIT
(($vm: expr, $fv: ident) $name: ident: THREADEXIT) => {
let $name = $fv.new_inst(Instruction{
hdr: MuEntityHeader::unnamed($vm.next_id()),
value: None,
ops: RwLock::new(vec![]),
v: Instruction_::ThreadExit
});
};
// PRINTHEX
(($vm: expr, $fv: ident) $name: ident: PRINTHEX $val: ident) => {
let $name = $fv.new_inst(Instruction{
hdr: MuEntityHeader::unnamed($vm.next_id()),
value: None,
ops: RwLock::new(vec![$val.clone()]),
v: Instruction_::PrintHex(0)
});
}
}
#[macro_use]
extern crate mu;
#[macro_use]
extern crate utils;
#[macro_use]
extern crate log;
#[macro_use]
extern crate maplit;
#[macro_use]
mod ir_macros;
mod test_ir;
mod test_compiler;
mod test_runtime;
mod test_api;
mod common {
use std::fmt;
#[allow(dead_code)]
pub fn assert_vector_ordered <T: fmt::Debug> (left: &Vec<T>, right: &Vec<T>) {
assert_debug_str(left, right);
}
#[allow(dead_code)]
pub fn assert_vector_no_order <T: Ord + fmt::Debug + Clone> (left: &Vec<T>, right: &Vec<T>) {
let mut left_clone = left.clone();
left_clone.sort();
let mut right_clone = right.clone();
right_clone.sort();
assert_debug_str(left_clone, right_clone);
}
#[allow(dead_code)]
pub fn assert_debug_str<T: fmt::Debug, U: fmt::Debug> (left: T, right: U) {
assert_eq!(format!("{:?}", left), format!("{:?}", right))
}
}
mod test_vm_serialize;
extern crate rustc_serialize;
use test_ir::test_ir::factorial;
use mu::vm::*;
use std::sync::Arc;
use self::rustc_serialize::json;
use self::rustc_serialize::base64::ToBase64;
use self::rustc_serialize::hex::ToHex;
use self::rustc_serialize::base64::STANDARD;
#[test]
fn test_vm_serialize_factorial() {
VM::start_logging_trace();
let vm = Arc::new(factorial());
let serialized_json = json::encode(&vm).unwrap();
println!("JSON(len={}):", serialized_json.len());
println!("{}", serialized_json);
let base64 = serialized_json.as_bytes().to_base64(STANDARD);
println!("base64(len={}):", base64.len());
println!("{}", base64);
let hex = serialized_json.as_bytes().to_hex();
println!("hex(len={}):", hex.len());
println!("{}", hex);
let reconstruct_vm : VM = json::decode(&serialized_json).unwrap();
let serialized_again = json::encode(&reconstruct_vm).unwrap();
println!("JSON for reconstructed VM(len={}):", serialized_again.len());
println!("{}", serialized_again);
// check_string_eq_char_by_char(serialized, serialized_again);
}
#[allow(dead_code)]
fn check_string_eq_char_by_char(str1: String, str2: String) {
use std::cmp;
let min_len = cmp::min(str1.len(), str2.len());
println!("str1_len = {}, str2_len = {}", str1.len(), str2.len());
let b1 = str1.into_bytes();
let b2 = str2.into_bytes();
for i in 0..min_len {
if b1[i] != b2[i] {
println!("different here ({}):", i);
print!("str1: ..");
for j in 0..20 {
print!("{}", b1[i + j] as char);
}
println!("..");
print!("str2: ..");
for j in 0..20 {
print!("{}", b2[i + j] as char);
}
println!("..");
panic!("found difference in two strings");
}
}
}
mod test_pre_instsel;
mod test_instsel;
mod test_regalloc;
mod test_global;
mod test_compiler;
mod test_alloc;
mod test_exception;
mod test_thread;
mod test_floatingpoint;
mod test_int;
mod test_binop;
mod test_controlflow;
mod test_call;
mod test_mem_inst;
mod test_inline;
mod test_convop;
\ No newline at end of file
extern crate log;
extern crate libloading;
extern crate mu;
use self::mu::ast::types::*;
use self::mu::ast::ir::*;
use self::mu::ast::inst::*;
use self::mu::vm::*;
use self::mu::compiler::*;
use self::mu::runtime::thread::MuThread;
use self::mu::utils::Address;
use self::mu::utils::LinkedHashMap;
use std::sync::Arc;
use std::sync::RwLock;
use self::mu::testutil;
use self::mu::testutil::aot;