WARNING! Access to this system is limited to authorised users only.
Unauthorised users may be subject to prosecution.
Unauthorised access to this system is a criminal offence under Australian law (Federal Crimes Act 1914 Part VIA)
It is a criminal offence to:
(1) Obtain access to data without authority. -Penalty 2 years imprisonment.
(2) Damage, delete, alter or insert data without authority. -Penalty 10 years imprisonment.
User activity is monitored and recorded. Anyone using this system expressly consents to such monitoring and recording.

Commit f12b89da authored by qinsoon's avatar qinsoon
Browse files

add a new test for GetElemIRef, currently ignored

parent ff41be9e
......@@ -81,9 +81,21 @@ pub fn compile_fnc<'a>(fnc_name: &'static str, build_fnc: &'a Fn() -> VM) -> ll:
let func_id = vm.id_of(fnc_name);
{
let funcs = vm.funcs().read().unwrap();
let func = funcs.get(&func_id).unwrap().read().unwrap();
let func = match funcs.get(&func_id) {
Some(func) => func.read().unwrap(),
None => panic!("cannot find function {}", fnc_name)
};
let cur_ver = match func.cur_ver {
Some(v) => v,
None => panic!("function {} does not have a defined current version", fnc_name)
};
let func_vers = vm.func_vers().read().unwrap();
let mut func_ver = func_vers.get(&func.cur_ver.unwrap()).unwrap().write().unwrap();
let mut func_ver = match func_vers.get(&cur_ver) {
Some(fv) => fv.write().unwrap(),
None => panic!("cannot find function version {}", cur_ver)
};
compiler.compile(&mut func_ver);
}
backend::emit_context(&vm);
......
......@@ -51,10 +51,10 @@ macro_rules! typedef {
};
// array
(($vm: expr) $name: ident = mu_array($ty: ident, $len: expr) => {
(($vm: expr) $name: ident = mu_array($ty: ident, $len: expr)) => {
let $name = $vm.declare_type($vm.next_id(), MuType_::array($ty.clone(), $len));
$vm.set_name($name.as_entity(), Mu(stringify!($name)));
});
};
// funcref
(($vm: expr) $name: ident = mu_funcref($sig: ident)) => {
......@@ -193,6 +193,20 @@ macro_rules! inst {
});
};
// GETELEMIREF
(($vm: expr, $fv: ident) $name: ident: $value: ident = GETELEMIREF $op: ident $index: 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(), $index.clone()]),
v: Instruction_::GetElementIRef {
is_ptr: $is_ptr,
base: 0,
index: 1
}
});
};
// GETVARPARTIREF
(($vm: expr, $fv: ident) $name: ident: $value: ident = GETVARPARTIREF $op: ident (is_ptr: $is_ptr: expr)) => {
let $name = $fv.new_inst(Instruction{
......
......@@ -90,6 +90,7 @@ fn write_int8() -> VM {
vm
}
#[allow(unused_variables)]
#[test]
fn test_write_int8_const() {
let lib = testutil::compile_fnc("write_int8_const", &write_int8_const);
......@@ -1544,5 +1545,68 @@ fn shift_iref_ele_16bytes() -> VM {
blk_entry
});
vm
}
#[test]
#[ignore]
fn test_get_elem_iref_array_ele_9bytes() {
let lib = testutil::compile_fnc("get_elem_iref_array_ele_9bytes", &get_elem_iref_array_ele_9bytes);
unsafe {
let get_elem_iref_array_ele_9bytes : libloading::Symbol<unsafe extern fn(u64, u64) -> u64> = lib.get(b"get_elem_iref_array_ele_9bytes").unwrap();
let res = get_elem_iref_array_ele_9bytes(0, 0);
println!("get_elem_iref_array_ele_9bytes(0, 0) = {}", res);
assert_eq!(res, 0);
let res = get_elem_iref_array_ele_9bytes(0, 1);
println!("get_elem_iref_array_ele_9bytes(0, 1) = {}", res);
assert_eq!(res, 16);
let res = get_elem_iref_array_ele_9bytes(0, 2);
println!("get_elem_iref_array_ele_9bytes(0, 2) = {}", res);
assert_eq!(res, 32);
}
}
fn get_elem_iref_array_ele_9bytes() -> VM {
let vm = VM::new();
typedef! ((vm) int8 = mu_int(8));
typedef! ((vm) int64 = mu_int(64));
typedef! ((vm) elem = mu_struct(int64, int8));
typedef! ((vm) array_9bytes = mu_array(elem, 5));
typedef! ((vm) iref_elem = mu_iref(elem));
typedef! ((vm) iref_array = mu_iref(array_9bytes));
funcsig! ((vm) sig = (iref_array, int64) -> (iref_elem));
funcdecl! ((vm) <sig> get_elem_iref_array_ele_9bytes);
funcdef! ((vm) <sig> get_elem_iref_array_ele_9bytes VERSION get_elem_iref_array_ele_9bytes_v1);
// blk entry
block! ((vm, get_elem_iref_array_ele_9bytes_v1) blk_entry);
ssa! ((vm, get_elem_iref_array_ele_9bytes_v1) <iref_array> base);
ssa! ((vm, get_elem_iref_array_ele_9bytes_v1) <int64> index);
ssa! ((vm, get_elem_iref_array_ele_9bytes_v1) <iref_elem> res);
inst! ((vm, get_elem_iref_array_ele_9bytes_v1) blk_entry_get_elem_iref:
res = GETELEMIREF base index (is_ptr: false)
);
inst! ((vm, get_elem_iref_array_ele_9bytes_v1) blk_entry_ret:
RET (res)
);
define_block!((vm, get_elem_iref_array_ele_9bytes_v1) blk_entry(base, index) {
blk_entry_get_elem_iref, blk_entry_ret
});
define_func_ver!((vm) get_elem_iref_array_ele_9bytes_v1 (entry: blk_entry) {
blk_entry
});
vm
}
\ No newline at end of file
use mu::ast::types::*;
use mu::ast::ir::*;
use mu::ast::inst::*;
use mu::ast::op::*;
use mu::vm::*;
use utils::Address;
use mu::runtime::mm;
use mu::runtime::thread;
use mu::runtime::thread::MuThread;
use std::sync::Arc;
#[test]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment