updated lexer_lex and ir
[henge/webcc.git] / src / apc / ir.c
index 8030755..5af236d 100644 (file)
@@ -56,7 +56,7 @@ curr_set(void);
 
 extern
 struct ref*
-prev_ref(void);
+curr_ref(void);
 
 extern
 struct quad*
@@ -104,7 +104,6 @@ void
 pop_cdat
 ()
 {
-  *cdat_stackp = NULL;
   cdat_stackp--;
 }
 
@@ -116,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
@@ -124,6 +124,7 @@ insert_set_label
   uint64_t ref_id
 )
 {
+
   struct set* curr_setp;
 
   curr_setp = curr_set();
@@ -131,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;
@@ -152,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;
 
@@ -174,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);
@@ -196,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;
@@ -221,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();
 
@@ -236,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;
@@ -256,12 +263,17 @@ 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,
@@ -273,7 +285,11 @@ insert_ele_label
   curr_odatp = alloc_odat();
 
   memmove(curr_odatp->name, name, 32);
-  curr_odatp->ref_id = ref_id;
+
+  if(ref_id != -1)
+    curr_odatp->ref_id = ref_id;
+  else
+    curr_odatp->ref_id = ss_ref_id++;
 
 }
 
@@ -293,12 +309,12 @@ insert_ele_olink
   //curr_elep = curr_ele();
   curr_linkp = alloc_link();
 
-  //curr_elep->cdat_idx = curr_cdatp->idx;
+  //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++;
 
@@ -320,7 +336,7 @@ 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;
@@ -342,7 +358,7 @@ 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;
@@ -368,8 +384,8 @@ insert_ele()
   curr_odatp = curr_odat(); //malloced @ insert_ele_label
   curr_vdatp = curr_vdat();
   curr_setp = curr_set();
+  prev_refp = curr_ref();
   curr_refp = alloc_ref();
-  prev_refp = prev_ref();
 
   curr_vdatp->creator = curr_odatp;
 
@@ -379,12 +395,6 @@ insert_ele()
 
   ref_id = curr_odatp->ref_id;
 
-
-  if(ref_id == -1) /* user did not define a ref_id so */
-    { ref_id = ss_ref_id;
-      ss_ref_id++;
-    }
-
   curr_refp->ref_id = ref_id;
   curr_refp->lastref = prev_refp;
   curr_refp->odatp = curr_odatp;
@@ -405,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;