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 28f4ed79 authored by Isaac Oscar Gariano's avatar Isaac Oscar Gariano
Browse files

Fixed bugs and formatting

parent 4202cd93
......@@ -424,7 +424,7 @@ const PRINT_INST_NAME: bool = false;
impl fmt::Display for Instruction {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let ref ops = self.ops;
let value = match &self.value{
let value = match &self.value {
&Some(ref v) if v.len() == 0 => format!(""),
&Some(ref v) if v.len() == 1 => format!("{} = ", v[0]),
&Some(ref v) => format!("({}) = ", vec_utils::as_str_sp(&v)),
......@@ -718,11 +718,22 @@ pub enum Instruction_ {
impl Instruction_ {
fn debug_str(&self, ops: &Vec<P<TreeNode>>) -> String {
match self {
&Instruction_::BinOp(op, op1, op2) => format!("{}<{}> {} {}", op, ops[op1].ty(), ops[op1], ops[op2]),
&Instruction_::BinOp(op, op1, op2) => {
format!("{}<{}> {} {}", op, ops[op1].ty(), ops[op1], ops[op2])
}
&Instruction_::BinOpWithStatus(op, status, op1, op2) => {
format!("{}{}<{}> {} {}", op, status, ops[op1].ty(), ops[op1], ops[op2])
format!(
"{}{}<{}> {} {}",
op,
status,
ops[op1].ty(),
ops[op1],
ops[op2]
)
}
&Instruction_::CmpOp(op, op1, op2) => {
format!("{}<{}> {} {}", op, ops[op1].ty(), ops[op1], ops[op2])
}
&Instruction_::CmpOp(op, op1, op2) => format!("{}<{}> {} {}", op, ops[op1].ty(), ops[op1], ops[op2]),
&Instruction_::ConvOp {
operation,
ref from_ty,
......@@ -747,7 +758,13 @@ impl Instruction_ {
order
} => {
let ptr = select_value!(is_ptr, " PTR", "");
format!("LOAD{} {}<{}> {}", ptr, order, ops[mem_loc].ty().get_referent_ty().unwrap(), ops[mem_loc])
format!(
"LOAD{} {}<{}> {}",
ptr,
order,
ops[mem_loc].ty().get_referent_ty().unwrap(),
ops[mem_loc]
)
}
&Instruction_::Store {
value,
......@@ -756,7 +773,14 @@ impl Instruction_ {
order
} => {
let ptr = select_value!(is_ptr, " PTR", "");
format!("STORE{} {}<{}> {} {}", ptr, order, ops[mem_loc].ty().get_referent_ty().unwrap(), ops[mem_loc], ops[value])
format!(
"STORE{} {}<{}> {} {}",
ptr,
order,
ops[mem_loc].ty().get_referent_ty().unwrap(),
ops[mem_loc],
ops[value]
)
}
&Instruction_::CmpXchg {
is_ptr,
......@@ -801,9 +825,19 @@ impl Instruction_ {
}
&Instruction_::New(ref ty) => format!("NEW<{}>", ty),
&Instruction_::AllocA(ref ty) => format!("ALLOCA<{}>", ty),
&Instruction_::NewHybrid(ref ty, len) => format!("NEWHYBRID<{} {}> {}", ty, ops[len].ty(), ops[len]),
&Instruction_::AllocAHybrid(ref ty, len) => format!("ALLOCAHYBRID<{} {}> {}", ty, ops[len].ty(), ops[len]),
&Instruction_::NewStack(func) => format!("COMMINST @uvm.new_stack<[{}]>({})", ops[func].ty().get_sig().unwrap(), ops[func]),
&Instruction_::NewHybrid(ref ty, len) => {
format!("NEWHYBRID<{} {}> {}", ty, ops[len].ty(), ops[len])
}
&Instruction_::AllocAHybrid(ref ty, len) => {
format!("ALLOCAHYBRID<{} {}> {}", ty, ops[len].ty(), ops[len])
}
&Instruction_::NewStack(func) => {
format!(
"COMMINST @uvm.new_stack<[{}]>({})",
ops[func].ty().get_sig().unwrap(),
ops[func]
)
}
&Instruction_::NewThread {
stack,
thread_local,
......@@ -821,15 +855,29 @@ impl Instruction_ {
new_stack_clause,
)
}
&Instruction_::NewFrameCursor(stack) => format!("COMMINST @uvm.meta.new_cursor({})", ops[stack]),
&Instruction_::GetIRef(reference) => format!("GETIREF<{}> {}", ops[reference].ty().get_referent_ty().unwrap(), ops[reference]),
&Instruction_::NewFrameCursor(stack) => {
format!("COMMINST @uvm.meta.new_cursor({})", ops[stack])
}
&Instruction_::GetIRef(reference) => {
format!(
"GETIREF<{}> {}",
ops[reference].ty().get_referent_ty().unwrap(),
ops[reference]
)
}
&Instruction_::GetFieldIRef {
is_ptr,
base,
index
} => {
let ptr = select_value!(is_ptr, " PTR", "");
format!("GETFIELDIREF{}<{} {}> {}", ptr, ops[base].ty().get_referent_ty().unwrap(), index, ops[base])
format!(
"GETFIELDIREF{}<{} {}> {}",
ptr,
ops[base].ty().get_referent_ty().unwrap(),
index,
ops[base]
)
}
&Instruction_::GetElementIRef {
is_ptr,
......@@ -837,7 +885,14 @@ impl Instruction_ {
index
} => {
let ptr = select_value!(is_ptr, " PTR", "");
format!("GETELEMIREF{}<{} {}>{} {}", ptr, ops[base].ty().get_referent_ty().unwrap(), ops[index].ty(), ops[base], ops[index])
format!(
"GETELEMIREF{}<{} {}>{} {}",
ptr,
ops[base].ty().get_referent_ty().unwrap(),
ops[index].ty(),
ops[base],
ops[index]
)
}
&Instruction_::ShiftIRef {
is_ptr,
......@@ -845,11 +900,23 @@ impl Instruction_ {
offset
} => {
let ptr = select_value!(is_ptr, " PTR", "");
format!("GETELEMIREF{}<{} {}>{} {}", ptr, ops[base].ty().get_referent_ty().unwrap(), ops[offset].ty(), ops[base], ops[offset])
format!(
"GETELEMIREF{}<{} {}>{} {}",
ptr,
ops[base].ty().get_referent_ty().unwrap(),
ops[offset].ty(),
ops[base],
ops[offset]
)
}
&Instruction_::GetVarPartIRef { is_ptr, base } => {
let ptr = select_value!(is_ptr, " PTR", "");
format!("GETVARPARTIREF{}<{}> {}", ptr, ops[base].ty().get_referent_ty().unwrap(), ops[base])
format!(
"GETVARPARTIREF{}<{}> {}",
ptr,
ops[base].ty().get_referent_ty().unwrap(),
ops[base]
)
}
&Instruction_::Fence(order) => format!("FENCE {}", order),
......@@ -862,7 +929,7 @@ impl Instruction_ {
} else {
format!("RET ({})", op_vector_str(vals, ops))
}
},
}
&Instruction_::ThreadExit => "COMMINST @uvm.thread_exit".to_string(),
&Instruction_::CurrentStack => "COMMINST @uvm.current_stack".to_string(),
&Instruction_::KillStack(s) => format!("COMMINST @uvm.kill_stack({})", ops[s]),
......@@ -982,7 +1049,12 @@ impl Instruction_ {
ref branches
} => {
//SWITCH < T > opnd default { ( value dest ) rep }
let mut ret = format!("SWITCH<{}> {} {} {{", ops[cond].ty(), ops[cond], default.debug_str(ops));
let mut ret = format!(
"SWITCH<{}> {} {} {{",
ops[cond].ty(),
ops[cond],
default.debug_str(ops)
);
for i in 0..branches.len() {
let (op, ref dest) = branches[i];
ret.push_str(format!("{} {}", ops[op], dest.debug_str(ops)).as_str());
......@@ -1005,13 +1077,29 @@ impl Instruction_ {
format!("COMMINST @uvm.set_threadlocal({})", ops[op])
}
&Instruction_::CommonInst_Pin(op) => format!("COMMINST @uvm.native.pin<{}>({})", ops[op].ty(), ops[op]),
&Instruction_::CommonInst_Unpin(op) => format!("COMMINST @uvm.native.unpin<{}>({})", ops[op].ty(), ops[op]),
&Instruction_::CommonInst_GetAddr(op) => format!("COMMINST @uvm.native.get_addr<{}>({})", ops[op].ty(), ops[op]),
&Instruction_::CommonInst_Pin(op) => {
format!("COMMINST @uvm.native.pin<{}>({})", ops[op].ty(), ops[op])
}
&Instruction_::CommonInst_Unpin(op) => {
format!("COMMINST @uvm.native.unpin<{}>({})", ops[op].ty(), ops[op])
}
&Instruction_::CommonInst_GetAddr(op) => {
format!(
"COMMINST @uvm.native.get_addr<{}>({})",
ops[op].ty(),
ops[op]
)
}
// Tagerf64
&Instruction_::CommonInst_Tr64IsFp(op) => format!("COMMINST @uvm.tr64.is_fp({})", ops[op]),
&Instruction_::CommonInst_Tr64IsInt(op) => format!("COMMINST @uvm.tr64.is_int({})", ops[op]),
&Instruction_::CommonInst_Tr64IsRef(op) => format!("COMMINST @uvm.tr64.is_ref({})", ops[op]),
&Instruction_::CommonInst_Tr64IsFp(op) => {
format!("COMMINST @uvm.tr64.is_fp({})", ops[op])
}
&Instruction_::CommonInst_Tr64IsInt(op) => {
format!("COMMINST @uvm.tr64.is_int({})", ops[op])
}
&Instruction_::CommonInst_Tr64IsRef(op) => {
format!("COMMINST @uvm.tr64.is_ref({})", ops[op])
}
&Instruction_::CommonInst_Tr64FromFp(op) => {
format!("COMMINST @uvm.tr64.from_fp({})", ops[op])
}
......@@ -1021,10 +1109,18 @@ impl Instruction_ {
&Instruction_::CommonInst_Tr64FromRef(op1, op2) => {
format!("COMMINST @uvm.tr64.from_ref({} {})", ops[op1], ops[op2])
}
&Instruction_::CommonInst_Tr64ToFp(op) => format!("COMMINST @uvm.tr64.to_fp({})", ops[op]),
&Instruction_::CommonInst_Tr64ToInt(op) => format!("COMMINST @uvm.tr64.to_int({})", ops[op]),
&Instruction_::CommonInst_Tr64ToRef(op) => format!("COMMINST @uvm.tr64.to_ref({})", ops[op]),
&Instruction_::CommonInst_Tr64ToTag(op) => format!("COMMINST @uvm.tr64.to_tag({})", ops[op]),
&Instruction_::CommonInst_Tr64ToFp(op) => {
format!("COMMINST @uvm.tr64.to_fp({})", ops[op])
}
&Instruction_::CommonInst_Tr64ToInt(op) => {
format!("COMMINST @uvm.tr64.to_int({})", ops[op])
}
&Instruction_::CommonInst_Tr64ToRef(op) => {
format!("COMMINST @uvm.tr64.to_ref({})", ops[op])
}
&Instruction_::CommonInst_Tr64ToTag(op) => {
format!("COMMINST @uvm.tr64.to_tag({})", ops[op])
}
// move
&Instruction_::Move(from) => format!("MOVE<{}> {}", ops[from].ty(), ops[from]),
......@@ -1035,7 +1131,11 @@ impl Instruction_ {
}
}
}
fn format_new_stack_clause(is_exception: bool, args: &Vec<OpIndex>, ops: &Vec<P<TreeNode>>) -> String {
fn format_new_stack_clause(
is_exception: bool,
args: &Vec<OpIndex>,
ops: &Vec<P<TreeNode>>
) -> String {
if is_exception {
assert!(args.len() == 1);
format!("THROW_EXC {}", ops[args[0]])
......@@ -1167,7 +1267,9 @@ pub enum MemoryOrder {
impl fmt::Display for MemoryOrder {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use self::MemoryOrder::*;
write!(f, "{}",
write!(
f,
"{}",
match *self {
NotAtomic => "",
Relaxed => "RELAXED",
......@@ -1193,7 +1295,7 @@ impl fmt::Display for CallConvention {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
if *self == C_CALL_CONVENTION {
write!(f, "#DEFAULT")
} else if *self == MU_CALL_CONVENTION{
} else if *self == MU_CALL_CONVENTION {
write!(f, "#MU")
} else {
unimplemented!()
......@@ -1216,7 +1318,11 @@ pub struct CallData {
impl CallData {
fn debug_str(&self, ops: &Vec<P<TreeNode>>) -> String {
let func = &ops[self.func];
let conv = if self.convention == CallConvention::Mu { "".to_string() } else { format!(" {}", self.convention) };
let conv = if self.convention == CallConvention::Mu {
"".to_string()
} else {
format!(" {}", self.convention)
};
format!(
"{}<{}> {} ({})",
conv,
......
......@@ -1253,11 +1253,11 @@ impl fmt::Display for Constant {
&Constant::IntEx(ref v) => {
let mut res = format!("");
// Stored in little-endian order, but we need to display it in big-endian order
for i in 1 .. v.len() + 1 {
for i in 1..v.len() + 1 {
res.push_str(format!("{:016X}", v[v.len() - i]).to_string().as_str());
}
write!(f, "0x{}", res)
},
}
&Constant::Float(v) => write!(f, "{}", v),
&Constant::Double(v) => write!(f, "{}", v),
// &Constant::IRef(v) => write!(f, "{}", v),
......@@ -1576,8 +1576,12 @@ impl MuEntityHeader {
}
/// an abbreviate (easy reading) version of the name
fn abbreviate_name(&self) -> String {
self.name.split('.').last().unwrap().to_string()
pub fn abbreviate_name(&self) -> String {
if PRINT_ABBREVIATE_NAME {
self.name.split('.').last().unwrap().to_string()
} else {
(*self.name()).clone()
}
}
pub fn clone_with_id(&self, new_id: MuID) -> MuEntityHeader {
......@@ -1597,17 +1601,9 @@ impl PartialEq for MuEntityHeader {
impl fmt::Display for MuEntityHeader {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
if DISPLAY_ID {
if PRINT_ABBREVIATE_NAME {
write!(f, "{} #{}", self.abbreviate_name(), self.id)
} else {
write!(f, "{} #{}", self.name(), self.id)
}
write!(f, "{} #{}", self.abbreviate_name(), self.id)
} else {
if PRINT_ABBREVIATE_NAME {
write!(f, "{}", self.abbreviate_name())
} else {
write!(f, "{}", self.name())
}
write!(f, "{}", self.abbreviate_name())
}
}
}
......
......@@ -393,7 +393,7 @@ impl MuType {
/// gets the signature of a funcref or ufuncptr type
pub fn get_sig(&self) -> Option<P<MuFuncSig>> {
match self.v {
MuType_::FuncRef(ref sig) | MuType_::UFuncPtr(ref sig)=> Some(sig.clone()),
MuType_::FuncRef(ref sig) | MuType_::UFuncPtr(ref sig) => Some(sig.clone()),
_ => None
}
}
......
......@@ -4853,7 +4853,8 @@ impl<'a> InstructionSelection {
);
if resumption.is_some() {
self.backend.emit_b(resumption.as_ref().unwrap().normal_dest.target.name());
self.backend
.emit_b(resumption.as_ref().unwrap().normal_dest.target.name());
}
}
}
......
......@@ -2064,8 +2064,12 @@ pub fn emit_ireg_value(
&Constant::FuncRef(ref func) => {
let tmp = make_temporary(f_context, pv.ty.clone(), vm);
let mem =
make_value_symbolic(vm.get_name_for_func(func.id()), true, &ADDRESS_TYPE, vm);
let mem = make_value_symbolic(
vm.get_name_for_func(func.id()),
true,
&ADDRESS_TYPE,
vm
);
emit_calculate_address(backend, &tmp, &mem, vm);
tmp
}
......
......@@ -4558,7 +4558,8 @@ impl<'a> InstructionSelection {
// jump to target block
if resumption.is_some() {
self.backend.emit_jmp(resumption.as_ref().unwrap().normal_dest.target.name());
self.backend
.emit_jmp(resumption.as_ref().unwrap().normal_dest.target.name());
}
}
......
......@@ -162,7 +162,12 @@ pub fn emit_mu_globals(suffix: &str, vm: &VM) {
let global_guard = vm.globals().read().unwrap();
for g in global_guard.values() {
write!(file, ".global {}<{}>", g.name(), g.ty.get_referent_ty().unwrap()).unwrap();
write!(
file,
".global {}<{}>",
g.name(),
g.ty.get_referent_ty().unwrap()
).unwrap();
}
}
}
......
......@@ -100,7 +100,7 @@ fn emit_muir_dot_inner(file: &mut File, f_name: MuName, f_content: &FunctionCont
// every graph node (basic block)
for (id, block) in f_content.blocks.iter() {
let block_name = block.name();
let block_name = block.hdr.abbreviate_name();
// BBid [label = "name
write!(file, "BB{} [label = \"{}", *id, &block_name).unwrap();
let block_content = block.content.as_ref().unwrap();
......@@ -122,7 +122,7 @@ fn emit_muir_dot_inner(file: &mut File, f_name: MuName, f_content: &FunctionCont
write!(file, "[{}]", block_content.exn_arg.as_ref().unwrap()).unwrap();
}
write!(file, ":\\l{{\\l").unwrap();
write!(file, ":\\l").unwrap();
// all the instructions
for inst in block_content.body.iter() {
......@@ -130,7 +130,7 @@ fn emit_muir_dot_inner(file: &mut File, f_name: MuName, f_content: &FunctionCont
}
// "];
writeln!(file, "\\}}\\l\"];").unwrap();
writeln!(file, "\"];").unwrap();
}
// every edge
......
......@@ -214,7 +214,8 @@ impl Inlining {
);
// creates a new block ID
// which will be the entry block for the inlined function
let new_inlined_entry_hdr = new_inlined_block_name(inlined_fv_content.get_entry_block().name(), vm);
let new_inlined_entry_hdr =
new_inlined_block_name(inlined_fv_content.get_entry_block().name(), vm);
// change current call instruction to a branch
trace!("turning CALL instruction into a branch");
let ref ops = inst.ops;
......@@ -390,7 +391,10 @@ impl Inlining {
fn new_inlined_block_name(old_block_name: MuName, vm: &VM) -> MuEntityHeader {
let new_id = vm.next_id();
MuEntityHeader::named(new_id, Arc::new(format!("{}:inlinedblock.#{}", old_block_name, new_id)))
MuEntityHeader::named(
new_id,
Arc::new(format!("{}:inlinedblock.#{}", old_block_name, new_id))
)
}
/// copies blocks from callee to caller, with specified entry block and return block
fn copy_inline_blocks(
......
......@@ -95,12 +95,18 @@ fn emit_uir(suffix: &str, func_ver: &MuFunctionVersion, vm: &VM) {
fn emit_uir_inner(file: &mut File, func_name: MuName, func_ver: &MuFunctionVersion) {
let f_content = func_ver.content.as_ref().unwrap();
writeln!(file, ".funcdef {} <{}> VERSION {}{{", func_name, func_ver.sig, func_ver.name()).unwrap();
// self.abbreviate_name()
writeln!(
file,
".funcdef {} <{}> VERSION {}",
func_name,
func_ver.sig,
func_ver.hdr.abbreviate_name()
).unwrap();
writeln!(file, "{{").unwrap();
// every basic block
for (_, block) in f_content.blocks.iter() {
write!(file, "\t{}", block.name()).unwrap();
write!(file, "\t{}", block.hdr.abbreviate_name()).unwrap();
let block_content = block.content.as_ref().unwrap();
// (args)
write!(file, "(").unwrap();
......@@ -119,15 +125,13 @@ fn emit_uir_inner(file: &mut File, func_name: MuName, func_ver: &MuFunctionVersi
}
writeln!(file, ":").unwrap();
writeln!(file, "\t{{").unwrap();
// all the instructions
for inst in block_content.body.iter() {
writeln!(file, "\t\t{}", inst.as_inst_ref()).unwrap();
}
// "];
writeln!(file, "\n\t}}").unwrap();
writeln!(file, "").unwrap();
}
writeln!(file, "}}").unwrap();
}
......
......@@ -30,4 +30,4 @@ mod test_inline;
mod test_convop;
mod test_int128;
mod test_misc;
mod test_opt;
\ No newline at end of file
mod test_opt;
......@@ -912,7 +912,7 @@ pub fn hybrid_var_part_insts() -> VM {
ssa! ((vm, hybrid_var_part_insts_v1) <int64> blk_head_sum);
ssa! ((vm, hybrid_var_part_insts_v1) <int64> blk_head_n);
ssa! ((vm, hybrid_var_part_insts_v1) <int64> blk_head_i);
ssa! ((vm, hybrid_var_part_insts_v1) <int64> blk_head_a);
ssa! ((vm, hybrid_var_part_insts_v1) <ref_hybrid> blk_head_a);
// %cond = SLT <@int64> %i %n
ssa! ((vm, hybrid_var_part_insts_v1) <int1> blk_head_cond);
......@@ -940,7 +940,7 @@ pub fn hybrid_var_part_insts() -> VM {
ssa! ((vm, hybrid_var_part_insts_v1) <int64> blk_body_sum);
ssa! ((vm, hybrid_var_part_insts_v1) <int64> blk_body_n);
ssa! ((vm, hybrid_var_part_insts_v1) <int64> blk_body_i);
ssa! ((vm, hybrid_var_part_insts_v1) <int64> blk_body_a);
ssa! ((vm, hybrid_var_part_insts_v1) <ref_hybrid> blk_body_a);
// %blk_body_iref_a = GETIREF <@my_hybrid> a
ssa! ((vm, hybrid_var_part_insts_v1) <iref_hybrid> blk_body_iref_a);
......
......@@ -143,4 +143,4 @@ fn infinite_loop2() -> VM {
});
vm
}
\ No newline at end of file
}
......@@ -114,7 +114,7 @@ fn test_type_constructors() {
assert_type!(*types[4], "iref<int<8>>");
assert_type!(*types[5], "weakref<int<8>>");
assert_type!(*types[6], "uptr<int<8>>");
assert_type!(*types[7], "MyStructTag1(struct)");
assert_type!(*types[7], "MyStructTag1");
{
let map = STRUCT_TAG_MAP.read().unwrap();
let t7_struct_ty = map.get(&"MyStructTag1".to_string()).unwrap();
......@@ -152,7 +152,7 @@ fn test_cyclic_struct() {
let map = STRUCT_TAG_MAP.read().unwrap();
let struct_ty = map.get(&"MyStructTag2".to_string()).unwrap();
assert_type!(struct_ty, "struct<ref<MyStructTag2(struct)> int<32>>");
assert_type!(struct_ty, "struct<ref<MyStructTag2> int<32>>");
}
#[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