gen: allow dereferencing accumulator (for i386)

This commit is contained in:
corey 2024-02-01 08:37:08 -06:00
parent 4daf8e6ebf
commit f9bfbb94af
3 changed files with 18 additions and 8 deletions

6
TODO
View File

@ -15,15 +15,13 @@ Parser----------------------
Code Generator--------------
1. Code generator state
Code generator state
File output buffer
Set a block size and only output when full
Variable data
Types & type annotation (i32, i8, string, references,...)
x86_64: reference type needs 64-bit size to store addresses
"Run" build architecture
Virtual machine for intermediate representation/language
"Intermediate build representation/architecture/language"
Smart pointers (references/borrow checking)?
2. x86_64-linux ABI
Function calls
Nested functions

12
gen.c
View File

@ -1084,15 +1084,19 @@ void gen_evalop(Gen*gen,PNode*pn,eval_elem*elem,size_t nops,Tok*curtok,FILE*file
switch(elem[0].type)
{
default:
if(gen->buildarch==M_X86_64)
{
err_log("%u: cannot dereference '%s'",vec_at(&pn->tokens,0,Tok*)->line,operands[0]);
break;
}
/* FALL THROUGH */
case EE_VAR:
opos+=sprintf(output_buffer+opos,"\t%s %s,%%%s\n",ld.mov_wordsize,operands[0],ld.scratch1_wordsize);
opos+=sprintf(output_buffer+opos,"\t%s (%%%s),%%%s\n",operator,ld.scratch1_wordsize,ld.acc_32);
break;
default:
err_log("%u: cannot dereference '%s'",vec_at(&pn->tokens,0,Tok*)->line,operands[0]);
break;
}
tmpelem=(eval_elem){.type=EE_ACC,.val={0}};

8
tests/all/derefref.lr Normal file
View File

@ -0,0 +1,8 @@
#*:110
# Reference and dereference together
fn main()
{
let x=105;
let y=*(&x)+5;
ret y;
}