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
59d6a895
Commit
59d6a895
authored
1 year ago
by
Russel Arbore
Browse files
Options
Downloads
Patches
Plain Diff
Skeleton IR parsing code
parent
55718b78
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
hercules_ir/src/ir.rs
+42
-53
42 additions, 53 deletions
hercules_ir/src/ir.rs
hercules_ir/src/lib.rs
+2
-0
2 additions, 0 deletions
hercules_ir/src/lib.rs
hercules_ir/src/parse.rs
+55
-0
55 additions, 0 deletions
hercules_ir/src/parse.rs
with
99 additions
and
53 deletions
hercules_ir/src/ir.rs
+
42
−
53
View file @
59d6a895
pub
struct
FunctionID
(
u32
);
pub
struct
NodeID
(
u32
);
const
NULL_NODE
:
NodeID
=
NodeID
(
0xFFFFFFFF
);
pub
struct
ConstantID
(
u32
);
pub
struct
TypeID
(
u32
);
#[derive(Clone)]
pub
struct
Module
{
functions
:
Vec
<
Function
>
,
type
d
:
Vec
<
Type
>
,
constants
:
Vec
<
Constant
>
,
pub
functions
:
Vec
<
Function
>
,
pub
type
s
:
Vec
<
Type
>
,
pub
constants
:
Vec
<
Constant
>
,
}
#[derive(Clone)]
pub
struct
Function
{
name
:
String
,
nodes
:
Vec
<
Node
>
,
pub
name
:
String
,
pub
nodes
:
Vec
<
Node
>
,
}
#[derive(Clone)]
pub
enum
Type
{
Control
,
Control
(
u64
)
,
Integer8
,
Integer16
,
Integer32
,
...
...
@@ -28,6 +22,7 @@ pub enum Type {
Float64
,
}
#[derive(Clone)]
pub
enum
Constant
{
Integer8
(
u8
),
Integer16
(
u16
),
...
...
@@ -37,6 +32,7 @@ pub enum Constant {
Float64
(
f64
),
}
#[derive(Clone)]
pub
enum
Node
{
Start
,
Region
{
...
...
@@ -46,6 +42,14 @@ pub enum Node {
control
:
NodeID
,
cond
:
NodeID
,
},
Fork
{
control
:
NodeID
,
factor
:
u64
,
},
Join
{
control
:
NodeID
,
factor
:
u64
,
},
Phi
{
control
:
NodeID
,
data
:
Box
<
[
NodeID
]
>
,
...
...
@@ -54,6 +58,9 @@ pub enum Node {
control
:
NodeID
,
value
:
NodeID
,
},
Parameter
{
index
:
u64
,
},
Constant
{
id
:
ConstantID
,
},
...
...
@@ -82,56 +89,38 @@ pub enum Node {
},
}
impl
From
<
u32
>
for
FunctionID
{
fn
from
(
v
:
u32
)
->
Self
{
FunctionID
(
v
)
}
}
impl
From
<
u64
>
for
FunctionID
{
fn
from
(
v
:
u64
)
->
Self
{
FunctionID
(
v
as
u32
)
}
}
#[derive(Clone)]
pub
struct
FunctionID
(
u32
);
impl
From
<
usize
>
for
FunctionID
{
fn
from
(
v
:
usize
)
->
Self
{
FunctionID
(
v
as
u
32
)
impl
FunctionID
{
pub
fn
idx
(
&
self
)
->
usize
{
self
.0
as
u
size
}
}
impl
From
<
u32
>
for
NodeID
{
fn
from
(
v
:
u32
)
->
Self
{
NodeID
(
v
)
}
}
#[derive(Clone)]
pub
struct
NodeID
(
u32
);
impl
From
<
u64
>
for
NodeID
{
fn
from
(
v
:
u64
)
->
Self
{
NodeID
(
v
as
u
32
)
impl
NodeID
{
pub
fn
idx
(
&
self
)
->
usize
{
self
.0
as
u
size
}
}
impl
From
<
usize
>
for
NodeID
{
fn
from
(
v
:
usize
)
->
Self
{
NodeID
(
v
as
u32
)
}
}
#[derive(Clone)]
pub
struct
ConstantID
(
u32
);
impl
From
<
u32
>
for
ConstantID
{
fn
from
(
v
:
u32
)
->
Self
{
ConstantID
(
v
)
impl
ConstantID
{
pub
fn
idx
(
&
self
)
->
usize
{
self
.0
as
usize
}
}
impl
From
<
u64
>
for
ConstantID
{
fn
from
(
v
:
u64
)
->
Self
{
ConstantID
(
v
as
u32
)
}
}
#[derive(Clone)]
pub
struct
TypeID
(
u32
);
impl
From
<
usize
>
for
Constant
ID
{
fn
from
(
v
:
usize
)
->
Self
{
ConstantID
(
v
as
u
32
)
impl
Type
ID
{
pub
fn
idx
(
&
self
)
->
usize
{
self
.0
as
u
size
}
}
This diff is collapsed.
Click to expand it.
hercules_ir/src/lib.rs
+
2
−
0
View file @
59d6a895
pub
mod
ir
;
pub
mod
parse
;
pub
use
crate
::
ir
::
*
;
pub
use
crate
::
parse
::
*
;
This diff is collapsed.
Click to expand it.
hercules_ir/src/parse.rs
0 → 100644
+
55
−
0
View file @
59d6a895
extern
crate
nom
;
use
std
::
collections
::
HashMap
;
use
crate
::
*
;
fn
parse
(
ir_test
:
&
str
)
->
Module
{
parse_module
(
ir_test
,
Context
::
default
())
.unwrap
()
.1
}
#[derive(Default)]
struct
Context
<
'a
>
{
function_ids
:
HashMap
<&
'a
str
,
FunctionID
>
,
node_ids
:
HashMap
<&
'a
str
,
NodeID
>
,
interned_types
:
HashMap
<
Type
,
TypeID
>
,
interned_constants
:
HashMap
<
Constant
,
ConstantID
>
,
}
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
)
?
;
nom
::
combinator
::
eof
(
rest
)
?
;
let
mut
types
=
vec!
[
Type
::
Control
(
0
);
context
.interned_types
.len
()];
for
(
ty
,
id
)
in
context
.interned_types
{
types
[
id
.idx
()]
=
ty
;
}
let
mut
constants
=
vec!
[
Constant
::
Integer8
(
0
);
context
.interned_constants
.len
()];
for
(
constant
,
id
)
in
context
.interned_constants
{
constants
[
id
.idx
()]
=
constant
;
}
Ok
((
rest
,
Module
{
functions
,
types
,
constants
,
},
))
}
fn
parse_function
<
'a
>
(
ir_text
:
&
'a
str
,
context
:
&
mut
Context
<
'a
>
,
)
->
nom
::
IResult
<&
'a
str
,
Function
>
{
todo!
()
}
mod
tests
{
#[allow(unused_imports)]
use
super
::
*
;
#[test]
fn
parse_ir1
()
{
parse
(
"fn add(x: i32, y: i32) -> i32 return(z) z = add(start, x, y)"
);
}
}
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