History

handle computed gotos

bellard committed 24 years ago

Commit fde824b1 parent bde35a81 file · +19 −6Browse files

Unified · Split

i386-gen.c+19−6
@@ -349,9 +349,8 @@ static void gadd_sp(int val) · 348 unmodified lines
349349 }
350350 }
351351
352−/* generate function call with address in (vtop->t, vtop->c) and free function
353− context. Stack entry is popped */
354−void gfunc_call(GFuncContext *c)
352+/* 'is_jmp' is '1' if it is a jump */
353+static void gcall_or_jmp(int is_jmp)
355354 {
356355 int r;
357356 if ((vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST) {
@@ -365,13 +364,20 @@ void gfunc_call(GFuncContext *c) · 7 unmodified lines
365364 put_elf_reloc(symtab_section, cur_text_section,
366365 ind + 1, R_386_PC32, 0);
367366 }
368− oad(0xe8, vtop->c.ul - 4);
367+ oad(0xe8 + is_jmp, vtop->c.ul - 4); /* call/jmp im */
369368 } else {
370369 /* otherwise, indirect call */
371370 r = gv(RC_INT);
372− o(0xff); /* call *r */
373− o(0xd0 + r);
371+ o(0xff); /* call/jmp *r */
372+ o(0xd0 + r + (is_jmp << 4));
374373 }
374+}
375+
376+/* generate function call with address in (vtop->t, vtop->c) and free function
377+ context. Stack entry is popped */
378+void gfunc_call(GFuncContext *c)
379+{
380+ gcall_or_jmp(0);
375381 if (c->args_size && c->func_call == FUNC_CDECL)
376382 gadd_sp(c->args_size);
377383 vtop--;
@@ -862,6 +868,13 @@ void gen_cvt_ftof(int t) · 484 unmodified lines
862868 gv(RC_FLOAT);
863869 }
864870
871+/* computed goto support */
872+void ggoto(void)
873+{
874+ gcall_or_jmp(1);
875+ vtop--;
876+}
877+
865878 /* bound check support functions */
866879 #ifdef CONFIG_TCC_BCHECK
867880

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t