Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Lustrec - public version
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LustreC
Lustrec - public version
Commits
6fa45cb6
Commit
6fa45cb6
authored
8 years ago
by
Pierre Loic Garoche
Browse files
Options
Downloads
Patches
Plain Diff
Changed the generated C file to produce input and output csv files (named inXX and outXX)
parent
59ac5058
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
include/io_frontend.c
+14
-6
14 additions, 6 deletions
include/io_frontend.c
include/io_frontend.h
+6
-6
6 additions, 6 deletions
include/io_frontend.h
src/backends/C/c_backend_main.ml
+36
-24
36 additions, 24 deletions
src/backends/C/c_backend_main.ml
src/utils.ml
+21
-0
21 additions, 0 deletions
src/utils.ml
with
77 additions
and
36 deletions
include/io_frontend.c
+
14
−
6
View file @
6fa45cb6
...
...
@@ -6,7 +6,7 @@
int
ISATTY
;
/* Standard Input procedures **************/
_Bool
_get_bool
(
char
*
n
){
_Bool
_get_bool
(
FILE
*
file
,
char
*
n
){
char
b
[
512
];
_Bool
r
=
0
;
int
s
=
1
;
...
...
@@ -22,9 +22,11 @@ _Bool _get_bool(char* n){
if
((
c
==
'0'
)
||
(
c
==
'f'
)
||
(
c
==
'F'
))
r
=
0
;
if
((
c
==
'1'
)
||
(
c
==
't'
)
||
(
c
==
'T'
))
r
=
1
;
}
while
((
s
!=
1
)
||
(
r
==
-
1
));
fprintf
(
file
,
"%i
\n
"
,
r
);
return
r
;
}
int
_get_int
(
char
*
n
){
int
_get_int
(
FILE
*
file
,
char
*
n
){
char
b
[
512
];
int
r
;
int
s
=
1
;
...
...
@@ -36,9 +38,11 @@ int _get_int(char* n){
if
(
scanf
(
"%s"
,
b
)
==
EOF
)
exit
(
0
);
s
=
sscanf
(
b
,
"%d"
,
&
r
);
}
while
(
s
!=
1
);
fprintf
(
file
,
"%d
\n
"
,
r
);
return
r
;
}
double
_get_double
(
char
*
n
){
double
_get_double
(
FILE
*
file
,
char
*
n
){
char
b
[
512
];
double
r
;
int
s
=
1
;
...
...
@@ -50,10 +54,11 @@ double _get_double(char* n){
if
(
scanf
(
"%s"
,
b
)
==
EOF
)
exit
(
0
);
s
=
sscanf
(
b
,
"%lf"
,
&
r
);
}
while
(
s
!=
1
);
fprintf
(
file
,
"%f
\n
"
,
r
);
return
r
;
}
/* Standard Output procedures **************/
void
_put_bool
(
char
*
n
,
_Bool
_V
){
void
_put_bool
(
FILE
*
file
,
char
*
n
,
_Bool
_V
){
if
(
ISATTY
)
{
printf
(
"%s = "
,
n
);
}
else
{
...
...
@@ -61,8 +66,9 @@ void _put_bool(char* n, _Bool _V){
};
printf
(
"'%i' "
,
(
_V
)
?
1
:
0
);
printf
(
"
\n
"
);
fprintf
(
file
,
"%i
\n
"
,
_V
);
}
void
_put_int
(
char
*
n
,
int
_V
){
void
_put_int
(
FILE
*
file
,
char
*
n
,
int
_V
){
if
(
ISATTY
)
{
printf
(
"%s = "
,
n
);
}
else
{
...
...
@@ -70,8 +76,9 @@ void _put_int(char* n, int _V){
};
printf
(
"'%d' "
,
_V
);
printf
(
"
\n
"
);
fprintf
(
file
,
"%d
\n
"
,
_V
);
}
void
_put_double
(
char
*
n
,
double
_V
){
void
_put_double
(
FILE
*
file
,
char
*
n
,
double
_V
){
if
(
ISATTY
)
{
printf
(
"%s = "
,
n
);
}
else
{
...
...
@@ -79,4 +86,5 @@ void _put_double(char* n, double _V){
};
printf
(
"'%f' "
,
_V
);
printf
(
"
\n
"
);
fprintf
(
file
,
"%f
\n
"
,
_V
);
}
This diff is collapsed.
Click to expand it.
include/io_frontend.h
+
6
−
6
View file @
6fa45cb6
...
...
@@ -7,22 +7,22 @@ extern int ISATTY;
/* Standard Input procedures **************/
/*@ assigns *n; */
extern
_Bool
_get_bool
(
char
*
n
);
extern
_Bool
_get_bool
(
FILE
*
file
,
char
*
n
);
/*@ assigns *n; */
extern
int
_get_int
(
char
*
n
);
extern
int
_get_int
(
FILE
*
file
,
char
*
n
);
/*@ assigns *n; */
extern
double
_get_double
(
char
*
n
);
extern
double
_get_double
(
FILE
*
file
,
char
*
n
);
/* Standard Output procedures **************/
/*@ assigns \nothing; */
extern
void
_put_bool
(
char
*
n
,
_Bool
_V
);
extern
void
_put_bool
(
FILE
*
file
,
char
*
n
,
_Bool
_V
);
/*@ assigns \nothing; */
extern
void
_put_int
(
char
*
n
,
int
_V
);
extern
void
_put_int
(
FILE
*
file
,
char
*
n
,
int
_V
);
/*@ assigns \nothing; */
extern
void
_put_double
(
char
*
n
,
double
_V
);
extern
void
_put_double
(
FILE
*
file
,
char
*
n
,
double
_V
);
#endif
This diff is collapsed.
Click to expand it.
src/backends/C/c_backend_main.ml
+
36
−
24
View file @
6fa45cb6
...
...
@@ -14,6 +14,7 @@ open Corelang
open
Machine_code
open
Format
open
C_backend_common
open
Utils
module
type
MODIFIERS_MAINSRC
=
sig
...
...
@@ -31,12 +32,12 @@ struct
(********************************************************************************************)
let
print_get_inputs
fmt
m
=
let
pi
fmt
(
v'
,
v
)
=
let
pi
fmt
(
id
,
v'
,
v
)
=
match
(
Types
.
unclock_type
v
.
var_type
)
.
Types
.
tdesc
with
|
Types
.
Tint
->
fprintf
fmt
"%s = _get_int(
\"
%s
\"
)"
v
.
var_id
v'
.
var_id
|
Types
.
Tbool
->
fprintf
fmt
"%s = _get_bool(
\"
%s
\"
)"
v
.
var_id
v'
.
var_id
|
Types
.
Treal
when
!
Options
.
mpfr
->
fprintf
fmt
"mpfr_set_d(%s, _get_double(
\"
%s
\"
), %i)"
v
.
var_id
v'
.
var_id
(
Mpfr
.
mpfr_prec
()
)
|
Types
.
Treal
->
fprintf
fmt
"%s = _get_double(
\"
%s
\"
)"
v
.
var_id
v'
.
var_id
|
Types
.
Tint
->
fprintf
fmt
"%s = _get_int(
f_in%i,
\"
%s
\"
)"
v
.
var_id
id
v'
.
var_id
|
Types
.
Tbool
->
fprintf
fmt
"%s = _get_bool(
f_in%i,
\"
%s
\"
)"
v
.
var_id
id
v'
.
var_id
|
Types
.
Treal
when
!
Options
.
mpfr
->
fprintf
fmt
"mpfr_set_d(%s, _get_double(
f_in%i,
\"
%s
\"
), %i)"
v
.
var_id
id
v'
.
var_id
(
Mpfr
.
mpfr_prec
()
)
|
Types
.
Treal
->
fprintf
fmt
"%s = _get_double(
f_in%i,
\"
%s
\"
)"
v
.
var_id
id
v'
.
var_id
|
_
->
begin
Global
.
main_node
:=
!
Options
.
main_node
;
...
...
@@ -46,30 +47,39 @@ let print_get_inputs fmt m =
raise
(
Error
(
v'
.
var_loc
,
Main_wrong_kind
))
end
in
List
.
iter2
(
fun
v'
v
->
fprintf
fmt
"@ %a;"
pi
(
v'
,
v
))
m
.
mname
.
node_inputs
m
.
mstep
.
step_inputs
List
.
iteri2
(
fun
idx
v'
v
->
fprintf
fmt
"@ %a;"
pi
((
idx
+
1
)
,
v'
,
v
);
)
m
.
mname
.
node_inputs
m
.
mstep
.
step_inputs
let
print_put_outputs
fmt
m
=
let
po
fmt
(
o'
,
o
)
=
let
po
fmt
(
id
,
o'
,
o
)
=
match
(
Types
.
unclock_type
o
.
var_type
)
.
Types
.
tdesc
with
|
Types
.
Tint
->
fprintf
fmt
"_put_int(
\"
%s
\"
, %s)"
o'
.
var_id
o
.
var_id
|
Types
.
Tbool
->
fprintf
fmt
"_put_bool(
\"
%s
\"
, %s)"
o'
.
var_id
o
.
var_id
|
Types
.
Treal
when
!
Options
.
mpfr
->
fprintf
fmt
"_put_double(
\"
%s
\"
, mpfr_get_d(%s, %s))"
o'
.
var_id
o
.
var_id
(
Mpfr
.
mpfr_rnd
()
)
|
Types
.
Treal
->
fprintf
fmt
"_put_double(
\"
%s
\"
, %s)"
o'
.
var_id
o
.
var_id
|
Types
.
Tint
->
fprintf
fmt
"_put_int(
f_out%i,
\"
%s
\"
, %s)"
id
o'
.
var_id
o
.
var_id
|
Types
.
Tbool
->
fprintf
fmt
"_put_bool(
f_out%i,
\"
%s
\"
, %s)"
id
o'
.
var_id
o
.
var_id
|
Types
.
Treal
when
!
Options
.
mpfr
->
fprintf
fmt
"_put_double(
f_out%i,
\"
%s
\"
, mpfr_get_d(%s, %s))"
id
o'
.
var_id
o
.
var_id
(
Mpfr
.
mpfr_rnd
()
)
|
Types
.
Treal
->
fprintf
fmt
"_put_double(
f_out%i,
\"
%s
\"
, %s)"
id
o'
.
var_id
o
.
var_id
|
_
->
assert
false
in
List
.
iter2
(
fun
v'
v
->
fprintf
fmt
"@ %a;"
po
(
v'
,
v
))
m
.
mname
.
node_outputs
m
.
mstep
.
step_outputs
let
print_main_inout_declaration
fmt
m
=
begin
fprintf
fmt
"/* Declaration of inputs/outputs variables */@ "
;
List
.
iter
(
fun
v
->
fprintf
fmt
"%a;@ "
(
pp_c_type
v
.
var_id
)
v
.
var_type
)
m
.
mstep
.
step_inputs
;
List
.
iter
(
fun
v
->
fprintf
fmt
"%a;@ "
(
pp_c_type
v
.
var_id
)
v
.
var_type
)
m
.
mstep
.
step_outputs
end
Utils
.
List
.
iteri2
(
fun
idx
v'
v
->
fprintf
fmt
"@ %a;"
po
((
idx
+
1
)
,
v'
,
v
))
m
.
mname
.
node_outputs
m
.
mstep
.
step_outputs
let
print_main_inout_declaration
basename
fmt
m
=
let
mname
=
m
.
mname
.
node_id
in
fprintf
fmt
"/* Declaration of inputs/outputs variables */@ "
;
List
.
iteri
(
fun
idx
v
->
fprintf
fmt
"%a;@ "
(
pp_c_type
v
.
var_id
)
v
.
var_type
;
fprintf
fmt
"FILE *f_in%i;@ "
(
idx
+
1
);
(* we start from 1: in1, in2, ... *)
fprintf
fmt
"f_in%i = fopen(
\"
%s_%s_simu.in%i
\"
,
\"
w
\"
);@ "
(
idx
+
1
)
basename
mname
(
idx
+
1
);
)
m
.
mstep
.
step_inputs
;
List
.
iteri
(
fun
idx
v
->
fprintf
fmt
"%a;@ "
(
pp_c_type
v
.
var_id
)
v
.
var_type
;
fprintf
fmt
"FILE *f_out%i;@ "
(
idx
+
1
);
(* we start from 1: in1, in2, ... *)
fprintf
fmt
"f_out%i = fopen(
\"
%s_%s_simu.out%i
\"
,
\"
w
\"
);@ "
(
idx
+
1
)
basename
mname
(
idx
+
1
);
)
m
.
mstep
.
step_outputs
let
print_main_memory_allocation
mname
main_mem
fmt
m
=
if
not
(
fst
(
get_stateless_status
m
))
then
begin
...
...
@@ -132,6 +142,8 @@ let print_main_loop mname main_mem fmt m =
fprintf
fmt
"@ /* Infinite loop */@ "
;
fprintf
fmt
"@[<v 2>while(1){@ "
;
fprintf
fmt
"fflush(stdout);@ "
;
List
.
iteri
(
fun
idx
_
->
fprintf
fmt
"fflush(f_in%i);@ "
(
idx
+
1
))
m
.
mstep
.
step_inputs
;
List
.
iteri
(
fun
idx
_
->
fprintf
fmt
"fflush(f_out%i);@ "
(
idx
+
1
))
m
.
mstep
.
step_outputs
;
fprintf
fmt
"%a@ %t%a"
print_get_inputs
m
(
fun
fmt
->
pp_main_call
mname
main_mem
fmt
m
input_values
m
.
mstep
.
step_outputs
)
...
...
@@ -145,7 +157,7 @@ let print_main_code fmt basename m =
then
"&main_mem"
else
"main_mem"
in
fprintf
fmt
"@[<v 2>int main (int argc, char *argv[]) {@ "
;
print_main_inout_declaration
fmt
m
;
print_main_inout_declaration
basename
fmt
m
;
print_main_memory_allocation
mname
main_mem
fmt
m
;
if
!
Options
.
mpfr
then
begin
...
...
This diff is collapsed.
Click to expand it.
src/utils.ml
+
21
−
0
View file @
6fa45cb6
...
...
@@ -361,6 +361,27 @@ let last_tag = ref (-1)
let
new_tag
()
=
incr
last_tag
;
!
last_tag
module
List
=
struct
include
List
let
iteri2
f
l1
l2
=
if
List
.
length
l1
<>
List
.
length
l2
then
raise
(
Invalid_argument
"iteri2: lists have different lengths"
)
else
let
rec
run
idx
l1
l2
=
match
l1
,
l2
with
|
[]
,
[]
->
()
|
hd1
::
tl1
,
hd2
::
tl2
->
(
f
idx
hd1
hd2
;
run
(
idx
+
1
)
tl1
tl2
)
|
_
->
assert
false
in
run
0
l1
l2
end
(* Local Variables: *)
(* compile-command:"make -C .." *)
(* End: *)
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