Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
J
javawlp
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
Model registry
Operate
Environments
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
impresshs
javawlp
Commits
173f0d02
Commit
173f0d02
authored
8 years ago
by
koen
Browse files
Options
Downloads
Patches
Plain Diff
unrolling loops a finite amount of times (instead of using invariants)
parent
6a635b58
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
Settings.hs
+6
-3
6 additions, 3 deletions
Settings.hs
Tests/loops.java
+1
-1
1 addition, 1 deletion
Tests/loops.java
WLP.hs
+6
-6
6 additions, 6 deletions
WLP.hs
with
13 additions
and
10 deletions
Settings.hs
+
6
−
3
View file @
173f0d02
module
Settings
where
testFile
=
"arrays"
postCond
=
"a == b"
invariant
=
"i <= 5"
\ No newline at end of file
testFile
,
postCond
::
String
testFile
=
"loops"
postCond
=
"x == 5"
nrOfUnroll
::
Int
nrOfUnroll
=
6
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Tests/loops.java
+
1
−
1
View file @
173f0d02
...
...
@@ -7,7 +7,7 @@ public class C1
int
i
=
0
;
while
(
i
<
5
)
while
(
i
<
6
)
{
i
++;
...
...
This diff is collapsed.
Click to expand it.
WLP.hs
+
6
−
6
View file @
173f0d02
...
...
@@ -37,7 +37,7 @@ wlpStmtAlgebra = (fStmtBlock, fIfThen, fIfThenElse, fWhile, fBasicFor, fEnhanced
fIfThenElse
e
s1
s2
inh
=
let
e'
=
getExp
(
foldExp
wlpExpAlgebra
e
)
inh
in
((
\
q
->
(
e'
&*
fst
(
s1
inh
)
q
)
|*
(
neg
e'
&*
fst
(
s2
inh
)
q
))
.
acc
inh
,
env
inh
)
fWhile
e
s
inh
=
let
e'
=
getExp
(
foldExp
wlpExpAlgebra
e
)
inh
in
((
\
q
->
if
unsafeIsTrue
(((
inv
&*
neg
e'
)
`
imp
`
q
)
&*
((
inv
&*
e'
)
`
imp
`
fst
(
s
inh
)
inv
)
&*
((
inv
&*
e'
)
`
imp
`
fst
(
s
inh
{
br
=
const
q
})
true
))
then
inv
else
(
neg
e'
&*
q
)
)
.
acc
inh
,
env
inh
)
in
((
\
q
->
unrollLoop
nrOfUnroll
e'
(
fst
(
s
(
inh
{
br
=
const
q
})
))
q
)
.
acc
inh
,
env
inh
)
fBasicFor
init
me
incr
s
inh
=
let
loop
=
fst
(
fWhile
(
fromMaybeGuard
me
)
(
\
inh'
->
s
(
inh
{
acc
=
fst
(
wlp'
inh'
(
incrToStmt
incr
))}))
inh
)
in
wlp'
(
inh
{
acc
=
loop
})
(
initToStmt
init
)
fEnhancedFor
=
error
"EnhancedFor"
fEmpty
inh
=
(
acc
inh
,
env
inh
)
-- Empty does nothing, but still passes control to the next statement
...
...
@@ -82,11 +82,11 @@ wlpStmtAlgebra = (fStmtBlock, fIfThen, fIfThenElse, fWhile, fBasicFor, fEnhanced
-- We don't initialize ref types to null, because we want to keep pointer information
RefType
_
->
acc
inh
wlpDeclAssignment
t
inh
(
VarDecl
(
VarId
ident
)
(
Just
(
InitExp
e
)))
=
substVar
(
env
inh
)
(
decls
inh
)
(
NameLhs
(
Name
[
ident
]))
e
.
acc
inh
--
inv = true -- for simplicity, "True" is used as an invariant for now
inv
=
case
parser
Language
.
Java
.
Parser
.
exp
invariant
of
Right
e
->
e
_
->
error
"syntax error in invariant"
--
Unrolls a while-loop a finite amount of times
unrollLoop
::
Int
->
Exp
->
(
Exp
->
Exp
)
->
Exp
->
Exp
unrollLoop
0
g
_
q
=
neg
g
`
imp
`
q
unrollLoop
n
g
body
q
=
(
neg
g
`
imp
`
q
)
&*
(
g
`
imp
`
body
(
unrollLoop
(
n
-
1
)
g
body
q
))
-- Converts initialization code of a for loop to a statement
...
...
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