diff options
author | Matthew Sotoudeh <matthew@masot.net> | 2023-07-31 13:34:45 -0700 |
---|---|---|
committer | Matthew Sotoudeh <matthew@masot.net> | 2023-07-31 13:34:45 -0700 |
commit | 135b17bada960c4585d5a124fedb7e4e9d849078 (patch) | |
tree | 5169b290f4bcbe48fd02c514314eb49be631fd77 /c/libdietc.l | |
parent | c8ef4cf86bb97033238e3aa5c95789ea665341b1 (diff) |
simple refcounting pass in C
Diffstat (limited to 'c/libdietc.l')
-rw-r--r-- | c/libdietc.l | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/c/libdietc.l b/c/libdietc.l index 7133803..51c8e91 100644 --- a/c/libdietc.l +++ b/c/libdietc.l @@ -13,7 +13,7 @@ static void define_aggregate(char *); static void declare_basic(char *); static void declare_object(char *); static void start_function(char *); -static void add_instruction(char *); +static void add_instruction(char *, enum INSTRUCTION_TYPE); static void end_function(); %} %% @@ -33,9 +33,13 @@ static void end_function(); ^[^{\n]*"{"$ { start_function(yytext); } ^\tType_[0-9]*" "[a-zA-Z0-9_]*" ;"$ { declare_object(yytext); - add_instruction(yytext); + add_instruction(yytext, INSTRUCTION_DECLARE); } -\t[^\n]*$ { add_instruction(yytext); } +\t[*]" "[a-zA-Z_0-9]*" = "[a-zA-Z_0-9]*" ;"$ { add_instruction(yytext, INSTRUCTION_DEREF_ASSIGN); } +\t[a-zA-Z_0-9]*" = "[*]" "[a-zA-Z_0-9]*" ;"$ { add_instruction(yytext, INSTRUCTION_ASSIGN_DEREF); } +\t[a-zA-Z_0-9]*" = "[a-zA-Z_0-9]*" ;"$ { add_instruction(yytext, INSTRUCTION_COPY); } +\t[a-zA-Z_0-9]*" = ( Type_"[0-9]*" ) "[a-zA-Z_0-9]*" ;"$ { add_instruction(yytext, INSTRUCTION_CAST); } +\t[^\n]*$ { add_instruction(yytext, INSTRUCTION_OTHER); } "}"$ { end_function(); } \n { } (.|[ \t]) { fprintf(stderr, "UNKNOWN: %s\n", yytext); } @@ -188,9 +192,11 @@ static void start_function(char *line) { NEXT_INSTRUCTION = &(FUNCTION.instructions); } -static void add_instruction(char *line) { +static void add_instruction(char *line, enum INSTRUCTION_TYPE kind) { *NEXT_INSTRUCTION = calloc(sizeof(**NEXT_INSTRUCTION), 1); (*NEXT_INSTRUCTION)->line = strdup(line); + (*NEXT_INSTRUCTION)->kind = kind; + (*NEXT_INSTRUCTION)->pprev = NEXT_INSTRUCTION; NEXT_INSTRUCTION = &((*NEXT_INSTRUCTION)->next); } @@ -264,3 +270,13 @@ struct type *libdietc_object_type(struct program program, char *name) { free(name_tok); return program.objects[h] ? program.objects[h]->type : 0; } + +struct type *libdietc_lhs_type(struct program program, struct instruction *instruction) { + char *name = 0; + if (instruction->line[1] == '*') { + name = libdietc_tokdup(libdietc_nth_token(instruction->line, 1)); + return libdietc_object_type(program, name)->base; + } + name = libdietc_tokdup(libdietc_nth_token(instruction->line, 0)); + return libdietc_object_type(program, name); +} |