Module Name:    src
Committed By:   rillig
Date:           Tue Jan  5 23:50:29 UTC 2021

Modified Files:
        src/usr.bin/xlint/lint1: Makefile op.h ops.def
Added Files:
        src/usr.bin/xlint/lint1: ops.c
Removed Files:
        src/usr.bin/xlint/lint1: Makefile.ops-c Makefile.ops-h mkops

Log Message:
lint: clean up generation of the operator tables

Instead of running a shell program that runs an AWK program that
generates the two files ops.c and ops.h, just define the operator tables
once in ops.def and use these definitions flexibly in ops.c and op.h.


To generate a diff of this commit:
cvs rdiff -u -r1.55 -r1.56 src/usr.bin/xlint/lint1/Makefile
cvs rdiff -u -r1.3 -r0 src/usr.bin/xlint/lint1/Makefile.ops-c \
    src/usr.bin/xlint/lint1/Makefile.ops-h
cvs rdiff -u -r1.13 -r0 src/usr.bin/xlint/lint1/mkops
cvs rdiff -u -r1.9 -r1.10 src/usr.bin/xlint/lint1/op.h
cvs rdiff -u -r0 -r1.1 src/usr.bin/xlint/lint1/ops.c
cvs rdiff -u -r1.6 -r1.7 src/usr.bin/xlint/lint1/ops.def

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/xlint/lint1/Makefile
diff -u src/usr.bin/xlint/lint1/Makefile:1.55 src/usr.bin/xlint/lint1/Makefile:1.56
--- src/usr.bin/xlint/lint1/Makefile:1.55	Sun Jan  3 18:48:37 2021
+++ src/usr.bin/xlint/lint1/Makefile	Tue Jan  5 23:50:29 2021
@@ -1,10 +1,10 @@
-#	$NetBSD: Makefile,v 1.55 2021/01/03 18:48:37 rillig Exp $
+#	$NetBSD: Makefile,v 1.56 2021/01/05 23:50:29 rillig Exp $
 
 .include <bsd.own.mk>
 
 PROG=		lint1
 SRCS=		cgram.y decl.c emit.c emit1.c err.c func.c init.c inittyp.c \
-		main1.c mem.c mem1.c print.c scan.l tree.c tyname.c
+		main1.c mem.c mem1.c ops.c print.c scan.l tree.c tyname.c
 
 MAN=		lint.7
 YHEADER=
@@ -38,11 +38,9 @@ LDADD+=		-ll
 DPADD+=		${LIBL}
 .endif
 
+ops.o: ops.def
+
 .include "Makefile.err-msgs-h"
-.include "Makefile.ops-h"
-.include "Makefile.ops-c"
+${SRCS:Nerr.c}: err-msgs.h
 
 .include <bsd.prog.mk>
-
-${SRCS}: ops.h
-${SRCS:Nerr.c}: err-msgs.h

