asm: implement an asm parser and emitter

This commit is contained in:
2024-12-13 12:26:01 +00:00
parent 0a8d913fdd
commit 5fe1a21978
19 changed files with 1106 additions and 49 deletions

42
asm/parse/unit.c Normal file
View File

@@ -0,0 +1,42 @@
#include "parse.h"
struct unit_parser_state {
struct parser_state s_base;
};
static enum ivy_status parse_constpool(struct ivy_asm_parser* ctx, struct ivy_asm_token* tok)
{
asm_parser_push_state(ctx, ASM_PARSER_CONSTPOOL);
return IVY_OK;
}
static enum ivy_status parse_import(
struct ivy_asm_parser *ctx, struct ivy_asm_token *tok)
{
asm_parser_push_state(ctx, ASM_PARSER_IMPORT);
return IVY_OK;
}
static enum ivy_status parse_block(
struct ivy_asm_parser *ctx, struct ivy_asm_token *tok)
{
asm_parser_push_state(ctx, ASM_PARSER_BLOCK);
return IVY_OK;
}
static enum ivy_status parse_class(
struct ivy_asm_parser *ctx, struct ivy_asm_token *tok)
{
asm_parser_push_state(ctx, ASM_PARSER_CLASS);
return IVY_OK;
}
struct parser_state_type unit_parser_state_type = {
.n_state_size = sizeof(struct unit_parser_state),
.n_keyword_parsers = {
KW_PARSER(CONSTPOOL, parse_constpool),
KW_PARSER(IMPORT, parse_import),
KW_PARSER(CLASS, parse_class),
KW_PARSER(BLOCK, parse_block),
},
};