61 lines
1.1 KiB
C
61 lines
1.1 KiB
C
#ifndef UNDAR_IR_ASSEMBLER_H
|
|
#define UNDAR_IR_ASSEMBLER_H
|
|
|
|
#include "../../vm/common.h"
|
|
#include "../../vm/opcodes.h"
|
|
#include "lexer.h"
|
|
|
|
typedef enum { GLOBAL, LOCAL, VAR } ScopeType;
|
|
typedef enum {
|
|
VOID,
|
|
BOOL,
|
|
I8,
|
|
I16,
|
|
I32,
|
|
U8,
|
|
U16,
|
|
U32,
|
|
F8,
|
|
F16,
|
|
F32,
|
|
STR,
|
|
PLEX,
|
|
ARRAY,
|
|
FUNCTION
|
|
} SymbolType;
|
|
|
|
typedef struct symbol_s Symbol;
|
|
typedef struct symbol_tab_s SymbolTable;
|
|
typedef struct scope_tab_s ScopeTable;
|
|
typedef struct assembler_s Assembler;
|
|
|
|
#define MAX_SYMBOL_NAME_LENGTH 64
|
|
struct symbol_s {
|
|
char name[MAX_SYMBOL_NAME_LENGTH];
|
|
u8 name_length;
|
|
SymbolType type;
|
|
ScopeType scope;
|
|
u32 ref; // vm->mp if global, vm->pc local, register if var
|
|
u32 size; // size of symbol
|
|
};
|
|
|
|
struct symbol_tab_s {
|
|
Symbol symbols[256];
|
|
u8 count;
|
|
i32 parent;
|
|
};
|
|
|
|
struct scope_tab_s {
|
|
SymbolTable *scopes;
|
|
u32 count;
|
|
u32 capacity;
|
|
i32 scope_ref;
|
|
};
|
|
|
|
void assemble(VM *vm, ScopeTable *st, char *source);
|
|
extern bool table_realloc(ScopeTable *table);/* implement this in arch/ not here */
|
|
|
|
const char *opcode_to_string(Opcode op);
|
|
|
|
#endif
|