Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mu-impl-fast
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
40
Issues
40
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
mu
mu-impl-fast
Commits
f192c70c
Commit
f192c70c
authored
Jul 19, 2016
by
qinsoon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[wip] code emission is specific to plat/backend
parent
18349852
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
44 additions
and
35 deletions
+44
-35
src/compiler/backend/arch/x86_64/asm_backend.rs
src/compiler/backend/arch/x86_64/asm_backend.rs
+35
-0
src/compiler/backend/arch/x86_64/mod.rs
src/compiler/backend/arch/x86_64/mod.rs
+2
-0
src/compiler/backend/code_emission.rs
src/compiler/backend/code_emission.rs
+2
-30
src/compiler/backend/mod.rs
src/compiler/backend/mod.rs
+4
-5
tests/test_compiler/test_global.rs
tests/test_compiler/test_global.rs
+1
-0
No files found.
src/compiler/backend/arch/x86_64/asm_backend.rs
View file @
f192c70c
...
...
@@ -4,6 +4,7 @@ use compiler::backend;
use
compiler
::
backend
::
x86_64
;
use
compiler
::
backend
::
x86_64
::
CodeGenerator
;
use
vm
::
machine_code
::
MachineCode
;
use
vm
::
context
::
VMContext
;
use
utils
::
string_utils
;
...
...
@@ -1060,3 +1061,37 @@ impl CodeGenerator for ASMCodeGen {
)
}
}
pub
fn
emit_code
(
func
:
&
mut
MuFunctionVersion
,
vm
:
&
VMContext
)
{
use
std
::
io
::
prelude
::
*
;
use
std
::
fs
::
File
;
use
std
::
fs
;
let
compiled_funcs
=
vm
.compiled_funcs
()
.read
()
.unwrap
();
let
cf
=
compiled_funcs
.get
(
func
.fn_name
)
.unwrap
()
.borrow
();
let
code
=
cf
.mc
.emit
();
const
EMIT_DIR
:
&
'static
str
=
"emit"
;
match
fs
::
create_dir
(
EMIT_DIR
)
{
Ok
(
_
)
=>
{},
Err
(
_
)
=>
{}
}
let
file_name
=
EMIT_DIR
.to_string
()
+
"/"
+
func
.fn_name
+
".s"
;
let
mut
file
=
match
File
::
create
(
file_name
.clone
())
{
Err
(
why
)
=>
panic!
(
"couldn't create emission file {}: {}"
,
file_name
,
why
),
Ok
(
file
)
=>
file
};
match
file
.write_all
(
code
.as_slice
())
{
Err
(
why
)
=>
panic!
(
"couldn'd write to file {}: {}"
,
file_name
,
why
),
Ok
(
_
)
=>
println!
(
"emit code to {}"
,
file_name
)
}
}
pub
fn
emit_context
(
vm
:
&
VMContext
)
{
debug!
(
"---Emit VM Context---"
);
debug!
(
"---finish---"
);
}
\ No newline at end of file
src/compiler/backend/arch/x86_64/mod.rs
View file @
f192c70c
...
...
@@ -8,6 +8,8 @@ pub use compiler::backend::x86_64::codegen::CodeGenerator;
mod
asm_backend
;
pub
use
compiler
::
backend
::
x86_64
::
asm_backend
::
ASMCodeGen
;
pub
use
compiler
::
backend
::
x86_64
::
asm_backend
::
emit_code
;
pub
use
compiler
::
backend
::
x86_64
::
asm_backend
::
emit_context
;
use
ast
::
ptr
::
P
;
use
ast
::
ir
::
*
;
...
...
src/compiler/backend/code_emission.rs
View file @
f192c70c
...
...
@@ -3,6 +3,7 @@
use
compiler
::
CompilerPass
;
use
ast
::
ir
::
*
;
use
vm
::
context
::
VMContext
;
use
compiler
::
backend
::
emit_code
;
pub
struct
CodeEmission
{
name
:
&
'static
str
...
...
@@ -22,35 +23,6 @@ impl CompilerPass for CodeEmission {
}
fn
visit_function
(
&
mut
self
,
vm_context
:
&
VMContext
,
func
:
&
mut
MuFunctionVersion
)
{
use
std
::
io
::
prelude
::
*
;
use
std
::
fs
::
File
;
use
std
::
fs
;
let
compiled_funcs
=
vm_context
.compiled_funcs
()
.read
()
.unwrap
();
let
cf
=
compiled_funcs
.get
(
func
.fn_name
)
.unwrap
()
.borrow
();
let
code
=
cf
.mc
.emit
();
// FIXME: this is only for asm backend
const
EMIT_DIR
:
&
'static
str
=
"emit"
;
// match fs::remove_dir_all(EMIT_DIR) {
// Ok(dir) => {},
// Err(_) => {}
// }
match
fs
::
create_dir
(
EMIT_DIR
)
{
Ok
(
_
)
=>
{},
Err
(
_
)
=>
{}
}
let
file_name
=
EMIT_DIR
.to_string
()
+
"/"
+
func
.fn_name
+
".s"
;
let
mut
file
=
match
File
::
create
(
file_name
.clone
())
{
Err
(
why
)
=>
panic!
(
"couldn't create emission file {}: {}"
,
file_name
,
why
),
Ok
(
file
)
=>
file
};
match
file
.write_all
(
code
.as_slice
())
{
Err
(
why
)
=>
panic!
(
"couldn'd write to file {}: {}"
,
file_name
,
why
),
Ok
(
_
)
=>
println!
(
"emit code to {}"
,
file_name
)
}
emit_code
(
func
,
vm_context
);
}
}
src/compiler/backend/mod.rs
View file @
f192c70c
...
...
@@ -25,12 +25,11 @@ pub use compiler::backend::x86_64::all_usable_regs;
pub
use
compiler
::
backend
::
x86_64
::
pick_group_for_reg
;
#[cfg(target_arch
=
"x86_64"
)]
pub
use
compiler
::
backend
::
x86_64
::
is_callee_saved
;
#[cfg(target_arch
=
"x86_64"
)]
pub
use
compiler
::
backend
::
x86_64
::
emit_code
;
#[cfg(target_arch
=
"x86_64"
)]
pub
use
compiler
::
backend
::
x86_64
::
emit_context
;
#[cfg(target_arch
=
"arm"
)]
#[path
=
"arch/arm/mod.rs"
]
mod
arm
;
#[cfg(target_arch
=
"arm"
)]
pub
use
compiler
::
backend
::
arm
::
GPR_COUNT
;
#[cfg(target_arch
=
"arm"
)]
pub
use
compiler
::
backend
::
arm
::
FPR_COUNT
;
tests/test_compiler/test_global.rs
View file @
f192c70c
...
...
@@ -30,4 +30,5 @@ fn test_global_access() {
let
mut
func_ver
=
func_vers
.get
(
&
(
func
.fn_name
,
func
.cur_ver
.unwrap
()))
.unwrap
()
.borrow_mut
();
compiler
.compile
(
&
mut
func_ver
);
backend
::
emit_context
(
&
vm_context
);
}
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