PIPS
genSML.c File Reference
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include "newgen_include.h"
#include "genC.h"
+ Include dependency graph for genSML.c:

Go to the source code of this file.

Macros

#define GEN_HEADER   2
 For simplicity, the tabulation slot is always here. More...
 
#define IS_NON_INLINABLE_BASIS(f)   (strcmp(f,"chunk")==0)
 
#define UPPER(c)   ((islower( c )) ? toupper( c ) : c )
 
#define TYPE(bp)   (bp-Domains-Number_imports-Current_start)
 
#define OR_TAG_OFFSET   2
 

Functions

int gen_size (bp)
 GEN_SIZE returns the size (in gen_chunks) of an object of type defined by the BP type. More...
 
static char * primitive_field (dp)
 PRIMITIVE_FIELD returns the appropriate field to acces an object in BP. More...
 
static void gen_member (name, dp, offset)
 GEN_MEMBER generates a member access functions for domain DP and OFFSET. More...
 
static char * gen_arg (dp)
 GEN_ARG returns the constructor name of domain DP. More...
 
static char * gen_args (dlp)
 GEN_ARGS returns a comma-separated list of constructor names for the list of domains DLP. More...
 
static char * gen_update_arg (dp, index)
 
static char * gen_update_args (dlp)
 GEN_UPDATE_ARGS returns a comma-separated list of constructor names for the list of domains DLP. More...
 
static void gen_make (bp, size, char *args, char *updated_args, char *option_name)
 GEN_MAKE generates the gen_alloc call for gen_bindings BD with SIZE user members and ARGS as list of arguments. More...
 
void gen_and (bp)
 GEN_AND generates the manipulation functions for an AND type BP. More...
 
void gen_or (bp)
 GEN_OR generates the manipulation function for an OR_OP type BP. More...
 
void gen_list (bp)
 GEN_LIST defines the manipulation functions for a list type BP. More...
 
void gen_set (bp)
 GEN_SET defines the manipulation functions for a set type BP. More...
 
void gen_array (bp)
 GEN_ARRAY defines the manipulation functions for an array type BP. More...
 
void gen_external (bp)
 GEN_EXTERNAL defines the acces functions for an external type BP. More...
 
void gen_domain (bp)
 GEN_DOMAIN generates the manipulation functions for a type BP. More...
 
void gencode (file)
 GENCODE generates the code necessary to manipulate every internal and non-inlinable type in the Domains table. More...
 

Variables

static char start [1024]
 
int Read_spec_mode
 extern int Current_first ; More...
 
struct gen_bindingTabulated_bp
 

Macro Definition Documentation

◆ GEN_HEADER

#define GEN_HEADER   2

For simplicity, the tabulation slot is always here.

Definition at line 34 of file genSML.c.

◆ IS_NON_INLINABLE_BASIS

#define IS_NON_INLINABLE_BASIS (   f)    (strcmp(f,"chunk")==0)

Definition at line 36 of file genSML.c.

◆ OR_TAG_OFFSET

#define OR_TAG_OFFSET   2

Definition at line 40 of file genSML.c.

◆ TYPE

#define TYPE (   bp)    (bp-Domains-Number_imports-Current_start)

Definition at line 38 of file genSML.c.

◆ UPPER

#define UPPER (   c)    ((islower( c )) ? toupper( c ) : c )

Definition at line 37 of file genSML.c.

Function Documentation

◆ gen_and()

void gen_and ( bp  )

GEN_AND generates the manipulation functions for an AND type BP.

Definition at line 230 of file genSML.c.

232 {
233  union domain *dom = bp->domain ;
234  struct domainlist *dlp ;
235  int size ;
236 
237  gen_make(bp, gen_size(bp)-GEN_HEADER,
238  gen_args(dom->co.components),
240  "") ;
241  size = GEN_HEADER ;
242 
243  for( dlp=dom->co.components ; dlp != NULL ; dlp=dlp->cdr )
244  gen_member( bp->name, dlp->domain, size++ ) ;
245 }
int gen_size(bp)
GEN_SIZE returns the size (in gen_chunks) of an object of type defined by the BP type.
Definition: genSML.c:52
#define GEN_HEADER
For simplicity, the tabulation slot is always here.
Definition: genSML.c:34
static void gen_make(bp, size, char *args, char *updated_args, char *option_name)
GEN_MAKE generates the gen_alloc call for gen_bindings BD with SIZE user members and ARGS as list of ...
Definition: genSML.c:202
static void gen_member(name, dp, offset)
GEN_MEMBER generates a member access functions for domain DP and OFFSET.
Definition: genSML.c:122
static char * gen_update_args(dlp)
GEN_UPDATE_ARGS returns a comma-separated list of constructor names for the list of domains DLP.
Definition: genSML.c:185
static char * gen_args(dlp)
GEN_ARGS returns a comma-separated list of constructor names for the list of domains DLP.
Definition: genSML.c:156
A DOMAIN union describes the structure of a user type.
struct domainlist * components
struct domain::@7 co

References domain::co, domain::components, gen_binding::domain, gen_args(), GEN_HEADER, gen_make(), gen_member(), gen_size(), gen_update_args(), and gen_binding::name.

Referenced by gen_domain().

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

◆ gen_arg()

static char* gen_arg ( dp  )
static

GEN_ARG returns the constructor name of domain DP.

Definition at line 141 of file genSML.c.

143 {
144  return( (dp->ba.type == BASIS_DT) ? dp->ba.constructor :
145  (dp->ba.type == LIST_DT) ? dp->li.constructor :
146  (dp->ba.type == SET_DT) ? dp->se.constructor :
147  (dp->ba.type == ARRAY_DT) ? dp->ar.constructor :
148  (fatal( "gen_arg: Unknown type %s\n", i2a( dp->ba.type )),
149  (char *)NULL) ) ;
150 }
char * i2a(int)
I2A (Integer TO Ascii) yields a string for a given Integer.
Definition: string.c:121
@ SET_DT
@ ARRAY_DT
@ LIST_DT
@ BASIS_DT
void fatal(char *,...)

References domain::ar, ARRAY_DT, domain::ba, BASIS_DT, domain::constructor, fatal(), i2a(), domain::li, LIST_DT, domain::se, SET_DT, and domain::type.

Referenced by gen_args(), and gen_update_arg().

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

◆ gen_args()

static char* gen_args ( dlp  )
static

GEN_ARGS returns a comma-separated list of constructor names for the list of domains DLP.

Definition at line 156 of file genSML.c.

158 {
159  static char buffer[ 1024 ] ;
160 
161  for( sprintf( buffer, "" ) ; dlp->cdr != NULL ; dlp = dlp->cdr ) {
162  strcat( buffer, gen_arg( dlp->domain )) ;
163  strcat( buffer, ", " ) ;
164  }
165  strcat( buffer, gen_arg( dlp->domain )) ;
166  return( buffer ) ;
167 }
static char * gen_arg(dp)
GEN_ARG returns the constructor name of domain DP.
Definition: genSML.c:141
static string buffer
Definition: string.c:113

References buffer, and gen_arg().

Referenced by gen_and().

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

◆ gen_array()

void gen_array ( bp  )

GEN_ARRAY defines the manipulation functions for an array type BP.

Definition at line 314 of file genSML.c.

316 {
317  extern int printf();
318  char *name = bp->name ;
319  union domain *dom = bp->domain ;
320  int data = GEN_HEADER ;
321 
322  gen_make(bp, 1, dom->ar.constructor, gen_update_arg(dom, 2), "");
323  (void) printf("fun %s_%s (vector ar) = ", name, dom->ar.constructor ) ;
324  (void) printf("(sub (ar,%d));\n", data) ;
325 }
static char * gen_update_arg(dp, index)
Definition: genSML.c:170
int printf()
char * constructor
struct domain::@6 ar

