updated lexer_lex and ir
[henge/webcc.git] / src / apc / ir.c
index fe613ba..5af236d 100644 (file)
@@ -50,17 +50,13 @@ extern
 struct vdat*
 curr_vdat(void);
 
-extern
-struct ele*
-curr_ele(void);
-
 extern
 struct set*
 curr_set(void);
 
 extern
 struct ref*
-prev_ref(void);
+curr_ref(void);
 
 extern
 struct quad*
@@ -108,7 +104,6 @@ void
 pop_cdat
 ()
 {
-  *cdat_stackp = NULL;
   cdat_stackp--;
 }
 
@@ -120,7 +115,8 @@ pop_cdat
    the curr_odat is going to be the last element and NOT the set that was first allocated.
    To get around this, we create a global variable set_odatp that will store the pointer
    to the odat when it is first allocated (in insert_set_label()) so that insert_set() can
-   have access to it. */
+   have access to it. Curr set points the sets representation in the cdat, curr_set_odatp
+   points to the sets representation as an odat*/
 
 void
 insert_set_label
@@ -128,6 +124,7 @@ insert_set_label
   uint64_t ref_id
 )
 {
+
   struct set* curr_setp;
 
   curr_setp = curr_set();
@@ -135,20 +132,31 @@ insert_set_label
 
   memmove(curr_set_odatp->name, name, 32);
   memmove(curr_setp->name, name, 32);
-  curr_setp->ref_id = ref_id;
+
+  if(ref_id != -1)
+    { curr_set_odatp->ref_id = ref_id;
+      curr_setp->ref_id = ref_id;
+    }
+  else
+    { curr_setp->ref_id = ss_ref_id;
+      curr_set_odatp->ref_id = ss_ref_id++;
+    }
 
 }
