To protect your data, the CISO officer has suggested users to enable GitLab 2FA as soon as possible.

Commit b1f44703 authored by Yi Lin's avatar Yi Lin
Browse files

[wip] pass compilation on aarch64, cannot run though

parent c9b13533
...@@ -34,7 +34,7 @@ gcc = "*" ...@@ -34,7 +34,7 @@ gcc = "*"
ast = {path = "src/ast"} ast = {path = "src/ast"}
utils = {path = "src/utils"} utils = {path = "src/utils"}
gc = {path = "src/gc"} gc = {path = "src/gc"}
rodal = { git = "https://gitlab.anu.edu.au/mu/rodal", version = "0.0.2" } rodal = { git = "https://gitlab.anu.edu.au/mu/rodal", version = "*" }
libc="*" libc="*"
field-offset = "*" field-offset = "*"
libloading = "*" libloading = "*"
......
...@@ -25,4 +25,4 @@ utils = {path = "../utils"} ...@@ -25,4 +25,4 @@ utils = {path = "../utils"}
lazy_static = "*" lazy_static = "*"
log = "*" log = "*"
simple_logger = "*" simple_logger = "*"
rodal = { git = "https://gitlab.anu.edu.au/mu/rodal", version = "0.0.2" } rodal = { git = "https://gitlab.anu.edu.au/mu/rodal", version = "*" }
...@@ -1128,6 +1128,10 @@ pub enum MemoryLocation { ...@@ -1128,6 +1128,10 @@ pub enum MemoryLocation {
} }
} }
#[cfg(target_arch = "aarch64")]
rodal_enum!(MemoryLocation{{VirtualAddress: base, offset, signed, scale},
{Address: base, offset, shift, signed}, {Symbolic: label, is_global}});
#[cfg(target_arch = "aarch64")] #[cfg(target_arch = "aarch64")]
impl fmt::Display for MemoryLocation { impl fmt::Display for MemoryLocation {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
...@@ -1323,4 +1327,4 @@ impl MuEntity for TreeNode { ...@@ -1323,4 +1327,4 @@ impl MuEntity for TreeNode {
TreeNode_::Value(ref pv) => pv.as_entity() TreeNode_::Value(ref pv) => pv.as_entity()
} }
} }
} }
\ No newline at end of file
...@@ -2845,13 +2845,13 @@ pub fn emit_context_with_reloc(vm: &VM, ...@@ -2845,13 +2845,13 @@ pub fn emit_context_with_reloc(vm: &VM,
file.write_fmt(format_args!("{}:\n", dump_label)).unwrap(); file.write_fmt(format_args!("{}:\n", dump_label)).unwrap();
let base = obj_dump.reference_addr; let base = obj_dump.reference_addr;
let end = obj_dump.mem_start.plus(obj_dump.mem_size); let end = obj_dump.mem_start + obj_dump.mem_size;
assert!(base.is_aligned_to(POINTER_SIZE)); assert!(base.is_aligned_to(POINTER_SIZE));
let mut offset = 0; let mut offset = 0;
while offset < obj_dump.mem_size { while offset < obj_dump.mem_size {
let cur_addr = base.plus(offset); let cur_addr = base + offset;
if obj_dump.reference_offsets.contains(&offset) { if obj_dump.reference_offsets.contains(&offset) {
// write ref with label // write ref with label
...@@ -2874,7 +2874,7 @@ pub fn emit_context_with_reloc(vm: &VM, ...@@ -2874,7 +2874,7 @@ pub fn emit_context_with_reloc(vm: &VM,
file.write_fmt(format_args!(".xword {}\n", label.clone())).unwrap(); file.write_fmt(format_args!(".xword {}\n", label.clone())).unwrap();
} else { } else {
// write plain word (as bytes) // write plain word (as bytes)
let next_word_addr = cur_addr.plus(POINTER_SIZE); let next_word_addr = cur_addr + POINTER_SIZE;
if next_word_addr <= end { if next_word_addr <= end {
write_data_bytes(&mut file, cur_addr, next_word_addr); write_data_bytes(&mut file, cur_addr, next_word_addr);
...@@ -2930,7 +2930,7 @@ fn write_data_bytes(f: &mut File, from: Address, to: Address) { ...@@ -2930,7 +2930,7 @@ fn write_data_bytes(f: &mut File, from: Address, to: Address) {
let byte = unsafe {cursor.load::<u8>()}; let byte = unsafe {cursor.load::<u8>()};
f.write_fmt(format_args!("0x{:x}", byte)).unwrap(); f.write_fmt(format_args!("0x{:x}", byte)).unwrap();
cursor = cursor.plus(1); cursor = cursor + 1 as ByteSize;
if cursor != to { if cursor != to {
f.write(",".as_bytes()).unwrap(); f.write(",".as_bytes()).unwrap();
......
...@@ -2617,7 +2617,7 @@ impl <'a> InstructionSelection { ...@@ -2617,7 +2617,7 @@ impl <'a> InstructionSelection {
fn emit_alloc_sequence(&mut self, tmp_allocator: P<Value>, size: P<Value>, align: usize, node: &TreeNode, f_context: &mut FunctionContext, vm: &VM) -> P<Value> { fn emit_alloc_sequence(&mut self, tmp_allocator: P<Value>, size: P<Value>, align: usize, node: &TreeNode, f_context: &mut FunctionContext, vm: &VM) -> P<Value> {
if size.is_int_const() { if size.is_int_const() {
// size known at compile time, we can choose to emit alloc_small or large now // size known at compile time, we can choose to emit alloc_small or large now
let size_i = size.extract_int_const(); let size_i = size.extract_int_const().unwrap();
if size_i + OBJECT_HEADER_SIZE as u64 > mm::LARGE_OBJECT_THRESHOLD as u64 { if size_i + OBJECT_HEADER_SIZE as u64 > mm::LARGE_OBJECT_THRESHOLD as u64 {
self.emit_alloc_sequence_large(tmp_allocator, size, align, node, f_context, vm) self.emit_alloc_sequence_large(tmp_allocator, size, align, node, f_context, vm)
...@@ -2804,7 +2804,7 @@ impl <'a> InstructionSelection { ...@@ -2804,7 +2804,7 @@ impl <'a> InstructionSelection {
if hfa_n > 0 { if hfa_n > 0 {
let mut res = vec![get_alias_for_length(RETURN_FPRS[0].id(), get_bit_size(&t, vm)/hfa_n)]; let mut res = vec![get_alias_for_length(RETURN_FPRS[0].id(), get_bit_size(&t, vm)/hfa_n)];
for i in 1..hfa_n { for i in 1..hfa_n {
res.push(get_alias_for_length(RETURN_FPR[i].id(), get_bit_size(&t, vm)/hfa_n)); res.push(get_alias_for_length(RETURN_FPRS[i].id(), get_bit_size(&t, vm)/hfa_n));
} }
res res
} else if size <= 8 { } else if size <= 8 {
...@@ -2823,7 +2823,7 @@ impl <'a> InstructionSelection { ...@@ -2823,7 +2823,7 @@ impl <'a> InstructionSelection {
Void => vec![], // Nothing to return Void => vec![], // Nothing to return
Int(128) => // Return in 2 GPRs Int(128) => // Return in 2 GPRs
vec![RETURN_GPRs[0].clone(), RETURN_GPRs[0].clone()], vec![RETURN_GPRS[0].clone(), RETURN_GPRS[0].clone()],
// Integral or pointer type // Integral or pointer type
_ => _ =>
...@@ -2965,7 +2965,7 @@ impl <'a> InstructionSelection { ...@@ -2965,7 +2965,7 @@ impl <'a> InstructionSelection {
ngrn = round_up(ngrn, 2); // align NGRN to the next even number ngrn = round_up(ngrn, 2); // align NGRN to the next even number
if ngrn < 7 { if ngrn < 7 {
locations.push(ARGUMENT_GPRs[ngrn].clone()); locations.push(ARGUMENT_GPRS[ngrn].clone());
ngrn += 2; ngrn += 2;
} else { } else {
ngrn = 8; ngrn = 8;
...@@ -3286,8 +3286,13 @@ impl <'a> InstructionSelection { ...@@ -3286,8 +3286,13 @@ impl <'a> InstructionSelection {
// record exception block (CCall may have an exception block) // record exception block (CCall may have an exception block)
if cur_node.is_some() { if cur_node.is_some() {
let cur_node = cur_node.unwrap(); let cur_node = cur_node.unwrap();
if cur_node.op == OpCode::CCall { match cur_node.v {
unimplemented!() TreeNode_::Instruction(Instruction {v: Instruction_::CCall{..}, ..}) => {
unimplemented!()
}
_ => {
// wont have an exception branch, ignore
}
} }
} }
} }
...@@ -3526,8 +3531,8 @@ impl <'a> InstructionSelection { ...@@ -3526,8 +3531,8 @@ impl <'a> InstructionSelection {
let loc = emit_mem(self.backend.as_mut(), &loc, get_type_alignment(&reg.ty, vm), f_context, vm); let loc = emit_mem(self.backend.as_mut(), &loc, get_type_alignment(&reg.ty, vm), f_context, vm);
self.backend.emit_str_callee_saved(&loc, &reg); self.backend.emit_str_callee_saved(&loc, &reg);
} }
for i in 0..CALLEE_SAVED_FPRs.len() { for i in 0..CALLEE_SAVED_FPRS.len() {
let ref reg = CALLEE_SAVED_FPRs[i]; let ref reg = CALLEE_SAVED_FPRS[i];
trace!("allocate frame slot for reg {}", reg); trace!("allocate frame slot for reg {}", reg);
let loc = self.current_frame.as_mut().unwrap().alloc_slot_for_callee_saved_reg(reg.clone(), vm); let loc = self.current_frame.as_mut().unwrap().alloc_slot_for_callee_saved_reg(reg.clone(), vm);
...@@ -3669,7 +3674,7 @@ impl <'a> InstructionSelection { ...@@ -3669,7 +3674,7 @@ impl <'a> InstructionSelection {
match inst.v { match inst.v {
Instruction_::CmpOp(op, op1, ..) => { Instruction_::CmpOp(op, op1, ..) => {
if op::is_int_cmp(op) { if op.is_int_cmp() {
node_type(&ops[op1]).get_int_length().unwrap() == 128 && node_type(&ops[op1]).get_int_length().unwrap() == 128 &&
!op.is_symmetric() !op.is_symmetric()
} else { } else {
......
...@@ -44,6 +44,7 @@ use ast::op; ...@@ -44,6 +44,7 @@ use ast::op;
use compiler::backend::RegGroup; use compiler::backend::RegGroup;
use vm::VM; use vm::VM;
use utils::ByteSize;
use utils::LinkedHashMap; use utils::LinkedHashMap;
use std::collections::HashMap; use std::collections::HashMap;
...@@ -668,7 +669,7 @@ lazy_static! { ...@@ -668,7 +669,7 @@ lazy_static! {
// put caller saved regs first (they imposes no overhead if there is no call instruction) // put caller saved regs first (they imposes no overhead if there is no call instruction)
pub static ref ALL_USABLE_MACHINE_REGs : Vec<P<Value>> = vec![ pub static ref ALL_USABLE_MACHINE_REGS : Vec<P<Value>> = vec![
X0.clone(), X0.clone(),
X1.clone(), X1.clone(),
X2.clone(), X2.clone(),
...@@ -788,13 +789,13 @@ pub fn get_previous_frame_pointer(frame_pointer: Address) -> Address { ...@@ -788,13 +789,13 @@ pub fn get_previous_frame_pointer(frame_pointer: Address) -> Address {
// Gets the return address for the current frame pointer // Gets the return address for the current frame pointer
#[inline(always)] #[inline(always)]
pub fn get_return_address(frame_pointer: Address) -> Address { pub fn get_return_address(frame_pointer: Address) -> Address {
unsafe { frame_pointer.plus(8).load::<Address>() } unsafe { (frame_pointer + 8 as ByteSize).load::<Address>() }
} }
// Gets the stack pointer before the current frame was created // Gets the stack pointer before the current frame was created
#[inline(always)] #[inline(always)]
pub fn get_previous_stack_pointer(frame_pointer: Address) -> Address { pub fn get_previous_stack_pointer(frame_pointer: Address) -> Address {
frame_pointer.plus(16) frame_pointer + 16 as ByteSize
} }
#[inline(always)] #[inline(always)]
...@@ -805,16 +806,16 @@ pub fn set_previous_frame_pointer(frame_pointer: Address, value: Address) { ...@@ -805,16 +806,16 @@ pub fn set_previous_frame_pointer(frame_pointer: Address, value: Address) {
// Gets the return address for the current frame pointer // Gets the return address for the current frame pointer
#[inline(always)] #[inline(always)]
pub fn set_return_address(frame_pointer: Address, value: Address) { pub fn set_return_address(frame_pointer: Address, value: Address) {
unsafe { frame_pointer.plus(8).store::<Address>(value) } unsafe { (frame_pointer + 8 as ByteSize).store::<Address>(value) }
} }
// Reg should be a 64-bit callee saved GPR or FPR // Reg should be a 64-bit callee saved GPR or FPR
pub fn get_callee_saved_offset(reg: MuID) -> isize { pub fn get_callee_saved_offset(reg: MuID) -> isize {
debug_assert!(is_callee_saved(reg)); debug_assert!(is_callee_saved(reg));
let id = if reg < FPR_ID_START { let id = if reg < FPR_ID_START {
(reg - CALLEE_SAVED_GPRs[0].id())/2 (reg - CALLEE_SAVED_GPRS[0].id())/2
} else { } else {
(reg - CALLEE_SAVED_FPRs[0].id()) / 2 + CALLEE_SAVED_GPRs.len() (reg - CALLEE_SAVED_FPRS[0].id()) / 2 + CALLEE_SAVED_GPRS.len()
}; };
(id as isize + 1)*(-8) (id as isize + 1)*(-8)
} }
...@@ -1862,7 +1863,7 @@ fn emit_reg_value(backend: &mut CodeGenerator, pv: &P<Value>, f_context: &mut Fu ...@@ -1862,7 +1863,7 @@ fn emit_reg_value(backend: &mut CodeGenerator, pv: &P<Value>, f_context: &mut Fu
&Constant::FuncRef(func_id) => { &Constant::FuncRef(func_id) => {
let tmp = make_temporary(f_context, pv.ty.clone(), vm); let tmp = make_temporary(f_context, pv.ty.clone(), vm);
let mem = make_value_symbolic(vm.get_func_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, f_context, vm); emit_calculate_address(backend, &tmp, &mem, f_context, vm);
tmp tmp
}, },
...@@ -1922,7 +1923,7 @@ pub fn emit_ireg_value(backend: &mut CodeGenerator, pv: &P<Value>, f_context: &m ...@@ -1922,7 +1923,7 @@ pub fn emit_ireg_value(backend: &mut CodeGenerator, pv: &P<Value>, f_context: &m
&Constant::FuncRef(func_id) => { &Constant::FuncRef(func_id) => {
let tmp = make_temporary(f_context, pv.ty.clone(), vm); let tmp = make_temporary(f_context, pv.ty.clone(), vm);
let mem = make_value_symbolic(vm.get_func_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, f_context, vm); emit_calculate_address(backend, &tmp, &mem, f_context, vm);
tmp tmp
}, },
...@@ -2317,7 +2318,7 @@ fn memory_location_shift(backend: &mut CodeGenerator, mem: MemoryLocation, more_ ...@@ -2317,7 +2318,7 @@ fn memory_location_shift(backend: &mut CodeGenerator, mem: MemoryLocation, more_
if offset.is_some() { if offset.is_some() {
let offset = offset.as_ref().unwrap(); let offset = offset.as_ref().unwrap();
if match_value_int_imm(&offset) { if match_value_int_imm(&offset) {
let offset = offset.extract_int_const()*scale + (more_offset as u64); let offset = offset.extract_int_const().unwrap() *scale + (more_offset as u64);
make_value_int_const(offset as u64, vm) make_value_int_const(offset as u64, vm)
} else { } else {
let offset = emit_ireg_value(backend, &offset, f_context, vm); let offset = emit_ireg_value(backend, &offset, f_context, vm);
...@@ -2372,7 +2373,7 @@ fn memory_location_shift_scale(backend: &mut CodeGenerator, mem: MemoryLocation, ...@@ -2372,7 +2373,7 @@ fn memory_location_shift_scale(backend: &mut CodeGenerator, mem: MemoryLocation,
let offset = offset.as_ref().unwrap(); let offset = offset.as_ref().unwrap();
if match_value_int_imm(&offset) { if match_value_int_imm(&offset) {
let temp = make_temporary(f_context, offset.ty.clone(), vm); let temp = make_temporary(f_context, offset.ty.clone(), vm);
let offset_scaled = (offset.extract_int_const() as i64)*(scale as i64); let offset_scaled = (offset.extract_int_const().unwrap() as i64)*(scale as i64);
if offset_scaled % (new_scale as i64) == 0 { if offset_scaled % (new_scale as i64) == 0 {
emit_add_u64(backend, &temp, &more_offset, f_context, vm, (offset_scaled / (new_scale as i64)) as u64); emit_add_u64(backend, &temp, &more_offset, f_context, vm, (offset_scaled / (new_scale as i64)) as u64);
// new_scale*temp = (more_offset + (offset*scale)/new_scale) // new_scale*temp = (more_offset + (offset*scale)/new_scale)
......
...@@ -182,9 +182,9 @@ pub use compiler::backend::aarch64::emit_context_with_reloc; ...@@ -182,9 +182,9 @@ pub use compiler::backend::aarch64::emit_context_with_reloc;
#[cfg(target_arch = "aarch64")] #[cfg(target_arch = "aarch64")]
pub use compiler::backend::aarch64::spill_rewrite; pub use compiler::backend::aarch64::spill_rewrite;
#[cfg(target_arch = "aarch64")] #[cfg(target_arch = "aarch64")]
pub use compiler::backend::x86_64::ARGUMENT_GPRS; pub use compiler::backend::aarch64::ARGUMENT_GPRS;
#[cfg(target_arch = "aarch64")] #[cfg(target_arch = "aarch64")]
pub use compiler::backend::x86_64::ARGUMENT_FPRS; pub use compiler::backend::aarch64::ARGUMENT_FPRS;
use vm::VM; use vm::VM;
use ast::types::*; use ast::types::*;
...@@ -497,4 +497,4 @@ impl RegGroup { ...@@ -497,4 +497,4 @@ impl RegGroup {
pub fn get_from_value(val: &P<Value>) -> RegGroup { pub fn get_from_value(val: &P<Value>) -> RegGroup {
RegGroup::get_from_ty(&val.ty) RegGroup::get_from_ty(&val.ty)
} }
} }
\ No newline at end of file
...@@ -38,4 +38,4 @@ simple_logger = "*" ...@@ -38,4 +38,4 @@ simple_logger = "*"
aligned_alloc = "*" aligned_alloc = "*"
crossbeam = "*" crossbeam = "*"
field-offset = "*" field-offset = "*"
rodal = { git = "https://gitlab.anu.edu.au/mu/rodal", version = "0.0.2" } rodal = { git = "https://gitlab.anu.edu.au/mu/rodal", version = "*" }
...@@ -24,6 +24,6 @@ crate-type = ["rlib"] ...@@ -24,6 +24,6 @@ crate-type = ["rlib"]
memmap = "*" memmap = "*"
memsec = "0.1.9" memsec = "0.1.9"
byteorder = "*" byteorder = "*"
rodal = { git = "https://gitlab.anu.edu.au/mu/rodal", version = "0.0.2" } rodal = { git = "https://gitlab.anu.edu.au/mu/rodal", version = "*" }
log = "*" log = "*"
doubly = "1.1.3" doubly = "1.1.3"
\ No newline at end of file
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