PIPS
craft.c File Reference
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "linear.h"
#include "genC.h"
#include "misc.h"
#include "properties.h"
#include "text-util.h"
#include "ri-util.h"
#include "prettyprint.h"
+ Include dependency graph for craft.c:

Go to the source code of this file.

Functions

static void rewrite_modulo_expression (expression exp)
 Prettyprinter for CRAFT loops. More...
 
expression remove_modulo (expression exp)
 ===================================================================== More...
 
text text_loop_craft (entity module, const char *label, int margin, loop obj, int n, list lr, list lidx)
 ===================================================================== More...
 

Function Documentation

◆ remove_modulo()

expression remove_modulo ( expression  exp)

=====================================================================

craft.c

Parameters
expxp

Definition at line 83 of file craft.c.

85 {
87 
88  return(exp);
89 }
static void rewrite_modulo_expression(expression exp)
Prettyprinter for CRAFT loops.
Definition: craft.c:57
#define gen_recurse(start, domain_number, flt, rwt)
Definition: genC.h:283
bool gen_true(__attribute__((unused)) gen_chunk *unused)
Return true and ignore the argument.
Definition: genClib.c:2780
#define expression_domain
newgen_execution_domain_defined
Definition: ri.h:154
#define exp
Avoid some warnings from "gcc -Wshadow".
Definition: vasnprintf.c:207

References exp, expression_domain, gen_recurse, gen_true(), and rewrite_modulo_expression().

Referenced by text_loop_craft().

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

◆ rewrite_modulo_expression()

static void rewrite_modulo_expression ( expression  exp)
static

Prettyprinter for CRAFT loops.

There are memory leaks here since a new expression is constructed. ====================================================================== void rewrite_modulo_expression(exp):

filter on the call "ca". It removes all the call to the modulo function.

AP 94/12/20

Definition at line 57 of file craft.c.

58 {
59  syntax sy;
60  call ca;
61  entity func;
62  list args;
63  expression first_arg;
64 
65  sy = expression_syntax(exp);
66  if(syntax_tag(sy) == is_syntax_call) {
67  ca = syntax_call(sy);
68  func = call_function(ca);
69  if(strcmp(entity_local_name(func), MODULO_OPERATOR_NAME) == 0) {
70  args = call_arguments(ca);
71  if(gen_length(args) != 2)
72  user_error("rewrite_modulo_expression",
73  "\nA modulo not with exactly 2 arguments\n");
74  else {
75  first_arg = EXPRESSION(CAR(args));
77  }
78  }
79  }
80 }
size_t gen_length(const list l)
Definition: list.c:150
#define CAR(pcons)
Get the value of the first element of a list.
Definition: newgen_list.h:92
#define user_error(fn,...)
Definition: misc-local.h:265
#define MODULO_OPERATOR_NAME
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
#define syntax_tag(x)
Definition: ri.h:2727
#define call_function(x)
Definition: ri.h:709
@ is_syntax_call
Definition: ri.h:2693
#define EXPRESSION(x)
EXPRESSION.
Definition: ri.h:1217
#define syntax_call(x)
Definition: ri.h:2736
#define call_arguments(x)
Definition: ri.h:711
#define expression_syntax(x)
Definition: ri.h:1247
The structure used to build lists in NewGen.
Definition: newgen_list.h:41

References call_arguments, call_function, CAR, entity_local_name(), exp, EXPRESSION, expression_syntax, gen_length(), is_syntax_call, MODULO_OPERATOR_NAME, syntax_call, syntax_tag, and user_error.

Referenced by remove_modulo().

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

◆ text_loop_craft()

text text_loop_craft ( entity  module,
const char*  label,
int  margin,
loop  obj,
int  n,
list  lr,
list  lidx 
)

=====================================================================

Parameters
moduleodule
labelabel
marginargin
objbj
lrr
lidxidx

Definition at line 92 of file craft.c.

