GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: usr.bin/make/generate.c Lines: 24 30 80.0 %
Date: 2016-12-06 Branches: 13 18 72.2 %

Line Branch Exec Source
1
/*	$OpenBSD: generate.c,v 1.17 2015/04/18 18:28:37 deraadt Exp $ */
2
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>
29
#include <stdint.h>
30
#include <stdio.h>
31
#include <stdlib.h>
32
#include <limits.h>
33
#include <ohash.h>
34
35
#include "stats.h"
36
#include "cond_int.h"
37
#include "var_int.h"
38
#include "node_int.h"
39
40
#define M(x)	x, #x
41
char *table_var[] = {
42
	M(TARGET),
43
	M(OODATE),
44
	M(ALLSRC),
45
	M(IMPSRC),
46
	M(PREFIX),
47
	M(ARCHIVE),
48
	M(MEMBER),
49
	M(LONGTARGET),
50
	M(LONGOODATE),
51
	M(LONGALLSRC),
52
	M(LONGIMPSRC),
53
	M(LONGPREFIX),
54
	M(LONGARCHIVE),
55
	M(LONGMEMBER),
56
	M(FTARGET),
57
	M(DTARGET),
58
	M(FPREFIX),
59
	M(DPREFIX),
60
	M(FARCHIVE),
61
	M(DARCHIVE),
62
	M(FMEMBER),
63
	M(DMEMBER),
64
	NULL
65
};
66
67
char *table_cond[] = {
68
	M(COND_IF),
69
	M(COND_IFDEF),
70
	M(COND_IFNDEF),
71
	M(COND_IFMAKE),
72
	M(COND_IFNMAKE),
73
	M(COND_ELSE),
74
	M(COND_ELIF),
75
	M(COND_ELIFDEF),
76
	M(COND_ELIFNDEF),
77
	M(COND_ELIFMAKE),
78
	M(COND_ELIFNMAKE),
79
	M(COND_ENDIF),
80
	M(COND_FOR),
81
	M(COND_ENDFOR),
82
	M(COND_INCLUDE),
83
	M(COND_UNDEF),
84
	M(COND_POISON),
85
	NULL
86
};
87
88
char *table_nodes[] = {
89
	M(NODE_DEFAULT),
90
	M(NODE_EXEC),
91
	M(NODE_IGNORE),
92
	M(NODE_INCLUDES),
93
	M(NODE_INVISIBLE),
94
	M(NODE_JOIN),
95
	M(NODE_LIBS),
96
	M(NODE_MADE),
97
	M(NODE_MAIN),
98
	M(NODE_MAKE),
99
	M(NODE_MAKEFLAGS),
100
	M(NODE_MFLAGS),
101
	M(NODE_NOTMAIN),
102
	M(NODE_NOTPARALLEL),
103
	M(NODE_NO_PARALLEL),
104
	M(NODE_NULL),
105
	M(NODE_OPTIONAL),
106
	M(NODE_ORDER),
107
	M(NODE_PARALLEL),
108
	M(NODE_PATH),
109
	M(NODE_PHONY),
110
	M(NODE_PRECIOUS),
111
	M(NODE_RECURSIVE),
112
	M(NODE_SILENT),
113
	M(NODE_SINGLESHELL),
114
	M(NODE_SUFFIXES),
115
	M(NODE_USE),
116
	M(NODE_WAIT),
117
	M(NODE_BEGIN),
118
	M(NODE_END),
119
	M(NODE_INTERRUPT),
120
	M(NODE_CHEAP),
121
	M(NODE_EXPENSIVE),
122
	M(NODE_POSIX),
123
	M(NODE_SCCS_GET),
124
	NULL
125
};
126
127
128
char **table[] = {
129
	table_var,
130
	table_cond,
131
	table_nodes
132
};
133
134
int
135
main(int argc, char *argv[])
136
3
{
137
	uint32_t i;
138
	uint32_t v;
139
	uint32_t h;
140
	uint32_t slots;
141
	const char *errstr;
142
	const char *e;
143
	char **occupied;
144
	char **t;
145
	int tn;
146
147
	Init_Stats();
148
3
	if (argc != 3)
149
		exit(1);
150
151
3
	tn = strtonum(argv[1], 1, INT_MAX, &errstr);
152
3
	if (errstr)
153
		exit(1);
154
3
	t = table[tn-1];
155
3
	slots = strtonum(argv[2], 0, INT_MAX, &errstr);
156
3
	if (errstr)
157
		exit(1);
158
3
	if (slots) {
159
2
		occupied = calloc(slots, sizeof(char *));
160
2
		if (!occupied)
161
			exit(1);
162
	} else
163
1
		occupied = NULL;
164
165
3
	printf("/* File created by generate %d %d, do not edit */\n",
166
	    tn, slots);
167
77
	for (i = 0; t[i] != NULL; i++) {
168
74
		e = NULL;
169
74
		v = ohash_interval(t[i], &e);
170
74
		if (slots) {
171
39
			h = v % slots;
172
39
			if (occupied[h]) {
173
				fprintf(stderr,
174
				    "Collision: %s / %s (%d)\n", occupied[h],
175
				    t[i], h);
176
				exit(1);
177
			}
178
39
			occupied[h] = t[i];
179
		}
180
74
		i++;
181
74
		printf("#define K_%s %u\n", t[i], v);
182
	}
183
3
	if (slots)
184
2
		printf("#define MAGICSLOTS%d %u\n", tn, slots);
185
3
	exit(0);
186
}