47 lines
961 B
C
47 lines
961 B
C
#include "AST.h"
|
|
|
|
List_define(Argument);
|
|
List_define(Operation);
|
|
List_define(DataDefinition);
|
|
List_define(Section);
|
|
|
|
static str _ArgumentType_str[] = {
|
|
STR("Unset"),
|
|
STR("Register"),
|
|
STR("ConstValue"),
|
|
STR("DataName"),
|
|
STR("NamedDataPointer"),
|
|
STR("NamedDataSize"),
|
|
};
|
|
|
|
str ArgumentType_toString(ArgumentType t){
|
|
if(t >= ARRAY_SIZE(_ArgumentType_str))
|
|
return STR("!!INDEX_ERROR!!");
|
|
return _ArgumentType_str[t];
|
|
}
|
|
|
|
|
|
void Section_init(Section* sec, str name){
|
|
sec->name = name;
|
|
sec->data = List_DataDefinition_alloc(256);
|
|
sec->code = List_Operation_alloc(1024);
|
|
}
|
|
|
|
void Section_free(Section* sec){
|
|
free(sec->name.data);
|
|
free(sec->data.data);
|
|
free(sec->code.data);
|
|
}
|
|
|
|
|
|
void AST_init(AST* ast){
|
|
ast->sections = List_Section_alloc(32);
|
|
}
|
|
|
|
void AST_free(AST* ast){
|
|
for(u32 i = 0; i != ast->sections.len; i++){
|
|
Section_free(&ast->sections.data[i]);
|
|
}
|
|
free(ast->sections.data);
|
|
}
|