Closer to OW-compliance + removed some leaks

This commit is contained in:
Mid 2023-08-31 21:24:46 +03:00
parent 9c89bfbdaf
commit 4d182e1685
4 changed files with 15 additions and 14 deletions

View File

@ -6,7 +6,7 @@
#include<assert.h>
#define REGS 4
static const char *regs[REGS][3] = {{"al", "ax", "eax"}, {"bl", "bx", "ebx"}, {"cl", "cx", "ecx"}, {"dl", "dx", "edx"}, {"sil", "si", "esi"}, {"dil", "di", "edi"}};
static const char *regs[REGS][3] = {{"al", "ax", "eax"}, {"bl", "bx", "ebx"}, {"cl", "cx", "ecx"}, {"dl", "dx", "edx"}};
static const char *BINOP_SIMPLE_INSTRS[] = {[BINOP_ADD] = "add", [BINOP_SUB] = "sub", [BINOP_BITWISE_AND] = "and", [BINOP_BITWISE_OR] = "or", [BINOP_BITWISE_XOR] = "xor"};

View File

@ -318,3 +318,10 @@ Token *nct_lex(FILE *f) {
return NULL; /* Doesn't reach here. */
}
void nct_lex_free(Token *tokens) {
for(Token *t = tokens; t->type != TOKEN_EOF; t++) {
if(t->content) free(t->content);
}
free(tokens);
}

View File

@ -50,5 +50,6 @@ typedef struct {
Token nct_tokenize(FILE*);
Token *nct_lex(FILE*);
void nct_lex_free(Token *);
#endif

View File

@ -16,7 +16,7 @@ typedef struct {
typedef struct {
Token *tokens;
ssize_t i;
intmax_t i;
VarTable *scope;
@ -115,15 +115,11 @@ static ASTExprPrimitive *parse_prim(Parser *P) {
static void newusedef(Parser *P, VarTableEntry *v, AST *expr) {
for(size_t i = 0; i < v->data.var.reachingDefs->defCount; i++) {
P->udsToAdd = realloc(P->udsToAdd, sizeof(*P->udsToAdd) * (++P->udsToAddCount));
P->udsToAdd[P->udsToAddCount - 1] = (UseDefToAdd) {
.ud = {
.def = v->data.var.reachingDefs->defs[i],
.use = expr,
.stmt = NULL, // set by pushstmt
.next = NULL,
},
.to = v
};
P->udsToAdd[P->udsToAddCount - 1].ud.def = v->data.var.reachingDefs->defs[i];
P->udsToAdd[P->udsToAddCount - 1].ud.use = expr;
P->udsToAdd[P->udsToAddCount - 1].ud.stmt = NULL; // set by pushstmt
P->udsToAdd[P->udsToAddCount - 1].ud.next = NULL;
P->udsToAdd[P->udsToAddCount - 1].to = v;
}
}
@ -773,9 +769,6 @@ void nct_parse_statement(Parser *P) {
}
ASTChunk *nct_parse_chunk(Parser *P, int isTopLevel, int varPrioritize) {
if(P->scope) {
}
AST *ret = malloc(sizeof(ASTChunk));
ret->nodeKind = AST_CHUNK;
ret->chunk.statementFirst = ret->chunk.statementLast = NULL;