#define ASTIR_COMMON_H__
#define MEM_VECTOR_PROTO(Towner, Tmem, mem) \
- void Towner##_##mem##_add(Towner*, Tmem);
+ void Towner##_##mem##_add(Towner*, Tmem); \
+ void Towner##_##mem##_remove(Towner*, size_t);
#define MEM_VECTOR_PROTO_ALL(Towner, Tmem, mem) \
MEM_VECTOR_PROTO(Towner, Towner, Tmem, mem) \
qbool Towner##_##mem##_find(Towner*, Tmem, size_t*); \
- void Towner##_##mem##_clear(Towner*); \
- void Towner##_##mem##_remove(Towner*, size_t);
+ void Towner##_##mem##_clear(Towner*);
#define MEM_VECTOR_MAKE(Twhat, name) \
Twhat *name; \
}
#define MEM_VEC_FUNCTIONS(Tself, Twhat, mem) \
+_MEM_VEC_FUN_REMOVE(Tself, Twhat, mem) \
_MEM_VEC_FUN_ADD(Tself, Twhat, mem)
#define MEM_VEC_FUNCTIONS_ALL(Tself, Twhat, mem) \
MEM_VEC_FUNCTIONS(Tself, Twhat, mem) \
-_MEM_VEC_FUN_REMOVE(Tself, Twhat, mem) \
_MEM_VEC_FUN_CLEAR(Tself, Twhat, mem) \
_MEM_VEC_FUN_FIND(Tself, Twhat, mem)
ir_store_t store;
filecontext_t context;
- MAKE_VEC(struct ir_instr_s*, reads);
- MAKE_VEC(struct ir_instr_s*, writes);
+ MEM_VECTOR_MAKE(struct ir_instr_s*, reads);
+ MEM_VECTOR_MAKE(struct ir_instr_s*, writes);
/* constantvalues */
union {
qbool has_constval;
/* For the temp allocator */
- MAKE_VEC(ir_life_entry_t, life);
+ MEM_VECTOR_MAKE(ir_life_entry_t, life);
} ir_value;
/* ir_value can be a variable, or created by an operation */
void ir_value_delete(ir_value*);
void ir_value_set_name(ir_value*, const char *name);
-void ir_value_reads_add(ir_value*, struct ir_instr_s*);
-void ir_value_writes_add(ir_value*, struct ir_instr_s*);
+MEM_VECTOR_PROTO(ir_value, struct ir_instr_s*, reads)
+MEM_VECTOR_PROTO(ir_value, struct ir_instr_s*, writes)
qbool ir_value_set_float(ir_value*, float f);
qbool ir_value_set_int(ir_value*, int i);
/*qbool ir_value_set_pointer_v(ir_value*, ir_value* p); */
/*qbool ir_value_set_pointer_i(ir_value*, int i); */
-void ir_value_life_add(ir_value*, ir_life_entry_t e);
+MEM_VECTOR_PROTO(ir_value, ir_life_entry_t, life)
/* merge an instruction into the life-range */
/* returns false if the lifepoint was already known */
qbool ir_value_life_merge(ir_value*, size_t);
ir_value* (_ops[3]);
struct ir_block_s* (bops[2]);
- MAKE_VEC(ir_phi_entry_t, phi);
+ MEM_VECTOR_MAKE(ir_phi_entry_t, phi);
/* For the temp-allocation */
size_t eid;
ir_instr* ir_instr_new(struct ir_block_s *owner, ir_op_t opcode);
void ir_instr_delete(ir_instr*);
-void ir_instr_phi_add(ir_instr*, ir_phi_entry_t e);
+MEM_VECTOR_PROTO(ir_value, ir_phi_entry_t, phi)
void ir_instr_op(ir_instr*, int op, ir_value *value, qbool writing);
void ir_instr_dump(ir_instr* in, char *ind, int (*oprintf)(const char*,...));
filecontext_t context;
qbool final; /* once a jump is added we're done */
- MAKE_VEC(ir_instr*, instr);
- MAKE_VEC(struct ir_block_s*, entries);
- MAKE_VEC(struct ir_block_s*, exits);
- MAKE_VEC(ir_value*, living);
+ MEM_VECTOR_MAKE(ir_instr*, instr);
+ MEM_VECTOR_MAKE(struct ir_block_s*, entries);
+ MEM_VECTOR_MAKE(struct ir_block_s*, exits);
+ MEM_VECTOR_MAKE(ir_value*, living);
/* For the temp-allocation */
size_t eid;
void ir_block_set_label(ir_block*, const char *label);
-void ir_block_instr_add(ir_block*, ir_instr *instr);
-void ir_block_instr_remove(ir_block*, size_t idx);
-void ir_block_exits_add(ir_block*, ir_block *b);
-void ir_block_entries_add(ir_block*, ir_block *b);
-qbool ir_block_entries_find(ir_block*, ir_block *b, size_t *idx);
+MEM_VECTOR_PROTO(ir_block, ir_instr*, instr)
+MEM_VECTOR_PROTO_ALL(ir_block, ir_block*, exits)
+MEM_VECTOR_PROTO_ALL(ir_block, ir_block*, entries)
ir_value* ir_block_create_binop(ir_block*, const char *label, ir_op_t op,
ir_value *left, ir_value *right);
void ir_block_create_jump(ir_block*, ir_block *to);
void ir_block_create_goto(ir_block*, ir_block *to);
-void ir_block_living_add(ir_block*, ir_value*);
-void ir_block_living_remove(ir_block*, size_t idx);
-qbool ir_block_living_find(ir_block*, ir_value*, size_t *idx);
+MEM_VECTOR_PROTO_ALL(ir_block, ir_value*, living)
void ir_block_dump(ir_block*, char *ind, int (*oprintf)(const char*,...));
{
const char *_name;
ir_type_t retype;
- MAKE_VEC(ir_type_t, params);
- MAKE_VEC(ir_block*, blocks);
+ MEM_VECTOR_MAKE(ir_type_t, params);
+ MEM_VECTOR_MAKE(ir_block*, blocks);
/* values generated from operations
* which might get optimized away, so anything
* in there needs to be deleted in the dtor.
*/
- MAKE_VEC(ir_value*, values);
+ MEM_VECTOR_MAKE(ir_value*, values);
/* locally defined variables */
- MAKE_VEC(ir_value*, locals);
+ MEM_VECTOR_MAKE(ir_value*, locals);
ir_block* first;
ir_block* last;
void ir_function_collect_value(ir_function*, ir_value *value);
void ir_function_set_name(ir_function*, const char *name);
-void ir_function_params_add(ir_function*, ir_type_t p);
-void ir_function_blocks_add(ir_function*, ir_block *b);
+MEM_VECTOR_PROTO(ir_function, ir_type_t, params)
+MEM_VECTOR_PROTO(ir_function, ir_block*, blocks)
ir_value* ir_function_get_local(ir_function *self, const char *name);
ir_value* ir_function_create_local(ir_function *self, const char *name, ir_type_t vtype);
typedef struct ir_builder_s
{
const char *_name;
- MAKE_VEC(ir_function*, functions);
- MAKE_VEC(ir_value*, globals);
+ MEM_VECTOR_MAKE(ir_function*, functions);
+ MEM_VECTOR_MAKE(ir_value*, globals);
} ir_builder;
ir_builder* ir_builder_new(const char *modulename);
void ir_builder_set_name(ir_builder *self, const char *name);
-void ir_builder_functions_add(ir_builder* b, ir_function* f);
-void ir_builder_globals_add(ir_builder* b, ir_value* f);
+MEM_VECTOR_PROTO(ir_builder, ir_function*, functions)
+MEM_VECTOR_PROTO(ir_builder, ir_value*, globals)
ir_function* ir_builder_get_function(ir_builder*, const char *fun);
ir_function* ir_builder_create_function(ir_builder*, const char *name);