References domain::ar, domain::constructor, gen_binding::domain, GEN_HEADER, gen_make(), gen_update_arg(), gen_binding::name, and printf().

Referenced by gen_domain().

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

◆ gen_domain()

void gen_domain ( bp  )

GEN_DOMAIN generates the manipulation functions for a type BP.

This is manily a dispatching function.

Definition at line 342 of file genSML.c.

344 {
345  extern int printf();
346  union domain *dp = bp->domain ;
347  char *s = bp->name ;
348 
349  if( !IS_EXTERNAL( bp )) {
350  (void) printf( "type %s = chunk;\n", bp->name ) ;
351  (void) printf( "val %s_undefined = (undefined:%s);\n",
352  bp->name, bp->name ) ;
353  (void) printf( "fun write_%s fd obj = gen_write fd obj;\n",
354  bp->name ) ;
355  (void) printf( "fun read_%s fd = (gen_read fd):%s;\n",
356  bp->name, bp->name ) ;
357  }
358  switch( dp->ba.type ) {
359  case CONSTRUCTED_DT:
360  switch( dp->co.op ) {
361  case AND_OP:
362  gen_and( bp ) ;
363  break ;
364  case OR_OP:
365  gen_or( bp ) ;
366  break ;
367  default:
368  fatal( "gen_domain: Unknown constructed %s\n", i2a( dp->co.op )) ;
369  }
370  break ;
371  case LIST_DT:
372  gen_list( bp ) ;
373  break ;
374  case SET_DT:
375  gen_set( bp ) ;
376  break ;
377  case ARRAY_DT:
378  gen_array( bp ) ;
379  break ;
380  case EXTERNAL_DT:
381  gen_external( bp ) ;
382  break ;
383  default:
384  fatal( "gen_domain: Unknown type %s\n", i2a( dp->ba.type )) ;
385  }
386 }
void gen_external(bp)
GEN_EXTERNAL defines the acces functions for an external type BP.
Definition: genSML.c:332
void gen_list(bp)
GEN_LIST defines the manipulation functions for a list type BP.
Definition: genSML.c:289
void gen_or(bp)
GEN_OR generates the manipulation function for an OR_OP type BP.
Definition: genSML.c:252
void gen_and(bp)
GEN_AND generates the manipulation functions for an AND type BP.
Definition: genSML.c:230
void gen_array(bp)
GEN_ARRAY defines the manipulation functions for an array type BP.
Definition: genSML.c:314
void gen_set(bp)
GEN_SET defines the manipulation functions for a set type BP.
Definition: genSML.c:305
@ OR_OP
@ AND_OP
#define IS_EXTERNAL(bp)
@ EXTERNAL_DT
@ CONSTRUCTED_DT
enum domain_operator op
int type
EXTERNAL.
struct domain::@3 ba

References AND_OP, ARRAY_DT, domain::ba, domain::co, CONSTRUCTED_DT, gen_binding::domain, EXTERNAL_DT, fatal(), gen_and(), gen_array(), gen_external(), gen_list(), gen_or(), gen_set(), i2a(), IS_EXTERNAL, LIST_DT, gen_binding::name, domain::op, OR_OP, printf(), SET_DT, and domain::type.

Referenced by gencode().

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

◆ gen_external()

void gen_external ( bp  )

GEN_EXTERNAL defines the acces functions for an external type BP.

The TYPEDEF has to be added by the user, but should be castable to a string (char *).

Definition at line 332 of file genSML.c.

334 {
335  fprintf( stderr, "External: too be implemented\n" ) ;
336 }
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...

References fprintf().

Referenced by gen_domain().

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

◆ gen_list()

void gen_list ( bp  )

GEN_LIST defines the manipulation functions for a list type BP.

