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

Fixxed formatting

parent 52b8e828
Pipeline #1236 passed with stages
in 53 minutes and 54 seconds
......@@ -766,7 +766,7 @@ impl Instruction {
ret.push_str(" ");
}
}
ret.push_str("}}");
ret.push_str("}");
ret
}
......
......@@ -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());
}
fn escape_string(s: String) -> String
{
fn escape_string(s: String) -> String {
s.replace("\"", "\\\"") // Replace " with \"
}
......@@ -124,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", 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 {
error!($($arg)*)
}
}
}
\ No newline at end of file
}
......@@ -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;
\ No newline at end of file
pub mod handle;
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");
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
)
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");
};
{
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
)
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 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
)
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;
};
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(_) => {}
}
}
\ No newline at end of file
}
}
......@@ -1128,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