-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
(ruleset assume) | ||
|
||
(sort AssumeList) | ||
;; We collect multiple assumes into one AssumeMulti. | ||
;; When it gets to the bottom, we flatten it back out to multiple `Assume` nodes | ||
;; for the convenience of other analyses. | ||
(function AssumeMulti (AssumeList Expr) Expr :unextractable) | ||
|
||
(function AssumeCons (Assumption AssumeList) AssumeList :unextractable) | ||
(function AssumeNil () AssumeList :unextractable) | ||
|
||
; ################### start top-down assumptions | ||
|
||
(rewrite | ||
(Function name in_ty out_ty output) | ||
(Function name in_ty out_ty | ||
(AssumeList (AssumeCons (InFunction name) (AssumeNil)) | ||
output)) | ||
:ruleset assume) | ||
|
||
|
||
; ################### operations | ||
(rewrite (AssumeList asum (Bop op c1 c2)) | ||
(Bop op (AssumeList asum c1) (AssumeList asum c2)) | ||
:ruleset assume) | ||
(rewrite (AssumeList assum (Uop op c1)) | ||
(Uop op (AssumeList assum c1)) | ||
:ruleset assume) | ||
(rewrite (AssumeList assum (Get expr index)) | ||
(Get (AssumeList assum expr) index) | ||
:ruleset assume) | ||
(rewrite (AssumeList assum (Alloc expr ty)) | ||
(Alloc (AssumeList assum expr) ty) | ||
:ruleset assume) | ||
(rewrite (AssumeList assum (Call name expr)) | ||
(Call name (AssumeList assum expr)) | ||
:ruleset assume) | ||
|
||
; ################### tuple operations | ||
(rewrite (AssumeList assum (Single expr)) | ||
(Single (AssumeList assum expr)) | ||
:ruleset assume) | ||
(rewrite (AssumeList assum (Concat order e1 e2)) | ||
(Concat order (AssumeList assum e1) (AssumeList assum e2)) | ||
:ruleset assume) | ||
|
||
; #################### control flow | ||
|
||
(rewrite (AssumeList assum (Switch pred cases)) | ||
(Switch (AssumeList assum pred) | ||
(AssumeList | ||
|
||
(rule ((= lhs (Switch pred cases)) | ||
(AssumeDepth pred d1) | ||
(ListAssumeDepth cases d2)) | ||
((set (AssumeDepth lhs) (max d1 d2))) | ||
:ruleset assume) | ||
(rule ((= lhs (If pred then else)) | ||
(AssumeDepth pred d1) | ||
(AssumeDepth then d2) | ||
(AssumeDepth else d3)) | ||
((set (AssumeDepth lhs) (max d1 (max d2 d3)))) | ||
:ruleset assume) | ||
|
||
|
||
; Let and DoWhile are the only complex cases | ||
; When the depth is at the limit, don't substitute | ||
; into the body and reset the depth. | ||
|
||
(rule ((= lhs (Let inputs body)) | ||
(AssumeDepth inputs inputdepth) | ||
(< inputdepth max-assumedepth)) | ||
((let newlet | ||
(Let inputs (Assume (InLet inputs) body))) | ||
(set (AssumeDepth newlet) | ||
|
||
|
||
|
||
|
||
|
||
; ####################### lists | ||
|
||
(rule ((= lhs (Nil))) | ||
((set (ListAssumeDepth lhs) 0)) | ||
:ruleset assume) | ||
(rule ((= lhs (Cons head tail)) | ||
(AssumeDepth head d1) | ||
(ListAssumeDepth tail d2)) | ||
((set (ListAssumeDepth lhs) (max d1 d2))) | ||
:ruleset assume) | ||
|