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.7% of users enabled 2FA.

Commit a797959a authored by Kunshan Wang's avatar Kunshan Wang
Browse files

IRBuilder: Build sigs.

parent b362e1ec
......@@ -132,7 +132,8 @@ impl MuIRBuilder {
}
pub fn new_type_ufuncptr(&mut self, id: MuID, sig: MuID) {
panic!("Not implemented")
self.bundle.types.insert(id, Box::new(NodeType::TypeUFuncPtr{ id: id,
sig: sig }));
}
pub fn new_type_struct(&mut self, id: MuID, fieldtys: Vec<MuID>) {
......@@ -478,12 +479,22 @@ impl<'lb, 'lvm> BundleLoader<'lb, 'lvm> {
for (id, ref tag) in struct_id_tags {
self.fill_struct(id, tag)
}
for id in self.b.bundle.sigs.keys() {
if !self.visited.contains(id) {
self.build_sig(*id)
}
}
}
fn name_from_id(id: MuID, hint: &str) -> String {
format!("@uvm.unnamed{}{}", hint, id)
}
// fn maybe_get_name(&self, id: MuID) -> Option<String> {
// self.b.id_name_map.get(id).cloned()
// }
fn get_name_or_make(&self, id: MuID, hint: &str) -> String {
match self.b.id_name_map.get(&id) {
Some(n) => n.clone(),
......@@ -491,6 +502,10 @@ impl<'lb, 'lvm> BundleLoader<'lb, 'lvm> {
}
}
// fn make_mu_entity_header(&self, id: MuID, hint: &str) -> MuEntityHeader {
// MuEntityHeader::named(id, self.get_name_or_make(id, hint))
// }
fn build_type(&mut self, id: MuID) {
self.visited.insert(id);
......@@ -506,6 +521,10 @@ impl<'lb, 'lvm> BundleLoader<'lb, 'lvm> {
let toty_i = self.ensure_type_rec(toty);
MuType_::UPtr(toty_i)
},
NodeType::TypeUFuncPtr { id: _, sig: sig } => {
let sig_i = self.ensure_sig_rec(sig);
MuType_::UFuncPtr(sig_i)
},
NodeType::TypeStruct { id: _, fieldtys: _ } => {
let tag = self.get_name_or_make(id, "struct");
self.struct_id_tags.push((id, tag.clone()));
......@@ -565,5 +584,39 @@ impl<'lb, 'lvm> BundleLoader<'lb, 'lvm> {
ref t => panic!("{} {:?} should be a Struct type", id, ty),
}
}
fn build_sig(&mut self, id: MuID) {
self.visited.insert(id);
let sig = self.b.bundle.sigs.get(&id).unwrap();
trace!("Building function signature {} {:?}", id, sig);
let impl_sig = MuFuncSig{
hdr: MuEntityHeader::unnamed(id),
ret_tys: sig.rettys.iter().map(|i| self.ensure_type_rec(*i)).collect::<Vec<_>>(),
arg_tys: sig.paramtys.iter().map(|i| self.ensure_type_rec(*i)).collect::<Vec<_>>(),
};
trace!("Function signature built: {} {:?}", id, impl_sig);
self.built_sigs.insert(id, P(impl_sig));
}
fn ensure_sig_rec(&mut self, id: MuID) -> P<MuFuncSig> {
if self.b.bundle.sigs.contains_key(&id) {
if self.visited.contains(&id) {
match self.built_sigs.get(&id) {
Some(t) => t.clone(),
None => panic!("Cyclic signature found. id: {}", id)
}
} else {
self.build_sig(id);
self.built_sigs.get(&id).unwrap().clone()
}
} else {
self.vm.get_func_sig(id)
}
}
}
......@@ -102,6 +102,16 @@ fn test_types_sigs_loading() {
let mut fields = vec![id3, id7];
((*b).new_type_struct)(b, id6, fields.as_mut_ptr(), fields.len());
((*b).new_type_uptr)(b, id7, id6);
let id8 = ((*b).gen_sym)(b, csp.get("@sig1"));
let id9 = ((*b).gen_sym)(b, csp.get("@funcptr1"));
let mut ptys = vec![id1, id2];
let mut rtys = vec![id3, id7];
((*b).new_funcsig)(b, id8,
ptys.as_mut_ptr(), ptys.len(),
rtys.as_mut_ptr(), rtys.len());
((*b).new_type_ufuncptr)(b, id9, id8);
((*b).load)(b);
((*ctx).close_context)(ctx);
......
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