PIPS
xml_output.c
Go to the documentation of this file.
1 /*
2 
3  $Id $
4 
5  Copyright 1989-2016 MINES ParisTech
6  Copyright 2012 Silkan
7 
8  This file is part of PIPS.
9 
10  PIPS is free software: you can redistribute it and/or modify it
11  under the terms of the GNU General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  any later version.
14 
15  PIPS is distributed in the hope that it will be useful, but WITHOUT ANY
16  WARRANTY; without even the implied warranty of MERCHANTABILITY or
17  FITNESS FOR A PARTICULAR PURPOSE.
18 
19  See the GNU General Public License for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with PIPS. If not, see <http://www.gnu.org/licenses/>.
23 
24  */
25 #ifdef HAVE_CONFIG_H
26 #include "pips_config.h"
27 #endif
28 
29 #include <stdio.h>
30 #include <ctype.h>
31 
32 #include "genC.h"
33 #include "linear.h"
34 #include "ri.h"
35 #include "effects.h"
36 
37 #include "resources.h"
38 
39 #include "misc.h"
40 #include "ri-util.h"
41 #include "prettyprint.h"
42 #include "effects-util.h"
43 #include "control.h"
44 #include "pipsdbm.h"
45 #include "text-util.h"
46 #include "properties.h"
47 
48 #define NL "\n"
49 
50 #define XMLPRETTY ".xml"
51 
52 static FILE *out_fp = 0;
53 
54 // Define output
55 static void xml_set_output(FILE *new_fp) {
56  out_fp = new_fp;
57 }
58 
59 /*
60  * Print to the defined output the format string and an optional string argument
61  */
62 #define xml_print(format, args...) \
63 { \
64  pips_assert("Output is set",out_fp); \
65  fprintf(out_fp,format,##args); \
66 }
67 
68 static void xml_output(string s) {
69  xml_print("%s", s);
70 }
71 
72 static void xml_print_entity_name(entity e) {
73  xml_output(entity_name( e ));
74 }
75 
76 static void xml_print_type(type t) {
77  if(t == type_undefined) {
78  xml_print("*undefined*");
79  } else {
80  switch(type_tag( t )) {
81  case is_type_statement:
82  xml_output("Statement (unit ?) ");
83  break;
84  case is_type_area:
85  xml_output("Area unsupported");
86  break;
87  case is_type_variable:
88  xml_output("Variable unsupported");
89  //xml_print_variable(type_variable( t ));
90  break;
91  case is_type_functional:
92  xml_output("Functional unsupported");
93  //xml_print_functional(type_functional( t ));
94  break;
95  case is_type_varargs:
96  xml_output("VarArgs unsupported");
97  //xml_print_type(type_varargs( t ));
98  break;
99  case is_type_unknown:
100  xml_output("Unknown");
101  break;
102  case is_type_void:
103  xml_output("void");
104  break;
105  case is_type_struct: {
106  FOREACH(entity, e, type_struct( t ) )
107  {
109  }
110  break;
111  }
112  case is_type_union:
113  xml_output("Union");
114  FOREACH(entity, e, type_union( t ) )
115  {
117  }
118  break;
119  case is_type_enum:
120  xml_output("Enum");
121  FOREACH(entity, e, type_enum( t ) )
122  {
124  }
125  break;
126  default:
127  break;
128  }
129  }
130 }
131 
133  xml_output(entity_name( e ));
135  //xml_print_storage(entity_storage( e ));
136  //xml_print_value(entity_initial( e ));
137 }
138 
139 static void xml_print_parameter(entity p, bool is_a_dim) {
140  xml_print("<Arg type=\"")
141  type t = entity_type( p );
142 
143  // Pointeur or Array/scalar
144  // BTW it would be too easy if "array" means Array type, in fact it means pointer...
145  type ut = ultimate_type(t);
147  xml_print("array");
148  } else {
149  xml_print("param");
150  }
151 
152  // Name
153  xml_print("\" name=\"%s\" ", entity_user_name(p));
154 
155  // Type
156  xml_print(" typeData=\"%s\"", string_of_type(t));
157 
158  if(is_a_dim) {
159  xml_print(" value=\"0\"")
160  }
161  xml_print("/>" NL)
162 }
163 
164 
165 void gather_grid_dim(statement s, void *ctx) {
166  // ctx is a pointer to a list of variable
167  list *dims = (list *)ctx;
168 
169  string comment = statement_comments(s);
170  pips_debug(3,"Statement %p, Compare comment '%s'\n",s,comment);
172  size_t sentinel_len = strlen("// To be assigned to a call to P4A_vp_X: ");
173  string sentinel;
174  while((sentinel=strstr(comment,"// To be assigned to a call to P4A_vp_"))!=NULL) {
175  string varname_ptr = sentinel+sentinel_len;
176  string varname_end = strchr(varname_ptr,'\n');
177  int varname_len = varname_end-varname_ptr;
178  string varname = strndup(varname_ptr,varname_len); // to be freed
179  pips_debug(2,"Catch dimension %s\n",varname);
180  *dims = CONS(string,varname,*dims);
181  comment = varname_end;
182  }
183  }
184 }
185 
186 /** PIPSMAKE INTERFACE */
187 bool gpu_xml_dump(string mod_name) {
188 
190  mod_name,
191  true);
192 
194 
195  /* Set the current module entity required to have many things
196  working in PIPS: */
198 
199  debug_on("GPU_XML_DUMP_DEBUG_LEVEL");
200  pips_assert("Statement should be OK at entry...",
202 
203  // Prepare the output file
204  string xml_file_name = db_build_file_resource_name("RI",
205  mod_name,
206  ".out.xml");
208  "/",
209  xml_file_name,
210  NULL));
211  pips_debug(2, "Output in %s\n", output_file);
212  FILE *fp = safe_fopen(output_file, "w");
213  xml_set_output(fp);
214 
215  /* First find grid dimension by looking for magic comments */
216  list /* of const strings */ dims = NIL;
219 
220  /* Print current module */
222  type module_type = entity_type(module);
223  pips_assert("Functional module", type_functional_p(module_type));
224 
225  // Remove wrapper prefix FIXME: bad hack...
226  string original_name = mod_name + strlen("p4a_wrapper_");
227 
228  // Print Task
229  xml_print("<Task name=\"%s\" kernel=\"%s\" nbParallelLoops=\"%zu\">" NL,
230  original_name, mod_name, gen_length(dims));
231 
232  // Params
233  int nparams = gen_length(functional_parameters(type_functional(module_type)));
234  for(int i = 1; i <= nparams; i++) {
236  bool is_a_dim = false;
237  FOREACH(string, dim, dims) {
239  is_a_dim=true;
240  break;
241  }
242  }
243  xml_print_parameter(param, is_a_dim );
244  }
245 
246  //xml_print_statement(module_statement);
247  xml_print("</Task>" NL);
248 
249  // Reset output file
250  xml_set_output(0);
251  safe_fclose(fp, output_file);
252 
253  DB_PUT_FILE_RESOURCE( DBR_GPU_XML_FILE, strdup( mod_name ), xml_file_name );
254 
255  debug_off();
256 
259 
260  return true;
261 }
bool statement_consistent_p(statement p)
Definition: ri.c:2195
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
int safe_fclose(FILE *stream, const char *filename)
Definition: file.c:77
static void comment(string_buffer code, spoc_hardware_type hw, dagvtx v, int stage, int side, bool flip)
Definition: freia_spoc.c:52
#define gen_context_recurse(start, ctxt, domain_number, flt, rwt)
Definition: genC.h:285
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
entity get_current_module_entity(void)
Get the entity of the current module.
Definition: static.c:85
bool gen_true2(__attribute__((unused)) gen_chunk *u1, __attribute__((unused)) void *u2)
Definition: genClib.c:2785
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
size_t gen_length(const list l)
Definition: list.c:150
#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 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 pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172
#define debug_off()
Definition: misc-local.h:160
string concatenate(const char *,...)
Return the concatenation of the given strings.
Definition: string.c:183
#define same_string_p(s1, s2)
#define string_undefined_p(s)
Definition: newgen_types.h:41
static char * module
Definition: pips.c:74
string db_get_current_workspace_directory(void)
Definition: workspace.c:96
string string_of_type(const type)
Definition: type.c:56
const char * entity_user_name(entity e)
Since entity_local_name may contain PIPS special characters such as prefixes (label,...
Definition: entity.c:487
entity module_name_to_entity(const char *mn)
This is an alias for local_name_to_top_level_entity.
Definition: entity.c:1479
type ultimate_type(type)
Definition: type.c:3466
entity find_ith_parameter(entity, int)
Definition: util.c:93
#define type_functional_p(x)
Definition: ri.h:2950
#define type_struct(x)
Definition: ri.h:2964
#define type_tag(x)
Definition: ri.h:2940
#define type_functional(x)
Definition: ri.h:2952
#define type_variable(x)
Definition: ri.h:2949
#define basic_pointer_p(x)
Definition: ri.h:635
#define statement_domain
newgen_sizeofexpression_domain_defined
Definition: ri.h:362
#define type_enum(x)
Definition: ri.h:2970
#define entity_name(x)
Definition: ri.h:2790
#define functional_parameters(x)
Definition: ri.h:1442
#define statement_comments(x)
Definition: ri.h:2456
#define type_undefined
Definition: ri.h:2883
@ is_type_varargs
Definition: ri.h:2902
@ is_type_void
Definition: ri.h:2904
@ is_type_enum
Definition: ri.h:2907
@ is_type_statement
Definition: ri.h:2898
@ is_type_functional
Definition: ri.h:2901
@ is_type_variable
Definition: ri.h:2900
@ is_type_union
Definition: ri.h:2906
@ is_type_area
Definition: ri.h:2899
@ is_type_unknown
Definition: ri.h:2903
@ is_type_struct
Definition: ri.h:2905
#define entity_type(x)
Definition: ri.h:2792
#define type_union(x)
Definition: ri.h:2967
#define variable_basic(x)
Definition: ri.h:3120
char * strdup()
char * strndup(char const *s, size_t n)
A replacement function, for systems that lack strndup.
Definition: strndup.c:26
The structure used to build lists in NewGen.
Definition: newgen_list.h:41
Definition: replace.c:135
void xml_print_entity_full(entity e)
xml_output.c
Definition: xml_output.c:132
static void xml_print_parameter(entity p, bool is_a_dim)
Definition: xml_output.c:139
bool gpu_xml_dump(string mod_name)
PIPSMAKE INTERFACE.
Definition: xml_output.c:187
#define xml_print(format, args...)
Definition: xml_output.c:62
#define NL
Definition: xml_output.c:48
static void xml_print_type(type t)
Definition: xml_output.c:76
void gather_grid_dim(statement s, void *ctx)
Definition: xml_output.c:165
static void xml_output(string s)
Definition: xml_output.c:68
static FILE * out_fp
Definition: xml_output.c:52
static void xml_set_output(FILE *new_fp)
Definition: xml_output.c:55
static void xml_print_entity_name(entity e)
Definition: xml_output.c:72