Index: src/usr.bin/xlint/lint1/op.h
diff -u src/usr.bin/xlint/lint1/op.h:1.9 src/usr.bin/xlint/lint1/op.h:1.10
--- src/usr.bin/xlint/lint1/op.h:1.9	Mon Jan  4 23:58:19 2021
+++ src/usr.bin/xlint/lint1/op.h	Tue Jan  5 23:50:29 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: op.h,v 1.9 2021/01/04 23:58:19 rillig Exp $	*/
+/*	$NetBSD: op.h,v 1.10 2021/01/05 23:50:29 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -60,4 +60,13 @@ typedef	struct {
 
 extern mod_t   modtab[];
 
-#include "ops.h"
+#define begin_ops() typedef enum {
+#define op(name, repr, \
+		bi, lo, in, sc, ar, fo, va, ts, ba, se, \
+		lu, ru, pc, cm, ve, de, ew, ic, active) \
+	name,
+#define end_ops() } op_t;
+#include "ops.def"
+
+const char *getopname(op_t);
+void initmtab(void);

Index: src/usr.bin/xlint/lint1/ops.def
diff -u src/usr.bin/xlint/lint1/ops.def:1.6 src/usr.bin/xlint/lint1/ops.def:1.7
--- src/usr.bin/xlint/lint1/ops.def:1.6	Tue Jan  5 23:07:49 2021
+++ src/usr.bin/xlint/lint1/ops.def	Tue Jan  5 23:50:29 2021
@@ -1,62 +1,77 @@
-NOOP	no-op	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0	0
-ARROW	->	1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0	1
-POINT	.	1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0	1
-NOT	!	0,1,0,1,0,1,0,1,0,0,0,0,0,0,0,1,0,0	1
-COMPL	~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,0,0,0,0,0,0,0,0,0,0	1
-FSEL	fsel	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0	1
-CALL	call	1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0	1
-COMMA	,	1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0	1
-CVT	convert	0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0	1
-ICALL	icall	1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0	1
-LOAD	load	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0	1
-PUSH	push	0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0	1
-RETURN	return	1,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0	1
-REAL	real	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0	0
-IMAG	imag	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0	0
-INIT	init	1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0	1	pseudo
-CASE	case	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0	0	pseudo
-FARG	farg	1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0	1	pseudo
+/*	$NetBSD: ops.def,v 1.7 2021/01/05 23:50:29 rillig Exp $ */
+
+begin_ops()
+/*	name	repr		b l i s a f v t b s l r p c e e q c	act */
+op(	NOOP,	"no-op",	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,	0)
+op(	ARROW,	"->",		1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,	1)
+op(	POINT,	".",		1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,	1)
+op(	NOT,	"!",		0,1,0,1,0,1,0,1,0,0,0,0,0,0,0,1,0,0,	1)
+op(	COMPL,	"~",		0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,1,1,1,	1)
+op(	INC,	"++",		0,0,0,0,0,0,0,0,0,0,0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0,0,0,0,1,0,0,0,0,0,1,0,0,	1)
+op(	XORASS,	"^=",		1,0,1,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,	1)
+op(	ORASS,	"|=",		1,0,1,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,	1)
+op(	NAME,	"name",		0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,	1)
+op(	CON,	"const",	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,	1)
+op(	STRING,	"string",	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,	1)
+op(	FSEL,	"fsel",		0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,	1)
+op(	CALL,	"call",		1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,	1)
+op(	COMMA,	",",		1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,	1)
+op(	CVT,	"convert",	0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,	1)
+op(	ICALL,	"icall",	1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,	1)
+op(	LOAD,	"load",		0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,	1)
+op(	PUSH,	"push",		0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,	1)
+op(	RETURN,	"return",	1,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,	1)
+op(	REAL,	"real",		0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,	0)
+op(	IMAG,	"imag",		0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,	0)
+/* INIT, CASE and FARG are pseudo operators that don't appear in the tree. */
+op(	INIT,	"init",		1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,	1)
+op(	CASE,	"case",		0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,	0)
+op(	FARG,	"farg",		1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,	1)
+/*	name	repr		b l i s a f v t b s l r p c e e q c	act */
+end_ops()
+
+#ifndef NOPS
+#  define NOPS ((int)FARG + 1)
+#endif
+
+#undef begin_ops
+#undef op
+#undef end_ops

Added files:

Index: src/usr.bin/xlint/lint1/ops.c
diff -u /dev/null src/usr.bin/xlint/lint1/ops.c:1.1
--- /dev/null	Tue Jan  5 23:50:29 2021
+++ src/usr.bin/xlint/lint1/ops.c	Tue Jan  5 23:50:29 2021
@@ -0,0 +1,64 @@
+/*	$NetBSD: ops.c,v 1.1 2021/01/05 23:50:29 rillig Exp $	*/
+
+/*-
+ * Copyright (c) 2021 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Roland Illig.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/types.h>
+#include "op.h"
+#include "param.h"
+
+mod_t modtab[NOPS];
+
+static const struct {
+	mod_t	m;
+	unsigned char	ok;
+} imods[] =
+#define begin_ops() {
+#define op(name, repr, \
+		bi, lo, in, sc, ar, fo, va, ts, ba, se, \
+		lu, ru, pc, cm, ve, de, ew, ic, active) \
+	{ { bi, lo, in, sc, ar, fo, va, ts, ba, se, \
+	    lu, ru, pc, cm, ve, de, ew, ic, repr }, active },
+#define end_ops(n) };
+#include "ops.def"
+
+const char *
+getopname(op_t op) {
+	return imods[op].m.m_name;
+}
+
+void
+initmtab(void)
+{
+	size_t i;
+
+	for (i = 0; i < sizeof imods / sizeof imods[0]; i++)
+		if (imods[i].ok)
+			modtab[i] = imods[i].m;
+}

Reply via email to