49 lines
957 B
C
49 lines
957 B
C
#include <stdint.h>
|
|
#include <stddef.h>
|
|
#include "rifle/codegen.h"
|
|
#include "rifle/trace.h"
|
|
#include "rifle/mu.h"
|
|
|
|
static int
|
|
resolve_func(struct rifle_state *state, struct ast_node *root)
|
|
{
|
|
struct symbol *symbol;
|
|
|
|
if (state == NULL || root == NULL) {
|
|
return -1;
|
|
}
|
|
|
|
if (root->epilogue) {
|
|
return mu_gen_ret(state);
|
|
}
|
|
|
|
if ((symbol = root->symbol) == NULL) {
|
|
trace_error(state, "internal: no symbol associated with func node\n");
|
|
return -1;
|
|
}
|
|
|
|
return mu_gen_label(state, symbol->name, symbol->pub);
|
|
}
|
|
|
|
int
|
|
cg_resolve_node(struct rifle_state *state, struct ast_node *root)
|
|
{
|
|
if (state == NULL || root == NULL) {
|
|
return -1;
|
|
}
|
|
|
|
switch (root->type) {
|
|
case AST_FUNC:
|
|
if (resolve_func(state, root) < 0) {
|
|
return -1;
|
|
}
|
|
|
|
break;
|
|
default:
|
|
trace_error(state, "unknown ast node %d\n", root->type);
|
|
break;
|
|
}
|
|
|
|
return 0;
|
|
}
|