ir files compile, still a wip
[henge/webcc.git] / src / apc / ir.c
index 10aede8..c5c4125 100644 (file)
@@ -1,90 +1,76 @@
 #include <errno.h>
-#include <ir.h>
+#include <stdio.h>
+#include <string.h>
+#include <apc/ir.h>
 
-#define CURR_OBI (OB[obi])
-#define CURR_VBI (VB[vbi])
-#define CURR_CBI (CB[cbi])
-#define IS_SUBCLASS() (CB[cbi].num_subclasses)
+#define CURR_ODAT (odat_buf[obi])
+#define CURR_VDAT (vdat_buf[vbi])
+#define CURR_CDAT (cdat_buf[cbi]) //more like the base cdat
 
 //TODO: label and vdat_id
 void
 insert_set()
 {
-  if(IS_SUBCLASS()) //if set is set of subclass
-    OB[obi].class_id = CB[cbi].subclass_list[subclass_index].label; //TODO: specify subclass other than label?
-  else
-    OB[obi].class_id = CB[cbi].label;
-
-  CB[cbi].set_list[set_index].odat_id = obi;
-  CB[cbi].set_list[set_index].parent_id = OB[obi].class_id;
+  CURR_CDAT.set_list[CURR_CDAT.set_index].odat_id = obi;
+  CURR_CDAT.set_list[CURR_CDAT.set_index].parent_id = 0;//from lexer
   //TODO: add ele_stack is created in element_list
-  //TODO: add odat
+  //TODO: add set to odat_buf
 
 }
 
-#define CURR_QUAD (OB[obi].ref_list[ref_index])
+#define CURR_QUAD (CURR_ODAT.ref_list[CURR_ODAT.ref_index])
 void
 insert_ref(int x, int y, int z, int ref)
 {
   CURR_QUAD.x = x;
   CURR_QUAD.y = y;
   CURR_QUAD.z = z;
-  CURR_QUAD.ref = ref;
+  CURR_QUAD.objref = ref;
 }
 
 
-//Insert element into OB and CB
+//Insert element into odat_buf and cdat_buf
 void
 insert_ele(char* label, int vdat_id)
 {
 
 
-  OB[obi].label = label;
-  OB[obi].vdat_id = vdat_id;
+  memmove(CURR_ODAT.label,label,32);
+  CURR_ODAT.vdat_id = vdat_id;
   //TODO: check set_obi to see if set_map_data exists
-  OB[obi].num_ref = OB[set_obi].num_ref;
-  OB[obi].ref_list = OB[set_obi].ref_list;
-  OB[obi].class_id = cbi;
-
-  if(IS_SUBCLASS())
-    {
-      CB[cbi].subclass_list[subclass_index].set_list[set_index].ele_list[ele_index].odat_id = obi;
-      CB[cbi].subclass_list[subclass_index].set_list[set_index].ele_list[ele_index].parent_id = CB[cbi].subclass_list[subclass_index].set_index;
-    }
-  else
-    {
-      CB[cbi].set_list[set_index].ele_list[ele_index].odat_id = obi;
-      CB[cbi].set_list[set_index].ele_list[ele_index].parent_id = CB[cbi].set_index;
-    }
+  //comes from e
+  //CURR_ODAT.num_ref = //comes from its set
+  //CURR_ODAT.ref_list = //comes from its set
+  //CURR_ODAT.class_id = //comes from lexer?
 
   obi++;
 }
 
 
 /* fd could be a directory entry */
-int
+void
 insert_fdat(char* label, char direction, int fd)
 {
-  VB[vbi].model_list[VB[vbi].len].label = label;
-  VB[vbi].model_list[VB[vbi].len].fdat_id[(int)direction] = fd;
+  memmove(CURR_VDAT.model_list[CURR_VDAT.num_models].label,label,32);
+  CURR_VDAT.model_list[CURR_VDAT.num_models].fdat_id[(int)direction] = fd;
 }
 
 void
 condense()
 {
-  FILE* vp, op, cp;
+  FILE *vp, *op, *cp;
   int v, m;
   int num_models;
 
-  vp = fopen("vdat_output", w+);
+  vp = fopen("vdat_output", "w+");
   if(!vp)
     perror("vdat_output failed to open\n");
 
-  op = fopen("odat_output", w+);
+  op = fopen("odat_output", "w+");
   if(!op)
     perror("odat_output failed to open\n");
 
-  cp = fopen("cdat_output", w+);
+  cp = fopen("cdat_output", "w+");
   if(!cp)
     perror("cdat_output failed to open\n");
 
@@ -93,7 +79,7 @@ condense()
   /* fwrite vdat */
   for(v = 0; v <= vbi; v++)
     {
-      num_models = VB[v].num_models; //data duplication for caching
+      num_models = vdat_buf[v].num_models; //data duplication for caching
       for(m = 0; m <= num_models; m++)
         {
             
@@ -107,4 +93,48 @@ condense()
 
 
 }
+void
+inc_cbi()
+{
+  cbi++;
+}
+
+void
+set_class_label(char* label)
+{
+  memmove(CURR_CDAT.label,label,32);
+}
 
+void
+inc_subclass_idx()
+{
+  CURR_CDAT.subclass_index++;
+}
+
+void
+inc_set_index()
+{
+  cdat_buf[cbi].set_index++;
+}
+
+void
+inc_ref()
+{
+  CURR_ODAT.ref_index++;
+  CURR_ODAT.num_ref++;
+}
+
+//TODO: This needs to be changed to account for
+//      when the set is of a subclass.
+void
+inc_ele()
+{
+  CURR_CDAT.set_list[CURR_CDAT.set_index].num_ele++;
+  vbi++;
+}
+
+void
+inc_models()
+{
+  CURR_VDAT.num_models++;
+}