c241a29aa3fa78849164a8f979bd14b30963d7a9
37 #define PAGES_PER_CHUNK 16
39 //"type free" chunk stacking
41 { void* chunks
[MAX_CHUNKS
];
42 void* *csp
; //chunk stack pointer
43 void* dsp
[MAX_CHUNKS
]; //dat stack pointer (per chunk)
44 int chunk_size
; //size of a chunk (including its forfeited page)
45 int max_dats
; //number of dats per chunk for this stack
46 } ocs
, vcs
, ccs
, rcs
, lcs
, pcs
, varcs
; //odat, vdat, cdat,variant, ref, link, post stacks
48 //type safety handled by macro expansion (do not call these directly from code, make dependent macros for access to these)
49 #define CHUNKS_LEN(STACK) ((STACK).csp - (STACK).chunks)
50 #define CURRENT_CHUNK(STACK) ((STACK).chunks[CHUNKS_LEN(STACK) - 1])
51 #define CHUNKS_FULL(STACK) ( (STACK).csp >= \
52 (STACK).chunks + MAX_CHUNKS * (STACK).chunk_size)
53 #define CURRENT_DSP(STACK,TYPE) ((TYPE*) ((STACK).dsp[CHUNKS_LEN(STACK) - 1]))
54 #define DATA_FULL(STACK,TYPE) ((void*) CURRENT_DSP(STACK,TYPE) >= \
55 (CURRENT_CHUNK(STACK) + (STACK).chunk_size))
56 #define CSP_PUSH(STACK) (*(++(STACK).csp) = malloc((STACK).chunk_size))
57 #define CURRENT_DATP(STACK,TYPE) (((TYPE**)(STACK).dsp)[CHUNKS_LEN(STACK) - 1])
58 #define PREVIOUS_DATP(STACK,TYPE) (((TYPE**)(STACK).dsp)[CHUNKS_LEN(STACK) - 2])
59 #define ALLOC_DAT(STACK,TYPE) (++CURRENT_DATP(STACK,TYPE))
60 #define INIT_STACK(STACK,TYPE) \
62 (STACK).chunk_size = PAGES_PER_CHUNK * pagesize; \
63 (STACK).max_dats = (STACK).chunk_size / sizeof (TYPE); \
65 for( i = 0; i < MAX_CHUNKS; i++){ \
66 (STACK).dsp[i] += pagesize; \
69 //Stack-specific macros (called directly from code (safety enforcement)
70 #define INIT_ODAT() (INIT_STACK(ocs, struct odat))
71 #define CURRENT_ODAT() (CURRENT_DATP(ocs,struct odat))
72 #define ODAT_FULL() (DATA_FULL(ocs,struct odat))
73 #define ODAT_ALLOC() (ALLOC_DAT(ocs,struct odat))
74 #define OCS_FULL() (CHUNKS_FULL(ocs))
75 #define INIT_VDAT() (INIT_STACK(vcs, struct vdat))
76 #define CURRENT_VDAT() (CURRENT_DATP(vcs,struct vdat))
77 #define VDAT_FULL() (DATA_FULL(vcs,struct vdat))
78 #define VDAT_ALLOC() (ALLOC_DAT(vcs,struct vdat))
79 #define VCS_FULL() (CHUNKS_FULL(vcs))
80 #define INIT_CDAT() (INIT_STACK(ccs, struct cdat))
81 #define CURRENT_CDAT() (CURRENT_DATP(ccs,struct cdat))
82 #define CDAT_FULL() (DATA_FULL(ccs, struct cdat))
83 #define CDAT_ALLOC() (ALLOC_DAT(ccs, struct cdat))
84 #define CCS_FULL() (CHUNKS_FULL(ccs))
85 #define INIT_VARIANT() (INIT_STACK(varcs, struct variant))
86 #define CURRENT_VARIANT() (CURRENT_DATP(varcs, struct variant))
87 #define VARIANT_FULL() (DATA_FULL(varcs, struct variant))
88 #define VARIANT_ALLOC() (ALLOC_DAT(varcs, struct variant))
89 #define VARCS_FULL() (CHUNKS_FULL(varcs))
90 #define INIT_LINK() (INIT_STACK(lcs, struct link))
91 #define CURRENT_LINK() (CURRENT_DATP(lcs,struct link))
92 #define LDAT_FULL() (DATA_FULL(lcs, struct link))
93 #define LDAT_ALLOC() (ALLOC_DAT(lcs, struct link))
94 #define LCS_FULL() (CHUNKS_FULL(lcs))
95 #define INIT_POST() (INIT_STACK(rcs, struct ref))
96 #define CURRENT_POST() (CURRENT_DATP(pcs,struct ref))
97 #define POST_FULL() (DATA_FULL(pcs,struct ref))
98 #define POST_ALLOC() (ALLOC_DAT(pcs,struct ref))
99 #define PCS_FULL() (CHUNKS_FULL(pcs))
100 #define INIT_REF() (INIT_STACK(rcs, struct ref))
101 #define CURRENT_REF() (CURRENT_DATP(rcs,struct ref))
102 #define PREVIOUS_REF() (PREVIOUS_DATP(rcs, struct ref))
103 #define REF_FULL() (DATA_FULL(rcs,struct ref))
104 #define REF_ALLOC() (ALLOC_DAT(rcs,struct ref))
105 #define RCS_FULL() (CHUNKS_FULL(rcs))
107 #define CURRENT_SET() (CURRENT_CDAT()->set_list[CURRENT_CDAT()->num_sets])
108 //#define CURRENT_QUAD() (CURRENT_VARIANT()->quad_list[CURRENT_VARIANT()->num_quads])
109 //#define CURRENT_MODEL() (CURRENT_VDAT()->model_list[CURRENT_VDAT()->num_models])
117 struct cdat
* cdat_stack
[MAX_CLASSES
];
118 struct cdat
** cdat_stackp
;
124 int num_variants
= 0;
127 int ss_ref_id
= 0x0FFFFFFF; /* system space for ref_ids */
134 /* The initalization function of the IR. */
139 char root
[4] = "root";
141 pagesize
= sysconf(_SC_PAGESIZE
);
144 *cdat_stackp
= CURRENT_CDAT();
146 memmove((*cdat_stackp
)->name
, root
, 32);
165 for(i
= 0; i
< CHUNKS_LEN(ccs
) ; i
++)
169 for(i
= 0; i
< CHUNKS_LEN(ocs
); i
++)
173 for(i
= 0; i
< CHUNKS_LEN(vcs
) ; i
++)
177 for(i
= 0; i
< CHUNKS_LEN(rcs
); i
++)
181 for(i
= 0; i
< CHUNKS_LEN(lcs
); i
++)
185 for(i
= 0; i
< CHUNKS_LEN(pcs
); i
++)
198 { fprintf(stderr
, "You have allocated to many (%d) cdats ", num_cdats
);
207 return CURRENT_CDAT();
210 //these should probably be inline
218 { fprintf(stderr
, "You have allocated to many (%d) odats ", num_odats
);
227 return CURRENT_ODAT();
236 { fprintf(stderr
, "You have allocated to many (%d) vdats ", num_vdats
);
245 return CURRENT_VDAT();
254 { fprintf(stderr
, "You have allocated to many (%d) variants ", num_variants
);
263 return CURRENT_VARIANT();
273 { fprintf(stderr
, "You have allocated to many (%d) links ", num_links
);
282 return CURRENT_LINK();
292 { fprintf(stderr
, "You have allocated to many (%d) refs ", num_refs
);
302 if(num_refs
% 16 == 0)
303 { CURRENT_POST() = CURRENT_REF();
307 return CURRENT_REF();
315 { fprintf(stderr
, "You have allocated to many (%d) refs ", num_posts
);
330 return (*cdat_stackp
);
337 return CURRENT_ODAT();
343 return CURRENT_VDAT();
349 return &CURRENT_SET();
355 return CURRENT_REF();
361 return CURRENT_VARIANT();
367 /* return &CURRENT_QUAD(); */
373 /* return &CURRENT_MODEL(); */