lr/mem.h

58 lines
954 B
C

#pragma once
#include<stdint.h>
#include<stdio.h>
#include<stdlib.h>
#include"str.h"
#include"tok.h"
// Data types
typedef enum{I8,I16,I32,I64,U8,U16,U32,U64,U8P,U16P,U32P,U64P,STR}VTYPE;
// Memory location
// "Where do I look to find this value?"
// REG: Register
// STACK: On stack
// HEAP: Dynamically allocated
// IMM: Immediate/constant value
typedef enum{REG,STACK,HEAP,IMM}VLOC;
// Generic memory location
typedef union Mem
{
uint64_t*u64p;
uint32_t*u32p;
uint16_t*u16p;
uint8_t*u8p;
uint64_t u64;
uint32_t u32;
uint16_t u16;
uint8_t u8;
int64_t i64;
int32_t i32;
int16_t i16;
int8_t i8;
} Mem;
// Variable descriptor
typedef struct Var
{
char*name;
VTYPE type;
bool is_arg; // Remember to move arg register to stack
int32_t stackloc; // STACK: rsp-???
} Var;
// Function descriptor
typedef struct Func
{
char*name;
size_t no_args;
} Func;
Var var_new(void);
void var_free(Var*v);
void var_set_fromtoken(Var*v,Tok*t);