ref: e78d8bbdee7ae1ed843ec185eaa2cef31dd7d66d
parent: eee351ec4167b3d70cd704edb38f85c63a7eca4d
author: Ori Bernstein <[email protected]>
date: Tue Oct 7 12:46:09 EDT 2014
Start adding support for '$noret' attr This flags a function as non-returning.
--- a/6/simp.c
+++ b/6/simp.c
@@ -1749,7 +1749,7 @@
cfg = mkcfg(dcl, s->stmts, s->nstmts);
if (debugopt['C'])
- check(cfg);
+ check(cfg);
if (debugopt['t'] || debugopt['s'])
dumpcfg(cfg, stdout);
--- a/libstd/die.myr
+++ b/libstd/die.myr
@@ -2,7 +2,7 @@
use "types.use"
pkg std =
- const die : (msg : byte[:] -> void)
+ $noret const die : (msg : byte[:] -> void)
const assert : (cond : bool, msg : byte[:] -> void)
;;
--- a/libstd/fmt.myr
+++ b/libstd/fmt.myr
@@ -30,12 +30,13 @@
const fput : (fd : fd, fmt : byte[:], args : ... -> size)
const putv : (fmt : byte[:], ap : valist -> size)
const fputv : (fd : fd, fmt : byte[:], ap : valist -> size)
- const fatal : (status : int, fmt : byte[:], args : ... -> void)
- const fatalv : (status : int, fmt : byte[:], ap : valist -> void)
const fmt : (fmt : byte[:], args : ... -> byte[:])
const fmtv : (fmt : byte[:], ap : valist -> byte[:])
const bfmt : (buf : byte[:], fmt : byte[:], args : ... -> size)
const bfmtv : (buf : byte[:], fmt : byte[:], ap : valist -> size)
+
+ $noret const fatal : (status : int, fmt : byte[:], args : ... -> void)
+ $noret const fatalv : (status : int, fmt : byte[:], ap : valist -> void)
;;
/* Writes a string of text up to 2 kb in size to stdout */
--- a/opt/cfg.c
+++ b/opt/cfg.c
@@ -45,6 +45,16 @@
strlabel(cfg, lblstr(lbl), bb);
}
+static int isnonretcall(Node *fn)
+{
+ Node *dcl;
+
+ if (exprop(fn) != Ovar)
+ return 0;
+ dcl = decls[fn->expr.did];
+ return dcl->decl.isnoret;
+}
+
static int addnode(Cfg *cfg, Bb *bb, Node *n)
{
switch (exprop(n)) {
@@ -55,6 +65,10 @@
lappend(&cfg->fixjmp, &cfg->nfixjmp, n);
lappend(&cfg->fixblk, &cfg->nfixblk, bb);
return 1;
+ break;
+ case Ocall:
+ lappend(&bb->nl, &bb->nnl, n);
+ return isnonretcall(n->expr.args[0]);
break;
default:
lappend(&bb->nl, &bb->nnl, n);
--- a/parse/gram.y
+++ b/parse/gram.y
@@ -327,8 +327,7 @@
else
fatal($$.line, "invalid type attribute '%s'", $1.str[i]);
}
-
- }
+ }
| tydef {$$ = $1;}
;