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
a797959a
Commit
a797959a
authored
Oct 21, 2016
by
Kunshan Wang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
IRBuilder: Build sigs.
parent
b362e1ec
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
1 deletion
+64
-1
src/vm/api/api_impl/muirbuilder.rs
src/vm/api/api_impl/muirbuilder.rs
+54
-1
tests/test_ir/test_builder_api.rs
tests/test_ir/test_builder_api.rs
+10
-0
No files found.
src/vm/api/api_impl/muirbuilder.rs
View file @
a797959a
...
...
@@ -132,7 +132,8 @@ impl MuIRBuilder {
}
pub
fn
new_type_ufuncptr
(
&
mut
self
,
id
:
MuID
,
sig
:
MuID
)
{
panic!
(
"Not implemented"
)
self
.bundle.types
.insert
(
id
,
Box
::
new
(
NodeType
::
TypeUFuncPtr
{
id
:
id
,
sig
:
sig
}));
}
pub
fn
new_type_struct
(
&
mut
self
,
id
:
MuID
,
fieldtys
:
Vec
<
MuID
>
)
{
...
...
@@ -478,12 +479,22 @@ impl<'lb, 'lvm> BundleLoader<'lb, 'lvm> {
for
(
id
,
ref
tag
)
in
struct_id_tags
{
self
.fill_struct
(
id
,
tag
)
}
for
id
in
self
.b.bundle.sigs
.keys
()
{
if
!
self
.visited
.contains
(
id
)
{
self
.build_sig
(
*
id
)
}
}
}
fn
name_from_id
(
id
:
MuID
,
hint
:
&
str
)
->
String
{
format!
(
"@uvm.unnamed{}{}"
,
hint
,
id
)
}
// fn maybe_get_name(&self, id: MuID) -> Option<String> {
// self.b.id_name_map.get(id).cloned()
// }
fn
get_name_or_make
(
&
self
,
id
:
MuID
,
hint
:
&
str
)
->
String
{
match
self
.b.id_name_map
.get
(
&
id
)
{
Some
(
n
)
=>
n
.clone
(),
...
...
@@ -491,6 +502,10 @@ impl<'lb, 'lvm> BundleLoader<'lb, 'lvm> {
}
}
// fn make_mu_entity_header(&self, id: MuID, hint: &str) -> MuEntityHeader {
// MuEntityHeader::named(id, self.get_name_or_make(id, hint))
// }
fn
build_type
(
&
mut
self
,
id
:
MuID
)
{
self
.visited
.insert
(
id
);
...
...
@@ -506,6 +521,10 @@ impl<'lb, 'lvm> BundleLoader<'lb, 'lvm> {
let
toty_i
=
self
.ensure_type_rec
(
toty
);
MuType_
::
UPtr
(
toty_i
)
},
NodeType
::
TypeUFuncPtr
{
id
:
_
,
sig
:
sig
}
=>
{
let
sig_i
=
self
.ensure_sig_rec
(
sig
);
MuType_
::
UFuncPtr
(
sig_i
)
},
NodeType
::
TypeStruct
{
id
:
_
,
fieldtys
:
_
}
=>
{
let
tag
=
self
.get_name_or_make
(
id
,
"struct"
);
self
.struct_id_tags
.push
((
id
,
tag
.clone
()));
...
...
@@ -565,5 +584,39 @@ impl<'lb, 'lvm> BundleLoader<'lb, 'lvm> {
ref
t
=>
panic!
(
"{} {:?} should be a Struct type"
,
id
,
ty
),
}
}
fn
build_sig
(
&
mut
self
,
id
:
MuID
)
{
self
.visited
.insert
(
id
);
let
sig
=
self
.b.bundle.sigs
.get
(
&
id
)
.unwrap
();
trace!
(
"Building function signature {} {:?}"
,
id
,
sig
);
let
impl_sig
=
MuFuncSig
{
hdr
:
MuEntityHeader
::
unnamed
(
id
),
ret_tys
:
sig
.rettys
.iter
()
.map
(|
i
|
self
.ensure_type_rec
(
*
i
))
.collect
::
<
Vec
<
_
>>
(),
arg_tys
:
sig
.paramtys
.iter
()
.map
(|
i
|
self
.ensure_type_rec
(
*
i
))
.collect
::
<
Vec
<
_
>>
(),
};
trace!
(
"Function signature built: {} {:?}"
,
id
,
impl_sig
);
self
.built_sigs
.insert
(
id
,
P
(
impl_sig
));
}
fn
ensure_sig_rec
(
&
mut
self
,
id
:
MuID
)
->
P
<
MuFuncSig
>
{
if
self
.b.bundle.sigs
.contains_key
(
&
id
)
{
if
self
.visited
.contains
(
&
id
)
{
match
self
.built_sigs
.get
(
&
id
)
{
Some
(
t
)
=>
t
.clone
(),
None
=>
panic!
(
"Cyclic signature found. id: {}"
,
id
)
}
}
else
{
self
.build_sig
(
id
);
self
.built_sigs
.get
(
&
id
)
.unwrap
()
.clone
()
}
}
else
{
self
.vm
.get_func_sig
(
id
)
}
}
}
tests/test_ir/test_builder_api.rs
View file @
a797959a
...
...
@@ -102,6 +102,16 @@ fn test_types_sigs_loading() {
let
mut
fields
=
vec!
[
id3
,
id7
];
((
*
b
)
.new_type_struct
)(
b
,
id6
,
fields
.as_mut_ptr
(),
fields
.len
());
((
*
b
)
.new_type_uptr
)(
b
,
id7
,
id6
);
let
id8
=
((
*
b
)
.gen_sym
)(
b
,
csp
.get
(
"@sig1"
));
let
id9
=
((
*
b
)
.gen_sym
)(
b
,
csp
.get
(
"@funcptr1"
));
let
mut
ptys
=
vec!
[
id1
,
id2
];
let
mut
rtys
=
vec!
[
id3
,
id7
];
((
*
b
)
.new_funcsig
)(
b
,
id8
,
ptys
.as_mut_ptr
(),
ptys
.len
(),
rtys
.as_mut_ptr
(),
rtys
.len
());
((
*
b
)
.new_type_ufuncptr
)(
b
,
id9
,
id8
);
((
*
b
)
.load
)(
b
);
((
*
ctx
)
.close_context
)(
ctx
);
...
...
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