FAUST compiler  0.9.9.6b8
Functions
privatise.cpp File Reference
#include "sigtype.hh"
#include "compatibility.hh"
#include <stdio.h>
#include "sigprint.hh"
#include "sigtyperules.hh"
#include "privatise.hh"
Include dependency graph for privatise.cpp:

Go to the source code of this file.

Functions

static Tree makePrivatisationKey (const Tree &t)
 
static Tree makePrivatisationLabel (const Tree &exp)
 
static Tree privatisation (const Tree &k, const Tree &t)
 
static Tree computePrivatisation (const Tree &k, const Tree &t)
 
static Tree labelize (const Tree &label, const Tree &exp)
 
Tree privatise (const Tree &t)
 

Function Documentation

static Tree computePrivatisation ( const Tree k,
const Tree t 
)
static

Definition at line 102 of file privatise.cpp.

References CTree::arity(), CTree::branch(), isRec(), isSigGen(), isSigTable(), isSigWRTbl(), labelize(), makePrivatisationLabel(), nil, CTree::node(), privatisation(), rec(), setProperty(), sigWRTbl(), and tree().

Referenced by privatisation().

103 {
104  Tree tbl, size, idx, wrt, content, id, var, body;
105 
106  if ( isSigWRTbl(exp, id, tbl, idx, wrt) ) {
107  /* Ce qui ne peut pas être partagé, ce sont les
108  tables dans lesquelles on ecrit. Pour cela
109  on leur donne un label unique
110  */
111  return sigWRTbl(
112  id,
114  privatisation(k, idx),
115  privatisation(k, wrt) );
116 
117  } else if ( isSigTable(exp, id, size, content) ) {
118  /* Rien à privatiser dans une table (car size est
119  censée etre une expression entiere)
120  */
121  return exp;
122 
123  } else if ( isSigGen(exp, content) ) {
124  /* On ne visite pas les contenus des tables
125  */
126  printf("erreur 1 dans computePrivatisation\n");
127  exit(1);
128 
129  } else if ( isRec(exp, var, body) ) {
130  /* On ne visite pas les contenus des tables
131  */
132  setProperty(exp, k, nil);
133  return rec(var, privatisation(k,body));
134 
135  } else {
136  /* On parcours les autres arbres en privatisant les branches
137  */
138 
139  tvec br;
140  int n = exp->arity();
141  for (int i = 0; i < n; i++) {
142  br.push_back( privatisation(k,exp->branch(i)) );
143  }
144 
145  return tree(exp->node(), br);
146 
147  }
148 }
Tree rec(Tree body)
create a de Bruijn recursive tree
vector< Tree > tvec
Definition: tree.hh:90
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
bool isSigGen(Tree t, Tree &x)
Definition: signals.cpp:91
bool isSigTable(Tree t, Tree &id, Tree &n, Tree &sig)
Definition: signals.cpp:85
static Tree privatisation(const Tree &k, const Tree &t)
Definition: privatise.cpp:71
bool isSigWRTbl(Tree u, Tree &id, Tree &t, Tree &i, Tree &s)
Definition: signals.cpp:81
bool isRec(Tree t, Tree &body)
is t a de Bruijn recursive tree
Tree tree(const Node &n)
Definition: tree.hh:186
void setProperty(Tree t, Tree key, Tree val)
Definition: list.cpp:418
Tree nil
Definition: list.cpp:116
static Tree makePrivatisationLabel(const Tree &exp)
Definition: privatise.cpp:61
static Tree labelize(const Tree &label, const Tree &exp)
Definition: privatise.cpp:150
Tree sigWRTbl(Tree id, Tree t, Tree i, Tree s)
Definition: signals.cpp:80
Tree branch(int i) const
return the ith branch (subtree) of a tree
Definition: tree.hh:145

Here is the call graph for this function:

Here is the caller graph for this function:

static Tree labelize ( const Tree label,
const Tree exp 
)
static

Definition at line 150 of file privatise.cpp.

References isSigTable(), isSigWRTbl(), sigTable(), and sigWRTbl().

Referenced by computePrivatisation().

