parser wip pt2
authorjordan@hack_attack <jordanlavatai@gmail.com>
Tue, 30 Aug 2016 01:59:05 +0000 (18:59 -0700)
committerjordan@hack_attack <jordanlavatai@gmail.com>
Tue, 30 Aug 2016 01:59:05 +0000 (18:59 -0700)
src/apc/ir.c [new file with mode: 0644]
src/apc/ir.h [new file with mode: 0644]
src/apc/parser.y [moved from src/parser.y with 100% similarity]

diff --git a/src/apc/ir.c b/src/apc/ir.c
new file mode 100644 (file)
index 0000000..10aede8
--- /dev/null
@@ -0,0 +1,110 @@
+#include <errno.h>
+#include <ir.h>
+
+#define CURR_OBI (OB[obi])
+#define CURR_VBI (VB[vbi])
+#define CURR_CBI (CB[cbi])
+#define IS_SUBCLASS() (CB[cbi].num_subclasses)
+
+//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;
+  //TODO: add ele_stack is created in element_list
+  //TODO: add odat
+
+}
+
+#define CURR_QUAD (OB[obi].ref_list[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;
+}
+
+
+//Insert element into OB and CB
+void
+insert_ele(char* label, int vdat_id)
+{
+
+
+  OB[obi].label = label;
+  OB[obi].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;
+    }
+
+  obi++;
+}
+
+
+/* fd could be a directory entry */
+int
+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;
+}
+
+void
+condense()
+{
+  FILE* vp, op, cp;
+  int v, m;
+  int num_models;
+
+  vp = fopen("vdat_output", w+);
+  if(!vp)
+    perror("vdat_output failed to open\n");
+
+  op = fopen("odat_output", w+);
+  if(!op)
+    perror("odat_output failed to open\n");
+
+  cp = fopen("cdat_output", w+);
+  if(!cp)
+    perror("cdat_output failed to open\n");
+
+
+
+  /* fwrite vdat */
+  for(v = 0; v <= vbi; v++)
+    {
+      num_models = VB[v].num_models; //data duplication for caching
+      for(m = 0; m <= num_models; m++)
+        {
+            
+        }
+    }
+
+  /* fwrite odat */
+  /* Convert ref_list to actual offset */
+
+  /* fwrite cdat */
+
+
+}
+
diff --git a/src/apc/ir.h b/src/apc/ir.h
new file mode 100644 (file)
index 0000000..d4ab90b
--- /dev/null
@@ -0,0 +1,72 @@
+/* Structures allocated for and updated during parse time that
+   are the IR before writing to the output file */
+
+#define BUFF_SIZE 256
+#define MAX_SUBCLASSES 16
+#define MAX_SETS 256
+#define MAX_ELES 256
+#define MAX_REFS 256
+#define MAX_MODELS 256
+
+//These IR buffers will be condensed into their respective output files.
+//parse_init() all to zero.
+struct cdat CB[BUFF_SIZE];
+struct vdat VB[BUFF_SIZE];
+struct odat OB[BUFF_SIZE];
+
+//indexes for buffers
+int cbi = 0;
+int vbi = 0;
+int obi = 0;
+
+struct cdat {
+  char label[32];
+  int num_subclasses;
+  int num_sets;
+  int subclass_index;
+  int set_index;
+  struct cdat subclass_list[MAX_SUBCLASSES];
+  struct set set_list[MAX_SETS];
+};
+
+//Element or a set
+struct odat {
+  char label[32];
+  int vdat_id;
+  int class_id;
+  int num_ref;
+  int ref_index;
+  struct ref ref_list[MAX_REFS];
+};
+
+struct ref {
+  int x, y, z, objref;
+};
+
+struct set {
+  int odat_id;
+  int parent_id;//offset into CB
+  int num_ele;
+  int ele_index; //same as num_ele?
+  struct ele ele_list[MAX_ELES];
+};
+
+struct ele {
+  int odat_id;
+  int parent_id;//offset into class set_stack
+};
+
+//TODO: Do vdats need labels?
+struct vdat {
+  int num_models;
+  int msi; //model_stack_index
+  struct model model_list[MAX_MODELS];
+};
+
+//8 ids for each direction
+//fdat_id ordered by alphabetical direction
+struct model {
+  char label[32];
+  int fdat_id[8];
+};
+
similarity index 100%
rename from src/parser.y
rename to src/apc/parser.y