]> gcc.gnu.org Git - gcc.git/blame - gcc/m2/gm2-compiler/M2Quads.def
Bugfix detect assigning constant constructors within a code block.
[gcc.git] / gcc / m2 / gm2-compiler / M2Quads.def
CommitLineData
7401123f
GM
1(* M2Quads.def generates quadruples.
2
3d864fce 3Copyright (C) 2001-2022 Free Software Foundation, Inc.
7401123f
GM
4Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
5
6This file is part of GNU Modula-2.
7
8GNU Modula-2 is free software; you can redistribute it and/or modify
9it under the terms of the GNU General Public License as published by
10the Free Software Foundation; either version 3, or (at your option)
11any later version.
12
13GNU Modula-2 is distributed in the hope that it will be useful, but
14WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with GNU Modula-2; see the file COPYING3. If not see
20<http://www.gnu.org/licenses/>. *)
21
22DEFINITION MODULE M2Quads ;
23
24(*
25 Author : Gaius Mulley
26 Title : M2Quads
27 Date : 3/6/87
28 Description: generates quadruples.
29*)
30
31FROM SYSTEM IMPORT WORD ;
32FROM DynamicStrings IMPORT String ;
33
34EXPORT QUALIFIED StartBuildDefFile, StartBuildModFile, EndBuildFile,
c196fa13 35 BuildModuleStart, BuildScaffold,
7401123f
GM
36 StartBuildInit, EndBuildInit,
37 StartBuildFinally, EndBuildFinally,
38 BuildExceptInitial, BuildExceptFinally,
39 BuildExceptProcedure,
40 BuildRetry,
41 BuildReThrow,
42 BuildBuiltinConst, BuildBuiltinTypeInfo,
806751e5
GM
43 BuildAssignment, BuildAssignConstant,
44 BuildAlignment,
7401123f
GM
45 BuildDefaultFieldAlignment, BuildPragmaField,
46 BuildRepeat, BuildUntil,
47 BuildWhile, BuildDoWhile, BuildEndWhile,
48 BuildLoop, BuildExit, BuildEndLoop,
49 BuildThenIf, BuildElse, BuildEndIf,
50 BuildElsif1, BuildElsif2,
51 BuildForToByDo, BuildPseudoBy, BuildEndFor,
52 BuildCaseStartStatementSequence,
53 BuildCaseEndStatementSequence,
54 BuildCaseList,
55 BuildCaseStart,
56 BuildCaseOr,
57 BuildCaseElse, BuildCaseEnd, BuildCaseCheck,
58 BuildCaseRange, BuildCaseEquality,
59 BuildNulParam, BuildProcedureCall,
60 CheckBuildFunction,
61 BuildFunctionCall, BuildConstFunctionCall,
62 BuildProcedureStart, BuildProcedureEnd,
63 BuildProcedureBegin,
64 BuildReturn,
65 BuildModulePriority,
66 BuildBooleanVariable,
67 BuildSizeCheckStart,
68 StartBuildWith, EndBuildWith, CheckWithReference,
69 BuildDesignatorRecord,
70 BuildDesignatorArray,
71 BuildDesignatorPointer,
72 BuildSetStart, BuildSetEnd,
73 BuildEmptySet,
74 BuildInclRange, BuildInclBit,
75 BuildNulExpression,
76 BuildNot,
77 BuildRelOp,
78 BuildBinaryOp,
79 BuildUnaryOp,
80 RecordOp,
81 Top,
82 PopTF, PushTF, PopT, PushT, PopNothing, PopN, PushTFA,
83 PushTtok, PushTFtok, PopTFtok, PopTtok, PushTFAtok,
84 PushTFn, PopTFn,
85 OperandT, OperandF, OperandA, OperandAnno, OperandTok,
86 DisplayStack, WriteOperand, Annotate,
87
88 BuildCodeOn, BuildCodeOff,
89 BuildProfileOn, BuildProfileOff,
90 BuildOptimizeOn, BuildOptimizeOff,
91 BuildInline, BuildStmtNote, BuildLineNo, PushLineNo,
92 BuildConstructor,
93 BuildConstructorStart,
94 BuildConstructorEnd,
95 NextConstructorField, BuildTypeForConstructor,
96 BuildComponentValue,
97 SilentBuildConstructor, SilentBuildConstructorStart,
98
99 SetOptionOptimizing, SetOptionCoding, SetOptionProfiling,
100
101 QuadOperator,
102 Opposite,
103
104 IsReferenced,
105 IsBackReference,
106 IsUnConditional,
107 IsConditional, IsBackReferenceConditional,
108 IsCall,
109 IsReturn,
110 IsProcedureScope,
111 IsNewLocalVar,
112 IsKillLocalVar,
113 IsCatchBegin,
114 IsCatchEnd,
115 IsInitStart,
116 IsInitEnd,
117 IsFinallyStart,
118 IsFinallyEnd,
119 IsCodeOn, (* Compiler flag testing routines *)
120 IsProfileOn,
121 IsOptimizeOn,
122 IsPseudoQuad,
123 IsDefOrModFile,
124 IsInitialisingConst,
125
126 DisplayQuadList, DisplayQuadRange, DisplayQuad,
127 WriteOperator, BackPatchSubrangesAndOptParam,
128
129 GetQuad, GetFirstQuad, GetNextQuad, PutQuad,
130 SubQuad, EraseQuad, GetRealQuad,
131 GetQuadtok, GetQuadOtok,
06642d29 132 GetQuadOp, GetM2OperatorDesc,
7401123f
GM
133 CountQuads,
134 GetLastFileQuad,
135 GetLastQuadNo,
136 QuadToLineNo, QuadToTokenNo,
137 VariableAnalysis, LoopAnalysis, ForLoopAnalysis,
138 AddVarientFieldToList, AddRecordToList,
139 AddVarientToList,
140 AddVarientRange, AddVarientEquality,
141 BeginVarient, EndVarient, ElseVarient,
142 BeginVarientList, EndVarientList,
143 IsAutoPushOn, PushAutoOn, PushAutoOff, PopAuto,
144 PushInConstExpression, PopInConstExpression,
145 IsInConstExpression,
146 MustCheckOverflow ;
147
148
149TYPE
150 QuadOperator = (BecomesOp, IndrXOp, XIndrOp, ArrayOp, ElementSizeOp,
151 RecordFieldOp,
5e2c046e 152 AddrOp, SizeOp,
7401123f
GM
153 IfEquOp, IfLessEquOp, IfGreEquOp, IfGreOp, IfLessOp,
154 IfNotEquOp, IfInOp, IfNotInOp,
155 CallOp, ParamOp, OptParamOp, ReturnOp, ReturnValueOp, FunctValueOp,
156 NewLocalVarOp, KillLocalVarOp,
157 ProcedureScopeOp, ModuleScopeOp,
158 DummyOp,
159 GotoOp, InitEndOp, InitStartOp,
160 FinallyStartOp, FinallyEndOp,
161 RetryOp, TryOp, CatchBeginOp, CatchEndOp, ThrowOp,
162 NegateOp, AddOp, SubOp, MultOp,
163 DivM2Op, ModM2Op,
164 DivCeilOp, ModCeilOp,
165 DivFloorOp, ModFloorOp, DivTruncOp, ModTruncOp,
166 LogicalOrOp, LogicalAndOp, LogicalXorOp, LogicalDiffOp,
167 InclOp, ExclOp, LogicalShiftOp, LogicalRotateOp,
168 UnboundedOp, HighOp,
169 CoerceOp, ConvertOp, CastOp,
170 InitAddressOp,
171 StartDefFileOp, StartModFileOp, EndFileOp,
172 CodeOnOp, CodeOffOp,
173 ProfileOnOp, ProfileOffOp,
174 OptimizeOnOp, OptimizeOffOp,
175 InlineOp, LineNumberOp, StatementNoteOp,
176 SubrangeLowOp, SubrangeHighOp,
177 BuiltinConstOp, BuiltinTypeInfoOp, StandardFunctionOp,
178 SavePriorityOp, RestorePriorityOp,
179 SaveExceptionOp, RestoreExceptionOp,
180 RangeCheckOp, ErrorOp) ;
181
182
183(*
184 SetOptionCoding - builds a code quadruple if the profiling
185 option was given to the compiler.
186*)
187
188PROCEDURE SetOptionCoding (b: BOOLEAN) ;
189
190
191(*
192 SetOptionProfiling - builds a profile quadruple if the profiling
193 option was given to the compiler.
194*)
195
196PROCEDURE SetOptionProfiling (b: BOOLEAN) ;
197
198
199(*
200 SetOptionOptimizing - builds a code quadruple if the profiling
201 option was given to the compiler.
202*)
203
204PROCEDURE SetOptionOptimizing (b: BOOLEAN) ;
205
206
207(*
208 Opposite - returns the opposite comparison operator.
209*)
210
211PROCEDURE Opposite (Operator: QuadOperator) : QuadOperator ;
212
213
214(*
215 IsReferenced - returns true if QuadNo is referenced by another quadruple.
216*)
217
218PROCEDURE IsReferenced (QuadNo: CARDINAL) : BOOLEAN ;
219
220
221(*
222 IsBackReference - returns TRUE if quadruple, q, is referenced from a quad further on.
223*)
224
225PROCEDURE IsBackReference (q: CARDINAL) : BOOLEAN ;
226
227
228(*
229 IsUnConditional - returns true if QuadNo is an unconditional jump.
230*)
231
232PROCEDURE IsUnConditional (QuadNo: CARDINAL) : BOOLEAN ;
233
234
235(*
236 IsConditional - returns true if QuadNo is a conditional jump.
237*)
238
239PROCEDURE IsConditional (QuadNo: CARDINAL) : BOOLEAN ;
240
241
242(*
243 IsBackReferenceConditional - returns TRUE if quadruple, q, is referenced from
244 a conditional quad further on.
245*)
246
247PROCEDURE IsBackReferenceConditional (q: CARDINAL) : BOOLEAN ;
248
249
250(*
251 IsCall - returns true if QuadNo is a call operation.
252*)
253
254PROCEDURE IsCall (QuadNo: CARDINAL) : BOOLEAN ;
255
256
257(*
258 IsReturn - returns true if QuadNo is a return operation.
259*)
260
261PROCEDURE IsReturn (QuadNo: CARDINAL) : BOOLEAN ;
262
263
264(*
265 IsProcedureScope - returns true if QuadNo is a ProcedureScope operation.
266*)
267
268PROCEDURE IsProcedureScope (QuadNo: CARDINAL) : BOOLEAN ;
269
270
271(*
272 IsNewLocalVar - returns true if QuadNo is a NewLocalVar operation.
273*)
274
275PROCEDURE IsNewLocalVar (QuadNo: CARDINAL) : BOOLEAN ;
276
277
278(*
279 IsKillLocalVar - returns true if QuadNo is a KillLocalVar operation.
280*)
281
282PROCEDURE IsKillLocalVar (QuadNo: CARDINAL) : BOOLEAN ;
283
284
285(*
286 IsCatchBegin - returns true if QuadNo is a catch begin quad.
287*)
288
289PROCEDURE IsCatchBegin (QuadNo: CARDINAL) : BOOLEAN ;
290
291
292(*
293 IsCatchEnd - returns true if QuadNo is a catch end quad.
294*)
295
296PROCEDURE IsCatchEnd (QuadNo: CARDINAL) : BOOLEAN ;
297
298
299(*
300 IsInitStart - returns true if QuadNo is a init start quad.
301*)
302
303PROCEDURE IsInitStart (QuadNo: CARDINAL) : BOOLEAN ;
304
305
306(*
307 IsInitEnd - returns true if QuadNo is a init end quad.
308*)
309
310PROCEDURE IsInitEnd (QuadNo: CARDINAL) : BOOLEAN ;
311
312
313(*
314 IsFinallyStart - returns true if QuadNo is a finally start quad.
315*)
316
317PROCEDURE IsFinallyStart (QuadNo: CARDINAL) : BOOLEAN ;
318
319
320(*
321 IsFinallyEnd - returns true if QuadNo is a finally end quad.
322*)
323
324PROCEDURE IsFinallyEnd (QuadNo: CARDINAL) : BOOLEAN ;
325
326
327(*
328 IsInitialisingConst - returns TRUE if the quadruple is setting
329 a const (op1) with a value.
330*)
331
332PROCEDURE IsInitialisingConst (QuadNo: CARDINAL) : BOOLEAN ;
333
334
335(*
336 IsOptimizeOn - returns true if the Optimize flag was true at QuadNo.
337*)
338
339PROCEDURE IsOptimizeOn (QuadNo: CARDINAL) : BOOLEAN ;
340
341
342(*
343 IsProfileOn - returns true if the Profile flag was true at QuadNo.
344*)
345
346PROCEDURE IsProfileOn (QuadNo: CARDINAL) : BOOLEAN ;
347
348
349(*
350 IsCodeOn - returns true if the Code flag was true at QuadNo.
351*)
352
353PROCEDURE IsCodeOn (QuadNo: CARDINAL) : BOOLEAN ;
354
355
356(*
357 IsPseudoQuad - returns true if QuadNo is a compiler directive.
358 ie code, profile and optimize.
359*)
360
361PROCEDURE IsPseudoQuad (QuadNo: CARDINAL) : BOOLEAN ;
362
363
364(*
365 IsDefOrModFile - returns TRUE if QuadNo is a start of Module or Def file
366 directive.
367*)
368
369PROCEDURE IsDefOrModFile (QuadNo: CARDINAL) : BOOLEAN ;
370
371
372(*
373 DisplayQuadList - displays all quads.
374*)
375
376PROCEDURE DisplayQuadList ;
377
378
379(*
380 DisplayQuadRange - displays all quads in list range, start..end.
381*)
382
383PROCEDURE DisplayQuadRange (start, end: CARDINAL) ;
384
385
386(*
387 DisplayQuad - displays a quadruple, QuadNo.
388*)
389
390PROCEDURE DisplayQuad (QuadNo: CARDINAL) ;
391
392
393(*
394 GetLastFileQuad - returns the Quadruple number of the last StartDefFile or
395 StartModFile quadruple.
396*)
397
398PROCEDURE GetLastFileQuad (QuadNo: CARDINAL) : CARDINAL ;
399
400
401(*
402 GetLastQuadNo - returns the last quadruple number referenced
403 by a GetQuad.
404*)
405
406PROCEDURE GetLastQuadNo () : CARDINAL ;
407
408
409(*
410 QuadToTokenNo - Converts a QuadNo into the approprate token number of the
411 source file, the line number is returned.
412
413 This may be used to yield an idea where abouts in the
414 source file the code generetion is
415 processing.
416*)
417
418PROCEDURE QuadToTokenNo (QuadNo: CARDINAL) : CARDINAL ;
419
420
421(*
422 QuadToLineNo - Converts a QuadNo into the approprate line number of the
423 source file, the line number is returned.
424
425 This may be used to yield an idea where abouts in the
426 source file the code generetion is
427 processing.
428*)
429
430PROCEDURE QuadToLineNo (QuadNo: CARDINAL) : CARDINAL ;
431
432
433(*
434 GetQuad - returns the Quadruple QuadNo.
435*)
436
437PROCEDURE GetQuad (QuadNo: CARDINAL;
438 VAR Op: QuadOperator;
439 VAR Oper1, Oper2, Oper3: CARDINAL) ;
440
441
06642d29
GM
442(*
443 GetQuadOp - returns the operator for quad.
444*)
445
446PROCEDURE GetQuadOp (quad: CARDINAL) : QuadOperator ;
447
448
449(*
450 GetM2OperatorDesc - returns the Modula-2 string associated with the quad operator
451 (if possible). It returns NIL if no there is not an obvious match
452 in Modula-2. It is assummed that the string will be used during
453 construction of error messages and therefore keywords are
454 wrapped with a format specifier.
455*)
456
457PROCEDURE GetM2OperatorDesc (op: QuadOperator) : String ;
458
459
7401123f
GM
460(*
461 GetQuadtok - returns the Quadruple QuadNo.
462*)
463
464PROCEDURE GetQuadtok (QuadNo: CARDINAL;
465 VAR Op: QuadOperator;
466 VAR Oper1, Oper2, Oper3: CARDINAL;
467 VAR Op1Pos, Op2Pos, Op3Pos: CARDINAL) ;
468
469
470(*
471 GetQuadOtok - returns the Quadruple QuadNo.
472*)
473
474PROCEDURE GetQuadOtok (QuadNo: CARDINAL;
475 VAR tok: CARDINAL;
476 VAR Op: QuadOperator;
477 VAR Oper1, Oper2, Oper3: CARDINAL;
478 VAR Op1Pos, Op2Pos, Op3Pos: CARDINAL) ;
479
480
481(*
482 PutQuad - overwrites a quadruple QuadNo with Op, Oper1, Oper2, Oper3
483*)
484
485PROCEDURE PutQuad (QuadNo: CARDINAL;
486 Op: QuadOperator;
487 Oper1, Oper2, Oper3: CARDINAL) ;
488
489(*
490 GetFirstQuad - returns the first quadruple.
491*)
492
493PROCEDURE GetFirstQuad () : CARDINAL ;
494
495
496(*
497 GetNextQuad - returns the Quadruple number following QuadNo.
498*)
499
500PROCEDURE GetNextQuad (QuadNo: CARDINAL) : CARDINAL ;
501
502
503(*
504 GetRealQuad - returns the Quadruple number of the real quadruple
505 at QuadNo or beyond.
506*)
507
508PROCEDURE GetRealQuad (QuadNo: CARDINAL) : CARDINAL ;
509
510
511(*
512 SubQuad - removes quadruple QuadNo.
513*)
514
515PROCEDURE SubQuad (QuadNo: CARDINAL) ;
516
517
518(*
519 EraseQuad - erases a quadruple QuadNo, the quaduple is still in the list
520 but wiped clean.
521*)
522
523PROCEDURE EraseQuad (QuadNo: CARDINAL) ;
524
525
526(*
527 CountQuads - returns the number of quadruples.
528*)
529
530PROCEDURE CountQuads () : CARDINAL ;
531
532
c196fa13
GM
533(*
534 BuildScaffold - generate the main, init, finish functions if
535 no -c and this is the application module.
536*)
537
538PROCEDURE BuildScaffold (tok: CARDINAL; moduleSym: CARDINAL) ;
539
540
7401123f
GM
541(*
542 StartBuildDefFile - generates a StartFileOp quadruple indicating the file
543 that has produced the subsequent quadruples.
544 The code generator uses the StartDefFileOp quadruples
545 to relate any error to the appropriate file.
546
547
548 Entry Exit
549 ===== ====
550
551
552 Ptr -> <- Ptr
553 +------------+ +------------+
554 | ModuleName | | ModuleName |
555 |------------| |------------|
556
557
558 Quadruples Produced
559
560 q StartDefFileOp _ _ ModuleSym
561*)
562
563PROCEDURE StartBuildDefFile ;
564
565
566(*
567 StartBuildModFile - generates a StartModFileOp quadruple indicating the file
568 that has produced the subsequent quadruples.
569 The code generator uses the StartModFileOp quadruples
570 to relate any error to the appropriate file.
571
572
573 Entry Exit
574 ===== ====
575
576
577 Ptr -> <- Ptr
578 +------------+ +------------+
579 | ModuleName | | ModuleName |
580 |------------| |------------|
581
582
583 Quadruples Produced
584
585 q StartModFileOp _ _ ModuleSym
586*)
587
588PROCEDURE StartBuildModFile ;
589
590
591(*
592 EndBuildFile - generates an EndFileOp quadruple indicating the file
593 that has produced the previous quadruples has ended.
594
595 Entry Exit
596 ===== ====
597
598
599 Ptr -> <- Ptr
600 +------------+ +------------+
601 | ModuleName | | ModuleName |
602 |------------| |------------|
603
604
605 Quadruples Produced
606
607 q EndFileOp _ _ ModuleSym
608*)
609
610PROCEDURE EndBuildFile ;
611
612
613(*
614 StartBuildInit - Builds the start initialisation code of a module.
615*)
616
617PROCEDURE StartBuildInit ;
618
619
620(*
621 EndBuildInit - Builds the end initialisation code of a module.
622*)
623
624PROCEDURE EndBuildInit ;
625
626
627(*
628 StartBuildFinally - Builds the start finalisation code of a module.
629*)
630
631PROCEDURE StartBuildFinally ;
632
633
634(*
635 EndBuildFinally - Builds the end finalisation code of a module.
636*)
637
638PROCEDURE EndBuildFinally ;
639
640
641(*
642 BuildExceptInitial - adds an ExceptOp quadruple in a modules
643 initial block.
644*)
645
646PROCEDURE BuildExceptInitial ;
647
648
649(*
650 BuildExceptFinally - adds an ExceptOp quadruple in a modules
651 finally block.
652*)
653
654PROCEDURE BuildExceptFinally ;
655
656
657(*
658 BuildExceptProcedure - adds an ExceptOp quadruple in a procedure
659 block.
660*)
661
662PROCEDURE BuildExceptProcedure ;
663
664
665(*
666 BuildRetry - adds an RetryOp quadruple.
667*)
668
669PROCEDURE BuildRetry ;
670
671
672(*
673 BuildReThrow - creates a ThrowOp _ _ NulSym, indicating that
674 the exception needs to be rethrown. The stack
675 is unaltered.
676*)
677
678PROCEDURE BuildReThrow (tokenno: CARDINAL) ;
679
680
681(*
682 StartBuildInnerInit - Sets the start of initialization code of the
683 inner module to the next quadruple.
684*)
685
686PROCEDURE StartBuildInnerInit ;
687
688
689(*
690 EndBuildInnerInit - Sets the end initialization code of a module.
691*)
692
693PROCEDURE EndBuildInnerInit ;
694
695
696(*
697 BuildBuiltinConst - makes reference to a builtin constant within gm2.
698
699 Entry Exit
700
701 Ptr ->
702 +------------+ +------------+
703 | Ident | | Sym |
704 |------------| |------------|
705
706 Quadruple produced:
707
708 q Sym BuiltinConstOp Ident
709*)
710
711PROCEDURE BuildBuiltinConst ;
712
713
714(*
715 BuildBuiltinTypeInfo - make reference to a builtin typeinfo function
716 within gm2.
717
718 Entry Exit
719
720 Ptr ->
721 +-------------+
722 | IdentType |
723 |-------------| +------------+
724 | ConstString | | Sym |
725 |-------------| |------------|
726
727 Quadruple produced:
728
729 q Sym BuiltinTypeInfoOp Ident ConstString
730*)
731
732PROCEDURE BuildBuiltinTypeInfo ;
733
734
735(*
736 BuildAssignment - Builds an assignment from the values given on the
737 quad stack. Either an assignment to an
738 arithmetic expression or an assignment to a
806751e5
GM
739 boolean expression. This procedure should not
740 be called in CONST declarations.
7401123f
GM
741 The Stack is expected to contain:
742
743
744 Either
745
746 Entry Exit
747 ===== ====
748
749 Ptr ->
750 +------------+
751 | Expression |
752 |------------|
753 | Designator |
754 |------------| +------------+
755 | | | | <- Ptr
756 |------------| |------------|
757
758
759 Quadruples Produced
760
761 q BecomesOp Designator _ Expression
762
763 OR
764
765 Entry Exit
766 ===== ====
767
768 Ptr ->
769 +------------+
770 | True |False|
771 |------------|
772 | Designator |
773 |------------| +------------+
774 | | | | <- Ptr
775 |------------| |------------|
776
777
778 Quadruples Produced
779
780 q BecomesOp Designator _ TRUE
781 q+1 GotoOp q+3
782 q+2 BecomesOp Designator _ FALSE
783
784*)
785
786PROCEDURE BuildAssignment (becomesTokNo: CARDINAL) ;
787
788
806751e5
GM
789(*
790 BuildAssignConstant - used to create constant in the CONST declaration.
791 The stack is expected to contain:
792
793 Either
794
795 Entry Exit
796 ===== ====
797
798 Ptr ->
799 +------------+
800 | Expression |
801 |------------|
802 | Designator |
803 |------------| +------------+
804 | | | | <- Ptr
805 |------------| |------------|
806
807
808 Quadruples Produced
809
810 q BecomesOp Designator _ Expression
811
812 OR
813
814 Entry Exit
815 ===== ====
816
817 Ptr ->
818 +------------+
819 | True |False|
820 |------------|
821 | Designator |
822 |------------| +------------+
823 | | | | <- Ptr
824 |------------| |------------|
825
826
827 Quadruples Produced
828
829 q BecomesOp Designator _ TRUE
830 q+1 GotoOp q+3
831 q+2 BecomesOp Designator _ FALSE
832*)
833
834PROCEDURE BuildAssignConstant (equalsTokNo: CARDINAL) ;
835
836
7401123f
GM
837(*
838 BuildAlignment - builds an assignment to an alignment constant.
839
840 The Stack is expected to contain:
841
842
843 Entry Exit
844 ===== ====
845
846 Ptr ->
847 +---------------+
848 | Expression |
849 |---------------|
850 | bytealignment |
851 |---------------| empty
852*)
853
854PROCEDURE BuildAlignment ;
855
856
857(*
858 BuildBitLength - builds an assignment to a bit length constant.
859
860 The Stack is expected to contain:
861
862
863 Entry Exit
864 ===== ====
865
866 Ptr ->
867 +------------+
868 | Expression |
869 |------------| empty
870*)
871
872PROCEDURE BuildBitLength ;
873
874
875(*
876 BuildPragmaField - builds an assignment to a pragma constant.
877
878 The Stack is expected to contain:
879
880
881 Entry Exit
882 ===== ====
883
884 Ptr ->
885 +------------+
886 | Expression |
887 |------------| empty
888*)
889
890PROCEDURE BuildPragmaField ;
891
892
893(*
894 BuildDefaultFieldAlignment - builds an assignment to an alignment constant.
895
896 The Stack is expected to contain:
897
898
899 Entry Exit
900 ===== ====
901
902 Ptr ->
903 +------------+
904 | Expression |
905 |------------| empty
906*)
907
908PROCEDURE BuildDefaultFieldAlignment ;
909
910
911(*
912 BuildRepeat - Builds the repeat statement from the quad stack.
913 The Stack is expected to contain:
914
915
916 Entry Exit
917 ===== ====
918
919
920 Empty
921 <- Ptr
922 +------------+
923 | RepeatQuad |
924 |------------|
925
926*)
927
928PROCEDURE BuildRepeat ;
929
930
931(*
932 BuildUntil - Builds the until part of the repeat statement
933 from the quad stack.
934 The Stack is expected to contain:
935
936
937 Entry Exit
938 ===== ====
939
940 Ptr ->
941 +------------+
942 | t | f |
943 |------------|
944 | RepeatQuad | Empty
945 |------------|
946*)
947
948PROCEDURE BuildUntil ;
949
950
951(*
952 BuildWhile - Builds the While part of the While statement
953 from the quad stack.
954 The Stack is expected to contain:
955
956
957 Entry Exit
958 ===== ====
959
960 <- Ptr
961 |------------|
962 Empty | WhileQuad |
963 |------------|
964*)
965
966PROCEDURE BuildWhile ;
967
968
969(*
970 BuildDoWhile - Builds the Do part of the while statement
971 from the quad stack.
972 The Stack is expected to contain:
973
974
975 Entry Exit
976 ===== ====
977
978 Ptr ->
979 +------------+ +------------+
980 | t | f | | 0 | f |
981 |------------| |------------|
982 | WhileQuad | | WhileQuad |
983 |------------| |------------|
984
985 Quadruples
986
987 BackPatch t exit to the NextQuad
988*)
989
990PROCEDURE BuildDoWhile ;
991
992
993(*
994 BuildEndWhile - Builds the end part of the while statement
995 from the quad stack.
996 The Stack is expected to contain:
997
998
999 Entry Exit
1000 ===== ====
1001
1002 Ptr ->
1003 +------------+
1004 | t | f |
1005 |------------|
1006 | WhileQuad | Empty
1007 |------------|
1008
1009 Quadruples
1010
1011 q GotoOp WhileQuad
1012 False exit is backpatched with q+1
1013*)
1014
1015PROCEDURE BuildEndWhile ;
1016
1017
1018(*
1019 BuildLoop - Builds the Loop part of the Loop statement
1020 from the quad stack.
1021 The Stack is expected to contain:
1022
1023
1024 Entry Exit
1025 ===== ====
1026
1027 <- Ptr
1028 Empty +------------+
1029 | LoopQuad |
1030 |------------|
1031*)
1032
1033PROCEDURE BuildLoop ;
1034
1035
1036(*
1037 BuildExit - Builds the Exit part of the Loop statement.
1038*)
1039
1040PROCEDURE BuildExit ;
1041
1042
1043(*
1044 BuildEndLoop - Builds the End part of the Loop statement
1045 from the quad stack.
1046 The Stack is expected to contain:
1047
1048
1049 Entry Exit
1050 ===== ====
1051
1052 Ptr ->
1053 +------------+
1054 | LoopQuad | Empty
1055 |------------|
1056
1057 Quadruples
1058
1059 Goto _ _ LoopQuad
1060*)
1061
1062PROCEDURE BuildEndLoop ;
1063
1064
1065(*
1066 BuildThenIf - Builds the Then part of the If statement
1067 from the quad stack.
1068 The Stack is expected to contain:
1069
1070
1071 Entry Exit
1072 ===== ====
1073
1074 Ptr -> <- Ptr
1075 +------------+ +------------+
1076 | t | f | | 0 | f |
1077 |------------| |------------|
1078
1079 Quadruples
1080
1081 The true exit is BackPatched to point to
1082 the NextQuad.
1083*)
1084
1085PROCEDURE BuildThenIf ;
1086
1087
1088(*
1089 BuildElse - Builds the Else part of the If statement
1090 from the quad stack.
1091 The Stack is expected to contain:
1092
1093
1094 Entry Exit
1095 ===== ====
1096
1097 Ptr ->
1098 +------------+ +------------+
1099 | t | f | | t+q | 0 |
1100 |------------| |------------|
1101
1102 Quadruples
1103
1104 q GotoOp _ _ 0
1105 q+1 <- BackPatched from f
1106*)
1107
1108PROCEDURE BuildElse ;
1109
1110
1111(*
1112 BuildEndIf - Builds the End part of the If statement
1113 from the quad stack.
1114 The Stack is expected to contain:
1115
1116
1117 Entry Exit
1118 ===== ====
1119
1120 Ptr ->
1121 +------------+
1122 | t | f | Empty
1123 |------------|
1124
1125 Quadruples
1126
1127 Both t and f are backpatched to point to the NextQuad
1128*)
1129
1130PROCEDURE BuildEndIf ;
1131
1132
1133(*
1134 BuildElsif1 - Builds the Elsif part of the If statement
1135 from the quad stack.
1136 The Stack is expected to contain:
1137
1138
1139 Entry Exit
1140 ===== ====
1141
1142 Ptr ->
1143 +------------+ +------------+
1144 | t | f | | t+q | 0 |
1145 |------------| |------------|
1146
1147 Quadruples
1148
1149 q GotoOp _ _ 0
1150 q+1 <- BackPatched from f
1151*)
1152
1153PROCEDURE BuildElsif1 ;
1154
1155
1156(*
1157 BuildElsif2 - Builds the Elsif until part of the If statement
1158 from the quad stack.
1159 The Stack is expected to contain:
1160
1161
1162 Entry Exit
1163 ===== ====
1164
1165 Ptr ->
1166 +--------------+
1167 | 0 | f1 | <- Ptr
1168 |--------------| +---------------+
1169 | t2 | f2 | | t2 | f1+f2 |
1170 |--------------| |---------------|
1171*)
1172
1173PROCEDURE BuildElsif2 ;
1174
1175
1176(*
1177 BuildForToByDo - Builds the For To By Do part of the For statement
1178 from the quad stack.
1179 The Stack is expected to contain:
1180
1181
1182 Entry Exit
1183 ===== ====
1184
1185
1186 Ptr -> <- Ptr
1187 +------------+ +------------+
1188 | BySym | | t | f |
1189 |------------| |------------|
1190 | e2 | | ForQuad |
1191 |------------| |------------|
1192 | e1 | | BySym |
1193 |------------| |------------|
1194 | Ident | | IdentSym |
1195 |------------| |------------|
1196
1197 Quadruple
1198
1199 q BecomesOp IdentSym _ e1
1200 q+1 if < by 0 q+5
1201 q+2 GotoOp q+3
1202 q+3 If > IdentSym e2 _
1203 q+4 GotoOp q+7
1204 q+5 If <= IdentSym e2 _
1205 q+6 GotoOp q+7
1206
1207
1208 The For Loop is regarded:
1209
1210 For ident := e1 To e2 By by Do
1211
1212 End
1213*)
1214
1215PROCEDURE BuildForToByDo ;
1216
1217
1218(*
1219 BuildPseudoBy - Builds the Non existant part of the By
1220 clause of the For statement
1221 from the quad stack.
1222 The Stack is expected to contain:
1223
1224
1225 Entry Exit
1226 ===== ====
1227
1228 <- Ptr
1229 +------------+
1230 Empty | BySym |
1231 |------------|
1232*)
1233
1234PROCEDURE BuildPseudoBy ;
1235
1236
1237(*
1238 BuildEndFor - Builds the End part of the For statement
1239 from the quad stack.
1240 The Stack is expected to contain:
1241
1242
1243 Entry Exit
1244 ===== ====
1245
1246 Ptr ->
1247 +------------+
1248 | t | f |
1249 |------------|
1250 | ForQuad |
1251 |------------|
1252 | BySym |
1253 |------------|
1254 | IdSym | Empty
1255 |------------|
1256*)
1257
1258PROCEDURE BuildEndFor (endpostok: CARDINAL) ;
1259
1260
1261(*
1262 BuildCaseStart - starts the case statement.
1263 It initializes a backpatch list on the compile
1264 time stack, the list is used to contain all
1265 case break points. The list is later backpatched
1266 and contains all positions of the case statement
1267 which jump to the end of the case statement.
1268 The stack also contains room for a boolean
1269 expression, this is needed to allow , operator
1270 in the CaseField alternatives.
1271
1272 The Stack is expected to contain:
1273
1274
1275 Entry Exit
1276 ===== ====
1277
1278 <- Ptr
1279 +------------+
1280 Empty | 0 | 0 |
1281 |------------|
1282 | 0 | 0 |
1283 |------------|
1284*)
1285
1286PROCEDURE BuildCaseStart ;
1287
1288
1289(*
1290 BuildCaseStartStatementSequence - starts the statement sequence
1291 inside a case clause.
1292 BackPatches the true exit to the
1293 NextQuad.
1294 The Stack:
1295
1296 Entry Exit
1297
1298 Ptr -> <- Ptr
1299 +-----------+ +------------+
1300 | t | f | | 0 | f |
1301 |-----------| |------------|
1302*)
1303
1304PROCEDURE BuildCaseStartStatementSequence ;
1305
1306
1307(*
1308 BuildCaseEndStatementSequence - ends the statement sequence
1309 inside a case clause.
1310 BackPatches the false exit f1 to the
1311 NextQuad.
1312 Asserts that t1 and f2 is 0
1313 Pushes t2+q and 0
1314
1315 Quadruples:
1316
1317 q GotoOp _ _ 0
1318
1319 The Stack:
1320
1321 Entry Exit
1322
1323 Ptr -> <- Ptr
1324 +-----------+ +------------+
1325 | t1 | f1 | | 0 | 0 |
1326 |-----------| |------------|
1327 | t2 | f2 | | t2+q | 0 |
1328 |-----------| |------------|
1329*)
1330
1331PROCEDURE BuildCaseEndStatementSequence ;
1332
1333
1334(*
1335 BuildCaseRange - builds the range testing quaruples for
1336 a case clause.
1337
1338 IF (e1>=ce1) AND (e1<=ce2)
1339 THEN
1340
1341 ELS..
1342
1343 The Stack:
1344
1345 Entry Exit
1346
1347 Ptr ->
1348 +-----------+
1349 | ce2 | <- Ptr
1350 |-----------| +-----------+
1351 | ce1 | | t | f |
1352 |-----------| |-----------|
1353 | t1 | f1 | | t1 | f1 |
1354 |-----------| |-----------|
1355 | t2 | f2 | | t2 | f2 |
1356 |-----------| |-----------|
1357 | e1 | | e1 |
1358 |-----------| |-----------|
1359*)
1360
1361PROCEDURE BuildCaseRange ;
1362
1363
1364(*
1365 BuildCaseEquality - builds the range testing quadruples for
1366 a case clause.
1367
1368 IF e1=ce1
1369 THEN
1370
1371 ELS..
1372
1373 The Stack:
1374
1375 Entry Exit
1376
1377 Ptr ->
1378 +-----------+ +-----------+
1379 | ce1 | | t | f |
1380 |-----------| |-----------|
1381 | t1 | f1 | | t1 | f1 |
1382 |-----------| |-----------|
1383 | t2 | f2 | | t2 | f2 |
1384 |-----------| |-----------|
1385 | e1 | | e1 |
1386 |-----------| |-----------|
1387*)
1388
1389PROCEDURE BuildCaseEquality ;
1390
1391
1392(*
1393 BuildCaseList - merges two case tests into one
1394
1395 The Stack:
1396
1397 Entry Exit
1398
1399 Ptr ->
1400 +-----------+
1401 | t2 | f2 |
1402 |-----------| +-------------+
1403 | t1 | f1 | | t1+t2| f1+f2|
1404 |-----------| |-------------|
1405*)
1406
1407PROCEDURE BuildCaseList ;
1408
1409
1410(*
1411 BuildCaseOr - builds the , in the case clause.
1412
1413 The Stack:
1414
1415 Entry Exit
1416
1417 Ptr -> <- Ptr
1418 +-----------+ +------------+
1419 | t | f | | t | 0 |
1420 |-----------| |------------|
1421*)
1422
1423PROCEDURE BuildCaseOr ;
1424
1425
1426(*
1427 BuildCaseElse - builds the else of case clause.
1428
1429 The Stack:
1430
1431 Entry Exit
1432
1433 Ptr -> <- Ptr
1434 +-----------+ +------------+
1435 | t | f | | t | 0 |
1436 |-----------| |------------|
1437*)
1438
1439PROCEDURE BuildCaseElse ;
1440
1441
1442(*
1443 BuildCaseEnd - builds the end of case clause.
1444
1445 The Stack:
1446
1447 Entry Exit
1448
1449 Ptr ->
1450 +-----------+
1451 | t1 | f1 |
1452 |-----------|
1453 | t2 | f2 |
1454 |-----------|
1455 | e1 |
1456 |-----------| Empty
1457*)
1458
1459PROCEDURE BuildCaseEnd ;
1460
1461
1462(*
1463 BuildCaseCheck - builds the case checking code to ensure that
1464 the program does not need an else clause at runtime.
1465 The stack is unaltered.
1466*)
1467
1468PROCEDURE BuildCaseCheck ;
1469
1470
1471(*
1472 BuildNulParam - Builds a nul parameter on the stack.
1473 The Stack:
1474
1475 Entry Exit
1476
1477 <- Ptr
1478 Empty +------------+
1479 | 0 |
1480 |------------|
1481*)
1482
1483PROCEDURE BuildNulParam ;
1484
1485
1486(*
1487 BuildProcedureCall - builds a procedure call.
1488 The Stack:
1489
1490
1491 Entry Exit
1492
1493 Ptr ->
1494 +----------------+
1495 | NoOfParam |
1496 |----------------|
1497 | Param 1 |
1498 |----------------|
1499 | Param 2 |
1500 |----------------|
1501 . .
1502 . .
1503 . .
1504 |----------------|
1505 | Param # |
1506 |----------------|
1507 | ProcSym | Type | Empty
1508 |----------------|
1509*)
1510
1511PROCEDURE BuildProcedureCall (tokno: CARDINAL) ;
1512
1513
1514(*
1515 CheckBuildFunction - checks to see whether ProcSym is a function
1516 and if so it adds a TempSym value which will
1517 hold the return value once the function finishes.
1518 This procedure also generates an error message
1519 if the user is calling a function and ignoring
1520 the return result. The additional TempSym
1521 is not created if ProcSym is a procedure
1522 and the stack is unaltered.
1523
1524 The Stack:
1525
1526
1527 Entry Exit
1528
1529 Ptr ->
1530
1531 +----------------+
1532 | ProcSym | Type |
1533 +----------------+ |----------------|
1534 | ProcSym | Type | | TempSym | Type |
1535 |----------------| |----------------|
1536*)
1537
1538PROCEDURE CheckBuildFunction () : BOOLEAN ;
1539
1540
1541(*
1542 BuildFunctionCall - builds a function call.
1543 The Stack:
1544
1545
1546 Entry Exit
1547
1548 Ptr ->
1549 +----------------+
1550 | NoOfParam |
1551 |----------------|
1552 | Param 1 |
1553 |----------------|
1554 | Param 2 |
1555 |----------------|
1556 . .
1557 . .
1558 . .
1559 |----------------|
1560 | Param # | <- Ptr
1561 |----------------| +------------+
1562 | ProcSym | Type | | ReturnVar |
1563 |----------------| |------------|
1564
1565*)
1566
1567PROCEDURE BuildFunctionCall ;
1568
1569
1570(*
1571 BuildConstFunctionCall - builds a function call and checks that this function can be
1572 called inside a ConstExpression.
1573
1574 The Stack:
1575
1576
1577 Entry Exit
1578
1579 Ptr ->
1580 +----------------+
1581 | NoOfParam |
1582 |----------------|
1583 | Param 1 |
1584 |----------------|
1585 | Param 2 |
1586 |----------------|
1587 . .
1588 . .
1589 . .
1590 |----------------|
1591 | Param # | <- Ptr
1592 |----------------| +------------+
1593 | ProcSym | Type | | ReturnVar |
1594 |----------------| |------------|
1595
1596*)
1597
1598PROCEDURE BuildConstFunctionCall ;
1599
1600
1601(*
1602 BuildBooleanVariable - tests to see whether top of stack is a boolean
1603 conditional and if so it converts it into a boolean
1604 variable.
1605*)
1606
1607PROCEDURE BuildBooleanVariable ;
1608
1609
1610(*
1611 BuildModuleStart - starts current module scope.
1612*)
1613
1614PROCEDURE BuildModuleStart ;
1615
1616
1617(*
1618 BuildProcedureStart - Builds start of the procedure. Creates space for
1619 the local variables.
1620 The Stack is expected to contain:
1621
1622
1623 Entry Exit
1624 ===== ====
1625
1626 Ptr -> <- Ptr
1627 +------------+ +-----------+
1628 | ProcSym | | ProcSym |
1629 |------------| |-----------|
1630 | Name | | Name |
1631 |------------| |-----------|
1632
1633
1634 Quadruples:
1635
1636 q NewLocalVarOp _ _ ProcSym
1637*)
1638
1639PROCEDURE BuildProcedureStart ;
1640
1641
1642(*
1643 BuildProcedureBegin - determines the start of the BEGIN END block of
1644 the procedure.
1645 The Stack is expected to contain:
1646
1647
1648 Entry Exit
1649 ===== ====
1650
1651 Ptr -> <- Ptr
1652 +------------+ +-----------+
1653 | ProcSym | | ProcSym |
1654 |------------| |-----------|
1655 | Name | | Name |
1656 |------------| |-----------|
1657
1658
1659 Quadruples:
1660
1661 q BeginOp _ _ ProcSym
1662*)
1663
1664PROCEDURE BuildProcedureBegin ;
1665
1666
1667(*
1668 BuildProcedureEnd - Builds end of the procedure. Destroys space for
1669 the local variables.
1670 The Stack is expected to contain:
1671
1672
1673 Entry Exit
1674 ===== ====
1675
1676 Ptr -> <- Ptr
1677 +------------+ +-----------+
1678 | ProcSym | | ProcSym |
1679 |------------| |-----------|
1680 | Name | | Name |
1681 |------------| |-----------|
1682
1683
1684 Quadruples:
1685
1686 q KillLocalVarOp _ _ ProcSym
1687*)
1688
1689PROCEDURE BuildProcedureEnd ;
1690
1691
1692(*
1693 BuildReturn - Builds the Return part of the procedure.
1694 The Stack is expected to contain:
1695
1696
1697 Entry Exit
1698 ===== ====
1699
1700 Ptr ->
1701 +------------+
1702 | e1 | Empty
1703 |------------|
1704*)
1705
1706PROCEDURE BuildReturn (tokno: CARDINAL) ;
1707
1708
1709(*
1710 BuildModulePriority - assigns the current module with a priority
1711 from the top of stack.
1712
1713 Entry Exit
1714 ===== ====
1715
1716
1717 Ptr -> Empty
1718 +------------+
1719 | Priority |
1720 |------------|
1721*)
1722
1723PROCEDURE BuildModulePriority ;
1724
1725
1726(*
1727 StartBuildWith - performs the with statement.
1728 The Stack:
1729
1730 Entry Exit
1731
1732 +------------+
1733 | Sym | Type | Empty
1734 |------------|
1735*)
1736
1737PROCEDURE StartBuildWith ;
1738
1739
1740(*
1741 EndBuildWith - terminates the innermost with scope.
1742*)
1743
1744PROCEDURE EndBuildWith ;
1745
1746
1747(*
1748 CheckWithReference - performs the with statement.
1749 The Stack:
1750
1751 Entry Exit
1752
1753 +------------+ +------------+
1754 | Sym | Type | | Sym | Type |
1755 |------------| |------------|
1756*)
1757
1758PROCEDURE CheckWithReference ;
1759
1760
1761(*
1762 BuildDesignatorRecord - Builds the record referencing.
1763 The Stack is expected to contain:
1764
1765
1766 Entry Exit
1767 ===== ====
1768
1769 Ptr ->
1770 +--------------+
1771 | n |
1772 |--------------|
1773 | fld1 | type1 |
1774 |--------------|
1775 . .
1776 . .
1777 . .
1778 |--------------|
1779 | fldn | typen | <- Ptr
1780 |--------------| +-------------+
1781 | Sym | Type | | S | type1|
1782 |--------------| |-------------|
1783*)
1784
1785PROCEDURE BuildDesignatorRecord (dottok: CARDINAL) ;
1786
1787
1788(*
1789 BuildDesignatorArray - Builds the array referencing.
1790 The Stack is expected to contain:
1791
1792
1793 Entry Exit
1794 ===== ====
1795
1796 Ptr ->
1797 +--------------+
1798 | n | Empty
1799 |--------------|
1800 | e1 |
1801 |--------------|
1802 . .
1803 . .
1804 . .
1805 |--------------|
1806 | e2 | <- Ptr
1807 |--------------| +------------+
1808 | Sym | Type | | S | T |
1809 |--------------| |------------|
1810*)
1811
1812PROCEDURE BuildDesignatorArray ;
1813
1814
1815(*
1816 BuildDesignatorPointer - Builds the record referencing.
1817 The Stack is expected to contain:
1818
1819
1820 Entry Exit
1821 ===== ====
1822
1823 Ptr -> <- Ptr
1824 +--------------+ +--------------+
1825 | Sym1 | Type1| | Sym2 | Type2|
1826 |--------------| |--------------|
1827*)
1828
1829PROCEDURE BuildDesignatorPointer (ptrtok: CARDINAL) ;
1830
1831
1832(*
1833 BuildNulExpression - Builds a nul expression on the stack.
1834 The Stack:
1835
1836 Entry Exit
1837
1838 <- Ptr
1839 Empty +------------+
1840 | NulSym |
1841 |------------|
1842*)
1843
1844PROCEDURE BuildNulExpression ;
1845
1846
1847(*
1848 BuildSetStart - Pushes a Bitset type on the stack.
1849
1850 The Stack:
1851
1852 Entry Exit
1853
1854 Ptr -> <- Ptr
1855
1856 Empty +--------------+
1857 | Bitset |
1858 |--------------|
1859*)
1860
1861PROCEDURE BuildSetStart ;
1862
1863
1864(*
1865 BuildSetEnd - pops the set value and type from the stack
1866 and pushes the value,type pair.
1867
1868 Entry Exit
1869
1870 Ptr ->
1871 +--------------+
1872 | Set Value | <- Ptr
1873 |--------------| +--------------+
1874 | Set Type | | Value | Type |
1875 |--------------| |--------------|
1876*)
1877
1878PROCEDURE BuildSetEnd ;
1879
1880
1881(*
1882 BuildEmptySet - Builds an empty set on the stack.
1883 The Stack:
1884
1885 Entry Exit
1886
1887 <- Ptr
1888 +-------------+
1889 Ptr -> | Value |
1890 +-----------+ |-------------|
1891 | SetType | | SetType |
1892 |-----------| |-------------|
1893
1894*)
1895
1896PROCEDURE BuildEmptySet ;
1897
1898
1899(*
1900 BuildInclRange - includes a set range with a set.
1901
1902
1903 Entry Exit
1904 ===== ====
1905
1906
1907 Ptr ->
1908 +------------+
1909 | El2 |
1910 |------------|
1911 | El1 | <- Ptr
1912 |------------| +-------------------+
1913 | Set Value | | Value + {El1..El2}|
1914 |------------| |-------------------|
1915 | Set Type | | Set Type |
1916 |------------| |-------------------|
1917
1918 No quadruples produced as the range info is contained within
1919 the set value.
1920*)
1921
1922PROCEDURE BuildInclRange ;
1923
1924
1925(*
1926 BuildInclBit - includes a bit into the set.
1927
1928 Entry Exit
1929 ===== ====
1930
1931
1932 Ptr ->
1933 +------------+
1934 | Element | <- Ptr
1935 |------------| +------------+
1936 | Value | | Value |
1937 |------------| |------------|
1938 | Type | | Type |
1939 |------------| |------------|
1940
1941 No quadruples produced as this bit inclusion is contained within
1942 the set value.
1943*)
1944
1945PROCEDURE BuildInclBit ;
1946
1947
1948(*
1949 SilentBuildConstructor - places NulSym into the constructor fifo queue.
1950*)
1951
1952PROCEDURE SilentBuildConstructor ;
1953
1954
1955(*
1956 SilentBuildConstructorStart - removes an entry from the constructor fifo queue.
1957*)
1958
1959PROCEDURE SilentBuildConstructorStart ;
1960
1961
1962(*
1963 BuildConstructor - builds a constructor.
1964 Stack
1965
1966 Entry Exit
1967
1968 Ptr ->
1969 +------------+
1970 | Type | <- Ptr
1971 |------------+
1972*)
1973
1974PROCEDURE BuildConstructor ;
1975
1976
1977(*
1978 BuildConstructorStart - builds a constructor.
1979 Stack
1980
1981 Entry Exit
1982
1983 Ptr -> <- Ptr
1984 +------------+ +------------+
1985 | Name | | Sym |
1986 |------------+ |------------|
1987*)
1988
1989PROCEDURE BuildConstructorStart ;
1990
1991
1992(*
1993 BuildConstructorEnd - removes the current constructor frame from the
1994 constructor stack (it does not effect the quad
1995 stack)
1996
1997 Stack
1998
1999 Entry Exit
2000
2001 Ptr -> <- Ptr
2002 +------------+ +------------+
2003 | const | | const |
2004 |------------+ |------------|
2005*)
2006
2007PROCEDURE BuildConstructorEnd ;
2008
2009
2010(*
2011 NextConstructorField - increments the top of constructor stacks
2012 index by one.
2013*)
2014
2015PROCEDURE NextConstructorField ;
2016
2017
2018(*
2019 BuildTypeForConstructor - pushes the type implied by the current constructor.
2020 If no constructor is currently being built then
2021 it Pushes a Bitset type.
2022*)
2023
2024PROCEDURE BuildTypeForConstructor ;
2025
2026
2027(*
2028 BuildComponentValue - builds a component value.
2029
2030 Entry Exit
2031
2032 Ptr -> <- Ptr
2033
2034
2035 +------------+ +------------+
2036 | const | | const |
2037 |------------| |------------|
2038
2039 (this is incomplete (fixme))
2040*)
2041
2042PROCEDURE BuildComponentValue ;
2043
2044
2045(*
2046 BuildNot - Builds a NOT operation from the quad stack.
2047 The Stack is expected to contain:
2048
2049
2050 Entry Exit
2051 ===== ====
2052
2053 Ptr -> <- Ptr
2054 +------------+ +------------+
2055 | t | f | | f | t |
2056 |------------| |------------|
2057*)
2058
2059PROCEDURE BuildNot ;
2060
2061
2062(*
2063 RecordOp - Records the operator passed on the stack.
2064 Checks for AND operator or OR operator
2065 if either of these operators are found then BackPatching
2066 takes place.
2067 The Expected Stack:
2068
2069 Entry Exit
2070
2071 Ptr -> <- Ptr
2072 +-------------+ +-------------+
2073 | OperatorTok | | OperatorTok |
2074 |-------------| |-------------|
2075 | t | f | | t | f |
2076 |-------------| |-------------|
2077
2078
2079 If OperatorTok=AndTok
2080 Then
2081 BackPatch(f, NextQuad)
2082 Elsif OperatorTok=OrTok
2083 Then
2084 BackPatch(t, NextQuad)
2085 End
2086*)
2087
2088PROCEDURE RecordOp ;
2089
2090
2091(*
2092 BuildRelOp - Builds a relative operation from the quad stack.
2093 The Stack is expected to contain:
2094
2095
2096 Entry Exit
2097 ===== ====
2098
2099 Ptr ->
2100 +------------+
2101 | e1 |
2102 |------------| <- Ptr
2103 | Operator |
2104 |------------| +------------+
2105 | e2 | | t | f |
2106 |------------| |------------|
2107
2108
2109 Quadruples Produced
2110
2111 q IFOperator e1 e2 TrueExit
2112 q+1 GotoOp FalseExit
2113*)
2114
2115PROCEDURE BuildRelOp (optokpos: CARDINAL) ;
2116
2117
2118(*
2119 BuildBinaryOp - Builds a binary operation from the quad stack.
2120 The Stack is expected to contain:
2121
2122
2123 Entry Exit
2124 ===== ====
2125
2126 Ptr ->
2127 +------------+
2128 | Sym1 |
2129 |------------|
2130 | Operator | <- Ptr
2131 |------------| +------------+
2132 | Sym2 | | Temporary |
2133 |------------| |------------|
2134
2135
2136 Quadruples Produced
2137
2138 q Operator Temporary Sym1 Sym2
2139
2140*)
2141
2142PROCEDURE BuildBinaryOp ;
2143
2144
2145(*
2146 BuildUnaryOp - Builds a unary operation from the quad stack.
2147 The Stack is expected to contain:
2148
2149
2150 Entry Exit
2151 ===== ====
2152
2153 Ptr ->
2154 +------------+
2155 | Sym1 |
2156 |------------| +------------+
2157 | Operator | | Temporary | <- Ptr
2158 |------------| |------------|
2159
2160
2161 Quadruples Produced
2162
2163 q Operator Temporary _ Sym1
2164
2165*)
2166
2167PROCEDURE BuildUnaryOp ;
2168
2169
2170(*
2171 OperandT - returns the ident operand stored in the true position on the boolean stack.
2172*)
2173
2174PROCEDURE OperandT (pos: CARDINAL) : WORD ;
2175
2176
2177(*
2178 OperandF - returns the ident operand stored in the false position on the boolean stack.
2179*)
2180
2181PROCEDURE OperandF (pos: CARDINAL) : WORD ;
2182
2183
2184(*
2185 PushTF - Push a True and a False exit quad numbers onto the
2186 True/False stack.
2187*)
2188
2189PROCEDURE PushTF (True, False: WORD) ;
2190
2191
2192(*
2193 PopTF - Pops a True and a False exit quad numbers from the
2194 True/False stack.
2195*)
2196
2197PROCEDURE PopTF (VAR True, False: WORD) ;
2198
2199
2200(*
2201 PushT - Push a True exit quad numbers onto the
2202 True/False stack. The False exit will be zero.
2203*)
2204
2205PROCEDURE PushT (True: WORD) ;
2206
2207
2208(*
2209 PopT - Pop a True exit quad number from the True/False
2210 stack. The False exit is ignored.
2211*)
2212
2213PROCEDURE PopT (VAR True: WORD) ;
2214
2215
2216(*
2217 PushTtok - Push an item onto the stack in the T (true) position,
2218 it is assummed to be a token and its token location is recorded.
2219*)
2220
2221PROCEDURE PushTtok (True: WORD; tokno: CARDINAL) ;
2222
2223
2224(*
2225 PushTFtok - Push an item onto the stack in the T (true) position,
2226 it is assummed to be a token and its token location is recorded.
2227*)
2228
2229PROCEDURE PushTFtok (True, False: WORD; tokno: CARDINAL) ;
2230
2231
2232(*
2233 PopTFtok - Pop T/F/tok from the stack.
2234*)
2235
2236PROCEDURE PopTFtok (VAR True, False: WORD; VAR tokno: CARDINAL) ;
2237
2238
2239(*
2240 PushTFAtok - Push T/F/A/tok to the stack.
2241*)
2242
2243PROCEDURE PushTFAtok (True, False, Array: WORD; tokno: CARDINAL) ;
2244
2245
2246(*
2247 PopTtok - Pops the T value from the stack and token position.
2248*)
2249
2250PROCEDURE PopTtok (VAR True: WORD; VAR tok: CARDINAL) ;
2251
2252
2253(*
2254 PushTFn - Push a True and False numbers onto the True/False stack.
2255 True and False are assumed to contain Symbols or Ident etc.
2256*)
2257
2258PROCEDURE PushTFn (True, False, n: WORD) ;
2259
2260
2261(*
2262 PopTFn - Pop a True and False number from the True/False stack.
2263 True and False are assumed to contain Symbols or Ident etc.
2264*)
2265
2266PROCEDURE PopTFn (VAR True, False, n: WORD) ;
2267
2268
2269(*
2270 PopNothing - pops the top element on the stack.
2271*)
2272
2273PROCEDURE PopNothing ;
2274
2275
2276(*
2277 PopN - pops multiple elements from the BoolStack.
2278*)
2279
2280PROCEDURE PopN (n: CARDINAL) ;
2281
2282
2283(*
2284 PushTFA - Push True, False, Array, numbers onto the
2285 True/False stack. True and False are assumed to
2286 contain Symbols or Ident etc.
2287*)
2288
2289PROCEDURE PushTFA (True, False, Array: WORD) ;
2290
2291
2292(*
2293 OperandTok - returns the token associated with pos, on the stack.
2294*)
2295
2296PROCEDURE OperandTok (pos: CARDINAL) : WORD ;
2297
2298
2299(*
2300 OperandA - returns possible array symbol associated with the ident
2301 operand stored on the boolean stack.
2302*)
2303
2304PROCEDURE OperandA (pos: CARDINAL) : WORD ;
2305
2306
2307(*
2308 OperandAnno - returns the annotation string associated with the
2309 position, n, on the stack.
2310*)
2311
2312PROCEDURE OperandAnno (n: CARDINAL) : String ;
2313
2314
2315(*
2316 Annotate - annotate the top of stack.
2317*)
2318
2319PROCEDURE Annotate (a: ARRAY OF CHAR) ;
2320
2321
2322(*
2323 DisplayStack - displays the compile time symbol stack.
2324*)
2325
2326PROCEDURE DisplayStack ;
2327
2328
2329(*
2330 Top - returns the no of items held in the stack.
2331*)
2332
2333PROCEDURE Top () : CARDINAL ;
2334
2335
2336(*
2337 WriteOperand - displays the operands name, symbol id and mode of addressing.
2338*)
2339
2340PROCEDURE WriteOperand (Sym: CARDINAL) ;
2341
2342
2343(*
2344 BeginVarient - begin a varient record.
2345*)
2346
2347PROCEDURE BeginVarient ;
2348
2349
2350(*
2351 EndVarient - end a varient record.
2352*)
2353
2354PROCEDURE EndVarient ;
2355
2356
2357(*
2358 ElseVarient - associate an ELSE clause with a varient record.
2359*)
2360
2361PROCEDURE ElseVarient ;
2362
2363
2364(*
2365 BeginVarientList - begin an ident list containing ranges belonging to a
2366 varient list.
2367*)
2368
2369PROCEDURE BeginVarientList ;
2370
2371
2372(*
2373 EndVarientList - end a range list for a varient field.
2374*)
2375
2376PROCEDURE EndVarientList ;
2377
2378
2379(*
2380 AddRecordToList - adds the record held on the top of stack to the
2381 list of records and varient fields.
2382*)
2383
2384PROCEDURE AddRecordToList ;
2385
2386
2387(*
2388 AddVarientToList - adds varient held on the top of stack to the list.
2389*)
2390
2391PROCEDURE AddVarientToList ;
2392
2393
2394(*
2395 AddVarientFieldToList - adds varient field, f, to the list of all varient
2396 fields created.
2397*)
2398
2399PROCEDURE AddVarientFieldToList (f: CARDINAL) ;
2400
2401
2402(*
2403 AddVarientRange - creates a range from the top two contant expressions
2404 on the stack which are recorded with the current
2405 varient field. The stack is unaltered.
2406*)
2407
2408PROCEDURE AddVarientRange ;
2409
2410
2411(*
2412 AddVarientEquality - adds the contant expression on the top of the stack
2413 to the current varient field being recorded.
2414 The stack is unaltered.
2415*)
2416
2417PROCEDURE AddVarientEquality ;
2418
2419
2420(*
2421 BuildCodeOn - generates a quadruple declaring that code should be
2422 emitted from henceforth.
2423
2424 The Stack is unnaffected.
2425*)
2426
2427PROCEDURE BuildCodeOn ;
2428
2429
2430(*
2431 BuildCodeOff - generates a quadruple declaring that code should not be
2432 emmitted from henceforth.
2433
2434 The Stack is unnaffected.
2435*)
2436
2437PROCEDURE BuildCodeOff ;
2438
2439
2440(*
2441 BuildProfileOn - generates a quadruple declaring that profile timings
2442 should be emmitted from henceforth.
2443
2444 The Stack is unnaffected.
2445*)
2446
2447PROCEDURE BuildProfileOn ;
2448
2449
2450(*
2451 BuildProfileOn - generates a quadruple declaring that profile timings
2452 should be emmitted from henceforth.
2453
2454 The Stack is unnaffected.
2455*)
2456
2457PROCEDURE BuildProfileOff ;
2458
2459
2460(*
2461 BuildOptimizeOn - generates a quadruple declaring that optimization
2462 should occur from henceforth.
2463
2464 The Stack is unnaffected.
2465*)
2466
2467PROCEDURE BuildOptimizeOn ;
2468
2469
2470(*
2471 BuildOptimizeOff - generates a quadruple declaring that optimization
2472 should not occur from henceforth.
2473
2474 The Stack is unnaffected.
2475*)
2476
2477PROCEDURE BuildOptimizeOff ;
2478
2479
2480(*
2481 BuildInline - builds an Inline pseudo quadruple operator.
2482 The inline interface, Sym, is stored as the operand
2483 to the operator InlineOp.
2484
2485 The stack is expected to contain:
2486
2487
2488 Entry Exit
2489 ===== ====
2490
2491 Ptr ->
2492 +--------------+
2493 | Sym | Empty
2494 |--------------|
2495*)
2496
2497PROCEDURE BuildInline ;
2498
2499
2500(*
2501 BuildLineNo - builds a LineNumberOp pseudo quadruple operator.
2502 This quadruple indicates which source line has been
2503 processed, these quadruples are only generated if we
2504 are producing runtime debugging information.
2505
2506 The stack is not affected, read or altered in any way.
2507
2508
2509 Entry Exit
2510 ===== ====
2511
2512 Ptr -> <- Ptr
2513*)
2514
2515PROCEDURE BuildLineNo ;
2516
2517
2518(*
2519 PushLineNo - pushes the current file and line number to the stack.
2520*)
2521
2522PROCEDURE PushLineNo ;
2523
2524
2525(*
2526 BuildStmtNote - builds a StatementNoteOp pseudo quadruple operator.
2527 This quadruple indicates which source line has been
2528 processed and it represents the start of a statement
2529 sequence.
2530 It differs from LineNumberOp in that multiple successive
2531 LineNumberOps will be removed and the final one is attached to
2532 the next real GCC tree. Whereas a StatementNoteOp is always left
2533 alone. Depending upon the debugging level it will issue a nop
2534 instruction to ensure that the gdb single step will step into
2535 this line. Practically it allows pedalogical debugging to
2536 occur when there is syntax sugar such as:
2537
2538
2539 END (* step *)
2540 END (* step *)
2541 END ; (* step *)
2542 a := 1 ; (* step *)
2543
2544 REPEAT (* step *)
2545 i := 1 (* step *)
2546
2547 The stack is not affected, read or altered in any way.
2548
2549
2550 Entry Exit
2551 ===== ====
2552
2553 Ptr -> <- Ptr
2554*)
2555
2556PROCEDURE BuildStmtNote (offset: INTEGER) ;
2557
2558
2559(*
2560 VariableAnalysis - checks to see whether a variable is:
2561
2562 read without being initialized or
2563 written over when it is a non var parameter
2564*)
2565
2566PROCEDURE VariableAnalysis (Start, End: CARDINAL) ;
2567
2568
2569(*
2570 LoopAnalysis - checks whether an infinite loop exists.
2571*)
2572
2573PROCEDURE LoopAnalysis (Current, End: CARDINAL) ;
2574
2575
2576(*
2577 ForLoopAnalysis - checks all the FOR loops for index variable manipulation
2578 and dangerous usage outside the loop.
2579*)
2580
2581PROCEDURE ForLoopAnalysis ;
2582
2583
2584(*
2585 BuildSizeCheckStart - switches off all quadruple generation if the function SIZE
2586 is being "called". This should be done as SIZE only requires the
2587 actual type of the expression, not its value. Consider the problem of
2588 SIZE(UninitializedPointer^) quite legal and it must also be safe!
2589
2590
2591 The Stack is expected to contain:
2592
2593
2594 Entry Exit
2595 ===== ====
2596
2597 Ptr -> <- Ptr
2598 +------------+ +-----------+
2599 | ProcSym | | ProcSym |
2600 |------------| |-----------|
2601*)
2602
2603PROCEDURE BuildSizeCheckStart ;
2604
2605
2606(*
2607 BackPatchSubrangesAndOptParam - runs through all the quadruples and finds SubrangeLow or SubrangeHigh
2608 quadruples and replaces it by an assignment to the Low or High component
2609 of the subrange type.
2610
2611 Input:
2612 SubrangeLow op1 op3 (* op3 is a subrange *)
2613
2614 Output:
2615 Becomes op1 low
2616
2617 Input:
2618 SubrangeHigh op1 op3 (* op3 is a subrange *)
2619
2620 Output:
2621 Becomes op1 high
2622
2623 Input:
2624 OptParam op1 op2 op3
2625
2626 Output:
2627 Param op1 op2 GetOptArgInit(op3)
2628*)
2629
2630PROCEDURE BackPatchSubrangesAndOptParam ;
2631
2632
2633(*
2634 WriteOperator - writes the name of the quadruple operator.
2635*)
2636
2637PROCEDURE WriteOperator (Operator: QuadOperator) ;
2638
2639
2640(*
2641 PushAutoOn - push the auto flag and then set it to TRUE.
2642 Any call to ident in the parser will result in the token being pushed.
2643*)
2644
2645PROCEDURE PushAutoOn ;
2646
2647
2648(*
2649 PushAutoOff - push the auto flag and then set it to FALSE.
2650*)
2651
2652PROCEDURE PushAutoOff ;
2653
2654
2655(*
2656 IsAutoPushOn - returns the value of the current Auto ident push flag.
2657*)
2658
2659PROCEDURE IsAutoPushOn () : BOOLEAN ;
2660
2661
2662(*
2663 PopAuto - restores the previous value of the Auto flag.
2664*)
2665
2666PROCEDURE PopAuto ;
2667
2668
2669(*
2670 MustCheckOverflow - returns TRUE if the quadruple should test for overflow.
2671*)
2672
2673PROCEDURE MustCheckOverflow (q: CARDINAL) : BOOLEAN ;
2674
2675
2676(*
2677 PushInConstExpression - push the InConstExpression flag and then set it to TRUE.
2678*)
2679
2680PROCEDURE PushInConstExpression ;
2681
2682
2683(*
2684 PopInConstExpression - restores the previous value of the InConstExpression.
2685*)
2686
2687PROCEDURE PopInConstExpression ;
2688
2689
2690(*
2691 IsInConstExpression - returns the value of the InConstExpression.
2692*)
2693
2694PROCEDURE IsInConstExpression () : BOOLEAN ;
2695
2696
2697END M2Quads.
This page took 0.328388 seconds and 5 git commands to generate.