52 lines
1.3 KiB
C
52 lines
1.3 KiB
C
#include "AST.h"
|
|
|
|
Array_declare(str);
|
|
|
|
static Array(str) _ArgumentType_str_array = ARRAY(str, {
|
|
STR("Unset"),
|
|
STR("Register"),
|
|
STR("ConstValue"),
|
|
STR("VarDataName"),
|
|
STR("ConstDataPointer"),
|
|
STR("ConstDataSize"),
|
|
});
|
|
|
|
str ArgumentType_toString(ArgumentType t){
|
|
if(t >= _ArgumentType_str_array.len)
|
|
return STR("!!ArgumentType INDEX_ERROR!!");
|
|
return _ArgumentType_str_array.data[t];
|
|
}
|
|
|
|
|
|
void Section_construct(Section* sec, str name){
|
|
sec->name = name;
|
|
sec->data_definitions_list = List_DataDefinition_alloc(256);
|
|
sec->operations_list = List_Operation_alloc(1024);
|
|
}
|
|
|
|
void Section_destroy(Section* sec){
|
|
for(u32 i = 0; i < sec->data_definitions_list.len; i++){
|
|
DataDefinition* dd = sec->data_definitions_list.data + i;
|
|
List_u8_destroy(&dd->data_bytes);
|
|
}
|
|
List_DataDefinition_destroy(&sec->data_definitions_list);
|
|
|
|
for(u32 i = 0; i < sec->operations_list.len; i++){
|
|
Operation* op = sec->operations_list.data + i;
|
|
List_Argument_destroy(&op->args);
|
|
}
|
|
List_Operation_destroy(&sec->operations_list);
|
|
}
|
|
|
|
|
|
void AST_construct(AST* ast){
|
|
ast->sections = List_Section_alloc(32);
|
|
}
|
|
|
|
void AST_destroy(AST* ast){
|
|
for(u32 i = 0; i != ast->sections.len; i++){
|
|
Section_destroy(ast->sections.data + i);
|
|
}
|
|
List_Section_destroy(&ast->sections);
|
|
}
|