Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
Hercules
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
llvm
Hercules
Commits
42347bb6
Commit
42347bb6
authored
1 year ago
by
Russel Arbore
Browse files
Options
Downloads
Patches
Plain Diff
Parse function
parent
59d6a895
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
hercules_ir/src/ir.rs
+21
-3
21 additions, 3 deletions
hercules_ir/src/ir.rs
hercules_ir/src/parse.rs
+63
-2
63 additions, 2 deletions
hercules_ir/src/parse.rs
with
84 additions
and
5 deletions
hercules_ir/src/ir.rs
+
21
−
3
View file @
42347bb6
...
@@ -8,6 +8,8 @@ pub struct Module {
...
@@ -8,6 +8,8 @@ pub struct Module {
#[derive(Clone)]
#[derive(Clone)]
pub
struct
Function
{
pub
struct
Function
{
pub
name
:
String
,
pub
name
:
String
,
pub
param_types
:
Vec
<
TypeID
>
,
pub
return_type
:
TypeID
,
pub
nodes
:
Vec
<
Node
>
,
pub
nodes
:
Vec
<
Node
>
,
}
}
...
@@ -44,11 +46,11 @@ pub enum Node {
...
@@ -44,11 +46,11 @@ pub enum Node {
},
},
Fork
{
Fork
{
control
:
NodeID
,
control
:
NodeID
,
factor
:
u
64
,
factor
:
u
size
,
},
},
Join
{
Join
{
control
:
NodeID
,
control
:
NodeID
,
factor
:
u
64
,
factor
:
u
size
,
},
},
Phi
{
Phi
{
control
:
NodeID
,
control
:
NodeID
,
...
@@ -59,7 +61,7 @@ pub enum Node {
...
@@ -59,7 +61,7 @@ pub enum Node {
value
:
NodeID
,
value
:
NodeID
,
},
},
Parameter
{
Parameter
{
index
:
u
64
,
index
:
u
size
,
},
},
Constant
{
Constant
{
id
:
ConstantID
,
id
:
ConstantID
,
...
@@ -93,6 +95,10 @@ pub enum Node {
...
@@ -93,6 +95,10 @@ pub enum Node {
pub
struct
FunctionID
(
u32
);
pub
struct
FunctionID
(
u32
);
impl
FunctionID
{
impl
FunctionID
{
pub
fn
new
(
x
:
usize
)
->
Self
{
FunctionID
(
x
as
u32
)
}
pub
fn
idx
(
&
self
)
->
usize
{
pub
fn
idx
(
&
self
)
->
usize
{
self
.0
as
usize
self
.0
as
usize
}
}
...
@@ -102,6 +108,10 @@ impl FunctionID {
...
@@ -102,6 +108,10 @@ impl FunctionID {
pub
struct
NodeID
(
u32
);
pub
struct
NodeID
(
u32
);
impl
NodeID
{
impl
NodeID
{
pub
fn
new
(
x
:
usize
)
->
Self
{
NodeID
(
x
as
u32
)
}
pub
fn
idx
(
&
self
)
->
usize
{
pub
fn
idx
(
&
self
)
->
usize
{
self
.0
as
usize
self
.0
as
usize
}
}
...
@@ -111,6 +121,10 @@ impl NodeID {
...
@@ -111,6 +121,10 @@ impl NodeID {
pub
struct
ConstantID
(
u32
);
pub
struct
ConstantID
(
u32
);
impl
ConstantID
{
impl
ConstantID
{
pub
fn
new
(
x
:
usize
)
->
Self
{
ConstantID
(
x
as
u32
)
}
pub
fn
idx
(
&
self
)
->
usize
{
pub
fn
idx
(
&
self
)
->
usize
{
self
.0
as
usize
self
.0
as
usize
}
}
...
@@ -120,6 +134,10 @@ impl ConstantID {
...
@@ -120,6 +134,10 @@ impl ConstantID {
pub
struct
TypeID
(
u32
);
pub
struct
TypeID
(
u32
);
impl
TypeID
{
impl
TypeID
{
pub
fn
new
(
x
:
usize
)
->
Self
{
TypeID
(
x
as
u32
)
}
pub
fn
idx
(
&
self
)
->
usize
{
pub
fn
idx
(
&
self
)
->
usize
{
self
.0
as
usize
self
.0
as
usize
}
}
...
...
This diff is collapsed.
Click to expand it.
hercules_ir/src/parse.rs
+
63
−
2
View file @
42347bb6
...
@@ -17,8 +17,10 @@ struct Context<'a> {
...
@@ -17,8 +17,10 @@ struct Context<'a> {
}
}
fn
parse_module
<
'a
>
(
ir_text
:
&
'a
str
,
mut
context
:
Context
<
'a
>
)
->
nom
::
IResult
<&
'a
str
,
Module
>
{
fn
parse_module
<
'a
>
(
ir_text
:
&
'a
str
,
mut
context
:
Context
<
'a
>
)
->
nom
::
IResult
<&
'a
str
,
Module
>
{
let
(
rest
,
functions
)
=
nom
::
multi
::
many0
(|
x
|
parse_function
(
x
,
&
mut
context
))(
ir_text
)
?
;
let
(
rest
,
functions
)
=
nom
::
combinator
::
eof
(
rest
)
?
;
nom
::
combinator
::
all_consuming
(
nom
::
multi
::
many0
(|
x
|
parse_function
(
x
,
&
mut
context
)))(
ir_text
,
)
?
;
let
mut
types
=
vec!
[
Type
::
Control
(
0
);
context
.interned_types
.len
()];
let
mut
types
=
vec!
[
Type
::
Control
(
0
);
context
.interned_types
.len
()];
for
(
ty
,
id
)
in
context
.interned_types
{
for
(
ty
,
id
)
in
context
.interned_types
{
types
[
id
.idx
()]
=
ty
;
types
[
id
.idx
()]
=
ty
;
...
@@ -41,6 +43,65 @@ fn parse_function<'a>(
...
@@ -41,6 +43,65 @@ fn parse_function<'a>(
ir_text
:
&
'a
str
,
ir_text
:
&
'a
str
,
context
:
&
mut
Context
<
'a
>
,
context
:
&
mut
Context
<
'a
>
,
)
->
nom
::
IResult
<&
'a
str
,
Function
>
{
)
->
nom
::
IResult
<&
'a
str
,
Function
>
{
context
.node_ids
.clear
();
let
ir_text
=
nom
::
character
::
complete
::
multispace0
(
ir_text
)
?
.0
;
let
ir_text
=
nom
::
bytes
::
complete
::
tag
(
"fn"
)(
ir_text
)
?
.0
;
let
ir_text
=
nom
::
character
::
complete
::
multispace0
(
ir_text
)
?
.0
;
let
(
ir_text
,
function_name
)
=
nom
::
character
::
complete
::
alphanumeric0
(
ir_text
)
?
;
let
ir_text
=
nom
::
character
::
complete
::
char
(
'('
)(
ir_text
)
?
.0
;
let
(
ir_text
,
params
)
=
nom
::
multi
::
separated_list0
(
nom
::
character
::
complete
::
char
(
','
),
nom
::
sequence
::
tuple
((
nom
::
character
::
complete
::
alphanumeric1
,
nom
::
character
::
complete
::
multispace0
,
nom
::
character
::
complete
::
char
(
':'
),
nom
::
character
::
complete
::
multispace0
,
|
x
|
parse_type
(
x
,
context
),
)),
)(
ir_text
)
?
;
for
param
in
params
.iter
()
{
context
.node_ids
.insert
(
param
.0
,
NodeID
::
new
(
context
.node_ids
.len
()));
}
let
ir_text
=
nom
::
character
::
complete
::
char
(
')'
)(
ir_text
)
?
.0
;
let
ir_text
=
nom
::
character
::
complete
::
multispace0
(
ir_text
)
?
.0
;
let
ir_text
=
nom
::
bytes
::
complete
::
tag
(
"->"
)(
ir_text
)
?
.0
;
let
(
ir_text
,
return_type
)
=
parse_type
(
ir_text
,
context
)
?
;
let
(
ir_text
,
nodes
)
=
nom
::
multi
::
many1
(|
x
|
parse_node
(
x
,
context
))(
ir_text
)
?
;
let
mut
fixed_nodes
=
vec!
[
Node
::
Start
;
context
.node_ids
.len
()];
for
(
name
,
node
)
in
nodes
{
fixed_nodes
[
context
.node_ids
.remove
(
name
)
.unwrap
()
.idx
()]
=
node
;
}
for
(
_
,
id
)
in
context
.node_ids
.iter
()
{
fixed_nodes
[
id
.idx
()]
=
Node
::
Parameter
{
index
:
id
.idx
()
}
}
return
Ok
((
ir_text
,
Function
{
name
:
String
::
from
(
function_name
),
param_types
:
params
.into_iter
()
.map
(|
x
|
x
.4
)
.collect
(),
return_type
,
nodes
:
fixed_nodes
,
},
));
}
fn
parse_node
<
'a
>
(
ir_text
:
&
'a
str
,
context
:
&
mut
Context
<
'a
>
,
)
->
nom
::
IResult
<&
'a
str
,
(
&
'a
str
,
Node
)
>
{
todo!
()
}
fn
parse_type
<
'a
>
(
ir_text
:
&
'a
str
,
context
:
&
mut
Context
<
'a
>
)
->
nom
::
IResult
<&
'a
str
,
TypeID
>
{
todo!
()
}
fn
parse_constant
<
'a
>
(
ir_text
:
&
'a
str
,
context
:
&
mut
Context
<
'a
>
,
)
->
nom
::
IResult
<&
'a
str
,
ConstantID
>
{
todo!
()
todo!
()
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment