PIPS
cmfortran.c
Go to the documentation of this file.
1 /*
2 
3  $Id: cmfortran.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 /* Prettyprinter for CM FORTRAN loops.
28 
29  There are memory leaks here since a new expression is constructed.
30 
31 */
32 
33 #include <stdio.h>
34 #include <string.h>
35 
36 #include "linear.h"
37 
38 #include "genC.h"
39 
40 #include "text-util.h"
41 #include "ri-util.h"
42 
43 #include "prettyprint.h"
44 
45 /*======================================================================*/
47 range obj;
48 {
49  cons *pc;
51 
52  pc = Words_Subexpression(range_lower(obj), 0, true);
53  pc = CHAIN_SWORD(pc,":");
54  pc = gen_nconc(pc, Words_Subexpression(range_upper(obj), 0, true));
55  if (/* expression_constant_p(range_increment(obj)) && */
56  strcmp( entity_local_name(call_function(c)), "1") == 0 )
57  return(pc);
58  pc = CHAIN_SWORD(pc,":");
60 
61  return(pc);
62 }
63 
64 
65 /*======================================================================*/
66 text text_loop_cmf(module, label, margin, obj, n, lr, lidx)
67  entity module;
68  const char* label;
69  int margin;
70  loop obj;
71  int n;
72  list lr, lidx;
73 {
74  text result_text = text_undefined;
75  instruction i;
76  entity idx;
77  range r;
78 
80  idx = loop_index(obj);
81  r = loop_range(obj);
82 
83  lr = gen_nconc(lr, CONS(RANGE, r, NIL));
84  lidx = gen_nconc(lidx, CONS(ENTITY, idx, NIL));
85 
86  if(!instruction_assign_p(i)) {
87  if(instruction_loop_p(i)) {
88  result_text = text_loop_cmf(module, label, margin,
89  instruction_loop(i), n, lr, lidx);
90  }
91  }
92  else {
93  list pc, lli, llr;
94  unformatted u;
95 
96  pc = CHAIN_SWORD(NIL, "FORALL(");
97  for(lli = lidx, llr = lr; !ENDP(lli); POP(lli), POP(llr)) {
98  pc = CHAIN_SWORD(pc, entity_local_name(ENTITY(CAR(lli))));
99  pc = CHAIN_SWORD(pc, " = ");
100  pc = gen_nconc(pc, words_cmf_loop_range(RANGE(CAR(llr))));
101  if(CDR(lli) != NIL)
102  pc = CHAIN_SWORD(pc, ", ");
103  }
104  pc = CHAIN_SWORD(pc, ") ");
105  pc = gen_nconc(pc, Words_Call(instruction_call(i), 0, true, true));
106  u = make_unformatted(strdup(label), n, margin, pc) ;
107  result_text = make_text(CONS(SENTENCE,
109  u),
110  NIL));
111  }
112  return(result_text);
113 }
114 
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_cmf(entity module, const char *label, int margin, loop obj, int n, list lr, list lidx)
=====================================================================
Definition: cmfortran.c:66
cons * words_cmf_loop_range(range obj)
Prettyprinter for CM FORTRAN loops.
Definition: cmfortran.c:46
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
#define CAR(pcons)
Get the value of the first element of a list.
Definition: newgen_list.h:92
#define CDR(pcons)
Get the list less its first element.
Definition: newgen_list.h:111
static char * module
Definition: pips.c:74
list Words_Subexpression(expression obj, int precedence, bool leftmost)
Definition: misc.c:2695
list Words_Call(call obj, int precedence, bool leftmost, bool is_a_subroutine)
Definition: misc.c:2597
list Words_Expression(expression obj)
of string
Definition: misc.c:2616
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 loop_body(x)
Definition: ri.h:1644
#define instruction_loop_p(x)
Definition: ri.h:1518
#define call_function(x)
Definition: ri.h:709
#define range_upper(x)
Definition: ri.h:2290
#define ENTITY(x)
ENTITY.
Definition: ri.h:2755
#define instruction_loop(x)
Definition: ri.h:1520
#define range_increment(x)
Definition: ri.h:2292
#define RANGE(x)
RANGE.
Definition: ri.h:2257
#define syntax_call(x)
Definition: ri.h:2736
#define range_lower(x)
Definition: ri.h:2288
#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 expression_syntax(x)
Definition: ri.h:1247
#define loop_index(x)
Definition: ri.h:1640
char * strdup()
The structure used to build lists in NewGen.
Definition: newgen_list.h:41
#define CHAIN_SWORD(l, s)
#define SENTENCE(x)
newgen_unformatted_domain_defined
Definition: text.h:36
#define text_undefined
Definition: text.h:91
@ is_sentence_unformatted
Definition: text.h:58