Annotation of src/usr.bin/make/generate.c, Revision 1.12
1.12 ! espie 1: /* $OpenBSD: generate.c,v 1.11 2010/07/19 19:30:37 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),
119: NULL
120: };
121:
1.3 espie 122:
123: char **table[] = {
124: table_var,
1.9 espie 125: table_cond,
126: table_nodes
1.3 espie 127: };
1.1 espie 128:
129: int
130: main(int argc, char *argv[])
131: {
1.6 espie 132: uint32_t i;
133: uint32_t v;
134: uint32_t h;
135: uint32_t slots;
1.1 espie 136: const char *e;
137: char **occupied;
1.3 espie 138: char **t;
139: int tn;
1.1 espie 140:
141: Init_Stats();
1.3 espie 142: if (argc != 3)
1.1 espie 143: exit(1);
144:
1.3 espie 145: tn = atoi(argv[1]);
146: if (!tn)
1.1 espie 147: exit(1);
1.3 espie 148: t = table[tn-1];
149: slots = atoi(argv[2]);
150: if (slots) {
1.8 espie 151: occupied = calloc(sizeof(char *), slots);
1.3 espie 152: if (!occupied)
153: exit(1);
154: for (i = 0; i < slots; i++)
155: occupied[i] = NULL;
156: } else
157: occupied = NULL;
158:
1.10 espie 159: printf("/* File created by generate %d %d, do not edit */\n",
1.3 espie 160: tn, slots);
161: for (i = 0; t[i] != NULL; i++) {
1.1 espie 162: e = NULL;
1.3 espie 163: v = ohash_interval(t[i], &e);
164: if (slots) {
165: h = v % slots;
166: if (occupied[h]) {
1.10 espie 167: fprintf(stderr,
1.3 espie 168: "Collision: %s / %s (%d)\n", occupied[h],
169: t[i], h);
170: exit(1);
171: }
172: occupied[h] = t[i];
1.1 espie 173: }
1.3 espie 174: i++;
175: printf("#define K_%s %u\n", t[i], v);
1.1 espie 176: }
1.3 espie 177: if (slots)
178: printf("#define MAGICSLOTS%d %u\n", tn, slots);
1.1 espie 179: exit(0);
180: }