Commit 81b9bfe4 authored by qinsoon's avatar qinsoon

[wip] keep debugging

parent 0ddfce69
......@@ -2917,16 +2917,37 @@ pub fn emit_code(fv: &mut MuFunctionVersion, vm: &VM) {
}
// min alignment as 16 byte (written as 4 (2^4) on macos)
const MIN_ALIGN : ByteSize = 16;
fn check_min_align(align: ByteSize) -> ByteSize {
if align > MIN_ALIGN {
MIN_ALIGN
} else {
align
}
}
#[cfg(target_os = "linux")]
fn write_const_min_align(f: &mut File) {
write_align(f, MIN_ALIGN);
}
#[cfg(target_os = "linux")]
fn write_align(f: &mut File, align: ByteSize) {
use std::io::Write;
f.write("\t.align 16\n".as_bytes()).unwrap();
f.write_fmt(format_args!("\t.align {}\n", check_min_align(align))).unwrap();
}
#[cfg(target_os = "macos")]
fn write_const_min_align(f: &mut File) {
fn write_align(f: &mut File, align: ByteSize) {
use std::io::Write;
f.write("\t.align 4\n".as_bytes()).unwrap();
let align = check_min_align(align);
let mut n = 0;
while 2usize.pow(n) < align {
n += 1;
}
assert!(2usize.pow(n) == align, "alignment needs to be power of 2, alignment is {}", align);
f.write_fmt(format_args!("\t.align {}\n", n)).unwrap();
}
fn write_const(f: &mut File, constant: P<Value>, loc: P<Value>) {
......@@ -3048,6 +3069,8 @@ pub fn emit_context_with_reloc(vm: &VM,
}
for obj_dump in objects.values() {
write_align(&mut file, 8);
// .bytes xx,xx,xx,xx (between mem_start to reference_addr)
write_data_bytes(&mut file, obj_dump.mem_start, obj_dump.reference_addr);
......
......@@ -1613,8 +1613,10 @@ impl <'a> InstructionSelection {
match is_power_of_two(var_ty_size) {
Some(shift) => {
// a shift-left will get the total size of var part
self.backend.emit_shl_r_imm8(&tmp_var_len, shift);
if shift != 0 {
// a shift-left will get the total size of var part
self.backend.emit_shl_r_imm8(&tmp_var_len, shift);
}
// add with fix-part size
self.backend.emit_add_r_imm(&tmp_var_len, fix_part_size as i32);
......
......@@ -61,7 +61,7 @@ pub fn allocate_hybrid(ty: P<MuType>, len: u64, backendtype: Box<BackendTypeInfo
let gctype = backendtype.gc_type.clone();
let encode = get_gc_type_encode(gctype.id);
trace!("API: allocate fixed ty: {}", ty);
trace!("API: allocate hybrd ty: {}", ty);
trace!("API: gc ty : {:?}", gctype);
trace!("API: encode : {:b}", encode);
......@@ -74,6 +74,8 @@ pub fn allocate_global(iref_global: P<Value>, backendtype: Box<BackendTypeInfo>)
None => panic!("expected global to be an iref type, found {}", iref_global.ty)
};
assert!(!referenced_type.is_hybrid(), "global cell cannot be hybrid type");
let addr = allocate_fixed(referenced_type, backendtype);
ValueLocation::Direct(RegGroup::GPR, addr)
}
......@@ -12,7 +12,7 @@ fn link_executable_internal (files: Vec<PathBuf>, lib: &Vec<String>, libpath: &V
let mut cc = Command::new(get_test_clang_path());
for file in files {
println!("link with {:?}", file.as_path());
trace!("link with {:?}", file.as_path());
cc.arg(file.as_path());
}
......
......@@ -1091,6 +1091,7 @@ impl <'a> VM {
pub fn new_fixed(&self, tyid: MuID) -> APIHandleResult {
let ty = self.get_type(tyid);
assert!(!ty.is_hybrid());
let backend_ty = self.get_backend_type_info(tyid);
let addr = gc::allocate_fixed(ty.clone(), backend_ty);
......@@ -1104,6 +1105,8 @@ impl <'a> VM {
pub fn new_hybrid(&self, tyid: MuID, length: APIHandleArg) -> APIHandleResult {
let ty = self.get_type(tyid);
assert!(ty.is_hybrid());
let len = self.handle_to_uint64(length);
let backend_ty = self.get_backend_type_info(tyid);
......@@ -1152,14 +1155,12 @@ impl <'a> VM {
/// FIXME: iref/ref share the same address - this actually depends on GC
// iref has the same address as ref
trace!("API: get iref from {:?}", handle_ref);
let ret = self.new_handle(APIHandle {
id: self.next_id(),
v : APIHandleValue::IRef(ty, addr)
});
trace!("API: get iref from {:?}", handle_ref);
trace!("API: result {:?}", ret);
ret
......@@ -1174,10 +1175,15 @@ impl <'a> VM {
addr.plus(backend_ty.size * (offset as usize))
};
self.new_handle(APIHandle {
let ret = self.new_handle(APIHandle {
id: self.next_id(),
v : APIHandleValue::IRef(ty, offset_addr)
})
});
trace!("API: shift iref from {:?}", handle_iref);
trace!("API: result {:?}", ret);
ret
}
pub fn handle_get_elem_iref(&self, handle_iref: APIHandleArg, index: APIHandleArg) -> APIHandleResult {
......@@ -1193,10 +1199,15 @@ impl <'a> VM {
addr.plus(backend_ty.size * (index as usize))
};
self.new_handle(APIHandle {
let ret = self.new_handle(APIHandle {
id: self.next_id(),
v : APIHandleValue::IRef(ele_ty, elem_addr)
})
});
trace!("API: get element iref from {:?} at index {:?}", handle_iref, index);
trace!("API: result {:?}", ret);
ret
}
pub fn handle_get_var_part_iref(&self, handle_iref: APIHandleArg) -> APIHandleResult {
......@@ -1212,10 +1223,15 @@ impl <'a> VM {
None => panic!("cannot get varpart ty from {}", ty)
};
self.new_handle(APIHandle {
let ret = self.new_handle(APIHandle {
id: self.next_id(),
v : APIHandleValue::IRef(varpart_ty, varpart_addr)
})
});
trace!("API: get var part iref from {:?}", handle_iref);
trace!("API: result {:?}", ret);
ret
}
pub fn handle_get_field_iref(&self, handle_iref: APIHandleArg, field: usize) -> APIHandleResult {
......@@ -1234,10 +1250,15 @@ impl <'a> VM {
addr.plus(field_offset)
};
self.new_handle(APIHandle {
let ret = self.new_handle(APIHandle {
id: self.next_id(),
v : APIHandleValue::IRef(field_ty, field_addr)
})
});
trace!("API: get field iref from {:?}, field: {}", handle_iref, field);
trace!("API: result {:?}", ret);
ret
}
pub fn handle_load(&self, ord: MemoryOrder, loc: APIHandleArg) -> APIHandleResult {
......@@ -1257,10 +1278,15 @@ impl <'a> VM {
}
};
self.new_handle(APIHandle {
let ret = self.new_handle(APIHandle {
id: handle_id,
v : handle_value
})
});
trace!("API: load from {:?}", loc);
trace!("API: result {:?}", ret);
ret
}
pub fn handle_store(&self, ord: MemoryOrder, loc: APIHandleArg, val: APIHandleArg) {
......@@ -1297,6 +1323,8 @@ impl <'a> VM {
_ => unimplemented!()
}
}
trace!("API: store value {:?} to location {:?}", val, loc);
}
// this function and the following two make assumption that GC will not move object
......
......@@ -25,6 +25,21 @@ def test_add():
assert fn(1, 2) == 3
@may_spawn_proc
def test_list_append():
def list_append(n):
l = []
for i in range(0, n):
l.append(i)
sum = 0
for i in l:
sum += i
return sum
fn, _ = fncptr_from_rpy_func(list_append, [rffi.LONGLONG], rffi.LONGLONG)
assert fn(10) == 45
@may_spawn_proc
def test_vec3prod():
......@@ -1042,7 +1057,7 @@ def test_rpytarget_print_argv():
assert res.returncode == 0, res.err
assert res.out == '[%s, abc, 123]\n' % exe
@pytest.mark.xfail(reason = "probably need to align frame size to 16 bytes")
@pytest.mark.xfail(reason = "no idea")
@may_spawn_proc
def test_rpython_helloworld():
from rpython.translator.interactive import Translation
......@@ -1064,6 +1079,49 @@ def test_rpython_helloworld():
assert res.returncode == 0, res.err
assert res.out == 'hello world\n'
@pytest.mark.xfail(reason = "new test")
@may_spawn_proc
def test_rpython_print_number():
from rpython.translator.interactive import Translation
def main(argv):
print 255
return 0
t = Translation(main, None, backend='mu', muimpl='fast', mucodegen='api')
t.driver.exe_name = '/tmp/test_print_number'
t.compile_mu()
exe = py.path.local('/tmp/test_print_number.mu')
# zebu
import os
from rpython.translator.mu import dir_mu
exe.chmod(stat.S_IRWXU)
res = platform.execute(str(exe), [], env={'DYLD_LIBRARY_PATH': os.path.join(dir_mu, 'rpyc')})
assert res.returncode == 0, res.err
assert res.out == '1\n'
@may_spawn_proc
def test_rpython_main():
from rpython.translator.interactive import Translation
def main(argv):
return 0
t = Translation(main, None, backend='mu', muimpl='fast', mucodegen='api')
t.driver.exe_name = '/tmp/test_main'
t.compile_mu()
exe = py.path.local('/tmp/test_main.mu')
# zebu
import os
from rpython.translator.mu import dir_mu
exe.chmod(stat.S_IRWXU)
res = platform.execute(str(exe), [], env={'DYLD_LIBRARY_PATH': os.path.join(dir_mu, 'rpyc')})
assert res.returncode == 0, res.err
@pytest.mark.skipif("True")
@may_spawn_proc
def test_rpytarget_sha1sum():
......
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