|
|
|
@ -34,34 +34,32 @@ static void ravi_destroy_linearizer(struct linearizer *linearizer) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Allocate a new proc. If no root proc then this becomes root proc.
|
|
|
|
|
* If no current proc then this becomes current proc.
|
|
|
|
|
* If there is a current proc, then this proc gets added to the current procs children, and it becomes the current proc.
|
|
|
|
|
* @param linearizer
|
|
|
|
|
* @param function_expr
|
|
|
|
|
* @return
|
|
|
|
|
* Allocate a new proc. If there is a current proc, then the new proc gets added to the
|
|
|
|
|
* current procs children.
|
|
|
|
|
*/
|
|
|
|
|
static struct proc* allocate_proc(struct linearizer *linearizer, struct ast_node *function_expr) {
|
|
|
|
|
static struct proc *allocate_proc(struct linearizer *linearizer, struct ast_node *function_expr) {
|
|
|
|
|
assert(function_expr->type == AST_FUNCTION_EXPR);
|
|
|
|
|
struct proc *proc = dmrC_allocator_allocate(&linearizer->proc_allocator, 0);
|
|
|
|
|
proc->function_expr = function_expr;
|
|
|
|
|
ptrlist_add(&linearizer->all_procs, proc, &linearizer->ptrlist_allocator);
|
|
|
|
|
if (linearizer->main_proc == NULL) {
|
|
|
|
|
assert(function_expr->function_expr.parent_function == NULL);
|
|
|
|
|
// This proc must be the main
|
|
|
|
|
linearizer->main_proc = proc;
|
|
|
|
|
}
|
|
|
|
|
if (linearizer->current_proc == NULL) {
|
|
|
|
|
proc->parent = NULL;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (linearizer->current_proc) {
|
|
|
|
|
proc->parent = linearizer->current_proc;
|
|
|
|
|
ptrlist_add(&linearizer->current_proc, proc, &linearizer->ptrlist_allocator);
|
|
|
|
|
linearizer->current_proc = proc;
|
|
|
|
|
}
|
|
|
|
|
return proc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void set_main_proc(struct linearizer *linearizer, struct proc *proc) {
|
|
|
|
|
assert(linearizer->main_proc == NULL);
|
|
|
|
|
assert(linearizer->current_proc == NULL);
|
|
|
|
|
linearizer->main_proc = proc;
|
|
|
|
|
assert(proc->function_expr->function_expr.parent_function == NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void set_current_proc(struct linearizer *linearizer, struct proc *proc) {
|
|
|
|
|
linearizer->current_proc = proc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void raviA_ast_linearize(struct linearizer *linearizer, struct ast_container *container) {
|
|
|
|
|
ravi_init_linearizer(linearizer, container);
|
|
|
|
|
struct proc *proc = allocate_proc(linearizer, container->main_function);
|
|
|
|
|