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

Converted line endings to UNIX style

parent 83f6e292
...@@ -7,7 +7,7 @@ Cargo.lock ...@@ -7,7 +7,7 @@ Cargo.lock
*.log *.log
*.DS_Store *.DS_Store
*.swp *.swp
.idea .idea
*.pyc *.pyc
*.o *.o
*.dylib *.dylib
......
This diff is collapsed.
use ast::ir::*; use ast::ir::*;
use ast::ptr::*; use ast::ptr::*;
use ast::types::*; use ast::types::*;
use runtime::ValueLocation; use runtime::ValueLocation;
use std::fmt; use std::fmt;
use std::collections::HashMap; use std::collections::HashMap;
use utils::POINTER_SIZE; use utils::POINTER_SIZE;
use vm::VM; use vm::VM;
// | previous frame ... // | previous frame ...
// |--------------- // |---------------
// | return address // | return address
// | old RBP <- RBP // | old RBP <- RBP
// | callee saved // | callee saved
// | spilled // | spilled
// |--------------- // |---------------
// | alloca area // | alloca area
#[derive(RustcEncodable, RustcDecodable, Clone)] #[derive(RustcEncodable, RustcDecodable, Clone)]
pub struct Frame { pub struct Frame {
func_ver_id: MuID, func_ver_id: MuID,
cur_offset: isize, // offset to frame base pointer cur_offset: isize, // offset to frame base pointer
pub argument_by_reg: HashMap<MuID, P<Value>>, pub argument_by_reg: HashMap<MuID, P<Value>>,
pub argument_by_stack: HashMap<MuID, P<Value>>, pub argument_by_stack: HashMap<MuID, P<Value>>,
pub allocated: HashMap<MuID, FrameSlot>, pub allocated: HashMap<MuID, FrameSlot>,
// (callsite, destination address) // (callsite, destination address)
exception_callsites: Vec<(ValueLocation, ValueLocation)> exception_callsites: Vec<(ValueLocation, ValueLocation)>
} }
impl fmt::Display for Frame { impl fmt::Display for Frame {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
writeln!(f, "\nFrame for FuncVer {} {{", self.func_ver_id).unwrap(); writeln!(f, "\nFrame for FuncVer {} {{", self.func_ver_id).unwrap();
writeln!(f, " allocated slots:").unwrap(); writeln!(f, " allocated slots:").unwrap();
for slot in self.allocated.values() { for slot in self.allocated.values() {
writeln!(f, " {}", slot).unwrap(); writeln!(f, " {}", slot).unwrap();
} }
writeln!(f, " exception callsites:").unwrap(); writeln!(f, " exception callsites:").unwrap();
for &(ref callsite, ref dest) in self.exception_callsites.iter() { for &(ref callsite, ref dest) in self.exception_callsites.iter() {
writeln!(f, " callsite: {} -> {}", callsite, dest).unwrap() writeln!(f, " callsite: {} -> {}", callsite, dest).unwrap()
} }
writeln!(f, " cur offset: {}", self.cur_offset).unwrap(); writeln!(f, " cur offset: {}", self.cur_offset).unwrap();
writeln!(f, "}}") writeln!(f, "}}")
} }
} }
impl Frame { impl Frame {
pub fn new(func_ver_id: MuID) -> Frame { pub fn new(func_ver_id: MuID) -> Frame {
Frame { Frame {
func_ver_id: func_ver_id, func_ver_id: func_ver_id,
cur_offset: - (POINTER_SIZE as isize * 1), // reserve for old RBP cur_offset: - (POINTER_SIZE as isize * 1), // reserve for old RBP
argument_by_reg: HashMap::new(), argument_by_reg: HashMap::new(),
argument_by_stack: HashMap::new(), argument_by_stack: HashMap::new(),
allocated: HashMap::new(), allocated: HashMap::new(),
exception_callsites: vec![] exception_callsites: vec![]
} }
} }
#[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))] #[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))]
pub fn cur_size(&self) -> usize { pub fn cur_size(&self) -> usize {
// frame size is a multiple of 16 bytes // frame size is a multiple of 16 bytes
let size = self.cur_offset.abs() as usize; let size = self.cur_offset.abs() as usize;
// align size to a multiple of 16 bytes // align size to a multiple of 16 bytes
let size = (size + 16 - 1) & !(16 - 1); let size = (size + 16 - 1) & !(16 - 1);
debug_assert!(size % 16 == 0); debug_assert!(size % 16 == 0);
size size
} }
pub fn add_argument_by_reg(&mut self, temp: MuID, reg: P<Value>) { pub fn add_argument_by_reg(&mut self, temp: MuID, reg: P<Value>) {
self.argument_by_reg.insert(temp, reg); self.argument_by_reg.insert(temp, reg);
} }
pub fn add_argument_by_stack(&mut self, temp: MuID, stack_slot: P<Value>) { pub fn add_argument_by_stack(&mut self, temp: MuID, stack_slot: P<Value>) {
self.argument_by_stack.insert(temp, stack_slot); self.argument_by_stack.insert(temp, stack_slot);
} }
pub fn alloc_slot_for_callee_saved_reg(&mut self, reg: P<Value>, vm: &VM) -> P<Value> { pub fn alloc_slot_for_callee_saved_reg(&mut self, reg: P<Value>, vm: &VM) -> P<Value> {
let slot = self.alloc_slot(&reg, vm); let slot = self.alloc_slot(&reg, vm);
slot.make_memory_op(reg.ty.clone(), vm) slot.make_memory_op(reg.ty.clone(), vm)
} }
pub fn remove_record_for_callee_saved_reg(&mut self, reg: MuID) { pub fn remove_record_for_callee_saved_reg(&mut self, reg: MuID) {
self.allocated.remove(&reg); self.allocated.remove(&reg);
} }
pub fn alloc_slot_for_spilling(&mut self, reg: P<Value>, vm: &VM) -> P<Value> { pub fn alloc_slot_for_spilling(&mut self, reg: P<Value>, vm: &VM) -> P<Value> {
let slot = self.alloc_slot(&reg, vm); let slot = self.alloc_slot(&reg, vm);
slot.make_memory_op(reg.ty.clone(), vm) slot.make_memory_op(reg.ty.clone(), vm)
} }
pub fn get_exception_callsites(&self) -> &Vec<(ValueLocation, ValueLocation)> { pub fn get_exception_callsites(&self) -> &Vec<(ValueLocation, ValueLocation)> {
&self.exception_callsites &self.exception_callsites
} }
pub fn add_exception_callsite(&mut self, callsite: ValueLocation, dest: ValueLocation) { pub fn add_exception_callsite(&mut self, callsite: ValueLocation, dest: ValueLocation) {
trace!("add exception callsite: {} to dest {}", callsite, dest); trace!("add exception callsite: {} to dest {}", callsite, dest);
self.exception_callsites.push((callsite, dest)); self.exception_callsites.push((callsite, dest));
} }
fn alloc_slot(&mut self, val: &P<Value>, vm: &VM) -> &FrameSlot { fn alloc_slot(&mut self, val: &P<Value>, vm: &VM) -> &FrameSlot {
let id = val.id(); let id = val.id();
let ret = FrameSlot { let ret = FrameSlot {
offset: self.cur_offset, offset: self.cur_offset,
value: val.clone() value: val.clone()
}; };
self.cur_offset -= vm.get_type_size(val.ty.id()) as isize; self.cur_offset -= vm.get_type_size(val.ty.id()) as isize;
self.allocated.insert(id, ret); self.allocated.insert(id, ret);
self.allocated.get(&id).unwrap() self.allocated.get(&id).unwrap()
} }
} }
#[derive(RustcEncodable, RustcDecodable, Clone)] #[derive(RustcEncodable, RustcDecodable, Clone)]
pub struct FrameSlot { pub struct FrameSlot {
pub offset: isize, pub offset: isize,
pub value: P<Value> pub value: P<Value>
} }
impl fmt::Display for FrameSlot { impl fmt::Display for FrameSlot {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}(RBP): {}", self.offset, self.value) write!(f, "{}(RBP): {}", self.offset, self.value)
} }
} }
impl FrameSlot { impl FrameSlot {
#[cfg(target_arch = "x86_64")] #[cfg(target_arch = "x86_64")]
pub fn make_memory_op(&self, ty: P<MuType>, vm: &VM) -> P<Value> { pub fn make_memory_op(&self, ty: P<MuType>, vm: &VM) -> P<Value> {
use compiler::backend::x86_64; use compiler::backend::x86_64;
P(Value{ P(Value{
hdr: MuEntityHeader::unnamed(vm.next_id()), hdr: MuEntityHeader::unnamed(vm.next_id()),
ty: ty.clone(), ty: ty.clone(),
v: Value_::Memory( v: Value_::Memory(
MemoryLocation::Address{ MemoryLocation::Address{
base: x86_64::RBP.clone(), base: x86_64::RBP.clone(),
offset: Some(Value::make_int_const(vm.next_id(), self.offset as u64)), offset: Some(Value::make_int_const(vm.next_id(), self.offset as u64)),
index: None, index: None,
scale: None scale: None
} }
) )
}) })
} }
#[cfg(target_arch = "aarch64")] #[cfg(target_arch = "aarch64")]
pub fn make_memory_op(&self, ty: P<MuType>, vm: &VM) -> P<Value> { pub fn make_memory_op(&self, ty: P<MuType>, vm: &VM) -> P<Value> {
use compiler::backend::aarch64; use compiler::backend::aarch64;
P(Value{ P(Value{
hdr: MuEntityHeader::unnamed(vm.next_id()), hdr: MuEntityHeader::unnamed(vm.next_id()),
ty: ty.clone(), ty: ty.clone(),
v: Value_::Memory( v: Value_::Memory(
MemoryLocation::Address{ MemoryLocation::Address{
base: aarch64::FP.clone(), base: aarch64::FP.clone(),
offset: Some(Value::make_int_const(vm.next_id(), self.offset as u64)), offset: Some(Value::make_int_const(vm.next_id(), self.offset as u64)),
shift: 0, shift: 0,
signed: false signed: false
} }
) )
}) })
} }
} }
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