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
212638e9
Commit
212638e9
authored
Mar 15, 2016
by
qinsoon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactored ast
parent
e31a5a4b
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
279 additions
and
257 deletions
+279
-257
src/ast/ir.rs
src/ast/ir.rs
+175
-229
src/ast/mod.rs
src/ast/mod.rs
+2
-1
src/ast/op.rs
src/ast/op.rs
+73
-0
src/ast/types.rs
src/ast/types.rs
+1
-1
tests/test_ir/test_ir.rs
tests/test_ir/test_ir.rs
+28
-26
No files found.
src/ast/ir.rs
View file @
212638e9
This diff is collapsed.
Click to expand it.
src/ast/mod.rs
View file @
212638e9
pub
mod
types
;
pub
mod
ir
;
pub
mod
ptr
;
\ No newline at end of file
pub
mod
ptr
;
pub
mod
op
;
\ No newline at end of file
src/ast/op.rs
0 → 100644
View file @
212638e9
#[derive(Copy,
Clone,
Debug)]
pub
enum
BinOp
{
// Int(n) BinOp Int(n) -> Int(n)
Add
,
Sub
,
Mul
,
Sdiv
,
Srem
,
Udiv
,
And
,
Or
,
Xor
,
// Int(n) BinOp Int(m) -> Int(n)
Shl
,
Lshr
,
AsHR
,
// FP BinOp FP -> FP
Fadd
,
FSub
,
FMul
,
FDiv
,
FRem
}
#[derive(Copy,
Clone,
Debug)]
pub
enum
CmpOp
{
// for Int comparison
EQ
,
NE
,
SGE
,
SGT
,
SLE
,
SLT
,
UGE
,
UGT
,
ULE
,
ULT
,
// for FP comparison
FFALSE
,
FTRUE
,
FOEQ
,
FOGT
,
FOGE
,
FOLT
,
FOLE
,
FONE
,
FORD
,
FUEQ
,
FUGT
,
FUGE
,
FULT
,
FULE
,
FUNE
,
FUNO
}
#[derive(Copy,
Clone,
Debug)]
pub
enum
AtomicRMWOp
{
XCHG
,
ADD
,
SUB
,
AND
,
NAND
,
OR
,
XOR
,
MAX
,
MIN
,
UMAX
,
UMIN
}
\ No newline at end of file
src/ast/types.rs
View file @
212638e9
extern
crate
std
;
use
ast
::
ptr
::
*
;
use
ast
::
ptr
::
P
;
use
ast
::
ir
::
*
;
use
std
::
collections
::
HashMap
;
use
std
::
sync
::
RwLock
;
...
...
tests/test_ir/test_ir.rs
View file @
212638e9
...
...
@@ -3,6 +3,7 @@ extern crate mu;
use
self
::
mu
::
ast
::
types
::
*
;
use
self
::
mu
::
ast
::
ir
::
*
;
use
self
::
mu
::
ast
::
ptr
::
*
;
use
self
::
mu
::
ast
::
op
::
*
;
use
self
::
mu
::
vm
::
context
::
*
;
#[test]
...
...
@@ -41,29 +42,30 @@ pub fn factorial() -> VMContext {
// %blk_0(<@int_64> %n_3):
let
mut
blk_0
=
Block
::
new
(
"blk_0"
);
let
blk_0_n_3
=
P
(
Value
::
SSAVar
(
SSAVar
{
id
:
0
,
tag
:
"n_3"
,
ty
:
type_def_int64
.clone
()}));
let
blk_0_n_3
=
TreeNode
::
new_value
(
Value
::
new_ssa
(
SSAVar
{
id
:
0
,
tag
:
"n_3"
,
ty
:
type_def_int64
.clone
()}));
let
const_def_int64_1_local
=
TreeNode
::
new_value
(
const_def_int64_1
.clone
());
// %v48 = EQ <@int_64> %n_3 @int_64_1
let
blk_0_v48
=
P
(
Value
::
SSAVar
(
SSAVar
{
id
:
1
,
tag
:
"v48"
,
ty
:
type_def_int64
.clone
()}));
let
blk_0_v48_expr
=
Expression
::
CmpOp
(
let
blk_0_v48
=
TreeNode
::
new_value
(
Value
::
new_ssa
(
SSAVar
{
id
:
1
,
tag
:
"v48"
,
ty
:
type_def_int64
.clone
()}));
let
blk_0_v48_expr
=
Expression
_
::
CmpOp
(
CmpOp
::
EQ
,
blk_0_n_3
.clone
(),
const_def_int64_1
.clone
()
const_def_int64_1
_local
.clone
()
);
let
blk_0_inst0
=
Instruction
::
NonTerm
(
NonTermInstruction
::
Assign
{
left
:
vec!
[
blk_0_v48
.clone
()],
right
:
blk_0_v48_expr
}
);
let
blk_0_inst0
=
TreeNode
::
new_inst
(
Instruction
::
NonTerm
(
NonTermInstruction
::
Assign
{
left
:
vec!
[
blk_0_v48
.clone
()],
right
:
blk_0_v48_expr
})
);
// BRANCH2 %v48 %blk_2(@int_64_1) %blk_1(%n_3)
let
blk_0_term
=
Instruction
::
Term
(
Terminal
::
Branch2
{
let
blk_0_term
=
TreeNode
::
new_inst
(
Instruction
::
Term
(
Terminal
::
Branch2
{
cond
:
blk_0_v48
.clone
(),
true_dest
:
Destination
{
target
:
"blk_2"
,
args
:
vec!
[
DestArg
::
Normal
(
const_def_int64_1
.clone
())]
args
:
vec!
[
DestArg
::
Normal
(
const_def_int64_1
_local
.clone
())]
},
false_dest
:
Destination
{
target
:
"blk_1"
,
args
:
vec!
[
DestArg
::
Normal
(
blk_0_n_3
.clone
())]
}
});
})
)
;
let
blk_0_content
=
BlockContent
{
args
:
vec!
[
blk_0_n_3
.clone
()],
...
...
@@ -74,10 +76,10 @@ pub fn factorial() -> VMContext {
// %blk_2(<@int_64> %v53):
let
mut
blk_2
=
Block
::
new
(
"blk_2"
);
let
blk_2_v53
=
P
(
Value
::
SSAVar
(
SSAVar
{
id
:
2
,
tag
:
"v53"
,
ty
:
type_def_int64
.clone
()}));
let
blk_2_v53
=
TreeNode
::
new_value
(
Value
::
new_ssa
(
SSAVar
{
id
:
2
,
tag
:
"v53"
,
ty
:
type_def_int64
.clone
()}));
// RET %v53
let
blk_2_term
=
Instruction
::
Term
(
Terminal
::
Return
(
vec!
[
blk_2_v53
.clone
()]
));
let
blk_2_term
=
TreeNode
::
new_inst
(
Instruction
::
Term
(
Terminal
::
Return
(
vec!
[
blk_2_v53
.clone
()])
));
let
blk_2_content
=
BlockContent
{
args
:
vec!
[
blk_2_v53
.clone
()],
...
...
@@ -88,49 +90,49 @@ pub fn factorial() -> VMContext {
// %blk_1(<@int_64> %n_3):
let
mut
blk_1
=
Block
::
new
(
"blk_1"
);
let
blk_1_n_3
=
P
(
Value
::
SSAVar
(
SSAVar
{
id
:
3
,
tag
:
"n_3"
,
ty
:
type_def_int64
.clone
()}));
let
blk_1_n_3
=
TreeNode
::
new_value
(
Value
::
new_ssa
(
SSAVar
{
id
:
3
,
tag
:
"n_3"
,
ty
:
type_def_int64
.clone
()}));
// %v50 = SUB <@int_64> %n_3 @int_64_1
let
blk_1_v50
=
P
(
Value
::
SSAVar
(
SSAVar
{
id
:
4
,
tag
:
"v50"
,
ty
:
type_def_int64
.clone
()}));
let
blk_1_v50_expr
=
Expression
::
BinOp
(
let
blk_1_v50
=
TreeNode
::
new_value
(
Value
::
new_ssa
(
SSAVar
{
id
:
4
,
tag
:
"v50"
,
ty
:
type_def_int64
.clone
()}));
let
blk_1_v50_expr
=
Expression
_
::
BinOp
(
BinOp
::
Sub
,
blk_1_n_3
.clone
(),
const_def_int64_1
.clone
()
const_def_int64_1
_local
.clone
()
);
let
blk_1_inst0
=
Instruction
::
NonTerm
(
NonTermInstruction
::
Assign
{
left
:
vec!
[
blk_1_v50
.clone
()],
right
:
blk_1_v50_expr
}
);
let
blk_1_inst0
=
TreeNode
::
new_inst
(
Instruction
::
NonTerm
(
NonTermInstruction
::
Assign
{
left
:
vec!
[
blk_1_v50
.clone
()],
right
:
blk_1_v50_expr
})
);
// %v51 = CALL <@fac_sig> @fac (%v50)
let
blk_1_v51
=
P
(
Value
::
SSAVar
(
SSAVar
{
id
:
5
,
tag
:
"v51"
,
ty
:
type_def_int64
.clone
()}));
let
blk_1_inst1
=
Instruction
::
NonTerm
(
NonTermInstruction
::
Assign
{
let
blk_1_v51
=
TreeNode
::
new_value
(
Value
::
new_ssa
(
SSAVar
{
id
:
5
,
tag
:
"v51"
,
ty
:
type_def_int64
.clone
()}));
let
blk_1_inst1
=
TreeNode
::
new_inst
(
Instruction
::
NonTerm
(
NonTermInstruction
::
Assign
{
left
:
vec!
[
blk_1_v51
.clone
()],
right
:
Expression
::
ExprCall
{
right
:
Expression
_
::
ExprCall
{
data
:
CallData
{
func
:
P
(
SSAVar
{
id
:
6
,
tag
:
"fac"
,
ty
:
fac_func_ref
.clone
()}
),
func
:
TreeNode
::
new_value
(
Value
::
new_ssa
(
SSAVar
{
id
:
6
,
tag
:
"fac"
,
ty
:
fac_func_ref
.clone
()})
),
args
:
vec!
[
blk_1_v50
.clone
()],
convention
:
CallConvention
::
Mu
},
is_abort
:
true
}
});
})
)
;
// %v52 = MUL <@int_64> %n_3 %v51
let
blk_1_v52
=
P
(
Value
::
SSAVar
(
SSAVar
{
id
:
9
,
tag
:
"v52"
,
ty
:
type_def_int64
.clone
()}));
let
blk_1_v52_expr
=
Expression
::
BinOp
(
let
blk_1_v52
=
TreeNode
::
new_value
(
Value
::
new_ssa
(
SSAVar
{
id
:
9
,
tag
:
"v52"
,
ty
:
type_def_int64
.clone
()}));
let
blk_1_v52_expr
=
Expression
_
::
BinOp
(
BinOp
::
Mul
,
blk_1_n_3
.clone
(),
blk_1_v51
.clone
()
);
let
blk_1_inst2
=
Instruction
::
NonTerm
(
NonTermInstruction
::
Assign
{
let
blk_1_inst2
=
TreeNode
::
new_inst
(
Instruction
::
NonTerm
(
NonTermInstruction
::
Assign
{
left
:
vec!
[
blk_1_v52
.clone
()],
right
:
blk_1_v52_expr
});
})
)
;
let
blk_1_term
=
Instruction
::
Term
(
Terminal
::
Branch1
(
let
blk_1_term
=
TreeNode
::
new_inst
(
Instruction
::
Term
(
Terminal
::
Branch1
(
Destination
{
target
:
"blk_2"
,
args
:
vec!
[
DestArg
::
Normal
(
blk_1_v52
.clone
())]
}
));
))
)
;
let
blk_1_content
=
BlockContent
{
args
:
vec!
[
blk_1_n_3
.clone
()],
...
...
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