73 lines
1.8 KiB
C
73 lines
1.8 KiB
C
/***********
|
|
* State for code
|
|
* generator
|
|
***********/
|
|
|
|
#pragma once
|
|
|
|
#include"mem.h"
|
|
#include"i386.h"
|
|
#include"pnode.h"
|
|
#include"x86_64.h"
|
|
|
|
// Build architecture types
|
|
enum {M_I386=1,M_IR,M_RUN,M_X86_64};
|
|
|
|
typedef struct Gen
|
|
{
|
|
PNode*stackptr;
|
|
const PNode*rootnode;
|
|
size_t labelno;
|
|
uint32_t buildarch;
|
|
bool showrpn;
|
|
bool showeval;
|
|
} Gen;
|
|
|
|
#define AM(x,y) ((((uint32_t)(x&0xff))<<8)|(y&0xff))
|
|
enum EVAL_ELEM_TYPE {EE_I32=1,EE_IDENT,EE_VAR,EE_FUNC,EE_ACC,EE_SEP};
|
|
typedef struct eval_elem
|
|
{
|
|
size_t type;
|
|
VTYPE vtype;
|
|
size_t vstackloc;
|
|
union
|
|
{
|
|
int32_t i32;
|
|
char*name;
|
|
}val;
|
|
}eval_elem;
|
|
|
|
// Used to abstract different architectures
|
|
typedef struct LangDef
|
|
{
|
|
const char*const registers_abi_wordsize[6];
|
|
const char*const registers_abi_32[6];
|
|
const char*const mov_wordsize;
|
|
const char*const mov_32;
|
|
const char*const push_wordsize;
|
|
const char*const sub_wordsize;
|
|
const char*const pop_wordsize;
|
|
const char*const sp;
|
|
const char*const bp;
|
|
const char*const scratch1;
|
|
}LangDef;
|
|
|
|
/* static void gen_print_string(Gen*gen,const PNode*pn,FILE*file,const Str*str) */
|
|
Gen gen_new(void);
|
|
Vec gen_i2r(const Vec*tokens);
|
|
|
|
bool gen_findret(const PNode*pn,bool found);
|
|
size_t gen_stacksize(const PNode*pn);
|
|
void gen(Gen*gen,PNode*pn,FILE*file);
|
|
void gen_code(Gen*gen,PNode*pn,FILE*file);
|
|
void gen_declare_function(Gen*gen,PNode*pn,FILE*file);
|
|
void gen_declare_variable(Gen*gen,PNode*pn,FILE*file);
|
|
void gen_epilog(Gen*gen,const PNode*pn,FILE*file);
|
|
void gen_eval(Gen*gen,const PNode*pn,FILE*file);
|
|
void gen_eval_analyze(const PNode*pn);
|
|
void gen_evalop(Gen*gen,PNode*pn,eval_elem*elem,size_t nops,Tok*curtok,FILE*file,Vec*stack);
|
|
void gen_free(Gen*gen);
|
|
void gen_prolog(Gen*gen,const PNode*pn,FILE*file,size_t stacksize);
|
|
void gen_setrootnode(Gen*gen,PNode*rootnode);
|
|
void vec_print_tokens(Vec*tokens);
|