cocl.c 7.51 KB
Newer Older
clean's avatar
clean committed
1
2
3
4

#include "compiledefines.h"
#include "comsupport.h"
#include "settings.h"
5
#include <ctype.h>
clean's avatar
clean committed
6
7
8
9
10
#include "compiler.h"
#include "version.h"

#include "MAIN_CLM.d"

11
12
13
14
#ifdef _SUN_
FILE *std_out_file_p,*std_error_file_p;
#endif

clean's avatar
clean committed
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
static char usage[]=
	"Usage: \'cocl [options] [-o file] file\'\n"
	"Options: [-v] [-w] [-tc] [-d] [-sl] [-p] [-sa] [-lt] [-lset] [-lat] [-lattr]";

static void Usage (void)
{
	FPutS (usage, StdError);
	FPutC ('\n', StdError);
}

static Bool GetInt (char *s, int *i)
{
	int j;
	char *cp;
	
	for (j = 0, cp = s; *cp; cp++)
	{	if (!isdigit (*cp))
			return False;
		
		j = (10 * j) + (*cp - '0');
	}
	*i = j;
	return True;
}

static Bool SetStrictOption (char *opt)
{	int i;

	if (strcmp (opt, "w") == 0)
		DoStrictWarning = False;
	else if (strcmp (opt, "wa") == 0)
		DoStrictAllWarning = True;
	else if (strcmp (opt, "c") == 0)
		DoStrictCheck = True;
	else if (strcmp (opt, "sa") == 0)
		StrictDoAnnots = True;
	else if (opt[0] == 'd')
	{	if (GetInt (opt+1, &i))
			StrictDepth = i;
		else
			return False;
	}
	else
		return False;

	return True;
}

char *path_parameter;
#ifdef _SUN_
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
65
int use_clean_system_files;
clean's avatar
clean committed
66
67
68
#endif

#ifdef CLEAN2
69
int StdOutReopened,StdErrorReopened;
clean's avatar
clean committed
70
71
#endif

72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#if defined (_MAC_) && defined (GNU_C)
extern char *convert_file_name (char *file_name,char *buffer);

static FILE *freopen_with_file_name_conversion (char *file_name,char *mode,FILE *file_p)
{
	char buffer[512+1];

	file_name=convert_file_name (file_name,buffer);
	if (file_name==NULL)
		return NULL;

	return freopen (file_name,mode,file_p);
}

# define freopen freopen_with_file_name_conversion
#endif

