Skip to content
Snippets Groups Projects
Commit 1e48ef45 authored by Pierre Loic Garoche's avatar Pierre Loic Garoche
Browse files

- Dealt with compiling lusic from distant lusi files.

- Header now do not allow the generation of function previously declared as C prototype



git-svn-id: https://cavale.enseeiht.fr/svn/lustrec/lustre_compiler/trunk@375 041b043f-8d7c-46b2-b46e-ef0dd855326e
parent 17db36ed
No related branches found
No related tags found
No related merge requests found
# OASIS_START
# DO NOT EDIT (digest: bc1e05bfc8b39b664f29dae8dbd3ebbb)
SETUP = ocaml setup.ml
build: setup.data
$(SETUP) -build $(BUILDFLAGS)
doc: setup.data build
$(SETUP) -doc $(DOCFLAGS)
test: setup.data build
$(SETUP) -test $(TESTFLAGS)
all:
$(SETUP) -all $(ALLFLAGS)
install: setup.data
$(SETUP) -install $(INSTALLFLAGS)
uninstall: setup.data
$(SETUP) -uninstall $(UNINSTALLFLAGS)
reinstall: setup.data
$(SETUP) -reinstall $(REINSTALLFLAGS)
clean:
$(SETUP) -clean $(CLEANFLAGS)
distclean:
$(SETUP) -distclean $(DISTCLEANFLAGS)
setup.data:
$(SETUP) -configure $(CONFIGUREFLAGS)
.PHONY: build doc test all install uninstall reinstall clean distclean configure
# OASIS_STOP
OCAMLBUILD=@OCAMLBUILD@ -classic-display -no-links
prefix=@prefix@
exec_prefix=@exec_prefix@
bindir=@bindir@
datarootdir = ${prefix}/share
includedir = ${prefix}/include
LUSI_LIBS=include/math.lusi include/conv.lusi
LOCAL_BINDIR=bin
LOCAL_DOCDIR=doc/manual
lustrec:
@echo Compiling binary lustrec
@$(OCAMLBUILD) src/main_lustre_compiler.native
@mkdir -p $(LOCAL_BINDIR)
@mv _build/src/main_lustre_compiler.native $(LOCAL_BINDIR)/lustrec
doc:
@echo Generating doc
@$(OCAMLBUILD) lustrec.docdir/index.html
@rm -rf $(LOCAL_DOCDIR)
@cp -rf _build/lustrec.docdir $(LOCAL_DOCDIR)
dot: doc
$(OCAMLBUILD) lustrec.docdir/lustrec.dot
dot -T ps -o lustrec.dot _build/lustrec.docdir/lustrec.dot
mv _build/lustrec.docdir/lustrec.dot $(LOCAL_DOCDIR)
clean:
$(OCAMLBUILD) -clean
dist-clean: clean
rm -f Makefile myocamlbuild.ml config.log config.status configure include/*.lusic include/math.h include/conv.h
%.lusic: %.lusi
@echo Compiling $<
@$(LOCAL_BINDIR)/lustrec -verbose 0 -d include $<
compile-lusi: $(LUSI_LIBS:%.lusi=%.lusic)
install: compile-lusi
mkdir -p ${bindir}
install -m 0755 $(LOCAL_BINDIR)/* ${bindir}
mkdir -p ${includedir}/lustrec
cp include/* ${includedir}/lustrec
.PHONY: compile-lusi doc dot lustrec lustrec.odocl clean install dist-clean
"src": include
"src/backends/C": include
"src/backends/Horn": include
# OASIS_START
# DO NOT EDIT (digest: 98bcbc21d29d2f6266238c1025fff223)
# Ignore VCS directories, you can use the same kind of rule outside
# OASIS_START/STOP if you want to exclude directories that contains
# useless stuff for the build process
<**/.svn>: -traverse
<**/.svn>: not_hygienic
".bzr": -traverse
".bzr": not_hygienic
".hg": -traverse
".hg": not_hygienic
".git": -traverse
".git": not_hygienic
"_darcs": -traverse
"_darcs": not_hygienic
# Executable lustrec
"src/main_lustre_compiler.native": pkg_ocamlgraph
"src/main_lustre_compiler.native": pkg_str
"src/main_lustre_compiler.native": pkg_unix
<src/*.ml{,i}>: pkg_ocamlgraph
<src/*.ml{,i}>: pkg_str
<src/*.ml{,i}>: pkg_unix
# OASIS_STOP
"src/main_lustre_compiler.native": use_graph
"src/main_lustre_compiler.native": use_str
"src/main_lustre_compiler.native": use_unix
<src/*.ml{,i}>: use_graph
<src/*.ml{,i}>: use_str
<src/*.ml{,i}>: use_unix
This diff is collapsed.
define([svnversion], esyscmd([sh -c "svnversion|sed "s/:.*//"|tr -d '\n'"]))dnl
AC_INIT([lustrec], [0.1-svnversion], [ploc@garoche.net])
AC_DEFINE(SVN_REVISION, "svnversion", [SVN Revision])
AC_SUBST(SVN_REVISION)
AC_CONFIG_SRCDIR([src/main_lustre_compiler.ml])
# default prefix is /usr/local
AC_PREFIX_DEFAULT(/usr/local)
AC_ARG_WITH([ocamlgraph-path],
[AS_HELP_STRING([--ocamlgraph-path],
[specify the path of ocamlgraph library. graph.cmxa should be in ocamlgraph-path @<:@default=$(ocamlfind query ocamlgraph)@:>@])],
[AS_IF([test "x$ocamlgraph_path" = xno],
[AC_MSG_ERROR([ocamlgraph library is needed])],
[test "x$ocamlgraph_path" = xyes],
[OCAMLGRAPH_PATH=$(ocamlfind query ocamlgraph)],
[OCAMLGRAPH_PATH=$ocamlgraph_path]
)],
[OCAMLGRAPH_PATH=$(ocamlfind query ocamlgraph)]
)
AC_SUBST(OCAMLGRAPH_PATH)
AC_PATH_PROG([OCAMLC],[ocamlc],[:])
AC_MSG_CHECKING(OCaml version)
ocamlc_version=`$OCAMLC -v | grep version | rev| cut -d \ -f 1 | rev`
major=`echo $ocamlc_version | cut -d . -f 1`
minor=`echo $ocamlc_version | cut -d . -f 2`
if (test "$major" -lt 3 -a "$minor" -lt 11 ); then
AC_MSG_ERROR([Ocaml version must be at least 3.11. You have version $ocamlc_version])
fi
AC_MSG_RESULT(valid ocaml version detected: $ocamlc_version)
AC_PATH_PROG([OCAMLBUILD],[ocamlbuild],[:])
# Checking libs
# Checks for libraries. OCamlgraph
AC_MSG_CHECKING(ocamlgraph library)
ocamlgraph_lib=`find $OCAMLGRAPH_PATH -iname graph.cmxa -nowarn | grep -m 1 -o "graph.cmxa"`
if (test "x$ocamlgraph_lib" = xgraph.cmxa ); then
ocamlgraph_lib_full=`find $OCAMLGRAPH_PATH -iname graph.cmxa -nowarn | grep -m 1 "graph.cmxa"`
AC_MSG_RESULT(library detected: $ocamlgraph_lib_full )
else
AC_MSG_ERROR([ocamlgraph library not installed in $OCAMLGRAPH_PATH])
fi
# Workaround to solve an issue with ocamlbuild and C libraries.
oCFLAGS="$CFLAGS"
CFLAGS="$FLAGS -Wl,--no-as-needed"
AC_MSG_CHECKING([whether we need to add --no-as-needed linking option])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]],
[[
int main(){ return 0; }
]])],
[AC_MSG_RESULT([yes]); CC_NOASNEEDED="true"],
[AC_MSG_RESULT([no]); CC_NOASNEEDED="false"])
CFLAGS=$oCFLAGS
AC_SUBST(CC_NOASNEEDED)
# End of config
AC_DEFUN([AC_DEFINE_DIR], [
prefix_NONE=
exec_prefix_NONE=
test "x$prefix" = xNONE && prefix_NONE=yes && prefix=$ac_default_prefix
test "x$exec_prefix" = xNONE && exec_prefix_NONE=yes && exec_prefix=$prefix
dnl In Autoconf 2.60, ${datadir} refers to ${datarootdir}, which in turn
dnl refers to ${prefix}. Thus we have to use `eval' twice.
eval ac_define_dir="\"[$]$2\""
eval ac_define_dir="\"$ac_define_dir\""
AC_SUBST($1, "$ac_define_dir")
AC_DEFINE_UNQUOTED($1, "$ac_define_dir", [$3])
test "$prefix_NONE" && prefix=NONE
test "$exec_prefix_NONE" && exec_prefix=NONE
])
AC_DEFINE_DIR([abs_datadir], [datadir])
# Instanciation
AC_CONFIG_FILES([Makefile
myocamlbuild.ml
src/version.ml])
AC_OUTPUT
# summary
dnl AC_MSG_NOTICE(******** Configuration ********)
int real_to_int (double in1);
double int_to_real (int in1);
(* OASIS_START *)
(* DO NOT EDIT (digest: 72be793de58c2829edbc48dbc71bb938) *)
module OASISGettext = struct
(* # 21 "src/oasis/OASISGettext.ml" *)
let ns_ str =
str
let s_ str =
str
let f_ (str : ('a, 'b, 'c, 'd) format4) =
str
let fn_ fmt1 fmt2 n =
if n = 1 then
fmt1^^""
else
fmt2^^""
let init =
[]
end
module OASISExpr = struct
(* # 21 "src/oasis/OASISExpr.ml" *)
open OASISGettext
type test = string
type flag = string
type t =
| EBool of bool
| ENot of t
| EAnd of t * t
| EOr of t * t
| EFlag of flag
| ETest of test * string
type 'a choices = (t * 'a) list
let eval var_get t =
let rec eval' =
function
| EBool b ->
b
| ENot e ->
not (eval' e)
| EAnd (e1, e2) ->
(eval' e1) && (eval' e2)
| EOr (e1, e2) ->
(eval' e1) || (eval' e2)
| EFlag nm ->
let v =
var_get nm
in
assert(v = "true" || v = "false");
(v = "true")
| ETest (nm, vl) ->
let v =
var_get nm
in
(v = vl)
in
eval' t
let choose ?printer ?name var_get lst =
let rec choose_aux =
function
| (cond, vl) :: tl ->
if eval var_get cond then
vl
else
choose_aux tl
| [] ->
let str_lst =
if lst = [] then
s_ "<empty>"
else
String.concat
(s_ ", ")
(List.map
(fun (cond, vl) ->
match printer with
| Some p -> p vl
| None -> s_ "<no printer>")
lst)
in
match name with
| Some nm ->
failwith
(Printf.sprintf
(f_ "No result for the choice list '%s': %s")
nm str_lst)
| None ->
failwith
(Printf.sprintf
(f_ "No result for a choice list: %s")
str_lst)
in
choose_aux (List.rev lst)
end
# 117 "myocamlbuild.ml"
module BaseEnvLight = struct
(* # 21 "src/base/BaseEnvLight.ml" *)
module MapString = Map.Make(String)
type t = string MapString.t
let default_filename =
Filename.concat
(Sys.getcwd ())
"setup.data"
let load ?(allow_empty=false) ?(filename=default_filename) () =
if Sys.file_exists filename then
begin
let chn =
open_in_bin filename
in
let st =
Stream.of_channel chn
in
let line =
ref 1
in
let st_line =
Stream.from
(fun _ ->
try
match Stream.next st with
| '\n' -> incr line; Some '\n'
| c -> Some c
with Stream.Failure -> None)
in
let lexer =
Genlex.make_lexer ["="] st_line
in
let rec read_file mp =
match Stream.npeek 3 lexer with
| [Genlex.Ident nm; Genlex.Kwd "="; Genlex.String value] ->
Stream.junk lexer;
Stream.junk lexer;
Stream.junk lexer;
read_file (MapString.add nm value mp)
| [] ->
mp
| _ ->
failwith
(Printf.sprintf
"Malformed data file '%s' line %d"
filename !line)
in
let mp =
read_file MapString.empty
in
close_in chn;
mp
end
else if allow_empty then
begin
MapString.empty
end
else
begin
failwith
(Printf.sprintf
"Unable to load environment, the file '%s' doesn't exist."
filename)
end
let var_get name env =
let rec var_expand str =
let buff =
Buffer.create ((String.length str) * 2)
in
Buffer.add_substitute
buff
(fun var ->
try
var_expand (MapString.find var env)
with Not_found ->
failwith
(Printf.sprintf
"No variable %s defined when trying to expand %S."
var
str))
str;
Buffer.contents buff
in
var_expand (MapString.find name env)
let var_choose lst env =
OASISExpr.choose
(fun nm -> var_get nm env)
lst
end
# 215 "myocamlbuild.ml"
module MyOCamlbuildFindlib = struct
(* # 21 "src/plugins/ocamlbuild/MyOCamlbuildFindlib.ml" *)
(** OCamlbuild extension, copied from
* http://brion.inria.fr/gallium/index.php/Using_ocamlfind_with_ocamlbuild
* by N. Pouillard and others
*
* Updated on 2009/02/28
*
* Modified by Sylvain Le Gall
*)
open Ocamlbuild_plugin
(* these functions are not really officially exported *)
let run_and_read =
Ocamlbuild_pack.My_unix.run_and_read
let blank_sep_strings =
Ocamlbuild_pack.Lexers.blank_sep_strings
let split s ch =
let x =
ref []
in
let rec go s =
let pos =
String.index s ch
in
x := (String.before s pos)::!x;
go (String.after s (pos + 1))
in
try
go s
with Not_found -> !x
let split_nl s = split s '\n'
let before_space s =
try
String.before s (String.index s ' ')
with Not_found -> s
(* this lists all supported packages *)
let find_packages () =
List.map before_space (split_nl & run_and_read "ocamlfind list")
(* this is supposed to list available syntaxes, but I don't know how to do it. *)
let find_syntaxes () = ["camlp4o"; "camlp4r"]
(* ocamlfind command *)
let ocamlfind x = S[A"ocamlfind"; x]
let dispatch =
function
| Before_options ->
(* by using Before_options one let command line options have an higher priority *)
(* on the contrary using After_options will guarantee to have the higher priority *)
(* override default commands by ocamlfind ones *)
Options.ocamlc := ocamlfind & A"ocamlc";
Options.ocamlopt := ocamlfind & A"ocamlopt";
Options.ocamldep := ocamlfind & A"ocamldep";
Options.ocamldoc := ocamlfind & A"ocamldoc";
Options.ocamlmktop := ocamlfind & A"ocamlmktop"
| After_rules ->
(* When one link an OCaml library/binary/package, one should use -linkpkg *)
flag ["ocaml"; "link"; "program"] & A"-linkpkg";
(* For each ocamlfind package one inject the -package option when
* compiling, computing dependencies, generating documentation and
* linking. *)
List.iter
begin fun pkg ->
flag ["ocaml"; "compile"; "pkg_"^pkg] & S[A"-package"; A pkg];
flag ["ocaml"; "ocamldep"; "pkg_"^pkg] & S[A"-package"; A pkg];
flag ["ocaml"; "doc"; "pkg_"^pkg] & S[A"-package"; A pkg];
flag ["ocaml"; "link"; "pkg_"^pkg] & S[A"-package"; A pkg];
flag ["ocaml"; "infer_interface"; "pkg_"^pkg] & S[A"-package"; A pkg];
end
(find_packages ());
(* Like -package but for extensions syntax. Morover -syntax is useless
* when linking. *)
List.iter begin fun syntax ->
flag ["ocaml"; "compile"; "syntax_"^syntax] & S[A"-syntax"; A syntax];
flag ["ocaml"; "ocamldep"; "syntax_"^syntax] & S[A"-syntax"; A syntax];
flag ["ocaml"; "doc"; "syntax_"^syntax] & S[A"-syntax"; A syntax];
flag ["ocaml"; "infer_interface"; "syntax_"^syntax] & S[A"-syntax"; A syntax];
end (find_syntaxes ());
(* The default "thread" tag is not compatible with ocamlfind.
* Indeed, the default rules add the "threads.cma" or "threads.cmxa"
* options when using this tag. When using the "-linkpkg" option with
* ocamlfind, this module will then be added twice on the command line.
*
* To solve this, one approach is to add the "-thread" option when using
* the "threads" package using the previous plugin.
*)
flag ["ocaml"; "pkg_threads"; "compile"] (S[A "-thread"]);
flag ["ocaml"; "pkg_threads"; "doc"] (S[A "-I"; A "+threads"]);
flag ["ocaml"; "pkg_threads"; "link"] (S[A "-thread"]);
flag ["ocaml"; "pkg_threads"; "infer_interface"] (S[A "-thread"])
| _ ->
()
end
module MyOCamlbuildBase = struct
(* # 21 "src/plugins/ocamlbuild/MyOCamlbuildBase.ml" *)
(** Base functions for writing myocamlbuild.ml
@author Sylvain Le Gall
*)
open Ocamlbuild_plugin
module OC = Ocamlbuild_pack.Ocaml_compiler
type dir = string
type file = string
type name = string
type tag = string
(* # 56 "src/plugins/ocamlbuild/MyOCamlbuildBase.ml" *)
type t =
{
lib_ocaml: (name * dir list) list;
lib_c: (name * dir * file list) list;
flags: (tag list * (spec OASISExpr.choices)) list;
(* Replace the 'dir: include' from _tags by a precise interdepends in
* directory.
*)
includes: (dir * dir list) list;
}
let env_filename =
Pathname.basename
BaseEnvLight.default_filename
let dispatch_combine lst =
fun e ->
List.iter
(fun dispatch -> dispatch e)
lst
let tag_libstubs nm =
"use_lib"^nm^"_stubs"
let nm_libstubs nm =
nm^"_stubs"
let dispatch t e =
let env =
BaseEnvLight.load
~filename:env_filename
~allow_empty:true
()
in
match e with
| Before_options ->
let no_trailing_dot s =
if String.length s >= 1 && s.[0] = '.' then
String.sub s 1 ((String.length s) - 1)
else
s
in
List.iter
(fun (opt, var) ->
try
opt := no_trailing_dot (BaseEnvLight.var_get var env)
with Not_found ->
Printf.eprintf "W: Cannot get variable %s" var)
[
Options.ext_obj, "ext_obj";
Options.ext_lib, "ext_lib";
Options.ext_dll, "ext_dll";
]
| After_rules ->
(* Declare OCaml libraries *)
List.iter
(function
| nm, [] ->
ocaml_lib nm
| nm, dir :: tl ->
ocaml_lib ~dir:dir (dir^"/"^nm);
List.iter
(fun dir ->
List.iter
(fun str ->
flag ["ocaml"; "use_"^nm; str] (S[A"-I"; P dir]))
["compile"; "infer_interface"; "doc"])
tl)
t.lib_ocaml;
(* Declare directories dependencies, replace "include" in _tags. *)
List.iter
(fun (dir, include_dirs) ->
Pathname.define_context dir include_dirs)
t.includes;
(* Declare C libraries *)
List.iter
(fun (lib, dir, headers) ->
(* Handle C part of library *)
flag ["link"; "library"; "ocaml"; "byte"; tag_libstubs lib]
(S[A"-dllib"; A("-l"^(nm_libstubs lib)); A"-cclib";
A("-l"^(nm_libstubs lib))]);
flag ["link"; "library"; "ocaml"; "native"; tag_libstubs lib]
(S[A"-cclib"; A("-l"^(nm_libstubs lib))]);
flag ["link"; "program"; "ocaml"; "byte"; tag_libstubs lib]
(S[A"-dllib"; A("dll"^(nm_libstubs lib))]);
(* When ocaml link something that use the C library, then one
need that file to be up to date.
*)
dep ["link"; "ocaml"; "program"; tag_libstubs lib]
[dir/"lib"^(nm_libstubs lib)^"."^(!Options.ext_lib)];
dep ["compile"; "ocaml"; "program"; tag_libstubs lib]
[dir/"lib"^(nm_libstubs lib)^"."^(!Options.ext_lib)];
(* TODO: be more specific about what depends on headers *)
(* Depends on .h files *)
dep ["compile"; "c"]
headers;
(* Setup search path for lib *)
flag ["link"; "ocaml"; "use_"^lib]
(S[A"-I"; P(dir)]);
)
t.lib_c;
(* Add flags *)
List.iter
(fun (tags, cond_specs) ->
let spec =
BaseEnvLight.var_choose cond_specs env
in
flag tags & spec)
t.flags
| _ ->
()
let dispatch_default t =
dispatch_combine
[
dispatch t;
MyOCamlbuildFindlib.dispatch;
]
end
# 476 "myocamlbuild.ml"
open Ocamlbuild_plugin;;
let package_default =
{MyOCamlbuildBase.lib_ocaml = []; lib_c = []; flags = []; includes = []}
;;
let dispatch_default = MyOCamlbuildBase.dispatch_default package_default;;
# 485 "myocamlbuild.ml"
(* OASIS_STOP *)
Ocamlbuild_plugin.dispatch dispatch_default;;
open Ocamlbuild_plugin
open Command
;;
dispatch begin function
| After_rules ->
(* We declare external libraries *)
ocaml_lib ~extern:true ~dir:"@OCAMLGRAPH_PATH@" "graph";
if @CC_NOASNEEDED@ then
flag ["ocaml"; "link"]
(S [A"-cclib";A"-Wl,--no-as-needed"]);
| _ -> ()
end
......@@ -94,20 +94,31 @@ let pp_machine_step_name fmt id = fprintf fmt "%s_step" id
let pp_c_dimension fmt d =
fprintf fmt "%a" Dimension.pp_dimension d
let is_basic_c_type t =
match (Types.repr t).Types.tdesc with
| Types.Tbool | Types.Treal | Types.Tint -> true
| _ -> false
let pp_basic_c_type fmt t =
match (Types.repr t).Types.tdesc with
| Types.Tbool -> fprintf fmt "_Bool"
| Types.Treal -> fprintf fmt "double"
| Types.Tint -> fprintf fmt "int"
| _ -> assert false (* Not a basic C type. Do not handle arrays or pointers *)
let pp_c_type var fmt t =
let rec aux t pp_suffix =
match (Types.repr t).Types.tdesc with
| Types.Tclock t' -> aux t' pp_suffix
| Types.Tbool -> fprintf fmt "_Bool %s%a" var pp_suffix ()
| Types.Treal -> fprintf fmt "double %s%a" var pp_suffix ()
| Types.Tint -> fprintf fmt "int %s%a" var pp_suffix ()
| Types.Tarray (d, t') ->
let pp_suffix' fmt () = fprintf fmt "%a[%a]" pp_suffix () pp_c_dimension d in
aux t' pp_suffix'
| Types.Tstatic (_, t') -> fprintf fmt "const "; aux t' pp_suffix
| Types.Tconst ty -> fprintf fmt "%s %s" ty var
| Types.Tarrow (_, _) -> fprintf fmt "void (*%s)()" var
| _ -> eprintf "internal error: pp_c_type %a@." Types.print_ty t; assert false
match (Types.repr t).Types.tdesc with
| Types.Tclock t' -> aux t' pp_suffix
| Types.Tbool | Types.Treal | Types.Tint
-> fprintf fmt "%a %s%a" pp_basic_c_type t var pp_suffix ()
| Types.Tarray (d, t') ->
let pp_suffix' fmt () = fprintf fmt "%a[%a]" pp_suffix () pp_c_dimension d in
aux t' pp_suffix'
| Types.Tstatic (_, t') -> fprintf fmt "const "; aux t' pp_suffix
| Types.Tconst ty -> fprintf fmt "%s %s" ty var
| Types.Tarrow (_, _) -> fprintf fmt "void (*%s)()" var
| _ -> eprintf "internal error: pp_c_type %a@." Types.print_ty t; assert false
in aux t (fun fmt () -> ())
let rec pp_c_initialize fmt t =
......@@ -319,6 +330,19 @@ let print_step_prototype self fmt (name, inputs, outputs) =
pp_machine_memtype_name name
self
let print_stateless_C_prototype fmt (name, inputs, outputs) =
let output =
match outputs with
| [hd] -> hd
| _ -> assert false
in
fprintf fmt "%a %s (@[<v>@[%a@]@,@])"
pp_basic_c_type output.var_type
name
(Utils.fprintf_list ~sep:",@ " pp_c_decl_input_var) inputs
let print_import_prototype fmt (_, s, _) =
fprintf fmt "#include \"%s.h\"@," s
......
......@@ -34,7 +34,7 @@ module Main = functor (Mod: MODIFIERS_HDR) ->
struct
let print_import_standard fmt =
fprintf fmt "#include \"%s/include/lustrec/arrow.h\"@.@." Version.prefix
fprintf fmt "#include \"%s/arrow.h\"@.@." Version.include_path
let print_static_declare_instance attr fmt (i, (m, static)) =
fprintf fmt "%a(%s, %a%t%s)"
......@@ -163,26 +163,36 @@ let print_machine_alloc_decl fmt m =
let print_machine_decl_from_header fmt inode =
(*Mod.print_machine_decl_prefix fmt m;*)
if inode.nodei_stateless then
begin
fprintf fmt "extern %a;@.@."
print_stateless_prototype
(inode.nodei_id, inode.nodei_inputs, inode.nodei_outputs)
end
if inode.nodei_prototype = Some "C" then
if inode.nodei_stateless then
begin
fprintf fmt "extern %a;@.@."
print_stateless_C_prototype
(inode.nodei_id, inode.nodei_inputs, inode.nodei_outputs)
end
else (
raise (Invalid_argument ("A node with declared prototype C cannot be stateful, it has to be a function")))
else
if inode.nodei_stateless then
begin
let static_inputs = List.filter (fun v -> v.var_dec_const) inode.nodei_inputs in
let used name =
(List.exists (fun v -> v.var_id = name) inode.nodei_inputs)
|| (List.exists (fun v -> v.var_id = name) inode.nodei_outputs) in
let self = mk_new_name used "self" in
fprintf fmt "extern %a;@.@."
(print_reset_prototype self) (inode.nodei_id, static_inputs);
fprintf fmt "extern %a;@.@."
(print_step_prototype self)
print_stateless_prototype
(inode.nodei_id, inode.nodei_inputs, inode.nodei_outputs)
end
else
begin
let static_inputs = List.filter (fun v -> v.var_dec_const) inode.nodei_inputs in
let used name =
(List.exists (fun v -> v.var_id = name) inode.nodei_inputs)
|| (List.exists (fun v -> v.var_id = name) inode.nodei_outputs) in
let self = mk_new_name used "self" in
fprintf fmt "extern %a;@.@."
(print_reset_prototype self) (inode.nodei_id, static_inputs);
fprintf fmt "extern %a;@.@."
(print_step_prototype self)
(inode.nodei_id, inode.nodei_inputs, inode.nodei_outputs)
end
let print_const_decl fmt cdecl =
fprintf fmt "extern %a;@."
......@@ -303,6 +313,8 @@ let print_alloc_header header_fmt basename prog machines dependencies =
pp_print_newline header_fmt ()
end
(* Function called when compiling a lusi file and generating the associated C
header. *)
let print_header_from_header header_fmt basename header =
(* Include once: start *)
let baseNAME = String.uppercase basename in
......
......@@ -107,7 +107,7 @@ let print_main_fun machines m fmt =
fprintf fmt "@]@ }@."
let print_main_header fmt =
fprintf fmt "#include <stdio.h>@.#include <unistd.h>@.#include \"%s/include/lustrec/io_frontend.h\"@." Version.prefix
fprintf fmt "#include <stdio.h>@.#include <unistd.h>@.#include \"%s/io_frontend.h\"@." Version.include_path
let print_main_c main_fmt main_machine basename prog machines dependencies =
......
......@@ -47,7 +47,7 @@ let fprintf_dependencies fmt dep =
(("${INC}/io_frontend.c"):: (* IO functions when a main function is computed *)
(List.map
(fun (local, s, _) ->
(if local then s else Version.prefix ^ "/include/lustrec/" ^ s) ^ ".c")
(if local then s else Version.include_path ^ "/" ^ s) ^ ".c")
compiled_dep))
module type MODIFIERS_MKF =
......
......@@ -231,10 +231,12 @@ let is_imported_node td =
(* alias and type definition table *)
let top_int_type = mktop_decl Location.dummy_loc Version.prefix false (TypeDef {tydef_id = "int"; tydef_desc = Tydec_int})
let top_bool_type = mktop_decl Location.dummy_loc Version.prefix false (TypeDef {tydef_id = "bool"; tydef_desc = Tydec_bool})
let top_float_type = mktop_decl Location.dummy_loc Version.prefix false (TypeDef {tydef_id = "float"; tydef_desc = Tydec_float})
let top_real_type = mktop_decl Location.dummy_loc Version.prefix false (TypeDef {tydef_id = "real"; tydef_desc = Tydec_real})
let mktop = mktop_decl Location.dummy_loc Version.include_path false
let top_int_type = mktop (TypeDef {tydef_id = "int"; tydef_desc = Tydec_int})
let top_bool_type = mktop (TypeDef {tydef_id = "bool"; tydef_desc = Tydec_bool})
let top_float_type = mktop (TypeDef {tydef_id = "float"; tydef_desc = Tydec_float})
let top_real_type = mktop (TypeDef {tydef_id = "real"; tydef_desc = Tydec_real})
let type_table =
Utils.create_hashtable 20 [
......@@ -788,7 +790,7 @@ let mk_internal_node id =
let (tin, tout) = Types.split_arrow ty in
(*eprintf "internal fun %s: %d -> %d@." id (List.length (Types.type_list_of_type tin)) (List.length (Types.type_list_of_type tout));*)
let cpt = ref (-1) in
mktop_decl Location.dummy_loc Version.prefix false
mktop
(ImportedNode
{nodei_id = id;
nodei_type = ty;
......
......@@ -166,7 +166,7 @@ let arrow_desc =
let arrow_top_decl =
{
top_decl_desc = Node arrow_desc;
top_decl_owner = Version.prefix;
top_decl_owner = Version.include_path;
top_decl_itf = false;
top_decl_loc = Location.dummy_loc
}
......
......@@ -32,17 +32,18 @@ let print_lusi prog basename extension =
end
(* compile a .lusi header file *)
let compile_header basename extension =
let compile_header dirname basename extension =
let destname = !Options.dest_dir ^ "/" ^ basename in
let header_name = basename ^ extension in
let lusic_ext = extension ^ "c" in
begin
Log.report ~level:1 (fun fmt -> fprintf fmt "@[<v>");
let header = parse_header true header_name in
let header = parse_header true (dirname ^ "/" ^ header_name) in
ignore (Modules.load_header ISet.empty header);
ignore (check_top_decls header);
create_dest_dir ();
Log.report ~level:1 (fun fmt -> fprintf fmt ".. generating compiled header file %sc@," header_name);
Log.report ~level:1
(fun fmt -> fprintf fmt ".. generating compiled header file %sc@," (destname ^ extension));
Lusic.write_lusic true header destname lusic_ext;
Lusic.print_lusic_to_h destname lusic_ext;
Log.report ~level:1 (fun fmt -> fprintf fmt ".. done !@ @]@.")
......@@ -82,8 +83,8 @@ let compile_source_to_header prog computed_types_env computed_clocks_env basenam
end
(* compile a .lus source file *)
let rec compile_source basename extension =
let source_name = basename ^ extension in
let rec compile_source dirname basename extension =
let source_name = (*dirname ^ "/" ^*) basename ^ extension in
Log.report ~level:1 (fun fmt -> fprintf fmt "@[<v>");
......@@ -293,17 +294,24 @@ let rec compile_source basename extension =
exit 0
end
let compile basename extension =
let compile dirname basename extension =
match extension with
| ".lusi" -> compile_header basename extension
| ".lus" -> compile_source basename extension
| ".lusi" -> compile_header dirname basename extension
| ".lus" -> compile_source dirname basename extension
| _ -> assert false
let anonymous filename =
let ok_ext, ext = List.fold_left (fun (ok, ext) ext' -> if not ok && Filename.check_suffix filename ext' then true, ext' else ok, ext) (false, "") extensions in
let ok_ext, ext = List.fold_left
(fun (ok, ext) ext' ->
if not ok && Filename.check_suffix filename ext' then
true, ext'
else
ok, ext)
(false, "") extensions in
if ok_ext then
let dirname = Filename.dirname filename in
let basename = Filename.chop_suffix (Filename.basename filename) ext in
compile basename ext
compile dirname basename ext
else
raise (Arg.Bad ("Can only compile *.lusi, *.lus or *.ec files"))
......
......@@ -114,7 +114,7 @@ let add_const itf name value =
with Not_found -> Hashtbl.add consts_table name value
let name_dependency (local, dep) =
(if local then !Options.dest_dir ^ "/" else Version.prefix ^ "/include/lustrec/") ^ dep
((if local then !Options.dest_dir else Version.include_path) ^ "/") ^ dep
let import_dependency loc (local, dep) =
let basename = name_dependency (local, dep) in
......
......@@ -9,7 +9,13 @@
(* *)
(********************************************************************)
let version = "0.1-"^Version.number
let version = Version.number
let include_path = Version.include_path
let print_version () =
Format.printf "Lustrec compiler, version %s@." version;
Format.printf "Include directory: %s@." include_path
let main_node = ref ""
let static_mem = ref true
let print_types = ref true
......@@ -31,6 +37,7 @@ let horntraces = ref false
let horn_cex = ref false
let horn_queries = ref false
let options =
[ "-d", Arg.Set_string dest_dir,
"uses the specified directory as root for generated/imported object and C files (default: .)";
......@@ -55,7 +62,7 @@ let options =
"-print_clocks", Arg.Set print_clocks, "prints node clocks";
"-O", Arg.Set_int optimization, " changes optimization level <default: 2>";
"-verbose", Arg.Set_int verbose_level, " changes verbose level <default: 1>";
"-version", Arg.Unit (fun () -> print_endline version), " displays the version";]
"-version", Arg.Unit print_version, " displays the version";]
let get_witness_dir filename =
(* Make sure the directory exists *)
......
let number = "@PACKAGE_VERSION@"
let prefix = "@prefix@"
let include_path = prefix ^ "/include/lustrec"
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