core: Add initial codegen sources
Signed-off-by: Ian Moffett <ian@mirocom.org>
This commit is contained in:
42
core/codegen.c
Normal file
42
core/codegen.c
Normal file
@@ -0,0 +1,42 @@
|
||||
#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 ((symbol = root->symbol) == NULL) {
|
||||
trace_error(state, "internal: no symbol associated with func node\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return mu_gen_label(state, symbol->name);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user