PIPS
pips.c
Go to the documentation of this file.
1 /*
2 
3  $Id: pips.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 #include <stdio.h>
29 #include <stdlib.h>
30 #include <unistd.h>
31 #include <stdarg.h>
32 
33 #include "linear.h"
34 
35 #include "genC.h"
36 #include "ri.h"
37 #include "effects.h"
38 #include "properties.h"
39 
40 #include "misc.h"
41 #include "newgen.h"
42 #include "ri-util.h"
43 #include "complexity_ri.h"
44 
45 #include "constants.h"
46 #include "resources.h"
47 
48 #include "database.h"
49 #include "pipsdbm.h"
50 
51 #include "pipsmake.h"
52 
53 #include "top-level.h"
54 
55 extern void (*pips_error_handler)();
56 extern void (*pips_log_handler)();
57 extern void (*pips_warning_handler)();
58 
59 extern char * soft_revisions;
60 extern char * soft_date;
61 extern char * cc_version;
62 
63 static char *usage =
64  "Usage: %s [-v] [-f F]* [-m M] [-s S]* [-p P] [-b B] [-(0|1) T]* wspace\n"
65  "\t-v: pips version (which pips/ARCH)\n"
66  "\t-f F: source file F\n"
67  "\t-m M: module M\n"
68  "\t-s S: select rule S\n"
69  "\t-p P: perform rule P\n"
70  "\t-b B: build resource B\n"
71  "\t-(0|1) T: set boolean property T to FALSE or TRUE\n" ;
72 
73 static char *wspace = NULL;
74 static char *module = NULL;
75 static char *performed_rule = NULL;
77 static gen_array_t source_files = NULL;
79 
80 static void pips_parse_arguments(int argc, char * argv[])
81 {
82  int c;
83  extern char *optarg;
84  extern int optind;
86 
87  while ((c = getopt(argc, argv, "vf:m:s:p:b:1:0:")) != -1)
88  switch (c) {
89  case 'v':
90  fprintf(stdout,
91  "pips: (%s)\n"
92  "ARCH=" STRINGIFY(SOFT_ARCH) "\n"
93  "REVS=\n"
94  "%s"
95  "DATE=%s\n",
96  argv[0], soft_revisions, soft_date);
97  exit(0);
98  break;
99  case 'f':
101  break;
102  case 'm':
103  module= optarg;
104  break;
105  case 's':
108  break;
109  case 'p':
111  break;
112  case 'b':
115  break;
116 
117  /* next two added to deal with boolean properties directly
118  * FC, 27/03/95
119  */
120  case '1':
121  set_bool_property(optarg, true);
122  break;
123  case '0':
124  set_bool_property(optarg, false);
125  break;
126  case '?':
127  fprintf(stderr, usage, argv[0]);
128  exit(1);
129  ;
130  }
131 
132  if (argc < 2) {
133  fprintf(stderr, usage, argv[0]);
134  exit(1);
135  }
136 
137  if (argc != optind + 1) {
138  user_warning("pips_parse_argument",
139  ((argc < (optind + 1)) ?
140  "Too few arguments\n" : "illegal argument: %s\n"),
141  argv[optind + 1]);
142  fprintf(stderr, usage, argv[0]);
143  exit(1);
144  }
145  wspace= argv[argc - 1];
146 }
147 
148 static void
149 select_rule(rule_name)
150 char *rule_name;
151 {
152  user_log("Selecting rule: %s\n", rule_name);
153 
154  activate(rule_name);
155 
156  ifdebug(5) fprint_activated(stderr);
157 }
158 
159 int
160 pips_main(int argc, char ** argv)
161 {
162  volatile bool success = true;
163  pips_checks();
165 
169 
170  pips_parse_arguments(argc, argv);
171 
172  debug_on("PIPS_DEBUG_LEVEL");
174 
176  {
177  // no need to pop_pips_context() at top-level
178  // FI: are you sure make_close_program() cannot call user_error() ?
179  close_workspace(true);
180  success = false;
181  }
182  TRY
183  {
184  // Initialize workspace
188  }
189  else {
190  user_log("Cannot create workspace %s!\n", wspace);
191  exit(1);
192  }
193  } else {
194  // Workspace must be opened
195  if (!open_workspace(wspace)) {
196  user_log("Cannot open workspace %s!\n", wspace);
197  exit(1);
198  }
199  }
200 
201  // Open module
202  if (module != NULL)
204  else
206 
207  // Activate rules
208  if (success && selected_rules)
209  {
211  }
212 
213  // Perform applies
214  if (success && performed_rule && module)
215  {
217  if (success) {
218  user_log("%s performed for %s.\n", performed_rule, module);
219  }
220  else {
221  user_log("Cannot perform %s for %s.\n", performed_rule, module);
222  }
223  }
224 
225  // Build resources
227  {
228  FOREACH(STRING, build_resource_name, build_resource_names)
229  {
230  success = safe_make(build_resource_name, module);
231  if (!success)
232  {
233  user_log("Cannot build %s for %s.\n", build_resource_name, module);
234  break;
235  }
236  }
237  }
238  // whether success or not...
239  close_workspace(true);
240 
242  }
243 
244  debug_off();
245 
246  return !success;
247 }
248 
249 /* end of it.
250  */
void user_log(const char *format,...)
Definition: message.c:234
void set_pips_meta_informations(const char *revs, const char *date, const char *comp)
Definition: message.c:102
const char * activate(const char *phase)
Definition: activate.c:214
void fprint_activated(FILE *fd)
Definition: activate.c:110
#define CATCH(what)
@ any_exception_error
catch all
#define UNCATCH(what)
#define TRY
void set_exception_callbacks(exception_callback_t, exception_callback_t)
size_t gen_array_nitems(const gen_array_t a)
Definition: array.c:131
gen_array_t gen_array_make(size_t size)
declarations...
Definition: array.c:40
void gen_array_append(gen_array_t a, void *what)
Definition: array.c:105
bool open_module(const char *name)
tpips used to convert lower cases into upper cases for all module names, but this is no longer possib...
Definition: dbm.c:95
bool open_module_if_unique(void)
Open the module of a workspace if there is only one.
Definition: dbm.c:144
bool create_workspace(gen_array_t files)
FI: should be called "initialize_workspace()"; a previous call to db_create_workspace() is useful to ...
Definition: dbm.c:180
bool close_workspace(bool is_quit)
Definition: dbm.c:346
bool open_workspace(const char *name)
should be: success (cf wpips.h)
Definition: dbm.c:309
void push_pips_context(char const *file, char const *function, int line)
exception.c
Definition: exception.c:43
void pop_pips_context(char const *file, char const *function, int line)
Definition: exception.c:50
#define STRING(x)
Definition: genC.h:87
bool success
Definition: gpips-local.h:59
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
#define CONS(_t_, _i_, _l_)
List element cell constructor (insert an element at the beginning of a list)
Definition: newgen_list.h:150
list gen_nconc(list cp1, list cp2)
physically concatenates CP1 and CP2 but do not duplicates the elements
Definition: list.c:344
#define FOREACH(_fe_CASTER, _fe_item, _fe_list)
Apply/map an instruction block on all the elements of a list.
Definition: newgen_list.h:179
void pips_checks(void)
add checkings here (FI: why in help.c?) SG : PIPS_ROOT should not be required :)
Definition: help.c:100
#define debug_on(env)
Definition: misc-local.h:157
#define STRINGIFY(symbol)
If not using this 2-stage macro evaluation, the generated string is not the value of the macro but th...
Definition: misc-local.h:50
#define debug_off()
Definition: misc-local.h:160
#define exit(code)
Definition: misc-local.h:54
#define user_warning(fn,...)
Definition: misc-local.h:262
void initialize_newgen()
cproto-generated files
Definition: newgen.c:48
static list selected_rules
Definition: pips.c:78
char * soft_revisions
could be shared somewhere?
Definition: revisions.c:33
void(* pips_warning_handler)()
static list build_resource_names
Definition: pips.c:76
void(* pips_error_handler)()
char * cc_version
Definition: revisions.c:41
static void select_rule(char *rule_name)
Definition: pips.c:149
char * soft_date
Definition: revisions.c:39
void(* pips_log_handler)()
int pips_main(int argc, char **argv)
Warning! Do not modify this file that is automatically generated!
Definition: pips.c:160
static char * performed_rule
Definition: pips.c:75
static char * usage
Definition: pips.c:63
static char * wspace
Definition: pips.c:73
static void pips_parse_arguments(int argc, char *argv[])
Definition: pips.c:80
static char * module
Definition: pips.c:74
static gen_array_t source_files
Definition: pips.c:77
bool db_create_workspace(const char *)
Definition: workspace.c:282
bool safe_make(const char *res_n, const char *module_n)
Definition: pipsmake.c:1717
bool safe_apply(const char *phase_n, const char *module_n)
Definition: pipsmake.c:1723
void initialize_signal_catcher(void)
Definition: signal.c:126
void set_bool_property(const char *, bool)
const char * entity_local_name(entity e)
entity_local_name modified so that it does not core when used in vect_fprint, since someone thought t...
Definition: entity.c:453
void initialize_sc(char *(*var_to_string)(Variable))
Definition: sc_debug.c:253
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...
#define ifdebug(n)
Definition: sg.c:47
The structure used to build lists in NewGen.
Definition: newgen_list.h:41
int optind
char * optarg
void * Variable
arithmetique is a requirement for vecteur, but I do not want to inforce it in all pips files....
Definition: vecteur-local.h:60