shithub: mc

Download patch

ref: 4ff322bbbc9b8c181b6f48b55c72f5482cec3c88
parent: 186c4e4026e1d9db729153e185bd717377060926
author: Ori Bernstein <ori@eigenstate.org>
date: Sun Jan 8 16:39:08 EST 2017

Dedup const initialization.

--- a/6/asm.h
+++ b/6/asm.h
@@ -250,6 +250,7 @@
 extern int extracheck;
 extern Asmsyntax asmsyntax;
 
+void initconsts(Htab *globls);
 void fillglobls(Stab *st, Htab *globls);
 void simpglobl(Node *dcl, Htab *globls, Func ***fn, size_t *nfn, Node ***blob, size_t *nblob);
 void selfunc(Isel *is, Func *fn, Htab *globls, Htab *strtab);
--- a/6/gen.c
+++ b/6/gen.c
@@ -45,6 +45,31 @@
 	free(ns);
 }
 
+
+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;
+}
+
 Type *codetype(Type *ft)
 {
 	ft = tybase(ft);
--- a/6/gengas.c
+++ b/6/gengas.c
@@ -41,31 +41,6 @@
 
 static void locprint(FILE *fd, Loc *l, char spec);
 
-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;
-	dcl->decl.isglobl = 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;
-}
-
 void printmem(FILE *fd, Loc *l, char spec)
 {
 	if (l->type == Locmem) {
--- a/6/genp9.c
+++ b/6/genp9.c
@@ -40,30 +40,6 @@
 
 static void locprint(FILE *fd, Loc *l, char spec);
 
-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;
-}
-
 static void printmem(FILE *fd, Loc *l, char spec)
 {
 	if (l->type == Locmem) {