Skip to content
Snippets Groups Projects
Commit ca7ff3f7 authored by BRUN Lelio's avatar BRUN Lelio
Browse files

reformatting

parent 3ee26303
No related branches found
No related tags found
No related merge requests found
Showing
with 5400 additions and 5090 deletions
This diff is collapsed.
This diff is collapsed.
......@@ -13,115 +13,126 @@ open Format
open Lustre_types
let pp_dep fmt dep =
Format.fprintf fmt "%b, %s, {%a}, %b"
dep.local dep.name Printers.pp_prog dep.content dep.is_stateful
let pp_deps fmt deps = Format.fprintf fmt "@[<v 0>%a@ @]" (Utils.fprintf_list ~sep:"@ ," pp_dep) deps
Format.fprintf fmt "%b, %s, {%a}, %b" dep.local dep.name Printers.pp_prog
dep.content dep.is_stateful
let pp_deps fmt deps =
Format.fprintf fmt "@[<v 0>%a@ @]" (Utils.fprintf_list ~sep:"@ ," pp_dep) deps
let header_has_code header =
List.exists
(fun top ->
List.exists
(fun top ->
match top.top_decl_desc with
| Const _ -> true
| ImportedNode nd -> nd.nodei_in_lib = []
| _ -> false
)
| Const _ ->
true
| ImportedNode nd ->
nd.nodei_in_lib = []
| _ ->
false)
header
let header_libs header =
List.fold_left (fun accu top ->
match top.top_decl_desc with
| ImportedNode nd -> Utils.list_union nd.nodei_in_lib accu
| _ -> accu
) [] header
let compiled_dependencies deps =
List.fold_left
(fun accu top ->
match top.top_decl_desc with
| ImportedNode nd ->
Utils.list_union nd.nodei_in_lib accu
| _ ->
accu)
[] header
let compiled_dependencies deps =
List.filter (fun dep -> header_has_code dep.content) deps
let lib_dependencies deps =
List.fold_left
(fun accu dep -> Utils.list_union (header_libs dep.content) accu) [] deps
let fprintf_dependencies fmt (deps: dep_t list) =
let lib_dependencies deps =
List.fold_left
(fun accu dep -> Utils.list_union (header_libs dep.content) accu)
[] deps
let fprintf_dependencies fmt (deps : dep_t list) =
(* Format.eprintf "Deps: %a@." pp_deps dep; *)
let compiled_deps = compiled_dependencies deps in
(* Format.eprintf "Compiled Deps: %a@." pp_deps compiled_dep; *)
List.iter (fun s -> Log.report ~level:1 (fun fmt -> fprintf fmt "Adding dependency: %s@." s);
fprintf fmt "\t${GCC} -I${INC} -c %s@." s)
(("${INC}/io_frontend.c"):: (* IO functions when a main function is computed *)
(List.map
(fun dep ->
(if dep.local then dep.name else Version.include_path ^ "/" ^ dep.name) ^ ".c")
compiled_deps))
module type MODIFIERS_MKF =
sig (* dep was (bool * ident * top_decl list) *)
val other_targets: Format.formatter -> string -> string -> dep_t list -> unit
List.iter
(fun s ->
Log.report ~level:1 (fun fmt -> fprintf fmt "Adding dependency: %s@." s);
fprintf fmt "\t${GCC} -I${INC} -c %s@." s)
("${INC}/io_frontend.c"
::
(* IO functions when a main function is computed *)
List.map
(fun dep ->
(if dep.local then dep.name else Version.include_path ^ "/" ^ dep.name)
^ ".c")
compiled_deps)
module type MODIFIERS_MKF = sig
(* dep was (bool * ident * top_decl list) *)
val other_targets : Format.formatter -> string -> string -> dep_t list -> unit
end
module EmptyMod =
(struct
module EmptyMod : MODIFIERS_MKF = struct
let other_targets _ _ _ _ = ()
end: MODIFIERS_MKF)
module Main = functor (Mod: MODIFIERS_MKF) ->
struct
(* TODO: BEWARE OF THE BUG !! in case of very long nodename or maybe even
basename, the string basename_nodename exceed a limit length for files on linux
and prevent gcc to generate the binary of that name.
To be solved (later) with
- either the default name if it short
- a shorter version if it is long (md5?)
- a provided name given when calling the makefile so the user can control the
expected name of the binary
*)
let print_makefile basename nodename (dependencies: dep_t list) fmt =
let binname =
let s = basename ^ "_" ^ nodename in
if String.length s > 100 (* seems that GCC fails from 144 characters and
on: File name too long collect2 ld error. *)
then
if String.length nodename > 100 then
basename ^ "_run" (* shorter version *)
else
nodename ^ "run"
else
s
in
fprintf fmt "BINNAME?=%s@." binname;
fprintf fmt "GCC=gcc -O0@.";
fprintf fmt "LUSTREC=%s@." Sys.executable_name;
fprintf fmt "LUSTREC_BASE=%s@." (Filename.dirname (Filename.dirname Sys.executable_name));
fprintf fmt "INC=%s@." Version.include_path (*"${LUSTREC_BASE}/include/lustrec"*);
fprintf fmt "@.";
(* Main binary *)
fprintf fmt "%s_%s: %s.c %s_main.c@." basename "run"(*nodename*) basename basename;
fprintf fmt "\t${GCC} -I${INC} -I. -c %s.c@." basename;
fprintf fmt "\t${GCC} -I${INC} -I. -c %s_main.c@." basename;
fprintf_dependencies fmt dependencies;
fprintf fmt "\t${GCC} -o ${BINNAME} io_frontend.o %a %s.o %s_main.o %a@."
(Utils.fprintf_list ~sep:" " (fun fmt dep -> Format.fprintf fmt "%s.o" dep.name))
(compiled_dependencies dependencies)
basename (* library .o *)
basename (* main function . o *)
(Utils.fprintf_list ~sep:" " (fun fmt lib -> fprintf fmt "-l%s" lib)) (lib_dependencies dependencies)
;
fprintf fmt "@.";
fprintf fmt "clean:@.";
fprintf fmt "\t\\rm -f *.o ${BINNAME}@.";
fprintf fmt "@.";
Mod.other_targets fmt basename nodename dependencies;
fprintf fmt "@.";
end
module Main =
functor
(Mod : MODIFIERS_MKF)
->
struct
(* TODO: BEWARE OF THE BUG !! in case of very long nodename or maybe even
basename, the string basename_nodename exceed a limit length for files on
linux and prevent gcc to generate the binary of that name.
To be solved (later) with - either the default name if it short - a
shorter version if it is long (md5?) - a provided name given when calling
the makefile so the user can control the expected name of the binary *)
let print_makefile basename nodename (dependencies : dep_t list) fmt =
let binname =
let s = basename ^ "_" ^ nodename in
if
String.length s > 100
(* seems that GCC fails from 144 characters and on: File name too long
collect2 ld error. *)
then
if String.length nodename > 100 then basename ^ "_run"
(* shorter version *)
else nodename ^ "run"
else s
in
fprintf fmt "BINNAME?=%s@." binname;
fprintf fmt "GCC=gcc -O0@.";
fprintf fmt "LUSTREC=%s@." Sys.executable_name;
fprintf fmt "LUSTREC_BASE=%s@."
(Filename.dirname (Filename.dirname Sys.executable_name));
fprintf fmt "INC=%s@." Version.include_path
(*"${LUSTREC_BASE}/include/lustrec"*);
fprintf fmt "@.";
(* Main binary *)
fprintf fmt "%s_%s: %s.c %s_main.c@." basename "run" (*nodename*) basename
basename;
fprintf fmt "\t${GCC} -I${INC} -I. -c %s.c@." basename;
fprintf fmt "\t${GCC} -I${INC} -I. -c %s_main.c@." basename;
fprintf_dependencies fmt dependencies;
fprintf fmt "\t${GCC} -o ${BINNAME} io_frontend.o %a %s.o %s_main.o %a@."
(Utils.fprintf_list ~sep:" " (fun fmt dep ->
Format.fprintf fmt "%s.o" dep.name))
(compiled_dependencies dependencies)
basename (* library .o *) basename
(* main function . o *)
(Utils.fprintf_list ~sep:" " (fun fmt lib -> fprintf fmt "-l%s" lib))
(lib_dependencies dependencies);
fprintf fmt "@.";
fprintf fmt "clean:@.";
fprintf fmt "\t\\rm -f *.o ${BINNAME}@.";
fprintf fmt "@.";
Mod.other_targets fmt basename nodename dependencies;
fprintf fmt "@."
end
(* Local Variables: *)
(* compile-command:"make -C ../../.." *)
(* End: *)
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
(** This function focuses on standard library calls: conversion functions and
math library. It could be later extended to handle more functions. For the
moment, modular compilation of multiple lustre sources as one output JSON is not
considered. *)
moment, modular compilation of multiple lustre sources as one output JSON is
not considered. *)
open Lustre_types
open Machine_code_types
......@@ -9,30 +9,26 @@ open Format
open EMF_common
let pp_call fmt m f outputs inputs =
let (decl, _) = List.assoc f m.mcalls in
if Corelang.is_imported_node decl then
let decl, _ = List.assoc f m.mcalls in
if Corelang.is_imported_node decl then (
let inode = Corelang.imported_node_of_top decl in
match inode.nodei_id, Filename.basename decl.top_decl_owner with
| name, (("lustrec_math" | "simulink_math_fcn" | "conv") as lib) -> (
fprintf fmt "\"kind\": \"functioncall\",@ \"name\": \"%s\",@ \"library\": \"%s\",@ "
| name, (("lustrec_math" | "simulink_math_fcn" | "conv") as lib) ->
fprintf fmt
"\"kind\": \"functioncall\",@ \"name\": \"%s\",@ \"library\": \"%s\",@ "
name lib;
fprintf fmt "\"lhs\": [@[%a@]],@ \"args\": [@[%a@]]"
(Utils.fprintf_list ~sep:",@ " (fun fmt v -> fprintf fmt "\"%a\"" Printers.pp_var_name v)) outputs
(pp_emf_cst_or_var_list m) inputs
)
(Utils.fprintf_list ~sep:",@ " (fun fmt v ->
fprintf fmt "\"%a\"" Printers.pp_var_name v))
outputs (pp_emf_cst_or_var_list m) inputs
| _ ->
Format.eprintf "Calls to function %s in library %s are not handled yet.@."
inode.nodei_id
(Filename.basename decl.top_decl_owner)
;
assert false
else
assert false (* shall not happen *)
Format.eprintf "Calls to function %s in library %s are not handled yet.@."
inode.nodei_id
(Filename.basename decl.top_decl_owner);
assert false)
else assert false
(* shall not happen *)
(* Local Variables: *)
(* compile-command: "make -C ../.." *)
(* End: *)
(* Local Variables: *)
(* compile-command: "make -C ../.." *)
(* End: *)
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -2,46 +2,37 @@
let join_guards = ref true
let setup () =
if !Options.output = "emf" then begin
if !Options.output = "emf" then (
(* Not merging branches *)
join_guards := false;
(* In case of a default "int" type, substitute it with the legal int32 value *)
if !Options.int_type = "int" then Options.int_type := "int32"
end;
if !Options.optimization < 0 then
join_guards := false
if !Options.int_type = "int" then Options.int_type := "int32");
if !Options.optimization < 0 then join_guards := false
let is_functional () =
let is_functional () =
match !Options.output with
| "horn" | "lustre" | "acsl" | "emf" -> true
| _ -> false
| "horn" | "lustre" | "acsl" | "emf" ->
true
| _ ->
false
(* Special treatment of arrows in lustre backend. We want to keep them *)
let unfold_arrow () =
match !Options.output with
| "lustre" -> false
| _ -> true
let unfold_arrow () = match !Options.output with "lustre" -> false | _ -> true
(* Forcing ite normalization *)
let alias_ite () =
match !Options.output with
| "emf" -> true
| _ -> false
let alias_ite () = match !Options.output with "emf" -> true | _ -> false
(* Forcing basic functions normalization *)
let alias_internal_fun () =
match !Options.output with
| "emf" -> true
| _ -> false
match !Options.output with "emf" -> true | _ -> false
let get_normalization_params () = {
let get_normalization_params () =
{
Normalization.unfold_arrow_active = unfold_arrow ();
force_alias_ite = alias_ite ();
force_alias_internal_fun = alias_internal_fun ();
}
(* Local Variables: *)
(* compile-command: "make -k -C .." *)
(* End: *)
This diff is collapsed.
This diff is collapsed.
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