PIPS
module.c
Go to the documentation of this file.
1 /*
2 
3  $Id: module.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 // strndup are GNU extensions...
29 #include <stdio.h>
30 #include <string.h>
31 
32 #include "genC.h"
33 #include "text.h"
34 #include "constants.h"
35 
36 #include "text-util.h"
37 #include "misc.h"
38 #include "linear.h"
39 #include "ri.h"
40 #include "ri-util.h"
41 #include "pipsdbm.h"
42 #include "workspace-util.h"
43 
44 #include "prettyprint.h"
45 
46 /* High-level functions about modules, using prettyprint, pipsdbm and
47  ri-util
48  */
49 
51 
52  /* build and register textual representation */
54  //add_new_module_from_text(module,t,fortran_module_p(modified_module),compilation_unit_of_module(module));
55  string dirname = db_get_current_workspace_directory();
56  string res = fortran_module_p(module)? DBR_INITIAL_FILE : DBR_C_SOURCE_FILE;
57  string filename = db_get_file_resource(res,module_local_name(module),true);
58  string fullname = strdup(concatenate(dirname, "/",filename, NULL));
59  FILE* f = safe_fopen(fullname,"w");
60  free(fullname);
61  print_text(f,t);
62  fclose(f);
63  free_text(t);
64 
66 
67  /* the module will be reparsed, so fix(=delete) all its previous entites */
68 #if 0
69  {
70  list p = NIL;
71  FOREACH(ENTITY, e, entity_declarations(modified_module))
72  {
73  if( recompile_module_removable_entity_p((gen_chunkp)e))
75  else
76  p = CONS(ENTITY,e,p);
77  }
78  entity_declarations(modified_module) = gen_nreverse(p);
80  }
81 #endif
82 }
83 
84 
85 /* build a textual representation of the modified module and update db
86  */
87 bool recompile_module(const string module)
88 {
89  entity modified_module = module_name_to_entity(module);
90  statement modified_module_statement =
91  (statement) db_get_memory_resource(DBR_CODE, module, true);
92  do_recompile_module(modified_module,modified_module_statement);
93  return true;
94 }
sequence make_sequence(list a)
Definition: ri.c:2125
void free_text(text p)
Definition: text.c:74
static statement module_statement
Definition: alias_check.c:125
struct _newgen_struct_statement_ * statement
Definition: cloning.h:21
FILE * safe_fopen(const char *filename, const char *what)
Definition: file.c:67
void free(void *)
list gen_nreverse(list cp)
reverse a list in place
Definition: list.c:304
#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
#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
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 concatenate(const char *,...)
Return the concatenation of the given strings.
Definition: string.c:183
int f(int off1, int off2, int n, float r[n], float a[n], float b[n])
Definition: offsets.c:15
static char * module
Definition: pips.c:74
#define db_get_file_resource
string db_get_current_workspace_directory(void)
Definition: workspace.c:96
static void do_recompile_module(entity module, statement module_statement)
High-level functions about modules, using prettyprint, pipsdbm and ri-util.
Definition: module.c:50
bool recompile_module(const string module)
build a textual representation of the modified module and update db
Definition: module.c:87
text text_module(entity, statement)
#define entity_declarations(e)
MISC: newgen shorthands.
entity module_name_to_entity(const char *mn)
This is an alias for local_name_to_top_level_entity.
Definition: entity.c:1479
const char * module_local_name(entity e)
Returns the module local user name.
Definition: entity.c:582
bool fortran_module_p(entity m)
Test if a module is in Fortran.
Definition: entity.c:2799
#define ENTITY(x)
ENTITY.
Definition: ri.h:2755
#define code_initializations(x)
Definition: ri.h:788
#define value_code(x)
Definition: ri.h:3067
#define entity_initial(x)
Definition: ri.h:2796
char * strdup()
The structure used to build lists in NewGen.
Definition: newgen_list.h:41
void gen_clear_tabulated_element(gen_chunk *obj)
GEN_CLEAR_TABULATED_ELEMENT only clears the entry for object OBJ in the gen_tabulated_ and gen_tabula...
Definition: tabulated.c:251
void print_text(FILE *fd, text t)
Definition: print.c:195
A gen_chunk is used to store every object.
Definition: genC.h:58