#pragma once #include "../std.h" #include "../collections/List.h" #include "token.h" List_declare(Token); typedef enum CompilerState { CompilerState_Initial, CompilerState_LexemaRecognition, CompilerState_ReadingComment, CompilerState_ReadingLabel, CompilerState_ReadingInstruction, CompilerState_ReadingArguments, CompilerState_ReadingData, CompilerState_Error, CompilerState_Success } CompilerState; typedef struct Compiler { const char* code; size_t code_len; char* out_buffer; size_t out_len; u32 line; // > 0 if code parsing started u32 column; // > 0 if code parsing started NULLABLE(char* error_message); CompilerState state; List_Token tokens; } Compiler; void Compiler_init(Compiler* cmp); void Compiler_free(Compiler* cmp); /// @brief compile assembly language code to machine code /// @return true if no errors, false if any error occured (check cmp->error_message) bool Compiler_compileTasm(Compiler* cmp, const char* restrict code, size_t code_len, char* restrict out_buffer, size_t out_len); #define Compiler_setError(cmp, format, ...) _Compiler_setError(cmp, __func__, format ,##__VA_ARGS__) void _Compiler_setError(Compiler* cmp, const char* context, const char* format, ...) __attribute__((__format__(__printf__, 3, 4)));