ir files compile, still a wip
[henge/webcc.git] / src / apc / ir.c
index ffc1020..c5c4125 100644 (file)
@@ -1,29 +1,31 @@
 #include <errno.h>
-#include <ir.h> 
+#include <stdio.h>
+#include <string.h>
+#include <apc/ir.h>
 
-//#define CURR_ODAT (OB[obi])
-//#define CURR_VDAT (VB[vbi])
-//#define CURR_CDAT (CB[cbi])
+#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()
 {
-  cdat_buf[cbi].set_list[set_index].odat_id = obi;
-  cdat_buf[cbi].set_list[set_index].parent_id =//from lexer
+  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 set to odat_buf
 
 }
 
-#define CURR_QUAD (odat_buf[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;
 }
 
 
@@ -33,53 +35,42 @@ insert_ele(char* label, int vdat_id)
 {
 
 
-  odat_buf[obi].label = label;
-  odat_buf[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
   //comes from e
-  odat_buf[obi].num_ref = odat_buf[set_obi].num_ref;
-  odat_buf[obi].ref_list = odat_buf[set_obi].ref_list;
-  odat_buf[obi].class_id = cbi;
-
-  if(IS_SUBCLASS())
-    {
-      cdat_buf[cbi].subclass_list[subclass_index].set_list[set_index].ele_list[ele_index].odat_id = obi;
-      cdat_buf[cbi].subclass_list[subclass_index].set_list[set_index].ele_list[ele_index].parent_id = cdat_buf[cbi].subclass_list[subclass_index].set_index;
-    }
-  else
-    {
-      cdat_buf[cbi].set_list[set_index].ele_list[ele_index].odat_id = obi;
-      cdat_buf[cbi].set_list[set_index].ele_list[ele_index].parent_id = cdat_buf[cbi].set_index;
-    }
+  //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)
 {
-  vdat_buf[vbi].model_list[vdat_buf[vbi].len].label = label;
-  vdat_buf[vbi].model_list[vdat_buf[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");
 
@@ -111,26 +102,26 @@ inc_cbi()
 void
 set_class_label(char* label)
 {
-  cdat_buf[cbi].label = $1;
+  memmove(CURR_CDAT.label,label,32);
 }
 
 void
 inc_subclass_idx()
 {
-  cdat_buf[cbi].subclass_index++;
+  CURR_CDAT.subclass_index++;
 }
 
 void
 inc_set_index()
 {
-  odat_buf[cbi].set_index++;
+  cdat_buf[cbi].set_index++;
 }
 
 void
 inc_ref()
 {
-  odat_buf[obi].ref_index++;
-  odat_buf[obi].num_ref++;
+  CURR_ODAT.ref_index++;
+  CURR_ODAT.num_ref++;
 }
 
 //TODO: This needs to be changed to account for
@@ -138,11 +129,12 @@ inc_ref()
 void
 inc_ele()
 {
-  cdat_buf[cbi].set_stack[stack_index].num_ele++;
+  CURR_CDAT.set_list[CURR_CDAT.set_index].num_ele++;
+  vbi++;
 }
 
 void
 inc_models()
 {
-  vdat_buf[vbi].num_models++;
+  CURR_VDAT.num_models++;
 }