Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/xlint/lint1 lint: clean up generation of the operato...
details: https://anonhg.NetBSD.org/src/rev/26f39be83310
branches: trunk
changeset: 979686:26f39be83310
user: rillig <rillig%NetBSD.org@localhost>
date: Tue Jan 05 23:50:29 2021 +0000
description:
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.
diffstat:
usr.bin/xlint/lint1/Makefile | 12 +-
usr.bin/xlint/lint1/Makefile.ops-c | 8 --
usr.bin/xlint/lint1/Makefile.ops-h | 10 --
usr.bin/xlint/lint1/mkops | 130 ----------------------------------
usr.bin/xlint/lint1/op.h | 13 ++-
usr.bin/xlint/lint1/ops.c | 64 +++++++++++++++++
usr.bin/xlint/lint1/ops.def | 139 ++++++++++++++++++++----------------
7 files changed, 157 insertions(+), 219 deletions(-)
diffs (truncated from 426 to 300 lines):
diff -r 10aad1407d68 -r 26f39be83310 usr.bin/xlint/lint1/Makefile
--- a/usr.bin/xlint/lint1/Makefile Tue Jan 05 23:20:53 2021 +0000
+++ b/usr.bin/xlint/lint1/Makefile Tue Jan 05 23:50:29 2021 +0000
@@ -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 @@
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
diff -r 10aad1407d68 -r 26f39be83310 usr.bin/xlint/lint1/Makefile.ops-c
--- a/usr.bin/xlint/lint1/Makefile.ops-c Tue Jan 05 23:20:53 2021 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,8 +0,0 @@
-# $NetBSD: Makefile.ops-c,v 1.3 2011/02/05 19:13:48 christos Exp $
-
-ops.c: mkops ops.def Makefile.ops-c
- ${_MKTARGET_CREATE}
- AWK=${TOOL_AWK:Q} ${HOST_SH} ${NETBSDSRCDIR}/usr.bin/xlint/lint1/mkops -c ${.ALLSRC:M*ops.def} > ${.TARGET}
-
-SRCS+= ops.c
-CLEANFILES+= ops.c
diff -r 10aad1407d68 -r 26f39be83310 usr.bin/xlint/lint1/Makefile.ops-h
--- a/usr.bin/xlint/lint1/Makefile.ops-h Tue Jan 05 23:20:53 2021 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,10 +0,0 @@
-# $NetBSD: Makefile.ops-h,v 1.3 2011/02/05 19:13:48 christos Exp $
-
-ops.h: ops.def mkops Makefile.ops-h
- ${_MKTARGET_CREATE}
- AWK=${TOOL_AWK:Q} ${HOST_SH} ${NETBSDSRCDIR}/usr.bin/xlint/lint1/mkops -h ${.ALLSRC:M*ops.def} > ${.TARGET}
-
-CLEANFILES+= ops.h
-DPSRCS+= ops.h
-
-op.h: ops.h
diff -r 10aad1407d68 -r 26f39be83310 usr.bin/xlint/lint1/mkops
--- a/usr.bin/xlint/lint1/mkops Tue Jan 05 23:20:53 2021 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,130 +0,0 @@
-#!/bin/sh -
-# $NetBSD: mkops,v 1.13 2021/01/05 21:40:42 rillig Exp $
-#
-# Copyright (c) 2011 The NetBSD Foundation, Inc.
-# All rights reserved.
-#
-# This code is derived from software contributed to The NetBSD Foundation
-# by Christos Zoulas.
-#
-# 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.
-
-# allow AWK to be overridden
-: "${AWK:=awk}"
-
-
-while getopts ch f
-do
- case $f in
- c)
- v=c;;
- h)
- v=h;;
- *)
- echo "Usage: $0 -c|-h";;
- esac
-done
-
-# shellcheck disable=SC2003
-shift "$(expr ${OPTIND} - 1)"
-
-# shellcheck disable=SC2016
-$AWK -F' ' -v v=$v '
-function println(s)
-{
- printf("%s\n", s);
-}
-
-function display(fmt, last, comment)
-{
- printf(fmt, last);
- if (comment != "")
- printf("\t/* pseudo op not used in trees */");
- println("");
-}
-
-BEGIN {
- print "/* Automatically generated file; do not edit */";
- if (v == "h") {
- println("typedef enum {");
- FIRST = "";
- LAST = "";
- LASTCOMMENT= "";
- }
- if (v == "c") {
- println("#include <sys/types.h>");
- println("#include \"op.h\"");
- println("#include \"param.h\"");
- println("#ifndef __arraycount");
- println("#define __arraycount(a) (sizeof(a) / sizeof(a[0]))");
- println("#endif /* __arraycount */");
- println("mod_t modtab[NOPS];");
- println("static const struct {");
- println("\tmod_t\tm;");
- println("\tunsigned char\tok;");
- println("} imods[] = {");
- }
-}
-
-{
- if (v == "h") {
- if (LAST != "") {
- if (FIRST == "") {
- display("\t%s\t= 0,", LAST, LASTCOMMENT);
- } else {
- display("\t%s,", LAST, LASTCOMMENT);
- }
- }
- FIRST = LAST;
- LAST = $1;
- LASTCOMMENT = $5;
- }
- if (v == "c")
- printf("\t{ /* %s */\t{ %s, \"%s\" }, %d },\n", $1, $3, $2, $4);
-}
-
-END {
- if (v == "h") {
- display("\t%s,", LAST, LASTCOMMENT);
- printf("#define\tNOPS\t((int)%s + 1)\n", LAST);
- println("} op_t;");
- println("const char *getopname(op_t);");
- println("void initmtab(void);");
- }
- if (v == "c") {
- println("};");
- println("const char *");
- println("getopname(op_t op) {");
- println("\treturn imods[op].m.m_name;");
- println("}");
- println("void");
- println("initmtab(void)");
- println("{");
- println("\tsize_t i;");
- println("");
- println("\tfor (i = 0; i < __arraycount(imods); i++)");
- println("\t\tif (imods[i].ok)");
- println("\t\t\tmodtab[i] = imods[i].m;");
- println("}");
- }
-}
-' "$@"
diff -r 10aad1407d68 -r 26f39be83310 usr.bin/xlint/lint1/op.h
--- a/usr.bin/xlint/lint1/op.h Tue Jan 05 23:20:53 2021 +0000
+++ b/usr.bin/xlint/lint1/op.h Tue Jan 05 23:50:29 2021 +0000
@@ -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 @@
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);
diff -r 10aad1407d68 -r 26f39be83310 usr.bin/xlint/lint1/ops.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/xlint/lint1/ops.c Tue Jan 05 23:50:29 2021 +0000
@@ -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;
+}
diff -r 10aad1407d68 -r 26f39be83310 usr.bin/xlint/lint1/ops.def
--- a/usr.bin/xlint/lint1/ops.def Tue Jan 05 23:20:53 2021 +0000
+++ b/usr.bin/xlint/lint1/ops.def Tue Jan 05 23:50:29 2021 +0000
@@ -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 ~ 0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,1,1,1 1
-INC ++ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 0
-DEC -- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 0
-INCBEF ++x 0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0 1
-DECBEF --x 0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0 1
-INCAFT x++ 0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0 1
-DECAFT x-- 0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0 1
-UPLUS + 0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,1,1,0 1
-UMINUS - 0,0,0,0,1,1,1,0,0,0,1,0,0,0,0,1,1,0 1
Home |
Main Index |
Thread Index |
Old Index