core: Add initial codegen sources

Signed-off-by: Ian Moffett <ian@mirocom.org>
This commit is contained in:
2026-02-15 22:17:40 -05:00
parent 1db0ed78e1
commit 154a71b1f6
9 changed files with 131 additions and 2 deletions

42
core/codegen.c Normal file
View 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;
}
}