+
+/* Inserting a olink instead of a set. Set is really just a placeholder
+   for another set. Allocate the memory for the set so taht it can be populated*/
 void
 insert_set_olink
 ( uint64_t ref_id
 )
 {
-  struct set* curr_setp;
   struct cdat* curr_cdatp;
   struct link* curr_linkp;
+  struct odat* curr_setp;
 
-  curr_setp = curr_set();
   curr_cdatp = curr_cdat();
+  curr_setp = alloc_odat();
   curr_linkp = alloc_link();
 
   curr_setp->cdat_idx = curr_cdatp->idx;
@@ -156,7 +164,7 @@ insert_set_olink
                                           when link is processed */
   curr_linkp->type = 1;
   curr_linkp->link_t.olink.ref_id = ref_id;
-  curr_linkp->cdat_idx = curr_cdatp->idx;
+  curr_linkp->classp = curr_cdatp;
   curr_linkp->set_idx = curr_cdatp->num_sets++;
   curr_linkp->ele_idx = -1;
 
@@ -178,7 +186,7 @@ insert_set_vlink
      output time */
   curr_linkp->type = 2;
   curr_linkp->link_t.vlink.ref_id = ref_id;
-  curr_linkp->cdat_idx = curr_cdatp->idx;
+  curr_linkp->classp = curr_cdatp;
   curr_linkp->set_idx = curr_cdatp->num_sets;
   curr_linkp->ele_idx = -1;
   memmove(curr_linkp->link_t.vlink.anim_name, anim_name, 32);
@@ -200,7 +208,7 @@ insert_set_svlink
   /* Insert svlink into link_stack so that it gets processed at
      output time */
   curr_linkp->type = 3;
-  curr_linkp->cdat_idx = curr_cdatp->idx;
+  curr_linkp->classp = curr_cdatp;
   curr_linkp->set_idx = curr_cdatp->num_sets;
   curr_linkp->ele_idx = -1;
   curr_linkp->link_t.svlink.ref_id = ref_id;
@@ -225,7 +233,7 @@ insert_set
   curr_odatp = curr_set_odatp; //allocated at insert_set_label, preserved in global space
   curr_cdatp = curr_cdat();
   curr_setp = curr_set();
-  prev_refp = prev_ref();
+  prev_refp = curr_ref();
   curr_refp = alloc_ref();
   curr_vdatp = curr_vdat();
 
@@ -240,11 +248,6 @@ insert_set
 
   ref_id = curr_setp->ref_id; // ref_id set by insert_set_label(name, ref_id)
 
-  if(ref_id == -1) /* user did not define a ref_id  */
-    { ref_id = ss_ref_id;
-      ss_ref_id++;
-    }
-
   curr_refp->ref_id = ref_id;
   curr_refp->lastref = prev_refp;
   curr_refp->odatp = curr_odatp;
@@ -260,28 +263,34 @@ void
 insert_set_vdatid
 ()
 {
+  struct vdat* curr_vdatp;
+
+  curr_vdatp = curr_vdat();
+
   curr_set_odatp->vdat_id = num_vdats; //no vdat_id for odats that have vlinks/svlinks
-  curr_set_odatp = NULL; //So this sets odat cant be modified after (which would be a bug)
+  curr_set_odatp->vdatp = curr_vdatp;
+  curr_set_odatp = NULL; //This sets odat shouldnt be modified after populating odats vdat info
 }
 
-/* Populates both the odat name and ref_id
  for odat and ele */
+/* Populates the odat name and ref_id for odat, allocate the odat here for the rest of
the functions to use via curr_odat(). */
 void
 insert_ele_label
 ( char* name,
   uint64_t ref_id
 )
 {
-  struct ele* curr_elep;
   struct odat* curr_odatp;
 
-  curr_elep = curr_ele();
   curr_odatp = alloc_odat();
 
   memmove(curr_odatp->name, name, 32);
 
-  memmove(curr_elep->name, name, 32);
-  curr_elep->ref_id = ref_id;
+  if(ref_id != -1)
+    curr_odatp->ref_id = ref_id;
+  else
+    curr_odatp->ref_id = ss_ref_id++;
+
 }
 
 /* We don't make an odat here, at output time we will resolve
@@ -297,17 +306,17 @@ insert_ele_olink
   struct link* curr_linkp;
 
   curr_cdatp = curr_cdat();
-  curr_elep = curr_ele();
+  //curr_elep = curr_ele();
   curr_linkp = alloc_link();
 
-  curr_elep->cdat_idx = curr_cdatp->idx;
-  curr_elep->ref_id = ref_id;
+  //curr_elep->cdat_idx = curr_cdatp;
+  //curr_elep->ref_id = ref_id;
 
   curr_linkp->type = 1;
   curr_linkp->link_t.olink.ref_id = ref_id;
-  curr_linkp->cdat_idx = curr_cdatp->idx;
+  curr_linkp->classp = curr_cdatp;
   curr_linkp->set_idx = curr_cdatp->num_sets++;
-  curr_linkp->ele_idx = curr_setp->num_ele++;
+  //curr_linkp->ele_idx = curr_setp->num_ele++;
 
 }
 
@@ -327,10 +336,10 @@ insert_ele_vlink
 
   /* Insert vlink into link_stack so that it gets processed at
      output time */
-  curr_linkp->cdat_idx = curr_cdatp->idx;
+  curr_linkp->classp = curr_cdatp;
   curr_linkp->type = 2;
   curr_linkp->set_idx = curr_cdatp->num_sets;
-  curr_linkp->ele_idx = curr_setp->num_ele;
+  //curr_linkp->ele_idx = curr_setp->num_ele;
   curr_linkp->link_t.vlink.ref_id = ref_id;
   memmove(curr_linkp->link_t.vlink.anim_name, anim_name, 32);
 
@@ -349,10 +358,10 @@ insert_ele_svlink
   curr_setp = curr_set();
   curr_linkp = alloc_link();
 
-  curr_linkp->cdat_idx = curr_cdatp->idx;
+  curr_linkp->classp = curr_cdatp;
   curr_linkp->type = 3;
 
-  curr_linkp->ele_idx = curr_setp->num_ele;
+  //curr_linkp->ele_idx = curr_setp->num_ele;
   curr_linkp->link_t.svlink.ref_id = ref_id;
 
 
@@ -372,30 +381,19 @@ insert_ele()
   struct ref* prev_refp;
 
 
-  curr_cdatp = curr_cdat();
   curr_odatp = curr_odat(); //malloced @ insert_ele_label
   curr_vdatp = curr_vdat();
   curr_setp = curr_set();
-  curr_elep = curr_ele();
+  prev_refp = curr_ref();
   curr_refp = alloc_ref();
-  prev_refp = prev_ref();
 
   curr_vdatp->creator = curr_odatp;
-  /* Populate ele in cdat */
-  curr_elep->cdat_idx = curr_cdatp->idx;
-  curr_setp->num_ele++;
 
   /* Populate odat for ele */
   curr_odatp->cdat_idx = curr_cdatp->idx;
   curr_odatp->refp = curr_refp;
 
-  /* Add ele to ref_buf */
-  ref_id = curr_elep->ref_id;
-
-  if(ref_id == -1) /* user did not define a ref_id so */
-    { ref_id = ss_ref_id;
-      ss_ref_id++;
-    }
+  ref_id = curr_odatp->ref_id;
 
   curr_refp->ref_id = ref_id;
   curr_refp->lastref = prev_refp;
@@ -417,18 +415,6 @@ insert_quad
 ( void* quad_filep
 )
 {
-
-  /* struct quad* curr_quadp; */
-  /* struct odat* curr_odatp; */
-
-  /* curr_quadp = curr_quad(); */
-  /* curr_odatp = curr_odat(); */
-
-  /* curr_quadp->x = x; */
-  /* curr_quadp->y = y; */
-  /* curr_quadp->z = z; */
-  /* curr_quadp->ref_id = ref_id; */
-  /* curr_odatp->num_quads++; */
   struct odat* curr_odatp;
 
   curr_odatp->quad_filep = quad_filep;