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.

To protect your data, the CISO officer has suggested users to enable 2FA as soon as possible.
Currently 2.6% of users enabled 2FA.

Commit 116e0e2d authored by qinsoon's avatar qinsoon
Browse files

[wip] refactoring const/global

parent e716d22f
......@@ -506,8 +506,8 @@ impl fmt::Display for Value {
Value_::Constant(ref c) => {
write!(f, "+({} {})", self.ty, c)
},
Value_::Global(ref g) => {
write!(f, "+({} to GLOBAL {} @{})", self.ty, g.ty, g.tag)
Value_::Global => {
write!(f, "+(GLOBAL {} @{})", self.ty, self.name.unwrap())
},
Value_::Memory(ref mem) => {
write!(f, "+({})", mem)
......@@ -520,7 +520,7 @@ impl fmt::Display for Value {
pub enum Value_ {
SSAVar(MuID),
Constant(Constant),
Global(P<GlobalCell>),
Global,
Memory(MemoryLocation)
}
......@@ -619,12 +619,6 @@ impl fmt::Display for MemoryLocation {
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct GlobalCell {
pub tag: MuName,
pub ty: P<MuType>
}
pub fn op_vector_str(vec: &Vec<OpIndex>, ops: &Vec<P<TreeNode>>) -> String {
let mut ret = String::new();
for i in 0..vec.len() {
......
......@@ -1131,14 +1131,14 @@ pub fn emit_context(vm: &VM) {
file.write_fmt(format_args!("\t.bss\n")).unwrap();
let globals = vm.globals().read().unwrap();
for cell in globals.values() {
for global in globals.values() {
let (size, align) = {
let ty_info = vm.get_backend_type_info(&cell.ty);
let ty_info = vm.get_backend_type_info(&global.ty);
(ty_info.size, ty_info.alignment)
};
file.write_fmt(format_args!("\t{}\n", directive_globl(symbol(cell.tag)))).unwrap();
file.write_fmt(format_args!("\t{}\n", directive_comm(symbol(cell.tag), size, align))).unwrap();
file.write_fmt(format_args!("\t{}\n", directive_globl(symbol(global.name.unwrap())))).unwrap();
file.write_fmt(format_args!("\t{}\n", directive_comm(symbol(global.name.unwrap()), size, align))).unwrap();
file.write("\n".as_bytes()).unwrap();
}
......
......@@ -621,7 +621,7 @@ impl <'a> InstructionSelection {
TreeNode_::Value(ref pv) => {
match pv.v {
Value_::Constant(_)
| Value_::Global(_)
| Value_::Global
| Value_::Memory(_) => panic!("expected ireg"),
Value_::SSAVar(_) => {
pv.clone()
......@@ -672,7 +672,7 @@ impl <'a> InstructionSelection {
scale: None
})
}),
Value_::Global(ref glob) => {
Value_::Global => {
if vm.is_running() {
// get address from vm
unimplemented!()
......@@ -684,7 +684,7 @@ impl <'a> InstructionSelection {
ty: types::get_referent_ty(&pv.ty).unwrap(),
v: Value_::Memory(MemoryLocation::Symbolic{
base: Some(x86_64::RIP.clone()),
label: glob.tag
label: pv.name.unwrap()
})
})
}
......
......@@ -81,7 +81,7 @@ pub type MuChildNode = MuIRNode;
pub type MuTypeNode = P<MuType>;
pub type MuFuncSigNode= P<MuFuncSig>;
pub type MuConstNode = P<Value>;
pub type MuGlobalNode = P<GlobalCell>;
pub type MuGlobalNode = P<Value>;
pub type MuFuncNode = RefCell<MuFunction>;
pub type MuFuncVerNode= RefCell<MuFunctionVersion>;
pub type MuBBNode = P<Block>;
......@@ -445,4 +445,5 @@ mu_entity!(MuFunction);
mu_entity!(MuFunctionVersion);
mu_entity!(Block);
mu_entity!(TreeNode);
mu_entity!(MuType);
\ No newline at end of file
mu_entity!(MuType);
mu_entity!(Value);
\ No newline at end of file
......@@ -8,7 +8,7 @@ pub struct MuBundle {
pub type_defs: HashMap<MuID, P<MuType>>,
pub func_sigs: HashMap<MuID, P<MuFuncSig>>,
pub constants: HashMap<MuID, P<Value>>,
pub globals : HashMap<MuID, P<GlobalCell>>,
pub globals : HashMap<MuID, P<Value>>,
pub func_defs: HashMap<MuID, MuFunction>,
pub func_decls: HashMap<MuID, MuFunctionVersion>,
......
......@@ -22,12 +22,11 @@ pub struct VM {
id_name_map: RwLock<HashMap<MuID, MuName>>,
name_id_map: RwLock<HashMap<MuName, MuID>>,
constants: RwLock<HashMap<MuName, P<Value>>>,
types: RwLock<HashMap<MuID, P<MuType>>>,
backend_type_info: RwLock<HashMap<P<MuType>, BackendTypeInfo>>,
globals: RwLock<HashMap<MuName, P<GlobalCell>>>,
constants: RwLock<HashMap<MuID, P<Value>>>,
globals: RwLock<HashMap<MuID, P<Value>>>,
func_sigs: RwLock<HashMap<MuName, P<MuFuncSig>>>,
func_vers: RwLock<HashMap<(MuID, MuID), RefCell<MuFunctionVersion>>>,
......@@ -79,28 +78,28 @@ impl <'a> VM {
self.is_running.load(Ordering::Relaxed)
}
pub fn declare_const(&self, id: MuID, const_name: MuName, ty: P<MuType>, val: Constant) -> P<Value> {
pub fn declare_const(&self, id: MuID, ty: P<MuType>, val: Constant) -> P<Value> {
let mut constants = self.constants.write().unwrap();
debug_assert!(!constants.contains_key(const_name));
debug_assert!(!constants.contains_key(&id));
let ret = P(Value{id: id, name: Some(const_name), ty: ty, v: Value_::Constant(val)});
constants.insert(const_name, ret.clone());
let ret = P(Value{id: id, name: None, ty: ty, v: Value_::Constant(val)});
constants.insert(id, ret.clone());
ret
}
pub fn declare_global(&self, id: MuID, global_name: MuName, ty: P<MuType>) -> P<Value> {
let global = P(GlobalCell{tag: global_name, ty: ty.clone()});
pub fn declare_global(&self, id: MuID, ty: P<MuType>) -> P<Value> {
let global = P(Value{
id: id,
name: None,
ty: P(MuType::new(self.next_id(), MuType_::iref(ty))),
v: Value_::Global
});
let mut globals = self.globals.write().unwrap();
globals.insert(global_name, global.clone());
globals.insert(id, global.clone());
P(Value{
id: id,
name: Some(global_name),
ty: P(MuType::new(self.next_id(), MuType_::iref(ty))),
v: Value_::Global(global.clone())
})
global
}
pub fn declare_type(&self, id: MuID, ty: MuType_) -> P<MuType> {
......@@ -190,7 +189,7 @@ impl <'a> VM {
*self.id_name_map.read().unwrap().get(&id).unwrap()
}
pub fn globals(&self) -> &RwLock<HashMap<MuName, P<GlobalCell>>> {
pub fn globals(&self) -> &RwLock<HashMap<MuID, P<Value>>> {
&self.globals
}
......
......@@ -40,8 +40,10 @@ pub fn sum() -> VM {
// .const @int_64_0 <@int_64> = 0
// .const @int_64_1 <@int_64> = 1
let const_def_int64_0 = vm.declare_const(vm.next_id(), "int64_0", type_def_int64.clone(), Constant::Int(0));
let const_def_int64_1 = vm.declare_const(vm.next_id(), "int64_1", type_def_int64.clone(), Constant::Int(1));
let mut const_def_int64_0 = vm.declare_const(vm.next_id(), type_def_int64.clone(), Constant::Int(0));
const_def_int64_0.set_name("int64_0");
let mut const_def_int64_1 = vm.declare_const(vm.next_id(), type_def_int64.clone(), Constant::Int(1));
const_def_int64_1.set_name("int64_1");
// .funcsig @sum_sig = (@int_64) -> (@int_64)
let sum_sig = vm.declare_func_sig("sum_sig", vec![type_def_int64.clone()], vec![type_def_int64.clone()]);
......@@ -201,7 +203,8 @@ pub fn factorial() -> VM {
type_def_int32.set_name("int32");
// .const @int_64_1 <@int_64> = 1
let const_def_int64_1 = vm.declare_const(vm.next_id(), "int64_1", type_def_int64.clone(), Constant::Int(1));
let mut const_def_int64_1 = vm.declare_const(vm.next_id(), type_def_int64.clone(), Constant::Int(1));
const_def_int64_1.set_name("int64_1");
// .funcsig @fac_sig = (@int_64) -> (@int_64)
let fac_sig = vm.declare_func_sig("fac_sig", vec![type_def_int64.clone()], vec![type_def_int64.clone()]);
......@@ -214,7 +217,8 @@ pub fn factorial() -> VM {
vm.declare_func(func);
// .funcdef @fac VERSION @fac_v1 <@fac_sig>
let const_func_fac = vm.declare_const(vm.next_id(), "fac", type_def_funcref_fac, Constant::FuncRef("fac"));
let mut const_func_fac = vm.declare_const(vm.next_id(), type_def_funcref_fac, Constant::FuncRef("fac"));
const_func_fac.set_name("fac");
let mut func_ver = MuFunctionVersion::new(vm.next_id(), func_id, fac_sig.clone());
// %blk_0(<@int_64> %n_3):
......@@ -359,11 +363,14 @@ pub fn global_access() -> VM {
// .const @int_64_0 <@int_64> = 0
// .const @int_64_1 <@int_64> = 1
let const_def_int64_0 = vm.declare_const(vm.next_id(), "int64_0", type_def_int64.clone(), Constant::Int(0));
let const_def_int64_1 = vm.declare_const(vm.next_id(), "int64_1", type_def_int64.clone(), Constant::Int(1));
let mut const_def_int64_0 = vm.declare_const(vm.next_id(), type_def_int64.clone(), Constant::Int(0));
const_def_int64_0.set_name("int64_0");
let mut const_def_int64_1 = vm.declare_const(vm.next_id(), type_def_int64.clone(), Constant::Int(1));
const_def_int64_1.set_name("int64_1");
// .global @a <@int_64>
let global_a = vm.declare_global(vm.next_id(), "a", type_def_int64.clone());
let mut global_a = vm.declare_global(vm.next_id(), type_def_int64.clone());
global_a.set_name("a");
// .funcsig @global_access_sig = () -> ()
let func_sig = vm.declare_func_sig("global_access_sig", vec![type_def_int64.clone()], vec![]);
......
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