151 {
152  Tree tbl, size, idx, wrt, content, oldid;
153 
154  if ( isSigWRTbl(exp, oldid, tbl, idx, wrt) ) {
155  /* Ce qui ne peut pas être partagé, ce sont les
156  tables dans lesquelles on ecrit. Pour cela
157  on leur donne un label unique
158  */
159  return sigWRTbl(newid, tbl, idx, wrt);
160 
161  } else if ( isSigTable(exp, oldid, size, content) ) {
162  /* Rien à privatiser dans une table (car size est
163  censée etre une expression entiere)
164  */
165  return sigTable(newid, size, content);
166 
167  } else {
168 
169  printf("erreur labelize\n");
170  exit(1);
171  }
172 
173  return exp;
174 }
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
bool isSigTable(Tree t, Tree &id, Tree &n, Tree &sig)
Definition: signals.cpp:85
bool isSigWRTbl(Tree u, Tree &id, Tree &t, Tree &i, Tree &s)
Definition: signals.cpp:81
Tree sigWRTbl(Tree id, Tree t, Tree i, Tree s)
Definition: signals.cpp:80
Tree sigTable(Tree id, Tree n, Tree sig)
Definition: signals.cpp:84

Here is the call graph for this function:

Here is the caller graph for this function:

static Tree makePrivatisationKey ( const Tree t)
static

Definition at line 54 of file privatise.cpp.

References name(), tree(), and unique().

Referenced by privatise().

55 {
56  char name[256];
57  snprintf(name, 256, "PRIVATISE %p : ", (CTree*)t);
58  return tree(unique(name));
59 }
Symbol * unique(const char *str)
Returns a new unique symbol of name strxxx.
Definition: symbol.hh:97
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
const char * name(Symbol *sym)
Returns the name of a symbol.
Definition: symbol.hh:98
Tree tree(const Node &n)
Definition: tree.hh:186

Here is the call graph for this function:

Here is the caller graph for this function:

static Tree makePrivatisationLabel ( const Tree exp)
static

Definition at line 61 of file privatise.cpp.

References name(), tree(), and unique().

Referenced by computePrivatisation().

62 {
63  char name[256];
64  snprintf(name, 256, "OWNER IS %p : ", (CTree*)t);
65  return tree(unique(name));
66 }
Symbol * unique(const char *str)
Returns a new unique symbol of name strxxx.
Definition: symbol.hh:97
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
const char * name(Symbol *sym)
Returns the name of a symbol.
Definition: symbol.hh:98
Tree tree(const Node &n)
Definition: tree.hh:186

Here is the call graph for this function:

Here is the caller graph for this function:

static Tree privatisation ( const Tree k,
const Tree t 
)
static

Definition at line 71 of file privatise.cpp.

References CTree::arity(), computePrivatisation(), getProperty(), isNil(), nil, and setProperty().

Referenced by computePrivatisation(), and privatise().

72 {
73  Tree v;
74 
75  if (t->arity() == 0) {
76  return t;
77 
78  } else if (getProperty(t, k, v)) {
79  /* Terme deja visité. La propriété nous indique
80  la version privatisée ou nil si elle est identique
81  au terme initial.
82  */
83  return isNil(v) ? t : v;
84 
85  } else {
86  /* Calcul du terme privatisé et mis à jour
87  de la propriété. Nil indique que le terme
88  privatisé est identique à celui de depart
89  (pour eviter les boucles avec les compteurs
90  de references)
91  */
92  v = computePrivatisation(k,t);
93  if (v != t) {
94  setProperty(t, k, v );
95  } else {
96  setProperty(t, k, nil);
97  }
98  return v;
99  }
100 }
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
bool isNil(Tree l)
Definition: list.hh:137
int arity() const
return the number of branches (subtrees) of a tree
Definition: tree.hh:144
void setProperty(Tree t, Tree key, Tree val)
Definition: list.cpp:418
Tree nil
Definition: list.cpp:116
static Tree computePrivatisation(const Tree &k, const Tree &t)
Definition: privatise.cpp:102
bool getProperty(Tree t, Tree key, Tree &val)
Definition: list.cpp:423

Here is the call graph for this function:

Here is the caller graph for this function:

Tree privatise ( const Tree t)

Definition at line 45 of file privatise.cpp.

References makePrivatisationKey(), and privatisation().

Referenced by ScalarCompiler::prepare().

46 {
47 
48  return privatisation(makePrivatisationKey(t), t);
49 }
static Tree privatisation(const Tree &k, const Tree &t)
Definition: privatise.cpp:71
static Tree makePrivatisationKey(const Tree &t)
Definition: privatise.cpp:54

Here is the call graph for this function:

Here is the caller graph for this function: