PIPS
initial.c File Reference
#include <stdio.h>
#include <string.h>
#include "genC.h"
#include "linear.h"
#include "ri.h"
#include "effects.h"
#include "ri-util.h"
#include "effects-util.h"
#include "database.h"
#include "pipsdbm.h"
#include "resources.h"
#include "misc.h"
#include "effects-generic.h"
#include "effects-simple.h"
#include "prettyprint.h"
#include "transformer.h"
#include "semantics.h"
+ Include dependency graph for initial.c:

Go to the source code of this file.

Macros

#define pred_debug(level, msg, trans)    ifdebug(level) { pips_debug(level, msg); dump_transformer(trans);}
 

Functions

bool initial_precondition (string name)
 Compute an initial transformer. More...
 
static void intersect (transformer t1, transformer t2)
 returns t1 inter= t2; More...
 
bool program_precondition (const string name)
 Compute the union of all initial preconditions. More...
 
bool program_postcondition (const string name)
 The program correctness postcondition cannot be infered. More...
 
bool print_initial_precondition (const string name)
 
bool print_program_precondition (const string name)
 

Macro Definition Documentation

◆ pred_debug

#define pred_debug (   level,
  msg,
  trans 
)     ifdebug(level) { pips_debug(level, msg); dump_transformer(trans);}

Definition at line 129 of file initial.c.

Function Documentation

◆ initial_precondition()

bool initial_precondition ( string  name)

Compute an initial transformer.

initial.c

Filter out local and unused variables from the local precondition? No, because it is not possible to guess what is used or unused at the program level. Filtering is postponed to program_precondition().

Parameters
nameame

Definition at line 75 of file initial.c.

