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
Deploy
Releases
Container Registry
Model registry
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
pub
frama-c
Commits
7fe8fce0
Commit
7fe8fce0
authored
5 years ago
by
Basile Desloges
Browse files
Options
Downloads
Patches
Plain Diff
[eacsl:codegen] Change the type of main to kernel_function in injector.ml
parent
607e3dbf
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/plugins/e-acsl/src/code_generator/injector.ml
+17
-7
17 additions, 7 deletions
src/plugins/e-acsl/src/code_generator/injector.ml
with
17 additions
and
7 deletions
src/plugins/e-acsl/src/code_generator/injector.ml
+
17
−
7
View file @
7fe8fce0
...
@@ -593,7 +593,7 @@ let inject_in_fundec main fundec =
...
@@ -593,7 +593,7 @@ let inject_in_fundec main fundec =
add_generated_variables_in_function
env
fundec
;
add_generated_variables_in_function
env
fundec
;
add_malloc_and_free_stmts
kf
fundec
;
add_malloc_and_free_stmts
kf
fundec
;
(* setting main if necessary *)
(* setting main if necessary *)
let
main
=
if
Kernel_function
.
is_main
kf
then
Some
f
undec
else
main
in
let
main
=
if
Kernel_function
.
is_main
kf
then
Some
k
f
else
main
in
Options
.
feedback
~
dkey
~
level
:
2
"function %a done."
Options
.
feedback
~
dkey
~
level
:
2
"function %a done."
Kernel_function
.
pretty
kf
;
Kernel_function
.
pretty
kf
;
env
,
main
env
,
main
...
@@ -686,11 +686,17 @@ let inject_global_initializer file main =
...
@@ -686,11 +686,17 @@ let inject_global_initializer file main =
in
in
vi
.
vreferenced
<-
true
;
vi
.
vreferenced
<-
true
;
(* insert [__e_acsl_globals_init ();] as first statement of [main] *)
(* insert [__e_acsl_globals_init ();] as first statement of [main] *)
main
.
sbody
.
bstmts
<-
stmt
::
main
.
sbody
.
bstmts
;
let
main_fundec
=
try
Kernel_function
.
get_definition
main
with
_
->
assert
false
(* by construction, the main kf has a fundec *)
in
main_fundec
.
sbody
.
bstmts
<-
stmt
::
main_fundec
.
sbody
.
bstmts
;
(* Retrieve all globals except main *)
let
main_vi
=
Globals
.
Functions
.
get_vi
main
in
let
new_globals
=
let
new_globals
=
List
.
fold_left
List
.
fold_left
(
fun
acc
g
->
match
g
with
(
fun
acc
g
->
match
g
with
|
GFun
({
svar
=
vi
}
,
_
)
when
Varinfo
.
equal
vi
main
.
svar
->
acc
|
GFun
({
svar
=
vi
}
,
_
)
when
Varinfo
.
equal
vi
main
_vi
->
acc
|
_
->
g
::
acc
)
|
_
->
g
::
acc
)
[]
[]
file
.
globals
file
.
globals
...
@@ -701,7 +707,7 @@ let inject_global_initializer file main =
...
@@ -701,7 +707,7 @@ let inject_global_initializer file main =
|
f
::
l
->
rev_and_extend
(
f
::
acc
)
l
|
f
::
l
->
rev_and_extend
(
f
::
acc
)
l
in
in
(* [__e_acsl_globals_init] and [main] at the end *)
(* [__e_acsl_globals_init] and [main] at the end *)
rev_and_extend
[
cil_fct
;
GFun
(
main
,
Location
.
unknown
)
]
new_globals
rev_and_extend
[
cil_fct
;
GFun
(
main
_fundec
,
Location
.
unknown
)
]
new_globals
in
in
(* add the literal string varinfos as the very first globals *)
(* add the literal string varinfos as the very first globals *)
let
new_globals
=
let
new_globals
=
...
@@ -725,18 +731,22 @@ let inject_mmodel_initializer main =
...
@@ -725,18 +731,22 @@ let inject_mmodel_initializer main =
let
loc
=
Location
.
unknown
in
let
loc
=
Location
.
unknown
in
let
nulls
=
[
Cil
.
zero
loc
;
Cil
.
zero
loc
]
in
let
nulls
=
[
Cil
.
zero
loc
;
Cil
.
zero
loc
]
in
let
handle_main
main
=
let
handle_main
main
=
let
fundec
=
try
Kernel_function
.
get_definition
main
with
_
->
assert
false
(* by construction, the main kf has a fundec *)
in
let
args
=
let
args
=
(* record arguments only if the second has a pointer type, so argument
(* record arguments only if the second has a pointer type, so argument
strings can be recorded. This is sufficient to capture C99 compliant
strings can be recorded. This is sufficient to capture C99 compliant
arguments and GCC extensions with environ. *)
arguments and GCC extensions with environ. *)
match
main
.
sformals
with
match
fundec
.
sformals
with
|
[]
->
|
[]
->
(* no arguments to main given *)
(* no arguments to main given *)
nulls
nulls
|
_argc
::
argv
::
_
when
Cil
.
isPointerType
argv
.
vtype
->
|
_argc
::
argv
::
_
when
Cil
.
isPointerType
argv
.
vtype
->
(* grab addresses of arguments for a call to the main initialization
(* grab addresses of arguments for a call to the main initialization
function, i.e., [__e_acsl_memory_init] *)
function, i.e., [__e_acsl_memory_init] *)
List
.
map
Cil
.
mkAddrOfVi
main
.
sformals
;
List
.
map
Cil
.
mkAddrOfVi
fundec
.
sformals
;
|
_
::
_
->
|
_
::
_
->
(* some non-standard arguments. *)
(* some non-standard arguments. *)
nulls
nulls
...
@@ -744,7 +754,7 @@ let inject_mmodel_initializer main =
...
@@ -744,7 +754,7 @@ let inject_mmodel_initializer main =
let
ptr_size
=
Cil
.
sizeOf
loc
Cil
.
voidPtrType
in
let
ptr_size
=
Cil
.
sizeOf
loc
Cil
.
voidPtrType
in
let
args
=
args
@
[
ptr_size
]
in
let
args
=
args
@
[
ptr_size
]
in
let
init
=
Constructor
.
mk_rtl_call
loc
"memory_init"
args
in
let
init
=
Constructor
.
mk_rtl_call
loc
"memory_init"
args
in
main
.
sbody
.
bstmts
<-
init
::
main
.
sbody
.
bstmts
fundec
.
sbody
.
bstmts
<-
init
::
fundec
.
sbody
.
bstmts
in
in
Extlib
.
may
handle_main
main
Extlib
.
may
handle_main
main
...
...
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