-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathPLI.C
More file actions
939 lines (706 loc) · 30.2 KB
/
Copy pathPLI.C
File metadata and controls
939 lines (706 loc) · 30.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
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
130
131
132
133
134
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
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
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
/****************************************************************************/
/* COPYRIGHT NOTICE */
/****************************************************************************/
/* A PL/I Compiler for the Win32 platform. */
/* Copyright (C) 1997 - 2006 Hugh Gleaves. */
/* */
/* This program is free software; you can redistribute it and/or */
/* modify it under the terms of the GNU General Public License */
/* as published by the Free Software Foundation; either version 2 */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program; if not, write to the Free Software */
/* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 */
/* USA. */
/****************************************************************************/
/****************************************************************************/
/* PL/1 Compiler */
/****************************************************************************/
/****************************************************************************/
/* Modification History */
/****************************************************************************/
/* Who When What */
/* ------------------------------------------------------------------------ */
/* HWG 13-07-90 Initial Prototype. Rel 1.0 */
/* HWG 20-07-90 Simple parser. Rel 1.1 */
/* HWG 18-09-90 Initial Symtab Rel 1.2 */
/* HWG 23-10-90 Converted to Turbo C, from MS-C. Rel 1.3 */
/* HWG 20-06-91 Storage allocater added. Rel 1.5 */
/* HWG 07-07-91 Options can now be defaulted in autoexec. Rel 1.7 */
/* HWG 08-07-91 Parse command help(F1) implemented. Rel 1.8 */
/* HWG 02-08-91 Major re-org of tokens/refs/symbols. Rel 2.1 */
/* HWG 18-09-91 Debugging switches trace_pass2/heap added. */
/* HWG 21-09-91 New switch -error added to create .err file. */
/* HWG 22-10-91 Total static storage now printed at end. */
/* HWG 24-10-91 External/internal procedure calls working. Rel 2.3 */
/* HWG 14-08-93 Only gen code if allocator was successful. */
/* HWG 14-08-93 Delete any semi-built .OBJ file. */
/* HWG 04-02-96 Dont print symtab if unable to compile, cos it */
/* will not be in any state to print ! */
/* */
/****************************************************************************/
/****************************************************************************/
/* Functional Description */
/****************************************************************************/
/* This module will extract command line arguments and verify existence of */
/* specified source file. */
/* The various phases that constitute the compiler, are called in sequence */
/* according to success of previous phases, and user selected options. */
/* */
/* Statistics for each phase are maintained and printed in here too. */
/****************************************************************************/
#include "windows.h"
#include <math.h>
#include <stdlib.h>
#include <string.h>
#ifndef X64
#include <dos.h>
#include "intaface.h"
#endif
#include <time.h>
#include <stdio.h>
#include "ctype.h"
#include "platform.h"
#include "token.h"
# define SOURCE_HELP "Enter the name of the source file, the 'pl1' suffix is optional."
# define LIST_HELP "Select this option, if you require a listing file."
# define NEST_HELP "Select this option, if you want nesting levels shown in the listing."
# define OPT_HELP "Select this option, if you want the precode optimizer to run."
# define BND_HELP "Select this option, if you want runtime array bound checking."
# define TABLE_HELP "Select this option, to retain debugging information in your program."
# define BEEP_HELP "Select this option, to beep on errors and completion."
# define SYS_HELP "Select this option, if you require an assembly listing."
# define CODE_HELP "Select this option, if you require an object module."
# define NDP_HELP "Select this option, if you require math coprocessor instructions generated."
# define DN_HELP "This option is reserved for engineering use only."
# define TH_HELP "This option is reserved for engineering use only."
# define TC_HELP "This option is reserved for engineering use only."
# define TP2_HELP "This option is reserved for engineering use only."
# define DBG_HELP "This option is reserved for engineering use only."
# define HALT_HELP "This option is reserved for engineering use only."
# define SEM_HELP "This option is reserved for engineering use only."
# define ERR_HELP "Select this option, if you require an error listing file."
# define MAP_HELP "Select this option, to accept uppercase source input."
# define UNREFS_HELP "Warn about unreferenced variables."
/* short CuiMenu (char * title, ...); */
# define _LINE_ ((short)__LINE__)
char stats[25][256];
long MilliSeconds(void);
long phase_start;
long phase_stop;
short duration;
short Err_count;
short Warn_count;
int able_to_compile;
int I;
short total_errs;
short total_warns;
short total_msecs;
short total_disk;
short unrecoverable_error = 0;
extern FILE *LISTING;
extern unsigned long symtab_heap_used;
extern unsigned long node_heap_used;
extern unsigned long nodes_allocated;
extern unsigned long code_bytes;
extern unsigned long bytes_read;
unsigned long total_static = 0;
short sects = 0;
double fsects;
double fbytes;
extern long total_lines;
extern long total_stmts;
double total_time = 0;
long rate = 0;
long srate = 0;
short system_reqd = 0;
short listing_reqd = 0;
short nesting_reqd = 0;
short error_reqd = 0;
short optimize_reqd = 0;
short bounds_reqd = 0;
short table_reqd = 0;
short code_reqd = 0;
short beep_reqd = 0;
short dump_reqd = 0;
short trace_heap = 0;
short trace_pass2 = 0;
short trace_code = 0;
short debug_reqd = 0;
short mapcase_reqd = 0;
short ndp_reqd = 0;
short halt_reqd = 0;
short unrefs_reqd = 0;
short semantic_reqd = 0;
extern char file[128];
char error_list[128] = "";
void open_error (char *);
void set_defaults (void);
int parse_program (void);
void enter_pass2 (void);
void allocator(char*);
void initialise (char*);
static void begin_init(void);
static void end_init(void);
void process_declares();
static void begin_declare(void);
static void end_declare(void);
static void begin_pass1(void);
static void end_pass1(void);
static void begin_pass2(void);
static void end_pass2(void);
static void begin_optimize(void);
/* void enter_optimizer(void); */
static void end_optimize(void);
static void begin_alloc(void);
static void end_alloc(void);
static void begin_code(void);
void enter_code(void);
static void end_code(void);
static void totals(void);
void report(short,char *,short);
void print_symtab (void);
void open_listing (char[]);
void dump_tree (void); /* DEBUG ONLY */
static void calc_disk_io (void);
Token_ptr get_token(void);
char program_path [128];
extern char * _pgmptr;
long except_code = 0;
void * except_addr = NULL;
char except_msg[32];
/***************************************************************************/
/* Win32 Exception handling support. */
/***************************************************************************/
long filterer (LPEXCEPTION_POINTERS);
/***************************************************************************/
/* Entry point for start of compilation. */
/***************************************************************************/
void main (long argcount,char * argvector[])
{
short status;
char obj_file [128] = "";
__try {
listing_reqd = 0;
strcpy (file,"");
set_defaults();
/***********************************************************************/
/* Because the compiler error file must be in the same dir as the */
/* compiler executable, we need the full path of the executable to */
/* work this out. MS Visual C++ (for DOS projects) puts the full path */
/* in argv[0], other implementations put only the program name. */
/***********************************************************************/
strcpy(program_path,_pgmptr);
#ifndef X64
status = AquireCmdLineArgs
("PL/I 32 Optimizing Compiler",argcount,argvector,
"posn(source_file),length(64),string,required",SOURCE_HELP,file,
"switch(list),color(9)",LIST_HELP,&listing_reqd,
"switch(nesting),color(9)",NEST_HELP,&nesting_reqd,
"switch(mapcase),color(9)",MAP_HELP,&mapcase_reqd,
"switch(error),color(9)",ERR_HELP,&error_reqd,
"switch(optimize),color(9)",OPT_HELP,&optimize_reqd,
"switch(bounds),color(9)",BND_HELP,&bounds_reqd,
"switch(ndp),color(9)",NDP_HELP,&ndp_reqd,
"switch(table),color(9)",TABLE_HELP,&table_reqd,
"switch(beep),color(9)",BEEP_HELP,&beep_reqd,
"switch(system),color(9)",SYS_HELP,&system_reqd,
"switch(code),color(9)",CODE_HELP,&code_reqd,
"switch(dump_nodes),secret,color(9)",DN_HELP,&dump_reqd,
"switch(trace_heap),color(9),secret",TH_HELP,&trace_heap,
"switch(trace_pass2),secret,color(9)",TP2_HELP,&trace_pass2,
"switch(trace_code),secret,color(9)",TC_HELP,&trace_code,
"switch(debug),secret,color(9)",TC_HELP,&debug_reqd,
"switch(halt),secret,color(9)",HALT_HELP,&halt_reqd,
"switch(unrefs),color(9)",UNREFS_HELP,&unrefs_reqd,
"switch(semantic),color(9)",SEM_HELP,&semantic_reqd,
"end,wide,color(14)");
if (status == 1019) /* Escape from form */
exit(0);
if (status != 0)
{
printf ("An error ocurred processing the command line arguments.\n");
exit(0);
}
#else
/*Replace lost source library with normal parsing of parameters */
/*First argument must be the filename, with or without extension */
/*Giuliano Vannini 2022-02-04*/
if (argcount < 2)
{
printf("Specificare il nome del file\n");
exit(0);
}
for (int i = 1; i < argcount; i++)
{
if (i == 1) strcpy(file, argvector[i]);
if(strcmp("+list" , argvector[i]) == 0) listing_reqd =1;
if(strcmp("+mapcase" , argvector[i]) == 0) mapcase_reqd = 1;
if(strcmp("+optimize" , argvector[i]) == 0) optimize_reqd = 1;
if(strcmp("+ndp" , argvector[i]) == 0) ndp_reqd = 1;
if(strcmp("+beep" , argvector[i]) == 0) beep_reqd = 1;
if(strcmp("+code" , argvector[i]) == 0) code_reqd = 1;
if(strcmp("+semantic" , argvector[i]) == 0) semantic_reqd = 1;
if(strcmp("+nesting" , argvector[i]) == 0) nesting_reqd = 1;
if(strcmp("+error" , argvector[i]) == 0) error_reqd = 1;
if(strcmp("+bounds" , argvector[i]) == 0) bounds_reqd = 1;
if(strcmp("+table" , argvector[i]) == 0) table_reqd = 1;
if(strcmp("+system" , argvector[i]) == 0) system_reqd = 1;
if(strcmp("+unrefs" , argvector[i]) == 0) unrefs_reqd = 1;
if(strcmp("+dump_nodes" , argvector[i]) == 0) dump_reqd = 1;
if(strcmp("+trace_heap" , argvector[i]) == 0) trace_heap = 1;
if(strcmp("+trace_pass2", argvector[i]) == 0) trace_pass2 = 1;
if(strcmp("+trace_code" , argvector[i]) == 0) trace_code = 1;
if(strcmp("+debug" , argvector[i]) == 0) debug_reqd = 1;
if(strcmp("+halt" , argvector[i]) == 0) halt_reqd = 1;
}
#endif
if (nesting_reqd || system_reqd) /* nesting implies listing */
listing_reqd = 1;
if (system_reqd)
code_reqd = 1;
if (ndp_reqd)
code_reqd = 1;
if ((code_reqd) || (unrefs_reqd) || (trace_pass2))
semantic_reqd = 1;
/***********************************************************/
/* Does the input file name end in .pl1 ? */
/***********************************************************/
strrev (file);
if (file[3] != '.')
{
strrev (file);
strcat (file,".pl1");
}
else
strrev (file);
/********************************************************************/
/* Set the pathname for the error listing to the same as the source */
/* file, but set the suffix to .err We must always delete any .err */
/* and any .obj */
/********************************************************************/
strcpy (error_list,file);
strrev (error_list);
error_list[0] = 'R';
error_list[1] = 'R';
error_list[2] = 'E';
strrev (error_list);
remove(error_list);
if (code_reqd)
{
strcpy (obj_file,file);
strrev (obj_file);
obj_file[0] = 'J';
obj_file[1] = 'B';
obj_file[2] = 'O';
strrev (obj_file);
remove(obj_file);
}
/*******************************************************************/
/* Initialise various bits and pieces. */
/*******************************************************************/
duration = 0;
Err_count = 0;
Warn_count = 0;
able_to_compile = 1;
total_errs = 0;
total_warns = 0;
total_msecs = 0;
total_disk = 0;
if (debug_reqd)
printf("Program pathname is: %s\n",program_path);
open_error(program_path);
/***********************************************************/
/* perform all required initialisation first. */
/***********************************************************/
begin_init();
initialise(file);
end_init();
if (listing_reqd)
{
open_listing (file);
}
/*************************************************************/
/* parse_program, is the main entry to the syntax phase. */
/* This phase reads the source file, parses the input, saves */
/* symbol entries and declarations, and constructs a parse */
/* tree. */
/*************************************************************/
begin_pass1();
parse_program();
end_pass1();
/**************************************************************/
/* The declare phase processes the symbol table constructed */
/* by the syntax phase.It reports on undeclared parameters. */
/* It also calcuates storage requiremenst, reports undeclared */
/* variables, and applies language defaults where required. */
/**************************************************************/
if (unrecoverable_error == 0)
{
begin_declare();
process_declares();
end_declare();
}
/**************************************************************/
/* The semantic phase walks-thru the parse-tree. */
/* This phase resolves all references to their declarations. */
/* It verifies that all variables are of the right data type */
/* for the context of their use. */
/* It creates temporary variables, and determines conversion */
/* requirements for different operations. */
/* Resultant data-types for conversions and expressions are */
/* also determined. */
/**************************************************************/
if ((unrecoverable_error == 0) && (semantic_reqd))
{
begin_pass2();
enter_pass2();
end_pass2();
}
/************************************************************/
/* Optimize the intermediate parse tree */
/************************************************************/
if (unrecoverable_error == 0)
if (able_to_compile)
if (optimize_reqd)
{
begin_optimize();
/* enter_optimizer(); */
end_optimize();
}
/************************************************************/
/* Print identifier attributes and xref information. */
/************************************************************/
if (unrecoverable_error == 0)
if (able_to_compile)
print_symtab();
/************************************************************/
/* The next two phases are only concerned with the creation */
/* of an object module. */
/* The allocator builds all the required parts of the obj */
/* module with the exception of code, it is concerned with */
/* the creation of external reference information, and the */
/* allocation and initialisation of static storage. */
/* The code generator analyses the parse-tree for each PL/1 */
/* block and generates machine instructions for each type */
/* of tree node. The actual creation of the raw instruction */
/* stream is performed by the code emitter, which is called */
/* from the code generator for each instruction required. */
/************************************************************/
if (unrecoverable_error == 0)
if ((able_to_compile) && (code_reqd))
{
begin_alloc();
allocator(file);
end_alloc();
if ((unrecoverable_error == 0) && (able_to_compile))
{
begin_code();
enter_code();
end_code();
}
/* Delete any semi-built .obj file. */
if ((unrecoverable_error) || (!able_to_compile))
remove(obj_file);
}
if (dump_reqd)
dump_tree();
/************************************************************/
/* If no errors or warning were produced, then delete any */
/* error file (one may exist from a previous compile). */
/************************************************************/
if (error_reqd)
if ((total_errs == 0) && (total_warns == 0))
remove (error_list);
/************************************************************/
/* print the compilation totals. */
/************************************************************/
totals();
if (beep_reqd)
{
sound (1500);
delay (100);
sound (1000);
delay (100);
}
nosound ();
if (able_to_compile == 0)
{
sprintf (stats[19],"\nTranslation Aborted\n");
printf (stats[19]);
}
if (halt_reqd)
{
printf("Halt requested, compiler has been suspended...\n");
os_sleep(-1);
}
exit(0);
} /* __try */
__except (filterer(GetExceptionInformation() ))
{
sprintf(except_msg,"(Code=%08lX, Addr=%08lX)",except_code,except_addr);
report(181,except_msg,(short)_LINE_);
exit(0);
}
}
/****************************************************************************/
/* These functions handle simple statistical totalling and reporting */
/****************************************************************************/
static void begin_init(void)
{
Err_count = 0;
Warn_count = 0;
phase_start = MilliSeconds();
memset(stats,0,sizeof(stats));
}
static void end_init (void)
{
double elapsed;
calc_disk_io();
phase_stop = MilliSeconds();;
elapsed = phase_stop - phase_start;
duration = (short) elapsed;
if ((Err_count > 0) || (Warn_count > 0))
sprintf (stats[3],"\ninitialize %4d %4d %4d %4d\n",duration,Err_count,Warn_count,sects);
else
sprintf (stats[3],"initialize %4d %4d %4d %4d\n",duration,Err_count,Warn_count,sects);
printf (stats[3]);
total_time += duration;
duration = 0;
total_disk += sects;
total_errs += Err_count;
total_warns += Warn_count;
Err_count = 0; Warn_count = 0;
}
static void begin_declare(void)
{
Err_count = 0; Warn_count = 0;
phase_start = MilliSeconds();;
}
static void begin_pass1(void)
{
Err_count = 0; Warn_count = 0;
phase_start = MilliSeconds();;
}
static void end_pass1 (void)
{
double elapsed;
calc_disk_io();
phase_stop = MilliSeconds();;
elapsed = phase_stop - phase_start;
duration = (short) elapsed;
if ((Err_count > 0) || (Warn_count > 0))
sprintf (stats[4],"\nsyntax %4d %4d %4d %4d\n",duration,Err_count,Warn_count,sects);
else
sprintf (stats[4],"syntax %4d %4d %4d %4d\n",duration,Err_count,Warn_count,sects);
printf(stats[4]);
total_time += duration;
total_disk += sects;
total_errs += Err_count;
total_warns += Warn_count;
duration = 0;
Err_count = 0; Warn_count = 0;
}
static void end_declare (void)
{
double elapsed;
calc_disk_io();
phase_stop = MilliSeconds();;
elapsed = phase_stop - phase_start;
duration = (short) elapsed;
if ((Err_count > 0) || (Warn_count > 0))
sprintf (stats[5],"\ndeclare %4d %4d %4d %4d\n",duration,Err_count,Warn_count,sects);
else
sprintf (stats[5],"declare %4d %4d %4d %4d\n",duration,Err_count,Warn_count,sects);
printf(stats[5]);
total_disk += sects;
total_time += duration;
total_errs += Err_count;
total_warns += Warn_count;
duration = 0;
Err_count = 0; Warn_count = 0;
}
static void begin_pass2(void)
{
Err_count = 0; Warn_count = 0;
phase_start = MilliSeconds();;
}
static void end_pass2 (void)
{
double elapsed;
calc_disk_io();
phase_stop = MilliSeconds();;
elapsed = phase_stop - phase_start;
duration = (short) elapsed;
if ((Err_count > 0) || (Warn_count > 0))
sprintf (stats[6],"\nsemantic %4d %4d %4d %4d\n",duration,Err_count,Warn_count,sects);
else
sprintf (stats[6],"semantic %4d %4d %4d %4d\n",duration,Err_count,Warn_count,sects);
printf(stats[6]);
total_disk += sects;
total_time += duration;
total_errs += Err_count;
total_warns += Warn_count;
duration = 0;
Err_count = 0; Warn_count = 0;
}
static void begin_optimize(void)
{
Err_count = 0; Warn_count = 0;
phase_start = MilliSeconds();;
}
static void end_optimize (void)
{
double elapsed;
calc_disk_io();
phase_stop = MilliSeconds();;
elapsed = phase_stop - phase_start;
duration = (short) elapsed;
if ((Err_count > 0) || (Warn_count > 0))
sprintf (stats[7],"\noptimize %4d %4d %4d %4d\n",duration,Err_count,Warn_count,sects);
else
sprintf (stats[7],"optimize %4d %4d %4d %4d\n",duration,Err_count,Warn_count,sects);
printf(stats[7]);
total_disk += sects;
total_time += duration;
total_errs += Err_count;
total_warns += Warn_count;
duration = 0;
Err_count = 0; Warn_count = 0;
}
static void begin_alloc(void)
{
Err_count = 0; Warn_count = 0;
phase_start = MilliSeconds();;
}
static void end_alloc (void)
{
double elapsed;
calc_disk_io();
phase_stop = MilliSeconds();;
elapsed = phase_stop - phase_start;
duration = (short) elapsed;
if ((Err_count > 0) || (Warn_count > 0))
sprintf (stats[8],"\nallocator %4d %4d %4d %4d\n",duration,Err_count,Warn_count,sects);
else
sprintf (stats[8],"allocator %4d %4d %4d %4d\n",duration,Err_count,Warn_count,sects);
printf(stats[8]);
total_disk += sects;
total_time += duration;
total_errs += Err_count;
total_warns += Warn_count;
duration = 0;
Err_count = 0; Warn_count = 0;
}
static void begin_code(void)
{
Err_count = 0; Warn_count = 0;
phase_start = MilliSeconds();;
}
static void end_code (void)
{
double elapsed;
calc_disk_io();
phase_stop = MilliSeconds();;
elapsed = phase_stop - phase_start;
duration = (short) elapsed;
if ((Err_count > 0) || (Warn_count > 0))
sprintf (stats[9],"\ntranslate %4d %4d %4d %4d\n",duration,Err_count,Warn_count,sects);
else
sprintf (stats[9],"translate %4d %4d %4d %4d\n",duration,Err_count,Warn_count,sects);
printf(stats[9]);
total_disk += sects;
total_time += duration;
total_errs += Err_count;
total_warns += Warn_count;
duration = 0;
Err_count = 0; Warn_count = 0;
}
static void totals (void)
{
calc_disk_io();
total_msecs = (short)total_time;
sprintf (stats[10],"totals %4d %4d %4d %4d\n",total_msecs,total_errs,total_warns,total_disk);
printf(stats[10]);
if (total_time == 0)
total_time = total_lines/24; /* approx extrapolated value */
if (total_time == 0)
total_time = 1;
rate = (long)(total_lines / (total_time / 1000)) ;
srate = (long)(total_stmts / (total_time / 1000)) ;
sprintf (stats[11],"\nSOURCE STMTS %d\n", total_stmts);
sprintf (stats[12], "SYMBOL TABLE %ld\n", symtab_heap_used);
if (optimize_reqd)
{
sprintf (stats[13], "NODE STORAGE %ld\n", node_heap_used);
sprintf (stats[14], "NODES NEEDED %ld\n", nodes_allocated);
}
printf(stats[11]);
printf(stats[12]);
if (optimize_reqd)
{
printf(stats[13]);
printf(stats[14]);
}
if (code_bytes > 0)
{
sprintf (stats[15], "CODE SIZE %ld\n", code_bytes);
printf(stats[15]);
}
if (total_static > 0)
{
sprintf (stats[16], "STATIC SIZE %ld\n", total_static);
printf(stats[16]);
}
sprintf (stats[17], "LINES/SECOND %ld\n", rate);
sprintf (stats[18], "STMTS/SECOND %ld\n", srate);
printf(stats[17]);
printf(stats[18]);
/*******************************************************************/
/* Print the compiler statistics and totals to the listing file */
/*******************************************************************/
if (listing_reqd)
{
fprintf(LISTING,"\f\n");
for (I = 0; I <= 19; I++)
{
/*************************************************************/
/* Some of these lines of stats info, may have a newline */
/* char at the front (for clean spacing on CRT whenreporting */
/* errors etc, BUT in the .lst file we do not want to see */
/* such spacing (cos errors dont get written to the .lst) */
/*************************************************************/
if ((I >= 3) && (I <=9)) /* only these lines are relevant */
if (isalpha(stats[I][0]))
fprintf (LISTING,stats[I]);
else
fprintf (LISTING,&(stats[I][1])); /* skip the \n */
else
fprintf (LISTING,stats[I]);
}
}
}
static void calc_disk_io (void)
{
fbytes = bytes_read;
fbytes = fbytes / 512;
fsects = ceil (fbytes);
sects = (short) fsects;
bytes_read = 0;
}
/************************************************************/
/* This is the Win32 exception filter function. */
/************************************************************/
long filterer (LPEXCEPTION_POINTERS machine_info)
{
/* if (machine->ExceptionRecord->ExceptionCode == EXCEPTION_ACCESS_VIOLATION)
printf("Exceptioncode: %08lX\n",machine->ExceptionRecord->ExceptionCode); */
except_code = machine_info->ExceptionRecord->ExceptionCode;
except_addr = machine_info->ExceptionRecord->ExceptionAddress;
return(EXCEPTION_EXECUTE_HANDLER);
}