Skip to content
Snippets Groups Projects
Commit 2a7db9b8 authored by Erwan Jahier's avatar Erwan Jahier
Browse files

Soc2c: declare the ctx of memoryless nodes in the loop file.

parent f82064a4
No related branches found
No related tags found
No related merge requests found
(* Time-stamp: <modified the 12/06/2014 (at 09:42) by Erwan Jahier> *)
(* Time-stamp: <modified the 04/07/2014 (at 16:23) by Erwan Jahier> *)
open Lxm
open Lv6errors
......
(* Time-stamp: <modified the 04/07/2014 (at 11:51) by Erwan Jahier> *)
(* Time-stamp: <modified the 07/07/2014 (at 11:49) by Erwan Jahier> *)
(* let put (os: out_channel) (fmt:('a, unit, string, unit) format4) : 'a = *)
......@@ -227,7 +227,7 @@ let (soc2c: int -> out_channel -> out_channel -> Soc.tbl -> Soc.t -> unit) =
let ctx_name_type = ctx_name^"_type" in
if pass=1 then (
(* Only for ctx of memoryless nodes + main node *)
if is_memory_less soc then hfmt "%s %s;\n" ctx_name_type ctx_name;
if is_memory_less soc then cfmt "%s %s;\n" ctx_name_type ctx_name;
) else (
if is_memory_less soc then () else (
cfmt "// Memory initialisation for %s\n" ctx_name;
......@@ -423,11 +423,22 @@ let (constdef : LicPrg.t -> string) =
(****************************************************************************)
let (gen_loop_file : Soc.t -> unit) =
fun soc ->
let (gen_memoryless_ctx : Soc.tbl -> string) =
fun stbl ->
let acc = Printf.sprintf "\n// Allocation of memoryless ctx\n" in
let do_soc sk soc acc =
if is_memory_less soc && not (inline_soc sk) then
let ctx_name = get_ctx_name soc.key in
let ctx_name_type = ctx_name^"_type" in
Printf.sprintf "%sextern %s %s;\n" acc ctx_name_type ctx_name
else acc
in
Soc.SocMap.fold do_soc stbl acc
(****************************************************************************)
let (gen_loop_file : Soc.t -> out_channel -> Soc.tbl -> unit) =
fun soc oc stbl ->
let base = (string_of_soc_key soc.key) in
let loopfile = base^"_loop.c" in
let oc = open_out loopfile in
let putc s = output_string oc s in
let ctx = get_ctx_name soc.key in
let step = Soc2cUtil.step_name soc.key "step" in
......@@ -536,7 +547,8 @@ void %s_BOT_n(void* cdata){
/* Output procedures **********************/
void "^n^"_O_n(void* cdata, _integer _V) {
_put_int(\"n\", _V);
}/* Main procedure *************************/
}"^ (gen_memoryless_ctx stbl) ^
"/* Main procedure *************************/
int main(){
int s = 0;
......@@ -572,10 +584,7 @@ int main(){
return 1;
}
") ;
flush oc; close_out oc;
Printf.printf "%s has been generated.\n" loopfile
")
(****************************************************************************)
(* The entry point for lus2lic --to-c *)
......@@ -588,15 +597,18 @@ let (f : Lv6MainArgs.t -> Soc.key -> Soc.tbl -> LicPrg.t -> unit) =
let base = string_of_soc_key msoc in
let hfile = base ^ ".h" in
let cfile = base ^ ".c" in
let loopfile = base^"_loop.c" in
let occ = open_out cfile in
let och = open_out hfile in
let ocl = open_out loopfile in
let putc s = output_string occ s ; flush occ in
let puth s = output_string och s ; flush och in
let main_soc = Soc.SocMap.find msoc stbl in
Lv6util.entete occ "/*" "*/" ;
Lv6util.entete och "/*" "*/";
gen_loop_file main_soc;
gen_loop_file main_soc ocl stbl;
output_string och "
#include <stdlib.h>
......@@ -633,9 +645,11 @@ typedef float _float;
puth "#endif\n";
flush occ; close_out occ;
flush och; close_out och;
flush ocl; close_out ocl;
Printf.printf "%s has been generated.\n" loopfile;
Printf.printf "%s has been generated.\n" hfile;
Printf.printf "%s has been generated.\n" cfile;
let base = (string_of_soc_key main_soc.key) in
let loopfile = base^"_loop.c" in
Printf.printf "you can compile those files doing, e.g.,\n gcc %s\n" loopfile;
Printf.printf "you can compile those files doing, e.g.,\n gcc %s %s\n" cfile loopfile;
flush stdout
Test Run By jahier on Fri Jul 4 16:18:39 2014
Test Run By jahier on Mon Jul 7 11:37:24 2014
Native configuration is i686-pc-linux-gnu
=== lus2lic tests ===
......@@ -1511,5 +1511,5 @@ XPASS: Test bad programs (semantics): lus2lic {-o /tmp/bug.lic should_fail/seman
# of unexpected failures 110
# of unexpected successes 21
# of expected failures 37
testcase ./lus2lic.tests/non-reg.exp completed in 139 seconds
testcase ./lus2lic.tests/non-reg.exp completed in 140 seconds
testcase ./lus2lic.tests/progression.exp completed in 0 seconds
testcase ./lus2lic.tests/non-reg.exp completed in 139 seconds
testcase ./lus2lic.tests/non-reg.exp completed in 140 seconds
testcase ./lus2lic.tests/progression.exp completed in 0 seconds
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment