35 #define PAGES_PER_CHUNK 16
37 //"type free" chunk stacking
39 { void* chunks
[MAX_CHUNKS
];
40 void* *csp
; //chunk stack pointer
41 void* dsp
[MAX_CHUNKS
]; //dat stack pointer (per chunk)
42 int chunk_size
; //size of a chunk (including its forfeited page)
43 int max_dats
; //number of dats per chunk for this stack
44 } ocs
, vcs
, ccs
, rcs
, lcs
, pcs
; //odat, vdat, and cdat, ref, link, post stacks
46 //type safety handled by macro expansion (do not call these directly from code, make dependent macros for access to these)
47 #define CHUNKS_LEN(STACK) ((STACK).csp - (STACK).chunks)
48 #define CURRENT_CHUNK(STACK) ((STACK).chunks[CHUNKS_LEN(STACK) - 1])
49 #define CHUNKS_FULL(STACK) ( (STACK).csp >= \
50 (STACK).chunks + MAX_CHUNKS * (STACK).chunk_size)
51 #define CURRENT_DSP(STACK,TYPE) ((TYPE*) ((STACK).dsp[CHUNKS_LEN(STACK) - 1]))
52 #define DATA_FULL(STACK,TYPE) ((void*) CURRENT_DSP(STACK,TYPE) >= \
53 (CURRENT_CHUNK(STACK) + (STACK).chunk_size))
54 #define CSP_PUSH(STACK) (*(++(STACK).csp) = malloc((STACK).chunk_size))
55 #define CURRENT_DATP(STACK,TYPE) (((TYPE**)(STACK).dsp)[CHUNKS_LEN(STACK) - 1])
56 #define PREVIOUS_DATP(STACK,TYPE) (((TYPE**)(STACK).dsp)[CHUNKS_LEN(STACK) - 2])
57 #define ALLOC_DAT(STACK,TYPE) (++CURRENT_DATP(STACK,TYPE))
58 #define INIT_STACK(STACK,TYPE) \
60 (STACK).chunk_size = PAGES_PER_CHUNK * pagesize; \
61 (STACK).max_dats = (STACK).chunk_size / sizeof (TYPE); \
63 for( i = 0; i < MAX_CHUNKS; i++){ \
64 (STACK).dsp[i] += pagesize; \
67 //Stack-specific macros (called directly from code (safety enforcement)
68 #define INIT_ODAT() (INIT_STACK(ocs, struct odat))
69 #define CURRENT_ODAT() (CURRENT_DATP(ocs,struct odat))
70 #define ODAT_FULL() (DATA_FULL(ocs,struct odat))
71 #define ODAT_ALLOC() (ALLOC_DAT(ocs,struct odat))
72 #define OCS_FULL() (CHUNKS_FULL(ocs))
73 #define INIT_VDAT() (INIT_STACK(vcs, struct vdat))
74 #define CURRENT_VDAT() (CURRENT_DATP(vcs,struct vdat))
75 #define VDAT_FULL() (DATA_FULL(vcs,struct vdat))
76 #define VDAT_ALLOC() (ALLOC_DAT(vcs,struct vdat))
77 #define VCS_FULL() (CHUNKS_FULL(vcs))
78 #define INIT_CDAT() (INIT_STACK(ccs, struct cdat))
79 #define CURRENT_CDAT() (CURRENT_DATP(ccs,struct cdat))
80 #define CDAT_FULL() (DATA_FULL(ccs, struct cdat))
81 #define CDAT_ALLOC() (ALLOC_DAT(ccs, struct cdat))
82 #define CCS_FULL() (CHUNKS_FULL(ccs))
83 #define INIT_LINK() (INIT_STACK(lcs, struct link))
84 #define CURRENT_LINK() (CURRENT_DATP(lcs,struct link))
85 #define LDAT_FULL() (DATA_FULL(lcs, struct link))
86 #define LDAT_ALLOC() (ALLOC_DAT(lcs, struct link))
87 #define LCS_FULL() (CHUNKS_FULL(lcs))
88 #define INIT_POST() (INIT_STACK(rcs, struct ref))
89 #define CURRENT_POST() (CURRENT_DATP(pcs,struct ref))
90 #define POST_FULL() (DATA_FULL(pcs,struct ref))
91 #define POST_ALLOC() (ALLOC_DAT(pcs,struct ref))
92 #define PCS_FULL() (CHUNKS_FULL(pcs))
93 #define INIT_REF() (INIT_STACK(rcs, struct ref))
94 #define CURRENT_REF() (CURRENT_DATP(rcs,struct ref))
95 #define PREVIOUS_REF() (PREVIOUS_DATP(rcs, struct ref))
96 #define REF_FULL() (DATA_FULL(rcs,struct ref))
97 #define REF_ALLOC() (ALLOC_DAT(rcs,struct ref))
98 #define RCS_FULL() (CHUNKS_FULL(rcs))
100 #define CURRENT_SET() (CURRENT_CDAT()->set_list[CURRENT_CDAT()->num_sets])
101 #define CURRENT_MODEL() (CURRENT_VDAT()->model_list[CURRENT_VDAT()->num_models])
104 #define CURR_QUAD (CURR_ODAT->quad_file)
110 struct cdat
* cdat_stack
[MAX_CLASSES
];
111 struct cdat
** cdat_stackp
;
118 uint64_t ss_ref_id
= 0x00FFFFFF; /* system space for ref_ids */
125 /* The initalization function of the IR. */
130 char root
[4] = "root";
132 pagesize
= sysconf(_SC_PAGESIZE
);
135 *cdat_stackp
= CURRENT_CDAT();
136 memmove((*cdat_stackp
)->name
, root
, 32);
154 for(i
= 0; i
< CHUNKS_LEN(ccs
) ; i
++)
158 for(i
= 0; i
< CHUNKS_LEN(ocs
); i
++)
162 for(i
= 0; i
< CHUNKS_LEN(vcs
) ; i
++)
166 for(i
= 0; i
< CHUNKS_LEN(rcs
); i
++)
170 for(i
= 0; i
< CHUNKS_LEN(lcs
); i
++)
174 for(i
= 0; i
< CHUNKS_LEN(pcs
); i
++)
187 { fprintf(stderr
, "You have allocated to many (%d) cdats ", num_cdats
);
196 return CURRENT_CDAT();
199 //these should probably be inline
207 { fprintf(stderr
, "You have allocated to many (%d) odats ", num_odats
);
216 return CURRENT_ODAT();
225 { fprintf(stderr
, "You have allocated to many (%d) vdats ", num_vdats
);
241 { fprintf(stderr
, "You have allocated to many (%d) links ", num_links
);
250 return CURRENT_LINK();
260 { fprintf(stderr
, "You have allocated to many (%d) refs ", num_refs
);
270 if(num_refs
% 16 == 0)
271 { CURRENT_POST() = CURRENT_REF();
275 return CURRENT_REF();
283 { fprintf(stderr
, "You have allocated to many (%d) refs ", num_posts
);
298 return (*cdat_stackp
);
305 return CURRENT_ODAT();
311 return CURRENT_VDAT();
317 return &CURRENT_SET();
323 return CURRENT_REF();
329 return &CURRENT_MODEL();