99 {
100  text result_text = make_text(NIL);
101  instruction i;
102  entity idx;
103  range r;
104 
106  idx = loop_index(obj);
107  r = loop_range(obj);
108 
109  lr = gen_nconc(lr, CONS(RANGE, r, NIL));
110  lidx = gen_nconc(lidx, CONS(ENTITY, idx, NIL));
111 
112  if(!instruction_assign_p(i)) {
113  if(instruction_loop_p(i)) {
114  result_text = text_loop_craft(module, label, margin,
115  instruction_loop(i), n, lr, lidx);
116  }
117  }
118  else {
119  list pc, lli, llr, args, new_lli = NIL;
120  unformatted u;
121  int c;
122  char *comment;
124  syntax lhs_sy;
125 
126  args = call_arguments(instruction_call(i));
127  if(!ENDP(args))
128  lhs_exp = copy_expression(EXPRESSION(CAR(args)));
129  else
130  user_error("text_loop_craft",
131  "Call to an assign with no argument\n");
132 
133  lhs_sy = expression_syntax(lhs_exp);
134  if(syntax_tag(lhs_sy) != is_syntax_reference)
135  user_error("text_loop_craft", "\n An lhs expression not a ref\n");
136  else {
137  lli = reference_indices(syntax_reference(lhs_sy));
138  for(; !ENDP(lli); POP(lli)) {
139  new_lli = gen_nconc(new_lli, CONS(EXPRESSION,
141  NIL));
142  }
143  reference_indices(syntax_reference(lhs_sy)) = new_lli;
144  }
145 
146  // BUG: missing overflow checks
147  comment = (char*) malloc(64);
148  char * x = comment;
149  x += sprintf(comment, "CDIR$ DOSHARED(");
150  for(lli = lidx; !ENDP(lli); POP(lli)) {
151  x += sprintf(x, "%s", entity_local_name(ENTITY(CAR(lli))));
152  if(CDR(lli) != NIL)
153  x += sprintf(x, ", ");
154  }
155  list pdl = NIL;
156  x += sprintf(x, ") ON %s\n", words_to_string(words_expression(lhs_exp, &pdl)));
157  gen_free_list(pdl);
159  comment));
160 
161  for(lli = lidx, llr = lr, c = 0; !ENDP(lli); POP(lli), POP(llr), c++) {
162  pc = CHAIN_SWORD(NIL, "DO " );
163  pc = CHAIN_SWORD(pc, entity_local_name(ENTITY(CAR(lli))));
164  pc = CHAIN_SWORD(pc, " = ");
165  pc = gen_nconc(pc, words_loop_range(RANGE(CAR(llr)), &pdl));
166  gen_free_list(pdl);
167  u = make_unformatted(strdup(label), n,
168  margin+c*INDENTATION, pc);
169  ADD_SENTENCE_TO_TEXT(result_text,
171  }
172  MERGE_TEXTS(result_text, text_statement(module, margin+c*INDENTATION,
173  loop_body(obj), &pdl));
174  gen_free_list(pdl);
175 
176  for(c = gen_length(lidx)-1; c > -1; c--) {
177  ADD_SENTENCE_TO_TEXT(result_text,
179  "ENDDO"));
180  }
181  }
182  return(result_text);
183 }
expression copy_expression(expression p)
EXPRESSION.
Definition: ri.c:850
unformatted make_unformatted(string a1, intptr_t a2, intptr_t a3, list a4)
Definition: text.c:149
sentence make_sentence(enum sentence_utype tag, void *val)
Definition: text.c:59
text make_text(list a)
Definition: text.c:107
text text_loop_craft(entity module, const char *label, int margin, loop obj, int n, list lr, list lidx)
=====================================================================
Definition: craft.c:92
expression remove_modulo(expression exp)
=====================================================================
Definition: craft.c:83
static void comment(string_buffer code, spoc_hardware_type hw, dagvtx v, int stage, int side, bool flip)
Definition: freia_spoc.c:52
void * malloc(YYSIZE_T)
bool instruction_assign_p(instruction i)
Test if an instruction is an assignment.
Definition: instruction.c:164
#define ENDP(l)
Test if a list is empty.
Definition: newgen_list.h:66
#define POP(l)
Modify a list pointer to point on the next element of the list.
Definition: newgen_list.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
void gen_free_list(list l)
free the spine of the list
Definition: list.c:327
#define CDR(pcons)
Get the list less its first element.
Definition: newgen_list.h:111
static char * module
Definition: pips.c:74
list words_expression(expression obj, list *ppdl)
This one is exported.
Definition: misc.c:2611
list words_loop_range(range obj, list *ppdl)
exported for craft
Definition: misc.c:434
text text_statement(entity, int, statement, list *)
#define INDENTATION
#define loop_body(x)
Definition: ri.h:1644
#define syntax_reference(x)
Definition: ri.h:2730
#define instruction_loop_p(x)
Definition: ri.h:1518
#define ENTITY(x)
ENTITY.
Definition: ri.h:2755
#define instruction_loop(x)
Definition: ri.h:1520
@ is_syntax_reference
Definition: ri.h:2691
#define expression_undefined
Definition: ri.h:1223
#define RANGE(x)
RANGE.
Definition: ri.h:2257
#define reference_indices(x)
Definition: ri.h:2328
#define statement_instruction(x)
Definition: ri.h:2458
#define instruction_call(x)
Definition: ri.h:1529
#define loop_range(x)
Definition: ri.h:1642
#define loop_index(x)
Definition: ri.h:1640
char * strdup()
static char * x
Definition: split_file.c:159
#define CHAIN_SWORD(l, s)
#define MERGE_TEXTS(r, t)
#define MAKE_ONE_WORD_SENTENCE(m, s)
#define ADD_SENTENCE_TO_TEXT(t, p)
string words_to_string(cons *lw)
Definition: print.c:211
@ is_sentence_formatted
Definition: text.h:57
@ is_sentence_unformatted
Definition: text.h:58

References ADD_SENTENCE_TO_TEXT, call_arguments, CAR, CDR, CHAIN_SWORD, comment(), CONS, copy_expression(), ENDP, ENTITY, entity_local_name(), EXPRESSION, expression_syntax, expression_undefined, gen_free_list(), gen_length(), gen_nconc(), INDENTATION, instruction_assign_p(), instruction_call, instruction_loop, instruction_loop_p, is_sentence_formatted, is_sentence_unformatted, is_syntax_reference, loop_body, loop_index, loop_range, MAKE_ONE_WORD_SENTENCE, make_sentence(), make_text(), make_unformatted(), malloc(), MERGE_TEXTS, module, NIL, POP, RANGE, reference_indices, remove_modulo(), statement_instruction, strdup(), syntax_reference, syntax_tag, text_statement(), user_error, words_expression(), words_loop_range(), words_to_string(), and x.

Referenced by text_loop().

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