detect duplicate functions
This commit is contained in:
parent
506eb67e3b
commit
2d2e01f957
6
gen.c
6
gen.c
@ -13,3 +13,9 @@ void gen_free(Gen*gen)
|
||||
{
|
||||
if(!gen)return;
|
||||
}
|
||||
|
||||
void gen_setrootnode(Gen*gen,PNode*rootnode)
|
||||
{
|
||||
if(!gen||!rootnode)return;
|
||||
gen->rootnode=rootnode;
|
||||
}
|
||||
|
2
gen.h
2
gen.h
@ -11,8 +11,10 @@
|
||||
typedef struct Gen
|
||||
{
|
||||
size_t labelno;
|
||||
const PNode*rootnode;
|
||||
const PNode*stackptr;
|
||||
} Gen;
|
||||
|
||||
Gen gen_new(void);
|
||||
void gen_free(Gen*gen);
|
||||
void gen_setrootnode(Gen*gen,PNode*rootnode);
|
||||
|
4
main.c
4
main.c
@ -141,6 +141,10 @@ int main(int argc,char**argv)
|
||||
{
|
||||
state=state_new();
|
||||
|
||||
state.gen.rootnode=&state.parser.root;
|
||||
printf("rootnode=%p\n",state.gen.rootnode);
|
||||
printf("&parser.root=%p\n",&state.parser.root);
|
||||
|
||||
state.infile=fopen(*vec_at(&args,i,const char**),"r");
|
||||
if(!state.infile)
|
||||
{
|
||||
|
16
x86_64.c
16
x86_64.c
@ -29,6 +29,22 @@ void gen_x86_64(Gen*gen,const PNode*pn,FILE*file)
|
||||
{
|
||||
if(pn->parentnode&&pn->parentnode->parentnode!=NULL)
|
||||
err_log("%u: nested function declaration",pn->firstline);
|
||||
|
||||
for(size_t i=0;i<gen->rootnode->funcs.size;++i)
|
||||
{
|
||||
if(strcmp(vec_at(&pn->tokens,0,const Tok*)->str.buffer,vec_at(&gen->rootnode->funcs,i,Func*)->name)==0)
|
||||
{
|
||||
err_log("%u: '%s' already declared",vec_at(&pn->tokens,0,const Tok*)->line,vec_at(&pn->tokens,0,const Tok*)->str.buffer);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Func func={
|
||||
.name=vec_at(&pn->tokens,0,const Tok*)->str.buffer,
|
||||
/* .type=I32, */
|
||||
};
|
||||
vec_push((Vec*)&gen->rootnode->funcs,&func);
|
||||
|
||||
fprintf(file,"global %s\n%s:\n",vec_at(&pn->tokens,0,const Tok*)->str.buffer,vec_at(&pn->tokens,0,const Tok*)->str.buffer);
|
||||
|
||||
gen->stackptr=pn;
|
||||
|
Loading…
Reference in New Issue
Block a user