Commit 7ee4feca authored by Isaac Oscar Gariano's avatar Isaac Oscar Gariano

Fixxed formatting

parent 52b8e828
...@@ -766,7 +766,7 @@ impl Instruction { ...@@ -766,7 +766,7 @@ impl Instruction {
ret.push_str(" "); ret.push_str(" ");
} }
} }
ret.push_str("}}"); ret.push_str("}");
ret ret
} }
......
...@@ -80,8 +80,7 @@ fn emit_muir_dot(suffix: &str, func: &MuFunctionVersion, vm: &VM) { ...@@ -80,8 +80,7 @@ fn emit_muir_dot(suffix: &str, func: &MuFunctionVersion, vm: &VM) {
emit_muir_dot_inner(&mut file, func_name.clone(), func.content.as_ref().unwrap()); emit_muir_dot_inner(&mut file, func_name.clone(), func.content.as_ref().unwrap());
} }
fn escape_string(s: String) -> String fn escape_string(s: String) -> String {
{
s.replace("\"", "\\\"") // Replace " with \" s.replace("\"", "\\\"") // Replace " with \"
} }
...@@ -124,7 +123,11 @@ fn emit_muir_dot_inner(file: &mut File, f_name: MuName, f_content: &FunctionCont ...@@ -124,7 +123,11 @@ fn emit_muir_dot_inner(file: &mut File, f_name: MuName, f_content: &FunctionCont
// all the instructions // all the instructions
for inst in block_content.body.iter() { for inst in block_content.body.iter() {
write!(file, " {}\\l", escape_string(format!("{}", inst.as_inst_ref()))).unwrap(); write!(
file,
" {}\\l",
escape_string(format!("{}", inst.as_inst_ref()))
).unwrap();
} }
// "]; // "];
......
...@@ -178,4 +178,4 @@ macro_rules! error_if { ...@@ -178,4 +178,4 @@ macro_rules! error_if {
error!($($arg)*) error!($($arg)*)
} }
} }
} }
\ No newline at end of file
...@@ -29,4 +29,4 @@ pub mod built_info; ...@@ -29,4 +29,4 @@ pub mod built_info;
pub mod api; pub mod api;
/// handle type for client. This handle type is opaque to the client /// handle type for client. This handle type is opaque to the client
pub mod handle; pub mod handle;
\ No newline at end of file
use ast::ir::*; use ast::ir::*;
use vm::VM; use vm::VM;
use std::path; use std::path;
use std::io::prelude::*; use std::io::prelude::*;
use std::fs::File; use std::fs::File;
/// should emit Mu IR dot graph? /// should emit Mu IR dot graph?
pub const EMIT_MUIR: bool = true; pub const EMIT_MUIR: bool = true;
pub fn emit_uir(suffix: &str, vm: &VM) { pub fn emit_uir(suffix: &str, vm: &VM) {
if EMIT_MUIR { if EMIT_MUIR {
emit_mu_types(suffix, vm); emit_mu_types(suffix, vm);
emit_mu_globals(suffix, vm); emit_mu_globals(suffix, vm);
emit_mu_funcdecls(suffix, vm); emit_mu_funcdecls(suffix, vm);
} }
} }
fn emit_mu_types(suffix: &str, vm: &VM) { fn emit_mu_types(suffix: &str, vm: &VM) {
create_emit_directory(vm); create_emit_directory(vm);
let mut file_path = path::PathBuf::new(); let mut file_path = path::PathBuf::new();
file_path.push(&vm.vm_options.flag_aot_emit_dir); file_path.push(&vm.vm_options.flag_aot_emit_dir);
file_path.push("___types".to_string() + suffix + ".uir"); file_path.push("___types".to_string() + suffix + ".uir");
let mut file = match File::create(file_path.as_path()) { let mut file = match File::create(file_path.as_path()) {
Err(why) => { Err(why) => {
panic!( panic!(
"couldn't create mu types file {}: {}", "couldn't create mu types file {}: {}",
file_path.to_str().unwrap(), file_path.to_str().unwrap(),
why why
) )
} }
Ok(file) => file Ok(file) => file
}; };
{ {
use ast::types::*; use ast::types::*;
let ty_guard = vm.types().read().unwrap(); let ty_guard = vm.types().read().unwrap();
let struct_map = STRUCT_TAG_MAP.read().unwrap(); let struct_map = STRUCT_TAG_MAP.read().unwrap();
let hybrid_map = HYBRID_TAG_MAP.read().unwrap(); let hybrid_map = HYBRID_TAG_MAP.read().unwrap();
for ty in ty_guard.values() { for ty in ty_guard.values() {
if ty.is_struct() { if ty.is_struct() {
write!(file, ".typedef {} = ", ty.hdr).unwrap(); write!(file, ".typedef {} = ", ty.hdr).unwrap();
let struct_ty = struct_map let struct_ty = struct_map
.get(&ty.get_struct_hybrid_tag().unwrap()) .get(&ty.get_struct_hybrid_tag().unwrap())
.unwrap(); .unwrap();
writeln!(file, "{}", struct_ty).unwrap(); writeln!(file, "{}", struct_ty).unwrap();
writeln!(file, "\n\t/*{}*/", vm.get_backend_type_info(ty.id())).unwrap(); writeln!(file, "\n\t/*{}*/", vm.get_backend_type_info(ty.id())).unwrap();
} else if ty.is_hybrid() { } else if ty.is_hybrid() {
write!(file, ".typedef {} = ", ty.hdr).unwrap(); write!(file, ".typedef {} = ", ty.hdr).unwrap();
let hybrid_ty = hybrid_map let hybrid_ty = hybrid_map
.get(&ty.get_struct_hybrid_tag().unwrap()) .get(&ty.get_struct_hybrid_tag().unwrap())
.unwrap(); .unwrap();
writeln!(file, "{}", hybrid_ty).unwrap(); writeln!(file, "{}", hybrid_ty).unwrap();
writeln!(file, "\n\t/*{}*/", vm.get_backend_type_info(ty.id())).unwrap(); writeln!(file, "\n\t/*{}*/", vm.get_backend_type_info(ty.id())).unwrap();
} else { } else {
// we only care about struct // we only care about struct
} }
} }
} }
} }
fn emit_mu_globals(suffix: &str, vm: &VM) { fn emit_mu_globals(suffix: &str, vm: &VM) {
create_emit_directory(vm); create_emit_directory(vm);
let mut file_path = path::PathBuf::new(); let mut file_path = path::PathBuf::new();
file_path.push(&vm.vm_options.flag_aot_emit_dir); file_path.push(&vm.vm_options.flag_aot_emit_dir);
file_path.push("___globals".to_string() + suffix + ".uir"); file_path.push("___globals".to_string() + suffix + ".uir");
let mut file = match File::create(file_path.as_path()) { let mut file = match File::create(file_path.as_path()) {
Err(why) => { Err(why) => {
panic!( panic!(
"couldn't create mu globals file {}: {}", "couldn't create mu globals file {}: {}",
file_path.to_str().unwrap(), file_path.to_str().unwrap(),
why why
) )
} }
Ok(file) => file Ok(file) => file
}; };
let global_guard = vm.globals().read().unwrap(); let global_guard = vm.globals().read().unwrap();
for g in global_guard.values() { for g in global_guard.values() {
writeln!( writeln!(
file, file,
".global {}<{}>", ".global {}<{}>",
g.name(), g.name(),
g.ty.get_referent_ty().unwrap() g.ty.get_referent_ty().unwrap()
).unwrap(); ).unwrap();
} }
} }
fn emit_mu_funcdecls(suffix: &str, vm: &VM) { fn emit_mu_funcdecls(suffix: &str, vm: &VM) {
create_emit_directory(vm); create_emit_directory(vm);
let mut file_path = path::PathBuf::new(); let mut file_path = path::PathBuf::new();
file_path.push(&vm.vm_options.flag_aot_emit_dir); file_path.push(&vm.vm_options.flag_aot_emit_dir);
file_path.push("___funcdecls".to_string() + suffix + ".uir"); file_path.push("___funcdecls".to_string() + suffix + ".uir");
let mut file = match File::create(file_path.as_path()) { let mut file = match File::create(file_path.as_path()) {
Err(why) => { Err(why) => {
panic!( panic!(
"couldn't create mu funcdecls file {}: {}", "couldn't create mu funcdecls file {}: {}",
file_path.to_str().unwrap(), file_path.to_str().unwrap(),
why why
) )
} }
Ok(file) => file Ok(file) => file
}; };
let funcs_guard = vm.funcs().read().unwrap(); let funcs_guard = vm.funcs().read().unwrap();
for f in funcs_guard.values() { for f in funcs_guard.values() {
let f_lock = f.read().unwrap(); let f_lock = f.read().unwrap();
writeln!( writeln!(file, ".funcdecl {}<{}>", f_lock.name(), f_lock.sig).unwrap();
file, }
".funcdecl {}<{}>", }
f_lock.name(),
f_lock.sig pub fn create_emit_directory(vm: &VM) {
).unwrap(); use std::fs;
}
}
pub fn create_emit_directory(vm: &VM) {
use std::fs;
match fs::create_dir(&vm.vm_options.flag_aot_emit_dir) { match fs::create_dir(&vm.vm_options.flag_aot_emit_dir) {
Ok(_) => {} Ok(_) => {}
Err(_) => {} Err(_) => {}
} }
} }
\ No newline at end of file
...@@ -1128,7 +1128,7 @@ impl<'a> VM { ...@@ -1128,7 +1128,7 @@ impl<'a> VM {
compiler.compile(&mut func_ver); 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