From 0114e1d65f6499e0d6d1bad19fb8ae3d012626d2 Mon Sep 17 00:00:00 2001 From: Meyer Simon Date: Mon, 5 May 2025 20:18:23 -0400 Subject: [PATCH] emission for func dec --- src/grammar.y | 1 + src/intermediate_code.c | 13 +++++++++++++ src/intermediate_code.h | 2 ++ 3 files changed, 16 insertions(+) diff --git a/src/grammar.y b/src/grammar.y index 354f19d..3d7db57 100644 --- a/src/grammar.y +++ b/src/grammar.y @@ -315,6 +315,7 @@ function_declaration: CreateEntry(cur,TYPE_FUNCTION_DECLARATION, look_up(cur, $4), $2, CreateFunctionDeclarationInfo(-1, false,NULL)); } + emit_function_dec(table_lookup(cur, $2)); } | EXTERNAL FUNCTION ID COLON ID diff --git a/src/intermediate_code.c b/src/intermediate_code.c index 73d43df..beccafd 100644 --- a/src/intermediate_code.c +++ b/src/intermediate_code.c @@ -167,6 +167,7 @@ TNodeOrConst *tn_or_const(Discriminant d, void *tnc) { return count; } + static void emit_helper(void) { Instruction *inst = calloc(1, sizeof(*inst)); if (begin == NULL) { @@ -179,6 +180,11 @@ static void emit_helper(void) { current = inst; } } +void emit_function_dec(TableNode * name){ + emit_helper(); + current->opcode = E_FUNC_DEC; + current->result = name; +} void emit_binary_op( Op op, @@ -405,6 +411,13 @@ void emit_as_file(FILE *out_file, Instruction *i) { return; } switch (i->opcode) { + case E_FUNC_DEC: + fprintf(out_file, + "%4.d: func_dec : %s\n", + i->index, + getName(i->result)); + + break; case E_FUNC_START: fprintf(out_file, "%4.d: func : %s\n", diff --git a/src/intermediate_code.h b/src/intermediate_code.h index 1e60a91..5f50828 100644 --- a/src/intermediate_code.h +++ b/src/intermediate_code.h @@ -44,6 +44,7 @@ typedef struct TNodeOrConst TNodeOrConst; typedef enum { // these are from page 364 E_LABEL = 10000, // this is not in the book E_FUNC_START, + E_FUNC_DEC, E_ADD, // 1 from the list E_SUB, // 1 E_MUL, // 1 @@ -138,6 +139,7 @@ void emit_conditional_jump(Op condition, int label, ...); void emit_function_start(TableNode *name); void emit_parameter(TNodeOrConst *param); void emit_function_call(TableNode *result, int param_count, TNodeOrConst *name); +void emit_function_dec(TableNode * name); void emit_return(TNodeOrConst *value); void emit_reserve(TableNode *result, TNodeOrConst *size); void emit_release(TableNode *pointer);