PIPS
stub.c
Go to the documentation of this file.
1 /*
2 
3  $Id: stub.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 
29  Stub.c --
30 
31  Interface to CommonLISP's implementation of Generalized Reductions
32 
33  P. Jouvelot
34 
35 */
36 
37 
38 #include <stdio.h>
39 #include <string.h>
40 #include <stdlib.h>
41 #include <sys/types.h>
42 #include <sys/stat.h>
43 
44 #include "genC.h"
45 #include "linear.h"
46 #include "ri.h"
47 #include "effects.h"
48 #include "ri-util.h"
49 #include "effects-util.h"
50 #include "misc.h"
51 #include "database.h"
52 #include "resources.h"
53 
54 #include "pipsdbm.h"
55 
56 #include "control.h"
57 
58 #define LISP (getenv("LISP"))
59 
60 #define REDUCTIONS_SOURCE_DIRECTORY \
61  (strdup(concatenate(getenv("DEVEDIR"), "/Lib/reductions", NULL)))
62 
63 bool old_reductions(string mod_name)
64 {
65  string program_name = db_get_current_workspace_name() ;
66  char *command ;
67  struct stat buf ;
68  char *options ;
70 
71  if( stat( LISP, &buf ) != 0 ) {
72  user_warning("reductions",
73  "No lisp! Skipping reduction detection\n") ;
74  /* true or FALSE? After all, it's just a user warning, not an error */
75  return false;
76  }
77  debug_on("REDUCTIONS_DEBUG_LEVEL");
78  db_close_workspace(false) ;
79  options = (get_debug_level() <= 5) ? " -batch" : "" ;
80  asprintf(&command,
81  "(echo \"(defparameter files-directory \\\"%s\\\")\
82  (load (concatenate %s files-directory \\\"/init\\\"))\
83  (load (concatenate %s files-directory \\\"/top\\\"))\
84  (reductions t \\\"%s\\\" \\\"%s\\\")\") | %s%s",
86  "'string",
87  "'string",
88  program_name,
89  mod_name,
90  LISP,
91  options ) ;
92  debug( 5, "reductions", "\ncommand = %s\n", command ) ;
93 
94  if( (system( command ) >> 8) != 0 ) {
95  pips_internal_error("Lisp process died unexpectedly" ) ;
96  }
97  free(command);
98  debug_off();
99  db_open_workspace( program_name ) ;
100  mod_stat = (statement)
101  db_get_memory_resource(DBR_CODE, mod_name, true);
103  DB_PUT_MEMORY_RESOURCE(DBR_CODE, strdup(mod_name), mod_stat);
104 
105  return true;
106 }
struct _newgen_struct_statement_ * statement
Definition: cloning.h:21
void free(void *)
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
static statement mod_stat
We want to keep track of the current statement inside the recurse.
Definition: impact_check.c:41
#define debug_on(env)
Definition: misc-local.h:157
#define asprintf
Definition: misc-local.h:225
#define pips_internal_error
Definition: misc-local.h:149
#define debug_off()
Definition: misc-local.h:160
#define user_warning(fn,...)
Definition: misc-local.h:262
int get_debug_level(void)
GET_DEBUG_LEVEL returns the current debugging level.
Definition: debug.c:67
void debug(const int the_expected_debug_level, const char *calling_function_name, const char *a_message_format,...)
ARARGS0.
Definition: debug.c:189
bool db_close_workspace(bool)
Definition: workspace.c:367
bool db_open_workspace(const char *)
Definition: workspace.c:380
string db_get_current_workspace_name(void)
the function is used to check that there is some current workspace...
Definition: workspace.c:82
bool module_reorder(statement body)
Reorder a module and recompute order to statement if any.
Definition: reorder.c:244
char * strdup()
static char buf[BSZ]
Definition: split_file.c:157
#define LISP
Definition: stub.c:58
#define REDUCTIONS_SOURCE_DIRECTORY
Definition: stub.c:60
bool old_reductions(string mod_name)
stub.c
Definition: stub.c:63