예제 #1
0
파일: node.c 프로젝트: oridb/mc
Node *
mkfunc(Srcloc loc, Node **args, size_t nargs, Type *ret, Node *body)
{
	Node *n;
	Node *f;
	size_t i;
	Stab *st;

	f = mknode(loc, Nfunc);
	f->func.args = args;
	f->func.nargs = nargs;
	f->func.body = body;
	f->func.scope = mkstab(1);
	f->func.type = mktyfunc(loc, args, nargs, ret);
	f->func.env = mkenv();

	bindtype(f->func.env, f->func.type);
	st = body->block.scope;
	for (i = 0; i < nargs; i++)
		putdcl(st, args[i]);

	n = mknode(loc, Nlit);
	n->lit.littype = Lfunc;
	n->lit.fnval = f;
	return n;
}
예제 #2
0
파일: genp9.c 프로젝트: kirbyfan64/mc
static void initconsts(Htab *globls)
{
	Type *ty;
	Node *name;
	Node *dcl;

	tyintptr = mktype(Zloc, Tyuint64);
	tyword = mktype(Zloc, Tyuint);
	tyvoid = mktype(Zloc, Tyvoid);

	ty = mktyfunc(Zloc, NULL, 0, mktype(Zloc, Tyvoid));
	ty->type = Tycode;
	name = mknsname(Zloc, "_rt", "abort_oob");
	dcl = mkdecl(Zloc, name, ty);
	dcl->decl.isconst = 1;
	dcl->decl.isextern = 1;
	htput(globls, dcl, asmname(dcl));

	abortoob = mkexpr(Zloc, Ovar, name, NULL);
	abortoob->expr.type = ty;
	abortoob->expr.did = dcl->decl.did;
	abortoob->expr.isconst = 1;
}