From d6ba30b94a24607bce5db5e706eb20cc051a98f0 Mon Sep 17 00:00:00 2001 From: A404M Date: Wed, 18 Sep 2024 19:46:38 +0330 Subject: initial commit --- src/compiler/code_generator/code_generator.h | 41 ++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/compiler/code_generator/code_generator.h (limited to 'src/compiler/code_generator/code_generator.h') diff --git a/src/compiler/code_generator/code_generator.h b/src/compiler/code_generator/code_generator.h new file mode 100644 index 0000000..1a9b4ff --- /dev/null +++ b/src/compiler/code_generator/code_generator.h @@ -0,0 +1,41 @@ +#pragma once + +#include + +#include "compiler/parser/parser.h" +typedef enum Command { + COMMAND_NONE = 0, + COMMAND_PRINT, + COMMAND_PUSH_STRING, +} Command; + +extern const char *COMMAND_STRINGS[]; + +typedef struct Instruction { + Command command; + void *operand; +} Instruction; + +typedef struct Instructions { + Instruction *restrict instructions; + size_t size; +} Instructions; + +extern void printInstruction(Instruction instruction); +extern void printInstructions(Instructions instructions); + +extern void deleteInstruction(Instruction instruction); +extern void deleteInstructions(Instructions instructions); + +extern Instructions codeGenerator(ParsedNode *root); + +extern bool nodeToInstruction(ParsedNode *node, Instruction **instructions, + size_t *instructions_size, + size_t *instructions_inserted); + +extern void insertInstruction(const Instruction instruction, + Instruction **restrict instructions, + size_t *restrict instructions_size, + size_t *restrict instructions_inserted); + +extern SizedString *nodeToString(ParsedNode const *node); -- cgit v1.2.3