ir files compile, still a wip
[henge/webcc.git] / src / apc / ir.c
1 #include <errno.h>
2 #include <stdio.h>
3 #include <string.h>
4 #include <apc/ir.h>
5
6 #define CURR_ODAT (odat_buf[obi])
7 #define CURR_VDAT (vdat_buf[vbi])
8 #define CURR_CDAT (cdat_buf[cbi]) //more like the base cdat
9
10 //TODO: label and vdat_id
11 void
12 insert_set()
13 {
14 CURR_CDAT.set_list[CURR_CDAT.set_index].odat_id = obi;
15 CURR_CDAT.set_list[CURR_CDAT.set_index].parent_id = 0;//from lexer
16 //TODO: add ele_stack is created in element_list
17 //TODO: add set to odat_buf
18
19 }
20
21 #define CURR_QUAD (CURR_ODAT.ref_list[CURR_ODAT.ref_index])
22 void
23 insert_ref(int x, int y, int z, int ref)
24 {
25 CURR_QUAD.x = x;
26 CURR_QUAD.y = y;
27 CURR_QUAD.z = z;
28 CURR_QUAD.objref = ref;
29 }
30
31
32 //Insert element into odat_buf and cdat_buf
33 void
34 insert_ele(char* label, int vdat_id)
35 {
36
37
38 memmove(CURR_ODAT.label,label,32);
39 CURR_ODAT.vdat_id = vdat_id;
40 //TODO: check set_obi to see if set_map_data exists
41 //comes from e
42 //CURR_ODAT.num_ref = //comes from its set
43 //CURR_ODAT.ref_list = //comes from its set
44 //CURR_ODAT.class_id = //comes from lexer?
45
46 obi++;
47 }
48
49
50 /* fd could be a directory entry */
51 void
52 insert_fdat(char* label, char direction, int fd)
53 {
54 memmove(CURR_VDAT.model_list[CURR_VDAT.num_models].label,label,32);
55 CURR_VDAT.model_list[CURR_VDAT.num_models].fdat_id[(int)direction] = fd;
56 }
57
58 void
59 condense()
60 {
61 FILE *vp, *op, *cp;
62 int v, m;
63 int num_models;
64
65 vp = fopen("vdat_output", "w+");
66 if(!vp)
67 perror("vdat_output failed to open\n");
68
69 op = fopen("odat_output", "w+");
70 if(!op)
71 perror("odat_output failed to open\n");
72
73 cp = fopen("cdat_output", "w+");
74 if(!cp)
75 perror("cdat_output failed to open\n");
76
77
78
79 /* fwrite vdat */
80 for(v = 0; v <= vbi; v++)
81 {
82 num_models = vdat_buf[v].num_models; //data duplication for caching
83 for(m = 0; m <= num_models; m++)
84 {
85
86 }
87 }
88
89 /* fwrite odat */
90 /* Convert ref_list to actual offset */
91
92 /* fwrite cdat */
93
94
95 }
96 void
97 inc_cbi()
98 {
99 cbi++;
100 }
101
102 void
103 set_class_label(char* label)
104 {
105 memmove(CURR_CDAT.label,label,32);
106 }
107
108 void
109 inc_subclass_idx()
110 {
111 CURR_CDAT.subclass_index++;
112 }
113
114 void
115 inc_set_index()
116 {
117 cdat_buf[cbi].set_index++;
118 }
119
120 void
121 inc_ref()
122 {
123 CURR_ODAT.ref_index++;
124 CURR_ODAT.num_ref++;
125 }
126
127 //TODO: This needs to be changed to account for
128 // when the set is of a subclass.
129 void
130 inc_ele()
131 {
132 CURR_CDAT.set_list[CURR_CDAT.set_index].num_ele++;
133 vbi++;
134 }
135
136 void
137 inc_models()
138 {
139 CURR_VDAT.num_models++;
140 }