clean's avatar
clean committed
89
90
91
92
93
94
95
96
97
#ifdef CLEAN2
Bool ParseCommandArgs (int argc, char **argv, char **file_name_p, char **output_file_name_p)
#else
Bool CallCompiler (int argc, char **argv)
#endif
{
	char *fname,*output_file_name;
	int i;

98
99
100
101
# ifdef _SUN_
	std_out_file_p = stdout;
	std_error_file_p = stderr;
# endif
clean's avatar
clean committed
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129

	fname = NULL;
	output_file_name=NULL;

	path_parameter=NULL;
#ifdef _SUN_
	use_clean_system_files=0;
#endif
	
	DoWarning 				= True;
	DoVerbose 				= False;
	DoCode					= True;
	DoDebug 				= False;
	DoStrictnessAnalysis	= True;
	DoStackLayout			= True /* False */;
	DoParallel				= False;
	DoShowAttributes		= True;
	DoListTypes				= False;
	DoListAllTypes			= False;
	DoListStrictTypes		= False;

	DoStrictCheck			= False;
	DoStrictWarning			= True;
	DoStrictAllWarning		= False;

	DoProfiling=False;
	DoTimeProfiling=False;
	DoReuseUniqueNodes=False;
John van Groningen's avatar
John van Groningen committed
130
	DoFusion=False;
131
132
	DoDescriptors=False;
	ExportLocalLabels=False;
133
	AddStrictnessToExportedFunctionTypes=False;
134
	Dynamics=False;
clean's avatar
clean committed
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187

	StrictDoAnnots			= False;
	StrictDepth				= 10;/* 8; */

	FunctionMayFailIsError	= False;

#ifdef CLEAN2
	StdErrorReopened	= False;
	StdOutReopened		= False;
#endif

	for (i = 0; i < argc; i++){
		if (argv[i][0] == '-' || argv[i][0] == '+'){
			char *argv_i;
			
			argv_i=argv[i];
			
			if (strcmp (argv_i, "-v") == 0)
				DoVerbose = True;
			else if (strcmp (argv_i, "-w") == 0){
				DoWarning = False;
				DoStrictWarning	= False;
			} else if (strcmp (argv_i, "-d") == 0)
				DoDebug = True;
			else if (strcmp (argv_i, "-c") == 0)
				DoCode = False;
			else if (strcmp (argv_i, "-p") == 0)
				DoParallel = True;
#ifdef _SUN_
			else if (strcmp (argv_i, "-csf")==0)
				use_clean_system_files=1;
#endif
			else if (strcmp (argv_i, "-sl") == 0)
				DoStackLayout = True;
			else if (strcmp (argv_i, "-sa") == 0)
				DoStrictnessAnalysis = False;
			else if (strcmp (argv_i, "-lattr") == 0)
				DoShowAttributes = False;
			else if (strcmp (argv_i, "-lt") == 0)
				DoListTypes = True;
			else if (strcmp (argv_i, "-lset") == 0)
				DoListStrictTypes = True;				
			else if (strcmp (argv_i, "-lat") == 0)
				DoListAllTypes = True;
			else if (strcmp (argv_i,"-ou") == 0)
				DoReuseUniqueNodes=True;
			else if (strcmp (argv_i,"-pm") == 0)
				DoProfiling=True;
			else if (strcmp (argv_i,"-pt") == 0)
				DoTimeProfiling=True;
			else if (strcmp (argv_i,"-wmt") == 0)
				WriteModificationTimes=True;
			else if (strcmp (argv_i,"-emf") == 0)
188
				FunctionMayFailIsError=True;
clean's avatar
clean committed
189
190
191
192
			else if (strcmp (argv_i,"-desc") ==0)
				DoDescriptors=True;
			else if (strcmp (argv_i,"-exl") ==0)
				ExportLocalLabels=True;
John van Groningen's avatar
John van Groningen committed
193
194
			else if (strcmp (argv_i,"-fusion") == 0)
				DoFusion=True;
195
196
			else if (strcmp (argv_i,"-seft") == 0)
				AddStrictnessToExportedFunctionTypes=True;
197
198
			else if (strcmp (argv_i,"-dynamics") == 0)
				Dynamics=True;
clean's avatar
clean committed
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
			else if (strncmp (argv_i, "-sa", 3) == 0){
				if (!SetStrictOption (argv[i]+3)){
					CmdError ("unknown flag %s", argv[i]);
					Usage ();
					return False;
				}
			} else if (strcmp (argv_i, "-o") == 0){
				if (++i < argc)
					output_file_name = argv[i];
				else {
					CmdError ("no output file given to option -o");
					return False;
				}
			} else if (strcmp (argv_i, "-P") == 0){
				if (++i < argc)
					path_parameter = argv[i];
				else {
					CmdError ("no path list given to option -P");
					return False;
				}
			} else if (strcmp (argv_i, "-RE") == 0){
				if (++i < argc){
221
222
223
224
225
226
227
#ifdef _SUN_
					std_error_file_p = fopen (argv[i],"w");
					if (std_error_file_p!=NULL)
						StdErrorReopened = True;
					else
						std_error_file_p = stderr;
#else
clean's avatar
clean committed
228
					freopen (argv[i],"w",StdError);
229
# ifdef CLEAN2
clean's avatar
clean committed
230
					StdErrorReopened	= True;
231
# endif
clean's avatar
clean committed
232
233
234
235
236
237
238
#endif
				} else {
					CmdError ("file name expected after -RE");
					return False;
				}
			} else if (strcmp (argv_i, "-RAE") == 0){
				if (++i < argc){
239
240
241
242
243
244
245
#ifdef _SUN_
					std_error_file_p = fopen (argv[i],"aw");
					if (std_error_file_p!=NULL)
						StdErrorReopened = True;
					else
						std_error_file_p = stderr;
#else
clean's avatar
clean committed
246
					freopen (argv[i],"aw",StdError);
247
# ifdef CLEAN2
clean's avatar
clean committed
248
					StdErrorReopened	= True;
249
# endif
clean's avatar
clean committed
250
251
252
253
254
255
256
#endif
				} else {
					CmdError ("file name expected after -RAE");
					return False;
				}
			} else if (strcmp (argv_i, "-RO") == 0){
				if (++i < argc){
257
258
259
260
261
262
263
#ifdef _SUN_
					std_out_file_p = fopen (argv[i],"w");
					if (std_out_file_p!=NULL)
						StdOutReopened = True;
					else
						std_out_file_p = stdout;
#else
clean's avatar
clean committed
264
					freopen (argv[i],"w",StdOut);
265
# ifdef CLEAN2
clean's avatar
clean committed
266
					StdOutReopened	= True;
267
# endif
clean's avatar
clean committed
268
269
270
271
272
273
274
#endif
				} else {
					CmdError ("file name expected after -RO");
					return False;
				}
			} else if (strcmp (argv_i, "-RAO") == 0){
				if (++i < argc){
275
276
277
278
279
280
281
#ifdef _SUN_
					std_out_file_p = fopen (argv[i],"aw");
					if (std_out_file_p!=NULL)
						StdOutReopened = True;
					else
						std_out_file_p = stdout;
#else
clean's avatar
clean committed
282
					freopen (argv[i],"aw",StdOut);
283
# ifdef CLEAN2
clean's avatar
clean committed
284
					StdOutReopened	= True;
285
# endif
clean's avatar
clean committed
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
#endif
				} else {
					CmdError ("file name expected after -RAO");
					return False;
				}
			} else {
				CmdError ("unknown flag %s", argv_i);
				Usage ();
				return False;
			}
		} else {
			/* process (non-flag) argument */
			if (fname){
				CmdError ("only one input file allowed");
				return False;
			}
			fname = argv[i];
		}
	}

#ifdef CLEAN2
		*file_name_p=fname;
		*output_file_name_p=output_file_name;
	
	#ifdef _MAC_
		GetInitialPathList();
	#endif
	
		InitCompiler();
	
		return True;
	}
	/*
	Bool CallCompiler (int argc, char **argv)
	{
		char *fname, *output_file_name;
	
		if (!ParseCommandArgs (argc,argv,&fname,&output_file_name))
			return False;
	*/
#else

	if (fname)
		return Compile (fname,output_file_name);
	else if (DoVerbose){
		FPrintF (StdOut, "\nConcurrent Clean Compiler (Version %d.%d)\n\n", VERSION / 1000, VERSION % 1000);
		return True;
	} else {
		CmdError ("no input file given");
		Usage ();
		return False;
	}
}

#if ! defined (MAIN_CLM)
int main (int argc, char *argv[])
{
343
344
345
346
# ifdef _SUN_
	std_out_file_p = stdout;
	std_error_file_p = stderr;
# endif
clean's avatar
clean committed
347
348
349
350
351
352
353
354
355

	if (CallCompiler (argc-1, & argv[1]))
		return 0;
	else
		return 1;
}
#endif

#endif