mips/masm/asm.c

42 lines
753 B
C
Raw Normal View History

2024-09-10 00:48:08 +00:00
#include <merror.h>
#include <stdlib.h>
#include "asm.h"
int assembler_init(struct assembler *asm, const char *path)
{
if (lexer_init(path, &asm->lexer))
return M_ERROR;
if (parser_init(&asm->lexer, &asm->parser)) {
lexer_free(&asm->lexer);
return M_ERROR;
}
if (strtbl_init(&asm->shstr_tbl)) {
parser_free(&asm->parser);
lexer_free(&asm->lexer);
return M_ERROR;
}
if (strtbl_init(&asm->str_tbl)) {
strtbl_free(&asm->shstr_tbl);
parser_free(&asm->parser);
lexer_free(&asm->lexer);
return M_ERROR;
}
asm->meta = NULL;
return M_SUCCESS;
}
void assembler_free(struct assembler *asm)
{
strtbl_free(&asm->str_tbl);
strtbl_free(&asm->shstr_tbl);
parser_free(&asm->parser);
lexer_free(&asm->lexer);
free(asm->meta);
}