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 4d267476 authored by Isaac Oscar Gariano's avatar Isaac Oscar Gariano

Added a ___funcdecls.uir output, now output some uirs before compiling

parent 31b3e72d
Pipeline #1227 failed with stages
in 5 minutes and 8 seconds
......@@ -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);
......
......@@ -4143,7 +4143,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(
......@@ -4154,9 +4153,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,13 @@ 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 +124,7 @@ 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();
......
......@@ -178,4 +178,4 @@ macro_rules! error_if {
error!($($arg)*)
}
}
}
}
\ No newline at end of file
......@@ -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;
......@@ -29,4 +29,4 @@ pub mod built_info;
pub mod api;
/// handle type for client. This handle type is opaque to the client
pub mod handle;
pub mod handle;
\ No newline at end of file
......@@ -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());
......
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