PIPS
flint.c
Go to the documentation of this file.
1 /*
2 
3  $Id: flint.c 23065 2016-03-02 09:05:50Z coelho $
4 
5  Copyright 1989-2016 MINES ParisTech
6 
7  This file is part of PIPS.
8 
9  PIPS is free software: you can redistribute it and/or modify it
10  under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  any later version.
13 
14  PIPS is distributed in the hope that it will be useful, but WITHOUT ANY
15  WARRANTY; without even the implied warranty of MERCHANTABILITY or
16  FITNESS FOR A PARTICULAR PURPOSE.
17 
18  See the GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with PIPS. If not, see <http://www.gnu.org/licenses/>.
22 
23 */
24 #ifdef HAVE_CONFIG_H
25  #include "pips_config.h"
26 #endif
27 /*
28  * This File contains the routine of verification launching
29  *
30  * Laurent Aniort & Fabien COELHO 1992
31  *
32  * Modified 92 08 31
33  * Author Arnauld Leservot
34  * Old Version flint.c.old
35  * Object Include this as a pips phase.
36  */
37 
38 /*************************************************************/
39 
40 #include "local.h"
41 
42 /* internal variables */
43 static FILE *flint_messages_file = NULL;
44 static bool no_message = true;
45 static int number_of_messages = 0;
47 
48 /* name of module being flinted */
50 
51 /*************************************************************/
52 /* Routine of global module verification */
53 
54 bool flinter(const string module_name)
55 {
58  statement module_stat;
59  string localfilename = NULL;
60  string filename = NULL;
61 
62  /* user_error() is not used in flint, no need for an exception handler */
63 
64  debug_on("FLINT_DEBUG_LEVEL");
65 
69  no_message = true;
70 
71  debug(1, "flinter", "flinting module %s\n", module_name);
72 
73  /* Getting parsed code of module */
74  /* the last parameter should be pure=true; the code should not be modified! */
75  module_stat = (statement)
76  db_get_memory_resource(DBR_CODE, module_name, true);
77 
78  /* Resource to trace uninitialized variables: */
80  (graph) db_get_memory_resource(DBR_CHAINS, module_name, true);
81  set_ordering_to_statement(module_stat);
82 
84  db_get_memory_resource(DBR_PROPER_EFFECTS,
86  true));
87  set_current_module_statement(module_stat);
89 
90  localfilename = db_build_file_resource_name(DBR_FLINTED_FILE,
92  ".flinted");
94  "/", localfilename, NULL));
96  (FILE *) safe_fopen(filename, "w");
97 
98  /* what is done */
99  pips_debug(3, "checking uninitialized variables\n");
101 
102  debug(3, "flinter", "checking commons\n");
103  check_commons(module); /* checking commons */
104 
105  debug(3, "flinter", "checking statements\n");
106  flint_statement(module_stat); /* checking syntax */
107 
108  if (no_message) /* final message */
110  "%s has been flinted : everything is ok.\n",
111  module_name);
112  else
114  "number of messages from flint for %s : %d\n",
115  module_name,
117 
118  safe_fclose(flint_messages_file, filename);
119  DB_PUT_FILE_RESOURCE(DBR_FLINTED_FILE, strdup(module_name),
120  localfilename);
121  free(filename);
122 
125  number_of_messages = 0;
126  no_message = true;
127 
132 
133  debug_off();
134 
135  /* Should have worked: */
136  return true;
137 }
138 
139 
140 /*************************************************************/
141 
142 /*
143  * FLINT_MESSAGE(fonction, format [, arg] ... ) string fonction, format;
144  */
145 
146 void
147 flint_message(char *fun,
148  char *fmt,
149  ...)
150 {
151  va_list args;
152  int order;
153 
154  va_start(args, fmt);
155 
156  /*
157  * print name of function causing message, and in which module it
158  * occured.
159  */
160 
161  no_message = false;
163 
165 
167  "flint message from %s, in module %s, in statement (%d.%d), number %td\n",
169  ORDERING_NUMBER(order), ORDERING_STATEMENT(order),
171 
172 
173  /* print out remainder of message */
174  (void) vfprintf(flint_messages_file, fmt, args);
175 
176  va_end(args);
177 
178 }
179 /*************************************************************/
180 /* Same as flint_message but without the function name */
181 
182 void
183 flint_message_2(char *fun,
184  char *fmt,
185  ...)
186 {
187  va_list args;
188 
189  va_start(args, fmt);
190 
191  no_message = false;
193 
195  "flint message from %s, in module %s\n",
197 
198  /* print out remainder of message */
199  (void) vfprintf(flint_messages_file, fmt, args);
200 
201  va_end(args);
202 
203 }
204 
205 
206 /*************************************************************/
207 /* Same as flint_message but a bare bones version */
208 /* count is used to decide if we count tjis message or not. */
209 
210 void
212  char *fmt,
213  ...)
214 {
215  va_list args;
216 
217  va_start(args, fmt);
218 
219  no_message = false;
220  if (count)
222 
223  (void) vfprintf(flint_messages_file, fmt, args);
224 
225  va_end(args);
226 }
227 
228 /*************************************************************/
229 /* End of File */
static int count
Definition: SDG.c:519
static graph dependence_graph
Definition: delay.c:93
struct _newgen_struct_statement_ * statement
Definition: cloning.h:21
void reset_proper_rw_effects(void)
void set_proper_rw_effects(statement_effects)
const char * module_name(const char *s)
Return the module part of an entity name.
Definition: entity_names.c:296
FILE * safe_fopen(const char *filename, const char *what)
Definition: file.c:67
int safe_fclose(FILE *stream, const char *filename)
Definition: file.c:77
static bool no_message
Definition: flint.c:44
void raw_flint_message(bool count, char *fmt,...)
Same as flint_message but a bare bones version
Definition: flint.c:211
static FILE * flint_messages_file
internal variables
Definition: flint.c:43
void flint_message(char *fun, char *fmt,...)
Definition: flint.c:147
void flint_message_2(char *fun, char *fmt,...)
Same as flint_message but without the function name
Definition: flint.c:183
static char * flint_current_module_name
name of module being flinted
Definition: flint.c:49
static int number_of_messages
Definition: flint.c:45
statement flint_current_statement
cproto-generated files
Definition: flint.c:46
bool flinter(const string module_name)
Routine of global module verification
Definition: flint.c:54
bool check_commons(entity)
Definition: flint_check.c:632
void flint_uninitialized_variables(graph, statement)
uninitialized_variables.c
statement flint_statement(statement)
Definition: flint_walk.c:278
void free(void *)
struct _newgen_struct_graph_ * graph
Definition: graph.h:31
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_FILE_RESOURCE
Put a file resource into the current workspace database.
Definition: pipsdbm-local.h:85
string db_build_file_resource_name(const char *rname, const char *oname, const char *suffix)
returns an allocated file name for a file resource.
Definition: lowlevel.c:169
#define debug_on(env)
Definition: misc-local.h:157
#define pips_debug
these macros use the GNU extensions that allow variadic macros, including with an empty list.
Definition: misc-local.h:145
#define debug_off()
Definition: misc-local.h:160
void debug(const int the_expected_debug_level, const char *calling_function_name, const char *a_message_format,...)
ARARGS0.
Definition: debug.c:189
string concatenate(const char *,...)
Return the concatenation of the given strings.
Definition: string.c:183
hash_table set_ordering_to_statement(statement s)
To be used instead of initialize_ordering_to_statement() to make sure that the hash table ots is in s...
Definition: ordering.c:172
void reset_ordering_to_statement(void)
Reset the mapping from ordering to statement.
Definition: ordering.c:185
static char * module
Definition: pips.c:74
string db_get_current_workspace_directory(void)
Definition: workspace.c:96
#define ORDERING_NUMBER(o)
#define ORDERING_STATEMENT(o)
entity local_name_to_top_level_entity(const char *n)
This function try to find a top-level entity from a local name.
Definition: entity.c:1450
#define statement_ordering(x)
Definition: ri.h:2454
#define statement_number(x)
Definition: ri.h:2452
#define statement_undefined
Definition: ri.h:2419
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...
char * strdup()