Commit 5e05fd11 authored by Isaac Oscar Gariano's avatar Isaac Oscar Gariano
Browse files

Changed MuName and CName to Arc<String>

parent 2e8bb439
...@@ -37,7 +37,7 @@ gcc = "*" ...@@ -37,7 +37,7 @@ gcc = "*"
mu_ast = {path = "src/ast"} mu_ast = {path = "src/ast"}
mu_utils = {path = "src/utils"} mu_utils = {path = "src/utils"}
#mu_gc = {path = "src/gc"} #mu_gc = {path = "src/gc"}
rodal = { git = "https://gitlab.anu.edu.au/mu/rodal", version = ">= 0.0.5" } rodal = { git = "https://gitlab.anu.edu.au/mu/rodal", version = ">= 0.0.10" }
#rodal = { path = "../rodal_test/rodal", version = ">= 0.0.5" } #rodal = { path = "../rodal_test/rodal", version = ">= 0.0.5" }
libc="*" libc="*"
......
...@@ -25,6 +25,6 @@ mu_utils = {path = "../utils"} ...@@ -25,6 +25,6 @@ mu_utils = {path = "../utils"}
lazy_static = "*" lazy_static = "*"
log = "*" log = "*"
simple_logger = "*" simple_logger = "*"
rodal = { git = "https://gitlab.anu.edu.au/mu/rodal", version = ">= 0.0.5" } rodal = { git = "https://gitlab.anu.edu.au/mu/rodal", version = ">= 0.0.10" }
regex = "*" regex = "*"
#rodal = { path = "../../../rodal_test/rodal", version = ">= 0.0.5" } #rodal = { path = "../../../rodal_test/rodal", version = ">= 0.0.5" }
...@@ -22,21 +22,22 @@ use utils::LinkedHashSet; ...@@ -22,21 +22,22 @@ use utils::LinkedHashSet;
use std; use std;
use std::fmt; use std::fmt;
pub use std::sync::Arc;
use std::default; use std::default;
use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering}; use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
pub type WPID = usize; pub type WPID = usize;
pub type MuID = usize; pub type MuID = usize;
pub type MuName = String; pub type MuName = Arc<String>;
pub type CName = MuName; pub type CName = MuName;
#[allow(non_snake_case)] #[allow(non_snake_case)]
pub fn Mu(str: &'static str) -> MuName { pub fn Mu(str: &'static str) -> MuName {
str.to_string() Arc::new(str.to_string())
} }
#[allow(non_snake_case)] #[allow(non_snake_case)]
pub fn C(str: &'static str) -> CName { pub fn C(str: &'static str) -> CName {
str.to_string() Arc::new(str.to_string())
} }
pub type OpIndex = usize; pub type OpIndex = usize;
...@@ -460,7 +461,7 @@ impl FunctionContent { ...@@ -460,7 +461,7 @@ impl FunctionContent {
} }
} }
pub fn get_block_by_name(&self, name: String) -> &Block { pub fn get_block_by_name(&self, name: MuName) -> &Block {
for block in self.blocks.values() { for block in self.blocks.values() {
if block.name() == name { if block.name() == name {
return block; return block;
...@@ -1466,7 +1467,7 @@ pub fn is_valid_c_identifier(name: &MuName) -> bool { ...@@ -1466,7 +1467,7 @@ pub fn is_valid_c_identifier(name: &MuName) -> bool {
/// changes name to mangled name /// changes name to mangled name
/// This will always return a valid C identifier /// This will always return a valid C identifier
pub fn mangle_name(name: MuName) -> MuName { pub fn mangle_name(name: MuName) -> String {
let name = name.replace('@', ""); let name = name.replace('@', "");
if name.starts_with("__mu_") { if name.starts_with("__mu_") {
// TODO: Get rid of this, since it will be triggered if a client provides a name // TODO: Get rid of this, since it will be triggered if a client provides a name
...@@ -1488,7 +1489,7 @@ pub fn mangle_name(name: MuName) -> MuName { ...@@ -1488,7 +1489,7 @@ pub fn mangle_name(name: MuName) -> MuName {
/// demangles a Mu name /// demangles a Mu name
// WARNING: This only reverses mangle_name above when no warning is issued) // WARNING: This only reverses mangle_name above when no warning is issued)
pub fn demangle_name(mut name: MuName) -> MuName { pub fn demangle_name(mut name: String) -> MuName {
let name = if cfg!(target_os = "macos") && name.starts_with("___mu_") { let name = if cfg!(target_os = "macos") && name.starts_with("___mu_") {
name.split_off(1) name.split_off(1)
} else { } else {
...@@ -1507,13 +1508,13 @@ pub fn demangle_name(mut name: MuName) -> MuName { ...@@ -1507,13 +1508,13 @@ pub fn demangle_name(mut name: MuName) -> MuName {
.replace("Zh", "-") .replace("Zh", "-")
.replace("Zd", ".") .replace("Zd", ".")
.replace("ZZ", "Z"); .replace("ZZ", "Z");
name Arc::new(name)
} }
extern crate regex; extern crate regex;
/// identifies mu names and demangles them /// identifies mu names and demangles them
pub fn demangle_text(text: String) -> String { pub fn demangle_text(text: &String) -> String {
use self::regex::Regex; use self::regex::Regex;
lazy_static!{ lazy_static!{
...@@ -1539,14 +1540,14 @@ impl MuEntityHeader { ...@@ -1539,14 +1540,14 @@ impl MuEntityHeader {
pub fn unnamed(id: MuID) -> MuEntityHeader { pub fn unnamed(id: MuID) -> MuEntityHeader {
MuEntityHeader { MuEntityHeader {
id: id, id: id,
name: format!("#{}", id) name: Arc::new(format!("#{}", id))
} }
} }
pub fn named(id: MuID, name: MuName) -> MuEntityHeader { pub fn named(id: MuID, name: MuName) -> MuEntityHeader {
MuEntityHeader { MuEntityHeader {
id: id, id: id,
name: name.replace('@', "") name: Arc::new(name.replace('@', ""))
} }
} }
...@@ -1559,7 +1560,7 @@ impl MuEntityHeader { ...@@ -1559,7 +1560,7 @@ impl MuEntityHeader {
} }
/// an abbreviate (easy reading) version of the name /// an abbreviate (easy reading) version of the name
fn abbreviate_name(&self) -> MuName { fn abbreviate_name(&self) -> String {
let split: Vec<&str> = self.name.split('.').collect(); let split: Vec<&str> = self.name.split('.').collect();
let mut ret = "".to_string(); let mut ret = "".to_string();
...@@ -1580,7 +1581,7 @@ impl MuEntityHeader { ...@@ -1580,7 +1581,7 @@ impl MuEntityHeader {
pub fn clone_with_id(&self, new_id: MuID) -> MuEntityHeader { pub fn clone_with_id(&self, new_id: MuID) -> MuEntityHeader {
let mut clone = self.clone(); let mut clone = self.clone();
clone.id = new_id; clone.id = new_id;
clone.name = format!("{}-#{}", clone.name, clone.id); clone.name = Arc::new(format!("{}-#{}", clone.name, clone.id));
clone clone
} }
} }
......
...@@ -3444,7 +3444,7 @@ pub fn emit_code(fv: &mut MuFunctionVersion, vm: &VM) { ...@@ -3444,7 +3444,7 @@ pub fn emit_code(fv: &mut MuFunctionVersion, vm: &VM) {
{ {
let mut demangled_path = path::PathBuf::new(); let mut demangled_path = path::PathBuf::new();
demangled_path.push(&vm.vm_options.flag_aot_emit_dir); demangled_path.push(&vm.vm_options.flag_aot_emit_dir);
demangled_path.push(func.name() + ".demangled.S"); demangled_path.push(*func.name() + ".demangled.S");
let mut demangled_file = match File::create(demangled_path.as_path()) { let mut demangled_file = match File::create(demangled_path.as_path()) {
Err(why) => { Err(why) => {
...@@ -3577,7 +3577,7 @@ use std::collections::HashMap; ...@@ -3577,7 +3577,7 @@ use std::collections::HashMap;
pub fn emit_context_with_reloc( pub fn emit_context_with_reloc(
vm: &VM, vm: &VM,
symbols: HashMap<Address, String>, symbols: HashMap<Address, MuName>,
fields: HashMap<Address, String> fields: HashMap<Address, String>
) { ) {
use std::path; use std::path;
......
...@@ -5957,7 +5957,7 @@ impl<'a> InstructionSelection { ...@@ -5957,7 +5957,7 @@ impl<'a> InstructionSelection {
self.backend.end_block(cur_block.clone()); self.backend.end_block(cur_block.clone());
} }
fn start_block(&mut self, block: String) { fn start_block(&mut self, block: MuName) {
self.current_block = Some(block.clone()); self.current_block = Some(block.clone());
self.backend.start_block(block.clone()); self.backend.start_block(block.clone());
} }
......
...@@ -59,7 +59,7 @@ macro_rules! REGISTER { ...@@ -59,7 +59,7 @@ macro_rules! REGISTER {
($id:expr, $name: expr, $ty: ident) => { ($id:expr, $name: expr, $ty: ident) => {
{ {
P(Value { P(Value {
hdr: MuEntityHeader::named($id, $name.to_string()), hdr: MuEntityHeader::named($id, Arc::new($name.to_string())),
ty: $ty.clone(), ty: $ty.clone(),
v: Value_::SSAVar($id) v: Value_::SSAVar($id)
}) })
......
...@@ -226,7 +226,7 @@ pub trait CodeGenerator { ...@@ -226,7 +226,7 @@ pub trait CodeGenerator {
// call // call
fn emit_call_near_rel32( fn emit_call_near_rel32(
&mut self, &mut self,
callsite: String, callsite: MuName,
func: MuName, func: MuName,
pe: Option<MuName>, pe: Option<MuName>,
uses: Vec<P<Value>>, uses: Vec<P<Value>>,
...@@ -235,7 +235,7 @@ pub trait CodeGenerator { ...@@ -235,7 +235,7 @@ pub trait CodeGenerator {
) -> ValueLocation; ) -> ValueLocation;
fn emit_call_near_r64( fn emit_call_near_r64(
&mut self, &mut self,
callsite: String, callsite: MuName,
func: &P<Value>, func: &P<Value>,
pe: Option<MuName>, pe: Option<MuName>,
uses: Vec<P<Value>>, uses: Vec<P<Value>>,
...@@ -243,7 +243,7 @@ pub trait CodeGenerator { ...@@ -243,7 +243,7 @@ pub trait CodeGenerator {
) -> ValueLocation; ) -> ValueLocation;
fn emit_call_near_mem64( fn emit_call_near_mem64(
&mut self, &mut self,
callsite: String, callsite: MuName,
func: &P<Value>, func: &P<Value>,
pe: Option<MuName>, pe: Option<MuName>,
uses: Vec<P<Value>>, uses: Vec<P<Value>>,
...@@ -253,7 +253,7 @@ pub trait CodeGenerator { ...@@ -253,7 +253,7 @@ pub trait CodeGenerator {
// sometimes we use jmp as a call (but without pushing return address) // sometimes we use jmp as a call (but without pushing return address)
fn emit_call_jmp( fn emit_call_jmp(
&mut self, &mut self,
callsite: String, callsite: MuName,
func: MuName, func: MuName,
pe: Option<MuName>, pe: Option<MuName>,
uses: Vec<P<Value>>, uses: Vec<P<Value>>,
...@@ -262,7 +262,7 @@ pub trait CodeGenerator { ...@@ -262,7 +262,7 @@ pub trait CodeGenerator {
) -> ValueLocation; ) -> ValueLocation;
fn emit_call_jmp_indirect( fn emit_call_jmp_indirect(
&mut self, &mut self,
callsite: String, callsite: MuName,
func: &P<Value>, func: &P<Value>,
pe: Option<MuName>, pe: Option<MuName>,
uses: Vec<P<Value>>, uses: Vec<P<Value>>,
......
...@@ -46,7 +46,7 @@ use utils::{BitSize, ByteSize}; ...@@ -46,7 +46,7 @@ use utils::{BitSize, ByteSize};
use std::collections::HashMap; use std::collections::HashMap;
use std::collections::LinkedList; use std::collections::LinkedList;
use std::sync::Arc;
use std::any::Any; use std::any::Any;
lazy_static! { lazy_static! {
...@@ -176,7 +176,7 @@ impl<'a> InstructionSelection { ...@@ -176,7 +176,7 @@ impl<'a> InstructionSelection {
backend: Box::new(ASMCodeGen::new()), backend: Box::new(ASMCodeGen::new()),
current_fv_id: 0, current_fv_id: 0,
current_fv_name: String::new(), current_fv_name: Arc::new(String::new()),
current_sig: None, current_sig: None,
current_callsite_id: 0, current_callsite_id: 0,
current_frame: None, current_frame: None,
...@@ -4850,7 +4850,7 @@ impl<'a> InstructionSelection { ...@@ -4850,7 +4850,7 @@ impl<'a> InstructionSelection {
f_context: &mut FunctionContext, f_context: &mut FunctionContext,
vm: &VM vm: &VM
) { ) {
let block_name = format!("{}:{}", self.current_fv_name, PROLOGUE_BLOCK_NAME); let block_name = Arc::new(format!("{}:{}", self.current_fv_name, PROLOGUE_BLOCK_NAME));
self.backend.start_block(block_name.clone()); self.backend.start_block(block_name.clone());
// push rbp // push rbp
...@@ -6367,7 +6367,7 @@ impl<'a> InstructionSelection { ...@@ -6367,7 +6367,7 @@ impl<'a> InstructionSelection {
} }
/// creates a callsite label that is globally unique /// creates a callsite label that is globally unique
fn new_callsite_label(&mut self, cur_node: Option<&TreeNode>) -> String { fn new_callsite_label(&mut self, cur_node: Option<&TreeNode>) -> MuName {
let ret = { let ret = {
if cur_node.is_some() { if cur_node.is_some() {
make_block_name( make_block_name(
...@@ -6375,11 +6375,11 @@ impl<'a> InstructionSelection { ...@@ -6375,11 +6375,11 @@ impl<'a> InstructionSelection {
format!("callsite_{}", self.current_callsite_id).as_str() format!("callsite_{}", self.current_callsite_id).as_str()
) )
} else { } else {
format!( Arc::new(format!(
"{}:callsite_{}", "{}:callsite_{}",
self.current_fv_name, self.current_fv_name,
self.current_callsite_id self.current_callsite_id
) ))
} }
}; };
self.current_callsite_id += 1; self.current_callsite_id += 1;
...@@ -6510,7 +6510,7 @@ impl<'a> InstructionSelection { ...@@ -6510,7 +6510,7 @@ impl<'a> InstructionSelection {
} }
/// starts a new block /// starts a new block
fn start_block(&mut self, block: String) { fn start_block(&mut self, block: MuName) {
self.current_block = Some(block.clone()); self.current_block = Some(block.clone());
self.backend.start_block(block); self.backend.start_block(block);
} }
......
...@@ -46,6 +46,7 @@ use ast::ir::*; ...@@ -46,6 +46,7 @@ use ast::ir::*;
use ast::types::*; use ast::types::*;
use compiler::backend::RegGroup; use compiler::backend::RegGroup;
use vm::VM; use vm::VM;
use std::sync::Arc;
use utils::LinkedHashMap; use utils::LinkedHashMap;
use std::collections::HashMap; use std::collections::HashMap;
...@@ -96,7 +97,7 @@ macro_rules! GPR { ...@@ -96,7 +97,7 @@ macro_rules! GPR {
($id:expr, $name: expr, $ty: ident) => { ($id:expr, $name: expr, $ty: ident) => {
{ {
P(Value { P(Value {
hdr: MuEntityHeader::named($id, $name.to_string()), hdr: MuEntityHeader::named($id, Arc::new($name.to_string())),
ty: $ty.clone(), ty: $ty.clone(),
v: Value_::SSAVar($id) v: Value_::SSAVar($id)
}) })
...@@ -109,7 +110,7 @@ macro_rules! FPR { ...@@ -109,7 +110,7 @@ macro_rules! FPR {
($id:expr, $name: expr) => { ($id:expr, $name: expr) => {
{ {
P(Value { P(Value {
hdr: MuEntityHeader::named($id, $name.to_string()), hdr: MuEntityHeader::named($id, Arc::new($name.to_string())),
ty: DOUBLE_TYPE.clone(), ty: DOUBLE_TYPE.clone(),
v: Value_::SSAVar($id) v: Value_::SSAVar($id)
}) })
......
...@@ -146,7 +146,7 @@ fn emit_mc_dot(func: &MuFunctionVersion, vm: &VM) { ...@@ -146,7 +146,7 @@ fn emit_mc_dot(func: &MuFunctionVersion, vm: &VM) {
// create emit directory/file // create emit directory/file
create_emit_directory(vm); create_emit_directory(vm);
let mut file = create_emit_file(func_name.clone() + ".mc.dot", &vm); let mut file = create_emit_file((*func_name).clone() + ".mc.dot", &vm);
// diagraph func { // diagraph func {
writeln!(file, "digraph {} {{", mangle_name(func_name)).unwrap(); writeln!(file, "digraph {} {{", mangle_name(func_name)).unwrap();
......
...@@ -541,5 +541,5 @@ impl RegGroup { ...@@ -541,5 +541,5 @@ impl RegGroup {
} }
fn make_block_name(inst: &MuName, label: &str) -> MuName { fn make_block_name(inst: &MuName, label: &str) -> MuName {
format!("{}:{}", inst, label) Arc::new(format!("{}:{}", inst, label))
} }
...@@ -494,7 +494,7 @@ fn build_global_liveness(cf: &mut CompiledFunction, func: &MuFunctionVersion) { ...@@ -494,7 +494,7 @@ fn build_global_liveness(cf: &mut CompiledFunction, func: &MuFunctionVersion) {
/// CFGBlockNode represents a basic block as a whole for global liveness analysis /// CFGBlockNode represents a basic block as a whole for global liveness analysis
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
struct CFGBlockNode { struct CFGBlockNode {
block: String, block: MuName,
pred: Vec<String>, pred: Vec<String>,
succ: Vec<String>, succ: Vec<String>,
uses: Vec<MuID>, uses: Vec<MuID>,
...@@ -507,7 +507,7 @@ struct CFGBlockNode { ...@@ -507,7 +507,7 @@ struct CFGBlockNode {
/// * successors /// * successors
/// * uses /// * uses
/// * defs /// * defs
fn build_cfg_nodes(cf: &mut CompiledFunction) -> LinkedHashMap<String, CFGBlockNode> { fn build_cfg_nodes(cf: &mut CompiledFunction) -> LinkedHashMap<MuName, CFGBlockNode> {
info!("---local liveness analysis---"); info!("---local liveness analysis---");
let mc = cf.mc(); let mc = cf.mc();
let mut ret = LinkedHashMap::new(); let mut ret = LinkedHashMap::new();
...@@ -634,7 +634,7 @@ fn build_cfg_nodes(cf: &mut CompiledFunction) -> LinkedHashMap<String, CFGBlockN ...@@ -634,7 +634,7 @@ fn build_cfg_nodes(cf: &mut CompiledFunction) -> LinkedHashMap<String, CFGBlockN
/// global analysis, the iterative algorithm to compute livenss until livein/out reaches a fix point /// global analysis, the iterative algorithm to compute livenss until livein/out reaches a fix point
fn global_liveness_analysis( fn global_liveness_analysis(
blocks: LinkedHashMap<String, CFGBlockNode>, blocks: LinkedHashMap<MuName, CFGBlockNode>,
cf: &mut CompiledFunction, cf: &mut CompiledFunction,
func: &MuFunctionVersion func: &MuFunctionVersion
) { ) {
...@@ -642,14 +642,14 @@ fn global_liveness_analysis( ...@@ -642,14 +642,14 @@ fn global_liveness_analysis(
info!("{} blocks", blocks.len()); info!("{} blocks", blocks.len());
// init live in and live out // init live in and live out
let mut livein: LinkedHashMap<String, LinkedHashSet<MuID>> = { let mut livein: LinkedHashMap<MuName, LinkedHashSet<MuID>> = {
let mut ret = LinkedHashMap::new(); let mut ret = LinkedHashMap::new();
for name in blocks.keys() { for name in blocks.keys() {
ret.insert(name.clone(), LinkedHashSet::new()); ret.insert(name.clone(), LinkedHashSet::new());
} }
ret ret
}; };
let mut liveout: LinkedHashMap<String, LinkedHashSet<MuID>> = { let mut liveout: LinkedHashMap<MuName, LinkedHashSet<MuID>> = {
let mut ret = LinkedHashMap::new(); let mut ret = LinkedHashMap::new();
for name in blocks.keys() { for name in blocks.keys() {
ret.insert(name.clone(), LinkedHashSet::new()); ret.insert(name.clone(), LinkedHashSet::new());
......
...@@ -74,7 +74,7 @@ pub fn validate_regalloc( ...@@ -74,7 +74,7 @@ pub fn validate_regalloc(
let mut work_queue: LinkedHashMap<MuName, AliveEntries> = LinkedHashMap::new(); let mut work_queue: LinkedHashMap<MuName, AliveEntries> = LinkedHashMap::new();
let mut visited: LinkedHashMap<MuName, AliveEntries> = LinkedHashMap::new(); let mut visited: LinkedHashMap<MuName, AliveEntries> = LinkedHashMap::new();
// push entry block // push entry block
work_queue.insert(PROLOGUE_BLOCK_NAME.to_string(), alive.clone()); work_queue.insert(Arc::new(PROLOGUE_BLOCK_NAME.to_string()), alive.clone());
while !work_queue.is_empty() { while !work_queue.is_empty() {
// fetch next block // fetch next block
......
...@@ -73,7 +73,7 @@ fn emit_muir(suffix: &str, func: &MuFunctionVersion, vm: &VM) { ...@@ -73,7 +73,7 @@ fn emit_muir(suffix: &str, func: &MuFunctionVersion, vm: &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(func_name.clone() + suffix + ".muir"); file_path.push((*func_name).clone() + suffix + ".muir");
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!(
...@@ -96,7 +96,7 @@ fn emit_muir_dot(suffix: &str, func: &MuFunctionVersion, vm: &VM) { ...@@ -96,7 +96,7 @@ fn emit_muir_dot(suffix: &str, func: &MuFunctionVersion, vm: &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(func_name.clone() + suffix + ".dot"); file_path.push((*func_name).clone() + suffix + ".dot");
let mut file = match File::create(file_path.as_path()) { let mut file = match File::create(file_path.as_path()) {
Err(why) => { Err(why) => {
...@@ -112,7 +112,7 @@ fn emit_muir_dot(suffix: &str, func: &MuFunctionVersion, vm: &VM) { ...@@ -112,7 +112,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 emit_muir_dot_inner(file: &mut File, f_name: String, f_content: &FunctionContent) { fn emit_muir_dot_inner(file: &mut File, f_name: MuName, f_content: &FunctionContent) {
use utils::vec_utils; use utils::vec_utils;
// digraph func { // digraph func {
......
...@@ -403,7 +403,7 @@ fn process_dest( ...@@ -403,7 +403,7 @@ fn process_dest(
blocks_to_insert.push(IntermediateBlockInfo { blocks_to_insert.push(IntermediateBlockInfo {
blk_id: new_blk_id, blk_id: new_blk_id,