Branch data Line data Source code
1 : : /* do not edit automatically generated by mc from M2GenGCC. */
2 : : /* M2GenGCC.mod convert the quadruples into GCC trees.
3 : :
4 : : Copyright (C) 2001-2025 Free Software Foundation, Inc.
5 : : Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
6 : :
7 : : This file is part of GNU Modula-2.
8 : :
9 : : GNU Modula-2 is free software; you can redistribute it and/or modify
10 : : it under the terms of the GNU General Public License as published by
11 : : the Free Software Foundation; either version 3, or (at your option)
12 : : any later version.
13 : :
14 : : GNU Modula-2 is distributed in the hope that it will be useful, but
15 : : WITHOUT ANY WARRANTY; without even the implied warranty of
16 : : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 : : General Public License for more details.
18 : :
19 : : You should have received a copy of the GNU General Public License
20 : : along with GNU Modula-2; see the file COPYING3. If not see
21 : : <http://www.gnu.org/licenses/>. */
22 : :
23 : : #include "config.h"
24 : : #include "system.h"
25 : : #include "gcc-consolidation.h"
26 : :
27 : : #include <stdbool.h>
28 : : # if !defined (PROC_D)
29 : : # define PROC_D
30 : : typedef void (*PROC_t) (void);
31 : : typedef struct { PROC_t proc; } PROC;
32 : : # endif
33 : :
34 : : # if !defined (TRUE)
35 : : # define TRUE (1==1)
36 : : # endif
37 : :
38 : : # if !defined (FALSE)
39 : : # define FALSE (1==0)
40 : : # endif
41 : :
42 : : # include "Gmcrts.h"
43 : : #if defined(__cplusplus)
44 : : # undef NULL
45 : : # define NULL 0
46 : : #endif
47 : : #define _M2GenGCC_C
48 : :
49 : : #include "GM2GenGCC.h"
50 : : # include "GSYSTEM.h"
51 : : # include "GSymbolTable.h"
52 : : # include "GM2Batch.h"
53 : : # include "GM2LexBuf.h"
54 : : # include "GM2Code.h"
55 : : # include "GM2Debug.h"
56 : : # include "GM2Error.h"
57 : : # include "GM2MetaError.h"
58 : : # include "GM2Options.h"
59 : : # include "GM2Printf.h"
60 : : # include "GM2Quiet.h"
61 : : # include "GM2Base.h"
62 : : # include "GM2Bitset.h"
63 : : # include "GNameKey.h"
64 : : # include "GDynamicStrings.h"
65 : : # include "GFormatStrings.h"
66 : : # include "GM2System.h"
67 : : # include "GM2FileName.h"
68 : : # include "GSymbolConversion.h"
69 : : # include "GM2StackWord.h"
70 : : # include "GLists.h"
71 : : # include "GM2ALU.h"
72 : : # include "GM2GCCDeclare.h"
73 : : # include "GM2Range.h"
74 : : # include "Gm2builtins.h"
75 : : # include "Gm2expr.h"
76 : : # include "Gm2tree.h"
77 : : # include "Ggcctypes.h"
78 : : # include "Gm2decl.h"
79 : : # include "Gm2statement.h"
80 : : # include "Gm2type.h"
81 : : # include "Gm2block.h"
82 : : # include "Gm2misc.h"
83 : : # include "Gm2convert.h"
84 : : # include "Gm2except.h"
85 : : # include "GM2Quads.h"
86 : : # include "GM2Check.h"
87 : : # include "GM2SSA.h"
88 : : # include "GM2Optimize.h"
89 : : # include "GM2BasicBlock.h"
90 : :
91 : : # define Debugging false
92 : : # define PriorityDebugging false
93 : : # define CascadedDebugging false
94 : : typedef struct M2GenGCC_DoProcedure_p M2GenGCC_DoProcedure;
95 : :
96 : : typedef struct M2GenGCC_DoUnaryProcedure_p M2GenGCC_DoUnaryProcedure;
97 : :
98 : : # define Verbose false
99 : : # define DebugTokPos false
100 : : # define DebugTokPos false
101 : : typedef void (*M2GenGCC_DoProcedure_t) (unsigned int);
102 : : struct M2GenGCC_DoProcedure_p { M2GenGCC_DoProcedure_t proc; };
103 : :
104 : : typedef void (*M2GenGCC_DoUnaryProcedure_t) (unsigned int);
105 : : struct M2GenGCC_DoUnaryProcedure_p { M2GenGCC_DoUnaryProcedure_t proc; };
106 : :
107 : : static unsigned int Memset;
108 : : static unsigned int Memcpy;
109 : : static unsigned int CurrentQuadToken;
110 : : static unsigned int UnboundedLabelNo;
111 : : static unsigned int LastLine;
112 : : static M2Quads_QuadOperator LastOperator;
113 : : static M2StackWord_StackOfWord ScopeStack;
114 : : static bool NoChange;
115 : : static tree tryBlock;
116 : : static tree handlerBlock;
117 : :
118 : : /*
119 : : ConvertQuadsToTree - runs through the quadruple list and converts it into
120 : : the GCC tree structure.
121 : : */
122 : :
123 : : extern "C" void M2GenGCC_ConvertQuadsToTree (unsigned int Start, unsigned int End);
124 : :
125 : : /*
126 : : ResolveConstantExpressions - resolves constant expressions from the quadruple list.
127 : : It returns TRUE if one or more constants were folded.
128 : : When a constant symbol value is solved, the call back
129 : : p(sym) is invoked.
130 : : */
131 : :
132 : : extern "C" bool M2GenGCC_ResolveConstantExpressions (M2GCCDeclare_WalkAction p, M2BasicBlock_BasicBlock bb);
133 : :
134 : : /*
135 : : GetHighFromUnbounded - returns a Tree containing the value of
136 : : param.HIGH.
137 : : */
138 : :
139 : : extern "C" tree M2GenGCC_GetHighFromUnbounded (location_t location, unsigned int dim, unsigned int param);
140 : :
141 : : /*
142 : : StringToChar - if type=Char and str is a string (of size <= 1)
143 : : then convert the string into a character constant.
144 : : */
145 : :
146 : : extern "C" tree M2GenGCC_StringToChar (tree t, unsigned int type, unsigned int str);
147 : :
148 : : /*
149 : : LValueToGenericPtr - returns a Tree representing symbol, sym.
150 : : It coerces a lvalue into an internal pointer type
151 : : */
152 : :
153 : : extern "C" tree M2GenGCC_LValueToGenericPtr (location_t location, unsigned int sym);
154 : :
155 : : /*
156 : : ZConstToTypedConst - checks whether op1 and op2 are constants and
157 : : coerces, t, appropriately.
158 : : */
159 : :
160 : : extern "C" tree M2GenGCC_ZConstToTypedConst (tree t, unsigned int op1, unsigned int op2);
161 : :
162 : : /*
163 : : PrepareCopyString - returns two trees:
164 : : length number of bytes to be copied (including the nul if room)
165 : : srcTreeType the new string type (with the extra nul character).
166 : :
167 : : Pre condition: destStrType the dest type string.
168 : : src is the original string (without a nul)
169 : : to be copied.
170 : : Post condition: TRUE or FALSE is returned.
171 : : if true length and srcTreeType will be assigned
172 : : else length is set to the maximum length to be
173 : : copied and srcTree is set to the max length
174 : : which fits in dest.
175 : : */
176 : :
177 : : extern "C" bool M2GenGCC_PrepareCopyString (unsigned int tokenno, tree *length, tree *srcTree, unsigned int src, unsigned int destStrType);
178 : :
179 : : /*
180 : : ErrorMessageDecl - emit an error message together with declaration fragments of left
181 : : and right if they are parameters or variables.
182 : : */
183 : :
184 : : static void ErrorMessageDecl (unsigned int tok, const char *message_, unsigned int _message_high, unsigned int left, unsigned int right, bool iserror);
185 : :
186 : : /*
187 : : IsExportedGcc - returns TRUE if this symbol should be (as far as the middle/backend of GCC)
188 : : is concerned, exported.
189 : : */
190 : :
191 : : static bool IsExportedGcc (unsigned int sym);
192 : :
193 : : /*
194 : : IsCompilingMainModule -
195 : : */
196 : :
197 : : static bool IsCompilingMainModule (unsigned int sym);
198 : :
199 : : /*
200 : : CodeLastForIterator - call PerformLastForIterator allowing for
201 : : a non constant last iterator value.
202 : : */
203 : :
204 : : static void CodeLastForIterator (unsigned int quad);
205 : :
206 : : /*
207 : : FoldLastForIterator - call PerformLastForIterator providing
208 : : all operands are constant and are known by GCC.
209 : : */
210 : :
211 : : static void FoldLastForIterator (unsigned int quad, M2GCCDeclare_WalkAction p);
212 : : static void PerformLastForIterator (unsigned int quad, M2GCCDeclare_WalkAction p, bool constant);
213 : :
214 : : /*
215 : : CodeStatement - A multi-way decision call depending on the current
216 : : quadruple.
217 : : */
218 : :
219 : : static void CodeStatement (unsigned int q);
220 : :
221 : : /*
222 : : FindSize - given a Modula-2 symbol sym return a gcc tree
223 : : constant representing the storage size in bytes.
224 : : */
225 : :
226 : : static tree FindSize (unsigned int tokenno, unsigned int sym);
227 : :
228 : : /*
229 : : FindType - returns the type of, Sym, if Sym is a TYPE then return Sym otherwise return GetType(Sym)
230 : : */
231 : :
232 : : static unsigned int FindType (unsigned int Sym);
233 : :
234 : : /*
235 : : BuildTreeFromInterface - generates a GCC tree from an interface definition.
236 : : */
237 : :
238 : : static tree BuildTreeFromInterface (unsigned int sym);
239 : :
240 : : /*
241 : : BuildTrashTreeFromInterface - generates a GCC string tree from an interface definition.
242 : : */
243 : :
244 : : static tree BuildTrashTreeFromInterface (unsigned int sym);
245 : :
246 : : /*
247 : : CodeInline - InlineOp is a quadruple which has the following format:
248 : :
249 : : InlineOp NulSym NulSym Sym
250 : : */
251 : :
252 : : static void CodeInline (unsigned int quad);
253 : :
254 : : /*
255 : : FoldStatementNote - set CurrentQuadToken to tokennno.
256 : : */
257 : :
258 : : static void FoldStatementNote (unsigned int tokenno);
259 : :
260 : : /*
261 : : CodeStatementNote - set CurrentQuadToken to tokennno and
262 : : add a statement note.
263 : : */
264 : :
265 : : static void CodeStatementNote (unsigned int tokenno);
266 : :
267 : : /*
268 : : FoldRange - attempts to fold the range test.
269 : : --fixme-- complete this.
270 : : */
271 : :
272 : : static void FoldRange (unsigned int tokenno, unsigned int quad, unsigned int rangeno);
273 : :
274 : : /*
275 : : CodeSaveException - op1 := op3(TRUE)
276 : : */
277 : :
278 : : static void CodeSaveException (unsigned int des, unsigned int exceptionProcedure);
279 : :
280 : : /*
281 : : CodeRestoreException - op1 := op3(op1).
282 : : */
283 : :
284 : : static void CodeRestoreException (unsigned int des, unsigned int exceptionProcedure);
285 : :
286 : : /*
287 : : PushScope -
288 : : */
289 : :
290 : : static void PushScope (unsigned int sym);
291 : :
292 : : /*
293 : : PopScope -
294 : : */
295 : :
296 : : static void PopScope (void);
297 : :
298 : : /*
299 : : GetCurrentScopeDescription - returns a description of the current scope.
300 : : */
301 : :
302 : : static DynamicStrings_String GetCurrentScopeDescription (void);
303 : :
304 : : /*
305 : : CodeRange - encode the range test associated with op3.
306 : : */
307 : :
308 : : static void CodeRange (unsigned int rangeId);
309 : :
310 : : /*
311 : : CodeError - encode the error test associated with op3.
312 : : */
313 : :
314 : : static void CodeError (unsigned int errorId);
315 : :
316 : : /*
317 : : CodeModuleScope - ModuleScopeOp is a quadruple which has the following
318 : : format:
319 : :
320 : : ModuleScopeOp _ _ moduleSym
321 : :
322 : : Its purpose is to reset the source file to another
323 : : file, hence all line numbers emitted with the
324 : : generated code will be relative to this source file.
325 : : */
326 : :
327 : : static void CodeModuleScope (unsigned int moduleSym);
328 : :
329 : : /*
330 : : CodeStartModFile - StartModFileOp is a quadruple which has the following
331 : : format:
332 : :
333 : : StartModFileOp _ _ moduleSym
334 : :
335 : : A new source file has been encountered therefore
336 : : set LastLine to 1.
337 : : Call pushGlobalScope.
338 : : */
339 : :
340 : : static void CodeStartModFile (unsigned int moduleSym);
341 : :
342 : : /*
343 : : CodeStartDefFile - StartDefFileOp is a quadruple with the following
344 : : format:
345 : :
346 : : StartDefFileOp _ _ moduleSym
347 : :
348 : : A new source file has been encountered therefore
349 : : set LastLine to 1.
350 : : Call pushGlobalScope.
351 : : */
352 : :
353 : : static void CodeStartDefFile (unsigned int moduleSym);
354 : :
355 : : /*
356 : : CodeEndFile - pops the GlobalScope.
357 : : */
358 : :
359 : : static void CodeEndFile (void);
360 : :
361 : : /*
362 : : CallInnerInit - produce a call to inner module initialization routine.
363 : : */
364 : :
365 : : static void CallInnerInit (unsigned int moduleSym);
366 : :
367 : : /*
368 : : CallInnerFinally - produce a call to inner module finalization routine.
369 : : */
370 : :
371 : : static void CallInnerFinally (unsigned int moduleSym);
372 : :
373 : : /*
374 : : CodeInitStart - emits starting code before the main BEGIN END of the
375 : : current module.
376 : : */
377 : :
378 : : static void CodeInitStart (unsigned int moduleSym, bool CompilingMainModule);
379 : :
380 : : /*
381 : : CodeInitEnd - emits terminating code after the main BEGIN END of the
382 : : current module.
383 : : */
384 : :
385 : : static void CodeInitEnd (unsigned int moduleSym, bool CompilingMainModule);
386 : :
387 : : /*
388 : : CodeFinallyStart - emits starting code before the main BEGIN END of the
389 : : current module.
390 : : */
391 : :
392 : : static void CodeFinallyStart (unsigned int moduleSym, bool CompilingMainModule);
393 : :
394 : : /*
395 : : CodeFinallyEnd - emits terminating code after the main BEGIN END of the
396 : : current module. It also creates the scaffold if the
397 : : cflag was not present.
398 : : */
399 : :
400 : : static void CodeFinallyEnd (unsigned int moduleSym, bool CompilingMainModule);
401 : :
402 : : /*
403 : : GetAddressOfUnbounded - returns the address of the unbounded array contents.
404 : : */
405 : :
406 : : static tree GetAddressOfUnbounded (location_t location, unsigned int param);
407 : :
408 : : /*
409 : : GetSizeOfHighFromUnbounded - returns a Tree containing the value of
410 : : param.HIGH * sizeof(unboundedType).
411 : : The number of legal bytes this array
412 : : occupies.
413 : : */
414 : :
415 : : static tree GetSizeOfHighFromUnbounded (unsigned int tokenno, unsigned int param);
416 : :
417 : : /*
418 : : MaybeDebugBuiltinAlloca - if DebugBuiltins is set
419 : : then call Builtins.alloca_trace
420 : : else call Builtins.alloca.
421 : : */
422 : :
423 : : static tree MaybeDebugBuiltinAlloca (location_t location, unsigned int tok, tree high);
424 : :
425 : : /*
426 : : MaybeDebugBuiltinMemcpy - if DebugBuiltins is set
427 : : then call memcpy
428 : : else call Builtins.memcpy.
429 : : */
430 : :
431 : : static tree MaybeDebugBuiltinMemcpy (location_t location, tree src, tree dest, tree nbytes);
432 : :
433 : : /*
434 : : MakeCopyUse - make a copy of the unbounded array and alter all references
435 : : from the old unbounded array to the new unbounded array.
436 : : The parameter, param, contains a RECORD
437 : : ArrayAddress: ADDRESS ;
438 : : ArrayHigh : CARDINAL ;
439 : : END
440 : : we simply declare a new array of size, ArrayHigh
441 : : and set ArrayAddress to the address of the copy.
442 : :
443 : : Remember ArrayHigh == sizeof(Array)-sizeof(typeof(array))
444 : : so we add 1 for the size and add 1 for a possible <nul>
445 : : */
446 : :
447 : : static void MakeCopyUse (unsigned int tokenno, unsigned int param);
448 : :
449 : : /*
450 : : GetParamAddress - returns the address of parameter, param.
451 : : */
452 : :
453 : : static tree GetParamAddress (location_t location, unsigned int proc, unsigned int param);
454 : :
455 : : /*
456 : : IsUnboundedWrittenTo - returns TRUE if the unbounded parameter
457 : : might be written to, or if -funbounded-by-reference
458 : : was _not_ specified.
459 : : */
460 : :
461 : : static bool IsUnboundedWrittenTo (unsigned int proc, unsigned int param);
462 : :
463 : : /*
464 : : GetParamSize - returns the size in bytes of, param.
465 : : */
466 : :
467 : : static tree GetParamSize (unsigned int tokenno, unsigned int param);
468 : :
469 : : /*
470 : : DoIsIntersection - jumps to, tLabel, if the ranges i1..i2 j1..j2 overlap
471 : : else jump to, fLabel.
472 : : */
473 : :
474 : : static void DoIsIntersection (unsigned int tokenno, tree ta, tree tb, tree tc, tree td, DynamicStrings_String tLabel, DynamicStrings_String fLabel);
475 : :
476 : : /*
477 : : BuildCascadedIfThenElsif - mustCheck contains a list of variables which
478 : : must be checked against the address of (proc, param, i).
479 : : If the address matches we make a copy of the unbounded
480 : : parameter (proc, param) and quit further checking.
481 : : */
482 : :
483 : : static void BuildCascadedIfThenElsif (unsigned int tokenno, Lists_List mustCheck, unsigned int proc, unsigned int param);
484 : :
485 : : /*
486 : : CheckUnboundedNonVarParameter - if non var unbounded parameter is written to
487 : : then
488 : : make a copy of the contents of this parameter
489 : : and use the copy
490 : : else if param
491 : : is type compatible with any parameter, symv
492 : : and at runtime its address matches symv
493 : : then
494 : : make a copy of the contents of this parameter
495 : : and use the copy
496 : : fi
497 : : */
498 : :
499 : : static void CheckUnboundedNonVarParameter (unsigned int tokenno, Lists_List trashed, unsigned int proc, unsigned int param);
500 : :
501 : : /*
502 : : IsParameterWritten - returns TRUE if a parameter, sym, is written to.
503 : : */
504 : :
505 : : static bool IsParameterWritten (unsigned int proc, unsigned int sym);
506 : :
507 : : /*
508 : : SaveNonVarUnboundedParameters - for each var parameter, symv, do
509 : : not just unbounded var parameters, but _all_
510 : : parameters
511 : : if symv is written to
512 : : then
513 : : add symv to a compile list
514 : : fi
515 : : done
516 : :
517 : : for each parameter of procedure, symu, do
518 : : if non var unbounded parameter is written to
519 : : then
520 : : make a copy of the contents of this parameter
521 : : and use the copy
522 : : else if
523 : : symu is type compatible with any parameter, symv
524 : : and at runtime its address matches symv
525 : : then
526 : : make a copy of the contents of this parameter
527 : : and use the copy
528 : : fi
529 : : done
530 : : */
531 : :
532 : : static void SaveNonVarUnboundedParameters (unsigned int tokenno, unsigned int proc);
533 : :
534 : : /*
535 : : AutoInitVariable -
536 : : */
537 : :
538 : : static void AutoInitVariable (location_t location, unsigned int sym);
539 : :
540 : : /*
541 : : AutoInitialize - scope will be a procedure, module or defimp. All pointer
542 : : variables are assigned to NIL.
543 : : */
544 : :
545 : : static void AutoInitialize (location_t location, unsigned int scope);
546 : :
547 : : /*
548 : : CodeNewLocalVar - Builds a new frame on the stack to contain the procedure
549 : : local variables.
550 : : */
551 : :
552 : : static void CodeNewLocalVar (unsigned int tokenno, unsigned int CurrentProcedure);
553 : :
554 : : /*
555 : : CodeKillLocalVar - removes local variables and returns to previous scope.
556 : : */
557 : :
558 : : static void CodeKillLocalVar (unsigned int CurrentProcedure);
559 : :
560 : : /*
561 : : CodeProcedureScope - start a procedure scope for CurrentProcedure.
562 : : */
563 : :
564 : : static void CodeProcedureScope (unsigned int CurrentProcedure);
565 : :
566 : : /*
567 : : CodeReturnValue - places the operand into the return value space
568 : : allocated by the function call.
569 : : */
570 : :
571 : : static void CodeReturnValue (unsigned int quad);
572 : :
573 : : /*
574 : : CodeCall - determines whether the procedure call is a direct call
575 : : or an indirect procedure call.
576 : : */
577 : :
578 : : static void CodeCall (unsigned int tokenno, unsigned int procedure);
579 : :
580 : : /*
581 : : UseBuiltin - returns a Tree containing the builtin function
582 : : and parameters. It should only be called if
583 : : CanUseBuiltin or IsProcedureBuiltinAvailable returns TRUE.
584 : : */
585 : :
586 : : static tree UseBuiltin (unsigned int tokenno, unsigned int Sym);
587 : :
588 : : /*
589 : : CodeDirectCall - calls a function/procedure.
590 : : */
591 : :
592 : : static tree CodeDirectCall (unsigned int tokenno, unsigned int procedure);
593 : :
594 : : /*
595 : : CodeIndirectCall - calls a function/procedure indirectly.
596 : : */
597 : :
598 : : static tree CodeIndirectCall (unsigned int tokenno, unsigned int ProcVar);
599 : :
600 : : /*
601 : : ConvertTo - convert gcc tree, t, (which currently represents Modula-2 op3) into
602 : : a symbol of, type.
603 : : */
604 : :
605 : : static tree ConvertTo (tree t, unsigned int type, unsigned int op3);
606 : :
607 : : /*
608 : : ConvertRHS - convert (t, rhs) into, type. (t, rhs) refer to the
609 : : same entity t is a GCC Tree and, rhs, is a Modula-2
610 : : symbol. It checks for char and strings
611 : : first and then the remaining types.
612 : : */
613 : :
614 : : static tree ConvertRHS (tree t, unsigned int type, unsigned int rhs);
615 : :
616 : : /*
617 : : IsCoerceableParameter - returns TRUE if symbol, sym, is a
618 : : coerceable parameter.
619 : : */
620 : :
621 : : static bool IsCoerceableParameter (unsigned int sym);
622 : :
623 : : /*
624 : : IsConstProcedure - returns TRUE if, p, is a const procedure.
625 : : */
626 : :
627 : : static bool IsConstProcedure (unsigned int p);
628 : :
629 : : /*
630 : : IsConstant - returns TRUE if symbol, p, is either a const or procedure.
631 : : */
632 : :
633 : : static bool IsConstant (unsigned int p);
634 : :
635 : : /*
636 : : CheckConvertCoerceParameter - ensure that actual parameter is the same as the nth of callee.
637 : : */
638 : :
639 : : static tree CheckConvertCoerceParameter (unsigned int tokenno, unsigned int nth, unsigned int callee, unsigned int actual);
640 : :
641 : : /*
642 : : CheckConstant - checks to see whether we should declare the constant.
643 : : */
644 : :
645 : : static tree CheckConstant (unsigned int tokenno, unsigned int des, unsigned int expr);
646 : :
647 : : /*
648 : : CodeMakeAdr - code the function MAKEADR.
649 : : */
650 : :
651 : : static void CodeMakeAdr (unsigned int q, unsigned int op1, unsigned int op2, unsigned int op3);
652 : :
653 : : /*
654 : : CodeBuiltinFunction - attempts to inline a function. Currently it only
655 : : inlines the SYSTEM function MAKEADR.
656 : : */
657 : :
658 : : static void CodeBuiltinFunction (unsigned int q, unsigned int nth, unsigned int func, unsigned int parameter);
659 : :
660 : : /*
661 : : FoldMakeAdr - attempts to fold the function MAKEADR.
662 : : */
663 : :
664 : : static void FoldMakeAdr (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int q, unsigned int op1, unsigned int op2, unsigned int op3);
665 : :
666 : : /*
667 : : doParam - builds the parameter, op3, which is to be passed to
668 : : procedure, op2. The number of the parameter is op1.
669 : : */
670 : :
671 : : static void doParam (unsigned int quad, unsigned int paramtok, unsigned int op1, unsigned int op2, unsigned int op3);
672 : :
673 : : /*
674 : : FoldBuiltin - attempts to fold the gcc builtin function.
675 : : */
676 : :
677 : : static void FoldBuiltin (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int q);
678 : :
679 : : /*
680 : : FoldBuiltinFunction - attempts to inline a function. Currently it only
681 : : inlines the SYSTEM function MAKEADR.
682 : : */
683 : :
684 : : static void FoldBuiltinFunction (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int q, unsigned int op1, unsigned int op2, unsigned int op3);
685 : :
686 : : /*
687 : : CodeParam - builds a parameter list.
688 : : Note that we can ignore ModeOfAddr as any lvalue will
689 : : have been created in a preceeding quadruple.
690 : : */
691 : :
692 : : static void CodeParam (unsigned int quad);
693 : :
694 : : /*
695 : : Replace - replace the entry for sym in the double entry bookkeeping with sym/tree.
696 : : */
697 : :
698 : : static void Replace (unsigned int sym, tree gcc);
699 : :
700 : : /*
701 : : CodeFunctValue - retrieves the function return value and assigns it
702 : : into a variable.
703 : : */
704 : :
705 : : static void CodeFunctValue (location_t location, unsigned int op1);
706 : :
707 : : /*
708 : : FoldStringLength -
709 : : */
710 : :
711 : : static void FoldStringLength (unsigned int quad, M2GCCDeclare_WalkAction p);
712 : :
713 : : /*
714 : : FoldStringConvertM2nul - attempt to assign the des with the string contents from expr.
715 : : It also marks the des as a m2 string which must be nul terminated.
716 : : The front end uses double book keeping and it is easier to have
717 : : different m2 string symbols each of which map onto a slightly different
718 : : gcc string tree.
719 : : */
720 : :
721 : : static void FoldStringConvertM2nul (unsigned int quad, M2GCCDeclare_WalkAction p);
722 : :
723 : : /*
724 : : FoldStringConvertCnul -attempt to assign the des with the string contents from expr.
725 : : It also marks the des as a C string which must be nul terminated.
726 : : */
727 : :
728 : : static void FoldStringConvertCnul (unsigned int quad, M2GCCDeclare_WalkAction p);
729 : : static void CodeAddr (unsigned int tokenno, unsigned int quad, unsigned int op1, unsigned int op3);
730 : : static void stop (void);
731 : : static void CheckStop (unsigned int q);
732 : : static void FoldBecomes (M2GCCDeclare_WalkAction p, M2BasicBlock_BasicBlock bb, unsigned int quad);
733 : :
734 : : /*
735 : : TryDeclareConst -
736 : : */
737 : :
738 : : static void TryDeclareConst (unsigned int tokenno, unsigned int sym);
739 : :
740 : : /*
741 : : RemoveQuad - remove quad and ensure p (des) is called.
742 : : */
743 : :
744 : : static void RemoveQuad (M2GCCDeclare_WalkAction p, unsigned int des, unsigned int quad);
745 : :
746 : : /*
747 : : DeclaredOperandsBecomes -
748 : : */
749 : :
750 : : static bool DeclaredOperandsBecomes (M2GCCDeclare_WalkAction p, unsigned int quad);
751 : :
752 : : /*
753 : : TypeCheckBecomes - returns TRUE if the type check succeeds.
754 : : */
755 : :
756 : : static bool TypeCheckBecomes (M2GCCDeclare_WalkAction p, unsigned int quad);
757 : :
758 : : /*
759 : : PerformFoldBecomes - attempts to fold quad. It propagates constant strings
760 : : and attempts to declare des providing it is a constant
761 : : and expr is resolved.
762 : : */
763 : :
764 : : static void PerformFoldBecomes (M2GCCDeclare_WalkAction p, unsigned int quad);
765 : :
766 : : /*
767 : : CodeTry - starts building a GCC 'try' node.
768 : : */
769 : :
770 : : static void CodeTry (void);
771 : :
772 : : /*
773 : : CodeThrow - builds a GCC 'throw' node.
774 : : */
775 : :
776 : : static void CodeThrow (unsigned int value);
777 : : static void CodeRetry (unsigned int destQuad);
778 : : static void CodeCatchBegin (void);
779 : : static void CodeCatchEnd (void);
780 : :
781 : : /*
782 : : DescribeTypeError -
783 : : */
784 : :
785 : : static void DescribeTypeError (unsigned int token, unsigned int op1, unsigned int op2);
786 : :
787 : : /*
788 : : DefaultConvertGM2 - provides a simple mapping between
789 : : front end data types and GCC equivalents.
790 : : This is only used to aid assignment of
791 : : typed constants.
792 : : */
793 : :
794 : : static tree DefaultConvertGM2 (unsigned int sym);
795 : :
796 : : /*
797 : : FoldConstBecomes - returns a Tree containing op3.
798 : : The tree will have been folded and
799 : : type converted if necessary.
800 : : */
801 : :
802 : : static tree FoldConstBecomes (unsigned int tokenno, unsigned int op1, unsigned int op3);
803 : :
804 : : /*
805 : : checkArrayElements - return TRUE if des or expr are not arrays.
806 : : If they are arrays and have different number of
807 : : elements return FALSE, otherwise TRUE.
808 : : */
809 : :
810 : : static bool checkArrayElements (unsigned int des, unsigned int expr, unsigned int virtpos, unsigned int despos, unsigned int exprpos);
811 : :
812 : : /*
813 : : CodeInitAddress -
814 : : */
815 : :
816 : : static void CodeInitAddress (unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3);
817 : :
818 : : /*
819 : : checkRecordTypes - returns TRUE if des is not a record or if the record
820 : : is the same type as expr.
821 : : */
822 : :
823 : : static bool checkRecordTypes (unsigned int des, unsigned int expr, unsigned int virtpos);
824 : :
825 : : /*
826 : : checkIncorrectMeta - checks to see if des and expr are assignment compatible is allows
827 : : generic system types to be assigned.
828 : : */
829 : :
830 : : static bool checkIncorrectMeta (unsigned int des, unsigned int expr, unsigned int virtpos);
831 : :
832 : : /*
833 : : checkBecomes - returns TRUE if the checks pass.
834 : : */
835 : :
836 : : static bool checkBecomes (unsigned int des, unsigned int expr, unsigned int virtpos, unsigned int despos, unsigned int exprpos);
837 : :
838 : : /*
839 : : checkDeclare - checks to see if sym is declared and if it is not then declare it.
840 : : */
841 : :
842 : : static void checkDeclare (unsigned int sym);
843 : :
844 : : /*
845 : : PerformCodeBecomes -
846 : : */
847 : :
848 : : static void PerformCodeBecomes (location_t location, unsigned int virtpos, unsigned int des, unsigned int expr);
849 : : static void CodeBecomes (unsigned int quad);
850 : :
851 : : /*
852 : : LValueToGenericPtrOrConvert - if sym is an lvalue then convert to pointer type
853 : : else convert to type, type. Return the converted tree.
854 : : */
855 : :
856 : : static tree LValueToGenericPtrOrConvert (unsigned int sym, tree type);
857 : :
858 : : /*
859 : : FoldBinary - check whether we can fold the binop operation.
860 : : */
861 : :
862 : : static void FoldBinary (unsigned int tokenno, M2GCCDeclare_WalkAction p, m2expr_BuildBinProcedure binop, unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3);
863 : :
864 : : /*
865 : : ConvertBinaryOperands -
866 : : */
867 : :
868 : : static void ConvertBinaryOperands (location_t location, tree *tl, tree *tr, unsigned int type, unsigned int op2, unsigned int op3);
869 : :
870 : : /*
871 : : CodeBinaryCheck - encode a binary arithmetic operation.
872 : : */
873 : :
874 : : static void CodeBinaryCheck (m2expr_BuildBinCheckProcedure binop, unsigned int quad);
875 : :
876 : : /*
877 : : MixTypesBinary - depending upon overflowCheck do not check pointer arithmetic.
878 : : */
879 : :
880 : : static unsigned int MixTypesBinary (unsigned int left, unsigned int right, unsigned int tokpos, bool overflowCheck);
881 : :
882 : : /*
883 : : CodeBinary - encode a binary arithmetic operation.
884 : : */
885 : :
886 : : static void CodeBinary (m2expr_BuildBinProcedure binop, unsigned int quad);
887 : :
888 : : /*
889 : : NoWalkProcedure -
890 : : */
891 : :
892 : : static void NoWalkProcedure (unsigned int param __attribute__((unused)));
893 : :
894 : : /*
895 : : CheckBinaryExpressionTypes - returns TRUE if all expression checks pass.
896 : : If the expression check fails quad is removed,
897 : : the walk procedure (des) is called and NoChange is
898 : : set to FALSE.
899 : : */
900 : :
901 : : static bool CheckBinaryExpressionTypes (unsigned int quad, M2GCCDeclare_WalkAction p);
902 : :
903 : : /*
904 : : CheckElementSetTypes - returns TRUE if all expression checks pass.
905 : : If the expression check fails quad is removed,
906 : : the walk procedure (des) is called and NoChange is
907 : : set to FALSE.
908 : : */
909 : :
910 : : static bool CheckElementSetTypes (unsigned int quad);
911 : :
912 : : /*
913 : : CodeBinarySet - encode a binary set arithmetic operation.
914 : : Set operands may be longer than a word.
915 : : */
916 : :
917 : : static void CodeBinarySet (m2expr_BuildBinProcedure binop, M2GenGCC_DoProcedure doOp, unsigned int quad);
918 : :
919 : : /*
920 : : CheckUnaryOperand - checks to see whether operand is using a generic type.
921 : : */
922 : :
923 : : static bool CheckUnaryOperand (unsigned int quad, unsigned int operand);
924 : :
925 : : /*
926 : : UnaryOperand - returns TRUE if operand is acceptable for
927 : : unary operator: + -. If FALSE
928 : : is returned, an error message will be generated
929 : : and the quad is deleted.
930 : : */
931 : :
932 : : static bool UnaryOperand (unsigned int quad, unsigned int operand);
933 : :
934 : : /*
935 : : CheckBinaryOperand - checks to see whether operand is using a generic type.
936 : : */
937 : :
938 : : static bool CheckBinaryOperand (unsigned int quad, bool isleft, unsigned int operand, bool result);
939 : :
940 : : /*
941 : : BinaryOperands - returns TRUE if, l, and, r, are acceptable for
942 : : binary operator: + - / * and friends. If FALSE
943 : : is returned, an error message will be generated
944 : : and the, quad, is deleted.
945 : : */
946 : :
947 : : static bool BinaryOperands (unsigned int quad, unsigned int l, unsigned int r);
948 : :
949 : : /*
950 : : IsConstStr - returns TRUE if sym is a constant string or a char constant.
951 : : */
952 : :
953 : : static bool IsConstStr (unsigned int sym);
954 : :
955 : : /*
956 : : IsConstStrKnown - returns TRUE if sym is a constant string or a char constant
957 : : which is known.
958 : : */
959 : :
960 : : static bool IsConstStrKnown (unsigned int sym);
961 : :
962 : : /*
963 : : GetStr - return a string containing a constant string value associated with sym.
964 : : A nul char constant will return an empty string.
965 : : */
966 : :
967 : : static DynamicStrings_String GetStr (unsigned int tokenno, unsigned int sym);
968 : :
969 : : /*
970 : : FoldAdd - check addition for constant folding. It checks for conststrings
971 : : overloading the +.
972 : : */
973 : :
974 : : static void FoldAdd (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3);
975 : :
976 : : /*
977 : : FoldArithAdd - check arithmetic addition for constant folding.
978 : : */
979 : :
980 : : static void FoldArithAdd (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3);
981 : :
982 : : /*
983 : : CodeAddChecked - code an addition instruction, determine whether checking
984 : : is required.
985 : : */
986 : :
987 : : static void CodeAddChecked (unsigned int quad, unsigned int left, unsigned int right);
988 : :
989 : : /*
990 : : CodeAddCheck - encode addition but check for overflow.
991 : : */
992 : :
993 : : static void CodeAddCheck (unsigned int quad, unsigned int left, unsigned int right);
994 : :
995 : : /*
996 : : CodeAdd - encode addition.
997 : : */
998 : :
999 : : static void CodeAdd (unsigned int quad, unsigned int left, unsigned int right);
1000 : :
1001 : : /*
1002 : : FoldSub - check subtraction for constant folding.
1003 : : */
1004 : :
1005 : : static void FoldSub (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3);
1006 : :
1007 : : /*
1008 : : CodeSubChecked - code a subtract instruction, determine whether checking
1009 : : is required.
1010 : : */
1011 : :
1012 : : static void CodeSubChecked (unsigned int quad, unsigned int left, unsigned int right);
1013 : :
1014 : : /*
1015 : : CodeSubCheck - encode subtraction but check for overflow.
1016 : : */
1017 : :
1018 : : static void CodeSubCheck (unsigned int quad, unsigned int left, unsigned int right);
1019 : :
1020 : : /*
1021 : : CodeSub - encode subtraction.
1022 : : */
1023 : :
1024 : : static void CodeSub (unsigned int quad, unsigned int left, unsigned int right);
1025 : :
1026 : : /*
1027 : : FoldMult - check multiplication for constant folding.
1028 : : */
1029 : :
1030 : : static void FoldMult (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3);
1031 : :
1032 : : /*
1033 : : CodeMultChecked - code a multiplication instruction, determine whether checking
1034 : : is required.
1035 : : */
1036 : :
1037 : : static void CodeMultChecked (unsigned int quad, unsigned int left, unsigned int right);
1038 : :
1039 : : /*
1040 : : CodeMultCheck - encode multiplication but check for overflow.
1041 : : */
1042 : :
1043 : : static void CodeMultCheck (unsigned int quad, unsigned int left, unsigned int right);
1044 : :
1045 : : /*
1046 : : CodeMult - encode multiplication.
1047 : : */
1048 : :
1049 : : static void CodeMult (unsigned int quad, unsigned int left, unsigned int right);
1050 : :
1051 : : /*
1052 : : CodeDivM2Checked - code a divide instruction, determine whether checking
1053 : : is required.
1054 : : */
1055 : :
1056 : : static void CodeDivM2Checked (unsigned int quad, unsigned int left, unsigned int right);
1057 : :
1058 : : /*
1059 : : CodeDivM2Check - encode addition but check for overflow.
1060 : : */
1061 : :
1062 : : static void CodeDivM2Check (unsigned int quad, unsigned int left, unsigned int right);
1063 : :
1064 : : /*
1065 : : CodeModM2Checked - code a modulus instruction, determine whether checking
1066 : : is required.
1067 : : */
1068 : :
1069 : : static void CodeModM2Checked (unsigned int quad, unsigned int left, unsigned int right);
1070 : :
1071 : : /*
1072 : : CodeModM2Check - encode addition but check for overflow.
1073 : : */
1074 : :
1075 : : static void CodeModM2Check (unsigned int quad, unsigned int left, unsigned int right);
1076 : :
1077 : : /*
1078 : : BinaryOperandRealFamily -
1079 : : */
1080 : :
1081 : : static bool BinaryOperandRealFamily (unsigned int op);
1082 : :
1083 : : /*
1084 : : FoldDivM2 - check division for constant folding.
1085 : : */
1086 : :
1087 : : static void FoldDivM2 (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3);
1088 : :
1089 : : /*
1090 : : CodeDivM2 - encode division.
1091 : : */
1092 : :
1093 : : static void CodeDivM2 (unsigned int quad, unsigned int left, unsigned int right);
1094 : :
1095 : : /*
1096 : : FoldModM2 - check modulus for constant folding.
1097 : : */
1098 : :
1099 : : static void FoldModM2 (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3);
1100 : :
1101 : : /*
1102 : : CodeModM2 - encode modulus.
1103 : : */
1104 : :
1105 : : static void CodeModM2 (unsigned int quad, unsigned int left, unsigned int right);
1106 : :
1107 : : /*
1108 : : FoldDivTrunc - check division for constant folding.
1109 : : */
1110 : :
1111 : : static void FoldDivTrunc (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3);
1112 : :
1113 : : /*
1114 : : CodeDivTrunc - encode multiplication.
1115 : : */
1116 : :
1117 : : static void CodeDivTrunc (unsigned int quad, unsigned int left, unsigned int right);
1118 : :
1119 : : /*
1120 : : FoldModTrunc - check modulus for constant folding.
1121 : : */
1122 : :
1123 : : static void FoldModTrunc (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3);
1124 : :
1125 : : /*
1126 : : CodeModTrunc - encode modulus.
1127 : : */
1128 : :
1129 : : static void CodeModTrunc (unsigned int quad, unsigned int left, unsigned int right);
1130 : :
1131 : : /*
1132 : : FoldDivCeil - check division for constant folding.
1133 : : */
1134 : :
1135 : : static void FoldDivCeil (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3);
1136 : :
1137 : : /*
1138 : : CodeDivCeil - encode multiplication.
1139 : : */
1140 : :
1141 : : static void CodeDivCeil (unsigned int quad, unsigned int left, unsigned int right);
1142 : :
1143 : : /*
1144 : : FoldModCeil - check modulus for constant folding.
1145 : : */
1146 : :
1147 : : static void FoldModCeil (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3);
1148 : :
1149 : : /*
1150 : : CodeModCeil - encode multiplication.
1151 : : */
1152 : :
1153 : : static void CodeModCeil (unsigned int quad, unsigned int left, unsigned int right);
1154 : :
1155 : : /*
1156 : : FoldDivFloor - check division for constant folding.
1157 : : */
1158 : :
1159 : : static void FoldDivFloor (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3);
1160 : :
1161 : : /*
1162 : : CodeDivFloor - encode multiplication.
1163 : : */
1164 : :
1165 : : static void CodeDivFloor (unsigned int quad, unsigned int left, unsigned int right);
1166 : :
1167 : : /*
1168 : : FoldModFloor - check modulus for constant folding.
1169 : : */
1170 : :
1171 : : static void FoldModFloor (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3);
1172 : :
1173 : : /*
1174 : : CodeModFloor - encode modulus.
1175 : : */
1176 : :
1177 : : static void CodeModFloor (unsigned int quad, unsigned int left, unsigned int right);
1178 : :
1179 : : /*
1180 : : FoldBuiltinConst -
1181 : : */
1182 : :
1183 : : static void FoldBuiltinConst (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int quad, unsigned int result, unsigned int constDesc);
1184 : :
1185 : : /*
1186 : : FoldBuiltinTypeInfo - attempts to fold a builtin attribute value on type op2.
1187 : : */
1188 : :
1189 : : static void FoldBuiltinTypeInfo (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3);
1190 : :
1191 : : /*
1192 : : FoldTBitsize - attempt to fold the standard function SYSTEM.TBITSIZE
1193 : : quadruple. If the quadruple is folded it is removed.
1194 : : */
1195 : :
1196 : : static void FoldTBitsize (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int quad, unsigned int res, unsigned int type);
1197 : :
1198 : : /*
1199 : : FoldStandardFunction - attempts to fold a standard function.
1200 : : */
1201 : :
1202 : : static void FoldStandardFunction (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3);
1203 : :
1204 : : /*
1205 : : CodeStandardFunction -
1206 : : */
1207 : :
1208 : : static void CodeStandardFunction (unsigned int quad, unsigned int result, unsigned int function, unsigned int param);
1209 : :
1210 : : /*
1211 : : CodeSavePriority - checks to see whether op2 is reachable and is directly accessible
1212 : : externally. If so then it saves the current interrupt priority
1213 : : in op1 and sets the current priority to that determined by
1214 : : appropriate module.
1215 : :
1216 : : op1 := op3(GetModuleScope(op2))
1217 : : */
1218 : :
1219 : : static void CodeSavePriority (unsigned int oldValue, unsigned int scopeSym, unsigned int procedureSym);
1220 : :
1221 : : /*
1222 : : CodeRestorePriority - checks to see whether op2 is reachable and is directly accessible
1223 : : externally. If so then it restores the previous interrupt priority
1224 : : held in op1.
1225 : :
1226 : : op1 := op3(op1)
1227 : : */
1228 : :
1229 : : static void CodeRestorePriority (unsigned int oldValue, unsigned int scopeSym, unsigned int procedureSym);
1230 : :
1231 : : /*
1232 : : FoldBinarySet - attempts to fold set arithmetic it removes the quad if successful.
1233 : : */
1234 : :
1235 : : static void FoldBinarySet (unsigned int tokenno, M2GCCDeclare_WalkAction p, M2GenGCC_DoProcedure op, unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3);
1236 : :
1237 : : /*
1238 : : FoldSetOr - check whether we can fold a set arithmetic or.
1239 : : */
1240 : :
1241 : : static void FoldSetOr (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3);
1242 : :
1243 : : /*
1244 : : CodeSetOr - encode set arithmetic or.
1245 : : */
1246 : :
1247 : : static void CodeSetOr (unsigned int quad);
1248 : :
1249 : : /*
1250 : : FoldSetAnd - check whether we can fold a logical and.
1251 : : */
1252 : :
1253 : : static void FoldSetAnd (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3);
1254 : :
1255 : : /*
1256 : : CodeSetAnd - encode set arithmetic and.
1257 : : */
1258 : :
1259 : : static void CodeSetAnd (unsigned int quad);
1260 : :
1261 : : /*
1262 : : CodeBinarySetShift - encode a binary set arithmetic operation.
1263 : : The set maybe larger than a machine word
1264 : : and the value of one word may effect the
1265 : : values of another - ie shift and rotate.
1266 : : Set sizes of a word or less are evaluated
1267 : : with binop, whereas multiword sets are
1268 : : evaluated by M2RTS.
1269 : : */
1270 : :
1271 : : static void CodeBinarySetShift (m2expr_BuildSetProcedure binop, M2GenGCC_DoProcedure doOp, NameKey_Name var, NameKey_Name left, NameKey_Name right, unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3);
1272 : :
1273 : : /*
1274 : : FoldSetShift - check whether we can fold a logical shift.
1275 : : */
1276 : :
1277 : : static void FoldSetShift (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3);
1278 : :
1279 : : /*
1280 : : CodeSetShift - encode set arithmetic shift.
1281 : : */
1282 : :
1283 : : static void CodeSetShift (unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3);
1284 : :
1285 : : /*
1286 : : FoldSetRotate - check whether we can fold a logical rotate.
1287 : : */
1288 : :
1289 : : static void FoldSetRotate (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3);
1290 : :
1291 : : /*
1292 : : CodeSetRotate - encode set arithmetic rotate.
1293 : : */
1294 : :
1295 : : static void CodeSetRotate (unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3);
1296 : :
1297 : : /*
1298 : : CodeSetLogicalDifference - encode set arithmetic logical difference.
1299 : : */
1300 : :
1301 : : static void CodeSetLogicalDifference (unsigned int quad);
1302 : :
1303 : : /*
1304 : : FoldSymmetricDifference - check whether we can fold a logical difference.
1305 : : */
1306 : :
1307 : : static void FoldSymmetricDifference (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3);
1308 : :
1309 : : /*
1310 : : CodeSetSymmetricDifference - code set difference.
1311 : : */
1312 : :
1313 : : static void CodeSetSymmetricDifference (unsigned int quad);
1314 : :
1315 : : /*
1316 : : CodeUnarySet - encode a unary set arithmetic operation.
1317 : : Set operands may be longer than a word.
1318 : : */
1319 : :
1320 : : static void CodeUnarySet (m2expr_BuildUnarySetFunction unop, M2GenGCC_DoUnaryProcedure constop, unsigned int quad, unsigned int result, unsigned int expr);
1321 : :
1322 : : /*
1323 : : FoldIncl - check whether we can fold the InclOp.
1324 : : result := result + (1 << expr)
1325 : : */
1326 : :
1327 : : static void FoldIncl (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int quad, unsigned int result, unsigned int expr);
1328 : :
1329 : : /*
1330 : : FoldIfLess - check to see if it is possible to evaluate
1331 : : if op1 < op2 then goto op3.
1332 : : */
1333 : :
1334 : : static void FoldIfLess (unsigned int tokenno, unsigned int quad, unsigned int left, unsigned int right, unsigned int destQuad);
1335 : :
1336 : : /*
1337 : : FoldIfGre - check to see if it is possible to evaluate
1338 : : if op1 > op2 then goto op3.
1339 : : */
1340 : :
1341 : : static void FoldIfGre (unsigned int tokenno, unsigned int quad, unsigned int left, unsigned int right, unsigned int destQuad);
1342 : :
1343 : : /*
1344 : : FoldIfLessEqu - check to see if it is possible to evaluate
1345 : : if op1 <= op2 then goto op3.
1346 : : */
1347 : :
1348 : : static void FoldIfLessEqu (unsigned int tokenno, unsigned int quad, unsigned int left, unsigned int right, unsigned int destQuad);
1349 : :
1350 : : /*
1351 : : FoldIfGreEqu - check to see if it is possible to evaluate
1352 : : if op1 >= op2 then goto op3.
1353 : : */
1354 : :
1355 : : static void FoldIfGreEqu (unsigned int tokenno, unsigned int quad, unsigned int left, unsigned int right, unsigned int destQuad);
1356 : :
1357 : : /*
1358 : : FoldIfIn - check whether we can fold the IfInOp
1359 : : if op1 in op2 then goto op3
1360 : : */
1361 : :
1362 : : static void FoldIfIn (unsigned int tokenno, unsigned int quad, unsigned int left, unsigned int right, unsigned int destQuad);
1363 : :
1364 : : /*
1365 : : FoldIfNotIn - check whether we can fold the IfNotInOp
1366 : : if not (op1 in op2) then goto op3
1367 : : */
1368 : :
1369 : : static void FoldIfNotIn (unsigned int tokenno, unsigned int quad, unsigned int left, unsigned int right, unsigned int destQuad);
1370 : :
1371 : : /*
1372 : : FoldIfEqu - check to see if it is possible to evaluate
1373 : : if op1 = op2 then goto op3.
1374 : : */
1375 : :
1376 : : static void FoldIfEqu (unsigned int tokenno, unsigned int quad, unsigned int left, unsigned int right, unsigned int destQuad);
1377 : :
1378 : : /*
1379 : : FoldIfNotEqu - check to see if it is possible to evaluate
1380 : : if op1 # op2 then goto op3.
1381 : : */
1382 : :
1383 : : static void FoldIfNotEqu (unsigned int tokenno, unsigned int quad, unsigned int left, unsigned int right, unsigned int destQuad);
1384 : :
1385 : : /*
1386 : : GetSetLimits - assigns low and high to the limits of the declared, set.
1387 : : */
1388 : :
1389 : : static void GetSetLimits (unsigned int set, unsigned int *low, unsigned int *high);
1390 : :
1391 : : /*
1392 : : GetFieldNo - returns the field number in the, set, which contains, element.
1393 : : */
1394 : :
1395 : : static int GetFieldNo (unsigned int tokenno, unsigned int element, unsigned int set, tree *offset);
1396 : :
1397 : : /*
1398 : : CodeIncl - encode an InclOp:
1399 : : result := result + (1 << expr)
1400 : : */
1401 : :
1402 : : static void CodeIncl (unsigned int result, unsigned int expr);
1403 : :
1404 : : /*
1405 : : FoldExcl - check whether we can fold the InclOp.
1406 : : op1 := op1 - (1 << op3)
1407 : : */
1408 : :
1409 : : static void FoldExcl (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int quad, unsigned int result, unsigned int expr);
1410 : :
1411 : : /*
1412 : : CodeExcl - encode an ExclOp:
1413 : : result := result - (1 << expr)
1414 : : */
1415 : :
1416 : : static void CodeExcl (unsigned int result, unsigned int expr);
1417 : :
1418 : : /*
1419 : : FoldUnary - check whether we can fold the unop operation.
1420 : : */
1421 : :
1422 : : static void FoldUnary (unsigned int tokenno, M2GCCDeclare_WalkAction p, m2expr_BuildUnaryProcedure unop, tree ZConstToTypedConst, unsigned int quad, unsigned int result, unsigned int expr);
1423 : :
1424 : : /*
1425 : : FoldUnarySet - check whether we can fold the doOp operation.
1426 : : */
1427 : :
1428 : : static void FoldUnarySet (unsigned int tokenno, M2GCCDeclare_WalkAction p, M2GenGCC_DoUnaryProcedure doOp, unsigned int quad, unsigned int result, unsigned int expr);
1429 : :
1430 : : /*
1431 : : CodeUnaryCheck - encode a unary arithmetic operation.
1432 : : */
1433 : :
1434 : : static void CodeUnaryCheck (m2expr_BuildUnaryCheckProcedure unop, tree ZConstToTypedConst, unsigned int quad, unsigned int result, unsigned int expr);
1435 : :
1436 : : /*
1437 : : CodeUnary - encode a unary arithmetic operation.
1438 : : */
1439 : :
1440 : : static void CodeUnary (m2expr_BuildUnaryProcedure unop, tree ZConstToTypedConst, unsigned int quad, unsigned int result, unsigned int expr);
1441 : :
1442 : : /*
1443 : : FoldNegate - check unary negate for constant folding.
1444 : : */
1445 : :
1446 : : static void FoldNegate (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int quad, unsigned int result, unsigned int expr);
1447 : :
1448 : : /*
1449 : : CodeNegateChecked - code a negate instruction, determine whether checking
1450 : : is required.
1451 : : */
1452 : :
1453 : : static void CodeNegateChecked (unsigned int quad, unsigned int op1, unsigned int op3);
1454 : :
1455 : : /*
1456 : : FoldSize - check unary SIZE for constant folding.
1457 : : */
1458 : :
1459 : : static void FoldSize (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3);
1460 : :
1461 : : /*
1462 : : CodeSize - encode the inbuilt SIZE function.
1463 : : */
1464 : :
1465 : : static void CodeSize (unsigned int result, unsigned int sym);
1466 : :
1467 : : /*
1468 : : FoldRecordField - check whether we can fold an RecordFieldOp quadruple.
1469 : : Very similar to FoldBinary, except that we need to
1470 : : hard code a few parameters to the gcc backend.
1471 : : */
1472 : :
1473 : : static void FoldRecordField (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int quad, unsigned int result, unsigned int record, unsigned int field);
1474 : :
1475 : : /*
1476 : : CodeRecordField - encode a reference to a field within a record.
1477 : : */
1478 : :
1479 : : static void CodeRecordField (unsigned int result, unsigned int record, unsigned int field);
1480 : :
1481 : : /*
1482 : : BuildHighFromChar -
1483 : : */
1484 : :
1485 : : static tree BuildHighFromChar (unsigned int operand);
1486 : :
1487 : : /*
1488 : : SkipToArray -
1489 : : */
1490 : :
1491 : : static unsigned int SkipToArray (unsigned int operand, unsigned int dim);
1492 : :
1493 : : /*
1494 : : BuildHighFromArray -
1495 : : */
1496 : :
1497 : : static tree BuildHighFromArray (unsigned int tokenno, unsigned int dim, unsigned int operand);
1498 : :
1499 : : /*
1500 : : BuildHighFromStaticArray -
1501 : : */
1502 : :
1503 : : static tree BuildHighFromStaticArray (location_t location, unsigned int Type);
1504 : :
1505 : : /*
1506 : : BuildHighFromString -
1507 : : */
1508 : :
1509 : : static tree BuildHighFromString (unsigned int operand);
1510 : :
1511 : : /*
1512 : : ResolveHigh - given an Modula-2 operand, it resolves the HIGH(operand)
1513 : : and returns a GCC constant symbol containing the value of
1514 : : HIGH(operand).
1515 : : */
1516 : :
1517 : : static tree ResolveHigh (unsigned int tokenno, unsigned int dim, unsigned int operand);
1518 : :
1519 : : /*
1520 : : FoldHigh - if the array is not dynamic then we should be able to
1521 : : remove the HighOp quadruple and assign op1 with
1522 : : the known compile time HIGH(op3).
1523 : : */
1524 : :
1525 : : static void FoldHigh (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int quad, unsigned int op1, unsigned int dim, unsigned int op3);
1526 : :
1527 : : /*
1528 : : CodeHigh - encode a unary arithmetic operation.
1529 : : */
1530 : :
1531 : : static void CodeHigh (unsigned int result, unsigned int dim, unsigned int array);
1532 : :
1533 : : /*
1534 : : CodeUnbounded - codes the creation of an unbounded parameter variable.
1535 : : places the address of op3 into *op1
1536 : : */
1537 : :
1538 : : static void CodeUnbounded (unsigned int result, unsigned int array);
1539 : :
1540 : : /*
1541 : : AreSubrangesKnown - returns TRUE if the subranges values used within, array, are known.
1542 : : */
1543 : :
1544 : : static bool AreSubrangesKnown (unsigned int array);
1545 : :
1546 : : /*
1547 : : CodeArray - res is an lvalue which will point to the array element.
1548 : : */
1549 : :
1550 : : static void CodeArray (unsigned int res, unsigned int index, unsigned int array);
1551 : :
1552 : : /*
1553 : : FoldElementSizeForArray - attempts to calculate the Subscript
1554 : : multiplier for the index op3.
1555 : : */
1556 : :
1557 : : static void FoldElementSizeForArray (unsigned int tokenno, unsigned int quad, M2GCCDeclare_WalkAction p, unsigned int result, unsigned int type);
1558 : :
1559 : : /*
1560 : : FoldElementSizeForUnbounded - Unbounded arrays only have one index,
1561 : : therefore element size will be the
1562 : : TSIZE(Type) where Type is defined as:
1563 : : ARRAY OF Type.
1564 : : */
1565 : :
1566 : : static void FoldElementSizeForUnbounded (unsigned int tokenno, unsigned int quad, M2GCCDeclare_WalkAction p, unsigned int result, unsigned int ArrayType);
1567 : :
1568 : : /*
1569 : : FoldElementSize - folds the element size for an ArraySym or UnboundedSym.
1570 : : ElementSize returns a constant which defines the
1571 : : multiplier to be multiplied by this element index.
1572 : : */
1573 : :
1574 : : static void FoldElementSize (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int quad, unsigned int result, unsigned int type);
1575 : :
1576 : : /*
1577 : : PopKindTree - returns a Tree from M2ALU of the type implied by, op.
1578 : : */
1579 : :
1580 : : static tree PopKindTree (unsigned int op, unsigned int tokenno);
1581 : :
1582 : : /*
1583 : : FoldConvert - attempts to fold expr to type into result
1584 : : providing that result and expr are constants.
1585 : : If required convert will alter the machine representation
1586 : : of expr to comply with type.
1587 : : */
1588 : :
1589 : : static void FoldConvert (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int quad, unsigned int result, unsigned int type, unsigned int expr);
1590 : :
1591 : : /*
1592 : : CodeConvert - Converts, rhs, to, type, placing the result into lhs.
1593 : : Convert will, if need be, alter the machine representation
1594 : : of op3 to comply with TYPE op2.
1595 : : */
1596 : :
1597 : : static void CodeConvert (unsigned int quad, unsigned int lhs, unsigned int type, unsigned int rhs);
1598 : :
1599 : : /*
1600 : : CodeCoerce - Coerce op3 to type op2 placing the result into
1601 : : op1.
1602 : : Coerce will NOT alter the machine representation
1603 : : of op3 to comply with TYPE op2.
1604 : : Therefore it _insists_ that under all circumstances that the
1605 : : type sizes of op1 and op3 are the same.
1606 : : CONVERT will perform machine manipulation to change variable
1607 : : types, coerce does no such thing.
1608 : : */
1609 : :
1610 : : static void CodeCoerce (unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3);
1611 : :
1612 : : /*
1613 : : FoldCoerce -
1614 : : */
1615 : :
1616 : : static void FoldCoerce (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3);
1617 : :
1618 : : /*
1619 : : CanConvert - returns TRUE if we can convert variable, var, to a, type.
1620 : : */
1621 : :
1622 : : static bool CanConvert (unsigned int type, unsigned int var);
1623 : :
1624 : : /*
1625 : : CodeCast - Cast op3 to type op2 placing the result into op1.
1626 : : Cast will NOT alter the machine representation
1627 : : of op3 to comply with TYPE op2 as long as SIZE(op3)=SIZE(op2).
1628 : : If the sizes differ then Convert is called.
1629 : : */
1630 : :
1631 : : static void CodeCast (unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3);
1632 : : static void FoldCast (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3);
1633 : :
1634 : : /*
1635 : : CreateLabelProcedureN - creates a label using procedure name and
1636 : : an integer.
1637 : : */
1638 : :
1639 : : static DynamicStrings_String CreateLabelProcedureN (unsigned int proc, const char *leader_, unsigned int _leader_high, unsigned int unboundedCount, unsigned int n);
1640 : :
1641 : : /*
1642 : : CreateLabelName - creates a namekey from quadruple, q.
1643 : : */
1644 : :
1645 : : static DynamicStrings_String CreateLabelName (unsigned int q);
1646 : :
1647 : : /*
1648 : : CodeGoto - creates a jump to a labeled quadruple.
1649 : : */
1650 : :
1651 : : static void CodeGoto (unsigned int destquad);
1652 : :
1653 : : /*
1654 : : CheckReferenced - checks to see whether this quadruple requires a label.
1655 : : */
1656 : :
1657 : : static void CheckReferenced (unsigned int quad, M2Quads_QuadOperator op);
1658 : :
1659 : : /*
1660 : : CodeIfSetLess -
1661 : : */
1662 : :
1663 : : static void CodeIfSetLess (unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3);
1664 : :
1665 : : /*
1666 : : PerformCodeIfLess - codes the quadruple if op1 < op2 then goto op3
1667 : : */
1668 : :
1669 : : static void PerformCodeIfLess (unsigned int quad);
1670 : :
1671 : : /*
1672 : : CodeIfLess - codes the quadruple if op1 < op2 then goto op3
1673 : : */
1674 : :
1675 : : static void CodeIfLess (unsigned int quad);
1676 : :
1677 : : /*
1678 : : CodeIfSetGre -
1679 : : */
1680 : :
1681 : : static void CodeIfSetGre (unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3);
1682 : :
1683 : : /*
1684 : : PerformCodeIfGre - codes the quadruple if op1 > op2 then goto op3
1685 : : */
1686 : :
1687 : : static void PerformCodeIfGre (unsigned int quad);
1688 : :
1689 : : /*
1690 : : CodeIfGre - codes the quadruple if op1 > op2 then goto op3
1691 : : */
1692 : :
1693 : : static void CodeIfGre (unsigned int quad);
1694 : :
1695 : : /*
1696 : : CodeIfSetLessEqu -
1697 : : */
1698 : :
1699 : : static void CodeIfSetLessEqu (unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3);
1700 : :
1701 : : /*
1702 : : PerformCodeIfLessEqu - codes the quadruple if op1 <= op2 then goto op3
1703 : : */
1704 : :
1705 : : static void PerformCodeIfLessEqu (unsigned int quad);
1706 : :
1707 : : /*
1708 : : CodeIfLessEqu - codes the quadruple if op1 <= op2 then goto op3
1709 : : */
1710 : :
1711 : : static void CodeIfLessEqu (unsigned int quad);
1712 : :
1713 : : /*
1714 : : CodeIfSetGreEqu -
1715 : : */
1716 : :
1717 : : static void CodeIfSetGreEqu (unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3);
1718 : :
1719 : : /*
1720 : : PerformCodeIfGreEqu - codes the quadruple if op1 >= op2 then goto op3
1721 : : */
1722 : :
1723 : : static void PerformCodeIfGreEqu (unsigned int quad);
1724 : :
1725 : : /*
1726 : : CodeIfGreEqu - codes the quadruple if op1 >= op2 then goto op3
1727 : : */
1728 : :
1729 : : static void CodeIfGreEqu (unsigned int quad);
1730 : :
1731 : : /*
1732 : : CodeIfSetEqu - codes if op1 = op2 then goto op3
1733 : : Note that if op1 and op2 are not both constants
1734 : : since this will have been evaluated in CodeIfEqu.
1735 : : */
1736 : :
1737 : : static void CodeIfSetEqu (unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3);
1738 : :
1739 : : /*
1740 : : CodeIfSetNotEqu - codes if op1 # op2 then goto op3
1741 : : Note that if op1 and op2 are not both constants
1742 : : since this will have been evaluated in CodeIfNotEqu.
1743 : : */
1744 : :
1745 : : static void CodeIfSetNotEqu (unsigned int left, unsigned int right, unsigned int destQuad);
1746 : :
1747 : : /*
1748 : : ComparisonMixTypes -
1749 : : */
1750 : :
1751 : : static unsigned int ComparisonMixTypes (unsigned int varleft, unsigned int varright, unsigned int left, unsigned int right, unsigned int tokpos);
1752 : :
1753 : : /*
1754 : : PerformCodeIfEqu -
1755 : : */
1756 : :
1757 : : static void PerformCodeIfEqu (unsigned int quad);
1758 : :
1759 : : /*
1760 : : PerformCodeIfNotEqu -
1761 : : */
1762 : :
1763 : : static void PerformCodeIfNotEqu (unsigned int quad);
1764 : :
1765 : : /*
1766 : : IsValidExpressionRelOp - declare left and right constants (if they are not already declared).
1767 : : Check whether left and right are expression compatible.
1768 : : */
1769 : :
1770 : : static bool IsValidExpressionRelOp (unsigned int quad, bool isin);
1771 : :
1772 : : /*
1773 : : CodeIfEqu - codes the quadruple if op1 = op2 then goto op3
1774 : : */
1775 : :
1776 : : static void CodeIfEqu (unsigned int quad);
1777 : :
1778 : : /*
1779 : : CodeIfNotEqu - codes the quadruple if op1 # op2 then goto op3
1780 : : */
1781 : :
1782 : : static void CodeIfNotEqu (unsigned int quad);
1783 : :
1784 : : /*
1785 : : MixTypes3 - returns a type compatible from, low, high, var.
1786 : : */
1787 : :
1788 : : static unsigned int MixTypes3 (unsigned int low, unsigned int high, unsigned int var, unsigned int tokenno);
1789 : :
1790 : : /*
1791 : : BuildIfVarInConstValue - if var in constsetvalue then goto trueexit
1792 : : */
1793 : :
1794 : : static void BuildIfVarInConstValue (location_t location, unsigned int tokenno, M2ALU_PtrToValue constsetvalue, unsigned int var, unsigned int trueexit);
1795 : :
1796 : : /*
1797 : : BuildIfNotVarInConstValue - if not (var in constsetvalue) then goto trueexit
1798 : : */
1799 : :
1800 : : static void BuildIfNotVarInConstValue (unsigned int quad, M2ALU_PtrToValue constsetvalue, unsigned int var, unsigned int trueexit);
1801 : :
1802 : : /*
1803 : : PerformCodeIfIn - code the quadruple: if op1 in op2 then goto op3
1804 : : */
1805 : :
1806 : : static void PerformCodeIfIn (unsigned int quad);
1807 : :
1808 : : /*
1809 : : PerformCodeIfNotIn - code the quadruple: if not (op1 in op2) then goto op3
1810 : : */
1811 : :
1812 : : static void PerformCodeIfNotIn (unsigned int quad);
1813 : :
1814 : : /*
1815 : : CodeIfIn - code the quadruple: if op1 in op2 then goto op3
1816 : : */
1817 : :
1818 : : static void CodeIfIn (unsigned int quad);
1819 : :
1820 : : /*
1821 : : CodeIfNotIn - code the quadruple: if not (op1 in op2) then goto op3
1822 : : */
1823 : :
1824 : : static void CodeIfNotIn (unsigned int quad);
1825 : : static void CodeIndrX (unsigned int quad);
1826 : :
1827 : : /*
1828 : : CodeXIndr - operands for XIndrOp are: left type right.
1829 : : *left = right. The second operand is the type of the data being
1830 : : indirectly copied.
1831 : : */
1832 : :
1833 : : static void CodeXIndr (unsigned int quad);
1834 : :
1835 : : /*
1836 : : InitBuiltinSyms -
1837 : : */
1838 : :
1839 : : static void InitBuiltinSyms (unsigned int tok);
1840 : :
1841 : :
1842 : : /*
1843 : : ErrorMessageDecl - emit an error message together with declaration fragments of left
1844 : : and right if they are parameters or variables.
1845 : : */
1846 : :
1847 : 12 : static void ErrorMessageDecl (unsigned int tok, const char *message_, unsigned int _message_high, unsigned int left, unsigned int right, bool iserror)
1848 : : {
1849 : 12 : char message[_message_high+1];
1850 : :
1851 : : /* make a local copy of each unbounded array. */
1852 : 12 : memcpy (message, message_, _message_high+1);
1853 : :
1854 : 12 : M2MetaError_MetaErrorT2 (tok, (const char *) message, _message_high, left, right);
1855 : 12 : M2MetaError_MetaErrorDecl (left, iserror);
1856 : 12 : M2MetaError_MetaErrorDecl (right, iserror);
1857 : 12 : }
1858 : :
1859 : :
1860 : : /*
1861 : : IsExportedGcc - returns TRUE if this symbol should be (as far as the middle/backend of GCC)
1862 : : is concerned, exported.
1863 : : */
1864 : :
1865 : 98814 : static bool IsExportedGcc (unsigned int sym)
1866 : : {
1867 : 98814 : unsigned int scope;
1868 : :
1869 : : /* Has a procedure been overridden as public? */
1870 : 98814 : if ((SymbolTable_IsProcedure (sym)) && (SymbolTable_IsPublic (sym)))
1871 : : {
1872 : : return true;
1873 : : }
1874 : : /* Check for whole program. */
1875 : 52141 : if (M2Options_WholeProgram)
1876 : : {
1877 : 7320 : scope = SymbolTable_GetScope (sym);
1878 : 14640 : while (scope != SymbolTable_NulSym)
1879 : : {
1880 : 7320 : if (SymbolTable_IsDefImp (scope))
1881 : : {
1882 : 7296 : return SymbolTable_IsExported (scope, sym);
1883 : : }
1884 : 24 : else if (SymbolTable_IsModule (scope))
1885 : : {
1886 : : /* avoid dangling else. */
1887 : : return false;
1888 : : }
1889 : 0 : scope = SymbolTable_GetScope (scope);
1890 : : }
1891 : 0 : M2Error_InternalError ((const char *) "expecting scope to eventually reach a module or defimp symbol", 61);
1892 : : }
1893 : : else
1894 : : {
1895 : : /* Otherwise it is public if it were exported. */
1896 : 44821 : return SymbolTable_IsExported (SymbolTable_GetMainModule (), sym);
1897 : : }
1898 : : ReturnException ("/home/worker/buildworker/tiber-lcov/build/gcc/m2/gm2-compiler/M2GenGCC.def", 20, 1);
1899 : : __builtin_unreachable ();
1900 : : }
1901 : :
1902 : :
1903 : : /*
1904 : : IsCompilingMainModule -
1905 : : */
1906 : :
1907 : 159840 : static bool IsCompilingMainModule (unsigned int sym)
1908 : : {
1909 : 263612 : while ((sym != SymbolTable_NulSym) && ((SymbolTable_GetMainModule ()) != sym))
1910 : : {
1911 : 103772 : sym = SymbolTable_GetModuleScope (sym);
1912 : : }
1913 : 159840 : return sym != SymbolTable_NulSym;
1914 : : /* static analysis guarentees a RETURN statement will be used before here. */
1915 : : __builtin_unreachable ();
1916 : : }
1917 : :
1918 : :
1919 : : /*
1920 : : CodeLastForIterator - call PerformLastForIterator allowing for
1921 : : a non constant last iterator value.
1922 : : */
1923 : :
1924 : 536 : static void CodeLastForIterator (unsigned int quad)
1925 : : {
1926 : 0 : PerformLastForIterator (quad, (M2GCCDeclare_WalkAction) {(M2GCCDeclare_WalkAction_t) NoWalkProcedure}, false);
1927 : 536 : }
1928 : :
1929 : :
1930 : : /*
1931 : : FoldLastForIterator - call PerformLastForIterator providing
1932 : : all operands are constant and are known by GCC.
1933 : : */
1934 : :
1935 : 12006 : static void FoldLastForIterator (unsigned int quad, M2GCCDeclare_WalkAction p)
1936 : : {
1937 : 12006 : M2Quads_QuadOperator op;
1938 : 12006 : unsigned int e1;
1939 : 12006 : unsigned int e2;
1940 : 12006 : unsigned int op1;
1941 : 12006 : unsigned int tuple;
1942 : 12006 : unsigned int incr;
1943 : :
1944 : 12006 : M2Quads_GetQuad (quad, &op, &op1, &tuple, &incr);
1945 : 12006 : M2Debug_Assert (SymbolTable_IsTuple (tuple));
1946 : 12006 : e1 = SymbolTable_GetNth (tuple, 1);
1947 : 12006 : e2 = SymbolTable_GetNth (tuple, 2);
1948 : 12006 : if (((((((SymbolTable_IsConst (op1)) && (SymbolTable_IsConst (e1))) && (SymbolTable_IsConst (e2))) && (SymbolTable_IsConst (incr))) && (SymbolConversion_GccKnowsAbout (e1))) && (SymbolConversion_GccKnowsAbout (e2))) && (SymbolConversion_GccKnowsAbout (incr)))
1949 : : {
1950 : 1526 : PerformLastForIterator (quad, p, true);
1951 : : }
1952 : 12006 : }
1953 : :
1954 : 2062 : static void PerformLastForIterator (unsigned int quad, M2GCCDeclare_WalkAction p, bool constant)
1955 : : {
1956 : 2062 : bool success;
1957 : 2062 : bool constExpr;
1958 : 2062 : bool overflowChecking;
1959 : 2062 : M2Quads_QuadOperator op;
1960 : 2062 : unsigned int lastpos;
1961 : 2062 : unsigned int op1pos;
1962 : 2062 : unsigned int op2pos;
1963 : 2062 : unsigned int incrpos;
1964 : 2062 : unsigned int last;
1965 : 2062 : unsigned int tuple;
1966 : 2062 : unsigned int incr;
1967 : 2062 : unsigned int e1;
1968 : 2062 : unsigned int e2;
1969 : 2062 : tree lasttree;
1970 : 2062 : tree e1tree;
1971 : 2062 : tree e2tree;
1972 : 2062 : tree expr;
1973 : 2062 : tree incrtree;
1974 : 2062 : location_t location;
1975 : :
1976 : : /*
1977 : : FoldLastForIterator - generates code to calculate the last iterator value
1978 : : in a for loop. It examines the increment constant
1979 : : and generates different code depending whether it is
1980 : : negative or positive.
1981 : : */
1982 : 2062 : M2Quads_GetQuadOtok (quad, &lastpos, &op, &last, &tuple, &incr, &overflowChecking, &constExpr, &op1pos, &op2pos, &incrpos);
1983 : 2062 : M2GCCDeclare_DeclareConstant (incrpos, incr);
1984 : 2062 : lasttree = SymbolConversion_Mod2Gcc (last);
1985 : 2062 : success = true;
1986 : 2062 : if (SymbolTable_IsConst (incr))
1987 : : {
1988 : : /* avoid dangling else. */
1989 : 2062 : incrtree = SymbolConversion_Mod2Gcc (incr);
1990 : 2062 : location = M2LexBuf_TokenToLocation (lastpos);
1991 : 2062 : e1 = SymbolTable_GetNth (tuple, 1);
1992 : 2062 : e2 = SymbolTable_GetNth (tuple, 2);
1993 : 2062 : e1tree = SymbolConversion_Mod2Gcc (e1);
1994 : 2062 : e2tree = SymbolConversion_Mod2Gcc (e2);
1995 : 2062 : if ((m2expr_CompareTrees (incrtree, m2expr_GetIntegerZero (location))) == 0)
1996 : : {
1997 : 6 : M2MetaError_MetaErrorT0 (lastpos, (const char *) "the {%kFOR} loop step value must not be zero", 44);
1998 : 6 : M2MetaError_MetaErrorDecl (incr, true);
1999 : 6 : NoChange = false;
2000 : 6 : M2Quads_SubQuad (quad);
2001 : 6 : success = false;
2002 : : }
2003 : 2056 : else if ((m2expr_CompareTrees (incrtree, m2expr_GetIntegerZero (location))) > 0)
2004 : : {
2005 : : /* avoid dangling else. */
2006 : : /* If incr > 0 then LastIterator := ((e2-e1) DIV incr) * incr + e1. */
2007 : 1846 : expr = m2expr_BuildSub (location, e2tree, e1tree, false);
2008 : 1846 : incrtree = m2convert_BuildConvert (location, m2type_GetTreeType (expr), incrtree, false);
2009 : 1846 : if (m2expr_TreeOverflow (incrtree))
2010 : : {
2011 : 0 : M2MetaError_MetaErrorT0 (lastpos, (const char *) "the intemediate calculation for the last iterator value in the {%kFOR} loop has caused an overflow", 98);
2012 : 0 : NoChange = false;
2013 : 0 : M2Quads_SubQuad (quad);
2014 : 0 : success = false;
2015 : : }
2016 : : else
2017 : : {
2018 : 1846 : expr = m2expr_BuildDivFloor (location, expr, incrtree, false);
2019 : 1846 : expr = m2expr_BuildMult (location, expr, incrtree, false);
2020 : 1846 : expr = m2expr_BuildAdd (location, expr, e1tree, false);
2021 : : }
2022 : : }
2023 : : else
2024 : : {
2025 : : /* avoid dangling else. */
2026 : : /* Else use LastIterator := e1 - ((e1-e2) DIV PositiveBy) * PositiveBy
2027 : : to avoid unsigned div signed arithmetic. */
2028 : 210 : expr = m2expr_BuildSub (location, e1tree, e2tree, false);
2029 : 210 : incrtree = m2convert_BuildConvert (location, m2type_GetM2ZType (), incrtree, false);
2030 : 210 : incrtree = m2expr_BuildNegate (location, incrtree, false);
2031 : 210 : incrtree = m2convert_BuildConvert (location, m2type_GetTreeType (expr), incrtree, false);
2032 : 210 : if (m2expr_TreeOverflow (incrtree))
2033 : : {
2034 : 0 : M2MetaError_MetaErrorT0 (lastpos, (const char *) "the intemediate calculation for the last iterator value in the {%kFOR} loop has caused an overflow", 98);
2035 : 0 : NoChange = false;
2036 : 0 : M2Quads_SubQuad (quad);
2037 : 0 : success = false;
2038 : : }
2039 : : else
2040 : : {
2041 : 210 : expr = m2expr_BuildSub (location, e1tree, e2tree, false);
2042 : 210 : expr = m2expr_BuildDivFloor (location, expr, incrtree, false);
2043 : 210 : expr = m2expr_BuildMult (location, expr, incrtree, false);
2044 : 210 : expr = m2expr_BuildSub (location, e1tree, expr, false);
2045 : : }
2046 : : }
2047 : 2062 : if (success)
2048 : : {
2049 : : /* avoid gcc warning by using compound statement even if not strictly necessary. */
2050 : 2056 : if (SymbolTable_IsConst (last))
2051 : : {
2052 : 1520 : SymbolConversion_AddModGcc (last, expr);
2053 : 1520 : (*p.proc) (last);
2054 : 1520 : NoChange = false;
2055 : 1520 : M2Quads_SubQuad (quad);
2056 : : }
2057 : : else
2058 : : {
2059 : 536 : M2Debug_Assert (! constant);
2060 : 536 : m2statement_BuildAssignmentStatement (location, lasttree, expr);
2061 : : }
2062 : : }
2063 : : }
2064 : : else
2065 : : {
2066 : 0 : M2MetaError_MetaErrorT1 (lastpos, (const char *) "the value {%1Ead} in the {%kBY} clause of the {%kFOR} loop must be constant", 75, incr);
2067 : 0 : M2MetaError_MetaErrorDecl (incr, true);
2068 : 0 : NoChange = false;
2069 : 0 : M2Quads_SubQuad (quad);
2070 : : }
2071 : 2062 : }
2072 : :
2073 : :
2074 : : /*
2075 : : CodeStatement - A multi-way decision call depending on the current
2076 : : quadruple.
2077 : : */
2078 : :
2079 : 3604464 : static void CodeStatement (unsigned int q)
2080 : : {
2081 : 3604464 : M2Quads_QuadOperator op;
2082 : 3604464 : unsigned int op1;
2083 : 3604464 : unsigned int op2;
2084 : 3604464 : unsigned int op3;
2085 : 3604464 : location_t location;
2086 : :
2087 : 3604464 : InitBuiltinSyms (M2LexBuf_BuiltinTokenNo);
2088 : 3604464 : M2Quads_GetQuad (q, &op, &op1, &op2, &op3);
2089 : 3604464 : if (op == M2Quads_StatementNoteOp)
2090 : : {
2091 : 418372 : FoldStatementNote (op3); /* Will change CurrentQuadToken using op3. */
2092 : : }
2093 : : else
2094 : : {
2095 : 3186092 : CurrentQuadToken = M2Quads_QuadToTokenNo (q);
2096 : : }
2097 : 3604464 : location = M2LexBuf_TokenToLocation (CurrentQuadToken);
2098 : 3604464 : CheckReferenced (q, op);
2099 : 3604464 : if (M2Options_GetDebugTraceQuad ())
2100 : : {
2101 : 0 : M2Printf_printf0 ((const char *) "building: ", 10);
2102 : 0 : M2Quads_DisplayQuad (q);
2103 : : }
2104 : 3604464 : switch (op)
2105 : : {
2106 : 117423 : case M2Quads_StartDefFileOp:
2107 : 117423 : CodeStartDefFile (op3);
2108 : 117423 : break;
2109 : :
2110 : 64661 : case M2Quads_StartModFileOp:
2111 : 64661 : CodeStartModFile (op3);
2112 : 64661 : break;
2113 : :
2114 : 65069 : case M2Quads_ModuleScopeOp:
2115 : 65069 : CodeModuleScope (op3);
2116 : 65069 : break;
2117 : :
2118 : 182084 : case M2Quads_EndFileOp:
2119 : 182084 : CodeEndFile ();
2120 : 182084 : break;
2121 : :
2122 : 65069 : case M2Quads_InitStartOp:
2123 : 65069 : CodeInitStart (op3, IsCompilingMainModule (op3));
2124 : 65069 : break;
2125 : :
2126 : 65069 : case M2Quads_InitEndOp:
2127 : 65069 : CodeInitEnd (op3, IsCompilingMainModule (op3));
2128 : 65069 : break;
2129 : :
2130 : 14851 : case M2Quads_FinallyStartOp:
2131 : 14851 : CodeFinallyStart (op3, IsCompilingMainModule (op3));
2132 : 14851 : break;
2133 : :
2134 : 14851 : case M2Quads_FinallyEndOp:
2135 : 14851 : CodeFinallyEnd (op3, IsCompilingMainModule (op3));
2136 : 14851 : break;
2137 : :
2138 : 69106 : case M2Quads_NewLocalVarOp:
2139 : 69106 : CodeNewLocalVar (op1, op3);
2140 : 69106 : break;
2141 : :
2142 : 69100 : case M2Quads_KillLocalVarOp:
2143 : 69100 : CodeKillLocalVar (op3);
2144 : 69100 : break;
2145 : :
2146 : 69112 : case M2Quads_ProcedureScopeOp:
2147 : 69112 : CodeProcedureScope (op3);
2148 : 69112 : break;
2149 : :
2150 : : case M2Quads_ReturnOp:
2151 : : break;
2152 : :
2153 : 18881 : case M2Quads_ReturnValueOp:
2154 : 18881 : CodeReturnValue (q); /* Not used as return is achieved by KillLocalVar. */
2155 : 18881 : break;
2156 : :
2157 : 2806 : case M2Quads_TryOp:
2158 : 2806 : CodeTry ();
2159 : 2806 : break;
2160 : :
2161 : 322 : case M2Quads_ThrowOp:
2162 : 322 : CodeThrow (op3);
2163 : 322 : break;
2164 : :
2165 : 2806 : case M2Quads_CatchBeginOp:
2166 : 2806 : CodeCatchBegin ();
2167 : 2806 : break;
2168 : :
2169 : 2806 : case M2Quads_CatchEndOp:
2170 : 2806 : CodeCatchEnd ();
2171 : 2806 : break;
2172 : :
2173 : 156 : case M2Quads_RetryOp:
2174 : 156 : CodeRetry (op3);
2175 : 156 : break;
2176 : :
2177 : : case M2Quads_DummyOp:
2178 : : break;
2179 : :
2180 : 54 : case M2Quads_InitAddressOp:
2181 : 54 : CodeInitAddress (q, op1, op2, op3);
2182 : 54 : break;
2183 : :
2184 : 166809 : case M2Quads_BecomesOp:
2185 : 166809 : CodeBecomes (q);
2186 : 166809 : break;
2187 : :
2188 : 29012 : case M2Quads_ArithAddOp:
2189 : 29012 : case M2Quads_AddOp:
2190 : 29012 : CodeAddChecked (q, op2, op3);
2191 : 29012 : break;
2192 : :
2193 : 8516 : case M2Quads_SubOp:
2194 : 8516 : CodeSubChecked (q, op2, op3);
2195 : 8516 : break;
2196 : :
2197 : 10054 : case M2Quads_MultOp:
2198 : 10054 : CodeMultChecked (q, op2, op3);
2199 : 10054 : break;
2200 : :
2201 : 1702 : case M2Quads_DivM2Op:
2202 : 1702 : CodeDivM2Checked (q, op2, op3);
2203 : 1702 : break;
2204 : :
2205 : 1828 : case M2Quads_ModM2Op:
2206 : 1828 : CodeModM2Checked (q, op2, op3);
2207 : 1828 : break;
2208 : :
2209 : 430 : case M2Quads_DivTruncOp:
2210 : 430 : CodeDivTrunc (q, op2, op3);
2211 : 430 : break;
2212 : :
2213 : 0 : case M2Quads_ModTruncOp:
2214 : 0 : CodeModTrunc (q, op2, op3);
2215 : 0 : break;
2216 : :
2217 : 0 : case M2Quads_DivCeilOp:
2218 : 0 : CodeDivCeil (q, op2, op3);
2219 : 0 : break;
2220 : :
2221 : 0 : case M2Quads_ModCeilOp:
2222 : 0 : CodeModCeil (q, op2, op3);
2223 : 0 : break;
2224 : :
2225 : 0 : case M2Quads_DivFloorOp:
2226 : 0 : CodeDivFloor (q, op2, op3);
2227 : 0 : break;
2228 : :
2229 : 0 : case M2Quads_ModFloorOp:
2230 : 0 : CodeModFloor (q, op2, op3);
2231 : 0 : break;
2232 : :
2233 : 37737 : case M2Quads_GotoOp:
2234 : 37737 : CodeGoto (op3);
2235 : 37737 : break;
2236 : :
2237 : 782 : case M2Quads_InclOp:
2238 : 782 : CodeIncl (op1, op3);
2239 : 782 : break;
2240 : :
2241 : 444 : case M2Quads_ExclOp:
2242 : 444 : CodeExcl (op1, op3);
2243 : 444 : break;
2244 : :
2245 : 834 : case M2Quads_NegateOp:
2246 : 834 : CodeNegateChecked (q, op1, op3);
2247 : 834 : break;
2248 : :
2249 : 536 : case M2Quads_LastForIteratorOp:
2250 : 536 : CodeLastForIterator (q);
2251 : 536 : break;
2252 : :
2253 : 696 : case M2Quads_LogicalShiftOp:
2254 : 696 : CodeSetShift (q, op1, op2, op3);
2255 : 696 : break;
2256 : :
2257 : 382 : case M2Quads_LogicalRotateOp:
2258 : 382 : CodeSetRotate (q, op1, op2, op3);
2259 : 382 : break;
2260 : :
2261 : 818 : case M2Quads_LogicalOrOp:
2262 : 818 : CodeSetOr (q);
2263 : 818 : break;
2264 : :
2265 : 60 : case M2Quads_LogicalAndOp:
2266 : 60 : CodeSetAnd (q);
2267 : 60 : break;
2268 : :
2269 : 12 : case M2Quads_LogicalXorOp:
2270 : 12 : CodeSetSymmetricDifference (q);
2271 : 12 : break;
2272 : :
2273 : 66 : case M2Quads_LogicalDiffOp:
2274 : 66 : CodeSetLogicalDifference (q);
2275 : 66 : break;
2276 : :
2277 : 3152 : case M2Quads_IfLessOp:
2278 : 3152 : CodeIfLess (q);
2279 : 3152 : break;
2280 : :
2281 : 18474 : case M2Quads_IfEquOp:
2282 : 18474 : CodeIfEqu (q);
2283 : 18474 : break;
2284 : :
2285 : 28447 : case M2Quads_IfNotEquOp:
2286 : 28447 : CodeIfNotEqu (q);
2287 : 28447 : break;
2288 : :
2289 : 5164 : case M2Quads_IfGreEquOp:
2290 : 5164 : CodeIfGreEqu (q);
2291 : 5164 : break;
2292 : :
2293 : 4950 : case M2Quads_IfLessEquOp:
2294 : 4950 : CodeIfLessEqu (q);
2295 : 4950 : break;
2296 : :
2297 : 4122 : case M2Quads_IfGreOp:
2298 : 4122 : CodeIfGre (q);
2299 : 4122 : break;
2300 : :
2301 : 372 : case M2Quads_IfInOp:
2302 : 372 : CodeIfIn (q);
2303 : 372 : break;
2304 : :
2305 : 1166 : case M2Quads_IfNotInOp:
2306 : 1166 : CodeIfNotIn (q);
2307 : 1166 : break;
2308 : :
2309 : 14499 : case M2Quads_IndrXOp:
2310 : 14499 : CodeIndrX (q);
2311 : 14499 : break;
2312 : :
2313 : 36300 : case M2Quads_XIndrOp:
2314 : 36300 : CodeXIndr (q);
2315 : 36300 : break;
2316 : :
2317 : 182906 : case M2Quads_CallOp:
2318 : 182906 : CodeCall (CurrentQuadToken, op3);
2319 : 182906 : break;
2320 : :
2321 : 521543 : case M2Quads_ParamOp:
2322 : 521543 : CodeParam (q);
2323 : 521543 : break;
2324 : :
2325 : 46853 : case M2Quads_FunctValueOp:
2326 : 46853 : CodeFunctValue (location, op1);
2327 : 46853 : break;
2328 : :
2329 : 179409 : case M2Quads_AddrOp:
2330 : 179409 : CodeAddr (CurrentQuadToken, q, op1, op3);
2331 : 179409 : break;
2332 : :
2333 : 0 : case M2Quads_SizeOp:
2334 : 0 : CodeSize (op1, op3);
2335 : 0 : break;
2336 : :
2337 : 31329 : case M2Quads_UnboundedOp:
2338 : 31329 : CodeUnbounded (op1, op3);
2339 : 31329 : break;
2340 : :
2341 : 125282 : case M2Quads_RecordFieldOp:
2342 : 125282 : CodeRecordField (op1, op2, op3);
2343 : 125282 : break;
2344 : :
2345 : 36147 : case M2Quads_HighOp:
2346 : 36147 : CodeHigh (op1, op2, op3);
2347 : 36147 : break;
2348 : :
2349 : 40896 : case M2Quads_ArrayOp:
2350 : 40896 : CodeArray (op1, op2, op3);
2351 : 40896 : break;
2352 : :
2353 : 0 : case M2Quads_ElementSizeOp:
2354 : 0 : M2Error_InternalError ((const char *) "ElementSizeOp is expected to have been folded via constant evaluation", 69);
2355 : 41576 : break;
2356 : :
2357 : 41576 : case M2Quads_ConvertOp:
2358 : 41576 : CodeConvert (q, op1, op2, op3);
2359 : 41576 : break;
2360 : :
2361 : 448 : case M2Quads_CoerceOp:
2362 : 448 : CodeCoerce (q, op1, op2, op3);
2363 : 448 : break;
2364 : :
2365 : 126 : case M2Quads_CastOp:
2366 : 126 : CodeCast (q, op1, op2, op3);
2367 : 126 : break;
2368 : :
2369 : 282 : case M2Quads_StandardFunctionOp:
2370 : 282 : CodeStandardFunction (q, op1, op2, op3);
2371 : 282 : break;
2372 : :
2373 : 420 : case M2Quads_SavePriorityOp:
2374 : 420 : CodeSavePriority (op1, op2, op3);
2375 : 420 : break;
2376 : :
2377 : 412 : case M2Quads_RestorePriorityOp:
2378 : 412 : CodeRestorePriority (op1, op2, op3);
2379 : 412 : break;
2380 : :
2381 : 27 : case M2Quads_InlineOp:
2382 : 27 : CodeInline (q);
2383 : 27 : break;
2384 : :
2385 : 418372 : case M2Quads_StatementNoteOp:
2386 : 418372 : CodeStatementNote (op3);
2387 : 418372 : break;
2388 : :
2389 : : case M2Quads_CodeOnOp:
2390 : : break;
2391 : :
2392 : : case M2Quads_CodeOffOp:
2393 : : break;
2394 : :
2395 : : case M2Quads_ProfileOnOp:
2396 : : break;
2397 : :
2398 : : case M2Quads_ProfileOffOp:
2399 : : break;
2400 : :
2401 : : case M2Quads_OptimizeOnOp:
2402 : : break;
2403 : :
2404 : : case M2Quads_OptimizeOffOp:
2405 : : break;
2406 : :
2407 : 700685 : case M2Quads_RangeCheckOp:
2408 : 700685 : CodeRange (op3); /* The following make no sense with gcc. */
2409 : 700685 : break;
2410 : :
2411 : 825 : case M2Quads_ErrorOp:
2412 : 825 : CodeError (op3);
2413 : 825 : break;
2414 : :
2415 : 2806 : case M2Quads_SaveExceptionOp:
2416 : 2806 : CodeSaveException (op1, op3);
2417 : 2806 : break;
2418 : :
2419 : 2746 : case M2Quads_RestoreExceptionOp:
2420 : 2746 : CodeRestoreException (op1, op3);
2421 : 2746 : break;
2422 : :
2423 : :
2424 : 0 : default:
2425 : 0 : M2Error_WriteFormat1 ((const char *) "quadruple %d not yet implemented", 32, (const unsigned char *) &q, (sizeof (q)-1));
2426 : 0 : M2Error_InternalError ((const char *) "quadruple not implemented yet", 29);
2427 : 3604452 : break;
2428 : : }
2429 : 3604452 : LastOperator = op;
2430 : 3604452 : }
2431 : :
2432 : :
2433 : : /*
2434 : : FindSize - given a Modula-2 symbol sym return a gcc tree
2435 : : constant representing the storage size in bytes.
2436 : : */
2437 : :
2438 : 26294 : static tree FindSize (unsigned int tokenno, unsigned int sym)
2439 : : {
2440 : 26294 : location_t location;
2441 : :
2442 : 26294 : location = M2LexBuf_TokenToLocation (tokenno);
2443 : 26294 : if (SymbolTable_IsConstString (sym))
2444 : : {
2445 : 6408 : M2Debug_Assert (SymbolTable_IsConstStringKnown (sym));
2446 : 6408 : M2ALU_PushCard (SymbolTable_GetStringLength (tokenno, sym));
2447 : 6408 : return M2ALU_PopIntegerTree ();
2448 : : }
2449 : 19886 : else if (SymbolTable_IsSizeSolved (sym))
2450 : : {
2451 : : /* avoid dangling else. */
2452 : 17722 : SymbolTable_PushSize (sym);
2453 : 17722 : return M2ALU_PopIntegerTree ();
2454 : : }
2455 : : else
2456 : : {
2457 : : /* avoid dangling else. */
2458 : 2164 : if (SymbolConversion_GccKnowsAbout (sym))
2459 : : {
2460 : 2164 : if ((SymbolTable_IsVar (sym)) && (SymbolTable_IsVariableSSA (sym)))
2461 : : {
2462 : 0 : sym = SymbolTable_GetType (sym);
2463 : : }
2464 : 2164 : M2ALU_PushIntegerTree (m2expr_BuildSize (location, SymbolConversion_Mod2Gcc (sym), false));
2465 : 2164 : SymbolTable_PopSize (sym);
2466 : 2164 : SymbolTable_PushSize (sym);
2467 : 2164 : return M2ALU_PopIntegerTree ();
2468 : : }
2469 : 0 : else if ((SymbolTable_IsVar (sym)) && (SymbolConversion_GccKnowsAbout (SymbolTable_GetType (sym))))
2470 : : {
2471 : : /* avoid dangling else. */
2472 : 0 : M2ALU_PushIntegerTree (m2expr_BuildSize (location, SymbolConversion_Mod2Gcc (SymbolTable_GetType (sym)), false));
2473 : 0 : return M2ALU_PopIntegerTree ();
2474 : : }
2475 : : else
2476 : : {
2477 : : /* avoid dangling else. */
2478 : 0 : M2Error_InternalError ((const char *) "expecting gcc to already know about this symbol", 47);
2479 : : }
2480 : : }
2481 : : ReturnException ("/home/worker/buildworker/tiber-lcov/build/gcc/m2/gm2-compiler/M2GenGCC.def", 20, 1);
2482 : : __builtin_unreachable ();
2483 : : }
2484 : :
2485 : :
2486 : : /*
2487 : : FindType - returns the type of, Sym, if Sym is a TYPE then return Sym otherwise return GetType(Sym)
2488 : : */
2489 : :
2490 : 172938 : static unsigned int FindType (unsigned int Sym)
2491 : : {
2492 : 172938 : if (SymbolTable_IsType (Sym))
2493 : : {
2494 : : return Sym;
2495 : : }
2496 : : else
2497 : : {
2498 : 172938 : return SymbolTable_GetType (Sym);
2499 : : }
2500 : : /* static analysis guarentees a RETURN statement will be used before here. */
2501 : : __builtin_unreachable ();
2502 : : }
2503 : :
2504 : :
2505 : : /*
2506 : : BuildTreeFromInterface - generates a GCC tree from an interface definition.
2507 : : */
2508 : :
2509 : 54 : static tree BuildTreeFromInterface (unsigned int sym)
2510 : : {
2511 : 54 : unsigned int tok;
2512 : 54 : unsigned int i;
2513 : 54 : NameKey_Name name;
2514 : 54 : unsigned int str;
2515 : 54 : unsigned int obj;
2516 : 54 : tree gccName;
2517 : 54 : tree asmTree;
2518 : :
2519 : 54 : asmTree = (tree) (NULL);
2520 : 54 : if (sym != SymbolTable_NulSym)
2521 : : {
2522 : : i = 1;
2523 : 63 : do {
2524 : 63 : SymbolTable_GetRegInterface (sym, i, &tok, &name, &str, &obj);
2525 : 63 : if (str != SymbolTable_NulSym)
2526 : : {
2527 : : /* avoid gcc warning by using compound statement even if not strictly necessary. */
2528 : 33 : if (SymbolTable_IsConstString (str))
2529 : : {
2530 : : /* avoid dangling else. */
2531 : 33 : M2GCCDeclare_DeclareConstant (tok, obj);
2532 : 33 : if (name == NameKey_NulName)
2533 : : {
2534 : : gccName = NULL;
2535 : : }
2536 : : else
2537 : : {
2538 : 6 : gccName = m2decl_BuildCStringConstant (const_cast <const char * > (static_cast <char * > (NameKey_KeyToCharStar (name))), static_cast<int> (NameKey_LengthKey (name)));
2539 : : }
2540 : 33 : asmTree = m2type_ChainOnParamValue (asmTree, gccName, M2GCCDeclare_PromoteToCString (tok, str), m2tree_skip_const_decl (SymbolConversion_Mod2Gcc (obj)));
2541 : 33 : if (DebugTokPos)
2542 : : {
2543 : : M2Error_WarnStringAt (DynamicStrings_InitString ((const char *) "input expression", 16), tok);
2544 : : }
2545 : : }
2546 : : else
2547 : : {
2548 : 0 : M2MetaError_MetaErrorT1 (tok, (const char *) "a constraint to the GNU ASM statement must be a constant string and not a {%1Ed}", 80, str);
2549 : : }
2550 : : }
2551 : 63 : i += 1;
2552 : 63 : } while (! ((str == SymbolTable_NulSym) && (obj == SymbolTable_NulSym)));
2553 : : }
2554 : 54 : return asmTree;
2555 : : /* static analysis guarentees a RETURN statement will be used before here. */
2556 : : __builtin_unreachable ();
2557 : : }
2558 : :
2559 : :
2560 : : /*
2561 : : BuildTrashTreeFromInterface - generates a GCC string tree from an interface definition.
2562 : : */
2563 : :
2564 : 27 : static tree BuildTrashTreeFromInterface (unsigned int sym)
2565 : : {
2566 : 27 : unsigned int tok;
2567 : 27 : unsigned int i;
2568 : 27 : unsigned int str;
2569 : 27 : unsigned int obj;
2570 : 27 : NameKey_Name name;
2571 : 27 : tree asmTree;
2572 : :
2573 : 27 : asmTree = (tree) (NULL);
2574 : 27 : if (sym != SymbolTable_NulSym)
2575 : : {
2576 : : i = 1;
2577 : 6 : do {
2578 : 6 : SymbolTable_GetRegInterface (sym, i, &tok, &name, &str, &obj);
2579 : 6 : if (str != SymbolTable_NulSym)
2580 : : {
2581 : : /* avoid gcc warning by using compound statement even if not strictly necessary. */
2582 : 0 : if (SymbolTable_IsConstString (str))
2583 : : {
2584 : : /* avoid dangling else. */
2585 : 0 : asmTree = m2type_AddStringToTreeList (asmTree, M2GCCDeclare_PromoteToCString (tok, str));
2586 : 0 : if (DebugTokPos)
2587 : : {
2588 : : M2Error_WarnStringAt (DynamicStrings_InitString ((const char *) "trash expression", 16), tok);
2589 : : }
2590 : : }
2591 : : else
2592 : : {
2593 : 0 : M2MetaError_MetaErrorT1 (tok, (const char *) "a constraint to the GNU ASM statement must be a constant string and not a {%1Ed}", 80, str);
2594 : : }
2595 : : }
2596 : 6 : i += 1;
2597 : 6 : } while (! ((str == SymbolTable_NulSym) && (obj == SymbolTable_NulSym)));
2598 : : }
2599 : 27 : return asmTree;
2600 : : /* static analysis guarentees a RETURN statement will be used before here. */
2601 : : __builtin_unreachable ();
2602 : : }
2603 : :
2604 : :
2605 : : /*
2606 : : CodeInline - InlineOp is a quadruple which has the following format:
2607 : :
2608 : : InlineOp NulSym NulSym Sym
2609 : : */
2610 : :
2611 : 27 : static void CodeInline (unsigned int quad)
2612 : : {
2613 : 27 : bool constExpr;
2614 : 27 : bool overflowChecking;
2615 : 27 : M2Quads_QuadOperator op;
2616 : 27 : unsigned int op1;
2617 : 27 : unsigned int op2;
2618 : 27 : unsigned int GnuAsm;
2619 : 27 : unsigned int op1pos;
2620 : 27 : unsigned int op2pos;
2621 : 27 : unsigned int op3pos;
2622 : 27 : unsigned int asmpos;
2623 : 27 : unsigned int string;
2624 : 27 : tree inputs;
2625 : 27 : tree outputs;
2626 : 27 : tree trash;
2627 : 27 : tree labels;
2628 : 27 : location_t location;
2629 : :
2630 : 27 : M2Quads_GetQuadOtok (quad, &asmpos, &op, &op1, &op2, &GnuAsm, &overflowChecking, &constExpr, &op1pos, &op2pos, &op3pos);
2631 : 27 : location = M2LexBuf_TokenToLocation (asmpos);
2632 : 27 : inputs = BuildTreeFromInterface (SymbolTable_GetGnuAsmInput (GnuAsm));
2633 : 27 : outputs = BuildTreeFromInterface (SymbolTable_GetGnuAsmOutput (GnuAsm));
2634 : 27 : trash = BuildTrashTreeFromInterface (SymbolTable_GetGnuAsmTrash (GnuAsm));
2635 : 27 : labels = NULL; /* At present it makes no sence for Modula-2 to jump to a label,
2636 : : given that labels are not allowed in Modula-2. */
2637 : 27 : string = SymbolTable_GetGnuAsm (GnuAsm); /* At present it makes no sence for Modula-2 to jump to a label,
2638 : : given that labels are not allowed in Modula-2. */
2639 : 27 : m2statement_BuildAsm (location, M2GCCDeclare_PromoteToCString (SymbolTable_GetDeclaredMod (string), string), SymbolTable_IsGnuAsmVolatile (GnuAsm), SymbolTable_IsGnuAsmSimple (GnuAsm), inputs, outputs, trash, labels);
2640 : 27 : }
2641 : :
2642 : :
2643 : : /*
2644 : : FoldStatementNote - set CurrentQuadToken to tokennno.
2645 : : */
2646 : :
2647 : 7252434 : static void FoldStatementNote (unsigned int tokenno)
2648 : : {
2649 : 7252434 : CurrentQuadToken = tokenno;
2650 : 418372 : }
2651 : :
2652 : :
2653 : : /*
2654 : : CodeStatementNote - set CurrentQuadToken to tokennno and
2655 : : add a statement note.
2656 : : */
2657 : :
2658 : 418372 : static void CodeStatementNote (unsigned int tokenno)
2659 : : {
2660 : 418372 : if (Debugging)
2661 : : {
2662 : : M2MetaError_MetaErrorT0 (tokenno, (const char *) "{%W} statement note", 19);
2663 : : }
2664 : 418372 : CurrentQuadToken = tokenno;
2665 : 418372 : m2block_addStmtNote (M2LexBuf_TokenToLocation (tokenno));
2666 : 418372 : }
2667 : :
2668 : :
2669 : : /*
2670 : : FoldRange - attempts to fold the range test.
2671 : : --fixme-- complete this.
2672 : : */
2673 : :
2674 : 11136235 : static void FoldRange (unsigned int tokenno, unsigned int quad, unsigned int rangeno)
2675 : : {
2676 : 0 : M2Range_FoldRangeCheck (tokenno, quad, rangeno); /* p: WalkAction; */
2677 : 11136073 : }
2678 : :
2679 : :
2680 : : /*
2681 : : CodeSaveException - op1 := op3(TRUE)
2682 : : */
2683 : :
2684 : 2806 : static void CodeSaveException (unsigned int des, unsigned int exceptionProcedure)
2685 : : {
2686 : 2806 : tree functValue;
2687 : 2806 : location_t location;
2688 : :
2689 : 2806 : location = M2LexBuf_TokenToLocation (CurrentQuadToken);
2690 : 2806 : m2statement_BuildParam (location, SymbolConversion_Mod2Gcc (M2Base_True));
2691 : 2806 : m2statement_BuildFunctionCallTree (location, SymbolConversion_Mod2Gcc (exceptionProcedure), SymbolConversion_Mod2Gcc (SymbolTable_GetType (exceptionProcedure)));
2692 : 2806 : functValue = m2statement_BuildFunctValue (location, SymbolConversion_Mod2Gcc (des));
2693 : 2806 : m2type_AddStatement (location, functValue);
2694 : 2806 : }
2695 : :
2696 : :
2697 : : /*
2698 : : CodeRestoreException - op1 := op3(op1).
2699 : : */
2700 : :
2701 : 2746 : static void CodeRestoreException (unsigned int des, unsigned int exceptionProcedure)
2702 : : {
2703 : 2746 : tree functValue;
2704 : 2746 : location_t location;
2705 : :
2706 : 2746 : location = M2LexBuf_TokenToLocation (CurrentQuadToken);
2707 : 2746 : m2statement_BuildParam (location, SymbolConversion_Mod2Gcc (des));
2708 : 2746 : m2statement_BuildFunctionCallTree (location, SymbolConversion_Mod2Gcc (exceptionProcedure), SymbolConversion_Mod2Gcc (SymbolTable_GetType (exceptionProcedure)));
2709 : 2746 : functValue = m2statement_BuildFunctValue (location, SymbolConversion_Mod2Gcc (des));
2710 : 2746 : m2type_AddStatement (location, functValue);
2711 : 2746 : }
2712 : :
2713 : :
2714 : : /*
2715 : : PushScope -
2716 : : */
2717 : :
2718 : 316259 : static void PushScope (unsigned int sym)
2719 : : {
2720 : 0 : M2StackWord_PushWord (ScopeStack, sym);
2721 : 0 : }
2722 : :
2723 : :
2724 : : /*
2725 : : PopScope -
2726 : : */
2727 : :
2728 : 69100 : static void PopScope (void)
2729 : : {
2730 : 69100 : unsigned int sym;
2731 : :
2732 : 69100 : sym = static_cast<unsigned int> (M2StackWord_PopWord (ScopeStack));
2733 : 69100 : M2Debug_Assert (sym != SymbolTable_NulSym);
2734 : 69100 : }
2735 : :
2736 : :
2737 : : /*
2738 : : GetCurrentScopeDescription - returns a description of the current scope.
2739 : : */
2740 : :
2741 : 701510 : static DynamicStrings_String GetCurrentScopeDescription (void)
2742 : : {
2743 : 701510 : unsigned int sym;
2744 : 701510 : DynamicStrings_String n;
2745 : :
2746 : 701510 : if (M2StackWord_IsEmptyWord (ScopeStack))
2747 : : {
2748 : 0 : M2Error_InternalError ((const char *) "not expecting scope stack to be empty", 37);
2749 : : }
2750 : : else
2751 : : {
2752 : 701510 : sym = static_cast<unsigned int> (M2StackWord_PeepWord (ScopeStack, 1));
2753 : 701510 : n = DynamicStrings_Mark (DynamicStrings_InitStringCharStar (NameKey_KeyToCharStar (SymbolTable_GetSymName (sym))));
2754 : 701510 : if (SymbolTable_IsDefImp (sym))
2755 : : {
2756 : 4016 : return FormatStrings_Sprintf1 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "implementation module %s", 24)), (const unsigned char *) &n, (sizeof (n)-1));
2757 : : }
2758 : 697494 : else if (SymbolTable_IsModule (sym))
2759 : : {
2760 : : /* avoid dangling else. */
2761 : 53210 : if (SymbolTable_IsInnerModule (sym))
2762 : : {
2763 : 84 : return FormatStrings_Sprintf1 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "inner module %s", 15)), (const unsigned char *) &n, (sizeof (n)-1));
2764 : : }
2765 : : else
2766 : : {
2767 : 53126 : return FormatStrings_Sprintf1 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "program module %s", 17)), (const unsigned char *) &n, (sizeof (n)-1));
2768 : : }
2769 : : }
2770 : 644284 : else if (SymbolTable_IsProcedure (sym))
2771 : : {
2772 : : /* avoid dangling else. */
2773 : 644284 : if (SymbolTable_IsProcedureNested (sym))
2774 : : {
2775 : 396 : return FormatStrings_Sprintf1 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "nested procedure %s", 19)), (const unsigned char *) &n, (sizeof (n)-1));
2776 : : }
2777 : : else
2778 : : {
2779 : 643888 : return FormatStrings_Sprintf1 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "procedure %s", 12)), (const unsigned char *) &n, (sizeof (n)-1));
2780 : : }
2781 : : }
2782 : : else
2783 : : {
2784 : : /* avoid dangling else. */
2785 : 0 : M2Error_InternalError ((const char *) "unexpected scope symbol", 23);
2786 : : }
2787 : : }
2788 : : ReturnException ("/home/worker/buildworker/tiber-lcov/build/gcc/m2/gm2-compiler/M2GenGCC.def", 20, 1);
2789 : : __builtin_unreachable ();
2790 : : }
2791 : :
2792 : :
2793 : : /*
2794 : : CodeRange - encode the range test associated with op3.
2795 : : */
2796 : :
2797 : 700685 : static void CodeRange (unsigned int rangeId)
2798 : : {
2799 : 700685 : M2Range_CodeRangeCheck (rangeId, GetCurrentScopeDescription ());
2800 : 700679 : }
2801 : :
2802 : :
2803 : : /*
2804 : : CodeError - encode the error test associated with op3.
2805 : : */
2806 : :
2807 : 825 : static void CodeError (unsigned int errorId)
2808 : : {
2809 : : /* We would like to test whether this position is in the same basicblock
2810 : : as any known entry point. If so we could emit an error message.
2811 : : */
2812 : 825 : m2type_AddStatement (M2LexBuf_TokenToLocation (CurrentQuadToken), M2Range_CodeErrorCheck (errorId, GetCurrentScopeDescription (), static_cast<DynamicStrings_String> (NULL)));
2813 : 825 : }
2814 : :
2815 : :
2816 : : /*
2817 : : CodeModuleScope - ModuleScopeOp is a quadruple which has the following
2818 : : format:
2819 : :
2820 : : ModuleScopeOp _ _ moduleSym
2821 : :
2822 : : Its purpose is to reset the source file to another
2823 : : file, hence all line numbers emitted with the
2824 : : generated code will be relative to this source file.
2825 : : */
2826 : :
2827 : 65069 : static void CodeModuleScope (unsigned int moduleSym)
2828 : : {
2829 : 65069 : PushScope (moduleSym);
2830 : 65069 : }
2831 : :
2832 : :
2833 : : /*
2834 : : CodeStartModFile - StartModFileOp is a quadruple which has the following
2835 : : format:
2836 : :
2837 : : StartModFileOp _ _ moduleSym
2838 : :
2839 : : A new source file has been encountered therefore
2840 : : set LastLine to 1.
2841 : : Call pushGlobalScope.
2842 : : */
2843 : :
2844 : 64661 : static void CodeStartModFile (unsigned int moduleSym)
2845 : : {
2846 : 64661 : m2block_pushGlobalScope ();
2847 : 64661 : LastLine = 1;
2848 : 64661 : PushScope (moduleSym);
2849 : 64661 : }
2850 : :
2851 : :
2852 : : /*
2853 : : CodeStartDefFile - StartDefFileOp is a quadruple with the following
2854 : : format:
2855 : :
2856 : : StartDefFileOp _ _ moduleSym
2857 : :
2858 : : A new source file has been encountered therefore
2859 : : set LastLine to 1.
2860 : : Call pushGlobalScope.
2861 : : */
2862 : :
2863 : 117423 : static void CodeStartDefFile (unsigned int moduleSym)
2864 : : {
2865 : 117423 : m2block_pushGlobalScope ();
2866 : 117423 : PushScope (moduleSym);
2867 : 117423 : LastLine = 1;
2868 : 117423 : }
2869 : :
2870 : :
2871 : : /*
2872 : : CodeEndFile - pops the GlobalScope.
2873 : : */
2874 : :
2875 : 182084 : static void CodeEndFile (void)
2876 : : {
2877 : 182084 : m2block_popGlobalScope ();
2878 : 182084 : }
2879 : :
2880 : :
2881 : : /*
2882 : : CallInnerInit - produce a call to inner module initialization routine.
2883 : : */
2884 : :
2885 : 408 : static void CallInnerInit (unsigned int moduleSym)
2886 : : {
2887 : 408 : location_t location;
2888 : 408 : unsigned int ctor;
2889 : 408 : unsigned int init;
2890 : 408 : unsigned int fini;
2891 : 408 : unsigned int dep;
2892 : :
2893 : 408 : location = M2LexBuf_TokenToLocation (CurrentQuadToken);
2894 : 408 : SymbolTable_GetModuleCtors (moduleSym, &ctor, &init, &fini, &dep);
2895 : 408 : m2statement_BuildCallInner (location, SymbolConversion_Mod2Gcc (init));
2896 : 408 : }
2897 : :
2898 : :
2899 : : /*
2900 : : CallInnerFinally - produce a call to inner module finalization routine.
2901 : : */
2902 : :
2903 : 264 : static void CallInnerFinally (unsigned int moduleSym)
2904 : : {
2905 : 264 : location_t location;
2906 : 264 : unsigned int ctor;
2907 : 264 : unsigned int init;
2908 : 264 : unsigned int fini;
2909 : 264 : unsigned int dep;
2910 : :
2911 : 264 : location = M2LexBuf_TokenToLocation (CurrentQuadToken);
2912 : 264 : SymbolTable_GetModuleCtors (moduleSym, &ctor, &init, &fini, &dep);
2913 : 264 : m2statement_BuildCallInner (location, SymbolConversion_Mod2Gcc (fini));
2914 : 264 : }
2915 : :
2916 : :
2917 : : /*
2918 : : CodeInitStart - emits starting code before the main BEGIN END of the
2919 : : current module.
2920 : : */
2921 : :
2922 : 65069 : static void CodeInitStart (unsigned int moduleSym, bool CompilingMainModule)
2923 : : {
2924 : 65069 : location_t location;
2925 : 65069 : unsigned int ctor;
2926 : 65069 : unsigned int init;
2927 : 65069 : unsigned int fini;
2928 : 65069 : unsigned int dep;
2929 : :
2930 : 65069 : if (CompilingMainModule || M2Options_WholeProgram)
2931 : : {
2932 : 14851 : location = M2LexBuf_TokenToLocation (CurrentQuadToken);
2933 : 14851 : SymbolTable_GetModuleCtors (moduleSym, &ctor, &init, &fini, &dep);
2934 : 14851 : m2statement_BuildStartFunctionCode (location, SymbolConversion_Mod2Gcc (init), IsExportedGcc (init), false);
2935 : 14851 : SymbolTable_ForeachInnerModuleDo (moduleSym, (SymbolKey_PerformOperation) {(SymbolKey_PerformOperation_t) CallInnerInit});
2936 : : }
2937 : 65069 : }
2938 : :
2939 : :
2940 : : /*
2941 : : CodeInitEnd - emits terminating code after the main BEGIN END of the
2942 : : current module.
2943 : : */
2944 : :
2945 : 65069 : static void CodeInitEnd (unsigned int moduleSym, bool CompilingMainModule)
2946 : : {
2947 : 65069 : location_t location;
2948 : 65069 : unsigned int ctor;
2949 : 65069 : unsigned int init;
2950 : 65069 : unsigned int fini;
2951 : 65069 : unsigned int dep;
2952 : :
2953 : 65069 : if (CompilingMainModule || M2Options_WholeProgram)
2954 : : {
2955 : 14851 : location = M2LexBuf_TokenToLocation (SymbolTable_GetDeclaredMod (moduleSym));
2956 : 14851 : SymbolTable_GetModuleCtors (moduleSym, &ctor, &init, &fini, &dep);
2957 : 14851 : m2block_finishFunctionDecl (location, SymbolConversion_Mod2Gcc (init));
2958 : 14851 : m2statement_BuildEndFunctionCode (location, SymbolConversion_Mod2Gcc (init), SymbolTable_IsModuleWithinProcedure (moduleSym));
2959 : : }
2960 : 65069 : }
2961 : :
2962 : :
2963 : : /*
2964 : : CodeFinallyStart - emits starting code before the main BEGIN END of the
2965 : : current module.
2966 : : */
2967 : :
2968 : 14851 : static void CodeFinallyStart (unsigned int moduleSym, bool CompilingMainModule)
2969 : : {
2970 : 14851 : location_t location;
2971 : 14851 : unsigned int ctor;
2972 : 14851 : unsigned int init;
2973 : 14851 : unsigned int fini;
2974 : 14851 : unsigned int dep;
2975 : :
2976 : 14851 : if (CompilingMainModule || M2Options_WholeProgram)
2977 : : {
2978 : 14851 : location = M2LexBuf_TokenToLocation (CurrentQuadToken);
2979 : 14851 : SymbolTable_GetModuleCtors (moduleSym, &ctor, &init, &fini, &dep);
2980 : 14851 : m2statement_BuildStartFunctionCode (location, SymbolConversion_Mod2Gcc (fini), IsExportedGcc (fini), false);
2981 : 14851 : SymbolTable_ForeachInnerModuleDo (moduleSym, (SymbolKey_PerformOperation) {(SymbolKey_PerformOperation_t) CallInnerFinally});
2982 : : }
2983 : 14851 : }
2984 : :
2985 : :
2986 : : /*
2987 : : CodeFinallyEnd - emits terminating code after the main BEGIN END of the
2988 : : current module. It also creates the scaffold if the
2989 : : cflag was not present.
2990 : : */
2991 : :
2992 : 14851 : static void CodeFinallyEnd (unsigned int moduleSym, bool CompilingMainModule)
2993 : : {
2994 : 14851 : location_t location;
2995 : 14851 : unsigned int tokenpos;
2996 : 14851 : unsigned int ctor;
2997 : 14851 : unsigned int init;
2998 : 14851 : unsigned int fini;
2999 : 14851 : unsigned int dep;
3000 : :
3001 : 14851 : if (CompilingMainModule || M2Options_WholeProgram)
3002 : : {
3003 : 14851 : tokenpos = SymbolTable_GetDeclaredMod (moduleSym);
3004 : 14851 : location = M2LexBuf_TokenToLocation (tokenpos);
3005 : 14851 : SymbolTable_GetModuleCtors (moduleSym, &ctor, &init, &fini, &dep);
3006 : 14851 : m2block_finishFunctionDecl (location, SymbolConversion_Mod2Gcc (fini));
3007 : 14851 : m2statement_BuildEndFunctionCode (location, SymbolConversion_Mod2Gcc (fini), SymbolTable_IsModuleWithinProcedure (moduleSym));
3008 : : }
3009 : 14851 : }
3010 : :
3011 : :
3012 : : /*
3013 : : GetAddressOfUnbounded - returns the address of the unbounded array contents.
3014 : : */
3015 : :
3016 : 4402 : static tree GetAddressOfUnbounded (location_t location, unsigned int param)
3017 : : {
3018 : 4402 : unsigned int UnboundedType;
3019 : :
3020 : 4402 : UnboundedType = SymbolTable_GetType (param);
3021 : 4402 : M2Debug_Assert (SymbolTable_IsUnbounded (UnboundedType));
3022 : 4402 : return m2convert_BuildConvert (M2LexBuf_TokenToLocation (SymbolTable_GetDeclaredMod (param)), m2type_GetPointerType (), m2expr_BuildComponentRef (location, SymbolConversion_Mod2Gcc (param), SymbolConversion_Mod2Gcc (SymbolTable_GetUnboundedAddressOffset (UnboundedType))), false);
3023 : : /* static analysis guarentees a RETURN statement will be used before here. */
3024 : : __builtin_unreachable ();
3025 : : }
3026 : :
3027 : :
3028 : : /*
3029 : : GetSizeOfHighFromUnbounded - returns a Tree containing the value of
3030 : : param.HIGH * sizeof(unboundedType).
3031 : : The number of legal bytes this array
3032 : : occupies.
3033 : : */
3034 : :
3035 : 4402 : static tree GetSizeOfHighFromUnbounded (unsigned int tokenno, unsigned int param)
3036 : : {
3037 : 4402 : tree t;
3038 : 4402 : unsigned int UnboundedType;
3039 : 4402 : unsigned int ArrayType;
3040 : 4402 : unsigned int i;
3041 : 4402 : unsigned int n;
3042 : 4402 : location_t location;
3043 : :
3044 : 4402 : location = M2LexBuf_TokenToLocation (tokenno);
3045 : 4402 : UnboundedType = SymbolTable_GetType (param);
3046 : 4402 : M2Debug_Assert (SymbolTable_IsUnbounded (UnboundedType));
3047 : 4402 : ArrayType = SymbolTable_GetType (UnboundedType);
3048 : 4402 : i = 1;
3049 : 4402 : n = SymbolTable_GetDimension (UnboundedType);
3050 : 4402 : t = m2expr_GetCardinalOne (location);
3051 : 13296 : while (i <= n)
3052 : : {
3053 : 4492 : t = m2expr_BuildMult (location, m2expr_BuildAdd (location, M2GenGCC_GetHighFromUnbounded (location, i, param), m2expr_GetCardinalOne (location), false), t, false);
3054 : : /* Remember we must add one as a[HIGH(a)] is the last accessible element of the array. */
3055 : 4492 : i += 1;
3056 : : }
3057 : 4402 : return m2convert_BuildConvert (location, m2type_GetCardinalType (), m2expr_BuildMult (location, t, m2convert_BuildConvert (location, m2type_GetCardinalType (), FindSize (tokenno, ArrayType), false), false), false);
3058 : : /* static analysis guarentees a RETURN statement will be used before here. */
3059 : : __builtin_unreachable ();
3060 : : }
3061 : :
3062 : :
3063 : : /*
3064 : : MaybeDebugBuiltinAlloca - if DebugBuiltins is set
3065 : : then call Builtins.alloca_trace
3066 : : else call Builtins.alloca.
3067 : : */
3068 : :
3069 : 4402 : static tree MaybeDebugBuiltinAlloca (location_t location, unsigned int tok, tree high)
3070 : : {
3071 : 4402 : tree call;
3072 : 4402 : tree memptr;
3073 : 4402 : tree func;
3074 : :
3075 : 4402 : if (M2Options_DebugBuiltins)
3076 : : {
3077 : 0 : func = SymbolConversion_Mod2Gcc (SymbolTable_FromModuleGetSym (tok, NameKey_MakeKey ((const char *) "alloca_trace", 12), M2Batch_MakeDefinitionSource (tok, NameKey_MakeKey ((const char *) "Builtins", 8))));
3078 : 0 : call = m2builtins_BuiltInAlloca (location, high);
3079 : 0 : m2statement_SetLastFunction (call);
3080 : 0 : memptr = m2statement_BuildFunctValue (location, call);
3081 : 0 : call = m2statement_BuildCall2 (location, func, m2type_GetPointerType (), memptr, high);
3082 : : }
3083 : : else
3084 : : {
3085 : 4402 : call = m2builtins_BuiltInAlloca (location, high);
3086 : : }
3087 : 4402 : m2statement_SetLastFunction (call);
3088 : 4402 : return m2statement_BuildFunctValue (location, call);
3089 : : /* static analysis guarentees a RETURN statement will be used before here. */
3090 : : __builtin_unreachable ();
3091 : : }
3092 : :
3093 : :
3094 : : /*
3095 : : MaybeDebugBuiltinMemcpy - if DebugBuiltins is set
3096 : : then call memcpy
3097 : : else call Builtins.memcpy.
3098 : : */
3099 : :
3100 : 5844 : static tree MaybeDebugBuiltinMemcpy (location_t location, tree src, tree dest, tree nbytes)
3101 : : {
3102 : 5844 : tree call;
3103 : 5844 : tree func;
3104 : :
3105 : 5844 : if (M2Options_DebugBuiltins)
3106 : : {
3107 : 0 : func = SymbolConversion_Mod2Gcc (Memcpy);
3108 : 0 : call = m2statement_BuildCall3 (location, func, m2type_GetPointerType (), src, dest, nbytes);
3109 : : }
3110 : : else
3111 : : {
3112 : 5844 : call = m2builtins_BuiltinMemCopy (location, src, dest, nbytes);
3113 : : }
3114 : 5844 : m2statement_SetLastFunction (call);
3115 : 5844 : return m2statement_BuildFunctValue (location, call);
3116 : : /* static analysis guarentees a RETURN statement will be used before here. */
3117 : : __builtin_unreachable ();
3118 : : }
3119 : :
3120 : :
3121 : : /*
3122 : : MakeCopyUse - make a copy of the unbounded array and alter all references
3123 : : from the old unbounded array to the new unbounded array.
3124 : : The parameter, param, contains a RECORD
3125 : : ArrayAddress: ADDRESS ;
3126 : : ArrayHigh : CARDINAL ;
3127 : : END
3128 : : we simply declare a new array of size, ArrayHigh
3129 : : and set ArrayAddress to the address of the copy.
3130 : :
3131 : : Remember ArrayHigh == sizeof(Array)-sizeof(typeof(array))
3132 : : so we add 1 for the size and add 1 for a possible <nul>
3133 : : */
3134 : :
3135 : 4402 : static void MakeCopyUse (unsigned int tokenno, unsigned int param)
3136 : : {
3137 : 4402 : location_t location;
3138 : 4402 : unsigned int UnboundedType;
3139 : 4402 : tree Addr;
3140 : 4402 : tree High;
3141 : 4402 : tree NewArray;
3142 : :
3143 : 4402 : location = M2LexBuf_TokenToLocation (tokenno);
3144 : 4402 : UnboundedType = SymbolTable_GetType (param);
3145 : 4402 : M2Debug_Assert (SymbolTable_IsUnbounded (UnboundedType));
3146 : 4402 : High = GetSizeOfHighFromUnbounded (tokenno, param);
3147 : 4402 : Addr = GetAddressOfUnbounded (location, param);
3148 : 4402 : NewArray = MaybeDebugBuiltinAlloca (location, tokenno, High);
3149 : 4402 : NewArray = MaybeDebugBuiltinMemcpy (location, NewArray, Addr, High);
3150 : : /* Now assign param.Addr := ADR(NewArray). */
3151 : 4402 : m2statement_BuildAssignmentStatement (location, m2expr_BuildComponentRef (location, SymbolConversion_Mod2Gcc (param), SymbolConversion_Mod2Gcc (SymbolTable_GetUnboundedAddressOffset (UnboundedType))), NewArray);
3152 : 4402 : }
3153 : :
3154 : :
3155 : : /*
3156 : : GetParamAddress - returns the address of parameter, param.
3157 : : */
3158 : :
3159 : 0 : static tree GetParamAddress (location_t location, unsigned int proc, unsigned int param)
3160 : : {
3161 : 0 : unsigned int sym;
3162 : 0 : unsigned int type;
3163 : :
3164 : 0 : if (SymbolTable_IsParameter (param))
3165 : : {
3166 : 0 : type = SymbolTable_GetType (param);
3167 : 0 : sym = SymbolTable_GetLocalSym (proc, SymbolTable_GetSymName (param));
3168 : 0 : if (SymbolTable_IsUnbounded (type))
3169 : : {
3170 : 0 : return GetAddressOfUnbounded (location, sym);
3171 : : }
3172 : : else
3173 : : {
3174 : 0 : M2Debug_Assert ((SymbolTable_GetMode (sym)) == SymbolTable_LeftValue);
3175 : 0 : return SymbolConversion_Mod2Gcc (sym);
3176 : : }
3177 : : }
3178 : : else
3179 : : {
3180 : 0 : M2Debug_Assert (SymbolTable_IsVar (param));
3181 : 0 : M2Debug_Assert ((SymbolTable_GetMode (param)) == SymbolTable_LeftValue);
3182 : 0 : return SymbolConversion_Mod2Gcc (param);
3183 : : }
3184 : : /* static analysis guarentees a RETURN statement will be used before here. */
3185 : : __builtin_unreachable ();
3186 : : }
3187 : :
3188 : :
3189 : : /*
3190 : : IsUnboundedWrittenTo - returns TRUE if the unbounded parameter
3191 : : might be written to, or if -funbounded-by-reference
3192 : : was _not_ specified.
3193 : : */
3194 : :
3195 : 4402 : static bool IsUnboundedWrittenTo (unsigned int proc, unsigned int param)
3196 : : {
3197 : 4402 : DynamicStrings_String f;
3198 : 4402 : unsigned int l;
3199 : 4402 : unsigned int sym;
3200 : 4402 : NameKey_Name n1;
3201 : 4402 : NameKey_Name n2;
3202 : :
3203 : 4402 : sym = SymbolTable_GetLocalSym (proc, SymbolTable_GetSymName (param));
3204 : 4402 : if (sym == SymbolTable_NulSym)
3205 : : {
3206 : 0 : M2Error_InternalError ((const char *) "should find symbol in table", 27);
3207 : : }
3208 : : else
3209 : : {
3210 : 4402 : if (M2Options_UnboundedByReference)
3211 : : {
3212 : 0 : if ((! (SymbolTable_GetVarWritten (sym))) && M2Options_VerboseUnbounded)
3213 : : {
3214 : 0 : n1 = SymbolTable_GetSymName (sym);
3215 : 0 : n2 = SymbolTable_GetSymName (proc);
3216 : 0 : f = M2LexBuf_FindFileNameFromToken (SymbolTable_GetDeclaredMod (sym), 0);
3217 : 0 : l = M2LexBuf_TokenToLineNo (SymbolTable_GetDeclaredMod (sym), 0);
3218 : 0 : M2Printf_printf4 ((const char *) "%s:%d:non VAR unbounded parameter %a in procedure %a does not need to be copied\\n", 81, (const unsigned char *) &f, (sizeof (f)-1), (const unsigned char *) &l, (sizeof (l)-1), (const unsigned char *) &n1, (sizeof (n1)-1), (const unsigned char *) &n2, (sizeof (n2)-1));
3219 : : }
3220 : 0 : return SymbolTable_GetVarWritten (sym);
3221 : : }
3222 : : else
3223 : : {
3224 : : return true;
3225 : : }
3226 : : }
3227 : : ReturnException ("/home/worker/buildworker/tiber-lcov/build/gcc/m2/gm2-compiler/M2GenGCC.def", 20, 1);
3228 : : __builtin_unreachable ();
3229 : : }
3230 : :
3231 : :
3232 : : /*
3233 : : GetParamSize - returns the size in bytes of, param.
3234 : : */
3235 : :
3236 : 0 : static tree GetParamSize (unsigned int tokenno, unsigned int param)
3237 : : {
3238 : 0 : M2Debug_Assert ((SymbolTable_IsVar (param)) || (SymbolTable_IsParameter (param)));
3239 : 0 : if (SymbolTable_IsUnbounded (param))
3240 : : {
3241 : 0 : return GetSizeOfHighFromUnbounded (tokenno, param);
3242 : : }
3243 : : else
3244 : : {
3245 : 0 : return m2expr_BuildSize (M2LexBuf_TokenToLocation (tokenno), SymbolConversion_Mod2Gcc (SymbolTable_GetType (param)), false);
3246 : : }
3247 : : /* static analysis guarentees a RETURN statement will be used before here. */
3248 : : __builtin_unreachable ();
3249 : : }
3250 : :
3251 : :
3252 : : /*
3253 : : DoIsIntersection - jumps to, tLabel, if the ranges i1..i2 j1..j2 overlap
3254 : : else jump to, fLabel.
3255 : : */
3256 : :
3257 : 0 : static void DoIsIntersection (unsigned int tokenno, tree ta, tree tb, tree tc, tree td, DynamicStrings_String tLabel, DynamicStrings_String fLabel)
3258 : : {
3259 : 0 : location_t location;
3260 : :
3261 : 0 : location = M2LexBuf_TokenToLocation (tokenno);
3262 : : /*
3263 : : if (ta>td) OR (tb<tc)
3264 : : then
3265 : : goto fLabel
3266 : : else
3267 : : goto tLabel
3268 : : fi
3269 : : */
3270 : 0 : m2statement_DoJump (location, m2expr_BuildGreaterThan (location, ta, td), NULL, reinterpret_cast <char * > (DynamicStrings_string (fLabel)));
3271 : 0 : m2statement_DoJump (location, m2expr_BuildLessThan (location, tb, tc), NULL, reinterpret_cast <char * > (DynamicStrings_string (fLabel)));
3272 : 0 : m2statement_BuildGoto (location, reinterpret_cast <char * > (DynamicStrings_string (tLabel)));
3273 : 0 : if (CascadedDebugging)
3274 : : {
3275 : : M2Printf_printf1 ((const char *) "label used %s\\n", 15, (const unsigned char *) &tLabel, (sizeof (tLabel)-1));
3276 : : M2Printf_printf1 ((const char *) "label used %s\\n", 15, (const unsigned char *) &fLabel, (sizeof (fLabel)-1));
3277 : : }
3278 : 0 : }
3279 : :
3280 : :
3281 : : /*
3282 : : BuildCascadedIfThenElsif - mustCheck contains a list of variables which
3283 : : must be checked against the address of (proc, param, i).
3284 : : If the address matches we make a copy of the unbounded
3285 : : parameter (proc, param) and quit further checking.
3286 : : */
3287 : :
3288 : 0 : static void BuildCascadedIfThenElsif (unsigned int tokenno, Lists_List mustCheck, unsigned int proc, unsigned int param)
3289 : : {
3290 : 0 : tree ta;
3291 : 0 : tree tb;
3292 : 0 : tree tc;
3293 : 0 : tree td;
3294 : 0 : unsigned int n;
3295 : 0 : unsigned int j;
3296 : 0 : DynamicStrings_String tLabel;
3297 : 0 : DynamicStrings_String fLabel;
3298 : 0 : DynamicStrings_String nLabel;
3299 : 0 : location_t location;
3300 : :
3301 : 0 : location = M2LexBuf_TokenToLocation (tokenno);
3302 : 0 : n = Lists_NoOfItemsInList (mustCheck);
3303 : : /* We want a sequence of if then elsif statements. */
3304 : 0 : if (n > 0)
3305 : : {
3306 : 0 : UnboundedLabelNo += 1;
3307 : 0 : j = 1;
3308 : 0 : ta = GetAddressOfUnbounded (location, param);
3309 : 0 : tb = m2convert_BuildConvert (M2LexBuf_TokenToLocation (tokenno), m2type_GetPointerType (), m2expr_BuildAddAddress (location, ta, GetSizeOfHighFromUnbounded (tokenno, param)), false);
3310 : 0 : while (j <= n)
3311 : : {
3312 : 0 : if (j > 1)
3313 : : {
3314 : 0 : nLabel = CreateLabelProcedureN (proc, (const char *) "n", 1, UnboundedLabelNo, j);
3315 : 0 : if (CascadedDebugging)
3316 : : {
3317 : : M2Printf_printf1 ((const char *) "label declared %s\\n", 19, (const unsigned char *) &nLabel, (sizeof (nLabel)-1));
3318 : : }
3319 : 0 : m2statement_DeclareLabel (location, reinterpret_cast <char * > (DynamicStrings_string (nLabel)));
3320 : : }
3321 : 0 : tc = GetParamAddress (location, proc, Lists_GetItemFromList (mustCheck, j));
3322 : 0 : td = m2convert_BuildConvert (M2LexBuf_TokenToLocation (tokenno), m2type_GetPointerType (), m2expr_BuildAddAddress (location, tc, GetParamSize (tokenno, param)), false);
3323 : 0 : tLabel = CreateLabelProcedureN (proc, (const char *) "t", 1, UnboundedLabelNo, j+1);
3324 : 0 : fLabel = CreateLabelProcedureN (proc, (const char *) "f", 1, UnboundedLabelNo, j+1);
3325 : 0 : DoIsIntersection (tokenno, ta, tb, tc, td, tLabel, fLabel);
3326 : 0 : if (CascadedDebugging)
3327 : : {
3328 : : M2Printf_printf1 ((const char *) "label declared %s\\n", 19, (const unsigned char *) &tLabel, (sizeof (tLabel)-1));
3329 : : }
3330 : 0 : m2statement_DeclareLabel (location, reinterpret_cast <char * > (DynamicStrings_string (tLabel)));
3331 : 0 : MakeCopyUse (tokenno, param);
3332 : 0 : if (j < n)
3333 : : {
3334 : 0 : nLabel = CreateLabelProcedureN (proc, (const char *) "n", 1, UnboundedLabelNo, n+1);
3335 : 0 : m2statement_BuildGoto (location, reinterpret_cast <char * > (DynamicStrings_string (nLabel)));
3336 : 0 : if (CascadedDebugging)
3337 : : {
3338 : : M2Printf_printf1 ((const char *) "goto %s\\n", 9, (const unsigned char *) &nLabel, (sizeof (nLabel)-1));
3339 : : }
3340 : : }
3341 : 0 : if (CascadedDebugging)
3342 : : {
3343 : : M2Printf_printf1 ((const char *) "label declared %s\\n", 19, (const unsigned char *) &fLabel, (sizeof (fLabel)-1));
3344 : : }
3345 : 0 : m2statement_DeclareLabel (location, reinterpret_cast <char * > (DynamicStrings_string (fLabel)));
3346 : 0 : j += 1;
3347 : : }
3348 : : }
3349 : : /*
3350 : : nLabel := CreateLabelProcedureN(proc, "fin", UnboundedLabelNo, n+1) ;
3351 : : IF CascadedDebugging
3352 : : THEN
3353 : : printf1('label declared %s
3354 : : ', nLabel)
3355 : : END ;
3356 : : DeclareLabel(location, string(nLabel))
3357 : : */
3358 : 0 : }
3359 : :
3360 : :
3361 : : /*
3362 : : CheckUnboundedNonVarParameter - if non var unbounded parameter is written to
3363 : : then
3364 : : make a copy of the contents of this parameter
3365 : : and use the copy
3366 : : else if param
3367 : : is type compatible with any parameter, symv
3368 : : and at runtime its address matches symv
3369 : : then
3370 : : make a copy of the contents of this parameter
3371 : : and use the copy
3372 : : fi
3373 : : */
3374 : :
3375 : 4402 : static void CheckUnboundedNonVarParameter (unsigned int tokenno, Lists_List trashed, unsigned int proc, unsigned int param)
3376 : : {
3377 : 4402 : Lists_List mustCheck;
3378 : 4402 : unsigned int paramTrashed;
3379 : 4402 : unsigned int n;
3380 : 4402 : unsigned int j;
3381 : 4402 : DynamicStrings_String f;
3382 : 4402 : unsigned int l;
3383 : 4402 : NameKey_Name n1;
3384 : 4402 : NameKey_Name n2;
3385 : :
3386 : 4402 : if (IsUnboundedWrittenTo (proc, param))
3387 : : {
3388 : 4402 : MakeCopyUse (tokenno, param);
3389 : : }
3390 : : else
3391 : : {
3392 : 0 : Lists_InitList (&mustCheck);
3393 : 0 : n = Lists_NoOfItemsInList (trashed);
3394 : 0 : j = 1;
3395 : 0 : while (j <= n)
3396 : : {
3397 : 0 : paramTrashed = static_cast<unsigned int> (Lists_GetItemFromList (trashed, j));
3398 : 0 : if (M2Base_IsAssignmentCompatible (SymbolTable_GetLowestType (param), SymbolTable_GetLowestType (paramTrashed)))
3399 : : {
3400 : : /* We must check whether this unbounded parameter has the same
3401 : : address as the trashed parameter. */
3402 : 0 : if (M2Options_VerboseUnbounded)
3403 : : {
3404 : 0 : n1 = SymbolTable_GetSymName (paramTrashed);
3405 : 0 : n2 = SymbolTable_GetSymName (proc);
3406 : 0 : f = M2LexBuf_FindFileNameFromToken (SymbolTable_GetDeclaredMod (paramTrashed), 0);
3407 : 0 : l = M2LexBuf_TokenToLineNo (SymbolTable_GetDeclaredMod (paramTrashed), 0);
3408 : 0 : M2Printf_printf4 ((const char *) "%s:%d:must check at runtime the address of parameter, %a, in procedure, %a, whose contents will be trashed\\n", 108, (const unsigned char *) &f, (sizeof (f)-1), (const unsigned char *) &l, (sizeof (l)-1), (const unsigned char *) &n1, (sizeof (n1)-1), (const unsigned char *) &n2, (sizeof (n2)-1));
3409 : 0 : n1 = SymbolTable_GetSymName (param);
3410 : 0 : n2 = SymbolTable_GetSymName (paramTrashed);
3411 : 0 : M2Printf_printf4 ((const char *) "%s:%d:against address of parameter, %a, possibly resulting in a copy of parameter, %a\\n", 87, (const unsigned char *) &f, (sizeof (f)-1), (const unsigned char *) &l, (sizeof (l)-1), (const unsigned char *) &n1, (sizeof (n1)-1), (const unsigned char *) &n2, (sizeof (n2)-1));
3412 : : }
3413 : 0 : Lists_PutItemIntoList (mustCheck, paramTrashed);
3414 : : }
3415 : 0 : j += 1;
3416 : : }
3417 : : /* Now we build a sequence of if then { elsif then } end to check addresses. */
3418 : 0 : BuildCascadedIfThenElsif (tokenno, mustCheck, proc, param);
3419 : 0 : Lists_KillList (&mustCheck);
3420 : : }
3421 : 4402 : }
3422 : :
3423 : :
3424 : : /*
3425 : : IsParameterWritten - returns TRUE if a parameter, sym, is written to.
3426 : : */
3427 : :
3428 : 75257 : static bool IsParameterWritten (unsigned int proc, unsigned int sym)
3429 : : {
3430 : 75257 : if (SymbolTable_IsParameter (sym))
3431 : : {
3432 : 75257 : sym = SymbolTable_GetLocalSym (proc, SymbolTable_GetSymName (sym));
3433 : : }
3434 : 75257 : if (SymbolTable_IsVar (sym))
3435 : : {
3436 : : /* Unbounded arrays will appear as vars. */
3437 : 75257 : return SymbolTable_GetVarWritten (sym);
3438 : : }
3439 : 0 : M2Error_InternalError ((const char *) "expecting IsVar to return TRUE", 30);
3440 : : ReturnException ("/home/worker/buildworker/tiber-lcov/build/gcc/m2/gm2-compiler/M2GenGCC.def", 20, 1);
3441 : : __builtin_unreachable ();
3442 : : }
3443 : :
3444 : :
3445 : : /*
3446 : : SaveNonVarUnboundedParameters - for each var parameter, symv, do
3447 : : not just unbounded var parameters, but _all_
3448 : : parameters
3449 : : if symv is written to
3450 : : then
3451 : : add symv to a compile list
3452 : : fi
3453 : : done
3454 : :
3455 : : for each parameter of procedure, symu, do
3456 : : if non var unbounded parameter is written to
3457 : : then
3458 : : make a copy of the contents of this parameter
3459 : : and use the copy
3460 : : else if
3461 : : symu is type compatible with any parameter, symv
3462 : : and at runtime its address matches symv
3463 : : then
3464 : : make a copy of the contents of this parameter
3465 : : and use the copy
3466 : : fi
3467 : : done
3468 : : */
3469 : :
3470 : 69106 : static void SaveNonVarUnboundedParameters (unsigned int tokenno, unsigned int proc)
3471 : : {
3472 : 69106 : unsigned int i;
3473 : 69106 : unsigned int p;
3474 : 69106 : Lists_List trashed;
3475 : 69106 : DynamicStrings_String f;
3476 : 69106 : unsigned int sym;
3477 : 69106 : unsigned int l;
3478 : 69106 : NameKey_Name n1;
3479 : 69106 : NameKey_Name n2;
3480 : :
3481 : 69106 : Lists_InitList (&trashed);
3482 : 69106 : i = 1;
3483 : 69106 : p = SymbolTable_NoOfParamAny (proc);
3484 : 213469 : while (i <= p)
3485 : : {
3486 : 75257 : sym = SymbolTable_GetNthParamAny (proc, i);
3487 : 75257 : if (IsParameterWritten (proc, sym))
3488 : : {
3489 : 5898 : if (M2Options_VerboseUnbounded)
3490 : : {
3491 : 0 : n1 = SymbolTable_GetSymName (sym);
3492 : 0 : n2 = SymbolTable_GetSymName (proc);
3493 : 0 : f = M2LexBuf_FindFileNameFromToken (SymbolTable_GetDeclaredMod (sym), 0);
3494 : 0 : l = M2LexBuf_TokenToLineNo (SymbolTable_GetDeclaredMod (sym), 0);
3495 : 0 : M2Printf_printf4 ((const char *) "%s:%d:parameter, %a, in procedure, %a, is trashed\\n", 51, (const unsigned char *) &f, (sizeof (f)-1), (const unsigned char *) &l, (sizeof (l)-1), (const unsigned char *) &n1, (sizeof (n1)-1), (const unsigned char *) &n2, (sizeof (n2)-1));
3496 : : }
3497 : 5898 : Lists_PutItemIntoList (trashed, sym);
3498 : : }
3499 : 75257 : i += 1;
3500 : : }
3501 : : /* Now see whether we need to copy any unbounded array parameters. */
3502 : 69106 : i = 1;
3503 : 69106 : p = SymbolTable_NoOfParamAny (proc);
3504 : 213469 : while (i <= p)
3505 : : {
3506 : 75257 : if ((SymbolTable_IsUnboundedParamAny (proc, i)) && (! (SymbolTable_IsVarParamAny (proc, i))))
3507 : : {
3508 : 4402 : CheckUnboundedNonVarParameter (tokenno, trashed, proc, SymbolTable_GetNth (proc, i));
3509 : : }
3510 : 75257 : i += 1;
3511 : : }
3512 : 69106 : Lists_KillList (&trashed);
3513 : 69106 : }
3514 : :
3515 : :
3516 : : /*
3517 : : AutoInitVariable -
3518 : : */
3519 : :
3520 : 60 : static void AutoInitVariable (location_t location, unsigned int sym)
3521 : : {
3522 : 60 : unsigned int type;
3523 : :
3524 : 60 : if (((! (SymbolTable_IsParameter (sym))) && (SymbolTable_IsVar (sym))) && (! (SymbolTable_IsTemporary (sym))))
3525 : : {
3526 : : /* PrintSym (sym) ; */
3527 : 6 : type = SymbolTable_SkipType (SymbolTable_GetType (sym));
3528 : : /* The type SYSTEM.ADDRESS is a pointer type. */
3529 : 6 : if (SymbolTable_IsPointer (type))
3530 : : {
3531 : 6 : m2statement_BuildAssignmentStatement (location, SymbolConversion_Mod2Gcc (sym), m2convert_BuildConvert (location, SymbolConversion_Mod2Gcc (SymbolTable_GetType (sym)), m2expr_GetPointerZero (location), true));
3532 : : }
3533 : : }
3534 : 60 : }
3535 : :
3536 : :
3537 : : /*
3538 : : AutoInitialize - scope will be a procedure, module or defimp. All pointer
3539 : : variables are assigned to NIL.
3540 : : */
3541 : :
3542 : 69106 : static void AutoInitialize (location_t location, unsigned int scope)
3543 : : {
3544 : 69106 : unsigned int i;
3545 : 69106 : unsigned int n;
3546 : :
3547 : 69106 : if (M2Options_AutoInit)
3548 : : {
3549 : 30 : n = SymbolTable_NoOfVariables (scope);
3550 : 30 : i = 1;
3551 : 30 : if (SymbolTable_IsProcedure (scope))
3552 : : {
3553 : : /* The parameters are stored as local variables. */
3554 : 30 : i += SymbolTable_NoOfParamAny (scope);
3555 : : }
3556 : 90 : while (i <= n)
3557 : : {
3558 : 60 : AutoInitVariable (location, SymbolTable_GetNth (scope, i));
3559 : 60 : i += 1;
3560 : : }
3561 : : }
3562 : 69106 : }
3563 : :
3564 : :
3565 : : /*
3566 : : CodeNewLocalVar - Builds a new frame on the stack to contain the procedure
3567 : : local variables.
3568 : : */
3569 : :
3570 : 69106 : static void CodeNewLocalVar (unsigned int tokenno, unsigned int CurrentProcedure)
3571 : : {
3572 : 69106 : unsigned int begin;
3573 : 69106 : unsigned int end;
3574 : :
3575 : : /* Callee saves non var unbounded parameter contents. */
3576 : 69106 : SaveNonVarUnboundedParameters (tokenno, CurrentProcedure);
3577 : 69106 : m2statement_BuildPushFunctionContext ();
3578 : 69106 : SymbolTable_GetProcedureBeginEnd (CurrentProcedure, &begin, &end);
3579 : 69106 : CurrentQuadToken = begin;
3580 : 69106 : m2statement_SetBeginLocation (M2LexBuf_TokenToLocation (begin));
3581 : 69106 : AutoInitialize (M2LexBuf_TokenToLocation (begin), CurrentProcedure);
3582 : 69106 : SymbolTable_ForeachProcedureDo (CurrentProcedure, (SymbolKey_PerformOperation) {(SymbolKey_PerformOperation_t) M2Code_CodeBlock});
3583 : 69106 : SymbolTable_ForeachInnerModuleDo (CurrentProcedure, (SymbolKey_PerformOperation) {(SymbolKey_PerformOperation_t) M2Code_CodeBlock});
3584 : 69106 : m2statement_BuildPopFunctionContext ();
3585 : 69106 : SymbolTable_ForeachInnerModuleDo (CurrentProcedure, (SymbolKey_PerformOperation) {(SymbolKey_PerformOperation_t) CallInnerInit});
3586 : 69106 : }
3587 : :
3588 : :
3589 : : /*
3590 : : CodeKillLocalVar - removes local variables and returns to previous scope.
3591 : : */
3592 : :
3593 : 69100 : static void CodeKillLocalVar (unsigned int CurrentProcedure)
3594 : : {
3595 : 69100 : unsigned int begin;
3596 : 69100 : unsigned int end;
3597 : 69100 : tree proc;
3598 : :
3599 : 69100 : SymbolTable_GetProcedureBeginEnd (CurrentProcedure, &begin, &end);
3600 : 69100 : CurrentQuadToken = end;
3601 : 69100 : proc = NULL;
3602 : 69100 : if (SymbolTable_IsCtor (CurrentProcedure))
3603 : : {
3604 : 14381 : proc = m2decl_DeclareModuleCtor (SymbolConversion_Mod2Gcc (CurrentProcedure));
3605 : : }
3606 : 69100 : m2statement_BuildEndFunctionCode (M2LexBuf_TokenToLocation (end), SymbolConversion_Mod2Gcc (CurrentProcedure), M2GCCDeclare_IsProcedureGccNested (CurrentProcedure));
3607 : 69100 : if ((SymbolTable_IsCtor (CurrentProcedure)) && (proc != NULL))
3608 : : {
3609 : 14381 : m2decl_BuildModuleCtor (proc);
3610 : : }
3611 : 69100 : M2GCCDeclare_PoisonSymbols (CurrentProcedure);
3612 : 69100 : m2block_removeStmtNote ();
3613 : 69100 : PopScope ();
3614 : 69100 : }
3615 : :
3616 : :
3617 : : /*
3618 : : CodeProcedureScope - start a procedure scope for CurrentProcedure.
3619 : : */
3620 : :
3621 : 69112 : static void CodeProcedureScope (unsigned int CurrentProcedure)
3622 : : {
3623 : 69112 : unsigned int begin;
3624 : 69112 : unsigned int end;
3625 : :
3626 : 69112 : m2block_removeStmtNote ();
3627 : 69112 : SymbolTable_GetProcedureBeginEnd (CurrentProcedure, &begin, &end);
3628 : 69112 : m2statement_BuildStartFunctionCode (M2LexBuf_TokenToLocation (begin), SymbolConversion_Mod2Gcc (CurrentProcedure), IsExportedGcc (CurrentProcedure), SymbolTable_IsProcedureInline (CurrentProcedure));
3629 : 69112 : M2GCCDeclare_StartDeclareScope (CurrentProcedure);
3630 : 69106 : PushScope (CurrentProcedure);
3631 : 69106 : }
3632 : :
3633 : :
3634 : : /*
3635 : : CodeReturnValue - places the operand into the return value space
3636 : : allocated by the function call.
3637 : : */
3638 : :
3639 : 18881 : static void CodeReturnValue (unsigned int quad)
3640 : : {
3641 : 18881 : M2Quads_QuadOperator op;
3642 : 18881 : bool constExpr;
3643 : 18881 : bool overflowChecking;
3644 : 18881 : unsigned int expr;
3645 : 18881 : unsigned int none;
3646 : 18881 : unsigned int procedure;
3647 : 18881 : unsigned int combinedpos;
3648 : 18881 : unsigned int returnpos;
3649 : 18881 : unsigned int exprpos;
3650 : 18881 : unsigned int nonepos;
3651 : 18881 : unsigned int procpos;
3652 : 18881 : tree value;
3653 : 18881 : tree length;
3654 : 18881 : location_t location;
3655 : :
3656 : 18881 : M2Quads_GetQuadOtok (quad, &returnpos, &op, &expr, &none, &procedure, &overflowChecking, &constExpr, &exprpos, &nonepos, &procpos);
3657 : 18881 : combinedpos = M2LexBuf_MakeVirtualTok (returnpos, returnpos, exprpos);
3658 : 18881 : location = M2LexBuf_TokenToLocation (combinedpos);
3659 : 18881 : M2GCCDeclare_TryDeclareConstant (exprpos, expr); /* Checks to see whether it is a constant and declares it. */
3660 : 18881 : M2GCCDeclare_TryDeclareConstructor (exprpos, expr); /* Checks to see whether it is a constant and declares it. */
3661 : 18881 : if ((SymbolTable_IsConstString (expr)) && ((SymbolTable_SkipTypeAndSubrange (SymbolTable_GetType (procedure))) != M2Base_Char))
3662 : : {
3663 : 24 : if (! (M2GenGCC_PrepareCopyString (returnpos, &length, &value, expr, SymbolTable_GetType (procedure))))
3664 : : {
3665 : 0 : M2MetaError_MetaErrorT3 (M2LexBuf_MakeVirtualTok (returnpos, returnpos, exprpos), (const char *) "string constant {%1Ea} is too large to be returned from procedure {%2a} via the {%3d} {%3a}", 91, expr, procedure, SymbolTable_GetType (procedure));
3666 : : }
3667 : 24 : value = m2type_BuildArrayStringConstructor (location, SymbolConversion_Mod2Gcc (SymbolTable_GetType (procedure)), value, length);
3668 : : }
3669 : : else
3670 : : {
3671 : 18857 : value = SymbolConversion_Mod2Gcc (expr);
3672 : : }
3673 : 18881 : m2statement_BuildReturnValueCode (location, SymbolConversion_Mod2Gcc (procedure), value);
3674 : 18881 : }
3675 : :
3676 : :
3677 : : /*
3678 : : CodeCall - determines whether the procedure call is a direct call
3679 : : or an indirect procedure call.
3680 : : */
3681 : :
3682 : 182906 : static void CodeCall (unsigned int tokenno, unsigned int procedure)
3683 : : {
3684 : 182906 : tree callTree;
3685 : 182906 : location_t location;
3686 : :
3687 : 182906 : if (SymbolTable_IsProcedure (procedure))
3688 : : {
3689 : 182234 : M2GCCDeclare_DeclareParameters (procedure);
3690 : 182234 : callTree = CodeDirectCall (tokenno, procedure);
3691 : : }
3692 : 672 : else if (SymbolTable_IsProcType (SymbolTable_SkipType (SymbolTable_GetType (procedure))))
3693 : : {
3694 : : /* avoid dangling else. */
3695 : 672 : M2GCCDeclare_DeclareParameters (SymbolTable_SkipType (SymbolTable_GetType (procedure)));
3696 : 672 : callTree = CodeIndirectCall (tokenno, procedure);
3697 : 672 : procedure = SymbolTable_SkipType (SymbolTable_GetType (procedure));
3698 : : }
3699 : : else
3700 : : {
3701 : : /* avoid dangling else. */
3702 : 0 : M2Error_InternalError ((const char *) "expecting Procedure or ProcType", 31);
3703 : : }
3704 : 182906 : if ((SymbolTable_GetType (procedure)) == SymbolTable_NulSym)
3705 : : {
3706 : 136053 : location = M2LexBuf_TokenToLocation (tokenno);
3707 : 136053 : m2type_AddStatement (location, callTree);
3708 : : }
3709 : : /* Leave tree alone - as it will be picked up when processing FunctValue. */
3710 : 182906 : }
3711 : :
3712 : :
3713 : : /*
3714 : : UseBuiltin - returns a Tree containing the builtin function
3715 : : and parameters. It should only be called if
3716 : : CanUseBuiltin or IsProcedureBuiltinAvailable returns TRUE.
3717 : : */
3718 : :
3719 : 1068 : static tree UseBuiltin (unsigned int tokenno, unsigned int Sym)
3720 : : {
3721 : 1068 : if (m2builtins_BuiltinExists (reinterpret_cast <char * > (NameKey_KeyToCharStar (SymbolTable_GetProcedureBuiltin (Sym)))))
3722 : : {
3723 : 1068 : return m2builtins_BuildBuiltinTree (M2LexBuf_TokenToLocation (tokenno), reinterpret_cast <char * > (NameKey_KeyToCharStar (SymbolTable_GetProcedureBuiltin (Sym))));
3724 : : }
3725 : : else
3726 : : {
3727 : 0 : return m2builtins_BuildBuiltinTree (M2LexBuf_TokenToLocation (tokenno), reinterpret_cast <char * > (NameKey_KeyToCharStar (SymbolTable_GetSymName (Sym))));
3728 : : }
3729 : : /* static analysis guarentees a RETURN statement will be used before here. */
3730 : : __builtin_unreachable ();
3731 : : }
3732 : :
3733 : :
3734 : : /*
3735 : : CodeDirectCall - calls a function/procedure.
3736 : : */
3737 : :
3738 : 182234 : static tree CodeDirectCall (unsigned int tokenno, unsigned int procedure)
3739 : : {
3740 : 182234 : location_t location;
3741 : 182234 : tree call;
3742 : :
3743 : 182234 : location = M2LexBuf_TokenToLocation (tokenno);
3744 : 182234 : if (SymbolTable_IsProcedureBuiltinAvailable (procedure))
3745 : : {
3746 : : /* avoid dangling else. */
3747 : 1062 : call = UseBuiltin (tokenno, procedure);
3748 : 1062 : if (call != NULL)
3749 : : {
3750 : 1062 : call = m2statement_BuildBuiltinCallTree (call);
3751 : : }
3752 : : }
3753 : : else
3754 : : {
3755 : : call = NULL;
3756 : : }
3757 : 1062 : if (call == NULL)
3758 : : {
3759 : : /* avoid gcc warning by using compound statement even if not strictly necessary. */
3760 : 181172 : if ((SymbolTable_GetType (procedure)) == SymbolTable_NulSym)
3761 : : {
3762 : 135433 : call = m2statement_BuildProcedureCallTree (location, SymbolConversion_Mod2Gcc (procedure), NULL);
3763 : : }
3764 : : else
3765 : : {
3766 : 45739 : call = m2statement_BuildProcedureCallTree (location, SymbolConversion_Mod2Gcc (procedure), SymbolConversion_Mod2Gcc (SymbolTable_GetType (procedure)));
3767 : : }
3768 : : }
3769 : 182234 : if ((SymbolTable_GetType (procedure)) == SymbolTable_NulSym)
3770 : : {
3771 : 135457 : m2statement_SetLastFunction (NULL);
3772 : : }
3773 : : else
3774 : : {
3775 : 46777 : m2statement_SetLastFunction (call);
3776 : : }
3777 : 182234 : return call;
3778 : : /* static analysis guarentees a RETURN statement will be used before here. */
3779 : : __builtin_unreachable ();
3780 : : }
3781 : :
3782 : :
3783 : : /*
3784 : : CodeIndirectCall - calls a function/procedure indirectly.
3785 : : */
3786 : :
3787 : 672 : static tree CodeIndirectCall (unsigned int tokenno, unsigned int ProcVar)
3788 : : {
3789 : 672 : tree ReturnType;
3790 : 672 : unsigned int proc;
3791 : 672 : location_t location;
3792 : :
3793 : 672 : location = M2LexBuf_TokenToLocation (tokenno);
3794 : 672 : proc = SymbolTable_SkipType (SymbolTable_GetType (ProcVar));
3795 : 672 : if ((SymbolTable_GetType (proc)) == SymbolTable_NulSym)
3796 : : {
3797 : : ReturnType = (tree) (NULL);
3798 : : }
3799 : : else
3800 : : {
3801 : 76 : ReturnType = (tree) (SymbolConversion_Mod2Gcc (SymbolTable_GetType (proc)));
3802 : : }
3803 : : /* Now we dereference the lvalue if necessary. */
3804 : 672 : if ((SymbolTable_GetMode (ProcVar)) == SymbolTable_LeftValue)
3805 : : {
3806 : 68 : return m2statement_BuildIndirectProcedureCallTree (location, m2expr_BuildIndirect (location, SymbolConversion_Mod2Gcc (ProcVar), SymbolConversion_Mod2Gcc (proc)), ReturnType);
3807 : : }
3808 : : else
3809 : : {
3810 : 604 : return m2statement_BuildIndirectProcedureCallTree (location, SymbolConversion_Mod2Gcc (ProcVar), ReturnType);
3811 : : }
3812 : : /* static analysis guarentees a RETURN statement will be used before here. */
3813 : : __builtin_unreachable ();
3814 : : }
3815 : :
3816 : :
3817 : : /*
3818 : : ConvertTo - convert gcc tree, t, (which currently represents Modula-2 op3) into
3819 : : a symbol of, type.
3820 : : */
3821 : :
3822 : 25722 : static tree ConvertTo (tree t, unsigned int type, unsigned int op3)
3823 : : {
3824 : 25722 : if ((SymbolTable_SkipType (type)) != (SymbolTable_SkipType (SymbolTable_GetType (op3))))
3825 : : {
3826 : 17096 : if ((SymbolTable_IsConst (op3)) && (! (SymbolTable_IsConstString (op3))))
3827 : : {
3828 : 1616 : SymbolTable_PushValue (op3);
3829 : 1616 : return m2convert_BuildConvert (M2LexBuf_TokenToLocation (SymbolTable_GetDeclaredMod (op3)), SymbolConversion_Mod2Gcc (type), t, false);
3830 : : }
3831 : : }
3832 : : return t;
3833 : : /* static analysis guarentees a RETURN statement will be used before here. */
3834 : : __builtin_unreachable ();
3835 : : }
3836 : :
3837 : :
3838 : : /*
3839 : : ConvertRHS - convert (t, rhs) into, type. (t, rhs) refer to the
3840 : : same entity t is a GCC Tree and, rhs, is a Modula-2
3841 : : symbol. It checks for char and strings
3842 : : first and then the remaining types.
3843 : : */
3844 : :
3845 : 25722 : static tree ConvertRHS (tree t, unsigned int type, unsigned int rhs)
3846 : : {
3847 : 25722 : t = M2GenGCC_StringToChar (SymbolConversion_Mod2Gcc (rhs), type, rhs);
3848 : 25722 : return ConvertTo (t, type, rhs);
3849 : : /* static analysis guarentees a RETURN statement will be used before here. */
3850 : : __builtin_unreachable ();
3851 : : }
3852 : :
3853 : :
3854 : : /*
3855 : : IsCoerceableParameter - returns TRUE if symbol, sym, is a
3856 : : coerceable parameter.
3857 : : */
3858 : :
3859 : 346888 : static bool IsCoerceableParameter (unsigned int sym)
3860 : : {
3861 : 346888 : return ((((((SymbolTable_IsSet (sym)) || (((M2Base_IsOrdinalType (sym)) && (sym != M2Base_Boolean)) && (! (SymbolTable_IsEnumeration (sym))))) || (M2Base_IsComplexType (sym))) || (M2Base_IsRealType (sym))) || (M2System_IsComplexN (sym))) || (M2System_IsRealN (sym))) || (M2System_IsSetN (sym));
3862 : : /* static analysis guarentees a RETURN statement will be used before here. */
3863 : : __builtin_unreachable ();
3864 : : }
3865 : :
3866 : :
3867 : : /*
3868 : : IsConstProcedure - returns TRUE if, p, is a const procedure.
3869 : : */
3870 : :
3871 : 580 : static bool IsConstProcedure (unsigned int p)
3872 : : {
3873 : 580 : return ((SymbolTable_IsConst (p)) && ((SymbolTable_GetType (p)) != SymbolTable_NulSym)) && (SymbolTable_IsProcType (SymbolTable_GetType (p)));
3874 : : /* static analysis guarentees a RETURN statement will be used before here. */
3875 : : __builtin_unreachable ();
3876 : : }
3877 : :
3878 : :
3879 : : /*
3880 : : IsConstant - returns TRUE if symbol, p, is either a const or procedure.
3881 : : */
3882 : :
3883 : 716955 : static bool IsConstant (unsigned int p)
3884 : : {
3885 : 716955 : return (SymbolTable_IsConst (p)) || (SymbolTable_IsProcedure (p));
3886 : : /* static analysis guarentees a RETURN statement will be used before here. */
3887 : : __builtin_unreachable ();
3888 : : }
3889 : :
3890 : :
3891 : : /*
3892 : : CheckConvertCoerceParameter - ensure that actual parameter is the same as the nth of callee.
3893 : : */
3894 : :
3895 : 474648 : static tree CheckConvertCoerceParameter (unsigned int tokenno, unsigned int nth, unsigned int callee, unsigned int actual)
3896 : : {
3897 : 474648 : unsigned int OperandType;
3898 : 474648 : unsigned int ParamType;
3899 : 474648 : location_t location;
3900 : :
3901 : 474648 : location = M2LexBuf_TokenToLocation (tokenno);
3902 : 474648 : if ((SymbolTable_GetNthParamAny (callee, nth)) == SymbolTable_NulSym)
3903 : : {
3904 : : /* We reach here if the argument is being passed to a C vararg function. */
3905 : 6004 : return SymbolConversion_Mod2Gcc (actual);
3906 : : }
3907 : : else
3908 : : {
3909 : 468644 : OperandType = SymbolTable_SkipType (SymbolTable_GetType (actual));
3910 : 468644 : ParamType = SymbolTable_SkipType (SymbolTable_GetType (SymbolTable_GetNthParamAny (callee, nth)));
3911 : : }
3912 : 468644 : if (SymbolTable_IsProcType (ParamType))
3913 : : {
3914 : 44971 : if (((SymbolTable_IsProcedure (actual)) || (IsConstProcedure (actual))) || (OperandType == ParamType))
3915 : : {
3916 : 44907 : return SymbolConversion_Mod2Gcc (actual);
3917 : : }
3918 : : else
3919 : : {
3920 : 64 : return m2convert_BuildConvert (location, SymbolConversion_Mod2Gcc (ParamType), SymbolConversion_Mod2Gcc (actual), false);
3921 : : }
3922 : : }
3923 : 423673 : else if (((M2Base_IsRealType (OperandType)) && (M2Base_IsRealType (ParamType))) && (ParamType != OperandType))
3924 : : {
3925 : : /* avoid dangling else. */
3926 : : /* SHORTREAL, LONGREAL and REAL conversion during parameter passing. */
3927 : 1962 : return m2convert_BuildConvert (location, SymbolConversion_Mod2Gcc (ParamType), SymbolConversion_Mod2Gcc (actual), false);
3928 : : }
3929 : 421711 : else if (((OperandType != SymbolTable_NulSym) && (SymbolTable_IsSet (OperandType))) && (SymbolTable_IsConst (actual)))
3930 : : {
3931 : : /* avoid dangling else. */
3932 : 502 : return m2decl_DeclareKnownConstant (location, SymbolConversion_Mod2Gcc (ParamType), SymbolConversion_Mod2Gcc (actual));
3933 : : }
3934 : 421209 : else if ((SymbolTable_IsConst (actual)) && ((M2Base_IsOrdinalType (ParamType)) || (M2System_IsSystemType (ParamType))))
3935 : : {
3936 : : /* avoid dangling else. */
3937 : 74297 : return m2convert_BuildConvert (location, SymbolConversion_Mod2Gcc (ParamType), M2GenGCC_StringToChar (SymbolConversion_Mod2Gcc (actual), ParamType, actual), false);
3938 : : }
3939 : 346912 : else if ((SymbolTable_IsConstString (actual)) || (((OperandType != SymbolTable_NulSym) && (IsCoerceableParameter (OperandType))) && (OperandType != ParamType)))
3940 : : {
3941 : : /* avoid dangling else. */
3942 : 4104 : return m2convert_BuildConvert (location, SymbolConversion_Mod2Gcc (ParamType), SymbolConversion_Mod2Gcc (actual), false);
3943 : : }
3944 : : else
3945 : : {
3946 : : /* avoid dangling else. */
3947 : 342808 : return SymbolConversion_Mod2Gcc (actual);
3948 : : }
3949 : : /* static analysis guarentees a RETURN statement will be used before here. */
3950 : : __builtin_unreachable ();
3951 : : }
3952 : :
3953 : :
3954 : : /*
3955 : : CheckConstant - checks to see whether we should declare the constant.
3956 : : */
3957 : :
3958 : 6 : static tree CheckConstant (unsigned int tokenno, unsigned int des, unsigned int expr)
3959 : : {
3960 : 6 : location_t location;
3961 : :
3962 : 6 : location = M2LexBuf_TokenToLocation (tokenno);
3963 : 6 : if (SymbolTable_IsProcedure (expr))
3964 : : {
3965 : 0 : return SymbolConversion_Mod2Gcc (expr);
3966 : : }
3967 : : else
3968 : : {
3969 : 6 : return m2decl_DeclareKnownConstant (location, SymbolConversion_Mod2Gcc (SymbolTable_GetType (des)), SymbolConversion_Mod2Gcc (expr));
3970 : : }
3971 : : /* static analysis guarentees a RETURN statement will be used before here. */
3972 : : __builtin_unreachable ();
3973 : : }
3974 : :
3975 : :
3976 : : /*
3977 : : CodeMakeAdr - code the function MAKEADR.
3978 : : */
3979 : :
3980 : 0 : static void CodeMakeAdr (unsigned int q, unsigned int op1, unsigned int op2, unsigned int op3)
3981 : : {
3982 : 0 : unsigned int r;
3983 : 0 : unsigned int n;
3984 : 0 : unsigned int type;
3985 : 0 : M2Quads_QuadOperator op;
3986 : 0 : tree bits;
3987 : 0 : tree max;
3988 : 0 : tree tmp;
3989 : 0 : tree res;
3990 : 0 : tree val;
3991 : 0 : location_t location;
3992 : :
3993 : 0 : location = M2LexBuf_TokenToLocation (CurrentQuadToken);
3994 : 0 : n = q;
3995 : 0 : do {
3996 : 0 : if (op1 > 0)
3997 : : {
3998 : 0 : M2GCCDeclare_DeclareConstant (CurrentQuadToken, op3);
3999 : : }
4000 : 0 : n = M2Quads_GetNextQuad (n);
4001 : 0 : M2Quads_GetQuad (n, &op, &r, &op2, &op3);
4002 : 0 : } while (! (op == M2Quads_FunctValueOp));
4003 : 0 : n = q;
4004 : 0 : M2Quads_GetQuad (n, &op, &op1, &op2, &op3);
4005 : 0 : res = SymbolConversion_Mod2Gcc (r);
4006 : 0 : max = m2expr_GetSizeOfInBits (SymbolConversion_Mod2Gcc (M2System_Address));
4007 : 0 : bits = m2expr_GetIntegerZero (location);
4008 : 0 : val = m2expr_GetPointerZero (location);
4009 : 0 : do {
4010 : 0 : location = M2LexBuf_TokenToLocation (CurrentQuadToken);
4011 : 0 : if ((op == M2Quads_ParamOp) && (op1 > 0))
4012 : : {
4013 : : /* avoid gcc warning by using compound statement even if not strictly necessary. */
4014 : 0 : if ((SymbolTable_GetType (op3)) == SymbolTable_NulSym)
4015 : : {
4016 : 0 : M2Error_WriteFormat0 ((const char *) "must supply typed constants to MAKEADR", 38);
4017 : : }
4018 : : else
4019 : : {
4020 : 0 : type = SymbolTable_GetType (op3);
4021 : 0 : tmp = m2convert_BuildConvert (location, m2type_GetPointerType (), SymbolConversion_Mod2Gcc (op3), false);
4022 : 0 : if ((m2expr_CompareTrees (bits, m2expr_GetIntegerZero (location))) > 0)
4023 : : {
4024 : 0 : tmp = m2expr_BuildLSL (location, tmp, bits, false);
4025 : : }
4026 : 0 : bits = m2expr_BuildAdd (location, bits, m2expr_GetSizeOfInBits (SymbolConversion_Mod2Gcc (type)), false);
4027 : 0 : val = m2expr_BuildLogicalOrAddress (location, val, tmp, false);
4028 : : }
4029 : : }
4030 : 0 : M2Quads_SubQuad (n);
4031 : 0 : n = M2Quads_GetNextQuad (n);
4032 : 0 : M2Quads_GetQuad (n, &op, &op1, &op2, &op3);
4033 : 0 : } while (! (op == M2Quads_FunctValueOp));
4034 : 0 : if ((m2expr_CompareTrees (bits, max)) > 0)
4035 : : {
4036 : 0 : M2MetaError_MetaErrorT0 (CurrentQuadToken, (const char *) "total number of bits specified as parameters to {%kMAKEADR} exceeds address width", 81);
4037 : : }
4038 : 0 : M2Quads_SubQuad (n);
4039 : 0 : m2statement_BuildAssignmentStatement (location, res, val);
4040 : 0 : }
4041 : :
4042 : :
4043 : : /*
4044 : : CodeBuiltinFunction - attempts to inline a function. Currently it only
4045 : : inlines the SYSTEM function MAKEADR.
4046 : : */
4047 : :
4048 : 46853 : static void CodeBuiltinFunction (unsigned int q, unsigned int nth, unsigned int func, unsigned int parameter)
4049 : : {
4050 : 46853 : if (nth == 0)
4051 : : {
4052 : 46853 : InitBuiltinSyms (M2LexBuf_BuiltinTokenNo);
4053 : 46853 : if (func == M2System_MakeAdr)
4054 : : {
4055 : 0 : CodeMakeAdr (q, nth, func, parameter);
4056 : : }
4057 : : }
4058 : 46853 : }
4059 : :
4060 : :
4061 : : /*
4062 : : FoldMakeAdr - attempts to fold the function MAKEADR.
4063 : : */
4064 : :
4065 : 12 : static void FoldMakeAdr (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int q, unsigned int op1, unsigned int op2, unsigned int op3)
4066 : : {
4067 : 12 : bool resolved;
4068 : 12 : unsigned int r;
4069 : 12 : unsigned int n;
4070 : 12 : M2Quads_QuadOperator op;
4071 : 12 : unsigned int type;
4072 : 12 : tree bits;
4073 : 12 : tree max;
4074 : 12 : tree tmp;
4075 : 12 : tree val;
4076 : 12 : location_t location;
4077 : :
4078 : 12 : location = M2LexBuf_TokenToLocation (tokenno);
4079 : 12 : resolved = true;
4080 : 12 : n = q;
4081 : 12 : r = op1;
4082 : 24 : do {
4083 : 24 : if (r > 0)
4084 : : {
4085 : 12 : M2GCCDeclare_TryDeclareConstant (tokenno, op3);
4086 : 12 : if (! (SymbolConversion_GccKnowsAbout (op3)))
4087 : : {
4088 : 24 : resolved = false;
4089 : : }
4090 : : }
4091 : 24 : n = M2Quads_GetNextQuad (n);
4092 : 24 : M2Quads_GetQuad (n, &op, &r, &op2, &op3);
4093 : 24 : } while (! (op == M2Quads_FunctValueOp));
4094 : 12 : if (resolved && (SymbolTable_IsConst (r)))
4095 : : {
4096 : 12 : n = q;
4097 : 12 : M2Quads_GetQuad (n, &op, &op1, &op2, &op3);
4098 : 12 : max = m2expr_GetSizeOfInBits (SymbolConversion_Mod2Gcc (M2System_Address));
4099 : 12 : bits = m2expr_GetIntegerZero (location);
4100 : 12 : val = m2expr_GetPointerZero (location);
4101 : 24 : do {
4102 : 24 : location = M2LexBuf_TokenToLocation (tokenno);
4103 : 24 : if ((op == M2Quads_ParamOp) && (op1 > 0))
4104 : : {
4105 : : /* avoid gcc warning by using compound statement even if not strictly necessary. */
4106 : 12 : if ((SymbolTable_GetType (op3)) == SymbolTable_NulSym)
4107 : : {
4108 : 0 : M2MetaError_MetaErrorT0 (tokenno, (const char *) "constants passed to {%kMAKEADR} must be typed", 45);
4109 : : }
4110 : : else
4111 : : {
4112 : 12 : type = SymbolTable_GetType (op3);
4113 : 12 : tmp = m2convert_BuildConvert (location, m2type_GetPointerType (), SymbolConversion_Mod2Gcc (op3), false);
4114 : 12 : if ((m2expr_CompareTrees (bits, m2expr_GetIntegerZero (location))) > 0)
4115 : : {
4116 : 0 : tmp = m2expr_BuildLSL (location, tmp, bits, false);
4117 : : }
4118 : 12 : bits = m2expr_BuildAdd (location, bits, m2expr_GetSizeOfInBits (SymbolConversion_Mod2Gcc (type)), false);
4119 : 12 : val = m2expr_BuildLogicalOrAddress (location, val, tmp, false);
4120 : : }
4121 : : }
4122 : 24 : M2Quads_SubQuad (n);
4123 : 24 : n = M2Quads_GetNextQuad (n);
4124 : 24 : M2Quads_GetQuad (n, &op, &op1, &op2, &op3);
4125 : 24 : } while (! (op == M2Quads_FunctValueOp));
4126 : 12 : if ((m2expr_CompareTrees (bits, max)) > 0)
4127 : : {
4128 : 0 : M2MetaError_MetaErrorT0 (tokenno, (const char *) "total number of bits specified as parameters to {%kMAKEADR} exceeds address width", 81);
4129 : : }
4130 : 12 : SymbolTable_PutConst (r, M2System_Address);
4131 : 12 : SymbolConversion_AddModGcc (r, m2decl_DeclareKnownConstant (location, SymbolConversion_Mod2Gcc (M2System_Address), val));
4132 : 12 : (*p.proc) (r);
4133 : 12 : NoChange = false;
4134 : 12 : M2Quads_SubQuad (n);
4135 : : }
4136 : 12 : }
4137 : :
4138 : :
4139 : : /*
4140 : : doParam - builds the parameter, op3, which is to be passed to
4141 : : procedure, op2. The number of the parameter is op1.
4142 : : */
4143 : :
4144 : 474648 : static void doParam (unsigned int quad, unsigned int paramtok, unsigned int op1, unsigned int op2, unsigned int op3)
4145 : : {
4146 : 474648 : location_t location;
4147 : :
4148 : 474648 : location = M2LexBuf_TokenToLocation (paramtok);
4149 : 474648 : M2GCCDeclare_DeclareConstant (paramtok, op3);
4150 : 474648 : M2GCCDeclare_DeclareConstructor (paramtok, quad, op3);
4151 : 474648 : m2statement_BuildParam (location, CheckConvertCoerceParameter (paramtok, op1, op2, op3));
4152 : 474648 : }
4153 : :
4154 : :
4155 : : /*
4156 : : FoldBuiltin - attempts to fold the gcc builtin function.
4157 : : */
4158 : :
4159 : 15432 : static void FoldBuiltin (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int q)
4160 : : {
4161 : 15432 : bool resolved;
4162 : 15432 : unsigned int procedure;
4163 : 15432 : unsigned int r;
4164 : 15432 : unsigned int n;
4165 : 15432 : unsigned int op1;
4166 : 15432 : unsigned int op2;
4167 : 15432 : unsigned int op3;
4168 : 15432 : M2Quads_QuadOperator op;
4169 : 15432 : tree val;
4170 : 15432 : tree call;
4171 : 15432 : location_t location;
4172 : :
4173 : 15432 : M2Quads_GetQuad (q, &op, &op1, &op2, &op3);
4174 : 15432 : resolved = true;
4175 : 15432 : procedure = SymbolTable_NulSym;
4176 : 15432 : n = q;
4177 : 15432 : r = op1;
4178 : 48340 : do {
4179 : 48340 : if (r > 0)
4180 : : {
4181 : 17476 : M2GCCDeclare_TryDeclareConstant (tokenno, op3);
4182 : 17476 : if (! (SymbolConversion_GccKnowsAbout (op3)))
4183 : : {
4184 : 48340 : resolved = false;
4185 : : }
4186 : : }
4187 : 48340 : if ((op == M2Quads_CallOp) && (! (SymbolTable_IsProcedure (op3))))
4188 : : {
4189 : : /* Cannot fold an indirect procedure function call. */
4190 : : resolved = false;
4191 : : }
4192 : 48340 : n = M2Quads_GetNextQuad (n);
4193 : 48340 : M2Quads_GetQuad (n, &op, &r, &op2, &op3);
4194 : 48340 : } while (! (op == M2Quads_FunctValueOp));
4195 : 15432 : if (resolved && (SymbolTable_IsConst (r)))
4196 : : {
4197 : 6 : n = q;
4198 : 6 : M2Quads_GetQuad (n, &op, &op1, &op2, &op3);
4199 : 18 : do {
4200 : 18 : if ((op == M2Quads_ParamOp) && (op1 > 0))
4201 : : {
4202 : 6 : doParam (tokenno, n, op1, op2, op3);
4203 : : }
4204 : 12 : else if (op == M2Quads_CallOp)
4205 : : {
4206 : : /* avoid dangling else. */
4207 : 6 : procedure = op3;
4208 : : }
4209 : 18 : M2Quads_SubQuad (n);
4210 : 18 : n = M2Quads_GetNextQuad (n);
4211 : 18 : M2Quads_GetQuad (n, &op, &op1, &op2, &op3);
4212 : 18 : } while (! (op == M2Quads_FunctValueOp));
4213 : 6 : if (SymbolTable_IsProcedureBuiltinAvailable (procedure))
4214 : : {
4215 : 6 : location = M2LexBuf_TokenToLocation (tokenno);
4216 : 6 : call = UseBuiltin (tokenno, procedure);
4217 : 6 : val = m2statement_BuildFunctValue (location, call);
4218 : 6 : val = m2expr_FoldAndStrip (val);
4219 : 6 : SymbolTable_PutConst (r, SymbolTable_GetType (procedure));
4220 : 6 : SymbolConversion_AddModGcc (r, m2decl_DeclareKnownConstant (location, SymbolConversion_Mod2Gcc (SymbolTable_GetType (procedure)), val));
4221 : 6 : (*p.proc) (r);
4222 : 6 : m2statement_SetLastFunction (NULL);
4223 : : }
4224 : : else
4225 : : {
4226 : 0 : M2MetaError_MetaErrorT1 (tokenno, (const char *) "gcc builtin procedure {%1Ead} cannot be used in a constant expression", 69, procedure);
4227 : : }
4228 : 6 : NoChange = false;
4229 : 6 : M2Quads_SubQuad (n);
4230 : : }
4231 : 15432 : }
4232 : :
4233 : :
4234 : : /*
4235 : : FoldBuiltinFunction - attempts to inline a function. Currently it only
4236 : : inlines the SYSTEM function MAKEADR.
4237 : : */
4238 : :
4239 : 6079537 : static void FoldBuiltinFunction (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int q, unsigned int op1, unsigned int op2, unsigned int op3)
4240 : : {
4241 : 6079537 : if (op1 == 0)
4242 : : {
4243 : : /* avoid gcc warning by using compound statement even if not strictly necessary. */
4244 : : /* Must be a function as op1 is the return parameter. */
4245 : 738087 : if (op3 == M2System_MakeAdr)
4246 : : {
4247 : 12 : FoldMakeAdr (tokenno, p, q, op1, op2, op3);
4248 : : }
4249 : 738075 : else if ((SymbolTable_IsProcedure (op3)) && (SymbolTable_IsProcedureBuiltinAvailable (op3)))
4250 : : {
4251 : : /* avoid dangling else. */
4252 : 15432 : FoldBuiltin (tokenno, p, q);
4253 : : }
4254 : : }
4255 : 6079537 : }
4256 : :
4257 : :
4258 : : /*
4259 : : CodeParam - builds a parameter list.
4260 : : Note that we can ignore ModeOfAddr as any lvalue will
4261 : : have been created in a preceeding quadruple.
4262 : : */
4263 : :
4264 : 521543 : static void CodeParam (unsigned int quad)
4265 : : {
4266 : 521543 : unsigned int nopos;
4267 : 521543 : unsigned int procedure;
4268 : 521543 : unsigned int parameter;
4269 : 521543 : unsigned int parampos;
4270 : 521543 : unsigned int nth;
4271 : 521543 : bool compatible;
4272 : 521543 : bool constExpr;
4273 : 521543 : bool overflow;
4274 : 521543 : M2Quads_QuadOperator op;
4275 : :
4276 : 521543 : M2Quads_GetQuadOtok (quad, ¶mpos, &op, &nth, &procedure, ¶meter, &overflow, &constExpr, &nopos, &nopos, &nopos);
4277 : 521543 : compatible = true;
4278 : 521543 : if (nth == 0)
4279 : : {
4280 : 46853 : CodeBuiltinFunction (quad, nth, procedure, parameter);
4281 : : }
4282 : : else
4283 : : {
4284 : 474690 : if (M2Options_StrictTypeChecking)
4285 : : {
4286 : 474690 : if (nth <= (SymbolTable_NoOfParamAny (procedure)))
4287 : : {
4288 : 468686 : compatible = M2Check_ParameterTypeCompatible (parampos, (const char *) "parameter incompatibility when attempting to pass actual parameter {%2ad} to a {%kVAR} formal parameter {%3Ead} during call to procedure {%1ad}", 143, procedure, SymbolTable_GetNthParamAny (procedure, nth), parameter, nth, SymbolTable_IsVarParamAny (procedure, nth));
4289 : : }
4290 : : }
4291 : 474690 : if (((nth <= (SymbolTable_NoOfParamAny (procedure))) && (SymbolTable_IsVarParamAny (procedure, nth))) && (SymbolTable_IsConst (parameter)))
4292 : : {
4293 : 0 : M2MetaError_MetaErrorT1 (parampos, (const char *) "cannot pass a constant {%1Ead} as a VAR parameter", 49, parameter);
4294 : : }
4295 : 474690 : else if (SymbolTable_IsAModula2Type (parameter))
4296 : : {
4297 : : /* avoid dangling else. */
4298 : 0 : M2MetaError_MetaErrorT2 (parampos, (const char *) "cannot pass a type {%1Ead} as a parameter to procedure {%2ad}", 61, parameter, procedure);
4299 : : }
4300 : 474690 : else if (compatible)
4301 : : {
4302 : : /* avoid dangling else. */
4303 : 474642 : doParam (quad, parampos, nth, procedure, parameter);
4304 : : }
4305 : : }
4306 : 521543 : }
4307 : :
4308 : :
4309 : : /*
4310 : : Replace - replace the entry for sym in the double entry bookkeeping with sym/tree.
4311 : : */
4312 : :
4313 : 0 : static void Replace (unsigned int sym, tree gcc)
4314 : : {
4315 : 0 : if (SymbolConversion_GccKnowsAbout (sym))
4316 : : {
4317 : 0 : SymbolConversion_RemoveMod2Gcc (sym);
4318 : : }
4319 : 0 : SymbolConversion_AddModGcc (sym, gcc);
4320 : 0 : }
4321 : :
4322 : :
4323 : : /*
4324 : : CodeFunctValue - retrieves the function return value and assigns it
4325 : : into a variable.
4326 : : */
4327 : :
4328 : 46853 : static void CodeFunctValue (location_t location, unsigned int op1)
4329 : : {
4330 : 46853 : tree call;
4331 : 46853 : tree value;
4332 : :
4333 : : /*
4334 : : operator : FunctValueOp
4335 : : op1 : The Returned Variable
4336 : : op3 : The Function Returning this Variable
4337 : : */
4338 : 46853 : if (M2SSA_EnableSSA && (SymbolTable_IsVariableSSA (op1)))
4339 : : {
4340 : : call = m2statement_GetLastFunction ();
4341 : : m2statement_SetLastFunction (NULL);
4342 : : Replace (op1, call);
4343 : : }
4344 : : else
4345 : : {
4346 : 46853 : value = m2statement_BuildFunctValue (location, SymbolConversion_Mod2Gcc (op1));
4347 : : /* AddStatement (location, CheckCleanup (location, op3, value, call)) */
4348 : 46853 : m2type_AddStatement (location, value);
4349 : : }
4350 : 46853 : }
4351 : :
4352 : :
4353 : : /*
4354 : : FoldStringLength -
4355 : : */
4356 : :
4357 : 72 : static void FoldStringLength (unsigned int quad, M2GCCDeclare_WalkAction p)
4358 : : {
4359 : 72 : M2Quads_QuadOperator op;
4360 : 72 : unsigned int des;
4361 : 72 : unsigned int none;
4362 : 72 : unsigned int expr;
4363 : 72 : unsigned int stroppos;
4364 : 72 : unsigned int despos;
4365 : 72 : unsigned int nonepos;
4366 : 72 : unsigned int exprpos;
4367 : 72 : bool constExpr;
4368 : 72 : bool overflowChecking;
4369 : 72 : location_t location;
4370 : :
4371 : 72 : M2Quads_GetQuadOtok (quad, &stroppos, &op, &des, &none, &expr, &overflowChecking, &constExpr, &despos, &nonepos, &exprpos);
4372 : 72 : if ((IsConstStr (expr)) && (IsConstStrKnown (expr)))
4373 : : {
4374 : 66 : location = M2LexBuf_TokenToLocation (stroppos);
4375 : 66 : M2ALU_PushCard (SymbolTable_GetStringLength (exprpos, expr));
4376 : 66 : SymbolConversion_AddModGcc (des, m2convert_BuildConvert (location, SymbolConversion_Mod2Gcc (SymbolTable_GetType (des)), M2ALU_PopIntegerTree (), false));
4377 : 132 : RemoveQuad (p, des, quad);
4378 : : }
4379 : 72 : }
4380 : :
4381 : :
4382 : : /*
4383 : : FoldStringConvertM2nul - attempt to assign the des with the string contents from expr.
4384 : : It also marks the des as a m2 string which must be nul terminated.
4385 : : The front end uses double book keeping and it is easier to have
4386 : : different m2 string symbols each of which map onto a slightly different
4387 : : gcc string tree.
4388 : : */
4389 : :
4390 : 31629 : static void FoldStringConvertM2nul (unsigned int quad, M2GCCDeclare_WalkAction p)
4391 : : {
4392 : 31629 : M2Quads_QuadOperator op;
4393 : 31629 : unsigned int des;
4394 : 31629 : unsigned int none;
4395 : 31629 : unsigned int expr;
4396 : 31629 : unsigned int stroppos;
4397 : 31629 : unsigned int despos;
4398 : 31629 : unsigned int nonepos;
4399 : 31629 : unsigned int exprpos;
4400 : 31629 : DynamicStrings_String s;
4401 : 31629 : bool constExpr;
4402 : 31629 : bool overflowChecking;
4403 : :
4404 : 31629 : M2Quads_GetQuadOtok (quad, &stroppos, &op, &des, &none, &expr, &overflowChecking, &constExpr, &despos, &nonepos, &exprpos);
4405 : 31629 : if ((IsConstStr (expr)) && (IsConstStrKnown (expr)))
4406 : : {
4407 : 31629 : s = GetStr (exprpos, expr);
4408 : 31629 : SymbolTable_PutConstStringKnown (stroppos, des, NameKey_makekey (DynamicStrings_string (s)), false, true);
4409 : 31629 : M2GCCDeclare_TryDeclareConstant (despos, des);
4410 : 31629 : (*p.proc) (des);
4411 : 31629 : NoChange = false;
4412 : 31629 : M2Quads_SubQuad (quad);
4413 : 31629 : s = DynamicStrings_KillString (s);
4414 : : }
4415 : 31629 : }
4416 : :
4417 : :
4418 : : /*
4419 : : FoldStringConvertCnul -attempt to assign the des with the string contents from expr.
4420 : : It also marks the des as a C string which must be nul terminated.
4421 : : */
4422 : :
4423 : 8001 : static void FoldStringConvertCnul (unsigned int quad, M2GCCDeclare_WalkAction p)
4424 : : {
4425 : 8001 : M2Quads_QuadOperator op;
4426 : 8001 : unsigned int des;
4427 : 8001 : unsigned int none;
4428 : 8001 : unsigned int expr;
4429 : 8001 : unsigned int stroppos;
4430 : 8001 : unsigned int despos;
4431 : 8001 : unsigned int nonepos;
4432 : 8001 : unsigned int exprpos;
4433 : 8001 : DynamicStrings_String s;
4434 : 8001 : bool constExpr;
4435 : 8001 : bool overflowChecking;
4436 : :
4437 : 8001 : M2Quads_GetQuadOtok (quad, &stroppos, &op, &des, &none, &expr, &overflowChecking, &constExpr, &despos, &nonepos, &exprpos);
4438 : 8001 : if ((IsConstStr (expr)) && (IsConstStrKnown (expr)))
4439 : : {
4440 : 7977 : s = GetStr (exprpos, expr);
4441 : 7977 : SymbolTable_PutConstStringKnown (stroppos, des, NameKey_makekey (DynamicStrings_string (s)), true, true);
4442 : 7977 : M2GCCDeclare_TryDeclareConstant (despos, des);
4443 : 7977 : (*p.proc) (des);
4444 : 7977 : NoChange = false;
4445 : 7977 : M2Quads_SubQuad (quad);
4446 : 7977 : s = DynamicStrings_KillString (s);
4447 : : }
4448 : 8001 : }
4449 : :
4450 : 179409 : static void CodeAddr (unsigned int tokenno, unsigned int quad, unsigned int op1, unsigned int op3)
4451 : : {
4452 : 179409 : tree value;
4453 : 179409 : unsigned int type;
4454 : 179409 : location_t location;
4455 : :
4456 : : /*
4457 : : Addr Operator - generates the address of a variable (op1 = &op3).
4458 : : */
4459 : 179409 : if ((SymbolTable_IsConst (op3)) && (! (SymbolTable_IsConstString (op3))))
4460 : : {
4461 : 6 : M2MetaError_MetaErrorT1 (tokenno, (const char *) "error in expression, trying to find the address of a constant {%1Ead}", 69, op3);
4462 : : }
4463 : : else
4464 : : {
4465 : 179403 : if ((SymbolTable_IsConstString (op3)) && (! (SymbolTable_IsConstStringKnown (op3))))
4466 : : {
4467 : 0 : M2Printf_printf1 ((const char *) "failure in quad: %d\\n", 21, (const unsigned char *) &quad, (sizeof (quad)-1));
4468 : : }
4469 : 179403 : location = M2LexBuf_TokenToLocation (tokenno);
4470 : 179403 : type = SymbolTable_SkipType (SymbolTable_GetType (op3));
4471 : 179403 : M2GCCDeclare_DeclareConstant (tokenno, op3); /* We might be asked to find the address of a constant string. */
4472 : 179403 : M2GCCDeclare_DeclareConstructor (tokenno, quad, op3); /* We might be asked to find the address of a constant string. */
4473 : 179403 : if (((SymbolTable_IsConst (op3)) && (type == M2Base_Char)) || (SymbolTable_IsConstString (op3)))
4474 : : {
4475 : 165137 : value = m2decl_BuildStringConstant (const_cast <const char * > (static_cast <char * > (NameKey_KeyToCharStar (SymbolTable_GetString (op3)))), static_cast<int> (SymbolTable_GetStringLength (tokenno, op3)));
4476 : : }
4477 : : else
4478 : : {
4479 : 14266 : value = SymbolConversion_Mod2Gcc (op3);
4480 : : }
4481 : 179403 : m2statement_BuildAssignmentStatement (location, SymbolConversion_Mod2Gcc (op1), m2expr_BuildAddr (location, value, false));
4482 : : }
4483 : 179409 : }
4484 : :
4485 : 0 : static void stop (void)
4486 : : {
4487 : 0 : }
4488 : :
4489 : 0 : static void CheckStop (unsigned int q)
4490 : : {
4491 : 0 : if (q == 3827)
4492 : : {
4493 : 0 : stop ();
4494 : : }
4495 : 0 : }
4496 : :
4497 : 3605680 : static void FoldBecomes (M2GCCDeclare_WalkAction p, M2BasicBlock_BasicBlock bb, unsigned int quad)
4498 : : {
4499 : 3605680 : M2Quads_QuadOperator op;
4500 : 3605680 : unsigned int des;
4501 : 3605680 : unsigned int op2;
4502 : 3605680 : unsigned int expr;
4503 : :
4504 : : /*
4505 : : ------------------------------------------------------------------------------
4506 : : := Operator
4507 : : ------------------------------------------------------------------------------
4508 : : Sym1<I> := Sym3<I> := produces a constant
4509 : : */
4510 : 3605680 : if (DeclaredOperandsBecomes (p, quad))
4511 : : {
4512 : 252660 : if ((! (M2Quads_IsConditionalBooleanQuad (quad))) || (M2BasicBlock_IsBasicBlockFirst (bb)))
4513 : : {
4514 : 248628 : if (TypeCheckBecomes (p, quad))
4515 : : {
4516 : 248628 : PerformFoldBecomes (p, quad);
4517 : : }
4518 : : }
4519 : : }
4520 : 3605680 : }
4521 : :
4522 : :
4523 : : /*
4524 : : TryDeclareConst -
4525 : : */
4526 : :
4527 : 3605680 : static void TryDeclareConst (unsigned int tokenno, unsigned int sym)
4528 : : {
4529 : : /* Check whether expr is a constant literal and if so declare it. */
4530 : 3605680 : M2GCCDeclare_TryDeclareConstant (tokenno, sym);
4531 : : /* Check whether expr is a const constructor and if so declare it. */
4532 : 3605680 : M2GCCDeclare_TryDeclareConstructor (tokenno, sym);
4533 : 3605680 : }
4534 : :
4535 : :
4536 : : /*
4537 : : RemoveQuad - remove quad and ensure p (des) is called.
4538 : : */
4539 : :
4540 : 248338 : static void RemoveQuad (M2GCCDeclare_WalkAction p, unsigned int des, unsigned int quad)
4541 : : {
4542 : 66 : (*p.proc) (des);
4543 : 248338 : NoChange = false;
4544 : 248338 : M2Quads_SubQuad (quad);
4545 : 0 : }
4546 : :
4547 : :
4548 : : /*
4549 : : DeclaredOperandsBecomes -
4550 : : */
4551 : :
4552 : 3605680 : static bool DeclaredOperandsBecomes (M2GCCDeclare_WalkAction p, unsigned int quad)
4553 : : {
4554 : 3605680 : unsigned int des;
4555 : 3605680 : unsigned int op2;
4556 : 3605680 : unsigned int expr;
4557 : 3605680 : bool constExpr;
4558 : 3605680 : bool overflowChecking;
4559 : 3605680 : unsigned int despos;
4560 : 3605680 : unsigned int op2pos;
4561 : 3605680 : unsigned int exprpos;
4562 : 3605680 : unsigned int becomespos;
4563 : 3605680 : M2Quads_QuadOperator op;
4564 : :
4565 : 3605680 : M2Quads_GetQuadOtok (quad, &becomespos, &op, &des, &op2, &expr, &overflowChecking, &constExpr, &despos, &op2pos, &exprpos);
4566 : 3605680 : M2Debug_Assert (op2pos == M2LexBuf_UnknownTokenNo);
4567 : 3605680 : TryDeclareConst (exprpos, expr);
4568 : 3605680 : if ((SymbolTable_IsConst (des)) && (IsConstant (expr)))
4569 : : {
4570 : : /* Constant folding taking place, but have we resolved op3 yet? */
4571 : 259832 : if (SymbolConversion_GccKnowsAbout (expr))
4572 : : {
4573 : : /* avoid gcc warning by using compound statement even if not strictly necessary. */
4574 : : /* RemoveSSAPlaceholder (quad, des) ; */
4575 : 252660 : if (SymbolConversion_GccKnowsAbout (des))
4576 : : {
4577 : 0 : M2MetaError_MetaErrorT1 (despos, (const char *) "constant {%1Ead} should not be reassigned", 41, des);
4578 : 0 : RemoveQuad (p, des, quad);
4579 : 0 : return false;
4580 : : }
4581 : : else
4582 : : {
4583 : : return true;
4584 : : }
4585 : : }
4586 : : }
4587 : : return false;
4588 : : /* static analysis guarentees a RETURN statement will be used before here. */
4589 : : __builtin_unreachable ();
4590 : : }
4591 : :
4592 : :
4593 : : /*
4594 : : TypeCheckBecomes - returns TRUE if the type check succeeds.
4595 : : */
4596 : :
4597 : 248628 : static bool TypeCheckBecomes (M2GCCDeclare_WalkAction p, unsigned int quad)
4598 : : {
4599 : 248628 : unsigned int des;
4600 : 248628 : unsigned int op2;
4601 : 248628 : unsigned int expr;
4602 : 248628 : bool constExpr;
4603 : 248628 : bool overflowChecking;
4604 : 248628 : unsigned int despos;
4605 : 248628 : unsigned int op2pos;
4606 : 248628 : unsigned int exprpos;
4607 : 248628 : unsigned int becomespos;
4608 : 248628 : M2Quads_QuadOperator op;
4609 : :
4610 : 248628 : M2Quads_GetQuadOtok (quad, &becomespos, &op, &des, &op2, &expr, &overflowChecking, &constExpr, &despos, &op2pos, &exprpos);
4611 : 248628 : M2Debug_Assert (op2pos == M2LexBuf_UnknownTokenNo);
4612 : 248628 : if (M2Options_StrictTypeChecking && (! (M2Check_AssignmentTypeCompatible (despos, (const char *) "", 0, des, expr, true))))
4613 : : {
4614 : 0 : M2MetaError_MetaErrorT2 (M2LexBuf_MakeVirtualTok (becomespos, despos, exprpos), (const char *) "assignment check caught mismatch between {%1Ead} and {%2ad}", 59, des, expr);
4615 : 0 : RemoveQuad (p, des, quad);
4616 : 0 : return false;
4617 : : }
4618 : : return true;
4619 : : /* static analysis guarentees a RETURN statement will be used before here. */
4620 : : __builtin_unreachable ();
4621 : : }
4622 : :
4623 : :
4624 : : /*
4625 : : PerformFoldBecomes - attempts to fold quad. It propagates constant strings
4626 : : and attempts to declare des providing it is a constant
4627 : : and expr is resolved.
4628 : : */
4629 : :
4630 : 248628 : static void PerformFoldBecomes (M2GCCDeclare_WalkAction p, unsigned int quad)
4631 : : {
4632 : 248628 : unsigned int des;
4633 : 248628 : unsigned int op2;
4634 : 248628 : unsigned int expr;
4635 : 248628 : bool constExpr;
4636 : 248628 : bool overflowChecking;
4637 : 248628 : unsigned int despos;
4638 : 248628 : unsigned int op2pos;
4639 : 248628 : unsigned int exprpos;
4640 : 248628 : unsigned int becomespos;
4641 : 248628 : unsigned int virtpos;
4642 : 248628 : M2Quads_QuadOperator op;
4643 : :
4644 : 248628 : M2Quads_GetQuadOtok (quad, &becomespos, &op, &des, &op2, &expr, &overflowChecking, &constExpr, &despos, &op2pos, &exprpos);
4645 : 248628 : M2Debug_Assert (op2pos == M2LexBuf_UnknownTokenNo);
4646 : 248628 : if ((SymbolTable_IsConst (des)) && (SymbolTable_IsConstString (expr)))
4647 : : {
4648 : : /* avoid dangling else. */
4649 : 1396 : if ((SymbolTable_IsConstStringKnown (expr)) && (! (SymbolTable_IsConstStringKnown (des))))
4650 : : {
4651 : 1396 : SymbolTable_CopyConstString (exprpos, des, expr);
4652 : : }
4653 : : }
4654 : 247232 : else if ((SymbolTable_GetType (des)) == SymbolTable_NulSym)
4655 : : {
4656 : : /* avoid dangling else. */
4657 : 0 : M2Debug_Assert ((SymbolTable_GetType (expr)) != SymbolTable_NulSym);
4658 : 0 : SymbolTable_PutConst (des, SymbolTable_GetType (expr));
4659 : : }
4660 : 248628 : if ((SymbolTable_GetType (expr)) == SymbolTable_NulSym)
4661 : : {
4662 : 4042 : M2ALU_CheckOrResetOverflow (exprpos, SymbolConversion_Mod2Gcc (expr), M2Quads_MustCheckOverflow (quad));
4663 : 4042 : SymbolConversion_AddModGcc (des, SymbolConversion_Mod2Gcc (expr));
4664 : : }
4665 : : else
4666 : : {
4667 : 244586 : if (! (SymbolConversion_GccKnowsAbout (SymbolTable_GetType (des))))
4668 : : {
4669 : 356 : return;
4670 : : }
4671 : 244230 : if (SymbolTable_IsProcedure (expr))
4672 : : {
4673 : 12 : SymbolConversion_AddModGcc (des, m2convert_BuildConvert (M2LexBuf_TokenToLocation (exprpos), SymbolConversion_Mod2Gcc (SymbolTable_GetType (des)), m2expr_BuildAddr (M2LexBuf_TokenToLocation (exprpos), SymbolConversion_Mod2Gcc (expr), false), true));
4674 : : }
4675 : 244218 : else if (SymbolTable_IsValueSolved (expr))
4676 : : {
4677 : : /* avoid dangling else. */
4678 : 244218 : SymbolTable_PushValue (expr);
4679 : 244218 : if (M2ALU_IsValueTypeReal ())
4680 : : {
4681 : 504 : M2ALU_CheckOrResetOverflow (exprpos, M2ALU_PopRealTree (), M2Quads_MustCheckOverflow (quad));
4682 : 504 : SymbolTable_PushValue (expr);
4683 : 504 : SymbolConversion_AddModGcc (des, M2ALU_PopRealTree ());
4684 : : }
4685 : 243714 : else if (M2ALU_IsValueTypeSet ())
4686 : : {
4687 : : /* avoid dangling else. */
4688 : 3582 : SymbolTable_PopValue (des);
4689 : 3582 : SymbolTable_PutConstSet (des);
4690 : : }
4691 : 240132 : else if (((M2ALU_IsValueTypeConstructor ()) || (M2ALU_IsValueTypeArray ())) || (M2ALU_IsValueTypeRecord ()))
4692 : : {
4693 : : /* avoid dangling else. */
4694 : 404 : SymbolTable_PopValue (des);
4695 : 404 : SymbolTable_PutConstructor (des);
4696 : : }
4697 : 239728 : else if (M2ALU_IsValueTypeComplex ())
4698 : : {
4699 : : /* avoid dangling else. */
4700 : 330 : M2ALU_CheckOrResetOverflow (exprpos, M2ALU_PopComplexTree (), M2Quads_MustCheckOverflow (quad));
4701 : 330 : SymbolTable_PushValue (expr);
4702 : 330 : SymbolTable_PopValue (des);
4703 : : }
4704 : : else
4705 : : {
4706 : : /* avoid dangling else. */
4707 : 239398 : M2ALU_CheckOrResetOverflow (exprpos, M2ALU_PopIntegerTree (), M2Quads_MustCheckOverflow (quad));
4708 : 239398 : if ((SymbolTable_GetType (des)) == SymbolTable_NulSym)
4709 : : {
4710 : 0 : SymbolTable_PushValue (expr);
4711 : 0 : SymbolConversion_AddModGcc (des, M2ALU_PopIntegerTree ());
4712 : : }
4713 : : else
4714 : : {
4715 : 239398 : virtpos = M2LexBuf_MakeVirtualTok (becomespos, despos, exprpos);
4716 : 239398 : SymbolTable_PushValue (expr);
4717 : 239398 : SymbolConversion_AddModGcc (des, m2convert_BuildConvert (M2LexBuf_TokenToLocation (virtpos), SymbolConversion_Mod2Gcc (SymbolTable_GetType (des)), M2ALU_PopIntegerTree (), false));
4718 : : }
4719 : : }
4720 : : }
4721 : : else
4722 : : {
4723 : : /* avoid dangling else. */
4724 : 0 : virtpos = M2LexBuf_MakeVirtualTok (becomespos, despos, exprpos);
4725 : 0 : M2ALU_CheckOrResetOverflow (exprpos, SymbolConversion_Mod2Gcc (des), M2Quads_MustCheckOverflow (quad));
4726 : 0 : SymbolConversion_AddModGcc (des, m2convert_BuildConvert (M2LexBuf_TokenToLocation (virtpos), SymbolConversion_Mod2Gcc (SymbolTable_GetType (des)), m2decl_DeclareKnownConstant (M2LexBuf_TokenToLocation (virtpos), SymbolConversion_Mod2Gcc (SymbolTable_GetType (expr)), SymbolConversion_Mod2Gcc (expr)), false));
4727 : : }
4728 : : }
4729 : 248272 : RemoveQuad (p, des, quad);
4730 : 248272 : M2Debug_Assert ((m2block_RememberConstant (SymbolConversion_Mod2Gcc (des))) == (SymbolConversion_Mod2Gcc (des)));
4731 : : }
4732 : :
4733 : :
4734 : : /*
4735 : : CodeTry - starts building a GCC 'try' node.
4736 : : */
4737 : :
4738 : 2806 : static void CodeTry (void)
4739 : : {
4740 : 2806 : location_t location;
4741 : :
4742 : 2806 : location = M2LexBuf_TokenToLocation (CurrentQuadToken);
4743 : 2806 : handlerBlock = NULL;
4744 : 2806 : tryBlock = m2except_BuildTryBegin (location);
4745 : 2806 : }
4746 : :
4747 : :
4748 : : /*
4749 : : CodeThrow - builds a GCC 'throw' node.
4750 : : */
4751 : :
4752 : 322 : static void CodeThrow (unsigned int value)
4753 : : {
4754 : 322 : location_t location;
4755 : :
4756 : 322 : location = M2LexBuf_TokenToLocation (CurrentQuadToken);
4757 : 322 : if (value == SymbolTable_NulSym)
4758 : : {
4759 : 210 : m2type_AddStatement (location, m2except_BuildThrow (location, (tree) (NULL)));
4760 : : }
4761 : : else
4762 : : {
4763 : 112 : M2GCCDeclare_DeclareConstant (CurrentQuadToken, value); /* Checks to see whether it is a constant and declares it. */
4764 : 112 : m2type_AddStatement (location, m2except_BuildThrow (location, m2convert_BuildConvert (location, m2type_GetIntegerType (), SymbolConversion_Mod2Gcc (value), false))); /* Checks to see whether it is a constant and declares it. */
4765 : : }
4766 : 322 : }
4767 : :
4768 : 156 : static void CodeRetry (unsigned int destQuad)
4769 : : {
4770 : 156 : location_t location;
4771 : :
4772 : 156 : location = M2LexBuf_TokenToLocation (CurrentQuadToken);
4773 : 156 : m2statement_BuildGoto (location, reinterpret_cast <char * > (DynamicStrings_string (CreateLabelName (destQuad))));
4774 : 156 : }
4775 : :
4776 : 2806 : static void CodeCatchBegin (void)
4777 : : {
4778 : 2806 : location_t location;
4779 : :
4780 : 2806 : location = M2LexBuf_TokenToLocation (CurrentQuadToken);
4781 : 2806 : m2except_BuildTryEnd (tryBlock);
4782 : 2806 : handlerBlock = m2except_BuildCatchBegin (location);
4783 : 2806 : }
4784 : :
4785 : 2806 : static void CodeCatchEnd (void)
4786 : : {
4787 : 2806 : location_t location;
4788 : :
4789 : 2806 : location = M2LexBuf_TokenToLocation (CurrentQuadToken);
4790 : 2806 : tryBlock = m2except_BuildCatchEnd (location, handlerBlock, tryBlock);
4791 : 2806 : m2type_AddStatement (location, tryBlock);
4792 : 2806 : }
4793 : :
4794 : :
4795 : : /*
4796 : : DescribeTypeError -
4797 : : */
4798 : :
4799 : 6 : static void DescribeTypeError (unsigned int token, unsigned int op1, unsigned int op2)
4800 : : {
4801 : 6 : M2MetaError_MetaErrorT2 (token, (const char *) "incompatible set types in assignment, assignment between {%1ERad} and {%2ad}", 76, op1, op2);
4802 : 6 : M2MetaError_MetaError2 ((const char *) "set types are {%1CDtsad} and {%2Dtsad}", 38, op1, op2);
4803 : 6 : }
4804 : :
4805 : :
4806 : : /*
4807 : : DefaultConvertGM2 - provides a simple mapping between
4808 : : front end data types and GCC equivalents.
4809 : : This is only used to aid assignment of
4810 : : typed constants.
4811 : : */
4812 : :
4813 : 19058 : static tree DefaultConvertGM2 (unsigned int sym)
4814 : : {
4815 : 19058 : sym = SymbolTable_SkipType (sym);
4816 : 19058 : if (sym == M2Bitset_Bitset)
4817 : : {
4818 : 0 : return m2type_GetWordType ();
4819 : : }
4820 : : else
4821 : : {
4822 : 19058 : return SymbolConversion_Mod2Gcc (sym);
4823 : : }
4824 : : /* static analysis guarentees a RETURN statement will be used before here. */
4825 : : __builtin_unreachable ();
4826 : : }
4827 : :
4828 : :
4829 : : /*
4830 : : FoldConstBecomes - returns a Tree containing op3.
4831 : : The tree will have been folded and
4832 : : type converted if necessary.
4833 : : */
4834 : :
4835 : 165959 : static tree FoldConstBecomes (unsigned int tokenno, unsigned int op1, unsigned int op3)
4836 : : {
4837 : 165959 : tree t;
4838 : 165959 : tree type;
4839 : 165959 : location_t location;
4840 : :
4841 : 165959 : if ((SymbolTable_IsConstSet (op3)) || (((SymbolTable_SkipType (SymbolTable_GetType (op3))) != SymbolTable_NulSym) && (SymbolTable_IsSet (SymbolTable_SkipType (SymbolTable_GetType (op3))))))
4842 : : {
4843 : 2514 : if ((SymbolTable_SkipType (SymbolTable_GetTypeMode (op1))) != (SymbolTable_SkipType (SymbolTable_GetTypeMode (op3))))
4844 : : {
4845 : 6 : DescribeTypeError (tokenno, op1, op3);
4846 : : /* Assigning an errant op3 might ICE, therefore it is safer to return op1. */
4847 : 6 : return SymbolConversion_Mod2Gcc (op1);
4848 : : }
4849 : : }
4850 : 165953 : location = M2LexBuf_TokenToLocation (tokenno);
4851 : 165953 : M2GCCDeclare_TryDeclareConstant (tokenno, op3);
4852 : 165953 : t = SymbolConversion_Mod2Gcc (op3);
4853 : 165953 : M2Debug_Assert (t != NULL);
4854 : 165953 : if (IsConstant (op3))
4855 : : {
4856 : : /* avoid gcc warning by using compound statement even if not strictly necessary. */
4857 : 48654 : if (SymbolTable_IsProcedure (op3))
4858 : : {
4859 : : return t;
4860 : : }
4861 : 47982 : else if (((! (SymbolTable_IsConstString (op3))) && (! (SymbolTable_IsConstSet (op3)))) && ((SymbolTable_SkipType (SymbolTable_GetType (op3))) != (SymbolTable_SkipType (SymbolTable_GetType (op1)))))
4862 : : {
4863 : : /* avoid dangling else. */
4864 : 19058 : type = DefaultConvertGM2 (SymbolTable_GetType (op1)); /* do we need this now? --fixme-- */
4865 : 19058 : t = m2convert_ConvertConstantAndCheck (location, type, t); /* do we need this now? --fixme-- */
4866 : : }
4867 : 28924 : else if ((SymbolTable_GetType (op1)) != SymbolTable_NulSym)
4868 : : {
4869 : : /* avoid dangling else. */
4870 : 28924 : t = M2GenGCC_StringToChar (SymbolConversion_Mod2Gcc (op3), SymbolTable_GetType (op1), op3);
4871 : : }
4872 : : }
4873 : : return t;
4874 : : /* static analysis guarentees a RETURN statement will be used before here. */
4875 : : __builtin_unreachable ();
4876 : : }
4877 : :
4878 : :
4879 : : /*
4880 : : checkArrayElements - return TRUE if des or expr are not arrays.
4881 : : If they are arrays and have different number of
4882 : : elements return FALSE, otherwise TRUE.
4883 : : */
4884 : :
4885 : 165959 : static bool checkArrayElements (unsigned int des, unsigned int expr, unsigned int virtpos, unsigned int despos, unsigned int exprpos)
4886 : : {
4887 : 165959 : tree e1;
4888 : 165959 : tree e3;
4889 : 165959 : unsigned int t1;
4890 : 165959 : unsigned int t3;
4891 : :
4892 : 165959 : t1 = SymbolTable_GetType (des);
4893 : 165959 : t3 = SymbolTable_GetType (expr);
4894 : 165959 : if ((((t1 != SymbolTable_NulSym) && (t3 != SymbolTable_NulSym)) && (SymbolTable_IsArray (SymbolTable_SkipType (SymbolTable_GetType (expr))))) && (SymbolTable_IsArray (SymbolTable_SkipType (SymbolTable_GetType (des)))))
4895 : : {
4896 : : /* both arrays continue checking */
4897 : 476 : e1 = m2type_GetArrayNoOfElements (M2LexBuf_TokenToLocation (despos), SymbolConversion_Mod2Gcc (SymbolTable_SkipType (SymbolTable_GetType (des))));
4898 : 476 : e3 = m2type_GetArrayNoOfElements (M2LexBuf_TokenToLocation (exprpos), SymbolConversion_Mod2Gcc (SymbolTable_SkipType (SymbolTable_GetType (expr))));
4899 : 476 : if ((m2expr_CompareTrees (e1, e3)) != 0)
4900 : : {
4901 : 0 : M2MetaError_MetaErrorT2 (virtpos, (const char *) "not allowed to assign array {%2Ead} to {%1ad} as they have a different number of elements", 89, des, expr);
4902 : 0 : return false;
4903 : : }
4904 : : }
4905 : : return true;
4906 : : /* static analysis guarentees a RETURN statement will be used before here. */
4907 : : __builtin_unreachable ();
4908 : : }
4909 : :
4910 : :
4911 : : /*
4912 : : CodeInitAddress -
4913 : : */
4914 : :
4915 : 54 : static void CodeInitAddress (unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3)
4916 : : {
4917 : 54 : location_t location;
4918 : :
4919 : 54 : M2GCCDeclare_DeclareConstant (CurrentQuadToken, op3); /* checks to see whether it is a constant and declares it */
4920 : 54 : M2GCCDeclare_DeclareConstructor (CurrentQuadToken, quad, op3); /* checks to see whether it is a constant and declares it */
4921 : 54 : location = M2LexBuf_TokenToLocation (CurrentQuadToken);
4922 : 54 : M2Debug_Assert (op2 == SymbolTable_NulSym);
4923 : 54 : M2Debug_Assert ((SymbolTable_GetMode (op1)) == SymbolTable_LeftValue);
4924 : 54 : m2statement_BuildAssignmentStatement (location, SymbolConversion_Mod2Gcc (op1), m2convert_BuildConvert (location, m2type_GetPointerType (), SymbolConversion_Mod2Gcc (op3), false));
4925 : 54 : }
4926 : :
4927 : :
4928 : : /*
4929 : : checkRecordTypes - returns TRUE if des is not a record or if the record
4930 : : is the same type as expr.
4931 : : */
4932 : :
4933 : 165959 : static bool checkRecordTypes (unsigned int des, unsigned int expr, unsigned int virtpos)
4934 : : {
4935 : 165959 : unsigned int t1;
4936 : 165959 : unsigned int t2;
4937 : :
4938 : 165959 : if (((SymbolTable_GetType (des)) == SymbolTable_NulSym) || ((SymbolTable_GetMode (des)) == SymbolTable_LeftValue))
4939 : : {
4940 : 18470 : return true;
4941 : : }
4942 : : else
4943 : : {
4944 : 147489 : t1 = SymbolTable_SkipType (SymbolTable_GetType (des));
4945 : 147489 : if (SymbolTable_IsRecord (t1))
4946 : : {
4947 : : /* avoid gcc warning by using compound statement even if not strictly necessary. */
4948 : 302 : if ((SymbolTable_GetType (expr)) == SymbolTable_NulSym)
4949 : : {
4950 : 0 : M2MetaError_MetaErrorT2 (virtpos, (const char *) "cannot assign an operand of type {%1Ets} to a record type {%2tsa}", 65, expr, des);
4951 : 0 : return false;
4952 : : }
4953 : : else
4954 : : {
4955 : 302 : t2 = SymbolTable_SkipType (SymbolTable_GetType (expr));
4956 : 302 : if (t1 == t2)
4957 : : {
4958 : : return true;
4959 : : }
4960 : : else
4961 : : {
4962 : 0 : M2MetaError_MetaErrorT2 (virtpos, (const char *) "cannot assign an operand of type {%1ts} to a record type {%2tsa}", 64, expr, des);
4963 : 0 : return false;
4964 : : }
4965 : : }
4966 : : }
4967 : : }
4968 : : return true;
4969 : : /* static analysis guarentees a RETURN statement will be used before here. */
4970 : : __builtin_unreachable ();
4971 : : }
4972 : :
4973 : :
4974 : : /*
4975 : : checkIncorrectMeta - checks to see if des and expr are assignment compatible is allows
4976 : : generic system types to be assigned.
4977 : : */
4978 : :
4979 : 165959 : static bool checkIncorrectMeta (unsigned int des, unsigned int expr, unsigned int virtpos)
4980 : : {
4981 : 165959 : unsigned int t1;
4982 : 165959 : unsigned int t2;
4983 : :
4984 : 165959 : t1 = SymbolTable_SkipType (SymbolTable_GetType (des));
4985 : 165959 : t2 = SymbolTable_SkipType (SymbolTable_GetType (expr));
4986 : 165959 : if ((((t1 == SymbolTable_NulSym) || ((SymbolTable_GetMode (des)) == SymbolTable_LeftValue)) || (t2 == SymbolTable_NulSym)) || ((SymbolTable_GetMode (expr)) == SymbolTable_LeftValue))
4987 : : {
4988 : 19166 : return true;
4989 : : }
4990 : 146793 : else if (((t1 != t2) && (! (M2System_IsGenericSystemType (t1)))) && (! (M2System_IsGenericSystemType (t2))))
4991 : : {
4992 : : /* avoid dangling else. */
4993 : 28687 : if (((SymbolTable_IsArray (t1)) || (SymbolTable_IsSet (t1))) || (SymbolTable_IsRecord (t1)))
4994 : : {
4995 : 12 : if (! (M2Base_IsAssignmentCompatible (t1, t2)))
4996 : : {
4997 : 0 : ErrorMessageDecl (virtpos, (const char *) "illegal assignment error between {%1Etad} and {%2tad}", 53, des, expr, true);
4998 : 0 : return false;
4999 : : }
5000 : : }
5001 : : }
5002 : : return true;
5003 : : /* static analysis guarentees a RETURN statement will be used before here. */
5004 : : __builtin_unreachable ();
5005 : : }
5006 : :
5007 : :
5008 : : /*
5009 : : checkBecomes - returns TRUE if the checks pass.
5010 : : */
5011 : :
5012 : 165959 : static bool checkBecomes (unsigned int des, unsigned int expr, unsigned int virtpos, unsigned int despos, unsigned int exprpos)
5013 : : {
5014 : 165959 : if (((! (checkArrayElements (des, expr, virtpos, despos, exprpos))) || (! (checkRecordTypes (des, expr, virtpos)))) || (! (checkIncorrectMeta (des, expr, virtpos))))
5015 : : {
5016 : 0 : return false;
5017 : : }
5018 : : return true;
5019 : : /* static analysis guarentees a RETURN statement will be used before here. */
5020 : : __builtin_unreachable ();
5021 : : }
5022 : :
5023 : :
5024 : : /*
5025 : : checkDeclare - checks to see if sym is declared and if it is not then declare it.
5026 : : */
5027 : :
5028 : 2372 : static void checkDeclare (unsigned int sym)
5029 : : {
5030 : 2372 : if (((SymbolTable_IsTemporary (sym)) && (SymbolTable_IsVariableSSA (sym))) && (! (SymbolConversion_GccKnowsAbout (sym))))
5031 : : {
5032 : 0 : M2GCCDeclare_DeclareLocalVariable (sym);
5033 : : }
5034 : 2372 : }
5035 : :
5036 : :
5037 : : /*
5038 : : PerformCodeBecomes -
5039 : : */
5040 : :
5041 : 165959 : static void PerformCodeBecomes (location_t location, unsigned int virtpos, unsigned int des, unsigned int expr)
5042 : : {
5043 : 165959 : tree destree;
5044 : 165959 : tree exprtree;
5045 : :
5046 : 165959 : destree = SymbolConversion_Mod2Gcc (des);
5047 : 165959 : exprtree = FoldConstBecomes (virtpos, des, expr);
5048 : 165959 : if ((SymbolTable_IsVar (des)) && (SymbolTable_IsVariableSSA (des)))
5049 : : {
5050 : 0 : Replace (des, exprtree);
5051 : : }
5052 : 165959 : else if (m2type_IsGccStrictTypeEquivalent (destree, exprtree))
5053 : : {
5054 : : /* avoid dangling else. */
5055 : 165887 : m2statement_BuildAssignmentStatement (location, destree, exprtree);
5056 : : }
5057 : : else
5058 : : {
5059 : : /* avoid dangling else. */
5060 : 72 : m2statement_CopyByField (location, destree, exprtree);
5061 : : }
5062 : 165959 : }
5063 : :
5064 : 166809 : static void CodeBecomes (unsigned int quad)
5065 : : {
5066 : 166809 : bool constExpr;
5067 : 166809 : bool overflowChecking;
5068 : 166809 : M2Quads_QuadOperator op;
5069 : 166809 : unsigned int des;
5070 : 166809 : unsigned int op2;
5071 : 166809 : unsigned int expr;
5072 : 166809 : unsigned int virtpos;
5073 : 166809 : unsigned int becomespos;
5074 : 166809 : unsigned int despos;
5075 : 166809 : unsigned int op2pos;
5076 : 166809 : unsigned int exprpos;
5077 : 166809 : tree length;
5078 : 166809 : tree exprt;
5079 : 166809 : location_t location;
5080 : :
5081 : : /*
5082 : : ------------------------------------------------------------------------------
5083 : : := Operator
5084 : : ------------------------------------------------------------------------------
5085 : : Sym1<I> := Sym3<I> := produces a constant
5086 : : Sym1<O> := Sym3<O> := has the effect Mem[Sym1<I>] := Mem[Sym3<I>]
5087 : : */
5088 : 166809 : M2Quads_GetQuadOtok (quad, &becomespos, &op, &des, &op2, &expr, &overflowChecking, &constExpr, &despos, &op2pos, &exprpos);
5089 : 166809 : M2Debug_Assert (op2pos == M2LexBuf_UnknownTokenNo);
5090 : 166809 : M2GCCDeclare_DeclareConstant (exprpos, expr); /* Check to see whether expr is a constant and declare it. */
5091 : 166809 : M2GCCDeclare_DeclareConstructor (exprpos, quad, expr); /* Check to see whether expr is a constant and declare it. */
5092 : 166809 : virtpos = M2LexBuf_MakeVirtualTok (becomespos, despos, exprpos);
5093 : 166809 : location = M2LexBuf_TokenToLocation (virtpos);
5094 : 166809 : if (M2Options_StrictTypeChecking && (! (M2Check_AssignmentTypeCompatible (virtpos, (const char *) "", 0, des, expr, true))))
5095 : : {
5096 : 0 : ErrorMessageDecl (virtpos, (const char *) "assignment check caught mismatch between {%1Ead} and {%2ad}", 59, des, expr, true);
5097 : : }
5098 : 166809 : if ((SymbolTable_IsConstString (expr)) && (! (SymbolTable_IsConstStringKnown (expr))))
5099 : : {
5100 : 0 : M2MetaError_MetaErrorT2 (virtpos, (const char *) "internal error: CodeBecomes {%1Aad} in quad {%2n}", 49, des, quad);
5101 : : }
5102 : 166809 : if ((SymbolTable_IsConst (des)) && (! (SymbolConversion_GccKnowsAbout (des))))
5103 : : {
5104 : 6 : M2GCCDeclare_ConstantKnownAndUsed (des, CheckConstant (virtpos, des, expr));
5105 : : }
5106 : 166803 : else if ((SymbolTable_IsConstString (expr)) && ((SymbolTable_SkipTypeAndSubrange (SymbolTable_GetType (des))) != M2Base_Char))
5107 : : {
5108 : : /* avoid dangling else. */
5109 : 534 : checkDeclare (des);
5110 : 534 : if (! (M2GenGCC_PrepareCopyString (becomespos, &length, &exprt, expr, SymbolTable_SkipType (SymbolTable_GetType (des)))))
5111 : : {
5112 : 12 : ErrorMessageDecl (virtpos, (const char *) "string constant {%1Ea} is too large to be assigned to the array {%2ad}", 70, expr, des, true);
5113 : : }
5114 : 534 : m2type_AddStatement (location, MaybeDebugBuiltinMemcpy (location, m2expr_BuildAddr (location, SymbolConversion_Mod2Gcc (des), false), m2expr_BuildAddr (location, exprt, false), length));
5115 : : }
5116 : : else
5117 : : {
5118 : : /* avoid dangling else. */
5119 : 166269 : if ((((M2System_IsGenericSystemType (SymbolTable_SkipType (SymbolTable_GetType (des)))) != (M2System_IsGenericSystemType (SymbolTable_SkipType (SymbolTable_GetType (expr))))) || (((SymbolTable_IsUnbounded (SymbolTable_SkipType (SymbolTable_GetType (des)))) && (SymbolTable_IsUnbounded (SymbolTable_SkipType (SymbolTable_GetType (expr))))) && ((M2System_IsGenericSystemType (SymbolTable_SkipType (SymbolTable_GetType (SymbolTable_GetType (des))))) != (M2System_IsGenericSystemType (SymbolTable_SkipType (SymbolTable_GetType (SymbolTable_GetType (expr)))))))) && (! (IsConstant (expr))))
5120 : : {
5121 : 310 : checkDeclare (des);
5122 : 310 : m2type_AddStatement (location, MaybeDebugBuiltinMemcpy (location, m2expr_BuildAddr (location, SymbolConversion_Mod2Gcc (des), false), m2expr_BuildAddr (location, SymbolConversion_Mod2Gcc (expr), false), m2expr_BuildSize (location, SymbolConversion_Mod2Gcc (des), false)));
5123 : : }
5124 : : else
5125 : : {
5126 : 165959 : if (checkBecomes (des, expr, virtpos, despos, exprpos))
5127 : : {
5128 : 165959 : PerformCodeBecomes (location, virtpos, des, expr);
5129 : : }
5130 : : else
5131 : : {
5132 : 0 : M2Quads_SubQuad (quad); /* We don't want multiple errors for the quad. */
5133 : : }
5134 : : }
5135 : : }
5136 : 166809 : }
5137 : :
5138 : :
5139 : : /*
5140 : : LValueToGenericPtrOrConvert - if sym is an lvalue then convert to pointer type
5141 : : else convert to type, type. Return the converted tree.
5142 : : */
5143 : :
5144 : 18882 : static tree LValueToGenericPtrOrConvert (unsigned int sym, tree type)
5145 : : {
5146 : 18882 : tree n;
5147 : 18882 : location_t location;
5148 : :
5149 : 18882 : n = SymbolConversion_Mod2Gcc (sym);
5150 : 18882 : location = M2LexBuf_TokenToLocation (SymbolTable_GetDeclaredMod (sym));
5151 : 18882 : if (n == NULL)
5152 : : {
5153 : 0 : M2Error_InternalError ((const char *) "expecting symbol to be resolved", 31);
5154 : : }
5155 : 18882 : if ((SymbolTable_GetMode (sym)) == SymbolTable_LeftValue)
5156 : : {
5157 : 0 : n = m2convert_BuildConvert (location, m2type_GetPointerType (), n, false);
5158 : : }
5159 : : else
5160 : : {
5161 : 18882 : n = m2convert_BuildConvert (location, type, n, false);
5162 : : }
5163 : 18882 : return n;
5164 : : /* static analysis guarentees a RETURN statement will be used before here. */
5165 : : __builtin_unreachable ();
5166 : : }
5167 : :
5168 : :
5169 : : /*
5170 : : FoldBinary - check whether we can fold the binop operation.
5171 : : */
5172 : :
5173 : 582530 : static void FoldBinary (unsigned int tokenno, M2GCCDeclare_WalkAction p, m2expr_BuildBinProcedure binop, unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3)
5174 : : {
5175 : 582530 : tree tl;
5176 : 582530 : tree tr;
5177 : 582530 : tree tv;
5178 : 582530 : tree resType;
5179 : 582530 : location_t location;
5180 : :
5181 : : /* firstly ensure that constant literals are declared */
5182 : 582530 : M2GCCDeclare_TryDeclareConstant (tokenno, op3);
5183 : 582530 : M2GCCDeclare_TryDeclareConstant (tokenno, op2);
5184 : 582530 : location = M2LexBuf_TokenToLocation (tokenno);
5185 : 582530 : if ((SymbolTable_IsConst (op2)) && (SymbolTable_IsConst (op3)))
5186 : : {
5187 : 26264 : if ((SymbolConversion_GccKnowsAbout (op2)) && (SymbolConversion_GccKnowsAbout (op3)))
5188 : : {
5189 : : /* avoid gcc warning by using compound statement even if not strictly necessary. */
5190 : : /* fine, we can take advantage of this and fold constants */
5191 : 20312 : if (SymbolTable_IsConst (op1))
5192 : : {
5193 : 20312 : M2Debug_Assert ((M2Base_MixTypes (FindType (op3), FindType (op2), tokenno)) != SymbolTable_NulSym);
5194 : 20312 : SymbolTable_PutConst (op1, M2Base_MixTypes (FindType (op3), FindType (op2), tokenno));
5195 : 20312 : tl = M2GenGCC_LValueToGenericPtr (location, op2);
5196 : 20312 : tr = M2GenGCC_LValueToGenericPtr (location, op3);
5197 : 20312 : if ((SymbolTable_GetType (op1)) == SymbolTable_NulSym)
5198 : : {
5199 : 0 : resType = m2type_GetM2ZType ();
5200 : : }
5201 : : else
5202 : : {
5203 : 20312 : resType = SymbolConversion_Mod2Gcc (SymbolTable_GetType (op1));
5204 : : }
5205 : 20312 : tl = m2convert_BuildConvert (location, resType, tl, false);
5206 : 20312 : tr = m2convert_BuildConvert (location, resType, tr, false);
5207 : 20312 : tv = (*binop.proc) (location, tl, tr, true);
5208 : 20312 : M2ALU_CheckOrResetOverflow (tokenno, tv, M2Quads_MustCheckOverflow (quad));
5209 : 20300 : SymbolConversion_AddModGcc (op1, m2decl_DeclareKnownConstant (location, resType, tv));
5210 : 20300 : (*p.proc) (op1);
5211 : 20300 : NoChange = false;
5212 : 20300 : M2Quads_SubQuad (quad);
5213 : : }
5214 : : /* we can still fold the expression, but not the assignment,
5215 : : however, we will not do this here but in CodeBinary
5216 : : */
5217 : : }
5218 : : }
5219 : 582518 : }
5220 : :
5221 : :
5222 : : /*
5223 : : ConvertBinaryOperands -
5224 : : */
5225 : :
5226 : 114919 : static void ConvertBinaryOperands (location_t location, tree *tl, tree *tr, unsigned int type, unsigned int op2, unsigned int op3)
5227 : : {
5228 : 114919 : (*tl) = NULL;
5229 : 114919 : (*tr) = NULL;
5230 : 114919 : if ((SymbolTable_GetMode (op2)) == SymbolTable_LeftValue)
5231 : : {
5232 : 90 : (*tl) = M2GenGCC_LValueToGenericPtr (location, op2);
5233 : 90 : type = M2System_Address;
5234 : : }
5235 : 114919 : if ((SymbolTable_GetMode (op3)) == SymbolTable_LeftValue)
5236 : : {
5237 : 0 : (*tr) = M2GenGCC_LValueToGenericPtr (location, op3);
5238 : 0 : type = M2System_Address;
5239 : : }
5240 : 114919 : if (((*tl) == NULL) && ((*tr) == NULL))
5241 : : {
5242 : 114829 : (*tl) = m2convert_BuildConvert (location, SymbolConversion_Mod2Gcc (type), SymbolConversion_Mod2Gcc (op2), false);
5243 : 114829 : (*tr) = m2convert_BuildConvert (location, SymbolConversion_Mod2Gcc (type), SymbolConversion_Mod2Gcc (op3), false);
5244 : : }
5245 : 90 : else if ((*tl) == NULL)
5246 : : {
5247 : : /* avoid dangling else. */
5248 : 0 : (*tl) = m2convert_BuildConvert (location, SymbolConversion_Mod2Gcc (type), SymbolConversion_Mod2Gcc (op2), false);
5249 : : }
5250 : 90 : else if ((*tr) == NULL)
5251 : : {
5252 : : /* avoid dangling else. */
5253 : 90 : (*tr) = m2convert_BuildConvert (location, SymbolConversion_Mod2Gcc (type), SymbolConversion_Mod2Gcc (op3), false);
5254 : : }
5255 : 114919 : }
5256 : :
5257 : :
5258 : : /*
5259 : : CodeBinaryCheck - encode a binary arithmetic operation.
5260 : : */
5261 : :
5262 : 41630 : static void CodeBinaryCheck (m2expr_BuildBinCheckProcedure binop, unsigned int quad)
5263 : : {
5264 : 41630 : M2Quads_QuadOperator op;
5265 : 41630 : unsigned int op1;
5266 : 41630 : unsigned int op2;
5267 : 41630 : unsigned int op3;
5268 : 41630 : unsigned int op1pos;
5269 : 41630 : unsigned int op2pos;
5270 : 41630 : unsigned int op3pos;
5271 : 41630 : unsigned int lowestType;
5272 : 41630 : unsigned int type;
5273 : 41630 : tree min;
5274 : 41630 : tree max;
5275 : 41630 : tree lowest;
5276 : 41630 : tree tv;
5277 : 41630 : tree tl;
5278 : 41630 : tree tr;
5279 : 41630 : location_t location;
5280 : :
5281 : : /* firstly ensure that constant literals are declared. */
5282 : 41630 : M2Quads_GetQuadtok (quad, &op, &op1, &op2, &op3, &op1pos, &op2pos, &op3pos);
5283 : 41630 : M2GCCDeclare_DeclareConstant (op3pos, op3);
5284 : 41630 : M2GCCDeclare_DeclareConstant (op2pos, op2);
5285 : 41630 : location = M2LexBuf_TokenToLocation (op1pos);
5286 : 41630 : type = MixTypesBinary (op2, op3, op1pos, M2Quads_MustCheckOverflow (quad));
5287 : 41630 : ConvertBinaryOperands (location, &tl, &tr, type, op2, op3);
5288 : 41630 : lowestType = SymbolTable_GetLType (op1);
5289 : 41630 : lowest = SymbolConversion_Mod2Gcc (lowestType);
5290 : 41630 : if (M2Range_GetMinMax (CurrentQuadToken, lowestType, &min, &max))
5291 : : {
5292 : 38168 : tv = (*binop.proc) (location, tl, tr, lowest, min, max);
5293 : : }
5294 : : else
5295 : : {
5296 : 3462 : tv = (*binop.proc) (location, tl, tr, NULL, NULL, NULL);
5297 : : }
5298 : 41630 : M2ALU_CheckOrResetOverflow (op1pos, tv, M2Quads_MustCheckOverflow (quad));
5299 : 41630 : if (SymbolTable_IsConst (op1))
5300 : : {
5301 : : /* still have a constant which was not resolved, pass it to gcc. */
5302 : 0 : M2Debug_Assert ((M2Base_MixTypes (FindType (op3), FindType (op2), op3pos)) != SymbolTable_NulSym);
5303 : 0 : SymbolTable_PutConst (op1, M2Base_MixTypes (FindType (op3), FindType (op2), op3pos));
5304 : 0 : M2GCCDeclare_ConstantKnownAndUsed (op1, m2decl_DeclareKnownConstant (location, SymbolConversion_Mod2Gcc (SymbolTable_GetType (op3)), tv));
5305 : : }
5306 : : else
5307 : : {
5308 : 41630 : if (M2SSA_EnableSSA && (SymbolTable_IsVariableSSA (op1)))
5309 : : {
5310 : : Replace (op1, tv);
5311 : : }
5312 : : else
5313 : : {
5314 : 41630 : m2statement_BuildAssignmentStatement (location, SymbolConversion_Mod2Gcc (op1), tv);
5315 : : }
5316 : : }
5317 : 41630 : }
5318 : :
5319 : :
5320 : : /*
5321 : : MixTypesBinary - depending upon overflowCheck do not check pointer arithmetic.
5322 : : */
5323 : :
5324 : 51542 : static unsigned int MixTypesBinary (unsigned int left, unsigned int right, unsigned int tokpos, bool overflowCheck)
5325 : : {
5326 : 51542 : if (! overflowCheck && ((SymbolTable_IsPointer (SymbolTable_GetTypeMode (left))) || (SymbolTable_IsPointer (SymbolTable_GetTypeMode (right)))))
5327 : : {
5328 : 7434 : return M2System_Address;
5329 : : }
5330 : : else
5331 : : {
5332 : 44108 : return M2Base_MixTypesDecl (left, right, FindType (left), FindType (right), tokpos);
5333 : : }
5334 : : /* static analysis guarentees a RETURN statement will be used before here. */
5335 : : __builtin_unreachable ();
5336 : : }
5337 : :
5338 : :
5339 : : /*
5340 : : CodeBinary - encode a binary arithmetic operation.
5341 : : */
5342 : :
5343 : 9912 : static void CodeBinary (m2expr_BuildBinProcedure binop, unsigned int quad)
5344 : : {
5345 : 9912 : M2Quads_QuadOperator op;
5346 : 9912 : unsigned int op1;
5347 : 9912 : unsigned int op2;
5348 : 9912 : unsigned int op3;
5349 : 9912 : unsigned int op1pos;
5350 : 9912 : unsigned int op2pos;
5351 : 9912 : unsigned int op3pos;
5352 : 9912 : unsigned int type;
5353 : 9912 : tree tv;
5354 : 9912 : tree tl;
5355 : 9912 : tree tr;
5356 : 9912 : location_t location;
5357 : :
5358 : : /* firstly ensure that constant literals are declared */
5359 : 9912 : M2Quads_GetQuadtok (quad, &op, &op1, &op2, &op3, &op1pos, &op2pos, &op3pos);
5360 : 9912 : M2GCCDeclare_DeclareConstant (op3pos, op3);
5361 : 9912 : M2GCCDeclare_DeclareConstant (op2pos, op2);
5362 : 9912 : location = M2LexBuf_TokenToLocation (op1pos);
5363 : 9912 : type = MixTypesBinary (op2, op3, op1pos, M2Quads_MustCheckOverflow (quad));
5364 : 9912 : ConvertBinaryOperands (location, &tl, &tr, type, op2, op3);
5365 : 9912 : tv = (*binop.proc) (location, tl, tr, false);
5366 : 9912 : M2ALU_CheckOrResetOverflow (op1pos, tv, M2Quads_MustCheckOverflow (quad));
5367 : 9912 : if (SymbolTable_IsConst (op1))
5368 : : {
5369 : : /* still have a constant which was not resolved, pass it to gcc */
5370 : 0 : M2Debug_Assert ((M2Base_MixTypes (FindType (op3), FindType (op2), op1pos)) != SymbolTable_NulSym);
5371 : 0 : SymbolTable_PutConst (op1, M2Base_MixTypes (FindType (op3), FindType (op2), op1pos));
5372 : 0 : M2GCCDeclare_ConstantKnownAndUsed (op1, m2decl_DeclareKnownConstant (location, SymbolConversion_Mod2Gcc (SymbolTable_GetType (op3)), tv));
5373 : : }
5374 : : else
5375 : : {
5376 : 9912 : if (M2SSA_EnableSSA && (SymbolTable_IsVariableSSA (op1)))
5377 : : {
5378 : : Replace (op1, tv);
5379 : : }
5380 : : else
5381 : : {
5382 : 9912 : m2statement_BuildAssignmentStatement (location, SymbolConversion_Mod2Gcc (op1), tv);
5383 : : }
5384 : : }
5385 : 9912 : }
5386 : :
5387 : :
5388 : : /*
5389 : : NoWalkProcedure -
5390 : : */
5391 : :
5392 : 0 : static void NoWalkProcedure (unsigned int param __attribute__((unused)))
5393 : : {
5394 : 0 : }
5395 : :
5396 : :
5397 : : /*
5398 : : CheckBinaryExpressionTypes - returns TRUE if all expression checks pass.
5399 : : If the expression check fails quad is removed,
5400 : : the walk procedure (des) is called and NoChange is
5401 : : set to FALSE.
5402 : : */
5403 : :
5404 : 4920 : static bool CheckBinaryExpressionTypes (unsigned int quad, M2GCCDeclare_WalkAction p)
5405 : : {
5406 : 4920 : unsigned int des;
5407 : 4920 : unsigned int left;
5408 : 4920 : unsigned int right;
5409 : 4920 : bool typeChecking;
5410 : 4920 : bool constExpr;
5411 : 4920 : bool overflowChecking;
5412 : 4920 : unsigned int despos;
5413 : 4920 : unsigned int leftpos;
5414 : 4920 : unsigned int rightpos;
5415 : 4920 : unsigned int operatorpos;
5416 : 4920 : unsigned int subexprpos;
5417 : 4920 : M2Quads_QuadOperator op;
5418 : :
5419 : 4920 : M2Quads_GetQuadOTypetok (quad, &operatorpos, &op, &des, &left, &right, &overflowChecking, &typeChecking, &constExpr, &despos, &leftpos, &rightpos);
5420 : 4920 : if ((typeChecking && (op != M2Quads_LogicalRotateOp)) && (op != M2Quads_LogicalShiftOp))
5421 : : {
5422 : 3102 : subexprpos = M2LexBuf_MakeVirtualTok (operatorpos, leftpos, rightpos);
5423 : 3102 : if (M2Options_StrictTypeChecking && (! (M2Check_ExpressionTypeCompatible (subexprpos, (const char *) "", 0, left, right, M2Options_StrictTypeChecking, false))))
5424 : : {
5425 : 0 : M2MetaError_MetaErrorT2 (subexprpos, (const char *) "expression mismatch between {%1Etad} and {%2tad}", 48, left, right);
5426 : 0 : NoChange = false;
5427 : 0 : M2Quads_SubQuad (quad);
5428 : 0 : (*p.proc) (des);
5429 : 0 : return false;
5430 : : }
5431 : : }
5432 : : return true;
5433 : : /* static analysis guarentees a RETURN statement will be used before here. */
5434 : : __builtin_unreachable ();
5435 : : }
5436 : :
5437 : :
5438 : : /*
5439 : : CheckElementSetTypes - returns TRUE if all expression checks pass.
5440 : : If the expression check fails quad is removed,
5441 : : the walk procedure (des) is called and NoChange is
5442 : : set to FALSE.
5443 : : */
5444 : :
5445 : 1526 : static bool CheckElementSetTypes (unsigned int quad)
5446 : : {
5447 : 1526 : unsigned int righttype;
5448 : 1526 : unsigned int ignore;
5449 : 1526 : unsigned int left;
5450 : 1526 : unsigned int right;
5451 : 1526 : bool constExpr;
5452 : 1526 : bool overflowChecking;
5453 : 1526 : unsigned int ignorepos;
5454 : 1526 : unsigned int leftpos;
5455 : 1526 : unsigned int rightpos;
5456 : 1526 : unsigned int operatorpos;
5457 : 1526 : unsigned int subexprpos;
5458 : 1526 : M2Quads_QuadOperator op;
5459 : :
5460 : 1526 : M2Quads_GetQuadOtok (quad, &operatorpos, &op, &left, &right, &ignore, &overflowChecking, &constExpr, &leftpos, &rightpos, &ignorepos);
5461 : 1526 : subexprpos = M2LexBuf_MakeVirtualTok (operatorpos, leftpos, rightpos);
5462 : 1526 : righttype = SymbolTable_GetType (right);
5463 : 1526 : if (M2Options_StrictTypeChecking && (! (M2Check_ExpressionTypeCompatible (subexprpos, (const char *) "", 0, left, right, M2Options_StrictTypeChecking, true))))
5464 : : {
5465 : 0 : M2MetaError_MetaErrorT2 (subexprpos, (const char *) "the types used in expression {%1Etad} {%kIN} {%2tad} are incompatible", 69, left, right);
5466 : 0 : NoChange = false;
5467 : 0 : M2Quads_SubQuad (quad);
5468 : 0 : return false;
5469 : : }
5470 : 1526 : if ((righttype == SymbolTable_NulSym) || (! (SymbolTable_IsSet (SymbolTable_SkipType (righttype)))))
5471 : : {
5472 : 6 : M2MetaError_MetaErrorT1 (rightpos, (const char *) "an {%kIN} expression is expecting {%1Etad} to be a {%kSET} type", 63, right);
5473 : 6 : NoChange = false;
5474 : 6 : M2Quads_SubQuad (quad);
5475 : 6 : return false;
5476 : : }
5477 : : return true;
5478 : : /* static analysis guarentees a RETURN statement will be used before here. */
5479 : : __builtin_unreachable ();
5480 : : }
5481 : :
5482 : :
5483 : : /*
5484 : : CodeBinarySet - encode a binary set arithmetic operation.
5485 : : Set operands may be longer than a word.
5486 : : */
5487 : :
5488 : 956 : static void CodeBinarySet (m2expr_BuildBinProcedure binop, M2GenGCC_DoProcedure doOp, unsigned int quad)
5489 : : {
5490 : 956 : location_t location;
5491 : 956 : bool constExpr;
5492 : 956 : bool overflowChecking;
5493 : 956 : M2Quads_QuadOperator op;
5494 : 956 : unsigned int virttoken;
5495 : 956 : unsigned int virtexpr;
5496 : 956 : unsigned int des;
5497 : 956 : unsigned int left;
5498 : 956 : unsigned int right;
5499 : 956 : unsigned int despos;
5500 : 956 : unsigned int leftpos;
5501 : 956 : unsigned int rightpos;
5502 : 956 : unsigned int operatorpos;
5503 : :
5504 : 956 : M2Quads_GetQuadOtok (quad, &operatorpos, &op, &des, &left, &right, &overflowChecking, &constExpr, &despos, &leftpos, &rightpos);
5505 : : /* Firstly ensure that constant literals are declared. */
5506 : 956 : M2GCCDeclare_DeclareConstant (rightpos, right);
5507 : 956 : M2GCCDeclare_DeclareConstant (leftpos, left);
5508 : 956 : M2GCCDeclare_DeclareConstructor (rightpos, quad, right);
5509 : 956 : M2GCCDeclare_DeclareConstructor (leftpos, quad, left);
5510 : 956 : virttoken = M2LexBuf_MakeVirtualTok (operatorpos, despos, rightpos);
5511 : 956 : location = M2LexBuf_TokenToLocation (virttoken);
5512 : 956 : if (CheckBinaryExpressionTypes (quad, (M2GCCDeclare_WalkAction) {(M2GCCDeclare_WalkAction_t) NoWalkProcedure}))
5513 : : {
5514 : : /* avoid gcc warning by using compound statement even if not strictly necessary. */
5515 : 956 : if (SymbolTable_IsConst (des))
5516 : : {
5517 : 6 : virtexpr = M2LexBuf_MakeVirtualTok (operatorpos, leftpos, rightpos);
5518 : 6 : if ((SymbolTable_IsValueSolved (left)) && (SymbolTable_IsValueSolved (right)))
5519 : : {
5520 : 6 : M2Debug_Assert ((M2Base_MixTypes (FindType (right), FindType (left), virtexpr)) != SymbolTable_NulSym);
5521 : 6 : SymbolTable_PutConst (des, FindType (right));
5522 : 6 : SymbolTable_PushValue (left);
5523 : 6 : SymbolTable_PushValue (right);
5524 : 6 : (*doOp.proc) (virttoken);
5525 : 6 : SymbolTable_PopValue (des);
5526 : 6 : SymbolTable_PutConstSet (des);
5527 : : }
5528 : : else
5529 : : {
5530 : 0 : M2MetaError_MetaErrorT0 (virtexpr, (const char *) "{%E}constant expression cannot be evaluated", 43);
5531 : : }
5532 : : }
5533 : : else
5534 : : {
5535 : 950 : checkDeclare (des);
5536 : 950 : m2expr_BuildBinaryForeachWordDo (location, SymbolConversion_Mod2Gcc (SymbolTable_SkipType (SymbolTable_GetType (des))), SymbolConversion_Mod2Gcc (des), SymbolConversion_Mod2Gcc (left), SymbolConversion_Mod2Gcc (right), (m2expr_BuildBinProcedure_C) binop.proc, (SymbolTable_GetMode (des)) == SymbolTable_LeftValue, (SymbolTable_GetMode (left)) == SymbolTable_LeftValue, (SymbolTable_GetMode (right)) == SymbolTable_LeftValue, SymbolTable_IsConst (des), SymbolTable_IsConst (left), SymbolTable_IsConst (right));
5537 : : }
5538 : : }
5539 : 956 : }
5540 : :
5541 : :
5542 : : /*
5543 : : CheckUnaryOperand - checks to see whether operand is using a generic type.
5544 : : */
5545 : :
5546 : 812 : static bool CheckUnaryOperand (unsigned int quad, unsigned int operand)
5547 : : {
5548 : 812 : unsigned int type;
5549 : 812 : DynamicStrings_String s;
5550 : 812 : DynamicStrings_String op;
5551 : :
5552 : 812 : type = SymbolTable_SkipType (SymbolTable_GetType (operand));
5553 : 812 : if ((((M2System_Word == type) || (M2System_IsWordN (type))) || (M2System_Byte == type)) || (M2System_Loc == type))
5554 : : {
5555 : 6 : op = M2Quads_GetM2OperatorDesc (M2Quads_GetQuadOp (quad));
5556 : 6 : s = DynamicStrings_InitString ((const char *) "operand of type {%1Ets} is not allowed in an unary expression", 61);
5557 : 6 : if (op != NULL)
5558 : : {
5559 : 6 : s = DynamicStrings_ConCatChar (s, ' ');
5560 : 6 : s = DynamicStrings_ConCat (s, DynamicStrings_Mark (op));
5561 : : }
5562 : 6 : M2MetaError_MetaErrorStringT1 (CurrentQuadToken, s, operand);
5563 : 6 : return false;
5564 : : }
5565 : : return true;
5566 : : /* static analysis guarentees a RETURN statement will be used before here. */
5567 : : __builtin_unreachable ();
5568 : : }
5569 : :
5570 : :
5571 : : /*
5572 : : UnaryOperand - returns TRUE if operand is acceptable for
5573 : : unary operator: + -. If FALSE
5574 : : is returned, an error message will be generated
5575 : : and the quad is deleted.
5576 : : */
5577 : :
5578 : 812 : static bool UnaryOperand (unsigned int quad, unsigned int operand)
5579 : : {
5580 : 812 : if (! (CheckUnaryOperand (quad, operand)))
5581 : : {
5582 : 6 : M2Quads_SubQuad (quad); /* We do not want multiple copies of the same error. */
5583 : 6 : return false; /* We do not want multiple copies of the same error. */
5584 : : }
5585 : : return true;
5586 : : /* static analysis guarentees a RETURN statement will be used before here. */
5587 : : __builtin_unreachable ();
5588 : : }
5589 : :
5590 : :
5591 : : /*
5592 : : CheckBinaryOperand - checks to see whether operand is using a generic type.
5593 : : */
5594 : :
5595 : 1268168 : static bool CheckBinaryOperand (unsigned int quad, bool isleft, unsigned int operand, bool result)
5596 : : {
5597 : 1268168 : unsigned int type;
5598 : 1268168 : M2Quads_QuadOperator qop;
5599 : 1268168 : unsigned int op1;
5600 : 1268168 : unsigned int op2;
5601 : 1268168 : unsigned int op3;
5602 : 1268168 : unsigned int op1pos;
5603 : 1268168 : unsigned int op2pos;
5604 : 1268168 : unsigned int op3pos;
5605 : 1268168 : DynamicStrings_String s;
5606 : 1268168 : DynamicStrings_String op;
5607 : :
5608 : 1268168 : type = SymbolTable_SkipType (SymbolTable_GetType (operand));
5609 : 1268168 : if ((((M2System_Word == type) || (M2System_IsWordN (type))) || (M2System_Byte == type)) || (M2System_Loc == type))
5610 : : {
5611 : 18 : M2Quads_GetQuadtok (quad, &qop, &op1, &op2, &op3, &op1pos, &op2pos, &op3pos);
5612 : 18 : op = M2Quads_GetM2OperatorDesc (M2Quads_GetQuadOp (quad));
5613 : 18 : if (isleft)
5614 : : {
5615 : 6 : s = DynamicStrings_InitString ((const char *) "left operand {%1Ea} of type {%1Ets} is not allowed in binary expression", 71);
5616 : : }
5617 : : else
5618 : : {
5619 : 12 : s = DynamicStrings_InitString ((const char *) "right operand {%1Ea} of type {%1Ets} is not allowed in binary expression", 72);
5620 : : }
5621 : 18 : if (op != NULL)
5622 : : {
5623 : 18 : s = DynamicStrings_ConCatChar (s, ' ');
5624 : 18 : s = DynamicStrings_ConCat (s, DynamicStrings_Mark (op));
5625 : : }
5626 : 18 : M2MetaError_MetaErrorStringT1 (op1pos, s, operand);
5627 : 18 : return false;
5628 : : }
5629 : : return result;
5630 : : /* static analysis guarentees a RETURN statement will be used before here. */
5631 : : __builtin_unreachable ();
5632 : : }
5633 : :
5634 : :
5635 : : /*
5636 : : BinaryOperands - returns TRUE if, l, and, r, are acceptable for
5637 : : binary operator: + - / * and friends. If FALSE
5638 : : is returned, an error message will be generated
5639 : : and the, quad, is deleted.
5640 : : */
5641 : :
5642 : 634084 : static bool BinaryOperands (unsigned int quad, unsigned int l, unsigned int r)
5643 : : {
5644 : 634084 : bool result;
5645 : :
5646 : 634084 : result = CheckBinaryOperand (quad, true, l, true);
5647 : 634084 : result = CheckBinaryOperand (quad, false, r, result);
5648 : 634084 : if (! result)
5649 : : {
5650 : 12 : M2Quads_SubQuad (quad); /* We do not want multiple copies of the same error. */
5651 : : }
5652 : 634084 : return result;
5653 : : /* static analysis guarentees a RETURN statement will be used before here. */
5654 : : __builtin_unreachable ();
5655 : : }
5656 : :
5657 : :
5658 : : /*
5659 : : IsConstStr - returns TRUE if sym is a constant string or a char constant.
5660 : : */
5661 : :
5662 : 367888 : static bool IsConstStr (unsigned int sym)
5663 : : {
5664 : 367888 : return (SymbolTable_IsConstString (sym)) || ((SymbolTable_IsConst (sym)) && ((SymbolTable_GetSType (sym)) == M2Base_Char));
5665 : : /* static analysis guarentees a RETURN statement will be used before here. */
5666 : : __builtin_unreachable ();
5667 : : }
5668 : :
5669 : :
5670 : : /*
5671 : : IsConstStrKnown - returns TRUE if sym is a constant string or a char constant
5672 : : which is known.
5673 : : */
5674 : :
5675 : 40758 : static bool IsConstStrKnown (unsigned int sym)
5676 : : {
5677 : 40758 : return ((SymbolTable_IsConstString (sym)) && (SymbolTable_IsConstStringKnown (sym))) || ((SymbolTable_IsConst (sym)) && ((SymbolTable_GetSType (sym)) == M2Base_Char));
5678 : : /* static analysis guarentees a RETURN statement will be used before here. */
5679 : : __builtin_unreachable ();
5680 : : }
5681 : :
5682 : :
5683 : : /*
5684 : : GetStr - return a string containing a constant string value associated with sym.
5685 : : A nul char constant will return an empty string.
5686 : : */
5687 : :
5688 : 40590 : static DynamicStrings_String GetStr (unsigned int tokenno, unsigned int sym)
5689 : : {
5690 : 40590 : char ch;
5691 : :
5692 : 40590 : M2Debug_Assert (SymbolTable_IsConst (sym));
5693 : 40590 : if (SymbolTable_IsConstString (sym))
5694 : : {
5695 : 40566 : return DynamicStrings_InitStringCharStar (NameKey_KeyToCharStar (SymbolTable_GetString (sym)));
5696 : : }
5697 : : else
5698 : : {
5699 : 24 : M2Debug_Assert ((SymbolTable_GetSType (sym)) == M2Base_Char);
5700 : 24 : SymbolTable_PushValue (sym);
5701 : 24 : ch = M2ALU_PopChar (tokenno);
5702 : 24 : return DynamicStrings_InitStringChar (ch);
5703 : : }
5704 : : /* static analysis guarentees a RETURN statement will be used before here. */
5705 : : __builtin_unreachable ();
5706 : : }
5707 : :
5708 : :
5709 : : /*
5710 : : FoldAdd - check addition for constant folding. It checks for conststrings
5711 : : overloading the +.
5712 : : */
5713 : :
5714 : 327646 : static void FoldAdd (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3)
5715 : : {
5716 : 327646 : DynamicStrings_String s;
5717 : :
5718 : 327646 : if ((IsConstStr (op2)) && (IsConstStr (op3)))
5719 : : {
5720 : : /* avoid dangling else. */
5721 : 540 : if ((IsConstStrKnown (op2)) && (IsConstStrKnown (op3)))
5722 : : {
5723 : : /* Handle special addition for constant strings. */
5724 : 492 : s = DynamicStrings_Dup (GetStr (tokenno, op2));
5725 : 492 : s = DynamicStrings_ConCat (s, GetStr (tokenno, op3));
5726 : 492 : SymbolTable_PutConstStringKnown (tokenno, op1, NameKey_makekey (DynamicStrings_string (s)), false, true);
5727 : 492 : M2GCCDeclare_TryDeclareConstant (tokenno, op1);
5728 : 492 : (*p.proc) (op1);
5729 : 492 : NoChange = false;
5730 : 492 : M2Quads_SubQuad (quad);
5731 : 492 : s = DynamicStrings_KillString (s);
5732 : : }
5733 : : }
5734 : : else
5735 : : {
5736 : 327106 : FoldArithAdd (tokenno, p, quad, op1, op2, op3);
5737 : : }
5738 : 327634 : }
5739 : :
5740 : :
5741 : : /*
5742 : : FoldArithAdd - check arithmetic addition for constant folding.
5743 : : */
5744 : :
5745 : 327106 : static void FoldArithAdd (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3)
5746 : : {
5747 : 327106 : if (BinaryOperands (quad, op2, op3))
5748 : : {
5749 : 327094 : FoldBinary (tokenno, p, (m2expr_BuildBinProcedure) {(m2expr_BuildBinProcedure_t) m2expr_BuildAdd}, quad, op1, op2, op3);
5750 : : }
5751 : 327094 : }
5752 : :
5753 : :
5754 : : /*
5755 : : CodeAddChecked - code an addition instruction, determine whether checking
5756 : : is required.
5757 : : */
5758 : :
5759 : 29012 : static void CodeAddChecked (unsigned int quad, unsigned int left, unsigned int right)
5760 : : {
5761 : 29012 : if (M2Quads_MustCheckOverflow (quad))
5762 : : {
5763 : 19530 : CodeAddCheck (quad, left, right);
5764 : : }
5765 : : else
5766 : : {
5767 : 9482 : CodeAdd (quad, left, right);
5768 : : }
5769 : 29012 : }
5770 : :
5771 : :
5772 : : /*
5773 : : CodeAddCheck - encode addition but check for overflow.
5774 : : */
5775 : :
5776 : 19530 : static void CodeAddCheck (unsigned int quad, unsigned int left, unsigned int right)
5777 : : {
5778 : 19530 : if (BinaryOperands (quad, left, right))
5779 : : {
5780 : 19530 : CodeBinaryCheck ((m2expr_BuildBinCheckProcedure) {(m2expr_BuildBinCheckProcedure_t) m2expr_BuildAddCheck}, quad);
5781 : : }
5782 : 19530 : }
5783 : :
5784 : :
5785 : : /*
5786 : : CodeAdd - encode addition.
5787 : : */
5788 : :
5789 : 9482 : static void CodeAdd (unsigned int quad, unsigned int left, unsigned int right)
5790 : : {
5791 : 9482 : if (BinaryOperands (quad, left, right))
5792 : : {
5793 : 9482 : CodeBinary ((m2expr_BuildBinProcedure) {(m2expr_BuildBinProcedure_t) m2expr_BuildAdd}, quad);
5794 : : }
5795 : 9482 : }
5796 : :
5797 : :
5798 : : /*
5799 : : FoldSub - check subtraction for constant folding.
5800 : : */
5801 : :
5802 : 122294 : static void FoldSub (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3)
5803 : : {
5804 : 122294 : if (BinaryOperands (quad, op2, op3))
5805 : : {
5806 : 122294 : FoldBinary (tokenno, p, (m2expr_BuildBinProcedure) {(m2expr_BuildBinProcedure_t) m2expr_BuildSub}, quad, op1, op2, op3);
5807 : : }
5808 : 122294 : }
5809 : :
5810 : :
5811 : : /*
5812 : : CodeSubChecked - code a subtract instruction, determine whether checking
5813 : : is required.
5814 : : */
5815 : :
5816 : 8516 : static void CodeSubChecked (unsigned int quad, unsigned int left, unsigned int right)
5817 : : {
5818 : 8516 : if (M2Quads_MustCheckOverflow (quad))
5819 : : {
5820 : 8516 : CodeSubCheck (quad, left, right);
5821 : : }
5822 : : else
5823 : : {
5824 : 0 : CodeSub (quad, left, right);
5825 : : }
5826 : 8516 : }
5827 : :
5828 : :
5829 : : /*
5830 : : CodeSubCheck - encode subtraction but check for overflow.
5831 : : */
5832 : :
5833 : 8516 : static void CodeSubCheck (unsigned int quad, unsigned int left, unsigned int right)
5834 : : {
5835 : 8516 : if (BinaryOperands (quad, left, right))
5836 : : {
5837 : 8516 : CodeBinaryCheck ((m2expr_BuildBinCheckProcedure) {(m2expr_BuildBinCheckProcedure_t) m2expr_BuildSubCheck}, quad);
5838 : : }
5839 : 8516 : }
5840 : :
5841 : :
5842 : : /*
5843 : : CodeSub - encode subtraction.
5844 : : */
5845 : :
5846 : 0 : static void CodeSub (unsigned int quad, unsigned int left, unsigned int right)
5847 : : {
5848 : 0 : if (BinaryOperands (quad, left, right))
5849 : : {
5850 : 0 : CodeBinary ((m2expr_BuildBinProcedure) {(m2expr_BuildBinProcedure_t) m2expr_BuildSub}, quad);
5851 : : }
5852 : 0 : }
5853 : :
5854 : :
5855 : : /*
5856 : : FoldMult - check multiplication for constant folding.
5857 : : */
5858 : :
5859 : 88836 : static void FoldMult (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3)
5860 : : {
5861 : 88836 : if (BinaryOperands (quad, op2, op3))
5862 : : {
5863 : 88836 : FoldBinary (tokenno, p, (m2expr_BuildBinProcedure) {(m2expr_BuildBinProcedure_t) m2expr_BuildMult}, quad, op1, op2, op3);
5864 : : }
5865 : 88836 : }
5866 : :
5867 : :
5868 : : /*
5869 : : CodeMultChecked - code a multiplication instruction, determine whether checking
5870 : : is required.
5871 : : */
5872 : :
5873 : 10054 : static void CodeMultChecked (unsigned int quad, unsigned int left, unsigned int right)
5874 : : {
5875 : 10054 : if (M2Quads_MustCheckOverflow (quad))
5876 : : {
5877 : 10054 : CodeMultCheck (quad, left, right);
5878 : : }
5879 : : else
5880 : : {
5881 : 0 : CodeMult (quad, left, right);
5882 : : }
5883 : 10054 : }
5884 : :
5885 : :
5886 : : /*
5887 : : CodeMultCheck - encode multiplication but check for overflow.
5888 : : */
5889 : :
5890 : 10054 : static void CodeMultCheck (unsigned int quad, unsigned int left, unsigned int right)
5891 : : {
5892 : 10054 : if (BinaryOperands (quad, left, right))
5893 : : {
5894 : 10054 : CodeBinaryCheck ((m2expr_BuildBinCheckProcedure) {(m2expr_BuildBinCheckProcedure_t) m2expr_BuildMultCheck}, quad);
5895 : : }
5896 : 10054 : }
5897 : :
5898 : :
5899 : : /*
5900 : : CodeMult - encode multiplication.
5901 : : */
5902 : :
5903 : 0 : static void CodeMult (unsigned int quad, unsigned int left, unsigned int right)
5904 : : {
5905 : 0 : if (BinaryOperands (quad, left, right))
5906 : : {
5907 : 0 : CodeBinary ((m2expr_BuildBinProcedure) {(m2expr_BuildBinProcedure_t) m2expr_BuildMult}, quad);
5908 : : }
5909 : 0 : }
5910 : :
5911 : :
5912 : : /*
5913 : : CodeDivM2Checked - code a divide instruction, determine whether checking
5914 : : is required.
5915 : : */
5916 : :
5917 : 1702 : static void CodeDivM2Checked (unsigned int quad, unsigned int left, unsigned int right)
5918 : : {
5919 : 1702 : if (M2Quads_MustCheckOverflow (quad))
5920 : : {
5921 : 1702 : CodeDivM2Check (quad, left, right);
5922 : : }
5923 : : else
5924 : : {
5925 : 0 : CodeDivM2 (quad, left, right);
5926 : : }
5927 : 1702 : }
5928 : :
5929 : :
5930 : : /*
5931 : : CodeDivM2Check - encode addition but check for overflow.
5932 : : */
5933 : :
5934 : 1702 : static void CodeDivM2Check (unsigned int quad, unsigned int left, unsigned int right)
5935 : : {
5936 : 1702 : if (BinaryOperands (quad, left, right))
5937 : : {
5938 : 1702 : CodeBinaryCheck ((m2expr_BuildBinCheckProcedure) {(m2expr_BuildBinCheckProcedure_t) m2expr_BuildDivM2Check}, quad);
5939 : : }
5940 : 1702 : }
5941 : :
5942 : :
5943 : : /*
5944 : : CodeModM2Checked - code a modulus instruction, determine whether checking
5945 : : is required.
5946 : : */
5947 : :
5948 : 1828 : static void CodeModM2Checked (unsigned int quad, unsigned int left, unsigned int right)
5949 : : {
5950 : 1828 : if (M2Quads_MustCheckOverflow (quad))
5951 : : {
5952 : 1828 : CodeModM2Check (quad, left, right);
5953 : : }
5954 : : else
5955 : : {
5956 : 0 : CodeModM2 (quad, left, right);
5957 : : }
5958 : 1828 : }
5959 : :
5960 : :
5961 : : /*
5962 : : CodeModM2Check - encode addition but check for overflow.
5963 : : */
5964 : :
5965 : 1828 : static void CodeModM2Check (unsigned int quad, unsigned int left, unsigned int right)
5966 : : {
5967 : 1828 : if (BinaryOperands (quad, left, right))
5968 : : {
5969 : 1828 : CodeBinaryCheck ((m2expr_BuildBinCheckProcedure) {(m2expr_BuildBinCheckProcedure_t) m2expr_BuildModM2Check}, quad);
5970 : : }
5971 : 1828 : }
5972 : :
5973 : :
5974 : : /*
5975 : : BinaryOperandRealFamily -
5976 : : */
5977 : :
5978 : 40198 : static bool BinaryOperandRealFamily (unsigned int op)
5979 : : {
5980 : 40198 : unsigned int t;
5981 : :
5982 : 40198 : t = SymbolTable_SkipType (SymbolTable_GetType (op));
5983 : 40198 : return (((M2Base_IsComplexType (t)) || (M2System_IsComplexN (t))) || (M2Base_IsRealType (t))) || (M2System_IsRealN (t));
5984 : : /* static analysis guarentees a RETURN statement will be used before here. */
5985 : : __builtin_unreachable ();
5986 : : }
5987 : :
5988 : :
5989 : : /*
5990 : : FoldDivM2 - check division for constant folding.
5991 : : */
5992 : :
5993 : 14004 : static void FoldDivM2 (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3)
5994 : : {
5995 : 14004 : if (BinaryOperands (quad, op2, op3))
5996 : : {
5997 : : /* avoid gcc warning by using compound statement even if not strictly necessary. */
5998 : 14004 : if ((BinaryOperandRealFamily (op2)) || (BinaryOperandRealFamily (op3)))
5999 : : {
6000 : 0 : FoldBinary (tokenno, p, (m2expr_BuildBinProcedure) {(m2expr_BuildBinProcedure_t) m2expr_BuildRDiv}, quad, op1, op2, op3);
6001 : : }
6002 : : else
6003 : : {
6004 : 14004 : FoldBinary (tokenno, p, (m2expr_BuildBinProcedure) {(m2expr_BuildBinProcedure_t) m2expr_BuildDivM2}, quad, op1, op2, op3);
6005 : : }
6006 : : }
6007 : 14004 : }
6008 : :
6009 : :
6010 : : /*
6011 : : CodeDivM2 - encode division.
6012 : : */
6013 : :
6014 : 0 : static void CodeDivM2 (unsigned int quad, unsigned int left, unsigned int right)
6015 : : {
6016 : 0 : if (BinaryOperands (quad, left, right))
6017 : : {
6018 : : /* avoid gcc warning by using compound statement even if not strictly necessary. */
6019 : 0 : if ((BinaryOperandRealFamily (left)) || (BinaryOperandRealFamily (right)))
6020 : : {
6021 : 0 : CodeBinary ((m2expr_BuildBinProcedure) {(m2expr_BuildBinProcedure_t) m2expr_BuildRDiv}, quad);
6022 : : }
6023 : : else
6024 : : {
6025 : 0 : CodeBinary ((m2expr_BuildBinProcedure) {(m2expr_BuildBinProcedure_t) m2expr_BuildDivM2}, quad);
6026 : : }
6027 : : }
6028 : 0 : }
6029 : :
6030 : :
6031 : : /*
6032 : : FoldModM2 - check modulus for constant folding.
6033 : : */
6034 : :
6035 : 21946 : static void FoldModM2 (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3)
6036 : : {
6037 : 21946 : if (BinaryOperands (quad, op2, op3))
6038 : : {
6039 : 21946 : FoldBinary (tokenno, p, (m2expr_BuildBinProcedure) {(m2expr_BuildBinProcedure_t) m2expr_BuildModM2}, quad, op1, op2, op3);
6040 : : }
6041 : 21946 : }
6042 : :
6043 : :
6044 : : /*
6045 : : CodeModM2 - encode modulus.
6046 : : */
6047 : :
6048 : 0 : static void CodeModM2 (unsigned int quad, unsigned int left, unsigned int right)
6049 : : {
6050 : 0 : if (BinaryOperands (quad, left, right))
6051 : : {
6052 : 0 : CodeBinary ((m2expr_BuildBinProcedure) {(m2expr_BuildBinProcedure_t) m2expr_BuildModM2}, quad);
6053 : : }
6054 : 0 : }
6055 : :
6056 : :
6057 : : /*
6058 : : FoldDivTrunc - check division for constant folding.
6059 : : */
6060 : :
6061 : 8260 : static void FoldDivTrunc (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3)
6062 : : {
6063 : 8260 : if (BinaryOperands (quad, op2, op3))
6064 : : {
6065 : : /* avoid gcc warning by using compound statement even if not strictly necessary. */
6066 : 8260 : if ((BinaryOperandRealFamily (op2)) || (BinaryOperandRealFamily (op3)))
6067 : : {
6068 : 5054 : FoldBinary (tokenno, p, (m2expr_BuildBinProcedure) {(m2expr_BuildBinProcedure_t) m2expr_BuildRDiv}, quad, op1, op2, op3);
6069 : : }
6070 : : else
6071 : : {
6072 : 3206 : FoldBinary (tokenno, p, (m2expr_BuildBinProcedure) {(m2expr_BuildBinProcedure_t) m2expr_BuildDivTrunc}, quad, op1, op2, op3);
6073 : : }
6074 : : }
6075 : 8260 : }
6076 : :
6077 : :
6078 : : /*
6079 : : CodeDivTrunc - encode multiplication.
6080 : : */
6081 : :
6082 : 430 : static void CodeDivTrunc (unsigned int quad, unsigned int left, unsigned int right)
6083 : : {
6084 : 430 : if (BinaryOperands (quad, left, right))
6085 : : {
6086 : : /* avoid gcc warning by using compound statement even if not strictly necessary. */
6087 : 430 : if ((BinaryOperandRealFamily (left)) || (BinaryOperandRealFamily (right)))
6088 : : {
6089 : 136 : CodeBinary ((m2expr_BuildBinProcedure) {(m2expr_BuildBinProcedure_t) m2expr_BuildRDiv}, quad);
6090 : : }
6091 : : else
6092 : : {
6093 : 294 : CodeBinary ((m2expr_BuildBinProcedure) {(m2expr_BuildBinProcedure_t) m2expr_BuildDivTrunc}, quad);
6094 : : }
6095 : : }
6096 : 430 : }
6097 : :
6098 : :
6099 : : /*
6100 : : FoldModTrunc - check modulus for constant folding.
6101 : : */
6102 : :
6103 : 96 : static void FoldModTrunc (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3)
6104 : : {
6105 : 96 : if (BinaryOperands (quad, op2, op3))
6106 : : {
6107 : 96 : FoldBinary (tokenno, p, (m2expr_BuildBinProcedure) {(m2expr_BuildBinProcedure_t) m2expr_BuildModTrunc}, quad, op1, op2, op3);
6108 : : }
6109 : 96 : }
6110 : :
6111 : :
6112 : : /*
6113 : : CodeModTrunc - encode modulus.
6114 : : */
6115 : :
6116 : 0 : static void CodeModTrunc (unsigned int quad, unsigned int left, unsigned int right)
6117 : : {
6118 : 0 : if (BinaryOperands (quad, left, right))
6119 : : {
6120 : 0 : CodeBinary ((m2expr_BuildBinProcedure) {(m2expr_BuildBinProcedure_t) m2expr_BuildModTrunc}, quad);
6121 : : }
6122 : 0 : }
6123 : :
6124 : :
6125 : : /*
6126 : : FoldDivCeil - check division for constant folding.
6127 : : */
6128 : :
6129 : 0 : static void FoldDivCeil (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3)
6130 : : {
6131 : 0 : if (BinaryOperands (quad, op2, op3))
6132 : : {
6133 : : /* avoid gcc warning by using compound statement even if not strictly necessary. */
6134 : 0 : if ((BinaryOperandRealFamily (op2)) || (BinaryOperandRealFamily (op3)))
6135 : : {
6136 : 0 : FoldBinary (tokenno, p, (m2expr_BuildBinProcedure) {(m2expr_BuildBinProcedure_t) m2expr_BuildRDiv}, quad, op1, op2, op3);
6137 : : }
6138 : : else
6139 : : {
6140 : 0 : FoldBinary (tokenno, p, (m2expr_BuildBinProcedure) {(m2expr_BuildBinProcedure_t) m2expr_BuildDivCeil}, quad, op1, op2, op3);
6141 : : }
6142 : : }
6143 : 0 : }
6144 : :
6145 : :
6146 : : /*
6147 : : CodeDivCeil - encode multiplication.
6148 : : */
6149 : :
6150 : 0 : static void CodeDivCeil (unsigned int quad, unsigned int left, unsigned int right)
6151 : : {
6152 : 0 : if (BinaryOperands (quad, left, right))
6153 : : {
6154 : : /* avoid gcc warning by using compound statement even if not strictly necessary. */
6155 : 0 : if ((BinaryOperandRealFamily (left)) || (BinaryOperandRealFamily (right)))
6156 : : {
6157 : 0 : CodeBinary ((m2expr_BuildBinProcedure) {(m2expr_BuildBinProcedure_t) m2expr_BuildRDiv}, quad);
6158 : : }
6159 : : else
6160 : : {
6161 : 0 : CodeBinary ((m2expr_BuildBinProcedure) {(m2expr_BuildBinProcedure_t) m2expr_BuildDivCeil}, quad);
6162 : : }
6163 : : }
6164 : 0 : }
6165 : :
6166 : :
6167 : : /*
6168 : : FoldModCeil - check modulus for constant folding.
6169 : : */
6170 : :
6171 : 0 : static void FoldModCeil (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3)
6172 : : {
6173 : 0 : if (BinaryOperands (quad, op2, op3))
6174 : : {
6175 : 0 : FoldBinary (tokenno, p, (m2expr_BuildBinProcedure) {(m2expr_BuildBinProcedure_t) m2expr_BuildModCeil}, quad, op1, op2, op3);
6176 : : }
6177 : 0 : }
6178 : :
6179 : :
6180 : : /*
6181 : : CodeModCeil - encode multiplication.
6182 : : */
6183 : :
6184 : 0 : static void CodeModCeil (unsigned int quad, unsigned int left, unsigned int right)
6185 : : {
6186 : 0 : if (BinaryOperands (quad, left, right))
6187 : : {
6188 : 0 : CodeBinary ((m2expr_BuildBinProcedure) {(m2expr_BuildBinProcedure_t) m2expr_BuildModCeil}, quad);
6189 : : }
6190 : 0 : }
6191 : :
6192 : :
6193 : : /*
6194 : : FoldDivFloor - check division for constant folding.
6195 : : */
6196 : :
6197 : 0 : static void FoldDivFloor (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3)
6198 : : {
6199 : 0 : if (BinaryOperands (quad, op2, op3))
6200 : : {
6201 : : /* avoid gcc warning by using compound statement even if not strictly necessary. */
6202 : 0 : if ((BinaryOperandRealFamily (op2)) || (BinaryOperandRealFamily (op3)))
6203 : : {
6204 : 0 : FoldBinary (tokenno, p, (m2expr_BuildBinProcedure) {(m2expr_BuildBinProcedure_t) m2expr_BuildRDiv}, quad, op1, op2, op3);
6205 : : }
6206 : : else
6207 : : {
6208 : 0 : FoldBinary (tokenno, p, (m2expr_BuildBinProcedure) {(m2expr_BuildBinProcedure_t) m2expr_BuildDivFloor}, quad, op1, op2, op3);
6209 : : }
6210 : : }
6211 : 0 : }
6212 : :
6213 : :
6214 : : /*
6215 : : CodeDivFloor - encode multiplication.
6216 : : */
6217 : :
6218 : 0 : static void CodeDivFloor (unsigned int quad, unsigned int left, unsigned int right)
6219 : : {
6220 : 0 : if (BinaryOperands (quad, left, right))
6221 : : {
6222 : : /* avoid gcc warning by using compound statement even if not strictly necessary. */
6223 : 0 : if ((BinaryOperandRealFamily (left)) || (BinaryOperandRealFamily (right)))
6224 : : {
6225 : 0 : CodeBinary ((m2expr_BuildBinProcedure) {(m2expr_BuildBinProcedure_t) m2expr_BuildRDiv}, quad);
6226 : : }
6227 : : else
6228 : : {
6229 : 0 : CodeBinary ((m2expr_BuildBinProcedure) {(m2expr_BuildBinProcedure_t) m2expr_BuildDivFloor}, quad);
6230 : : }
6231 : : }
6232 : 0 : }
6233 : :
6234 : :
6235 : : /*
6236 : : FoldModFloor - check modulus for constant folding.
6237 : : */
6238 : :
6239 : 0 : static void FoldModFloor (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3)
6240 : : {
6241 : 0 : if (BinaryOperands (quad, op2, op3))
6242 : : {
6243 : 0 : FoldBinary (tokenno, p, (m2expr_BuildBinProcedure) {(m2expr_BuildBinProcedure_t) m2expr_BuildModFloor}, quad, op1, op2, op3);
6244 : : }
6245 : 0 : }
6246 : :
6247 : :
6248 : : /*
6249 : : CodeModFloor - encode modulus.
6250 : : */
6251 : :
6252 : 0 : static void CodeModFloor (unsigned int quad, unsigned int left, unsigned int right)
6253 : : {
6254 : 0 : if (BinaryOperands (quad, left, right))
6255 : : {
6256 : 0 : CodeBinary ((m2expr_BuildBinProcedure) {(m2expr_BuildBinProcedure_t) m2expr_BuildModFloor}, quad);
6257 : : }
6258 : 0 : }
6259 : :
6260 : :
6261 : : /*
6262 : : FoldBuiltinConst -
6263 : : */
6264 : :
6265 : 28234 : static void FoldBuiltinConst (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int quad, unsigned int result, unsigned int constDesc)
6266 : : {
6267 : 28234 : tree value;
6268 : :
6269 : 28234 : value = m2builtins_GetBuiltinConst (reinterpret_cast <char * > (NameKey_KeyToCharStar ((NameKey_Name) (constDesc))));
6270 : 28234 : if (value == NULL)
6271 : : {
6272 : 0 : M2MetaError_MetaErrorT1 (tokenno, (const char *) "unknown built in constant {%1Ead}", 33, constDesc);
6273 : : }
6274 : : else
6275 : : {
6276 : 28234 : SymbolConversion_AddModGcc (result, value);
6277 : 28234 : (*p.proc) (result);
6278 : 28234 : NoChange = false;
6279 : 28234 : M2Quads_SubQuad (quad);
6280 : : }
6281 : 28234 : }
6282 : :
6283 : :
6284 : : /*
6285 : : FoldBuiltinTypeInfo - attempts to fold a builtin attribute value on type op2.
6286 : : */
6287 : :
6288 : 360 : static void FoldBuiltinTypeInfo (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3)
6289 : : {
6290 : 360 : tree t;
6291 : 360 : location_t location;
6292 : :
6293 : 360 : if ((SymbolConversion_GccKnowsAbout (op2)) && (M2GCCDeclare_CompletelyResolved (op2)))
6294 : : {
6295 : 360 : location = M2LexBuf_TokenToLocation (tokenno);
6296 : 360 : t = m2builtins_GetBuiltinTypeInfo (location, SymbolConversion_Mod2Gcc (op2), const_cast <const char * > (static_cast <char * > (NameKey_KeyToCharStar ((NameKey_Name) (op3)))));
6297 : 360 : if (t == NULL)
6298 : : {
6299 : 0 : M2MetaError_MetaErrorT2 (tokenno, (const char *) "unknown built in constant {%1Ead} attribute for type {%2ad}", 59, op3, op2);
6300 : : }
6301 : : else
6302 : : {
6303 : 360 : SymbolConversion_AddModGcc (op1, t);
6304 : 360 : (*p.proc) (op1);
6305 : 360 : NoChange = false;
6306 : 360 : M2Quads_SubQuad (quad);
6307 : : }
6308 : : }
6309 : 360 : }
6310 : :
6311 : :
6312 : : /*
6313 : : FoldTBitsize - attempt to fold the standard function SYSTEM.TBITSIZE
6314 : : quadruple. If the quadruple is folded it is removed.
6315 : : */
6316 : :
6317 : 60 : static void FoldTBitsize (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int quad, unsigned int res, unsigned int type)
6318 : : {
6319 : 60 : location_t location;
6320 : :
6321 : 60 : location = M2LexBuf_TokenToLocation (tokenno);
6322 : 60 : M2GCCDeclare_TryDeclareType (type);
6323 : 60 : type = SymbolTable_GetDType (type);
6324 : 60 : if (M2GCCDeclare_CompletelyResolved (type))
6325 : : {
6326 : 60 : SymbolConversion_AddModGcc (res, m2expr_BuildSystemTBitSize (location, SymbolConversion_Mod2Gcc (type)));
6327 : 60 : (*p.proc) (res);
6328 : 60 : NoChange = false;
6329 : 60 : M2Quads_SubQuad (quad);
6330 : : }
6331 : 60 : }
6332 : :
6333 : :
6334 : : /*
6335 : : FoldStandardFunction - attempts to fold a standard function.
6336 : : */
6337 : :
6338 : 2768 : static void FoldStandardFunction (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3)
6339 : : {
6340 : 2768 : DynamicStrings_String s;
6341 : 2768 : unsigned int type;
6342 : 2768 : unsigned int d;
6343 : 2768 : unsigned int result;
6344 : 2768 : location_t location;
6345 : :
6346 : 2768 : location = M2LexBuf_TokenToLocation (tokenno);
6347 : 2768 : if ((SymbolTable_GetSymName (op2)) == (NameKey_MakeKey ((const char *) "Length", 6)))
6348 : : {
6349 : : /* avoid dangling else. */
6350 : 0 : M2GCCDeclare_TryDeclareConstant (tokenno, op3);
6351 : 0 : if ((SymbolTable_IsConst (op3)) && (SymbolConversion_GccKnowsAbout (op3)))
6352 : : {
6353 : : /* avoid gcc warning by using compound statement even if not strictly necessary. */
6354 : : /* fine, we can take advantage of this and fold constants */
6355 : 0 : if (SymbolTable_IsConst (op1))
6356 : : {
6357 : 0 : if (SymbolTable_IsConstString (op3))
6358 : : {
6359 : 0 : SymbolConversion_AddModGcc (op1, FindSize (tokenno, op3));
6360 : 0 : (*p.proc) (op1);
6361 : 0 : NoChange = false;
6362 : 0 : M2Quads_SubQuad (quad);
6363 : : }
6364 : : else
6365 : : {
6366 : 0 : M2MetaError_MetaErrorT1 (tokenno, (const char *) "parameter to LENGTH must be a string {%1Ead}", 44, op3);
6367 : : }
6368 : : }
6369 : : else
6370 : : {
6371 : : /* rewrite the quad to use becomes. */
6372 : 0 : d = SymbolTable_GetStringLength (tokenno, op3);
6373 : 0 : s = FormatStrings_Sprintf1 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "%d", 2)), (const unsigned char *) &d, (sizeof (d)-1));
6374 : 0 : result = SymbolTable_MakeConstLit (tokenno, NameKey_makekey (DynamicStrings_string (s)), M2Base_Cardinal);
6375 : 0 : s = DynamicStrings_KillString (s);
6376 : 0 : M2GCCDeclare_TryDeclareConstant (tokenno, result);
6377 : 0 : M2Quads_PutQuad (quad, M2Quads_BecomesOp, op1, SymbolTable_NulSym, result);
6378 : : }
6379 : : }
6380 : : }
6381 : 2768 : else if ((SymbolTable_GetSymName (op2)) == (NameKey_MakeKey ((const char *) "CAP", 3)))
6382 : : {
6383 : : /* avoid dangling else. */
6384 : 730 : M2GCCDeclare_TryDeclareConstant (tokenno, op3);
6385 : 730 : if ((SymbolTable_IsConst (op3)) && (SymbolConversion_GccKnowsAbout (op3)))
6386 : : {
6387 : : /* fine, we can take advantage of this and fold constants */
6388 : 24 : if (SymbolTable_IsConst (op1))
6389 : : {
6390 : : /* avoid gcc warning by using compound statement even if not strictly necessary. */
6391 : 24 : if (((SymbolTable_IsConstString (op3)) && ((SymbolTable_GetStringLength (tokenno, op3)) == 1)) || ((SymbolTable_GetType (op3)) == M2Base_Char))
6392 : : {
6393 : 24 : SymbolConversion_AddModGcc (op1, m2expr_BuildCap (location, SymbolConversion_Mod2Gcc (op3)));
6394 : 24 : (*p.proc) (op1);
6395 : 24 : NoChange = false;
6396 : 24 : M2Quads_SubQuad (quad);
6397 : : }
6398 : : else
6399 : : {
6400 : 0 : M2MetaError_MetaErrorT1 (tokenno, (const char *) "parameter to CAP must be a single character {%1Ead}", 51, op3);
6401 : : }
6402 : : }
6403 : : }
6404 : : }
6405 : 2038 : else if ((SymbolTable_GetSymName (op2)) == (NameKey_MakeKey ((const char *) "ABS", 3)))
6406 : : {
6407 : : /* avoid dangling else. */
6408 : 580 : M2GCCDeclare_TryDeclareConstant (tokenno, op3);
6409 : 580 : if ((SymbolTable_IsConst (op3)) && (SymbolConversion_GccKnowsAbout (op3)))
6410 : : {
6411 : : /* fine, we can take advantage of this and fold constants */
6412 : 12 : if (SymbolTable_IsConst (op1))
6413 : : {
6414 : 12 : SymbolConversion_AddModGcc (op1, m2expr_BuildAbs (location, SymbolConversion_Mod2Gcc (op3)));
6415 : 12 : (*p.proc) (op1);
6416 : 12 : NoChange = false;
6417 : 12 : M2Quads_SubQuad (quad);
6418 : : }
6419 : : }
6420 : : }
6421 : 1458 : else if (op2 == M2Base_Im)
6422 : : {
6423 : : /* avoid dangling else. */
6424 : 90 : M2GCCDeclare_TryDeclareConstant (tokenno, op3);
6425 : 90 : if ((SymbolTable_IsConst (op3)) && (SymbolConversion_GccKnowsAbout (op3)))
6426 : : {
6427 : : /* fine, we can take advantage of this and fold constants */
6428 : 36 : if (SymbolTable_IsConst (op1))
6429 : : {
6430 : 36 : SymbolConversion_AddModGcc (op1, m2expr_BuildIm (SymbolConversion_Mod2Gcc (op3)));
6431 : 36 : (*p.proc) (op1);
6432 : 36 : NoChange = false;
6433 : 36 : M2Quads_SubQuad (quad);
6434 : : }
6435 : : }
6436 : : }
6437 : 1368 : else if (op2 == M2Base_Re)
6438 : : {
6439 : : /* avoid dangling else. */
6440 : 90 : M2GCCDeclare_TryDeclareConstant (tokenno, op3);
6441 : 90 : if ((SymbolTable_IsConst (op3)) && (SymbolConversion_GccKnowsAbout (op3)))
6442 : : {
6443 : : /* fine, we can take advantage of this and fold constants */
6444 : 36 : if (SymbolTable_IsConst (op1))
6445 : : {
6446 : 36 : SymbolConversion_AddModGcc (op1, m2expr_BuildRe (SymbolConversion_Mod2Gcc (op3)));
6447 : 36 : (*p.proc) (op1);
6448 : 36 : NoChange = false;
6449 : 36 : M2Quads_SubQuad (quad);
6450 : : }
6451 : : }
6452 : : }
6453 : 1278 : else if (op2 == M2Base_Cmplx)
6454 : : {
6455 : : /* avoid dangling else. */
6456 : 1218 : M2GCCDeclare_TryDeclareConstant (tokenno, SymbolTable_GetNth (op3, 1));
6457 : 1218 : M2GCCDeclare_TryDeclareConstant (tokenno, SymbolTable_GetNth (op3, 2));
6458 : 1218 : if ((((SymbolTable_IsConst (SymbolTable_GetNth (op3, 1))) && (SymbolConversion_GccKnowsAbout (SymbolTable_GetNth (op3, 1)))) && (SymbolTable_IsConst (SymbolTable_GetNth (op3, 2)))) && (SymbolConversion_GccKnowsAbout (SymbolTable_GetNth (op3, 2))))
6459 : : {
6460 : : /* fine, we can take advantage of this and fold constants */
6461 : 414 : if (SymbolTable_IsConst (op1))
6462 : : {
6463 : 414 : type = M2Base_GetCmplxReturnType (SymbolTable_GetType (SymbolTable_GetNth (op3, 1)), SymbolTable_GetType (SymbolTable_GetNth (op3, 2)));
6464 : 414 : if (type == SymbolTable_NulSym)
6465 : : {
6466 : 0 : M2MetaError_MetaErrorT2 (tokenno, (const char *) "real {%1Eatd} and imaginary {%2atd} types are incompatible", 58, SymbolTable_GetNth (op3, 1), SymbolTable_GetNth (op3, 2));
6467 : : }
6468 : : else
6469 : : {
6470 : 414 : SymbolConversion_AddModGcc (op1, m2expr_BuildCmplx (location, SymbolConversion_Mod2Gcc (type), SymbolConversion_Mod2Gcc (SymbolTable_GetNth (op3, 1)), SymbolConversion_Mod2Gcc (SymbolTable_GetNth (op3, 2))));
6471 : 414 : (*p.proc) (op1);
6472 : 414 : NoChange = false;
6473 : 414 : M2Quads_SubQuad (quad);
6474 : : }
6475 : : }
6476 : : }
6477 : : }
6478 : 60 : else if (op2 == M2System_TBitSize)
6479 : : {
6480 : : /* avoid dangling else. */
6481 : 60 : FoldTBitsize (tokenno, p, quad, op1, op3);
6482 : : }
6483 : : else
6484 : : {
6485 : : /* avoid dangling else. */
6486 : 0 : M2Error_InternalError ((const char *) "only expecting LENGTH, CAP, ABS, IM, RE", 39);
6487 : : }
6488 : 2768 : }
6489 : :
6490 : :
6491 : : /*
6492 : : CodeStandardFunction -
6493 : : */
6494 : :
6495 : 282 : static void CodeStandardFunction (unsigned int quad, unsigned int result, unsigned int function, unsigned int param)
6496 : : {
6497 : 282 : unsigned int type;
6498 : 282 : location_t location;
6499 : :
6500 : 282 : M2GCCDeclare_DeclareConstant (CurrentQuadToken, param);
6501 : 282 : M2GCCDeclare_DeclareConstructor (CurrentQuadToken, quad, param);
6502 : 282 : location = M2LexBuf_TokenToLocation (CurrentQuadToken);
6503 : 282 : if ((function != SymbolTable_NulSym) && ((SymbolTable_GetSymName (function)) == (NameKey_MakeKey ((const char *) "Length", 6))))
6504 : : {
6505 : : /* avoid dangling else. */
6506 : 0 : if (SymbolTable_IsConst (result))
6507 : : {
6508 : 0 : M2Error_InternalError ((const char *) "LENGTH function should already have been folded", 47);
6509 : : }
6510 : : }
6511 : 282 : else if ((function != SymbolTable_NulSym) && ((SymbolTable_GetSymName (function)) == (NameKey_MakeKey ((const char *) "CAP", 3))))
6512 : : {
6513 : : /* avoid dangling else. */
6514 : 82 : if (SymbolTable_IsConst (result))
6515 : : {
6516 : 0 : M2Error_InternalError ((const char *) "CAP function should already have been folded", 44);
6517 : : }
6518 : : else
6519 : : {
6520 : 82 : m2statement_BuildAssignmentStatement (location, SymbolConversion_Mod2Gcc (result), m2expr_BuildCap (location, SymbolConversion_Mod2Gcc (param)));
6521 : : }
6522 : : }
6523 : 200 : else if ((function != SymbolTable_NulSym) && ((SymbolTable_GetSymName (function)) == (NameKey_MakeKey ((const char *) "ABS", 3))))
6524 : : {
6525 : : /* avoid dangling else. */
6526 : 92 : if (SymbolTable_IsConst (result))
6527 : : {
6528 : 0 : M2Error_InternalError ((const char *) "ABS function should already have been folded", 44);
6529 : : }
6530 : : else
6531 : : {
6532 : 92 : m2statement_BuildAssignmentStatement (location, SymbolConversion_Mod2Gcc (result), m2expr_BuildAbs (location, SymbolConversion_Mod2Gcc (param)));
6533 : : }
6534 : : }
6535 : 108 : else if (function == M2Base_Im)
6536 : : {
6537 : : /* avoid dangling else. */
6538 : 18 : if (SymbolTable_IsConst (result))
6539 : : {
6540 : 0 : M2Error_InternalError ((const char *) "IM function should already have been folded", 43);
6541 : : }
6542 : : else
6543 : : {
6544 : 18 : m2statement_BuildAssignmentStatement (location, SymbolConversion_Mod2Gcc (result), m2expr_BuildIm (SymbolConversion_Mod2Gcc (param)));
6545 : : }
6546 : : }
6547 : 90 : else if (function == M2Base_Re)
6548 : : {
6549 : : /* avoid dangling else. */
6550 : 18 : if (SymbolTable_IsConst (result))
6551 : : {
6552 : 0 : M2Error_InternalError ((const char *) "RE function should already have been folded", 43);
6553 : : }
6554 : : else
6555 : : {
6556 : 18 : m2statement_BuildAssignmentStatement (location, SymbolConversion_Mod2Gcc (result), m2expr_BuildRe (SymbolConversion_Mod2Gcc (param)));
6557 : : }
6558 : : }
6559 : 72 : else if (function == M2Base_Cmplx)
6560 : : {
6561 : : /* avoid dangling else. */
6562 : 72 : if (SymbolTable_IsConst (result))
6563 : : {
6564 : 0 : M2Error_InternalError ((const char *) "CMPLX function should already have been folded", 46);
6565 : : }
6566 : : else
6567 : : {
6568 : 72 : type = M2Base_GetCmplxReturnType (SymbolTable_GetType (SymbolTable_GetNth (param, 1)), SymbolTable_GetType (SymbolTable_GetNth (param, 2)));
6569 : 72 : if (type == SymbolTable_NulSym)
6570 : : {
6571 : 0 : M2MetaError_MetaErrorT2 (CurrentQuadToken, (const char *) "real {%1Eatd} and imaginary {%2atd} types are incompatible", 58, SymbolTable_GetNth (param, 1), SymbolTable_GetNth (param, 2));
6572 : : }
6573 : : else
6574 : : {
6575 : 72 : m2statement_BuildAssignmentStatement (location, SymbolConversion_Mod2Gcc (result), m2expr_BuildCmplx (location, SymbolConversion_Mod2Gcc (type), SymbolConversion_Mod2Gcc (SymbolTable_GetNth (param, 1)), SymbolConversion_Mod2Gcc (SymbolTable_GetNth (param, 2))));
6576 : : }
6577 : : }
6578 : : }
6579 : 0 : else if (function == M2System_TBitSize)
6580 : : {
6581 : : /* avoid dangling else. */
6582 : 0 : if (SymbolTable_IsConst (result))
6583 : : {
6584 : 0 : M2Error_InternalError ((const char *) "TBITSIZE function should already have been folded", 49);
6585 : : }
6586 : : else
6587 : : {
6588 : 0 : m2statement_BuildAssignmentStatement (location, SymbolConversion_Mod2Gcc (result), m2expr_BuildTBitSize (location, SymbolConversion_Mod2Gcc (param)));
6589 : : }
6590 : : }
6591 : : else
6592 : : {
6593 : : /* avoid dangling else. */
6594 : 0 : M2Error_InternalError ((const char *) "expecting LENGTH, CAP, ABS, IM", 30);
6595 : : }
6596 : 282 : }
6597 : :
6598 : :
6599 : : /*
6600 : : CodeSavePriority - checks to see whether op2 is reachable and is directly accessible
6601 : : externally. If so then it saves the current interrupt priority
6602 : : in op1 and sets the current priority to that determined by
6603 : : appropriate module.
6604 : :
6605 : : op1 := op3(GetModuleScope(op2))
6606 : : */
6607 : :
6608 : 420 : static void CodeSavePriority (unsigned int oldValue, unsigned int scopeSym, unsigned int procedureSym)
6609 : : {
6610 : 420 : tree funcTree;
6611 : 420 : unsigned int mod;
6612 : 420 : NameKey_Name n;
6613 : 420 : location_t location;
6614 : :
6615 : 420 : location = M2LexBuf_TokenToLocation (CurrentQuadToken);
6616 : 420 : if (((SymbolTable_IsModule (scopeSym)) || (SymbolTable_IsDefImp (scopeSym))) || ((SymbolTable_IsProcedure (scopeSym)) && (SymbolTable_GetNeedSavePriority (scopeSym))))
6617 : : {
6618 : 206 : if (SymbolTable_IsProcedure (scopeSym))
6619 : : {
6620 : 130 : mod = SymbolTable_GetModuleScope (scopeSym);
6621 : : }
6622 : : else
6623 : : {
6624 : 76 : M2Debug_Assert ((SymbolTable_IsModule (scopeSym)) || (SymbolTable_IsDefImp (scopeSym)));
6625 : 76 : mod = scopeSym;
6626 : : }
6627 : 206 : if ((SymbolTable_GetPriority (mod)) != SymbolTable_NulSym)
6628 : : {
6629 : 206 : if (PriorityDebugging)
6630 : : {
6631 : : n = SymbolTable_GetSymName (scopeSym);
6632 : : M2Printf_printf1 ((const char *) "procedure <%a> needs to save interrupts\\n", 41, (const unsigned char *) &n, (sizeof (n)-1));
6633 : : }
6634 : 206 : M2GCCDeclare_DeclareConstant (CurrentQuadToken, SymbolTable_GetPriority (mod));
6635 : 206 : m2statement_BuildParam (location, SymbolConversion_Mod2Gcc (SymbolTable_GetPriority (mod)));
6636 : 206 : funcTree = m2statement_BuildProcedureCallTree (location, SymbolConversion_Mod2Gcc (procedureSym), SymbolConversion_Mod2Gcc (SymbolTable_GetType (procedureSym)));
6637 : 206 : funcTree = m2statement_BuildFunctValue (location, SymbolConversion_Mod2Gcc (oldValue));
6638 : 206 : m2type_AddStatement (location, funcTree);
6639 : : }
6640 : : }
6641 : 420 : }
6642 : :
6643 : :
6644 : : /*
6645 : : CodeRestorePriority - checks to see whether op2 is reachable and is directly accessible
6646 : : externally. If so then it restores the previous interrupt priority
6647 : : held in op1.
6648 : :
6649 : : op1 := op3(op1)
6650 : : */
6651 : :
6652 : 412 : static void CodeRestorePriority (unsigned int oldValue, unsigned int scopeSym, unsigned int procedureSym)
6653 : : {
6654 : 412 : tree funcTree;
6655 : 412 : unsigned int mod;
6656 : 412 : NameKey_Name n;
6657 : 412 : location_t location;
6658 : :
6659 : 412 : location = M2LexBuf_TokenToLocation (CurrentQuadToken);
6660 : 412 : if (((SymbolTable_IsModule (scopeSym)) || (SymbolTable_IsDefImp (scopeSym))) || ((SymbolTable_IsProcedure (scopeSym)) && (SymbolTable_GetNeedSavePriority (scopeSym))))
6661 : : {
6662 : 198 : if (SymbolTable_IsProcedure (scopeSym))
6663 : : {
6664 : 122 : mod = SymbolTable_GetModuleScope (scopeSym);
6665 : : }
6666 : : else
6667 : : {
6668 : 76 : M2Debug_Assert ((SymbolTable_IsModule (scopeSym)) || (SymbolTable_IsDefImp (scopeSym)));
6669 : 76 : mod = scopeSym;
6670 : : }
6671 : 198 : if ((SymbolTable_GetPriority (mod)) != SymbolTable_NulSym)
6672 : : {
6673 : 198 : if (PriorityDebugging)
6674 : : {
6675 : : n = SymbolTable_GetSymName (scopeSym);
6676 : : M2Printf_printf1 ((const char *) "procedure <%a> needs to restore interrupts\\n", 44, (const unsigned char *) &n, (sizeof (n)-1));
6677 : : }
6678 : 198 : m2statement_BuildParam (location, SymbolConversion_Mod2Gcc (oldValue));
6679 : 198 : funcTree = m2statement_BuildProcedureCallTree (location, SymbolConversion_Mod2Gcc (procedureSym), SymbolConversion_Mod2Gcc (SymbolTable_GetType (procedureSym)));
6680 : 198 : funcTree = m2statement_BuildFunctValue (location, SymbolConversion_Mod2Gcc (oldValue));
6681 : 198 : m2type_AddStatement (location, funcTree);
6682 : : }
6683 : : }
6684 : 412 : }
6685 : :
6686 : :
6687 : : /*
6688 : : FoldBinarySet - attempts to fold set arithmetic it removes the quad if successful.
6689 : : */
6690 : :
6691 : 47154 : static void FoldBinarySet (unsigned int tokenno, M2GCCDeclare_WalkAction p, M2GenGCC_DoProcedure op, unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3)
6692 : : {
6693 : 47154 : location_t location;
6694 : :
6695 : : /* firstly try and ensure that constants are declared */
6696 : 47154 : M2GCCDeclare_TryDeclareConstant (tokenno, op2);
6697 : 47154 : M2GCCDeclare_TryDeclareConstant (tokenno, op3);
6698 : 47154 : location = M2LexBuf_TokenToLocation (tokenno);
6699 : 47154 : if ((SymbolConversion_GccKnowsAbout (op2)) && (SymbolConversion_GccKnowsAbout (op3)))
6700 : : {
6701 : 3964 : if (CheckBinaryExpressionTypes (quad, p))
6702 : : {
6703 : 3964 : if (((((SymbolTable_IsConst (op2)) && (SymbolTable_IsConstSet (op2))) && (SymbolTable_IsConst (op3))) && (SymbolTable_IsConstSet (op3))) && (SymbolTable_IsConst (op1)))
6704 : : {
6705 : 212 : if ((SymbolTable_IsValueSolved (op2)) && (SymbolTable_IsValueSolved (op3)))
6706 : : {
6707 : 212 : M2Debug_Assert ((M2Base_MixTypes (FindType (op3), FindType (op2), tokenno)) != SymbolTable_NulSym);
6708 : 212 : SymbolTable_PutConst (op1, M2Base_MixTypes (FindType (op3), FindType (op2), tokenno));
6709 : 212 : SymbolTable_PushValue (op2);
6710 : 212 : SymbolTable_PushValue (op3);
6711 : 212 : (*op.proc) (tokenno);
6712 : 212 : SymbolTable_PopValue (op1);
6713 : 212 : SymbolTable_PushValue (op1);
6714 : 212 : SymbolTable_PutConstSet (op1);
6715 : 212 : SymbolConversion_AddModGcc (op1, m2decl_DeclareKnownConstant (location, SymbolConversion_Mod2Gcc (SymbolTable_GetType (op3)), M2ALU_PopSetTree (tokenno)));
6716 : 212 : (*p.proc) (op1);
6717 : 212 : NoChange = false;
6718 : 212 : M2Quads_SubQuad (quad);
6719 : : }
6720 : : }
6721 : : }
6722 : : }
6723 : 47154 : }
6724 : :
6725 : :
6726 : : /*
6727 : : FoldSetOr - check whether we can fold a set arithmetic or.
6728 : : */
6729 : :
6730 : 8964 : static void FoldSetOr (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3)
6731 : : {
6732 : 0 : FoldBinarySet (tokenno, p, (M2GenGCC_DoProcedure) {(M2GenGCC_DoProcedure_t) M2ALU_SetOr}, quad, op1, op2, op3);
6733 : 0 : }
6734 : :
6735 : :
6736 : : /*
6737 : : CodeSetOr - encode set arithmetic or.
6738 : : */
6739 : :
6740 : 818 : static void CodeSetOr (unsigned int quad)
6741 : : {
6742 : 818 : CodeBinarySet ((m2expr_BuildBinProcedure) {(m2expr_BuildBinProcedure_t) m2expr_BuildLogicalOr}, (M2GenGCC_DoProcedure) {(M2GenGCC_DoProcedure_t) M2ALU_SetOr}, quad);
6743 : 818 : }
6744 : :
6745 : :
6746 : : /*
6747 : : FoldSetAnd - check whether we can fold a logical and.
6748 : : */
6749 : :
6750 : 1904 : static void FoldSetAnd (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3)
6751 : : {
6752 : 0 : FoldBinarySet (tokenno, p, (M2GenGCC_DoProcedure) {(M2GenGCC_DoProcedure_t) M2ALU_SetAnd}, quad, op1, op2, op3);
6753 : 0 : }
6754 : :
6755 : :
6756 : : /*
6757 : : CodeSetAnd - encode set arithmetic and.
6758 : : */
6759 : :
6760 : 60 : static void CodeSetAnd (unsigned int quad)
6761 : : {
6762 : 60 : CodeBinarySet ((m2expr_BuildBinProcedure) {(m2expr_BuildBinProcedure_t) m2expr_BuildLogicalAnd}, (M2GenGCC_DoProcedure) {(M2GenGCC_DoProcedure_t) M2ALU_SetAnd}, quad);
6763 : 60 : }
6764 : :
6765 : :
6766 : : /*
6767 : : CodeBinarySetShift - encode a binary set arithmetic operation.
6768 : : The set maybe larger than a machine word
6769 : : and the value of one word may effect the
6770 : : values of another - ie shift and rotate.
6771 : : Set sizes of a word or less are evaluated
6772 : : with binop, whereas multiword sets are
6773 : : evaluated by M2RTS.
6774 : : */
6775 : :
6776 : 1078 : static void CodeBinarySetShift (m2expr_BuildSetProcedure binop, M2GenGCC_DoProcedure doOp, NameKey_Name var, NameKey_Name left, NameKey_Name right, unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3)
6777 : : {
6778 : 1078 : tree nBits;
6779 : 1078 : tree unbounded;
6780 : 1078 : tree leftproc;
6781 : 1078 : tree rightproc;
6782 : 1078 : tree varproc;
6783 : 1078 : location_t location;
6784 : :
6785 : : /* firstly ensure that constant literals are declared */
6786 : 1078 : M2GCCDeclare_DeclareConstant (CurrentQuadToken, op3);
6787 : 1078 : M2GCCDeclare_DeclareConstant (CurrentQuadToken, op2);
6788 : 1078 : M2GCCDeclare_DeclareConstructor (CurrentQuadToken, quad, op3);
6789 : 1078 : M2GCCDeclare_DeclareConstructor (CurrentQuadToken, quad, op2);
6790 : 1078 : location = M2LexBuf_TokenToLocation (CurrentQuadToken);
6791 : 1078 : if (SymbolTable_IsConst (op1))
6792 : : {
6793 : 0 : if ((SymbolTable_IsValueSolved (op2)) && (SymbolTable_IsValueSolved (op3)))
6794 : : {
6795 : 0 : M2Debug_Assert ((M2Base_MixTypes (FindType (op3), FindType (op2), CurrentQuadToken)) != SymbolTable_NulSym);
6796 : 0 : SymbolTable_PutConst (op1, FindType (op3));
6797 : 0 : SymbolTable_PushValue (op2);
6798 : 0 : SymbolTable_PushValue (op3);
6799 : 0 : (*doOp.proc) (CurrentQuadToken);
6800 : 0 : SymbolTable_PopValue (op1);
6801 : 0 : SymbolTable_PutConstSet (op1);
6802 : : }
6803 : : else
6804 : : {
6805 : 0 : M2MetaError_MetaErrorT0 (CurrentQuadToken, (const char *) "{%E}constant expression cannot be evaluated", 43);
6806 : : }
6807 : : }
6808 : : else
6809 : : {
6810 : 1078 : varproc = SymbolConversion_Mod2Gcc (SymbolTable_FromModuleGetSym (CurrentQuadToken, var, M2System_System));
6811 : 1078 : leftproc = SymbolConversion_Mod2Gcc (SymbolTable_FromModuleGetSym (CurrentQuadToken, left, M2System_System));
6812 : 1078 : rightproc = SymbolConversion_Mod2Gcc (SymbolTable_FromModuleGetSym (CurrentQuadToken, right, M2System_System));
6813 : 1078 : unbounded = SymbolConversion_Mod2Gcc (SymbolTable_GetType (SymbolTable_GetNthParamAny (SymbolTable_FromModuleGetSym (CurrentQuadToken, var, M2System_System), 1)));
6814 : 1078 : SymbolTable_PushValue (M2GCCDeclare_GetTypeMax (SymbolTable_SkipType (SymbolTable_GetType (op1))));
6815 : 1078 : M2ALU_PushIntegerTree (m2convert_BuildConvert (location, m2type_GetM2ZType (), M2ALU_PopIntegerTree (), false));
6816 : 1078 : SymbolTable_PushValue (M2GCCDeclare_GetTypeMin (SymbolTable_SkipType (SymbolTable_GetType (op1))));
6817 : 1078 : M2ALU_PushIntegerTree (m2convert_BuildConvert (location, m2type_GetM2ZType (), M2ALU_PopIntegerTree (), false));
6818 : 1078 : M2ALU_Sub ();
6819 : 1078 : M2ALU_PushCard (1);
6820 : 1078 : M2ALU_PushIntegerTree (m2convert_BuildConvert (location, m2type_GetM2ZType (), M2ALU_PopIntegerTree (), false));
6821 : 1078 : M2ALU_Addn ();
6822 : 1078 : nBits = M2ALU_PopIntegerTree ();
6823 : 1078 : m2expr_BuildBinarySetDo (location, SymbolConversion_Mod2Gcc (SymbolTable_SkipType (SymbolTable_GetType (op1))), SymbolConversion_Mod2Gcc (op1), SymbolConversion_Mod2Gcc (op2), SymbolConversion_Mod2Gcc (op3), (m2expr_BuildSetProcedure_C) binop.proc, (SymbolTable_GetMode (op1)) == SymbolTable_LeftValue, (SymbolTable_GetMode (op2)) == SymbolTable_LeftValue, (SymbolTable_GetMode (op3)) == SymbolTable_LeftValue, nBits, unbounded, varproc, leftproc, rightproc);
6824 : : }
6825 : 1078 : }
6826 : :
6827 : :
6828 : : /*
6829 : : FoldSetShift - check whether we can fold a logical shift.
6830 : : */
6831 : :
6832 : 19942 : static void FoldSetShift (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3)
6833 : : {
6834 : 0 : FoldBinarySet (tokenno, p, (M2GenGCC_DoProcedure) {(M2GenGCC_DoProcedure_t) M2ALU_SetShift}, quad, op1, op2, op3);
6835 : 0 : }
6836 : :
6837 : :
6838 : : /*
6839 : : CodeSetShift - encode set arithmetic shift.
6840 : : */
6841 : :
6842 : 696 : static void CodeSetShift (unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3)
6843 : : {
6844 : 696 : CodeBinarySetShift ((m2expr_BuildSetProcedure) {(m2expr_BuildSetProcedure_t) m2expr_BuildLogicalShift}, (M2GenGCC_DoProcedure) {(M2GenGCC_DoProcedure_t) M2ALU_SetShift}, NameKey_MakeKey ((const char *) "ShiftVal", 8), NameKey_MakeKey ((const char *) "ShiftLeft", 9), NameKey_MakeKey ((const char *) "ShiftRight", 10), quad, op1, op2, op3);
6845 : 696 : }
6846 : :
6847 : :
6848 : : /*
6849 : : FoldSetRotate - check whether we can fold a logical rotate.
6850 : : */
6851 : :
6852 : 16296 : static void FoldSetRotate (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3)
6853 : : {
6854 : 0 : FoldBinarySet (tokenno, p, (M2GenGCC_DoProcedure) {(M2GenGCC_DoProcedure_t) M2ALU_SetRotate}, quad, op1, op2, op3);
6855 : 0 : }
6856 : :
6857 : :
6858 : : /*
6859 : : CodeSetRotate - encode set arithmetic rotate.
6860 : : */
6861 : :
6862 : 382 : static void CodeSetRotate (unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3)
6863 : : {
6864 : 382 : CodeBinarySetShift ((m2expr_BuildSetProcedure) {(m2expr_BuildSetProcedure_t) m2expr_BuildLogicalRotate}, (M2GenGCC_DoProcedure) {(M2GenGCC_DoProcedure_t) M2ALU_SetRotate}, NameKey_MakeKey ((const char *) "RotateVal", 9), NameKey_MakeKey ((const char *) "RotateLeft", 10), NameKey_MakeKey ((const char *) "RotateRight", 11), quad, op1, op2, op3);
6865 : 382 : }
6866 : :
6867 : :
6868 : : /*
6869 : : CodeSetLogicalDifference - encode set arithmetic logical difference.
6870 : : */
6871 : :
6872 : 66 : static void CodeSetLogicalDifference (unsigned int quad)
6873 : : {
6874 : 66 : CodeBinarySet ((m2expr_BuildBinProcedure) {(m2expr_BuildBinProcedure_t) m2expr_BuildLogicalDifference}, (M2GenGCC_DoProcedure) {(M2GenGCC_DoProcedure_t) M2ALU_SetDifference}, quad);
6875 : 66 : }
6876 : :
6877 : :
6878 : : /*
6879 : : FoldSymmetricDifference - check whether we can fold a logical difference.
6880 : : */
6881 : :
6882 : 48 : static void FoldSymmetricDifference (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3)
6883 : : {
6884 : 0 : FoldBinarySet (tokenno, p, (M2GenGCC_DoProcedure) {(M2GenGCC_DoProcedure_t) M2ALU_SetSymmetricDifference}, quad, op1, op2, op3);
6885 : 0 : }
6886 : :
6887 : :
6888 : : /*
6889 : : CodeSetSymmetricDifference - code set difference.
6890 : : */
6891 : :
6892 : 12 : static void CodeSetSymmetricDifference (unsigned int quad)
6893 : : {
6894 : 12 : CodeBinarySet ((m2expr_BuildBinProcedure) {(m2expr_BuildBinProcedure_t) m2expr_BuildSymmetricDifference}, (M2GenGCC_DoProcedure) {(M2GenGCC_DoProcedure_t) M2ALU_SetSymmetricDifference}, quad);
6895 : 12 : }
6896 : :
6897 : :
6898 : : /*
6899 : : CodeUnarySet - encode a unary set arithmetic operation.
6900 : : Set operands may be longer than a word.
6901 : : */
6902 : :
6903 : 22 : static void CodeUnarySet (m2expr_BuildUnarySetFunction unop, M2GenGCC_DoUnaryProcedure constop, unsigned int quad, unsigned int result, unsigned int expr)
6904 : : {
6905 : 22 : location_t location;
6906 : :
6907 : : /* firstly ensure that constant literals are declared */
6908 : 22 : M2GCCDeclare_DeclareConstant (CurrentQuadToken, expr);
6909 : 22 : M2GCCDeclare_DeclareConstructor (CurrentQuadToken, quad, expr);
6910 : 22 : location = M2LexBuf_TokenToLocation (CurrentQuadToken);
6911 : 22 : if (SymbolTable_IsConst (result))
6912 : : {
6913 : 0 : if (SymbolTable_IsValueSolved (expr))
6914 : : {
6915 : 0 : M2Debug_Assert ((FindType (expr)) != SymbolTable_NulSym);
6916 : 0 : SymbolTable_PutConst (result, FindType (expr));
6917 : 0 : SymbolTable_PushValue (expr);
6918 : 0 : (*constop.proc) (CurrentQuadToken);
6919 : 0 : SymbolTable_PopValue (result);
6920 : 0 : SymbolTable_PushValue (result);
6921 : 0 : SymbolTable_PutConstSet (result);
6922 : 0 : M2GCCDeclare_ConstantKnownAndUsed (result, m2decl_DeclareKnownConstant (location, SymbolConversion_Mod2Gcc (SymbolTable_GetType (expr)), M2ALU_PopSetTree (CurrentQuadToken)));
6923 : : }
6924 : : else
6925 : : {
6926 : 0 : M2MetaError_MetaErrorT0 (CurrentQuadToken, (const char *) "{%E}constant expression cannot be evaluated", 43);
6927 : : }
6928 : : }
6929 : : else
6930 : : {
6931 : 22 : checkDeclare (result);
6932 : 22 : m2statement_BuildUnaryForeachWordDo (location, SymbolConversion_Mod2Gcc (SymbolTable_GetType (result)), SymbolConversion_Mod2Gcc (result), SymbolConversion_Mod2Gcc (expr), (m2expr_BuildUnarySetFunction_C) unop.proc, (SymbolTable_GetMode (result)) == SymbolTable_LeftValue, (SymbolTable_GetMode (expr)) == SymbolTable_LeftValue, SymbolTable_IsConst (result), SymbolTable_IsConst (expr));
6933 : : }
6934 : 22 : }
6935 : :
6936 : :
6937 : : /*
6938 : : FoldIncl - check whether we can fold the InclOp.
6939 : : result := result + (1 << expr)
6940 : : */
6941 : :
6942 : 17358 : static void FoldIncl (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int quad, unsigned int result, unsigned int expr)
6943 : : {
6944 : : /* firstly ensure that constant literals are declared */
6945 : 17358 : M2GCCDeclare_TryDeclareConstant (tokenno, expr);
6946 : 17358 : if ((SymbolTable_IsConst (result)) && (SymbolTable_IsConst (expr)))
6947 : : {
6948 : 0 : if ((SymbolConversion_GccKnowsAbout (expr)) && (SymbolTable_IsValueSolved (result)))
6949 : : {
6950 : : /* fine, we can take advantage of this and fold constants */
6951 : 0 : SymbolTable_PushValue (result);
6952 : 0 : M2ALU_AddBit (tokenno, expr);
6953 : 0 : SymbolConversion_AddModGcc (result, M2ALU_PopSetTree (tokenno));
6954 : 0 : (*p.proc) (result);
6955 : 0 : NoChange = false;
6956 : 0 : M2Quads_SubQuad (quad);
6957 : : }
6958 : : }
6959 : 17358 : }
6960 : :
6961 : :
6962 : : /*
6963 : : FoldIfLess - check to see if it is possible to evaluate
6964 : : if op1 < op2 then goto op3.
6965 : : */
6966 : :
6967 : 29674 : static void FoldIfLess (unsigned int tokenno, unsigned int quad, unsigned int left, unsigned int right, unsigned int destQuad)
6968 : : {
6969 : : /* Firstly ensure that constant literals are declared. */
6970 : 29674 : M2GCCDeclare_TryDeclareConstant (tokenno, left);
6971 : 29674 : M2GCCDeclare_TryDeclareConstant (tokenno, right);
6972 : 29674 : if ((SymbolTable_IsConst (left)) && (SymbolTable_IsConst (right)))
6973 : : {
6974 : 1684 : if ((SymbolTable_IsValueSolved (left)) && (SymbolTable_IsValueSolved (right)))
6975 : : {
6976 : : /* We can take advantage of the known values and evaluate the condition. */
6977 : 1684 : SymbolTable_PushValue (left);
6978 : 1684 : SymbolTable_PushValue (right);
6979 : 1684 : if (M2ALU_Less (tokenno))
6980 : : {
6981 : 806 : M2Quads_PutQuad (quad, M2Quads_GotoOp, SymbolTable_NulSym, SymbolTable_NulSym, destQuad);
6982 : : }
6983 : : else
6984 : : {
6985 : 878 : M2Quads_SubQuad (quad);
6986 : : }
6987 : 1684 : NoChange = false;
6988 : : }
6989 : : }
6990 : 29674 : }
6991 : :
6992 : :
6993 : : /*
6994 : : FoldIfGre - check to see if it is possible to evaluate
6995 : : if op1 > op2 then goto op3.
6996 : : */
6997 : :
6998 : 24950 : static void FoldIfGre (unsigned int tokenno, unsigned int quad, unsigned int left, unsigned int right, unsigned int destQuad)
6999 : : {
7000 : : /* Firstly ensure that constant literals are declared. */
7001 : 24950 : M2GCCDeclare_TryDeclareConstant (tokenno, left);
7002 : 24950 : M2GCCDeclare_TryDeclareConstant (tokenno, right);
7003 : 24950 : if ((SymbolTable_IsConst (left)) && (SymbolTable_IsConst (right)))
7004 : : {
7005 : 72 : if ((SymbolTable_IsValueSolved (left)) && (SymbolTable_IsValueSolved (right)))
7006 : : {
7007 : : /* We can take advantage of the known values and evaluate the condition. */
7008 : 72 : SymbolTable_PushValue (left);
7009 : 72 : SymbolTable_PushValue (right);
7010 : 72 : if (M2ALU_Gre (tokenno))
7011 : : {
7012 : 12 : M2Quads_PutQuad (quad, M2Quads_GotoOp, SymbolTable_NulSym, SymbolTable_NulSym, destQuad);
7013 : : }
7014 : : else
7015 : : {
7016 : 60 : M2Quads_SubQuad (quad);
7017 : : }
7018 : 72 : NoChange = false;
7019 : : }
7020 : : }
7021 : 24950 : }
7022 : :
7023 : :
7024 : : /*
7025 : : FoldIfLessEqu - check to see if it is possible to evaluate
7026 : : if op1 <= op2 then goto op3.
7027 : : */
7028 : :
7029 : 27550 : static void FoldIfLessEqu (unsigned int tokenno, unsigned int quad, unsigned int left, unsigned int right, unsigned int destQuad)
7030 : : {
7031 : : /* Firstly ensure that constant literals are declared. */
7032 : 27550 : M2GCCDeclare_TryDeclareConstant (tokenno, left);
7033 : 27550 : M2GCCDeclare_TryDeclareConstant (tokenno, right);
7034 : 27550 : if ((SymbolTable_IsConst (left)) && (SymbolTable_IsConst (right)))
7035 : : {
7036 : 42 : if ((SymbolTable_IsValueSolved (left)) && (SymbolTable_IsValueSolved (right)))
7037 : : {
7038 : : /* We can take advantage of the known values and evaluate the condition. */
7039 : 42 : SymbolTable_PushValue (left);
7040 : 42 : SymbolTable_PushValue (right);
7041 : 42 : if (M2ALU_LessEqu (tokenno))
7042 : : {
7043 : 36 : M2Quads_PutQuad (quad, M2Quads_GotoOp, SymbolTable_NulSym, SymbolTable_NulSym, destQuad);
7044 : : }
7045 : : else
7046 : : {
7047 : 6 : M2Quads_SubQuad (quad);
7048 : : }
7049 : 42 : NoChange = false;
7050 : : }
7051 : : }
7052 : 27550 : }
7053 : :
7054 : :
7055 : : /*
7056 : : FoldIfGreEqu - check to see if it is possible to evaluate
7057 : : if op1 >= op2 then goto op3.
7058 : : */
7059 : :
7060 : 36988 : static void FoldIfGreEqu (unsigned int tokenno, unsigned int quad, unsigned int left, unsigned int right, unsigned int destQuad)
7061 : : {
7062 : : /* Firstly ensure that constant literals are declared. */
7063 : 36988 : M2GCCDeclare_TryDeclareConstant (tokenno, left);
7064 : 36988 : M2GCCDeclare_TryDeclareConstant (tokenno, right);
7065 : 36988 : if ((SymbolTable_IsConst (left)) && (SymbolTable_IsConst (right)))
7066 : : {
7067 : 7198 : if ((SymbolTable_IsValueSolved (left)) && (SymbolTable_IsValueSolved (right)))
7068 : : {
7069 : : /* We can take advantage of the known values and evaluate the condition. */
7070 : 3364 : SymbolTable_PushValue (left);
7071 : 3364 : SymbolTable_PushValue (right);
7072 : 3364 : if (M2ALU_GreEqu (tokenno))
7073 : : {
7074 : 2548 : M2Quads_PutQuad (quad, M2Quads_GotoOp, SymbolTable_NulSym, SymbolTable_NulSym, destQuad);
7075 : : }
7076 : : else
7077 : : {
7078 : 816 : M2Quads_SubQuad (quad);
7079 : : }
7080 : 3364 : NoChange = false;
7081 : : }
7082 : : }
7083 : 36988 : }
7084 : :
7085 : :
7086 : : /*
7087 : : FoldIfIn - check whether we can fold the IfInOp
7088 : : if op1 in op2 then goto op3
7089 : : */
7090 : :
7091 : 24564 : static void FoldIfIn (unsigned int tokenno, unsigned int quad, unsigned int left, unsigned int right, unsigned int destQuad)
7092 : : {
7093 : : /* Firstly ensure that constant literals are declared. */
7094 : 24564 : M2GCCDeclare_TryDeclareConstant (tokenno, left);
7095 : 24564 : M2GCCDeclare_TryDeclareConstant (tokenno, right);
7096 : 24564 : if ((SymbolTable_IsConst (left)) && (SymbolTable_IsConst (right)))
7097 : : {
7098 : 0 : if ((SymbolTable_IsValueSolved (left)) && (SymbolTable_IsValueSolved (right)))
7099 : : {
7100 : 0 : if (CheckBinaryExpressionTypes (quad, (M2GCCDeclare_WalkAction) {(M2GCCDeclare_WalkAction_t) NoWalkProcedure}))
7101 : : {
7102 : : /* We can take advantage of the known values and evaluate the condition. */
7103 : 0 : SymbolTable_PushValue (right);
7104 : 0 : if (M2ALU_SetIn (tokenno, left))
7105 : : {
7106 : 0 : M2Quads_PutQuad (quad, M2Quads_GotoOp, SymbolTable_NulSym, SymbolTable_NulSym, destQuad);
7107 : : }
7108 : : else
7109 : : {
7110 : 0 : M2Quads_SubQuad (quad);
7111 : : }
7112 : : }
7113 : : else
7114 : : {
7115 : 0 : M2Quads_SubQuad (quad);
7116 : : }
7117 : 0 : NoChange = false;
7118 : : }
7119 : : }
7120 : 24564 : }
7121 : :
7122 : :
7123 : : /*
7124 : : FoldIfNotIn - check whether we can fold the IfNotInOp
7125 : : if not (op1 in op2) then goto op3
7126 : : */
7127 : :
7128 : 5210 : static void FoldIfNotIn (unsigned int tokenno, unsigned int quad, unsigned int left, unsigned int right, unsigned int destQuad)
7129 : : {
7130 : : /* Firstly ensure that constant literals are declared. */
7131 : 5210 : M2GCCDeclare_TryDeclareConstant (tokenno, left);
7132 : 5210 : M2GCCDeclare_TryDeclareConstant (tokenno, right);
7133 : 5210 : if ((SymbolTable_IsConst (left)) && (SymbolTable_IsConst (right)))
7134 : : {
7135 : 0 : if ((SymbolTable_IsValueSolved (left)) && (SymbolTable_IsValueSolved (right)))
7136 : : {
7137 : 0 : if (CheckBinaryExpressionTypes (quad, (M2GCCDeclare_WalkAction) {(M2GCCDeclare_WalkAction_t) NoWalkProcedure}))
7138 : : {
7139 : : /* We can take advantage of the known values and evaluate the
7140 : : condition. */
7141 : 0 : SymbolTable_PushValue (right);
7142 : 0 : if (! (M2ALU_SetIn (tokenno, left)))
7143 : : {
7144 : 0 : M2Quads_PutQuad (quad, M2Quads_GotoOp, SymbolTable_NulSym, SymbolTable_NulSym, destQuad);
7145 : : }
7146 : : else
7147 : : {
7148 : 0 : M2Quads_SubQuad (quad);
7149 : : }
7150 : : }
7151 : : else
7152 : : {
7153 : 0 : M2Quads_SubQuad (quad);
7154 : : }
7155 : 0 : NoChange = false;
7156 : : }
7157 : : }
7158 : 5210 : }
7159 : :
7160 : :
7161 : : /*
7162 : : FoldIfEqu - check to see if it is possible to evaluate
7163 : : if op1 = op2 then goto op3.
7164 : : */
7165 : :
7166 : 536855 : static void FoldIfEqu (unsigned int tokenno, unsigned int quad, unsigned int left, unsigned int right, unsigned int destQuad)
7167 : : {
7168 : : /* Firstly ensure that constant literals are declared. */
7169 : 536855 : M2GCCDeclare_TryDeclareConstant (tokenno, left);
7170 : 536855 : M2GCCDeclare_TryDeclareConstant (tokenno, right);
7171 : 536855 : if ((SymbolTable_IsConst (left)) && (SymbolTable_IsConst (right)))
7172 : : {
7173 : 974 : if ((SymbolTable_IsValueSolved (left)) && (SymbolTable_IsValueSolved (right)))
7174 : : {
7175 : : /* We can take advantage of the known values and evaluate the
7176 : : condition. */
7177 : 518 : SymbolTable_PushValue (left);
7178 : 518 : SymbolTable_PushValue (right);
7179 : 518 : if (M2ALU_Equ (tokenno))
7180 : : {
7181 : 344 : M2Quads_PutQuad (quad, M2Quads_GotoOp, SymbolTable_NulSym, SymbolTable_NulSym, destQuad);
7182 : : }
7183 : : else
7184 : : {
7185 : 174 : M2Quads_SubQuad (quad);
7186 : : }
7187 : 518 : NoChange = false;
7188 : : }
7189 : : }
7190 : 536855 : }
7191 : :
7192 : :
7193 : : /*
7194 : : FoldIfNotEqu - check to see if it is possible to evaluate
7195 : : if op1 # op2 then goto op3.
7196 : : */
7197 : :
7198 : 260155 : static void FoldIfNotEqu (unsigned int tokenno, unsigned int quad, unsigned int left, unsigned int right, unsigned int destQuad)
7199 : : {
7200 : : /* Firstly ensure that constant literals are declared. */
7201 : 260155 : M2GCCDeclare_TryDeclareConstant (tokenno, left);
7202 : 260155 : M2GCCDeclare_TryDeclareConstant (tokenno, right);
7203 : 260155 : if ((SymbolTable_IsConst (left)) && (SymbolTable_IsConst (right)))
7204 : : {
7205 : 1434 : if ((SymbolTable_IsValueSolved (left)) && (SymbolTable_IsValueSolved (right)))
7206 : : {
7207 : : /* We can take advantage of the known values and evaluate the
7208 : : condition. */
7209 : 1368 : SymbolTable_PushValue (left);
7210 : 1368 : SymbolTable_PushValue (right);
7211 : 1368 : if (M2ALU_NotEqu (tokenno))
7212 : : {
7213 : 1002 : M2Quads_PutQuad (quad, M2Quads_GotoOp, SymbolTable_NulSym, SymbolTable_NulSym, destQuad);
7214 : : }
7215 : : else
7216 : : {
7217 : 366 : M2Quads_SubQuad (quad);
7218 : : }
7219 : 1368 : NoChange = false;
7220 : : }
7221 : : }
7222 : 260155 : }
7223 : :
7224 : :
7225 : : /*
7226 : : GetSetLimits - assigns low and high to the limits of the declared, set.
7227 : : */
7228 : :
7229 : 2680 : static void GetSetLimits (unsigned int set, unsigned int *low, unsigned int *high)
7230 : : {
7231 : 2680 : unsigned int type;
7232 : :
7233 : 2680 : type = SymbolTable_GetType (set);
7234 : 2680 : if (SymbolTable_IsSubrange (type))
7235 : : {
7236 : 2028 : SymbolTable_GetSubrange (type, high, low);
7237 : : }
7238 : : else
7239 : : {
7240 : 652 : (*low) = M2GCCDeclare_GetTypeMin (type);
7241 : 652 : (*high) = M2GCCDeclare_GetTypeMax (type);
7242 : : }
7243 : 2680 : }
7244 : :
7245 : :
7246 : : /*
7247 : : GetFieldNo - returns the field number in the, set, which contains, element.
7248 : : */
7249 : :
7250 : 1344 : static int GetFieldNo (unsigned int tokenno, unsigned int element, unsigned int set, tree *offset)
7251 : : {
7252 : 1344 : unsigned int low;
7253 : 1344 : unsigned int high;
7254 : 1344 : unsigned int bpw;
7255 : 1344 : unsigned int c;
7256 : 1344 : location_t location;
7257 : :
7258 : 1344 : location = M2LexBuf_TokenToLocation (tokenno);
7259 : 1344 : bpw = m2decl_GetBitsPerBitset ();
7260 : 1344 : GetSetLimits (set, &low, &high);
7261 : : /* check element is legal */
7262 : 1344 : SymbolTable_PushValue (element);
7263 : 1344 : SymbolTable_PushValue (low);
7264 : 1344 : if (M2ALU_Less (tokenno))
7265 : : {
7266 : : /* out of range */
7267 : : return -1;
7268 : : }
7269 : : else
7270 : : {
7271 : 1338 : SymbolTable_PushValue (element);
7272 : 1338 : SymbolTable_PushValue (high);
7273 : 1338 : if (M2ALU_Gre (tokenno))
7274 : : {
7275 : : return -1;
7276 : : }
7277 : : }
7278 : : /* all legal */
7279 : 1338 : SymbolTable_PushValue (low);
7280 : 1338 : (*offset) = M2ALU_PopIntegerTree ();
7281 : 1338 : c = 0;
7282 : 1338 : SymbolTable_PushValue (element);
7283 : 1338 : SymbolTable_PushValue (low);
7284 : 1338 : M2ALU_PushIntegerTree (m2convert_ToCardinal (location, M2ALU_PopIntegerTree ()));
7285 : 1338 : M2ALU_PushCard (bpw);
7286 : 1338 : M2ALU_PushIntegerTree (m2convert_ToCardinal (location, M2ALU_PopIntegerTree ()));
7287 : 1338 : M2ALU_Addn ();
7288 : 2832 : while (M2ALU_GreEqu (tokenno))
7289 : : {
7290 : 156 : c += 1; /* move onto next field */
7291 : 156 : SymbolTable_PushValue (element); /* move onto next field */
7292 : 156 : M2ALU_PushIntegerTree (m2convert_ToCardinal (location, M2ALU_PopIntegerTree ()));
7293 : 156 : M2ALU_PushCard ((c+1)*bpw);
7294 : 156 : SymbolTable_PushValue (low);
7295 : 156 : M2ALU_PushIntegerTree (m2convert_ToCardinal (location, M2ALU_PopIntegerTree ()));
7296 : 156 : M2ALU_Addn ();
7297 : 156 : M2ALU_PushIntegerTree ((*offset));
7298 : 156 : M2ALU_PushIntegerTree (m2convert_ToCardinal (location, M2ALU_PopIntegerTree ()));
7299 : 156 : M2ALU_PushCard (bpw);
7300 : 156 : M2ALU_PushIntegerTree (m2convert_ToCardinal (location, M2ALU_PopIntegerTree ()));
7301 : 156 : M2ALU_Addn ();
7302 : 156 : (*offset) = M2ALU_PopIntegerTree ();
7303 : : }
7304 : 1338 : return (int ) (c);
7305 : : /* static analysis guarentees a RETURN statement will be used before here. */
7306 : : __builtin_unreachable ();
7307 : : }
7308 : :
7309 : :
7310 : : /*
7311 : : CodeIncl - encode an InclOp:
7312 : : result := result + (1 << expr)
7313 : : */
7314 : :
7315 : 782 : static void CodeIncl (unsigned int result, unsigned int expr)
7316 : : {
7317 : 782 : unsigned int low;
7318 : 782 : unsigned int high;
7319 : 782 : tree offset;
7320 : 782 : int fieldno;
7321 : 782 : location_t location;
7322 : :
7323 : : /* firstly ensure that constant literals are declared */
7324 : 782 : M2GCCDeclare_DeclareConstant (CurrentQuadToken, expr);
7325 : 782 : location = M2LexBuf_TokenToLocation (CurrentQuadToken);
7326 : 782 : if (SymbolTable_IsConst (result))
7327 : : {
7328 : 0 : if (SymbolTable_IsConst (expr))
7329 : : {
7330 : 0 : M2Error_InternalError ((const char *) "this quadruple should have been removed by FoldIncl", 51);
7331 : : }
7332 : : else
7333 : : {
7334 : 0 : M2Error_InternalError ((const char *) "should not get to here (why are we generating <incl const, var> ?)", 66);
7335 : : }
7336 : : }
7337 : : else
7338 : : {
7339 : 782 : if (SymbolTable_IsConst (expr))
7340 : : {
7341 : 340 : fieldno = GetFieldNo (CurrentQuadToken, expr, SymbolTable_GetType (result), &offset);
7342 : 340 : if (fieldno >= 0)
7343 : : {
7344 : 340 : SymbolTable_PushValue (expr);
7345 : 340 : M2ALU_PushIntegerTree (offset);
7346 : 340 : M2ALU_Sub ();
7347 : 340 : m2statement_BuildIncludeVarConst (location, SymbolConversion_Mod2Gcc (SymbolTable_GetType (result)), SymbolConversion_Mod2Gcc (result), M2ALU_PopIntegerTree (), (SymbolTable_GetMode (result)) == SymbolTable_LeftValue, fieldno);
7348 : : }
7349 : : else
7350 : : {
7351 : 0 : M2MetaError_MetaErrorT1 (CurrentQuadToken, (const char *) "bit exceeded the range of set {%1Eatd}", 38, result);
7352 : : }
7353 : : }
7354 : : else
7355 : : {
7356 : 442 : GetSetLimits (SymbolTable_GetType (result), &low, &high);
7357 : 442 : m2statement_BuildIncludeVarVar (location, SymbolConversion_Mod2Gcc (SymbolTable_GetType (result)), SymbolConversion_Mod2Gcc (result), SymbolConversion_Mod2Gcc (expr), (SymbolTable_GetMode (result)) == SymbolTable_LeftValue, SymbolConversion_Mod2Gcc (low));
7358 : : }
7359 : : }
7360 : 782 : }
7361 : :
7362 : :
7363 : : /*
7364 : : FoldExcl - check whether we can fold the InclOp.
7365 : : op1 := op1 - (1 << op3)
7366 : : */
7367 : :
7368 : 10912 : static void FoldExcl (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int quad, unsigned int result, unsigned int expr)
7369 : : {
7370 : : /* firstly ensure that constant literals are declared */
7371 : 10912 : M2GCCDeclare_TryDeclareConstant (tokenno, expr);
7372 : 10912 : if ((SymbolTable_IsConst (result)) && (SymbolTable_IsConst (expr)))
7373 : : {
7374 : 0 : if ((SymbolConversion_GccKnowsAbout (expr)) && (SymbolTable_IsValueSolved (result)))
7375 : : {
7376 : 0 : SymbolTable_PushValue (result);
7377 : 0 : M2ALU_SubBit (tokenno, expr);
7378 : 0 : SymbolConversion_AddModGcc (result, M2ALU_PopSetTree (tokenno));
7379 : 0 : (*p.proc) (result);
7380 : 0 : NoChange = false;
7381 : 0 : M2Quads_SubQuad (quad);
7382 : : }
7383 : : }
7384 : 10912 : }
7385 : :
7386 : :
7387 : : /*
7388 : : CodeExcl - encode an ExclOp:
7389 : : result := result - (1 << expr)
7390 : : */
7391 : :
7392 : 444 : static void CodeExcl (unsigned int result, unsigned int expr)
7393 : : {
7394 : 444 : unsigned int low;
7395 : 444 : unsigned int high;
7396 : 444 : tree offset;
7397 : 444 : int fieldno;
7398 : 444 : location_t location;
7399 : :
7400 : : /* firstly ensure that constant literals are declared */
7401 : 444 : M2GCCDeclare_DeclareConstant (CurrentQuadToken, expr);
7402 : 444 : location = M2LexBuf_TokenToLocation (CurrentQuadToken);
7403 : 444 : if (SymbolTable_IsConst (result))
7404 : : {
7405 : 0 : M2Error_InternalError ((const char *) "should not get to here (if we do we should consider calling FoldInclOp)", 71);
7406 : : }
7407 : : else
7408 : : {
7409 : 444 : if (SymbolTable_IsConst (expr))
7410 : : {
7411 : 214 : fieldno = GetFieldNo (CurrentQuadToken, expr, SymbolTable_GetType (result), &offset);
7412 : 214 : if (fieldno >= 0)
7413 : : {
7414 : 214 : SymbolTable_PushValue (expr);
7415 : 214 : M2ALU_PushIntegerTree (offset);
7416 : 214 : M2ALU_Sub ();
7417 : 214 : m2statement_BuildExcludeVarConst (location, SymbolConversion_Mod2Gcc (SymbolTable_GetType (result)), SymbolConversion_Mod2Gcc (result), M2ALU_PopIntegerTree (), (SymbolTable_GetMode (result)) == SymbolTable_LeftValue, fieldno);
7418 : : }
7419 : : else
7420 : : {
7421 : 0 : M2MetaError_MetaErrorT1 (CurrentQuadToken, (const char *) "bit exceeded the range of set {%1Eatd}", 38, result);
7422 : : }
7423 : : }
7424 : : else
7425 : : {
7426 : 230 : GetSetLimits (SymbolTable_GetType (result), &low, &high);
7427 : 230 : m2statement_BuildExcludeVarVar (location, SymbolConversion_Mod2Gcc (SymbolTable_GetType (result)), SymbolConversion_Mod2Gcc (result), SymbolConversion_Mod2Gcc (expr), (SymbolTable_GetMode (result)) == SymbolTable_LeftValue, SymbolConversion_Mod2Gcc (low));
7428 : : }
7429 : : }
7430 : 444 : }
7431 : :
7432 : :
7433 : : /*
7434 : : FoldUnary - check whether we can fold the unop operation.
7435 : : */
7436 : :
7437 : 32654 : static void FoldUnary (unsigned int tokenno, M2GCCDeclare_WalkAction p, m2expr_BuildUnaryProcedure unop, tree ZConstToTypedConst, unsigned int quad, unsigned int result, unsigned int expr)
7438 : : {
7439 : 32654 : tree tv;
7440 : 32654 : location_t location;
7441 : :
7442 : : /* firstly ensure that any constant literal is declared */
7443 : 32654 : M2GCCDeclare_TryDeclareConstant (tokenno, expr);
7444 : 32654 : location = M2LexBuf_TokenToLocation (tokenno);
7445 : 32654 : if (SymbolTable_IsConst (expr))
7446 : : {
7447 : 18882 : if (SymbolConversion_GccKnowsAbout (expr))
7448 : : {
7449 : : /* avoid gcc warning by using compound statement even if not strictly necessary. */
7450 : : /* fine, we can take advantage of this and fold constants */
7451 : 18882 : if (SymbolTable_IsConst (result))
7452 : : {
7453 : 18882 : if (ZConstToTypedConst == ((tree) (NULL)))
7454 : : {
7455 : : /* avoid gcc warning by using compound statement even if not strictly necessary. */
7456 : 18882 : if (((SymbolTable_GetType (expr)) == SymbolTable_NulSym) || (M2Base_IsOrdinalType (SymbolTable_SkipType (SymbolTable_GetType (expr)))))
7457 : : {
7458 : 18510 : ZConstToTypedConst = m2type_GetM2ZType ();
7459 : : }
7460 : 372 : else if ((M2Base_IsRealType (SymbolTable_SkipType (SymbolTable_GetType (expr)))) || (M2System_IsRealN (SymbolTable_SkipType (SymbolTable_GetType (expr)))))
7461 : : {
7462 : : /* avoid dangling else. */
7463 : 192 : ZConstToTypedConst = m2type_GetM2RType ();
7464 : : }
7465 : 180 : else if ((M2Base_IsComplexType (SymbolTable_SkipType (SymbolTable_GetType (expr)))) || (M2System_IsComplexN (SymbolTable_SkipType (SymbolTable_GetType (expr)))))
7466 : : {
7467 : : /* avoid dangling else. */
7468 : 180 : ZConstToTypedConst = m2type_GetM2CType ();
7469 : : }
7470 : : }
7471 : 18882 : if ((SymbolTable_GetType (result)) == SymbolTable_NulSym)
7472 : : {
7473 : 0 : SymbolTable_PutConst (result, M2Base_NegateType (SymbolTable_GetType (expr))); /* , tokenno */
7474 : : }
7475 : 18882 : tv = (*unop.proc) (location, LValueToGenericPtrOrConvert (expr, ZConstToTypedConst), false);
7476 : 18882 : M2ALU_CheckOrResetOverflow (tokenno, tv, M2Quads_MustCheckOverflow (quad));
7477 : 18882 : SymbolConversion_AddModGcc (result, m2decl_DeclareKnownConstant (location, ZConstToTypedConst, tv));
7478 : 18882 : (*p.proc) (result);
7479 : 18882 : NoChange = false;
7480 : 18882 : M2Quads_SubQuad (quad);
7481 : : }
7482 : : /* we can still fold the expression, but not the assignment, however, we will
7483 : : not do this here but in CodeUnary
7484 : : */
7485 : : }
7486 : : }
7487 : 32654 : }
7488 : :
7489 : :
7490 : : /*
7491 : : FoldUnarySet - check whether we can fold the doOp operation.
7492 : : */
7493 : :
7494 : 4 : static void FoldUnarySet (unsigned int tokenno, M2GCCDeclare_WalkAction p, M2GenGCC_DoUnaryProcedure doOp, unsigned int quad, unsigned int result, unsigned int expr)
7495 : : {
7496 : 4 : location_t location;
7497 : :
7498 : : /* firstly try and ensure that constants are declared */
7499 : 4 : M2GCCDeclare_TryDeclareConstant (tokenno, expr);
7500 : 4 : location = M2LexBuf_TokenToLocation (tokenno);
7501 : 4 : if (((SymbolTable_IsConst (expr)) && (SymbolTable_IsConstSet (expr))) && (SymbolTable_IsConst (result)))
7502 : : {
7503 : 4 : if ((SymbolTable_IsValueSolved (expr)) && ((SymbolTable_GetType (expr)) != SymbolTable_NulSym))
7504 : : {
7505 : 4 : SymbolTable_PutConst (result, FindType (expr));
7506 : 4 : SymbolTable_PushValue (expr);
7507 : 4 : (*doOp.proc) (tokenno);
7508 : 4 : SymbolTable_PopValue (result);
7509 : 4 : SymbolTable_PushValue (result);
7510 : 4 : SymbolTable_PutConstSet (result);
7511 : 4 : SymbolConversion_AddModGcc (result, m2decl_DeclareKnownConstant (location, SymbolConversion_Mod2Gcc (SymbolTable_GetType (expr)), M2ALU_PopSetTree (tokenno)));
7512 : 4 : (*p.proc) (result);
7513 : 4 : NoChange = false;
7514 : 4 : M2Quads_SubQuad (quad);
7515 : : }
7516 : : }
7517 : 4 : }
7518 : :
7519 : :
7520 : : /*
7521 : : CodeUnaryCheck - encode a unary arithmetic operation.
7522 : : */
7523 : :
7524 : 806 : static void CodeUnaryCheck (m2expr_BuildUnaryCheckProcedure unop, tree ZConstToTypedConst, unsigned int quad, unsigned int result, unsigned int expr)
7525 : : {
7526 : 806 : unsigned int lowestType;
7527 : 806 : tree min;
7528 : 806 : tree max;
7529 : 806 : tree lowest;
7530 : 806 : tree tv;
7531 : 806 : location_t location;
7532 : :
7533 : : /* firstly ensure that any constant literal is declared */
7534 : 806 : M2GCCDeclare_DeclareConstant (CurrentQuadToken, expr);
7535 : 806 : M2GCCDeclare_DeclareConstructor (CurrentQuadToken, quad, expr);
7536 : 806 : location = M2LexBuf_TokenToLocation (CurrentQuadToken);
7537 : 806 : lowestType = SymbolTable_GetLType (result);
7538 : 806 : if (lowestType == SymbolTable_NulSym)
7539 : : {
7540 : : lowest = NULL;
7541 : : }
7542 : : else
7543 : : {
7544 : 806 : lowest = SymbolConversion_Mod2Gcc (lowestType);
7545 : : }
7546 : 806 : if (M2Range_GetMinMax (CurrentQuadToken, lowestType, &min, &max))
7547 : : {
7548 : 742 : tv = (*unop.proc) (location, M2GenGCC_LValueToGenericPtr (location, expr), lowest, min, max);
7549 : : }
7550 : : else
7551 : : {
7552 : 64 : tv = (*unop.proc) (location, M2GenGCC_LValueToGenericPtr (location, expr), NULL, NULL, NULL);
7553 : : }
7554 : 806 : M2ALU_CheckOrResetOverflow (CurrentQuadToken, tv, M2Quads_MustCheckOverflow (quad));
7555 : 806 : if (SymbolTable_IsConst (result))
7556 : : {
7557 : 0 : if (ZConstToTypedConst == ((tree) (NULL)))
7558 : : {
7559 : 0 : ZConstToTypedConst = (tree) (SymbolConversion_Mod2Gcc (SymbolTable_GetType (expr)));
7560 : : }
7561 : : /* still have a constant which was not resolved, pass it to gcc */
7562 : 0 : SymbolTable_PutConst (result, FindType (expr));
7563 : 0 : M2GCCDeclare_ConstantKnownAndUsed (result, m2decl_DeclareKnownConstant (location, ZConstToTypedConst, tv));
7564 : : }
7565 : : else
7566 : : {
7567 : 806 : if (M2SSA_EnableSSA && (SymbolTable_IsVariableSSA (result)))
7568 : : {
7569 : : Replace (result, tv);
7570 : : }
7571 : : else
7572 : : {
7573 : 806 : m2statement_BuildAssignmentStatement (location, SymbolConversion_Mod2Gcc (result), tv);
7574 : : }
7575 : : }
7576 : 806 : }
7577 : :
7578 : :
7579 : : /*
7580 : : CodeUnary - encode a unary arithmetic operation.
7581 : : */
7582 : :
7583 : 0 : static void CodeUnary (m2expr_BuildUnaryProcedure unop, tree ZConstToTypedConst, unsigned int quad, unsigned int result, unsigned int expr)
7584 : : {
7585 : 0 : tree tv;
7586 : 0 : location_t location;
7587 : :
7588 : : /* firstly ensure that any constant literal is declared */
7589 : 0 : M2GCCDeclare_DeclareConstant (CurrentQuadToken, expr);
7590 : 0 : M2GCCDeclare_DeclareConstructor (CurrentQuadToken, quad, expr);
7591 : 0 : location = M2LexBuf_TokenToLocation (CurrentQuadToken);
7592 : 0 : tv = (*unop.proc) (location, M2GenGCC_LValueToGenericPtr (location, expr), false);
7593 : 0 : M2ALU_CheckOrResetOverflow (CurrentQuadToken, tv, M2Quads_MustCheckOverflow (quad));
7594 : 0 : if (SymbolTable_IsConst (result))
7595 : : {
7596 : 0 : if (ZConstToTypedConst == ((tree) (NULL)))
7597 : : {
7598 : 0 : ZConstToTypedConst = (tree) (SymbolConversion_Mod2Gcc (SymbolTable_GetType (expr)));
7599 : : }
7600 : : /* still have a constant which was not resolved, pass it to gcc */
7601 : 0 : SymbolTable_PutConst (result, FindType (expr));
7602 : 0 : M2GCCDeclare_ConstantKnownAndUsed (result, m2decl_DeclareKnownConstant (location, ZConstToTypedConst, tv));
7603 : : }
7604 : : else
7605 : : {
7606 : 0 : if (M2SSA_EnableSSA && (SymbolTable_IsVariableSSA (result)))
7607 : : {
7608 : : Replace (result, tv);
7609 : : }
7610 : : else
7611 : : {
7612 : 0 : m2statement_BuildAssignmentStatement (location, SymbolConversion_Mod2Gcc (result), tv);
7613 : : }
7614 : : }
7615 : 0 : }
7616 : :
7617 : :
7618 : : /*
7619 : : FoldNegate - check unary negate for constant folding.
7620 : : */
7621 : :
7622 : 32658 : static void FoldNegate (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int quad, unsigned int result, unsigned int expr)
7623 : : {
7624 : 32658 : if (SymbolTable_IsConstSet (expr))
7625 : : {
7626 : 4 : FoldUnarySet (tokenno, p, (M2GenGCC_DoUnaryProcedure) {(M2GenGCC_DoUnaryProcedure_t) M2ALU_SetNegate}, quad, result, expr);
7627 : : }
7628 : : else
7629 : : {
7630 : 32654 : FoldUnary (tokenno, p, (m2expr_BuildUnaryProcedure) {(m2expr_BuildUnaryProcedure_t) m2expr_BuildNegate}, NULL, quad, result, expr);
7631 : : }
7632 : 32658 : }
7633 : :
7634 : :
7635 : : /*
7636 : : CodeNegateChecked - code a negate instruction, determine whether checking
7637 : : is required.
7638 : : */
7639 : :
7640 : 834 : static void CodeNegateChecked (unsigned int quad, unsigned int op1, unsigned int op3)
7641 : : {
7642 : 834 : if ((SymbolTable_IsConstSet (op3)) || (SymbolTable_IsSet (SymbolTable_GetType (op3))))
7643 : : {
7644 : 22 : CodeUnarySet ((m2expr_BuildUnarySetFunction) {(m2expr_BuildUnarySetFunction_t) m2expr_BuildSetNegate}, (M2GenGCC_DoUnaryProcedure) {(M2GenGCC_DoUnaryProcedure_t) M2ALU_SetNegate}, quad, op1, op3);
7645 : : }
7646 : 812 : else if (UnaryOperand (quad, op3))
7647 : : {
7648 : : /* avoid dangling else. */
7649 : 806 : if (M2Quads_MustCheckOverflow (quad))
7650 : : {
7651 : 806 : CodeUnaryCheck ((m2expr_BuildUnaryCheckProcedure) {(m2expr_BuildUnaryCheckProcedure_t) m2expr_BuildNegateCheck}, NULL, quad, op1, op3);
7652 : : }
7653 : : else
7654 : : {
7655 : 0 : CodeUnary ((m2expr_BuildUnaryProcedure) {(m2expr_BuildUnaryProcedure_t) m2expr_BuildNegate}, NULL, quad, op1, op3);
7656 : : }
7657 : : }
7658 : 834 : }
7659 : :
7660 : :
7661 : : /*
7662 : : FoldSize - check unary SIZE for constant folding.
7663 : : */
7664 : :
7665 : 7168 : static void FoldSize (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3)
7666 : : {
7667 : 7168 : tree t;
7668 : 7168 : location_t location;
7669 : :
7670 : 7168 : location = M2LexBuf_TokenToLocation (tokenno);
7671 : 7168 : if ((SymbolTable_IsConst (op1)) && (M2GCCDeclare_CompletelyResolved (op3)))
7672 : : {
7673 : : /* avoid gcc warning by using compound statement even if not strictly necessary. */
7674 : 5622 : if (op2 == SymbolTable_NulSym)
7675 : : {
7676 : 5622 : t = m2expr_BuildSize (location, SymbolConversion_Mod2Gcc (op3), false);
7677 : 5622 : M2ALU_PushIntegerTree (t);
7678 : 5622 : SymbolTable_PopValue (op1);
7679 : 5622 : SymbolTable_PutConst (op1, M2Base_Cardinal);
7680 : 5622 : (*p.proc) (op1);
7681 : 5622 : NoChange = false;
7682 : 5622 : M2Quads_SubQuad (quad);
7683 : 5622 : t = m2block_RememberConstant (t);
7684 : : }
7685 : 0 : else if (SymbolConversion_GccKnowsAbout (op2))
7686 : : {
7687 : : /* avoid dangling else. */
7688 : : /* ignore the chosen varients as we implement it as a C union */
7689 : 0 : t = m2expr_BuildSize (location, SymbolConversion_Mod2Gcc (op3), false);
7690 : 0 : M2ALU_PushIntegerTree (t);
7691 : 0 : SymbolTable_PopValue (op1);
7692 : 0 : SymbolTable_PutConst (op1, M2Base_Cardinal);
7693 : 0 : (*p.proc) (op1);
7694 : 0 : NoChange = false;
7695 : 0 : M2Quads_SubQuad (quad);
7696 : 0 : t = m2block_RememberConstant (t);
7697 : : }
7698 : : }
7699 : 7168 : }
7700 : :
7701 : :
7702 : : /*
7703 : : CodeSize - encode the inbuilt SIZE function.
7704 : : */
7705 : :
7706 : 0 : static void CodeSize (unsigned int result, unsigned int sym)
7707 : : {
7708 : 0 : location_t location;
7709 : :
7710 : 0 : location = M2LexBuf_TokenToLocation (CurrentQuadToken);
7711 : 0 : M2ALU_PushIntegerTree (m2expr_BuildSize (location, SymbolConversion_Mod2Gcc (sym), false));
7712 : 0 : if (SymbolTable_IsConst (result))
7713 : : {
7714 : 0 : SymbolTable_PopValue (result);
7715 : 0 : SymbolTable_PutConst (result, M2Base_Cardinal);
7716 : 0 : SymbolTable_PushValue (result);
7717 : 0 : M2GCCDeclare_ConstantKnownAndUsed (result, m2decl_DeclareKnownConstant (location, m2type_GetIntegerType (), M2ALU_PopIntegerTree ()));
7718 : : }
7719 : : else
7720 : : {
7721 : 0 : m2statement_BuildAssignmentStatement (location, SymbolConversion_Mod2Gcc (result), M2ALU_PopIntegerTree ());
7722 : : }
7723 : 0 : }
7724 : :
7725 : :
7726 : : /*
7727 : : FoldRecordField - check whether we can fold an RecordFieldOp quadruple.
7728 : : Very similar to FoldBinary, except that we need to
7729 : : hard code a few parameters to the gcc backend.
7730 : : */
7731 : :
7732 : 0 : static void FoldRecordField (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int quad, unsigned int result, unsigned int record, unsigned int field)
7733 : : {
7734 : 0 : unsigned int recordType;
7735 : 0 : unsigned int fieldType;
7736 : 0 : tree ptr;
7737 : 0 : location_t location;
7738 : :
7739 : 0 : return; /* this procedure should no longer be called */
7740 : : location = M2LexBuf_TokenToLocation (tokenno);
7741 : : /* firstly ensure that any constant literal is declared */
7742 : : M2GCCDeclare_TryDeclareConstant (tokenno, record);
7743 : : if ((SymbolTable_IsRecordField (record)) || (SymbolTable_IsFieldVarient (record)))
7744 : : {
7745 : : recordType = SymbolTable_GetType (record);
7746 : : fieldType = SymbolTable_GetType (field);
7747 : : if ((((((SymbolConversion_GccKnowsAbout (record)) && (SymbolConversion_GccKnowsAbout (field))) && (SymbolConversion_GccKnowsAbout (recordType))) && (SymbolConversion_GccKnowsAbout (fieldType))) && (M2GCCDeclare_CompletelyResolved (recordType))) && (M2GCCDeclare_CompletelyResolved (fieldType)))
7748 : : {
7749 : : /* avoid gcc warning by using compound statement even if not strictly necessary. */
7750 : : /* fine, we can take advantage of this and fold constants */
7751 : : if (SymbolTable_IsConst (result))
7752 : : {
7753 : : ptr = m2expr_BuildComponentRef (location, SymbolConversion_Mod2Gcc (record), SymbolConversion_Mod2Gcc (field));
7754 : : if (! (SymbolTable_IsValueSolved (result)))
7755 : : {
7756 : : M2ALU_PushIntegerTree (ptr);
7757 : : SymbolTable_PopValue (result);
7758 : : }
7759 : : SymbolTable_PutConst (result, fieldType);
7760 : : SymbolConversion_AddModGcc (result, m2decl_DeclareKnownConstant (location, SymbolConversion_Mod2Gcc (fieldType), ptr));
7761 : : (*p.proc) (result);
7762 : : NoChange = false;
7763 : : M2Quads_SubQuad (quad);
7764 : : }
7765 : : /* we can still fold the expression, but not the assignment, however, we will
7766 : : not do this here but in CodeOffset
7767 : : */
7768 : : }
7769 : : }
7770 : : }
7771 : :
7772 : :
7773 : : /*
7774 : : CodeRecordField - encode a reference to a field within a record.
7775 : : */
7776 : :
7777 : 125282 : static void CodeRecordField (unsigned int result, unsigned int record, unsigned int field)
7778 : : {
7779 : 125282 : unsigned int recordType;
7780 : 125282 : unsigned int fieldType;
7781 : 125282 : tree ptr;
7782 : 125282 : location_t location;
7783 : :
7784 : 125282 : location = M2LexBuf_TokenToLocation (CurrentQuadToken);
7785 : : /* firstly ensure that any constant literal is declared */
7786 : 125282 : if ((SymbolTable_IsRecordField (field)) || (SymbolTable_IsFieldVarient (field)))
7787 : : {
7788 : 125282 : recordType = SymbolTable_GetType (record);
7789 : 125282 : fieldType = SymbolTable_GetType (field);
7790 : 125282 : if ((((((SymbolConversion_GccKnowsAbout (record)) && (SymbolConversion_GccKnowsAbout (field))) && (SymbolConversion_GccKnowsAbout (recordType))) && (SymbolConversion_GccKnowsAbout (fieldType))) && (M2GCCDeclare_CompletelyResolved (recordType))) && (M2GCCDeclare_CompletelyResolved (fieldType)))
7791 : : {
7792 : 125282 : if ((SymbolTable_GetMode (record)) == SymbolTable_LeftValue)
7793 : : {
7794 : 41910 : ptr = m2expr_BuildComponentRef (location, m2expr_BuildIndirect (location, SymbolConversion_Mod2Gcc (record), SymbolConversion_Mod2Gcc (recordType)), SymbolConversion_Mod2Gcc (field));
7795 : : }
7796 : : else
7797 : : {
7798 : 83372 : ptr = m2expr_BuildComponentRef (location, SymbolConversion_Mod2Gcc (record), SymbolConversion_Mod2Gcc (field));
7799 : : }
7800 : 125282 : SymbolConversion_AddModGcc (result, ptr);
7801 : : }
7802 : : else
7803 : : {
7804 : 0 : M2Error_InternalError ((const char *) "symbol type should have been declared by now", 44);
7805 : : }
7806 : : }
7807 : : else
7808 : : {
7809 : 0 : M2Error_InternalError ((const char *) "not expecting this type of symbol", 33);
7810 : : }
7811 : 125282 : }
7812 : :
7813 : :
7814 : : /*
7815 : : BuildHighFromChar -
7816 : : */
7817 : :
7818 : 43406 : static tree BuildHighFromChar (unsigned int operand)
7819 : : {
7820 : 43406 : location_t location;
7821 : :
7822 : 43406 : location = M2LexBuf_TokenToLocation (SymbolTable_GetDeclaredMod (operand));
7823 : 43406 : if ((SymbolTable_IsConstString (operand)) && ((SymbolTable_IsConstStringM2nul (operand)) || (SymbolTable_IsConstStringCnul (operand))))
7824 : : {
7825 : 42626 : return m2expr_GetCardinalOne (location);
7826 : : }
7827 : 780 : return m2expr_GetCardinalZero (location);
7828 : : /* static analysis guarentees a RETURN statement will be used before here. */
7829 : : __builtin_unreachable ();
7830 : : }
7831 : :
7832 : :
7833 : : /*
7834 : : SkipToArray -
7835 : : */
7836 : :
7837 : 20830 : static unsigned int SkipToArray (unsigned int operand, unsigned int dim)
7838 : : {
7839 : 20830 : unsigned int type;
7840 : :
7841 : 21478 : while (dim > 1)
7842 : : {
7843 : 648 : type = SymbolTable_SkipType (SymbolTable_GetType (operand));
7844 : 648 : if (SymbolTable_IsArray (type))
7845 : : {
7846 : 648 : operand = type;
7847 : : }
7848 : 648 : dim -= 1;
7849 : : }
7850 : 20830 : return operand;
7851 : : /* static analysis guarentees a RETURN statement will be used before here. */
7852 : : __builtin_unreachable ();
7853 : : }
7854 : :
7855 : :
7856 : : /*
7857 : : BuildHighFromArray -
7858 : : */
7859 : :
7860 : 20830 : static tree BuildHighFromArray (unsigned int tokenno, unsigned int dim, unsigned int operand)
7861 : : {
7862 : 20830 : unsigned int Type;
7863 : 20830 : location_t location;
7864 : :
7865 : 20830 : location = M2LexBuf_TokenToLocation (tokenno);
7866 : 20830 : Type = SymbolTable_SkipType (SymbolTable_GetType (SkipToArray (operand, dim)));
7867 : 20830 : return BuildHighFromStaticArray (location, Type); /* dim, */
7868 : : /* static analysis guarentees a RETURN statement will be used before here. */
7869 : : __builtin_unreachable ();
7870 : : }
7871 : :
7872 : :
7873 : : /*
7874 : : BuildHighFromStaticArray -
7875 : : */
7876 : :
7877 : 20830 : static tree BuildHighFromStaticArray (location_t location, unsigned int Type)
7878 : : {
7879 : 20830 : unsigned int High;
7880 : 20830 : unsigned int Low;
7881 : 20830 : unsigned int Subscript;
7882 : 20830 : unsigned int Subrange;
7883 : :
7884 : 20830 : M2Debug_Assert (SymbolTable_IsArray (Type)); /* dim, */
7885 : 20830 : Subscript = SymbolTable_GetArraySubscript (Type);
7886 : 20830 : Subrange = SymbolTable_SkipType (SymbolTable_GetType (Subscript));
7887 : 20830 : if (SymbolTable_IsEnumeration (Subrange))
7888 : : {
7889 : : /* avoid dangling else. */
7890 : 96 : M2Base_GetBaseTypeMinMax (Subrange, &Low, &High);
7891 : 96 : if (SymbolConversion_GccKnowsAbout (High))
7892 : : {
7893 : 96 : return (tree) (SymbolConversion_Mod2Gcc (High));
7894 : : }
7895 : : }
7896 : 20734 : else if (SymbolTable_IsSubrange (Subrange))
7897 : : {
7898 : : /* avoid dangling else. */
7899 : 20734 : SymbolTable_GetSubrange (Subrange, &High, &Low);
7900 : 20734 : if ((SymbolConversion_GccKnowsAbout (Low)) && (SymbolConversion_GccKnowsAbout (High)))
7901 : : {
7902 : 20734 : return m2expr_BuildSub (location, SymbolConversion_Mod2Gcc (High), SymbolConversion_Mod2Gcc (Low), true);
7903 : : }
7904 : : }
7905 : : else
7906 : : {
7907 : : /* avoid dangling else. */
7908 : 0 : M2MetaError_MetaError1 ((const char *) "array subscript {%1EDad:for} must be a subrange or enumeration type", 67, Type);
7909 : 0 : return (tree) (NULL);
7910 : : }
7911 : 0 : if (SymbolConversion_GccKnowsAbout (High))
7912 : : {
7913 : 0 : return (tree) (SymbolConversion_Mod2Gcc (High));
7914 : : }
7915 : : else
7916 : : {
7917 : : return (tree) (NULL);
7918 : : }
7919 : : /* static analysis guarentees a RETURN statement will be used before here. */
7920 : : __builtin_unreachable ();
7921 : : }
7922 : :
7923 : :
7924 : : /*
7925 : : BuildHighFromString -
7926 : : */
7927 : :
7928 : 735792 : static tree BuildHighFromString (unsigned int operand)
7929 : : {
7930 : 735792 : location_t location;
7931 : :
7932 : 735792 : location = M2LexBuf_TokenToLocation (SymbolTable_GetDeclaredMod (operand));
7933 : 735792 : if ((SymbolConversion_GccKnowsAbout (operand)) && ((m2expr_StringLength (SymbolConversion_Mod2Gcc (operand))) > 0))
7934 : : {
7935 : 735792 : return m2decl_BuildIntegerConstant (static_cast<int> ((m2expr_StringLength (SymbolConversion_Mod2Gcc (operand)))-1));
7936 : : }
7937 : : else
7938 : : {
7939 : 0 : return m2expr_GetIntegerZero (location);
7940 : : }
7941 : : /* static analysis guarentees a RETURN statement will be used before here. */
7942 : : __builtin_unreachable ();
7943 : : }
7944 : :
7945 : :
7946 : : /*
7947 : : ResolveHigh - given an Modula-2 operand, it resolves the HIGH(operand)
7948 : : and returns a GCC constant symbol containing the value of
7949 : : HIGH(operand).
7950 : : */
7951 : :
7952 : 840212 : static tree ResolveHigh (unsigned int tokenno, unsigned int dim, unsigned int operand)
7953 : : {
7954 : 840212 : unsigned int Type;
7955 : 840212 : location_t location;
7956 : :
7957 : 840212 : Type = SymbolTable_SkipType (SymbolTable_GetType (operand));
7958 : 840212 : location = M2LexBuf_TokenToLocation (tokenno);
7959 : 840212 : if ((Type == M2Base_Char) && (dim == 1))
7960 : : {
7961 : 43406 : return BuildHighFromChar (operand);
7962 : : }
7963 : 796806 : else if ((SymbolTable_IsConstString (operand)) && (dim == 1))
7964 : : {
7965 : : /* avoid dangling else. */
7966 : 735792 : return BuildHighFromString (operand);
7967 : : }
7968 : 61014 : else if (SymbolTable_IsArray (Type))
7969 : : {
7970 : : /* avoid dangling else. */
7971 : 20830 : return BuildHighFromArray (tokenno, dim, operand);
7972 : : }
7973 : 40184 : else if (SymbolTable_IsUnbounded (Type))
7974 : : {
7975 : : /* avoid dangling else. */
7976 : 40184 : return M2GenGCC_GetHighFromUnbounded (location, dim, operand);
7977 : : }
7978 : : else
7979 : : {
7980 : : /* avoid dangling else. */
7981 : 0 : M2MetaError_MetaErrorT1 (tokenno, (const char *) "base procedure HIGH expects a variable of type array or a constant string or CHAR as its parameter, rather than {%1Etad}", 120, operand);
7982 : 0 : return m2expr_GetIntegerZero (location);
7983 : : }
7984 : : /* static analysis guarentees a RETURN statement will be used before here. */
7985 : : __builtin_unreachable ();
7986 : : }
7987 : :
7988 : :
7989 : : /*
7990 : : FoldHigh - if the array is not dynamic then we should be able to
7991 : : remove the HighOp quadruple and assign op1 with
7992 : : the known compile time HIGH(op3).
7993 : : */
7994 : :
7995 : 1013697 : static void FoldHigh (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int quad, unsigned int op1, unsigned int dim, unsigned int op3)
7996 : : {
7997 : 1013697 : tree t;
7998 : 1013697 : location_t location;
7999 : :
8000 : : /* firstly ensure that any constant literal is declared */
8001 : 1013697 : M2GCCDeclare_TryDeclareConstant (tokenno, op3);
8002 : 1013697 : location = M2LexBuf_TokenToLocation (tokenno);
8003 : 1013697 : if ((SymbolConversion_GccKnowsAbout (op3)) && (M2GCCDeclare_CompletelyResolved (op3)))
8004 : : {
8005 : 804065 : t = ResolveHigh (tokenno, dim, op3);
8006 : : /* fine, we can take advantage of this and fold constants */
8007 : 804065 : if ((SymbolTable_IsConst (op1)) && (t != ((tree) (NULL))))
8008 : : {
8009 : 102 : SymbolTable_PutConst (op1, M2Base_Cardinal);
8010 : 102 : SymbolConversion_AddModGcc (op1, m2decl_DeclareKnownConstant (location, m2type_GetCardinalType (), m2convert_ToCardinal (location, t)));
8011 : 102 : (*p.proc) (op1);
8012 : 102 : NoChange = false;
8013 : 102 : M2Quads_SubQuad (quad);
8014 : : }
8015 : : /* we can still fold the expression, but not the assignment, however, we will
8016 : : not do this here but in CodeHigh
8017 : : */
8018 : : }
8019 : 1013697 : }
8020 : :
8021 : :
8022 : : /*
8023 : : CodeHigh - encode a unary arithmetic operation.
8024 : : */
8025 : :
8026 : 36147 : static void CodeHigh (unsigned int result, unsigned int dim, unsigned int array)
8027 : : {
8028 : 36147 : location_t location;
8029 : :
8030 : 36147 : location = M2LexBuf_TokenToLocation (CurrentQuadToken);
8031 : : /* firstly ensure that any constant literal is declared */
8032 : 36147 : M2GCCDeclare_DeclareConstant (CurrentQuadToken, array);
8033 : 36147 : if (SymbolTable_IsConst (result))
8034 : : {
8035 : : /* still have a constant which was not resolved, pass it to gcc */
8036 : 24 : M2GCCDeclare_ConstantKnownAndUsed (result, m2decl_DeclareKnownConstant (location, m2type_GetM2ZType (), ResolveHigh (CurrentQuadToken, dim, array)));
8037 : : }
8038 : : else
8039 : : {
8040 : 36123 : m2statement_BuildAssignmentStatement (location, SymbolConversion_Mod2Gcc (result), m2convert_BuildConvert (location, SymbolConversion_Mod2Gcc (SymbolTable_GetType (result)), ResolveHigh (CurrentQuadToken, dim, array), false));
8041 : : }
8042 : 36147 : }
8043 : :
8044 : :
8045 : : /*
8046 : : CodeUnbounded - codes the creation of an unbounded parameter variable.
8047 : : places the address of op3 into *op1
8048 : : */
8049 : :
8050 : 31329 : static void CodeUnbounded (unsigned int result, unsigned int array)
8051 : : {
8052 : 31329 : tree Addr;
8053 : 31329 : location_t location;
8054 : :
8055 : 31329 : location = M2LexBuf_TokenToLocation (CurrentQuadToken);
8056 : 31329 : M2GCCDeclare_DeclareConstant (CurrentQuadToken, array);
8057 : 31329 : if ((SymbolTable_IsConstString (array)) || ((SymbolTable_IsConst (array)) && ((SymbolTable_GetSType (array)) == M2Base_Char)))
8058 : : {
8059 : 23421 : m2statement_BuildAssignmentStatement (location, SymbolConversion_Mod2Gcc (result), m2expr_BuildAddr (location, M2GCCDeclare_PromoteToString (CurrentQuadToken, array), false));
8060 : : }
8061 : 7908 : else if (SymbolTable_IsConstructor (array))
8062 : : {
8063 : : /* avoid dangling else. */
8064 : 12 : m2statement_BuildAssignmentStatement (location, SymbolConversion_Mod2Gcc (result), m2expr_BuildAddr (location, SymbolConversion_Mod2Gcc (array), true));
8065 : : }
8066 : 7896 : else if (SymbolTable_IsUnbounded (SymbolTable_GetType (array)))
8067 : : {
8068 : : /* avoid dangling else. */
8069 : 3396 : if ((SymbolTable_GetMode (array)) == SymbolTable_LeftValue)
8070 : : {
8071 : 0 : Addr = m2convert_BuildConvert (location, SymbolConversion_Mod2Gcc (SymbolTable_GetType (result)), SymbolConversion_Mod2Gcc (array), false);
8072 : : }
8073 : : else
8074 : : {
8075 : 3396 : Addr = m2expr_BuildComponentRef (location, SymbolConversion_Mod2Gcc (array), SymbolConversion_Mod2Gcc (SymbolTable_GetUnboundedAddressOffset (SymbolTable_GetType (array))));
8076 : : }
8077 : 3396 : m2statement_BuildAssignmentStatement (location, SymbolConversion_Mod2Gcc (result), Addr);
8078 : : }
8079 : 4500 : else if ((SymbolTable_GetMode (array)) == SymbolTable_RightValue)
8080 : : {
8081 : : /* avoid dangling else. */
8082 : 4446 : m2statement_BuildAssignmentStatement (location, SymbolConversion_Mod2Gcc (result), m2expr_BuildAddr (location, SymbolConversion_Mod2Gcc (array), false));
8083 : : }
8084 : : else
8085 : : {
8086 : : /* avoid dangling else. */
8087 : 54 : m2statement_BuildAssignmentStatement (location, SymbolConversion_Mod2Gcc (result), SymbolConversion_Mod2Gcc (array));
8088 : : }
8089 : 31329 : }
8090 : :
8091 : :
8092 : : /*
8093 : : AreSubrangesKnown - returns TRUE if the subranges values used within, array, are known.
8094 : : */
8095 : :
8096 : 40896 : static bool AreSubrangesKnown (unsigned int array)
8097 : : {
8098 : 40896 : unsigned int type;
8099 : 40896 : unsigned int subscript;
8100 : 40896 : unsigned int low;
8101 : 40896 : unsigned int high;
8102 : :
8103 : 40896 : if (SymbolConversion_GccKnowsAbout (array))
8104 : : {
8105 : 40896 : subscript = SymbolTable_GetArraySubscript (array);
8106 : 40896 : if (subscript == SymbolTable_NulSym)
8107 : : {
8108 : 0 : M2Error_InternalError ((const char *) "not expecting a NulSym as a subscript", 37);
8109 : : }
8110 : : else
8111 : : {
8112 : 40896 : type = SymbolTable_SkipType (SymbolTable_GetType (subscript));
8113 : 40896 : low = M2GCCDeclare_GetTypeMin (type);
8114 : 40896 : high = M2GCCDeclare_GetTypeMax (type);
8115 : 40896 : return (SymbolConversion_GccKnowsAbout (low)) && (SymbolConversion_GccKnowsAbout (high));
8116 : : }
8117 : : }
8118 : : else
8119 : : {
8120 : : return false;
8121 : : }
8122 : : ReturnException ("/home/worker/buildworker/tiber-lcov/build/gcc/m2/gm2-compiler/M2GenGCC.def", 20, 1);
8123 : : __builtin_unreachable ();
8124 : : }
8125 : :
8126 : :
8127 : : /*
8128 : : CodeArray - res is an lvalue which will point to the array element.
8129 : : */
8130 : :
8131 : 40896 : static void CodeArray (unsigned int res, unsigned int index, unsigned int array)
8132 : : {
8133 : 40896 : unsigned int resType;
8134 : 40896 : unsigned int arrayDecl;
8135 : 40896 : unsigned int type;
8136 : 40896 : unsigned int low;
8137 : 40896 : unsigned int subscript;
8138 : 40896 : tree a;
8139 : 40896 : tree ta;
8140 : 40896 : tree ti;
8141 : 40896 : tree tl;
8142 : 40896 : location_t location;
8143 : :
8144 : 40896 : location = M2LexBuf_TokenToLocation (CurrentQuadToken);
8145 : 40896 : arrayDecl = SymbolTable_SkipType (SymbolTable_GetType (array));
8146 : 40896 : if (AreSubrangesKnown (arrayDecl))
8147 : : {
8148 : 40896 : subscript = SymbolTable_GetArraySubscript (arrayDecl);
8149 : 40896 : type = SymbolTable_SkipType (SymbolTable_GetType (subscript));
8150 : 40896 : low = M2GCCDeclare_GetTypeMin (type);
8151 : 40896 : resType = SymbolTable_GetVarBackEndType (res);
8152 : 40896 : if (resType == SymbolTable_NulSym)
8153 : : {
8154 : 0 : resType = SymbolTable_SkipType (SymbolTable_GetType (res));
8155 : : }
8156 : 40896 : ta = SymbolConversion_Mod2Gcc (SymbolTable_SkipType (SymbolTable_GetType (arrayDecl)));
8157 : 40896 : if ((SymbolTable_GetMode (array)) == SymbolTable_LeftValue)
8158 : : {
8159 : 1642 : a = m2expr_BuildIndirect (location, SymbolConversion_Mod2Gcc (array), SymbolConversion_Mod2Gcc (SymbolTable_SkipType (SymbolTable_GetType (array))));
8160 : : }
8161 : : else
8162 : : {
8163 : 39254 : a = SymbolConversion_Mod2Gcc (array);
8164 : : }
8165 : 40896 : if (SymbolTable_IsArrayLarge (arrayDecl))
8166 : : {
8167 : 24 : tl = m2convert_BuildConvert (location, SymbolConversion_Mod2Gcc (type), SymbolConversion_Mod2Gcc (low), false);
8168 : 24 : ti = m2convert_BuildConvert (location, SymbolConversion_Mod2Gcc (type), SymbolConversion_Mod2Gcc (index), false);
8169 : 24 : ti = m2convert_BuildConvert (location, m2type_GetIntegerType (), m2expr_BuildSub (location, ti, tl, false), false);
8170 : 24 : tl = m2expr_GetIntegerZero (location);
8171 : : }
8172 : : else
8173 : : {
8174 : 40872 : tl = m2convert_BuildConvert (location, m2type_GetIntegerType (), SymbolConversion_Mod2Gcc (low), false);
8175 : 40872 : ti = m2convert_BuildConvert (location, m2type_GetIntegerType (), SymbolConversion_Mod2Gcc (index), false);
8176 : : }
8177 : : /* ti := BuildConvert(location, GetIntegerType(), Mod2Gcc(high), FALSE) ; */
8178 : 40896 : m2statement_BuildAssignmentStatement (location, SymbolConversion_Mod2Gcc (res), m2convert_BuildConvert (location, SymbolConversion_Mod2Gcc (resType), m2expr_BuildAddr (location, m2expr_BuildArray (location, ta, a, ti, tl), false), false));
8179 : : }
8180 : : else
8181 : : {
8182 : 0 : M2Error_InternalError ((const char *) "subranges not yet resolved", 26);
8183 : : }
8184 : 40896 : }
8185 : :
8186 : :
8187 : : /*
8188 : : FoldElementSizeForArray - attempts to calculate the Subscript
8189 : : multiplier for the index op3.
8190 : : */
8191 : :
8192 : 0 : static void FoldElementSizeForArray (unsigned int tokenno, unsigned int quad, M2GCCDeclare_WalkAction p, unsigned int result, unsigned int type)
8193 : : {
8194 : 0 : unsigned int Subscript;
8195 : 0 : location_t location;
8196 : :
8197 : 0 : location = M2LexBuf_TokenToLocation (tokenno);
8198 : 0 : if ((SymbolTable_IsConst (result)) && (! (SymbolConversion_GccKnowsAbout (result))))
8199 : : {
8200 : 0 : Subscript = SymbolTable_GetArraySubscript (type);
8201 : 0 : if (SymbolTable_IsSizeSolved (Subscript))
8202 : : {
8203 : 0 : SymbolTable_PutConst (result, M2Base_Integer);
8204 : 0 : SymbolTable_PushSize (Subscript);
8205 : 0 : SymbolConversion_AddModGcc (result, m2decl_DeclareKnownConstant (location, m2type_GetCardinalType (), m2convert_BuildConvert (location, m2type_GetCardinalType (), M2ALU_PopIntegerTree (), true)));
8206 : 0 : (*p.proc) (result);
8207 : 0 : NoChange = false;
8208 : 0 : M2Quads_SubQuad (quad);
8209 : : }
8210 : : }
8211 : 0 : }
8212 : :
8213 : :
8214 : : /*
8215 : : FoldElementSizeForUnbounded - Unbounded arrays only have one index,
8216 : : therefore element size will be the
8217 : : TSIZE(Type) where Type is defined as:
8218 : : ARRAY OF Type.
8219 : : */
8220 : :
8221 : 7908 : static void FoldElementSizeForUnbounded (unsigned int tokenno, unsigned int quad, M2GCCDeclare_WalkAction p, unsigned int result, unsigned int ArrayType)
8222 : : {
8223 : 7908 : unsigned int Type;
8224 : 7908 : location_t location;
8225 : :
8226 : 7908 : location = M2LexBuf_TokenToLocation (tokenno);
8227 : 7908 : if (SymbolTable_IsConst (result))
8228 : : {
8229 : : /* avoid gcc warning by using compound statement even if not strictly necessary. */
8230 : 7908 : if (SymbolConversion_GccKnowsAbout (result))
8231 : : {
8232 : 0 : M2Error_InternalError ((const char *) "cannot assign a value twice to a constant", 41);
8233 : : }
8234 : : else
8235 : : {
8236 : 7908 : M2Debug_Assert (SymbolTable_IsUnbounded (ArrayType));
8237 : 7908 : Type = SymbolTable_GetType (ArrayType);
8238 : 7908 : if (SymbolConversion_GccKnowsAbout (Type))
8239 : : {
8240 : 7908 : SymbolTable_PutConst (result, M2Base_Cardinal);
8241 : 7908 : SymbolConversion_AddModGcc (result, m2decl_DeclareKnownConstant (location, m2type_GetCardinalType (), m2convert_BuildConvert (location, m2type_GetCardinalType (), FindSize (tokenno, Type), true)));
8242 : 7908 : (*p.proc) (result);
8243 : 7908 : NoChange = false;
8244 : 7908 : M2Quads_SubQuad (quad);
8245 : : }
8246 : : }
8247 : : }
8248 : 7908 : }
8249 : :
8250 : :
8251 : : /*
8252 : : FoldElementSize - folds the element size for an ArraySym or UnboundedSym.
8253 : : ElementSize returns a constant which defines the
8254 : : multiplier to be multiplied by this element index.
8255 : : */
8256 : :
8257 : 7908 : static void FoldElementSize (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int quad, unsigned int result, unsigned int type)
8258 : : {
8259 : 7908 : if (SymbolTable_IsUnbounded (type))
8260 : : {
8261 : 7908 : FoldElementSizeForUnbounded (tokenno, quad, p, result, type);
8262 : : }
8263 : 0 : else if (SymbolTable_IsArray (type))
8264 : : {
8265 : : /* avoid dangling else. */
8266 : 0 : FoldElementSizeForArray (tokenno, quad, p, result, type);
8267 : : }
8268 : : else
8269 : : {
8270 : : /* avoid dangling else. */
8271 : 0 : M2Error_InternalError ((const char *) "expecting UnboundedSym or ArraySym", 34);
8272 : : }
8273 : 7908 : }
8274 : :
8275 : :
8276 : : /*
8277 : : PopKindTree - returns a Tree from M2ALU of the type implied by, op.
8278 : : */
8279 : :
8280 : 15912 : static tree PopKindTree (unsigned int op, unsigned int tokenno)
8281 : : {
8282 : 15912 : unsigned int type;
8283 : :
8284 : 15912 : if ((SymbolTable_IsConst (op)) && (SymbolTable_IsConstString (op)))
8285 : : {
8286 : : /* Converting a nul char or char for example. */
8287 : 844 : return M2ALU_PopIntegerTree ();
8288 : : }
8289 : : else
8290 : : {
8291 : 15068 : type = SymbolTable_SkipType (SymbolTable_GetType (op));
8292 : 15068 : if (SymbolTable_IsSet (type))
8293 : : {
8294 : 0 : return M2ALU_PopSetTree (tokenno);
8295 : : }
8296 : 15068 : else if (M2Base_IsRealType (type))
8297 : : {
8298 : : /* avoid dangling else. */
8299 : 42 : return M2ALU_PopRealTree ();
8300 : : }
8301 : : else
8302 : : {
8303 : : /* avoid dangling else. */
8304 : 15026 : return M2ALU_PopIntegerTree ();
8305 : : }
8306 : : }
8307 : : /* static analysis guarentees a RETURN statement will be used before here. */
8308 : : __builtin_unreachable ();
8309 : : }
8310 : :
8311 : :
8312 : : /*
8313 : : FoldConvert - attempts to fold expr to type into result
8314 : : providing that result and expr are constants.
8315 : : If required convert will alter the machine representation
8316 : : of expr to comply with type.
8317 : : */
8318 : :
8319 : 290818 : static void FoldConvert (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int quad, unsigned int result, unsigned int type, unsigned int expr)
8320 : : {
8321 : 290818 : tree tl;
8322 : 290818 : location_t location;
8323 : :
8324 : 290818 : location = M2LexBuf_TokenToLocation (tokenno);
8325 : : /* First ensure that constant literals are declared. */
8326 : 290818 : M2GCCDeclare_TryDeclareConstant (tokenno, expr);
8327 : 290818 : if (IsConstant (expr))
8328 : : {
8329 : 166492 : if (((SymbolConversion_GccKnowsAbout (type)) && ((SymbolTable_IsProcedure (expr)) || (SymbolTable_IsValueSolved (expr)))) && (SymbolConversion_GccKnowsAbout (SymbolTable_SkipType (type))))
8330 : : {
8331 : : /* The type is known and expr is resolved so fold the convert. */
8332 : 161194 : if (SymbolTable_IsConst (result))
8333 : : {
8334 : 5400 : SymbolTable_PutConst (result, type); /* Change result type just in case. */
8335 : 5400 : tl = SymbolConversion_Mod2Gcc (SymbolTable_SkipType (type)); /* Change result type just in case. */
8336 : 5400 : if (SymbolTable_IsProcedure (expr))
8337 : : {
8338 : 0 : SymbolConversion_AddModGcc (result, m2convert_BuildConvert (location, tl, SymbolConversion_Mod2Gcc (expr), true));
8339 : : }
8340 : : else
8341 : : {
8342 : 5400 : SymbolTable_PushValue (expr);
8343 : 5400 : if (SymbolTable_IsConstSet (expr))
8344 : : {
8345 : 84 : if (SymbolTable_IsSet (SymbolTable_SkipType (type)))
8346 : : {
8347 : 0 : M2Error_WriteFormat0 ((const char *) "cannot convert values between sets", 34);
8348 : : }
8349 : : else
8350 : : {
8351 : 84 : M2ALU_PushIntegerTree (m2expr_FoldAndStrip (m2convert_BuildConvert (location, tl, M2ALU_PopSetTree (tokenno), true)));
8352 : 84 : SymbolTable_PopValue (result);
8353 : 84 : SymbolTable_PushValue (result);
8354 : 84 : SymbolConversion_AddModGcc (result, M2ALU_PopIntegerTree ());
8355 : : }
8356 : : }
8357 : : else
8358 : : {
8359 : 5316 : if (SymbolTable_IsSet (SymbolTable_SkipType (type)))
8360 : : {
8361 : 0 : M2ALU_PushSetTree (tokenno, m2expr_FoldAndStrip (m2convert_BuildConvert (location, tl, PopKindTree (expr, tokenno), true)), SymbolTable_SkipType (type));
8362 : 0 : SymbolTable_PopValue (result);
8363 : 0 : SymbolTable_PutConstSet (result);
8364 : 0 : SymbolTable_PushValue (result);
8365 : 0 : SymbolConversion_AddModGcc (result, M2ALU_PopSetTree (tokenno));
8366 : : }
8367 : 5316 : else if (M2Base_IsRealType (SymbolTable_SkipType (type)))
8368 : : {
8369 : : /* avoid dangling else. */
8370 : 36 : M2ALU_PushRealTree (m2expr_FoldAndStrip (m2convert_BuildConvert (location, tl, PopKindTree (expr, tokenno), true)));
8371 : 36 : SymbolTable_PopValue (result);
8372 : 36 : SymbolTable_PushValue (result);
8373 : 36 : SymbolConversion_AddModGcc (result, PopKindTree (result, tokenno));
8374 : : }
8375 : : else
8376 : : {
8377 : : /* avoid dangling else. */
8378 : : /* Let CheckOverflow catch a potential overflow rather than BuildConvert. */
8379 : 5280 : M2ALU_PushIntegerTree (m2expr_FoldAndStrip (m2convert_BuildConvert (location, tl, PopKindTree (expr, tokenno), false)));
8380 : 5280 : SymbolTable_PopValue (result);
8381 : 5280 : SymbolTable_PushValue (result);
8382 : 5280 : M2ALU_CheckOrResetOverflow (tokenno, PopKindTree (result, tokenno), M2Quads_MustCheckOverflow (quad));
8383 : 5280 : SymbolTable_PushValue (result);
8384 : 5280 : SymbolConversion_AddModGcc (result, PopKindTree (result, tokenno));
8385 : : }
8386 : : }
8387 : : }
8388 : 5400 : (*p.proc) (result);
8389 : 5400 : NoChange = false;
8390 : 5400 : M2Quads_SubQuad (quad);
8391 : : }
8392 : : }
8393 : : }
8394 : 290818 : }
8395 : :
8396 : :
8397 : : /*
8398 : : CodeConvert - Converts, rhs, to, type, placing the result into lhs.
8399 : : Convert will, if need be, alter the machine representation
8400 : : of op3 to comply with TYPE op2.
8401 : : */
8402 : :
8403 : 41594 : static void CodeConvert (unsigned int quad, unsigned int lhs, unsigned int type, unsigned int rhs)
8404 : : {
8405 : 41594 : tree tl;
8406 : 41594 : tree tr;
8407 : 41594 : location_t location;
8408 : :
8409 : 41594 : CheckStop (quad);
8410 : : /* firstly ensure that constant literals are declared */
8411 : 41594 : M2GCCDeclare_DeclareConstant (CurrentQuadToken, rhs);
8412 : 41594 : M2GCCDeclare_DeclareConstructor (CurrentQuadToken, quad, rhs);
8413 : 41594 : location = M2LexBuf_TokenToLocation (CurrentQuadToken);
8414 : 41594 : tl = M2GenGCC_LValueToGenericPtr (location, type);
8415 : 41594 : if (SymbolTable_IsProcedure (rhs))
8416 : : {
8417 : 26034 : tr = m2expr_BuildAddr (location, SymbolConversion_Mod2Gcc (rhs), false);
8418 : : }
8419 : : else
8420 : : {
8421 : 15560 : tr = M2GenGCC_LValueToGenericPtr (location, rhs);
8422 : 15560 : tr = ConvertRHS (tr, type, rhs);
8423 : : }
8424 : 41594 : if (SymbolTable_IsConst (lhs))
8425 : : {
8426 : : /* fine, we can take advantage of this and fold constant */
8427 : 0 : SymbolTable_PutConst (lhs, type);
8428 : 0 : tl = SymbolConversion_Mod2Gcc (SymbolTable_SkipType (type));
8429 : 0 : M2GCCDeclare_ConstantKnownAndUsed (lhs, m2convert_BuildConvert (location, tl, SymbolConversion_Mod2Gcc (rhs), true));
8430 : : }
8431 : : else
8432 : : {
8433 : 41594 : m2statement_BuildAssignmentStatement (location, SymbolConversion_Mod2Gcc (lhs), m2convert_BuildConvert (location, tl, tr, true));
8434 : : }
8435 : 41594 : }
8436 : :
8437 : :
8438 : : /*
8439 : : CodeCoerce - Coerce op3 to type op2 placing the result into
8440 : : op1.
8441 : : Coerce will NOT alter the machine representation
8442 : : of op3 to comply with TYPE op2.
8443 : : Therefore it _insists_ that under all circumstances that the
8444 : : type sizes of op1 and op3 are the same.
8445 : : CONVERT will perform machine manipulation to change variable
8446 : : types, coerce does no such thing.
8447 : : */
8448 : :
8449 : 556 : static void CodeCoerce (unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3)
8450 : : {
8451 : 556 : location_t location;
8452 : :
8453 : 556 : M2GCCDeclare_DeclareConstant (CurrentQuadToken, op3); /* checks to see whether it is a constant literal and declares it */
8454 : 556 : M2GCCDeclare_DeclareConstructor (CurrentQuadToken, quad, op3); /* checks to see whether it is a constant literal and declares it */
8455 : 556 : location = M2LexBuf_TokenToLocation (CurrentQuadToken);
8456 : 556 : if (SymbolTable_IsProcedure (op3))
8457 : : {
8458 : 0 : if (m2expr_AreConstantsEqual (FindSize (CurrentQuadToken, op1), FindSize (CurrentQuadToken, M2System_Address)))
8459 : : {
8460 : 0 : if (SymbolTable_IsConst (op1))
8461 : : {
8462 : 0 : M2GCCDeclare_ConstantKnownAndUsed (op1, CheckConstant (CurrentQuadToken, op1, op3));
8463 : : }
8464 : : else
8465 : : {
8466 : 0 : m2statement_BuildAssignmentStatement (location, SymbolConversion_Mod2Gcc (op1), SymbolConversion_Mod2Gcc (op3));
8467 : : }
8468 : : }
8469 : : else
8470 : : {
8471 : 0 : M2MetaError_MetaErrorT0 (CurrentQuadToken, (const char *) "{%E}procedure address can only be stored in an address sized operand", 68);
8472 : : }
8473 : : }
8474 : 556 : else if ((SymbolTable_IsConst (op3)) || (m2expr_AreConstantsEqual (FindSize (CurrentQuadToken, op1), FindSize (CurrentQuadToken, op3))))
8475 : : {
8476 : : /* avoid dangling else. */
8477 : 556 : if (SymbolTable_IsConst (op1))
8478 : : {
8479 : 0 : M2GCCDeclare_ConstantKnownAndUsed (op1, m2decl_DeclareKnownConstant (location, SymbolConversion_Mod2Gcc (SymbolTable_GetType (op1)), SymbolConversion_Mod2Gcc (op3)));
8480 : : }
8481 : : else
8482 : : {
8483 : 556 : M2Debug_Assert (SymbolConversion_GccKnowsAbout (op2));
8484 : 556 : if (SymbolTable_IsConst (op3))
8485 : : {
8486 : 0 : m2statement_BuildAssignmentStatement (location, SymbolConversion_Mod2Gcc (op1), SymbolConversion_Mod2Gcc (op3));
8487 : : }
8488 : : else
8489 : : {
8490 : : /* does not work t := BuildCoerce(Mod2Gcc(op1), Mod2Gcc(op2), Mod2Gcc(op3)) */
8491 : 556 : checkDeclare (op1);
8492 : 556 : m2type_AddStatement (location, MaybeDebugBuiltinMemcpy (location, m2expr_BuildAddr (location, SymbolConversion_Mod2Gcc (op1), false), m2expr_BuildAddr (location, SymbolConversion_Mod2Gcc (op3), false), FindSize (CurrentQuadToken, op2)));
8493 : : }
8494 : : }
8495 : : }
8496 : : else
8497 : : {
8498 : : /* avoid dangling else. */
8499 : 0 : M2MetaError_MetaErrorT0 (CurrentQuadToken, (const char *) "can only {%kCAST} objects of the same size", 42);
8500 : : }
8501 : 556 : }
8502 : :
8503 : :
8504 : : /*
8505 : : FoldCoerce -
8506 : : */
8507 : :
8508 : 4602 : static void FoldCoerce (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3)
8509 : : {
8510 : 4602 : location_t location;
8511 : :
8512 : 4602 : M2GCCDeclare_TryDeclareConstant (tokenno, op3); /* checks to see whether it is a constant literal and declares it */
8513 : 4602 : location = M2LexBuf_TokenToLocation (tokenno); /* checks to see whether it is a constant literal and declares it */
8514 : 4602 : if ((SymbolConversion_GccKnowsAbout (op2)) && (SymbolConversion_GccKnowsAbout (op3)))
8515 : : {
8516 : : /* avoid gcc warning by using compound statement even if not strictly necessary. */
8517 : 1562 : if (SymbolTable_IsProcedure (op3))
8518 : : {
8519 : 0 : if (m2expr_AreConstantsEqual (FindSize (tokenno, op1), FindSize (tokenno, M2System_Address)))
8520 : : {
8521 : : /* avoid dangling else. */
8522 : 0 : if (SymbolTable_IsConst (op1))
8523 : : {
8524 : 0 : SymbolConversion_AddModGcc (op1, m2decl_DeclareKnownConstant (location, SymbolConversion_Mod2Gcc (SymbolTable_GetType (op1)), SymbolConversion_Mod2Gcc (op3)));
8525 : 0 : (*p.proc) (op1);
8526 : 0 : NoChange = false;
8527 : 0 : M2Quads_SubQuad (quad);
8528 : : }
8529 : : }
8530 : : else
8531 : : {
8532 : 0 : M2MetaError_MetaErrorT0 (CurrentQuadToken, (const char *) "{%E}procedure address can only be stored in a address sized operand", 67);
8533 : : }
8534 : : }
8535 : 1562 : else if (SymbolTable_IsConst (op3))
8536 : : {
8537 : : /* avoid dangling else. */
8538 : 1024 : if (SymbolTable_IsConst (op1))
8539 : : {
8540 : 1024 : SymbolConversion_AddModGcc (op1, m2decl_DeclareKnownConstant (location, SymbolConversion_Mod2Gcc (SymbolTable_GetType (op1)), SymbolConversion_Mod2Gcc (op3)));
8541 : 1024 : (*p.proc) (op1);
8542 : 1024 : NoChange = false;
8543 : 1024 : M2Quads_SubQuad (quad);
8544 : : }
8545 : : }
8546 : : }
8547 : 4602 : }
8548 : :
8549 : :
8550 : : /*
8551 : : CanConvert - returns TRUE if we can convert variable, var, to a, type.
8552 : : */
8553 : :
8554 : 0 : static bool CanConvert (unsigned int type, unsigned int var)
8555 : : {
8556 : 0 : unsigned int svar;
8557 : 0 : unsigned int stype;
8558 : :
8559 : 0 : stype = SymbolTable_SkipType (type);
8560 : 0 : svar = SymbolTable_SkipType (SymbolTable_GetType (var));
8561 : 0 : return (((M2Base_IsBaseType (stype)) || (M2Base_IsOrdinalType (stype))) || (M2System_IsSystemType (stype))) && (((M2Base_IsBaseType (svar)) || (M2Base_IsOrdinalType (svar))) || (M2System_IsSystemType (stype)));
8562 : : /* static analysis guarentees a RETURN statement will be used before here. */
8563 : : __builtin_unreachable ();
8564 : : }
8565 : :
8566 : :
8567 : : /*
8568 : : CodeCast - Cast op3 to type op2 placing the result into op1.
8569 : : Cast will NOT alter the machine representation
8570 : : of op3 to comply with TYPE op2 as long as SIZE(op3)=SIZE(op2).
8571 : : If the sizes differ then Convert is called.
8572 : : */
8573 : :
8574 : 126 : static void CodeCast (unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3)
8575 : : {
8576 : 126 : location_t location;
8577 : :
8578 : 126 : M2GCCDeclare_DeclareConstant (CurrentQuadToken, op3); /* checks to see whether it is a constant literal and declares it */
8579 : 126 : M2GCCDeclare_DeclareConstructor (CurrentQuadToken, quad, op3); /* checks to see whether it is a constant literal and declares it */
8580 : 126 : location = M2LexBuf_TokenToLocation (CurrentQuadToken);
8581 : 126 : if (SymbolTable_IsProcedure (op3))
8582 : : {
8583 : 0 : if (m2expr_AreConstantsEqual (FindSize (CurrentQuadToken, op1), FindSize (CurrentQuadToken, M2System_Address)))
8584 : : {
8585 : 0 : if (SymbolTable_IsConst (op1))
8586 : : {
8587 : 0 : M2GCCDeclare_ConstantKnownAndUsed (op1, CheckConstant (CurrentQuadToken, op1, op3));
8588 : : }
8589 : : else
8590 : : {
8591 : 0 : m2statement_BuildAssignmentStatement (location, SymbolConversion_Mod2Gcc (op1), SymbolConversion_Mod2Gcc (op3));
8592 : : }
8593 : : }
8594 : : else
8595 : : {
8596 : 0 : M2MetaError_MetaErrorT0 (CurrentQuadToken, (const char *) "{%E}procedure address can only be stored in an address sized operand", 68);
8597 : : }
8598 : : }
8599 : 126 : else if ((SymbolTable_IsConst (op3)) || (m2expr_AreConstantsEqual (FindSize (CurrentQuadToken, op1), FindSize (CurrentQuadToken, op3))))
8600 : : {
8601 : : /* avoid dangling else. */
8602 : 108 : CodeCoerce (quad, op1, op2, op3);
8603 : : }
8604 : : else
8605 : : {
8606 : : /* avoid dangling else. */
8607 : 18 : if (M2Options_PedanticCast && (! (CanConvert (op2, op3))))
8608 : : {
8609 : 0 : M2MetaError_MetaError2 ((const char *) "{%WkCAST} cannot copy a variable src {%2Dad} to a destination {%1Dad} as they are of different sizes and are not ordinal or real types", 134, op1, op3);
8610 : : }
8611 : 18 : CodeConvert (quad, op1, op2, op3);
8612 : : }
8613 : 126 : }
8614 : :
8615 : 1356 : static void FoldCast (unsigned int tokenno, M2GCCDeclare_WalkAction p, unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3)
8616 : : {
8617 : : /*
8618 : : FoldCoerce -
8619 : : */
8620 : 1356 : M2GCCDeclare_TryDeclareConstant (tokenno, op3); /* checks to see whether it is a constant literal and declares it */
8621 : 1356 : if ((SymbolConversion_GccKnowsAbout (op2)) && (SymbolConversion_GccKnowsAbout (op3))) /* checks to see whether it is a constant literal and declares it */
8622 : : {
8623 : : /* avoid gcc warning by using compound statement even if not strictly necessary. */
8624 : 234 : if (SymbolTable_IsProcedure (op3))
8625 : : {
8626 : 0 : if (m2expr_AreConstantsEqual (FindSize (tokenno, op1), FindSize (tokenno, M2System_Address)))
8627 : : {
8628 : 0 : FoldCoerce (tokenno, p, quad, op1, op2, op3);
8629 : : }
8630 : : else
8631 : : {
8632 : 0 : M2MetaError_MetaErrorT0 (tokenno, (const char *) "{%E}procedure address can only be stored in an address sized operand", 68);
8633 : : }
8634 : : }
8635 : 234 : else if (SymbolTable_IsConst (op3))
8636 : : {
8637 : : /* avoid dangling else. */
8638 : 0 : FoldCoerce (tokenno, p, quad, op1, op2, op3);
8639 : : }
8640 : : }
8641 : 1356 : }
8642 : :
8643 : :
8644 : : /*
8645 : : CreateLabelProcedureN - creates a label using procedure name and
8646 : : an integer.
8647 : : */
8648 : :
8649 : 0 : static DynamicStrings_String CreateLabelProcedureN (unsigned int proc, const char *leader_, unsigned int _leader_high, unsigned int unboundedCount, unsigned int n)
8650 : : {
8651 : 0 : DynamicStrings_String n1;
8652 : 0 : DynamicStrings_String n2;
8653 : 0 : char leader[_leader_high+1];
8654 : :
8655 : : /* make a local copy of each unbounded array. */
8656 : 0 : memcpy (leader, leader_, _leader_high+1);
8657 : :
8658 : 0 : n1 = DynamicStrings_Mark (DynamicStrings_InitStringCharStar (NameKey_KeyToCharStar (SymbolTable_GetSymName (proc))));
8659 : 0 : n2 = DynamicStrings_Mark (DynamicStrings_InitString ((const char *) leader, _leader_high));
8660 : : /* prefixed by .L unboundedCount and n to ensure that no Modula-2 identifiers clash */
8661 : 0 : return FormatStrings_Sprintf4 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) ".L%d.%d.unbounded.%s.%s", 23)), (const unsigned char *) &unboundedCount, (sizeof (unboundedCount)-1), (const unsigned char *) &n, (sizeof (n)-1), (const unsigned char *) &n1, (sizeof (n1)-1), (const unsigned char *) &n2, (sizeof (n2)-1));
8662 : : /* static analysis guarentees a RETURN statement will be used before here. */
8663 : : __builtin_unreachable ();
8664 : 0 : }
8665 : :
8666 : :
8667 : : /*
8668 : : CreateLabelName - creates a namekey from quadruple, q.
8669 : : */
8670 : :
8671 : 191410 : static DynamicStrings_String CreateLabelName (unsigned int q)
8672 : : {
8673 : : /* prefixed by . to ensure that no Modula-2 identifiers clash */
8674 : 191410 : return FormatStrings_Sprintf1 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) ".L%d", 4)), (const unsigned char *) &q, (sizeof (q)-1));
8675 : : /* static analysis guarentees a RETURN statement will be used before here. */
8676 : : __builtin_unreachable ();
8677 : : }
8678 : :
8679 : :
8680 : : /*
8681 : : CodeGoto - creates a jump to a labeled quadruple.
8682 : : */
8683 : :
8684 : 37737 : static void CodeGoto (unsigned int destquad)
8685 : : {
8686 : 37737 : location_t location;
8687 : :
8688 : 37737 : location = M2LexBuf_TokenToLocation (CurrentQuadToken);
8689 : 37737 : m2statement_BuildGoto (location, reinterpret_cast <char * > (DynamicStrings_string (CreateLabelName (destquad))));
8690 : 37737 : }
8691 : :
8692 : :
8693 : : /*
8694 : : CheckReferenced - checks to see whether this quadruple requires a label.
8695 : : */
8696 : :
8697 : 3604464 : static void CheckReferenced (unsigned int quad, M2Quads_QuadOperator op)
8698 : : {
8699 : 3604464 : location_t location;
8700 : :
8701 : 3604464 : location = M2LexBuf_TokenToLocation (CurrentQuadToken);
8702 : : /* we do not create labels for procedure entries */
8703 : 3604464 : if (((op != M2Quads_ProcedureScopeOp) && (op != M2Quads_NewLocalVarOp)) && (M2Quads_IsReferenced (quad)))
8704 : : {
8705 : 87748 : m2statement_DeclareLabel (location, reinterpret_cast <char * > (DynamicStrings_string (CreateLabelName (quad))));
8706 : : }
8707 : 3604464 : }
8708 : :
8709 : :
8710 : : /*
8711 : : CodeIfSetLess -
8712 : : */
8713 : :
8714 : 6 : static void CodeIfSetLess (unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3)
8715 : : {
8716 : 6 : unsigned int settype;
8717 : 6 : void * falselabel;
8718 : 6 : location_t location;
8719 : :
8720 : 6 : location = M2LexBuf_TokenToLocation (CurrentQuadToken);
8721 : 6 : if ((SymbolTable_IsConst (op1)) && (SymbolTable_IsConst (op2)))
8722 : : {
8723 : 0 : M2Error_InternalError ((const char *) "this should have been folded in the calling procedure", 53);
8724 : : }
8725 : 6 : else if (SymbolTable_IsConst (op1))
8726 : : {
8727 : : /* avoid dangling else. */
8728 : 0 : settype = SymbolTable_SkipType (SymbolTable_GetType (op2));
8729 : : }
8730 : : else
8731 : : {
8732 : : /* avoid dangling else. */
8733 : 6 : settype = SymbolTable_SkipType (SymbolTable_GetType (op1));
8734 : : }
8735 : 6 : if ((m2expr_CompareTrees (FindSize (CurrentQuadToken, settype), FindSize (CurrentQuadToken, M2System_Word))) <= 0)
8736 : : {
8737 : : /* word size sets */
8738 : 0 : m2statement_DoJump (location, m2expr_BuildIsNotSuperset (location, m2convert_BuildConvert (location, m2type_GetWordType (), SymbolConversion_Mod2Gcc (op1), false), m2convert_BuildConvert (location, m2type_GetWordType (), SymbolConversion_Mod2Gcc (op2), false)), NULL, reinterpret_cast <char * > (DynamicStrings_string (CreateLabelName (op3))));
8739 : : }
8740 : : else
8741 : : {
8742 : 6 : falselabel = DynamicStrings_string (FormatStrings_Sprintf1 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) ".Lset%dcomp", 11)), (const unsigned char *) &quad, (sizeof (quad)-1)));
8743 : 6 : m2expr_BuildForeachWordInSetDoIfExpr (location, SymbolConversion_Mod2Gcc (settype), SymbolConversion_Mod2Gcc (op1), SymbolConversion_Mod2Gcc (op2), (SymbolTable_GetMode (op1)) == SymbolTable_LeftValue, (SymbolTable_GetMode (op2)) == SymbolTable_LeftValue, SymbolTable_IsConst (op1), SymbolTable_IsConst (op2), (m2expr_BuildExprProcedure_C) m2expr_BuildIsSuperset, reinterpret_cast <char * > (falselabel));
8744 : 6 : m2statement_BuildGoto (location, reinterpret_cast <char * > (DynamicStrings_string (CreateLabelName (op3))));
8745 : 6 : m2statement_DeclareLabel (location, reinterpret_cast <char * > (falselabel));
8746 : : }
8747 : 6 : }
8748 : :
8749 : :
8750 : : /*
8751 : : PerformCodeIfLess - codes the quadruple if op1 < op2 then goto op3
8752 : : */
8753 : :
8754 : 3152 : static void PerformCodeIfLess (unsigned int quad)
8755 : : {
8756 : 3152 : tree tl;
8757 : 3152 : tree tr;
8758 : 3152 : location_t location;
8759 : 3152 : unsigned int left;
8760 : 3152 : unsigned int right;
8761 : 3152 : unsigned int dest;
8762 : 3152 : unsigned int combined;
8763 : 3152 : unsigned int leftpos;
8764 : 3152 : unsigned int rightpos;
8765 : 3152 : unsigned int destpos;
8766 : 3152 : bool constExpr;
8767 : 3152 : bool overflow;
8768 : 3152 : M2Quads_QuadOperator op;
8769 : :
8770 : 3152 : M2Quads_GetQuadOtok (quad, &combined, &op, &left, &right, &dest, &overflow, &constExpr, &leftpos, &rightpos, &destpos);
8771 : 3152 : location = M2LexBuf_TokenToLocation (combined);
8772 : 3152 : if ((SymbolTable_IsConst (left)) && (SymbolTable_IsConst (right)))
8773 : : {
8774 : 0 : SymbolTable_PushValue (left);
8775 : 0 : SymbolTable_PushValue (right);
8776 : 0 : if (M2ALU_Less (CurrentQuadToken))
8777 : : {
8778 : 0 : m2statement_BuildGoto (location, reinterpret_cast <char * > (DynamicStrings_string (CreateLabelName (dest))));
8779 : : }
8780 : : /* Fall through. */
8781 : : }
8782 : 3152 : else if ((((SymbolTable_IsConstSet (left)) || ((SymbolTable_IsVar (left)) && (SymbolTable_IsSet (SymbolTable_SkipType (SymbolTable_GetType (left)))))) || (SymbolTable_IsConstSet (right))) || ((SymbolTable_IsVar (right)) && (SymbolTable_IsSet (SymbolTable_SkipType (SymbolTable_GetType (right))))))
8783 : : {
8784 : : /* avoid dangling else. */
8785 : 6 : CodeIfSetLess (quad, left, right, dest);
8786 : : }
8787 : : else
8788 : : {
8789 : : /* avoid dangling else. */
8790 : 3146 : if ((SymbolTable_IsComposite (SymbolTable_GetType (left))) || (SymbolTable_IsComposite (SymbolTable_GetType (right))))
8791 : : {
8792 : 0 : M2MetaError_MetaErrorT2 (combined, (const char *) "comparison tests between composite types not allowed {%1Eatd} and {%2atd}", 73, left, right);
8793 : : }
8794 : : else
8795 : : {
8796 : 3146 : ConvertBinaryOperands (location, &tl, &tr, ComparisonMixTypes (left, right, SymbolTable_SkipType (SymbolTable_GetType (left)), SymbolTable_SkipType (SymbolTable_GetType (right)), combined), left, right);
8797 : 3146 : m2statement_DoJump (location, m2expr_BuildLessThan (location, tl, tr), NULL, reinterpret_cast <char * > (DynamicStrings_string (CreateLabelName (dest))));
8798 : : }
8799 : : }
8800 : 3152 : }
8801 : :
8802 : :
8803 : : /*
8804 : : CodeIfLess - codes the quadruple if op1 < op2 then goto op3
8805 : : */
8806 : :
8807 : 3152 : static void CodeIfLess (unsigned int quad)
8808 : : {
8809 : 3152 : if (IsValidExpressionRelOp (quad, false))
8810 : : {
8811 : 3152 : PerformCodeIfLess (quad);
8812 : : }
8813 : 3152 : }
8814 : :
8815 : :
8816 : : /*
8817 : : CodeIfSetGre -
8818 : : */
8819 : :
8820 : 0 : static void CodeIfSetGre (unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3)
8821 : : {
8822 : 0 : unsigned int settype;
8823 : 0 : void * falselabel;
8824 : 0 : location_t location;
8825 : :
8826 : 0 : location = M2LexBuf_TokenToLocation (CurrentQuadToken);
8827 : 0 : if ((SymbolTable_IsConst (op1)) && (SymbolTable_IsConst (op2)))
8828 : : {
8829 : 0 : M2Error_InternalError ((const char *) "this should have been folded in the calling procedure", 53);
8830 : : }
8831 : 0 : else if (SymbolTable_IsConst (op1))
8832 : : {
8833 : : /* avoid dangling else. */
8834 : 0 : settype = SymbolTable_SkipType (SymbolTable_GetType (op2));
8835 : : }
8836 : : else
8837 : : {
8838 : : /* avoid dangling else. */
8839 : 0 : settype = SymbolTable_SkipType (SymbolTable_GetType (op1));
8840 : : }
8841 : 0 : if ((m2expr_CompareTrees (FindSize (CurrentQuadToken, settype), FindSize (CurrentQuadToken, M2System_Word))) <= 0)
8842 : : {
8843 : : /* word size sets */
8844 : 0 : m2statement_DoJump (location, m2expr_BuildIsNotSubset (location, m2convert_BuildConvert (location, m2type_GetWordType (), SymbolConversion_Mod2Gcc (op1), false), m2convert_BuildConvert (location, m2type_GetWordType (), SymbolConversion_Mod2Gcc (op2), false)), NULL, reinterpret_cast <char * > (DynamicStrings_string (CreateLabelName (op3))));
8845 : : }
8846 : : else
8847 : : {
8848 : 0 : falselabel = DynamicStrings_string (FormatStrings_Sprintf1 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) ".Lset%dcomp", 11)), (const unsigned char *) &quad, (sizeof (quad)-1)));
8849 : 0 : m2expr_BuildForeachWordInSetDoIfExpr (location, SymbolConversion_Mod2Gcc (settype), SymbolConversion_Mod2Gcc (op1), SymbolConversion_Mod2Gcc (op2), (SymbolTable_GetMode (op1)) == SymbolTable_LeftValue, (SymbolTable_GetMode (op2)) == SymbolTable_LeftValue, SymbolTable_IsConst (op1), SymbolTable_IsConst (op2), (m2expr_BuildExprProcedure_C) m2expr_BuildIsSubset, reinterpret_cast <char * > (falselabel));
8850 : 0 : m2statement_BuildGoto (location, reinterpret_cast <char * > (DynamicStrings_string (CreateLabelName (op3))));
8851 : 0 : m2statement_DeclareLabel (location, reinterpret_cast <char * > (falselabel));
8852 : : }
8853 : 0 : }
8854 : :
8855 : :
8856 : : /*
8857 : : PerformCodeIfGre - codes the quadruple if op1 > op2 then goto op3
8858 : : */
8859 : :
8860 : 4122 : static void PerformCodeIfGre (unsigned int quad)
8861 : : {
8862 : 4122 : tree tl;
8863 : 4122 : tree tr;
8864 : 4122 : location_t location;
8865 : 4122 : unsigned int left;
8866 : 4122 : unsigned int right;
8867 : 4122 : unsigned int dest;
8868 : 4122 : unsigned int combined;
8869 : 4122 : unsigned int leftpos;
8870 : 4122 : unsigned int rightpos;
8871 : 4122 : unsigned int destpos;
8872 : 4122 : bool constExpr;
8873 : 4122 : bool overflow;
8874 : 4122 : M2Quads_QuadOperator op;
8875 : :
8876 : 4122 : M2Quads_GetQuadOtok (quad, &combined, &op, &left, &right, &dest, &overflow, &constExpr, &leftpos, &rightpos, &destpos);
8877 : 4122 : location = M2LexBuf_TokenToLocation (combined);
8878 : 4122 : if ((SymbolTable_IsConst (left)) && (SymbolTable_IsConst (right)))
8879 : : {
8880 : 0 : SymbolTable_PushValue (left);
8881 : 0 : SymbolTable_PushValue (right);
8882 : 0 : if (M2ALU_Gre (combined))
8883 : : {
8884 : 0 : m2statement_BuildGoto (location, reinterpret_cast <char * > (DynamicStrings_string (CreateLabelName (dest))));
8885 : : }
8886 : : /* fall through */
8887 : : }
8888 : 4122 : else if ((((SymbolTable_IsConstSet (left)) || ((SymbolTable_IsVar (left)) && (SymbolTable_IsSet (SymbolTable_SkipType (SymbolTable_GetType (left)))))) || (SymbolTable_IsConstSet (right))) || ((SymbolTable_IsVar (right)) && (SymbolTable_IsSet (SymbolTable_SkipType (SymbolTable_GetType (right))))))
8889 : : {
8890 : : /* avoid dangling else. */
8891 : 0 : CodeIfSetGre (quad, left, right, dest);
8892 : : }
8893 : : else
8894 : : {
8895 : : /* avoid dangling else. */
8896 : 4122 : if ((SymbolTable_IsComposite (SymbolTable_GetType (left))) || (SymbolTable_IsComposite (SymbolTable_GetType (right))))
8897 : : {
8898 : 0 : M2MetaError_MetaErrorT2 (combined, (const char *) "comparison tests between composite types not allowed {%1Eatd} and {%2atd}", 73, left, right);
8899 : : }
8900 : : else
8901 : : {
8902 : 4122 : ConvertBinaryOperands (location, &tl, &tr, ComparisonMixTypes (left, right, SymbolTable_SkipType (SymbolTable_GetType (left)), SymbolTable_SkipType (SymbolTable_GetType (right)), combined), left, right);
8903 : 4122 : m2statement_DoJump (location, m2expr_BuildGreaterThan (location, tl, tr), NULL, reinterpret_cast <char * > (DynamicStrings_string (CreateLabelName (dest))));
8904 : : }
8905 : : }
8906 : 4122 : }
8907 : :
8908 : :
8909 : : /*
8910 : : CodeIfGre - codes the quadruple if op1 > op2 then goto op3
8911 : : */
8912 : :
8913 : 4122 : static void CodeIfGre (unsigned int quad)
8914 : : {
8915 : 4122 : if (IsValidExpressionRelOp (quad, false))
8916 : : {
8917 : 4122 : PerformCodeIfGre (quad);
8918 : : }
8919 : 4122 : }
8920 : :
8921 : :
8922 : : /*
8923 : : CodeIfSetLessEqu -
8924 : : */
8925 : :
8926 : 6 : static void CodeIfSetLessEqu (unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3)
8927 : : {
8928 : 6 : unsigned int settype;
8929 : 6 : void * falselabel;
8930 : 6 : location_t location;
8931 : :
8932 : 6 : location = M2LexBuf_TokenToLocation (CurrentQuadToken);
8933 : 6 : if ((SymbolTable_IsConst (op1)) && (SymbolTable_IsConst (op2)))
8934 : : {
8935 : 0 : M2Error_InternalError ((const char *) "this should have been folded in the calling procedure", 53);
8936 : : }
8937 : 6 : else if (SymbolTable_IsConst (op1))
8938 : : {
8939 : : /* avoid dangling else. */
8940 : 0 : settype = SymbolTable_SkipType (SymbolTable_GetType (op2));
8941 : : }
8942 : : else
8943 : : {
8944 : : /* avoid dangling else. */
8945 : 6 : settype = SymbolTable_SkipType (SymbolTable_GetType (op1));
8946 : : }
8947 : 6 : if ((m2expr_CompareTrees (FindSize (CurrentQuadToken, settype), FindSize (CurrentQuadToken, M2System_Word))) <= 0)
8948 : : {
8949 : : /* word size sets */
8950 : 0 : m2statement_DoJump (location, m2expr_BuildIsSubset (location, m2convert_BuildConvert (location, m2type_GetWordType (), SymbolConversion_Mod2Gcc (op1), false), m2convert_BuildConvert (location, m2type_GetWordType (), SymbolConversion_Mod2Gcc (op2), false)), NULL, reinterpret_cast <char * > (DynamicStrings_string (CreateLabelName (op3))));
8951 : : }
8952 : : else
8953 : : {
8954 : 6 : falselabel = DynamicStrings_string (FormatStrings_Sprintf1 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) ".Lset%dcomp", 11)), (const unsigned char *) &quad, (sizeof (quad)-1)));
8955 : 6 : m2expr_BuildForeachWordInSetDoIfExpr (location, SymbolConversion_Mod2Gcc (settype), SymbolConversion_Mod2Gcc (op1), SymbolConversion_Mod2Gcc (op2), (SymbolTable_GetMode (op1)) == SymbolTable_LeftValue, (SymbolTable_GetMode (op2)) == SymbolTable_LeftValue, SymbolTable_IsConst (op1), SymbolTable_IsConst (op2), (m2expr_BuildExprProcedure_C) m2expr_BuildIsNotSubset, reinterpret_cast <char * > (falselabel));
8956 : 6 : m2statement_BuildGoto (location, reinterpret_cast <char * > (DynamicStrings_string (CreateLabelName (op3))));
8957 : 6 : m2statement_DeclareLabel (location, reinterpret_cast <char * > (falselabel));
8958 : : }
8959 : 6 : }
8960 : :
8961 : :
8962 : : /*
8963 : : PerformCodeIfLessEqu - codes the quadruple if op1 <= op2 then goto op3
8964 : : */
8965 : :
8966 : 4938 : static void PerformCodeIfLessEqu (unsigned int quad)
8967 : : {
8968 : 4938 : tree tl;
8969 : 4938 : tree tr;
8970 : 4938 : location_t location;
8971 : 4938 : unsigned int left;
8972 : 4938 : unsigned int right;
8973 : 4938 : unsigned int dest;
8974 : 4938 : unsigned int combined;
8975 : 4938 : unsigned int leftpos;
8976 : 4938 : unsigned int rightpos;
8977 : 4938 : unsigned int destpos;
8978 : 4938 : bool constExpr;
8979 : 4938 : bool overflow;
8980 : 4938 : M2Quads_QuadOperator op;
8981 : :
8982 : 4938 : M2Quads_GetQuadOtok (quad, &combined, &op, &left, &right, &dest, &overflow, &constExpr, &leftpos, &rightpos, &destpos);
8983 : 4938 : location = M2LexBuf_TokenToLocation (combined);
8984 : 4938 : if ((SymbolTable_IsConst (left)) && (SymbolTable_IsConst (right)))
8985 : : {
8986 : 0 : SymbolTable_PushValue (left);
8987 : 0 : SymbolTable_PushValue (right);
8988 : 0 : if (M2ALU_LessEqu (combined))
8989 : : {
8990 : 0 : m2statement_BuildGoto (location, reinterpret_cast <char * > (DynamicStrings_string (CreateLabelName (dest))));
8991 : : }
8992 : : /* fall through */
8993 : : }
8994 : 4938 : else if ((((SymbolTable_IsConstSet (left)) || ((SymbolTable_IsVar (left)) && (SymbolTable_IsSet (SymbolTable_SkipType (SymbolTable_GetType (left)))))) || (SymbolTable_IsConstSet (right))) || ((SymbolTable_IsVar (right)) && (SymbolTable_IsSet (SymbolTable_SkipType (SymbolTable_GetType (right))))))
8995 : : {
8996 : : /* avoid dangling else. */
8997 : 6 : CodeIfSetLessEqu (quad, left, right, dest);
8998 : : }
8999 : : else
9000 : : {
9001 : : /* avoid dangling else. */
9002 : 4932 : if ((SymbolTable_IsComposite (SymbolTable_GetType (left))) || (SymbolTable_IsComposite (SymbolTable_GetType (right))))
9003 : : {
9004 : 0 : M2MetaError_MetaErrorT2 (combined, (const char *) "comparison tests between composite types not allowed {%1Eatd} and {%2atd}", 73, left, right);
9005 : : }
9006 : : else
9007 : : {
9008 : 4932 : ConvertBinaryOperands (location, &tl, &tr, ComparisonMixTypes (left, right, SymbolTable_SkipType (SymbolTable_GetType (left)), SymbolTable_SkipType (SymbolTable_GetType (right)), combined), left, right);
9009 : 4932 : m2statement_DoJump (location, m2expr_BuildLessThanOrEqual (location, tl, tr), NULL, reinterpret_cast <char * > (DynamicStrings_string (CreateLabelName (dest))));
9010 : : }
9011 : : }
9012 : 4938 : }
9013 : :
9014 : :
9015 : : /*
9016 : : CodeIfLessEqu - codes the quadruple if op1 <= op2 then goto op3
9017 : : */
9018 : :
9019 : 4950 : static void CodeIfLessEqu (unsigned int quad)
9020 : : {
9021 : 4950 : if (IsValidExpressionRelOp (quad, false))
9022 : : {
9023 : 4938 : PerformCodeIfLessEqu (quad);
9024 : : }
9025 : 4950 : }
9026 : :
9027 : :
9028 : : /*
9029 : : CodeIfSetGreEqu -
9030 : : */
9031 : :
9032 : 6 : static void CodeIfSetGreEqu (unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3)
9033 : : {
9034 : 6 : unsigned int settype;
9035 : 6 : void * falselabel;
9036 : 6 : location_t location;
9037 : :
9038 : 6 : location = M2LexBuf_TokenToLocation (CurrentQuadToken);
9039 : 6 : if ((SymbolTable_IsConst (op1)) && (SymbolTable_IsConst (op2)))
9040 : : {
9041 : 0 : M2Error_InternalError ((const char *) "this should have been folded in the calling procedure", 53);
9042 : : }
9043 : 6 : else if (SymbolTable_IsConst (op1))
9044 : : {
9045 : : /* avoid dangling else. */
9046 : 0 : settype = SymbolTable_SkipType (SymbolTable_GetType (op2));
9047 : : }
9048 : : else
9049 : : {
9050 : : /* avoid dangling else. */
9051 : 6 : settype = SymbolTable_SkipType (SymbolTable_GetType (op1));
9052 : : }
9053 : 6 : if ((m2expr_CompareTrees (FindSize (CurrentQuadToken, settype), FindSize (CurrentQuadToken, M2System_Word))) <= 0)
9054 : : {
9055 : : /* word size sets */
9056 : 0 : m2statement_DoJump (location, m2expr_BuildIsSuperset (location, m2convert_BuildConvert (location, m2type_GetWordType (), SymbolConversion_Mod2Gcc (op1), false), m2convert_BuildConvert (location, m2type_GetWordType (), SymbolConversion_Mod2Gcc (op2), false)), NULL, reinterpret_cast <char * > (DynamicStrings_string (CreateLabelName (op3))));
9057 : : }
9058 : : else
9059 : : {
9060 : 6 : falselabel = DynamicStrings_string (FormatStrings_Sprintf1 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) ".Lset%dcomp", 11)), (const unsigned char *) &quad, (sizeof (quad)-1)));
9061 : 6 : m2expr_BuildForeachWordInSetDoIfExpr (location, SymbolConversion_Mod2Gcc (settype), SymbolConversion_Mod2Gcc (op1), SymbolConversion_Mod2Gcc (op2), (SymbolTable_GetMode (op1)) == SymbolTable_LeftValue, (SymbolTable_GetMode (op2)) == SymbolTable_LeftValue, SymbolTable_IsConst (op1), SymbolTable_IsConst (op2), (m2expr_BuildExprProcedure_C) m2expr_BuildIsNotSuperset, reinterpret_cast <char * > (falselabel));
9062 : 6 : m2statement_BuildGoto (location, reinterpret_cast <char * > (DynamicStrings_string (CreateLabelName (op3))));
9063 : 6 : m2statement_DeclareLabel (location, reinterpret_cast <char * > (falselabel));
9064 : : }
9065 : 6 : }
9066 : :
9067 : :
9068 : : /*
9069 : : PerformCodeIfGreEqu - codes the quadruple if op1 >= op2 then goto op3
9070 : : */
9071 : :
9072 : 5158 : static void PerformCodeIfGreEqu (unsigned int quad)
9073 : : {
9074 : 5158 : tree tl;
9075 : 5158 : tree tr;
9076 : 5158 : location_t location;
9077 : 5158 : unsigned int left;
9078 : 5158 : unsigned int right;
9079 : 5158 : unsigned int dest;
9080 : 5158 : unsigned int combined;
9081 : 5158 : unsigned int leftpos;
9082 : 5158 : unsigned int rightpos;
9083 : 5158 : unsigned int destpos;
9084 : 5158 : bool constExpr;
9085 : 5158 : bool overflow;
9086 : 5158 : M2Quads_QuadOperator op;
9087 : :
9088 : 5158 : M2Quads_GetQuadOtok (quad, &combined, &op, &left, &right, &dest, &overflow, &constExpr, &leftpos, &rightpos, &destpos);
9089 : 5158 : location = M2LexBuf_TokenToLocation (combined);
9090 : 5158 : if ((SymbolTable_IsConst (left)) && (SymbolTable_IsConst (right)))
9091 : : {
9092 : 0 : SymbolTable_PushValue (left);
9093 : 0 : SymbolTable_PushValue (right);
9094 : 0 : if (M2ALU_GreEqu (combined))
9095 : : {
9096 : 0 : m2statement_BuildGoto (location, reinterpret_cast <char * > (DynamicStrings_string (CreateLabelName (dest))));
9097 : : }
9098 : : /* fall through */
9099 : : }
9100 : 5158 : else if ((((SymbolTable_IsConstSet (left)) || ((SymbolTable_IsVar (left)) && (SymbolTable_IsSet (SymbolTable_SkipType (SymbolTable_GetType (left)))))) || (SymbolTable_IsConstSet (right))) || ((SymbolTable_IsVar (right)) && (SymbolTable_IsSet (SymbolTable_SkipType (SymbolTable_GetType (right))))))
9101 : : {
9102 : : /* avoid dangling else. */
9103 : 6 : CodeIfSetGreEqu (quad, left, right, dest);
9104 : : }
9105 : : else
9106 : : {
9107 : : /* avoid dangling else. */
9108 : 5152 : if ((SymbolTable_IsComposite (SymbolTable_GetType (left))) || (SymbolTable_IsComposite (SymbolTable_GetType (right))))
9109 : : {
9110 : 0 : M2MetaError_MetaErrorT2 (combined, (const char *) "comparison tests between composite types not allowed {%1Eatd} and {%2atd}", 73, left, right);
9111 : : }
9112 : : else
9113 : : {
9114 : 5152 : ConvertBinaryOperands (location, &tl, &tr, ComparisonMixTypes (left, right, SymbolTable_SkipType (SymbolTable_GetType (left)), SymbolTable_SkipType (SymbolTable_GetType (right)), combined), left, right);
9115 : 5152 : m2statement_DoJump (location, m2expr_BuildGreaterThanOrEqual (location, tl, tr), NULL, reinterpret_cast <char * > (DynamicStrings_string (CreateLabelName (dest))));
9116 : : }
9117 : : }
9118 : 5158 : }
9119 : :
9120 : :
9121 : : /*
9122 : : CodeIfGreEqu - codes the quadruple if op1 >= op2 then goto op3
9123 : : */
9124 : :
9125 : 5164 : static void CodeIfGreEqu (unsigned int quad)
9126 : : {
9127 : 5164 : if (IsValidExpressionRelOp (quad, false))
9128 : : {
9129 : 5158 : PerformCodeIfGreEqu (quad);
9130 : : }
9131 : 5164 : }
9132 : :
9133 : :
9134 : : /*
9135 : : CodeIfSetEqu - codes if op1 = op2 then goto op3
9136 : : Note that if op1 and op2 are not both constants
9137 : : since this will have been evaluated in CodeIfEqu.
9138 : : */
9139 : :
9140 : 488 : static void CodeIfSetEqu (unsigned int quad, unsigned int op1, unsigned int op2, unsigned int op3)
9141 : : {
9142 : 488 : unsigned int settype;
9143 : 488 : void * falselabel;
9144 : 488 : location_t location;
9145 : :
9146 : 488 : location = M2LexBuf_TokenToLocation (CurrentQuadToken);
9147 : 488 : if ((SymbolTable_IsConst (op1)) && (SymbolTable_IsConst (op2)))
9148 : : {
9149 : 0 : M2Error_InternalError ((const char *) "this should have been folded in the calling procedure", 53);
9150 : : }
9151 : 488 : else if (SymbolTable_IsConst (op1))
9152 : : {
9153 : : /* avoid dangling else. */
9154 : 0 : settype = SymbolTable_SkipType (SymbolTable_GetType (op2));
9155 : : }
9156 : : else
9157 : : {
9158 : : /* avoid dangling else. */
9159 : 488 : settype = SymbolTable_SkipType (SymbolTable_GetType (op1));
9160 : : }
9161 : 488 : if ((m2expr_CompareTrees (FindSize (CurrentQuadToken, settype), FindSize (CurrentQuadToken, M2System_Word))) <= 0)
9162 : : {
9163 : : /* word size sets */
9164 : 230 : m2statement_DoJump (location, m2expr_BuildEqualTo (location, m2convert_BuildConvert (location, m2type_GetWordType (), SymbolConversion_Mod2Gcc (op1), false), m2convert_BuildConvert (location, m2type_GetWordType (), SymbolConversion_Mod2Gcc (op2), false)), NULL, reinterpret_cast <char * > (DynamicStrings_string (CreateLabelName (op3))));
9165 : : }
9166 : 258 : else if ((SymbolTable_GetSType (op1)) == (SymbolTable_GetSType (op2)))
9167 : : {
9168 : : /* avoid dangling else. */
9169 : 258 : falselabel = DynamicStrings_string (FormatStrings_Sprintf1 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) ".Lset%dcomp", 11)), (const unsigned char *) &quad, (sizeof (quad)-1)));
9170 : 258 : m2expr_BuildForeachWordInSetDoIfExpr (location, SymbolConversion_Mod2Gcc (settype), SymbolConversion_Mod2Gcc (op1), SymbolConversion_Mod2Gcc (op2), (SymbolTable_GetMode (op1)) == SymbolTable_LeftValue, (SymbolTable_GetMode (op2)) == SymbolTable_LeftValue, SymbolTable_IsConst (op1), SymbolTable_IsConst (op2), (m2expr_BuildExprProcedure_C) m2expr_BuildNotEqualTo, reinterpret_cast <char * > (falselabel));
9171 : 258 : m2statement_BuildGoto (location, reinterpret_cast <char * > (DynamicStrings_string (CreateLabelName (op3))));
9172 : 258 : m2statement_DeclareLabel (location, reinterpret_cast <char * > (falselabel));
9173 : : }
9174 : : else
9175 : : {
9176 : : /* avoid dangling else. */
9177 : 0 : M2MetaError_MetaErrorT2 (CurrentQuadToken, (const char *) "set comparison is only allowed between the same set type, the set types used by {%1Eatd} and {%2atd} are different", 114, op1, op2);
9178 : : }
9179 : 488 : }
9180 : :
9181 : :
9182 : : /*
9183 : : CodeIfSetNotEqu - codes if op1 # op2 then goto op3
9184 : : Note that if op1 and op2 are not both constants
9185 : : since this will have been evaluated in CodeIfNotEqu.
9186 : : */
9187 : :
9188 : 588 : static void CodeIfSetNotEqu (unsigned int left, unsigned int right, unsigned int destQuad)
9189 : : {
9190 : 588 : unsigned int settype;
9191 : 588 : void * truelabel;
9192 : 588 : location_t location;
9193 : :
9194 : 588 : location = M2LexBuf_TokenToLocation (CurrentQuadToken);
9195 : 588 : if ((SymbolTable_IsConst (left)) && (SymbolTable_IsConst (right)))
9196 : : {
9197 : 0 : M2Error_InternalError ((const char *) "this should have been folded in the calling procedure", 53);
9198 : : }
9199 : 588 : else if (SymbolTable_IsConst (left))
9200 : : {
9201 : : /* avoid dangling else. */
9202 : 0 : settype = SymbolTable_SkipType (SymbolTable_GetType (right));
9203 : : }
9204 : : else
9205 : : {
9206 : : /* avoid dangling else. */
9207 : 588 : settype = SymbolTable_SkipType (SymbolTable_GetType (left));
9208 : : }
9209 : 588 : if ((m2expr_CompareTrees (FindSize (CurrentQuadToken, settype), FindSize (CurrentQuadToken, M2System_Word))) <= 0)
9210 : : {
9211 : : /* word size sets */
9212 : 360 : m2statement_DoJump (location, m2expr_BuildNotEqualTo (location, m2convert_BuildConvert (location, m2type_GetWordType (), SymbolConversion_Mod2Gcc (left), false), m2convert_BuildConvert (location, m2type_GetWordType (), SymbolConversion_Mod2Gcc (right), false)), NULL, reinterpret_cast <char * > (DynamicStrings_string (CreateLabelName (destQuad))));
9213 : : }
9214 : 228 : else if ((SymbolTable_GetSType (left)) == (SymbolTable_GetSType (right)))
9215 : : {
9216 : : /* avoid dangling else. */
9217 : 228 : truelabel = DynamicStrings_string (CreateLabelName (destQuad));
9218 : 228 : m2expr_BuildForeachWordInSetDoIfExpr (location, SymbolConversion_Mod2Gcc (settype), SymbolConversion_Mod2Gcc (left), SymbolConversion_Mod2Gcc (right), (SymbolTable_GetMode (left)) == SymbolTable_LeftValue, (SymbolTable_GetMode (right)) == SymbolTable_LeftValue, SymbolTable_IsConst (left), SymbolTable_IsConst (right), (m2expr_BuildExprProcedure_C) m2expr_BuildNotEqualTo, reinterpret_cast <char * > (truelabel));
9219 : : }
9220 : : else
9221 : : {
9222 : : /* avoid dangling else. */
9223 : 0 : M2MetaError_MetaErrorT2 (CurrentQuadToken, (const char *) "set comparison is only allowed between the same set type, the set types used by {%1Eatd} and {%2atd} are different", 114, left, right);
9224 : : }
9225 : 588 : }
9226 : :
9227 : :
9228 : : /*
9229 : : ComparisonMixTypes -
9230 : : */
9231 : :
9232 : 63161 : static unsigned int ComparisonMixTypes (unsigned int varleft, unsigned int varright, unsigned int left, unsigned int right, unsigned int tokpos)
9233 : : {
9234 : 63161 : if (M2System_IsGenericSystemType (left))
9235 : : {
9236 : : return left;
9237 : : }
9238 : 62987 : else if (M2System_IsGenericSystemType (right))
9239 : : {
9240 : : /* avoid dangling else. */
9241 : : return right;
9242 : : }
9243 : : else
9244 : : {
9245 : : /* avoid dangling else. */
9246 : 62987 : return M2Base_MixTypesDecl (varleft, varright, left, right, tokpos);
9247 : : }
9248 : : /* static analysis guarentees a RETURN statement will be used before here. */
9249 : : __builtin_unreachable ();
9250 : : }
9251 : :
9252 : :
9253 : : /*
9254 : : PerformCodeIfEqu -
9255 : : */
9256 : :
9257 : 18456 : static void PerformCodeIfEqu (unsigned int quad)
9258 : : {
9259 : 18456 : tree tl;
9260 : 18456 : tree tr;
9261 : 18456 : location_t location;
9262 : 18456 : unsigned int left;
9263 : 18456 : unsigned int right;
9264 : 18456 : unsigned int dest;
9265 : 18456 : unsigned int combined;
9266 : 18456 : unsigned int leftpos;
9267 : 18456 : unsigned int rightpos;
9268 : 18456 : unsigned int destpos;
9269 : 18456 : bool constExpr;
9270 : 18456 : bool overflow;
9271 : 18456 : M2Quads_QuadOperator op;
9272 : :
9273 : 18456 : M2Quads_GetQuadOtok (quad, &combined, &op, &left, &right, &dest, &overflow, &constExpr, &leftpos, &rightpos, &destpos);
9274 : 18456 : location = M2LexBuf_TokenToLocation (combined);
9275 : 18456 : if ((SymbolTable_IsConst (left)) && (SymbolTable_IsConst (right)))
9276 : : {
9277 : 0 : SymbolTable_PushValue (left);
9278 : 0 : SymbolTable_PushValue (right);
9279 : 0 : if (M2ALU_Equ (combined))
9280 : : {
9281 : 0 : m2statement_BuildGoto (location, reinterpret_cast <char * > (DynamicStrings_string (CreateLabelName (dest))));
9282 : : }
9283 : : /* Fall through. */
9284 : : }
9285 : 18456 : else if ((((SymbolTable_IsConstSet (left)) || ((SymbolTable_IsVar (left)) && (SymbolTable_IsSet (SymbolTable_SkipType (SymbolTable_GetType (left)))))) || (SymbolTable_IsConstSet (right))) || ((SymbolTable_IsVar (right)) && (SymbolTable_IsSet (SymbolTable_SkipType (SymbolTable_GetType (right))))))
9286 : : {
9287 : : /* avoid dangling else. */
9288 : 488 : CodeIfSetEqu (quad, left, right, dest);
9289 : : }
9290 : : else
9291 : : {
9292 : : /* avoid dangling else. */
9293 : 17968 : if ((SymbolTable_IsComposite (SymbolTable_GetType (left))) || (SymbolTable_IsComposite (SymbolTable_GetType (right))))
9294 : : {
9295 : 0 : M2MetaError_MetaErrorT2 (combined, (const char *) "equality tests between composite types not allowed {%1Eatd} and {%2atd}", 71, left, right);
9296 : : }
9297 : : else
9298 : : {
9299 : 17968 : ConvertBinaryOperands (location, &tl, &tr, ComparisonMixTypes (left, right, SymbolTable_SkipType (SymbolTable_GetType (left)), SymbolTable_SkipType (SymbolTable_GetType (right)), combined), left, right);
9300 : 17968 : m2statement_DoJump (location, m2expr_BuildEqualTo (location, tl, tr), NULL, reinterpret_cast <char * > (DynamicStrings_string (CreateLabelName (dest))));
9301 : : }
9302 : : }
9303 : 18456 : }
9304 : :
9305 : :
9306 : : /*
9307 : : PerformCodeIfNotEqu -
9308 : : */
9309 : :
9310 : 28435 : static void PerformCodeIfNotEqu (unsigned int quad)
9311 : : {
9312 : 28435 : tree tl;
9313 : 28435 : tree tr;
9314 : 28435 : location_t location;
9315 : 28435 : unsigned int left;
9316 : 28435 : unsigned int right;
9317 : 28435 : unsigned int dest;
9318 : 28435 : unsigned int combined;
9319 : 28435 : unsigned int leftpos;
9320 : 28435 : unsigned int rightpos;
9321 : 28435 : unsigned int destpos;
9322 : 28435 : bool constExpr;
9323 : 28435 : bool overflow;
9324 : 28435 : M2Quads_QuadOperator op;
9325 : :
9326 : : /* Ensure that any remaining undeclared constant literal is declared. */
9327 : 28435 : M2Quads_GetQuadOtok (quad, &combined, &op, &left, &right, &dest, &constExpr, &overflow, &leftpos, &rightpos, &destpos);
9328 : 28435 : location = M2LexBuf_TokenToLocation (combined);
9329 : 28435 : if ((SymbolTable_IsConst (left)) && (SymbolTable_IsConst (right)))
9330 : : {
9331 : 6 : SymbolTable_PushValue (left);
9332 : 6 : SymbolTable_PushValue (right);
9333 : 6 : if (M2ALU_NotEqu (combined))
9334 : : {
9335 : 0 : m2statement_BuildGoto (location, reinterpret_cast <char * > (DynamicStrings_string (CreateLabelName (dest))));
9336 : : }
9337 : : /* Fall through. */
9338 : : }
9339 : 28429 : else if ((((SymbolTable_IsConstSet (left)) || ((SymbolTable_IsVar (left)) && (SymbolTable_IsSet (SymbolTable_SkipType (SymbolTable_GetType (left)))))) || (SymbolTable_IsConstSet (right))) || ((SymbolTable_IsVar (right)) && (SymbolTable_IsSet (SymbolTable_SkipType (SymbolTable_GetType (right))))))
9340 : : {
9341 : : /* avoid dangling else. */
9342 : 588 : CodeIfSetNotEqu (left, right, dest);
9343 : : }
9344 : : else
9345 : : {
9346 : : /* avoid dangling else. */
9347 : 27841 : if ((SymbolTable_IsComposite (SymbolTable_GetType (left))) || (SymbolTable_IsComposite (SymbolTable_GetType (right))))
9348 : : {
9349 : 0 : M2MetaError_MetaErrorT2 (combined, (const char *) "inequality tests between composite types not allowed {%1Eatd} and {%2atd}", 73, left, right);
9350 : : }
9351 : : else
9352 : : {
9353 : 27841 : ConvertBinaryOperands (location, &tl, &tr, ComparisonMixTypes (left, right, SymbolTable_SkipType (SymbolTable_GetType (left)), SymbolTable_SkipType (SymbolTable_GetType (right)), combined), left, right);
9354 : 27841 : m2statement_DoJump (location, m2expr_BuildNotEqualTo (location, tl, tr), NULL, reinterpret_cast <char * > (DynamicStrings_string (CreateLabelName (dest))));
9355 : : }
9356 : : }
9357 : 28435 : }
9358 : :
9359 : :
9360 : : /*
9361 : : IsValidExpressionRelOp - declare left and right constants (if they are not already declared).
9362 : : Check whether left and right are expression compatible.
9363 : : */
9364 : :
9365 : 65847 : static bool IsValidExpressionRelOp (unsigned int quad, bool isin)
9366 : : {
9367 : 65847 : unsigned int left;
9368 : 65847 : unsigned int right;
9369 : 65847 : unsigned int dest;
9370 : 65847 : unsigned int combined;
9371 : 65847 : unsigned int leftpos;
9372 : 65847 : unsigned int rightpos;
9373 : 65847 : unsigned int destpos;
9374 : 65847 : bool constExpr;
9375 : 65847 : bool overflow;
9376 : 65847 : M2Quads_QuadOperator op;
9377 : :
9378 : : /* Ensure that any remaining undeclared constant literal is declared. */
9379 : 65847 : M2Quads_GetQuadOtok (quad, &combined, &op, &left, &right, &dest, &constExpr, &overflow, &leftpos, &rightpos, &destpos);
9380 : 65847 : M2GCCDeclare_DeclareConstant (leftpos, left);
9381 : 65847 : M2GCCDeclare_DeclareConstant (rightpos, right);
9382 : 65847 : M2GCCDeclare_DeclareConstructor (leftpos, quad, left);
9383 : 65847 : M2GCCDeclare_DeclareConstructor (rightpos, quad, right);
9384 : 65847 : if (M2Check_ExpressionTypeCompatible (combined, (const char *) "", 0, left, right, M2Options_StrictTypeChecking, isin))
9385 : : {
9386 : : return true;
9387 : : }
9388 : : else
9389 : : {
9390 : : if (Verbose)
9391 : : {
9392 : : M2MetaError_MetaErrorT2 (combined, (const char *) "expression mismatch between {%1Etad} and {%2tad} seen during comparison", 71, left, right);
9393 : : }
9394 : : return false;
9395 : : }
9396 : : /* static analysis guarentees a RETURN statement will be used before here. */
9397 : : __builtin_unreachable ();
9398 : : }
9399 : :
9400 : :
9401 : : /*
9402 : : CodeIfEqu - codes the quadruple if op1 = op2 then goto op3
9403 : : */
9404 : :
9405 : 18474 : static void CodeIfEqu (unsigned int quad)
9406 : : {
9407 : 18474 : if (IsValidExpressionRelOp (quad, false))
9408 : : {
9409 : 18456 : PerformCodeIfEqu (quad);
9410 : : }
9411 : 18474 : }
9412 : :
9413 : :
9414 : : /*
9415 : : CodeIfNotEqu - codes the quadruple if op1 # op2 then goto op3
9416 : : */
9417 : :
9418 : 28447 : static void CodeIfNotEqu (unsigned int quad)
9419 : : {
9420 : 28447 : if (IsValidExpressionRelOp (quad, false))
9421 : : {
9422 : 28435 : PerformCodeIfNotEqu (quad);
9423 : : }
9424 : 28447 : }
9425 : :
9426 : :
9427 : : /*
9428 : : MixTypes3 - returns a type compatible from, low, high, var.
9429 : : */
9430 : :
9431 : 108 : static unsigned int MixTypes3 (unsigned int low, unsigned int high, unsigned int var, unsigned int tokenno)
9432 : : {
9433 : 108 : unsigned int type;
9434 : :
9435 : 108 : type = M2Base_MixTypes (SymbolTable_SkipType (SymbolTable_GetType (low)), SymbolTable_SkipType (SymbolTable_GetType (high)), tokenno);
9436 : 108 : type = M2Base_MixTypes (type, SymbolTable_SkipType (SymbolTable_GetType (var)), tokenno);
9437 : 108 : return type;
9438 : : /* static analysis guarentees a RETURN statement will be used before here. */
9439 : : __builtin_unreachable ();
9440 : : }
9441 : :
9442 : :
9443 : : /*
9444 : : BuildIfVarInConstValue - if var in constsetvalue then goto trueexit
9445 : : */
9446 : :
9447 : 6 : static void BuildIfVarInConstValue (location_t location, unsigned int tokenno, M2ALU_PtrToValue constsetvalue, unsigned int var, unsigned int trueexit)
9448 : : {
9449 : 6 : tree vt;
9450 : 6 : tree lt;
9451 : 6 : tree ht;
9452 : 6 : unsigned int type;
9453 : 6 : unsigned int low;
9454 : 6 : unsigned int high;
9455 : 6 : unsigned int n;
9456 : 6 : DynamicStrings_String truelabel;
9457 : :
9458 : 6 : n = 1;
9459 : 6 : truelabel = static_cast<DynamicStrings_String> (DynamicStrings_string (CreateLabelName (trueexit)));
9460 : 24 : while (M2ALU_GetRange (constsetvalue, n, &low, &high))
9461 : : {
9462 : 12 : type = MixTypes3 (low, high, var, tokenno);
9463 : 12 : ConvertBinaryOperands (location, &vt, <, type, var, low);
9464 : 12 : ConvertBinaryOperands (location, &ht, <, type, high, low);
9465 : 12 : m2expr_BuildIfInRangeGoto (location, vt, lt, ht, reinterpret_cast <char * > (truelabel));
9466 : 12 : n += 1;
9467 : : }
9468 : 6 : }
9469 : :
9470 : :
9471 : : /*
9472 : : BuildIfNotVarInConstValue - if not (var in constsetvalue) then goto trueexit
9473 : : */
9474 : :
9475 : 60 : static void BuildIfNotVarInConstValue (unsigned int quad, M2ALU_PtrToValue constsetvalue, unsigned int var, unsigned int trueexit)
9476 : : {
9477 : 60 : tree vt;
9478 : 60 : tree lt;
9479 : 60 : tree ht;
9480 : 60 : unsigned int type;
9481 : 60 : unsigned int low;
9482 : 60 : unsigned int high;
9483 : 60 : unsigned int n;
9484 : 60 : DynamicStrings_String falselabel;
9485 : 60 : DynamicStrings_String truelabel;
9486 : 60 : location_t location;
9487 : :
9488 : 60 : location = M2LexBuf_TokenToLocation (CurrentQuadToken);
9489 : 60 : truelabel = static_cast<DynamicStrings_String> (DynamicStrings_string (CreateLabelName (trueexit)));
9490 : 60 : n = 1;
9491 : 216 : while (M2ALU_GetRange (constsetvalue, n, &low, &high))
9492 : : {
9493 : 96 : n += 1;
9494 : : }
9495 : 60 : if (n == 2)
9496 : : {
9497 : : /* actually only one set range, so we invert it */
9498 : 28 : type = MixTypes3 (low, high, var, CurrentQuadToken);
9499 : 28 : ConvertBinaryOperands (location, &vt, <, type, var, low);
9500 : 28 : ConvertBinaryOperands (location, &ht, <, type, high, low);
9501 : 28 : m2expr_BuildIfNotInRangeGoto (location, vt, lt, ht, reinterpret_cast <char * > (truelabel));
9502 : : }
9503 : : else
9504 : : {
9505 : 32 : n = 1;
9506 : 32 : falselabel = static_cast<DynamicStrings_String> (DynamicStrings_string (FormatStrings_Sprintf1 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) ".Lset%d", 7)), (const unsigned char *) &quad, (sizeof (quad)-1))));
9507 : 132 : while (M2ALU_GetRange (constsetvalue, n, &low, &high))
9508 : : {
9509 : 68 : type = MixTypes3 (low, high, var, CurrentQuadToken);
9510 : 68 : ConvertBinaryOperands (location, &vt, <, type, var, low);
9511 : 68 : ConvertBinaryOperands (location, &ht, <, type, high, low);
9512 : 68 : m2expr_BuildIfInRangeGoto (location, vt, lt, ht, reinterpret_cast <char * > (falselabel));
9513 : 68 : n += 1;
9514 : : }
9515 : 32 : m2statement_BuildGoto (location, reinterpret_cast <char * > (truelabel));
9516 : 32 : m2statement_DeclareLabel (location, reinterpret_cast <char * > (falselabel));
9517 : : }
9518 : 60 : }
9519 : :
9520 : :
9521 : : /*
9522 : : PerformCodeIfIn - code the quadruple: if op1 in op2 then goto op3
9523 : : */
9524 : :
9525 : 366 : static void PerformCodeIfIn (unsigned int quad)
9526 : : {
9527 : 366 : unsigned int low;
9528 : 366 : unsigned int high;
9529 : 366 : tree lowtree;
9530 : 366 : tree hightree;
9531 : 366 : tree offset;
9532 : 366 : int fieldno;
9533 : 366 : location_t location;
9534 : 366 : unsigned int left;
9535 : 366 : unsigned int right;
9536 : 366 : unsigned int dest;
9537 : 366 : unsigned int combined;
9538 : 366 : unsigned int leftpos;
9539 : 366 : unsigned int rightpos;
9540 : 366 : unsigned int destpos;
9541 : 366 : bool constExpr;
9542 : 366 : bool overflow;
9543 : 366 : M2Quads_QuadOperator op;
9544 : :
9545 : : /* Ensure that any remaining undeclared constant literal is declared. */
9546 : 366 : M2Quads_GetQuadOtok (quad, &combined, &op, &left, &right, &dest, &constExpr, &overflow, &leftpos, &rightpos, &destpos);
9547 : 366 : location = M2LexBuf_TokenToLocation (combined);
9548 : 366 : if ((SymbolTable_IsConst (left)) && (SymbolTable_IsConst (right)))
9549 : : {
9550 : 0 : M2Error_InternalError ((const char *) "should not get to here (if we do we should consider calling FoldIfIn)", 69);
9551 : : }
9552 : 366 : else if (CheckElementSetTypes (quad))
9553 : : {
9554 : : /* avoid dangling else. */
9555 : 366 : if (SymbolTable_IsConst (left))
9556 : : {
9557 : 168 : fieldno = GetFieldNo (combined, left, SymbolTable_GetType (right), &offset);
9558 : 168 : if (fieldno >= 0)
9559 : : {
9560 : 168 : SymbolTable_PushValue (left);
9561 : 168 : M2ALU_PushIntegerTree (offset);
9562 : 168 : M2ALU_ConvertToType (SymbolTable_GetType (left));
9563 : 168 : M2ALU_Sub ();
9564 : 168 : m2expr_BuildIfConstInVar (location, SymbolConversion_Mod2Gcc (SymbolTable_SkipType (SymbolTable_GetType (right))), SymbolConversion_Mod2Gcc (right), M2ALU_PopIntegerTree (), (SymbolTable_GetMode (right)) == SymbolTable_LeftValue, fieldno, reinterpret_cast <char * > (DynamicStrings_string (CreateLabelName (dest))));
9565 : : }
9566 : : else
9567 : : {
9568 : 0 : M2MetaError_MetaErrorT1 (combined, (const char *) "bit exceeded the range of set {%1Eatd}", 38, left);
9569 : : }
9570 : : }
9571 : 198 : else if (SymbolTable_IsConst (right))
9572 : : {
9573 : : /* avoid dangling else. */
9574 : : /* builds a cascaded list of if statements */
9575 : 6 : SymbolTable_PushValue (right);
9576 : 6 : BuildIfVarInConstValue (location, combined, M2ALU_GetValue (combined), left, dest);
9577 : : }
9578 : : else
9579 : : {
9580 : : /* avoid dangling else. */
9581 : 192 : GetSetLimits (SymbolTable_SkipType (SymbolTable_GetType (right)), &low, &high);
9582 : 192 : SymbolTable_PushValue (low);
9583 : 192 : lowtree = M2ALU_PopIntegerTree ();
9584 : 192 : SymbolTable_PushValue (high);
9585 : 192 : hightree = M2ALU_PopIntegerTree ();
9586 : 192 : m2expr_BuildIfVarInVar (location, SymbolConversion_Mod2Gcc (SymbolTable_SkipType (SymbolTable_GetType (right))), SymbolConversion_Mod2Gcc (right), SymbolConversion_Mod2Gcc (left), (SymbolTable_GetMode (right)) == SymbolTable_LeftValue, lowtree, hightree, reinterpret_cast <char * > (DynamicStrings_string (CreateLabelName (dest))));
9587 : : }
9588 : : }
9589 : 366 : }
9590 : :
9591 : :
9592 : : /*
9593 : : PerformCodeIfNotIn - code the quadruple: if not (op1 in op2) then goto op3
9594 : : */
9595 : :
9596 : 1160 : static void PerformCodeIfNotIn (unsigned int quad)
9597 : : {
9598 : 1160 : unsigned int low;
9599 : 1160 : unsigned int high;
9600 : 1160 : tree lowtree;
9601 : 1160 : tree hightree;
9602 : 1160 : tree offset;
9603 : 1160 : int fieldno;
9604 : 1160 : location_t location;
9605 : 1160 : unsigned int left;
9606 : 1160 : unsigned int right;
9607 : 1160 : unsigned int dest;
9608 : 1160 : unsigned int combined;
9609 : 1160 : unsigned int leftpos;
9610 : 1160 : unsigned int rightpos;
9611 : 1160 : unsigned int destpos;
9612 : 1160 : bool constExpr;
9613 : 1160 : bool overflow;
9614 : 1160 : M2Quads_QuadOperator op;
9615 : :
9616 : : /* Ensure that any remaining undeclared constant literal is declared. */
9617 : 1160 : M2Quads_GetQuadOtok (quad, &combined, &op, &left, &right, &dest, &overflow, &constExpr, &leftpos, &rightpos, &destpos);
9618 : 1160 : location = M2LexBuf_TokenToLocation (combined);
9619 : 1160 : if ((SymbolTable_IsConst (left)) && (SymbolTable_IsConst (right)))
9620 : : {
9621 : 0 : M2Error_InternalError ((const char *) "should not get to here (if we do we should consider calling FoldIfIn)", 69);
9622 : : }
9623 : 1160 : else if (CheckElementSetTypes (quad))
9624 : : {
9625 : : /* avoid dangling else. */
9626 : 1154 : if (SymbolTable_IsConst (left))
9627 : : {
9628 : 622 : fieldno = GetFieldNo (combined, left, SymbolTable_SkipType (SymbolTable_GetType (right)), &offset);
9629 : 622 : if (fieldno >= 0)
9630 : : {
9631 : 616 : SymbolTable_PushValue (left);
9632 : 616 : M2ALU_PushIntegerTree (offset);
9633 : 616 : M2ALU_ConvertToType (SymbolTable_GetType (left));
9634 : 616 : M2ALU_Sub ();
9635 : 616 : m2expr_BuildIfNotConstInVar (location, SymbolConversion_Mod2Gcc (SymbolTable_SkipType (SymbolTable_GetType (right))), SymbolConversion_Mod2Gcc (right), M2ALU_PopIntegerTree (), (SymbolTable_GetMode (right)) == SymbolTable_LeftValue, fieldno, reinterpret_cast <char * > (DynamicStrings_string (CreateLabelName (dest))));
9636 : : }
9637 : : else
9638 : : {
9639 : 6 : M2MetaError_MetaErrorT1 (combined, (const char *) "bit exceeded the range of set {%1Eatd}", 38, right);
9640 : : }
9641 : : }
9642 : 532 : else if (SymbolTable_IsConst (right))
9643 : : {
9644 : : /* avoid dangling else. */
9645 : : /* builds a cascaded list of if statements */
9646 : 60 : SymbolTable_PushValue (right);
9647 : 60 : BuildIfNotVarInConstValue (quad, M2ALU_GetValue (combined), left, dest);
9648 : : }
9649 : : else
9650 : : {
9651 : : /* avoid dangling else. */
9652 : 472 : GetSetLimits (SymbolTable_SkipType (SymbolTable_GetType (right)), &low, &high);
9653 : 472 : SymbolTable_PushValue (low);
9654 : 472 : lowtree = M2ALU_PopIntegerTree ();
9655 : 472 : SymbolTable_PushValue (high);
9656 : 472 : hightree = M2ALU_PopIntegerTree ();
9657 : 472 : m2expr_BuildIfNotVarInVar (location, SymbolConversion_Mod2Gcc (SymbolTable_SkipType (SymbolTable_GetType (right))), SymbolConversion_Mod2Gcc (right), SymbolConversion_Mod2Gcc (left), (SymbolTable_GetMode (right)) == SymbolTable_LeftValue, lowtree, hightree, reinterpret_cast <char * > (DynamicStrings_string (CreateLabelName (dest))));
9658 : : }
9659 : : }
9660 : 1160 : }
9661 : :
9662 : :
9663 : : /*
9664 : : CodeIfIn - code the quadruple: if op1 in op2 then goto op3
9665 : : */
9666 : :
9667 : 372 : static void CodeIfIn (unsigned int quad)
9668 : : {
9669 : 372 : if (IsValidExpressionRelOp (quad, true))
9670 : : {
9671 : 366 : PerformCodeIfIn (quad);
9672 : : }
9673 : 372 : }
9674 : :
9675 : :
9676 : : /*
9677 : : CodeIfNotIn - code the quadruple: if not (op1 in op2) then goto op3
9678 : : */
9679 : :
9680 : 1166 : static void CodeIfNotIn (unsigned int quad)
9681 : : {
9682 : 1166 : if (IsValidExpressionRelOp (quad, true))
9683 : : {
9684 : 1160 : PerformCodeIfNotIn (quad);
9685 : : }
9686 : 1166 : }
9687 : :
9688 : 14499 : static void CodeIndrX (unsigned int quad)
9689 : : {
9690 : 14499 : bool constExpr;
9691 : 14499 : bool overflowChecking;
9692 : 14499 : M2Quads_QuadOperator op;
9693 : 14499 : unsigned int tokenno;
9694 : 14499 : unsigned int left;
9695 : 14499 : unsigned int type;
9696 : 14499 : unsigned int right;
9697 : 14499 : unsigned int leftpos;
9698 : 14499 : unsigned int rightpos;
9699 : 14499 : unsigned int typepos;
9700 : 14499 : unsigned int indrxpos;
9701 : 14499 : tree length;
9702 : 14499 : tree newstr;
9703 : 14499 : location_t location;
9704 : :
9705 : : /*
9706 : : ------------------------------------------------------------------------------
9707 : : IndrX Operator a = *b
9708 : : ------------------------------------------------------------------------------
9709 : : Sym1<X> IndrX Sym2<I> Meaning Mem[Sym1<I>] := Mem[constant]
9710 : : Sym1<X> IndrX Sym2<X> Meaning Mem[Sym1<I>] := Mem[Mem[Sym3<I>]]
9711 : :
9712 : : (op2 is the type of the data being indirectly copied)
9713 : : */
9714 : 14499 : M2Quads_GetQuadOtok (quad, &indrxpos, &op, &left, &type, &right, &overflowChecking, &constExpr, &leftpos, &typepos, &rightpos);
9715 : 14499 : tokenno = M2LexBuf_MakeVirtualTok (indrxpos, leftpos, rightpos);
9716 : 14499 : location = M2LexBuf_TokenToLocation (tokenno);
9717 : : /*
9718 : : Follow the Quadruple rules:
9719 : : */
9720 : 14499 : M2GCCDeclare_DeclareConstant (rightpos, right); /* Checks to see whether it is a constant
9721 : : and if necessary declare it. */
9722 : 14499 : M2GCCDeclare_DeclareConstructor (rightpos, quad, right); /* Checks to see whether it is a constant
9723 : : and if necessary declare it. */
9724 : 14499 : if (SymbolTable_IsConstString (right))
9725 : : {
9726 : 0 : M2Error_InternalError ((const char *) "not expecting to index through a constant string", 48);
9727 : : }
9728 : 14499 : else if (M2Options_StrictTypeChecking && (! (M2Check_AssignmentTypeCompatible (indrxpos, (const char *) "", 0, left, SymbolTable_GetType (right), true))))
9729 : : {
9730 : : /* avoid dangling else. */
9731 : 0 : M2MetaError_MetaErrorT2 (tokenno, (const char *) "assignment check caught mismatch between {%1Ead} and {%2ad}", 59, left, right);
9732 : 0 : M2Quads_SubQuad (quad);
9733 : : }
9734 : : else
9735 : : {
9736 : : /* avoid dangling else. */
9737 : : /*
9738 : : Mem[op1] := Mem[Mem[op3]]
9739 : : */
9740 : 14499 : m2statement_BuildAssignmentStatement (location, SymbolConversion_Mod2Gcc (left), m2expr_BuildIndirect (location, SymbolConversion_Mod2Gcc (right), SymbolConversion_Mod2Gcc (type)));
9741 : : }
9742 : 14499 : }
9743 : :
9744 : :
9745 : : /*
9746 : : CodeXIndr - operands for XIndrOp are: left type right.
9747 : : *left = right. The second operand is the type of the data being
9748 : : indirectly copied.
9749 : : */
9750 : :
9751 : 36300 : static void CodeXIndr (unsigned int quad)
9752 : : {
9753 : 36300 : bool constExpr;
9754 : 36300 : bool overflowChecking;
9755 : 36300 : M2Quads_QuadOperator op;
9756 : 36300 : unsigned int tokenno;
9757 : 36300 : unsigned int left;
9758 : 36300 : unsigned int type;
9759 : 36300 : unsigned int right;
9760 : 36300 : unsigned int leftpos;
9761 : 36300 : unsigned int rightpos;
9762 : 36300 : unsigned int typepos;
9763 : 36300 : unsigned int xindrpos;
9764 : 36300 : tree length;
9765 : 36300 : tree newstr;
9766 : 36300 : location_t location;
9767 : :
9768 : 36300 : M2Quads_GetQuadOtok (quad, &xindrpos, &op, &left, &type, &right, &overflowChecking, &constExpr, &leftpos, &typepos, &rightpos);
9769 : 36300 : tokenno = M2LexBuf_MakeVirtualTok (xindrpos, leftpos, rightpos);
9770 : 36300 : location = M2LexBuf_TokenToLocation (tokenno);
9771 : 36300 : type = SymbolTable_SkipType (type);
9772 : 36300 : M2GCCDeclare_DeclareConstant (rightpos, right);
9773 : 36300 : M2GCCDeclare_DeclareConstructor (rightpos, quad, right);
9774 : 36300 : if (M2Options_StrictTypeChecking && (! (M2Check_AssignmentTypeCompatible (xindrpos, (const char *) "", 0, SymbolTable_GetType (left), right, true))))
9775 : : {
9776 : 0 : M2MetaError_MetaErrorT2 (tokenno, (const char *) "assignment check caught mismatch between {%1Ead} and {%2ad}", 59, left, right);
9777 : 0 : M2Quads_SubQuad (quad);
9778 : : }
9779 : 36300 : if (SymbolTable_IsProcType (SymbolTable_SkipType (type)))
9780 : : {
9781 : 26084 : m2statement_BuildAssignmentStatement (location, m2expr_BuildIndirect (location, SymbolConversion_Mod2Gcc (left), m2type_GetPointerType ()), SymbolConversion_Mod2Gcc (right));
9782 : : }
9783 : 10216 : else if (((SymbolTable_IsConstString (right)) && ((SymbolTable_GetStringLength (rightpos, right)) == 0)) && ((SymbolTable_GetMode (left)) == SymbolTable_LeftValue))
9784 : : {
9785 : : /* avoid dangling else. */
9786 : : /*
9787 : : no need to check for type errors,
9788 : : but we handle nul string as a special case as back end
9789 : : complains if we pass through a "" and ask it to copy the
9790 : : contents.
9791 : : */
9792 : 12 : m2statement_BuildAssignmentStatement (location, m2expr_BuildIndirect (location, M2GenGCC_LValueToGenericPtr (location, left), SymbolConversion_Mod2Gcc (M2Base_Char)), M2GenGCC_StringToChar (SymbolConversion_Mod2Gcc (right), M2Base_Char, right));
9793 : : }
9794 : 10204 : else if ((SymbolTable_IsConstString (right)) && ((SymbolTable_SkipTypeAndSubrange (SymbolTable_GetType (left))) != M2Base_Char))
9795 : : {
9796 : : /* avoid dangling else. */
9797 : 42 : if (! (M2GenGCC_PrepareCopyString (tokenno, &length, &newstr, right, type)))
9798 : : {
9799 : 0 : M2MetaError_MetaErrorT2 (M2LexBuf_MakeVirtualTok (xindrpos, leftpos, rightpos), (const char *) "string constant {%1Ea} is too large to be assigned to the array {%2ad}", 70, right, left);
9800 : : }
9801 : 42 : m2type_AddStatement (location, MaybeDebugBuiltinMemcpy (location, SymbolConversion_Mod2Gcc (left), m2expr_BuildAddr (location, newstr, false), length));
9802 : : }
9803 : : else
9804 : : {
9805 : : /* avoid dangling else. */
9806 : 10162 : m2statement_BuildAssignmentStatement (location, m2expr_BuildIndirect (location, SymbolConversion_Mod2Gcc (left), SymbolConversion_Mod2Gcc (type)), ConvertRHS (SymbolConversion_Mod2Gcc (right), type, right));
9807 : : }
9808 : 36300 : }
9809 : :
9810 : :
9811 : : /*
9812 : : InitBuiltinSyms -
9813 : : */
9814 : :
9815 : 56167592 : static void InitBuiltinSyms (unsigned int tok)
9816 : : {
9817 : 56167592 : if (Memset == SymbolTable_NulSym)
9818 : : {
9819 : 14329 : Memset = SymbolTable_FromModuleGetSym (tok, NameKey_MakeKey ((const char *) "memset", 6), M2Batch_MakeDefinitionSource (tok, NameKey_MakeKey ((const char *) "Builtins", 8)));
9820 : : }
9821 : 56167592 : if (Memcpy == SymbolTable_NulSym)
9822 : : {
9823 : 14329 : Memcpy = SymbolTable_FromModuleGetSym (tok, NameKey_MakeKey ((const char *) "memcpy", 6), M2Batch_MakeDefinitionSource (tok, NameKey_MakeKey ((const char *) "Builtins", 8)));
9824 : : }
9825 : 56167592 : }
9826 : :
9827 : :
9828 : : /*
9829 : : ConvertQuadsToTree - runs through the quadruple list and converts it into
9830 : : the GCC tree structure.
9831 : : */
9832 : :
9833 : 317533 : extern "C" void M2GenGCC_ConvertQuadsToTree (unsigned int Start, unsigned int End)
9834 : : {
9835 : 3604464 : do {
9836 : 3604464 : CodeStatement (Start);
9837 : 3604452 : Start = M2Quads_GetNextQuad (Start);
9838 : 3604452 : } while (! ((Start > End) || (Start == 0)));
9839 : 317521 : }
9840 : :
9841 : :
9842 : : /*
9843 : : ResolveConstantExpressions - resolves constant expressions from the quadruple list.
9844 : : It returns TRUE if one or more constants were folded.
9845 : : When a constant symbol value is solved, the call back
9846 : : p(sym) is invoked.
9847 : : */
9848 : :
9849 : 52516275 : extern "C" bool M2GenGCC_ResolveConstantExpressions (M2GCCDeclare_WalkAction p, M2BasicBlock_BasicBlock bb)
9850 : : {
9851 : 52516275 : unsigned int tokenno;
9852 : 52516275 : unsigned int quad;
9853 : 52516275 : M2Quads_QuadOperator op;
9854 : 52516275 : unsigned int op1;
9855 : 52516275 : unsigned int op2;
9856 : 52516275 : unsigned int op3;
9857 : 52516275 : unsigned int op1pos;
9858 : 52516275 : unsigned int op2pos;
9859 : 52516275 : unsigned int op3pos;
9860 : 52516275 : bool Changed;
9861 : 52516275 : unsigned int start;
9862 : 52516275 : unsigned int end;
9863 : :
9864 : 52516275 : InitBuiltinSyms (M2LexBuf_BuiltinTokenNo);
9865 : 52516275 : start = M2BasicBlock_GetBasicBlockStart (bb);
9866 : 52516275 : end = M2BasicBlock_GetBasicBlockEnd (bb);
9867 : 52516275 : Changed = false;
9868 : 52642158 : do {
9869 : 52642158 : NoChange = true;
9870 : 52642158 : quad = start;
9871 : 159578682 : while ((quad <= end) && (quad != 0))
9872 : : {
9873 : 106936698 : tokenno = CurrentQuadToken;
9874 : 106936698 : if (tokenno == 0)
9875 : : {
9876 : 2744401 : tokenno = M2Quads_QuadToTokenNo (quad);
9877 : : }
9878 : 106936698 : if (M2Options_GetDebugTraceQuad ())
9879 : : {
9880 : 0 : M2Printf_printf0 ((const char *) "examining fold: ", 16);
9881 : 0 : M2Quads_DisplayQuad (quad);
9882 : : }
9883 : 106936698 : M2Quads_GetQuadtok (quad, &op, &op1, &op2, &op3, &op1pos, &op2pos, &op3pos);
9884 : 106936698 : switch (op)
9885 : : {
9886 : 2768 : case M2Quads_StandardFunctionOp:
9887 : 2768 : FoldStandardFunction (tokenno, p, quad, op1, op2, op3);
9888 : 2768 : break;
9889 : :
9890 : 28234 : case M2Quads_BuiltinConstOp:
9891 : 28234 : FoldBuiltinConst (tokenno, p, quad, op1, op3);
9892 : 28234 : break;
9893 : :
9894 : 360 : case M2Quads_BuiltinTypeInfoOp:
9895 : 360 : FoldBuiltinTypeInfo (tokenno, p, quad, op1, op2, op3);
9896 : 360 : break;
9897 : :
9898 : 8964 : case M2Quads_LogicalOrOp:
9899 : 8964 : FoldSetOr (tokenno, p, quad, op1, op2, op3);
9900 : 8964 : break;
9901 : :
9902 : 1904 : case M2Quads_LogicalAndOp:
9903 : 1904 : FoldSetAnd (tokenno, p, quad, op1, op2, op3);
9904 : 1904 : break;
9905 : :
9906 : 48 : case M2Quads_LogicalXorOp:
9907 : 48 : FoldSymmetricDifference (tokenno, p, quad, op1, op2, op3);
9908 : 48 : break;
9909 : :
9910 : 3605680 : case M2Quads_BecomesOp:
9911 : 3605680 : FoldBecomes (p, bb, quad);
9912 : 3605680 : break;
9913 : :
9914 : 0 : case M2Quads_ArithAddOp:
9915 : 0 : FoldArithAdd (op1pos, p, quad, op1, op2, op3);
9916 : 0 : break;
9917 : :
9918 : 327646 : case M2Quads_AddOp:
9919 : 327646 : FoldAdd (op1pos, p, quad, op1, op2, op3);
9920 : 327646 : break;
9921 : :
9922 : 122294 : case M2Quads_SubOp:
9923 : 122294 : FoldSub (op1pos, p, quad, op1, op2, op3);
9924 : 122294 : break;
9925 : :
9926 : 88836 : case M2Quads_MultOp:
9927 : 88836 : FoldMult (op1pos, p, quad, op1, op2, op3);
9928 : 88836 : break;
9929 : :
9930 : 14004 : case M2Quads_DivM2Op:
9931 : 14004 : FoldDivM2 (op1pos, p, quad, op1, op2, op3);
9932 : 14004 : break;
9933 : :
9934 : 21946 : case M2Quads_ModM2Op:
9935 : 21946 : FoldModM2 (op1pos, p, quad, op1, op2, op3);
9936 : 21946 : break;
9937 : :
9938 : 8260 : case M2Quads_DivTruncOp:
9939 : 8260 : FoldDivTrunc (op1pos, p, quad, op1, op2, op3);
9940 : 8260 : break;
9941 : :
9942 : 96 : case M2Quads_ModTruncOp:
9943 : 96 : FoldModTrunc (op1pos, p, quad, op1, op2, op3);
9944 : 96 : break;
9945 : :
9946 : 0 : case M2Quads_DivCeilOp:
9947 : 0 : FoldDivCeil (op1pos, p, quad, op1, op2, op3);
9948 : 0 : break;
9949 : :
9950 : 0 : case M2Quads_ModCeilOp:
9951 : 0 : FoldModCeil (op1pos, p, quad, op1, op2, op3);
9952 : 0 : break;
9953 : :
9954 : 0 : case M2Quads_DivFloorOp:
9955 : 0 : FoldDivFloor (op1pos, p, quad, op1, op2, op3);
9956 : 0 : break;
9957 : :
9958 : 0 : case M2Quads_ModFloorOp:
9959 : 0 : FoldModFloor (op1pos, p, quad, op1, op2, op3);
9960 : 0 : break;
9961 : :
9962 : 32658 : case M2Quads_NegateOp:
9963 : 32658 : FoldNegate (op1pos, p, quad, op1, op3);
9964 : 32658 : break;
9965 : :
9966 : 7168 : case M2Quads_SizeOp:
9967 : 7168 : FoldSize (tokenno, p, quad, op1, op2, op3);
9968 : 7168 : break;
9969 : :
9970 : : case M2Quads_RecordFieldOp:
9971 : : FoldRecordField (tokenno, p, quad, op1, op2, op3);
9972 : : break;
9973 : :
9974 : 1013697 : case M2Quads_HighOp:
9975 : 1013697 : FoldHigh (tokenno, p, quad, op1, op2, op3);
9976 : 1013697 : break;
9977 : :
9978 : 7908 : case M2Quads_ElementSizeOp:
9979 : 7908 : FoldElementSize (tokenno, p, quad, op1, op2);
9980 : 7908 : break;
9981 : :
9982 : 290818 : case M2Quads_ConvertOp:
9983 : 290818 : FoldConvert (tokenno, p, quad, op1, op2, op3);
9984 : 290818 : break;
9985 : :
9986 : 4602 : case M2Quads_CoerceOp:
9987 : 4602 : FoldCoerce (tokenno, p, quad, op1, op2, op3);
9988 : 4602 : break;
9989 : :
9990 : 1356 : case M2Quads_CastOp:
9991 : 1356 : FoldCast (tokenno, p, quad, op1, op2, op3);
9992 : 1356 : break;
9993 : :
9994 : 17358 : case M2Quads_InclOp:
9995 : 17358 : FoldIncl (tokenno, p, quad, op1, op3);
9996 : 17358 : break;
9997 : :
9998 : 10912 : case M2Quads_ExclOp:
9999 : 10912 : FoldExcl (tokenno, p, quad, op1, op3);
10000 : 10912 : break;
10001 : :
10002 : 536855 : case M2Quads_IfEquOp:
10003 : 536855 : FoldIfEqu (tokenno, quad, op1, op2, op3);
10004 : 536855 : break;
10005 : :
10006 : 260155 : case M2Quads_IfNotEquOp:
10007 : 260155 : FoldIfNotEqu (tokenno, quad, op1, op2, op3);
10008 : 260155 : break;
10009 : :
10010 : 29674 : case M2Quads_IfLessOp:
10011 : 29674 : FoldIfLess (tokenno, quad, op1, op2, op3);
10012 : 29674 : break;
10013 : :
10014 : 27550 : case M2Quads_IfLessEquOp:
10015 : 27550 : FoldIfLessEqu (tokenno, quad, op1, op2, op3);
10016 : 27550 : break;
10017 : :
10018 : 24950 : case M2Quads_IfGreOp:
10019 : 24950 : FoldIfGre (tokenno, quad, op1, op2, op3);
10020 : 24950 : break;
10021 : :
10022 : 36988 : case M2Quads_IfGreEquOp:
10023 : 36988 : FoldIfGreEqu (tokenno, quad, op1, op2, op3);
10024 : 36988 : break;
10025 : :
10026 : 24564 : case M2Quads_IfInOp:
10027 : 24564 : FoldIfIn (tokenno, quad, op1, op2, op3);
10028 : 24564 : break;
10029 : :
10030 : 5210 : case M2Quads_IfNotInOp:
10031 : 5210 : FoldIfNotIn (tokenno, quad, op1, op2, op3);
10032 : 5210 : break;
10033 : :
10034 : 19942 : case M2Quads_LogicalShiftOp:
10035 : 19942 : FoldSetShift (tokenno, p, quad, op1, op2, op3);
10036 : 19942 : break;
10037 : :
10038 : 16296 : case M2Quads_LogicalRotateOp:
10039 : 16296 : FoldSetRotate (tokenno, p, quad, op1, op2, op3);
10040 : 16296 : break;
10041 : :
10042 : 6079537 : case M2Quads_ParamOp:
10043 : 6079537 : FoldBuiltinFunction (tokenno, p, quad, op1, op2, op3);
10044 : 6079537 : break;
10045 : :
10046 : 11136235 : case M2Quads_RangeCheckOp:
10047 : 11136235 : FoldRange (tokenno, quad, op3);
10048 : 11136235 : break;
10049 : :
10050 : 6834062 : case M2Quads_StatementNoteOp:
10051 : 6834062 : FoldStatementNote (op3);
10052 : 6834062 : break;
10053 : :
10054 : 72 : case M2Quads_StringLengthOp:
10055 : 72 : FoldStringLength (quad, p);
10056 : 72 : break;
10057 : :
10058 : 31629 : case M2Quads_StringConvertM2nulOp:
10059 : 31629 : FoldStringConvertM2nul (quad, p);
10060 : 31629 : break;
10061 : :
10062 : 8001 : case M2Quads_StringConvertCnulOp:
10063 : 8001 : FoldStringConvertCnul (quad, p);
10064 : 8001 : break;
10065 : :
10066 : 12006 : case M2Quads_LastForIteratorOp:
10067 : 12006 : FoldLastForIterator (quad, p);
10068 : 12006 : break;
10069 : :
10070 : :
10071 : : default:
10072 : : break;
10073 : : }
10074 : : /* Ignore quadruple as it is not associated with a constant expression. */
10075 : 106936524 : quad = M2Quads_GetNextQuad (quad);
10076 : : }
10077 : 52641984 : if (! NoChange)
10078 : : {
10079 : 125883 : Changed = true;
10080 : : }
10081 : 52641984 : } while (! (NoChange));
10082 : 52516101 : return Changed;
10083 : : /* static analysis guarentees a RETURN statement will be used before here. */
10084 : : __builtin_unreachable ();
10085 : : }
10086 : :
10087 : :
10088 : : /*
10089 : : GetHighFromUnbounded - returns a Tree containing the value of
10090 : : param.HIGH.
10091 : : */
10092 : :
10093 : 52110 : extern "C" tree M2GenGCC_GetHighFromUnbounded (location_t location, unsigned int dim, unsigned int param)
10094 : : {
10095 : 52110 : unsigned int UnboundedType;
10096 : 52110 : unsigned int ArrayType;
10097 : 52110 : unsigned int HighField;
10098 : 52110 : tree HighTree;
10099 : 52110 : unsigned int accessibleDim;
10100 : :
10101 : : /* remainingDim : CARDINAL ; */
10102 : 52110 : UnboundedType = SymbolTable_GetType (param);
10103 : 52110 : M2Debug_Assert (SymbolTable_IsUnbounded (UnboundedType));
10104 : 52110 : ArrayType = SymbolTable_GetType (UnboundedType);
10105 : 52110 : HighField = SymbolTable_GetUnboundedHighOffset (UnboundedType, dim);
10106 : 52110 : if (HighField == SymbolTable_NulSym)
10107 : : {
10108 : : /* It might be a dynamic array of static arrays,
10109 : : so lets see if there is an earlier dimension available. */
10110 : : accessibleDim = dim;
10111 : 0 : while ((HighField == SymbolTable_NulSym) && (accessibleDim > 1))
10112 : : {
10113 : 0 : accessibleDim -= 1;
10114 : 0 : HighField = SymbolTable_GetUnboundedHighOffset (UnboundedType, accessibleDim);
10115 : : }
10116 : 0 : if (HighField == SymbolTable_NulSym)
10117 : : {
10118 : 0 : M2MetaError_MetaError1 ((const char *) "{%EkHIGH} dimension number {%1N} for array does not exist", 57, dim);
10119 : 0 : return m2expr_GetCardinalZero (location);
10120 : : }
10121 : : else
10122 : : {
10123 : 0 : HighTree = BuildHighFromStaticArray (location, ArrayType); /* remainingDim, */
10124 : 0 : if (HighTree == NULL)
10125 : : {
10126 : 0 : M2MetaError_MetaError1 ((const char *) "{%EkHIGH} dimension number {%1N} for array does not exist", 57, dim);
10127 : 0 : return m2expr_GetCardinalZero (location);
10128 : : }
10129 : : return HighTree;
10130 : : }
10131 : : }
10132 : : else
10133 : : {
10134 : 52110 : return m2expr_BuildComponentRef (location, SymbolConversion_Mod2Gcc (param), SymbolConversion_Mod2Gcc (HighField));
10135 : : }
10136 : : /* static analysis guarentees a RETURN statement will be used before here. */
10137 : : __builtin_unreachable ();
10138 : : }
10139 : :
10140 : :
10141 : : /*
10142 : : StringToChar - if type=Char and str is a string (of size <= 1)
10143 : : then convert the string into a character constant.
10144 : : */
10145 : :
10146 : 957703 : extern "C" tree M2GenGCC_StringToChar (tree t, unsigned int type, unsigned int str)
10147 : : {
10148 : 957703 : DynamicStrings_String s;
10149 : 957703 : NameKey_Name n;
10150 : 957703 : unsigned int tokenno;
10151 : 957703 : location_t location;
10152 : :
10153 : 957703 : tokenno = SymbolTable_GetDeclaredMod (str);
10154 : 957703 : location = M2LexBuf_TokenToLocation (tokenno);
10155 : 957703 : type = SymbolTable_SkipType (type);
10156 : 957703 : if ((type == M2Base_Char) && (SymbolTable_IsConstString (str)))
10157 : : {
10158 : 8286 : M2Debug_Assert (SymbolTable_IsConstStringKnown (str));
10159 : 8286 : if ((SymbolTable_GetStringLength (tokenno, str)) == 0)
10160 : : {
10161 : 108 : s = DynamicStrings_InitString ((const char *) "", 0);
10162 : 108 : t = m2type_BuildCharConstant (location, reinterpret_cast <const char * > (s));
10163 : 108 : s = DynamicStrings_KillString (s);
10164 : : }
10165 : 8178 : else if ((SymbolTable_GetStringLength (tokenno, str)) > 1)
10166 : : {
10167 : : /* avoid dangling else. */
10168 : 0 : n = SymbolTable_GetSymName (str);
10169 : 0 : M2Error_WriteFormat1 ((const char *) "type incompatibility, attempting to use a string ('%a') when a CHAR is expected", 79, (const unsigned char *) &n, (sizeof (n)-1));
10170 : 0 : s = DynamicStrings_InitString ((const char *) "", 0); /* Do something safe. */
10171 : 0 : t = m2type_BuildCharConstant (location, reinterpret_cast <const char * > (s)); /* Do something safe. */
10172 : : }
10173 : 8286 : s = DynamicStrings_InitStringCharStar (NameKey_KeyToCharStar (SymbolTable_GetString (str)));
10174 : 8286 : s = DynamicStrings_Slice (s, 0, 1);
10175 : 8286 : t = m2type_BuildCharConstant (location, const_cast <const char * > (static_cast <char * > (DynamicStrings_string (s))));
10176 : 8286 : s = DynamicStrings_KillString (s);
10177 : : }
10178 : 957703 : return t;
10179 : : /* static analysis guarentees a RETURN statement will be used before here. */
10180 : : __builtin_unreachable ();
10181 : : }
10182 : :
10183 : :
10184 : : /*
10185 : : LValueToGenericPtr - returns a Tree representing symbol, sym.
10186 : : It coerces a lvalue into an internal pointer type
10187 : : */
10188 : :
10189 : 402540 : extern "C" tree M2GenGCC_LValueToGenericPtr (location_t location, unsigned int sym)
10190 : : {
10191 : 402540 : tree t;
10192 : :
10193 : 402540 : t = SymbolConversion_Mod2Gcc (sym);
10194 : 402540 : if (t == NULL)
10195 : : {
10196 : 0 : M2Error_InternalError ((const char *) "expecting symbol to be resolved", 31);
10197 : : }
10198 : 402540 : if ((SymbolTable_GetMode (sym)) == SymbolTable_LeftValue)
10199 : : {
10200 : 624 : t = m2convert_BuildConvert (location, m2type_GetPointerType (), t, false);
10201 : : }
10202 : 402540 : return t;
10203 : : /* static analysis guarentees a RETURN statement will be used before here. */
10204 : : __builtin_unreachable ();
10205 : : }
10206 : :
10207 : :
10208 : : /*
10209 : : ZConstToTypedConst - checks whether op1 and op2 are constants and
10210 : : coerces, t, appropriately.
10211 : : */
10212 : :
10213 : 7814 : extern "C" tree M2GenGCC_ZConstToTypedConst (tree t, unsigned int op1, unsigned int op2)
10214 : : {
10215 : 7814 : location_t location;
10216 : :
10217 : 7814 : location = M2LexBuf_TokenToLocation (SymbolTable_GetDeclaredMod (op2));
10218 : 7814 : if ((SymbolTable_IsConst (op1)) && (SymbolTable_IsConst (op2)))
10219 : : {
10220 : : /* leave, Z type, alone */
10221 : : return t;
10222 : : }
10223 : 3530 : else if (SymbolTable_IsConst (op1))
10224 : : {
10225 : : /* avoid dangling else. */
10226 : 2604 : if ((SymbolTable_GetMode (op2)) == SymbolTable_LeftValue)
10227 : : {
10228 : : /* convert, Z type const into type of non constant operand */
10229 : 0 : return m2convert_BuildConvert (location, m2type_GetPointerType (), t, false);
10230 : : }
10231 : : else
10232 : : {
10233 : : /* convert, Z type const into type of non constant operand */
10234 : 2604 : return m2convert_BuildConvert (location, SymbolConversion_Mod2Gcc (FindType (op2)), t, false);
10235 : : }
10236 : : }
10237 : 926 : else if (SymbolTable_IsConst (op2))
10238 : : {
10239 : : /* avoid dangling else. */
10240 : 0 : if ((SymbolTable_GetMode (op1)) == SymbolTable_LeftValue)
10241 : : {
10242 : : /* convert, Z type const into type of non constant operand */
10243 : 0 : return m2convert_BuildConvert (location, m2type_GetPointerType (), t, false);
10244 : : }
10245 : : else
10246 : : {
10247 : : /* convert, Z type const into type of non constant operand */
10248 : 0 : return m2convert_BuildConvert (location, SymbolConversion_Mod2Gcc (FindType (op1)), t, false);
10249 : : }
10250 : : }
10251 : : else
10252 : : {
10253 : : /* avoid dangling else. */
10254 : : /* neither operands are constants, leave alone */
10255 : : return t;
10256 : : }
10257 : : /* static analysis guarentees a RETURN statement will be used before here. */
10258 : : __builtin_unreachable ();
10259 : : }
10260 : :
10261 : :
10262 : : /*
10263 : : PrepareCopyString - returns two trees:
10264 : : length number of bytes to be copied (including the nul if room)
10265 : : srcTreeType the new string type (with the extra nul character).
10266 : :
10267 : : Pre condition: destStrType the dest type string.
10268 : : src is the original string (without a nul)
10269 : : to be copied.
10270 : : Post condition: TRUE or FALSE is returned.
10271 : : if true length and srcTreeType will be assigned
10272 : : else length is set to the maximum length to be
10273 : : copied and srcTree is set to the max length
10274 : : which fits in dest.
10275 : : */
10276 : :
10277 : 3300 : extern "C" bool M2GenGCC_PrepareCopyString (unsigned int tokenno, tree *length, tree *srcTree, unsigned int src, unsigned int destStrType)
10278 : : {
10279 : 3300 : location_t location;
10280 : 3300 : int intLength;
10281 : :
10282 : 3300 : location = M2LexBuf_TokenToLocation (tokenno);
10283 : 3300 : M2Debug_Assert (SymbolTable_IsArray (SymbolTable_SkipType (destStrType)));
10284 : : /* Handle string assignments:
10285 : : VAR
10286 : : str: ARRAY [0..10] OF CHAR ;
10287 : : ch : CHAR ;
10288 : :
10289 : : str := 'abcde' but not ch := 'a'
10290 : : */
10291 : 3300 : if ((SymbolTable_GetType (src)) == M2Base_Char)
10292 : : {
10293 : : /* avoid dangling else. */
10294 : : /*
10295 : : * Create string from char and add nul to the end, nul is
10296 : : * added by BuildStringConstant. In modula-2 an array must
10297 : : * have at least one element.
10298 : : */
10299 : 192 : (*length) = m2expr_GetIntegerOne (location);
10300 : 192 : M2ALU_PushIntegerTree (FindSize (tokenno, src));
10301 : 192 : M2ALU_PushIntegerTree (FindSize (tokenno, destStrType));
10302 : 192 : if (M2ALU_Less (tokenno))
10303 : : {
10304 : : /* There is room for the extra <nul> character. */
10305 : 156 : (*length) = m2expr_BuildAdd (location, (*length), m2expr_GetIntegerOne (location), false);
10306 : : }
10307 : : }
10308 : : else
10309 : : {
10310 : 3108 : M2ALU_PushIntegerTree (FindSize (tokenno, src));
10311 : 3108 : M2ALU_PushIntegerTree (FindSize (tokenno, destStrType));
10312 : 3108 : if (M2ALU_Less (tokenno))
10313 : : {
10314 : : /* There is room for the extra <nul> character. */
10315 : 2940 : (*length) = m2expr_BuildAdd (location, FindSize (tokenno, src), m2expr_GetIntegerOne (location), false);
10316 : 2940 : (*srcTree) = SymbolConversion_Mod2Gcc (src);
10317 : : }
10318 : : else
10319 : : {
10320 : : /* We need to truncate the <nul> at least. */
10321 : 168 : (*length) = FindSize (tokenno, destStrType);
10322 : 168 : M2ALU_PushIntegerTree (FindSize (tokenno, src));
10323 : 168 : M2ALU_PushIntegerTree ((*length));
10324 : : /* Greater or Equal so return max characters in the array. */
10325 : 168 : if (M2ALU_Gre (tokenno))
10326 : : {
10327 : : /* Create a new string without non nul characters to be gimple safe.
10328 : : But return FALSE indicating an overflow. */
10329 : 12 : intLength = m2expr_GetCstInteger ((*length));
10330 : 12 : (*srcTree) = m2decl_BuildStringConstant (const_cast <const char * > (static_cast <char * > (NameKey_KeyToCharStar (SymbolTable_GetString (src)))), intLength);
10331 : 12 : (*srcTree) = m2convert_ConvertString (SymbolConversion_Mod2Gcc (destStrType), (*srcTree));
10332 : 12 : return false;
10333 : : }
10334 : : }
10335 : : }
10336 : 3288 : intLength = m2expr_GetCstInteger ((*length));
10337 : 3288 : (*srcTree) = m2decl_BuildStringConstant (const_cast <const char * > (static_cast <char * > (NameKey_KeyToCharStar (SymbolTable_GetString (src)))), intLength);
10338 : 3288 : (*srcTree) = m2convert_ConvertString (SymbolConversion_Mod2Gcc (destStrType), (*srcTree));
10339 : 3288 : return true;
10340 : : /* static analysis guarentees a RETURN statement will be used before here. */
10341 : : __builtin_unreachable ();
10342 : : }
10343 : :
10344 : 15260 : extern "C" void _M2_M2GenGCC_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[])
10345 : : {
10346 : 15260 : Memset = SymbolTable_NulSym;
10347 : 15260 : Memcpy = SymbolTable_NulSym;
10348 : 15260 : UnboundedLabelNo = 0;
10349 : 15260 : CurrentQuadToken = 0;
10350 : 15260 : ScopeStack = M2StackWord_InitStackWord ();
10351 : 15260 : }
10352 : :
10353 : 0 : extern "C" void _M2_M2GenGCC_fini (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[])
10354 : : {
10355 : 0 : }
|