commit 45eb005b00057c2d1d0b5139ff66ca73414cace4 from: Benjamin Stürz date: Wed Oct 02 18:48:35 2024 UTC irc: add support for custom sections commit - e0cdee61b211d1aaeb253a85a0095d624ce000f4 commit + 45eb005b00057c2d1d0b5139ff66ca73414cace4 blob - 428485760a9d5dbb499b3c96a4d43745c3d06595 blob + 6a547979c00fb315afb7a9582d77a179f3bf2664 --- cc/irc/irc.c +++ cc/irc/irc.c @@ -359,6 +359,7 @@ struct func { struct dtype dt; struct reg regs[NREGS]; struct ir *body; + char *section; int stoff; int is_pub; }; @@ -945,21 +946,34 @@ parse (void) extern gen (); struct func fn; int tk, is_pub; + char *section; while ((tk = lex ()) != TK_EOF) { if (tk != TK_IDENT) goto err; is_pub = 0; + section = NULL; if (strcmp (lval.s, "pub") == 0) { is_pub = 1; expect (TK_IDENT); } + fprintf (stderr, "%s\n", lval.s); + if (strcmp (lval.s, "section") == 0) { + expect (TK_STRING); + section = lval.s; + expect (TK_IDENT); + } + if (strcmp (lval.s, "fn") == 0) { + if (section == NULL) + section = ".text"; + memset (&fn, 0, sizeof (fn)); fn.is_pub = is_pub; + fn.section = section; func (&fn); gen (&fn); reset (); @@ -2081,6 +2095,7 @@ struct func *fn; { struct ir *ir; + printf ("section %s\n", fn->section); if (fn->is_pub) printf ("global %s\n", fn->name); blob - f40174905a6499ded17706cc59a6777e9c9f3b50 blob + 05c15c8dcacdf5ca56fbddf41a9e6cea2c331754 --- cc/irc/test.ir +++ cc/irc/test.ir @@ -187,3 +187,7 @@ fn qdiv ($0: qword, $1: qword): qword { fn negative (): qword { ret -1; } + +pub section ".text.custom" fn custom_section (): qword { + ret 0; +}