Commit 1168f297 authored by qinsoon's avatar qinsoon

[wip] get handle from global, and create handle from int

parent 55aa2fe5
Pipeline #242 failed with stage
in 24 minutes and 15 seconds
use ir::*;
use ptr::*;
use types::*;
use utils::Address;
use std::collections::HashMap;
......@@ -35,121 +34,4 @@ impl MuBundle {
// name_id_map: HashMap::new()
}
}
}
#[derive(Copy, Clone, Debug)]
pub struct APIHandleKey {
pub id: MuID,
pub v: APIHandleKeyKind
}
#[derive(Copy, Clone, Debug)]
pub enum APIHandleKeyKind {
Int,
Float,
Double,
UPtr,
UFP,
// SeqValue
Struct,
Array,
Vector,
// GenRef
Ref,
IRef,
TagRef64,
FuncRef,
ThreadRef,
StackRef,
FCRef, // frame cursor ref
// GenRef->IR
Bundle,
// GenRef->IR->Child
Type,
FuncSig,
FuncVer,
BB,
Inst,
// GenRef->IR->Child->Var->Global
Const,
Global,
Func,
ExpFunc,
// GenRef->IR->Child->Var->Local
NorParam,
ExcParam,
InstRes,
}
macro_rules! handle_constructor {
($fn_name: ident, $kind: ident) => {
pub fn $fn_name(id: MuID) -> APIHandleKey {
APIHandleKey{
id: id, v: APIHandleKeyKind::$kind
}
}
}
}
handle_constructor!(handle_int, Int);
handle_constructor!(handle_float, Float);
handle_constructor!(handle_double, Double);
handle_constructor!(handle_uptr, UPtr);
handle_constructor!(handle_ufp, UFP);
handle_constructor!(handle_struct, Struct);
handle_constructor!(handle_array, Array);
handle_constructor!(handle_vector, Vector);
handle_constructor!(handle_ref, Ref);
handle_constructor!(handle_iref, IRef);
handle_constructor!(handle_tagref64, TagRef64);
handle_constructor!(handle_funcref, FuncRef);
handle_constructor!(handle_threadref, ThreadRef);
handle_constructor!(handle_stackref, StackRef);
handle_constructor!(handle_fcref, FCRef);
handle_constructor!(handle_bundle, Bundle);
handle_constructor!(handle_type, Type);
handle_constructor!(handle_funcsig, FuncSig);
handle_constructor!(handle_funcver, FuncVer);
handle_constructor!(handle_bb, BB);
handle_constructor!(handle_inst, Inst);
handle_constructor!(handle_const, Const);
handle_constructor!(handle_global, Global);
handle_constructor!(handle_func, Func);
handle_constructor!(handle_expfunc, ExpFunc);
handle_constructor!(handle_norparam, NorParam);
handle_constructor!(handle_excparam, ExcParam);
handle_constructor!(handle_instres, InstRes);
#[derive(Clone)]
pub enum APIHandleValue {
Int(u64),
Float(f32),
Double(f64),
UPtr(Address),
UFP(Address),
Struct(Vec<APIHandleValue>),
Array(Vec<APIHandleValue>),
Vector(Vec<APIHandleValue>),
Ref(Address),
IRef(Address),
TagRef64(u64),
FuncRef(MuID),
ThreadRef,
StackRef,
FCRef,
IBRef
}
\ No newline at end of file
......@@ -488,4 +488,4 @@ impl DestArg {
&DestArg::Freshbound(n) => format!("${}", n)
}
}
}
\ No newline at end of file
}
......@@ -42,4 +42,4 @@ pub mod inst;
pub mod types;
pub mod ir_semantics;
pub mod ptr;
pub mod op;
\ No newline at end of file
pub mod op;
......@@ -104,4 +104,4 @@ pub fn P<T>(value: T) -> P<T> {
// fn encode<S: Encoder> (&self, s: &mut S) -> Result<(), S::Error> {
// s.emit_usize(self.id())
// }
//}
\ No newline at end of file
//}
......@@ -2898,4 +2898,4 @@ pub fn spill_rewrite(
cf.mc().trace_mc();
new_nodes
}
\ No newline at end of file
}
......@@ -184,4 +184,4 @@ pub trait CodeGenerator {
// fp conversion
fn emit_cvtsi2sd_f64_r (&mut self, dest: Reg, src: Reg);
fn emit_cvtsd2si_r_f64 (&mut self, dest: Reg, src: Reg);
}
\ No newline at end of file
}
......@@ -518,4 +518,4 @@ pub fn estimate_insts_for_ir(inst: &Instruction) -> usize {
Move(_) => 0,
ExnInstruction{ref inner, ..} => estimate_insts_for_ir(&inner)
}
}
\ No newline at end of file
}
......@@ -306,4 +306,4 @@ impl RegGroup {
_ => unimplemented!()
}
}
}
\ No newline at end of file
}
pub mod graph_coloring;
pub use compiler::backend::reg_alloc::graph_coloring::RegisterAllocation;
\ No newline at end of file
pub use compiler::backend::reg_alloc::graph_coloring::RegisterAllocation;
......@@ -127,4 +127,4 @@ impl FrameSlot {
)
})
}
}
\ No newline at end of file
}
......@@ -144,4 +144,4 @@ pub trait MachineCode {
pub trait MachineInst {
}
\ No newline at end of file
}
......@@ -82,4 +82,4 @@ impl Default for CompilerPolicy {
CompilerPolicy{passes: passes}
}
}
\ No newline at end of file
}
......@@ -272,4 +272,4 @@ fn process_dest(dest: Destination, blocks_to_insert: &mut Vec<IntermediateBlockI
dest
}
}
\ No newline at end of file
}
......@@ -464,4 +464,4 @@ impl CompilerPass for Inlining {
debug!("after inlining: {:?}", func);
}
}
}
\ No newline at end of file
}
......@@ -71,4 +71,4 @@ impl AddressBitmap {
pub fn print(&self) {
self.bitmap.print();
}
}
\ No newline at end of file
}
......@@ -41,4 +41,4 @@ impl <T> AddressMap<T> where T: Copy{
let index = (addr.diff(self.start) >> LOG_POINTER_SIZE) as isize;
unsafe {*self.ptr.offset(index)}
}
}
\ No newline at end of file
}
......@@ -145,4 +145,4 @@ mod test {
assert_eq!(bitmap.length_until_next_bit(5), 1);
assert_eq!(bitmap.length_until_next_bit(6), 0);
}
}
\ No newline at end of file
}
......@@ -174,4 +174,4 @@ mod tests {
assert_eq!(vec[1].gen_ref_offsets(), vec![0, 16, 32, 48, 64, 80, 96, 112, 128, 144]);
assert_eq!(vec[2].gen_ref_offsets(), (0..100).map(|x| x * 16).collect::<Vec<ByteSize>>());
}
}
\ No newline at end of file
}
......@@ -4,4 +4,4 @@ mod address_map;
pub mod gctype;
pub use self::address_bitmap::AddressBitmap;
pub use self::address_map::AddressMap;
\ No newline at end of file
pub use self::address_map::AddressMap;
......@@ -124,4 +124,4 @@ impl fmt::Display for FreeListNode {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "FreeListNode#{}(start={:#X}, size={}, state={:?})", self.id, self.start, self.size, self.mark)
}
}
\ No newline at end of file
}
......@@ -22,4 +22,4 @@ pub fn alloc_large(size: usize, align: usize, mutator: &mut immix::ImmixMutatorL
return ret_addr;
}
}
}
\ No newline at end of file
}
......@@ -362,4 +362,4 @@ mod tests {
println!("Allocation{}: {}", i, ret);
}
}
}
\ No newline at end of file
}
......@@ -567,4 +567,4 @@ pub fn steal_process_edge(base: Address, offset: usize, local_queue:&mut Vec<Obj
}
}
}
}
\ No newline at end of file
}
......@@ -344,4 +344,4 @@ impl fmt::Display for ImmixMutatorLocal {
write!(f, "block = {}", self.block.as_ref().unwrap())
}
}
}
\ No newline at end of file
}
......@@ -440,4 +440,4 @@ impl fmt::Debug for ImmixBlock {
}
write!(f, "]")
}
}
\ No newline at end of file
}
......@@ -36,4 +36,4 @@ pub enum LineMark {
pub enum BlockMark {
Usable,
Full
}
\ No newline at end of file
}
......@@ -87,4 +87,4 @@ pub trait Space {
pub fn fill_alignment_gap(start : Address, end : Address) -> () {
debug_assert!(end >= start);
start.memset(ALIGNMENT_VALUE, end.diff(start));
}
\ No newline at end of file
}
......@@ -208,4 +208,4 @@ pub extern fn muentry_alloc_large(mutator: *mut ImmixMutatorLocal, size: usize,
#[no_mangle]
pub extern fn force_gc() {
heap::gc::trigger_gc();
}
\ No newline at end of file
}
......@@ -393,4 +393,4 @@ mod tests {
assert_eq!(header_get_hybrid_length(encode), 10);
assert_eq!(header_get_gctype_id(encode), 2);
}
}
\ No newline at end of file
}
......@@ -96,4 +96,4 @@ pub const SHORT_ENCODE_BIT : usize = 7;
#[inline(always)]
pub fn get_ref_byte(alloc_map:*mut u8, space_start: Address, obj: ObjectReference) -> u8 {
unsafe {*alloc_map.offset((obj.to_address().diff(space_start) >> LOG_POINTER_SIZE) as isize)}
}
\ No newline at end of file
}
mod test_gc_harness;
mod test_gcbench;
mod test_gc_linked_list;
\ No newline at end of file
mod test_gc_linked_list;
......@@ -275,4 +275,4 @@ fn test_alloc_trace() {
heap::gc::start_trace(&mut roots, shared_space, lo_space);
mutator.destroy();
}
\ No newline at end of file
}
......@@ -210,4 +210,4 @@ fn linked_list_survive_gc() {
}
mutator.destroy();
}
\ No newline at end of file
}
......@@ -205,4 +205,4 @@ fn start() {
println!("Finished with {} collections", heap::gc::GC_COUNT.load(Ordering::SeqCst));
mutator.destroy();
}
\ No newline at end of file
}
......@@ -95,4 +95,4 @@ lazy_static! {
aot: ValueLocation::Relocatable(RegGroup::GPR, String::from("muentry_frem")),
jit: RwLock::new(None)
};
}
\ No newline at end of file
}
......@@ -208,4 +208,4 @@ fn find_func_for_address (cf: &RwLockReadGuard<HashMap<MuID, RwLock<CompiledFunc
}
panic!("cannot find compiled function for pc 0x{:x}", pc_addr);
}
\ No newline at end of file
}
......@@ -4,4 +4,4 @@ pub extern fn muentry_frem(a: f64, b: f64) -> f64 {
use std::ops::Rem;
a.rem(b)
}
\ No newline at end of file
}
......@@ -28,4 +28,4 @@ pub fn allocate_value(value: P<Value>, vm: &VM) -> ValueLocation {
let addr = allocate(backend_ty.size, backend_ty.alignment).to_address();
ValueLocation::Direct(RegGroup::GPR, addr)
}
\ No newline at end of file
}
......@@ -203,4 +203,4 @@ pub extern fn mu_main(serialized_vm : *const c_char) {
thread.join().unwrap();
}
}
\ No newline at end of file
}
......@@ -171,4 +171,4 @@ pub fn link_dylib_with_extra_srcs(funcs: Vec<MuName>, srcs: Vec<String>, out: &s
out_path.push(out);
link_dylib_internal(files, out_path)
}
\ No newline at end of file
}
......@@ -40,4 +40,4 @@ pub fn compile_run_c_test(test_file_path: &'static str) -> PathBuf {
let test_out = exec(test);
Path::new(&String::from_utf8(test_out.stdout).unwrap()).to_path_buf()
}
\ No newline at end of file
}
......@@ -99,4 +99,4 @@ pub fn compile_fncs<'a>(entry: &'static str, fnc_names: Vec<&'static str>, build
let libname = &get_dylib_name(entry);
let dylib = aot::link_dylib(fnc_names.iter().map(|x| Mu(x)).collect(), libname, &vm);
ll::Library::new(dylib.as_os_str()).unwrap()
}
\ No newline at end of file
}
......@@ -196,4 +196,4 @@ impl fmt::Debug for ObjectReference {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "0x{:X}", self.0)
}
}
\ No newline at end of file
}
......@@ -43,4 +43,4 @@ mod tests {
assert_eq!(set_nth_bit_u64(a, 2, 1), 0b100);
assert_eq!(set_nth_bit_u64(b, 2, 0), 0b1011);
}
}
\ No newline at end of file
}
......@@ -4,4 +4,4 @@ use ast::ptr::*;
pub fn make_i32_const(id: MuID, val: i32) -> P<Value> {
unimplemented!()
}
\ No newline at end of file
}
extern crate byteorder;
extern crate rustc_serialize;
pub type BitSize = usize;
pub type ByteOffset = isize;
pub type ByteSize = usize;
pub type Word = usize;
......@@ -46,4 +47,4 @@ pub use address::ObjectReference;
pub mod vec_utils;
pub mod bit_utils;
pub mod string_utils;
\ No newline at end of file
pub mod string_utils;
......@@ -1128,4 +1128,4 @@ impl<K: Hash + Eq, V, S: BuildHasher> IntoIterator for LinkedHashMap<K, V, S> {
marker: marker::PhantomData,
}
}
}
\ No newline at end of file
}
......@@ -44,4 +44,4 @@ mod tests{
assert_eq!(raw, a);
}
}
\ No newline at end of file
}
......@@ -9,4 +9,4 @@ pub fn replace(s: &mut String, index: usize, replace: &String, replace_len: usiz
vec[index + i] = ' ' as u8;
}
}
}
\ No newline at end of file
}
......@@ -142,4 +142,4 @@ pub fn map<T, Q, F> (vec: &Vec<T>, map_func: F) -> Vec<Q>
}
ret
}
\ No newline at end of file
}
......@@ -19,7 +19,7 @@ mod deps {
pub type MuName = String;
pub type CName = MuName;
pub struct APIHandleKey {
pub struct APIHandle {
// stub
}
......
This diff is collapsed.
......@@ -105,17 +105,17 @@ fn from_MuBool(cbool: CMuBool) -> bool {
cbool != 0
}
// APIHandleKey is immutable when used.
// APIHandle is immutable when used.
#[inline(always)]
fn from_handle<'a>(cmuvalue: CMuValue) -> &'a APIHandleKey {
fn from_handle<'a>(cmuvalue: CMuValue) -> &'a APIHandle {
debug_assert!(!cmuvalue.is_null());
unsafe {
&*(cmuvalue as *const APIHandleKey)
&*(cmuvalue as *const APIHandle)
}
}
#[inline(always)]
fn from_handle_optional<'a>(cmuvalue: CMuValue) -> Option<&'a APIHandleKey> {
fn from_handle_optional<'a>(cmuvalue: CMuValue) -> Option<&'a APIHandle> {
if cmuvalue.is_null() {
None
} else {
......@@ -157,11 +157,11 @@ fn from_MuFlag_array<'a>(ptr: *const CMuFlag, len: usize) -> &'a [CMuFlag] {
/// way as raw pointers. So this function will convert each element. This function is only called
/// by `new_thread_nor`. As always, thread creation dominates the time.
#[inline(always)]
fn from_handle_array<'a>(ptr: *const CMuValue, len: usize) -> Vec<&'a APIHandleKey> {
fn from_handle_array<'a>(ptr: *const CMuValue, len: usize) -> Vec<&'a APIHandle> {
let slc = from_array_direct(ptr, len);
slc.iter().map(|&e| {
debug_assert!(!e.is_null());
unsafe { &*(e as *const APIHandleKey) }
unsafe { &*(e as *const APIHandle) }
}).collect::<Vec<_>>()
}
......@@ -190,7 +190,7 @@ fn to_MuID(value: MuID) -> CMuID {
}
#[inline(always)]
fn to_handle(muvalue: *const APIHandleKey) -> CMuValue {
fn to_handle(muvalue: *const APIHandle) -> CMuValue {
debug_assert!(!muvalue.is_null());
muvalue as CMuValue
}
......
......@@ -45,5 +45,7 @@ mod common {
pub use ast::ir::*;
pub use ast::ptr::*;
pub use ast::types::*;
pub use vm::handle::*;
}
This diff is collapsed.
......@@ -151,4 +151,4 @@ pub extern fn mu_fastimpl_new_with_opts(opts: *const c_char) -> *mut CMuVM {
debug!("The C-visible CMuVM struct address: {:?}", c_mvm);
c_mvm
}
\ No newline at end of file
}
......@@ -77,4 +77,4 @@ pub struct MuCtx {
// GENERATE_BEGIN: MuCtx
// GENERATE_END: MuCtx
}
\ No newline at end of file
}
......@@ -73,23 +73,23 @@ impl MuVM {
pub type MuArraySize = usize;
pub type MuIntValue = APIHandleKey;
pub type MuIntValue = APIHandle;
pub type MuBundleNode = APIHandleKey;
pub type MuChildNode = APIHandleKey;
pub type MuTypeNode = APIHandleKey;
pub type MuFuncSigNode= APIHandleKey;
pub type MuConstNode = APIHandleKey;
pub type MuGlobalNode = APIHandleKey;
pub type MuFuncNode = APIHandleKey;
pub type MuFuncVerNode= APIHandleKey;
pub type MuBBNode = APIHandleKey;
pub type MuNorParamNode = APIHandleKey;
pub type MuExcParamNode = APIHandleKey;
pub type MuInstNode = APIHandleKey;
pub type MuInstResNode = APIHandleKey;
pub type MuLocalVarNode = APIHandleKey;
pub type MuVarNode = APIHandleKey;
pub type MuBundleNode = APIHandle;
pub type MuChildNode = APIHandle;
pub type MuTypeNode = APIHandle;
pub type MuFuncSigNode= APIHandle;
pub type MuConstNode = APIHandle;
pub type MuGlobalNode = APIHandle;
pub type MuFuncNode = APIHandle;
pub type MuFuncVerNode= APIHandle;
pub type MuBBNode = APIHandle;
pub type MuNorParamNode = APIHandle;
pub type MuExcParamNode = APIHandle;
pub type MuInstNode = APIHandle;
pub type MuInstResNode = APIHandle;
pub type MuLocalVarNode = APIHandle;
pub type MuVarNode = APIHandle;
pub type MuFlag = usize;
pub type MuDestKind = MuFlag;
......@@ -637,4 +637,4 @@ impl MuCtxInternal {
cur_bundles: HashMap::new()
}
}
}
\ No newline at end of file
}
../api_bridge.rs
\ No newline at end of file
This diff is collapsed.
../api_c.rs
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
......@@ -23,7 +23,7 @@ mod deps {
}
#[derive(Debug)]
pub struct APIHandleKey {
pub struct APIHandle {
pub ty: MuID,
pub vb: ValueBox,
}
......
......@@ -10,7 +10,7 @@ mod deps {
pub use ast::ir::MuID;
pub use ast::ir::MuName;
pub use ast::ir::CName;
pub use ast::bundle::APIHandleKey;
pub use vm::handle::APIHandle;
extern crate ast;
}
......
use ast::ir::*;
use ast::inst::*;
use utils::BitSize;
use utils::Address;
use std::sync::Arc;
#[derive(Clone, Debug)]
pub struct APIHandle {
pub id: MuID,
pub v: APIHandleValue
}
#[derive(Clone, Debug)]
pub enum APIHandleValue {
Int(u64, BitSize),
Float(f32),
Double(f64),
UPtr(Address),
UFP(Address),
// SeqValue
Struct(Vec<APIHandleValue>),
Array (Vec<APIHandleValue>),
Vector(Vec<APIHandleValue>),
// GenRef
Ref(Address),
IRef(Address),
TagRef64(u64),
FuncRef,
ThreadRef,
StackRef,
FCRef, // frame cursor ref
// GenRef->IR
Bundle,
// GenRef->IR->Child
Type(MuID),
FuncSig(MuID),
FuncVer(MuID),
BB,
Inst,
// GenRef->IR->Child->Var->Global
Const,
Global(MuID),
Func,
ExpFunc,
// GenRef->IR->Child->Var->Local
NorParam,
ExcParam,
InstRes,
}
impl APIHandleValue {
pub fn as_iref(&self) -> Address {
match self {
&APIHandleValue::IRef(addr) => addr,
_ => panic!("expected IRef")
}
}
}
pub fn store(ord: MemoryOrder, loc: Arc<APIHandle>, val: Arc<APIHandle>) {
// FIXME: take memory order into consideration
// get address
let addr = loc.v.as_iref();
// get value and store
// we will store here (its unsafe)
unsafe {
match val.v {
APIHandleValue::Int(ival, bits) => {
match bits {
8 => addr.store::<u8>(ival as u8),
16 => addr.store::<u16>(ival as u16),
32 => addr.store::<u32>(ival as u32),