GitLab will continue to be upgraded from 11.4.5-ce.0 on November 25th 2019 at 4.00pm (AEDT) to 5.00pm (AEDT) due to Critical Security Patch Availability. During the update, GitLab and Mattermost services will not be available.

Commit d0bd8e72 authored by qinsoon's avatar qinsoon

[wip] more clear debug print

parent 7667e451
......@@ -490,7 +490,11 @@ pub struct CallData {
impl CallData {
fn debug_str(&self, ops: &Vec<P<TreeNode>>) -> String {
format!("{:?} {} [{}]", self.convention, ops[self.func], op_vector_str(&self.args, ops))
let func_name = match ops[self.func].name() {
Some(name) => name,
None => "Anonymous Function".to_string()
};
format!("{:?} {} [{}]", self.convention, func_name, op_vector_str(&self.args, ops))
}
}
......
......@@ -3057,14 +3057,7 @@ impl CodeGenerator for ASMCodeGen {
}
}
fn create_emit_directory(vm: &VM) {
use std::fs;
match fs::create_dir(&vm.vm_options.flag_aot_emit_dir) {
Ok(_) => {},
Err(_) => {}
}
}
use compiler::backend::code_emission::create_emit_directory;
use std::fs::File;
pub fn emit_code(fv: &mut MuFunctionVersion, vm: &VM) {
......
......@@ -4,9 +4,18 @@ use compiler::CompilerPass;
use ast::ir::*;
use vm::VM;
use compiler::backend::emit_code;
use std::any::Any;
const EMIT_MUIR : bool = true;
pub fn create_emit_directory(vm: &VM) {
use std::fs;
match fs::create_dir(&vm.vm_options.flag_aot_emit_dir) {
Ok(_) => {},
Err(_) => {}
}
}
pub struct CodeEmission {
name: &'static str
}
......@@ -17,6 +26,25 @@ impl CodeEmission {
name: "Code Emission"
}
}
fn emit_muir(&self, func: &MuFunctionVersion, vm: &VM) {
use std::path;
use std::io::prelude::*;
use std::fs::File;
// create emit directory
create_emit_directory(vm);
let mut file_path = path::PathBuf::new();
file_path.push(&vm.vm_options.flag_aot_emit_dir);
file_path.push(func.name().unwrap().to_string() + ".muir");
let mut file = match File::create(file_path.as_path()) {
Err(why) => panic!("couldn't create muir file {}: {}", file_path.to_str().unwrap(), why),
Ok(file) => file
};
file.write_fmt(format_args!("{:?}", func)).unwrap();
}
}
impl CompilerPass for CodeEmission {
......@@ -30,5 +58,9 @@ impl CompilerPass for CodeEmission {
fn visit_function(&mut self, vm: &VM, func: &mut MuFunctionVersion) {
emit_code(func, vm);
if EMIT_MUIR {
self.emit_muir(func, vm);
}
}
}
......@@ -33,36 +33,27 @@ impl Encodable for CompiledFunction {
s.emit_struct("CompiledFunction", CF_SERIALIZE_FIELDS, |s| {
let mut i = 0;
trace!("......serializing func_id");
try!(s.emit_struct_field("func_id", i, |s| self.func_id.encode(s)));
i += 1;
trace!("......serializing func_ver_id");
try!(s.emit_struct_field("func_ver_id", i, |s| self.func_ver_id.encode(s)));
i += 1;
trace!("......serializing temps");
try!(s.emit_struct_field("temps", i, |s| self.temps.encode(s)));
i += 1;
trace!("......serializing consts");
try!(s.emit_struct_field("consts", i, |s| self.consts.encode(s)));
i += 1;
trace!("......serializing const_mem");
try!(s.emit_struct_field("const_mem", i, |s| self.const_mem.encode(s)));
i += 1;
trace!("......serializing frame");
trace!("{}", self.frame);
try!(s.emit_struct_field("frame", i, |s| self.frame.encode(s)));
i += 1;
trace!("......serializing start");
try!(s.emit_struct_field("start", i, |s| self.start.encode(s)));
i += 1;
trace!("......serializing end");
try!(s.emit_struct_field("end", i, |s| self.end.encode(s)));
Ok(())
......
......@@ -268,26 +268,35 @@ impl FrameCursor {
}
}
const TRACE_FIND_FUNC : bool = false;
#[allow(unused_imports)]
fn find_func_for_address (cf: &RwLockReadGuard<HashMap<MuID, RwLock<CompiledFunction>>>, funcs: &RwLockReadGuard<HashMap<MuID, RwLock<MuFunction>>>, pc_addr: Address) -> (MuID, MuID) {
// use std::ops::Deref;
use std::ops::Deref;
// trace!("trying to find FuncVersion for address 0x{:x}", pc_addr);
if TRACE_FIND_FUNC {
trace!("trying to find FuncVersion for address 0x{:x}", pc_addr);
}
for (_, func) in cf.iter() {
let func = func.read().unwrap();
let f = match funcs.get(&func.func_id) {
Some(f) => f,
None => panic!("failed to find func #{}", func.func_id)
};
// let f_lock = f.read().unwrap();
let start = func.start.to_address();
let end = func.end.to_address();
// trace!("CompiledFunction: func={}, fv_id={}, start=0x{:x}, end=0x{:x}", f_lock.deref(), func.func_ver_id, start, end);
if TRACE_FIND_FUNC {
let f = match funcs.get(&func.func_id) {
Some(f) => f,
None => panic!("failed to find func #{}", func.func_id)
};
let f_lock = f.read().unwrap();
trace!("CompiledFunction: func={}, fv_id={}, start=0x{:x}, end=0x{:x}", f_lock.deref(), func.func_ver_id, start, end);
}
// pc won't be the start of a function, but could be the end
if pc_addr > start && pc_addr <= end {
// trace!("Found CompiledFunction: func_id={}, fv_id={}", func.func_id, func.func_ver_id);
if TRACE_FIND_FUNC {
trace!("Found CompiledFunction: func_id={}, fv_id={}", func.func_id, func.func_ver_id);
}
return (func.func_id, func.func_ver_id);
}
}
......
......@@ -56,23 +56,21 @@ impl VMOptions {
pub fn init(str: &str) -> VMOptions {
info!("init vm options with: {:?}", str);
let ret : VMOptions = Docopt::new(USAGE)
let mut ret : VMOptions = Docopt::new(USAGE)
.and_then(|d| d.argv(str.split_whitespace().into_iter()).parse())
.unwrap_or_else(|e| e.exit()).decode().unwrap();
info!("parsed as {:?}", ret);
// at the moment disable collection for debugging
ret.flag_gc_disable_collection = true;
ret
}
}
impl Default for VMOptions {
fn default() -> VMOptions {
let mut options = VMOptions::init("");
// by default, disable colleciton for easier debugging
options.flag_gc_disable_collection = true;
options
VMOptions::init("")
}
}
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