PIPS
xml_output.c File Reference
#include <stdio.h>
#include <ctype.h>
#include "genC.h"
#include "linear.h"
#include "ri.h"
#include "effects.h"
#include "resources.h"
#include "misc.h"
#include "ri-util.h"
#include "prettyprint.h"
#include "effects-util.h"
#include "control.h"
#include "pipsdbm.h"
#include "text-util.h"
#include "properties.h"
+ Include dependency graph for xml_output.c:

Go to the source code of this file.

Macros

#define NL   "\n"
 
#define XMLPRETTY   ".xml"
 
#define xml_print(format, args...)
 

Functions

static void xml_set_output (FILE *new_fp)
 
static void xml_output (string s)
 
static void xml_print_entity_name (entity e)
 
static void xml_print_type (type t)
 
void xml_print_entity_full (entity e)
 xml_output.c More...
 
static void xml_print_parameter (entity p, bool is_a_dim)
 
void gather_grid_dim (statement s, void *ctx)
 
bool gpu_xml_dump (string mod_name)
 PIPSMAKE INTERFACE. More...
 

Variables

static FILE * out_fp = 0
 

Macro Definition Documentation

◆ NL

#define NL   "\n"

Definition at line 48 of file xml_output.c.

◆ xml_print

#define xml_print (   format,
  args... 
)
Value:
{ \
pips_assert("Output is set",out_fp); \
fprintf(out_fp,format,##args); \
}
static FILE * out_fp
Definition: xml_output.c:52

Definition at line 62 of file xml_output.c.

◆ XMLPRETTY

#define XMLPRETTY   ".xml"

Definition at line 50 of file xml_output.c.

Function Documentation

◆ gather_grid_dim()

void gather_grid_dim ( statement  s,
void *  ctx 
)
Parameters
ctxtx

Definition at line 165 of file xml_output.c.

165  {
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 }
static void comment(string_buffer code, spoc_hardware_type hw, dagvtx v, int stage, int side, bool flip)
Definition: freia_spoc.c:52
#define CONS(_t_, _i_, _l_)
List element cell constructor (insert an element at the beginning of a list)
Definition: newgen_list.h:150
#define pips_debug
these macros use the GNU extensions that allow variadic macros, including with an empty list.
Definition: misc-local.h:145
#define string_undefined_p(s)
Definition: newgen_types.h:41
#define statement_comments(x)
Definition: ri.h:2456
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

References comment(), CONS, pips_debug, statement_comments, string_undefined_p, and strndup().

Referenced by gpu_xml_dump().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ gpu_xml_dump()

bool gpu_xml_dump ( string  mod_name)

PIPSMAKE INTERFACE.

Set the current module entity required to have many things working in PIPS:

First find grid dimension by looking for magic comments

of const strings

Print current module

Parameters
mod_nameod_name

Definition at line 187 of file xml_output.c.

187  {
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
#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 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_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)
static char * module
Definition: pips.c:74
string db_get_current_workspace_directory(void)
Definition: workspace.c:96
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
entity find_ith_parameter(entity, int)
Definition: util.c:93
#define type_functional_p(x)
Definition: ri.h:2950
#define type_functional(x)
Definition: ri.h:2952
#define statement_domain
newgen_sizeofexpression_domain_defined
Definition: ri.h:362
#define functional_parameters(x)
Definition: ri.h:1442
#define entity_type(x)
Definition: ri.h:2792
char * strdup()
Definition: replace.c:135
static void xml_print_parameter(entity p, bool is_a_dim)
Definition: xml_output.c:139
#define xml_print(format, args...)
Definition: xml_output.c:62
#define NL
Definition: xml_output.c:48
void gather_grid_dim(statement s, void *ctx)
Definition: xml_output.c:165
static void xml_set_output(FILE *new_fp)
Definition: xml_output.c:55

References concatenate(), db_build_file_resource_name(), db_get_current_workspace_directory(), db_get_memory_resource(), DB_PUT_FILE_RESOURCE, debug_off, debug_on, entity_type, entity_user_name(), find_ith_parameter(), FOREACH, functional_parameters, gather_grid_dim(), gen_context_recurse, gen_length(), gen_true2(), get_current_module_entity(), module, module_name_to_entity(), module_statement, NIL, NL, pips_assert, pips_debug, reset_current_module_entity(), reset_current_module_statement(), safe_fclose(), safe_fopen(), same_string_p, set_current_module_entity(), set_current_module_statement(), statement_consistent_p(), statement_domain, strdup(), type_functional, type_functional_p, xml_print, xml_print_parameter(), and xml_set_output().

+ Here is the call graph for this function:

◆ xml_output()

static void xml_output ( string  s)
static

Definition at line 68 of file xml_output.c.

68  {
69  xml_print("%s", s);
70 }

References xml_print.

Referenced by xml_print_entity_full(), xml_print_entity_name(), and xml_print_type().

+ Here is the caller graph for this function:

◆ xml_print_entity_full()

void xml_print_entity_full ( entity  e)

xml_output.c

Definition at line 132 of file xml_output.c.

132  {
133  xml_output(entity_name( e ));
135  //xml_print_storage(entity_storage( e ));
136  //xml_print_value(entity_initial( e ));
137 }
#define entity_name(x)
Definition: ri.h:2790
static void xml_print_type(type t)
Definition: xml_output.c:76
static void xml_output(string s)
Definition: xml_output.c:68

References entity_name, entity_type, xml_output(), and xml_print_type().

+ Here is the call graph for this function:

◆ xml_print_entity_name()

static void xml_print_entity_name ( entity  e)
static

Definition at line 72 of file xml_output.c.

72  {
73  xml_output(entity_name( e ));
74 }

References entity_name, and xml_output().

Referenced by xml_print_type().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ xml_print_parameter()

static void xml_print_parameter ( entity  p,
bool  is_a_dim 
)
static

Definition at line 139 of file xml_output.c.

139  {
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 }
if(!(yy_init))
Definition: genread_lex.c:1029
string string_of_type(const type)
Definition: type.c:56
type ultimate_type(type)
Definition: type.c:3466
#define type_variable(x)
Definition: ri.h:2949
#define basic_pointer_p(x)
Definition: ri.h:635
#define variable_basic(x)
Definition: ri.h:3120

References basic_pointer_p, entity_type, entity_user_name(), NL, string_of_type(), type_variable, ultimate_type(), variable_basic, and xml_print.

Referenced by gpu_xml_dump().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ xml_print_type()

static void xml_print_type ( type  t)
static

Definition at line 76 of file xml_output.c.

76  {
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 }
#define type_struct(x)
Definition: ri.h:2964
#define type_tag(x)
Definition: ri.h:2940
#define type_enum(x)
Definition: ri.h:2970
#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 type_union(x)
Definition: ri.h:2967
static void xml_print_entity_name(entity e)
Definition: xml_output.c:72

References FOREACH, is_type_area, is_type_enum, is_type_functional, is_type_statement, is_type_struct, is_type_union, is_type_unknown, is_type_varargs, is_type_variable, is_type_void, type_enum, type_struct, type_tag, type_undefined, type_union, xml_output(), xml_print, and xml_print_entity_name().

Referenced by xml_print_entity_full().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ xml_set_output()

static void xml_set_output ( FILE *  new_fp)
static

Definition at line 55 of file xml_output.c.

55  {
56  out_fp = new_fp;
57 }

References out_fp.

Referenced by gpu_xml_dump().

+ Here is the caller graph for this function:

Variable Documentation

◆ out_fp

FILE* out_fp = 0
static

Definition at line 52 of file xml_output.c.

Referenced by xml_set_output().