Definition at line 289 of file genSML.c.

291 {
292  extern int printf();
293  char *name = bp->name ;
294  union domain *dom = bp->domain ;
295  int data = GEN_HEADER ;
296 
297  gen_make(bp, 1, dom->li.constructor, gen_update_arg(dom, 2), "") ;
298  (void) printf("fun %s_%s (vector li) = ", name, dom->li.constructor ) ;
299  (void) printf("(sub (li,%d));\n", data) ;
300 }
struct domain::@4 li

References domain::constructor, gen_binding::domain, GEN_HEADER, gen_make(), gen_update_arg(), domain::li, gen_binding::name, and printf().

Referenced by gen_domain().

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

◆ gen_make()

static void gen_make ( bp  ,
size  ,
char *  args,
char *  updated_args,
char *  option_name 
)
static

GEN_MAKE generates the gen_alloc call for gen_bindings BD with SIZE user members and ARGS as list of arguments.

Definition at line 202 of file genSML.c.

206 {
207  extern int printf();
208 
209  (void) printf("fun make_%s%s%s (%s) =", bp->name,
210  (strcmp(option_name, "") == 0 ? "" : "_"), option_name,
211  args) ;
212  (void) printf(" let val gen_v = array(%d+%d, undefined) in\n",
213  GEN_HEADER, size);
214  (void) printf(" update(gen_v, 0, int (%s+%d));\n", start, TYPE(bp)) ;
215  (void) printf(" %s\n", updated_args);
216 
217  if( IS_TABULATED( bp )) {
218  fprintf(stderr, "enter_tabulated not called\n");
219  }
220  (void) printf(" vector gen_v end:%s;\n", bp->name) ;
221 
222  if( IS_TABULATED( bp )) {
223  printf( "val %s_domain = %s+%d;\n", bp->name, start, TYPE( bp )) ;
224  }
225 }
static char start[1024]
Definition: genSML.c:42
#define TYPE(bp)
Definition: genSML.c:38
#define IS_TABULATED(bp)

References fprintf(), GEN_HEADER, IS_TABULATED, gen_binding::name, printf(), gen_binding::size, start, and TYPE.

Referenced by gen_and(), gen_array(), gen_list(), and gen_or().

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

◆ gen_member()

static void gen_member ( name  ,
dp  ,
offset   
)
static

GEN_MEMBER generates a member access functions for domain DP and OFFSET.

NAME is the domain of the defined domain.

Definition at line 122 of file genSML.c.

126 {
127  char *field = primitive_field( dp ) ;
128 
129  if( dp->ba.type == BASIS_DT &&
130  strcmp( dp->ba.constructand->name, UNIT_TYPE_NAME ) == 0 )
131  return ;
132 
133  (void) printf( "fun %s_%s (vector node) = ", name, dp->ba.constructor ) ;
134  (void) printf("case (sub (node,%d)) of (%s x) => x;\n",
135  offset, field) ;
136 }
static Value offset
Definition: translation.c:283
static char * primitive_field(dp)
PRIMITIVE_FIELD returns the appropriate field to acces an object in BP.
Definition: genSML.c:84
#define UNIT_TYPE_NAME
The UNIT_TYPE_NAME is the used to type expressions which only perform side-effects.
return(s1)

References domain::ba, BASIS_DT, domain::constructand, domain::constructor, gen_binding::name, offset, primitive_field(), printf(), return(), domain::type, and UNIT_TYPE_NAME.

Referenced by gen_and(), and gen_or().

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

◆ gen_or()

void gen_or ( bp  )

GEN_OR generates the manipulation function for an OR_OP type BP.

Note that for a UNIT_TYPE_NAME, no access function is defined since the value is meaningless.

Definition at line 252 of file genSML.c.

254 {
255  extern int printf();
256  char *name = bp->name ;
257  union domain *dom = bp->domain ;
258  struct domainlist *dlp ;
259  int offset ;
260 
261  (void) printf("fun %s_tag (vector or) = ", name ) ;
262  (void) printf("case (sub (or,%d)) of (int x) => x;\n",
263  GEN_HEADER) ;
264 
265  for( dlp=dom->co.components,offset=dom->co.first ;
266  dlp != NULL ;
267  dlp=dlp->cdr, offset++ ) {
268  union domain *dp = dlp->domain ;
269  static char args[ 1024 ] ;
270  static char updated_args[ 1024 ] ;
271 
272  sprintf(args, "tag, %s", dp->ba.constructor ) ;
273  strcpy(updated_args, "update(gen_v, 2, int tag);") ;
274  gen_make(bp, 2,args ,
275  strcat(updated_args, gen_update_arg(dp, 3)),
276  dp->ba.constructor);
277  (void) printf("val is_%s_%s = %d;\n",
278  name, dp->ba.constructor, offset ) ;
279  (void) printf("fun %s_%s_p or = ((%s_tag or)=is_%s_%s);\n",
280  name, dp->ba.constructor, name,
281  name, dp->ba.constructor ) ;
282  gen_member( name, dp, OR_TAG_OFFSET ) ;
283  }
284 }
#define OR_TAG_OFFSET
Definition: genSML.c:40

References domain::ba, domain::co, domain::components, domain::constructor, gen_binding::domain, domain::first, GEN_HEADER, gen_make(), gen_member(), gen_update_arg(), gen_binding::name, offset, OR_TAG_OFFSET, and printf().

Referenced by gen_domain().

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

◆ gen_set()

void gen_set ( bp  )

GEN_SET defines the manipulation functions for a set type BP.

Definition at line 305 of file genSML.c.

307 {
308  fprintf( stderr, "Set: too be implemented\n" ) ;
309 }

References fprintf().

Referenced by gen_domain().

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

◆ gen_size()

int gen_size ( bp  )

GEN_SIZE returns the size (in gen_chunks) of an object of type defined by the BP type.

OTREACHED

Definition at line 52 of file genSML.c.

54 {
55  int overhead = GEN_HEADER ;
56 
57  switch( bp->domain->ba.type ) {
58  case BASIS_DT:
59  case ARRAY_DT:
60  case LIST_DT:
61  case SET_DT:
62  return( overhead + 1 ) ;
63  case CONSTRUCTED_DT:
64  if( bp->domain->co.op == OR_OP )
65  return( overhead + 2 ) ;
66  else {
67  int size ;
68  struct domainlist *dlp = bp->domain->co.components ;
69 
70  for( size=0 ; dlp != NULL ; dlp=dlp->cdr, size++ )
71  ;
72  return( overhead + size ) ;
73  }
74  default:
75  fatal( "gen_size: Unknown type %s\n", i2a( bp->domain->ba.type )) ;
76  /*NOTREACHED*/
77  }
78 }

References ARRAY_DT, domain::ba, BASIS_DT, domain::co, domain::components, CONSTRUCTED_DT, gen_binding::domain, fatal(), GEN_HEADER, i2a(), LIST_DT, domain::op, OR_OP, SET_DT, gen_binding::size, and domain::type.

Referenced by gen_and().

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

◆ gen_update_arg()

static char* gen_update_arg ( dp  ,
index   
)
static

Definition at line 170 of file genSML.c.

173 {
174  static char arg[ 1024 ] ;
175 
176  sprintf(arg, "update(gen_v, %d, %s %s);", index,
177  primitive_field(dp), gen_arg(dp));
178  return(arg) ;
179 }

References gen_arg(), and primitive_field().

Referenced by gen_array(), gen_list(), gen_or(), and gen_update_args().

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

◆ gen_update_args()

static char* gen_update_args ( dlp  )
static

GEN_UPDATE_ARGS returns a comma-separated list of constructor names for the list of domains DLP.

Definition at line 185 of file genSML.c.

187 {
188  static char buffer[ 1024 ] ;
189  int index = GEN_HEADER ;
190 
191  for( sprintf(buffer, "") ; dlp->cdr!=NULL ; dlp=dlp->cdr, index++ ) {
192  strcat(buffer, gen_update_arg(dlp->domain, index)) ;
193  }
194  strcat(buffer, gen_update_arg(dlp->domain, index)) ;
195  return( buffer ) ;
196 }

References buffer, GEN_HEADER, and gen_update_arg().

Referenced by gen_and().

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

◆ gencode()

void gencode ( file  )

GENCODE generates the code necessary to manipulate every internal and non-inlinable type in the Domains table.

Definition at line 392 of file genSML.c.

394 {
395  struct gen_binding *bp = Domains ;
396 
397  sprintf( start, "gen_%s_start", file ) ;
398 
399  for( ; bp < &Domains[ MAX_DOMAIN ] ; bp++ ) {
400  if(bp->name == NULL || IS_INLINABLE( bp ) || IS_IMPORT( bp ) ||
401  bp == Tabulated_bp )
402  continue ;
403 
404  gen_domain( bp ) ;
405  }
406 }
struct gen_binding * Tabulated_bp
Definition: genSML.c:46
void gen_domain(bp)
GEN_DOMAIN generates the manipulation functions for a type BP.
Definition: genSML.c:342
struct gen_binding Domains[MAX_DOMAIN]
in build.c
Definition: genspec_yacc.c:114
#define IS_INLINABLE(bp)
Different kinds of BINDING structure pointers.
#define MAX_DOMAIN
MAX_DOMAIN is the maximum number of entries in the DOMAINS table.
#define IS_IMPORT(bp)

References Domains, gen_domain(), IS_IMPORT, IS_INLINABLE, MAX_DOMAIN, gen_binding::name, start, and Tabulated_bp.

+ Here is the call graph for this function:

◆ primitive_field()

static char* primitive_field ( dp  )
static

PRIMITIVE_FIELD returns the appropriate field to acces an object in BP.

Note how inlined types are managed (see genC.h comments).

OTREACHED

Definition at line 84 of file genSML.c.

86 {
87  static char buffer[ 1024 ];
88 
89  switch( dp->ba.type ) {
90  case BASIS_DT: {
91  struct gen_binding *bp = dp->ba.constructand ;
92 
93  if( IS_INLINABLE( bp )) {
94  sprintf( buffer, "%s", bp->name ) ;
95  }
96  else if( IS_EXTERNAL( bp )) {
97  fprintf(stderr, "primitive_field not implemented\n");
98  }
99  else sprintf( buffer, "chunk" ) ;
100  break ;
101  }
102  case LIST_DT:
103  sprintf( buffer, "list" ) ;
104  break ;
105  case SET_DT:
106  sprintf( buffer, "set" ) ;
107  break ;
108  case ARRAY_DT:
109  sprintf( buffer, "vector" ) ;
110  break ;
111  default:
112  fatal( "primitive_field: Unknown type %s\n", i2a( dp->ba.type )) ;
113  /*NOTREACHED*/
114  }
115  return( buffer ) ;
116 }

References ARRAY_DT, domain::ba, BASIS_DT, buffer, domain::constructand, fatal(), fprintf(), i2a(), IS_EXTERNAL, IS_INLINABLE, LIST_DT, gen_binding::name, SET_DT, and domain::type.

Referenced by gen_member(), and gen_update_arg().

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

Variable Documentation

◆ Read_spec_mode

int Read_spec_mode

extern int Current_first ;

Definition at line 44 of file genSML.c.

◆ start

char start[1024]
static

Definition at line 42 of file genSML.c.

Referenced by gen_make(), and gencode().

◆ Tabulated_bp

struct gen_binding* Tabulated_bp

Definition at line 46 of file genSML.c.

Referenced by gencode().