Files
assm-test/includes/symbols_table.h
T

51 lines
1.0 KiB
C

#ifndef SYMBOLSTABLE_H
#define SYMBOLSTABLE_H
#include <stdint.h>
#include <stdlib.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include "opcodes.h"
#define SYMBOLSTABLE_DEFAULT_CAPACITY 128
typedef enum {
StringSymbol,
NumericSymbol,
InstructionPointerSymbol,
UnresolvedSymbol
} SymbolType;
typedef struct {
char* String;
int Terminated;
u_int8_t TerminatingByte;
} SymbolString;
typedef struct {
char* Name;
SymbolType Type;
union {
SymbolString* String;
int Number;
Instruction* Instruction;
} Value;
} Symbol;
typedef struct {
Symbol** Symbols;
int Size;
int Capacity;
} SymbolTable;
SymbolTable* CreateSymbolTable(void);
Symbol* TryGetSymbol(char* name, SymbolTable* table);
Symbol* AddSymbolToTable(char* name, SymbolType type, SymbolTable* table);
SymbolString* CreateSymbolString(char* string, int terminated);
void FreeSymbolTable(SymbolTable* table);
void FreeSymbol(Symbol* symbol);
#endif