Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mu-impl-fast
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
40
Issues
40
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
mu
mu-impl-fast
Commits
c9de0874
Commit
c9de0874
authored
Oct 17, 2017
by
qinsoon
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'develop' into domtree
parents
5bfc39a4
49182e46
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
141 additions
and
126 deletions
+141
-126
inst.rs
src/ast/src/inst.rs
+1
-1
ir.rs
src/ast/src/ir.rs
+1
-1
asm_backend.rs
src/compiler/backend/arch/aarch64/asm_backend.rs
+0
-4
asm_backend.rs
src/compiler/backend/arch/x86_64/asm_backend.rs
+0
-4
code_emission.rs
src/compiler/backend/code_emission.rs
+1
-95
dot_gen.rs
src/compiler/passes/dot_gen.rs
+12
-11
uir_gen.rs
src/compiler/passes/uir_gen.rs
+1
-8
mod.rs
src/vm/mod.rs
+1
-1
uir_output.rs
src/vm/uir_output.rs
+122
-0
vm.rs
src/vm/vm.rs
+2
-1
No files found.
src/ast/src/inst.rs
View file @
c9de0874
...
...
@@ -766,7 +766,7 @@ impl Instruction {
ret
.push_str
(
" "
);
}
}
ret
.push_str
(
"}
}
"
);
ret
.push_str
(
"}"
);
ret
}
...
...
src/ast/src/ir.rs
View file @
c9de0874
...
...
@@ -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
();
...
...
src/compiler/backend/arch/aarch64/asm_backend.rs
View file @
c9de0874
...
...
@@ -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
);
...
...
src/compiler/backend/arch/x86_64/asm_backend.rs
View file @
c9de0874
...
...
@@ -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
);
...
...
src/compiler/backend/code_emission.rs
View file @
c9de0874
...
...
@@ -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
();
...
...
src/compiler/passes/dot_gen.rs
View file @
c9de0874
...
...
@@ -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();
}
// "
];
...
...
src/compiler/passes/uir_gen.rs
View file @
c9de0874
...
...
@@ -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
();
...
...
src/vm/mod.rs
View file @
c9de0874
...
...
@@ -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
;
...
...
src/vm/uir_output.rs
0 → 100644
View file @
c9de0874
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
(
_
)
=>
{}
}
}
src/vm/vm.rs
View file @
c9de0874
...
...
@@ -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
)
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment