Annotation of src/usr.bin/make/generate.c, Revision 1.13
1.13 ! espie 1: /* $OpenBSD: generate.c,v 1.12 2010/07/19 19:46:44 espie Exp $ */
1.1 espie 2:
1.4 espie 3: /*
4: * Copyright (c) 2001 Marc Espie.
5: *
6: * Redistribution and use in source and binary forms, with or without
7: * modification, are permitted provided that the following conditions
8: * are met:
9: * 1. Redistributions of source code must retain the above copyright
10: * notice, this list of conditions and the following disclaimer.
11: * 2. Redistributions in binary form must reproduce the above copyright
12: * notice, this list of conditions and the following disclaimer in the
13: * documentation and/or other materials provided with the distribution.
14: *
15: * THIS SOFTWARE IS PROVIDED BY THE OPENBSD PROJECT AND CONTRIBUTORS
16: * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBSD
19: * PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26: */
27:
28: #include <stddef.h>
1.1 espie 29: #include <stdio.h>
1.6 espie 30: #include <stdint.h>
1.1 espie 31: #include <stdlib.h>
32:
1.3 espie 33: #include "stats.h"
1.1 espie 34: #include "ohash.h"
1.3 espie 35: #include "cond_int.h"
1.4 espie 36: #include "var_int.h"
1.9 espie 37: #include "node_int.h"
1.1 espie 38:
39: #define M(x) x, #x
1.3 espie 40: char *table_var[] = {
1.1 espie 41: M(TARGET),
42: M(OODATE),
43: M(ALLSRC),
44: M(IMPSRC),
45: M(PREFIX),
46: M(ARCHIVE),
47: M(MEMBER),
48: M(LONGTARGET),
49: M(LONGOODATE),
50: M(LONGALLSRC),
51: M(LONGIMPSRC),
52: M(LONGPREFIX),
53: M(LONGARCHIVE),
1.3 espie 54: M(LONGMEMBER),
55: M(FTARGET),
56: M(DTARGET),
57: M(FPREFIX),
58: M(DPREFIX),
59: M(FARCHIVE),
60: M(DARCHIVE),
61: M(FMEMBER),
62: M(DMEMBER),
63: NULL
1.1 espie 64: };
65:
1.3 espie 66: char *table_cond[] = {
67: M(COND_IF),
68: M(COND_IFDEF),
69: M(COND_IFNDEF),
70: M(COND_IFMAKE),
71: M(COND_IFNMAKE),
72: M(COND_ELSE),
1.5 espie 73: M(COND_ELIF),
1.3 espie 74: M(COND_ELIFDEF),
75: M(COND_ELIFNDEF),
76: M(COND_ELIFMAKE),
77: M(COND_ELIFNMAKE),
78: M(COND_ENDIF),
79: M(COND_FOR),
1.5 espie 80: M(COND_ENDFOR),
1.3 espie 81: M(COND_INCLUDE),
82: M(COND_UNDEF),
1.7 espie 83: M(COND_POISON),
1.3 espie 84: NULL
85: };
86:
1.9 espie 87: char *table_nodes[] = {
88: M(NODE_DEFAULT),
89: M(NODE_EXEC),
90: M(NODE_IGNORE),
91: M(NODE_INCLUDES),
92: M(NODE_INVISIBLE),
93: M(NODE_JOIN),
94: M(NODE_LIBS),
95: M(NODE_MADE),
96: M(NODE_MAIN),
97: M(NODE_MAKE),
98: M(NODE_MAKEFLAGS),
99: M(NODE_MFLAGS),
100: M(NODE_NOTMAIN),
101: M(NODE_NOTPARALLEL),
102: M(NODE_NO_PARALLEL),
103: M(NODE_NULL),
104: M(NODE_OPTIONAL),
105: M(NODE_ORDER),
106: M(NODE_PARALLEL),
107: M(NODE_PATH),
108: M(NODE_PHONY),
109: M(NODE_PRECIOUS),
110: M(NODE_RECURSIVE),
111: M(NODE_SILENT),
112: M(NODE_SINGLESHELL),
113: M(NODE_SUFFIXES),
114: M(NODE_USE),
115: M(NODE_WAIT),
116: M(NODE_BEGIN),
117: M(NODE_END),
118: M(NODE_INTERRUPT),
1.13 ! espie 119: M(NODE_CHEAP),
! 120: M(NODE_EXPENSIVE),
1.9 espie 121: NULL
122: };
123:
1.3 espie 124:
125: char **table[] = {
126: table_var,
1.9 espie 127: table_cond,
128: table_nodes
1.3 espie 129: };
1.1 espie 130:
131: int
132: main(int argc, char *argv[])
133: {
1.6 espie 134: uint32_t i;
135: uint32_t v;
136: uint32_t h;
137: uint32_t slots;
1.1 espie 138: const char *e;
139: char **occupied;
1.3 espie 140: char **t;
141: int tn;
1.1 espie 142:
143: Init_Stats();
1.3 espie 144: if (argc != 3)
1.1 espie 145: exit(1);
146:
1.3 espie 147: tn = atoi(argv[1]);
148: if (!tn)
1.1 espie 149: exit(1);
1.3 espie 150: t = table[tn-1];
151: slots = atoi(argv[2]);
152: if (slots) {
1.8 espie 153: occupied = calloc(sizeof(char *), slots);
1.3 espie 154: if (!occupied)
155: exit(1);
156: for (i = 0; i < slots; i++)
157: occupied[i] = NULL;
158: } else
159: occupied = NULL;
160:
1.10 espie 161: printf("/* File created by generate %d %d, do not edit */\n",
1.3 espie 162: tn, slots);
163: for (i = 0; t[i] != NULL; i++) {
1.1 espie 164: e = NULL;
1.3 espie 165: v = ohash_interval(t[i], &e);
166: if (slots) {
167: h = v % slots;
168: if (occupied[h]) {
1.10 espie 169: fprintf(stderr,
1.3 espie 170: "Collision: %s / %s (%d)\n", occupied[h],
171: t[i], h);
172: exit(1);
173: }
174: occupied[h] = t[i];
1.1 espie 175: }
1.3 espie 176: i++;
177: printf("#define K_%s %u\n", t[i], v);
1.1 espie 178: }
1.3 espie 179: if (slots)
180: printf("#define MAGICSLOTS%d %u\n", tn, slots);
1.1 espie 181: exit(0);
182: }