76 {
78  transformer prec;
79 
80  debug_on("SEMANTICS_DEBUG_LEVEL");
81 
84  db_get_memory_resource(DBR_CODE, name, true));
87  db_get_memory_resource(DBR_CUMULATED_EFFECTS, name, true));
89  db_get_memory_resource(DBR_PROPER_EFFECTS, name, true));
91 
93 
94  ifdebug(1)
95  pips_assert("consistent initial precondition before filtering",
97 
98  /* Filter out local and unused variables from the local precondition?
99  * No, because it is not possible to guess what is used or unused at
100  * the program level. Filtering is postponed to program_precondition().
101  */
102 
103  DB_PUT_MEMORY_RESOURCE(DBR_INITIAL_PRECONDITION, strdup(name), (char*) prec);
104 
110 
112 
113  debug_off();
114  return true;
115 }
bool transformer_consistency_p(transformer t)
FI: I do not know if this procedure should always return or fail when an inconsistency is found.
Definition: basic.c:612
void reset_proper_rw_effects(void)
void set_proper_rw_effects(statement_effects)
void set_cumulated_rw_effects(statement_effects)
void reset_cumulated_rw_effects(void)
void reset_current_module_entity(void)
Reset the current module entity.
Definition: static.c:97
void reset_current_module_statement(void)
Reset the current module statement.
Definition: static.c:221
statement set_current_module_statement(statement)
Set the current module statement.
Definition: static.c:165
entity set_current_module_entity(entity)
static.c
Definition: static.c:66
string db_get_memory_resource(const char *rname, const char *oname, bool pure)
Return the pointer to the resource, whatever it is.
Definition: database.c:755
#define DB_PUT_MEMORY_RESOURCE(res_name, own_name, res_val)
conform to old interface.
Definition: pipsdbm-local.h:66
#define debug_on(env)
Definition: misc-local.h:157
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172
#define debug_off()
Definition: misc-local.h:160
#define true
Definition: newgen_types.h:81
static char * module
Definition: pips.c:74
entity module_name_to_entity(const char *mn)
This is an alias for local_name_to_top_level_entity.
Definition: entity.c:1479
void free_statement_global_stack(void)
Definition: static.c:358
void make_statement_global_stack(void)
Definition: static.c:318
transformer all_data_to_precondition(entity m)
any variable is included.
char * strdup()
void module_to_value_mappings(entity m)
void module_to_value_mappings(entity m): build hash tables between variables and values (old,...
Definition: mappings.c:624
return(s1)
#define ifdebug(n)
Definition: sg.c:47
void free_value_mappings(void)
Normal call to free the mappings.
Definition: value.c:1212

References all_data_to_precondition(), db_get_memory_resource(), DB_PUT_MEMORY_RESOURCE, debug_off, debug_on, free_statement_global_stack(), free_value_mappings(), ifdebug, make_statement_global_stack(), module, module_name_to_entity(), module_to_value_mappings(), pips_assert, reset_cumulated_rw_effects(), reset_current_module_entity(), reset_current_module_statement(), reset_proper_rw_effects(), set_cumulated_rw_effects(), set_current_module_entity(), set_current_module_statement(), set_proper_rw_effects(), strdup(), and transformer_consistency_p().

+ Here is the call graph for this function:

◆ intersect()

static void intersect ( transformer  t1,
transformer  t2 
)
static

returns t1 inter= t2;

Definition at line 120 of file initial.c.

123 {
127 }
#define transformer_relation(x)
Definition: ri.h:2873
#define predicate_system(x)
Definition: ri.h:2069
Psysteme sc_append(Psysteme s1, Psysteme s2)
Psysteme sc_append(Psysteme s1, Psysteme s2): calcul de l'intersection des polyedres definis par s1 e...

References predicate_system, sc_append(), and transformer_relation.

Referenced by program_precondition().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ print_initial_precondition()

bool print_initial_precondition ( const string  name)
Parameters
nameame

Definition at line 261 of file initial.c.

262 {
263  bool ok;
265  transformer t = (transformer)
266  db_get_memory_resource(DBR_INITIAL_PRECONDITION, name, true);
267 
268  debug_on("SEMANTICS_DEBUG_LEVEL");
269 
272  db_get_memory_resource(DBR_CODE, name, true));
274  db_get_memory_resource(DBR_CUMULATED_EFFECTS,
275  name,
276  true));
278 
279  ok = make_text_resource_and_free(name, DBR_PRINTED_FILE, ".ipred",
280  text_transformer(t));
281 
285 
287 
288  debug_off();
289 
290  return ok;
291 }
bool make_text_resource_and_free(const char *, const char *, const char *, text)
Definition: print.c:82
struct _newgen_struct_transformer_ * transformer
Definition: ri.h:431
text text_transformer(transformer tran)
text text_transformer(transformer tran) input : a transformer representing a transformer or a precond...
Definition: prettyprint.c:464
static bool ok

References db_get_memory_resource(), debug_off, debug_on, free_value_mappings(), make_text_resource_and_free(), module, module_name_to_entity(), module_to_value_mappings(), ok, reset_cumulated_rw_effects(), reset_current_module_entity(), reset_current_module_statement(), set_cumulated_rw_effects(), set_current_module_entity(), set_current_module_statement(), and text_transformer().

+ Here is the call graph for this function:

◆ print_program_precondition()

bool print_program_precondition ( const string  name)

A small function that would require pipsdbm and ri-util

Parameters
nameame

Definition at line 293 of file initial.c.

294 {
295  bool ok;
296  transformer t = (transformer)
297  db_get_memory_resource(DBR_PROGRAM_PRECONDITION, "", true);
298 
299  /* A small function that would require pipsdbm and ri-util*/
300  const string mn = get_main_entity_name();
302  free(mn);
303 
304  debug_on("SEMANTICS_DEBUG_LEVEL");
305  pips_debug(1, "for \"%s\"\n", name);
306 
309  db_get_memory_resource(DBR_CODE,
311  true));
313  db_get_memory_resource(DBR_CUMULATED_EFFECTS,
315  true));
317 
318  ok = make_text_resource_and_free(name, DBR_PRINTED_FILE, ".pipred",
319  text_transformer(t));
320 
324 
326 
327  debug_off();
328 
329  return ok;
330 }
void free(void *)
#define pips_debug
these macros use the GNU extensions that allow variadic macros, including with an empty list.
Definition: misc-local.h:145
string get_main_entity_name(void)
Return the local name of the main module if it is available, or the local name of any module by defau...
Definition: util.c:63
const char * module_local_name(entity e)
Returns the module local user name.
Definition: entity.c:582

