Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
frama-c
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
Charles Southerland
frama-c
Commits
9c5b45de
Commit
9c5b45de
authored
4 years ago
by
Basile Desloges
Browse files
Options
Downloads
Patches
Plain Diff
[eacsl] Add constructor functions to manipulate expressions and statements
parent
efe25831
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/plugins/e-acsl/src/code_generator/constructor.ml
+34
-2
34 additions, 2 deletions
src/plugins/e-acsl/src/code_generator/constructor.ml
src/plugins/e-acsl/src/code_generator/constructor.mli
+41
-0
41 additions, 0 deletions
src/plugins/e-acsl/src/code_generator/constructor.mli
with
75 additions
and
2 deletions
src/plugins/e-acsl/src/code_generator/constructor.ml
+
34
−
2
View file @
9c5b45de
...
@@ -26,7 +26,31 @@ open Cil_types
...
@@ -26,7 +26,31 @@ open Cil_types
(* Expressions *)
(* Expressions *)
(* ********************************************************************** *)
(* ********************************************************************** *)
let
mk_deref
~
loc
lv
=
Cil
.
new_exp
~
loc
(
Lval
(
Mem
(
lv
)
,
NoOffset
))
let
extract_uncoerced_lval
e
=
let
rec
aux
e
=
match
e
.
enode
with
|
Lval
_
->
Some
e
|
CastE
(
_
,
e
)
->
aux
e
|
_
->
None
in
aux
e
let
mk_lval
~
loc
lval
=
Cil
.
new_exp
~
loc
(
Lval
lval
)
let
mk_deref
~
loc
lv
=
mk_lval
~
loc
(
Mem
lv
,
NoOffset
)
let
mk_subscript
~
loc
array
idx
=
match
extract_uncoerced_lval
array
with
|
Some
{
enode
=
Lval
lval
}
->
let
subscript_lval
=
Cil
.
addOffsetLval
(
Index
(
idx
,
NoOffset
))
lval
in
mk_lval
~
loc
subscript_lval
|
Some
_
|
None
->
Options
.
fatal
~
current
:
true
"Trying to create a subscript on an array that is not an Lval: %a"
Cil_types_debug
.
pp_exp
array
(* ********************************************************************** *)
(* ********************************************************************** *)
(* Statements *)
(* Statements *)
...
@@ -34,8 +58,16 @@ let mk_deref ~loc lv = Cil.new_exp ~loc (Lval(Mem(lv), NoOffset))
...
@@ -34,8 +58,16 @@ let mk_deref ~loc lv = Cil.new_exp ~loc (Lval(Mem(lv), NoOffset))
let
mk_stmt
sk
=
Cil
.
mkStmt
~
valid_sid
:
true
sk
let
mk_stmt
sk
=
Cil
.
mkStmt
~
valid_sid
:
true
sk
let
mk_instr
i
=
mk_stmt
(
Instr
i
)
let
mk_instr
i
=
mk_stmt
(
Instr
i
)
let
mk_block_stmt
blk
=
mk_stmt
(
Block
blk
)
let
mk_call
~
loc
?
result
e
args
=
mk_instr
(
Call
(
result
,
e
,
args
,
loc
))
let
mk_call
~
loc
?
result
e
args
=
mk_instr
(
Call
(
result
,
e
,
args
,
loc
))
let
mk_assigns
~
loc
~
result
e
=
mk_instr
(
Set
(
result
,
e
,
loc
))
let
mk_if
~
loc
~
cond
?
(
else_blk
=
Cil
.
mkBlock
[]
)
then_blk
=
mk_stmt
(
If
(
cond
,
then_blk
,
else_blk
,
loc
))
let
mk_break
~
loc
=
mk_stmt
(
Break
loc
)
type
annotation_kind
=
type
annotation_kind
=
|
Assertion
|
Assertion
|
Precondition
|
Precondition
...
@@ -59,7 +91,7 @@ let mk_block stmt b = match b.bstmts with
...
@@ -59,7 +91,7 @@ let mk_block stmt b = match b.bstmts with
|
Instr
(
Skip
_
)
->
stmt
|
Instr
(
Skip
_
)
->
stmt
|
_
->
assert
false
)
|
_
->
assert
false
)
|
[
s
]
->
s
|
[
s
]
->
s
|
_
::
_
->
mk_
stmt
(
Block
b
)
|
_
::
_
->
mk_
block_stmt
b
(* ********************************************************************** *)
(* ********************************************************************** *)
(* E-ACSL specific code *)
(* E-ACSL specific code *)
...
...
This diff is collapsed.
Click to expand it.
src/plugins/e-acsl/src/code_generator/constructor.mli
+
41
−
0
View file @
9c5b45de
...
@@ -25,13 +25,54 @@
...
@@ -25,13 +25,54 @@
open
Cil_types
open
Cil_types
open
Cil_datatype
open
Cil_datatype
(* ********************************************************************** *)
(* Expressions *)
(* ********************************************************************** *)
val
extract_uncoerced_lval
:
exp
->
exp
option
(** Unroll the [CastE] part of the expression until an [Lval] is found, and
return it.
If at some point the expression is neither a [CastE] nor an [Lval], then
return [None]. *)
val
mk_lval
:
loc
:
location
->
lval
->
exp
(** Construct an lval expression from an lval. *)
val
mk_deref
:
loc
:
Location
.
t
->
exp
->
exp
val
mk_deref
:
loc
:
Location
.
t
->
exp
->
exp
(** Construct a dereference of an expression. *)
(** Construct a dereference of an expression. *)
val
mk_subscript
:
loc
:
location
->
exp
->
exp
->
exp
(** [mk_subscript ~loc array idx] Create an expression to access the [idx]'th
element of the [array]. *)
(* ********************************************************************** *)
(* Statements *)
(* ********************************************************************** *)
val
mk_stmt
:
stmtkind
->
stmt
(** Create a statement from a statement kind. *)
val
mk_block
:
stmt
->
block
->
stmt
val
mk_block
:
stmt
->
block
->
stmt
(** Create a block statement from a block to replace a given statement.
(** Create a block statement from a block to replace a given statement.
Requires that (1) the block is not empty, or (2) the statement is a skip. *)
Requires that (1) the block is not empty, or (2) the statement is a skip. *)
val
mk_block_stmt
:
block
->
stmt
(** Create a block statement from a block *)
val
mk_assigns
:
loc
:
location
->
result
:
lval
->
exp
->
stmt
(** [mk_assigns ~loc ~result value] create a statement to assign the [value]
expression to the [result] lval. *)
val
mk_if
:
loc
:
location
->
cond
:
exp
->
?
else_blk
:
block
->
block
->
stmt
(** [mk_if ~loc ~cond ~then_blk ~else_blk] create an if statement with [cond]
as condition and [then_blk] and [else_blk] as respectively "then" block and
"else" block. *)
val
mk_break
:
loc
:
location
->
stmt
(** Create a break statement *)
(* ********************************************************************** *)
(* ********************************************************************** *)
(* E-ACSL specific code: build calls to its RTL API *)
(* E-ACSL specific code: build calls to its RTL API *)
(* ********************************************************************** *)
(* ********************************************************************** *)
...
...
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