Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
inox
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
LARA
inox
Commits
d41909c2
Commit
d41909c2
authored
9 years ago
by
Régis Blanc
Committed by
Regis Blanc
9 years ago
Browse files
Options
Downloads
Patches
Plain Diff
properly add a GlobalState to program
parent
0b6160a7
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/scala/leon/xlang/IntroduceGlobalStatePhase.scala
+11
-9
11 additions, 9 deletions
src/main/scala/leon/xlang/IntroduceGlobalStatePhase.scala
with
11 additions
and
9 deletions
src/main/scala/leon/xlang/IntroduceGlobalStatePhase.scala
+
11
−
9
View file @
d41909c2
...
@@ -19,18 +19,16 @@ object IntroduceGlobalStatePhase extends TransformationPhase {
...
@@ -19,18 +19,16 @@ object IntroduceGlobalStatePhase extends TransformationPhase {
val
description
=
"Introduce a global state passed around to all functions that depend on it"
val
description
=
"Introduce a global state passed around to all functions that depend on it"
private
val
globalStateCCD
=
new
CaseClassDef
(
FreshIdentifier
(
"GlobalState"
),
Seq
(),
None
,
false
)
private
val
epsilonSeed
=
FreshIdentifier
(
"epsilonSeed"
,
IntegerType
)
globalStateCCD
.
setFields
(
Seq
(
ValDef
(
epsilonSeed
).
setIsVar
(
true
)))
override
def
apply
(
ctx
:
LeonContext
,
pgm
:
Program
)
:
Program
=
{
override
def
apply
(
ctx
:
LeonContext
,
pgm
:
Program
)
:
Program
=
{
val
globalStateCCD
=
new
CaseClassDef
(
FreshIdentifier
(
"GlobalState"
),
Seq
(),
None
,
false
)
val
epsilonSeed
=
FreshIdentifier
(
"epsilonSeed"
,
IntegerType
)
globalStateCCD
.
setFields
(
Seq
(
ValDef
(
epsilonSeed
).
setIsVar
(
true
)))
val
fds
=
allFunDefs
(
pgm
)
val
fds
=
allFunDefs
(
pgm
)
var
updatedFunctions
:
Map
[
FunDef
,
FunDef
]
=
Map
()
var
updatedFunctions
:
Map
[
FunDef
,
FunDef
]
=
Map
()
val
statefulFunDefs
=
funDefsNeedingState
(
pgm
)
val
statefulFunDefs
=
funDefsNeedingState
(
pgm
)
//println("Stateful fun def: " + statefulFunDefs.map(_.id))
/*
/*
* The first pass will introduce all new function definitions,
* The first pass will introduce all new function definitions,
...
@@ -45,10 +43,14 @@ object IntroduceGlobalStatePhase extends TransformationPhase {
...
@@ -45,10 +43,14 @@ object IntroduceGlobalStatePhase extends TransformationPhase {
for
{
for
{
fd
<-
fds
if
statefulFunDefs
.
contains
(
fd
)
fd
<-
fds
if
statefulFunDefs
.
contains
(
fd
)
}
{
}
{
updateBody
(
fd
,
updatedFunctions
)(
ctx
)
updateBody
(
fd
,
updatedFunctions
,
globalStateCCD
,
epsilonSeed
)(
ctx
)
}
}
replaceDefsInProgram
(
pgm
)(
updatedFunctions
)
val
pgm0
=
replaceDefsInProgram
(
pgm
)(
updatedFunctions
)
val
globalStateModule
=
ModuleDef
(
FreshIdentifier
(
"GlobalStateModule"
),
Seq
(
globalStateCCD
),
false
)
val
globalStateUnit
=
UnitDef
(
FreshIdentifier
(
"GlobalStateUnit"
),
List
(
"leon"
,
"internal"
),
Seq
(),
Seq
(
globalStateModule
),
false
)
pgm0
.
copy
(
units
=
globalStateUnit
::
pgm0
.
units
)
}
}
private
def
extendFunDefWithState
(
fd
:
FunDef
,
stateCCD
:
CaseClassDef
)(
ctx
:
LeonContext
)
:
FunDef
=
{
private
def
extendFunDefWithState
(
fd
:
FunDef
,
stateCCD
:
CaseClassDef
)(
ctx
:
LeonContext
)
:
FunDef
=
{
...
@@ -59,7 +61,7 @@ object IntroduceGlobalStatePhase extends TransformationPhase {
...
@@ -59,7 +61,7 @@ object IntroduceGlobalStatePhase extends TransformationPhase {
newFunDef
newFunDef
}
}
private
def
updateBody
(
fd
:
FunDef
,
updatedFunctions
:
Map
[
FunDef
,
FunDef
])(
ctx
:
LeonContext
)
:
FunDef
=
{
private
def
updateBody
(
fd
:
FunDef
,
updatedFunctions
:
Map
[
FunDef
,
FunDef
]
,
globalStateCCD
:
CaseClassDef
,
epsilonSeed
:
Identifier
)(
ctx
:
LeonContext
)
:
FunDef
=
{
val
nfd
=
updatedFunctions
(
fd
)
val
nfd
=
updatedFunctions
(
fd
)
val
stateParam
:
ValDef
=
nfd
.
params
.
last
val
stateParam
:
ValDef
=
nfd
.
params
.
last
...
...
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