References db_get_memory_resource(), debug_off, debug_on, free(), free_value_mappings(), get_main_entity_name(), make_text_resource_and_free(), module_local_name(), module_name_to_entity(), module_to_value_mappings(), ok, pips_debug, reset_cumulated_rw_effects(), reset_current_module_entity(), reset_current_module_statement(), set_cumulated_rw_effects(), set_current_module_entity(), set_current_module_statement(), and text_transformer().

+ Here is the call graph for this function:

◆ program_postcondition()

bool program_postcondition ( const string  name)

The program correctness postcondition cannot be infered.

It should be provided by the user.

A small function that would require pipsdbm and ri-util

Parameters
nameame

Definition at line 233 of file initial.c.

234 {
236 
237  /* A small function that would require pipsdbm and ri-util*/
238  const string mn = get_main_entity_name();
239  entity the_main = module_name_to_entity(mn);
240  free(mn);
241 
242  debug_on("SEMANTICS_DEBUG_LEVEL");
243  pips_debug(1, "considering program \"%s\" with main \"%s\"\n", name,
244  module_local_name(the_main));
245 
246  pred_debug(1, "assumed program postcondition:\n", post);
247 
248  ifdebug(1)
249  pips_assert("consistent program postcondition",
251 
252  DB_PUT_MEMORY_RESOURCE(DBR_PROGRAM_POSTCONDITION, "", post);
253 
254  debug_off();
255  return true;
256 }
transformer transformer_identity()
Allocate an identity transformer.
Definition: basic.c:110
#define pred_debug(level, msg, trans)
Definition: initial.c:129

References DB_PUT_MEMORY_RESOURCE, debug_off, debug_on, free(), get_main_entity_name(), ifdebug, module_local_name(), module_name_to_entity(), pips_assert, pips_debug, pred_debug, transformer_consistency_p(), and transformer_identity().

+ Here is the call graph for this function:

◆ program_precondition()

bool program_precondition ( const string  name)

Compute the union of all initial preconditions.

A small function that would require pipsdbm and ri-util

e_inter = effects_to_list(get_cumulated_rw_effects(get_current_module_statement()));

Unavoidable pitfall: initializations in uncalled modules may be taken into account. It all depends on the "create" command.

no dup & false => core

modifies tm!

tm = transformer_normalize(tm, 2);

Parameters
nameame

Definition at line 134 of file initial.c.

135 {
137 
138  /* A small function that would require pipsdbm and ri-util*/
139  const string mn = get_main_entity_name();
140  entity the_main = module_name_to_entity(mn);
141 
142  pips_assert("main was found", the_main!=entity_undefined);
143 
144  free(mn);
145 
146  int i, nmodules;
147  gen_array_t modules;
148  list e_inter = NIL;
149 
150  debug_on("SEMANTICS_DEBUG_LEVEL");
151  pips_debug(1, "considering program \"%s\" with main \"%s\"\n", name,
152  module_local_name(the_main));
153 
154  set_current_module_entity(the_main);
156  db_get_memory_resource(DBR_CODE,
157  module_local_name(the_main),
158  true));
161  db_get_memory_resource(DBR_CUMULATED_EFFECTS,
162  module_local_name(the_main),
163  true));
165  db_get_memory_resource(DBR_PROPER_EFFECTS,
166  module_local_name(the_main),
167  true));
168 
169  /* e_inter = effects_to_list(get_cumulated_rw_effects(get_current_module_statement())); */
170 
171  e_inter = effects_to_list( (effects)
172  db_get_memory_resource(DBR_SUMMARY_EFFECTS,
173  module_local_name(the_main),
174  true));
175 
176  module_to_value_mappings(the_main);
177 
178  /* Unavoidable pitfall: initializations in uncalled modules may be
179  * taken into account. It all depends on the "create" command.
180  */
181  modules = db_get_module_list();
182  nmodules = gen_array_nitems(modules);
183  pips_assert("some modules in the program", nmodules>0);
184 
185  for(i=0; i<nmodules; i++) {
186  transformer tm;
187  string mname = gen_array_item(modules, i);
188  pips_debug(1, "considering module %s\n", mname);
189 
190  tm = transformer_dup((transformer) /* no dup & false => core */
191  db_get_memory_resource(DBR_INITIAL_PRECONDITION,
192  mname, true));
193 
194  pred_debug(3, "current: t =\n", t);
195  pred_debug(2, "to be added: tm =\n", tm);
196  translate_global_values(the_main, tm); /* modifies tm! */
197  pred_debug(3, "to be added after translation:\n", tm);
198  tm = transformer_intra_to_inter(tm, e_inter);
199  /* tm = transformer_normalize(tm, 2); */
200  if(!transformer_consistency_p(tm)) {
201  (void) print_transformer(tm);
202  pips_internal_error("Non-consistent filtered initial precondition");
203  }
204  pred_debug(3, "to be added after filtering:\n", tm);
205 
206  intersect(t, tm);
207  free_transformer(tm);
208  }
209 
210  pred_debug(1, "resulting program precondition:\n", t);
211 
212  ifdebug(1)
213  pips_assert("consistent program precondition",
215 
216  DB_PUT_MEMORY_RESOURCE(DBR_PROGRAM_PRECONDITION, "", t);
217 
223 
225  gen_array_full_free(modules);
226 
227  debug_off();
228  return true;
229 }
void free_transformer(transformer p)
Definition: ri.c:2616
size_t gen_array_nitems(const gen_array_t a)
Definition: array.c:131
void gen_array_full_free(gen_array_t a)
Definition: array.c:77
void * gen_array_item(const gen_array_t a, size_t i)
Definition: array.c:143
transformer transformer_dup(transformer t_in)
transformer package - basic routines
Definition: basic.c:49
list effects_to_list(effects)
Definition: effects.c:209
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
gen_array_t db_get_module_list(void)
Get an array of all the modules (functions, procedures and compilation units) of a workspace.
Definition: database.c:1266
static void intersect(transformer t1, transformer t2)
returns t1 inter= t2;
Definition: initial.c:120
#define pips_internal_error
Definition: misc-local.h:149
#define print_transformer(t)
Definition: print.c:357
#define entity_undefined
Definition: ri.h:2761
transformer transformer_intra_to_inter(transformer tf, list le)
void translate_global_values(entity m, transformer tf)
The structure used to build lists in NewGen.
Definition: newgen_list.h:41

References db_get_memory_resource(), db_get_module_list(), DB_PUT_MEMORY_RESOURCE, debug_off, debug_on, effects_to_list(), entity_undefined, free(), free_statement_global_stack(), free_transformer(), free_value_mappings(), gen_array_full_free(), gen_array_item(), gen_array_nitems(), get_main_entity_name(), ifdebug, intersect(), make_statement_global_stack(), module_local_name(), module_name_to_entity(), module_to_value_mappings(), NIL, pips_assert, pips_debug, pips_internal_error, pred_debug, print_transformer, reset_cumulated_rw_effects(), reset_current_module_entity(), reset_current_module_statement(), reset_proper_rw_effects(), set_cumulated_rw_effects(), set_current_module_entity(), set_current_module_statement(), set_proper_rw_effects(), transformer_consistency_p(), transformer_dup(), transformer_identity(), transformer_intra_to_inter(), and translate_global_values().

+ Here is the call graph for this function: