-
-/* The initalization function of the IR. Mallocs the
- first c/v/odat and the first links and refs and
- inits the cdat_stack */
-void
-ir_init()
-{
-
- /* Init root cdat and stack */
- char root[4] = "root";
-
- cdat_buf[num_cdats] = (struct cdat*) malloc(sizeof(struct cdat) );
- cdat_buf[num_cdats]->idx = 0;
- memmove(cdat_buf[num_cdats]->name, root, 4);
-
- cdat_stackp = cdat_stack;
- *cdat_stackp = cdat_buf[num_cdats++];
-
- /* Init first odat */
- if( (CURR_ODAT = (struct odat*) malloc(sizeof(struct odat))) == NULL)
- perror("malloc first odat failed");
-
- /* init first vdat*/
- if( (CURR_VDAT = (struct vdat*) malloc(sizeof(struct vdat))) == NULL)
- perror("malloc first vdat failed");
-
- /* Init first ref */
- if( (CURR_REF = (struct ref*) malloc(sizeof(struct ref))) == NULL)
- perror("malloc first ref failed");
-
- /* Init first link */
- if( (CURR_LINK = (struct link*) malloc(sizeof(struct link))) == NULL)
- perror("malloc first link failed");
-
- /* Init first post */
- if( (CURR_POST = (struct ref*) malloc(sizeof(struct ref))) == NULL)
- perror("malloc first post failed");
-}
-
-//TODO: FREE MEMORY!
-void
-malloc_cdat()
-{
- if(curr_max_cdats <= num_cdats)
- { if( (realloc((void*) cdat_buf, PTRS_IN_PAGE * 4)) == NULL)
- perror("realloc cdat_buf failed");
- curr_max_cdats += PTRS_IN_PAGE;
- if( (realloc( (void*) cdat_stack, PTRS_IN_PAGE * 4)) == NULL) //increase cdat_stack also
- perror("realloc cdat_stack failed");
- }
- if( (cdat_buf[num_cdats] = (struct cdat*) malloc(sizeof (struct cdat)) ) == NULL )
- perror("malloc cdat failed");
-
-
-}
-
-/* Dynamically allocate memory for a class data structure,
- or cdat, after a class has been identified in a grammar.
- We also create a stack of class pointers so that
- we can access the cdat during processing of that
- cdats sets and elements, a requirement because the
- nature of recursive classes prevents us from accessing
- the cdat based on the previous index into cdat_buf,
- which is a list of all allocated cdats*/
-void
-push_cdat
-( char* name
-)
-{
- malloc_cdat();
-
- memmove(cdat_buf[num_cdats]->name, name, 32);
- cdat_buf[num_cdats]->idx = num_cdats;
-
- /* Set the cdat as a class of the previous cdat */
- (*cdat_stackp)->class_list[(*cdat_stackp)->num_classes++] = cdat_buf[num_cdats];
-
- /* Push the cdat onto the cdat_stack */
- *++cdat_stackp = cdat_buf[num_cdats++];
-
-}
-
-void
-pop_cdat
-()
-{
- *cdat_stackp = NULL;
- cdat_stackp--;
-}
-
-void
-inc_posts