Commit ad110579 authored by Erwan Jahier's avatar Erwan Jahier
Browse files

Do something if -tparse and friends is used without -luc.

Also, add a --2c-4c that does the same job as luc2c without option.
parent 146dc006
......@@ -7,7 +7,7 @@ CFLAGS = \
-I../../../include
LIBS = -lluc4c_nc -llucky_nc -lgmp -lm -ldl -lstdc++
LUC2C=../../../$(HOSTTYPE)/bin/luc2c
LUC2C=../../../$(HOSTTYPE)/bin/lutin --2c-4c
ifeq ($(HOSTTYPE),mac)
LINKER=g++ -g
......@@ -41,6 +41,9 @@ endif
foo.c: foo.lut
$(LUC2C) foo.lut
foo-sock.c: foo.lut
$(LUC2C) foo.lut
foo.o : foo.c
$(CC) -c $(CFLAGS) foo.c
......@@ -51,6 +54,9 @@ foo$(EXE): foo.o call_foo.o
$(LINKER) $(CFLAGS) -o $@ $^ $(LIBS)
foo-sock$(EXE): foo-sock.o call_foo.o
$(LINKER) $(CFLAGS) -o $@ $^ $(LIBS)
################################################################
clean:
......
......@@ -93,16 +93,12 @@ LURETTE_SOURCES=\
$(OBJDIR)/fair_bddd.ml \
$(OBJDIR)/solver.mli \
$(OBJDIR)/solver.ml \
$(OBJDIR)/show_env.mli \
$(OBJDIR)/show_env.ml \
$(OBJDIR)/prog.ml \
$(OBJDIR)/prog.mli \
$(OBJDIR)/fGen.mli \
$(OBJDIR)/fGen.ml \
$(OBJDIR)/lucFGen.mli \
$(OBJDIR)/lucFGen.ml \
$(OBJDIR)/lucParse.mli \
$(OBJDIR)/lucParse.ml \
$(OBJDIR)/lucky.mli \
$(OBJDIR)/lucky.ml \
$(OBJDIR)/rif.mli \
......@@ -152,6 +148,10 @@ SOURCES=\
$(OBJDIR)/autoGen.mli \
$(OBJDIR)/auto2Lucky.ml \
$(OBJDIR)/auto2Lucky.mli \
$(OBJDIR)/show_env.ml \
$(OBJDIR)/show_env.mli \
$(OBJDIR)/lucParse.ml \
$(OBJDIR)/lucParse.mli \
$(OBJDIR)/lutProg.ml \
$(OBJDIR)/lutProg.mli \
$(OBJDIR)/lucProg.ml \
......
......@@ -405,41 +405,48 @@ let check_node
Returns CheckEnv.t,
if libs is non empty, checks external refs
*)
let check_pack_res = ref None
(* Make sure it is done once (Indeed, because of side effects, it won't
work if called twice) *)
let check_pack
(libs: string list option)
(p : Syntaxe.package) = (
(* on checke dans l'ordre de dclaration,
en dmarrant avec Predef.lutin_env
let env = CheckEnv.create () in
*)
let env0 = Predef.lutin_env in
let env = match libs with
| None -> env0
| Some ll -> CheckEnv.add_libs env0 ll
in
let check_def_item = ( function
LetDef s -> (
let m = (Hashtbl.find p.pck_lettab s.it) in
let tres = check_let env m in
let _ = CheckEnv.add_let env m tres m.lti_ident in (
)
) |
ExternDef x -> (
let m = (Hashtbl.find p.pck_lettab x.it) in
let tres = check_extern env m in
let _ = CheckEnv.add_extern env m tres m.lti_ident in (
)
) |
NodeDef s -> (
let n = (Hashtbl.find p.pck_nodetab s.it) in
check_node env n ;
) |
ExceptDef s -> (
(* quivalent une constante
abstraite GLOBALE de type except *)
let _ = CheckEnv.add_global_cst env s (CkTypeEff.except) in ()
)
) in
List.iter check_def_item p.pck_deflist ;
env
)
(libs: string list option)
(p : Syntaxe.package) = (
(* on checke dans l'ordre de dclaration,
en dmarrant avec Predef.lutin_env
let env = CheckEnv.create () in
*)
match !check_pack_res with
| Some res -> res
| None ->
let env0 = Predef.lutin_env in
let env = match libs with
| None -> env0
| Some ll -> CheckEnv.add_libs env0 ll
in
let check_def_item =
function
LetDef s -> (
let m = (Hashtbl.find p.pck_lettab s.it) in
let tres = check_let env m in
ignore (CheckEnv.add_let env m tres m.lti_ident)
)
| ExternDef x -> (
let m = (Hashtbl.find p.pck_lettab x.it) in
let tres = check_extern env m in
ignore (CheckEnv.add_extern env m tres m.lti_ident)
)
| NodeDef s -> (
let n = (Hashtbl.find p.pck_nodetab s.it) in
ignore (check_node env n)
)
| ExceptDef s -> (
(* quivalent une constante
abstraite GLOBALE de type except *)
ignore (CheckEnv.add_global_cst env s (CkTypeEff.except))
)
in
List.iter check_def_item p.pck_deflist ;
check_pack_res := Some env;
env
)
......@@ -117,26 +117,15 @@ let dump_prog p = (
)
(* simu *)
let rec to_simu () = (
let infile = MainArg.infile() in
let mnode = MainArg.main_node () in
if (infile = "") then (
if MainArg.see_all_options () then
(MainArg.full_usage stderr; exit 0)
else
(
MainArg.usage stderr;
raise (Global_error "no input file")
)
) else (
(* Parse and build the internal structure *)
Verbose.put "#Main.to_simu\n";
let rec to_simu infile mnode = (
(* Parse and build the internal structure *)
Verbose.put "#Main.to_simu\n";
Verbose.put ~level:3 "#-begin LutProg.make\n";
let (zelutprog, zeprog) = LutProg.make ~libs:(MainArg.libs()) infile mnode in
Verbose.put ~level:3 "#-end LutProg.make\n";
Verbose.put ~level:3 "#-begin LutProg.make\n";
let (zelutprog, zeprog) = LutProg.make ~libs:(MainArg.libs()) infile mnode in
Verbose.put ~level:3 "#-end LutProg.make\n";
(* zelutprog is necessary for extracting initial data store *)
(* zelutprog is necessary for extracting initial data store *)
let state0 = LutProg.get_init_state zelutprog zeprog in
Verbose.put ~level:3 "### BEGIN state0:\n";
......@@ -181,8 +170,8 @@ let rec to_simu () = (
(* first main_loop : no pre context *)
main_loop ~boot:(MainArg.boot()) 1 next_state;
flush stdout
)
)
)
and main_loop ?(boot=false) t state = (
Verbose.exe ( fun () ->
let csnme = (Prog.ctrl_state_to_string_long state.Prog.d.Prog.ctrl_state) in
......@@ -298,65 +287,79 @@ Utils.time_R "main_loop";
let main () = (
try (
MainArg.parse () ;
if (MainArg.simu ()) then to_simu ()
else if (Luc2c.option.Luc2c.gen_mode <> Luc2c.Nop) then
(
Luc2c.option.Luc2c.output <- MainArg.outfile () ;
Luc2c.option.Luc2c.seed <- (Some(MainArg.seed ()));
Luc2c.option.Luc2c.step_mode <- (
match (MainArg.draw_mode ()) with
| Lucky.StepInside -> Luc2c.Inside
| Lucky.StepEdges -> Luc2c.Edges
| Lucky.StepVertices -> Luc2c.Vertices)
;
Luc2c.option.Luc2c.env <- ([MainArg.infile()]);
Luc2c.main ()
)
else (
let inchannel = if (MainArg.infile() = "") then (
stdin
) else (
open_in(MainArg.infile())
) in
if MainArg.test_lex() then (
Parsers.lexemize_lut inchannel
) else (
(* analyse syntaxique *)
let mainprg = Parsers.read_lut inchannel in
if (MainArg.test_parse()) then (
SyntaxeDump.dump_pack mainprg; raise Stop
) else ();
(* type/binding check *)
let tlenv = CheckType.check_pack (MainArg.libs ()) mainprg in
if (MainArg.test_check()) then (
CheckEnv.dbg_dump tlenv; raise Stop
) else ();
try (
MainArg.parse () ;
let infile = MainArg.infile() in
let mnode = MainArg.main_node () in
let inchannel () =
if (infile <> "") then
open_in infile
else
if MainArg.see_all_options () then
(MainArg.full_usage stderr; exit 0)
else
(
MainArg.usage stderr;
raise (Global_error "no input file")
)
in
let mainprg = Parsers.read_lut (inchannel()) in
let tlenv = CheckType.check_pack (MainArg.libs ()) mainprg in
let _ =
if MainArg.test_lex() then (
Parsers.lexemize_lut (inchannel())
) else (
(* analyse syntaxique *)
if (MainArg.test_parse()) then (
SyntaxeDump.dump_pack mainprg;
raise Stop
);
if (MainArg.test_check()) then (
CheckEnv.dbg_dump tlenv;
raise Stop
);
);
in
match MainArg.gen_mode () with
| Simu -> to_simu infile mnode
| Cstubs -> (
Luc2c.option.Luc2c.output <- MainArg.outfile () ;
Luc2c.option.Luc2c.seed <- (Some(MainArg.seed ()));
Luc2c.option.Luc2c.step_mode <- (
match (MainArg.draw_mode ()) with
| Lucky.StepInside -> Luc2c.Inside
| Lucky.StepEdges -> Luc2c.Edges
| Lucky.StepVertices -> Luc2c.Vertices)
;
Luc2c.option.Luc2c.env <- ([MainArg.infile()]);
Luc2c.main ()
)
| GenLuc -> (
(* type/binding check *)
(**** DEFAUT -> simu ****)
to_luc mainprg tlenv
)
)
) with
| Stop -> ( (* OK *))
| Sys_error(s) -> (
prerr_string (s^"\n") ; exit 1
)
| Global_error s -> (
print_global_error s ; exit 1
)
| Parsing.Parse_error -> (
print_compile_error (Lexeme.last_made ()) "syntax error";
exit 1
)
| Compile_error(lxm,msg) -> (
print_compile_error lxm msg ; exit 1
)
| Internal_error (fname,msg) -> (
print_internal_error fname msg ; exit 1
)
| End_of_file -> (
)
) with
| Stop -> ( (* OK *))
| Sys_error(s) -> (
prerr_string (s^"\n") ; exit 1
)
| Global_error s -> (
print_global_error s ; exit 1
)
| Parsing.Parse_error -> (
print_compile_error (Lexeme.last_made ()) "syntax error";
exit 1
)
| Compile_error(lxm,msg) -> (
print_compile_error lxm msg ; exit 1
)
| Internal_error (fname,msg) -> (
print_internal_error fname msg ; exit 1
)
| End_of_file -> (
)
)
let _ = (
......
......@@ -48,9 +48,10 @@ let test_auto () = !_test_auto
let _libs : string list ref = ref []
let libs () = match !_libs with [] -> None | l -> Some l
(* simulation *)
let _simu = ref true
let simu () = !_simu
(* simulation*)
type gen_mode = Simu | GenLuc | Cstubs
let _gen_mode = ref Simu
let gen_mode () = !_gen_mode
let _boot = ref false
let boot () = !_boot
......@@ -199,7 +200,7 @@ let mkoptab () = (
(* ---- COMPILE OPTIONS *)
mkopt
["-luc"]
(Arg.Unit(function _ -> _simu := false ; ()))
(Arg.Unit(function _ -> _gen_mode := GenLuc ; ()))
["generate a lucky program"]
;
mkopt
......@@ -279,11 +280,18 @@ let mkoptab () = (
];
(* ---- luc2c OPTIONS *)
mkopt
["--2c-4c"]
(Arg.Unit(fun () ->
_gen_mode := Cstubs;
Luc2c.option.Luc2c.gen_mode <- Luc2c.Nop))
["generate C code to be called from C "];
mkopt
["--2c-4lustre"]
~arg:" <string>"
(Arg.String(fun str ->
_simu := false ;
_gen_mode := Cstubs;
Luc2c.option.Luc2c.gen_mode <- Luc2c.Lustre;
Luc2c.option.Luc2c.calling_module_name <- str))
["generate C code to be called from Lustre V4 "];
......@@ -292,7 +300,7 @@ let mkoptab () = (
["--2c-4scade"]
~arg:" <string>"
(Arg.String(fun str ->
_simu := false ;
_gen_mode := Cstubs;
Luc2c.option.Luc2c.gen_mode <- Luc2c.Scade;
Luc2c.option.Luc2c.calling_module_name <- str))
["generate C code to be called from Scade "];
......@@ -300,7 +308,7 @@ let mkoptab () = (
mkopt
["--2c-4luciole"]
(Arg.Unit(fun _ ->
_simu := false ;
_gen_mode := Cstubs;
Luc2c.option.Luc2c.gen_mode <- Luc2c.Luciole))
["generate a C file containing the necessary stuff to call the lucky file with luciole"];
......@@ -308,7 +316,7 @@ let mkoptab () = (
["--2c-4alice"]
~arg:" <string>"
(Arg.String(fun str ->
_simu := false ;
_gen_mode := Cstubs;
Luc2c.option.Luc2c.gen_mode <- Luc2c.Alice;
Luc2c.option.Luc2c.calling_module_name <- str))
["generate C and C++ code to be called from Alice"];
......
......@@ -22,7 +22,13 @@ val main_node : unit -> string
(* Simulation *)
val max_steps : unit -> int option
val simu : unit -> bool
type gen_mode =
Simu (* Simulate the Lutin file *)
| GenLuc (* Generate a lucky file *)
| Cstubs (* Generate C stubs files *)
val gen_mode : unit -> gen_mode
val boot : unit -> bool
val seed : unit -> int
......
......@@ -13,25 +13,32 @@ open Syntaxe;;
open Format;;
let lexemize_lut (inchannel) = (
let lexbuf = Lexing.from_channel inchannel in
let tk = ref (LutLexer.lexer lexbuf) in (
while !tk <> TK_EOF do
match (token_code !tk) with
( co , lxm) -> (
printf "line %3d col %2d to %2d : %15s = \"%s\"\n"
lxm.line lxm.cstart lxm.cend co lxm.str ;
);
tk := (LutLexer.lexer lexbuf)
done
)
let lexbuf = Lexing.from_channel inchannel in
let tk = ref (LutLexer.lexer lexbuf) in (
while !tk <> TK_EOF do
match (token_code !tk) with
( co , lxm) -> (
printf "line %3d col %2d to %2d : %15s = \"%s\"\n"
lxm.line lxm.cstart lxm.cend co lxm.str ;
);
tk := (LutLexer.lexer lexbuf)
done
)
)
let read_lut_res = ref None (* make sure this is done once *)
let read_lut (inchannel) = (
let lexbuf = Lexing.from_channel inchannel in
try (
LutParser.lutFileTop LutLexer.lexer lexbuf ;
) with Parse_error -> (
print_compile_error (Lexeme.last_made ()) "syntax error";
exit 1
)
match !read_lut_res with
| Some res -> res
| None ->
let lexbuf = Lexing.from_channel inchannel in
try (
let res = LutParser.lutFileTop LutLexer.lexer lexbuf in
read_lut_res := Some res;
res
)
with Parse_error -> (
print_compile_error (Lexeme.last_made ()) "syntax error";
exit 1
)
)
......@@ -629,26 +629,27 @@ BIN_VERIMAG_INSTALL_DIR= /usr/local/tools/lustre-misc/lurette/bin/
LIB_VERIMAG_INSTALL_DIR= /usr/local/tools/lustre-misc/lurette/lib/
INC_VERIMAG_INSTALL_DIR= /usr/local/tools/lustre-misc/lurette/include/
cp-verimag:
cp Gnuplot-rif/gnuplot-rif$(EXE) $(BIN_VERIMAG_INSTALL_DIR) ; \
cp misc/gnuplot-socket$(EXE) $(BIN_VERIMAG_INSTALL_DIR) ; \
cp misc/call-via-socket$(EXE) $(BIN_VERIMAG_INSTALL_DIR) ; \
cp common/gen_stubs_exe$(EXE) $(BIN_VERIMAG_INSTALL_DIR) ; \
cp Lucky/gen_fake_lucky$(EXE) $(BIN_VERIMAG_INSTALL_DIR) ; \
cp Lucky/lucky$(EXE) $(BIN_VERIMAG_INSTALL_DIR) ; \
cp Lucky/show_luc$(EXE) $(BIN_VERIMAG_INSTALL_DIR) ; \
cp Lucky/luc2c$(EXE) $(BIN_VERIMAG_INSTALL_DIR) ; \
cp Lucky/luc2luciole$(EXE) $(BIN_VERIMAG_INSTALL_DIR) ; \
cp Lurettetop/lurettetop_exe$(EXE) $(BIN_VERIMAG_INSTALL_DIR) ; \
cp common/liblurette_nc.a $(LIB_VERIMAG_INSTALL_DIR) ;\
cp common/liblucky_nc.a $(LIB_VERIMAG_INSTALL_DIR) ;\
cp $(OBJDIR)/*lurette_ml_exec*a $(LIB_VERIMAG_INSTALL_DIR) ;\
cp $(OBJDIR)/*.cmi $(LIB_VERIMAG_INSTALL_DIR) ;\
cp $(PRE_RELEASE_DIR)/bin/gnuplot-rif$(EXE) $(BIN_VERIMAG_INSTALL_DIR) ; \
cp $(PRE_RELEASE_DIR)/bin/gnuplot-socket$(EXE) $(BIN_VERIMAG_INSTALL_DIR) ; \
cp $(PRE_RELEASE_DIR)/bin/call-via-socket$(EXE) $(BIN_VERIMAG_INSTALL_DIR) ; \
cp $(PRE_RELEASE_DIR)/bin/gen_stubs_exe$(EXE) $(BIN_VERIMAG_INSTALL_DIR) ; \
cp $(PRE_RELEASE_DIR)/bin/gen_fake_lucky$(EXE) $(BIN_VERIMAG_INSTALL_DIR) ; \
cp $(PRE_RELEASE_DIR)/bin/lucky$(EXE) $(BIN_VERIMAG_INSTALL_DIR) ; \
cp $(PRE_RELEASE_DIR)/bin/lutin$(EXE) $(BIN_VERIMAG_INSTALL_DIR) ; \
cp $(PRE_RELEASE_DIR)/bin/show_luc$(EXE) $(BIN_VERIMAG_INSTALL_DIR) ; \
cp $(PRE_RELEASE_DIR)/bin/luc2c$(EXE) $(BIN_VERIMAG_INSTALL_DIR) ; \
cp $(PRE_RELEASE_DIR)/bin/luc2luciole$(EXE) $(BIN_VERIMAG_INSTALL_DIR) ; \
cp $(PRE_RELEASE_DIR)/bin/lurettetop_exe$(EXE) $(BIN_VERIMAG_INSTALL_DIR) ; \
cp $(PRE_RELEASE_DIR)/lib/liblurette_nc.a $(LIB_VERIMAG_INSTALL_DIR) ;\
cp $(PRE_RELEASE_DIR)/lib/liblucky_nc.a $(LIB_VERIMAG_INSTALL_DIR) ;\
cp $(PRE_RELEASE_DIR)/lib/*lurette_ml_exec*a $(LIB_VERIMAG_INSTALL_DIR) ;\
cp $(PRE_RELEASE_DIR)/lib/*.cmi $(LIB_VERIMAG_INSTALL_DIR) ;\
cp common/lurette_exec.ml $(LIB_VERIMAG_INSTALL_DIR) ;\
cp common/sut.mli $(LIB_VERIMAG_INSTALL_DIR) ;\
cp common/oracle.mli $(LIB_VERIMAG_INSTALL_DIR) ;\
cp common/libluc4c_nc.a $(LIB_VERIMAG_INSTALL_DIR) ;\
cp $(PRE_RELEASE_DIR)/lib/libluc4c_nc.a $(LIB_VERIMAG_INSTALL_DIR) ;\
cp common/ocaml2c.h $(INC_VERIMAG_INSTALL_DIR) ;\
cp Lucky/luc4c_stubs.h $(INC_VERIMAG_INSTALL_DIR) ;\
cp Lucky/luc4c_stubs.h $(INC_VERIMAG_INSTALL_DIR)
install_assert: all_assert cp
......
......@@ -18,6 +18,7 @@ open Lexing
(* pour calculer line/col *)
let line_num = ref 1
let line_start_pos = ref 0
let new_line ( lexbuf ) = (
line_start_pos := Lexing.lexeme_end lexbuf;
......@@ -48,7 +49,6 @@ let (flagit : 'a -> t -> 'a srcflaged) =
{ it = x; src = lxm }
let dummy = { str = "dummy" ; line = 0 ; cstart = 0 ; cend = 0; chstart = 0 ; chend = 0 }
let last_lexeme = ref dummy
let make ( lexbuf ) =
......
......@@ -22,3 +22,4 @@ val dummy : t
val make : Lexing.lexbuf -> t
val last_made : unit -> t
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment