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
30d607ac
Commit
30d607ac
authored
1 year ago
by
Russel Arbore
Browse files
Options
Downloads
Patches
Plain Diff
Parse type, use ordered_float
parent
42347bb6
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
Cargo.lock
+25
-0
25 additions, 0 deletions
Cargo.lock
hercules_ir/Cargo.toml
+2
-1
2 additions, 1 deletion
hercules_ir/Cargo.toml
hercules_ir/src/ir.rs
+10
-8
10 additions, 8 deletions
hercules_ir/src/ir.rs
hercules_ir/src/parse.rs
+13
-4
13 additions, 4 deletions
hercules_ir/src/parse.rs
with
50 additions
and
13 deletions
Cargo.lock
+
25
−
0
View file @
30d607ac
...
...
@@ -2,11 +2,18 @@
# It is not intended for manual editing.
version = 3
[[package]]
name = "autocfg"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "hercules_ir"
version = "0.1.0"
dependencies = [
"nom",
"ordered-float",
]
[[package]]
...
...
@@ -30,3 +37,21 @@ dependencies = [
"memchr",
"minimal-lexical",
]
[[package]]
name = "num-traits"
version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f30b0abd723be7e2ffca1272140fac1a2f084c77ec3e123c192b66af1ee9e6c2"
dependencies = [
"autocfg",
]
[[package]]
name = "ordered-float"
version = "3.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2a54938017eacd63036332b4ae5c8a49fc8c0c1d6d629893057e4f13609edd06"
dependencies = [
"num-traits",
]
This diff is collapsed.
Click to expand it.
hercules_ir/Cargo.toml
+
2
−
1
View file @
30d607ac
...
...
@@ -4,4 +4,5 @@ version = "0.1.0"
authors
=
[
"Russel Arbore <rarbore2@illinois.edu>"
]
[dependencies]
nom
=
"*"
\ No newline at end of file
nom
=
"*"
ordered-float
=
"*"
\ No newline at end of file
This diff is collapsed.
Click to expand it.
hercules_ir/src/ir.rs
+
10
−
8
View file @
30d607ac
extern
crate
ordered_float
;
#[derive(Clone)]
pub
struct
Module
{
pub
functions
:
Vec
<
Function
>
,
...
...
@@ -13,7 +15,7 @@ pub struct Function {
pub
nodes
:
Vec
<
Node
>
,
}
#[derive(Clone)]
#[derive(Clone
,
PartialEq,
Eq,
Hash
)]
pub
enum
Type
{
Control
(
u64
),
Integer8
,
...
...
@@ -24,14 +26,14 @@ pub enum Type {
Float64
,
}
#[derive(Clone)]
#[derive(Clone
,
PartialEq,
Eq,
Hash
)]
pub
enum
Constant
{
Integer8
(
u8
),
Integer16
(
u16
),
Integer32
(
u32
),
Integer64
(
u64
),
Float32
(
f32
),
Float64
(
f64
),
Float32
(
ordered_float
::
OrderedFloat
<
f32
>
),
Float64
(
ordered_float
::
OrderedFloat
<
f64
>
),
}
#[derive(Clone)]
...
...
@@ -91,7 +93,7 @@ pub enum Node {
},
}
#[derive(Clone)]
#[derive(Clone
,
Copy
)]
pub
struct
FunctionID
(
u32
);
impl
FunctionID
{
...
...
@@ -104,7 +106,7 @@ impl FunctionID {
}
}
#[derive(Clone)]
#[derive(Clone
,
Copy
)]
pub
struct
NodeID
(
u32
);
impl
NodeID
{
...
...
@@ -117,7 +119,7 @@ impl NodeID {
}
}
#[derive(Clone)]
#[derive(Clone
,
Copy
)]
pub
struct
ConstantID
(
u32
);
impl
ConstantID
{
...
...
@@ -130,7 +132,7 @@ impl ConstantID {
}
}
#[derive(Clone)]
#[derive(Clone
,
Copy
)]
pub
struct
TypeID
(
u32
);
impl
TypeID
{
...
...
This diff is collapsed.
Click to expand it.
hercules_ir/src/parse.rs
+
13
−
4
View file @
30d607ac
...
...
@@ -76,7 +76,7 @@ fn parse_function<'a>(
for
(
_
,
id
)
in
context
.node_ids
.iter
()
{
fixed_nodes
[
id
.idx
()]
=
Node
::
Parameter
{
index
:
id
.idx
()
}
}
return
Ok
((
Ok
((
ir_text
,
Function
{
name
:
String
::
from
(
function_name
),
...
...
@@ -84,7 +84,7 @@ fn parse_function<'a>(
return_type
,
nodes
:
fixed_nodes
,
},
))
;
))
}
fn
parse_node
<
'a
>
(
...
...
@@ -95,7 +95,16 @@ fn parse_node<'a>(
}
fn
parse_type
<
'a
>
(
ir_text
:
&
'a
str
,
context
:
&
mut
Context
<
'a
>
)
->
nom
::
IResult
<&
'a
str
,
TypeID
>
{
todo!
()
let
(
ir_text
,
ty
)
=
nom
::
combinator
::
map
(
nom
::
bytes
::
complete
::
tag
(
"i32"
),
|
_
|
Type
::
Integer32
)(
ir_text
)
?
;
let
id
=
if
let
Some
(
id
)
=
context
.interned_types
.get
(
&
ty
)
{
*
id
}
else
{
let
id
=
TypeID
::
new
(
context
.interned_types
.len
());
context
.interned_types
.insert
(
ty
,
id
);
id
};
Ok
((
ir_text
,
id
))
}
fn
parse_constant
<
'a
>
(
...
...
@@ -111,6 +120,6 @@ mod tests {
#[test]
fn
parse_ir1
()
{
parse
(
"fn add(x: i32, y: i32) -> i32 return(z) z = add(start, x, y)"
);
parse
(
"fn add(x: i32, y: i32) -> i32
r =
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