Bugs corrections

- callgraph: add idents used for instantiated nodes
- cgen : added Idents.enter_node
- cmain : removed error when simulated node does not exist (existence
of simulated node was tested for every program, comprising loaded ones)
This commit is contained in:
Gwenal Delaval 2012-08-01 17:08:58 +02:00
parent b858f0e987
commit 41fccc66fb
6 changed files with 35 additions and 10 deletions

View file

@ -123,10 +123,22 @@ struct
(** This function should be called every time we enter a node *)
let enter_node n =
(* TODO : see copy_node; same problem *)
(if not (QualEnv.mem n !node_env)
then node_env := QualEnv.add n (ref NamesSet.empty) !node_env);
used_names := QualEnv.find n !node_env
(** Copy environment of node of name [n] to new node name [n'] *)
let copy_node n n' =
(* TODO : do something smarter than create empty used names set *)
(* this happen when an object file is loaded: the used names set
of loaded nodes is not properly set *)
if not (QualEnv.mem n !node_env)
then node_env := QualEnv.add n (ref NamesSet.empty) !node_env;
assert (not (QualEnv.mem n' !node_env));
let used_names = !(QualEnv.find n !node_env) in
node_env := QualEnv.add n' (ref used_names) !node_env
(** @return a unique string for each identifier. Idents corresponding
to variables defined in the source file have the same name unless
there is a collision. *)
@ -172,5 +184,6 @@ let ident_of_name ?(reset=false) s =
let source_name id = id.source
let name id = UniqueNames.name id
let enter_node n = UniqueNames.enter_node n
let copy_node = UniqueNames.copy_node
let print_ident ff id = Format.fprintf ff "%s" (name id)

View file

@ -67,6 +67,8 @@ val is_reset : ident -> bool
(** /!\ [enter_node qualname] should be called every time we enter a node with name [qualname]. *)
val enter_node : Names.qualname -> unit
val copy_node : Names.qualname -> Names.qualname -> unit
(** Maps taking an identifier as a key. *)
module Env :
sig

View file

@ -60,7 +60,7 @@ let mk_target ?(interface=IMinils ignore) ?(load_conf = no_conf) name pt =
(** Writes a .epo file for program [p]. *)
let write_object_file p =
let filename = (Names.modul_to_string p.Minils.p_modname)^".epo" in
let filename = (String.uncapitalize (Names.modul_to_string p.Minils.p_modname)) ^".epo" in
let epoc = open_out_bin filename in
output_value epoc p;
close_out epoc;

View file

@ -27,6 +27,7 @@
(* *)
(***********************************************************************)
open Names
open Idents
open Types
open Misc
open Location
@ -129,6 +130,7 @@ struct
"_params_" params in
let new_ln =
Modules.fresh_value_in "callgraph" (n^param_string^"_") q in
Idents.copy_node ln new_ln;
nodes_names := M.add (ln, params) new_ln !nodes_names
(** Adds an instance of a node. *)

View file

@ -752,6 +752,7 @@ let cdefs_and_cdecls_of_class_def cd =
(** We keep the state of our class in a structure, holding both internal
variables and the state of other nodes. For a class named ["cname"], the
structure will be called ["cname_mem"]. *)
Idents.enter_node cd.cd_name;
let step_m = find_step_method cd in
let memory_struct_decl = mem_decl_of_class_def cd in
let out_struct_decl = out_decl_of_class_def cd in

View file

@ -364,12 +364,17 @@ let mk_main name p =
let classes = program_classes p in
let n_names = !Compiler_options.assert_nodes in
let find_class n =
try List.find (fun cd -> cd.cd_name.name = n) classes
with Not_found ->
Format.eprintf "Unknown node %s.@." n;
exit 1 in
List.find (fun cd -> cd.cd_name.name = n) classes
in
let a_classes = List.map find_class n_names in
let a_classes =
List.fold_left
(fun acc n ->
try
find_class n :: acc
with Not_found -> acc)
[]
n_names in
let (var_l, res_l, step_l) =
let add cd (var_l, res_l, step_l) =
@ -378,10 +383,12 @@ let mk_main name p =
List.fold_right add a_classes ([], [], []) in
let n = !Compiler_options.simulation_node in
let (mem, nvar_l, res, nstep_l) = main_def_of_class_def (find_class n) in
let defs = match mem with None -> [] | Some m -> [m] in
let (var_l, res_l, step_l) =
(nvar_l @ var_l, res @ res_l, nstep_l @ step_l) in
let (defs, var_l, res_l, step_l) =
try
let (mem, nvar_l, res, nstep_l) = main_def_of_class_def (find_class n) in
let defs = match mem with None -> [] | Some m -> [m] in
(defs, nvar_l @ var_l, res @ res_l, nstep_l @ step_l)
with Not_found -> ([],var_l,res_l,step_l) in
[("_main.c", Csource (defs @ [main_skel var_l res_l step_l]));
("_main.h", Cheader ([name], []))];