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
52b8e828
Commit
52b8e828
authored
Oct 11, 2017
by
Isaac Oscar Gariano
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added forgotten file (I will never stop forgeting them...)
parent
4d267476
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
127 additions
and
0 deletions
+127
-0
src/vm/uir_output.rs
src/vm/uir_output.rs
+127
-0
No files found.
src/vm/uir_output.rs
0 → 100644
View file @
52b8e828
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
(
_
)
=>
{}
}
}
\ No newline at end of file
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