Skip to content
Snippets Groups Projects
Commit bde99c3f authored by THIRIOUX Xavier's avatar THIRIOUX Xavier
Browse files

This is the first merge that does compile. Not tested yet.

parent 40d33d55
No related branches found
No related tags found
No related merge requests found
...@@ -7,6 +7,7 @@ AC_SUBST(VERSION_CODENAME, "Xia/Xiang-dev") ...@@ -7,6 +7,7 @@ AC_SUBST(VERSION_CODENAME, "Xia/Xiang-dev")
#AC_SUBST(VERSION_CODENAME, "Xia/Shao Kang") #AC_SUBST(VERSION_CODENAME, "Xia/Shao Kang")
AC_CONFIG_SRCDIR([src/main_lustre_compiler.ml]) AC_CONFIG_SRCDIR([src/main_lustre_compiler.ml])
AC_CONFIG_SRCDIR([src/main_lustre_testgen.ml])
# default prefix is /usr/local # default prefix is /usr/local
AC_PREFIX_DEFAULT(/usr/local) AC_PREFIX_DEFAULT(/usr/local)
......
...@@ -7,6 +7,10 @@ ...@@ -7,6 +7,10 @@
"main_lustre_compiler.native": use_str "main_lustre_compiler.native": use_str
"main_lustre_compiler.native": use_unix "main_lustre_compiler.native": use_unix
"main_lustre_compiler.native": use_nums "main_lustre_compiler.native": use_nums
"main_lustre_testgen.native": package(ocamlgraph)
"main_lustre_testgen.native": use_str
"main_lustre_testgen.native": use_unix
"main_lustre_testgen.native": use_nums
<*.ml{,i}>: package(ocamlgraph) <*.ml{,i}>: package(ocamlgraph)
<*.ml{,i}>: use_str <*.ml{,i}>: use_str
<*.ml{,i}>: use_unix <*.ml{,i}>: use_unix
...@@ -52,7 +52,7 @@ end ...@@ -52,7 +52,7 @@ end
let load_file f = let load_file f =
let ic = open_in f in let ic = open_in f in
let n = in_channel_length ic in let n = in_channel_length ic in
let s = String.create n in let s = Bytes.create n in
really_input ic s 0 n; really_input ic s 0 n;
close_in ic; close_in ic;
(s) (s)
......
...@@ -59,11 +59,6 @@ let stage1 prog dirname basename = ...@@ -59,11 +59,6 @@ let stage1 prog dirname basename =
(* Creating destination directory if needed *) (* Creating destination directory if needed *)
create_dest_dir (); create_dest_dir ();
(* Compatibility with Lusi *)
(* Checking the existence of a lusi (Lustre Interface file) *)
let extension = ".lusi" in
compile_source_to_header prog computed_types_env computed_clocks_env dirname basename extension;
Typing.uneval_prog_generics prog; Typing.uneval_prog_generics prog;
Clock_calculus.uneval_prog_generics prog; Clock_calculus.uneval_prog_generics prog;
......
open LustreSpec
open Corelang open Corelang
open Log open Log
open Format open Format
...@@ -103,12 +104,12 @@ let rec compute_records_expr expr = ...@@ -103,12 +104,12 @@ let rec compute_records_expr expr =
let compute_records_eq eq = compute_records_expr eq.eq_rhs let compute_records_eq eq = compute_records_expr eq.eq_rhs
let compute_records_node nd = let compute_records_node nd =
merge_records (List.map compute_records_eq nd.node_eqs) merge_records (List.map compute_records_eq (get_node_eqs nd))
let compute_records_top_decl td = let compute_records_top_decl td =
match td.top_decl_desc with match td.top_decl_desc with
| Node nd -> compute_records_node nd | Node nd -> compute_records_node nd
| Consts constsl -> merge_records (List.map (fun c -> compute_records_const_value c.const_value) constsl) | Const cst -> compute_records_const_value cst.const_value
| _ -> empty_records | _ -> empty_records
let compute_records prog = let compute_records prog =
...@@ -150,11 +151,20 @@ let rdm_mutate_int i = ...@@ -150,11 +151,20 @@ let rdm_mutate_int i =
else else
i i
let rdm_mutate_float f = let rdm_mutate_real r =
if Random.int 100 > threshold_random_float then if Random.int 100 > threshold_random_float then
Random.float 10. (* interval [0, bound] for random values *)
let bound = 10 in
(* max number of digits after comma *)
let digits = 5 in
(* number of digits after comma *)
let shift = Random.int (digits + 1) in
let eshift = 10. ** (float_of_int shift) in
let i = Random.int (1 + bound * (int_of_float eshift)) in
let f = float_of_int i /. eshift in
(Num.num_of_int i, shift, string_of_float f)
else else
f r
let rdm_mutate_op op = let rdm_mutate_op op =
match op with match op with
...@@ -174,7 +184,7 @@ let rdm_mutate_var expr = ...@@ -174,7 +184,7 @@ let rdm_mutate_var expr =
match (Types.repr expr.expr_type).Types.tdesc with match (Types.repr expr.expr_type).Types.tdesc with
| Types.Tbool -> | Types.Tbool ->
(* if Random.int 100 > threshold_negate_bool_var then *) (* if Random.int 100 > threshold_negate_bool_var then *)
let new_e = mkpredef_unary_call Location.dummy_loc "not" expr in let new_e = mkpredef_call expr.expr_loc "not" [expr] in
Some (expr, new_e), new_e Some (expr, new_e), new_e
(* else *) (* else *)
(* expr *) (* expr *)
...@@ -188,9 +198,10 @@ let rdm_mutate_pre orig_expr = ...@@ -188,9 +198,10 @@ let rdm_mutate_pre orig_expr =
let rdm_mutate_const_value c = let rdm_mutate_const_value c =
match c with match c with
| Const_int i -> Const_int (rdm_mutate_int i) | Const_int i -> Const_int (rdm_mutate_int i)
| Const_real s -> Const_real s (* those are string, let's leave them *) | Const_real (n, i, s) -> let (n', i', s') = rdm_mutate_real (n, i, s) in Const_real (n', i', s')
| Const_float f -> Const_float (rdm_mutate_float f)
| Const_array _ | Const_array _
| Const_string _
| Const_struct _
| Const_tag _ -> c | Const_tag _ -> c
let rdm_mutate_const c = let rdm_mutate_const c =
...@@ -249,7 +260,6 @@ let rec rdm_mutate_expr expr = ...@@ -249,7 +260,6 @@ let rec rdm_mutate_expr expr =
else else
let mut, new_args = rdm_mutate_expr args in let mut, new_args = rdm_mutate_expr args in
mut, mk_e (Expr_appl (op_id, new_args, r)) mut, mk_e (Expr_appl (op_id, new_args, r))
(* Other constructs are kept. (* Other constructs are kept.
| Expr_fby of expr * expr | Expr_fby of expr * expr
| Expr_array of expr list | Expr_array of expr list
...@@ -260,34 +270,38 @@ let rec rdm_mutate_expr expr = ...@@ -260,34 +270,38 @@ let rec rdm_mutate_expr expr =
| Expr_uclock of expr * int | Expr_uclock of expr * int
| Expr_dclock of expr * int | Expr_dclock of expr * int
| Expr_phclock of expr * rat *) | Expr_phclock of expr * rat *)
(* | _ -> expr.expr_desc *) | _ -> None, expr
let rdm_mutate_eq eq = let rdm_mutate_eq eq =
let mutation, new_rhs = rdm_mutate_expr eq.eq_rhs in let mutation, new_rhs = rdm_mutate_expr eq.eq_rhs in
mutation, { eq with eq_rhs = new_rhs } mutation, { eq with eq_rhs = new_rhs }
let rdm_mutate_node nd = let rnd_mutate_stmt stmt =
let mutation, new_node_eqs = match stmt with
select_in_list | Eq eq -> let mut, new_eq = rdm_mutate_eq eq in
nd.node_eqs
(fun eq -> let mut, new_eq = rdm_mutate_eq eq in
report ~level:1 report ~level:1
(fun fmt -> fprintf fmt "mutation: %a becomes %a@." (fun fmt -> fprintf fmt "mutation: %a becomes %a@."
Printers.pp_node_eq eq Printers.pp_node_eq eq
Printers.pp_node_eq new_eq); Printers.pp_node_eq new_eq);
mut, new_eq ) mut, Eq new_eq
| Aut aut -> assert false
let rdm_mutate_node nd =
let mutation, new_node_stmts =
select_in_list
nd.node_stmts rnd_mutate_stmt
in in
mutation, { nd with node_eqs = new_node_eqs } mutation, { nd with node_stmts = new_node_stmts }
let rdm_mutate_top_decl td = let rdm_mutate_top_decl td =
match td.top_decl_desc with match td.top_decl_desc with
| Node nd -> | Node nd ->
let mutation, new_node = rdm_mutate_node nd in let mutation, new_node = rdm_mutate_node nd in
mutation, { td with top_decl_desc = Node new_node} mutation, { td with top_decl_desc = Node new_node}
| Consts constsl -> | Const cst ->
let mut, new_constsl = select_in_list constsl rdm_mutate_const in let mut, new_cst = rdm_mutate_const cst in
mut, { td with top_decl_desc = Consts new_constsl } mut, { td with top_decl_desc = Const new_cst }
| _ -> None, td | _ -> None, td
(* Create a single mutant with the provided random seed *) (* Create a single mutant with the provided random seed *)
...@@ -394,7 +408,7 @@ let fold_mutate_boolexpr expr = ...@@ -394,7 +408,7 @@ let fold_mutate_boolexpr expr =
match !target with match !target with
| Some (Boolexpr 0) -> ( | Some (Boolexpr 0) -> (
target := None; target := None;
mkpredef_unary_call Location.dummy_loc "not" expr mkpredef_call expr.expr_loc "not" [expr]
) )
| Some (Boolexpr n) -> | Some (Boolexpr n) ->
(target := Some (Boolexpr (n-1)); expr) (target := Some (Boolexpr (n-1)); expr)
...@@ -474,17 +488,22 @@ let rec fold_mutate_expr expr = ...@@ -474,17 +488,22 @@ let rec fold_mutate_expr expr =
let fold_mutate_eq eq = let fold_mutate_eq eq =
{ eq with eq_rhs = fold_mutate_expr eq.eq_rhs } { eq with eq_rhs = fold_mutate_expr eq.eq_rhs }
let fold_mutate_stmt stmt =
match stmt with
| Eq eq -> Eq (fold_mutate_eq eq)
| Aut aut -> assert false
let fold_mutate_node nd = let fold_mutate_node nd =
{ nd with { nd with
node_eqs = node_stmts =
List.fold_right (fun e res -> (fold_mutate_eq e)::res) nd.node_eqs []; List.fold_right (fun stmt res -> (fold_mutate_stmt stmt)::res) nd.node_stmts [];
node_id = rename_app nd.node_id node_id = rename_app nd.node_id
} }
let fold_mutate_top_decl td = let fold_mutate_top_decl td =
match td.top_decl_desc with match td.top_decl_desc with
| Node nd -> { td with top_decl_desc = Node (fold_mutate_node nd)} | Node nd -> { td with top_decl_desc = Node (fold_mutate_node nd)}
| Consts constsl -> { td with top_decl_desc = Consts (List.fold_right (fun e res -> (fold_mutate_const e)::res) constsl [])} | Const cst -> { td with top_decl_desc = Const (fold_mutate_const cst)}
| _ -> td | _ -> td
(* Create a single mutant with the provided random seed *) (* Create a single mutant with the provided random seed *)
......
...@@ -79,7 +79,7 @@ let rec compute_neg_expr cpt_pre expr = ...@@ -79,7 +79,7 @@ let rec compute_neg_expr cpt_pre expr =
(compute_neg_expr (cpt_pre+1) e) (compute_neg_expr (cpt_pre+1) e)
| Expr_appl (op_name, args, r) when List.mem op_name rel_op -> | Expr_appl (op_name, args, r) when List.mem op_name rel_op ->
[(expr, cpt_pre), mkpredef_unary_call Location.dummy_loc "not" expr] [(expr, cpt_pre), mkpredef_call expr.expr_loc "not" [expr]]
| Expr_appl (op_name, args, r) -> | Expr_appl (op_name, args, r) ->
List.map List.map
...@@ -87,7 +87,7 @@ let rec compute_neg_expr cpt_pre expr = ...@@ -87,7 +87,7 @@ let rec compute_neg_expr cpt_pre expr =
(compute_neg_expr cpt_pre args) (compute_neg_expr cpt_pre args)
| Expr_ident _ when (Types.repr expr.expr_type).Types.tdesc = Types.Tbool -> | Expr_ident _ when (Types.repr expr.expr_type).Types.tdesc = Types.Tbool ->
[(expr, cpt_pre), mkpredef_unary_call Location.dummy_loc "not" expr] [(expr, cpt_pre), mkpredef_call expr.expr_loc "not" [expr]]
| _ -> [] | _ -> []
and and
...@@ -133,9 +133,14 @@ let mcdc_node_eq eq = ...@@ -133,9 +133,14 @@ let mcdc_node_eq eq =
| _::_, Types.Ttuple tl, Expr_tuple rhs -> List.iter2 mcdc_var_def eq.eq_lhs rhs | _::_, Types.Ttuple tl, Expr_tuple rhs -> List.iter2 mcdc_var_def eq.eq_lhs rhs
| _ -> mcdc_expr 0 eq.eq_rhs | _ -> mcdc_expr 0 eq.eq_rhs
let mcdc_node_stmt stmt =
match stmt with
| Eq eq -> mcdc_node_eq eq
| Aut aut -> assert false
let mcdc_top_decl td = let mcdc_top_decl td =
match td.top_decl_desc with match td.top_decl_desc with
| Node nd -> List.iter mcdc_node_eq nd.node_eqs | Node nd -> List.iter mcdc_node_stmt nd.node_stmts
| _ -> () | _ -> ()
......
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