Commit c9de0874 authored by qinsoon's avatar qinsoon

Merge branch 'develop' into domtree

parents 5bfc39a4 49182e46
......@@ -766,7 +766,7 @@ impl Instruction {
ret.push_str(" ");
}
}
ret.push_str("}}");
ret.push_str("}");
ret
}
......
......@@ -1286,7 +1286,7 @@ impl fmt::Display for Constant {
write!(f, "]")
}
&Constant::NullRef => write!(f, "NULL"),
&Constant::ExternSym(ref name) => write!(f, "EXTERN \\\"{}\\\"", name),
&Constant::ExternSym(ref name) => write!(f, "EXTERN \"{}\"", name),
&Constant::List(ref vec) => {
write!(f, "List(").unwrap();
......
......@@ -37,7 +37,6 @@ use std::usize;
use std::ops;
use std::collections::HashSet;
use std::sync::RwLock;
use compiler::backend::code_emission::{emit_mu_types, emit_mu_globals};
macro_rules! trace_emit {
($arg1:tt $($arg:tt)*) => {
......@@ -3642,9 +3641,6 @@ pub fn emit_context_with_reloc(
use std::path;
use std::io::prelude::*;
emit_mu_types("", vm);
emit_mu_globals("", vm);
debug!("---Emit VM Context---");
create_emit_directory(vm);
......
......@@ -4160,7 +4160,6 @@ pub fn emit_sym_table(vm: &VM) {
use std::collections::HashMap;
use compiler::backend::code_emission::{emit_mu_types, emit_mu_globals};
/// emit vm context for current session, considering relocation symbols/fields from the client
pub fn emit_context_with_reloc(
......@@ -4171,9 +4170,6 @@ pub fn emit_context_with_reloc(
use std::path;
use std::io::prelude::*;
emit_mu_types("", vm);
emit_mu_globals("", vm);
// creates emit directy, and file
debug!("---Emit VM Context---");
create_emit_directory(vm);
......
......@@ -24,9 +24,7 @@ use std::path;
use std::io::prelude::*;
use std::fs::File;
use std::collections::HashMap;
/// should emit Mu IR dot graph?
pub const EMIT_MUIR: bool = true;
pub use vm::uir_output::create_emit_directory;
/// should emit machien code dot graph?
pub const EMIT_MC_DOT: bool = true;
......@@ -62,15 +60,6 @@ impl CompilerPass for CodeEmission {
}
}
/// creates the emit directory (if it doesnt exist)
pub fn create_emit_directory(vm: &VM) {
use std::fs;
match fs::create_dir(&vm.vm_options.flag_aot_emit_dir) {
Ok(_) => {}
Err(_) => {}
}
}
/// creates an file to write, panics if the creation fails
fn create_emit_file(name: String, vm: &VM) -> File {
let mut file_path = path::PathBuf::new();
......@@ -89,89 +78,6 @@ fn create_emit_file(name: String, vm: &VM) -> File {
}
}
#[allow(dead_code)]
pub fn emit_mu_types(suffix: &str, vm: &VM) {
if EMIT_MUIR {
create_emit_directory(vm);
let mut file_path = path::PathBuf::new();
file_path.push(&vm.vm_options.flag_aot_emit_dir);
file_path.push("___types".to_string() + suffix + ".uir");
let mut file = match File::create(file_path.as_path()) {
Err(why) => {
panic!(
"couldn't create mu types file {}: {}",
file_path.to_str().unwrap(),
why
)
}
Ok(file) => file
};
{
use ast::types::*;
let ty_guard = vm.types().read().unwrap();
let struct_map = STRUCT_TAG_MAP.read().unwrap();
let hybrid_map = HYBRID_TAG_MAP.read().unwrap();
for ty in ty_guard.values() {
if ty.is_struct() {
write!(file, ".typedef {} = ", ty.hdr).unwrap();
let struct_ty = struct_map
.get(&ty.get_struct_hybrid_tag().unwrap())
.unwrap();
writeln!(file, "{}", struct_ty).unwrap();
writeln!(file, "\n\t/*{}*/", vm.get_backend_type_info(ty.id())).unwrap();
} else if ty.is_hybrid() {
write!(file, ".typedef {} = ", ty.hdr).unwrap();
let hybrid_ty = hybrid_map
.get(&ty.get_struct_hybrid_tag().unwrap())
.unwrap();
writeln!(file, "{}", hybrid_ty).unwrap();
writeln!(file, "\n\t/*{}*/", vm.get_backend_type_info(ty.id())).unwrap();
} else {
// we only care about struct
}
}
}
}
}
pub fn emit_mu_globals(suffix: &str, vm: &VM) {
if EMIT_MUIR {
create_emit_directory(vm);
let mut file_path = path::PathBuf::new();
file_path.push(&vm.vm_options.flag_aot_emit_dir);
file_path.push("___globals".to_string() + suffix + ".uir");
let mut file = match File::create(file_path.as_path()) {
Err(why) => {
panic!(
"couldn't create mu globals file {}: {}",
file_path.to_str().unwrap(),
why
)
}
Ok(file) => file
};
let global_guard = vm.globals().read().unwrap();
for g in global_guard.values() {
writeln!(
file,
".global {}<{}>",
g.name(),
g.ty.get_referent_ty().unwrap()
).unwrap();
}
}
}
fn emit_mc_dot(func: &MuFunctionVersion, vm: &VM) {
let func_name = func.name();
......
......@@ -22,16 +22,7 @@ use std::any::Any;
use std::path;
use std::io::prelude::*;
use std::fs::File;
pub 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(_) => {}
}
}
use vm::uir_output::{EMIT_MUIR, create_emit_directory};
fn create_emit_file(name: String, vm: &VM) -> File {
let mut file_path = path::PathBuf::new();
......@@ -89,6 +80,12 @@ fn emit_muir_dot(suffix: &str, func: &MuFunctionVersion, vm: &VM) {
emit_muir_dot_inner(&mut file, func_name.clone(), func.content.as_ref().unwrap());
}
fn escape_string(s: String) -> String {
s.replace("\"", "\\\"") // Replace " with \"
}
fn emit_muir_dot_inner(file: &mut File, f_name: MuName, f_content: &FunctionContent) {
use utils::vec_utils;
......@@ -126,7 +123,11 @@ fn emit_muir_dot_inner(file: &mut File, f_name: MuName, f_content: &FunctionCont
// all the instructions
for inst in block_content.body.iter() {
write!(file, " {}\\l", inst.as_inst_ref()).unwrap();
write!(
file,
" {}\\l",
escape_string(format!("{}", inst.as_inst_ref()))
).unwrap();
}
// "];
......
......@@ -22,16 +22,9 @@ use std::any::Any;
use std::path;
use std::io::prelude::*;
use std::fs::File;
use vm::uir_output::create_emit_directory;
pub 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(_) => {}
}
}
fn create_emit_file(name: String, vm: &VM) -> File {
let mut file_path = path::PathBuf::new();
......
......@@ -18,7 +18,7 @@ mod vm;
/// which includes types, globals, functions/IRs, compiled functions
/// and other runtime table (exception table etc)
pub use vm::vm::VM;
pub mod uir_output;
/// vm_options defines commandline flags to create a new Zebu instance
mod vm_options;
......
use ast::ir::*;
use vm::VM;
use std::path;
use std::io::prelude::*;
use std::fs::File;
/// should emit Mu IR dot graph?
pub const EMIT_MUIR: bool = true;
pub fn emit_uir(suffix: &str, vm: &VM) {
if EMIT_MUIR {
emit_mu_types(suffix, vm);
emit_mu_globals(suffix, vm);
emit_mu_funcdecls(suffix, vm);
}
}
fn emit_mu_types(suffix: &str, vm: &VM) {
create_emit_directory(vm);
let mut file_path = path::PathBuf::new();
file_path.push(&vm.vm_options.flag_aot_emit_dir);
file_path.push("___types".to_string() + suffix + ".uir");
let mut file = match File::create(file_path.as_path()) {
Err(why) => {
panic!(
"couldn't create mu types file {}: {}",
file_path.to_str().unwrap(),
why
)
}
Ok(file) => file
};
{
use ast::types::*;
let ty_guard = vm.types().read().unwrap();
let struct_map = STRUCT_TAG_MAP.read().unwrap();
let hybrid_map = HYBRID_TAG_MAP.read().unwrap();
for ty in ty_guard.values() {
if ty.is_struct() {
write!(file, ".typedef {} = ", ty.hdr).unwrap();
let struct_ty = struct_map
.get(&ty.get_struct_hybrid_tag().unwrap())
.unwrap();
writeln!(file, "{}", struct_ty).unwrap();
writeln!(file, "\n\t/*{}*/", vm.get_backend_type_info(ty.id())).unwrap();
} else if ty.is_hybrid() {
write!(file, ".typedef {} = ", ty.hdr).unwrap();
let hybrid_ty = hybrid_map
.get(&ty.get_struct_hybrid_tag().unwrap())
.unwrap();
writeln!(file, "{}", hybrid_ty).unwrap();
writeln!(file, "\n\t/*{}*/", vm.get_backend_type_info(ty.id())).unwrap();
} else {
// we only care about struct
}
}
}
}
fn emit_mu_globals(suffix: &str, vm: &VM) {
create_emit_directory(vm);
let mut file_path = path::PathBuf::new();
file_path.push(&vm.vm_options.flag_aot_emit_dir);
file_path.push("___globals".to_string() + suffix + ".uir");
let mut file = match File::create(file_path.as_path()) {
Err(why) => {
panic!(
"couldn't create mu globals file {}: {}",
file_path.to_str().unwrap(),
why
)
}
Ok(file) => file
};
let global_guard = vm.globals().read().unwrap();
for g in global_guard.values() {
writeln!(
file,
".global {}<{}>",
g.name(),
g.ty.get_referent_ty().unwrap()
).unwrap();
}
}
fn emit_mu_funcdecls(suffix: &str, vm: &VM) {
create_emit_directory(vm);
let mut file_path = path::PathBuf::new();
file_path.push(&vm.vm_options.flag_aot_emit_dir);
file_path.push("___funcdecls".to_string() + suffix + ".uir");
let mut file = match File::create(file_path.as_path()) {
Err(why) => {
panic!(
"couldn't create mu funcdecls file {}: {}",
file_path.to_str().unwrap(),
why
)
}
Ok(file) => file
};
let funcs_guard = vm.funcs().read().unwrap();
for f in funcs_guard.values() {
let f_lock = f.read().unwrap();
writeln!(file, ".funcdecl {}<{}>", f_lock.name(), f_lock.sig).unwrap();
}
}
pub fn create_emit_directory(vm: &VM) {
use std::fs;
match fs::create_dir(&vm.vm_options.flag_aot_emit_dir) {
Ok(_) => {}
Err(_) => {}
}
}
......@@ -1087,6 +1087,7 @@ impl<'a> VM {
) {
info!("Making boot image...");
super::uir_output::emit_uir("", self);
// Only store name info for whitelisted entities
{
let mut new_id_name_map = HashMap::<MuID, MuName>::with_capacity(whitelist.len());
......@@ -1127,7 +1128,7 @@ impl<'a> VM {
compiler.compile(&mut func_ver);
}
}
None => panic!("whitelist function {} has no version defined", f)
None => error!("whitelist function {} has no version defined", f)
}
}
}
......
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