| 1 |
(* M2Quads.mod generates quadruples. |
| 2 |
|
| 3 |
Copyright (C) 2001-2025 Free Software Foundation, Inc. |
| 4 |
Contributed by Gaius Mulley <[email protected]>. |
| 5 |
|
| 6 |
This file is part of GNU Modula-2. |
| 7 |
|
| 8 |
GNU Modula-2 is free software; you can redistribute it and/or modify |
| 9 |
it under the terms of the GNU General Public License as published by |
| 10 |
the Free Software Foundation; either version 3, or (at your option) |
| 11 |
any later version. |
| 12 |
|
| 13 |
GNU Modula-2 is distributed in the hope that it will be useful, but |
| 14 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 |
General Public License for more details. |
| 17 |
|
| 18 |
You should have received a copy of the GNU General Public License |
| 19 |
along with GNU Modula-2; see the file COPYING3. If not see |
| 20 |
<http://www.gnu.org/licenses/>. *) |
| 21 |
|
| 22 |
IMPLEMENTATION MODULE M2Quads ; |
| 23 |
|
| 24 |
|
| 25 |
FROM Storage IMPORT ALLOCATE, DEALLOCATE ; |
| 26 |
FROM M2Debug IMPORT Assert, WriteDebug ; |
| 27 |
FROM NameKey IMPORT Name, NulName, MakeKey, GetKey, makekey, KeyToCharStar, WriteKey ; |
| 28 |
FROM FormatStrings IMPORT Sprintf0, Sprintf1, Sprintf2, Sprintf3 ; |
| 29 |
FROM M2DebugStack IMPORT DebugStack ; |
| 30 |
FROM StrLib IMPORT StrLen ; |
| 31 |
FROM M2Scaffold IMPORT DeclareScaffold, mainFunction, initFunction, |
| 32 |
finiFunction, linkFunction, PopulateCtorArray, |
| 33 |
ForeachModuleCallInit, ForeachModuleCallFinish ; |
| 34 |
|
| 35 |
FROM M2MetaError IMPORT MetaError0, MetaError1, MetaError2, MetaError3, |
| 36 |
MetaErrors1, MetaErrors2, MetaErrors3, |
| 37 |
MetaErrorT0, MetaErrorT1, MetaErrorT2, |
| 38 |
MetaErrorsT1, MetaErrorsT2, MetaErrorT3, |
| 39 |
MetaErrorStringT0, MetaErrorStringT1, |
| 40 |
MetaErrorStringT2, |
| 41 |
MetaErrorString1, MetaErrorString2, |
| 42 |
MetaErrorN1, MetaErrorN2, |
| 43 |
MetaErrorNT0, MetaErrorNT1, MetaErrorNT2, |
| 44 |
MetaErrorDecl ; |
| 45 |
|
| 46 |
FROM DynamicStrings IMPORT String, string, InitString, KillString, |
| 47 |
ConCat, InitStringCharStar, Dup, Mark, |
| 48 |
PushAllocation, PopAllocationExemption, |
| 49 |
InitStringDB, InitStringCharStarDB, |
| 50 |
InitStringCharDB, MultDB, DupDB, SliceDB ; |
| 51 |
|
| 52 |
FROM SymbolTable IMPORT ModeOfAddr, GetMode, PutMode, GetSymName, IsUnknown, |
| 53 |
MakeTemporary, ProcedureKind, |
| 54 |
MakeTemporaryFromExpression, |
| 55 |
MakeTemporaryFromExpressions, |
| 56 |
MakeConstLit, |
| 57 |
MakeConstString, MakeConstant, MakeConstVar, |
| 58 |
MakeConstStringM2nul, MakeConstStringCnul, |
| 59 |
Make2Tuple, IsTuple, |
| 60 |
RequestSym, MakePointer, PutPointer, |
| 61 |
SkipType, |
| 62 |
GetDType, GetSType, GetLType, |
| 63 |
GetScope, GetCurrentScope, |
| 64 |
GetSubrange, SkipTypeAndSubrange, |
| 65 |
GetModule, GetMainModule, |
| 66 |
GetModuleScope, GetCurrentModuleScope, |
| 67 |
GetCurrentModule, GetFileModule, GetLocalSym, |
| 68 |
GetStringLength, GetString, |
| 69 |
GetArraySubscript, GetDimension, |
| 70 |
GetParam, |
| 71 |
GetNth, GetNthParamAny, |
| 72 |
GetNthParamAnyClosest, |
| 73 |
GetFirstUsed, GetDeclaredMod, |
| 74 |
GetQuads, GetReadQuads, GetWriteQuads, |
| 75 |
GetWriteLimitQuads, GetReadLimitQuads, |
| 76 |
GetVarScope, |
| 77 |
GetModuleQuads, GetProcedureQuads, |
| 78 |
GetModuleCtors, |
| 79 |
MakeProcedure, |
| 80 |
PutConstStringKnown, |
| 81 |
PutModuleStartQuad, PutModuleEndQuad, |
| 82 |
PutModuleFinallyStartQuad, PutModuleFinallyEndQuad, |
| 83 |
PutProcedureStartQuad, PutProcedureEndQuad, |
| 84 |
PutProcedureScopeQuad, |
| 85 |
PutVar, PutConstSet, |
| 86 |
GetVarPointerCheck, PutVarPointerCheck, |
| 87 |
PutVarWritten, |
| 88 |
PutReadQuad, RemoveReadQuad, |
| 89 |
PutWriteQuad, RemoveWriteQuad, |
| 90 |
PutPriority, GetPriority, |
| 91 |
PutProcedureBegin, PutProcedureEnd, |
| 92 |
PutVarConst, IsVarConst, |
| 93 |
PutConstLitInternal, |
| 94 |
PutVarHeap, |
| 95 |
IsVarParamAny, IsProcedure, IsPointer, IsParameter, |
| 96 |
IsUnboundedParamAny, IsEnumeration, IsDefinitionForC, |
| 97 |
IsVarAParam, IsVarient, IsLegal, |
| 98 |
UsesVarArgs, UsesOptArgAny, |
| 99 |
GetOptArgInit, |
| 100 |
IsReturnOptionalAny, |
| 101 |
NoOfElements, |
| 102 |
NoOfParamAny, |
| 103 |
StartScope, EndScope, |
| 104 |
IsGnuAsm, IsGnuAsmVolatile, |
| 105 |
MakeRegInterface, PutRegInterface, |
| 106 |
HasExceptionBlock, PutExceptionBlock, |
| 107 |
HasExceptionFinally, PutExceptionFinally, |
| 108 |
GetParent, GetRecord, IsRecordField, IsFieldVarient, IsRecord, |
| 109 |
IsFieldEnumeration, |
| 110 |
IsVar, IsProcType, IsType, IsSubrange, IsExported, |
| 111 |
IsConst, IsConstString, IsModule, IsDefImp, |
| 112 |
IsArray, IsUnbounded, IsProcedureNested, |
| 113 |
IsParameterUnbounded, |
| 114 |
IsPartialUnbounded, IsProcedureBuiltin, |
| 115 |
IsSet, IsConstSet, IsConstructor, PutConst, |
| 116 |
PutConstructor, PutConstructorFrom, |
| 117 |
PutDeclared, |
| 118 |
MakeComponentRecord, MakeComponentRef, |
| 119 |
IsSubscript, IsComponent, IsConstStringKnown, |
| 120 |
IsTemporary, IsHiddenType, |
| 121 |
IsAModula2Type, |
| 122 |
PutLeftValueFrontBackType, |
| 123 |
PushSize, PushValue, PopValue, |
| 124 |
GetVariableAtAddress, IsVariableAtAddress, |
| 125 |
MakeError, UnknownReported, |
| 126 |
IsProcedureBuiltinAvailable, |
| 127 |
IsError, |
| 128 |
IsInnerModule, |
| 129 |
IsImportStatement, IsImport, GetImportModule, GetImportDeclared, |
| 130 |
GetImportStatementList, |
| 131 |
GetModuleDefImportStatementList, GetModuleModImportStatementList, |
| 132 |
IsCtor, IsPublic, IsExtern, IsMonoName, |
| 133 |
|
| 134 |
GetUnboundedRecordType, |
| 135 |
GetUnboundedAddressOffset, |
| 136 |
GetUnboundedHighOffset, |
| 137 |
PutVarArrayRef, |
| 138 |
PutProcedureDefined, |
| 139 |
PutProcedureParametersDefined, |
| 140 |
GetVarDeclFullTok, |
| 141 |
|
| 142 |
ForeachFieldEnumerationDo, ForeachLocalSymDo, |
| 143 |
GetExported, PutImported, GetSym, GetLibName, |
| 144 |
GetTypeMode, |
| 145 |
IsVarConditional, PutVarConditional, |
| 146 |
IsUnused, |
| 147 |
NulSym ; |
| 148 |
|
| 149 |
FROM M2Batch IMPORT MakeDefinitionSource ; |
| 150 |
FROM M2GCCDeclare IMPORT PutToBeSolvedByQuads ; |
| 151 |
|
| 152 |
FROM FifoQueue IMPORT GetConstFromFifoQueue, |
| 153 |
PutConstructorIntoFifoQueue, GetConstructorFromFifoQueue ; |
| 154 |
|
| 155 |
FROM M2Comp IMPORT CompilingImplementationModule, |
| 156 |
CompilingProgramModule ; |
| 157 |
|
| 158 |
FROM M2LexBuf IMPORT currenttoken, UnknownTokenNo, BuiltinTokenNo, |
| 159 |
GetToken, MakeVirtualTok, MakeVirtual2Tok, |
| 160 |
GetFileName, TokenToLineNo, GetTokenName, |
| 161 |
GetTokenNo, GetLineNo, GetPreviousTokenLineNo, PrintTokenNo ; |
| 162 |
|
| 163 |
FROM M2Error IMPORT Error, |
| 164 |
InternalError, |
| 165 |
WriteFormat0, WriteFormat1, WriteFormat2, WriteFormat3, |
| 166 |
NewError, NewWarning, ErrorFormat0, ErrorFormat1, |
| 167 |
ErrorFormat2, ErrorFormat3, FlushErrors, ChainError, |
| 168 |
ErrorString, |
| 169 |
ErrorStringAt, ErrorStringAt2, ErrorStringsAt2, |
| 170 |
WarnStringAt, WarnStringAt2, WarnStringsAt2 ; |
| 171 |
|
| 172 |
FROM M2Printf IMPORT fprintf0, fprintf1, fprintf2, fprintf3, fprintf4, |
| 173 |
printf0, printf1, printf2, printf3, printf4 ; |
| 174 |
|
| 175 |
FROM M2Reserved IMPORT PlusTok, MinusTok, TimesTok, DivTok, ModTok, |
| 176 |
DivideTok, RemTok, |
| 177 |
OrTok, AndTok, AmbersandTok, |
| 178 |
EqualTok, LessEqualTok, GreaterEqualTok, |
| 179 |
LessTok, GreaterTok, HashTok, LessGreaterTok, |
| 180 |
InTok, |
| 181 |
UpArrowTok, RParaTok, LParaTok, CommaTok, |
| 182 |
NulTok, ByTok, |
| 183 |
SemiColonTok, toktype ; |
| 184 |
|
| 185 |
FROM M2Base IMPORT True, False, Boolean, Cardinal, Integer, Char, |
| 186 |
Real, LongReal, ShortReal, Nil, |
| 187 |
ZType, RType, CType, |
| 188 |
Re, Im, Cmplx, |
| 189 |
NegateType, ComplexToScalar, GetCmplxReturnType, |
| 190 |
IsAssignmentCompatible, IsExpressionCompatible, |
| 191 |
AssignmentRequiresWarning, |
| 192 |
CannotCheckTypeInPass3, ScalarToComplex, MixTypes, |
| 193 |
CheckAssignmentCompatible, CheckExpressionCompatible, |
| 194 |
High, LengthS, New, Dispose, Inc, Dec, Incl, Excl, |
| 195 |
Cap, Abs, Odd, |
| 196 |
IsOrd, Chr, Convert, Val, IsFloat, IsTrunc, |
| 197 |
IsInt, Min, Max, |
| 198 |
IsPseudoBaseProcedure, IsPseudoBaseFunction, |
| 199 |
IsMathType, IsOrdinalType, IsRealType, |
| 200 |
IsBaseType, GetBaseTypeMinMax, ActivationPointer ; |
| 201 |
|
| 202 |
FROM M2System IMPORT IsPseudoSystemFunction, IsPseudoSystemProcedure, |
| 203 |
IsSystemType, GetSystemTypeMinMax, |
| 204 |
IsPseudoSystemFunctionConstExpression, |
| 205 |
IsGenericSystemType, |
| 206 |
Adr, TSize, TBitSize, AddAdr, SubAdr, DifAdr, Cast, |
| 207 |
Shift, Rotate, MakeAdr, Address, Byte, Word, Loc, Throw ; |
| 208 |
|
| 209 |
FROM M2Size IMPORT Size ; |
| 210 |
FROM M2Bitset IMPORT Bitset ; |
| 211 |
|
| 212 |
FROM M2ALU IMPORT PushInt, Gre, Less, PushNulSet, AddBitRange, AddBit, |
| 213 |
IsGenericNulSet, IsValueAndTreeKnown, AddField, |
| 214 |
AddElements, ChangeToConstructor ; |
| 215 |
|
| 216 |
FROM Lists IMPORT List, InitList, GetItemFromList, NoOfItemsInList, PutItemIntoList, |
| 217 |
IsItemInList, KillList, IncludeItemIntoList ; |
| 218 |
|
| 219 |
FROM M2Options IMPORT NilChecking, |
| 220 |
WholeDivChecking, WholeValueChecking, |
| 221 |
IndexChecking, RangeChecking, |
| 222 |
CaseElseChecking, ReturnChecking, |
| 223 |
UnusedVariableChecking, UnusedParameterChecking, |
| 224 |
Iso, Pim, Pim2, Pim3, Pim4, PositiveModFloorDiv, |
| 225 |
Pedantic, CompilerDebugging, GenerateDebugging, |
| 226 |
GenerateLineDebug, Exceptions, |
| 227 |
Profiling, Coding, Optimizing, |
| 228 |
UninitVariableChecking, |
| 229 |
StrictTypeAssignment, |
| 230 |
ScaffoldDynamic, ScaffoldStatic, cflag, |
| 231 |
ScaffoldMain, SharedFlag, WholeProgram, |
| 232 |
GetDumpDir, GetM2DumpFilter, |
| 233 |
GetRuntimeModuleOverride, GetDebugTraceQuad, |
| 234 |
GetDumpQuad ; |
| 235 |
|
| 236 |
FROM M2LangDump IMPORT CreateDumpQuad, CloseDumpQuad, GetDumpFile ; |
| 237 |
FROM M2Pass IMPORT IsPassCodeGeneration, IsNoPass ; |
| 238 |
|
| 239 |
FROM M2StackAddress IMPORT StackOfAddress, InitStackAddress, KillStackAddress, |
| 240 |
PushAddress, PopAddress, PeepAddress, |
| 241 |
IsEmptyAddress, NoOfItemsInStackAddress ; |
| 242 |
|
| 243 |
FROM M2StackWord IMPORT StackOfWord, InitStackWord, KillStackWord, |
| 244 |
PushWord, PopWord, PeepWord, RemoveTop, |
| 245 |
IsEmptyWord, NoOfItemsInStackWord ; |
| 246 |
|
| 247 |
FROM Indexing IMPORT Index, InitIndex, GetIndice, PutIndice, InBounds, HighIndice, |
| 248 |
IncludeIndiceIntoIndex, InitIndexTuned ; |
| 249 |
|
| 250 |
FROM M2Range IMPORT InitAssignmentRangeCheck, |
| 251 |
InitReturnRangeCheck, |
| 252 |
InitSubrangeRangeCheck, |
| 253 |
InitStaticArraySubscriptRangeCheck, |
| 254 |
InitDynamicArraySubscriptRangeCheck, |
| 255 |
InitIncRangeCheck, |
| 256 |
InitDecRangeCheck, |
| 257 |
InitInclCheck, |
| 258 |
InitExclCheck, |
| 259 |
InitRotateCheck, |
| 260 |
InitShiftCheck, |
| 261 |
InitTypesAssignmentCheck, |
| 262 |
InitTypesIndrXCheck, |
| 263 |
InitTypesExpressionCheck, |
| 264 |
InitTypesParameterCheck, |
| 265 |
InitTypesReturnTypeCheck, |
| 266 |
InitForLoopBeginRangeCheck, |
| 267 |
InitForLoopToRangeCheck, |
| 268 |
InitForLoopEndRangeCheck, |
| 269 |
InitPointerRangeCheck, |
| 270 |
InitNoReturnRangeCheck, |
| 271 |
InitNoElseRangeCheck, |
| 272 |
InitCaseBounds, |
| 273 |
InitWholeZeroDivisionCheck, |
| 274 |
InitWholeZeroRemainderCheck, |
| 275 |
InitParameterRangeCheck, |
| 276 |
PutRangeForIncrement, |
| 277 |
WriteRangeCheck ; |
| 278 |
|
| 279 |
FROM M2CaseList IMPORT PushCase, PopCase, AddRange, BeginCaseList, EndCaseList, ElseCase ; |
| 280 |
FROM PCSymBuild IMPORT SkipConst ; |
| 281 |
FROM m2builtins IMPORT GetBuiltinTypeInfoType ; |
| 282 |
FROM M2LangDump IMPORT IsDumpRequired ; |
| 283 |
|
| 284 |
IMPORT M2Error, FIO, SFIO, DynamicStrings, StdIO ; |
| 285 |
|
| 286 |
|
| 287 |
CONST |
| 288 |
DebugStackOn = TRUE ; |
| 289 |
DebugVarients = FALSE ; |
| 290 |
DebugTokPos = FALSE ; |
| 291 |
|
| 292 |
TYPE |
| 293 |
ConstructorFrame = POINTER TO RECORD |
| 294 |
type : CARDINAL ; |
| 295 |
index: CARDINAL ; |
| 296 |
END ; |
| 297 |
|
| 298 |
BoolFrame = POINTER TO RECORD |
| 299 |
TrueExit : CARDINAL ; |
| 300 |
FalseExit : CARDINAL ; |
| 301 |
Unbounded : CARDINAL ; |
| 302 |
BooleanOp : BOOLEAN ; |
| 303 |
Dimension : CARDINAL ; |
| 304 |
ReadWrite : CARDINAL ; |
| 305 |
name : CARDINAL ; |
| 306 |
RangeDep : CARDINAL ; |
| 307 |
Annotation: String ; |
| 308 |
tokenno : CARDINAL ; |
| 309 |
END ; |
| 310 |
|
| 311 |
QuadFrame = POINTER TO RECORD |
| 312 |
Operator : QuadOperator ; |
| 313 |
Operand1 : CARDINAL ; |
| 314 |
Operand2 : CARDINAL ; |
| 315 |
Operand3 : CARDINAL ; |
| 316 |
Trash : CARDINAL ; |
| 317 |
Next : CARDINAL ; (* Next quadruple. *) |
| 318 |
LineNo : CARDINAL ; (* Line No of source text. *) |
| 319 |
TokenNo : CARDINAL ; (* Token No of source text. *) |
| 320 |
NoOfTimesReferenced: CARDINAL ; (* No of times quad is referenced. *) |
| 321 |
ConstExpr, (* Must backend resolve this at *) |
| 322 |
(* compile time? *) |
| 323 |
CheckType, |
| 324 |
CheckOverflow : BOOLEAN ; (* should backend check overflow *) |
| 325 |
op1pos, |
| 326 |
op2pos, |
| 327 |
op3pos : CARDINAL ; (* Token position of operands. *) |
| 328 |
END ; |
| 329 |
|
| 330 |
WithFrame = POINTER TO RECORD |
| 331 |
RecordSym : CARDINAL ; |
| 332 |
RecordType : CARDINAL ; |
| 333 |
RecordRef : CARDINAL ; |
| 334 |
rw : CARDINAL ; (* The record variable. *) |
| 335 |
RecordTokPos: CARDINAL ; (* Token of the record. *) |
| 336 |
END ; |
| 337 |
|
| 338 |
ForLoopInfo = POINTER TO RECORD |
| 339 |
IncrementQuad, |
| 340 |
StartOfForLoop, (* We keep a list of all for *) |
| 341 |
EndOfForLoop, (* loops so we can check index. *) |
| 342 |
ForLoopIndex, |
| 343 |
IndexTok : CARDINAL ; (* Used to ensure iterators are not *) |
| 344 |
(* user modified. *) |
| 345 |
END ; |
| 346 |
|
| 347 |
LineNote = POINTER TO RECORD |
| 348 |
Line: CARDINAL ; |
| 349 |
File: Name ; |
| 350 |
Next: LineNote ; |
| 351 |
END ; |
| 352 |
VAR |
| 353 |
ConstructorStack, |
| 354 |
LineStack, |
| 355 |
BoolStack, |
| 356 |
WithStack : StackOfAddress ; |
| 357 |
TryStack, |
| 358 |
CatchStack, |
| 359 |
ExceptStack, |
| 360 |
ConstExprStack, |
| 361 |
ConstParamStack, |
| 362 |
AutoStack, |
| 363 |
RepeatStack, |
| 364 |
WhileStack, |
| 365 |
ForStack, |
| 366 |
ExitStack, |
| 367 |
ReturnStack : StackOfWord ; (* Return quadruple of the procedure. *) |
| 368 |
PriorityStack : StackOfWord ; (* Temporary variable holding old *) |
| 369 |
(* priority. *) |
| 370 |
SuppressWith : BOOLEAN ; |
| 371 |
QuadArray : Index ; |
| 372 |
NextQuad : CARDINAL ; (* Next quadruple number to be created. *) |
| 373 |
FreeList : CARDINAL ; (* FreeList of quadruples. *) |
| 374 |
CurrentProc : CARDINAL ; (* Current procedure being compiled, used *) |
| 375 |
(* to determine which procedure a RETURN. *) |
| 376 |
(* ReturnValueOp must have as its 3rd op. *) |
| 377 |
InitQuad : CARDINAL ; (* Initial Quad BackPatch that starts the *) |
| 378 |
(* suit of Modules. *) |
| 379 |
LastQuadNo : CARDINAL ; (* Last Quadruple accessed by GetQuad. *) |
| 380 |
ArithPlusTok, (* Internal + token for arithmetic only. *) |
| 381 |
LogicalOrTok, (* Internal _LOR token. *) |
| 382 |
LogicalAndTok, (* Internal _LAND token. *) |
| 383 |
LogicalXorTok, (* Internal _LXOR token. *) |
| 384 |
LogicalDifferenceTok : Name ; (* Internal _LDIFF token. *) |
| 385 |
InConstExpression, |
| 386 |
InConstParameters, |
| 387 |
IsAutoOn, (* Should parser automatically push *) |
| 388 |
(* idents? *) |
| 389 |
MustNotCheckBounds : BOOLEAN ; |
| 390 |
ForInfo : Index ; (* Start and end of all FOR loops. *) |
| 391 |
GrowInitialization : CARDINAL ; (* Upper limit of where the initialized *) |
| 392 |
(* quadruples. *) |
| 393 |
BuildingHigh, |
| 394 |
BuildingSize, |
| 395 |
QuadrupleGeneration : BOOLEAN ; (* Should we be generating quadruples? *) |
| 396 |
FreeLineList : LineNote ; (* Free list of line notes. *) |
| 397 |
VarientFields : List ; (* The list of all varient fields created. *) |
| 398 |
VarientFieldNo : CARDINAL ; (* Used to retrieve the VarientFields *) |
| 399 |
(* in order. *) |
| 400 |
NoOfQuads : CARDINAL ; (* Number of used quadruples. *) |
| 401 |
Head : CARDINAL ; (* Head of the list of quadruples. *) |
| 402 |
BreakQuad : CARDINAL ; (* Stop when BreakQuad is created. *) |
| 403 |
|
| 404 |
|
| 405 |
(* |
| 406 |
Rules for file and initialization quadruples: |
| 407 |
|
| 408 |
StartModFileOp - indicates that this file (module) has produced the |
| 409 |
following code |
| 410 |
StartDefFileOp - indicates that this definition module has produced |
| 411 |
this code. |
| 412 |
EndFileOp - indicates that a module has finished |
| 413 |
InitStartOp - the start of the initialization code of a module |
| 414 |
InitEndOp - the end of the above |
| 415 |
FinallyStartOp - the start of the finalization code of a module |
| 416 |
FinallyEndOp - the end of the above |
| 417 |
*) |
| 418 |
|
| 419 |
|
| 420 |
(* |
| 421 |
#define InitString(X) InitStringDB(X, __FILE__, __LINE__) |
| 422 |
#define InitStringCharStar(X) InitStringCharStarDB(X, __FILE__, __LINE__) |
| 423 |
#define InitStringChar(X) InitStringCharDB(X, __FILE__, __LINE__) |
| 424 |
#define Mult(X,Y) MultDB(X, Y, __FILE__, __LINE__) |
| 425 |
#define Dup(X) DupDB(X, __FILE__, __LINE__) |
| 426 |
#define Slice(X,Y,Z) SliceDB(X, Y, Z, __FILE__, __LINE__) |
| 427 |
*) |
| 428 |
|
| 429 |
|
| 430 |
(* |
| 431 |
doDSdbEnter - |
| 432 |
*) |
| 433 |
|
| 434 |
(* |
| 435 |
PROCEDURE doDSdbEnter ; |
| 436 |
BEGIN |
| 437 |
PushAllocation |
| 438 |
END doDSdbEnter ; |
| 439 |
*) |
| 440 |
|
| 441 |
(* |
| 442 |
doDSdbExit - |
| 443 |
*) |
| 444 |
|
| 445 |
(* |
| 446 |
PROCEDURE doDSdbExit (s: String) ; |
| 447 |
BEGIN |
| 448 |
s := PopAllocationExemption(TRUE, s) |
| 449 |
END doDSdbExit ; |
| 450 |
*) |
| 451 |
|
| 452 |
(* |
| 453 |
DSdbEnter - |
| 454 |
*) |
| 455 |
|
| 456 |
PROCEDURE DSdbEnter ; |
| 457 |
BEGIN |
| 458 |
END DSdbEnter ; |
| 459 |
|
| 460 |
|
| 461 |
(* |
| 462 |
DSdbExit - |
| 463 |
*) |
| 464 |
|
| 465 |
PROCEDURE DSdbExit ; |
| 466 |
BEGIN |
| 467 |
END DSdbExit ; |
| 468 |
|
| 469 |
|
| 470 |
(* |
| 471 |
#define DBsbEnter doDBsbEnter |
| 472 |
#define DBsbExit doDBsbExit |
| 473 |
*) |
| 474 |
|
| 475 |
|
| 476 |
(* |
| 477 |
SetOptionProfiling - builds a profile quadruple if the profiling |
| 478 |
option was given to the compiler. |
| 479 |
*) |
| 480 |
|
| 481 |
PROCEDURE SetOptionProfiling (b: BOOLEAN) ; |
| 482 |
BEGIN |
| 483 |
IF b#Profiling |
| 484 |
THEN |
| 485 |
IF b |
| 486 |
THEN |
| 487 |
BuildProfileOn |
| 488 |
ELSE |
| 489 |
BuildProfileOff |
| 490 |
END ; |
| 491 |
Profiling := b |
| 492 |
END |
| 493 |
END SetOptionProfiling ; |
| 494 |
|
| 495 |
|
| 496 |
(* |
| 497 |
SetOptionCoding - builds a code quadruple if the profiling |
| 498 |
option was given to the compiler. |
| 499 |
*) |
| 500 |
|
| 501 |
PROCEDURE SetOptionCoding (b: BOOLEAN) ; |
| 502 |
BEGIN |
| 503 |
IF b#Coding |
| 504 |
THEN |
| 505 |
IF b |
| 506 |
THEN |
| 507 |
BuildCodeOn |
| 508 |
ELSE |
| 509 |
BuildCodeOff |
| 510 |
END ; |
| 511 |
Coding := b |
| 512 |
END |
| 513 |
END SetOptionCoding ; |
| 514 |
|
| 515 |
|
| 516 |
(* |
| 517 |
SetOptionOptimizing - builds a quadruple to say that the optimization option |
| 518 |
has been found in a comment. |
| 519 |
*) |
| 520 |
|
| 521 |
PROCEDURE SetOptionOptimizing (b: BOOLEAN) ; |
| 522 |
BEGIN |
| 523 |
IF b |
| 524 |
THEN |
| 525 |
BuildOptimizeOn |
| 526 |
ELSE |
| 527 |
BuildOptimizeOff |
| 528 |
END |
| 529 |
END SetOptionOptimizing ; |
| 530 |
|
| 531 |
|
| 532 |
(* |
| 533 |
GetQF - returns the QuadFrame associated with, q. |
| 534 |
*) |
| 535 |
|
| 536 |
PROCEDURE GetQF (q: CARDINAL) : QuadFrame ; |
| 537 |
BEGIN |
| 538 |
RETURN QuadFrame (GetIndice (QuadArray, q)) |
| 539 |
END GetQF ; |
| 540 |
|
| 541 |
|
| 542 |
(* |
| 543 |
Opposite - returns the opposite comparison operator. |
| 544 |
*) |
| 545 |
|
| 546 |
PROCEDURE Opposite (Operator: QuadOperator) : QuadOperator ; |
| 547 |
VAR |
| 548 |
Op: QuadOperator ; |
| 549 |
BEGIN |
| 550 |
CASE Operator OF |
| 551 |
|
| 552 |
IfNotEquOp : Op := IfEquOp | |
| 553 |
IfEquOp : Op := IfNotEquOp | |
| 554 |
IfLessEquOp: Op := IfGreOp | |
| 555 |
IfGreOp : Op := IfLessEquOp | |
| 556 |
IfGreEquOp : Op := IfLessOp | |
| 557 |
IfLessOp : Op := IfGreEquOp | |
| 558 |
IfInOp : Op := IfNotInOp | |
| 559 |
IfNotInOp : Op := IfInOp |
| 560 |
|
| 561 |
ELSE |
| 562 |
InternalError ('unexpected operator') |
| 563 |
END ; |
| 564 |
RETURN Op |
| 565 |
END Opposite ; |
| 566 |
|
| 567 |
|
| 568 |
(* |
| 569 |
IsReferenced - returns true if QuadNo is referenced by another quadruple. |
| 570 |
*) |
| 571 |
|
| 572 |
PROCEDURE IsReferenced (QuadNo: CARDINAL) : BOOLEAN ; |
| 573 |
VAR |
| 574 |
f: QuadFrame ; |
| 575 |
BEGIN |
| 576 |
f := GetQF(QuadNo) ; |
| 577 |
WITH f^ DO |
| 578 |
RETURN( (Operator=ProcedureScopeOp) OR (Operator=NewLocalVarOp) OR |
| 579 |
(NoOfTimesReferenced>0) ) |
| 580 |
END |
| 581 |
END IsReferenced ; |
| 582 |
|
| 583 |
|
| 584 |
(* |
| 585 |
IsBackReference - returns TRUE if quadruple, q, is referenced from a quad further on. |
| 586 |
*) |
| 587 |
|
| 588 |
PROCEDURE IsBackReference (q: CARDINAL) : BOOLEAN ; |
| 589 |
VAR |
| 590 |
i : CARDINAL ; |
| 591 |
op : QuadOperator ; |
| 592 |
op1, op2, op3: CARDINAL ; |
| 593 |
BEGIN |
| 594 |
i := q ; |
| 595 |
WHILE i#0 DO |
| 596 |
GetQuad (i, op, op1, op2, op3) ; |
| 597 |
CASE op OF |
| 598 |
|
| 599 |
NewLocalVarOp, |
| 600 |
KillLocalVarOp, |
| 601 |
FinallyStartOp, |
| 602 |
FinallyEndOp, |
| 603 |
InitEndOp, |
| 604 |
InitStartOp, |
| 605 |
EndFileOp, |
| 606 |
StartDefFileOp, |
| 607 |
StartModFileOp: RETURN( FALSE ) | (* run into end of procedure or module *) |
| 608 |
|
| 609 |
GotoOp, |
| 610 |
IfEquOp, |
| 611 |
IfLessEquOp, |
| 612 |
IfGreEquOp, |
| 613 |
IfGreOp, |
| 614 |
IfLessOp, |
| 615 |
IfNotEquOp, |
| 616 |
IfInOp, |
| 617 |
IfNotInOp : IF op3=q |
| 618 |
THEN |
| 619 |
RETURN( TRUE ) |
| 620 |
END |
| 621 |
|
| 622 |
ELSE |
| 623 |
END ; |
| 624 |
i := GetNextQuad (i) |
| 625 |
END ; |
| 626 |
InternalError ('fix this for the sake of efficiency..') |
| 627 |
END IsBackReference ; |
| 628 |
|
| 629 |
|
| 630 |
(* |
| 631 |
IsUnConditional - returns true if QuadNo is an unconditional jump. |
| 632 |
*) |
| 633 |
|
| 634 |
PROCEDURE IsUnConditional (QuadNo: CARDINAL) : BOOLEAN ; |
| 635 |
VAR |
| 636 |
f: QuadFrame ; |
| 637 |
BEGIN |
| 638 |
f := GetQF(QuadNo) ; |
| 639 |
WITH f^ DO |
| 640 |
CASE Operator OF |
| 641 |
|
| 642 |
ThrowOp, |
| 643 |
RetryOp, |
| 644 |
CallOp, |
| 645 |
ReturnOp, |
| 646 |
GotoOp : RETURN( TRUE ) |
| 647 |
|
| 648 |
ELSE |
| 649 |
RETURN( FALSE ) |
| 650 |
END |
| 651 |
END |
| 652 |
END IsUnConditional ; |
| 653 |
|
| 654 |
|
| 655 |
(* |
| 656 |
IsConditional - returns true if QuadNo is a conditional jump. |
| 657 |
*) |
| 658 |
|
| 659 |
PROCEDURE IsConditional (QuadNo: CARDINAL) : BOOLEAN ; |
| 660 |
VAR |
| 661 |
f: QuadFrame ; |
| 662 |
BEGIN |
| 663 |
f := GetQF(QuadNo) ; |
| 664 |
WITH f^ DO |
| 665 |
CASE Operator OF |
| 666 |
|
| 667 |
IfInOp, |
| 668 |
IfNotInOp, |
| 669 |
IfEquOp, |
| 670 |
IfNotEquOp, |
| 671 |
IfLessOp, |
| 672 |
IfLessEquOp, |
| 673 |
IfGreOp, |
| 674 |
IfGreEquOp : RETURN( TRUE ) |
| 675 |
|
| 676 |
ELSE |
| 677 |
RETURN( FALSE ) |
| 678 |
END ; |
| 679 |
END |
| 680 |
END IsConditional ; |
| 681 |
|
| 682 |
|
| 683 |
(* |
| 684 |
IsBackReferenceConditional - returns TRUE if quadruple, q, is referenced from |
| 685 |
a conditional quad further on. |
| 686 |
*) |
| 687 |
|
| 688 |
PROCEDURE IsBackReferenceConditional (q: CARDINAL) : BOOLEAN ; |
| 689 |
VAR |
| 690 |
i : CARDINAL ; |
| 691 |
op : QuadOperator ; |
| 692 |
op1, op2, op3: CARDINAL ; |
| 693 |
BEGIN |
| 694 |
i := q ; |
| 695 |
WHILE i#0 DO |
| 696 |
GetQuad (i, op, op1, op2, op3) ; |
| 697 |
CASE op OF |
| 698 |
|
| 699 |
NewLocalVarOp, |
| 700 |
KillLocalVarOp, |
| 701 |
FinallyStartOp, |
| 702 |
FinallyEndOp, |
| 703 |
InitEndOp, |
| 704 |
InitStartOp, |
| 705 |
EndFileOp, |
| 706 |
StartDefFileOp, |
| 707 |
StartModFileOp: RETURN( FALSE ) | (* run into end of procedure or module *) |
| 708 |
|
| 709 |
TryOp, |
| 710 |
RetryOp, |
| 711 |
GotoOp, |
| 712 |
IfEquOp, |
| 713 |
IfLessEquOp, |
| 714 |
IfGreEquOp, |
| 715 |
IfGreOp, |
| 716 |
IfLessOp, |
| 717 |
IfNotEquOp, |
| 718 |
IfInOp, |
| 719 |
IfNotInOp : IF (op3=q) AND IsConditional(q) |
| 720 |
THEN |
| 721 |
RETURN( TRUE ) |
| 722 |
END |
| 723 |
|
| 724 |
ELSE |
| 725 |
RETURN FALSE |
| 726 |
END ; |
| 727 |
i := GetNextQuad (i) |
| 728 |
END ; |
| 729 |
InternalError ('fix this for the sake of efficiency..') |
| 730 |
END IsBackReferenceConditional ; |
| 731 |
|
| 732 |
|
| 733 |
(* |
| 734 |
IsQuadA - returns true if QuadNo is a op. |
| 735 |
*) |
| 736 |
|
| 737 |
PROCEDURE IsQuadA (QuadNo: CARDINAL; op: QuadOperator) : BOOLEAN ; |
| 738 |
VAR |
| 739 |
f: QuadFrame ; |
| 740 |
BEGIN |
| 741 |
f := GetQF(QuadNo) ; |
| 742 |
WITH f^ DO |
| 743 |
RETURN( Operator=op ) |
| 744 |
END |
| 745 |
END IsQuadA ; |
| 746 |
|
| 747 |
|
| 748 |
(* |
| 749 |
IsGoto - returns true if QuadNo is a goto operation. |
| 750 |
*) |
| 751 |
|
| 752 |
PROCEDURE IsGoto (QuadNo: CARDINAL) : BOOLEAN ; |
| 753 |
BEGIN |
| 754 |
RETURN( IsQuadA (QuadNo, GotoOp) ) |
| 755 |
END IsGoto ; |
| 756 |
|
| 757 |
|
| 758 |
(* |
| 759 |
IsCall - returns true if QuadNo is a call operation. |
| 760 |
*) |
| 761 |
|
| 762 |
PROCEDURE IsCall (QuadNo: CARDINAL) : BOOLEAN ; |
| 763 |
BEGIN |
| 764 |
RETURN( IsQuadA(QuadNo, CallOp) ) |
| 765 |
END IsCall ; |
| 766 |
|
| 767 |
|
| 768 |
(* |
| 769 |
IsReturn - returns true if QuadNo is a return operation. |
| 770 |
*) |
| 771 |
|
| 772 |
PROCEDURE IsReturn (QuadNo: CARDINAL) : BOOLEAN ; |
| 773 |
BEGIN |
| 774 |
RETURN( IsQuadA(QuadNo, ReturnOp) ) |
| 775 |
END IsReturn ; |
| 776 |
|
| 777 |
|
| 778 |
(* |
| 779 |
IsNewLocalVar - returns true if QuadNo is a NewLocalVar operation. |
| 780 |
*) |
| 781 |
|
| 782 |
PROCEDURE IsNewLocalVar (QuadNo: CARDINAL) : BOOLEAN ; |
| 783 |
BEGIN |
| 784 |
RETURN( IsQuadA(QuadNo, NewLocalVarOp) ) |
| 785 |
END IsNewLocalVar ; |
| 786 |
|
| 787 |
|
| 788 |
(* |
| 789 |
IsKillLocalVar - returns true if QuadNo is a KillLocalVar operation. |
| 790 |
*) |
| 791 |
|
| 792 |
PROCEDURE IsKillLocalVar (QuadNo: CARDINAL) : BOOLEAN ; |
| 793 |
BEGIN |
| 794 |
RETURN( IsQuadA(QuadNo, KillLocalVarOp) ) |
| 795 |
END IsKillLocalVar ; |
| 796 |
|
| 797 |
|
| 798 |
(* |
| 799 |
IsProcedureScope - returns true if QuadNo is a ProcedureScope operation. |
| 800 |
*) |
| 801 |
|
| 802 |
PROCEDURE IsProcedureScope (QuadNo: CARDINAL) : BOOLEAN ; |
| 803 |
BEGIN |
| 804 |
RETURN( IsQuadA(QuadNo, ProcedureScopeOp) ) |
| 805 |
END IsProcedureScope ; |
| 806 |
|
| 807 |
|
| 808 |
(* |
| 809 |
IsCatchBegin - returns true if QuadNo is a catch begin quad. |
| 810 |
*) |
| 811 |
|
| 812 |
PROCEDURE IsCatchBegin (QuadNo: CARDINAL) : BOOLEAN ; |
| 813 |
BEGIN |
| 814 |
RETURN( IsQuadA(QuadNo, CatchBeginOp) ) |
| 815 |
END IsCatchBegin ; |
| 816 |
|
| 817 |
|
| 818 |
(* |
| 819 |
IsCatchEnd - returns true if QuadNo is a catch end quad. |
| 820 |
*) |
| 821 |
|
| 822 |
PROCEDURE IsCatchEnd (QuadNo: CARDINAL) : BOOLEAN ; |
| 823 |
BEGIN |
| 824 |
RETURN( IsQuadA(QuadNo, CatchEndOp) ) |
| 825 |
END IsCatchEnd ; |
| 826 |
|
| 827 |
|
| 828 |
(* |
| 829 |
IsInitStart - returns true if QuadNo is a init start quad. |
| 830 |
*) |
| 831 |
|
| 832 |
PROCEDURE IsInitStart (QuadNo: CARDINAL) : BOOLEAN ; |
| 833 |
BEGIN |
| 834 |
RETURN( IsQuadA(QuadNo, InitStartOp) ) |
| 835 |
END IsInitStart ; |
| 836 |
|
| 837 |
|
| 838 |
(* |
| 839 |
IsInitEnd - returns true if QuadNo is a init end quad. |
| 840 |
*) |
| 841 |
|
| 842 |
PROCEDURE IsInitEnd (QuadNo: CARDINAL) : BOOLEAN ; |
| 843 |
BEGIN |
| 844 |
RETURN( IsQuadA(QuadNo, InitEndOp) ) |
| 845 |
END IsInitEnd ; |
| 846 |
|
| 847 |
|
| 848 |
(* |
| 849 |
IsFinallyStart - returns true if QuadNo is a finally start quad. |
| 850 |
*) |
| 851 |
|
| 852 |
PROCEDURE IsFinallyStart (QuadNo: CARDINAL) : BOOLEAN ; |
| 853 |
BEGIN |
| 854 |
RETURN( IsQuadA(QuadNo, FinallyStartOp) ) |
| 855 |
END IsFinallyStart ; |
| 856 |
|
| 857 |
|
| 858 |
(* |
| 859 |
IsFinallyEnd - returns true if QuadNo is a finally end quad. |
| 860 |
*) |
| 861 |
|
| 862 |
PROCEDURE IsFinallyEnd (QuadNo: CARDINAL) : BOOLEAN ; |
| 863 |
BEGIN |
| 864 |
RETURN( IsQuadA(QuadNo, FinallyEndOp) ) |
| 865 |
END IsFinallyEnd ; |
| 866 |
|
| 867 |
|
| 868 |
(* |
| 869 |
IsBecomes - return TRUE if QuadNo is a BecomesOp. |
| 870 |
*) |
| 871 |
|
| 872 |
PROCEDURE IsBecomes (QuadNo: CARDINAL) : BOOLEAN ; |
| 873 |
BEGIN |
| 874 |
RETURN IsQuadA (QuadNo, BecomesOp) |
| 875 |
END IsBecomes ; |
| 876 |
|
| 877 |
|
| 878 |
(* |
| 879 |
IsDummy - return TRUE if QuadNo is a DummyOp. |
| 880 |
*) |
| 881 |
|
| 882 |
PROCEDURE IsDummy (QuadNo: CARDINAL) : BOOLEAN ; |
| 883 |
BEGIN |
| 884 |
RETURN IsQuadA (QuadNo, DummyOp) |
| 885 |
END IsDummy ; |
| 886 |
|
| 887 |
|
| 888 |
(* |
| 889 |
IsQuadConstExpr - returns TRUE if QuadNo is part of a constant expression. |
| 890 |
*) |
| 891 |
|
| 892 |
PROCEDURE IsQuadConstExpr (QuadNo: CARDINAL) : BOOLEAN ; |
| 893 |
VAR |
| 894 |
f: QuadFrame ; |
| 895 |
BEGIN |
| 896 |
f := GetQF (QuadNo) ; |
| 897 |
RETURN f^.ConstExpr |
| 898 |
END IsQuadConstExpr ; |
| 899 |
|
| 900 |
|
| 901 |
(* |
| 902 |
SetQuadConstExpr - sets the constexpr field to value. |
| 903 |
*) |
| 904 |
|
| 905 |
PROCEDURE SetQuadConstExpr (QuadNo: CARDINAL; value: BOOLEAN) ; |
| 906 |
VAR |
| 907 |
f: QuadFrame ; |
| 908 |
BEGIN |
| 909 |
f := GetQF (QuadNo) ; |
| 910 |
f^.ConstExpr := value |
| 911 |
END SetQuadConstExpr ; |
| 912 |
|
| 913 |
|
| 914 |
(* |
| 915 |
GetQuadDest - returns the jump destination associated with quad. |
| 916 |
*) |
| 917 |
|
| 918 |
PROCEDURE GetQuadDest (QuadNo: CARDINAL) : CARDINAL ; |
| 919 |
BEGIN |
| 920 |
RETURN GetQuadOp3 (QuadNo) |
| 921 |
END GetQuadDest ; |
| 922 |
|
| 923 |
|
| 924 |
(* |
| 925 |
GetQuadOp1 - returns the 1st operand associated with quad. |
| 926 |
*) |
| 927 |
|
| 928 |
PROCEDURE GetQuadOp1 (QuadNo: CARDINAL) : CARDINAL ; |
| 929 |
VAR |
| 930 |
f: QuadFrame ; |
| 931 |
BEGIN |
| 932 |
f := GetQF (QuadNo) ; |
| 933 |
RETURN f^.Operand1 |
| 934 |
END GetQuadOp1 ; |
| 935 |
|
| 936 |
|
| 937 |
(* |
| 938 |
GetQuadOp2 - returns the 2nd operand associated with quad. |
| 939 |
*) |
| 940 |
|
| 941 |
PROCEDURE GetQuadOp2 (QuadNo: CARDINAL) : CARDINAL ; |
| 942 |
VAR |
| 943 |
f: QuadFrame ; |
| 944 |
BEGIN |
| 945 |
f := GetQF (QuadNo) ; |
| 946 |
RETURN f^.Operand2 |
| 947 |
END GetQuadOp2 ; |
| 948 |
|
| 949 |
|
| 950 |
(* |
| 951 |
GetQuadOp3 - returns the 3rd operand associated with quad. |
| 952 |
*) |
| 953 |
|
| 954 |
PROCEDURE GetQuadOp3 (QuadNo: CARDINAL) : CARDINAL ; |
| 955 |
VAR |
| 956 |
f: QuadFrame ; |
| 957 |
BEGIN |
| 958 |
f := GetQF (QuadNo) ; |
| 959 |
RETURN f^.Operand3 |
| 960 |
END GetQuadOp3 ; |
| 961 |
|
| 962 |
|
| 963 |
(* |
| 964 |
IsInitialisingConst - returns TRUE if the quadruple is setting |
| 965 |
a const (op1) with a value. |
| 966 |
*) |
| 967 |
|
| 968 |
PROCEDURE IsInitialisingConst (QuadNo: CARDINAL) : BOOLEAN ; |
| 969 |
VAR |
| 970 |
op : QuadOperator ; |
| 971 |
op1, op2, op3: CARDINAL ; |
| 972 |
BEGIN |
| 973 |
GetQuad (QuadNo, op, op1, op2, op3) ; |
| 974 |
RETURN OpUsesOp1 (op) AND IsConst (op1) |
| 975 |
END IsInitialisingConst ; |
| 976 |
|
| 977 |
|
| 978 |
(* |
| 979 |
IsConstQuad - return TRUE if the quadruple is marked as a constexpr. |
| 980 |
*) |
| 981 |
|
| 982 |
PROCEDURE IsConstQuad (quad: CARDINAL) : BOOLEAN ; |
| 983 |
VAR |
| 984 |
f: QuadFrame ; |
| 985 |
BEGIN |
| 986 |
f := GetQF (quad) ; |
| 987 |
RETURN f^.ConstExpr |
| 988 |
END IsConstQuad ; |
| 989 |
|
| 990 |
|
| 991 |
(* |
| 992 |
OpUsesOp1 - return TRUE if op allows op1. |
| 993 |
*) |
| 994 |
|
| 995 |
PROCEDURE OpUsesOp1 (op: QuadOperator) : BOOLEAN ; |
| 996 |
BEGIN |
| 997 |
CASE op OF |
| 998 |
|
| 999 |
StringConvertCnulOp, |
| 1000 |
StringConvertM2nulOp, |
| 1001 |
StringLengthOp, |
| 1002 |
InclOp, |
| 1003 |
ExclOp, |
| 1004 |
UnboundedOp, |
| 1005 |
FunctValueOp, |
| 1006 |
NegateOp, |
| 1007 |
BecomesOp, |
| 1008 |
HighOp, |
| 1009 |
SizeOp, |
| 1010 |
AddrOp, |
| 1011 |
RecordFieldOp, |
| 1012 |
ArrayOp, |
| 1013 |
LogicalShiftOp, |
| 1014 |
LogicalRotateOp, |
| 1015 |
LogicalOrOp, |
| 1016 |
LogicalAndOp, |
| 1017 |
LogicalXorOp, |
| 1018 |
CoerceOp, |
| 1019 |
ConvertOp, |
| 1020 |
CastOp, |
| 1021 |
AddOp, |
| 1022 |
SubOp, |
| 1023 |
MultOp, |
| 1024 |
ModFloorOp, |
| 1025 |
DivCeilOp, |
| 1026 |
ModCeilOp, |
| 1027 |
DivFloorOp, |
| 1028 |
ModTruncOp, |
| 1029 |
DivTruncOp, |
| 1030 |
DivM2Op, |
| 1031 |
ModM2Op, |
| 1032 |
XIndrOp, |
| 1033 |
IndrXOp, |
| 1034 |
SaveExceptionOp, |
| 1035 |
RestoreExceptionOp: RETURN TRUE |
| 1036 |
|
| 1037 |
ELSE |
| 1038 |
RETURN FALSE |
| 1039 |
END |
| 1040 |
END OpUsesOp1 ; |
| 1041 |
|
| 1042 |
|
| 1043 |
(* |
| 1044 |
IsConditionalBooleanQuad - return TRUE if operand 1 is a boolean result. |
| 1045 |
*) |
| 1046 |
|
| 1047 |
PROCEDURE IsConditionalBooleanQuad (quad: CARDINAL) : BOOLEAN ; |
| 1048 |
VAR |
| 1049 |
f: QuadFrame ; |
| 1050 |
BEGIN |
| 1051 |
f := GetQF (quad) ; |
| 1052 |
RETURN OpUsesOp1 (f^.Operator) AND |
| 1053 |
(IsVar (f^.Operand1) OR IsConst (f^.Operand1)) AND |
| 1054 |
IsVarConditional (f^.Operand1) |
| 1055 |
END IsConditionalBooleanQuad ; |
| 1056 |
|
| 1057 |
|
| 1058 |
(* |
| 1059 |
IsOptimizeOn - returns true if the Optimize flag was true at QuadNo. |
| 1060 |
*) |
| 1061 |
|
| 1062 |
PROCEDURE IsOptimizeOn (QuadNo: CARDINAL) : BOOLEAN ; |
| 1063 |
VAR |
| 1064 |
f : QuadFrame ; |
| 1065 |
n, |
| 1066 |
q : CARDINAL ; |
| 1067 |
On: BOOLEAN ; |
| 1068 |
BEGIN |
| 1069 |
On := Optimizing ; |
| 1070 |
q := Head ; |
| 1071 |
WHILE (q#0) AND (q#QuadNo) DO |
| 1072 |
f := GetQF(q) ; |
| 1073 |
WITH f^ DO |
| 1074 |
IF Operator=OptimizeOnOp |
| 1075 |
THEN |
| 1076 |
On := TRUE |
| 1077 |
ELSIF Operator=OptimizeOffOp |
| 1078 |
THEN |
| 1079 |
On := FALSE |
| 1080 |
END ; |
| 1081 |
n := Next |
| 1082 |
END ; |
| 1083 |
q := n |
| 1084 |
END ; |
| 1085 |
RETURN( On ) |
| 1086 |
END IsOptimizeOn ; |
| 1087 |
|
| 1088 |
|
| 1089 |
(* |
| 1090 |
IsProfileOn - returns true if the Profile flag was true at QuadNo. |
| 1091 |
*) |
| 1092 |
|
| 1093 |
PROCEDURE IsProfileOn (QuadNo: CARDINAL) : BOOLEAN ; |
| 1094 |
VAR |
| 1095 |
f : QuadFrame ; |
| 1096 |
n, |
| 1097 |
q : CARDINAL ; |
| 1098 |
On: BOOLEAN ; |
| 1099 |
BEGIN |
| 1100 |
On := Profiling ; |
| 1101 |
q := Head ; |
| 1102 |
WHILE (q#0) AND (q#QuadNo) DO |
| 1103 |
f := GetQF(q) ; |
| 1104 |
WITH f^ DO |
| 1105 |
IF Operator=ProfileOnOp |
| 1106 |
THEN |
| 1107 |
On := TRUE |
| 1108 |
ELSIF Operator=ProfileOffOp |
| 1109 |
THEN |
| 1110 |
On := FALSE |
| 1111 |
END ; |
| 1112 |
n := Next |
| 1113 |
END ; |
| 1114 |
q := n |
| 1115 |
END ; |
| 1116 |
RETURN( On ) |
| 1117 |
END IsProfileOn ; |
| 1118 |
|
| 1119 |
|
| 1120 |
(* |
| 1121 |
IsCodeOn - returns true if the Code flag was true at QuadNo. |
| 1122 |
*) |
| 1123 |
|
| 1124 |
PROCEDURE IsCodeOn (QuadNo: CARDINAL) : BOOLEAN ; |
| 1125 |
VAR |
| 1126 |
f : QuadFrame ; |
| 1127 |
n, |
| 1128 |
q : CARDINAL ; |
| 1129 |
On: BOOLEAN ; |
| 1130 |
BEGIN |
| 1131 |
On := Coding ; |
| 1132 |
q := Head ; |
| 1133 |
WHILE (q#0) AND (q#QuadNo) DO |
| 1134 |
f := GetQF(q) ; |
| 1135 |
WITH f^ DO |
| 1136 |
IF Operator=CodeOnOp |
| 1137 |
THEN |
| 1138 |
On := TRUE |
| 1139 |
ELSIF Operator=CodeOffOp |
| 1140 |
THEN |
| 1141 |
On := FALSE |
| 1142 |
END ; |
| 1143 |
n := Next |
| 1144 |
END ; |
| 1145 |
q := n |
| 1146 |
END ; |
| 1147 |
RETURN( On ) |
| 1148 |
END IsCodeOn ; |
| 1149 |
|
| 1150 |
|
| 1151 |
(* |
| 1152 |
IsDefOrModFile - returns TRUE if QuadNo is a start of Module or Def file |
| 1153 |
directive. |
| 1154 |
*) |
| 1155 |
|
| 1156 |
PROCEDURE IsDefOrModFile (QuadNo: CARDINAL) : BOOLEAN ; |
| 1157 |
VAR |
| 1158 |
f: QuadFrame ; |
| 1159 |
BEGIN |
| 1160 |
f := GetQF(QuadNo) ; |
| 1161 |
WITH f^ DO |
| 1162 |
RETURN( (Operator=StartDefFileOp) OR (Operator=StartModFileOp) ) |
| 1163 |
END |
| 1164 |
END IsDefOrModFile ; |
| 1165 |
|
| 1166 |
|
| 1167 |
(* |
| 1168 |
IsPseudoQuad - returns true if QuadNo is a compiler directive. |
| 1169 |
ie code, profile and optimize. |
| 1170 |
StartFile, EndFile, |
| 1171 |
*) |
| 1172 |
|
| 1173 |
PROCEDURE IsPseudoQuad (QuadNo: CARDINAL) : BOOLEAN ; |
| 1174 |
VAR |
| 1175 |
f: QuadFrame ; |
| 1176 |
BEGIN |
| 1177 |
f := GetQF(QuadNo) ; |
| 1178 |
WITH f^ DO |
| 1179 |
RETURN( (Operator=CodeOnOp) OR (Operator=CodeOffOp) OR |
| 1180 |
(Operator=ProfileOnOp) OR (Operator=ProfileOffOp) OR |
| 1181 |
(Operator=OptimizeOnOp) OR (Operator=OptimizeOffOp) OR |
| 1182 |
(Operator=EndFileOp) OR |
| 1183 |
(Operator=StartDefFileOp) OR (Operator=StartModFileOp) |
| 1184 |
) |
| 1185 |
END |
| 1186 |
END IsPseudoQuad ; |
| 1187 |
|
| 1188 |
|
| 1189 |
(* |
| 1190 |
GetLastFileQuad - returns the Quadruple number of the last StartDefFile or |
| 1191 |
StartModFile quadruple. |
| 1192 |
*) |
| 1193 |
|
| 1194 |
PROCEDURE GetLastFileQuad (QuadNo: CARDINAL) : CARDINAL ; |
| 1195 |
VAR |
| 1196 |
f : QuadFrame ; |
| 1197 |
q, i, |
| 1198 |
FileQuad: CARDINAL ; |
| 1199 |
BEGIN |
| 1200 |
q := Head ; |
| 1201 |
FileQuad := 0 ; |
| 1202 |
REPEAT |
| 1203 |
f := GetQF(q) ; |
| 1204 |
WITH f^ DO |
| 1205 |
IF (Operator=StartModFileOp) OR (Operator=StartDefFileOp) |
| 1206 |
THEN |
| 1207 |
FileQuad := q |
| 1208 |
END ; |
| 1209 |
i := Next |
| 1210 |
END ; |
| 1211 |
q := i |
| 1212 |
UNTIL (i=QuadNo) OR (i=0) ; |
| 1213 |
Assert(i#0) ; |
| 1214 |
Assert(FileQuad#0) ; |
| 1215 |
RETURN( FileQuad ) |
| 1216 |
END GetLastFileQuad ; |
| 1217 |
|
| 1218 |
|
| 1219 |
(* |
| 1220 |
GetLastQuadNo - returns the last quadruple number referenced |
| 1221 |
by a GetQuad. |
| 1222 |
*) |
| 1223 |
|
| 1224 |
PROCEDURE GetLastQuadNo () : CARDINAL ; |
| 1225 |
BEGIN |
| 1226 |
RETURN( LastQuadNo ) |
| 1227 |
END GetLastQuadNo ; |
| 1228 |
|
| 1229 |
|
| 1230 |
(* |
| 1231 |
QuadToLineNo - Converts a QuadNo into the approprate line number of the |
| 1232 |
source file, the line number is returned. |
| 1233 |
|
| 1234 |
This may be used to yield an idea where abouts in the |
| 1235 |
source file the code generetion is |
| 1236 |
processing. |
| 1237 |
*) |
| 1238 |
|
| 1239 |
PROCEDURE QuadToLineNo (QuadNo: CARDINAL) : CARDINAL ; |
| 1240 |
VAR |
| 1241 |
f: QuadFrame ; |
| 1242 |
BEGIN |
| 1243 |
IF ((LastQuadNo=0) AND (NOT IsNoPass()) AND (NOT IsPassCodeGeneration())) OR |
| 1244 |
(NOT InBounds(QuadArray, QuadNo)) |
| 1245 |
THEN |
| 1246 |
RETURN( 0 ) |
| 1247 |
ELSE |
| 1248 |
f := GetQF(QuadNo) ; |
| 1249 |
RETURN( f^.LineNo ) |
| 1250 |
END |
| 1251 |
END QuadToLineNo ; |
| 1252 |
|
| 1253 |
|
| 1254 |
(* |
| 1255 |
QuadToTokenNo - Converts a QuadNo into the approprate token number of the |
| 1256 |
source file, the line number is returned. |
| 1257 |
|
| 1258 |
This may be used to yield an idea where abouts in the |
| 1259 |
source file the code generetion is |
| 1260 |
processing. |
| 1261 |
*) |
| 1262 |
|
| 1263 |
PROCEDURE QuadToTokenNo (QuadNo: CARDINAL) : CARDINAL ; |
| 1264 |
VAR |
| 1265 |
f: QuadFrame ; |
| 1266 |
BEGIN |
| 1267 |
IF ((LastQuadNo=0) AND (NOT IsNoPass()) AND (NOT IsPassCodeGeneration())) OR |
| 1268 |
(NOT InBounds(QuadArray, QuadNo)) |
| 1269 |
THEN |
| 1270 |
RETURN( 0 ) |
| 1271 |
ELSE |
| 1272 |
f := GetQF(QuadNo) ; |
| 1273 |
RETURN( f^.TokenNo ) |
| 1274 |
END |
| 1275 |
END QuadToTokenNo ; |
| 1276 |
|
| 1277 |
|
| 1278 |
(* |
| 1279 |
GetQuad - returns the Quadruple QuadNo. |
| 1280 |
*) |
| 1281 |
|
| 1282 |
PROCEDURE GetQuad (QuadNo: CARDINAL; |
| 1283 |
VAR Op: QuadOperator; |
| 1284 |
VAR Oper1, Oper2, Oper3: CARDINAL) ; |
| 1285 |
VAR |
| 1286 |
f: QuadFrame ; |
| 1287 |
BEGIN |
| 1288 |
f := GetQF(QuadNo) ; |
| 1289 |
LastQuadNo := QuadNo ; |
| 1290 |
WITH f^ DO |
| 1291 |
Op := Operator ; |
| 1292 |
Oper1 := Operand1 ; |
| 1293 |
Oper2 := Operand2 ; |
| 1294 |
Oper3 := Operand3 |
| 1295 |
END |
| 1296 |
END GetQuad ; |
| 1297 |
|
| 1298 |
|
| 1299 |
(* |
| 1300 |
GetQuadtok - returns the Quadruple QuadNo. |
| 1301 |
*) |
| 1302 |
|
| 1303 |
PROCEDURE GetQuadtok (QuadNo: CARDINAL; |
| 1304 |
VAR Op: QuadOperator; |
| 1305 |
VAR Oper1, Oper2, Oper3: CARDINAL; |
| 1306 |
VAR Op1Pos, Op2Pos, Op3Pos: CARDINAL) ; |
| 1307 |
VAR |
| 1308 |
f: QuadFrame ; |
| 1309 |
BEGIN |
| 1310 |
f := GetQF (QuadNo) ; |
| 1311 |
LastQuadNo := QuadNo ; |
| 1312 |
WITH f^ DO |
| 1313 |
Op := Operator ; |
| 1314 |
Oper1 := Operand1 ; |
| 1315 |
Oper2 := Operand2 ; |
| 1316 |
Oper3 := Operand3 ; |
| 1317 |
Op1Pos := op1pos ; |
| 1318 |
Op2Pos := op2pos ; |
| 1319 |
Op3Pos := op3pos |
| 1320 |
END |
| 1321 |
END GetQuadtok ; |
| 1322 |
|
| 1323 |
|
| 1324 |
(* |
| 1325 |
GetQuadOtok - returns the Quadruple QuadNo. |
| 1326 |
*) |
| 1327 |
|
| 1328 |
PROCEDURE GetQuadOtok (QuadNo: CARDINAL; |
| 1329 |
VAR tok: CARDINAL; |
| 1330 |
VAR Op: QuadOperator; |
| 1331 |
VAR Oper1, Oper2, Oper3: CARDINAL; |
| 1332 |
VAR overflowChecking, constExpr: BOOLEAN ; |
| 1333 |
VAR Op1Pos, Op2Pos, Op3Pos: CARDINAL) ; |
| 1334 |
VAR |
| 1335 |
f: QuadFrame ; |
| 1336 |
BEGIN |
| 1337 |
f := GetQF (QuadNo) ; |
| 1338 |
LastQuadNo := QuadNo ; |
| 1339 |
WITH f^ DO |
| 1340 |
Op := Operator ; |
| 1341 |
Oper1 := Operand1 ; |
| 1342 |
Oper2 := Operand2 ; |
| 1343 |
Oper3 := Operand3 ; |
| 1344 |
Op1Pos := op1pos ; |
| 1345 |
Op2Pos := op2pos ; |
| 1346 |
Op3Pos := op3pos ; |
| 1347 |
tok := TokenNo ; |
| 1348 |
overflowChecking := CheckOverflow ; |
| 1349 |
constExpr := ConstExpr |
| 1350 |
END |
| 1351 |
END GetQuadOtok ; |
| 1352 |
|
| 1353 |
|
| 1354 |
(* |
| 1355 |
PutQuadOtok - alters a quadruple QuadNo with Op, Oper1, Oper2, Oper3, and |
| 1356 |
sets a boolean to determinine whether overflow should be checked. |
| 1357 |
*) |
| 1358 |
|
| 1359 |
PROCEDURE PutQuadOtok (QuadNo: CARDINAL; |
| 1360 |
tok: CARDINAL; |
| 1361 |
Op: QuadOperator; |
| 1362 |
Oper1, Oper2, Oper3: CARDINAL; |
| 1363 |
overflowChecking, constExpr: BOOLEAN ; |
| 1364 |
Op1Pos, Op2Pos, Op3Pos: CARDINAL) ; |
| 1365 |
VAR |
| 1366 |
f: QuadFrame ; |
| 1367 |
BEGIN |
| 1368 |
IF QuadrupleGeneration |
| 1369 |
THEN |
| 1370 |
EraseQuad (QuadNo) ; |
| 1371 |
AddQuadInformation (QuadNo, Op, Oper1, Oper2, Oper3) ; |
| 1372 |
f := GetQF (QuadNo) ; |
| 1373 |
WITH f^ DO |
| 1374 |
Operator := Op ; |
| 1375 |
Operand1 := Oper1 ; |
| 1376 |
Operand2 := Oper2 ; |
| 1377 |
Operand3 := Oper3 ; |
| 1378 |
CheckOverflow := overflowChecking ; |
| 1379 |
op1pos := Op1Pos ; |
| 1380 |
op2pos := Op2Pos ; |
| 1381 |
op3pos := Op3Pos ; |
| 1382 |
TokenNo := tok ; |
| 1383 |
ConstExpr := constExpr |
| 1384 |
END |
| 1385 |
END |
| 1386 |
END PutQuadOtok ; |
| 1387 |
|
| 1388 |
|
| 1389 |
(* |
| 1390 |
AddQuadInformation - adds variable analysis and jump analysis to the new quadruple. |
| 1391 |
*) |
| 1392 |
|
| 1393 |
PROCEDURE AddQuadInformation (QuadNo: CARDINAL; |
| 1394 |
Op: QuadOperator; |
| 1395 |
Oper1, Oper2, Oper3: CARDINAL) ; |
| 1396 |
BEGIN |
| 1397 |
CASE Op OF |
| 1398 |
|
| 1399 |
IfInOp, |
| 1400 |
IfNotInOp, |
| 1401 |
IfEquOp, |
| 1402 |
IfNotEquOp, |
| 1403 |
IfLessOp, |
| 1404 |
IfLessEquOp, |
| 1405 |
IfGreOp, |
| 1406 |
IfGreEquOp : ManipulateReference(QuadNo, Oper3) ; |
| 1407 |
CheckAddVariableRead(Oper1, FALSE, QuadNo) ; |
| 1408 |
CheckAddVariableRead(Oper2, FALSE, QuadNo) | |
| 1409 |
LastForIteratorOp: CheckAddVariableWrite (Oper1, FALSE, QuadNo) ; |
| 1410 |
CheckAddTuple2Read (Oper2, FALSE, QuadNo) ; |
| 1411 |
CheckAddVariableRead (Oper3, FALSE, QuadNo) | |
| 1412 |
TryOp, |
| 1413 |
RetryOp, |
| 1414 |
GotoOp : ManipulateReference(QuadNo, Oper3) | |
| 1415 |
|
| 1416 |
(* variable references *) |
| 1417 |
|
| 1418 |
InclOp, |
| 1419 |
ExclOp : CheckConst(Oper1) ; |
| 1420 |
CheckAddVariableRead(Oper3, FALSE, QuadNo) ; |
| 1421 |
CheckAddVariableWrite(Oper1, TRUE, QuadNo) | |
| 1422 |
UnboundedOp, |
| 1423 |
FunctValueOp, |
| 1424 |
NegateOp, |
| 1425 |
BecomesOp, |
| 1426 |
HighOp, |
| 1427 |
SizeOp : CheckConst(Oper1) ; |
| 1428 |
CheckAddVariableWrite(Oper1, FALSE, QuadNo) ; |
| 1429 |
CheckAddVariableRead(Oper3, FALSE, QuadNo) | |
| 1430 |
AddrOp : CheckConst(Oper1) ; |
| 1431 |
CheckAddVariableWrite(Oper1, FALSE, QuadNo) ; |
| 1432 |
(* CheckAddVariableReadLeftValue(Oper3, QuadNo) *) |
| 1433 |
(* the next line is a kludge and assumes we _will_ |
| 1434 |
write to the variable as we have taken its address *) |
| 1435 |
CheckRemoveVariableWrite(Oper1, TRUE, QuadNo) | |
| 1436 |
ReturnValueOp : CheckAddVariableRead(Oper1, FALSE, QuadNo) | |
| 1437 |
ReturnOp, |
| 1438 |
NewLocalVarOp, |
| 1439 |
KillLocalVarOp : | |
| 1440 |
CallOp : CheckAddVariableRead(Oper3, TRUE, QuadNo) | |
| 1441 |
|
| 1442 |
ParamOp : CheckAddVariableRead(Oper2, FALSE, QuadNo) ; |
| 1443 |
CheckAddVariableRead(Oper3, FALSE, QuadNo) ; |
| 1444 |
IF (Oper1>0) AND (Oper1<=NoOfParamAny(Oper2)) AND |
| 1445 |
IsVarParamAny (Oper2, Oper1) |
| 1446 |
THEN |
| 1447 |
(* _may_ also write to a var parameter, although we dont know *) |
| 1448 |
CheckAddVariableWrite(Oper3, TRUE, QuadNo) |
| 1449 |
END | |
| 1450 |
RecordFieldOp, |
| 1451 |
ArrayOp, |
| 1452 |
LogicalShiftOp, |
| 1453 |
LogicalRotateOp, |
| 1454 |
LogicalOrOp, |
| 1455 |
LogicalAndOp, |
| 1456 |
LogicalXorOp, |
| 1457 |
CoerceOp, |
| 1458 |
ConvertOp, |
| 1459 |
CastOp, |
| 1460 |
AddOp, |
| 1461 |
SubOp, |
| 1462 |
MultOp, |
| 1463 |
DivM2Op, |
| 1464 |
ModM2Op, |
| 1465 |
ModFloorOp, |
| 1466 |
DivCeilOp, |
| 1467 |
ModCeilOp, |
| 1468 |
DivFloorOp, |
| 1469 |
ModTruncOp, |
| 1470 |
DivTruncOp : CheckConst(Oper1) ; |
| 1471 |
CheckAddVariableWrite(Oper1, FALSE, QuadNo) ; |
| 1472 |
CheckAddVariableRead(Oper2, FALSE, QuadNo) ; |
| 1473 |
CheckAddVariableRead(Oper3, FALSE, QuadNo) | |
| 1474 |
|
| 1475 |
XIndrOp : CheckConst(Oper1) ; |
| 1476 |
CheckAddVariableWrite(Oper1, TRUE, QuadNo) ; |
| 1477 |
CheckAddVariableRead(Oper3, FALSE, QuadNo) | |
| 1478 |
|
| 1479 |
IndrXOp : CheckConst(Oper1) ; |
| 1480 |
CheckAddVariableWrite(Oper1, FALSE, QuadNo) ; |
| 1481 |
CheckAddVariableRead(Oper3, TRUE, QuadNo) | |
| 1482 |
|
| 1483 |
(* RangeCheckOp : CheckRangeAddVariableRead(Oper3, QuadNo) | *) |
| 1484 |
SaveExceptionOp : CheckConst(Oper1) ; |
| 1485 |
CheckAddVariableWrite(Oper1, FALSE, QuadNo) | |
| 1486 |
RestoreExceptionOp: CheckAddVariableRead(Oper1, FALSE, QuadNo) |
| 1487 |
|
| 1488 |
ELSE |
| 1489 |
END |
| 1490 |
END AddQuadInformation ; |
| 1491 |
|
| 1492 |
|
| 1493 |
(* |
| 1494 |
PutQuadO - alters a quadruple QuadNo with Op, Oper1, Oper2, Oper3, and |
| 1495 |
sets a boolean to determinine whether overflow should be checked. |
| 1496 |
*) |
| 1497 |
|
| 1498 |
PROCEDURE PutQuadO (QuadNo: CARDINAL; |
| 1499 |
Op: QuadOperator; |
| 1500 |
Oper1, Oper2, Oper3: CARDINAL; |
| 1501 |
overflow: BOOLEAN) ; |
| 1502 |
BEGIN |
| 1503 |
PutQuadOType (QuadNo, Op, Oper1, Oper2, Oper3, overflow, TRUE) |
| 1504 |
END PutQuadO ; |
| 1505 |
|
| 1506 |
|
| 1507 |
(* |
| 1508 |
PutQuadOType - |
| 1509 |
*) |
| 1510 |
|
| 1511 |
PROCEDURE PutQuadOType (QuadNo: CARDINAL; |
| 1512 |
Op: QuadOperator; |
| 1513 |
Oper1, Oper2, Oper3: CARDINAL; |
| 1514 |
overflow, checktype: BOOLEAN) ; |
| 1515 |
VAR |
| 1516 |
f: QuadFrame ; |
| 1517 |
BEGIN |
| 1518 |
IF QuadrupleGeneration |
| 1519 |
THEN |
| 1520 |
EraseQuad (QuadNo) ; |
| 1521 |
AddQuadInformation (QuadNo, Op, Oper1, Oper2, Oper3) ; |
| 1522 |
f := GetQF (QuadNo) ; |
| 1523 |
WITH f^ DO |
| 1524 |
Operator := Op ; |
| 1525 |
Operand1 := Oper1 ; |
| 1526 |
Operand2 := Oper2 ; |
| 1527 |
Operand3 := Oper3 ; |
| 1528 |
CheckOverflow := overflow ; |
| 1529 |
CheckType := checktype ; |
| 1530 |
ConstExpr := FALSE ; (* IsInConstExpression () *) |
| 1531 |
END |
| 1532 |
END |
| 1533 |
END PutQuadOType ; |
| 1534 |
|
| 1535 |
|
| 1536 |
(* |
| 1537 |
PutQuad - overwrites a quadruple QuadNo with Op, Oper1, Oper2, Oper3 |
| 1538 |
*) |
| 1539 |
|
| 1540 |
PROCEDURE PutQuad (QuadNo: CARDINAL; |
| 1541 |
Op: QuadOperator; |
| 1542 |
Oper1, Oper2, Oper3: CARDINAL) ; |
| 1543 |
BEGIN |
| 1544 |
PutQuadO (QuadNo, Op, Oper1, Oper2, Oper3, TRUE) |
| 1545 |
END PutQuad ; |
| 1546 |
|
| 1547 |
|
| 1548 |
(* |
| 1549 |
GetQuadOTypetok - returns the fields associated with quadruple QuadNo. |
| 1550 |
*) |
| 1551 |
|
| 1552 |
PROCEDURE GetQuadOTypetok (QuadNo: CARDINAL; |
| 1553 |
VAR tok: CARDINAL; |
| 1554 |
VAR Op: QuadOperator; |
| 1555 |
VAR Oper1, Oper2, Oper3: CARDINAL; |
| 1556 |
VAR overflowChecking, typeChecking, constExpr: BOOLEAN ; |
| 1557 |
VAR Op1Pos, Op2Pos, Op3Pos: CARDINAL) ; |
| 1558 |
VAR |
| 1559 |
f: QuadFrame ; |
| 1560 |
BEGIN |
| 1561 |
f := GetQF (QuadNo) ; |
| 1562 |
LastQuadNo := QuadNo ; |
| 1563 |
WITH f^ DO |
| 1564 |
Op := Operator ; |
| 1565 |
Oper1 := Operand1 ; |
| 1566 |
Oper2 := Operand2 ; |
| 1567 |
Oper3 := Operand3 ; |
| 1568 |
Op1Pos := op1pos ; |
| 1569 |
Op2Pos := op2pos ; |
| 1570 |
Op3Pos := op3pos ; |
| 1571 |
tok := TokenNo ; |
| 1572 |
overflowChecking := CheckOverflow ; |
| 1573 |
typeChecking := CheckType ; |
| 1574 |
constExpr := ConstExpr |
| 1575 |
END |
| 1576 |
END GetQuadOTypetok ; |
| 1577 |
|
| 1578 |
|
| 1579 |
(* |
| 1580 |
UndoReadWriteInfo - |
| 1581 |
*) |
| 1582 |
|
| 1583 |
PROCEDURE UndoReadWriteInfo (QuadNo: CARDINAL; |
| 1584 |
Op: QuadOperator; |
| 1585 |
Oper1, Oper2, Oper3: CARDINAL) ; |
| 1586 |
BEGIN |
| 1587 |
CASE Op OF |
| 1588 |
|
| 1589 |
(* jumps, calls and branches *) |
| 1590 |
IfInOp, |
| 1591 |
IfNotInOp, |
| 1592 |
IfEquOp, |
| 1593 |
IfNotEquOp, |
| 1594 |
IfLessOp, |
| 1595 |
IfLessEquOp, |
| 1596 |
IfGreOp, |
| 1597 |
IfGreEquOp : RemoveReference(QuadNo) ; |
| 1598 |
CheckRemoveVariableRead(Oper1, FALSE, QuadNo) ; |
| 1599 |
CheckRemoveVariableRead(Oper2, FALSE, QuadNo) | |
| 1600 |
|
| 1601 |
TryOp, |
| 1602 |
RetryOp, |
| 1603 |
GotoOp : RemoveReference(QuadNo) | |
| 1604 |
|
| 1605 |
(* variable references *) |
| 1606 |
|
| 1607 |
InclOp, |
| 1608 |
ExclOp : CheckRemoveVariableRead(Oper1, FALSE, QuadNo) ; |
| 1609 |
CheckRemoveVariableWrite(Oper1, TRUE, QuadNo) | |
| 1610 |
|
| 1611 |
UnboundedOp, |
| 1612 |
FunctValueOp, |
| 1613 |
NegateOp, |
| 1614 |
BecomesOp, |
| 1615 |
HighOp, |
| 1616 |
SizeOp : CheckRemoveVariableWrite(Oper1, FALSE, QuadNo) ; |
| 1617 |
CheckRemoveVariableRead(Oper3, FALSE, QuadNo) | |
| 1618 |
AddrOp : CheckRemoveVariableWrite(Oper1, FALSE, QuadNo) ; |
| 1619 |
(* CheckRemoveVariableReadLeftValue(Oper3, QuadNo) ; *) |
| 1620 |
(* the next line is a kludge and assumes we _will_ |
| 1621 |
write to the variable as we have taken its address *) |
| 1622 |
CheckRemoveVariableWrite(Oper1, TRUE, QuadNo) | |
| 1623 |
ReturnValueOp : CheckRemoveVariableRead(Oper1, FALSE, QuadNo) | |
| 1624 |
ReturnOp, |
| 1625 |
CallOp, |
| 1626 |
NewLocalVarOp, |
| 1627 |
KillLocalVarOp : | |
| 1628 |
ParamOp : CheckRemoveVariableRead(Oper2, FALSE, QuadNo) ; |
| 1629 |
CheckRemoveVariableRead(Oper3, FALSE, QuadNo) ; |
| 1630 |
IF (Oper1>0) AND (Oper1<=NoOfParamAny(Oper2)) AND |
| 1631 |
IsVarParamAny (Oper2, Oper1) |
| 1632 |
THEN |
| 1633 |
(* _may_ also write to a var parameter, although we dont know *) |
| 1634 |
CheckRemoveVariableWrite(Oper3, TRUE, QuadNo) |
| 1635 |
END | |
| 1636 |
RecordFieldOp, |
| 1637 |
ArrayOp, |
| 1638 |
LogicalShiftOp, |
| 1639 |
LogicalRotateOp, |
| 1640 |
LogicalOrOp, |
| 1641 |
LogicalAndOp, |
| 1642 |
LogicalXorOp, |
| 1643 |
CoerceOp, |
| 1644 |
ConvertOp, |
| 1645 |
CastOp, |
| 1646 |
AddOp, |
| 1647 |
SubOp, |
| 1648 |
MultOp, |
| 1649 |
DivM2Op, |
| 1650 |
ModM2Op, |
| 1651 |
ModFloorOp, |
| 1652 |
DivCeilOp, |
| 1653 |
ModCeilOp, |
| 1654 |
DivFloorOp, |
| 1655 |
ModTruncOp, |
| 1656 |
DivTruncOp : CheckRemoveVariableWrite(Oper1, FALSE, QuadNo) ; |
| 1657 |
CheckRemoveVariableRead(Oper2, FALSE, QuadNo) ; |
| 1658 |
CheckRemoveVariableRead(Oper3, FALSE, QuadNo) | |
| 1659 |
|
| 1660 |
XIndrOp : CheckRemoveVariableWrite(Oper1, TRUE, QuadNo) ; |
| 1661 |
CheckRemoveVariableRead(Oper3, FALSE, QuadNo) | |
| 1662 |
|
| 1663 |
IndrXOp : CheckRemoveVariableWrite(Oper1, FALSE, QuadNo) ; |
| 1664 |
CheckRemoveVariableRead(Oper3, TRUE, QuadNo) | |
| 1665 |
|
| 1666 |
(* RangeCheckOp : CheckRangeRemoveVariableRead(Oper3, QuadNo) | *) |
| 1667 |
SaveExceptionOp : CheckRemoveVariableWrite(Oper1, FALSE, QuadNo) | |
| 1668 |
RestoreExceptionOp: CheckRemoveVariableRead(Oper1, FALSE, QuadNo) |
| 1669 |
|
| 1670 |
ELSE |
| 1671 |
END |
| 1672 |
END UndoReadWriteInfo ; |
| 1673 |
|
| 1674 |
|
| 1675 |
(* |
| 1676 |
EraseQuad - erases a quadruple QuadNo, the quadruple is still in the list |
| 1677 |
but wiped clean. |
| 1678 |
*) |
| 1679 |
|
| 1680 |
PROCEDURE EraseQuad (QuadNo: CARDINAL) ; |
| 1681 |
VAR |
| 1682 |
f: QuadFrame ; |
| 1683 |
BEGIN |
| 1684 |
CheckBreak (QuadNo) ; |
| 1685 |
f := GetQF(QuadNo) ; |
| 1686 |
WITH f^ DO |
| 1687 |
UndoReadWriteInfo(QuadNo, Operator, Operand1, Operand2, Operand3) ; |
| 1688 |
Operator := DummyOp ; (* finally blank it out *) |
| 1689 |
Operand1 := 0 ; |
| 1690 |
Operand2 := 0 ; |
| 1691 |
Operand3 := 0 ; |
| 1692 |
Trash := 0 ; |
| 1693 |
op1pos := UnknownTokenNo ; |
| 1694 |
op2pos := UnknownTokenNo ; |
| 1695 |
op3pos := UnknownTokenNo ; |
| 1696 |
ConstExpr := FALSE |
| 1697 |
END |
| 1698 |
END EraseQuad ; |
| 1699 |
|
| 1700 |
|
| 1701 |
(* |
| 1702 |
CheckAddVariableReadLeftValue - |
| 1703 |
*) |
| 1704 |
|
| 1705 |
(* |
| 1706 |
PROCEDURE CheckAddVariableReadLeftValue (sym: CARDINAL; q: CARDINAL) ; |
| 1707 |
BEGIN |
| 1708 |
IF IsVar(sym) |
| 1709 |
THEN |
| 1710 |
PutReadQuad(sym, LeftValue, q) |
| 1711 |
END |
| 1712 |
END CheckAddVariableReadLeftValue ; |
| 1713 |
*) |
| 1714 |
|
| 1715 |
|
| 1716 |
(* |
| 1717 |
CheckRemoveVariableReadLeftValue - |
| 1718 |
*) |
| 1719 |
|
| 1720 |
(* |
| 1721 |
PROCEDURE CheckRemoveVariableReadLeftValue (sym: CARDINAL; q: CARDINAL) ; |
| 1722 |
BEGIN |
| 1723 |
IF IsVar(sym) |
| 1724 |
THEN |
| 1725 |
RemoveReadQuad(sym, LeftValue, q) |
| 1726 |
END |
| 1727 |
END CheckRemoveVariableReadLeftValue ; |
| 1728 |
*) |
| 1729 |
|
| 1730 |
|
| 1731 |
(* |
| 1732 |
CheckAddTuple2Read - checks to see whether symbol tuple contains variables or |
| 1733 |
parameters and if so it then adds them to the quadruple |
| 1734 |
variable list. |
| 1735 |
*) |
| 1736 |
|
| 1737 |
PROCEDURE CheckAddTuple2Read (tuple: CARDINAL; canDereference: BOOLEAN; Quad: CARDINAL) ; |
| 1738 |
BEGIN |
| 1739 |
IF IsTuple (tuple) |
| 1740 |
THEN |
| 1741 |
CheckAddVariableRead (GetNth (tuple, 1), canDereference, Quad) ; |
| 1742 |
CheckAddVariableRead (GetNth (tuple, 2), canDereference, Quad) |
| 1743 |
END |
| 1744 |
END CheckAddTuple2Read ; |
| 1745 |
|
| 1746 |
|
| 1747 |
(* |
| 1748 |
CheckAddVariableRead - checks to see whether symbol, Sym, is a variable or |
| 1749 |
a parameter and if so it then adds this quadruple |
| 1750 |
to the variable list. |
| 1751 |
*) |
| 1752 |
|
| 1753 |
PROCEDURE CheckAddVariableRead (Sym: CARDINAL; canDereference: BOOLEAN; Quad: CARDINAL) ; |
| 1754 |
BEGIN |
| 1755 |
IF IsVar(Sym) |
| 1756 |
THEN |
| 1757 |
PutReadQuad(Sym, GetMode(Sym), Quad) ; |
| 1758 |
IF (GetMode(Sym)=LeftValue) AND canDereference |
| 1759 |
THEN |
| 1760 |
PutReadQuad(Sym, RightValue, Quad) |
| 1761 |
END |
| 1762 |
END |
| 1763 |
END CheckAddVariableRead ; |
| 1764 |
|
| 1765 |
|
| 1766 |
(* |
| 1767 |
CheckRemoveVariableRead - checks to see whether, Sym, is a variable or |
| 1768 |
a parameter and if so then it removes the |
| 1769 |
quadruple from the variable list. |
| 1770 |
*) |
| 1771 |
|
| 1772 |
PROCEDURE CheckRemoveVariableRead (Sym: CARDINAL; canDereference: BOOLEAN; Quad: CARDINAL) ; |
| 1773 |
BEGIN |
| 1774 |
IF IsVar(Sym) |
| 1775 |
THEN |
| 1776 |
RemoveReadQuad(Sym, GetMode(Sym), Quad) ; |
| 1777 |
IF (GetMode(Sym)=LeftValue) AND canDereference |
| 1778 |
THEN |
| 1779 |
RemoveReadQuad(Sym, RightValue, Quad) |
| 1780 |
END |
| 1781 |
END |
| 1782 |
END CheckRemoveVariableRead ; |
| 1783 |
|
| 1784 |
|
| 1785 |
(* |
| 1786 |
CheckAddVariableWrite - checks to see whether symbol, Sym, is a variable and |
| 1787 |
if so it then adds this quadruple to the variable list. |
| 1788 |
*) |
| 1789 |
|
| 1790 |
PROCEDURE CheckAddVariableWrite (Sym: CARDINAL; canDereference: BOOLEAN; Quad: CARDINAL) ; |
| 1791 |
BEGIN |
| 1792 |
IF IsVar(Sym) |
| 1793 |
THEN |
| 1794 |
IF (GetMode(Sym)=LeftValue) AND canDereference |
| 1795 |
THEN |
| 1796 |
PutReadQuad(Sym, LeftValue, Quad) ; |
| 1797 |
PutWriteQuad(Sym, RightValue, Quad) |
| 1798 |
ELSE |
| 1799 |
PutWriteQuad(Sym, GetMode(Sym), Quad) |
| 1800 |
END |
| 1801 |
END |
| 1802 |
END CheckAddVariableWrite ; |
| 1803 |
|
| 1804 |
|
| 1805 |
(* |
| 1806 |
CheckRemoveVariableWrite - checks to see whether, Sym, is a variable and |
| 1807 |
if so then it removes the quadruple from the |
| 1808 |
variable list. |
| 1809 |
*) |
| 1810 |
|
| 1811 |
PROCEDURE CheckRemoveVariableWrite (Sym: CARDINAL; canDereference: BOOLEAN; Quad: CARDINAL) ; |
| 1812 |
BEGIN |
| 1813 |
IF IsVar(Sym) |
| 1814 |
THEN |
| 1815 |
IF (GetMode(Sym)=LeftValue) AND canDereference |
| 1816 |
THEN |
| 1817 |
RemoveReadQuad(Sym, LeftValue, Quad) ; |
| 1818 |
RemoveWriteQuad(Sym, RightValue, Quad) |
| 1819 |
ELSE |
| 1820 |
RemoveWriteQuad(Sym, GetMode(Sym), Quad) |
| 1821 |
END |
| 1822 |
END |
| 1823 |
END CheckRemoveVariableWrite ; |
| 1824 |
|
| 1825 |
|
| 1826 |
(* |
| 1827 |
CheckConst - |
| 1828 |
*) |
| 1829 |
|
| 1830 |
PROCEDURE CheckConst (sym: CARDINAL) ; |
| 1831 |
BEGIN |
| 1832 |
IF IsConst(sym) |
| 1833 |
THEN |
| 1834 |
PutToBeSolvedByQuads(sym) |
| 1835 |
END |
| 1836 |
END CheckConst ; |
| 1837 |
|
| 1838 |
|
| 1839 |
(* |
| 1840 |
GetFirstQuad - returns the first quadruple. |
| 1841 |
*) |
| 1842 |
|
| 1843 |
PROCEDURE GetFirstQuad () : CARDINAL ; |
| 1844 |
BEGIN |
| 1845 |
RETURN( Head ) |
| 1846 |
END GetFirstQuad ; |
| 1847 |
|
| 1848 |
|
| 1849 |
(* |
| 1850 |
GetNextQuad - returns the Quadruple number following QuadNo. |
| 1851 |
*) |
| 1852 |
|
| 1853 |
PROCEDURE GetNextQuad (QuadNo: CARDINAL) : CARDINAL ; |
| 1854 |
VAR |
| 1855 |
f: QuadFrame ; |
| 1856 |
BEGIN |
| 1857 |
f := GetQF(QuadNo) ; |
| 1858 |
RETURN( f^.Next ) |
| 1859 |
END GetNextQuad ; |
| 1860 |
|
| 1861 |
|
| 1862 |
(* |
| 1863 |
SubQuad - subtracts a quadruple QuadNo from a list Head. |
| 1864 |
*) |
| 1865 |
|
| 1866 |
PROCEDURE SubQuad (QuadNo: CARDINAL) ; |
| 1867 |
VAR |
| 1868 |
i : CARDINAL ; |
| 1869 |
f, g: QuadFrame ; |
| 1870 |
BEGIN |
| 1871 |
CheckBreak (QuadNo) ; |
| 1872 |
f := GetQF(QuadNo) ; |
| 1873 |
WITH f^ DO |
| 1874 |
AlterReference(Head, QuadNo, f^.Next) ; |
| 1875 |
UndoReadWriteInfo(QuadNo, Operator, Operand1, Operand2, Operand3) |
| 1876 |
END ; |
| 1877 |
IF Head=QuadNo |
| 1878 |
THEN |
| 1879 |
Head := f^.Next |
| 1880 |
ELSE |
| 1881 |
i := Head ; |
| 1882 |
g := GetQF(i) ; |
| 1883 |
WHILE g^.Next#QuadNo DO |
| 1884 |
i := g^.Next ; |
| 1885 |
g := GetQF(i) |
| 1886 |
END ; |
| 1887 |
g^.Next := f^.Next |
| 1888 |
END ; |
| 1889 |
f^.Operator := DummyOp ; |
| 1890 |
DEC(NoOfQuads) |
| 1891 |
END SubQuad ; |
| 1892 |
|
| 1893 |
|
| 1894 |
(* |
| 1895 |
GetRealQuad - returns the Quadruple number of the real quadruple |
| 1896 |
at QuadNo or beyond. |
| 1897 |
*) |
| 1898 |
|
| 1899 |
PROCEDURE GetRealQuad (QuadNo: CARDINAL) : CARDINAL ; |
| 1900 |
VAR |
| 1901 |
f: QuadFrame ; |
| 1902 |
BEGIN |
| 1903 |
WHILE QuadNo#0 DO |
| 1904 |
IF InBounds(QuadArray, QuadNo) |
| 1905 |
THEN |
| 1906 |
f := GetQF(QuadNo) ; |
| 1907 |
WITH f^ DO |
| 1908 |
IF (NOT IsPseudoQuad(QuadNo)) AND |
| 1909 |
(Operator#DummyOp) AND (Operator#LineNumberOp) AND (Operator#StatementNoteOp) |
| 1910 |
THEN |
| 1911 |
RETURN( QuadNo ) |
| 1912 |
END |
| 1913 |
END ; |
| 1914 |
INC(QuadNo) |
| 1915 |
ELSE |
| 1916 |
RETURN( 0 ) |
| 1917 |
END |
| 1918 |
END ; |
| 1919 |
RETURN( 0 ) |
| 1920 |
END GetRealQuad ; |
| 1921 |
|
| 1922 |
|
| 1923 |
(* |
| 1924 |
AlterReference - alters all references from OldQuad, to NewQuad in a |
| 1925 |
quadruple list Head. |
| 1926 |
*) |
| 1927 |
|
| 1928 |
PROCEDURE AlterReference (Head, OldQuad, NewQuad: CARDINAL) ; |
| 1929 |
VAR |
| 1930 |
f, g: QuadFrame ; |
| 1931 |
i : CARDINAL ; |
| 1932 |
BEGIN |
| 1933 |
f := GetQF(OldQuad) ; |
| 1934 |
WHILE (f^.NoOfTimesReferenced>0) AND (Head#0) DO |
| 1935 |
g := GetQF(Head) ; |
| 1936 |
WITH g^ DO |
| 1937 |
CASE Operator OF |
| 1938 |
|
| 1939 |
IfInOp, |
| 1940 |
IfNotInOp, |
| 1941 |
IfEquOp, |
| 1942 |
IfNotEquOp, |
| 1943 |
IfLessOp, |
| 1944 |
IfLessEquOp, |
| 1945 |
IfGreOp, |
| 1946 |
IfGreEquOp, |
| 1947 |
TryOp, |
| 1948 |
RetryOp, |
| 1949 |
GotoOp : IF Operand3=OldQuad |
| 1950 |
THEN |
| 1951 |
ManipulateReference(Head, NewQuad) |
| 1952 |
END |
| 1953 |
|
| 1954 |
ELSE |
| 1955 |
END ; |
| 1956 |
i := Next |
| 1957 |
END ; |
| 1958 |
Head := i |
| 1959 |
END |
| 1960 |
END AlterReference ; |
| 1961 |
|
| 1962 |
|
| 1963 |
(* |
| 1964 |
GrowQuads - grows the list of quadruples to the quadruple, to. |
| 1965 |
*) |
| 1966 |
|
| 1967 |
PROCEDURE GrowQuads (to: CARDINAL) ; |
| 1968 |
VAR |
| 1969 |
i: CARDINAL ; |
| 1970 |
f: QuadFrame ; |
| 1971 |
BEGIN |
| 1972 |
IF (to#0) AND (to>GrowInitialization) |
| 1973 |
THEN |
| 1974 |
i := GrowInitialization+1 ; |
| 1975 |
WHILE i<=to DO |
| 1976 |
IF InBounds(QuadArray, i) |
| 1977 |
THEN |
| 1978 |
Assert(GetIndice(QuadArray, i)#NIL) |
| 1979 |
ELSE |
| 1980 |
NEW(f) ; |
| 1981 |
IF f=NIL |
| 1982 |
THEN |
| 1983 |
InternalError ('out of memory error when trying to allocate a quadruple') |
| 1984 |
END ; |
| 1985 |
PutIndice(QuadArray, i, f) ; |
| 1986 |
f^.NoOfTimesReferenced := 0 |
| 1987 |
END ; |
| 1988 |
INC(i) |
| 1989 |
END ; |
| 1990 |
GrowInitialization := to |
| 1991 |
END |
| 1992 |
END GrowQuads ; |
| 1993 |
|
| 1994 |
|
| 1995 |
(* |
| 1996 |
ManipulateReference - manipulates the quadruple, q, so that it now points to quad, to. |
| 1997 |
*) |
| 1998 |
|
| 1999 |
PROCEDURE ManipulateReference (q: CARDINAL; to: CARDINAL) ; |
| 2000 |
VAR |
| 2001 |
f: QuadFrame ; |
| 2002 |
BEGIN |
| 2003 |
Assert((GrowInitialization>=q) OR (to=0)) ; |
| 2004 |
GrowQuads(to) ; |
| 2005 |
RemoveReference(q) ; |
| 2006 |
f := GetQF(q) ; |
| 2007 |
f^.Operand3 := to ; |
| 2008 |
IF to#0 |
| 2009 |
THEN |
| 2010 |
f := GetQF(to) ; |
| 2011 |
INC(f^.NoOfTimesReferenced) |
| 2012 |
END |
| 2013 |
END ManipulateReference ; |
| 2014 |
|
| 2015 |
|
| 2016 |
(* |
| 2017 |
RemoveReference - remove the reference by quadruple q to wherever |
| 2018 |
it was pointing. |
| 2019 |
*) |
| 2020 |
|
| 2021 |
PROCEDURE RemoveReference (q: CARDINAL) ; |
| 2022 |
VAR |
| 2023 |
f, g: QuadFrame ; |
| 2024 |
BEGIN |
| 2025 |
f := GetQF(q) ; |
| 2026 |
IF (f^.Operand3#0) AND (f^.Operand3<NextQuad) |
| 2027 |
THEN |
| 2028 |
CheckBreak (f^.Operand3) ; |
| 2029 |
g := GetQF(f^.Operand3) ; |
| 2030 |
Assert(g^.NoOfTimesReferenced#0) ; |
| 2031 |
DEC(g^.NoOfTimesReferenced) |
| 2032 |
END |
| 2033 |
END RemoveReference ; |
| 2034 |
|
| 2035 |
|
| 2036 |
(* |
| 2037 |
CountQuads - returns the number of quadruples. |
| 2038 |
*) |
| 2039 |
|
| 2040 |
PROCEDURE CountQuads () : CARDINAL ; |
| 2041 |
BEGIN |
| 2042 |
RETURN( NoOfQuads ) |
| 2043 |
END CountQuads ; |
| 2044 |
|
| 2045 |
|
| 2046 |
(* |
| 2047 |
NewQuad - sets QuadNo to a new quadruple. |
| 2048 |
*) |
| 2049 |
|
| 2050 |
PROCEDURE NewQuad (VAR QuadNo: CARDINAL) ; |
| 2051 |
VAR |
| 2052 |
f: QuadFrame ; |
| 2053 |
BEGIN |
| 2054 |
QuadNo := FreeList ; |
| 2055 |
IF InBounds (QuadArray, QuadNo) AND (GetIndice (QuadArray, QuadNo) # NIL) |
| 2056 |
THEN |
| 2057 |
f := GetIndice (QuadArray, QuadNo) |
| 2058 |
ELSE |
| 2059 |
NEW (f) ; |
| 2060 |
IF f=NIL |
| 2061 |
THEN |
| 2062 |
InternalError ('out of memory error trying to allocate a quadruple') |
| 2063 |
ELSE |
| 2064 |
INC (NoOfQuads) ; |
| 2065 |
PutIndice (QuadArray, QuadNo, f) ; |
| 2066 |
f^.NoOfTimesReferenced := 0 |
| 2067 |
END |
| 2068 |
END ; |
| 2069 |
WITH f^ DO |
| 2070 |
Operator := DummyOp ; |
| 2071 |
Operand3 := 0 ; |
| 2072 |
Next := 0 |
| 2073 |
END ; |
| 2074 |
INC (FreeList) ; |
| 2075 |
IF GrowInitialization < FreeList |
| 2076 |
THEN |
| 2077 |
GrowInitialization := FreeList |
| 2078 |
END |
| 2079 |
END NewQuad ; |
| 2080 |
|
| 2081 |
|
| 2082 |
(* |
| 2083 |
CheckVariableAt - checks to see whether, sym, was declared at a particular address. |
| 2084 |
*) |
| 2085 |
|
| 2086 |
PROCEDURE CheckVariableAt (sym: CARDINAL) ; |
| 2087 |
BEGIN |
| 2088 |
IF IsVar (sym) AND IsVariableAtAddress (sym) |
| 2089 |
THEN |
| 2090 |
IF GetMode (sym) = LeftValue |
| 2091 |
THEN |
| 2092 |
GenQuad (InitAddressOp, sym, NulSym, GetVariableAtAddress (sym)) |
| 2093 |
ELSE |
| 2094 |
InternalError ('expecting lvalue for this variable which is declared at an explicit address') |
| 2095 |
END |
| 2096 |
END |
| 2097 |
END CheckVariableAt ; |
| 2098 |
|
| 2099 |
|
| 2100 |
(* |
| 2101 |
CheckVariablesAt - checks to see whether we need to initialize any pointers |
| 2102 |
which point to variable declared at addresses. |
| 2103 |
*) |
| 2104 |
|
| 2105 |
PROCEDURE CheckVariablesAt (scope: CARDINAL) ; |
| 2106 |
BEGIN |
| 2107 |
ForeachLocalSymDo (scope, CheckVariableAt) |
| 2108 |
END CheckVariablesAt ; |
| 2109 |
|
| 2110 |
|
| 2111 |
(* |
| 2112 |
GetTurnInterrupts - returns the TurnInterrupts procedure function. |
| 2113 |
*) |
| 2114 |
|
| 2115 |
PROCEDURE GetTurnInterrupts (tok: CARDINAL) : CARDINAL ; |
| 2116 |
BEGIN |
| 2117 |
IF Iso |
| 2118 |
THEN |
| 2119 |
RETURN GetQualidentImport (tok, |
| 2120 |
MakeKey ('TurnInterrupts'), MakeKey ('COROUTINES')) |
| 2121 |
ELSE |
| 2122 |
RETURN GetQualidentImport (tok, |
| 2123 |
MakeKey ('TurnInterrupts'), MakeKey ('SYSTEM')) |
| 2124 |
END |
| 2125 |
END GetTurnInterrupts ; |
| 2126 |
|
| 2127 |
|
| 2128 |
(* |
| 2129 |
GetProtection - returns the PROTECTION data type. |
| 2130 |
*) |
| 2131 |
|
| 2132 |
PROCEDURE GetProtection (tok: CARDINAL) : CARDINAL ; |
| 2133 |
BEGIN |
| 2134 |
IF Iso |
| 2135 |
THEN |
| 2136 |
RETURN GetQualidentImport (tok, |
| 2137 |
MakeKey ('PROTECTION'), MakeKey ('COROUTINES')) |
| 2138 |
ELSE |
| 2139 |
RETURN GetQualidentImport (tok, |
| 2140 |
MakeKey ('PROTECTION'), MakeKey ('SYSTEM')) |
| 2141 |
END |
| 2142 |
END GetProtection ; |
| 2143 |
|
| 2144 |
|
| 2145 |
(* |
| 2146 |
CheckNeedPriorityBegin - checks to see whether we need to save the old |
| 2147 |
module priority and change to another module |
| 2148 |
priority. |
| 2149 |
The current module initialization or procedure |
| 2150 |
being built is defined by, scope. The module whose |
| 2151 |
priority will be used is defined by, module. |
| 2152 |
*) |
| 2153 |
|
| 2154 |
PROCEDURE CheckNeedPriorityBegin (tok: CARDINAL; scope, module: CARDINAL) ; |
| 2155 |
VAR |
| 2156 |
ProcSym, old: CARDINAL ; |
| 2157 |
BEGIN |
| 2158 |
IF GetPriority (module) # NulSym |
| 2159 |
THEN |
| 2160 |
(* module has been given a priority *) |
| 2161 |
ProcSym := GetTurnInterrupts (tok) ; |
| 2162 |
IF ProcSym # NulSym |
| 2163 |
THEN |
| 2164 |
old := MakeTemporary (tok, RightValue) ; |
| 2165 |
PutVar (old, GetProtection (tok)) ; |
| 2166 |
|
| 2167 |
GenQuadO (tok, SavePriorityOp, old, scope, ProcSym, FALSE) ; |
| 2168 |
PushWord (PriorityStack, old) |
| 2169 |
END |
| 2170 |
END |
| 2171 |
END CheckNeedPriorityBegin ; |
| 2172 |
|
| 2173 |
|
| 2174 |
(* |
| 2175 |
CheckNeedPriorityEnd - checks to see whether we need to restore the old |
| 2176 |
module priority. |
| 2177 |
The current module initialization or procedure |
| 2178 |
being built is defined by, scope. |
| 2179 |
*) |
| 2180 |
|
| 2181 |
PROCEDURE CheckNeedPriorityEnd (tok: CARDINAL; |
| 2182 |
scope, module: CARDINAL) ; |
| 2183 |
VAR |
| 2184 |
ProcSym, old: CARDINAL ; |
| 2185 |
BEGIN |
| 2186 |
IF GetPriority (module) # NulSym |
| 2187 |
THEN |
| 2188 |
(* module has been given a priority *) |
| 2189 |
ProcSym := GetTurnInterrupts (tok) ; |
| 2190 |
IF ProcSym # NulSym |
| 2191 |
THEN |
| 2192 |
old := PopWord (PriorityStack) ; |
| 2193 |
GenQuad (RestorePriorityOp, old, scope, ProcSym) |
| 2194 |
END |
| 2195 |
END |
| 2196 |
END CheckNeedPriorityEnd ; |
| 2197 |
|
| 2198 |
|
| 2199 |
(* |
| 2200 |
StartBuildDefFile - generates a StartFileDefOp quadruple indicating the file |
| 2201 |
that has produced the subsequent quadruples. |
| 2202 |
The code generator uses the StartDefFileOp quadruples |
| 2203 |
to relate any error to the appropriate file. |
| 2204 |
|
| 2205 |
|
| 2206 |
Entry Exit |
| 2207 |
===== ==== |
| 2208 |
|
| 2209 |
|
| 2210 |
Ptr -> <- Ptr |
| 2211 |
+------------+ +------------+ |
| 2212 |
| ModuleName | | ModuleName | |
| 2213 |
|------------| |------------| |
| 2214 |
|
| 2215 |
|
| 2216 |
Quadruples Produced |
| 2217 |
|
| 2218 |
q StartDefFileOp _ _ ModuleSym |
| 2219 |
*) |
| 2220 |
|
| 2221 |
PROCEDURE StartBuildDefFile (tok: CARDINAL) ; |
| 2222 |
VAR |
| 2223 |
ModuleName: Name ; |
| 2224 |
BEGIN |
| 2225 |
PopT (ModuleName) ; |
| 2226 |
PushT (ModuleName) ; |
| 2227 |
GenQuadO (tok, StartDefFileOp, tok, NulSym, GetModule (ModuleName), FALSE) |
| 2228 |
END StartBuildDefFile ; |
| 2229 |
|
| 2230 |
|
| 2231 |
(* |
| 2232 |
StartBuildModFile - generates a StartModFileOp quadruple indicating the file |
| 2233 |
that has produced the subsequent quadruples. |
| 2234 |
The code generator uses the StartModFileOp quadruples |
| 2235 |
to relate any error to the appropriate file. |
| 2236 |
|
| 2237 |
|
| 2238 |
Entry Exit |
| 2239 |
===== ==== |
| 2240 |
|
| 2241 |
|
| 2242 |
Ptr -> <- Ptr |
| 2243 |
+------------+ +------------+ |
| 2244 |
| ModuleName | | ModuleName | |
| 2245 |
|------------| |------------| |
| 2246 |
|
| 2247 |
|
| 2248 |
Quadruples Produced |
| 2249 |
|
| 2250 |
q StartModFileOp lineno filename ModuleSym |
| 2251 |
*) |
| 2252 |
|
| 2253 |
PROCEDURE StartBuildModFile (tok: CARDINAL) ; |
| 2254 |
BEGIN |
| 2255 |
GenQuadO (tok, StartModFileOp, tok, |
| 2256 |
WORD (makekey (string (GetFileName ()))), |
| 2257 |
GetFileModule (), FALSE) |
| 2258 |
END StartBuildModFile ; |
| 2259 |
|
| 2260 |
|
| 2261 |
(* |
| 2262 |
EndBuildFile - generates an EndFileOp quadruple indicating the file |
| 2263 |
that has produced the previous quadruples has ended. |
| 2264 |
|
| 2265 |
Entry Exit |
| 2266 |
===== ==== |
| 2267 |
|
| 2268 |
|
| 2269 |
Ptr -> <- Ptr |
| 2270 |
+------------+ +------------+ |
| 2271 |
| ModuleName | | ModuleName | |
| 2272 |
|------------| |------------| |
| 2273 |
|
| 2274 |
|
| 2275 |
Quadruples Produced |
| 2276 |
|
| 2277 |
q EndFileOp _ _ ModuleSym |
| 2278 |
*) |
| 2279 |
|
| 2280 |
PROCEDURE EndBuildFile (tok: CARDINAL) ; |
| 2281 |
VAR |
| 2282 |
ModuleName: Name ; |
| 2283 |
BEGIN |
| 2284 |
ModuleName := OperandT (1) ; |
| 2285 |
GenQuadO (tok, EndFileOp, NulSym, NulSym, GetModule (ModuleName), FALSE) |
| 2286 |
END EndBuildFile ; |
| 2287 |
|
| 2288 |
|
| 2289 |
(* |
| 2290 |
StartBuildInit - Sets the start of initialization code of the |
| 2291 |
current module to the next quadruple. |
| 2292 |
*) |
| 2293 |
|
| 2294 |
PROCEDURE StartBuildInit (tok: CARDINAL) ; |
| 2295 |
VAR |
| 2296 |
name : Name ; |
| 2297 |
ModuleSym: CARDINAL ; |
| 2298 |
BEGIN |
| 2299 |
PopT(name) ; |
| 2300 |
ModuleSym := GetCurrentModule() ; |
| 2301 |
Assert(IsModule(ModuleSym) OR IsDefImp(ModuleSym)) ; |
| 2302 |
Assert(GetSymName(ModuleSym)=name) ; |
| 2303 |
PutModuleStartQuad(ModuleSym, NextQuad) ; |
| 2304 |
GenQuad(InitStartOp, tok, GetFileModule(), ModuleSym) ; |
| 2305 |
PushWord(ReturnStack, 0) ; |
| 2306 |
PushT(name) ; |
| 2307 |
CheckVariablesAt(ModuleSym) ; |
| 2308 |
CheckNeedPriorityBegin(tok, ModuleSym, ModuleSym) ; |
| 2309 |
PushWord(TryStack, NextQuad) ; |
| 2310 |
PushWord(CatchStack, 0) ; |
| 2311 |
IF HasExceptionBlock(ModuleSym) |
| 2312 |
THEN |
| 2313 |
GenQuad(TryOp, NulSym, NulSym, 0) |
| 2314 |
END |
| 2315 |
END StartBuildInit ; |
| 2316 |
|
| 2317 |
|
| 2318 |
(* |
| 2319 |
EndBuildInit - Sets the end initialization code of a module. |
| 2320 |
*) |
| 2321 |
|
| 2322 |
PROCEDURE EndBuildInit (tok: CARDINAL) ; |
| 2323 |
BEGIN |
| 2324 |
IF HasExceptionBlock(GetCurrentModule()) |
| 2325 |
THEN |
| 2326 |
BuildRTExceptLeave (tok, TRUE) ; |
| 2327 |
GenQuadO (tok, CatchEndOp, NulSym, NulSym, NulSym, FALSE) |
| 2328 |
END ; |
| 2329 |
BackPatch (PopWord (ReturnStack), NextQuad) ; |
| 2330 |
CheckNeedPriorityEnd (tok, GetCurrentModule(), GetCurrentModule()) ; |
| 2331 |
PutModuleEndQuad (GetCurrentModule(), NextQuad) ; |
| 2332 |
CheckVariablesInBlock (GetCurrentModule()) ; |
| 2333 |
GenQuadO (tok, InitEndOp, tok, GetFileModule(), GetCurrentModule(), FALSE) |
| 2334 |
END EndBuildInit ; |
| 2335 |
|
| 2336 |
|
| 2337 |
(* |
| 2338 |
StartBuildFinally - Sets the start of finalization code of the |
| 2339 |
current module to the next quadruple. |
| 2340 |
*) |
| 2341 |
|
| 2342 |
PROCEDURE StartBuildFinally (tok: CARDINAL) ; |
| 2343 |
VAR |
| 2344 |
name : Name ; |
| 2345 |
ModuleSym: CARDINAL ; |
| 2346 |
BEGIN |
| 2347 |
PopT(name) ; |
| 2348 |
ModuleSym := GetCurrentModule() ; |
| 2349 |
Assert(IsModule(ModuleSym) OR IsDefImp(ModuleSym)) ; |
| 2350 |
Assert(GetSymName(ModuleSym)=name) ; |
| 2351 |
PutModuleFinallyStartQuad(ModuleSym, NextQuad) ; |
| 2352 |
GenQuadO (tok, FinallyStartOp, tok, GetFileModule(), ModuleSym, FALSE) ; |
| 2353 |
PushWord (ReturnStack, 0) ; |
| 2354 |
PushT (name) ; |
| 2355 |
(* CheckVariablesAt(ModuleSym) ; *) |
| 2356 |
CheckNeedPriorityBegin (tok, ModuleSym, ModuleSym) ; |
| 2357 |
PushWord (TryStack, NextQuad) ; |
| 2358 |
PushWord (CatchStack, 0) ; |
| 2359 |
IF HasExceptionFinally (ModuleSym) |
| 2360 |
THEN |
| 2361 |
GenQuadO (tok, TryOp, NulSym, NulSym, 0, FALSE) |
| 2362 |
END |
| 2363 |
END StartBuildFinally ; |
| 2364 |
|
| 2365 |
|
| 2366 |
(* |
| 2367 |
EndBuildFinally - Sets the end finalization code of a module. |
| 2368 |
*) |
| 2369 |
|
| 2370 |
PROCEDURE EndBuildFinally (tok: CARDINAL) ; |
| 2371 |
BEGIN |
| 2372 |
IF HasExceptionFinally(GetCurrentModule()) |
| 2373 |
THEN |
| 2374 |
BuildRTExceptLeave (tok, TRUE) ; |
| 2375 |
GenQuadO (tok, CatchEndOp, NulSym, NulSym, NulSym, FALSE) |
| 2376 |
END ; |
| 2377 |
BackPatch (PopWord (ReturnStack), NextQuad) ; |
| 2378 |
CheckNeedPriorityEnd (tok, GetCurrentModule (), GetCurrentModule ()) ; |
| 2379 |
PutModuleFinallyEndQuad(GetCurrentModule (), NextQuad) ; |
| 2380 |
CheckVariablesInBlock (GetCurrentModule ()) ; |
| 2381 |
GenQuadO (tok, FinallyEndOp, tok, GetFileModule (), |
| 2382 |
GetCurrentModule(), FALSE) |
| 2383 |
END EndBuildFinally ; |
| 2384 |
|
| 2385 |
|
| 2386 |
(* |
| 2387 |
BuildRTExceptEnter - informs RTExceptions that we are about to enter the except state. |
| 2388 |
*) |
| 2389 |
|
| 2390 |
PROCEDURE BuildRTExceptEnter (tok: CARDINAL) ; |
| 2391 |
VAR |
| 2392 |
old, |
| 2393 |
ProcSym: CARDINAL ; |
| 2394 |
BEGIN |
| 2395 |
IF Exceptions |
| 2396 |
THEN |
| 2397 |
(* now inform the Modula-2 runtime we are in the exception state *) |
| 2398 |
ProcSym := GetQualidentImport (tok, |
| 2399 |
MakeKey('SetExceptionState'), MakeKey('RTExceptions')) ; |
| 2400 |
IF ProcSym=NulSym |
| 2401 |
THEN |
| 2402 |
MetaErrorT0 (tok, |
| 2403 |
'{%W}no procedure SetExceptionState found in RTExceptions which is needed to implement exception handling') |
| 2404 |
ELSE |
| 2405 |
old := MakeTemporary (tok, RightValue) ; |
| 2406 |
PutVar (old, Boolean) ; |
| 2407 |
GenQuadO (tok, SaveExceptionOp, old, NulSym, ProcSym, FALSE) ; |
| 2408 |
PushWord (ExceptStack, old) |
| 2409 |
END |
| 2410 |
ELSE |
| 2411 |
MetaErrorT0 (tok, |
| 2412 |
'{%E}cannot use {%kEXCEPT} blocks with the -fno-exceptions flag') |
| 2413 |
END |
| 2414 |
END BuildRTExceptEnter ; |
| 2415 |
|
| 2416 |
|
| 2417 |
(* |
| 2418 |
BuildRTExceptLeave - informs RTExceptions that we are about to leave the except state. |
| 2419 |
If, destroy, is TRUE then pop the ExceptStack. |
| 2420 |
*) |
| 2421 |
|
| 2422 |
PROCEDURE BuildRTExceptLeave (tok: CARDINAL; destroy: BOOLEAN) ; |
| 2423 |
VAR |
| 2424 |
old, |
| 2425 |
ProcSym: CARDINAL ; |
| 2426 |
BEGIN |
| 2427 |
IF Exceptions |
| 2428 |
THEN |
| 2429 |
(* now inform the Modula-2 runtime we are in the exception state *) |
| 2430 |
ProcSym := GetQualidentImport (tok, |
| 2431 |
MakeKey('SetExceptionState'), MakeKey('RTExceptions')) ; |
| 2432 |
IF ProcSym#NulSym |
| 2433 |
THEN |
| 2434 |
IF destroy |
| 2435 |
THEN |
| 2436 |
old := PopWord (ExceptStack) |
| 2437 |
ELSE |
| 2438 |
old := PeepWord (ExceptStack, 1) |
| 2439 |
END ; |
| 2440 |
GenQuadO (tok, RestoreExceptionOp, old, NulSym, ProcSym, FALSE) |
| 2441 |
END |
| 2442 |
ELSE |
| 2443 |
(* no need for an error message here as it will be generated in the Enter procedure above *) |
| 2444 |
END |
| 2445 |
END BuildRTExceptLeave ; |
| 2446 |
|
| 2447 |
|
| 2448 |
(* |
| 2449 |
BuildExceptInitial - adds an CatchBeginOp, CatchEndOp quadruple |
| 2450 |
in the current block. |
| 2451 |
*) |
| 2452 |
|
| 2453 |
PROCEDURE BuildExceptInitial (tok: CARDINAL) ; |
| 2454 |
VAR |
| 2455 |
previous: CARDINAL ; |
| 2456 |
BEGIN |
| 2457 |
(* we have finished the 'try' block, so now goto the return |
| 2458 |
section which will tidy up (any) priorities before returning. |
| 2459 |
*) |
| 2460 |
GenQuadO (tok, GotoOp, NulSym, NulSym, PopWord(ReturnStack), FALSE) ; |
| 2461 |
PushWord (ReturnStack, NextQuad-1) ; |
| 2462 |
(* |
| 2463 |
this is the 'catch' block. |
| 2464 |
*) |
| 2465 |
BackPatch (PeepWord (TryStack, 1), NextQuad) ; |
| 2466 |
GenQuadO (tok, CatchBeginOp, NulSym, NulSym, NulSym, FALSE) ; |
| 2467 |
previous := PopWord (CatchStack) ; |
| 2468 |
IF previous # 0 |
| 2469 |
THEN |
| 2470 |
MetaErrorT0 (tok, |
| 2471 |
'{%E}only allowed one EXCEPT statement in a procedure or module') |
| 2472 |
END ; |
| 2473 |
PushWord (CatchStack, NextQuad-1) ; |
| 2474 |
BuildRTExceptEnter (tok) |
| 2475 |
END BuildExceptInitial ; |
| 2476 |
|
| 2477 |
|
| 2478 |
(* |
| 2479 |
BuildExceptFinally - adds an ExceptOp quadruple in a modules |
| 2480 |
finally block. |
| 2481 |
*) |
| 2482 |
|
| 2483 |
PROCEDURE BuildExceptFinally (tok: CARDINAL) ; |
| 2484 |
BEGIN |
| 2485 |
BuildExceptInitial (tok) |
| 2486 |
END BuildExceptFinally ; |
| 2487 |
|
| 2488 |
|
| 2489 |
(* |
| 2490 |
BuildExceptProcedure - adds an ExceptOp quadruple in a procedure |
| 2491 |
block. |
| 2492 |
*) |
| 2493 |
|
| 2494 |
PROCEDURE BuildExceptProcedure (tok: CARDINAL) ; |
| 2495 |
BEGIN |
| 2496 |
BuildExceptInitial (tok) |
| 2497 |
END BuildExceptProcedure ; |
| 2498 |
|
| 2499 |
|
| 2500 |
(* |
| 2501 |
BuildRetry - adds an RetryOp quadruple. |
| 2502 |
*) |
| 2503 |
|
| 2504 |
PROCEDURE BuildRetry (tok: CARDINAL); |
| 2505 |
BEGIN |
| 2506 |
IF PeepWord (CatchStack, 1) = 0 |
| 2507 |
THEN |
| 2508 |
MetaErrorT0 (tok, |
| 2509 |
'{%E}the {%kRETRY} statement must occur after an {%kEXCEPT} statement in the same module or procedure block') |
| 2510 |
ELSE |
| 2511 |
BuildRTExceptLeave (tok, FALSE) ; |
| 2512 |
GenQuadO (tok, RetryOp, NulSym, NulSym, PeepWord (TryStack, 1), FALSE) |
| 2513 |
END |
| 2514 |
END BuildRetry ; |
| 2515 |
|
| 2516 |
|
| 2517 |
(* |
| 2518 |
SafeRequestSym - only used during scaffold to get argc, argv, envp. |
| 2519 |
It attempts to get symbol name from the current scope(s) and if |
| 2520 |
it fails then it falls back onto default constants. |
| 2521 |
*) |
| 2522 |
|
| 2523 |
PROCEDURE SafeRequestSym (tok: CARDINAL; name: Name) : CARDINAL ; |
| 2524 |
VAR |
| 2525 |
sym: CARDINAL ; |
| 2526 |
BEGIN |
| 2527 |
sym := GetSym (name) ; |
| 2528 |
IF sym = NulSym |
| 2529 |
THEN |
| 2530 |
IF name = MakeKey ('argc') |
| 2531 |
THEN |
| 2532 |
RETURN MakeConstLit (tok, MakeKey ('0'), ZType) |
| 2533 |
ELSIF (name = MakeKey ('argv')) OR (name = MakeKey ('envp')) |
| 2534 |
THEN |
| 2535 |
RETURN Nil |
| 2536 |
ELSE |
| 2537 |
InternalError ('not expecting this parameter name') ; |
| 2538 |
RETURN Nil |
| 2539 |
END |
| 2540 |
END ; |
| 2541 |
RETURN sym |
| 2542 |
END SafeRequestSym ; |
| 2543 |
|
| 2544 |
|
| 2545 |
(* |
| 2546 |
callRequestDependant - create a call: |
| 2547 |
RequestDependant (GetSymName (modulesym), GetLibName (modulesym), |
| 2548 |
GetSymName (depModuleSym), GetLibName (depModuleSym)); |
| 2549 |
*) |
| 2550 |
|
| 2551 |
PROCEDURE callRequestDependant (tokno: CARDINAL; |
| 2552 |
moduleSym, depModuleSym: CARDINAL; |
| 2553 |
requestDep: CARDINAL) ; |
| 2554 |
BEGIN |
| 2555 |
Assert (requestDep # NulSym) ; |
| 2556 |
PushTtok (requestDep, tokno) ; |
| 2557 |
PushTFtok (Adr, Address, tokno) ; |
| 2558 |
PushTtok (MakeConstString (tokno, GetSymName (moduleSym)), tokno) ; |
| 2559 |
PushT (1) ; |
| 2560 |
BuildAdrFunction ; |
| 2561 |
|
| 2562 |
PushTFtok (Adr, Address, tokno) ; |
| 2563 |
PushTtok (MakeConstString (tokno, GetLibName (moduleSym)), tokno) ; |
| 2564 |
PushT (1) ; |
| 2565 |
BuildAdrFunction ; |
| 2566 |
|
| 2567 |
IF depModuleSym = NulSym |
| 2568 |
THEN |
| 2569 |
PushTF (Nil, Address) ; |
| 2570 |
PushTF (Nil, Address) |
| 2571 |
ELSE |
| 2572 |
PushTFtok (Adr, Address, tokno) ; |
| 2573 |
PushTtok (MakeConstString (tokno, GetSymName (depModuleSym)), tokno) ; |
| 2574 |
PushT (1) ; |
| 2575 |
BuildAdrFunction ; |
| 2576 |
|
| 2577 |
PushTFtok (Adr, Address, tokno) ; |
| 2578 |
PushTtok (MakeConstString (tokno, GetLibName (depModuleSym)), tokno) ; |
| 2579 |
PushT (1) ; |
| 2580 |
BuildAdrFunction |
| 2581 |
END ; |
| 2582 |
|
| 2583 |
PushT (4) ; |
| 2584 |
BuildProcedureCall (tokno) |
| 2585 |
END callRequestDependant ; |
| 2586 |
|
| 2587 |
|
| 2588 |
(* |
| 2589 |
ForeachImportInDepDo - |
| 2590 |
*) |
| 2591 |
|
| 2592 |
PROCEDURE ForeachImportInDepDo (importStatements: List; moduleSym, requestDep: CARDINAL) ; |
| 2593 |
VAR |
| 2594 |
i, j, |
| 2595 |
m, n : CARDINAL ; |
| 2596 |
imported, |
| 2597 |
stmt : CARDINAL ; |
| 2598 |
l : List ; |
| 2599 |
BEGIN |
| 2600 |
IF importStatements # NIL |
| 2601 |
THEN |
| 2602 |
i := 1 ; |
| 2603 |
n := NoOfItemsInList (importStatements) ; |
| 2604 |
WHILE i <= n DO |
| 2605 |
stmt := GetItemFromList (importStatements, i) ; |
| 2606 |
Assert (IsImportStatement (stmt)) ; |
| 2607 |
l := GetImportStatementList (stmt) ; |
| 2608 |
j := 1 ; |
| 2609 |
m := NoOfItemsInList (l) ; |
| 2610 |
WHILE j <= m DO |
| 2611 |
imported := GetItemFromList (l, j) ; |
| 2612 |
Assert (IsImport (imported)) ; |
| 2613 |
callRequestDependant (GetImportDeclared (imported), |
| 2614 |
moduleSym, GetImportModule (imported), |
| 2615 |
requestDep) ; |
| 2616 |
INC (j) ; |
| 2617 |
END ; |
| 2618 |
INC (i) |
| 2619 |
END |
| 2620 |
END |
| 2621 |
END ForeachImportInDepDo ; |
| 2622 |
|
| 2623 |
|
| 2624 |
(* |
| 2625 |
ForeachImportedModuleDo - |
| 2626 |
*) |
| 2627 |
|
| 2628 |
PROCEDURE ForeachImportedModuleDo (moduleSym, requestDep: CARDINAL) ; |
| 2629 |
VAR |
| 2630 |
importStatements: List ; |
| 2631 |
BEGIN |
| 2632 |
importStatements := GetModuleModImportStatementList (moduleSym) ; |
| 2633 |
ForeachImportInDepDo (importStatements, moduleSym, requestDep) ; |
| 2634 |
importStatements := GetModuleDefImportStatementList (moduleSym) ; |
| 2635 |
ForeachImportInDepDo (importStatements, moduleSym, requestDep) |
| 2636 |
END ForeachImportedModuleDo ; |
| 2637 |
|
| 2638 |
|
| 2639 |
(* |
| 2640 |
BuildM2DepFunction - creates the dependency graph procedure using IR: |
| 2641 |
static void |
| 2642 |
dependencies (void) |
| 2643 |
{ |
| 2644 |
M2RTS_RequestDependant (module_name, libname, "b", "b libname"); |
| 2645 |
M2RTS_RequestDependant (module_name, libname, NULL, NULL); |
| 2646 |
} |
| 2647 |
*) |
| 2648 |
|
| 2649 |
PROCEDURE BuildM2DepFunction (tokno: CARDINAL; moduleSym: CARDINAL) ; |
| 2650 |
VAR |
| 2651 |
requestDep, |
| 2652 |
ctor, init, fini, dep: CARDINAL ; |
| 2653 |
BEGIN |
| 2654 |
IF ScaffoldDynamic |
| 2655 |
THEN |
| 2656 |
(* Scaffold required and dynamic dependency graph should be produced. *) |
| 2657 |
GetModuleCtors (moduleSym, ctor, init, fini, dep) ; |
| 2658 |
PushT (dep) ; |
| 2659 |
BuildProcedureStart ; |
| 2660 |
BuildProcedureBegin ; |
| 2661 |
StartScope (dep) ; |
| 2662 |
requestDep := GetQualidentImport (tokno, |
| 2663 |
MakeKey ("RequestDependant"), |
| 2664 |
MakeKey ("M2RTS")) ; |
| 2665 |
IF requestDep # NulSym |
| 2666 |
THEN |
| 2667 |
ForeachImportedModuleDo (moduleSym, requestDep) ; |
| 2668 |
callRequestDependant (tokno, moduleSym, NulSym, requestDep) |
| 2669 |
END ; |
| 2670 |
EndScope ; |
| 2671 |
BuildProcedureEnd ; |
| 2672 |
PopN (1) |
| 2673 |
END |
| 2674 |
END BuildM2DepFunction ; |
| 2675 |
|
| 2676 |
|
| 2677 |
(* |
| 2678 |
BuildM2LinkFunction - creates the _M2_link procedure which will |
| 2679 |
cause the linker to pull in all the module ctors. |
| 2680 |
*) |
| 2681 |
|
| 2682 |
PROCEDURE BuildM2LinkFunction (tokno: CARDINAL) ; |
| 2683 |
BEGIN |
| 2684 |
IF ScaffoldDynamic |
| 2685 |
THEN |
| 2686 |
IF linkFunction # NulSym |
| 2687 |
THEN |
| 2688 |
(* void |
| 2689 |
_M2_link (void) |
| 2690 |
{ |
| 2691 |
for each module in uselist do |
| 2692 |
PROC foo_%d = _M2_module_ctor |
| 2693 |
done |
| 2694 |
}. *) |
| 2695 |
PushT (linkFunction) ; |
| 2696 |
BuildProcedureStart ; |
| 2697 |
BuildProcedureBegin ; |
| 2698 |
StartScope (linkFunction) ; |
| 2699 |
PopulateCtorArray (tokno) ; |
| 2700 |
EndScope ; |
| 2701 |
BuildProcedureEnd ; |
| 2702 |
PopN (1) |
| 2703 |
END |
| 2704 |
END |
| 2705 |
END BuildM2LinkFunction ; |
| 2706 |
|
| 2707 |
|
| 2708 |
(* |
| 2709 |
BuildTry - build the try statement for main. |
| 2710 |
*) |
| 2711 |
|
| 2712 |
PROCEDURE BuildTry (tokno: CARDINAL) ; |
| 2713 |
BEGIN |
| 2714 |
IF Exceptions |
| 2715 |
THEN |
| 2716 |
PushWord (TryStack, NextQuad) ; |
| 2717 |
PushWord (CatchStack, 0) ; |
| 2718 |
GenQuadO (tokno, TryOp, NulSym, NulSym, 0, FALSE) |
| 2719 |
END |
| 2720 |
END BuildTry ; |
| 2721 |
|
| 2722 |
|
| 2723 |
(* |
| 2724 |
BuildExcept - build the except block for main. |
| 2725 |
*) |
| 2726 |
|
| 2727 |
PROCEDURE BuildExcept (tokno: CARDINAL) ; |
| 2728 |
VAR |
| 2729 |
catchProcedure: CARDINAL ; |
| 2730 |
BEGIN |
| 2731 |
IF Exceptions |
| 2732 |
THEN |
| 2733 |
BuildExceptInitial (tokno) ; |
| 2734 |
catchProcedure := GetQualidentImport (tokno, |
| 2735 |
MakeKey ('DefaultErrorCatch'), |
| 2736 |
MakeKey ('RTExceptions')) ; |
| 2737 |
IF catchProcedure # NulSym |
| 2738 |
THEN |
| 2739 |
PushTtok (catchProcedure, tokno) ; |
| 2740 |
PushT (0) ; |
| 2741 |
BuildProcedureCall (tokno) |
| 2742 |
END ; |
| 2743 |
BuildRTExceptLeave (tokno, TRUE) ; |
| 2744 |
GenQuadO (tokno, CatchEndOp, NulSym, NulSym, NulSym, FALSE) |
| 2745 |
END |
| 2746 |
END BuildExcept ; |
| 2747 |
|
| 2748 |
|
| 2749 |
(* |
| 2750 |
BuildM2MainFunction - creates the main function with appropriate calls to the scaffold. |
| 2751 |
*) |
| 2752 |
|
| 2753 |
PROCEDURE BuildM2MainFunction (tokno: CARDINAL) ; |
| 2754 |
BEGIN |
| 2755 |
IF (ScaffoldDynamic OR ScaffoldStatic) AND (NOT SharedFlag) |
| 2756 |
THEN |
| 2757 |
(* Scaffold required and main should be produced. *) |
| 2758 |
(* |
| 2759 |
int |
| 2760 |
main (int argc, char *argv[], char *envp[]) |
| 2761 |
{ |
| 2762 |
try { |
| 2763 |
_M2_init (argc, argv, envp); |
| 2764 |
_M2_fini (argc, argv, envp); |
| 2765 |
return 0; |
| 2766 |
} |
| 2767 |
catch (...) { |
| 2768 |
RTExceptions_DefaultErrorCatch (); |
| 2769 |
return 0; |
| 2770 |
} |
| 2771 |
} |
| 2772 |
*) |
| 2773 |
PushT (mainFunction) ; |
| 2774 |
BuildProcedureStart ; |
| 2775 |
BuildProcedureBegin ; |
| 2776 |
StartScope (mainFunction) ; |
| 2777 |
BuildTry (tokno) ; |
| 2778 |
(* _M2_init (argc, argv, envp); *) |
| 2779 |
PushTtok (initFunction, tokno) ; |
| 2780 |
PushTtok (RequestSym (tokno, MakeKey ("argc")), tokno) ; |
| 2781 |
PushTtok (RequestSym (tokno, MakeKey ("argv")), tokno) ; |
| 2782 |
PushTtok (RequestSym (tokno, MakeKey ("envp")), tokno) ; |
| 2783 |
PushT (3) ; |
| 2784 |
BuildProcedureCall (tokno) ; |
| 2785 |
|
| 2786 |
(* _M2_fini (argc, argv, envp); *) |
| 2787 |
PushTtok (finiFunction, tokno) ; |
| 2788 |
PushTtok (RequestSym (tokno, MakeKey ("argc")), tokno) ; |
| 2789 |
PushTtok (RequestSym (tokno, MakeKey ("argv")), tokno) ; |
| 2790 |
PushTtok (RequestSym (tokno, MakeKey ("envp")), tokno) ; |
| 2791 |
PushT (3) ; |
| 2792 |
BuildProcedureCall (tokno) ; |
| 2793 |
PushZero (tokno, Integer) ; |
| 2794 |
BuildReturn (tokno) ; |
| 2795 |
BuildExcept (tokno) ; |
| 2796 |
PushZero (tokno, Integer) ; |
| 2797 |
BuildReturn (tokno) ; |
| 2798 |
EndScope ; |
| 2799 |
BuildProcedureEnd ; |
| 2800 |
PopN (1) |
| 2801 |
END |
| 2802 |
END BuildM2MainFunction ; |
| 2803 |
|
| 2804 |
|
| 2805 |
(* |
| 2806 |
DeferMakeConstStringCnul - return a C const string which will be nul terminated. |
| 2807 |
*) |
| 2808 |
|
| 2809 |
PROCEDURE DeferMakeConstStringCnul (tok: CARDINAL; sym: CARDINAL) : CARDINAL ; |
| 2810 |
VAR |
| 2811 |
const: CARDINAL ; |
| 2812 |
BEGIN |
| 2813 |
const := MakeConstStringCnul (tok, NulName, FALSE) ; |
| 2814 |
GenQuadO (tok, StringConvertCnulOp, const, 0, sym, FALSE) ; |
| 2815 |
RETURN const |
| 2816 |
END DeferMakeConstStringCnul ; |
| 2817 |
|
| 2818 |
|
| 2819 |
(* |
| 2820 |
DeferMakeConstStringM2nul - return a const string which will be nul terminated. |
| 2821 |
*) |
| 2822 |
|
| 2823 |
PROCEDURE DeferMakeConstStringM2nul (tok: CARDINAL; sym: CARDINAL) : CARDINAL ; |
| 2824 |
VAR |
| 2825 |
const: CARDINAL ; |
| 2826 |
BEGIN |
| 2827 |
const := MakeConstStringM2nul (tok, NulName, FALSE) ; |
| 2828 |
GenQuadO (tok, StringConvertM2nulOp, const, 0, sym, FALSE) ; |
| 2829 |
RETURN const |
| 2830 |
END DeferMakeConstStringM2nul ; |
| 2831 |
|
| 2832 |
|
| 2833 |
(* |
| 2834 |
BuildStringAdrParam - push the address of a nul terminated string onto the quad stack. |
| 2835 |
*) |
| 2836 |
|
| 2837 |
PROCEDURE BuildStringAdrParam (tok: CARDINAL; name: Name); |
| 2838 |
VAR |
| 2839 |
str, m2strnul: CARDINAL ; |
| 2840 |
BEGIN |
| 2841 |
PushTFtok (Adr, Address, tok) ; |
| 2842 |
str := MakeConstString (tok, name) ; |
| 2843 |
PutConstStringKnown (tok, str, name, FALSE, TRUE) ; |
| 2844 |
m2strnul := DeferMakeConstStringM2nul (tok, str) ; |
| 2845 |
PushTtok (m2strnul, tok) ; |
| 2846 |
PushT (1) ; |
| 2847 |
BuildAdrFunction |
| 2848 |
END BuildStringAdrParam ; |
| 2849 |
|
| 2850 |
|
| 2851 |
(* |
| 2852 |
BuildM2InitFunction - |
| 2853 |
*) |
| 2854 |
|
| 2855 |
PROCEDURE BuildM2InitFunction (tok: CARDINAL; moduleSym: CARDINAL) ; |
| 2856 |
VAR |
| 2857 |
constructModules: CARDINAL ; |
| 2858 |
BEGIN |
| 2859 |
IF ScaffoldDynamic OR ScaffoldStatic |
| 2860 |
THEN |
| 2861 |
(* Scaffold required and main should be produced. *) |
| 2862 |
(* int |
| 2863 |
_M2_init (int argc, char *argv[], char *envp[]) |
| 2864 |
{ |
| 2865 |
M2RTS_ConstructModules (module_name, libname, |
| 2866 |
overrideliborder, argc, argv, envp); |
| 2867 |
} *) |
| 2868 |
PushT (initFunction) ; |
| 2869 |
BuildProcedureStart ; |
| 2870 |
BuildProcedureBegin ; |
| 2871 |
StartScope (initFunction) ; |
| 2872 |
IF ScaffoldDynamic |
| 2873 |
THEN |
| 2874 |
IF linkFunction # NulSym |
| 2875 |
THEN |
| 2876 |
(* _M2_link (); *) |
| 2877 |
PushTtok (linkFunction, tok) ; |
| 2878 |
PushT (0) ; |
| 2879 |
BuildProcedureCall (tok) |
| 2880 |
END ; |
| 2881 |
|
| 2882 |
(* Lookup ConstructModules and call it. *) |
| 2883 |
constructModules := GetQualidentImport (tok, |
| 2884 |
MakeKey ("ConstructModules"), |
| 2885 |
MakeKey ("M2RTS")) ; |
| 2886 |
IF constructModules # NulSym |
| 2887 |
THEN |
| 2888 |
(* ConstructModules (module_name, argc, argv, envp); *) |
| 2889 |
PushTtok (constructModules, tok) ; |
| 2890 |
|
| 2891 |
BuildStringAdrParam (tok, GetSymName (moduleSym)) ; |
| 2892 |
BuildStringAdrParam (tok, GetLibName (moduleSym)) ; |
| 2893 |
BuildStringAdrParam (tok, makekey (GetRuntimeModuleOverride ())) ; |
| 2894 |
|
| 2895 |
PushTtok (SafeRequestSym (tok, MakeKey ("argc")), tok) ; |
| 2896 |
PushTtok (SafeRequestSym (tok, MakeKey ("argv")), tok) ; |
| 2897 |
PushTtok (SafeRequestSym (tok, MakeKey ("envp")), tok) ; |
| 2898 |
PushT (6) ; |
| 2899 |
BuildProcedureCall (tok) ; |
| 2900 |
END |
| 2901 |
ELSIF ScaffoldStatic |
| 2902 |
THEN |
| 2903 |
ForeachModuleCallInit (tok, |
| 2904 |
SafeRequestSym (tok, MakeKey ("argc")), |
| 2905 |
SafeRequestSym (tok, MakeKey ("argv")), |
| 2906 |
SafeRequestSym (tok, MakeKey ("envp"))) |
| 2907 |
END ; |
| 2908 |
EndScope ; |
| 2909 |
BuildProcedureEnd ; |
| 2910 |
PopN (1) |
| 2911 |
END |
| 2912 |
END BuildM2InitFunction ; |
| 2913 |
|
| 2914 |
|
| 2915 |
(* |
| 2916 |
BuildM2FiniFunction - |
| 2917 |
*) |
| 2918 |
|
| 2919 |
PROCEDURE BuildM2FiniFunction (tok: CARDINAL; moduleSym: CARDINAL) ; |
| 2920 |
VAR |
| 2921 |
deconstructModules: CARDINAL ; |
| 2922 |
BEGIN |
| 2923 |
IF ScaffoldDynamic OR ScaffoldStatic |
| 2924 |
THEN |
| 2925 |
(* Scaffold required and main should be produced. *) |
| 2926 |
PushT (finiFunction) ; |
| 2927 |
BuildProcedureStart ; |
| 2928 |
BuildProcedureBegin ; |
| 2929 |
StartScope (finiFunction) ; |
| 2930 |
IF ScaffoldDynamic |
| 2931 |
THEN |
| 2932 |
(* static void |
| 2933 |
_M2_finish (int argc, char *argv[], char *envp[]) |
| 2934 |
{ |
| 2935 |
M2RTS_DeconstructModules (module_name, argc, argv, envp); |
| 2936 |
} *) |
| 2937 |
deconstructModules := GetQualidentImport (tok, |
| 2938 |
MakeKey ("DeconstructModules"), |
| 2939 |
MakeKey ("M2RTS")) ; |
| 2940 |
IF deconstructModules # NulSym |
| 2941 |
THEN |
| 2942 |
(* DeconstructModules (module_name, argc, argv, envp); *) |
| 2943 |
PushTtok (deconstructModules, tok) ; |
| 2944 |
|
| 2945 |
PushTFtok (Adr, Address, tok) ; |
| 2946 |
PushTtok (MakeConstString (tok, GetSymName (moduleSym)), tok) ; |
| 2947 |
PushT(1) ; |
| 2948 |
BuildAdrFunction ; |
| 2949 |
|
| 2950 |
PushTFtok (Adr, Address, tok) ; |
| 2951 |
PushTtok (MakeConstString (tok, GetLibName (moduleSym)), tok) ; |
| 2952 |
PushT(1) ; |
| 2953 |
BuildAdrFunction ; |
| 2954 |
|
| 2955 |
PushTtok (SafeRequestSym (tok, MakeKey ("argc")), tok) ; |
| 2956 |
PushTtok (SafeRequestSym (tok, MakeKey ("argv")), tok) ; |
| 2957 |
PushTtok (SafeRequestSym (tok, MakeKey ("envp")), tok) ; |
| 2958 |
PushT (5) ; |
| 2959 |
BuildProcedureCall (tok) |
| 2960 |
END |
| 2961 |
ELSIF ScaffoldStatic |
| 2962 |
THEN |
| 2963 |
ForeachModuleCallFinish (tok, |
| 2964 |
SafeRequestSym (tok, MakeKey ("argc")), |
| 2965 |
SafeRequestSym (tok, MakeKey ("argv")), |
| 2966 |
SafeRequestSym (tok, MakeKey ("envp"))) |
| 2967 |
END ; |
| 2968 |
EndScope ; |
| 2969 |
BuildProcedureEnd ; |
| 2970 |
PopN (1) |
| 2971 |
END |
| 2972 |
END BuildM2FiniFunction ; |
| 2973 |
|
| 2974 |
|
| 2975 |
(* |
| 2976 |
BuildM2CtorFunction - create a constructor function associated with moduleSym. |
| 2977 |
|
| 2978 |
void |
| 2979 |
ctorFunction () |
| 2980 |
{ |
| 2981 |
M2RTS_RegisterModule (GetSymName (moduleSym), GetLibName (moduleSym), |
| 2982 |
init, fini, dependencies); |
| 2983 |
} |
| 2984 |
*) |
| 2985 |
|
| 2986 |
PROCEDURE BuildM2CtorFunction (tok: CARDINAL; moduleSym: CARDINAL) ; |
| 2987 |
VAR |
| 2988 |
RegisterModule : CARDINAL ; |
| 2989 |
ctor, init, fini, dep: CARDINAL ; |
| 2990 |
BEGIN |
| 2991 |
IF ScaffoldDynamic |
| 2992 |
THEN |
| 2993 |
GetModuleCtors (moduleSym, ctor, init, fini, dep) ; |
| 2994 |
IF ctor # NulSym |
| 2995 |
THEN |
| 2996 |
Assert (IsProcedure (ctor)) ; |
| 2997 |
PushT (ctor) ; |
| 2998 |
BuildProcedureStart ; |
| 2999 |
BuildProcedureBegin ; |
| 3000 |
StartScope (ctor) ; |
| 3001 |
RegisterModule := GetQualidentImport (tok, |
| 3002 |
MakeKey ("RegisterModule"), |
| 3003 |
MakeKey ("M2RTS")) ; |
| 3004 |
IF RegisterModule # NulSym |
| 3005 |
THEN |
| 3006 |
(* RegisterModule (module_name, init, fini, dependencies); *) |
| 3007 |
PushTtok (RegisterModule, tok) ; |
| 3008 |
|
| 3009 |
PushTFtok (Adr, Address, tok) ; |
| 3010 |
PushTtok (MakeConstString (tok, GetSymName (moduleSym)), tok) ; |
| 3011 |
PushT (1) ; |
| 3012 |
BuildAdrFunction ; |
| 3013 |
|
| 3014 |
PushTFtok (Adr, Address, tok) ; |
| 3015 |
PushTtok (MakeConstString (tok, GetLibName (moduleSym)), tok) ; |
| 3016 |
PushT (1) ; |
| 3017 |
BuildAdrFunction ; |
| 3018 |
|
| 3019 |
PushTtok (init, tok) ; |
| 3020 |
PushTtok (fini, tok) ; |
| 3021 |
PushTtok (dep, tok) ; |
| 3022 |
PushT (5) ; |
| 3023 |
BuildProcedureCall (tok) |
| 3024 |
END ; |
| 3025 |
EndScope ; |
| 3026 |
BuildProcedureEnd ; |
| 3027 |
PopN (1) |
| 3028 |
END |
| 3029 |
END |
| 3030 |
END BuildM2CtorFunction ; |
| 3031 |
|
| 3032 |
|
| 3033 |
(* |
| 3034 |
BuildScaffold - generate the main, init, finish functions if |
| 3035 |
no -c and this is the application module. |
| 3036 |
*) |
| 3037 |
|
| 3038 |
PROCEDURE BuildScaffold (tok: CARDINAL; moduleSym: CARDINAL) ; |
| 3039 |
BEGIN |
| 3040 |
IF GetMainModule () = moduleSym |
| 3041 |
THEN |
| 3042 |
DeclareScaffold (tok) ; |
| 3043 |
IF (ScaffoldMain OR (NOT cflag)) |
| 3044 |
THEN |
| 3045 |
(* There are module init/fini functions and |
| 3046 |
application init/fini functions. |
| 3047 |
Here we create the application pair. *) |
| 3048 |
BuildM2LinkFunction (tok) ; |
| 3049 |
BuildM2MainFunction (tok) ; |
| 3050 |
BuildM2InitFunction (tok, moduleSym) ; (* Application init. *) |
| 3051 |
BuildM2FiniFunction (tok, moduleSym) ; (* Application fini. *) |
| 3052 |
END ; |
| 3053 |
BuildM2DepFunction (tok, moduleSym) ; (* Per module dependency. *) |
| 3054 |
(* Each module needs a ctor to register the module |
| 3055 |
init/finish/dep with M2RTS. *) |
| 3056 |
BuildM2CtorFunction (tok, moduleSym) |
| 3057 |
ELSIF WholeProgram |
| 3058 |
THEN |
| 3059 |
DeclareScaffold (tok) ; |
| 3060 |
BuildM2DepFunction (tok, moduleSym) ; (* Per module dependency. *) |
| 3061 |
(* Each module needs a ctor to register the module |
| 3062 |
init/finish/dep with M2RTS. *) |
| 3063 |
BuildM2CtorFunction (tok, moduleSym) |
| 3064 |
END |
| 3065 |
END BuildScaffold ; |
| 3066 |
|
| 3067 |
|
| 3068 |
(* |
| 3069 |
BuildModuleStart - starts current module scope. |
| 3070 |
*) |
| 3071 |
|
| 3072 |
PROCEDURE BuildModuleStart (tok: CARDINAL) ; |
| 3073 |
BEGIN |
| 3074 |
GenQuadO (tok, |
| 3075 |
ModuleScopeOp, tok, |
| 3076 |
WORD (makekey (string (GetFileName ()))), GetCurrentModule (), FALSE) |
| 3077 |
END BuildModuleStart ; |
| 3078 |
|
| 3079 |
|
| 3080 |
(* |
| 3081 |
StartBuildInnerInit - Sets the start of initialization code of the |
| 3082 |
inner module to the next quadruple. |
| 3083 |
*) |
| 3084 |
|
| 3085 |
PROCEDURE StartBuildInnerInit (tok: CARDINAL) ; |
| 3086 |
BEGIN |
| 3087 |
PutModuleStartQuad (GetCurrentModule(), NextQuad) ; |
| 3088 |
GenQuadO (tok, InitStartOp, tok, NulSym, GetCurrentModule(), FALSE) ; |
| 3089 |
PushWord (ReturnStack, 0) ; |
| 3090 |
CheckNeedPriorityBegin (tok, GetCurrentModule(), GetCurrentModule()) ; |
| 3091 |
PushWord (TryStack, NextQuad) ; |
| 3092 |
PushWord (CatchStack, 0) ; |
| 3093 |
IF HasExceptionFinally (GetCurrentModule()) |
| 3094 |
THEN |
| 3095 |
GenQuadO (tok, TryOp, NulSym, NulSym, 0, FALSE) |
| 3096 |
END |
| 3097 |
END StartBuildInnerInit ; |
| 3098 |
|
| 3099 |
|
| 3100 |
(* |
| 3101 |
EndBuildInnerInit - Sets the end initialization code of a module. |
| 3102 |
*) |
| 3103 |
|
| 3104 |
PROCEDURE EndBuildInnerInit (tok: CARDINAL) ; |
| 3105 |
BEGIN |
| 3106 |
IF HasExceptionBlock (GetCurrentModule()) |
| 3107 |
THEN |
| 3108 |
BuildRTExceptLeave (tok, TRUE) ; |
| 3109 |
GenQuadO (tok, CatchEndOp, NulSym, NulSym, NulSym, FALSE) |
| 3110 |
END ; |
| 3111 |
PutModuleEndQuad (GetCurrentModule(), NextQuad) ; |
| 3112 |
CheckVariablesInBlock (GetCurrentModule ()) ; |
| 3113 |
BackPatch (PopWord (ReturnStack), NextQuad) ; |
| 3114 |
CheckNeedPriorityEnd (tok, GetCurrentModule (), GetCurrentModule ()) ; |
| 3115 |
GenQuadO (tok, InitEndOp, tok, NulSym, GetCurrentModule (), FALSE) |
| 3116 |
END EndBuildInnerInit ; |
| 3117 |
|
| 3118 |
|
| 3119 |
(* |
| 3120 |
BuildModulePriority - assigns the current module with a priority |
| 3121 |
from the top of stack. |
| 3122 |
|
| 3123 |
Entry Exit |
| 3124 |
===== ==== |
| 3125 |
|
| 3126 |
|
| 3127 |
Ptr -> Empty |
| 3128 |
+------------+ |
| 3129 |
| Priority | |
| 3130 |
|------------| |
| 3131 |
*) |
| 3132 |
|
| 3133 |
PROCEDURE BuildModulePriority ; |
| 3134 |
VAR |
| 3135 |
Priority: CARDINAL ; |
| 3136 |
BEGIN |
| 3137 |
PopT (Priority) ; |
| 3138 |
PutPriority (GetCurrentModule (), Priority) |
| 3139 |
END BuildModulePriority ; |
| 3140 |
|
| 3141 |
|
| 3142 |
(* |
| 3143 |
ForLoopAnalysis - checks all the FOR loops for index variable manipulation |
| 3144 |
and dangerous usage outside the loop. |
| 3145 |
*) |
| 3146 |
|
| 3147 |
PROCEDURE ForLoopAnalysis ; |
| 3148 |
VAR |
| 3149 |
i, n : CARDINAL ; |
| 3150 |
forDesc: ForLoopInfo ; |
| 3151 |
BEGIN |
| 3152 |
IF Pedantic |
| 3153 |
THEN |
| 3154 |
n := HighIndice (ForInfo) ; |
| 3155 |
i := 1 ; |
| 3156 |
WHILE i <= n DO |
| 3157 |
forDesc := GetIndice (ForInfo, i) ; |
| 3158 |
CheckForIndex (forDesc) ; |
| 3159 |
INC (i) |
| 3160 |
END |
| 3161 |
END |
| 3162 |
END ForLoopAnalysis ; |
| 3163 |
|
| 3164 |
|
| 3165 |
(* |
| 3166 |
AddForInfo - adds the description of the FOR loop into the record list. |
| 3167 |
This is used if -pedantic is turned on to check index variable |
| 3168 |
usage. |
| 3169 |
*) |
| 3170 |
|
| 3171 |
PROCEDURE AddForInfo (Start, End, IncQuad: CARDINAL; Sym: CARDINAL; idtok: CARDINAL) ; |
| 3172 |
VAR |
| 3173 |
forDesc: ForLoopInfo ; |
| 3174 |
BEGIN |
| 3175 |
IF Pedantic |
| 3176 |
THEN |
| 3177 |
NEW (forDesc) ; |
| 3178 |
WITH forDesc^ DO |
| 3179 |
IncrementQuad := IncQuad ; |
| 3180 |
StartOfForLoop := Start ; |
| 3181 |
EndOfForLoop := End ; |
| 3182 |
ForLoopIndex := Sym ; |
| 3183 |
IndexTok := idtok |
| 3184 |
END ; |
| 3185 |
IncludeIndiceIntoIndex (ForInfo, forDesc) |
| 3186 |
END |
| 3187 |
END AddForInfo ; |
| 3188 |
|
| 3189 |
|
| 3190 |
(* |
| 3191 |
CheckForIndex - checks the quadruples: Start..End to see whether a |
| 3192 |
for loop index is manipulated by the programmer. |
| 3193 |
It generates a warning if this is the case. |
| 3194 |
It also checks to see whether the IndexSym is read |
| 3195 |
immediately outside the loop in which case a warning |
| 3196 |
is issued. |
| 3197 |
*) |
| 3198 |
|
| 3199 |
PROCEDURE CheckForIndex (forDesc: ForLoopInfo) ; |
| 3200 |
VAR |
| 3201 |
ReadStart, ReadEnd, |
| 3202 |
WriteStart, WriteEnd: CARDINAL ; |
| 3203 |
BEGIN |
| 3204 |
GetWriteLimitQuads (forDesc^.ForLoopIndex, RightValue, forDesc^.StartOfForLoop, forDesc^.EndOfForLoop, WriteStart, WriteEnd) ; |
| 3205 |
IF (WriteStart < forDesc^.IncrementQuad) AND (WriteStart > forDesc^.StartOfForLoop) |
| 3206 |
THEN |
| 3207 |
MetaErrorT1 (forDesc^.IndexTok, |
| 3208 |
'{%kFOR} loop index variable {%1Wad} is being manipulated inside the loop', |
| 3209 |
forDesc^.ForLoopIndex) ; |
| 3210 |
MetaErrorT1 (QuadToTokenNo (WriteStart), |
| 3211 |
'{%kFOR} loop index variable {%1Wad} is being manipulated, this is considered bad practice and may cause unknown program behaviour', |
| 3212 |
forDesc^.ForLoopIndex) |
| 3213 |
END ; |
| 3214 |
GetWriteLimitQuads (forDesc^.ForLoopIndex, RightValue, forDesc^.EndOfForLoop, 0, WriteStart, WriteEnd) ; |
| 3215 |
GetReadLimitQuads (forDesc^.ForLoopIndex, RightValue, forDesc^.EndOfForLoop, 0, ReadStart, ReadEnd) ; |
| 3216 |
IF (ReadStart#0) AND ((ReadStart < WriteStart) OR (WriteStart = 0)) |
| 3217 |
THEN |
| 3218 |
MetaErrorT1 (forDesc^.IndexTok, |
| 3219 |
'{%kFOR} loop index variable {%1Wad} is being read outside the FOR loop (without being reset)', |
| 3220 |
forDesc^.ForLoopIndex) ; |
| 3221 |
MetaErrorT1 (QuadToTokenNo (ReadStart), |
| 3222 |
'{%kFOR} loop index variable {%1Wad} is being read outside the FOR loop (without being reset), this is considered extremely bad practice and may cause unknown program behaviour', |
| 3223 |
forDesc^.ForLoopIndex) |
| 3224 |
END |
| 3225 |
END CheckForIndex ; |
| 3226 |
|
| 3227 |
|
| 3228 |
(* |
| 3229 |
GetCurrentFunctionName - returns the name for the current __FUNCTION__ |
| 3230 |
*) |
| 3231 |
|
| 3232 |
(* |
| 3233 |
PROCEDURE GetCurrentFunctionName () : Name ; |
| 3234 |
VAR |
| 3235 |
s: String ; |
| 3236 |
n: Name ; |
| 3237 |
BEGIN |
| 3238 |
IF CurrentProc=NulSym |
| 3239 |
THEN |
| 3240 |
s := InitStringCharStar(KeyToCharStar(GetSymName(GetCurrentModule()))) ; |
| 3241 |
s := Sprintf1(Mark(InitString('module %s initialization')), s) ; |
| 3242 |
n := makekey(string(s)) ; |
| 3243 |
s := KillString(s) ; |
| 3244 |
RETURN( n ) |
| 3245 |
ELSE |
| 3246 |
RETURN( GetSymName(CurrentProc) ) |
| 3247 |
END |
| 3248 |
END GetCurrentFunctionName ; |
| 3249 |
*) |
| 3250 |
|
| 3251 |
|
| 3252 |
(* |
| 3253 |
BuildRange - generates a RangeCheckOp quad with, r, as its operand. |
| 3254 |
*) |
| 3255 |
|
| 3256 |
PROCEDURE BuildRange (r: CARDINAL) ; |
| 3257 |
BEGIN |
| 3258 |
GenQuad (RangeCheckOp, WORD (GetLineNo ()), NulSym, r) |
| 3259 |
END BuildRange ; |
| 3260 |
|
| 3261 |
|
| 3262 |
(* |
| 3263 |
BuildError - generates a ErrorOp quad, indicating that if this |
| 3264 |
quadruple is reachable, then a runtime error would |
| 3265 |
occur. |
| 3266 |
*) |
| 3267 |
|
| 3268 |
PROCEDURE BuildError (r: CARDINAL) ; |
| 3269 |
BEGIN |
| 3270 |
GenQuad (ErrorOp, WORD (GetLineNo ()), NulSym, r) |
| 3271 |
END BuildError ; |
| 3272 |
|
| 3273 |
|
| 3274 |
(* |
| 3275 |
CheckPointerThroughNil - builds a range quadruple, providing, sym, is |
| 3276 |
a candidate for checking against NIL. |
| 3277 |
This range quadruple is only expanded into |
| 3278 |
code during the code generation phase |
| 3279 |
thus allowing limited compile time checking. |
| 3280 |
*) |
| 3281 |
|
| 3282 |
PROCEDURE CheckPointerThroughNil (tokpos: CARDINAL; sym: CARDINAL) ; |
| 3283 |
BEGIN |
| 3284 |
IF IsVar (sym) AND GetVarPointerCheck (sym) |
| 3285 |
THEN |
| 3286 |
(* PutVarPointerCheck(sym, FALSE) ; (* so we do not detect this again *) *) |
| 3287 |
BuildRange (InitPointerRangeCheck (tokpos, sym, GetMode (sym) = LeftValue)) |
| 3288 |
END |
| 3289 |
END CheckPointerThroughNil ; |
| 3290 |
|
| 3291 |
|
| 3292 |
(* |
| 3293 |
CollectLow - returns the low of the subrange value. |
| 3294 |
*) |
| 3295 |
|
| 3296 |
PROCEDURE CollectLow (sym: CARDINAL) : CARDINAL ; |
| 3297 |
VAR |
| 3298 |
low, high: CARDINAL ; |
| 3299 |
BEGIN |
| 3300 |
IF IsSubrange (sym) |
| 3301 |
THEN |
| 3302 |
GetSubrange (sym, high, low) ; |
| 3303 |
RETURN low |
| 3304 |
ELSE |
| 3305 |
InternalError ('expecting Subrange symbol') |
| 3306 |
END |
| 3307 |
END CollectLow ; |
| 3308 |
|
| 3309 |
|
| 3310 |
(* |
| 3311 |
CollectHigh - returns the high of the subrange value, sym. |
| 3312 |
*) |
| 3313 |
|
| 3314 |
PROCEDURE CollectHigh (sym: CARDINAL) : CARDINAL ; |
| 3315 |
VAR |
| 3316 |
low, high: CARDINAL ; |
| 3317 |
BEGIN |
| 3318 |
IF IsSubrange (sym) |
| 3319 |
THEN |
| 3320 |
GetSubrange (sym, high, low) ; |
| 3321 |
RETURN high |
| 3322 |
ELSE |
| 3323 |
InternalError ('expecting Subrange symbol') |
| 3324 |
END |
| 3325 |
END CollectHigh ; |
| 3326 |
|
| 3327 |
|
| 3328 |
(* |
| 3329 |
BackPatchSubrangesAndOptParam - runs through all the quadruples and finds SubrangeLow or SubrangeHigh |
| 3330 |
quadruples and replaces it by an assignment to the Low or High component |
| 3331 |
of the subrange type. |
| 3332 |
|
| 3333 |
Input: |
| 3334 |
SubrangeLow op1 op3 (* op3 is a subrange *) |
| 3335 |
|
| 3336 |
Output: |
| 3337 |
Becomes op1 low |
| 3338 |
|
| 3339 |
Input: |
| 3340 |
SubrangeHigh op1 op3 (* op3 is a subrange *) |
| 3341 |
|
| 3342 |
Output: |
| 3343 |
Becomes op1 high |
| 3344 |
|
| 3345 |
Input: |
| 3346 |
OptParam op1 op2 op3 |
| 3347 |
|
| 3348 |
Output: |
| 3349 |
Param op1 op2 GetOptArgInit(op3) |
| 3350 |
*) |
| 3351 |
|
| 3352 |
PROCEDURE BackPatchSubrangesAndOptParam ; |
| 3353 |
VAR |
| 3354 |
f: QuadFrame ; |
| 3355 |
q: CARDINAL ; |
| 3356 |
BEGIN |
| 3357 |
q := GetFirstQuad () ; |
| 3358 |
IF q # 0 |
| 3359 |
THEN |
| 3360 |
REPEAT |
| 3361 |
f := GetQF (q) ; |
| 3362 |
WITH f^ DO |
| 3363 |
CASE Operator OF |
| 3364 |
|
| 3365 |
SubrangeLowOp : Operand3 := CollectLow (Operand3) ; |
| 3366 |
Operator := BecomesOp ; |
| 3367 |
ConstExpr := FALSE | |
| 3368 |
SubrangeHighOp: Operand3 := CollectHigh (Operand3) ; |
| 3369 |
Operator := BecomesOp ; |
| 3370 |
ConstExpr := FALSE | |
| 3371 |
OptParamOp : Operand3 := GetOptArgInit (Operand3) ; |
| 3372 |
Operator := ParamOp |
| 3373 |
|
| 3374 |
ELSE |
| 3375 |
END ; |
| 3376 |
q := Next |
| 3377 |
END |
| 3378 |
UNTIL q = 0 |
| 3379 |
END |
| 3380 |
END BackPatchSubrangesAndOptParam ; |
| 3381 |
|
| 3382 |
|
| 3383 |
(* |
| 3384 |
CheckCompatibleWithBecomes - checks to see that symbol, sym, is |
| 3385 |
compatible with the := operator. |
| 3386 |
*) |
| 3387 |
|
| 3388 |
PROCEDURE CheckCompatibleWithBecomes (des, expr, |
| 3389 |
destok, exprtok: CARDINAL) ; |
| 3390 |
BEGIN |
| 3391 |
IF IsType (des) |
| 3392 |
THEN |
| 3393 |
MetaErrorT1 (destok, |
| 3394 |
'an assignment cannot assign a value to a type {%1a}', des) |
| 3395 |
ELSIF IsProcedure (des) |
| 3396 |
THEN |
| 3397 |
MetaErrorT1 (destok, |
| 3398 |
'an assignment cannot assign a value to a procedure {%1a}', des) |
| 3399 |
ELSIF IsFieldEnumeration (des) |
| 3400 |
THEN |
| 3401 |
MetaErrorT1 (destok, |
| 3402 |
'an assignment cannot assign a value to an enumeration field {%1a}', des) |
| 3403 |
END ; |
| 3404 |
IF IsPseudoBaseProcedure (expr) OR IsPseudoBaseFunction (expr) |
| 3405 |
THEN |
| 3406 |
MetaErrorT1 (exprtok, |
| 3407 |
'an assignment cannot assign a {%1d} {%1a}', expr) |
| 3408 |
END |
| 3409 |
END CheckCompatibleWithBecomes ; |
| 3410 |
|
| 3411 |
|
| 3412 |
(* |
| 3413 |
BuildAssignmentWithoutBounds - calls BuildAssignment but makes sure we do not |
| 3414 |
check bounds. |
| 3415 |
*) |
| 3416 |
|
| 3417 |
PROCEDURE BuildAssignmentWithoutBounds (tok: CARDINAL; checkTypes, checkOverflow: BOOLEAN) ; |
| 3418 |
VAR |
| 3419 |
old: BOOLEAN ; |
| 3420 |
BEGIN |
| 3421 |
old := MustNotCheckBounds ; |
| 3422 |
MustNotCheckBounds := TRUE ; |
| 3423 |
doBuildAssignment (tok, checkTypes, checkOverflow) ; |
| 3424 |
MustNotCheckBounds := old |
| 3425 |
END BuildAssignmentWithoutBounds ; |
| 3426 |
|
| 3427 |
|
| 3428 |
(* |
| 3429 |
MarkArrayWritten - marks, Array, as being written. |
| 3430 |
*) |
| 3431 |
|
| 3432 |
PROCEDURE MarkArrayWritten (Array: CARDINAL) ; |
| 3433 |
BEGIN |
| 3434 |
IF (Array#NulSym) AND IsVarAParam(Array) |
| 3435 |
THEN |
| 3436 |
PutVarWritten (Array, TRUE) |
| 3437 |
END |
| 3438 |
END MarkArrayWritten ; |
| 3439 |
|
| 3440 |
|
| 3441 |
(* |
| 3442 |
MarkAsReadWrite - marks the variable or parameter as being |
| 3443 |
read/write. |
| 3444 |
*) |
| 3445 |
|
| 3446 |
PROCEDURE MarkAsReadWrite (sym: CARDINAL) ; |
| 3447 |
BEGIN |
| 3448 |
IF (sym#NulSym) AND IsVar(sym) |
| 3449 |
THEN |
| 3450 |
PutReadQuad (sym, RightValue, NextQuad) ; |
| 3451 |
PutWriteQuad (sym, RightValue, NextQuad) |
| 3452 |
END |
| 3453 |
END MarkAsReadWrite ; |
| 3454 |
|
| 3455 |
|
| 3456 |
(* |
| 3457 |
MarkAsRead - marks the variable or parameter as being read. |
| 3458 |
*) |
| 3459 |
|
| 3460 |
PROCEDURE MarkAsRead (sym: CARDINAL) ; |
| 3461 |
BEGIN |
| 3462 |
IF (sym#NulSym) AND IsVar(sym) |
| 3463 |
THEN |
| 3464 |
PutReadQuad (sym, RightValue, NextQuad) |
| 3465 |
END |
| 3466 |
END MarkAsRead ; |
| 3467 |
|
| 3468 |
|
| 3469 |
(* |
| 3470 |
MarkAsWrite - marks the variable or parameter as being written. |
| 3471 |
*) |
| 3472 |
|
| 3473 |
PROCEDURE MarkAsWrite (sym: CARDINAL) ; |
| 3474 |
BEGIN |
| 3475 |
IF (sym # NulSym) AND IsVar (sym) |
| 3476 |
THEN |
| 3477 |
PutWriteQuad (sym, RightValue, NextQuad) |
| 3478 |
END |
| 3479 |
END MarkAsWrite ; |
| 3480 |
|
| 3481 |
|
| 3482 |
(* |
| 3483 |
doVal - return an expression which is VAL(type, expr). If |
| 3484 |
expr is a constant then return expr. |
| 3485 |
*) |
| 3486 |
|
| 3487 |
PROCEDURE doVal (type, expr: CARDINAL) : CARDINAL ; |
| 3488 |
BEGIN |
| 3489 |
IF (NOT IsConst (expr)) AND (SkipType (type) # GetDType (expr)) |
| 3490 |
THEN |
| 3491 |
PushTF (Convert, NulSym) ; |
| 3492 |
PushT (SkipType(type)) ; |
| 3493 |
PushT (expr) ; |
| 3494 |
PushT (2) ; (* Two parameters *) |
| 3495 |
BuildConvertFunction (Convert, FALSE) ; |
| 3496 |
PopT (expr) |
| 3497 |
END ; |
| 3498 |
RETURN( expr ) |
| 3499 |
END doVal ; |
| 3500 |
|
| 3501 |
|
| 3502 |
(* |
| 3503 |
MoveWithMode - |
| 3504 |
*) |
| 3505 |
|
| 3506 |
PROCEDURE MoveWithMode (tokno: CARDINAL; |
| 3507 |
Des, Exp, Array: CARDINAL; |
| 3508 |
destok, exptok: CARDINAL; |
| 3509 |
checkOverflow: BOOLEAN) ; |
| 3510 |
VAR |
| 3511 |
t: CARDINAL ; |
| 3512 |
BEGIN |
| 3513 |
IF IsConstString(Exp) AND IsConst(Des) |
| 3514 |
THEN |
| 3515 |
GenQuadOtok (tokno, BecomesOp, Des, NulSym, Exp, TRUE, |
| 3516 |
destok, UnknownTokenNo, exptok) ; |
| 3517 |
ELSE |
| 3518 |
IF GetMode(Des)=RightValue |
| 3519 |
THEN |
| 3520 |
IF GetMode(Exp)=LeftValue |
| 3521 |
THEN |
| 3522 |
CheckPointerThroughNil (tokno, Exp) ; (* Des = *Exp *) |
| 3523 |
doIndrX (tokno, Des, Exp) |
| 3524 |
ELSE |
| 3525 |
GenQuadOtok (tokno, BecomesOp, Des, NulSym, Exp, TRUE, |
| 3526 |
destok, UnknownTokenNo, exptok) |
| 3527 |
END |
| 3528 |
ELSIF GetMode(Des)=LeftValue |
| 3529 |
THEN |
| 3530 |
MarkArrayWritten (Array) ; |
| 3531 |
IF GetMode(Exp) = LeftValue |
| 3532 |
THEN |
| 3533 |
t := MakeTemporary (tokno, RightValue) ; |
| 3534 |
PutVar(t, GetSType(Exp)) ; |
| 3535 |
CheckPointerThroughNil (tokno, Exp) ; |
| 3536 |
doIndrX (tokno, t, Exp) ; |
| 3537 |
CheckPointerThroughNil (tokno, Des) ; (* *Des = Exp *) |
| 3538 |
GenQuadO (tokno, XIndrOp, Des, GetSType (Des), doVal (GetSType (Des), t), |
| 3539 |
checkOverflow) |
| 3540 |
ELSE |
| 3541 |
CheckPointerThroughNil (tokno, Des) ; (* *Des = Exp *) |
| 3542 |
GenQuadO (tokno, XIndrOp, Des, GetSType (Des), doVal (GetSType (Des), Exp), |
| 3543 |
checkOverflow) |
| 3544 |
END |
| 3545 |
ELSE |
| 3546 |
(* This might be inside a const expression. *) |
| 3547 |
GenQuadOTypetok (tokno, BecomesOp, |
| 3548 |
Des, NulSym, Exp, |
| 3549 |
TRUE, TRUE, |
| 3550 |
destok, UnknownTokenNo, exptok) |
| 3551 |
END |
| 3552 |
END |
| 3553 |
END MoveWithMode ; |
| 3554 |
|
| 3555 |
|
| 3556 |
(* |
| 3557 |
BuildBuiltinConst - makes reference to a builtin constant within gm2. |
| 3558 |
|
| 3559 |
Entry Exit |
| 3560 |
|
| 3561 |
Ptr -> |
| 3562 |
+------------+ +------------+ |
| 3563 |
| Ident | | Sym | |
| 3564 |
|------------| |------------| |
| 3565 |
|
| 3566 |
Quadruple produced: |
| 3567 |
|
| 3568 |
q Sym BuiltinConstOp Ident |
| 3569 |
*) |
| 3570 |
|
| 3571 |
PROCEDURE BuildBuiltinConst ; |
| 3572 |
VAR |
| 3573 |
idtok: CARDINAL ; |
| 3574 |
Id : CARDINAL ; |
| 3575 |
Sym : CARDINAL ; |
| 3576 |
BEGIN |
| 3577 |
PopTtok (Id, idtok) ; |
| 3578 |
Sym := MakeTemporary (idtok, ImmediateValue) ; |
| 3579 |
PutVar (Sym, Integer) ; |
| 3580 |
(* |
| 3581 |
CASE GetBuiltinConstType(KeyToCharStar(Name(Id))) OF |
| 3582 |
|
| 3583 |
0: ErrorFormat1(NewError(GetTokenNo()), |
| 3584 |
'%a unrecognised builtin constant', Id) | |
| 3585 |
1: PutVar(Sym, Integer) | |
| 3586 |
2: PutVar(Sym, Real) |
| 3587 |
|
| 3588 |
ELSE |
| 3589 |
InternalError ('unrecognised value') |
| 3590 |
END ; |
| 3591 |
*) |
| 3592 |
GenQuadO (idtok, BuiltinConstOp, Sym, NulSym, Id, FALSE) ; |
| 3593 |
PushTtok (Sym, idtok) |
| 3594 |
END BuildBuiltinConst ; |
| 3595 |
|
| 3596 |
|
| 3597 |
(* |
| 3598 |
BuildBuiltinTypeInfo - make reference to a builtin typeinfo function |
| 3599 |
within gm2. |
| 3600 |
|
| 3601 |
Entry Exit |
| 3602 |
|
| 3603 |
Ptr -> |
| 3604 |
+-------------+ |
| 3605 |
| Type | |
| 3606 |
|-------------| +------------+ |
| 3607 |
| Ident | | Sym | |
| 3608 |
|-------------| |------------| |
| 3609 |
|
| 3610 |
Quadruple produced: |
| 3611 |
|
| 3612 |
q Sym BuiltinTypeInfoOp Type Ident |
| 3613 |
*) |
| 3614 |
|
| 3615 |
PROCEDURE BuildBuiltinTypeInfo ; |
| 3616 |
VAR |
| 3617 |
idtok: CARDINAL ; |
| 3618 |
Ident, |
| 3619 |
Type, |
| 3620 |
Sym : CARDINAL ; |
| 3621 |
BEGIN |
| 3622 |
PopTtok (Ident, idtok) ; |
| 3623 |
PopT (Type) ; |
| 3624 |
Sym := MakeTemporary (BuiltinTokenNo, ImmediateValue) ; |
| 3625 |
CASE GetBuiltinTypeInfoType (KeyToCharStar (Name (Ident))) OF |
| 3626 |
|
| 3627 |
0: ErrorFormat1 (NewError(idtok), |
| 3628 |
'%a unrecognised builtin constant', Ident) | |
| 3629 |
1: PutVar (Sym, Boolean) | |
| 3630 |
2: PutVar (Sym, ZType) | |
| 3631 |
3: PutVar (Sym, RType) |
| 3632 |
|
| 3633 |
ELSE |
| 3634 |
InternalError ('unrecognised value') |
| 3635 |
END ; |
| 3636 |
GenQuadO (idtok, BuiltinTypeInfoOp, Sym, Type, Ident, FALSE) ; |
| 3637 |
PushTtok (Sym, idtok) |
| 3638 |
END BuildBuiltinTypeInfo ; |
| 3639 |
|
| 3640 |
|
| 3641 |
(* |
| 3642 |
CheckBecomesMeta - checks to make sure that we are not |
| 3643 |
assigning a variable to a constant. |
| 3644 |
Also check we are not assigning to an |
| 3645 |
unbounded array. |
| 3646 |
*) |
| 3647 |
|
| 3648 |
PROCEDURE CheckBecomesMeta (Des, Exp: CARDINAL; combinedtok, destok, exprtok: CARDINAL) ; |
| 3649 |
BEGIN |
| 3650 |
IF IsConst (Des) AND IsVar (Exp) |
| 3651 |
THEN |
| 3652 |
MetaErrorsT2 (combinedtok, |
| 3653 |
'in assignment, cannot assign a variable {%2a} to a constant {%1a}', |
| 3654 |
'designator {%1Da} is declared as a {%kCONST}', Des, Exp) |
| 3655 |
END ; |
| 3656 |
IF (GetDType(Des) # NulSym) AND IsVar (Des) AND IsUnbounded (GetDType (Des)) |
| 3657 |
THEN |
| 3658 |
MetaErrorT1 (destok, |
| 3659 |
'in assignment, cannot assign to an unbounded array {%1ad}', Des) |
| 3660 |
END ; |
| 3661 |
IF (GetDType(Exp) # NulSym) AND IsVar (Exp) AND IsUnbounded (GetDType (Exp)) |
| 3662 |
THEN |
| 3663 |
MetaErrorT1 (exprtok, |
| 3664 |
'in assignment, cannot assign from an unbounded array {%1ad}', Exp) |
| 3665 |
END |
| 3666 |
END CheckBecomesMeta ; |
| 3667 |
|
| 3668 |
|
| 3669 |
(* |
| 3670 |
BuildAssignment - Builds an assignment from the values given on the |
| 3671 |
quad stack. Either an assignment to an |
| 3672 |
arithmetic expression or an assignment to a |
| 3673 |
boolean expression. This procedure should not |
| 3674 |
be called in CONST declarations. |
| 3675 |
The Stack is expected to contain: |
| 3676 |
|
| 3677 |
|
| 3678 |
Either |
| 3679 |
|
| 3680 |
Entry Exit |
| 3681 |
===== ==== |
| 3682 |
|
| 3683 |
Ptr -> |
| 3684 |
+------------+ |
| 3685 |
| Expression | |
| 3686 |
|------------| |
| 3687 |
| Designator | |
| 3688 |
|------------| +------------+ |
| 3689 |
| | | | <- Ptr |
| 3690 |
|------------| |------------| |
| 3691 |
|
| 3692 |
|
| 3693 |
Quadruples Produced |
| 3694 |
|
| 3695 |
q BecomesOp Designator _ Expression |
| 3696 |
|
| 3697 |
OR |
| 3698 |
|
| 3699 |
Entry Exit |
| 3700 |
===== ==== |
| 3701 |
|
| 3702 |
Ptr -> |
| 3703 |
+------------+ |
| 3704 |
| True |False| |
| 3705 |
|------------| |
| 3706 |
| Designator | |
| 3707 |
|------------| +------------+ |
| 3708 |
| | | | <- Ptr |
| 3709 |
|------------| |------------| |
| 3710 |
|
| 3711 |
|
| 3712 |
Quadruples Produced |
| 3713 |
|
| 3714 |
q BecomesOp Designator _ TRUE |
| 3715 |
q+1 GotoOp q+3 |
| 3716 |
q+2 BecomesOp Designator _ FALSE |
| 3717 |
|
| 3718 |
*) |
| 3719 |
|
| 3720 |
PROCEDURE BuildAssignment (becomesTokNo: CARDINAL) ; |
| 3721 |
VAR |
| 3722 |
des, exp : CARDINAL ; |
| 3723 |
destok, |
| 3724 |
exptok, |
| 3725 |
combinedtok: CARDINAL ; |
| 3726 |
BEGIN |
| 3727 |
des := OperandT (2) ; |
| 3728 |
IF IsReadOnly (des) |
| 3729 |
THEN |
| 3730 |
destok := OperandTok (2) ; |
| 3731 |
exptok := OperandTok (1) ; |
| 3732 |
exp := OperandT (1) ; |
| 3733 |
IF DebugTokPos |
| 3734 |
THEN |
| 3735 |
MetaErrorT1 (destok, 'destok {%1Ead}', des) ; |
| 3736 |
MetaErrorT1 (exptok, 'exptok {%1Ead}', exp) |
| 3737 |
END ; |
| 3738 |
combinedtok := MakeVirtualTok (becomesTokNo, destok, exptok) ; |
| 3739 |
IF DebugTokPos |
| 3740 |
THEN |
| 3741 |
MetaErrorT1 (combinedtok, 'combined {%1Ead}', des) |
| 3742 |
END ; |
| 3743 |
IF IsBoolean (1) |
| 3744 |
THEN |
| 3745 |
MetaErrorT1 (combinedtok, |
| 3746 |
'cannot assign expression to a constant designator {%1Ead}', des) |
| 3747 |
ELSE |
| 3748 |
exp := OperandT (1) ; |
| 3749 |
MetaErrorT2 (combinedtok, |
| 3750 |
'cannot assign a constant designator {%1Ead} with an expression {%2Ead}', |
| 3751 |
des, exp) |
| 3752 |
END ; |
| 3753 |
PopN (2) (* Remove both parameters. *) |
| 3754 |
ELSIF IsError (des) |
| 3755 |
THEN |
| 3756 |
PopN (2) (* Remove both parameters. *) |
| 3757 |
ELSE |
| 3758 |
doBuildAssignment (becomesTokNo, TRUE, TRUE) |
| 3759 |
END |
| 3760 |
END BuildAssignment ; |
| 3761 |
|
| 3762 |
|
| 3763 |
(* |
| 3764 |
BuildAssignConstant - used to create constant in the CONST declaration. |
| 3765 |
The stack is expected to contain: |
| 3766 |
|
| 3767 |
Either |
| 3768 |
|
| 3769 |
Entry Exit |
| 3770 |
===== ==== |
| 3771 |
|
| 3772 |
Ptr -> |
| 3773 |
+------------+ |
| 3774 |
| Expression | |
| 3775 |
|------------| |
| 3776 |
| Designator | |
| 3777 |
|------------| +------------+ |
| 3778 |
| | | | <- Ptr |
| 3779 |
|------------| |------------| |
| 3780 |
|
| 3781 |
|
| 3782 |
Quadruples Produced |
| 3783 |
|
| 3784 |
q BecomesOp Designator _ Expression |
| 3785 |
|
| 3786 |
OR |
| 3787 |
|
| 3788 |
Entry Exit |
| 3789 |
===== ==== |
| 3790 |
|
| 3791 |
Ptr -> |
| 3792 |
+------------+ |
| 3793 |
| True |False| |
| 3794 |
|------------| |
| 3795 |
| Designator | |
| 3796 |
|------------| +------------+ |
| 3797 |
| | | | <- Ptr |
| 3798 |
|------------| |------------| |
| 3799 |
|
| 3800 |
|
| 3801 |
Quadruples Produced |
| 3802 |
|
| 3803 |
q BecomesOp Designator _ TRUE |
| 3804 |
q+1 GotoOp q+3 |
| 3805 |
q+2 BecomesOp Designator _ FALSE |
| 3806 |
*) |
| 3807 |
|
| 3808 |
PROCEDURE BuildAssignConstant (equalsTokNo: CARDINAL) ; |
| 3809 |
BEGIN |
| 3810 |
doBuildAssignment (equalsTokNo, TRUE, TRUE) |
| 3811 |
END BuildAssignConstant ; |
| 3812 |
|
| 3813 |
|
| 3814 |
(* |
| 3815 |
doBuildAssignment - subsiduary procedure of BuildAssignment. |
| 3816 |
It builds the assignment and optionally |
| 3817 |
checks the types are compatible. |
| 3818 |
*) |
| 3819 |
|
| 3820 |
PROCEDURE doBuildAssignment (becomesTokNo: CARDINAL; checkTypes, checkOverflow: BOOLEAN) ; |
| 3821 |
VAR |
| 3822 |
r, w, |
| 3823 |
t, f, |
| 3824 |
Array, |
| 3825 |
Des, Exp : CARDINAL ; |
| 3826 |
combinedtok, |
| 3827 |
destok, exptok: CARDINAL ; |
| 3828 |
BEGIN |
| 3829 |
DisplayStack ; |
| 3830 |
IF IsBoolean (1) |
| 3831 |
THEN |
| 3832 |
PopBool (t, f) ; |
| 3833 |
PopTtok (Des, destok) ; |
| 3834 |
PutVarConditional (Des, TRUE) ; (* Des will contain the result of a boolean relop. *) |
| 3835 |
(* Conditional Boolean Assignment. *) |
| 3836 |
BackPatch (t, NextQuad) ; |
| 3837 |
IF GetMode (Des) = LeftValue |
| 3838 |
THEN |
| 3839 |
CheckPointerThroughNil (destok, Des) ; |
| 3840 |
GenQuadO (destok, XIndrOp, Des, Boolean, True, checkOverflow) ; |
| 3841 |
GenQuadO (destok, GotoOp, NulSym, NulSym, NextQuad+2, FALSE) ; |
| 3842 |
ELSE |
| 3843 |
(* This might be inside a const expression. *) |
| 3844 |
GenQuadO (becomesTokNo, BecomesOp, Des, NulSym, True, checkOverflow) ; |
| 3845 |
GenQuadO (destok, GotoOp, NulSym, NulSym, NextQuad+2, FALSE) |
| 3846 |
END ; |
| 3847 |
BackPatch (f, NextQuad) ; |
| 3848 |
IF GetMode (Des) = LeftValue |
| 3849 |
THEN |
| 3850 |
CheckPointerThroughNil (destok, Des) ; |
| 3851 |
GenQuadO (destok, XIndrOp, Des, Boolean, False, checkOverflow) |
| 3852 |
ELSE |
| 3853 |
GenQuadO (becomesTokNo, BecomesOp, Des, NulSym, False, checkOverflow) |
| 3854 |
END |
| 3855 |
ELSE |
| 3856 |
PopTrwtok (Exp, r, exptok) ; |
| 3857 |
MarkAsRead (r) ; |
| 3858 |
IF Exp = NulSym |
| 3859 |
THEN |
| 3860 |
MetaError0 ('{%E}unknown expression found during assignment') ; |
| 3861 |
FlushErrors |
| 3862 |
END ; |
| 3863 |
Array := OperandA (1) ; |
| 3864 |
PopTrwtok (Des, w, destok) ; |
| 3865 |
MarkAsWrite (w) ; |
| 3866 |
CheckCompatibleWithBecomes (Des, Exp, destok, exptok) ; |
| 3867 |
IF DebugTokPos |
| 3868 |
THEN |
| 3869 |
MetaErrorT1 (becomesTokNo, 'becomestok {%1Oad}', Des) ; |
| 3870 |
MetaErrorT1 (destok, 'destok {%1Oad}', Des) ; |
| 3871 |
MetaErrorT1 (exptok, 'exptok {%1Oad}', Exp) |
| 3872 |
END ; |
| 3873 |
combinedtok := MakeVirtualTok (becomesTokNo, destok, exptok) ; |
| 3874 |
IF DebugTokPos |
| 3875 |
THEN |
| 3876 |
MetaErrorT1 (combinedtok, 'combined {%1Oad}', Des) |
| 3877 |
END ; |
| 3878 |
IF StrictTypeAssignment |
| 3879 |
THEN |
| 3880 |
BuildRange (InitTypesAssignmentCheck (combinedtok, Des, Exp)) |
| 3881 |
END ; |
| 3882 |
IF (GetSType (Des) # NulSym) AND (NOT IsSet (GetDType (Des))) |
| 3883 |
THEN |
| 3884 |
(* Tell code generator to test runtime values of assignment so ensure we |
| 3885 |
catch overflow and underflow. *) |
| 3886 |
BuildRange (InitAssignmentRangeCheck (combinedtok, Des, Exp, destok, exptok)) |
| 3887 |
END ; |
| 3888 |
IF checkTypes |
| 3889 |
THEN |
| 3890 |
CheckBecomesMeta (Des, Exp, combinedtok, destok, exptok) |
| 3891 |
END ; |
| 3892 |
(* Simple assignment. *) |
| 3893 |
MoveWithMode (combinedtok, Des, Exp, Array, destok, exptok, checkOverflow) ; |
| 3894 |
IF checkTypes |
| 3895 |
THEN |
| 3896 |
CheckAssignCompatible (Des, Exp, combinedtok, destok, exptok) |
| 3897 |
END |
| 3898 |
END ; |
| 3899 |
DisplayStack |
| 3900 |
END doBuildAssignment ; |
| 3901 |
|
| 3902 |
|
| 3903 |
(* |
| 3904 |
CheckAssignCompatible - checks to see that an assignment is compatible. |
| 3905 |
It performs limited checking - thorough checking |
| 3906 |
is done in pass 3. But we do what we can here |
| 3907 |
given knowledge so far. |
| 3908 |
*) |
| 3909 |
|
| 3910 |
PROCEDURE CheckAssignCompatible (Des, Exp: CARDINAL; combinedtok, destok, exprtok: CARDINAL) ; |
| 3911 |
VAR |
| 3912 |
DesT, ExpT, DesL: CARDINAL ; |
| 3913 |
BEGIN |
| 3914 |
DesT := GetSType(Des) ; |
| 3915 |
ExpT := GetSType(Exp) ; |
| 3916 |
DesL := GetLType(Des) ; |
| 3917 |
IF IsProcedure(Exp) AND |
| 3918 |
((DesT#NulSym) AND (NOT IsProcType(DesT))) AND |
| 3919 |
((DesL#NulSym) AND (NOT IsProcType(DesL))) |
| 3920 |
THEN |
| 3921 |
MetaErrorT1 (destok, |
| 3922 |
'incorrectly assigning a procedure to a designator {%1Ead} (designator is not a procedure type, {%1ast})', Des) |
| 3923 |
ELSIF IsProcedure (Exp) AND IsProcedureNested (Exp) |
| 3924 |
THEN |
| 3925 |
MetaErrorT1 (exprtok, |
| 3926 |
'cannot call nested procedure {%1Ead} indirectly as the outer scope will not be known', Exp) |
| 3927 |
ELSIF IsConstString(Exp) |
| 3928 |
THEN |
| 3929 |
ELSIF (DesT#NulSym) AND (IsUnbounded(DesT)) |
| 3930 |
THEN |
| 3931 |
ELSIF (ExpT#NulSym) AND (IsUnbounded(ExpT)) |
| 3932 |
THEN |
| 3933 |
ELSIF (DesL#NulSym) AND IsArray(DesL) |
| 3934 |
THEN |
| 3935 |
ELSIF IsConstructor(Exp) |
| 3936 |
THEN |
| 3937 |
IF ExpT=NulSym |
| 3938 |
THEN |
| 3939 |
(* ignore type checking *) |
| 3940 |
ELSIF (DesT=NulSym) AND IsConst(Des) AND (IsConstructor(Des) OR IsConstSet(Des)) |
| 3941 |
THEN |
| 3942 |
PutConst(Des, ExpT) |
| 3943 |
ELSIF NOT IsAssignmentCompatible(DesT, ExpT) |
| 3944 |
THEN |
| 3945 |
MetaErrorT1 (combinedtok, |
| 3946 |
'constructor expression is not compatible during assignment to {%1Ead}', Des) |
| 3947 |
END |
| 3948 |
ELSIF (DesT#NulSym) AND IsSet(DesT) AND IsConst(Exp) |
| 3949 |
THEN |
| 3950 |
(* We ignore checking of these types in pass 3 - but we do check them thoroughly post pass 3 *) |
| 3951 |
ELSIF IsConst(Exp) AND (ExpT#Address) AND (NOT IsConst(Des)) AND |
| 3952 |
(DesL#NulSym) AND ((DesL=Cardinal) OR (NOT IsSubrange(DesL))) AND |
| 3953 |
(NOT IsEnumeration(DesL)) |
| 3954 |
THEN |
| 3955 |
IF (IsBaseType(DesL) OR IsSystemType(DesL)) |
| 3956 |
THEN |
| 3957 |
CheckAssignmentCompatible (combinedtok, ExpT, DesT) |
| 3958 |
ELSE |
| 3959 |
MetaErrorT2 (combinedtok, |
| 3960 |
'assignment of a constant {%1Ead} can only be made to a variable whose type is equivalent to a Modula-2 base type {%2tsa}', Exp, Des) |
| 3961 |
END |
| 3962 |
ELSE |
| 3963 |
IF (DesT#NulSym) AND IsProcType(DesT) AND IsProcedure(Exp) |
| 3964 |
THEN |
| 3965 |
DesT := GetSType(DesT) ; (* we can at least check RETURN values of procedure variables *) |
| 3966 |
(* remember that thorough assignment checking is done post pass 3 *) |
| 3967 |
CheckAssignmentCompatible (combinedtok, ExpT, DesT) |
| 3968 |
END |
| 3969 |
END |
| 3970 |
END CheckAssignCompatible ; |
| 3971 |
|
| 3972 |
|
| 3973 |
(* |
| 3974 |
CheckBooleanId - Checks to see if the top operand is a boolean. |
| 3975 |
If the operand is not a boolean then it is tested |
| 3976 |
with true and a boolean is generated. |
| 3977 |
The Stack: |
| 3978 |
|
| 3979 |
|
| 3980 |
Entry Exit |
| 3981 |
Ptr -> <- Ptr |
| 3982 |
+------------+ +------------+ |
| 3983 |
| Sym | | t | f | |
| 3984 |
|------------| |------------| |
| 3985 |
|
| 3986 |
Quadruples |
| 3987 |
|
| 3988 |
q If= Sym True _ |
| 3989 |
q+1 GotoOp _ _ _ |
| 3990 |
*) |
| 3991 |
|
| 3992 |
PROCEDURE CheckBooleanId ; |
| 3993 |
VAR |
| 3994 |
tok: CARDINAL ; |
| 3995 |
BEGIN |
| 3996 |
IF NOT IsBoolean (1) |
| 3997 |
THEN |
| 3998 |
tok := OperandTok (1) ; |
| 3999 |
IF IsVar (OperandT (1)) |
| 4000 |
THEN |
| 4001 |
IF GetSType (OperandT (1)) # Boolean |
| 4002 |
THEN |
| 4003 |
MetaError1 ('{%1Ua:is not a boolean expression}' + |
| 4004 |
'{!%1Ua:boolean expression expected}', OperandT (1)) |
| 4005 |
END |
| 4006 |
END ; |
| 4007 |
PushT (EqualTok) ; |
| 4008 |
PushT (True) ; |
| 4009 |
BuildRelOp (tok) |
| 4010 |
END |
| 4011 |
END CheckBooleanId ; |
| 4012 |
|
| 4013 |
|
| 4014 |
(* |
| 4015 |
BuildAlignment - builds an assignment to an alignment constant. |
| 4016 |
|
| 4017 |
The Stack is expected to contain: |
| 4018 |
|
| 4019 |
|
| 4020 |
Entry Exit |
| 4021 |
===== ==== |
| 4022 |
|
| 4023 |
Ptr -> |
| 4024 |
+---------------+ |
| 4025 |
| Expression | |
| 4026 |
|---------------| |
| 4027 |
| bytealignment | |
| 4028 |
|---------------| empty |
| 4029 |
*) |
| 4030 |
|
| 4031 |
PROCEDURE BuildAlignment (tokno: CARDINAL) ; |
| 4032 |
VAR |
| 4033 |
name : Name ; |
| 4034 |
expr, |
| 4035 |
align: CARDINAL ; |
| 4036 |
BEGIN |
| 4037 |
PopT (expr) ; |
| 4038 |
PopT (name) ; |
| 4039 |
IF name # MakeKey ('bytealignment') |
| 4040 |
THEN |
| 4041 |
MetaError1 ('expecting bytealignment identifier, rather than {%1Ea}', |
| 4042 |
MakeError (tokno, name)) |
| 4043 |
END ; |
| 4044 |
GetConstFromFifoQueue (align) ; |
| 4045 |
PushT (align) ; |
| 4046 |
PushT (expr) ; |
| 4047 |
BuildAssignConstant (tokno) |
| 4048 |
END BuildAlignment ; |
| 4049 |
|
| 4050 |
|
| 4051 |
(* |
| 4052 |
BuildBitLength - builds an assignment to a bit length constant. |
| 4053 |
|
| 4054 |
The Stack is expected to contain: |
| 4055 |
|
| 4056 |
|
| 4057 |
Entry Exit |
| 4058 |
===== ==== |
| 4059 |
|
| 4060 |
Ptr -> |
| 4061 |
+------------+ |
| 4062 |
| Expression | |
| 4063 |
|------------| empty |
| 4064 |
*) |
| 4065 |
|
| 4066 |
PROCEDURE BuildBitLength (tokno: CARDINAL) ; |
| 4067 |
VAR |
| 4068 |
expr, |
| 4069 |
length: CARDINAL ; |
| 4070 |
BEGIN |
| 4071 |
PopT (expr) ; |
| 4072 |
GetConstFromFifoQueue (length) ; |
| 4073 |
PushT (length) ; |
| 4074 |
PushT (expr) ; |
| 4075 |
BuildAssignConstant (tokno) |
| 4076 |
END BuildBitLength ; |
| 4077 |
|
| 4078 |
|
| 4079 |
(* |
| 4080 |
BuildDefaultFieldAlignment - builds an assignment to an alignment constant. |
| 4081 |
|
| 4082 |
The Stack is expected to contain: |
| 4083 |
|
| 4084 |
|
| 4085 |
Entry Exit |
| 4086 |
===== ==== |
| 4087 |
|
| 4088 |
Ptr -> |
| 4089 |
+------------+ |
| 4090 |
| Expression | |
| 4091 |
|------------| empty |
| 4092 |
*) |
| 4093 |
|
| 4094 |
PROCEDURE BuildDefaultFieldAlignment ; |
| 4095 |
VAR |
| 4096 |
expr, |
| 4097 |
align: CARDINAL ; |
| 4098 |
name : Name ; |
| 4099 |
BEGIN |
| 4100 |
PopT (expr) ; |
| 4101 |
PopT (name) ; |
| 4102 |
IF name # MakeKey ('bytealignment') |
| 4103 |
THEN |
| 4104 |
MetaError0 ('{%E}only allowed to use the attribute {%kbytealignment} in the default record field alignment pragma') |
| 4105 |
END ; |
| 4106 |
GetConstFromFifoQueue (align) ; |
| 4107 |
PushT (align) ; |
| 4108 |
PushT (expr) ; |
| 4109 |
BuildAssignConstant (GetTokenNo ()) |
| 4110 |
END BuildDefaultFieldAlignment ; |
| 4111 |
|
| 4112 |
|
| 4113 |
(* |
| 4114 |
BuildPragmaField - builds an assignment to an alignment constant. |
| 4115 |
|
| 4116 |
The Stack is expected to contain: |
| 4117 |
|
| 4118 |
|
| 4119 |
Entry Exit |
| 4120 |
===== ==== |
| 4121 |
|
| 4122 |
Ptr -> |
| 4123 |
+------------+ |
| 4124 |
| Expression | |
| 4125 |
|------------| empty |
| 4126 |
*) |
| 4127 |
|
| 4128 |
PROCEDURE BuildPragmaField ; |
| 4129 |
VAR |
| 4130 |
expr, |
| 4131 |
const: CARDINAL ; |
| 4132 |
name : Name ; |
| 4133 |
BEGIN |
| 4134 |
PopT (expr) ; |
| 4135 |
PopT (name) ; |
| 4136 |
IF (name # MakeKey ('unused')) AND (name # MakeKey ('bytealignment')) |
| 4137 |
THEN |
| 4138 |
MetaError0 ('only allowed to use the attribute {%Ekbytealignment} in the default record field alignment pragma') |
| 4139 |
END ; |
| 4140 |
IF expr # NulSym |
| 4141 |
THEN |
| 4142 |
GetConstFromFifoQueue (const) ; |
| 4143 |
PushT (const) ; |
| 4144 |
PushT (expr) ; |
| 4145 |
BuildAssignConstant (GetTokenNo ()) |
| 4146 |
END |
| 4147 |
END BuildPragmaField ; |
| 4148 |
|
| 4149 |
|
| 4150 |
(* |
| 4151 |
BuildRepeat - Builds the repeat statement from the quad stack. |
| 4152 |
The Stack is expected to contain: |
| 4153 |
|
| 4154 |
|
| 4155 |
Entry Exit |
| 4156 |
===== ==== |
| 4157 |
|
| 4158 |
|
| 4159 |
Empty |
| 4160 |
<- Ptr |
| 4161 |
+------------+ |
| 4162 |
| RepeatQuad | |
| 4163 |
|------------| |
| 4164 |
|
| 4165 |
*) |
| 4166 |
|
| 4167 |
PROCEDURE BuildRepeat ; |
| 4168 |
BEGIN |
| 4169 |
PushT(NextQuad) |
| 4170 |
END BuildRepeat ; |
| 4171 |
|
| 4172 |
|
| 4173 |
(* |
| 4174 |
BuildUntil - Builds the until part of the repeat statement |
| 4175 |
from the quad stack. |
| 4176 |
The Stack is expected to contain: |
| 4177 |
|
| 4178 |
|
| 4179 |
Entry Exit |
| 4180 |
===== ==== |
| 4181 |
|
| 4182 |
Ptr -> |
| 4183 |
+------------+ |
| 4184 |
| t | f | |
| 4185 |
|------------| |
| 4186 |
| RepeatQuad | Empty |
| 4187 |
|------------| |
| 4188 |
*) |
| 4189 |
|
| 4190 |
PROCEDURE BuildUntil ; |
| 4191 |
VAR |
| 4192 |
t, f, |
| 4193 |
Repeat: CARDINAL ; |
| 4194 |
BEGIN |
| 4195 |
CheckBooleanId ; |
| 4196 |
PopBool(t, f) ; |
| 4197 |
PopT(Repeat) ; |
| 4198 |
BackPatch(f, Repeat) ; (* If False then keep on repeating *) |
| 4199 |
BackPatch(t, NextQuad) ; (* If True then exit repeat *) |
| 4200 |
END BuildUntil ; |
| 4201 |
|
| 4202 |
|
| 4203 |
(* |
| 4204 |
BuildWhile - Builds the While part of the While statement |
| 4205 |
from the quad stack. |
| 4206 |
The Stack is expected to contain: |
| 4207 |
|
| 4208 |
|
| 4209 |
Entry Exit |
| 4210 |
===== ==== |
| 4211 |
|
| 4212 |
<- Ptr |
| 4213 |
|------------| |
| 4214 |
Empty | WhileQuad | |
| 4215 |
|------------| |
| 4216 |
*) |
| 4217 |
|
| 4218 |
PROCEDURE BuildWhile ; |
| 4219 |
BEGIN |
| 4220 |
PushT(NextQuad) |
| 4221 |
END BuildWhile ; |
| 4222 |
|
| 4223 |
|
| 4224 |
(* |
| 4225 |
BuildDoWhile - Builds the Do part of the while statement |
| 4226 |
from the quad stack. |
| 4227 |
The Stack is expected to contain: |
| 4228 |
|
| 4229 |
|
| 4230 |
Entry Exit |
| 4231 |
===== ==== |
| 4232 |
|
| 4233 |
Ptr -> |
| 4234 |
+------------+ +------------+ |
| 4235 |
| t | f | | 0 | f | |
| 4236 |
|------------| |------------| |
| 4237 |
| WhileQuad | | WhileQuad | |
| 4238 |
|------------| |------------| |
| 4239 |
|
| 4240 |
Quadruples |
| 4241 |
|
| 4242 |
BackPatch t exit to the NextQuad |
| 4243 |
*) |
| 4244 |
|
| 4245 |
PROCEDURE BuildDoWhile ; |
| 4246 |
VAR |
| 4247 |
t, f: CARDINAL ; |
| 4248 |
BEGIN |
| 4249 |
CheckBooleanId ; |
| 4250 |
PopBool(t, f) ; |
| 4251 |
BackPatch(t, NextQuad) ; |
| 4252 |
PushBool(0, f) |
| 4253 |
END BuildDoWhile ; |
| 4254 |
|
| 4255 |
|
| 4256 |
(* |
| 4257 |
BuildEndWhile - Builds the end part of the while statement |
| 4258 |
from the quad stack. |
| 4259 |
The Stack is expected to contain: |
| 4260 |
|
| 4261 |
|
| 4262 |
Entry Exit |
| 4263 |
===== ==== |
| 4264 |
|
| 4265 |
Ptr -> |
| 4266 |
+------------+ |
| 4267 |
| t | f | |
| 4268 |
|------------| |
| 4269 |
| WhileQuad | Empty |
| 4270 |
|------------| |
| 4271 |
|
| 4272 |
Quadruples |
| 4273 |
|
| 4274 |
q GotoOp WhileQuad |
| 4275 |
False exit is backpatched with q+1 |
| 4276 |
*) |
| 4277 |
|
| 4278 |
PROCEDURE BuildEndWhile (reltokpos: INTEGER) ; |
| 4279 |
VAR |
| 4280 |
tok : CARDINAL ; |
| 4281 |
While, |
| 4282 |
t, f : CARDINAL ; |
| 4283 |
BEGIN |
| 4284 |
tok := GetTokenNo () ; |
| 4285 |
tok := VAL (INTEGER, tok) + reltokpos ; |
| 4286 |
PopBool (t, f) ; |
| 4287 |
Assert (t=0) ; |
| 4288 |
PopT (While) ; |
| 4289 |
GenQuadO (tok, GotoOp, NulSym, NulSym, While, FALSE) ; |
| 4290 |
BackPatch (f, NextQuad) |
| 4291 |
END BuildEndWhile ; |
| 4292 |
|
| 4293 |
|
| 4294 |
(* |
| 4295 |
BuildLoop - Builds the Loop part of the Loop statement |
| 4296 |
from the quad stack. |
| 4297 |
The Stack is expected to contain: |
| 4298 |
|
| 4299 |
|
| 4300 |
Entry Exit |
| 4301 |
===== ==== |
| 4302 |
|
| 4303 |
<- Ptr |
| 4304 |
Empty +------------+ |
| 4305 |
| LoopQuad | |
| 4306 |
|------------| |
| 4307 |
*) |
| 4308 |
|
| 4309 |
PROCEDURE BuildLoop ; |
| 4310 |
BEGIN |
| 4311 |
PushT(NextQuad) ; |
| 4312 |
PushExit(0) (* Seperate Exit Stack for loop end *) |
| 4313 |
END BuildLoop ; |
| 4314 |
|
| 4315 |
|
| 4316 |
(* |
| 4317 |
BuildExit - Builds the Exit part of the Loop statement. |
| 4318 |
*) |
| 4319 |
|
| 4320 |
PROCEDURE BuildExit ; |
| 4321 |
BEGIN |
| 4322 |
IF IsEmptyWord(ExitStack) |
| 4323 |
THEN |
| 4324 |
MetaError0 ('{%EkEXIT} is only allowed in a {%kLOOP} statement') |
| 4325 |
ELSE |
| 4326 |
GenQuad(GotoOp, NulSym, NulSym, 0) ; |
| 4327 |
PushExit(Merge(PopExit(), NextQuad-1)) |
| 4328 |
END |
| 4329 |
END BuildExit ; |
| 4330 |
|
| 4331 |
|
| 4332 |
(* |
| 4333 |
BuildEndLoop - Builds the End part of the Loop statement |
| 4334 |
from the quad stack. |
| 4335 |
The Stack is expected to contain: |
| 4336 |
|
| 4337 |
|
| 4338 |
Entry Exit |
| 4339 |
===== ==== |
| 4340 |
|
| 4341 |
Ptr -> |
| 4342 |
+------------+ |
| 4343 |
| LoopQuad | Empty |
| 4344 |
|------------| |
| 4345 |
|
| 4346 |
Quadruples |
| 4347 |
|
| 4348 |
Goto _ _ LoopQuad |
| 4349 |
*) |
| 4350 |
|
| 4351 |
PROCEDURE BuildEndLoop ; |
| 4352 |
VAR |
| 4353 |
Loop: CARDINAL ; |
| 4354 |
BEGIN |
| 4355 |
PopT(Loop) ; |
| 4356 |
GenQuad(GotoOp, NulSym, NulSym, Loop) ; |
| 4357 |
BackPatch(PopExit(), NextQuad) |
| 4358 |
END BuildEndLoop ; |
| 4359 |
|
| 4360 |
|
| 4361 |
(* |
| 4362 |
BuildThenIf - Builds the Then part of the If statement |
| 4363 |
from the quad stack. |
| 4364 |
The Stack is expected to contain: |
| 4365 |
|
| 4366 |
|
| 4367 |
Entry Exit |
| 4368 |
===== ==== |
| 4369 |
|
| 4370 |
Ptr -> <- Ptr |
| 4371 |
+------------+ +------------+ |
| 4372 |
| t | f | | 0 | f | |
| 4373 |
|------------| |------------| |
| 4374 |
|
| 4375 |
Quadruples |
| 4376 |
|
| 4377 |
The true exit is BackPatched to point to |
| 4378 |
the NextQuad. |
| 4379 |
*) |
| 4380 |
|
| 4381 |
PROCEDURE BuildThenIf ; |
| 4382 |
VAR |
| 4383 |
t, f: CARDINAL ; |
| 4384 |
BEGIN |
| 4385 |
CheckBooleanId ; |
| 4386 |
PopBool(t, f) ; |
| 4387 |
BackPatch(t, NextQuad) ; |
| 4388 |
PushBool(0, f) |
| 4389 |
END BuildThenIf ; |
| 4390 |
|
| 4391 |
|
| 4392 |
(* |
| 4393 |
BuildElse - Builds the Else part of the If statement |
| 4394 |
from the quad stack. |
| 4395 |
The Stack is expected to contain: |
| 4396 |
|
| 4397 |
|
| 4398 |
Entry Exit |
| 4399 |
===== ==== |
| 4400 |
|
| 4401 |
Ptr -> |
| 4402 |
+------------+ +------------+ |
| 4403 |
| t | f | | t+q | 0 | |
| 4404 |
|------------| |------------| |
| 4405 |
|
| 4406 |
Quadruples |
| 4407 |
|
| 4408 |
q GotoOp _ _ 0 |
| 4409 |
q+1 <- BackPatched from f |
| 4410 |
*) |
| 4411 |
|
| 4412 |
PROCEDURE BuildElse ; |
| 4413 |
VAR |
| 4414 |
t, f: CARDINAL ; |
| 4415 |
BEGIN |
| 4416 |
GenQuad(GotoOp, NulSym, NulSym, 0) ; |
| 4417 |
PopBool(t, f) ; |
| 4418 |
BackPatch(f, NextQuad) ; |
| 4419 |
PushBool(Merge(t, NextQuad-1), 0) (* NextQuad-1 = Goto Quad *) |
| 4420 |
END BuildElse ; |
| 4421 |
|
| 4422 |
|
| 4423 |
(* |
| 4424 |
BuildEndIf - Builds the End part of the If statement |
| 4425 |
from the quad stack. |
| 4426 |
The Stack is expected to contain: |
| 4427 |
|
| 4428 |
|
| 4429 |
Entry Exit |
| 4430 |
===== ==== |
| 4431 |
|
| 4432 |
Ptr -> |
| 4433 |
+------------+ |
| 4434 |
| t | f | Empty |
| 4435 |
|------------| |
| 4436 |
|
| 4437 |
Quadruples |
| 4438 |
|
| 4439 |
Both t and f are backpatched to point to the NextQuad |
| 4440 |
*) |
| 4441 |
|
| 4442 |
PROCEDURE BuildEndIf ; |
| 4443 |
VAR |
| 4444 |
t, f: CARDINAL ; |
| 4445 |
BEGIN |
| 4446 |
PopBool(t, f) ; |
| 4447 |
BackPatch(t, NextQuad) ; |
| 4448 |
BackPatch(f, NextQuad) |
| 4449 |
END BuildEndIf ; |
| 4450 |
|
| 4451 |
|
| 4452 |
(* |
| 4453 |
BuildElsif1 - Builds the Elsif part of the If statement |
| 4454 |
from the quad stack. |
| 4455 |
The Stack is expected to contain: |
| 4456 |
|
| 4457 |
|
| 4458 |
Entry Exit |
| 4459 |
===== ==== |
| 4460 |
|
| 4461 |
Ptr -> |
| 4462 |
+------------+ +------------+ |
| 4463 |
| t | f | | t+q | 0 | |
| 4464 |
|------------| |------------| |
| 4465 |
|
| 4466 |
Quadruples |
| 4467 |
|
| 4468 |
q GotoOp _ _ 0 |
| 4469 |
q+1 <- BackPatched from f |
| 4470 |
*) |
| 4471 |
|
| 4472 |
PROCEDURE BuildElsif1 ; |
| 4473 |
VAR |
| 4474 |
t, f: CARDINAL ; |
| 4475 |
BEGIN |
| 4476 |
GenQuad(GotoOp, NulSym, NulSym, 0) ; |
| 4477 |
PopBool(t, f) ; |
| 4478 |
BackPatch(f, NextQuad) ; |
| 4479 |
PushBool(Merge(t, NextQuad-1), 0) (* NextQuad-1 = Goto Quad *) |
| 4480 |
END BuildElsif1 ; |
| 4481 |
|
| 4482 |
|
| 4483 |
(* |
| 4484 |
BuildElsif2 - Builds the Elsif until part of the If statement |
| 4485 |
from the quad stack. |
| 4486 |
The Stack is expected to contain: |
| 4487 |
|
| 4488 |
|
| 4489 |
Entry Exit |
| 4490 |
===== ==== |
| 4491 |
|
| 4492 |
Ptr -> |
| 4493 |
+--------------+ |
| 4494 |
| 0 | f1 | <- Ptr |
| 4495 |
|--------------| +---------------+ |
| 4496 |
| t2 | f2 | | t2 | f1+f2 | |
| 4497 |
|--------------| |---------------| |
| 4498 |
*) |
| 4499 |
|
| 4500 |
PROCEDURE BuildElsif2 ; |
| 4501 |
VAR |
| 4502 |
t1, f1, |
| 4503 |
t2, f2: CARDINAL ; |
| 4504 |
BEGIN |
| 4505 |
PopBool(t1, f1) ; |
| 4506 |
Assert(t1=0) ; |
| 4507 |
PopBool(t2, f2) ; |
| 4508 |
PushBool(t2, Merge(f1, f2)) |
| 4509 |
END BuildElsif2 ; |
| 4510 |
|
| 4511 |
|
| 4512 |
(* |
| 4513 |
PushOne - pushes the value one to the stack. |
| 4514 |
The Stack is changed: |
| 4515 |
|
| 4516 |
|
| 4517 |
Entry Exit |
| 4518 |
===== ==== |
| 4519 |
|
| 4520 |
<- Ptr |
| 4521 |
+------------+ |
| 4522 |
Ptr -> | 1 | type | |
| 4523 |
|------------| |
| 4524 |
*) |
| 4525 |
|
| 4526 |
PROCEDURE PushOne (tok: CARDINAL; type: CARDINAL; |
| 4527 |
message: ARRAY OF CHAR) ; |
| 4528 |
VAR |
| 4529 |
const: CARDINAL ; |
| 4530 |
BEGIN |
| 4531 |
IF type = NulSym |
| 4532 |
THEN |
| 4533 |
const := MakeConstLit (tok, MakeKey('1'), NulSym) ; |
| 4534 |
PutConstLitInternal (const, TRUE) ; |
| 4535 |
PushTFtok (const, NulSym, tok) |
| 4536 |
ELSIF IsEnumeration (type) |
| 4537 |
THEN |
| 4538 |
IF NoOfElements (type) = 0 |
| 4539 |
THEN |
| 4540 |
MetaErrorString1 (ConCat (InitString ('enumeration type only has one element {%1Dad} and therefore '), |
| 4541 |
Mark (InitString (message))), |
| 4542 |
type) ; |
| 4543 |
PushZero (tok, type) |
| 4544 |
ELSE |
| 4545 |
PushTFtok (Convert, NulSym, tok) ; |
| 4546 |
PushT (type) ; |
| 4547 |
PushTFtok (MakeConstLit (tok, MakeKey ('1'), ZType), ZType, tok) ; |
| 4548 |
PushT (2) ; (* Two parameters *) |
| 4549 |
BuildConvertFunction (Convert, TRUE) |
| 4550 |
END |
| 4551 |
ELSE |
| 4552 |
const := MakeConstLit (tok, MakeKey ('1'), type) ; |
| 4553 |
PutConstLitInternal (const, TRUE) ; |
| 4554 |
PushTFtok (const, type, tok) |
| 4555 |
END |
| 4556 |
END PushOne ; |
| 4557 |
|
| 4558 |
|
| 4559 |
(* |
| 4560 |
PushZero - pushes the value zero to the stack. |
| 4561 |
The Stack is changed: |
| 4562 |
|
| 4563 |
|
| 4564 |
Entry Exit |
| 4565 |
===== ==== |
| 4566 |
|
| 4567 |
<- Ptr |
| 4568 |
+------------+ |
| 4569 |
Ptr -> | 0 | type | |
| 4570 |
|------------| |
| 4571 |
*) |
| 4572 |
|
| 4573 |
PROCEDURE PushZero (tok: CARDINAL; type: CARDINAL) ; |
| 4574 |
BEGIN |
| 4575 |
IF type = NulSym |
| 4576 |
THEN |
| 4577 |
PushTFtok (MakeConstLit (tok, MakeKey ('0'), NulSym), NulSym, tok) |
| 4578 |
ELSIF IsEnumeration (type) |
| 4579 |
THEN |
| 4580 |
PushTFtok (Convert, NulSym, tok) ; |
| 4581 |
PushTtok (type, tok) ; |
| 4582 |
PushTtok (MakeConstLit (tok, MakeKey ('0'), ZType), tok) ; |
| 4583 |
PushT (2) ; (* Two parameters *) |
| 4584 |
BuildConvertFunction (Convert, TRUE) |
| 4585 |
ELSE |
| 4586 |
PushTFtok (MakeConstLit (tok, MakeKey ('0'), type), type, tok) |
| 4587 |
END |
| 4588 |
END PushZero ; |
| 4589 |
|
| 4590 |
|
| 4591 |
(* |
| 4592 |
BuildPseudoBy - Builds the Non existant part of the By |
| 4593 |
clause of the For statement |
| 4594 |
from the quad stack. |
| 4595 |
The Stack is expected to contain: |
| 4596 |
|
| 4597 |
|
| 4598 |
Entry Exit |
| 4599 |
===== ==== |
| 4600 |
|
| 4601 |
<- Ptr |
| 4602 |
+------------+ |
| 4603 |
Ptr -> | BySym | t | |
| 4604 |
+------------+ |------------| |
| 4605 |
| e | t | | e | t | |
| 4606 |
|------------| |------------| |
| 4607 |
*) |
| 4608 |
|
| 4609 |
PROCEDURE BuildPseudoBy ; |
| 4610 |
VAR |
| 4611 |
expr, type, dotok: CARDINAL ; |
| 4612 |
BEGIN |
| 4613 |
(* As there is no BY token this position is the DO at the end of the last expression. *) |
| 4614 |
PopTFtok (expr, type, dotok) ; |
| 4615 |
PushTFtok (expr, type, dotok) ; |
| 4616 |
IF type = NulSym |
| 4617 |
THEN |
| 4618 |
(* type := ZType *) |
| 4619 |
ELSIF IsEnumeration (SkipType (type)) OR (SkipType (type) = Char) |
| 4620 |
THEN |
| 4621 |
(* Use type. *) |
| 4622 |
ELSIF IsOrdinalType (SkipType (type)) |
| 4623 |
THEN |
| 4624 |
type := ZType |
| 4625 |
END ; |
| 4626 |
PushOne (dotok, type, |
| 4627 |
'the implied {%kFOR} loop increment will cause an overflow {%1ad}') |
| 4628 |
END BuildPseudoBy ; |
| 4629 |
|
| 4630 |
|
| 4631 |
(* |
| 4632 |
ForLoopLastIterator - calculate the last iterator value but avoid setting |
| 4633 |
LastIterator twice if it is a constant (in the quads). |
| 4634 |
In the ForLoopLastIteratorVariable case only one |
| 4635 |
path will be chosen but at the time of quadruple |
| 4636 |
generation we do not know the value of BySym. |
| 4637 |
*) |
| 4638 |
|
| 4639 |
PROCEDURE ForLoopLastIterator (LastIterator, e1, e2, BySym: CARDINAL ; |
| 4640 |
e1tok, e2tok, bytok: CARDINAL) ; |
| 4641 |
BEGIN |
| 4642 |
IF NOT IsConst (BySym) |
| 4643 |
THEN |
| 4644 |
MetaErrorT1 (bytok, |
| 4645 |
'{%E}the {%kFOR} loop {%kBY} expression must be constant, the expression {%1a} is variable', |
| 4646 |
BySym) ; |
| 4647 |
MetaErrorDecl (BySym, TRUE) |
| 4648 |
ELSE |
| 4649 |
e1 := DereferenceLValue (e1tok, e1) ; |
| 4650 |
e2 := DereferenceLValue (e2tok, e2) ; |
| 4651 |
GenQuadOTypetok (bytok, LastForIteratorOp, LastIterator, |
| 4652 |
Make2Tuple (e1, e2), BySym, FALSE, FALSE, |
| 4653 |
bytok, MakeVirtual2Tok (e1tok, e2tok), bytok) |
| 4654 |
END |
| 4655 |
END ForLoopLastIterator ; |
| 4656 |
|
| 4657 |
|
| 4658 |
(* |
| 4659 |
BuildForToByDo - Builds the For To By Do part of the For statement |
| 4660 |
from the quad stack. |
| 4661 |
The Stack is expected to contain: |
| 4662 |
|
| 4663 |
|
| 4664 |
Entry Exit |
| 4665 |
===== ==== |
| 4666 |
|
| 4667 |
<- Ptr |
| 4668 |
+----------------+ |
| 4669 |
Ptr -> | RangeId | |
| 4670 |
+----------------+ |----------------| |
| 4671 |
| BySym | ByType | | ForQuad | |
| 4672 |
|----------------| |----------------| |
| 4673 |
| e2 | | LastValue | |
| 4674 |
|----------------| |----------------| |
| 4675 |
| e1 | | BySym | ByType | |
| 4676 |
|----------------| |----------------| |
| 4677 |
| Ident | | IdentSym | |
| 4678 |
|----------------| |----------------| |
| 4679 |
|
| 4680 |
|
| 4681 |
x := e1 ; |
| 4682 |
Note that LASTVALUE is calculated during M2GenGCC |
| 4683 |
after all the types have been resolved. |
| 4684 |
LASTVALUE := ((e2-e1) DIV BySym) * BySym + e1 |
| 4685 |
IF BySym<0 |
| 4686 |
THEN |
| 4687 |
IF e1<e2 |
| 4688 |
THEN |
| 4689 |
goto exit |
| 4690 |
END |
| 4691 |
ELSE |
| 4692 |
IF e1>e2 |
| 4693 |
THEN |
| 4694 |
goto exit |
| 4695 |
END |
| 4696 |
END ; |
| 4697 |
LOOP |
| 4698 |
body |
| 4699 |
IF x=LASTVALUE |
| 4700 |
THEN |
| 4701 |
goto exit |
| 4702 |
END ; |
| 4703 |
INC(x, BySym) |
| 4704 |
END |
| 4705 |
|
| 4706 |
Quadruples: |
| 4707 |
|
| 4708 |
q BecomesOp IdentSym _ e1 |
| 4709 |
q+ LastForIteratorOp LastValue := ((e1-e2) DIV by) * by + e1 |
| 4710 |
q+1 if >= by 0 q+..2 |
| 4711 |
q+2 GotoOp q+3 |
| 4712 |
q+3 If >= e1 e2 q+5 |
| 4713 |
q+4 GotoOp exit |
| 4714 |
q+5 .. |
| 4715 |
q+..1 Goto q+..5 |
| 4716 |
q+..2 If >= e2 e1 q+..4 |
| 4717 |
q+..3 GotoOp exit |
| 4718 |
q+..4 .. |
| 4719 |
|
| 4720 |
The For Loop is regarded: |
| 4721 |
|
| 4722 |
For ident := e1 To e2 By by Do |
| 4723 |
|
| 4724 |
End |
| 4725 |
*) |
| 4726 |
|
| 4727 |
PROCEDURE BuildForToByDo ; |
| 4728 |
VAR |
| 4729 |
l1, l2 : LineNote ; |
| 4730 |
e1, e2, |
| 4731 |
Id : Name ; |
| 4732 |
e1tok, |
| 4733 |
e2tok, |
| 4734 |
idtok, |
| 4735 |
bytok : CARDINAL ; |
| 4736 |
LastIterator, |
| 4737 |
exit1, |
| 4738 |
IdSym, |
| 4739 |
BySym, |
| 4740 |
ByType, |
| 4741 |
ForLoop, |
| 4742 |
RangeId, |
| 4743 |
t, f : CARDINAL ; |
| 4744 |
etype, |
| 4745 |
t1 : CARDINAL ; |
| 4746 |
BEGIN |
| 4747 |
l2 := PopLineNo() ; |
| 4748 |
l1 := PopLineNo() ; |
| 4749 |
UseLineNote(l1) ; |
| 4750 |
PushFor (0) ; |
| 4751 |
PopTFtok (BySym, ByType, bytok) ; |
| 4752 |
PopTtok (e2, e2tok) ; |
| 4753 |
PopTtok (e1, e1tok) ; |
| 4754 |
PopTtok (Id, idtok) ; |
| 4755 |
IdSym := RequestSym (idtok, Id) ; |
| 4756 |
RangeId := InitForLoopBeginRangeCheck (IdSym, idtok, e1, e1tok, e2, e2tok, BySym, bytok) ; |
| 4757 |
BuildRange (RangeId) ; |
| 4758 |
PushTtok (IdSym, idtok) ; |
| 4759 |
PushTtok (e1, e1tok) ; |
| 4760 |
BuildAssignmentWithoutBounds (idtok, TRUE, TRUE) ; |
| 4761 |
|
| 4762 |
UseLineNote (l2) ; |
| 4763 |
LastIterator := MakeTemporary (e2tok, |
| 4764 |
AreConstant (IsConst (e1) AND IsConst (e2) AND |
| 4765 |
IsConst (BySym))) ; |
| 4766 |
PutVar (LastIterator, GetSType (IdSym)) ; |
| 4767 |
etype := MixTypes (GetSType (e1), GetSType (e2), e2tok) ; |
| 4768 |
e1 := doConvert (etype, e1) ; |
| 4769 |
e2 := doConvert (etype, e2) ; |
| 4770 |
|
| 4771 |
ForLoopLastIterator (LastIterator, e1, e2, BySym, e1tok, e2tok, bytok) ; |
| 4772 |
|
| 4773 |
(* q+1 if >= by 0 q+..2 *) |
| 4774 |
(* q+2 GotoOp q+3 *) |
| 4775 |
PushTFtok (BySym, ByType, bytok) ; (* BuildRelOp 1st parameter. *) |
| 4776 |
PushT (GreaterEqualTok) ; (* 2nd parameter. *) |
| 4777 |
(* 3rd parameter. *) |
| 4778 |
PushZero (bytok, ByType) ; |
| 4779 |
|
| 4780 |
BuildRelOp (e2tok) ; (* Choose final expression position. *) |
| 4781 |
PopBool (t, f) ; |
| 4782 |
BackPatch (f, NextQuad) ; |
| 4783 |
(* q+3 If >= e1 e2 q+5 *) |
| 4784 |
(* q+4 GotoOp Exit *) |
| 4785 |
PushTFtok (e1, GetSType (e1), e1tok) ; (* BuildRelOp 1st parameter *) |
| 4786 |
PushT (GreaterEqualTok) ; (* 2nd parameter *) |
| 4787 |
PushTFtok (e2, GetSType (e2), e2tok) ; (* 3rd parameter *) |
| 4788 |
BuildRelOp (e2tok) ; (* Choose final expression position. *) |
| 4789 |
PopBool (t1, exit1) ; |
| 4790 |
BackPatch (t1, NextQuad) ; |
| 4791 |
PushFor (Merge (PopFor (), exit1)) ; (* Merge exit1. *) |
| 4792 |
|
| 4793 |
GenQuad (GotoOp, NulSym, NulSym, 0) ; |
| 4794 |
ForLoop := NextQuad-1 ; |
| 4795 |
|
| 4796 |
(* ELSE. *) |
| 4797 |
|
| 4798 |
BackPatch (t, NextQuad) ; |
| 4799 |
PushTFtok (e2, GetSType(e2), e2tok) ; (* BuildRelOp 1st parameter *) |
| 4800 |
PushT (GreaterEqualTok) ; (* 2nd parameter *) |
| 4801 |
PushTFtok (e1, GetSType(e1), e1tok) ; (* 3rd parameter *) |
| 4802 |
BuildRelOp (e2tok) ; |
| 4803 |
PopBool (t1, exit1) ; |
| 4804 |
BackPatch (t1, NextQuad) ; |
| 4805 |
PushFor (Merge (PopFor (), exit1)) ; (* Merge exit1. *) |
| 4806 |
|
| 4807 |
BackPatch(ForLoop, NextQuad) ; (* Fixes the start of the for loop. *) |
| 4808 |
ForLoop := NextQuad ; |
| 4809 |
|
| 4810 |
(* And set up the stack. *) |
| 4811 |
|
| 4812 |
PushTFtok (IdSym, GetSym (IdSym), idtok) ; |
| 4813 |
PushTFtok (BySym, ByType, bytok) ; |
| 4814 |
PushTFtok (LastIterator, GetSType (LastIterator), e2tok) ; |
| 4815 |
PushT (ForLoop) ; |
| 4816 |
PushT (RangeId) |
| 4817 |
END BuildForToByDo ; |
| 4818 |
|
| 4819 |
|
| 4820 |
(* |
| 4821 |
BuildEndFor - Builds the End part of the For statement |
| 4822 |
from the quad stack. |
| 4823 |
The Stack is expected to contain: |
| 4824 |
|
| 4825 |
|
| 4826 |
Entry Exit |
| 4827 |
===== ==== |
| 4828 |
|
| 4829 |
Ptr -> |
| 4830 |
+----------------+ |
| 4831 |
| RangeId | |
| 4832 |
|----------------| |
| 4833 |
| ForQuad | |
| 4834 |
|----------------| |
| 4835 |
| LastValue | |
| 4836 |
|----------------| |
| 4837 |
| BySym | ByType | |
| 4838 |
|----------------| |
| 4839 |
| IdSym | Empty |
| 4840 |
|----------------| |
| 4841 |
*) |
| 4842 |
|
| 4843 |
PROCEDURE BuildEndFor (endpostok: CARDINAL) ; |
| 4844 |
VAR |
| 4845 |
t, f, |
| 4846 |
tsym, |
| 4847 |
RangeId, |
| 4848 |
IncQuad, |
| 4849 |
ForQuad: CARDINAL ; |
| 4850 |
LastSym, |
| 4851 |
ByType, |
| 4852 |
BySym, |
| 4853 |
bytok, |
| 4854 |
IdSym, |
| 4855 |
idtok : CARDINAL ; |
| 4856 |
BEGIN |
| 4857 |
PopT (RangeId) ; |
| 4858 |
PopT (ForQuad) ; |
| 4859 |
PopT (LastSym) ; |
| 4860 |
PopTFtok (BySym, ByType, bytok) ; |
| 4861 |
PopTtok (IdSym, idtok) ; |
| 4862 |
|
| 4863 |
(* IF IdSym=LastSym THEN exit END *) |
| 4864 |
PushTF(IdSym, GetSType (IdSym)) ; |
| 4865 |
PushT (EqualTok) ; |
| 4866 |
PushTF (LastSym, GetSType (LastSym)) ; |
| 4867 |
BuildRelOp (endpostok) ; |
| 4868 |
PopBool (t, f) ; |
| 4869 |
|
| 4870 |
BackPatch (t, NextQuad) ; |
| 4871 |
GenQuad (GotoOp, NulSym, NulSym, 0) ; |
| 4872 |
PushFor (Merge (PopFor (), NextQuad-1)) ; |
| 4873 |
BackPatch (f, NextQuad) ; |
| 4874 |
IF GetMode (IdSym) = LeftValue |
| 4875 |
THEN |
| 4876 |
(* index variable is a LeftValue, therefore we must dereference it *) |
| 4877 |
tsym := MakeTemporary (idtok, RightValue) ; |
| 4878 |
PutVar (tsym, GetSType (IdSym)) ; |
| 4879 |
CheckPointerThroughNil (idtok, IdSym) ; |
| 4880 |
doIndrX (endpostok, tsym, IdSym) ; |
| 4881 |
BuildRange (InitForLoopEndRangeCheck (tsym, BySym)) ; (* --fixme-- pass endpostok. *) |
| 4882 |
IncQuad := NextQuad ; |
| 4883 |
(* we have explicitly checked using the above and also |
| 4884 |
this addition can legitimately overflow if a cardinal type |
| 4885 |
is counting down. The above test will generate a more |
| 4886 |
precise error message, so we suppress overflow detection |
| 4887 |
here. *) |
| 4888 |
GenQuadOTypetok (bytok, AddOp, tsym, tsym, BySym, FALSE, FALSE, |
| 4889 |
idtok, idtok, bytok) ; |
| 4890 |
CheckPointerThroughNil (idtok, IdSym) ; |
| 4891 |
GenQuadOtok (idtok, XIndrOp, IdSym, GetSType (IdSym), |
| 4892 |
tsym, FALSE, |
| 4893 |
idtok, idtok, idtok) |
| 4894 |
ELSE |
| 4895 |
BuildRange (InitForLoopEndRangeCheck (IdSym, BySym)) ; |
| 4896 |
IncQuad := NextQuad ; |
| 4897 |
(* we have explicitly checked using the above and also |
| 4898 |
this addition can legitimately overflow if a cardinal type |
| 4899 |
is counting down. The above test will generate a more |
| 4900 |
precise error message, so we suppress overflow detection |
| 4901 |
here. |
| 4902 |
|
| 4903 |
This quadruple suppresses the generic binary op type |
| 4904 |
check (performed in M2GenGCC.mod) as there |
| 4905 |
will be a more informative/exhaustive check performed by the |
| 4906 |
InitForLoopBeginRangeCheck setup in BuildForToByDo and |
| 4907 |
performed by M2Range.mod. *) |
| 4908 |
GenQuadOTypetok (idtok, AddOp, IdSym, IdSym, BySym, FALSE, FALSE, |
| 4909 |
idtok, idtok, bytok) |
| 4910 |
END ; |
| 4911 |
GenQuadO (endpostok, GotoOp, NulSym, NulSym, ForQuad, FALSE) ; |
| 4912 |
BackPatch (PopFor (), NextQuad) ; |
| 4913 |
AddForInfo (ForQuad, NextQuad-1, IncQuad, IdSym, idtok) ; |
| 4914 |
PutRangeForIncrement (RangeId, IncQuad) |
| 4915 |
END BuildEndFor ; |
| 4916 |
|
| 4917 |
|
| 4918 |
(* |
| 4919 |
BuildCaseStart - starts the case statement. |
| 4920 |
It initializes a backpatch list on the compile |
| 4921 |
time stack, the list is used to contain all |
| 4922 |
case break points. The list is later backpatched |
| 4923 |
and contains all positions of the case statement |
| 4924 |
which jump to the end of the case statement. |
| 4925 |
The stack also contains room for a boolean |
| 4926 |
expression, this is needed to allow , operator |
| 4927 |
in the CaseField alternatives. |
| 4928 |
|
| 4929 |
The Stack is expected to contain: |
| 4930 |
|
| 4931 |
|
| 4932 |
Entry Exit |
| 4933 |
===== ==== |
| 4934 |
|
| 4935 |
<- Ptr |
| 4936 |
+------------+ |
| 4937 |
| 0 | 0 | |
| 4938 |
|------------| |
| 4939 |
| 0 | 0 | |
| 4940 |
+-------------+ |------------| |
| 4941 |
| Expr | | | Expr | | |
| 4942 |
|-------------| |------------| |
| 4943 |
*) |
| 4944 |
|
| 4945 |
PROCEDURE BuildCaseStart ; |
| 4946 |
BEGIN |
| 4947 |
BuildRange (InitCaseBounds (PushCase (NulSym, NulSym, OperandT (1)))) ; |
| 4948 |
PushBool (0, 0) ; (* BackPatch list initialized *) |
| 4949 |
PushBool (0, 0) (* Room for a boolean expression *) |
| 4950 |
END BuildCaseStart ; |
| 4951 |
|
| 4952 |
|
| 4953 |
(* |
| 4954 |
BuildCaseStartStatementSequence - starts the statement sequence |
| 4955 |
inside a case clause. |
| 4956 |
BackPatches the true exit to the |
| 4957 |
NextQuad. |
| 4958 |
The Stack: |
| 4959 |
|
| 4960 |
Entry Exit |
| 4961 |
|
| 4962 |
Ptr -> <- Ptr |
| 4963 |
+-----------+ +------------+ |
| 4964 |
| t | f | | 0 | f | |
| 4965 |
|-----------| |------------| |
| 4966 |
*) |
| 4967 |
|
| 4968 |
PROCEDURE BuildCaseStartStatementSequence ; |
| 4969 |
VAR |
| 4970 |
t, f: CARDINAL ; |
| 4971 |
BEGIN |
| 4972 |
PopBool (t, f) ; |
| 4973 |
BackPatch (t, NextQuad) ; |
| 4974 |
PushBool (0, f) |
| 4975 |
END BuildCaseStartStatementSequence ; |
| 4976 |
|
| 4977 |
|
| 4978 |
(* |
| 4979 |
BuildCaseEndStatementSequence - ends the statement sequence |
| 4980 |
inside a case clause. |
| 4981 |
BackPatches the false exit f1 to the |
| 4982 |
NextQuad. |
| 4983 |
Asserts that t1 and f2 is 0 |
| 4984 |
Pushes t2+q and 0 |
| 4985 |
|
| 4986 |
Quadruples: |
| 4987 |
|
| 4988 |
q GotoOp _ _ 0 |
| 4989 |
|
| 4990 |
The Stack: |
| 4991 |
|
| 4992 |
Entry Exit |
| 4993 |
|
| 4994 |
Ptr -> <- Ptr |
| 4995 |
+-----------+ +------------+ |
| 4996 |
| t1 | f1 | | 0 | 0 | |
| 4997 |
|-----------| |------------| |
| 4998 |
| t2 | f2 | | t2+q | 0 | |
| 4999 |
|-----------| |------------| |
| 5000 |
*) |
| 5001 |
|
| 5002 |
PROCEDURE BuildCaseEndStatementSequence ; |
| 5003 |
VAR |
| 5004 |
t1, f1, |
| 5005 |
t2, f2: CARDINAL ; |
| 5006 |
BEGIN |
| 5007 |
GenQuad (GotoOp, NulSym, NulSym, 0) ; |
| 5008 |
PopBool (t1, f1) ; |
| 5009 |
PopBool (t2, f2) ; (* t2 contains the break list for the case *) |
| 5010 |
BackPatch (f1, NextQuad) ; (* f1 no longer needed *) |
| 5011 |
Assert (t1=0) ; |
| 5012 |
Assert (f2=0) ; |
| 5013 |
PushBool (Merge (t2, NextQuad-1), 0) ; (* NextQuad-1 = Goto Quad *) |
| 5014 |
PushBool (0, 0) (* Room for boolean expression *) |
| 5015 |
END BuildCaseEndStatementSequence ; |
| 5016 |
|
| 5017 |
|
| 5018 |
(* |
| 5019 |
BuildCaseRange - builds the range testing quaruples for |
| 5020 |
a case clause. |
| 5021 |
|
| 5022 |
IF (e1>=ce1) AND (e1<=ce2) |
| 5023 |
THEN |
| 5024 |
|
| 5025 |
ELS.. |
| 5026 |
|
| 5027 |
The Stack: |
| 5028 |
|
| 5029 |
Entry Exit |
| 5030 |
|
| 5031 |
Ptr -> |
| 5032 |
+-----------+ |
| 5033 |
| ce2 | <- Ptr |
| 5034 |
|-----------| +-----------+ |
| 5035 |
| ce1 | | t | f | |
| 5036 |
|-----------| |-----------| |
| 5037 |
| t1 | f1 | | t1 | f1 | |
| 5038 |
|-----------| |-----------| |
| 5039 |
| t2 | f2 | | t2 | f2 | |
| 5040 |
|-----------| |-----------| |
| 5041 |
| e1 | | e1 | |
| 5042 |
|-----------| |-----------| |
| 5043 |
*) |
| 5044 |
|
| 5045 |
PROCEDURE BuildCaseRange ; |
| 5046 |
VAR |
| 5047 |
ce1, ce2, |
| 5048 |
combinedtok, |
| 5049 |
ce1tok, |
| 5050 |
ce2tok, |
| 5051 |
e1tok, |
| 5052 |
e1, |
| 5053 |
t2, f2, |
| 5054 |
t1, f1 : CARDINAL ; |
| 5055 |
BEGIN |
| 5056 |
PopTtok (ce2, ce2tok) ; |
| 5057 |
PopTtok (ce1, ce1tok) ; |
| 5058 |
combinedtok := MakeVirtualTok (ce2tok, ce2tok, ce1tok) ; |
| 5059 |
AddRange (ce1, ce2, combinedtok) ; |
| 5060 |
PopBool (t1, f1) ; |
| 5061 |
PopBool (t2, f2) ; |
| 5062 |
PopTtok (e1, e1tok) ; |
| 5063 |
PushTtok (e1, e1tok) ; (* leave e1 on bottom of stack when exit procedure *) |
| 5064 |
PushBool (t2, f2) ; |
| 5065 |
PushBool (t1, f1) ; (* also leave t1 and f1 on the bottom of the stack *) |
| 5066 |
PushTtok (e1, e1tok) ; |
| 5067 |
PushT (GreaterEqualTok) ; |
| 5068 |
PushTtok (ce1, ce1tok) ; |
| 5069 |
BuildRelOp (combinedtok) ; |
| 5070 |
PushT (AndTok) ; |
| 5071 |
RecordOp ; |
| 5072 |
PushTtok (e1, e1tok) ; |
| 5073 |
PushT (LessEqualTok) ; |
| 5074 |
PushTtok (ce2, ce2tok) ; |
| 5075 |
BuildRelOp (combinedtok) ; |
| 5076 |
BuildBinaryOp |
| 5077 |
END BuildCaseRange ; |
| 5078 |
|
| 5079 |
|
| 5080 |
(* |
| 5081 |
BuildCaseEquality - builds the range testing quadruples for |
| 5082 |
a case clause. |
| 5083 |
|
| 5084 |
IF e1=ce1 |
| 5085 |
THEN |
| 5086 |
|
| 5087 |
ELS.. |
| 5088 |
|
| 5089 |
The Stack: |
| 5090 |
|
| 5091 |
Entry Exit |
| 5092 |
|
| 5093 |
Ptr -> |
| 5094 |
+-----------+ +-----------+ |
| 5095 |
| ce1 | | t | f | |
| 5096 |
|-----------| |-----------| |
| 5097 |
| t1 | f1 | | t1 | f1 | |
| 5098 |
|-----------| |-----------| |
| 5099 |
| t2 | f2 | | t2 | f2 | |
| 5100 |
|-----------| |-----------| |
| 5101 |
| e1 | | e1 | |
| 5102 |
|-----------| |-----------| |
| 5103 |
*) |
| 5104 |
|
| 5105 |
PROCEDURE BuildCaseEquality ; |
| 5106 |
VAR |
| 5107 |
ce1tok, |
| 5108 |
e1tok, |
| 5109 |
ce1, e1, |
| 5110 |
t2, f2, |
| 5111 |
t1, f1 : CARDINAL ; |
| 5112 |
BEGIN |
| 5113 |
PopTtok (ce1, ce1tok) ; |
| 5114 |
AddRange (ce1, NulSym, ce1tok) ; |
| 5115 |
PopBool (t1, f1) ; |
| 5116 |
PopBool (t2, f2) ; |
| 5117 |
PopTtok (e1, e1tok) ; |
| 5118 |
PushTtok (e1, e1tok) ; (* leave e1 on bottom of stack when exit procedure *) |
| 5119 |
PushBool (t2, f2) ; (* also leave t2 and f2 on the bottom of the stack *) |
| 5120 |
PushBool (t1, f1) ; |
| 5121 |
PushTtok (e1, e1tok) ; |
| 5122 |
PushT (EqualTok) ; |
| 5123 |
PushTtok (ce1, ce1tok) ; |
| 5124 |
BuildRelOp (ce1tok) |
| 5125 |
END BuildCaseEquality ; |
| 5126 |
|
| 5127 |
|
| 5128 |
(* |
| 5129 |
BuildCaseList - merges two case tests into one |
| 5130 |
|
| 5131 |
The Stack: |
| 5132 |
|
| 5133 |
Entry Exit |
| 5134 |
|
| 5135 |
Ptr -> |
| 5136 |
+-----------+ |
| 5137 |
| t2 | f2 | |
| 5138 |
|-----------| +-------------+ |
| 5139 |
| t1 | f1 | | t1+t2| f1+f2| |
| 5140 |
|-----------| |-------------| |
| 5141 |
*) |
| 5142 |
|
| 5143 |
PROCEDURE BuildCaseList ; |
| 5144 |
VAR |
| 5145 |
t2, f2, |
| 5146 |
t1, f1: CARDINAL ; |
| 5147 |
BEGIN |
| 5148 |
PopBool (t2, f2) ; |
| 5149 |
PopBool (t1, f1) ; |
| 5150 |
PushBool (Merge (t1, t2), Merge (f1, f2)) |
| 5151 |
END BuildCaseList ; |
| 5152 |
|
| 5153 |
|
| 5154 |
(* |
| 5155 |
BuildCaseOr - builds the , in the case clause. |
| 5156 |
|
| 5157 |
The Stack: |
| 5158 |
|
| 5159 |
Entry Exit |
| 5160 |
|
| 5161 |
Ptr -> <- Ptr |
| 5162 |
+-----------+ +------------+ |
| 5163 |
| t | f | | t | 0 | |
| 5164 |
|-----------| |------------| |
| 5165 |
*) |
| 5166 |
|
| 5167 |
PROCEDURE BuildCaseOr ; |
| 5168 |
VAR |
| 5169 |
t, f: CARDINAL ; |
| 5170 |
BEGIN |
| 5171 |
PopBool (t, f) ; |
| 5172 |
BackPatch (f, NextQuad) ; |
| 5173 |
PushBool (t, 0) |
| 5174 |
END BuildCaseOr ; |
| 5175 |
|
| 5176 |
|
| 5177 |
(* |
| 5178 |
BuildCaseElse - builds the else of case clause. |
| 5179 |
|
| 5180 |
The Stack: |
| 5181 |
|
| 5182 |
Entry Exit |
| 5183 |
|
| 5184 |
Ptr -> <- Ptr |
| 5185 |
+-----------+ +------------+ |
| 5186 |
| t | f | | t | 0 | |
| 5187 |
|-----------| |------------| |
| 5188 |
*) |
| 5189 |
|
| 5190 |
PROCEDURE BuildCaseElse ; |
| 5191 |
VAR |
| 5192 |
t, f: CARDINAL ; |
| 5193 |
BEGIN |
| 5194 |
PopBool (t, f) ; |
| 5195 |
BackPatch (f, NextQuad) ; |
| 5196 |
PushBool (t, 0) |
| 5197 |
END BuildCaseElse ; |
| 5198 |
|
| 5199 |
|
| 5200 |
(* |
| 5201 |
BuildCaseEnd - builds the end of case clause. |
| 5202 |
|
| 5203 |
The Stack: |
| 5204 |
|
| 5205 |
Entry Exit |
| 5206 |
|
| 5207 |
Ptr -> |
| 5208 |
+-----------+ |
| 5209 |
| t1 | f1 | |
| 5210 |
|-----------| |
| 5211 |
| t2 | f2 | |
| 5212 |
|-----------| |
| 5213 |
| e1 | |
| 5214 |
|-----------| Empty |
| 5215 |
*) |
| 5216 |
|
| 5217 |
PROCEDURE BuildCaseEnd ; |
| 5218 |
VAR |
| 5219 |
e1, |
| 5220 |
t, f: CARDINAL ; |
| 5221 |
BEGIN |
| 5222 |
PopBool (t, f) ; |
| 5223 |
BackPatch (f, NextQuad) ; |
| 5224 |
BackPatch (t, NextQuad) ; |
| 5225 |
PopBool (t, f) ; |
| 5226 |
BackPatch (f, NextQuad) ; |
| 5227 |
BackPatch (t, NextQuad) ; |
| 5228 |
PopT (e1) ; |
| 5229 |
PopCase |
| 5230 |
END BuildCaseEnd ; |
| 5231 |
|
| 5232 |
|
| 5233 |
(* |
| 5234 |
BuildCaseCheck - builds the case checking code to ensure that |
| 5235 |
the program does not need an else clause at runtime. |
| 5236 |
The stack is unaltered. |
| 5237 |
*) |
| 5238 |
|
| 5239 |
PROCEDURE BuildCaseCheck ; |
| 5240 |
BEGIN |
| 5241 |
BuildError (InitNoElseRangeCheck ()) |
| 5242 |
END BuildCaseCheck ; |
| 5243 |
|
| 5244 |
|
| 5245 |
(* |
| 5246 |
BuildNulParam - Builds a nul parameter on the stack. |
| 5247 |
The Stack: |
| 5248 |
|
| 5249 |
Entry Exit |
| 5250 |
|
| 5251 |
<- Ptr |
| 5252 |
Empty +------------+ |
| 5253 |
| 0 | |
| 5254 |
|------------| |
| 5255 |
*) |
| 5256 |
|
| 5257 |
PROCEDURE BuildNulParam ; |
| 5258 |
BEGIN |
| 5259 |
PushT (0) |
| 5260 |
END BuildNulParam ; |
| 5261 |
|
| 5262 |
|
| 5263 |
(* |
| 5264 |
BuildSizeCheckStart - switches off all quadruple generation if the function SIZE or HIGH |
| 5265 |
is being "called". This should be done as SIZE only requires the |
| 5266 |
actual type of the expression, not its value. Consider the problem of |
| 5267 |
SIZE(UninitializedPointer^) which is quite legal and it must |
| 5268 |
also be safe! |
| 5269 |
ISO Modula-2 also allows HIGH(a[0]) for a two dimensional array |
| 5270 |
and there is no need to compute a[0], we just need to follow the |
| 5271 |
type and count dimensions. However if SIZE(a) or HIGH(a) occurs |
| 5272 |
and, a, is an unbounded array then we turn on quadruple generation. |
| 5273 |
|
| 5274 |
The Stack is expected to contain: |
| 5275 |
|
| 5276 |
|
| 5277 |
Entry Exit |
| 5278 |
===== ==== |
| 5279 |
|
| 5280 |
Ptr -> <- Ptr |
| 5281 |
+----------------------+ +----------------------+ |
| 5282 |
| ProcSym | Type | tok | | ProcSym | Type | tok | |
| 5283 |
|----------------------| |----------------------| |
| 5284 |
*) |
| 5285 |
|
| 5286 |
PROCEDURE BuildSizeCheckStart ; |
| 5287 |
VAR |
| 5288 |
ProcSym, Type, tok: CARDINAL ; |
| 5289 |
BEGIN |
| 5290 |
PopTFtok (ProcSym, Type, tok) ; |
| 5291 |
IF (ProcSym=Size) OR (ProcSym=TSize) OR (ProcSym=TBitSize) |
| 5292 |
THEN |
| 5293 |
QuadrupleGeneration := FALSE ; |
| 5294 |
BuildingSize := TRUE |
| 5295 |
ELSIF ProcSym=High |
| 5296 |
THEN |
| 5297 |
QuadrupleGeneration := FALSE ; |
| 5298 |
BuildingHigh := TRUE |
| 5299 |
END ; |
| 5300 |
PushTFtok (ProcSym, Type, tok) |
| 5301 |
END BuildSizeCheckStart ; |
| 5302 |
|
| 5303 |
|
| 5304 |
(* |
| 5305 |
BuildSizeCheckEnd - checks to see whether the function "called" was in fact SIZE. |
| 5306 |
If so then we restore quadruple generation. |
| 5307 |
*) |
| 5308 |
|
| 5309 |
PROCEDURE BuildSizeCheckEnd (ProcSym: CARDINAL) ; |
| 5310 |
BEGIN |
| 5311 |
IF (ProcSym=Size) OR (ProcSym=TSize) OR (ProcSym=TBitSize) |
| 5312 |
THEN |
| 5313 |
QuadrupleGeneration := TRUE ; |
| 5314 |
BuildingSize := FALSE |
| 5315 |
ELSIF ProcSym=High |
| 5316 |
THEN |
| 5317 |
QuadrupleGeneration := TRUE ; |
| 5318 |
BuildingHigh := FALSE |
| 5319 |
END ; |
| 5320 |
END BuildSizeCheckEnd ; |
| 5321 |
|
| 5322 |
|
| 5323 |
(* |
| 5324 |
BuildProcedureCall - builds a procedure call. |
| 5325 |
Although this procedure does not directly |
| 5326 |
destroy the procedure parameters, it calls |
| 5327 |
routine which will manipulate the stack and |
| 5328 |
so the entry and exit states of the stack are shown. |
| 5329 |
|
| 5330 |
The Stack: |
| 5331 |
|
| 5332 |
|
| 5333 |
Entry Exit |
| 5334 |
|
| 5335 |
Ptr -> |
| 5336 |
+----------------+ |
| 5337 |
| NoOfParam | |
| 5338 |
|----------------| |
| 5339 |
| Param 1 | |
| 5340 |
|----------------| |
| 5341 |
| Param 2 | |
| 5342 |
|----------------| |
| 5343 |
. . |
| 5344 |
. . |
| 5345 |
. . |
| 5346 |
|----------------| |
| 5347 |
| Param # | |
| 5348 |
|----------------| |
| 5349 |
| ProcSym | Type | Empty |
| 5350 |
|----------------| |
| 5351 |
*) |
| 5352 |
|
| 5353 |
PROCEDURE BuildProcedureCall (tokno: CARDINAL) ; |
| 5354 |
VAR |
| 5355 |
NoOfParam, |
| 5356 |
ProcSym : CARDINAL ; |
| 5357 |
BEGIN |
| 5358 |
PopT(NoOfParam) ; |
| 5359 |
ProcSym := OperandT (NoOfParam+1) ; |
| 5360 |
PushT (NoOfParam) ; (* Compile time stack restored to entry state *) |
| 5361 |
IF IsPseudoBaseProcedure (ProcSym) OR IsPseudoSystemProcedure (ProcSym) |
| 5362 |
THEN |
| 5363 |
DisplayStack ; |
| 5364 |
ManipulatePseudoCallParameters ; |
| 5365 |
DisplayStack ; |
| 5366 |
BuildPseudoProcedureCall (tokno) ; |
| 5367 |
DisplayStack |
| 5368 |
ELSIF IsUnknown (ProcSym) |
| 5369 |
THEN |
| 5370 |
MetaError1 ('{%1Ua} is not recognised as a procedure, check declaration or import', ProcSym) ; |
| 5371 |
PopN (NoOfParam + 2) |
| 5372 |
ELSE |
| 5373 |
DisplayStack ; |
| 5374 |
BuildRealProcedureCall (tokno) ; |
| 5375 |
DisplayStack ; |
| 5376 |
END |
| 5377 |
END BuildProcedureCall ; |
| 5378 |
|
| 5379 |
|
| 5380 |
(* |
| 5381 |
BuildRealProcedureCall - builds a real procedure call. |
| 5382 |
The Stack: |
| 5383 |
|
| 5384 |
|
| 5385 |
Entry Exit |
| 5386 |
|
| 5387 |
Ptr -> |
| 5388 |
+----------------+ |
| 5389 |
| NoOfParam | |
| 5390 |
|----------------| |
| 5391 |
| Param 1 | |
| 5392 |
|----------------| |
| 5393 |
| Param 2 | |
| 5394 |
|----------------| |
| 5395 |
. . |
| 5396 |
. . |
| 5397 |
. . |
| 5398 |
|----------------| |
| 5399 |
| Param # | |
| 5400 |
|----------------| |
| 5401 |
| ProcSym | Type | Empty |
| 5402 |
|----------------| |
| 5403 |
*) |
| 5404 |
|
| 5405 |
PROCEDURE BuildRealProcedureCall (tokno: CARDINAL) ; |
| 5406 |
VAR |
| 5407 |
NoOfParam: CARDINAL ; |
| 5408 |
ProcSym : CARDINAL ; |
| 5409 |
BEGIN |
| 5410 |
PopT (NoOfParam) ; |
| 5411 |
PushT (NoOfParam) ; |
| 5412 |
ProcSym := OperandT (NoOfParam+2) ; |
| 5413 |
ProcSym := SkipConst (ProcSym) ; |
| 5414 |
(* tokno := OperandTtok (NoOfParam+2) ; *) (* --checkme-- *) |
| 5415 |
IF IsVar (ProcSym) |
| 5416 |
THEN |
| 5417 |
(* Procedure Variable ? *) |
| 5418 |
ProcSym := SkipType (OperandF (NoOfParam+2)) |
| 5419 |
END ; |
| 5420 |
IF IsDefImp (GetScope (ProcSym)) AND IsDefinitionForC (GetScope (ProcSym)) |
| 5421 |
THEN |
| 5422 |
BuildRealFuncProcCall (tokno, FALSE, TRUE, FALSE) |
| 5423 |
ELSE |
| 5424 |
BuildRealFuncProcCall (tokno, FALSE, FALSE, FALSE) |
| 5425 |
END |
| 5426 |
END BuildRealProcedureCall ; |
| 5427 |
|
| 5428 |
|
| 5429 |
(* |
| 5430 |
BuildRealFuncProcCall - builds a real procedure or function call. |
| 5431 |
The Stack: |
| 5432 |
|
| 5433 |
|
| 5434 |
Entry Exit |
| 5435 |
|
| 5436 |
Ptr -> |
| 5437 |
+----------------+ |
| 5438 |
| NoOfParam | |
| 5439 |
|----------------| |
| 5440 |
| Param 1 | |
| 5441 |
|----------------| |
| 5442 |
| Param 2 | |
| 5443 |
|----------------| |
| 5444 |
. . |
| 5445 |
. . |
| 5446 |
. . |
| 5447 |
|----------------| |
| 5448 |
| Param # | |
| 5449 |
|----------------| |
| 5450 |
| ProcSym | Type | Empty |
| 5451 |
|----------------| |
| 5452 |
*) |
| 5453 |
|
| 5454 |
PROCEDURE BuildRealFuncProcCall (tokno: CARDINAL; IsFunc, IsForC, ConstExpr: BOOLEAN) ; |
| 5455 |
VAR |
| 5456 |
AllocateProc, |
| 5457 |
DeallocateProc, |
| 5458 |
ForcedFunc, |
| 5459 |
ParamConstant : BOOLEAN ; |
| 5460 |
trash, |
| 5461 |
resulttok, |
| 5462 |
paramtok, |
| 5463 |
proctok, |
| 5464 |
NoOfParameters, |
| 5465 |
i, pi, |
| 5466 |
ParamType, |
| 5467 |
Param1, (* Used to remember first param for allocate/deallocate. *) |
| 5468 |
ReturnVar, |
| 5469 |
ProcSym, |
| 5470 |
Proc : CARDINAL ; |
| 5471 |
BEGIN |
| 5472 |
Param1 := NulSym ; |
| 5473 |
ParamType := NulSym ; |
| 5474 |
CheckProcedureParameters (IsForC) ; |
| 5475 |
PopT (NoOfParameters) ; |
| 5476 |
PushT (NoOfParameters) ; (* Restore stack to original state. *) |
| 5477 |
ProcSym := OperandT (NoOfParameters+2) ; |
| 5478 |
proctok := tokno ; (* OperandTtok (NoOfParameters+2) ; *) |
| 5479 |
IF proctok = UnknownTokenNo |
| 5480 |
THEN |
| 5481 |
proctok := GetTokenNo () |
| 5482 |
END ; |
| 5483 |
paramtok := proctok ; |
| 5484 |
ProcSym := SkipConst (ProcSym) ; |
| 5485 |
ForcedFunc := FALSE ; |
| 5486 |
AllocateProc := FALSE ; |
| 5487 |
DeallocateProc := FALSE ; |
| 5488 |
IF IsVar (ProcSym) |
| 5489 |
THEN |
| 5490 |
(* Procedure Variable ? *) |
| 5491 |
Proc := SkipType (OperandF (NoOfParameters+2)) ; |
| 5492 |
ParamConstant := FALSE |
| 5493 |
ELSE |
| 5494 |
Proc := ProcSym ; |
| 5495 |
ParamConstant := TRUE ; |
| 5496 |
AllocateProc := GetSymName (Proc) = MakeKey('ALLOCATE') ; |
| 5497 |
DeallocateProc := GetSymName (Proc) = MakeKey('DEALLOCATE') |
| 5498 |
END ; |
| 5499 |
IF IsFunc |
| 5500 |
THEN |
| 5501 |
IF GetSType (Proc) = NulSym |
| 5502 |
THEN |
| 5503 |
MetaErrors1 ('procedure {%1a} cannot be used as a function', |
| 5504 |
'procedure {%1Da} does not have a return type', |
| 5505 |
Proc) |
| 5506 |
END |
| 5507 |
ELSE |
| 5508 |
(* is being called as a procedure *) |
| 5509 |
IF GetSType (Proc) # NulSym |
| 5510 |
THEN |
| 5511 |
(* however it was declared as a procedure function *) |
| 5512 |
IF NOT IsReturnOptionalAny (Proc) |
| 5513 |
THEN |
| 5514 |
MetaErrors1 ('function {%1a} is being called but its return value is ignored', |
| 5515 |
'function {%1Da} return a type {%1ta:of {%1ta}}', |
| 5516 |
Proc) |
| 5517 |
END ; |
| 5518 |
IsFunc := TRUE ; |
| 5519 |
ForcedFunc := TRUE |
| 5520 |
END |
| 5521 |
END ; |
| 5522 |
IF AllocateProc OR DeallocateProc |
| 5523 |
THEN |
| 5524 |
Param1 := OperandT (NoOfParameters+1) (* Remember this before manipulating. *) |
| 5525 |
END ; |
| 5526 |
ManipulateParameters (IsForC) ; |
| 5527 |
CheckParameterOrdinals ; |
| 5528 |
PopT(NoOfParameters) ; |
| 5529 |
IF IsFunc |
| 5530 |
THEN |
| 5531 |
GenQuad (ParamOp, 0, Proc, ProcSym) (* Space for return value *) |
| 5532 |
END ; |
| 5533 |
IF (NoOfParameters+1=NoOfParamAny(Proc)) AND UsesOptArgAny (Proc) |
| 5534 |
THEN |
| 5535 |
GenQuad (OptParamOp, NoOfParamAny (Proc), Proc, Proc) |
| 5536 |
END ; |
| 5537 |
i := NoOfParameters ; |
| 5538 |
pi := 1 ; (* stack index referencing stacked parameter, i *) |
| 5539 |
WHILE i>0 DO |
| 5540 |
paramtok := OperandTtok (pi) ; |
| 5541 |
IF (AllocateProc OR DeallocateProc) AND (i = 1) AND (Param1 # NulSym) |
| 5542 |
THEN |
| 5543 |
ParamType := GetItemPointedTo (Param1) ; |
| 5544 |
IF ParamType = NulSym |
| 5545 |
THEN |
| 5546 |
GenQuadO (paramtok, ParamOp, i, Proc, OperandT (pi), TRUE) |
| 5547 |
ELSE |
| 5548 |
IF AllocateProc |
| 5549 |
THEN |
| 5550 |
trash := MakeTemporary (paramtok, RightValue) ; |
| 5551 |
PutVar (trash, ParamType) ; |
| 5552 |
PutVarHeap (trash, TRUE) |
| 5553 |
ELSE |
| 5554 |
Assert (DeallocateProc) ; |
| 5555 |
trash := Nil |
| 5556 |
END ; |
| 5557 |
GenQuadOTrash (paramtok, ParamOp, i, Proc, OperandT (pi), TRUE, trash) |
| 5558 |
END |
| 5559 |
ELSE |
| 5560 |
GenQuadO (paramtok, ParamOp, i, Proc, OperandT (pi), TRUE) |
| 5561 |
END ; |
| 5562 |
IF NOT IsConst (OperandT (pi)) |
| 5563 |
THEN |
| 5564 |
ParamConstant := FALSE |
| 5565 |
END ; |
| 5566 |
DEC (i) ; |
| 5567 |
INC (pi) |
| 5568 |
END ; |
| 5569 |
GenQuadO (proctok, CallOp, NulSym, NulSym, ProcSym, TRUE) ; |
| 5570 |
PopN (NoOfParameters+1) ; (* Destroy arguments and procedure call *) |
| 5571 |
IF IsFunc |
| 5572 |
THEN |
| 5573 |
(* ReturnVar has the type of the procedure. *) |
| 5574 |
resulttok := MakeVirtualTok (proctok, proctok, paramtok) ; |
| 5575 |
IF ConstExpr AND (NOT IsProcedureBuiltinAvailable (Proc)) |
| 5576 |
THEN |
| 5577 |
MetaError1('{%1d} {%1ad} cannot be used in a constant expression', Proc) ; |
| 5578 |
ParamConstant := FALSE |
| 5579 |
END ; |
| 5580 |
ReturnVar := MakeTemporary (resulttok, AreConstant (ParamConstant AND ConstExpr)) ; |
| 5581 |
PutVar (ReturnVar, GetSType (Proc)) ; |
| 5582 |
GenQuadO (resulttok, FunctValueOp, ReturnVar, NulSym, Proc, TRUE) ; |
| 5583 |
IF NOT ForcedFunc |
| 5584 |
THEN |
| 5585 |
PushTFtok (ReturnVar, GetSType (Proc), resulttok) |
| 5586 |
END |
| 5587 |
END |
| 5588 |
END BuildRealFuncProcCall ; |
| 5589 |
|
| 5590 |
|
| 5591 |
(* |
| 5592 |
CheckProcedureParameters - Checks the parameters which are being passed to |
| 5593 |
procedure ProcSym. |
| 5594 |
|
| 5595 |
The Stack: |
| 5596 |
|
| 5597 |
|
| 5598 |
Entry Exit |
| 5599 |
|
| 5600 |
Ptr -> <- Ptr |
| 5601 |
+----------------+ +----------------+ |
| 5602 |
| NoOfParam | | NoOfParam | |
| 5603 |
|----------------| |----------------| |
| 5604 |
| Param 1 | | Param 1 | |
| 5605 |
|----------------| |----------------| |
| 5606 |
| Param 2 | | Param 2 | |
| 5607 |
|----------------| |----------------| |
| 5608 |
. . . . |
| 5609 |
. . . . |
| 5610 |
. . . . |
| 5611 |
|----------------| |----------------| |
| 5612 |
| Param # | | Param # | |
| 5613 |
|----------------| |----------------| |
| 5614 |
| ProcSym | Type | | ProcSym | Type | |
| 5615 |
|----------------| |----------------| |
| 5616 |
|
| 5617 |
*) |
| 5618 |
|
| 5619 |
PROCEDURE CheckProcedureParameters (IsForC: BOOLEAN) ; |
| 5620 |
VAR |
| 5621 |
proctok, |
| 5622 |
paramtok : CARDINAL ; |
| 5623 |
n1, n2 : Name ; |
| 5624 |
ParamCheckId, |
| 5625 |
Dim, |
| 5626 |
Actual, |
| 5627 |
FormalI, |
| 5628 |
ParamTotal, |
| 5629 |
pi, |
| 5630 |
Proc, |
| 5631 |
ProcSym, |
| 5632 |
i : CARDINAL ; |
| 5633 |
s : String ; |
| 5634 |
BEGIN |
| 5635 |
PopT(ParamTotal) ; |
| 5636 |
PushT(ParamTotal) ; (* Restore stack to origional state *) |
| 5637 |
ProcSym := OperandT(ParamTotal+1+1) ; |
| 5638 |
proctok := OperandTtok(ParamTotal+1+1) ; |
| 5639 |
IF IsVar(ProcSym) AND IsProcType(GetDType(ProcSym)) |
| 5640 |
THEN |
| 5641 |
(* Procedure Variable ? *) |
| 5642 |
Proc := SkipType(OperandF(ParamTotal+1+1)) |
| 5643 |
ELSE |
| 5644 |
Proc := SkipConst(ProcSym) |
| 5645 |
END ; |
| 5646 |
IF NOT (IsProcedure(Proc) OR IsProcType(Proc)) |
| 5647 |
THEN |
| 5648 |
IF IsUnknown(Proc) |
| 5649 |
THEN |
| 5650 |
MetaError1('{%1Ua} is not recognised as a procedure, check declaration or import', Proc) |
| 5651 |
ELSE |
| 5652 |
MetaErrors1('{%1a} is not recognised as a procedure, check declaration or import', |
| 5653 |
'{%1Ua} is not recognised as a procedure, check declaration or import', |
| 5654 |
Proc) |
| 5655 |
END |
| 5656 |
END ; |
| 5657 |
IF CompilerDebugging |
| 5658 |
THEN |
| 5659 |
n1 := GetSymName(Proc) ; |
| 5660 |
printf1(' %a ( ', n1) |
| 5661 |
END ; |
| 5662 |
IF DebugTokPos |
| 5663 |
THEN |
| 5664 |
s := InitString ('procedure') ; |
| 5665 |
WarnStringAt (s, proctok) |
| 5666 |
END ; |
| 5667 |
|
| 5668 |
i := 1 ; |
| 5669 |
pi := ParamTotal+1 ; (* stack index referencing stacked parameter, i *) |
| 5670 |
WHILE i<=ParamTotal DO |
| 5671 |
IF i <= NoOfParamAny (Proc) |
| 5672 |
THEN |
| 5673 |
(* FormalI := GetParam(Proc, i) ; *) |
| 5674 |
FormalI := GetNthParamAnyClosest (Proc, i, GetCurrentModule ()) ; |
| 5675 |
IF CompilerDebugging |
| 5676 |
THEN |
| 5677 |
n1 := GetSymName(FormalI) ; |
| 5678 |
n2 := GetSymName(GetSType(FormalI)) ; |
| 5679 |
printf2('%a: %a', n1, n2) |
| 5680 |
END ; |
| 5681 |
Actual := OperandT(pi) ; |
| 5682 |
Dim := OperandD(pi) ; |
| 5683 |
paramtok := OperandTtok(pi) ; |
| 5684 |
IF DebugTokPos |
| 5685 |
THEN |
| 5686 |
s := InitString ('actual') ; |
| 5687 |
WarnStringAt (s, paramtok) |
| 5688 |
END ; |
| 5689 |
ParamCheckId := InitTypesParameterCheck (paramtok, Proc, i, FormalI, Actual, 0) ; |
| 5690 |
BuildRange (ParamCheckId) ; |
| 5691 |
(* Store the ParamCheckId on the quad stack so that any dependant checks |
| 5692 |
can be cancelled if the type check above detects an error. *) |
| 5693 |
PutRangeDep (pi, ParamCheckId) ; |
| 5694 |
IF IsConst(Actual) |
| 5695 |
THEN |
| 5696 |
IF IsVarParamAny (Proc, i) |
| 5697 |
THEN |
| 5698 |
FailParameter (paramtok, |
| 5699 |
'trying to pass a constant to a VAR parameter', |
| 5700 |
Actual, Proc, i) |
| 5701 |
ELSIF IsConstString (Actual) |
| 5702 |
THEN |
| 5703 |
IF (NOT IsConstStringKnown (Actual)) |
| 5704 |
THEN |
| 5705 |
(* We dont check this yet, it is checked in M2GenGCC.mod:CodeParam |
| 5706 |
after the string has been created. *) |
| 5707 |
ELSIF IsArray(GetDType(FormalI)) AND (GetSType(GetDType(FormalI))=Char) |
| 5708 |
THEN |
| 5709 |
(* Allow string literals to be passed to ARRAY [0..n] OF CHAR. *) |
| 5710 |
ELSIF (GetStringLength(paramtok, Actual) = 1) (* If = 1 then it maybe treated as a char. *) |
| 5711 |
THEN |
| 5712 |
CheckParameter (paramtok, Actual, Dim, FormalI, Proc, i, NIL, ParamCheckId) |
| 5713 |
ELSIF NOT IsUnboundedParamAny (Proc, i) |
| 5714 |
THEN |
| 5715 |
IF IsForC AND (GetSType(FormalI)=Address) |
| 5716 |
THEN |
| 5717 |
FailParameter (paramtok, |
| 5718 |
'a string constant can either be passed to an ADDRESS parameter or an ARRAY OF CHAR', |
| 5719 |
Actual, Proc, i) |
| 5720 |
ELSE |
| 5721 |
FailParameter (paramtok, |
| 5722 |
'cannot pass a string constant to a non unbounded array parameter', |
| 5723 |
Actual, Proc, i) |
| 5724 |
END |
| 5725 |
END |
| 5726 |
END |
| 5727 |
ELSE |
| 5728 |
CheckParameter (paramtok, Actual, Dim, FormalI, Proc, i, NIL, ParamCheckId) |
| 5729 |
END |
| 5730 |
ELSE |
| 5731 |
IF IsForC AND UsesVarArgs(Proc) |
| 5732 |
THEN |
| 5733 |
(* these are varargs, therefore we don't check them *) |
| 5734 |
i := ParamTotal |
| 5735 |
ELSE |
| 5736 |
MetaErrorT2 (proctok, 'too many parameters, {%2n} passed to {%1a} ', Proc, i) |
| 5737 |
END |
| 5738 |
END ; |
| 5739 |
INC(i) ; |
| 5740 |
DEC(pi) ; |
| 5741 |
IF CompilerDebugging |
| 5742 |
THEN |
| 5743 |
IF i<=ParamTotal |
| 5744 |
THEN |
| 5745 |
printf0 ('; ') |
| 5746 |
ELSE |
| 5747 |
printf0 (' ) ; \n') |
| 5748 |
END |
| 5749 |
END |
| 5750 |
END |
| 5751 |
END CheckProcedureParameters ; |
| 5752 |
|
| 5753 |
|
| 5754 |
(* |
| 5755 |
CheckProcTypeAndProcedure - checks the ProcType with the call. |
| 5756 |
*) |
| 5757 |
|
| 5758 |
PROCEDURE CheckProcTypeAndProcedure (tokno: CARDINAL; ProcType: CARDINAL; |
| 5759 |
call: CARDINAL; ParamCheckId: CARDINAL) ; |
| 5760 |
VAR |
| 5761 |
n1, n2 : Name ; |
| 5762 |
i, n, t : CARDINAL ; |
| 5763 |
CheckedProcedure: CARDINAL ; |
| 5764 |
e : Error ; |
| 5765 |
BEGIN |
| 5766 |
IF IsVar(call) OR IsTemporary(call) OR IsParameter(call) |
| 5767 |
THEN |
| 5768 |
CheckedProcedure := GetDType(call) |
| 5769 |
ELSE |
| 5770 |
CheckedProcedure := call |
| 5771 |
END ; |
| 5772 |
IF ProcType # CheckedProcedure |
| 5773 |
THEN |
| 5774 |
n := NoOfParamAny (ProcType) ; |
| 5775 |
(* We need to check the formal parameters between the procedure and proc type. *) |
| 5776 |
IF n # NoOfParamAny (CheckedProcedure) |
| 5777 |
THEN |
| 5778 |
e := NewError(GetDeclaredMod(ProcType)) ; |
| 5779 |
n1 := GetSymName(call) ; |
| 5780 |
n2 := GetSymName(ProcType) ; |
| 5781 |
ErrorFormat2(e, 'procedure (%a) is a parameter being passed as variable (%a) but they are declared with different number of parameters', |
| 5782 |
n1, n2) ; |
| 5783 |
e := ChainError(GetDeclaredMod(call), e) ; |
| 5784 |
t := NoOfParamAny (CheckedProcedure) ; |
| 5785 |
IF n<2 |
| 5786 |
THEN |
| 5787 |
ErrorFormat3(e, 'procedure (%a) is being called incorrectly with (%d) parameter, declared with (%d)', |
| 5788 |
n1, n, t) |
| 5789 |
ELSE |
| 5790 |
ErrorFormat3(e, 'procedure (%a) is being called incorrectly with (%d) parameters, declared with (%d)', |
| 5791 |
n1, n, t) |
| 5792 |
END |
| 5793 |
ELSE |
| 5794 |
i := 1 ; |
| 5795 |
WHILE i<=n DO |
| 5796 |
IF IsVarParamAny (ProcType, i) # IsVarParamAny (CheckedProcedure, i) |
| 5797 |
THEN |
| 5798 |
MetaError3 ('parameter {%3n} in {%1dD} causes a mismatch it was declared as a {%2d}', ProcType, GetNth (ProcType, i), i) ; |
| 5799 |
MetaError3 ('parameter {%3n} in {%1dD} causes a mismatch it was declared as a {%2d}', call, GetNth (call, i), i) |
| 5800 |
END ; |
| 5801 |
BuildRange (InitTypesParameterCheck (tokno, CheckedProcedure, i, |
| 5802 |
GetNthParamAnyClosest (CheckedProcedure, i, GetCurrentModule ()), |
| 5803 |
GetParam (ProcType, i), ParamCheckId)) ; |
| 5804 |
INC(i) |
| 5805 |
END |
| 5806 |
END |
| 5807 |
END |
| 5808 |
END CheckProcTypeAndProcedure ; |
| 5809 |
|
| 5810 |
|
| 5811 |
(* |
| 5812 |
IsReallyPointer - returns TRUE is sym is a pointer, address or a type declared |
| 5813 |
as a pointer or address. |
| 5814 |
*) |
| 5815 |
|
| 5816 |
PROCEDURE IsReallyPointer (Sym: CARDINAL) : BOOLEAN ; |
| 5817 |
BEGIN |
| 5818 |
IF IsVar(Sym) |
| 5819 |
THEN |
| 5820 |
Sym := GetSType(Sym) |
| 5821 |
END ; |
| 5822 |
Sym := SkipType(Sym) ; |
| 5823 |
RETURN( IsPointer(Sym) OR (Sym=Address) ) |
| 5824 |
END IsReallyPointer ; |
| 5825 |
|
| 5826 |
|
| 5827 |
(* |
| 5828 |
LegalUnboundedParam - returns TRUE if the parameter, Actual, can legitimately be |
| 5829 |
passed to ProcSym, i, the, Formal, parameter. |
| 5830 |
*) |
| 5831 |
|
| 5832 |
PROCEDURE LegalUnboundedParam (tokpos: CARDINAL; ProcSym, i, ActualType, Actual, Dimension, Formal: CARDINAL) : BOOLEAN ; |
| 5833 |
VAR |
| 5834 |
FormalType: CARDINAL ; |
| 5835 |
n, m : CARDINAL ; |
| 5836 |
BEGIN |
| 5837 |
ActualType := SkipType(ActualType) ; |
| 5838 |
FormalType := GetDType(Formal) ; |
| 5839 |
FormalType := GetSType(FormalType) ; (* type of the unbounded ARRAY *) |
| 5840 |
IF IsArray(ActualType) |
| 5841 |
THEN |
| 5842 |
m := GetDimension(Formal) ; |
| 5843 |
n := 0 ; |
| 5844 |
WHILE IsArray(ActualType) DO |
| 5845 |
INC(n) ; |
| 5846 |
ActualType := GetDType(ActualType) ; |
| 5847 |
IF (m=n) AND (ActualType=FormalType) |
| 5848 |
THEN |
| 5849 |
RETURN( TRUE ) |
| 5850 |
END |
| 5851 |
END ; |
| 5852 |
IF n=m |
| 5853 |
THEN |
| 5854 |
(* now we fall though and test ActualType against FormalType *) |
| 5855 |
ELSE |
| 5856 |
IF IsGenericSystemType(FormalType) |
| 5857 |
THEN |
| 5858 |
RETURN( TRUE ) |
| 5859 |
ELSE |
| 5860 |
FailParameter(tokpos, |
| 5861 |
'attempting to pass an array with the incorrect number dimenisons to an unbounded formal parameter of different dimensions', |
| 5862 |
Actual, ProcSym, i) ; |
| 5863 |
RETURN( FALSE ) |
| 5864 |
END |
| 5865 |
END |
| 5866 |
ELSIF IsUnbounded(ActualType) |
| 5867 |
THEN |
| 5868 |
IF (Dimension=0) AND (GetDimension(Formal)=GetDimension(Actual)) |
| 5869 |
THEN |
| 5870 |
(* now we fall though and test ActualType against FormalType *) |
| 5871 |
ActualType := GetSType(ActualType) |
| 5872 |
ELSE |
| 5873 |
IF IsGenericSystemType(FormalType) |
| 5874 |
THEN |
| 5875 |
RETURN( TRUE ) |
| 5876 |
ELSE |
| 5877 |
IF GetDimension(Actual)-Dimension = GetDimension(Formal) |
| 5878 |
THEN |
| 5879 |
ActualType := GetSType(ActualType) |
| 5880 |
ELSE |
| 5881 |
FailParameter(tokpos, |
| 5882 |
'attempting to pass an unbounded array with the incorrect number dimenisons to an unbounded formal parameter of different dimensions', |
| 5883 |
Actual, ProcSym, i) ; |
| 5884 |
RETURN( FALSE ) |
| 5885 |
END |
| 5886 |
END |
| 5887 |
END |
| 5888 |
END ; |
| 5889 |
IF IsGenericSystemType (FormalType) OR |
| 5890 |
IsGenericSystemType (ActualType) OR |
| 5891 |
IsAssignmentCompatible (FormalType, ActualType) |
| 5892 |
THEN |
| 5893 |
(* we think it is legal, but we ask post pass 3 to check as |
| 5894 |
not all types are known at this point *) |
| 5895 |
RETURN( TRUE ) |
| 5896 |
ELSE |
| 5897 |
FailParameter(tokpos, |
| 5898 |
'identifier with an incompatible type is being passed to this procedure', |
| 5899 |
Actual, ProcSym, i) ; |
| 5900 |
RETURN( FALSE ) |
| 5901 |
END |
| 5902 |
END LegalUnboundedParam ; |
| 5903 |
|
| 5904 |
|
| 5905 |
(* |
| 5906 |
CheckParameter - checks that types ActualType and FormalType are compatible for parameter |
| 5907 |
passing. ProcSym is the procedure and i is the parameter number. |
| 5908 |
|
| 5909 |
We obey the following rules: |
| 5910 |
|
| 5911 |
(1) we allow WORD, BYTE, LOC to be compitable with any like sized |
| 5912 |
type. |
| 5913 |
(2) we allow ADDRESS to be compatible with any pointer type. |
| 5914 |
(3) we relax INTEGER and CARDINAL checking for Temporary variables. |
| 5915 |
|
| 5916 |
Note that type sizes are checked during the code generation pass. |
| 5917 |
*) |
| 5918 |
|
| 5919 |
PROCEDURE CheckParameter (tokpos: CARDINAL; |
| 5920 |
Actual, Dimension, Formal, ProcSym: CARDINAL; |
| 5921 |
i: CARDINAL; TypeList: List; ParamCheckId: CARDINAL) ; |
| 5922 |
VAR |
| 5923 |
NewList : BOOLEAN ; |
| 5924 |
ActualType, FormalType: CARDINAL ; |
| 5925 |
BEGIN |
| 5926 |
IF IsConstString(Actual) AND (NOT IsConstStringKnown (Actual)) |
| 5927 |
THEN |
| 5928 |
(* Cannot check if the string content is not yet known. *) |
| 5929 |
RETURN |
| 5930 |
END ; |
| 5931 |
FormalType := GetDType(Formal) ; |
| 5932 |
IF IsConstString(Actual) AND (GetStringLength(tokpos, Actual) = 1) (* if = 1 then it maybe treated as a char *) |
| 5933 |
THEN |
| 5934 |
ActualType := Char |
| 5935 |
ELSIF Actual=Boolean |
| 5936 |
THEN |
| 5937 |
ActualType := Actual |
| 5938 |
ELSE |
| 5939 |
ActualType := GetDType(Actual) |
| 5940 |
END ; |
| 5941 |
IF TypeList=NIL |
| 5942 |
THEN |
| 5943 |
NewList := TRUE ; |
| 5944 |
InitList(TypeList) |
| 5945 |
ELSE |
| 5946 |
NewList := FALSE |
| 5947 |
END ; |
| 5948 |
IF IsItemInList(TypeList, ActualType) |
| 5949 |
THEN |
| 5950 |
(* no need to check *) |
| 5951 |
RETURN |
| 5952 |
END ; |
| 5953 |
IncludeItemIntoList(TypeList, ActualType) ; |
| 5954 |
IF IsProcType(FormalType) |
| 5955 |
THEN |
| 5956 |
IF (NOT IsProcedure(Actual)) AND ((ActualType=NulSym) OR (NOT IsProcType(SkipType(ActualType)))) |
| 5957 |
THEN |
| 5958 |
FailParameter(tokpos, |
| 5959 |
'expecting a procedure or procedure variable as a parameter', |
| 5960 |
Actual, ProcSym, i) ; |
| 5961 |
RETURN |
| 5962 |
END ; |
| 5963 |
IF IsProcedure(Actual) AND IsProcedureNested(Actual) |
| 5964 |
THEN |
| 5965 |
MetaError2 ('cannot pass a nested procedure {%1Ea} seen in the {%2N} parameter as the outer scope will be unknown at runtime', Actual, i) |
| 5966 |
END ; |
| 5967 |
(* we can check the return type of both proc types *) |
| 5968 |
IF (ActualType#NulSym) AND IsProcType(ActualType) |
| 5969 |
THEN |
| 5970 |
IF ((GetSType(ActualType)#NulSym) AND (GetSType(FormalType)=NulSym)) |
| 5971 |
THEN |
| 5972 |
FailParameter(tokpos, |
| 5973 |
'the item being passed is a function whereas the formal procedure parameter is a procedure', |
| 5974 |
Actual, ProcSym, i) ; |
| 5975 |
RETURN |
| 5976 |
ELSIF ((GetSType(ActualType)=NulSym) AND (GetSType(FormalType)#NulSym)) |
| 5977 |
THEN |
| 5978 |
FailParameter(tokpos, |
| 5979 |
'the item being passed is a procedure whereas the formal procedure parameter is a function', |
| 5980 |
Actual, ProcSym, i) ; |
| 5981 |
RETURN |
| 5982 |
ELSIF AssignmentRequiresWarning(GetSType(ActualType), GetSType(FormalType)) |
| 5983 |
THEN |
| 5984 |
WarnParameter(tokpos, |
| 5985 |
'the return result of the procedure variable parameter may not be compatible on other targets with the return result of the item being passed', |
| 5986 |
Actual, ProcSym, i) ; |
| 5987 |
RETURN |
| 5988 |
ELSIF IsGenericSystemType (GetSType(FormalType)) OR |
| 5989 |
IsGenericSystemType (GetSType(ActualType)) OR |
| 5990 |
IsAssignmentCompatible(GetSType(ActualType), GetSType(FormalType)) |
| 5991 |
THEN |
| 5992 |
(* pass *) |
| 5993 |
ELSE |
| 5994 |
FailParameter(tokpos, |
| 5995 |
'the return result of the procedure variable parameter is not compatible with the return result of the item being passed', |
| 5996 |
Actual, ProcSym, i) ; |
| 5997 |
RETURN |
| 5998 |
END |
| 5999 |
END ; |
| 6000 |
(* now to check each parameter of the proc type *) |
| 6001 |
CheckProcTypeAndProcedure (tokpos, FormalType, Actual, ParamCheckId) |
| 6002 |
ELSIF (ActualType#FormalType) AND (ActualType#NulSym) |
| 6003 |
THEN |
| 6004 |
IF IsUnknown(FormalType) |
| 6005 |
THEN |
| 6006 |
FailParameter(tokpos, |
| 6007 |
'procedure parameter type is undeclared', |
| 6008 |
Actual, ProcSym, i) ; |
| 6009 |
RETURN |
| 6010 |
END ; |
| 6011 |
IF IsUnbounded(ActualType) AND (NOT IsUnboundedParamAny (ProcSym, i)) |
| 6012 |
THEN |
| 6013 |
FailParameter(tokpos, |
| 6014 |
'attempting to pass an unbounded array to a NON unbounded parameter', |
| 6015 |
Actual, ProcSym, i) ; |
| 6016 |
RETURN |
| 6017 |
ELSIF IsUnboundedParamAny (ProcSym, i) |
| 6018 |
THEN |
| 6019 |
IF NOT LegalUnboundedParam(tokpos, ProcSym, i, ActualType, Actual, Dimension, Formal) |
| 6020 |
THEN |
| 6021 |
RETURN |
| 6022 |
END |
| 6023 |
ELSIF ActualType#FormalType |
| 6024 |
THEN |
| 6025 |
IF AssignmentRequiresWarning(FormalType, ActualType) |
| 6026 |
THEN |
| 6027 |
WarnParameter (tokpos, |
| 6028 |
'identifier being passed to this procedure may contain a possibly incompatible type when compiling for a different target', |
| 6029 |
Actual, ProcSym, i) |
| 6030 |
ELSIF IsGenericSystemType (FormalType) OR |
| 6031 |
IsGenericSystemType (ActualType) OR |
| 6032 |
IsAssignmentCompatible (ActualType, FormalType) |
| 6033 |
THEN |
| 6034 |
(* so far we know it is legal, but not all types have been resolved |
| 6035 |
and so this is checked later on in another pass. *) |
| 6036 |
ELSE |
| 6037 |
FailParameter (tokpos, |
| 6038 |
'identifier with an incompatible type is being passed to this procedure', |
| 6039 |
Actual, ProcSym, i) |
| 6040 |
END |
| 6041 |
END |
| 6042 |
END ; |
| 6043 |
IF NewList |
| 6044 |
THEN |
| 6045 |
KillList(TypeList) |
| 6046 |
END |
| 6047 |
END CheckParameter ; |
| 6048 |
|
| 6049 |
|
| 6050 |
(* |
| 6051 |
DescribeType - returns a String describing a symbol, Sym, name and its type. |
| 6052 |
*) |
| 6053 |
|
| 6054 |
PROCEDURE DescribeType (Sym: CARDINAL) : String ; |
| 6055 |
VAR |
| 6056 |
s, s1, s2: String ; |
| 6057 |
Low, High, |
| 6058 |
Subrange, |
| 6059 |
Subscript, |
| 6060 |
Type : CARDINAL ; |
| 6061 |
BEGIN |
| 6062 |
s := NIL ; |
| 6063 |
IF IsConstString(Sym) |
| 6064 |
THEN |
| 6065 |
(* If = 1 then it maybe treated as a char. *) |
| 6066 |
IF IsConstStringKnown (Sym) AND (GetStringLength (GetDeclaredMod (Sym), Sym) = 1) |
| 6067 |
THEN |
| 6068 |
s := InitString('(constant string) or {%kCHAR}') |
| 6069 |
ELSE |
| 6070 |
s := InitString('(constant string)') |
| 6071 |
END |
| 6072 |
ELSIF IsConst(Sym) |
| 6073 |
THEN |
| 6074 |
s := InitString('(constant)') |
| 6075 |
ELSIF IsUnknown(Sym) |
| 6076 |
THEN |
| 6077 |
s := InitString('(unknown)') |
| 6078 |
ELSE |
| 6079 |
Type := GetSType(Sym) ; |
| 6080 |
IF Type=NulSym |
| 6081 |
THEN |
| 6082 |
s := InitString('(unknown)') |
| 6083 |
ELSIF IsUnbounded(Type) |
| 6084 |
THEN |
| 6085 |
s1 := Mark(InitStringCharStar(KeyToCharStar(GetSymName(GetSType(Type))))) ; |
| 6086 |
s := Sprintf1(Mark(InitString('{%%kARRAY} {%%kOF} %s')), s1) |
| 6087 |
ELSIF IsArray(Type) |
| 6088 |
THEN |
| 6089 |
s := InitString('{%kARRAY} [') ; |
| 6090 |
Subscript := GetArraySubscript(Type) ; |
| 6091 |
IF Subscript#NulSym |
| 6092 |
THEN |
| 6093 |
Assert(IsSubscript(Subscript)) ; |
| 6094 |
Subrange := GetSType(Subscript) ; |
| 6095 |
IF NOT IsSubrange(Subrange) |
| 6096 |
THEN |
| 6097 |
MetaError3 ('error in definition of array {%1Ead} in the {%2N} subscript which has no subrange, instead type given is {%3a}', |
| 6098 |
Sym, Subscript, Subrange) |
| 6099 |
END ; |
| 6100 |
Assert(IsSubrange(Subrange)) ; |
| 6101 |
GetSubrange(Subrange, High, Low) ; |
| 6102 |
s1 := Mark(InitStringCharStar(KeyToCharStar(GetSymName(Low)))) ; |
| 6103 |
s2 := Mark(InitStringCharStar(KeyToCharStar(GetSymName(High)))) ; |
| 6104 |
s := ConCat(s, Mark(Sprintf2(Mark(InitString('%s..%s')), |
| 6105 |
s1, s2))) |
| 6106 |
END ; |
| 6107 |
s1 := Mark(DescribeType(Type)) ; |
| 6108 |
s := ConCat(ConCat(s, Mark(InitString('] OF '))), s1) |
| 6109 |
ELSE |
| 6110 |
IF IsUnknown(Type) |
| 6111 |
THEN |
| 6112 |
s1 := Mark(InitStringCharStar(KeyToCharStar(GetSymName(Type)))) ; |
| 6113 |
s := Sprintf1(Mark(InitString('%s (currently unknown, check declaration or import)')), |
| 6114 |
s1) |
| 6115 |
ELSE |
| 6116 |
s := InitStringCharStar(KeyToCharStar(GetSymName(Type))) |
| 6117 |
END |
| 6118 |
END |
| 6119 |
END ; |
| 6120 |
RETURN( s ) |
| 6121 |
END DescribeType ; |
| 6122 |
|
| 6123 |
|
| 6124 |
(* |
| 6125 |
FailParameter - generates an error message indicating that a parameter |
| 6126 |
declaration has failed. |
| 6127 |
|
| 6128 |
The parameters are: |
| 6129 |
|
| 6130 |
CurrentState - string describing the current failing state. |
| 6131 |
Actual - actual parameter. |
| 6132 |
ParameterNo - parameter number that has failed. |
| 6133 |
ProcedureSym - procedure symbol where parameter has failed. |
| 6134 |
|
| 6135 |
If any parameter is Nul then it is ignored. |
| 6136 |
*) |
| 6137 |
|
| 6138 |
PROCEDURE FailParameter (tokpos : CARDINAL; |
| 6139 |
CurrentState : ARRAY OF CHAR; |
| 6140 |
Actual : CARDINAL; |
| 6141 |
ProcedureSym : CARDINAL; |
| 6142 |
ParameterNo : CARDINAL) ; |
| 6143 |
VAR |
| 6144 |
FormalParam: CARDINAL ; |
| 6145 |
Msg : String ; |
| 6146 |
BEGIN |
| 6147 |
Msg := InitString ('parameter mismatch between the {%2N} parameter of procedure {%1Ead}, ') ; |
| 6148 |
Msg := ConCat (Msg, Mark (InitString (CurrentState))) ; |
| 6149 |
MetaErrorStringT2 (tokpos, Msg, ProcedureSym, ParameterNo) ; |
| 6150 |
IF NoOfParamAny (ProcedureSym) >= ParameterNo |
| 6151 |
THEN |
| 6152 |
FormalParam := GetNthParamAnyClosest (ProcedureSym, ParameterNo, GetCurrentModule ()) ; |
| 6153 |
IF IsUnboundedParamAny (ProcedureSym, ParameterNo) |
| 6154 |
THEN |
| 6155 |
MetaErrorT2 (GetVarDeclFullTok (FormalParam), 'formal parameter {%1ad} has an open array type {%2tad}', |
| 6156 |
FormalParam, GetSType (GetSType (FormalParam))) |
| 6157 |
ELSE |
| 6158 |
MetaErrorT1 (GetVarDeclFullTok (FormalParam), 'formal parameter {%1ad} has type {%1tad}', FormalParam) |
| 6159 |
END |
| 6160 |
ELSE |
| 6161 |
MetaErrorT1 (GetDeclaredMod (ProcedureSym), 'procedure declaration', ProcedureSym) |
| 6162 |
END ; |
| 6163 |
IF GetLType (Actual) = NulSym |
| 6164 |
THEN |
| 6165 |
MetaError1 ('actual parameter being passed is {%1Eda} {%1ad}', Actual) |
| 6166 |
ELSE |
| 6167 |
IF IsVar (Actual) |
| 6168 |
THEN |
| 6169 |
MetaErrorT1 (GetVarDeclFullTok (Actual), |
| 6170 |
'actual parameter variable being passed is {%1Eda} {%1ad} of an incompatible type {%1ts}', |
| 6171 |
Actual) |
| 6172 |
ELSE |
| 6173 |
MetaErrorT1 (tokpos, |
| 6174 |
'actual parameter being passed is {%1Eda} {%1ad} of an incompatible type {%1ts}', |
| 6175 |
Actual) |
| 6176 |
END |
| 6177 |
END |
| 6178 |
END FailParameter ; |
| 6179 |
|
| 6180 |
|
| 6181 |
(* |
| 6182 |
WarnParameter - generates a warning message indicating that a parameter |
| 6183 |
use might cause problems on another target. |
| 6184 |
|
| 6185 |
CurrentState - string describing the current failing state. |
| 6186 |
Actual - actual parameter. |
| 6187 |
ParameterNo - parameter number that has failed. |
| 6188 |
ProcedureSym - procedure symbol where parameter has failed. |
| 6189 |
|
| 6190 |
If any parameter is Nul then it is ignored. |
| 6191 |
*) |
| 6192 |
|
| 6193 |
PROCEDURE WarnParameter (tokpos : CARDINAL; |
| 6194 |
CurrentState : ARRAY OF CHAR; |
| 6195 |
Actual : CARDINAL; |
| 6196 |
ProcedureSym : CARDINAL; |
| 6197 |
ParameterNo : CARDINAL) ; |
| 6198 |
VAR |
| 6199 |
FormalParam: CARDINAL ; |
| 6200 |
Msg : String ; |
| 6201 |
BEGIN |
| 6202 |
Msg := InitString ('{%W}parameter mismatch between the {%2N} parameter of procedure {%1ad}, ') ; |
| 6203 |
Msg := ConCat (Msg, Mark (InitString (CurrentState))) ; |
| 6204 |
MetaErrorStringT2 (tokpos, Msg, ProcedureSym, ParameterNo) ; |
| 6205 |
IF NoOfParamAny (ProcedureSym) >= ParameterNo |
| 6206 |
THEN |
| 6207 |
FormalParam := GetNthParamAnyClosest (ProcedureSym, ParameterNo, GetCurrentModule ()) ; |
| 6208 |
IF IsUnboundedParamAny (ProcedureSym, ParameterNo) |
| 6209 |
THEN |
| 6210 |
MetaErrorT2 (GetVarDeclFullTok (FormalParam), '{%W}formal parameter {%1ad} has an open array type {%2tad}', |
| 6211 |
FormalParam, GetSType (GetSType (FormalParam))) |
| 6212 |
ELSE |
| 6213 |
MetaErrorT1 (GetVarDeclFullTok (FormalParam), '{%W}formal parameter {%1ad} has type {%1tad}', FormalParam) |
| 6214 |
END |
| 6215 |
ELSE |
| 6216 |
MetaErrorT1 (GetDeclaredMod (ProcedureSym), '{%W}procedure declaration', ProcedureSym) |
| 6217 |
END ; |
| 6218 |
IF GetLType (Actual) = NulSym |
| 6219 |
THEN |
| 6220 |
MetaError1 ('actual parameter being passed is {%1Wda} {%1ad}', Actual) |
| 6221 |
ELSE |
| 6222 |
IF IsVar (Actual) |
| 6223 |
THEN |
| 6224 |
MetaErrorT1 (GetVarDeclFullTok (Actual), |
| 6225 |
'actual parameter variable being passed is {%1Wda} {%1ad} of type {%1ts}', |
| 6226 |
Actual) |
| 6227 |
ELSE |
| 6228 |
MetaErrorT1 (tokpos, |
| 6229 |
'actual parameter being passed is {%1Wda} {%1ad} of type {%1ts}', |
| 6230 |
Actual) |
| 6231 |
END |
| 6232 |
END |
| 6233 |
END WarnParameter ; |
| 6234 |
|
| 6235 |
|
| 6236 |
(* |
| 6237 |
ExpectVariable - checks to see whether, sym, is declared as a variable. |
| 6238 |
If not then it generates an error message. |
| 6239 |
*) |
| 6240 |
|
| 6241 |
(* |
| 6242 |
PROCEDURE ExpectVariable (a: ARRAY OF CHAR; sym: CARDINAL) ; |
| 6243 |
VAR |
| 6244 |
e : Error ; |
| 6245 |
s1, s2, s3: String ; |
| 6246 |
BEGIN |
| 6247 |
IF NOT IsVar(sym) |
| 6248 |
THEN |
| 6249 |
e := NewError(GetTokenNo()) ; |
| 6250 |
IF IsUnknown(sym) |
| 6251 |
THEN |
| 6252 |
s1 := ConCat (InitString (a), |
| 6253 |
Mark (InitString ('but was given an undeclared symbol {%E1a}'))) ; |
| 6254 |
|
| 6255 |
ErrorString(e, Sprintf2(Mark(InitString('%s but was given an undeclared symbol %s')), s1, s2)) |
| 6256 |
ELSE |
| 6257 |
s1 := Mark(InitString(a)) ; |
| 6258 |
s2 := Mark(InitStringCharStar(KeyToCharStar(GetSymName(sym)))) ; |
| 6259 |
s3 := Mark(DescribeType(sym)) ; |
| 6260 |
ErrorString(e, Sprintf3(Mark(InitString('%s but was given %s: %s')), |
| 6261 |
s1, s2, s3)) |
| 6262 |
END |
| 6263 |
END |
| 6264 |
END ExpectVariable ; |
| 6265 |
*) |
| 6266 |
|
| 6267 |
|
| 6268 |
(* |
| 6269 |
doIndrX - perform des = *exp with a conversion if necessary. |
| 6270 |
*) |
| 6271 |
|
| 6272 |
PROCEDURE doIndrX (tok: CARDINAL; des, exp: CARDINAL) ; |
| 6273 |
VAR |
| 6274 |
t: CARDINAL ; |
| 6275 |
BEGIN |
| 6276 |
IF GetDType (des) = GetDType (exp) |
| 6277 |
THEN |
| 6278 |
GenQuadOtok (tok, IndrXOp, des, GetSType (des), exp, TRUE, |
| 6279 |
tok, tok, tok) |
| 6280 |
ELSE |
| 6281 |
IF StrictTypeAssignment |
| 6282 |
THEN |
| 6283 |
BuildRange (InitTypesIndrXCheck (tok, des, exp)) |
| 6284 |
END ; |
| 6285 |
t := MakeTemporary (tok, RightValue) ; |
| 6286 |
PutVar (t, GetSType (exp)) ; |
| 6287 |
GenQuadOtok (tok, IndrXOp, t, GetSType (exp), exp, TRUE, |
| 6288 |
tok, tok, tok) ; |
| 6289 |
GenQuadOtok (tok, BecomesOp, des, NulSym, doVal (GetSType (des), t), TRUE, |
| 6290 |
tok, UnknownTokenNo, tok) |
| 6291 |
END |
| 6292 |
END doIndrX ; |
| 6293 |
|
| 6294 |
|
| 6295 |
(* |
| 6296 |
MakeRightValue - returns a temporary which will have the RightValue of symbol, Sym. |
| 6297 |
If Sym is a right value and has type, type, then no quadruples are |
| 6298 |
generated and Sym is returned. Otherwise a new temporary is created |
| 6299 |
and an IndrX quadruple is generated. |
| 6300 |
*) |
| 6301 |
|
| 6302 |
PROCEDURE MakeRightValue (tok: CARDINAL; |
| 6303 |
Sym: CARDINAL; type: CARDINAL) : CARDINAL ; |
| 6304 |
VAR |
| 6305 |
t: CARDINAL ; |
| 6306 |
BEGIN |
| 6307 |
IF GetMode (Sym) = RightValue |
| 6308 |
THEN |
| 6309 |
IF GetSType(Sym) = type |
| 6310 |
THEN |
| 6311 |
RETURN Sym (* already a RightValue with desired type *) |
| 6312 |
ELSE |
| 6313 |
(* |
| 6314 |
type change or mode change, type changes are a pain, but I've |
| 6315 |
left them here as it is perhaps easier to remove them later. |
| 6316 |
*) |
| 6317 |
t := MakeTemporary (tok, RightValue) ; |
| 6318 |
PutVar (t, type) ; |
| 6319 |
GenQuadOtok (tok, BecomesOp, t, NulSym, doVal (type, Sym), TRUE, |
| 6320 |
tok, tok, tok) ; |
| 6321 |
RETURN t |
| 6322 |
END |
| 6323 |
ELSE |
| 6324 |
t := MakeTemporary (tok, RightValue) ; |
| 6325 |
PutVar (t, type) ; |
| 6326 |
CheckPointerThroughNil (tok, Sym) ; |
| 6327 |
doIndrX (tok, t, Sym) ; |
| 6328 |
RETURN t |
| 6329 |
END |
| 6330 |
END MakeRightValue ; |
| 6331 |
|
| 6332 |
|
| 6333 |
(* |
| 6334 |
MakeLeftValue - returns a temporary coresponding to the LeftValue of |
| 6335 |
symbol, Sym. No quadruple is generated if Sym is already |
| 6336 |
a LeftValue and has the same type. |
| 6337 |
*) |
| 6338 |
|
| 6339 |
PROCEDURE MakeLeftValue (tok: CARDINAL; |
| 6340 |
Sym: CARDINAL; with: ModeOfAddr; type: CARDINAL) : CARDINAL ; |
| 6341 |
VAR |
| 6342 |
t: CARDINAL ; |
| 6343 |
BEGIN |
| 6344 |
IF GetMode (Sym) = LeftValue |
| 6345 |
THEN |
| 6346 |
IF GetSType (Sym) = type |
| 6347 |
THEN |
| 6348 |
RETURN Sym |
| 6349 |
ELSE |
| 6350 |
(* |
| 6351 |
type change or mode change, type changes are a pain, but I've |
| 6352 |
left them here as it is perhaps easier to remove them later |
| 6353 |
*) |
| 6354 |
t := MakeTemporary (tok, with) ; |
| 6355 |
PutVar (t, type) ; |
| 6356 |
GenQuadOtok (tok, BecomesOp, t, NulSym, Sym, TRUE, |
| 6357 |
tok, UnknownTokenNo, tok) ; |
| 6358 |
RETURN t |
| 6359 |
END |
| 6360 |
ELSE |
| 6361 |
t := MakeTemporary (tok, with) ; |
| 6362 |
PutVar (t, type) ; |
| 6363 |
GenQuadOtok (tok, AddrOp, t, NulSym, Sym, TRUE, |
| 6364 |
tok, UnknownTokenNo, tok) ; |
| 6365 |
RETURN t |
| 6366 |
END |
| 6367 |
END MakeLeftValue ; |
| 6368 |
|
| 6369 |
|
| 6370 |
(* |
| 6371 |
ManipulatePseudoCallParameters - manipulates the parameters to a pseudo function or |
| 6372 |
procedure. It dereferences all LeftValue parameters |
| 6373 |
and Boolean parameters. |
| 6374 |
The Stack: |
| 6375 |
|
| 6376 |
|
| 6377 |
Entry Exit |
| 6378 |
|
| 6379 |
Ptr -> exactly the same |
| 6380 |
+----------------+ |
| 6381 |
| NoOfParameters | |
| 6382 |
|----------------| |
| 6383 |
| Param 1 | |
| 6384 |
|----------------| |
| 6385 |
| Param 2 | |
| 6386 |
|----------------| |
| 6387 |
. . |
| 6388 |
. . |
| 6389 |
. . |
| 6390 |
|----------------| |
| 6391 |
| Param # | |
| 6392 |
|----------------| |
| 6393 |
| ProcSym | Type | |
| 6394 |
|----------------| |
| 6395 |
|
| 6396 |
*) |
| 6397 |
|
| 6398 |
PROCEDURE ManipulatePseudoCallParameters ; |
| 6399 |
VAR |
| 6400 |
NoOfParameters, |
| 6401 |
ProcSym, Proc, |
| 6402 |
i, pi : CARDINAL ; |
| 6403 |
f : BoolFrame ; |
| 6404 |
BEGIN |
| 6405 |
PopT(NoOfParameters) ; |
| 6406 |
PushT(NoOfParameters) ; (* restored to original state *) |
| 6407 |
(* Ptr points to the ProcSym *) |
| 6408 |
ProcSym := OperandT(NoOfParameters+1+1) ; |
| 6409 |
IF IsVar(ProcSym) |
| 6410 |
THEN |
| 6411 |
InternalError ('expecting a pseudo procedure or a type') |
| 6412 |
ELSE |
| 6413 |
Proc := ProcSym |
| 6414 |
END ; |
| 6415 |
i := 1 ; |
| 6416 |
pi := NoOfParameters+1 ; |
| 6417 |
WHILE i<=NoOfParameters DO |
| 6418 |
IF (GetMode(OperandT(pi))=LeftValue) AND |
| 6419 |
(Proc#Adr) AND (Proc#Size) AND (Proc#TSize) AND (Proc#High) AND |
| 6420 |
(* procedures which have first parameter as a VAR param *) |
| 6421 |
(((Proc#Inc) AND (Proc#Incl) AND (Proc#Dec) AND (Proc#Excl) AND (Proc#New) AND (Proc#Dispose)) OR (i>1)) |
| 6422 |
THEN |
| 6423 |
(* must dereference LeftValue *) |
| 6424 |
f := PeepAddress(BoolStack, pi) ; |
| 6425 |
f^.TrueExit := MakeRightValue (GetTokenNo(), OperandT(pi), GetSType(OperandT(pi))) |
| 6426 |
END ; |
| 6427 |
INC(i) ; |
| 6428 |
DEC(pi) |
| 6429 |
END |
| 6430 |
END ManipulatePseudoCallParameters ; |
| 6431 |
|
| 6432 |
|
| 6433 |
(* |
| 6434 |
ManipulateParameters - manipulates the procedure parameters in |
| 6435 |
preparation for a procedure call. |
| 6436 |
Prepares Boolean, Unbounded and VAR parameters. |
| 6437 |
The Stack: |
| 6438 |
|
| 6439 |
|
| 6440 |
Entry Exit |
| 6441 |
|
| 6442 |
Ptr -> exactly the same |
| 6443 |
+----------------+ |
| 6444 |
| NoOfParameters | |
| 6445 |
|----------------| |
| 6446 |
| Param 1 | |
| 6447 |
|----------------| |
| 6448 |
| Param 2 | |
| 6449 |
|----------------| |
| 6450 |
. . |
| 6451 |
. . |
| 6452 |
. . |
| 6453 |
|----------------| |
| 6454 |
| Param # | |
| 6455 |
|----------------| |
| 6456 |
| ProcSym | Type | |
| 6457 |
|----------------| |
| 6458 |
*) |
| 6459 |
|
| 6460 |
PROCEDURE ManipulateParameters (IsForC: BOOLEAN) ; |
| 6461 |
VAR |
| 6462 |
tokpos, |
| 6463 |
np : CARDINAL ; |
| 6464 |
s : String ; |
| 6465 |
ArraySym, |
| 6466 |
UnboundedType, |
| 6467 |
ParamType, |
| 6468 |
NoOfParameters, |
| 6469 |
i, pi, |
| 6470 |
ProcSym, rw, |
| 6471 |
Proc, |
| 6472 |
t : CARDINAL ; |
| 6473 |
f : BoolFrame ; |
| 6474 |
BEGIN |
| 6475 |
PopT(NoOfParameters) ; |
| 6476 |
ProcSym := OperandT(NoOfParameters+1) ; |
| 6477 |
tokpos := OperandTtok(NoOfParameters+1) ; |
| 6478 |
IF IsVar(ProcSym) |
| 6479 |
THEN |
| 6480 |
(* Procedure Variable ? *) |
| 6481 |
Proc := SkipType(OperandF(NoOfParameters+1)) |
| 6482 |
ELSE |
| 6483 |
Proc := SkipConst(ProcSym) |
| 6484 |
END ; |
| 6485 |
|
| 6486 |
IF IsForC AND UsesVarArgs(Proc) |
| 6487 |
THEN |
| 6488 |
IF NoOfParameters < NoOfParamAny (Proc) |
| 6489 |
THEN |
| 6490 |
s := Mark(InitStringCharStar(KeyToCharStar(GetSymName(Proc)))) ; |
| 6491 |
np := NoOfParamAny (Proc) ; |
| 6492 |
ErrorStringAt2(Sprintf3(Mark(InitString('attempting to pass (%d) parameters to procedure (%s) which was declared with varargs but contains at least (%d) parameters')), |
| 6493 |
NoOfParameters, s, np), |
| 6494 |
tokpos, GetDeclaredMod(ProcSym)) |
| 6495 |
END |
| 6496 |
ELSIF UsesOptArgAny (Proc) |
| 6497 |
THEN |
| 6498 |
IF NOT ((NoOfParameters=NoOfParamAny (Proc)) OR (NoOfParameters+1=NoOfParamAny (Proc))) |
| 6499 |
THEN |
| 6500 |
s := Mark(InitStringCharStar(KeyToCharStar(GetSymName(Proc)))) ; |
| 6501 |
np := NoOfParamAny (Proc) ; |
| 6502 |
ErrorStringAt2(Sprintf3(Mark(InitString('attempting to pass (%d) parameters to procedure (%s) which was declared with an optarg with a maximum of (%d) parameters')), |
| 6503 |
NoOfParameters, s, np), |
| 6504 |
tokpos, GetDeclaredMod(ProcSym)) |
| 6505 |
END |
| 6506 |
ELSIF NoOfParameters#NoOfParamAny (Proc) |
| 6507 |
THEN |
| 6508 |
s := Mark(InitStringCharStar(KeyToCharStar(GetSymName(Proc)))) ; |
| 6509 |
np := NoOfParamAny (Proc) ; |
| 6510 |
ErrorStringAt2(Sprintf3(Mark(InitString('attempting to pass (%d) parameters to procedure (%s) which was declared with (%d) parameters')), |
| 6511 |
NoOfParameters, s, np), |
| 6512 |
tokpos, GetDeclaredMod(ProcSym)) |
| 6513 |
END ; |
| 6514 |
i := 1 ; |
| 6515 |
pi := NoOfParameters ; |
| 6516 |
WHILE i<=NoOfParameters DO |
| 6517 |
f := PeepAddress(BoolStack, pi) ; |
| 6518 |
rw := OperandMergeRW(pi) ; |
| 6519 |
Assert(IsLegal(rw)) ; |
| 6520 |
IF i>NoOfParamAny (Proc) |
| 6521 |
THEN |
| 6522 |
IF IsForC AND UsesVarArgs(Proc) |
| 6523 |
THEN |
| 6524 |
IF (GetSType(OperandT(pi))#NulSym) AND IsArray(GetDType(OperandT(pi))) |
| 6525 |
THEN |
| 6526 |
f^.TrueExit := MakeLeftValue(OperandTok(pi), OperandT(pi), RightValue, Address) ; |
| 6527 |
MarkAsReadWrite(rw) |
| 6528 |
ELSIF IsConstString (OperandT (pi)) |
| 6529 |
THEN |
| 6530 |
f^.TrueExit := MakeLeftValue (OperandTok (pi), |
| 6531 |
DeferMakeConstStringCnul (OperandTok (pi), OperandT (pi)), RightValue, Address) ; |
| 6532 |
MarkAsReadWrite(rw) |
| 6533 |
ELSIF (GetSType(OperandT(pi))#NulSym) AND IsUnbounded(GetSType(OperandT(pi))) |
| 6534 |
THEN |
| 6535 |
MarkAsReadWrite(rw) ; |
| 6536 |
(* pass the address field of an unbounded variable *) |
| 6537 |
PushTFtok (Adr, Address, OperandTok (pi)) ; |
| 6538 |
PushTFAD (f^.TrueExit, f^.FalseExit, f^.Unbounded, f^.Dimension) ; |
| 6539 |
PushT(1) ; |
| 6540 |
BuildAdrFunction ; |
| 6541 |
PopT(f^.TrueExit) |
| 6542 |
ELSIF GetMode(OperandT(pi))=LeftValue |
| 6543 |
THEN |
| 6544 |
MarkAsReadWrite(rw) ; |
| 6545 |
(* must dereference LeftValue (even if we are passing variable as a vararg) *) |
| 6546 |
t := MakeTemporary (OperandTok (pi), RightValue) ; |
| 6547 |
PutVar(t, GetSType (OperandT (pi))) ; |
| 6548 |
CheckPointerThroughNil (tokpos, OperandT (pi)) ; |
| 6549 |
doIndrX (OperandTok(pi), t, OperandT (pi)) ; |
| 6550 |
f^.TrueExit := t |
| 6551 |
END |
| 6552 |
ELSE |
| 6553 |
MetaErrorT2 (tokpos, |
| 6554 |
'attempting to pass too many parameters to procedure {%1a}, the {%2N} parameter does not exist', |
| 6555 |
Proc, i) |
| 6556 |
END |
| 6557 |
ELSIF IsForC AND IsUnboundedParamAny (Proc, i) AND |
| 6558 |
(GetSType(OperandT(pi))#NulSym) AND IsArray(GetDType(OperandT(pi))) |
| 6559 |
THEN |
| 6560 |
f^.TrueExit := MakeLeftValue(OperandTok(pi), OperandT(pi), RightValue, Address) ; |
| 6561 |
MarkAsReadWrite(rw) |
| 6562 |
ELSIF IsForC AND IsUnboundedParamAny (Proc, i) AND |
| 6563 |
(GetSType(OperandT(pi))#NulSym) AND IsUnbounded(GetDType(OperandT(pi))) |
| 6564 |
THEN |
| 6565 |
MarkAsReadWrite(rw) ; |
| 6566 |
(* pass the address field of an unbounded variable *) |
| 6567 |
PushTFtok (Adr, Address, OperandTok (pi)) ; |
| 6568 |
PushTFAD (f^.TrueExit, f^.FalseExit, f^.Unbounded, f^.Dimension) ; |
| 6569 |
PushT(1) ; |
| 6570 |
BuildAdrFunction ; |
| 6571 |
PopT(f^.TrueExit) |
| 6572 |
ELSIF IsForC AND IsConstString(OperandT(pi)) AND |
| 6573 |
(IsUnboundedParamAny (Proc, i) OR (GetDType(GetParam(Proc, i))=Address)) |
| 6574 |
THEN |
| 6575 |
f^.TrueExit := MakeLeftValue (OperandTok (pi), |
| 6576 |
DeferMakeConstStringCnul (OperandTok (pi), OperandT (pi)), |
| 6577 |
RightValue, Address) ; |
| 6578 |
MarkAsReadWrite (rw) |
| 6579 |
ELSIF IsUnboundedParamAny (Proc, i) |
| 6580 |
THEN |
| 6581 |
(* always pass constant strings with a nul terminator, but leave the HIGH as before. *) |
| 6582 |
IF IsConstString (OperandT(pi)) |
| 6583 |
THEN |
| 6584 |
(* this is a Modula-2 string which must be nul terminated. *) |
| 6585 |
f^.TrueExit := DeferMakeConstStringM2nul (OperandTok (pi), OperandT (pi)) |
| 6586 |
END ; |
| 6587 |
t := MakeTemporary (OperandTok (pi), RightValue) ; |
| 6588 |
UnboundedType := GetSType(GetParam(Proc, i)) ; |
| 6589 |
PutVar(t, UnboundedType) ; |
| 6590 |
ParamType := GetSType(UnboundedType) ; |
| 6591 |
IF OperandD(pi)=0 |
| 6592 |
THEN |
| 6593 |
ArraySym := OperandT(pi) |
| 6594 |
ELSE |
| 6595 |
ArraySym := OperandA(pi) |
| 6596 |
END ; |
| 6597 |
IF IsVarParamAny (Proc, i) |
| 6598 |
THEN |
| 6599 |
MarkArrayWritten (OperandT (pi)) ; |
| 6600 |
MarkArrayWritten (OperandA (pi)) ; |
| 6601 |
MarkAsReadWrite(rw) ; |
| 6602 |
AssignUnboundedVar (OperandTtok (pi), OperandT (pi), ArraySym, t, ParamType, OperandD (pi)) |
| 6603 |
ELSE |
| 6604 |
MarkAsRead(rw) ; |
| 6605 |
AssignUnboundedNonVar (OperandTtok (pi), OperandT (pi), ArraySym, t, ParamType, OperandD (pi)) |
| 6606 |
END ; |
| 6607 |
f^.TrueExit := t |
| 6608 |
ELSIF IsVarParamAny (Proc, i) |
| 6609 |
THEN |
| 6610 |
(* must reference by address, but we contain the type of the referenced entity *) |
| 6611 |
MarkArrayWritten(OperandT(pi)) ; |
| 6612 |
MarkArrayWritten(OperandA(pi)) ; |
| 6613 |
MarkAsReadWrite(rw) ; |
| 6614 |
f^.TrueExit := MakeLeftValue(OperandTok(pi), OperandT(pi), LeftValue, GetSType(GetParam(Proc, i))) |
| 6615 |
ELSIF (NOT IsVarParamAny (Proc, i)) AND (GetMode(OperandT(pi))=LeftValue) |
| 6616 |
THEN |
| 6617 |
(* must dereference LeftValue *) |
| 6618 |
t := MakeTemporary (OperandTok (pi), RightValue) ; |
| 6619 |
PutVar(t, GetSType(OperandT(pi))) ; |
| 6620 |
CheckPointerThroughNil (tokpos, OperandT (pi)) ; |
| 6621 |
doIndrX (OperandTok(pi), t, OperandT(pi)) ; |
| 6622 |
f^.TrueExit := t ; |
| 6623 |
MarkAsRead(rw) |
| 6624 |
ELSE |
| 6625 |
MarkAsRead(rw) |
| 6626 |
END ; |
| 6627 |
INC(i) ; |
| 6628 |
DEC(pi) |
| 6629 |
END ; |
| 6630 |
PushT(NoOfParameters) |
| 6631 |
END ManipulateParameters ; |
| 6632 |
|
| 6633 |
|
| 6634 |
(* |
| 6635 |
CheckParameterOrdinals - check that ordinal values are within type range. |
| 6636 |
*) |
| 6637 |
|
| 6638 |
PROCEDURE CheckParameterOrdinals ; |
| 6639 |
VAR |
| 6640 |
tokno : CARDINAL ; |
| 6641 |
Proc, |
| 6642 |
ProcSym : CARDINAL ; |
| 6643 |
Actual, |
| 6644 |
FormalI : CARDINAL ; |
| 6645 |
ParamTotal, |
| 6646 |
pi, i : CARDINAL ; |
| 6647 |
BEGIN |
| 6648 |
PopT (ParamTotal) ; |
| 6649 |
PushT (ParamTotal) ; (* Restore stack to origional state *) |
| 6650 |
ProcSym := OperandT (ParamTotal+1+1) ; |
| 6651 |
IF IsVar(ProcSym) AND IsProcType(GetDType(ProcSym)) |
| 6652 |
THEN |
| 6653 |
(* Indirect procedure call. *) |
| 6654 |
Proc := SkipType(OperandF(ParamTotal+1+1)) |
| 6655 |
ELSE |
| 6656 |
Proc := SkipConst(ProcSym) |
| 6657 |
END ; |
| 6658 |
i := 1 ; |
| 6659 |
pi := ParamTotal+1 ; (* stack index referencing stacked parameter, i *) |
| 6660 |
WHILE i<=ParamTotal DO |
| 6661 |
IF i<=NoOfParamAny (Proc) |
| 6662 |
THEN |
| 6663 |
FormalI := GetParam (Proc, i) ; |
| 6664 |
Actual := OperandT (pi) ; |
| 6665 |
tokno := OperandTok (pi) ; |
| 6666 |
IF IsOrdinalType (GetLType (FormalI)) |
| 6667 |
THEN |
| 6668 |
IF NOT IsSet (GetDType (FormalI)) |
| 6669 |
THEN |
| 6670 |
(* Tell the code generator to test the runtime values of the assignment |
| 6671 |
so ensure we catch overflow and underflow. *) |
| 6672 |
BuildRange (InitParameterRangeCheck (tokno, Proc, i, FormalI, Actual, |
| 6673 |
OperandRangeDep (pi))) |
| 6674 |
END |
| 6675 |
END |
| 6676 |
END ; |
| 6677 |
INC (i) ; |
| 6678 |
DEC (pi) |
| 6679 |
END |
| 6680 |
END CheckParameterOrdinals ; |
| 6681 |
|
| 6682 |
|
| 6683 |
(* |
| 6684 |
IsSameUnbounded - returns TRUE if unbounded types, t1, and, t2, |
| 6685 |
are compatible. |
| 6686 |
*) |
| 6687 |
|
| 6688 |
PROCEDURE IsSameUnbounded (t1, t2: CARDINAL) : BOOLEAN ; |
| 6689 |
BEGIN |
| 6690 |
Assert(IsUnbounded(t1)) ; |
| 6691 |
Assert(IsUnbounded(t2)) ; |
| 6692 |
RETURN( GetDType(t1)=GetDType(t2) ) |
| 6693 |
END IsSameUnbounded ; |
| 6694 |
|
| 6695 |
|
| 6696 |
(* |
| 6697 |
AssignUnboundedVar - assigns an Unbounded symbol fields, |
| 6698 |
ArrayAddress and ArrayHigh, from an array symbol. |
| 6699 |
UnboundedSym is not a VAR parameter and therefore |
| 6700 |
this procedure can complete both of the fields. |
| 6701 |
Sym can be a Variable with type Unbounded. |
| 6702 |
Sym can be a Variable with type Array. |
| 6703 |
Sym can be a String Constant. |
| 6704 |
|
| 6705 |
ParamType is the TYPE of the parameter |
| 6706 |
*) |
| 6707 |
|
| 6708 |
PROCEDURE AssignUnboundedVar (tok: CARDINAL; |
| 6709 |
Sym, ArraySym, UnboundedSym, ParamType: CARDINAL; dim: CARDINAL) ; |
| 6710 |
VAR |
| 6711 |
Type: CARDINAL ; |
| 6712 |
BEGIN |
| 6713 |
IF IsConst(Sym) |
| 6714 |
THEN |
| 6715 |
MetaErrorT1 (tok, '{%1ad} cannot be passed to a VAR formal parameter', Sym) |
| 6716 |
ELSIF IsVar(Sym) |
| 6717 |
THEN |
| 6718 |
Type := GetDType(Sym) ; |
| 6719 |
IF Type = NulSym |
| 6720 |
THEN |
| 6721 |
MetaErrorT1 (tok, '{%1ad} has no type and cannot be passed to a VAR formal parameter', Sym) |
| 6722 |
ELSIF IsUnbounded(Type) |
| 6723 |
THEN |
| 6724 |
IF Type = GetSType (UnboundedSym) |
| 6725 |
THEN |
| 6726 |
(* Copy Unbounded Symbol ie. UnboundedSym := Sym *) |
| 6727 |
PushT (UnboundedSym) ; |
| 6728 |
PushT (Sym) ; |
| 6729 |
BuildAssignmentWithoutBounds (tok, FALSE, TRUE) |
| 6730 |
ELSIF IsSameUnbounded (Type, GetSType (UnboundedSym)) OR |
| 6731 |
IsGenericSystemType (ParamType) |
| 6732 |
THEN |
| 6733 |
UnboundedVarLinkToArray (tok, Sym, ArraySym, UnboundedSym, ParamType, dim) |
| 6734 |
ELSE |
| 6735 |
MetaErrorT1 (tok, '{%1ad} cannot be passed to a VAR formal parameter', Sym) |
| 6736 |
END |
| 6737 |
ELSIF IsArray (Type) OR IsGenericSystemType (ParamType) |
| 6738 |
THEN |
| 6739 |
UnboundedVarLinkToArray (tok, Sym, ArraySym, UnboundedSym, ParamType, dim) |
| 6740 |
ELSE |
| 6741 |
MetaErrorT1 (tok, '{%1ad} cannot be passed to a VAR formal parameter', Sym) |
| 6742 |
END |
| 6743 |
ELSE |
| 6744 |
MetaErrorT1 (tok, '{%1ad} cannot be passed to a VAR formal parameter', Sym) |
| 6745 |
END |
| 6746 |
END AssignUnboundedVar ; |
| 6747 |
|
| 6748 |
|
| 6749 |
(* |
| 6750 |
AssignUnboundedNonVar - assigns an Unbounded symbol fields, |
| 6751 |
The difference between this procedure and |
| 6752 |
AssignUnboundedVar is that this procedure cannot |
| 6753 |
set the Unbounded.Address since the data from |
| 6754 |
Sym will be copied because parameter is NOT a VAR |
| 6755 |
parameter. |
| 6756 |
UnboundedSym is not a VAR parameter and therefore |
| 6757 |
this procedure can only complete the HIGH field |
| 6758 |
and not the ADDRESS field. |
| 6759 |
Sym can be a Variable with type Unbounded. |
| 6760 |
Sym can be a Variable with type Array. |
| 6761 |
Sym can be a String Constant. |
| 6762 |
|
| 6763 |
ParamType is the TYPE of the paramater |
| 6764 |
*) |
| 6765 |
|
| 6766 |
PROCEDURE AssignUnboundedNonVar (tok: CARDINAL; |
| 6767 |
Sym, ArraySym, UnboundedSym, ParamType: CARDINAL; dim: CARDINAL) ; |
| 6768 |
VAR |
| 6769 |
Type: CARDINAL ; |
| 6770 |
BEGIN |
| 6771 |
IF IsConst (Sym) (* was IsConstString(Sym) *) |
| 6772 |
THEN |
| 6773 |
UnboundedNonVarLinkToArray (tok, Sym, ArraySym, UnboundedSym, ParamType, dim) |
| 6774 |
ELSIF IsVar (Sym) |
| 6775 |
THEN |
| 6776 |
Type := GetDType (Sym) ; |
| 6777 |
IF Type = NulSym |
| 6778 |
THEN |
| 6779 |
MetaErrorT1 (tok, '{%1ad} has no type and cannot be passed to a non VAR formal parameter', Sym) |
| 6780 |
ELSIF IsUnbounded (Type) |
| 6781 |
THEN |
| 6782 |
UnboundedNonVarLinkToArray (tok, Sym, ArraySym, UnboundedSym, ParamType, dim) |
| 6783 |
ELSIF IsArray (Type) OR IsGenericSystemType (ParamType) |
| 6784 |
THEN |
| 6785 |
UnboundedNonVarLinkToArray (tok, Sym, ArraySym, UnboundedSym, ParamType, dim) |
| 6786 |
ELSE |
| 6787 |
MetaErrorT1 (tok, 'illegal type parameter {%1Ead} expecting array or dynamic array', Sym) |
| 6788 |
END |
| 6789 |
ELSE |
| 6790 |
MetaErrorT1 (tok, 'illegal parameter {%1Ead} which cannot be passed as {%kVAR} {%kARRAY} {%kOF} {%1tsad}', Sym) |
| 6791 |
END |
| 6792 |
END AssignUnboundedNonVar ; |
| 6793 |
|
| 6794 |
|
| 6795 |
(* |
| 6796 |
GenHigh - generates a HighOp but it checks if op3 is a |
| 6797 |
L value and if so it dereferences it. This |
| 6798 |
is inefficient, however it is clean and we let the gcc |
| 6799 |
backend detect these as common subexpressions. |
| 6800 |
It will also detect that a R value -> L value -> R value |
| 6801 |
via indirection and eleminate these. |
| 6802 |
*) |
| 6803 |
|
| 6804 |
PROCEDURE GenHigh (tok: CARDINAL; |
| 6805 |
op1, op2, op3: CARDINAL) ; |
| 6806 |
VAR |
| 6807 |
sym: CARDINAL ; |
| 6808 |
BEGIN |
| 6809 |
IF (GetMode(op3)=LeftValue) AND IsUnbounded(GetSType(op3)) |
| 6810 |
THEN |
| 6811 |
sym := MakeTemporary (tok, RightValue) ; |
| 6812 |
PutVar (sym, GetSType (op3)) ; |
| 6813 |
doIndrX (tok, sym, op3) ; |
| 6814 |
GenQuadO (tok, HighOp, op1, op2, sym, TRUE) |
| 6815 |
ELSE |
| 6816 |
GenQuadO (tok, HighOp, op1, op2, op3, TRUE) |
| 6817 |
END |
| 6818 |
END GenHigh ; |
| 6819 |
|
| 6820 |
|
| 6821 |
(* |
| 6822 |
AssignHighField - |
| 6823 |
*) |
| 6824 |
|
| 6825 |
PROCEDURE AssignHighField (tok: CARDINAL; |
| 6826 |
Sym, ArraySym, UnboundedSym, ParamType: CARDINAL; |
| 6827 |
actuali, formali: CARDINAL) ; |
| 6828 |
VAR |
| 6829 |
ReturnVar, |
| 6830 |
ArrayType, |
| 6831 |
Field : CARDINAL ; |
| 6832 |
BEGIN |
| 6833 |
(* Unbounded.ArrayHigh := HIGH(ArraySym) *) |
| 6834 |
PushTFtok (UnboundedSym, GetSType (UnboundedSym), tok) ; |
| 6835 |
Field := GetUnboundedHighOffset (GetSType (UnboundedSym), formali) ; |
| 6836 |
PushTFtok (Field, GetSType (Field), tok) ; |
| 6837 |
PushT (1) ; |
| 6838 |
BuildDesignatorRecord (tok) ; |
| 6839 |
IF IsGenericSystemType (ParamType) |
| 6840 |
THEN |
| 6841 |
IF IsConstString (Sym) |
| 6842 |
THEN |
| 6843 |
PushTtok (DeferMakeLengthConst (tok, Sym), tok) |
| 6844 |
ELSE |
| 6845 |
ArrayType := GetSType (Sym) ; |
| 6846 |
IF IsUnbounded (ArrayType) |
| 6847 |
THEN |
| 6848 |
(* |
| 6849 |
* SIZE(parameter) DIV TSIZE(ParamType) |
| 6850 |
* however in this case parameter |
| 6851 |
* is an unbounded symbol and therefore we must use |
| 6852 |
* (HIGH(parameter)+1)*SIZE(unbounded type) DIV TSIZE(ParamType) |
| 6853 |
* |
| 6854 |
* we call upon the function SIZE(ArraySym) |
| 6855 |
* remember SIZE doubles as |
| 6856 |
* (HIGH(a)+1) * SIZE(ArrayType) for unbounded symbols |
| 6857 |
*) |
| 6858 |
PushTFtok (calculateMultipicand (tok, ArraySym, ArrayType, actuali-1), Cardinal, tok) ; |
| 6859 |
PushT (DivideTok) ; (* Divide by *) |
| 6860 |
PushTFtok (TSize, Cardinal, tok) ; (* TSIZE(ParamType) *) |
| 6861 |
PushTtok (ParamType, tok) ; |
| 6862 |
PushT (1) ; (* 1 parameter for TSIZE() *) |
| 6863 |
BuildFunctionCall (FALSE) ; |
| 6864 |
BuildBinaryOp |
| 6865 |
ELSE |
| 6866 |
(* SIZE(parameter) DIV TSIZE(ParamType) *) |
| 6867 |
PushTFtok (TSize, Cardinal, tok) ; (* TSIZE(ArrayType) *) |
| 6868 |
PushTtok (ArrayType, tok) ; |
| 6869 |
PushT (1) ; (* 1 parameter for TSIZE() *) |
| 6870 |
BuildFunctionCall (TRUE) ; |
| 6871 |
PushT (DivideTok) ; (* Divide by *) |
| 6872 |
PushTFtok (TSize, Cardinal, tok) ; (* TSIZE(ParamType) *) |
| 6873 |
PushTtok (ParamType, tok) ; |
| 6874 |
PushT (1) ; (* 1 parameter for TSIZE() *) |
| 6875 |
BuildFunctionCall (TRUE) ; |
| 6876 |
BuildBinaryOp |
| 6877 |
END ; |
| 6878 |
(* now convert from no of elements into HIGH by subtracting 1 *) |
| 6879 |
PushT (MinusTok) ; (* -1 *) |
| 6880 |
PushTtok (MakeConstLit (tok, MakeKey('1'), Cardinal), tok) ; |
| 6881 |
BuildBinaryOp |
| 6882 |
END |
| 6883 |
ELSE |
| 6884 |
ReturnVar := MakeTemporary (tok, RightValue) ; |
| 6885 |
PutVar (ReturnVar, Cardinal) ; |
| 6886 |
IF (actuali # formali) AND (ArraySym # NulSym) AND IsUnbounded (GetSType (ArraySym)) |
| 6887 |
THEN |
| 6888 |
GenHigh (tok, ReturnVar, actuali, ArraySym) |
| 6889 |
ELSE |
| 6890 |
GenHigh (tok, ReturnVar, formali, Sym) |
| 6891 |
END ; |
| 6892 |
PushTFtok (ReturnVar, GetSType(ReturnVar), tok) |
| 6893 |
END ; |
| 6894 |
BuildAssignmentWithoutBounds (tok, FALSE, TRUE) |
| 6895 |
END AssignHighField ; |
| 6896 |
|
| 6897 |
|
| 6898 |
(* |
| 6899 |
AssignHighFields - |
| 6900 |
*) |
| 6901 |
|
| 6902 |
PROCEDURE AssignHighFields (tok: CARDINAL; |
| 6903 |
Sym, ArraySym, UnboundedSym, ParamType: CARDINAL; dim: CARDINAL) ; |
| 6904 |
VAR |
| 6905 |
type : CARDINAL ; |
| 6906 |
actuali, formali, |
| 6907 |
actualn, formaln: CARDINAL ; |
| 6908 |
BEGIN |
| 6909 |
type := GetDType (Sym) ; |
| 6910 |
actualn := 1 ; |
| 6911 |
IF (type # NulSym) AND (IsUnbounded (type) OR IsArray (type)) |
| 6912 |
THEN |
| 6913 |
actualn := GetDimension (type) |
| 6914 |
END ; |
| 6915 |
actuali := dim + 1 ; |
| 6916 |
formali := 1 ; |
| 6917 |
formaln := GetDimension (GetDType (UnboundedSym)) ; |
| 6918 |
WHILE (actuali < actualn) AND (formali < formaln) DO |
| 6919 |
AssignHighField (tok, Sym, ArraySym, UnboundedSym, NulSym, actuali, formali) ; |
| 6920 |
INC (actuali) ; |
| 6921 |
INC (formali) |
| 6922 |
END ; |
| 6923 |
AssignHighField (tok, Sym, ArraySym, UnboundedSym, ParamType, actuali, formali) |
| 6924 |
END AssignHighFields ; |
| 6925 |
|
| 6926 |
|
| 6927 |
(* |
| 6928 |
UnboundedNonVarLinkToArray - links an array, ArraySym, to an unbounded |
| 6929 |
array, UnboundedSym. The parameter is a |
| 6930 |
NON VAR variety. |
| 6931 |
*) |
| 6932 |
|
| 6933 |
PROCEDURE UnboundedNonVarLinkToArray (tok: CARDINAL; |
| 6934 |
Sym, ArraySym, UnboundedSym, ParamType: CARDINAL; dim: CARDINAL) ; |
| 6935 |
VAR |
| 6936 |
Field, |
| 6937 |
AddressField: CARDINAL ; |
| 6938 |
BEGIN |
| 6939 |
(* Unbounded.ArrayAddress := to be assigned at runtime. *) |
| 6940 |
PushTFtok (UnboundedSym, GetSType (UnboundedSym), tok) ; |
| 6941 |
|
| 6942 |
Field := GetUnboundedAddressOffset(GetSType(UnboundedSym)) ; |
| 6943 |
PushTFtok (Field, GetSType(Field), tok) ; |
| 6944 |
PushT (1) ; |
| 6945 |
BuildDesignatorRecord (tok) ; |
| 6946 |
PopT (AddressField) ; |
| 6947 |
|
| 6948 |
(* caller saves non var unbounded array contents. *) |
| 6949 |
GenQuadO (tok, UnboundedOp, AddressField, NulSym, Sym, FALSE) ; |
| 6950 |
|
| 6951 |
AssignHighFields (tok, Sym, ArraySym, UnboundedSym, ParamType, dim) |
| 6952 |
END UnboundedNonVarLinkToArray ; |
| 6953 |
|
| 6954 |
|
| 6955 |
(* |
| 6956 |
UnboundedVarLinkToArray - links an array, ArraySym, to an unbounded array, |
| 6957 |
UnboundedSym. The parameter is a VAR variety. |
| 6958 |
*) |
| 6959 |
|
| 6960 |
PROCEDURE UnboundedVarLinkToArray (tok: CARDINAL; |
| 6961 |
Sym, ArraySym, UnboundedSym, ParamType: CARDINAL; dim: CARDINAL) ; |
| 6962 |
VAR |
| 6963 |
SymType, |
| 6964 |
Field : CARDINAL ; |
| 6965 |
BEGIN |
| 6966 |
SymType := GetSType (Sym) ; |
| 6967 |
(* Unbounded.ArrayAddress := ADR(Sym) *) |
| 6968 |
PushTFtok (UnboundedSym, GetSType (UnboundedSym), tok) ; |
| 6969 |
Field := GetUnboundedAddressOffset (GetSType (UnboundedSym)) ; |
| 6970 |
PushTFtok (Field, GetSType (Field), tok) ; |
| 6971 |
PushT (1) ; |
| 6972 |
BuildDesignatorRecord (tok) ; |
| 6973 |
PushTFtok (Adr, Address, tok) ; (* ADR (Sym). *) |
| 6974 |
IF IsUnbounded (SymType) AND (dim = 0) |
| 6975 |
THEN |
| 6976 |
PushTFADtok (Sym, SymType, UnboundedSym, dim, tok) |
| 6977 |
ELSE |
| 6978 |
PushTFADtok (Sym, SymType, ArraySym, dim, tok) |
| 6979 |
END ; |
| 6980 |
PushT (1) ; (* 1 parameter for ADR(). *) |
| 6981 |
BuildFunctionCall (FALSE) ; |
| 6982 |
BuildAssignmentWithoutBounds (tok, FALSE, TRUE) ; |
| 6983 |
|
| 6984 |
AssignHighFields (tok, Sym, ArraySym, UnboundedSym, ParamType, dim) |
| 6985 |
END UnboundedVarLinkToArray ; |
| 6986 |
|
| 6987 |
|
| 6988 |
(* |
| 6989 |
BuildPseudoProcedureCall - builds a pseudo procedure call. |
| 6990 |
This procedure does not directly alter the |
| 6991 |
stack, but by calling routines the stack |
| 6992 |
will change in the following way when this |
| 6993 |
procedure returns. |
| 6994 |
|
| 6995 |
The Stack: |
| 6996 |
|
| 6997 |
|
| 6998 |
Entry Exit |
| 6999 |
|
| 7000 |
Ptr -> |
| 7001 |
+----------------+ |
| 7002 |
| NoOfParam | |
| 7003 |
|----------------| |
| 7004 |
| Param 1 | |
| 7005 |
|----------------| |
| 7006 |
| Param 2 | |
| 7007 |
|----------------| |
| 7008 |
. . |
| 7009 |
. . |
| 7010 |
. . |
| 7011 |
|----------------| |
| 7012 |
| Param # | |
| 7013 |
|----------------| |
| 7014 |
| ProcSym | Type | Empty |
| 7015 |
|----------------| |
| 7016 |
*) |
| 7017 |
|
| 7018 |
PROCEDURE BuildPseudoProcedureCall (tokno: CARDINAL) ; |
| 7019 |
VAR |
| 7020 |
NoOfParam, |
| 7021 |
ProcSym : CARDINAL ; |
| 7022 |
BEGIN |
| 7023 |
PopT (NoOfParam) ; |
| 7024 |
ProcSym := OperandT (NoOfParam + 1) ; |
| 7025 |
PushT (NoOfParam) ; |
| 7026 |
(* Compile time stack restored to entry state *) |
| 7027 |
IF ProcSym = New |
| 7028 |
THEN |
| 7029 |
BuildNewProcedure (tokno) |
| 7030 |
ELSIF ProcSym = Dispose |
| 7031 |
THEN |
| 7032 |
BuildDisposeProcedure (tokno) |
| 7033 |
ELSIF ProcSym = Inc |
| 7034 |
THEN |
| 7035 |
BuildIncProcedure (tokno) |
| 7036 |
ELSIF ProcSym = Dec |
| 7037 |
THEN |
| 7038 |
BuildDecProcedure (tokno) |
| 7039 |
ELSIF ProcSym = Incl |
| 7040 |
THEN |
| 7041 |
BuildInclProcedure (tokno) |
| 7042 |
ELSIF ProcSym = Excl |
| 7043 |
THEN |
| 7044 |
BuildExclProcedure (tokno) |
| 7045 |
ELSIF ProcSym = Throw |
| 7046 |
THEN |
| 7047 |
BuildThrowProcedure (tokno) |
| 7048 |
ELSE |
| 7049 |
InternalError ('pseudo procedure not implemented yet') |
| 7050 |
END |
| 7051 |
END BuildPseudoProcedureCall ; |
| 7052 |
|
| 7053 |
|
| 7054 |
(* |
| 7055 |
GetItemPointedTo - returns the symbol type that is being pointed to |
| 7056 |
by Sym. |
| 7057 |
*) |
| 7058 |
|
| 7059 |
PROCEDURE GetItemPointedTo (Sym: CARDINAL) : CARDINAL ; |
| 7060 |
BEGIN |
| 7061 |
IF IsPointer (Sym) |
| 7062 |
THEN |
| 7063 |
RETURN GetSType (Sym) |
| 7064 |
ELSIF IsVar (Sym) OR IsType (Sym) |
| 7065 |
THEN |
| 7066 |
RETURN GetItemPointedTo (GetSType (Sym)) |
| 7067 |
ELSE |
| 7068 |
RETURN NulSym |
| 7069 |
END |
| 7070 |
END GetItemPointedTo ; |
| 7071 |
|
| 7072 |
|
| 7073 |
(* |
| 7074 |
BuildThrowProcedure - builds the pseudo procedure call M2RTS.Throw. |
| 7075 |
The Stack: |
| 7076 |
|
| 7077 |
|
| 7078 |
Entry Exit |
| 7079 |
|
| 7080 |
Ptr -> |
| 7081 |
+----------------+ |
| 7082 |
| NoOfParam | |
| 7083 |
|----------------| |
| 7084 |
| Param 1 | |
| 7085 |
|----------------| |
| 7086 |
| Param 2 | |
| 7087 |
|----------------| |
| 7088 |
. . |
| 7089 |
. . |
| 7090 |
. . |
| 7091 |
|----------------| |
| 7092 |
| Param # | |
| 7093 |
|----------------| |
| 7094 |
| ProcSym | Type | Empty |
| 7095 |
|----------------| |
| 7096 |
*) |
| 7097 |
|
| 7098 |
PROCEDURE BuildThrowProcedure (functok: CARDINAL) ; |
| 7099 |
VAR |
| 7100 |
op : CARDINAL ; |
| 7101 |
NoOfParam: CARDINAL ; |
| 7102 |
BEGIN |
| 7103 |
PopT (NoOfParam) ; |
| 7104 |
IF NoOfParam = 1 |
| 7105 |
THEN |
| 7106 |
op := OperandT (NoOfParam) ; |
| 7107 |
GenQuadO (functok, ThrowOp, NulSym, NulSym, op, FALSE) |
| 7108 |
ELSE |
| 7109 |
MetaErrorT1 (functok, 'the pseudo procedure %{1Ea} takes one INTEGER parameter', Throw) |
| 7110 |
END ; |
| 7111 |
PopN (NoOfParam+1) |
| 7112 |
END BuildThrowProcedure ; |
| 7113 |
|
| 7114 |
|
| 7115 |
(* |
| 7116 |
BuildReThrow - creates a ThrowOp _ _ NulSym, indicating that |
| 7117 |
the exception needs to be rethrown. The stack |
| 7118 |
is unaltered. |
| 7119 |
*) |
| 7120 |
|
| 7121 |
PROCEDURE BuildReThrow (tokenno: CARDINAL) ; |
| 7122 |
BEGIN |
| 7123 |
GenQuadO (tokenno, ThrowOp, NulSym, NulSym, NulSym, FALSE) |
| 7124 |
END BuildReThrow ; |
| 7125 |
|
| 7126 |
|
| 7127 |
(* |
| 7128 |
BuildNewProcedure - builds the pseudo procedure call NEW. |
| 7129 |
This procedure is traditionally a "macro" for |
| 7130 |
NEW(x, ...) --> ALLOCATE(x, TSIZE(x^, ...)) |
| 7131 |
One method of implementation is to emulate a "macro" |
| 7132 |
processor by pushing the relevant input tokens |
| 7133 |
back onto the input stack. |
| 7134 |
However this causes two problems: |
| 7135 |
|
| 7136 |
(i) Unnecessary code is produced for x^ |
| 7137 |
(ii) SIZE must be imported from SYSTEM |
| 7138 |
Therefore we chose an alternative method of |
| 7139 |
implementation; |
| 7140 |
generate quadruples for ALLOCATE(x, TSIZE(x^, ...)) |
| 7141 |
this, although slightly more efficient, |
| 7142 |
is more complex and circumvents problems (i) and (ii). |
| 7143 |
|
| 7144 |
The Stack: |
| 7145 |
|
| 7146 |
|
| 7147 |
Entry Exit |
| 7148 |
|
| 7149 |
Ptr -> |
| 7150 |
+----------------+ |
| 7151 |
| NoOfParam | |
| 7152 |
|----------------| |
| 7153 |
| Param 1 | |
| 7154 |
|----------------| |
| 7155 |
| Param 2 | |
| 7156 |
|----------------| |
| 7157 |
. . |
| 7158 |
. . |
| 7159 |
. . |
| 7160 |
|----------------| |
| 7161 |
| Param # | |
| 7162 |
|----------------| |
| 7163 |
| ProcSym | Type | Empty |
| 7164 |
|----------------| |
| 7165 |
*) |
| 7166 |
|
| 7167 |
PROCEDURE BuildNewProcedure (functok: CARDINAL) ; |
| 7168 |
VAR |
| 7169 |
NoOfParam, |
| 7170 |
SizeSym, |
| 7171 |
PtrSym, |
| 7172 |
ProcSym : CARDINAL ; |
| 7173 |
paramtok, |
| 7174 |
combinedtok: CARDINAL ; |
| 7175 |
BEGIN |
| 7176 |
PopT(NoOfParam) ; |
| 7177 |
IF NoOfParam>=1 |
| 7178 |
THEN |
| 7179 |
ProcSym := RequestSym (functok, MakeKey('ALLOCATE')) ; |
| 7180 |
IF (ProcSym#NulSym) AND IsProcedure(ProcSym) |
| 7181 |
THEN |
| 7182 |
PtrSym := OperandT (NoOfParam) ; |
| 7183 |
paramtok := OperandTtok (1) ; |
| 7184 |
IF IsReallyPointer(PtrSym) |
| 7185 |
THEN |
| 7186 |
combinedtok := MakeVirtualTok (functok, functok, paramtok) ; |
| 7187 |
(* |
| 7188 |
Build macro: ALLOCATE( PtrSym, SIZE(PtrSym^) ) |
| 7189 |
*) |
| 7190 |
PushTFtok (TSize, Cardinal, paramtok) ;(* Procedure *) |
| 7191 |
(* x^ *) |
| 7192 |
PushTtok (GetItemPointedTo (PtrSym), paramtok) ; |
| 7193 |
PushT (1) ; (* One parameter *) |
| 7194 |
BuildFunctionCall (FALSE) ; |
| 7195 |
PopT (SizeSym) ; |
| 7196 |
|
| 7197 |
PushTtok (ProcSym, combinedtok) ; (* ALLOCATE *) |
| 7198 |
PushTtok (PtrSym, paramtok) ; (* x *) |
| 7199 |
PushTtok (SizeSym, paramtok) ; (* TSIZE(x^) *) |
| 7200 |
PushT (2) ; (* Two parameters *) |
| 7201 |
BuildProcedureCall (combinedtok) |
| 7202 |
ELSE |
| 7203 |
MetaErrorT0 (paramtok, 'parameter to {%EkNEW} must be a pointer') |
| 7204 |
END |
| 7205 |
ELSE |
| 7206 |
MetaErrorT0 (functok, '{%E}ALLOCATE procedure not found for NEW substitution') |
| 7207 |
END |
| 7208 |
ELSE |
| 7209 |
MetaErrorT0 (functok, 'the pseudo procedure {%EkNEW} has one or more parameters') |
| 7210 |
END ; |
| 7211 |
PopN (NoOfParam+1) |
| 7212 |
END BuildNewProcedure ; |
| 7213 |
|
| 7214 |
|
| 7215 |
(* |
| 7216 |
BuildDisposeProcedure - builds the pseudo procedure call DISPOSE. |
| 7217 |
This procedure is traditionally a "macro" for |
| 7218 |
DISPOSE(x) --> DEALLOCATE(x, TSIZE(x^)) |
| 7219 |
One method of implementation is to emulate a "macro" |
| 7220 |
processor by pushing the relevant input tokens |
| 7221 |
back onto the input stack. |
| 7222 |
However this causes two problems: |
| 7223 |
|
| 7224 |
(i) Unnecessary code is produced for x^ |
| 7225 |
(ii) TSIZE must be imported from SYSTEM |
| 7226 |
Therefore we chose an alternative method of |
| 7227 |
implementation; |
| 7228 |
generate quadruples for DEALLOCATE(x, TSIZE(x^)) |
| 7229 |
this, although slightly more efficient, |
| 7230 |
is more complex and circumvents problems (i) |
| 7231 |
and (ii). |
| 7232 |
|
| 7233 |
The Stack: |
| 7234 |
|
| 7235 |
|
| 7236 |
Entry Exit |
| 7237 |
|
| 7238 |
Ptr -> |
| 7239 |
+----------------+ |
| 7240 |
| NoOfParam | |
| 7241 |
|----------------| |
| 7242 |
| Param 1 | |
| 7243 |
|----------------| |
| 7244 |
| Param 2 | |
| 7245 |
|----------------| |
| 7246 |
. . |
| 7247 |
. . |
| 7248 |
. . |
| 7249 |
|----------------| |
| 7250 |
| Param # | |
| 7251 |
|----------------| |
| 7252 |
| ProcSym | Type | Empty |
| 7253 |
|----------------| |
| 7254 |
*) |
| 7255 |
|
| 7256 |
PROCEDURE BuildDisposeProcedure (functok: CARDINAL) ; |
| 7257 |
VAR |
| 7258 |
NoOfParam, |
| 7259 |
SizeSym, |
| 7260 |
PtrSym, |
| 7261 |
ProcSym : CARDINAL ; |
| 7262 |
combinedtok, |
| 7263 |
paramtok : CARDINAL ; |
| 7264 |
BEGIN |
| 7265 |
PopT (NoOfParam) ; |
| 7266 |
IF NoOfParam>=1 |
| 7267 |
THEN |
| 7268 |
ProcSym := RequestSym (functok, MakeKey ('DEALLOCATE')) ; |
| 7269 |
IF (ProcSym # NulSym) AND IsProcedure (ProcSym) |
| 7270 |
THEN |
| 7271 |
PtrSym := OperandT (NoOfParam) ; |
| 7272 |
paramtok := OperandTtok (1) ; |
| 7273 |
IF IsReallyPointer (PtrSym) |
| 7274 |
THEN |
| 7275 |
combinedtok := MakeVirtualTok (functok, functok, paramtok) ; |
| 7276 |
(* |
| 7277 |
Build macro: DEALLOCATE( PtrSym, TSIZE(PtrSym^) ) |
| 7278 |
*) |
| 7279 |
PushTFtok (TSize, Cardinal, paramtok) ;(* Procedure *) |
| 7280 |
(* x^ *) |
| 7281 |
PushTtok (GetItemPointedTo(PtrSym), paramtok) ; |
| 7282 |
PushT (1) ; (* One parameter *) |
| 7283 |
BuildFunctionCall (FALSE) ; |
| 7284 |
PopT (SizeSym) ; |
| 7285 |
|
| 7286 |
PushTtok (ProcSym, combinedtok) ; (* DEALLOCATE *) |
| 7287 |
PushTtok (PtrSym, paramtok) ; (* x *) |
| 7288 |
PushTtok (SizeSym, paramtok) ; (* TSIZE(x^) *) |
| 7289 |
PushT (2) ; (* Two parameters *) |
| 7290 |
BuildProcedureCall (combinedtok) |
| 7291 |
ELSE |
| 7292 |
MetaErrorT0 (paramtok, 'argument to {%EkDISPOSE} must be a pointer') |
| 7293 |
END |
| 7294 |
ELSE |
| 7295 |
MetaErrorT0 (functok, '{%E}DEALLOCATE procedure not found for DISPOSE substitution') |
| 7296 |
END |
| 7297 |
ELSE |
| 7298 |
MetaErrorT0 (functok, 'the pseudo procedure {%EkDISPOSE} has one or more parameters') |
| 7299 |
END ; |
| 7300 |
PopN (NoOfParam+1) |
| 7301 |
END BuildDisposeProcedure ; |
| 7302 |
|
| 7303 |
|
| 7304 |
(* |
| 7305 |
CheckRangeIncDec - performs des := des <tok> expr |
| 7306 |
with range checking (if enabled). |
| 7307 |
|
| 7308 |
Stack |
| 7309 |
Entry Exit |
| 7310 |
|
| 7311 |
+------------+ |
| 7312 |
empty | des + expr | |
| 7313 |
|------------| |
| 7314 |
*) |
| 7315 |
|
| 7316 |
PROCEDURE CheckRangeIncDec (tokenpos: CARDINAL; des, expr: CARDINAL; tok: Name) ; |
| 7317 |
VAR |
| 7318 |
dtype, etype: CARDINAL ; |
| 7319 |
BEGIN |
| 7320 |
dtype := GetDType(des) ; |
| 7321 |
etype := GetDType(expr) ; |
| 7322 |
IF (etype = NulSym) AND IsPointer (GetTypeMode (des)) |
| 7323 |
THEN |
| 7324 |
expr := ConvertToAddress (tokenpos, expr) ; |
| 7325 |
etype := Address |
| 7326 |
END ; |
| 7327 |
IF WholeValueChecking AND (NOT MustNotCheckBounds) |
| 7328 |
THEN |
| 7329 |
IF tok=PlusTok |
| 7330 |
THEN |
| 7331 |
BuildRange (InitIncRangeCheck (des, expr)) |
| 7332 |
ELSE |
| 7333 |
BuildRange (InitDecRangeCheck (des, expr)) |
| 7334 |
END |
| 7335 |
END ; |
| 7336 |
|
| 7337 |
IF IsExpressionCompatible (dtype, etype) |
| 7338 |
THEN |
| 7339 |
(* the easy case simulate a straightforward macro *) |
| 7340 |
PushTFtok (des, dtype, tokenpos) ; |
| 7341 |
PushT (tok) ; |
| 7342 |
PushTFtok (expr, etype, tokenpos) ; |
| 7343 |
doBuildBinaryOp (FALSE, TRUE) |
| 7344 |
ELSE |
| 7345 |
IF (IsOrdinalType (dtype) OR (dtype = Address) OR IsPointer (dtype)) AND |
| 7346 |
(IsOrdinalType (etype) OR (etype = Address) OR IsPointer (etype)) |
| 7347 |
THEN |
| 7348 |
PushTFtok (des, dtype, tokenpos) ; |
| 7349 |
PushT (tok) ; |
| 7350 |
PushTFtok (Convert, NulSym, tokenpos) ; |
| 7351 |
PushTtok (dtype, tokenpos) ; |
| 7352 |
PushTtok (expr, tokenpos) ; |
| 7353 |
PushT (2) ; (* Two parameters *) |
| 7354 |
BuildConvertFunction (Convert, FALSE) ; |
| 7355 |
doBuildBinaryOp (FALSE, TRUE) |
| 7356 |
ELSE |
| 7357 |
IF tok=PlusTok |
| 7358 |
THEN |
| 7359 |
MetaError0 ('cannot perform {%EkINC} using non ordinal types') |
| 7360 |
ELSE |
| 7361 |
MetaError0 ('cannot perform {%EkDEC} using non ordinal types') |
| 7362 |
END ; |
| 7363 |
PushTFtok (MakeConstLit (tokenpos, MakeKey ('0'), NulSym), NulSym, tokenpos) |
| 7364 |
END |
| 7365 |
END |
| 7366 |
END CheckRangeIncDec ; |
| 7367 |
|
| 7368 |
|
| 7369 |
(* |
| 7370 |
BuildIncProcedure - builds the pseudo procedure call INC. |
| 7371 |
INC is a procedure which increments a variable. |
| 7372 |
It takes one or two parameters: |
| 7373 |
INC(a, b) or INC(a) |
| 7374 |
a := a+b or a := a+1 |
| 7375 |
|
| 7376 |
The Stack: |
| 7377 |
|
| 7378 |
|
| 7379 |
Entry Exit |
| 7380 |
|
| 7381 |
Ptr -> |
| 7382 |
+----------------+ |
| 7383 |
| NoOfParam | |
| 7384 |
|----------------| |
| 7385 |
| Param 1 | |
| 7386 |
|----------------| |
| 7387 |
| Param 2 | |
| 7388 |
|----------------| |
| 7389 |
. . |
| 7390 |
. . |
| 7391 |
. . |
| 7392 |
|----------------| |
| 7393 |
| Param # | |
| 7394 |
|----------------| |
| 7395 |
| ProcSym | Type | Empty |
| 7396 |
|----------------| |
| 7397 |
*) |
| 7398 |
|
| 7399 |
PROCEDURE BuildIncProcedure (proctok: CARDINAL) ; |
| 7400 |
VAR |
| 7401 |
NoOfParam, |
| 7402 |
dtype, |
| 7403 |
OperandSym, |
| 7404 |
VarSym, |
| 7405 |
TempSym : CARDINAL ; |
| 7406 |
BEGIN |
| 7407 |
PopT (NoOfParam) ; |
| 7408 |
IF (NoOfParam = 1) OR (NoOfParam = 2) |
| 7409 |
THEN |
| 7410 |
VarSym := OperandT (NoOfParam) ; (* Bottom/first parameter. *) |
| 7411 |
IF IsVar (VarSym) |
| 7412 |
THEN |
| 7413 |
dtype := GetDType (VarSym) ; |
| 7414 |
IF NoOfParam = 2 |
| 7415 |
THEN |
| 7416 |
OperandSym := DereferenceLValue (proctok, OperandT (1)) |
| 7417 |
ELSE |
| 7418 |
PushOne (proctok, dtype, |
| 7419 |
'the {%EkINC} will cause an overflow {%1ad}') ; |
| 7420 |
PopT (OperandSym) |
| 7421 |
END ; |
| 7422 |
|
| 7423 |
PushTtok (VarSym, proctok) ; |
| 7424 |
TempSym := DereferenceLValue (proctok, VarSym) ; |
| 7425 |
CheckRangeIncDec (proctok, TempSym, OperandSym, PlusTok) ; (* TempSym + OperandSym. *) |
| 7426 |
BuildAssignmentWithoutBounds (proctok, FALSE, TRUE) (* VarSym := TempSym + OperandSym. *) |
| 7427 |
ELSE |
| 7428 |
MetaErrorT1 (proctok, |
| 7429 |
'base procedure {%EkINC} expects a variable as a parameter but was given {%1Ed}', |
| 7430 |
VarSym) |
| 7431 |
END |
| 7432 |
ELSE |
| 7433 |
MetaErrorT0 (proctok, |
| 7434 |
'the base procedure {%EkINC} expects 1 or 2 parameters') |
| 7435 |
END ; |
| 7436 |
PopN (NoOfParam + 1) |
| 7437 |
END BuildIncProcedure ; |
| 7438 |
|
| 7439 |
|
| 7440 |
(* |
| 7441 |
BuildDecProcedure - builds the pseudo procedure call DEC. |
| 7442 |
DEC is a procedure which decrements a variable. |
| 7443 |
It takes one or two parameters: |
| 7444 |
DEC(a, b) or DEC(a) |
| 7445 |
a := a-b or a := a-1 |
| 7446 |
|
| 7447 |
The Stack: |
| 7448 |
|
| 7449 |
|
| 7450 |
Entry Exit |
| 7451 |
|
| 7452 |
Ptr -> |
| 7453 |
+----------------+ |
| 7454 |
| NoOfParam | |
| 7455 |
|----------------| |
| 7456 |
| Param 1 | |
| 7457 |
|----------------| |
| 7458 |
| Param 2 | |
| 7459 |
|----------------| |
| 7460 |
. . |
| 7461 |
. . |
| 7462 |
. . |
| 7463 |
|----------------| |
| 7464 |
| Param # | |
| 7465 |
|----------------| |
| 7466 |
| ProcSym | Type | Empty |
| 7467 |
|----------------| |
| 7468 |
*) |
| 7469 |
|
| 7470 |
PROCEDURE BuildDecProcedure (proctok: CARDINAL) ; |
| 7471 |
VAR |
| 7472 |
NoOfParam, |
| 7473 |
dtype, |
| 7474 |
OperandSym, |
| 7475 |
VarSym, |
| 7476 |
TempSym : CARDINAL ; |
| 7477 |
BEGIN |
| 7478 |
PopT (NoOfParam) ; |
| 7479 |
IF (NoOfParam = 1) OR (NoOfParam = 2) |
| 7480 |
THEN |
| 7481 |
VarSym := OperandT (NoOfParam) ; (* Bottom/first parameter. *) |
| 7482 |
IF IsVar (VarSym) |
| 7483 |
THEN |
| 7484 |
dtype := GetDType (VarSym) ; |
| 7485 |
IF NoOfParam = 2 |
| 7486 |
THEN |
| 7487 |
OperandSym := DereferenceLValue (proctok, OperandT (1)) |
| 7488 |
ELSE |
| 7489 |
PushOne (proctok, dtype, |
| 7490 |
'the {%EkDEC} will cause an overflow {%1ad}') ; |
| 7491 |
PopT (OperandSym) |
| 7492 |
END ; |
| 7493 |
|
| 7494 |
PushTtok (VarSym, proctok) ; |
| 7495 |
TempSym := DereferenceLValue (OperandTok (NoOfParam), VarSym) ; |
| 7496 |
CheckRangeIncDec (proctok, TempSym, OperandSym, MinusTok) ; (* TempSym - OperandSym. *) |
| 7497 |
BuildAssignmentWithoutBounds (proctok, FALSE, TRUE) (* VarSym := TempSym - OperandSym. *) |
| 7498 |
ELSE |
| 7499 |
MetaErrorT1 (proctok, |
| 7500 |
'base procedure {%EkDEC} expects a variable as a parameter but was given {%1Ed}', |
| 7501 |
VarSym) |
| 7502 |
END |
| 7503 |
ELSE |
| 7504 |
MetaErrorT0 (proctok, |
| 7505 |
'the base procedure {%EkDEC} expects 1 or 2 parameters') |
| 7506 |
END ; |
| 7507 |
PopN (NoOfParam + 1) |
| 7508 |
END BuildDecProcedure ; |
| 7509 |
|
| 7510 |
|
| 7511 |
(* |
| 7512 |
DereferenceLValue - checks to see whether, operand, is declare as an LValue |
| 7513 |
and if so it dereferences it. |
| 7514 |
*) |
| 7515 |
|
| 7516 |
PROCEDURE DereferenceLValue (tok: CARDINAL; operand: CARDINAL) : CARDINAL ; |
| 7517 |
VAR |
| 7518 |
sym: CARDINAL ; |
| 7519 |
BEGIN |
| 7520 |
IF GetMode (operand) = LeftValue |
| 7521 |
THEN |
| 7522 |
(* dereference the pointer *) |
| 7523 |
sym := MakeTemporary (tok, AreConstant(IsConst(operand))) ; |
| 7524 |
PutVar(sym, GetSType (operand)) ; |
| 7525 |
|
| 7526 |
PushTtok (sym, tok) ; |
| 7527 |
PushTtok (operand, tok) ; |
| 7528 |
BuildAssignmentWithoutBounds (tok, FALSE, TRUE) ; |
| 7529 |
RETURN sym |
| 7530 |
ELSE |
| 7531 |
RETURN operand |
| 7532 |
END |
| 7533 |
END DereferenceLValue ; |
| 7534 |
|
| 7535 |
|
| 7536 |
(* |
| 7537 |
BuildInclProcedure - builds the pseudo procedure call INCL. |
| 7538 |
INCL is a procedure which adds bit b into a BITSET a. |
| 7539 |
It takes two parameters: |
| 7540 |
INCL(a, b) |
| 7541 |
|
| 7542 |
a := a + {b} |
| 7543 |
|
| 7544 |
The Stack: |
| 7545 |
|
| 7546 |
|
| 7547 |
Entry Exit |
| 7548 |
|
| 7549 |
Ptr -> |
| 7550 |
+----------------+ |
| 7551 |
| NoOfParam | |
| 7552 |
|----------------| |
| 7553 |
| Param 1 | |
| 7554 |
|----------------| |
| 7555 |
| Param 2 | |
| 7556 |
|----------------| |
| 7557 |
| ProcSym | Type | Empty |
| 7558 |
|----------------| |
| 7559 |
*) |
| 7560 |
|
| 7561 |
PROCEDURE BuildInclProcedure (proctok: CARDINAL) ; |
| 7562 |
VAR |
| 7563 |
optok : CARDINAL ; |
| 7564 |
NoOfParam, |
| 7565 |
DerefSym, |
| 7566 |
OperandSym, |
| 7567 |
VarSym : CARDINAL ; |
| 7568 |
BEGIN |
| 7569 |
PopT (NoOfParam) ; |
| 7570 |
IF NoOfParam = 2 |
| 7571 |
THEN |
| 7572 |
VarSym := OperandT (2) ; |
| 7573 |
MarkArrayWritten (OperandA (2)) ; |
| 7574 |
OperandSym := OperandT (1) ; |
| 7575 |
optok := OperandTok (1) ; |
| 7576 |
IF IsVar (VarSym) |
| 7577 |
THEN |
| 7578 |
IF IsSet (GetDType (VarSym)) |
| 7579 |
THEN |
| 7580 |
DerefSym := DereferenceLValue (optok, OperandSym) ; |
| 7581 |
BuildRange (InitInclCheck (VarSym, DerefSym)) ; |
| 7582 |
GenQuadO (proctok, InclOp, VarSym, NulSym, DerefSym, FALSE) |
| 7583 |
ELSE |
| 7584 |
MetaErrorT1 (proctok, |
| 7585 |
'the first parameter to {%EkINCL} must be a set variable but is {%1Ed}', |
| 7586 |
VarSym) |
| 7587 |
END |
| 7588 |
ELSE |
| 7589 |
MetaErrorT1 (proctok, |
| 7590 |
'base procedure {%EkINCL} expects a variable as a parameter but is {%1Ed}', |
| 7591 |
VarSym) |
| 7592 |
END |
| 7593 |
ELSE |
| 7594 |
MetaErrorT0 (proctok, 'the base procedure {%EkINCL} expects 1 or 2 parameters') |
| 7595 |
END ; |
| 7596 |
PopN (NoOfParam + 1) |
| 7597 |
END BuildInclProcedure ; |
| 7598 |
|
| 7599 |
|
| 7600 |
(* |
| 7601 |
BuildExclProcedure - builds the pseudo procedure call EXCL. |
| 7602 |
INCL is a procedure which removes bit b from SET a. |
| 7603 |
It takes two parameters: |
| 7604 |
EXCL(a, b) |
| 7605 |
|
| 7606 |
a := a - {b} |
| 7607 |
|
| 7608 |
The Stack: |
| 7609 |
|
| 7610 |
|
| 7611 |
Entry Exit |
| 7612 |
|
| 7613 |
Ptr -> |
| 7614 |
+----------------+ |
| 7615 |
| NoOfParam | |
| 7616 |
|----------------| |
| 7617 |
| Param 1 | |
| 7618 |
|----------------| |
| 7619 |
| Param 2 | |
| 7620 |
|----------------| |
| 7621 |
| ProcSym | Type | Empty |
| 7622 |
|----------------| |
| 7623 |
*) |
| 7624 |
|
| 7625 |
PROCEDURE BuildExclProcedure (proctok: CARDINAL) ; |
| 7626 |
VAR |
| 7627 |
optok : CARDINAL ; |
| 7628 |
NoOfParam, |
| 7629 |
DerefSym, |
| 7630 |
OperandSym, |
| 7631 |
VarSym : CARDINAL ; |
| 7632 |
BEGIN |
| 7633 |
PopT (NoOfParam) ; |
| 7634 |
IF NoOfParam=2 |
| 7635 |
THEN |
| 7636 |
VarSym := OperandT (2) ; |
| 7637 |
MarkArrayWritten (OperandA(2)) ; |
| 7638 |
OperandSym := OperandT (1) ; |
| 7639 |
optok := OperandTok (1) ; |
| 7640 |
IF IsVar (VarSym) |
| 7641 |
THEN |
| 7642 |
IF IsSet (GetDType (VarSym)) |
| 7643 |
THEN |
| 7644 |
DerefSym := DereferenceLValue (optok, OperandSym) ; |
| 7645 |
BuildRange (InitExclCheck (VarSym, DerefSym)) ; |
| 7646 |
GenQuadO (proctok, ExclOp, VarSym, NulSym, DerefSym, FALSE) |
| 7647 |
ELSE |
| 7648 |
MetaErrorT1 (proctok, |
| 7649 |
'the first parameter to {%EkEXCL} must be a set variable but is {%1Ed}', |
| 7650 |
VarSym) |
| 7651 |
END |
| 7652 |
ELSE |
| 7653 |
MetaErrorT1 (proctok, |
| 7654 |
'base procedure {%EkEXCL} expects a variable as a parameter but is {%1Ed}', |
| 7655 |
VarSym) |
| 7656 |
END |
| 7657 |
ELSE |
| 7658 |
MetaErrorT0 (proctok, |
| 7659 |
'the base procedure {%EkEXCL} expects 1 or 2 parameters') |
| 7660 |
END ; |
| 7661 |
PopN (NoOfParam + 1) |
| 7662 |
END BuildExclProcedure ; |
| 7663 |
|
| 7664 |
|
| 7665 |
(* |
| 7666 |
CheckBuildFunction - checks to see whether ProcSym is a function |
| 7667 |
and if so it adds a TempSym value which will |
| 7668 |
hold the return value once the function finishes. |
| 7669 |
This procedure also generates an error message |
| 7670 |
if the user is calling a function and ignoring |
| 7671 |
the return result. The additional TempSym |
| 7672 |
is not created if ProcSym is a procedure |
| 7673 |
and the stack is unaltered. |
| 7674 |
|
| 7675 |
The Stack: |
| 7676 |
|
| 7677 |
|
| 7678 |
Entry Exit |
| 7679 |
|
| 7680 |
Ptr -> |
| 7681 |
|
| 7682 |
+----------------+ |
| 7683 |
| ProcSym | Type | |
| 7684 |
+----------------+ |----------------| |
| 7685 |
| ProcSym | Type | | TempSym | Type | |
| 7686 |
|----------------| |----------------| |
| 7687 |
*) |
| 7688 |
|
| 7689 |
PROCEDURE CheckBuildFunction () : BOOLEAN ; |
| 7690 |
VAR |
| 7691 |
tokpos, |
| 7692 |
TempSym, |
| 7693 |
ProcSym, Type: CARDINAL ; |
| 7694 |
BEGIN |
| 7695 |
PopTFtok(ProcSym, Type, tokpos) ; |
| 7696 |
IF IsVar(ProcSym) AND IsProcType(Type) |
| 7697 |
THEN |
| 7698 |
IF GetSType(Type)#NulSym |
| 7699 |
THEN |
| 7700 |
TempSym := MakeTemporary (tokpos, RightValue) ; |
| 7701 |
PutVar(TempSym, GetSType(Type)) ; |
| 7702 |
PushTFtok(TempSym, GetSType(Type), tokpos) ; |
| 7703 |
PushTFtok(ProcSym, Type, tokpos) ; |
| 7704 |
IF NOT IsReturnOptionalAny (Type) |
| 7705 |
THEN |
| 7706 |
MetaErrorT1 (tokpos, |
| 7707 |
'function {%1Ea} is called but its return value is ignored', ProcSym) |
| 7708 |
END ; |
| 7709 |
RETURN TRUE |
| 7710 |
END |
| 7711 |
ELSIF IsProcedure(ProcSym) AND (Type#NulSym) |
| 7712 |
THEN |
| 7713 |
TempSym := MakeTemporary (tokpos, RightValue) ; |
| 7714 |
PutVar(TempSym, Type) ; |
| 7715 |
PushTFtok(TempSym, Type, tokpos) ; |
| 7716 |
PushTFtok(ProcSym, Type, tokpos) ; |
| 7717 |
IF NOT IsReturnOptionalAny (ProcSym) |
| 7718 |
THEN |
| 7719 |
MetaErrorT1 (tokpos, |
| 7720 |
'function {%1Ea} is called but its return value is ignored', ProcSym) |
| 7721 |
END ; |
| 7722 |
RETURN TRUE |
| 7723 |
END ; |
| 7724 |
PushTFtok (ProcSym, Type, tokpos) ; |
| 7725 |
RETURN FALSE |
| 7726 |
END CheckBuildFunction ; |
| 7727 |
|
| 7728 |
|
| 7729 |
(* |
| 7730 |
BuildFunctionCall - builds a function call. |
| 7731 |
The Stack: |
| 7732 |
|
| 7733 |
|
| 7734 |
Entry Exit |
| 7735 |
|
| 7736 |
Ptr -> |
| 7737 |
+----------------+ |
| 7738 |
| NoOfParam | |
| 7739 |
|----------------| |
| 7740 |
| Param 1 | |
| 7741 |
|----------------| |
| 7742 |
| Param 2 | |
| 7743 |
|----------------| |
| 7744 |
. . |
| 7745 |
. . |
| 7746 |
. . |
| 7747 |
|----------------| |
| 7748 |
| Param # | <- Ptr |
| 7749 |
|----------------| +------------+ |
| 7750 |
| ProcSym | Type | | ReturnVar | |
| 7751 |
|----------------| |------------| |
| 7752 |
*) |
| 7753 |
|
| 7754 |
PROCEDURE BuildFunctionCall (ConstExpr: BOOLEAN) ; |
| 7755 |
VAR |
| 7756 |
paramtok, |
| 7757 |
combinedtok, |
| 7758 |
functok, |
| 7759 |
NoOfParam, |
| 7760 |
ProcSym : CARDINAL ; |
| 7761 |
BEGIN |
| 7762 |
PopT (NoOfParam) ; |
| 7763 |
functok := OperandTtok (NoOfParam + 1) ; |
| 7764 |
ProcSym := OperandT (NoOfParam + 1) ; |
| 7765 |
ProcSym := SkipConst (ProcSym) ; |
| 7766 |
PushT (NoOfParam) ; |
| 7767 |
(* Compile time stack restored to entry state. *) |
| 7768 |
IF IsUnknown (ProcSym) |
| 7769 |
THEN |
| 7770 |
paramtok := OperandTtok (1) ; |
| 7771 |
combinedtok := MakeVirtual2Tok (functok, paramtok) ; |
| 7772 |
MetaErrorT1 (functok, 'procedure function {%1Ea} is undefined', ProcSym) ; |
| 7773 |
PopN (NoOfParam + 2) ; |
| 7774 |
(* Fake return value to continue compiling. *) |
| 7775 |
PushT (MakeConstLit (combinedtok, MakeKey ('0'), NulSym)) |
| 7776 |
ELSIF IsAModula2Type (ProcSym) |
| 7777 |
THEN |
| 7778 |
ManipulatePseudoCallParameters ; |
| 7779 |
BuildTypeCoercion (ConstExpr) |
| 7780 |
ELSIF IsPseudoSystemFunction (ProcSym) OR |
| 7781 |
IsPseudoBaseFunction (ProcSym) |
| 7782 |
THEN |
| 7783 |
ManipulatePseudoCallParameters ; |
| 7784 |
BuildPseudoFunctionCall (ConstExpr) |
| 7785 |
ELSE |
| 7786 |
BuildRealFunctionCall (functok, ConstExpr) |
| 7787 |
END |
| 7788 |
END BuildFunctionCall ; |
| 7789 |
|
| 7790 |
|
| 7791 |
(* |
| 7792 |
BuildConstFunctionCall - builds a function call and checks that this function can be |
| 7793 |
called inside a ConstExpression. |
| 7794 |
|
| 7795 |
The Stack: |
| 7796 |
|
| 7797 |
|
| 7798 |
Entry Exit |
| 7799 |
|
| 7800 |
Ptr -> |
| 7801 |
+----------------+ |
| 7802 |
| NoOfParam | |
| 7803 |
|----------------| |
| 7804 |
| Param 1 | |
| 7805 |
|----------------| |
| 7806 |
| Param 2 | |
| 7807 |
|----------------| |
| 7808 |
. . |
| 7809 |
. . |
| 7810 |
. . |
| 7811 |
|----------------| |
| 7812 |
| Param # | <- Ptr |
| 7813 |
|----------------| +------------+ |
| 7814 |
| ProcSym | Type | | ReturnVar | |
| 7815 |
|----------------| |------------| |
| 7816 |
|
| 7817 |
*) |
| 7818 |
|
| 7819 |
PROCEDURE BuildConstFunctionCall ; |
| 7820 |
VAR |
| 7821 |
functok, |
| 7822 |
combinedtok, |
| 7823 |
paramtok, |
| 7824 |
ConstExpression, |
| 7825 |
NoOfParam, |
| 7826 |
ProcSym : CARDINAL ; |
| 7827 |
BEGIN |
| 7828 |
DisplayStack ; |
| 7829 |
PopT(NoOfParam) ; |
| 7830 |
ProcSym := OperandT (NoOfParam + 1) ; |
| 7831 |
functok := OperandTtok (NoOfParam + 1) ; |
| 7832 |
IF CompilerDebugging |
| 7833 |
THEN |
| 7834 |
printf2 ('procsym = %d token = %d\n', ProcSym, functok) ; |
| 7835 |
(* ErrorStringAt (InitString ('constant function'), functok). *) |
| 7836 |
END ; |
| 7837 |
PushT (NoOfParam) ; |
| 7838 |
IF (ProcSym # Convert) AND |
| 7839 |
(IsPseudoBaseFunction (ProcSym) OR |
| 7840 |
IsPseudoSystemFunctionConstExpression (ProcSym) OR |
| 7841 |
(IsProcedure (ProcSym) AND IsProcedureBuiltin (ProcSym))) |
| 7842 |
THEN |
| 7843 |
BuildFunctionCall (TRUE) |
| 7844 |
ELSE |
| 7845 |
IF IsAModula2Type (ProcSym) |
| 7846 |
THEN |
| 7847 |
(* Type conversion. *) |
| 7848 |
IF NoOfParam = 1 |
| 7849 |
THEN |
| 7850 |
ConstExpression := OperandT (NoOfParam + 1) ; |
| 7851 |
paramtok := OperandTtok (NoOfParam + 1) ; |
| 7852 |
PopN (NoOfParam + 2) ; |
| 7853 |
(* Build macro: CONVERT( ProcSym, ConstExpression ). *) |
| 7854 |
PushTFtok (Convert, NulSym, functok) ; |
| 7855 |
PushTtok (ProcSym, functok) ; |
| 7856 |
PushTtok (ConstExpression, paramtok) ; |
| 7857 |
PushT (2) ; (* Two parameters. *) |
| 7858 |
BuildConvertFunction (Convert, TRUE) |
| 7859 |
ELSE |
| 7860 |
MetaErrorT0 (functok, '{%E}a constant type conversion can only have one argument') |
| 7861 |
END |
| 7862 |
ELSE |
| 7863 |
(* Error issue message and fake return stack. *) |
| 7864 |
IF Iso |
| 7865 |
THEN |
| 7866 |
MetaErrorT0 (functok, 'the only functions permissible in a constant expression are: {%kCAP}, {%kCHR}, {%kCMPLX}, {%kFLOAT}, {%kHIGH}, {%kIM}, {%kLENGTH}, {%kMAX}, {%kMIN}, {%kODD}, {%kORD}, {%kRE}, {%kSIZE}, {%kTSIZE}, {%kTRUNC}, {%kVAL} and gcc builtins') |
| 7867 |
ELSE |
| 7868 |
MetaErrorT0 (functok, 'the only functions permissible in a constant expression are: {%kCAP}, {%kCHR}, {%kFLOAT}, {%kHIGH}, {%kMAX}, {%kMIN}, {%kODD}, {%kORD}, {%kSIZE}, {%kTSIZE}, {%kTRUNC}, {%kVAL} and gcc builtins') |
| 7869 |
END ; |
| 7870 |
IF NoOfParam > 0 |
| 7871 |
THEN |
| 7872 |
paramtok := OperandTtok (NoOfParam + 1) ; |
| 7873 |
combinedtok := MakeVirtualTok (functok, functok, paramtok) |
| 7874 |
ELSE |
| 7875 |
combinedtok := functok |
| 7876 |
END ; |
| 7877 |
PopN (NoOfParam+2) ; |
| 7878 |
PushT (MakeConstLit (combinedtok, MakeKey('0'), NulSym)) (* Fake return value to continue compiling. *) |
| 7879 |
END |
| 7880 |
END |
| 7881 |
END BuildConstFunctionCall ; |
| 7882 |
|
| 7883 |
|
| 7884 |
(* |
| 7885 |
BuildTypeCoercion - builds the type coersion. |
| 7886 |
Modula-2 allows types to be coersed with no runtime |
| 7887 |
penility. |
| 7888 |
It insists that the TSIZE(t1)=TSIZE(t2) where |
| 7889 |
t2 variable := t2(variable of type t1). |
| 7890 |
The ReturnVar on the stack is of type t2. |
| 7891 |
|
| 7892 |
The Stack: |
| 7893 |
|
| 7894 |
|
| 7895 |
Entry Exit |
| 7896 |
|
| 7897 |
Ptr -> |
| 7898 |
+----------------+ |
| 7899 |
| NoOfParam | |
| 7900 |
|----------------| |
| 7901 |
| Param 1 | |
| 7902 |
|----------------| |
| 7903 |
| Param 2 | |
| 7904 |
|----------------| |
| 7905 |
. . |
| 7906 |
. . |
| 7907 |
. . |
| 7908 |
|----------------| |
| 7909 |
| Param # | <- Ptr |
| 7910 |
|----------------| +------------+ |
| 7911 |
| ProcSym | Type | | ReturnVar | |
| 7912 |
|----------------| |------------| |
| 7913 |
|
| 7914 |
Quadruples: |
| 7915 |
|
| 7916 |
CoerceOp ReturnVar Type Param1 |
| 7917 |
|
| 7918 |
A type coercion will only be legal if the different |
| 7919 |
types have exactly the same size. |
| 7920 |
Since we can only decide this after M2Eval has processed |
| 7921 |
the symbol table then we create a quadruple explaining |
| 7922 |
the coercion taking place, the code generator can test |
| 7923 |
this assertion and report an error if the type sizes |
| 7924 |
differ. |
| 7925 |
*) |
| 7926 |
|
| 7927 |
PROCEDURE BuildTypeCoercion (ConstExpr: BOOLEAN) ; |
| 7928 |
VAR |
| 7929 |
resulttok, |
| 7930 |
proctok, |
| 7931 |
exptok : CARDINAL ; |
| 7932 |
r, |
| 7933 |
exp, |
| 7934 |
NoOfParam, |
| 7935 |
ReturnVar, |
| 7936 |
ProcSym : CARDINAL ; |
| 7937 |
BEGIN |
| 7938 |
PopT(NoOfParam) ; |
| 7939 |
ProcSym := OperandT (NoOfParam+1) ; |
| 7940 |
proctok := OperandTok (NoOfParam+1) ; |
| 7941 |
IF NOT IsAModula2Type (ProcSym) |
| 7942 |
THEN |
| 7943 |
MetaError1 ('coersion expecting a type, seen {%1Ea} which is {%1Ed}', ProcSym) |
| 7944 |
END ; |
| 7945 |
IF NoOfParam = 1 |
| 7946 |
THEN |
| 7947 |
PopTrwtok (exp, r, exptok) ; |
| 7948 |
MarkAsRead (r) ; |
| 7949 |
resulttok := MakeVirtual2Tok (proctok, exptok) ; |
| 7950 |
PopN (1) ; (* Pop procedure. *) |
| 7951 |
IF ConstExprError (ProcSym, exp, exptok, ConstExpr) |
| 7952 |
THEN |
| 7953 |
ReturnVar := MakeTemporary (resulttok, ImmediateValue) ; |
| 7954 |
PutVar (ReturnVar, ProcSym) ; (* Set ReturnVar's TYPE. *) |
| 7955 |
ELSIF IsConst (exp) OR IsVar (exp) |
| 7956 |
THEN |
| 7957 |
ReturnVar := MakeTemporary (resulttok, AreConstant (IsConst (exp))) ; |
| 7958 |
PutVar (ReturnVar, ProcSym) ; (* Set ReturnVar's TYPE. *) |
| 7959 |
GenQuad (CoerceOp, ReturnVar, ProcSym, exp) |
| 7960 |
ELSE |
| 7961 |
MetaError2 ('trying to coerse {%1EMRad} which is not a variable or constant into {%2ad}', |
| 7962 |
exp, ProcSym) ; |
| 7963 |
MetaError2 ('trying to coerse {%1ECad} which is not a variable or constant into {%2ad}', |
| 7964 |
exp, ProcSym) ; |
| 7965 |
ReturnVar := MakeTemporary (resulttok, RightValue) ; |
| 7966 |
PutVar (ReturnVar, ProcSym) (* Set ReturnVar's TYPE. *) |
| 7967 |
END ; |
| 7968 |
PushTFtok (ReturnVar, ProcSym, resulttok) |
| 7969 |
ELSE |
| 7970 |
MetaError0 ('{%E}only one parameter expected in a TYPE coersion') |
| 7971 |
END |
| 7972 |
END BuildTypeCoercion ; |
| 7973 |
|
| 7974 |
|
| 7975 |
(* |
| 7976 |
BuildRealFunctionCall - builds a function call. |
| 7977 |
The Stack: |
| 7978 |
|
| 7979 |
|
| 7980 |
Entry Exit |
| 7981 |
|
| 7982 |
Ptr -> |
| 7983 |
+----------------+ |
| 7984 |
| NoOfParam | |
| 7985 |
|----------------| |
| 7986 |
| Param 1 | |
| 7987 |
|----------------| |
| 7988 |
| Param 2 | |
| 7989 |
|----------------| |
| 7990 |
. . |
| 7991 |
. . |
| 7992 |
. . |
| 7993 |
|----------------| |
| 7994 |
| Param # | <- Ptr |
| 7995 |
|----------------| +------------+ |
| 7996 |
| ProcSym | Type | | ReturnVar | |
| 7997 |
|----------------| |------------| |
| 7998 |
*) |
| 7999 |
|
| 8000 |
PROCEDURE BuildRealFunctionCall (tokno: CARDINAL; ConstExpr: BOOLEAN) ; |
| 8001 |
VAR |
| 8002 |
NoOfParam, |
| 8003 |
ProcSym : CARDINAL ; |
| 8004 |
BEGIN |
| 8005 |
PopT(NoOfParam) ; |
| 8006 |
PushT(NoOfParam) ; |
| 8007 |
ProcSym := OperandT (NoOfParam+2) ; |
| 8008 |
ProcSym := SkipConst (ProcSym) ; |
| 8009 |
IF IsVar(ProcSym) |
| 8010 |
THEN |
| 8011 |
(* Procedure Variable therefore get its type to see if it is a FOR "C" call. *) |
| 8012 |
ProcSym := SkipType (OperandF (NoOfParam+2)) |
| 8013 |
END ; |
| 8014 |
IF IsDefImp (GetScope (ProcSym)) AND IsDefinitionForC (GetScope (ProcSym)) |
| 8015 |
THEN |
| 8016 |
BuildRealFuncProcCall (tokno, TRUE, TRUE, ConstExpr) |
| 8017 |
ELSE |
| 8018 |
BuildRealFuncProcCall (tokno, TRUE, FALSE, ConstExpr) |
| 8019 |
END |
| 8020 |
END BuildRealFunctionCall ; |
| 8021 |
|
| 8022 |
|
| 8023 |
(* |
| 8024 |
BuildPseudoFunctionCall - builds the pseudo function |
| 8025 |
The Stack: |
| 8026 |
|
| 8027 |
|
| 8028 |
Entry Exit |
| 8029 |
|
| 8030 |
Ptr -> |
| 8031 |
+----------------+ |
| 8032 |
| NoOfParam | |
| 8033 |
|----------------| |
| 8034 |
| Param 1 | |
| 8035 |
|----------------| |
| 8036 |
| Param 2 | |
| 8037 |
|----------------| |
| 8038 |
. . |
| 8039 |
. . |
| 8040 |
. . |
| 8041 |
|----------------| |
| 8042 |
| Param # | <- Ptr |
| 8043 |
|----------------| +------------+ |
| 8044 |
| ProcSym | Type | | ReturnVar | |
| 8045 |
|----------------| |------------| |
| 8046 |
|
| 8047 |
*) |
| 8048 |
|
| 8049 |
PROCEDURE BuildPseudoFunctionCall (ConstExpr: BOOLEAN) ; |
| 8050 |
VAR |
| 8051 |
NoOfParam, |
| 8052 |
ProcSym : CARDINAL ; |
| 8053 |
BEGIN |
| 8054 |
PopT (NoOfParam) ; |
| 8055 |
ProcSym := OperandT (NoOfParam+1) ; |
| 8056 |
ProcSym := SkipConst (ProcSym) ; |
| 8057 |
PushT (NoOfParam) ; |
| 8058 |
(* Compile time stack restored to entry state. *) |
| 8059 |
IF ProcSym = High |
| 8060 |
THEN |
| 8061 |
BuildHighFunction |
| 8062 |
ELSIF ProcSym = LengthS |
| 8063 |
THEN |
| 8064 |
BuildLengthFunction (ProcSym, ConstExpr) |
| 8065 |
ELSIF ProcSym = Adr |
| 8066 |
THEN |
| 8067 |
BuildAdrFunction |
| 8068 |
ELSIF ProcSym = Size |
| 8069 |
THEN |
| 8070 |
BuildSizeFunction |
| 8071 |
ELSIF ProcSym = TSize |
| 8072 |
THEN |
| 8073 |
BuildTSizeFunction |
| 8074 |
ELSIF ProcSym = TBitSize |
| 8075 |
THEN |
| 8076 |
BuildTBitSizeFunction |
| 8077 |
ELSIF ProcSym = Convert |
| 8078 |
THEN |
| 8079 |
BuildConvertFunction (ProcSym, ConstExpr) |
| 8080 |
ELSIF ProcSym = Odd |
| 8081 |
THEN |
| 8082 |
BuildOddFunction (ProcSym, ConstExpr) |
| 8083 |
ELSIF ProcSym = Abs |
| 8084 |
THEN |
| 8085 |
BuildAbsFunction (ProcSym, ConstExpr) |
| 8086 |
ELSIF ProcSym = Cap |
| 8087 |
THEN |
| 8088 |
BuildCapFunction (ProcSym, ConstExpr) |
| 8089 |
ELSIF ProcSym = Val |
| 8090 |
THEN |
| 8091 |
BuildValFunction (ProcSym, ConstExpr) |
| 8092 |
ELSIF ProcSym = Chr |
| 8093 |
THEN |
| 8094 |
BuildChrFunction (ProcSym, ConstExpr) |
| 8095 |
ELSIF IsOrd (ProcSym) |
| 8096 |
THEN |
| 8097 |
BuildOrdFunction (ProcSym, ConstExpr) |
| 8098 |
ELSIF IsInt (ProcSym) |
| 8099 |
THEN |
| 8100 |
BuildIntFunction (ProcSym, ConstExpr) |
| 8101 |
ELSIF IsTrunc (ProcSym) |
| 8102 |
THEN |
| 8103 |
BuildTruncFunction (ProcSym, ConstExpr) |
| 8104 |
ELSIF IsFloat (ProcSym) |
| 8105 |
THEN |
| 8106 |
BuildFloatFunction (ProcSym, ConstExpr) |
| 8107 |
ELSIF ProcSym = Min |
| 8108 |
THEN |
| 8109 |
BuildMinFunction |
| 8110 |
ELSIF ProcSym = Max |
| 8111 |
THEN |
| 8112 |
BuildMaxFunction |
| 8113 |
ELSIF ProcSym = AddAdr |
| 8114 |
THEN |
| 8115 |
BuildAddAdrFunction (ProcSym, ConstExpr) |
| 8116 |
ELSIF ProcSym = SubAdr |
| 8117 |
THEN |
| 8118 |
BuildSubAdrFunction (ProcSym, ConstExpr) |
| 8119 |
ELSIF ProcSym = DifAdr |
| 8120 |
THEN |
| 8121 |
BuildDifAdrFunction (ProcSym, ConstExpr) |
| 8122 |
ELSIF ProcSym = Cast |
| 8123 |
THEN |
| 8124 |
BuildCastFunction (ProcSym, ConstExpr) |
| 8125 |
ELSIF ProcSym = Shift |
| 8126 |
THEN |
| 8127 |
BuildShiftFunction |
| 8128 |
ELSIF ProcSym = Rotate |
| 8129 |
THEN |
| 8130 |
BuildRotateFunction |
| 8131 |
ELSIF ProcSym = MakeAdr |
| 8132 |
THEN |
| 8133 |
BuildMakeAdrFunction |
| 8134 |
ELSIF ProcSym = Re |
| 8135 |
THEN |
| 8136 |
BuildReFunction (ProcSym, ConstExpr) |
| 8137 |
ELSIF ProcSym = Im |
| 8138 |
THEN |
| 8139 |
BuildImFunction (ProcSym, ConstExpr) |
| 8140 |
ELSIF ProcSym = Cmplx |
| 8141 |
THEN |
| 8142 |
BuildCmplxFunction (ProcSym, ConstExpr) |
| 8143 |
ELSE |
| 8144 |
InternalError ('pseudo function not implemented yet') |
| 8145 |
END |
| 8146 |
END BuildPseudoFunctionCall ; |
| 8147 |
|
| 8148 |
|
| 8149 |
(* |
| 8150 |
BuildAddAdrFunction - builds the pseudo procedure call ADDADR. |
| 8151 |
|
| 8152 |
PROCEDURE ADDADR (addr: ADDRESS; offset: CARDINAL): ADDRESS ; |
| 8153 |
|
| 8154 |
Which returns address given by (addr + offset), |
| 8155 |
[ the standard says that it _may_ |
| 8156 |
"raise an exception if this address is not valid." |
| 8157 |
currently we do not generate any exception code ] |
| 8158 |
|
| 8159 |
The Stack: |
| 8160 |
|
| 8161 |
Entry Exit |
| 8162 |
|
| 8163 |
Ptr -> |
| 8164 |
+----------------+ |
| 8165 |
| NoOfParam | |
| 8166 |
|----------------| |
| 8167 |
| Param 1 | |
| 8168 |
|----------------| |
| 8169 |
| Param 2 | <- Ptr |
| 8170 |
|----------------| +------------+ |
| 8171 |
| ProcSym | Type | | ReturnVar | |
| 8172 |
|----------------| |------------| |
| 8173 |
*) |
| 8174 |
|
| 8175 |
PROCEDURE BuildAddAdrFunction (ProcSym: CARDINAL; ConstExpr: BOOLEAN) ; |
| 8176 |
VAR |
| 8177 |
combinedtok, |
| 8178 |
functok, |
| 8179 |
vartok, |
| 8180 |
optok : CARDINAL ; |
| 8181 |
opa, |
| 8182 |
ReturnVar, |
| 8183 |
NoOfParam, |
| 8184 |
OperandSym, |
| 8185 |
VarSym : CARDINAL ; |
| 8186 |
BEGIN |
| 8187 |
PopT (NoOfParam) ; |
| 8188 |
functok := OperandTtok (NoOfParam + 1) ; |
| 8189 |
IF NoOfParam=2 |
| 8190 |
THEN |
| 8191 |
VarSym := OperandT (2) ; |
| 8192 |
vartok := OperandTok (2) ; |
| 8193 |
OperandSym := OperandT (1) ; |
| 8194 |
optok := OperandTok (1) ; |
| 8195 |
combinedtok := MakeVirtual2Tok (functok, optok) ; |
| 8196 |
PopN (NoOfParam + 1) ; |
| 8197 |
IF ConstExprError (ProcSym, VarSym, vartok, ConstExpr) OR |
| 8198 |
ConstExprError (ProcSym, OperandSym, optok, ConstExpr) |
| 8199 |
THEN |
| 8200 |
(* Fake return result. *) |
| 8201 |
PushTFtok (MakeConstLit (combinedtok, MakeKey('0'), Address), |
| 8202 |
Address, combinedtok) |
| 8203 |
ELSIF IsVar (VarSym) |
| 8204 |
THEN |
| 8205 |
IF IsReallyPointer (VarSym) OR (GetSType (VarSym) = Address) |
| 8206 |
THEN |
| 8207 |
ReturnVar := MakeTemporary (combinedtok, RightValue) ; |
| 8208 |
PutVar (ReturnVar, Address) ; |
| 8209 |
opa := ConvertToAddress (optok, DereferenceLValue (optok, OperandSym)) ; |
| 8210 |
GenQuadOtok (combinedtok, AddOp, ReturnVar, VarSym, opa, TRUE, |
| 8211 |
combinedtok, combinedtok, combinedtok) ; |
| 8212 |
PushTFtok (ReturnVar, Address, combinedtok) |
| 8213 |
ELSE |
| 8214 |
MetaErrorT1 (functok, |
| 8215 |
'the first parameter to ADDADR {%1Ea} must be a variable of type ADDRESS or a {%EkPOINTER}, rather than a {%1Etsd}', |
| 8216 |
VarSym) ; |
| 8217 |
PushTFtok (MakeConstLit (combinedtok, MakeKey('0'), Address), Address, combinedtok) |
| 8218 |
END |
| 8219 |
ELSE |
| 8220 |
MetaErrorT0 (functok, '{%E}SYSTEM procedure ADDADR expects a variable of type ADDRESS or POINTER as its first parameter') ; |
| 8221 |
PushTFtok (MakeConstLit (combinedtok, MakeKey('0'), Address), Address, combinedtok) |
| 8222 |
END |
| 8223 |
ELSE |
| 8224 |
MetaErrorT0 (functok, |
| 8225 |
'{%E}SYSTEM procedure {%EkADDADR} expects 2 parameters') ; |
| 8226 |
PopN (NoOfParam+1) ; |
| 8227 |
PushTFtok (MakeConstLit (functok, MakeKey('0'), Address), Address, functok) |
| 8228 |
END |
| 8229 |
END BuildAddAdrFunction ; |
| 8230 |
|
| 8231 |
|
| 8232 |
(* |
| 8233 |
BuildSubAdrFunction - builds the pseudo procedure call ADDADR. |
| 8234 |
|
| 8235 |
PROCEDURE SUBADR (addr: ADDRESS; offset: CARDINAL): ADDRESS ; |
| 8236 |
|
| 8237 |
Which returns address given by (addr - offset), |
| 8238 |
[ the standard says that it _may_ |
| 8239 |
"raise an exception if this address is not valid." |
| 8240 |
currently we do not generate any exception code ] |
| 8241 |
|
| 8242 |
The Stack: |
| 8243 |
|
| 8244 |
Entry Exit |
| 8245 |
|
| 8246 |
Ptr -> |
| 8247 |
+----------------+ |
| 8248 |
| NoOfParam | |
| 8249 |
|----------------| |
| 8250 |
| Param 1 | |
| 8251 |
|----------------| |
| 8252 |
| Param 2 | <- Ptr |
| 8253 |
|----------------| +------------+ |
| 8254 |
| ProcSym | Type | | ReturnVar | |
| 8255 |
|----------------| |------------| |
| 8256 |
*) |
| 8257 |
|
| 8258 |
PROCEDURE BuildSubAdrFunction (ProcSym: CARDINAL; ConstExpr: BOOLEAN) ; |
| 8259 |
VAR |
| 8260 |
functok, |
| 8261 |
combinedtok, |
| 8262 |
optok, |
| 8263 |
vartok : CARDINAL ; |
| 8264 |
ReturnVar, |
| 8265 |
NoOfParam, |
| 8266 |
OperandSym, |
| 8267 |
opa, |
| 8268 |
VarSym : CARDINAL ; |
| 8269 |
BEGIN |
| 8270 |
PopT (NoOfParam) ; |
| 8271 |
functok := OperandTtok (NoOfParam + 1) ; |
| 8272 |
IF NoOfParam = 2 |
| 8273 |
THEN |
| 8274 |
optok := OperandTok (1) ; |
| 8275 |
OperandSym := OperandT (1) ; |
| 8276 |
VarSym := OperandT (2) ; |
| 8277 |
vartok := OperandTok (2) ; |
| 8278 |
combinedtok := MakeVirtualTok (functok, functok, optok) ; |
| 8279 |
PopN (NoOfParam + 1) ; |
| 8280 |
IF ConstExprError (ProcSym, VarSym, vartok, ConstExpr) OR |
| 8281 |
ConstExprError (ProcSym, OperandSym, optok, ConstExpr) |
| 8282 |
THEN |
| 8283 |
(* Fake return result. *) |
| 8284 |
PushTFtok (MakeConstLit (combinedtok, MakeKey('0'), Address), |
| 8285 |
Address, combinedtok) |
| 8286 |
ELSIF IsVar (VarSym) |
| 8287 |
THEN |
| 8288 |
IF IsReallyPointer (VarSym) OR (GetSType (VarSym) = Address) |
| 8289 |
THEN |
| 8290 |
ReturnVar := MakeTemporary (combinedtok, RightValue) ; |
| 8291 |
PutVar (ReturnVar, Address) ; |
| 8292 |
opa := ConvertToAddress (optok, DereferenceLValue (optok, OperandSym)) ; |
| 8293 |
GenQuadOtok (combinedtok, SubOp, ReturnVar, VarSym, opa, TRUE, |
| 8294 |
combinedtok, combinedtok, combinedtok) ; |
| 8295 |
PushTFtok (ReturnVar, Address, combinedtok) |
| 8296 |
ELSE |
| 8297 |
MetaErrorT1 (functok, |
| 8298 |
'the first parameter to {%EkSUBADR} {%1Ea} must be a variable of type ADDRESS or a {%EkPOINTER}, rather than a {%1Etsd}', |
| 8299 |
VarSym) ; |
| 8300 |
PushTFtok (MakeConstLit (vartok, MakeKey('0'), Address), Address, vartok) |
| 8301 |
END |
| 8302 |
ELSE |
| 8303 |
combinedtok := MakeVirtualTok (functok, functok, optok) ; |
| 8304 |
MetaErrorT0 (combinedtok, |
| 8305 |
'{%E}SYSTEM procedure {%EkSUBADR} expects a variable of type ADDRESS or POINTER as its first parameter') ; |
| 8306 |
PushTFtok (MakeConstLit (combinedtok, MakeKey ('0'), Address), Address, combinedtok) |
| 8307 |
END |
| 8308 |
ELSE |
| 8309 |
MetaErrorT0 (functok, |
| 8310 |
'{%E}SYSTEM procedure {%EkSUBADR} expects 2 parameters') ; |
| 8311 |
PopN (NoOfParam+1) ; |
| 8312 |
PushTFtok (MakeConstLit (functok, MakeKey('0'), Address), Address, functok) |
| 8313 |
END |
| 8314 |
END BuildSubAdrFunction ; |
| 8315 |
|
| 8316 |
|
| 8317 |
(* |
| 8318 |
BuildDifAdrFunction - builds the pseudo procedure call DIFADR. |
| 8319 |
|
| 8320 |
PROCEDURE DIFADR (addr1, addr2: ADDRESS): INTEGER ; |
| 8321 |
|
| 8322 |
Which returns address given by (addr1 - addr2), |
| 8323 |
[ the standard says that it _may_ |
| 8324 |
"raise an exception if this address is invalid or |
| 8325 |
address space is non-contiguous." |
| 8326 |
currently we do not generate any exception code ] |
| 8327 |
|
| 8328 |
The Stack: |
| 8329 |
|
| 8330 |
Entry Exit |
| 8331 |
|
| 8332 |
Ptr -> |
| 8333 |
+----------------+ |
| 8334 |
| NoOfParam | |
| 8335 |
|----------------| |
| 8336 |
| Param 1 | |
| 8337 |
|----------------| |
| 8338 |
| Param 2 | <- Ptr |
| 8339 |
|----------------| +------------+ |
| 8340 |
| ProcSym | Type | | ReturnVar | |
| 8341 |
|----------------| |------------| |
| 8342 |
*) |
| 8343 |
|
| 8344 |
PROCEDURE BuildDifAdrFunction (ProcSym: CARDINAL; ConstExpr: BOOLEAN) ; |
| 8345 |
VAR |
| 8346 |
functok, |
| 8347 |
optok, |
| 8348 |
vartok, |
| 8349 |
combinedtok: CARDINAL ; |
| 8350 |
TempVar, |
| 8351 |
NoOfParam, |
| 8352 |
OperandSym, |
| 8353 |
opa, |
| 8354 |
VarSym : CARDINAL ; |
| 8355 |
BEGIN |
| 8356 |
PopT (NoOfParam) ; |
| 8357 |
functok := OperandTtok (NoOfParam + 1) ; |
| 8358 |
IF NoOfParam >= 1 |
| 8359 |
THEN |
| 8360 |
OperandSym := OperandT (1) ; |
| 8361 |
optok := OperandTok (1) |
| 8362 |
ELSE |
| 8363 |
optok := functok |
| 8364 |
END ; |
| 8365 |
IF NoOfParam = 2 |
| 8366 |
THEN |
| 8367 |
VarSym := OperandT (2) ; |
| 8368 |
vartok := OperandTok (2) ; |
| 8369 |
combinedtok := MakeVirtualTok (functok, functok, optok) ; |
| 8370 |
PopN (NoOfParam + 1) ; |
| 8371 |
IF ConstExprError (ProcSym, VarSym, vartok, ConstExpr) OR |
| 8372 |
ConstExprError (ProcSym, OperandSym, optok, ConstExpr) |
| 8373 |
THEN |
| 8374 |
(* Fake return result. *) |
| 8375 |
PushTFtok (MakeConstLit (combinedtok, MakeKey('0'), Integer), |
| 8376 |
Integer, combinedtok) |
| 8377 |
ELSIF IsVar (VarSym) |
| 8378 |
THEN |
| 8379 |
IF IsReallyPointer (VarSym) OR (GetSType (VarSym) = Address) |
| 8380 |
THEN |
| 8381 |
IF IsReallyPointer (OperandSym) OR (GetSType (OperandSym) = Address) |
| 8382 |
THEN |
| 8383 |
TempVar := MakeTemporary (vartok, RightValue) ; |
| 8384 |
PutVar (TempVar, Address) ; |
| 8385 |
opa := ConvertToAddress (optok, DereferenceLValue (optok, OperandSym)) ; |
| 8386 |
GenQuadOtok (combinedtok, SubOp, TempVar, VarSym, opa, TRUE, |
| 8387 |
combinedtok, combinedtok, combinedtok) ; |
| 8388 |
(* |
| 8389 |
Build macro: CONVERT( INTEGER, TempVar ) |
| 8390 |
*) |
| 8391 |
PushTFtok (Convert, NulSym, functok) ; |
| 8392 |
PushTtok (Integer, functok) ; |
| 8393 |
PushTtok (TempVar, vartok) ; |
| 8394 |
PushT (2) ; (* Two parameters *) |
| 8395 |
BuildConvertFunction (Convert, ConstExpr) |
| 8396 |
ELSE |
| 8397 |
MetaError1 ('the second parameter to {%EkDIFADR} {%1Ea} must be a variable of type ADDRESS or a {%EkPOINTER}, rather than a {%1Etsd}', |
| 8398 |
OperandSym) ; |
| 8399 |
PushTFtok (MakeConstLit (combinedtok, MakeKey ('0'), Integer), Integer, combinedtok) |
| 8400 |
END |
| 8401 |
ELSE |
| 8402 |
MetaErrorT1 (vartok, |
| 8403 |
'the first parameter to {%EkDIFADR} {%1Ea} must be a variable of type ADDRESS or a {%EkPOINTER}, rather than a {%1Etsd}', |
| 8404 |
VarSym) ; |
| 8405 |
PushTFtok (MakeConstLit (combinedtok, MakeKey ('0'), Integer), Integer, combinedtok) |
| 8406 |
END |
| 8407 |
ELSE |
| 8408 |
MetaError0 ('{%E}SYSTEM procedure {%EkDIFADR} expects a variable of type ADDRESS or POINTER as its first parameter') ; |
| 8409 |
PushTFtok (MakeConstLit (combinedtok, MakeKey('0'), Integer), Integer, combinedtok) |
| 8410 |
END |
| 8411 |
ELSE |
| 8412 |
combinedtok := MakeVirtual2Tok (functok, optok) ; |
| 8413 |
MetaErrorT0 (combinedtok, '{%E}SYSTEM procedure {%EkDIFADR} expects 2 parameters') ; |
| 8414 |
PopN (NoOfParam+1) ; |
| 8415 |
PushTFtok (MakeConstLit (combinedtok, MakeKey('0'), Integer), Integer, combinedtok) |
| 8416 |
END |
| 8417 |
END BuildDifAdrFunction ; |
| 8418 |
|
| 8419 |
|
| 8420 |
(* |
| 8421 |
BuildHighFunction - checks the stack in preparation for generating |
| 8422 |
quadruples which perform HIGH. |
| 8423 |
This procedure does not alter the stack but |
| 8424 |
determines whether, a, in HIGH(a) is an ArraySym |
| 8425 |
or UnboundedSym. |
| 8426 |
Both cases are different and appropriate quadruple |
| 8427 |
generating routines are called. |
| 8428 |
|
| 8429 |
The Stack: |
| 8430 |
|
| 8431 |
|
| 8432 |
Entry Exit |
| 8433 |
|
| 8434 |
Ptr -> |
| 8435 |
+----------------+ |
| 8436 |
| NoOfParam | |
| 8437 |
|----------------| |
| 8438 |
| Param 1 | |
| 8439 |
|----------------| |
| 8440 |
| Param 2 | |
| 8441 |
|----------------| |
| 8442 |
. . |
| 8443 |
. . |
| 8444 |
. . |
| 8445 |
|----------------| |
| 8446 |
| Param # | <- Ptr |
| 8447 |
|----------------| +------------+ |
| 8448 |
| ProcSym | Type | | ReturnVar | |
| 8449 |
|----------------| |------------| |
| 8450 |
|
| 8451 |
*) |
| 8452 |
|
| 8453 |
PROCEDURE BuildHighFunction ; |
| 8454 |
VAR |
| 8455 |
functok, |
| 8456 |
combinedtok, |
| 8457 |
paramtok : CARDINAL ; |
| 8458 |
ProcSym, |
| 8459 |
Type, |
| 8460 |
NoOfParam, |
| 8461 |
Param : CARDINAL ; |
| 8462 |
BEGIN |
| 8463 |
PopT (NoOfParam) ; |
| 8464 |
ProcSym := OperandT (NoOfParam+1) ; |
| 8465 |
functok := OperandTok (NoOfParam + 1) ; |
| 8466 |
BuildSizeCheckEnd (ProcSym) ; (* quadruple generation now on *) |
| 8467 |
IF NoOfParam = 1 |
| 8468 |
THEN |
| 8469 |
Param := OperandT (1) ; |
| 8470 |
paramtok := OperandTok (1) ; |
| 8471 |
combinedtok := MakeVirtualTok (paramtok, functok, paramtok) ; |
| 8472 |
Type := GetDType (Param) ; |
| 8473 |
(* Restore stack to original form *) |
| 8474 |
PushT (NoOfParam) ; |
| 8475 |
IF (NOT IsVar(Param)) AND (NOT IsConstString(Param)) AND (NOT IsConst(Param)) |
| 8476 |
THEN |
| 8477 |
(* we cannot test for IsConst(Param) AND (GetSType(Param)=Char) as the type might not be assigned yet *) |
| 8478 |
MetaError1 ('base procedure {%EkHIGH} expects a variable or string constant as its parameter {%1d:rather than {%1d}} {%1asa}', Param) |
| 8479 |
ELSIF (Type # NulSym) AND IsUnbounded(Type) |
| 8480 |
THEN |
| 8481 |
BuildHighFromUnbounded (combinedtok) |
| 8482 |
ELSE |
| 8483 |
BuildConstHighFromSym (combinedtok) |
| 8484 |
END |
| 8485 |
ELSE |
| 8486 |
MetaError0 ('base procedure {%EkHIGH} requires one parameter') ; |
| 8487 |
PopN (2) ; |
| 8488 |
PushTFtok (MakeConstLit (functok, MakeKey ('0'), Cardinal), Cardinal, functok) |
| 8489 |
END |
| 8490 |
END BuildHighFunction ; |
| 8491 |
|
| 8492 |
|
| 8493 |
(* |
| 8494 |
BuildConstHighFromSym - builds the pseudo function HIGH from an Sym. |
| 8495 |
Sym is a constant or an array which has constant bounds |
| 8496 |
and therefore it can be calculated at compile time. |
| 8497 |
|
| 8498 |
The Stack: |
| 8499 |
|
| 8500 |
|
| 8501 |
Entry Exit |
| 8502 |
|
| 8503 |
Ptr -> |
| 8504 |
+----------------+ |
| 8505 |
| NoOfParam | |
| 8506 |
|----------------| |
| 8507 |
| Param 1 | |
| 8508 |
|----------------| |
| 8509 |
| Param 2 | |
| 8510 |
|----------------| |
| 8511 |
. . |
| 8512 |
. . |
| 8513 |
. . |
| 8514 |
|----------------| |
| 8515 |
| Param # | <- Ptr |
| 8516 |
|----------------| +------------+ |
| 8517 |
| ProcSym | Type | | ReturnVar | |
| 8518 |
|----------------| |------------| |
| 8519 |
*) |
| 8520 |
|
| 8521 |
PROCEDURE BuildConstHighFromSym (tok: CARDINAL) ; |
| 8522 |
VAR |
| 8523 |
NoOfParam, |
| 8524 |
ReturnVar: CARDINAL ; |
| 8525 |
BEGIN |
| 8526 |
PopT (NoOfParam) ; |
| 8527 |
ReturnVar := MakeTemporary (tok, ImmediateValue) ; |
| 8528 |
PutConst (ReturnVar, Cardinal) ; |
| 8529 |
GenHigh (tok, ReturnVar, 1, OperandT (1)) ; |
| 8530 |
PopN (NoOfParam+1) ; |
| 8531 |
PushTtok (ReturnVar, tok) |
| 8532 |
END BuildConstHighFromSym ; |
| 8533 |
|
| 8534 |
|
| 8535 |
(* |
| 8536 |
BuildHighFromUnbounded - builds the pseudo function HIGH from an |
| 8537 |
UnboundedSym. |
| 8538 |
|
| 8539 |
The Stack: |
| 8540 |
|
| 8541 |
|
| 8542 |
Entry Exit |
| 8543 |
|
| 8544 |
Ptr -> |
| 8545 |
+----------------+ |
| 8546 |
| NoOfParam | |
| 8547 |
|----------------| |
| 8548 |
| Param # | <- Ptr |
| 8549 |
|----------------| +------------+ |
| 8550 |
| ProcSym | Type | | ReturnVar | |
| 8551 |
|----------------| |------------| |
| 8552 |
|
| 8553 |
*) |
| 8554 |
|
| 8555 |
PROCEDURE BuildHighFromUnbounded (tok: CARDINAL) ; |
| 8556 |
VAR |
| 8557 |
Dim, |
| 8558 |
NoOfParam, |
| 8559 |
ReturnVar: CARDINAL ; |
| 8560 |
BEGIN |
| 8561 |
PopT (NoOfParam) ; |
| 8562 |
Assert (NoOfParam=1) ; |
| 8563 |
ReturnVar := MakeTemporary (tok, RightValue) ; |
| 8564 |
PutVar (ReturnVar, Cardinal) ; |
| 8565 |
Dim := OperandD (1) ; |
| 8566 |
INC (Dim) ; |
| 8567 |
IF Dim > 1 |
| 8568 |
THEN |
| 8569 |
GenHigh (tok, ReturnVar, Dim, OperandA(1)) |
| 8570 |
ELSE |
| 8571 |
GenHigh (tok, ReturnVar, Dim, OperandT(1)) |
| 8572 |
END ; |
| 8573 |
PopN (2) ; |
| 8574 |
PushTFtok (ReturnVar, GetSType(ReturnVar), tok) |
| 8575 |
END BuildHighFromUnbounded ; |
| 8576 |
|
| 8577 |
|
| 8578 |
(* |
| 8579 |
GetQualidentImport - returns the symbol as if it were qualified from, module.n. |
| 8580 |
This is used to reference runtime support procedures and an |
| 8581 |
error is generated if the symbol cannot be obtained. |
| 8582 |
*) |
| 8583 |
|
| 8584 |
PROCEDURE GetQualidentImport (tokno: CARDINAL; |
| 8585 |
n: Name; module: Name) : CARDINAL ; |
| 8586 |
VAR |
| 8587 |
ModSym: CARDINAL ; |
| 8588 |
BEGIN |
| 8589 |
ModSym := MakeDefinitionSource (tokno, module) ; |
| 8590 |
IF ModSym=NulSym |
| 8591 |
THEN |
| 8592 |
MetaErrorNT2 (tokno, |
| 8593 |
'module %a cannot be found and is needed to import %a', module, n) ; |
| 8594 |
FlushErrors ; |
| 8595 |
RETURN NulSym |
| 8596 |
END ; |
| 8597 |
Assert(IsDefImp(ModSym)) ; |
| 8598 |
IF (GetExported (tokno, ModSym, n)=NulSym) OR IsUnknown (GetExported (tokno, ModSym, n)) |
| 8599 |
THEN |
| 8600 |
MetaErrorN2 ('module %a does not export procedure %a which is a necessary component of the runtime system, hint check the path and library/language variant', |
| 8601 |
module, n) ; |
| 8602 |
FlushErrors ; |
| 8603 |
RETURN NulSym |
| 8604 |
END ; |
| 8605 |
RETURN GetExported (tokno, MakeDefinitionSource (tokno, module), n) |
| 8606 |
END GetQualidentImport ; |
| 8607 |
|
| 8608 |
|
| 8609 |
(* |
| 8610 |
ConstExprError - return TRUE if a constant expression is being built and Var is a variable. |
| 8611 |
*) |
| 8612 |
|
| 8613 |
PROCEDURE ConstExprError (Func, Var: CARDINAL; optok: CARDINAL; ConstExpr: BOOLEAN) : BOOLEAN ; |
| 8614 |
BEGIN |
| 8615 |
IF ConstExpr AND IsVar (Var) |
| 8616 |
THEN |
| 8617 |
MetaErrorT2 (optok, |
| 8618 |
'the procedure function {%1Ea} is being called from within a constant expression and therefore the parameter {%2a} must be a constant, seen a {%2da}', |
| 8619 |
Func, Var) ; |
| 8620 |
RETURN TRUE |
| 8621 |
ELSE |
| 8622 |
RETURN FALSE |
| 8623 |
END |
| 8624 |
END ConstExprError ; |
| 8625 |
|
| 8626 |
|
| 8627 |
(* |
| 8628 |
DeferMakeLengthConst - creates a constant which contains the length of string, sym. |
| 8629 |
*) |
| 8630 |
|
| 8631 |
PROCEDURE DeferMakeLengthConst (tok: CARDINAL; sym: CARDINAL) : CARDINAL ; |
| 8632 |
VAR |
| 8633 |
const: CARDINAL ; |
| 8634 |
BEGIN |
| 8635 |
const := MakeTemporary (tok, ImmediateValue) ; |
| 8636 |
PutVar (const, ZType) ; |
| 8637 |
GenQuadO (tok, StringLengthOp, const, 0, sym, FALSE) ; |
| 8638 |
RETURN const |
| 8639 |
END DeferMakeLengthConst ; |
| 8640 |
|
| 8641 |
|
| 8642 |
(* |
| 8643 |
BuildLengthFunction - builds the inline standard function LENGTH. |
| 8644 |
|
| 8645 |
The Stack: |
| 8646 |
|
| 8647 |
|
| 8648 |
Entry Exit |
| 8649 |
|
| 8650 |
Ptr -> |
| 8651 |
+----------------+ |
| 8652 |
| NoOfParam | |
| 8653 |
|----------------| |
| 8654 |
| Param 1 | <- Ptr |
| 8655 |
|----------------| +------------+ |
| 8656 |
| ProcSym | Type | | ReturnVar | |
| 8657 |
|----------------| |------------| |
| 8658 |
|
| 8659 |
*) |
| 8660 |
|
| 8661 |
PROCEDURE BuildLengthFunction (Function: CARDINAL; ConstExpr: BOOLEAN) ; |
| 8662 |
VAR |
| 8663 |
combinedtok, |
| 8664 |
paramtok, |
| 8665 |
functok : CARDINAL ; |
| 8666 |
ProcSym, |
| 8667 |
Type, |
| 8668 |
NoOfParam, |
| 8669 |
Param, |
| 8670 |
ReturnVar : CARDINAL ; |
| 8671 |
BEGIN |
| 8672 |
PopT (NoOfParam) ; |
| 8673 |
Param := OperandT (1) ; |
| 8674 |
paramtok := OperandTok (1) ; |
| 8675 |
functok := OperandTok (NoOfParam + 1) ; |
| 8676 |
(* Restore stack to origional form. *) |
| 8677 |
PushT (NoOfParam) ; |
| 8678 |
Type := GetSType (Param) ; (* Get the type from the symbol, not the stack. *) |
| 8679 |
IF NoOfParam # 1 |
| 8680 |
THEN |
| 8681 |
MetaErrorT1 (functok, 'base procedure {%1EkLENGTH} expects 1 parameter, seen {%1n} parameters', NoOfParam) |
| 8682 |
END ; |
| 8683 |
IF NoOfParam >= 1 |
| 8684 |
THEN |
| 8685 |
combinedtok := MakeVirtual2Tok (functok, paramtok) ; |
| 8686 |
IF IsConst (Param) AND (GetSType (Param) = Char) |
| 8687 |
THEN |
| 8688 |
PopT (NoOfParam) ; |
| 8689 |
PopN (NoOfParam + 1) ; |
| 8690 |
ReturnVar := MakeConstLit (combinedtok, MakeKey ('1'), Cardinal) ; |
| 8691 |
PushTtok (ReturnVar, combinedtok) |
| 8692 |
ELSIF IsConstString (Param) |
| 8693 |
THEN |
| 8694 |
PopT (NoOfParam) ; |
| 8695 |
ReturnVar := DeferMakeLengthConst (combinedtok, OperandT (1)) ; |
| 8696 |
PopN (NoOfParam + 1) ; |
| 8697 |
PushTtok (ReturnVar, combinedtok) |
| 8698 |
ELSE |
| 8699 |
ProcSym := GetQualidentImport (functok, MakeKey ('Length'), MakeKey ('M2RTS')) ; |
| 8700 |
IF (ProcSym # NulSym) AND IsProcedure (ProcSym) |
| 8701 |
THEN |
| 8702 |
PopT (NoOfParam) ; |
| 8703 |
IF IsConst (Param) |
| 8704 |
THEN |
| 8705 |
(* This can be folded in M2GenGCC. *) |
| 8706 |
ReturnVar := MakeTemporary (combinedtok, ImmediateValue) ; |
| 8707 |
PutVar (ReturnVar, Cardinal) ; |
| 8708 |
GenQuad (StandardFunctionOp, ReturnVar, ProcSym, Param) ; |
| 8709 |
PopN (NoOfParam + 1) ; |
| 8710 |
PushTtok (ReturnVar, combinedtok) |
| 8711 |
ELSIF ConstExprError (Function, Param, paramtok, ConstExpr) |
| 8712 |
THEN |
| 8713 |
(* Fake a result as we have detected and reported an error. *) |
| 8714 |
PopN (NoOfParam + 1) ; |
| 8715 |
ReturnVar := MakeConstLit (combinedtok, MakeKey ('1'), Cardinal) ; |
| 8716 |
PushTtok (ReturnVar, combinedtok) |
| 8717 |
ELSE |
| 8718 |
(* We must resolve this at runtime or in the GCC optimizer. *) |
| 8719 |
PopTF (Param, Type); |
| 8720 |
PopN (NoOfParam) ; |
| 8721 |
PushTtok (ProcSym, functok) ; |
| 8722 |
PushTFtok (Param, Type, paramtok) ; |
| 8723 |
PushT (NoOfParam) ; |
| 8724 |
BuildRealFunctionCall (functok, FALSE) |
| 8725 |
END |
| 8726 |
ELSE |
| 8727 |
PopT (NoOfParam) ; |
| 8728 |
PopN (NoOfParam + 1) ; |
| 8729 |
PushTtok (MakeConstLit (combinedtok, MakeKey ('0'), Cardinal), combinedtok) ; |
| 8730 |
MetaErrorT0 (functok, 'no procedure Length found for substitution to the standard function {%1EkLENGTH} which is required to calculate non constant string lengths') |
| 8731 |
END |
| 8732 |
END |
| 8733 |
ELSE |
| 8734 |
(* NoOfParam is _very_ wrong, we flush all outstanding errors *) |
| 8735 |
FlushErrors |
| 8736 |
END |
| 8737 |
END BuildLengthFunction ; |
| 8738 |
|
| 8739 |
|
| 8740 |
(* |
| 8741 |
BuildOddFunction - builds the pseudo procedure call ODD. |
| 8742 |
This procedure is actually a "macro" for |
| 8743 |
ORD(x) --> VAL(BOOLEAN, x MOD 2) |
| 8744 |
However we cannot push tokens back onto the input stack |
| 8745 |
because the compiler is currently building a function |
| 8746 |
call and expecting a ReturnVar on the stack. |
| 8747 |
Hence we manipulate the stack and call |
| 8748 |
BuildConvertFunction. |
| 8749 |
|
| 8750 |
The Stack: |
| 8751 |
|
| 8752 |
|
| 8753 |
Entry Exit |
| 8754 |
|
| 8755 |
Ptr -> |
| 8756 |
+----------------+ |
| 8757 |
| NoOfParam | |
| 8758 |
|----------------| |
| 8759 |
| Param 1 | |
| 8760 |
|----------------| |
| 8761 |
| Param 2 | |
| 8762 |
|----------------| |
| 8763 |
. . |
| 8764 |
. . |
| 8765 |
. . |
| 8766 |
|----------------| |
| 8767 |
| Param # | |
| 8768 |
|----------------| |
| 8769 |
| ProcSym | Type | Empty |
| 8770 |
|----------------| |
| 8771 |
*) |
| 8772 |
|
| 8773 |
PROCEDURE BuildOddFunction (ProcSym: CARDINAL; ConstExpr: BOOLEAN) ; |
| 8774 |
VAR |
| 8775 |
combinedtok, |
| 8776 |
optok, |
| 8777 |
functok : CARDINAL ; |
| 8778 |
NoOfParam, |
| 8779 |
Res, Var : CARDINAL ; |
| 8780 |
BEGIN |
| 8781 |
PopT (NoOfParam) ; |
| 8782 |
functok := OperandTok (NoOfParam + 1) ; |
| 8783 |
IF NoOfParam=1 |
| 8784 |
THEN |
| 8785 |
Var := OperandT (1) ; |
| 8786 |
optok := OperandTok (1) ; |
| 8787 |
combinedtok := MakeVirtualTok (functok, functok, optok) ; |
| 8788 |
IF ConstExprError (ProcSym, Var, optok, ConstExpr) |
| 8789 |
THEN |
| 8790 |
(* Nothing to do. *) |
| 8791 |
PushTtok (False, combinedtok) |
| 8792 |
ELSIF IsVar(Var) OR IsConst(Var) |
| 8793 |
THEN |
| 8794 |
PopN (NoOfParam + 1) ; |
| 8795 |
(* |
| 8796 |
Build macro: VAL(BOOLEAN, (x MOD 2)) |
| 8797 |
*) |
| 8798 |
|
| 8799 |
(* compute (x MOD 2) *) |
| 8800 |
PushTFtok (Var, GetSType (Var), optok) ; |
| 8801 |
PushT (ModTok) ; |
| 8802 |
PushTFtok (MakeConstLit (optok, MakeKey ('2'), ZType), ZType, optok) ; |
| 8803 |
BuildBinaryOp ; |
| 8804 |
PopT (Res) ; |
| 8805 |
|
| 8806 |
(* compute IF ...=0 *) |
| 8807 |
PushTtok (Res, optok) ; |
| 8808 |
PushT (EqualTok) ; |
| 8809 |
PushTFtok (MakeConstLit (optok, MakeKey ('0'), ZType), ZType, optok) ; |
| 8810 |
BuildRelOp (combinedtok) ; |
| 8811 |
BuildThenIf ; |
| 8812 |
|
| 8813 |
Res := MakeTemporary (combinedtok, RightValue) ; |
| 8814 |
PutVar (Res, Boolean) ; |
| 8815 |
|
| 8816 |
PushTtok (Res, combinedtok) ; |
| 8817 |
PushTtok (False, combinedtok) ; |
| 8818 |
BuildAssignment (combinedtok) ; |
| 8819 |
BuildElse ; |
| 8820 |
PushTtok (Res, combinedtok) ; |
| 8821 |
PushTtok (True, combinedtok) ; |
| 8822 |
BuildAssignment (combinedtok) ; |
| 8823 |
BuildEndIf ; |
| 8824 |
|
| 8825 |
PushTtok (Res, combinedtok) |
| 8826 |
ELSE |
| 8827 |
MetaErrorT1 (optok, |
| 8828 |
'the parameter to {%1EkODD} must be a variable or constant, seen {%1ad}', |
| 8829 |
Var) ; |
| 8830 |
PushTtok (False, combinedtok) |
| 8831 |
END |
| 8832 |
ELSE |
| 8833 |
MetaErrorT1 (functok, |
| 8834 |
'the pseudo procedure {%E1kODD} only has one parameter, seen {%1n} parameters', |
| 8835 |
NoOfParam) ; |
| 8836 |
PushTtok (False, functok) |
| 8837 |
END |
| 8838 |
END BuildOddFunction ; |
| 8839 |
|
| 8840 |
|
| 8841 |
(* |
| 8842 |
BuildAbsFunction - builds a call to the standard function ABS. |
| 8843 |
|
| 8844 |
We cannot implement it as a macro or inline an |
| 8845 |
IF THEN statement as the IF THEN ELSE requires |
| 8846 |
we write the value to the same variable (or constant) |
| 8847 |
twice. The macro implementation will fail as |
| 8848 |
the compiler maybe building a function |
| 8849 |
call and expecting a ReturnVar on the stack. |
| 8850 |
The only method to implement this is to pass it to the |
| 8851 |
gcc backend. |
| 8852 |
|
| 8853 |
The Stack: |
| 8854 |
|
| 8855 |
|
| 8856 |
Entry Exit |
| 8857 |
|
| 8858 |
Ptr -> |
| 8859 |
+----------------+ |
| 8860 |
| NoOfParam | |
| 8861 |
|----------------| |
| 8862 |
| Param 1 | |
| 8863 |
|----------------| |
| 8864 |
| Param 2 | |
| 8865 |
|----------------| |
| 8866 |
. . |
| 8867 |
. . |
| 8868 |
. . |
| 8869 |
|----------------| |
| 8870 |
| Param # | |
| 8871 |
|----------------| |
| 8872 |
| ProcSym | Type | Empty |
| 8873 |
|----------------| |
| 8874 |
*) |
| 8875 |
|
| 8876 |
PROCEDURE BuildAbsFunction (ProcSym: CARDINAL; ConstExpr: BOOLEAN) ; |
| 8877 |
VAR |
| 8878 |
vartok, |
| 8879 |
functok, |
| 8880 |
combinedtok: CARDINAL ; |
| 8881 |
NoOfParam, |
| 8882 |
Res, Var : CARDINAL ; |
| 8883 |
BEGIN |
| 8884 |
PopT (NoOfParam) ; |
| 8885 |
functok := OperandTok (NoOfParam + 1) ; |
| 8886 |
IF NoOfParam = 1 |
| 8887 |
THEN |
| 8888 |
Var := OperandT (1) ; |
| 8889 |
vartok := OperandTok (1) ; |
| 8890 |
PopN (NoOfParam + 1) ; |
| 8891 |
combinedtok := MakeVirtualTok (functok, functok, vartok) ; |
| 8892 |
IF ConstExprError (ProcSym, Var, vartok, ConstExpr) |
| 8893 |
THEN |
| 8894 |
(* Create fake result. *) |
| 8895 |
Res := MakeTemporary (combinedtok, AreConstant (IsConst (Var))) ; |
| 8896 |
PutVar (Res, GetSType (Var)) ; |
| 8897 |
PushTFtok (Res, GetSType (Var), combinedtok) |
| 8898 |
ELSIF IsVar(Var) OR IsConst(Var) |
| 8899 |
THEN |
| 8900 |
Res := MakeTemporary (combinedtok, AreConstant (IsConst (Var))) ; |
| 8901 |
PutVar (Res, GetSType (Var)) ; |
| 8902 |
|
| 8903 |
GenQuadO (combinedtok, StandardFunctionOp, Res, ProcSym, Var, FALSE) ; |
| 8904 |
PushTFtok (Res, GetSType (Var), combinedtok) |
| 8905 |
ELSE |
| 8906 |
MetaErrorT1 (vartok, |
| 8907 |
'the parameter to {%AkABS} must be a variable or constant, seen {%1ad}', |
| 8908 |
Var) |
| 8909 |
END |
| 8910 |
ELSE |
| 8911 |
MetaErrorT1 (functok, |
| 8912 |
'the pseudo procedure {%AkABS} only has one parameter, seen {%1n} parameters', |
| 8913 |
NoOfParam) |
| 8914 |
END |
| 8915 |
END BuildAbsFunction ; |
| 8916 |
|
| 8917 |
|
| 8918 |
(* |
| 8919 |
BuildCapFunction - builds the pseudo procedure call CAP. |
| 8920 |
We generate a the following quad: |
| 8921 |
|
| 8922 |
|
| 8923 |
StandardFunctionOp ReturnVal Cap Param1 |
| 8924 |
|
| 8925 |
The Stack: |
| 8926 |
|
| 8927 |
|
| 8928 |
Entry Exit |
| 8929 |
|
| 8930 |
Ptr -> |
| 8931 |
+----------------+ |
| 8932 |
| NoOfParam = 1 | |
| 8933 |
|----------------| |
| 8934 |
| Param 1 | |
| 8935 |
|----------------| +-------------+ |
| 8936 |
| ProcSym | Type | | ReturnVal | |
| 8937 |
|----------------| |-------------| |
| 8938 |
*) |
| 8939 |
|
| 8940 |
PROCEDURE BuildCapFunction (ProcSym: CARDINAL; ConstExpr: BOOLEAN) ; |
| 8941 |
VAR |
| 8942 |
optok, |
| 8943 |
functok, |
| 8944 |
combinedtok: CARDINAL ; |
| 8945 |
NoOfParam, |
| 8946 |
Res, Var : CARDINAL ; |
| 8947 |
BEGIN |
| 8948 |
PopT (NoOfParam) ; |
| 8949 |
functok := OperandTok (NoOfParam + 1) ; |
| 8950 |
IF NoOfParam = 1 |
| 8951 |
THEN |
| 8952 |
Var := OperandT (1) ; |
| 8953 |
optok := OperandTok (1) ; |
| 8954 |
PopN (NoOfParam + 1) ; |
| 8955 |
IF ConstExprError (ProcSym, Var, optok, ConstExpr) |
| 8956 |
THEN |
| 8957 |
(* Create fake result. *) |
| 8958 |
combinedtok := MakeVirtual2Tok (functok, optok) ; |
| 8959 |
Res := MakeTemporary (combinedtok, AreConstant (IsConst (Var))) ; |
| 8960 |
PutVar (Res, Char) ; |
| 8961 |
PushTFtok (Res, Char, combinedtok) |
| 8962 |
ELSIF IsVar (Var) OR IsConst (Var) |
| 8963 |
THEN |
| 8964 |
combinedtok := MakeVirtual2Tok (functok, optok) ; |
| 8965 |
Res := MakeTemporary (combinedtok, AreConstant (IsConst (Var))) ; |
| 8966 |
PutVar (Res, Char) ; |
| 8967 |
GenQuadO (combinedtok, StandardFunctionOp, Res, ProcSym, Var, FALSE) ; |
| 8968 |
PushTFtok (Res, Char, combinedtok) |
| 8969 |
ELSE |
| 8970 |
MetaErrorT1 (optok, |
| 8971 |
'the parameter to {%AkCAP} must be a variable or constant, seen {%1ad}', |
| 8972 |
Var) |
| 8973 |
END |
| 8974 |
ELSE |
| 8975 |
MetaErrorT1 (functok, |
| 8976 |
'the pseudo procedure {%AkCAP} only has one parameter, seen {%1n} parameters', |
| 8977 |
NoOfParam) |
| 8978 |
END |
| 8979 |
END BuildCapFunction ; |
| 8980 |
|
| 8981 |
|
| 8982 |
(* |
| 8983 |
BuildChrFunction - builds the pseudo procedure call CHR. |
| 8984 |
This procedure is actually a "macro" for |
| 8985 |
CHR(x) --> CONVERT(CHAR, x) |
| 8986 |
However we cannot push tokens back onto the input stack |
| 8987 |
because the compiler is currently building a function |
| 8988 |
call and expecting a ReturnVar on the stack. |
| 8989 |
Hence we manipulate the stack and call |
| 8990 |
BuildConvertFunction. |
| 8991 |
|
| 8992 |
The Stack: |
| 8993 |
|
| 8994 |
|
| 8995 |
Entry Exit |
| 8996 |
|
| 8997 |
Ptr -> |
| 8998 |
+----------------+ |
| 8999 |
| NoOfParam | |
| 9000 |
|----------------| |
| 9001 |
| Param 1 | |
| 9002 |
|----------------| |
| 9003 |
| Param 2 | |
| 9004 |
|----------------| |
| 9005 |
. . |
| 9006 |
. . |
| 9007 |
. . |
| 9008 |
|----------------| |
| 9009 |
| Param # | |
| 9010 |
|----------------| |
| 9011 |
| ProcSym | Type | Empty |
| 9012 |
|----------------| |
| 9013 |
*) |
| 9014 |
|
| 9015 |
PROCEDURE BuildChrFunction (ProcSym: CARDINAL; ConstExpr: BOOLEAN) ; |
| 9016 |
VAR |
| 9017 |
functok, |
| 9018 |
combinedtok, |
| 9019 |
optok : CARDINAL ; |
| 9020 |
ReturnVar, |
| 9021 |
NoOfParam, |
| 9022 |
Var : CARDINAL ; |
| 9023 |
BEGIN |
| 9024 |
PopT (NoOfParam) ; |
| 9025 |
functok := OperandTok (NoOfParam + 1) ; |
| 9026 |
IF NoOfParam = 1 |
| 9027 |
THEN |
| 9028 |
Var := OperandT (1) ; |
| 9029 |
optok := OperandTok (1) ; |
| 9030 |
PopN (NoOfParam + 1) ; |
| 9031 |
IF ConstExprError (ProcSym, Var, optok, ConstExpr) |
| 9032 |
THEN |
| 9033 |
(* Generate fake result. *) |
| 9034 |
combinedtok := MakeVirtual2Tok (functok, optok) ; |
| 9035 |
ReturnVar := MakeTemporary (combinedtok, AreConstant (IsConst (Var))) ; |
| 9036 |
PutVar (ReturnVar, Char) ; |
| 9037 |
PushTFtok (ReturnVar, Char, combinedtok) |
| 9038 |
ELSIF IsVar (Var) OR IsConst (Var) |
| 9039 |
THEN |
| 9040 |
(* |
| 9041 |
Build macro: CONVERT( CHAR, Var ) |
| 9042 |
*) |
| 9043 |
PushTFtok (Convert, NulSym, functok) ; |
| 9044 |
PushTtok (Char, functok) ; |
| 9045 |
PushTtok (Var, optok) ; |
| 9046 |
PushT (2) ; (* Two parameters *) |
| 9047 |
BuildConvertFunction (Convert, ConstExpr) |
| 9048 |
ELSE |
| 9049 |
MetaErrorT1 (optok, |
| 9050 |
'the parameter to {%AkCHR} must be a variable or constant, seen {%1ad}', |
| 9051 |
Var) |
| 9052 |
END |
| 9053 |
ELSE |
| 9054 |
MetaErrorT1 (functok, |
| 9055 |
'the pseudo procedure {%AkCHR} only has one parameter, seen {%1n} parameters', |
| 9056 |
NoOfParam) |
| 9057 |
END |
| 9058 |
END BuildChrFunction ; |
| 9059 |
|
| 9060 |
|
| 9061 |
(* |
| 9062 |
BuildOrdFunction - builds the pseudo procedure call ORD. |
| 9063 |
This procedure is actually a "macro" for |
| 9064 |
ORD(x) --> CONVERT(GetSType(sym), x) |
| 9065 |
However we cannot push tokens back onto the input stack |
| 9066 |
because the compiler is currently building a function |
| 9067 |
call and expecting a ReturnVar on the stack. |
| 9068 |
Hence we manipulate the stack and call |
| 9069 |
BuildConvertFunction. |
| 9070 |
|
| 9071 |
The Stack: |
| 9072 |
|
| 9073 |
|
| 9074 |
Entry Exit |
| 9075 |
|
| 9076 |
Ptr -> |
| 9077 |
+----------------+ |
| 9078 |
| NoOfParam | |
| 9079 |
|----------------| |
| 9080 |
| Param 1 | |
| 9081 |
|----------------| |
| 9082 |
| Param 2 | |
| 9083 |
|----------------| |
| 9084 |
. . |
| 9085 |
. . |
| 9086 |
. . |
| 9087 |
|----------------| |
| 9088 |
| Param # | |
| 9089 |
|----------------| |
| 9090 |
| ProcSym | Type | Empty |
| 9091 |
|----------------| |
| 9092 |
*) |
| 9093 |
|
| 9094 |
PROCEDURE BuildOrdFunction (Sym: CARDINAL; ConstExpr: BOOLEAN) ; |
| 9095 |
VAR |
| 9096 |
combinedtok, |
| 9097 |
functok, |
| 9098 |
optok : CARDINAL ; |
| 9099 |
ReturnVar, |
| 9100 |
NoOfParam, |
| 9101 |
Type, Var : CARDINAL ; |
| 9102 |
BEGIN |
| 9103 |
PopT (NoOfParam) ; |
| 9104 |
functok := OperandTok (NoOfParam + 1) ; |
| 9105 |
IF NoOfParam = 1 |
| 9106 |
THEN |
| 9107 |
Var := OperandT (1) ; |
| 9108 |
optok := OperandTok (1) ; |
| 9109 |
PopN (NoOfParam + 1) ; |
| 9110 |
IF ConstExprError (Sym, Var, optok, ConstExpr) |
| 9111 |
THEN |
| 9112 |
(* Generate fake result. *) |
| 9113 |
combinedtok := MakeVirtual2Tok (functok, optok) ; |
| 9114 |
ReturnVar := MakeTemporary (combinedtok, AreConstant (IsConst (Var))) ; |
| 9115 |
PutVar (ReturnVar, Cardinal) ; |
| 9116 |
PushTFtok (ReturnVar, Cardinal, combinedtok) |
| 9117 |
ELSIF IsVar (Var) OR IsConst (Var) |
| 9118 |
THEN |
| 9119 |
Type := GetSType (Sym) ; |
| 9120 |
(* |
| 9121 |
Build macro: CONVERT( CARDINAL, Var ) |
| 9122 |
*) |
| 9123 |
PushTFtok (Convert, NulSym, functok) ; |
| 9124 |
PushTtok (Type, optok) ; |
| 9125 |
PushTtok (Var, optok) ; |
| 9126 |
PushT (2) ; (* Two parameters *) |
| 9127 |
BuildConvertFunction (Convert, ConstExpr) |
| 9128 |
ELSE |
| 9129 |
MetaErrorT2 (optok, |
| 9130 |
'the parameter to {%1Aa} must be a variable or constant, seen {%2ad}', |
| 9131 |
Sym, Var) |
| 9132 |
END |
| 9133 |
ELSE |
| 9134 |
MetaErrorT2 (functok, |
| 9135 |
'the pseudo procedure {%1Aa} only has one parameter, seen {%2n} parameters', |
| 9136 |
Sym, NoOfParam) |
| 9137 |
END |
| 9138 |
END BuildOrdFunction ; |
| 9139 |
|
| 9140 |
|
| 9141 |
(* |
| 9142 |
BuildIntFunction - builds the pseudo procedure call INT. |
| 9143 |
This procedure is actually a "macro" for |
| 9144 |
INT(x) --> CONVERT(INTEGER, x) |
| 9145 |
However we cannot push tokens back onto the input stack |
| 9146 |
because the compiler is currently building a function |
| 9147 |
call and expecting a ReturnVar on the stack. |
| 9148 |
Hence we manipulate the stack and call |
| 9149 |
BuildConvertFunction. |
| 9150 |
|
| 9151 |
The Stack: |
| 9152 |
|
| 9153 |
|
| 9154 |
Entry Exit |
| 9155 |
|
| 9156 |
Ptr -> |
| 9157 |
+----------------+ |
| 9158 |
| NoOfParam | |
| 9159 |
|----------------| |
| 9160 |
| Param 1 | |
| 9161 |
|----------------| |
| 9162 |
| Param 2 | |
| 9163 |
|----------------| |
| 9164 |
. . |
| 9165 |
. . |
| 9166 |
. . |
| 9167 |
|----------------| |
| 9168 |
| Param # | |
| 9169 |
|----------------| |
| 9170 |
| ProcSym | Type | Empty |
| 9171 |
|----------------| |
| 9172 |
*) |
| 9173 |
|
| 9174 |
PROCEDURE BuildIntFunction (Sym: CARDINAL; ConstExpr: BOOLEAN) ; |
| 9175 |
VAR |
| 9176 |
combinedtok, |
| 9177 |
functok, |
| 9178 |
optok : CARDINAL ; |
| 9179 |
ReturnVar, |
| 9180 |
NoOfParam, |
| 9181 |
Type, Var : CARDINAL ; |
| 9182 |
BEGIN |
| 9183 |
PopT (NoOfParam) ; |
| 9184 |
functok := OperandTok (NoOfParam + 1) ; |
| 9185 |
IF NoOfParam = 1 |
| 9186 |
THEN |
| 9187 |
Var := OperandT (1) ; |
| 9188 |
optok := OperandTok (1) ; |
| 9189 |
PopN (NoOfParam + 1) ; |
| 9190 |
IF ConstExprError (Sym, Var, optok, ConstExpr) |
| 9191 |
THEN |
| 9192 |
(* Generate fake result. *) |
| 9193 |
combinedtok := MakeVirtual2Tok (functok, optok) ; |
| 9194 |
ReturnVar := MakeTemporary (combinedtok, AreConstant (IsConst (Var))) ; |
| 9195 |
PutVar (ReturnVar, Integer) ; |
| 9196 |
PushTFtok (ReturnVar, Integer, combinedtok) |
| 9197 |
ELSIF IsVar (Var) OR IsConst (Var) |
| 9198 |
THEN |
| 9199 |
Type := GetSType (Sym) ; (* return type of function *) |
| 9200 |
(* Build macro: CONVERT( CARDINAL, Var ). *) |
| 9201 |
PushTFtok (Convert, NulSym, functok) ; |
| 9202 |
PushTtok (Type, functok) ; |
| 9203 |
PushTtok (Var, optok) ; |
| 9204 |
PushT (2) ; (* Two parameters *) |
| 9205 |
BuildConvertFunction (Convert, ConstExpr) |
| 9206 |
ELSE |
| 9207 |
combinedtok := MakeVirtualTok (functok, optok, optok) ; |
| 9208 |
MetaErrorT2 (optok, |
| 9209 |
'the parameter to {%1Ea} must be a variable or constant, seen {%2ad}', |
| 9210 |
Sym, Var) ; |
| 9211 |
PushTtok (combinedtok, MakeConstLit (combinedtok, MakeKey ('0'), ZType)) |
| 9212 |
END |
| 9213 |
ELSE |
| 9214 |
MetaErrorT2 (functok, |
| 9215 |
'the pseudo procedure {%1Ea} only has one parameter, seen {%2n} parameters', |
| 9216 |
Sym, NoOfParam) ; |
| 9217 |
PushTtok (functok, MakeConstLit (functok, MakeKey ('0'), ZType)) |
| 9218 |
END |
| 9219 |
END BuildIntFunction ; |
| 9220 |
|
| 9221 |
|
| 9222 |
(* |
| 9223 |
BuildMakeAdrFunction - builds the pseudo procedure call MAKEADR. |
| 9224 |
|
| 9225 |
The Stack: |
| 9226 |
|
| 9227 |
|
| 9228 |
Entry Exit |
| 9229 |
|
| 9230 |
Ptr -> |
| 9231 |
+----------------+ |
| 9232 |
| NoOfParam | |
| 9233 |
|----------------| |
| 9234 |
| Param 1 | |
| 9235 |
|----------------| |
| 9236 |
| Param 2 | |
| 9237 |
|----------------| |
| 9238 |
. . |
| 9239 |
. . |
| 9240 |
. . |
| 9241 |
|----------------| |
| 9242 |
| Param # | |
| 9243 |
|----------------| |
| 9244 |
| ProcSym | Type | Empty |
| 9245 |
|----------------| |
| 9246 |
*) |
| 9247 |
|
| 9248 |
PROCEDURE BuildMakeAdrFunction ; |
| 9249 |
VAR |
| 9250 |
functok, |
| 9251 |
starttok, |
| 9252 |
endtok, |
| 9253 |
resulttok : CARDINAL ; |
| 9254 |
AreConst : BOOLEAN ; |
| 9255 |
i, pi, |
| 9256 |
NoOfParameters: CARDINAL ; |
| 9257 |
ReturnVar : CARDINAL ; |
| 9258 |
BEGIN |
| 9259 |
PopT (NoOfParameters) ; |
| 9260 |
functok := OperandTok (NoOfParameters + 1) ; |
| 9261 |
IF NoOfParameters>0 |
| 9262 |
THEN |
| 9263 |
starttok := OperandTok (NoOfParameters + 1) ; (* ADR token. *) |
| 9264 |
endtok := OperandTok (1) ; (* last parameter. *) |
| 9265 |
GenQuad (ParamOp, 0, MakeAdr, MakeAdr) ; |
| 9266 |
i := NoOfParameters ; |
| 9267 |
(* stack index referencing stacked parameter, i *) |
| 9268 |
pi := 1 ; |
| 9269 |
WHILE i > 0 DO |
| 9270 |
GenQuadO (OperandTok (pi), ParamOp, i, MakeAdr, OperandT (pi), TRUE) ; |
| 9271 |
DEC (i) ; |
| 9272 |
INC (pi) |
| 9273 |
END ; |
| 9274 |
AreConst := TRUE ; |
| 9275 |
i := 1 ; |
| 9276 |
WHILE i <= NoOfParameters DO |
| 9277 |
IF IsVar (OperandT (i)) |
| 9278 |
THEN |
| 9279 |
AreConst := FALSE ; |
| 9280 |
ELSIF NOT IsConst (OperandT (i)) |
| 9281 |
THEN |
| 9282 |
MetaError1 ('problem in the {%1EN} argument for {%kMAKEADR}, all arguments to {%kMAKEADR} must be either variables or constants', i) |
| 9283 |
END ; |
| 9284 |
INC (i) |
| 9285 |
END ; |
| 9286 |
(* ReturnVar - will have the type of the procedure *) |
| 9287 |
resulttok := MakeVirtualTok (starttok, starttok, endtok) ; |
| 9288 |
ReturnVar := MakeTemporary (resulttok, AreConstant(AreConst)) ; |
| 9289 |
PutVar (ReturnVar, GetSType(MakeAdr)) ; |
| 9290 |
GenQuadO (resulttok, FunctValueOp, ReturnVar, NulSym, MakeAdr, TRUE) ; |
| 9291 |
PopN (NoOfParameters+1) ; |
| 9292 |
PushTFtok (ReturnVar, GetSType (MakeAdr), resulttok) |
| 9293 |
ELSE |
| 9294 |
MetaError1 ('the pseudo procedure {%EkMAKEADR} requires at least one parameter, seen {%1n}', NoOfParameters) ; |
| 9295 |
PopN (1) ; |
| 9296 |
PushTFtok (Nil, GetSType (MakeAdr), functok) |
| 9297 |
END |
| 9298 |
END BuildMakeAdrFunction ; |
| 9299 |
|
| 9300 |
|
| 9301 |
(* |
| 9302 |
BuildShiftFunction - builds the pseudo procedure call SHIFT. |
| 9303 |
|
| 9304 |
PROCEDURE SHIFT (val: <any type>; |
| 9305 |
num: INTEGER): <any type> ; |
| 9306 |
|
| 9307 |
"Returns a bit sequence obtained from val by |
| 9308 |
shifting up or down (left or right) by the |
| 9309 |
absolute value of num, introducing |
| 9310 |
zeros as necessary. The direction is down if |
| 9311 |
the sign of num is negative, otherwise the |
| 9312 |
direction is up." |
| 9313 |
|
| 9314 |
The Stack: |
| 9315 |
|
| 9316 |
Entry Exit |
| 9317 |
|
| 9318 |
Ptr -> |
| 9319 |
+----------------+ |
| 9320 |
| NoOfParam | |
| 9321 |
|----------------| |
| 9322 |
| Param 1 | |
| 9323 |
|----------------| |
| 9324 |
| Param 2 | <- Ptr |
| 9325 |
|----------------| +------------+ |
| 9326 |
| ProcSym | Type | | ReturnVar | |
| 9327 |
|----------------| |------------| |
| 9328 |
*) |
| 9329 |
|
| 9330 |
PROCEDURE BuildShiftFunction ; |
| 9331 |
VAR |
| 9332 |
combinedtok, |
| 9333 |
paramtok, |
| 9334 |
functok, |
| 9335 |
vartok, |
| 9336 |
exptok : CARDINAL ; |
| 9337 |
r, |
| 9338 |
procSym, |
| 9339 |
returnVar, |
| 9340 |
NoOfParam, |
| 9341 |
derefExp, |
| 9342 |
Exp, |
| 9343 |
varSet : CARDINAL ; |
| 9344 |
BEGIN |
| 9345 |
PopT (NoOfParam) ; |
| 9346 |
paramtok := OperandTok (1) ; |
| 9347 |
functok := OperandTok (NoOfParam + 1) ; |
| 9348 |
IF NoOfParam=2 |
| 9349 |
THEN |
| 9350 |
PopTrwtok (Exp, r, exptok) ; |
| 9351 |
MarkAsRead (r) ; |
| 9352 |
PopTtok (varSet, vartok) ; |
| 9353 |
PopT (procSym) ; |
| 9354 |
combinedtok := MakeVirtualTok (functok, functok, exptok) ; |
| 9355 |
IF (GetSType (varSet) # NulSym) AND IsSet (GetDType (varSet)) |
| 9356 |
THEN |
| 9357 |
derefExp := DereferenceLValue (exptok, Exp) ; |
| 9358 |
BuildRange (InitShiftCheck (varSet, derefExp)) ; |
| 9359 |
returnVar := MakeTemporary (combinedtok, RightValue) ; |
| 9360 |
PutVar (returnVar, GetSType (varSet)) ; |
| 9361 |
GenQuadO (combinedtok, LogicalShiftOp, returnVar, varSet, derefExp, TRUE) ; |
| 9362 |
PushTFtok (returnVar, GetSType (varSet), combinedtok) |
| 9363 |
ELSE |
| 9364 |
MetaErrorT1 (vartok, |
| 9365 |
'SYSTEM procedure {%1EkSHIFT} expects a constant or variable which has a type of SET as its first parameter, seen {%1ad}', |
| 9366 |
varSet) ; |
| 9367 |
PushTFtok (MakeConstLit (combinedtok, MakeKey ('0'), Cardinal), Cardinal, combinedtok) |
| 9368 |
END |
| 9369 |
ELSE |
| 9370 |
combinedtok := MakeVirtualTok (functok, functok, paramtok) ; |
| 9371 |
MetaErrorT1 (functok, |
| 9372 |
'the pseudo procedure {%kSHIFT} requires at least two parameters, seen {%1En}', |
| 9373 |
NoOfParam) ; |
| 9374 |
PopN (NoOfParam + 1) ; |
| 9375 |
PushTFtok (MakeConstLit (combinedtok, MakeKey ('0'), Cardinal), Cardinal, combinedtok) |
| 9376 |
END |
| 9377 |
END BuildShiftFunction ; |
| 9378 |
|
| 9379 |
|
| 9380 |
(* |
| 9381 |
BuildRotateFunction - builds the pseudo procedure call ROTATE. |
| 9382 |
|
| 9383 |
PROCEDURE ROTATE (val: <any type>; |
| 9384 |
num: INTEGER): <any type> ; |
| 9385 |
|
| 9386 |
"Returns a bit sequence obtained from val |
| 9387 |
by rotating up or down (left or right) by |
| 9388 |
the absolute value of num. The direction is |
| 9389 |
down if the sign of num is negative, otherwise |
| 9390 |
the direction is up." |
| 9391 |
|
| 9392 |
The Stack: |
| 9393 |
|
| 9394 |
Entry Exit |
| 9395 |
|
| 9396 |
Ptr -> |
| 9397 |
+----------------+ |
| 9398 |
| NoOfParam | |
| 9399 |
|----------------| |
| 9400 |
| Param 1 | |
| 9401 |
|----------------| |
| 9402 |
| Param 2 | <- Ptr |
| 9403 |
|----------------| +------------+ |
| 9404 |
| ProcSym | Type | | ReturnVar | |
| 9405 |
|----------------| |------------| |
| 9406 |
*) |
| 9407 |
|
| 9408 |
PROCEDURE BuildRotateFunction ; |
| 9409 |
VAR |
| 9410 |
combinedtok, |
| 9411 |
functok, |
| 9412 |
vartok, |
| 9413 |
exptok : CARDINAL ; |
| 9414 |
r, |
| 9415 |
procSym, |
| 9416 |
returnVar, |
| 9417 |
NoOfParam, |
| 9418 |
derefExp, |
| 9419 |
Exp, |
| 9420 |
varSet : CARDINAL ; |
| 9421 |
BEGIN |
| 9422 |
PopT (NoOfParam) ; |
| 9423 |
functok := OperandTok (NoOfParam + 1) ; |
| 9424 |
IF NoOfParam = 2 |
| 9425 |
THEN |
| 9426 |
PopTrwtok (Exp, r, exptok) ; |
| 9427 |
MarkAsRead (r) ; |
| 9428 |
PopTtok (varSet, vartok) ; |
| 9429 |
PopT (procSym) ; |
| 9430 |
IF (GetSType (varSet) # NulSym) AND IsSet (GetDType (varSet)) |
| 9431 |
THEN |
| 9432 |
combinedtok := MakeVirtualTok (functok, functok, exptok) ; |
| 9433 |
derefExp := DereferenceLValue (exptok, Exp) ; |
| 9434 |
BuildRange (InitRotateCheck (varSet, derefExp)) ; |
| 9435 |
returnVar := MakeTemporary (combinedtok, RightValue) ; |
| 9436 |
PutVar (returnVar, GetSType (varSet)) ; |
| 9437 |
GenQuadO (combinedtok, LogicalRotateOp, returnVar, varSet, derefExp, TRUE) ; |
| 9438 |
PushTFtok (returnVar, GetSType (varSet), combinedtok) |
| 9439 |
ELSE |
| 9440 |
MetaErrorT1 (vartok, |
| 9441 |
'SYSTEM procedure {%EkROTATE} expects a constant or variable which has a type of SET as its first parameter, seen {%1ad}', |
| 9442 |
varSet) ; |
| 9443 |
PushTFtok (MakeConstLit (functok, MakeKey('0'), Cardinal), Cardinal, functok) |
| 9444 |
END |
| 9445 |
ELSE |
| 9446 |
MetaErrorT1 (functok, |
| 9447 |
'SYSTEM procedure {%EkROTATE} expects 2 parameters and was given {%1n} parameters', |
| 9448 |
NoOfParam) ; |
| 9449 |
PopN (NoOfParam + 1) ; |
| 9450 |
PushTFtok (MakeConstLit (functok, MakeKey ('0'), Cardinal), Cardinal, functok) |
| 9451 |
END |
| 9452 |
END BuildRotateFunction ; |
| 9453 |
|
| 9454 |
|
| 9455 |
(* |
| 9456 |
BuildValFunction - builds the pseudo procedure call VAL. |
| 9457 |
This procedure is actually a "macro" for |
| 9458 |
VAL(Type, x) --> CONVERT(Type, x) |
| 9459 |
However we cannot push tokens back onto the input stack |
| 9460 |
because the compiler is currently building a function |
| 9461 |
call and expecting a ReturnVar on the stack. |
| 9462 |
Hence we manipulate the stack and call |
| 9463 |
BuildConvertFunction. |
| 9464 |
|
| 9465 |
The Stack: |
| 9466 |
|
| 9467 |
|
| 9468 |
Entry Exit |
| 9469 |
|
| 9470 |
Ptr -> |
| 9471 |
+----------------+ |
| 9472 |
| NoOfParam | |
| 9473 |
|----------------| |
| 9474 |
| Param 1 | |
| 9475 |
|----------------| |
| 9476 |
| Param 2 | |
| 9477 |
|----------------| |
| 9478 |
. . |
| 9479 |
. . |
| 9480 |
. . |
| 9481 |
|----------------| |
| 9482 |
| Param # | |
| 9483 |
|----------------| |
| 9484 |
| ProcSym | Type | Empty |
| 9485 |
|----------------| |
| 9486 |
*) |
| 9487 |
|
| 9488 |
PROCEDURE BuildValFunction (ProcSym: CARDINAL; ConstExpr: BOOLEAN) ; |
| 9489 |
VAR |
| 9490 |
combinedtok, |
| 9491 |
functok : CARDINAL ; |
| 9492 |
ReturnVar, |
| 9493 |
NoOfParam, |
| 9494 |
Exp, Type : CARDINAL ; |
| 9495 |
tok, r, |
| 9496 |
typetok, |
| 9497 |
exptok : CARDINAL ; |
| 9498 |
BEGIN |
| 9499 |
PopT (NoOfParam) ; |
| 9500 |
functok := OperandTok (NoOfParam + 1) ; |
| 9501 |
IF NoOfParam = 2 |
| 9502 |
THEN |
| 9503 |
PopTrwtok (Exp, r, exptok) ; |
| 9504 |
MarkAsRead (r) ; |
| 9505 |
PopTtok (Type, typetok) ; |
| 9506 |
PopTtok (ProcSym, tok) ; |
| 9507 |
IF IsUnknown (Type) |
| 9508 |
THEN |
| 9509 |
(* not sensible to try and recover when we dont know the return type. *) |
| 9510 |
MetaErrorT1 (typetok, |
| 9511 |
'undeclared type found in builtin procedure function {%AkVAL} {%1ad}', |
| 9512 |
Type) |
| 9513 |
(* non recoverable error. *) |
| 9514 |
ELSIF ConstExprError (ProcSym, Exp, exptok, ConstExpr) |
| 9515 |
THEN |
| 9516 |
(* Generate fake result. *) |
| 9517 |
combinedtok := MakeVirtualTok (functok, functok, exptok) ; |
| 9518 |
ReturnVar := MakeTemporary (combinedtok, AreConstant (IsConst (Exp))) ; |
| 9519 |
PutVar (ReturnVar, Type) ; |
| 9520 |
PushTFtok (ReturnVar, Type, combinedtok) |
| 9521 |
ELSIF (IsSet (Type) OR IsEnumeration (Type) OR IsSubrange (Type) OR |
| 9522 |
IsType (Type) OR IsPointer (Type) OR IsProcType (Type)) AND |
| 9523 |
(IsVar (Exp) OR IsConst (Exp) OR IsProcedure (Exp)) |
| 9524 |
THEN |
| 9525 |
(* |
| 9526 |
Build macro: CONVERT( Type, Var ) |
| 9527 |
*) |
| 9528 |
PushTFtok (Convert, NulSym, tok) ; |
| 9529 |
PushTtok (Type, typetok) ; |
| 9530 |
PushTtok (Exp, exptok) ; |
| 9531 |
PushT (2) ; (* Two parameters *) |
| 9532 |
BuildConvertFunction (Convert, ConstExpr) |
| 9533 |
ELSE |
| 9534 |
(* not sensible to try and recover when we dont know the return type. *) |
| 9535 |
MetaErrorT0 (functok, |
| 9536 |
'the builtin procedure {%AkVAL} has the following formal parameter declaration {%kVAL} (type, expression)') |
| 9537 |
(* non recoverable error. *) |
| 9538 |
END |
| 9539 |
ELSE |
| 9540 |
(* not sensible to try and recover when we dont know the return type. *) |
| 9541 |
MetaErrorT1 (functok, |
| 9542 |
'the builtin procedure {%AkVAL} expects 2 parameters, a type and an expression, but was given {%1n} parameters', NoOfParam) |
| 9543 |
(* non recoverable error. *) |
| 9544 |
END |
| 9545 |
END BuildValFunction ; |
| 9546 |
|
| 9547 |
|
| 9548 |
(* |
| 9549 |
BuildCastFunction - builds the pseudo procedure call CAST. |
| 9550 |
This procedure is actually a "macro" for |
| 9551 |
CAST(Type, x) --> Type(x) |
| 9552 |
However we cannot push tokens back onto the input stack |
| 9553 |
because the compiler is currently building a function |
| 9554 |
call and expecting a ReturnVar on the stack. |
| 9555 |
Hence we manipulate the stack and call |
| 9556 |
BuildConvertFunction. |
| 9557 |
|
| 9558 |
The Stack: |
| 9559 |
|
| 9560 |
|
| 9561 |
Entry Exit |
| 9562 |
|
| 9563 |
Ptr -> |
| 9564 |
+----------------+ |
| 9565 |
| NoOfParam | |
| 9566 |
|----------------| |
| 9567 |
| Param 1 | |
| 9568 |
|----------------| |
| 9569 |
| Param 2 | |
| 9570 |
|----------------| |
| 9571 |
. . |
| 9572 |
. . |
| 9573 |
. . |
| 9574 |
|----------------| |
| 9575 |
| Param # | |
| 9576 |
|----------------| |
| 9577 |
| ProcSym | Type | Empty |
| 9578 |
|----------------| |
| 9579 |
*) |
| 9580 |
|
| 9581 |
PROCEDURE BuildCastFunction (ProcSym: CARDINAL; ConstExpr: BOOLEAN) ; |
| 9582 |
VAR |
| 9583 |
combinedtok, |
| 9584 |
exptok, |
| 9585 |
typetok, |
| 9586 |
functok : CARDINAL ; |
| 9587 |
ReturnVar, |
| 9588 |
NoOfParam, |
| 9589 |
Exp, Type : CARDINAL ; |
| 9590 |
BEGIN |
| 9591 |
PopT (NoOfParam) ; |
| 9592 |
functok := OperandTok (NoOfParam + 1) ; |
| 9593 |
IF NoOfParam = 2 |
| 9594 |
THEN |
| 9595 |
Type := OperandT (2) ; |
| 9596 |
typetok := OperandTok (2) ; |
| 9597 |
Exp := OperandT (1) ; |
| 9598 |
exptok := OperandTok (1) ; |
| 9599 |
IF IsUnknown (Type) |
| 9600 |
THEN |
| 9601 |
(* we cannot recover if we dont have a type. *) |
| 9602 |
MetaErrorT1 (typetok, 'undeclared type {%1Aad} found in {%kCAST}', Type) |
| 9603 |
(* non recoverable error. *) |
| 9604 |
ELSIF ConstExprError (ProcSym, Exp, exptok, ConstExpr) |
| 9605 |
THEN |
| 9606 |
(* Generate fake result. *) |
| 9607 |
combinedtok := MakeVirtualTok (functok, functok, exptok) ; |
| 9608 |
ReturnVar := MakeTemporary (combinedtok, AreConstant (IsConst (Exp))) ; |
| 9609 |
PutVar (ReturnVar, Type) ; |
| 9610 |
PushTFtok (ReturnVar, Type, combinedtok) |
| 9611 |
ELSIF IsSet (Type) OR IsEnumeration (Type) OR IsSubrange (Type) OR IsType (Type) OR |
| 9612 |
IsPointer (Type) OR IsArray (Type) OR IsProcType (Type) |
| 9613 |
THEN |
| 9614 |
IF IsConst (Exp) |
| 9615 |
THEN |
| 9616 |
PopN (NoOfParam+1) ; |
| 9617 |
(* |
| 9618 |
Build macro: Type( Var ) |
| 9619 |
*) |
| 9620 |
PushTFtok (Type, NulSym, typetok) ; |
| 9621 |
PushTtok (Exp, exptok) ; |
| 9622 |
PushT (1) ; (* one parameter *) |
| 9623 |
BuildTypeCoercion (ConstExpr) |
| 9624 |
ELSIF IsVar (Exp) OR IsProcedure (Exp) |
| 9625 |
THEN |
| 9626 |
PopN (NoOfParam + 1) ; |
| 9627 |
combinedtok := MakeVirtual2Tok (functok, exptok) ; |
| 9628 |
ReturnVar := MakeTemporary (combinedtok, RightValue) ; |
| 9629 |
PutVar (ReturnVar, Type) ; |
| 9630 |
GenQuadO (combinedtok, CastOp, ReturnVar, Type, Exp, FALSE) ; |
| 9631 |
PushTFtok (ReturnVar, Type, combinedtok) |
| 9632 |
ELSE |
| 9633 |
(* not sensible to try and recover when we dont know the return type. *) |
| 9634 |
MetaErrorT0 (functok, |
| 9635 |
'the second parameter to the builtin procedure {%AkCAST} must either be a variable, constant or a procedure. The formal parameters to cast are {%kCAST} (type, variable or constant or procedure)') |
| 9636 |
(* non recoverable error. *) |
| 9637 |
END |
| 9638 |
ELSE |
| 9639 |
(* not sensible to try and recover when we dont know the return type. *) |
| 9640 |
MetaErrorT0 (functok, |
| 9641 |
'the builtin procedure {%AkCAST} has the following formal parameter declaration {%kCAST} (type, expression)') |
| 9642 |
(* non recoverable error. *) |
| 9643 |
END |
| 9644 |
ELSE |
| 9645 |
(* not sensible to try and recover when we dont know the return type. *) |
| 9646 |
MetaErrorT1 (functok, |
| 9647 |
'the builtin procedure {%AkCAST} `expects 2 parameters, a type and an expression, but was given {%1n} parameters', NoOfParam) |
| 9648 |
(* non recoverable error. *) |
| 9649 |
END |
| 9650 |
END BuildCastFunction ; |
| 9651 |
|
| 9652 |
|
| 9653 |
(* |
| 9654 |
BuildConvertFunction - builds the pseudo function CONVERT. |
| 9655 |
CONVERT( Type, Variable ) ; |
| 9656 |
|
| 9657 |
The Stack: |
| 9658 |
|
| 9659 |
|
| 9660 |
Entry Exit |
| 9661 |
|
| 9662 |
Ptr -> |
| 9663 |
+----------------+ |
| 9664 |
| NoOfParam | |
| 9665 |
|----------------| |
| 9666 |
| Param 1 | |
| 9667 |
|----------------| |
| 9668 |
| Param 2 | |
| 9669 |
|----------------| |
| 9670 |
. . |
| 9671 |
. . |
| 9672 |
. . |
| 9673 |
|----------------| |
| 9674 |
| Param # | <- Ptr |
| 9675 |
|----------------| +---------------------+ |
| 9676 |
| ProcSym | Type | | ReturnVar | Param1 | |
| 9677 |
|----------------| |---------------------| |
| 9678 |
|
| 9679 |
Quadruples: |
| 9680 |
|
| 9681 |
ConvertOp ReturnVar Param1 Param2 |
| 9682 |
|
| 9683 |
Converts variable Param2 into a variable Param1 |
| 9684 |
with a type Param1. |
| 9685 |
*) |
| 9686 |
|
| 9687 |
PROCEDURE BuildConvertFunction (ProcSym: CARDINAL; ConstExpr: BOOLEAN) ; |
| 9688 |
VAR |
| 9689 |
combinedtok, |
| 9690 |
functok, |
| 9691 |
typetok, |
| 9692 |
exptok : CARDINAL ; |
| 9693 |
t, r, |
| 9694 |
Exp, Type, |
| 9695 |
NoOfParam, |
| 9696 |
ReturnVar : CARDINAL ; |
| 9697 |
BEGIN |
| 9698 |
PopT (NoOfParam) ; |
| 9699 |
functok := OperandTok (NoOfParam + 1) ; |
| 9700 |
IF NoOfParam = 2 |
| 9701 |
THEN |
| 9702 |
PopTrwtok (Exp, r, exptok) ; |
| 9703 |
MarkAsRead (r) ; |
| 9704 |
PopTtok (Type, typetok) ; |
| 9705 |
PopT (ProcSym) ; |
| 9706 |
IF IsUnknown (Type) |
| 9707 |
THEN |
| 9708 |
(* we cannot recover if we dont have a type. *) |
| 9709 |
MetaErrorT1 (typetok, 'undeclared type {%1Aad} found in {%kCONVERT}', Type) |
| 9710 |
(* non recoverable error. *) |
| 9711 |
ELSIF IsUnknown (Exp) |
| 9712 |
THEN |
| 9713 |
(* we cannot recover if we dont have a type. *) |
| 9714 |
MetaErrorT1 (typetok, 'unknown {%1Ad} {%1ad} found in {%kCONVERT}', Exp) |
| 9715 |
(* non recoverable error. *) |
| 9716 |
ELSIF ConstExprError (ProcSym, Exp, exptok, ConstExpr) |
| 9717 |
THEN |
| 9718 |
(* Generate fake result. *) |
| 9719 |
combinedtok := MakeVirtualTok (functok, functok, exptok) ; |
| 9720 |
ReturnVar := MakeTemporary (combinedtok, AreConstant (IsConst (Exp))) ; |
| 9721 |
PutVar (ReturnVar, Type) ; |
| 9722 |
PushTFtok (ReturnVar, Type, combinedtok) |
| 9723 |
ELSIF (IsSet (Type) OR IsEnumeration (Type) OR IsSubrange (Type) OR |
| 9724 |
IsType (Type) OR IsPointer (Type) OR IsProcType (Type) OR IsRecord (Type)) AND |
| 9725 |
(IsVar (Exp) OR IsConst (Exp) OR IsProcedure (Exp)) |
| 9726 |
THEN |
| 9727 |
(* firstly dereference Var *) |
| 9728 |
IF GetMode (Exp) = LeftValue |
| 9729 |
THEN |
| 9730 |
t := MakeTemporary (exptok, RightValue) ; |
| 9731 |
PutVar (t, GetSType (Exp)) ; |
| 9732 |
CheckPointerThroughNil (exptok, Exp) ; |
| 9733 |
doIndrX (exptok, t, Exp) ; |
| 9734 |
Exp := t |
| 9735 |
END ; |
| 9736 |
|
| 9737 |
combinedtok := MakeVirtualTok (functok, functok, exptok) ; |
| 9738 |
ReturnVar := MakeTemporary (combinedtok, AreConstant (IsConst (Exp))) ; |
| 9739 |
PutVar (ReturnVar, Type) ; |
| 9740 |
GenQuadO (combinedtok, ConvertOp, ReturnVar, Type, Exp, TRUE) ; |
| 9741 |
PushTFtok (ReturnVar, Type, combinedtok) |
| 9742 |
ELSE |
| 9743 |
(* not sensible to try and recover when we dont know the return type. *) |
| 9744 |
MetaErrorT0 (functok, |
| 9745 |
'the builtin procedure {%AkCONVERT} has the following formal parameter declaration {%kCONVERT} (type, expression)') |
| 9746 |
(* non recoverable error. *) |
| 9747 |
END |
| 9748 |
ELSE |
| 9749 |
(* not sensible to try and recover when we dont know the return type. *) |
| 9750 |
MetaErrorT1 (functok, |
| 9751 |
'the builtin procedure {%AkCONVERT} expects 2 parameters, a type and an expression, but was given {%1n} parameters', NoOfParam) |
| 9752 |
(* non recoverable error. *) |
| 9753 |
END |
| 9754 |
END BuildConvertFunction ; |
| 9755 |
|
| 9756 |
|
| 9757 |
(* |
| 9758 |
CheckBaseTypeValue - checks to see whether the value, min, really exists. |
| 9759 |
*) |
| 9760 |
|
| 9761 |
PROCEDURE CheckBaseTypeValue (tok: CARDINAL; |
| 9762 |
type: CARDINAL; |
| 9763 |
min: CARDINAL; |
| 9764 |
func: CARDINAL) : CARDINAL ; |
| 9765 |
BEGIN |
| 9766 |
IF (type = Real) OR (type = LongReal) OR (type = ShortReal) |
| 9767 |
THEN |
| 9768 |
PushValue (min) ; |
| 9769 |
IF NOT IsValueAndTreeKnown () |
| 9770 |
THEN |
| 9771 |
MetaErrorT2 (tok, |
| 9772 |
'{%1Ead} ({%2ad}) cannot be calculated at compile time for the target architecture', func, type) ; |
| 9773 |
RETURN MakeConstLit (tok, MakeKey ('1.0'), RType) |
| 9774 |
END |
| 9775 |
END ; |
| 9776 |
RETURN min |
| 9777 |
END CheckBaseTypeValue ; |
| 9778 |
|
| 9779 |
|
| 9780 |
(* |
| 9781 |
GetTypeMin - returns the minimium value of type and generate an error |
| 9782 |
if this is unavailable. |
| 9783 |
*) |
| 9784 |
|
| 9785 |
PROCEDURE GetTypeMin (tok: CARDINAL; func, type: CARDINAL) : CARDINAL ; |
| 9786 |
VAR |
| 9787 |
min: CARDINAL ; |
| 9788 |
BEGIN |
| 9789 |
min := GetTypeMinLower (tok, func, type) ; |
| 9790 |
IF min = NulSym |
| 9791 |
THEN |
| 9792 |
MetaErrorT1 (tok, |
| 9793 |
'unable to obtain the {%AkMIN} value for type {%1ad}', type) |
| 9794 |
END ; |
| 9795 |
RETURN min |
| 9796 |
END GetTypeMin ; |
| 9797 |
|
| 9798 |
|
| 9799 |
(* |
| 9800 |
GetTypeMinLower - obtain the maximum value for type. |
| 9801 |
*) |
| 9802 |
|
| 9803 |
PROCEDURE GetTypeMinLower (tok: CARDINAL; func, type: CARDINAL) : CARDINAL ; |
| 9804 |
VAR |
| 9805 |
min, max: CARDINAL ; |
| 9806 |
BEGIN |
| 9807 |
IF IsSubrange (type) |
| 9808 |
THEN |
| 9809 |
min := MakeTemporary (tok, ImmediateValue) ; |
| 9810 |
PutVar (min, type) ; |
| 9811 |
GenQuad (SubrangeLowOp, min, NulSym, type) ; |
| 9812 |
RETURN min |
| 9813 |
ELSIF IsSet (SkipType (type)) |
| 9814 |
THEN |
| 9815 |
RETURN GetTypeMin (tok, func, GetSType (SkipType (type))) |
| 9816 |
ELSIF IsBaseType (type) OR IsEnumeration (type) |
| 9817 |
THEN |
| 9818 |
GetBaseTypeMinMax (type, min, max) ; |
| 9819 |
min := CheckBaseTypeValue (tok, type, min, func) ; |
| 9820 |
RETURN min |
| 9821 |
ELSIF IsSystemType (type) |
| 9822 |
THEN |
| 9823 |
GetSystemTypeMinMax (type, min, max) ; |
| 9824 |
RETURN min |
| 9825 |
ELSIF GetSType (type) = NulSym |
| 9826 |
THEN |
| 9827 |
RETURN NulSym |
| 9828 |
ELSE |
| 9829 |
RETURN GetTypeMin (tok, func, GetSType (type)) |
| 9830 |
END |
| 9831 |
END GetTypeMinLower ; |
| 9832 |
|
| 9833 |
|
| 9834 |
(* |
| 9835 |
GetTypeMax - returns the maximum value of type and generate an error |
| 9836 |
if this is unavailable. |
| 9837 |
*) |
| 9838 |
|
| 9839 |
PROCEDURE GetTypeMax (tok: CARDINAL; func, type: CARDINAL) : CARDINAL ; |
| 9840 |
VAR |
| 9841 |
max: CARDINAL ; |
| 9842 |
BEGIN |
| 9843 |
max := GetTypeMaxLower (tok, func, type) ; |
| 9844 |
IF max = NulSym |
| 9845 |
THEN |
| 9846 |
MetaErrorT1 (tok, |
| 9847 |
'unable to obtain the {%AkMAX} value for type {%1ad}', type) |
| 9848 |
END ; |
| 9849 |
RETURN max |
| 9850 |
END GetTypeMax ; |
| 9851 |
|
| 9852 |
|
| 9853 |
(* |
| 9854 |
GetTypeMaxLower - obtain the maximum value for type. |
| 9855 |
*) |
| 9856 |
|
| 9857 |
PROCEDURE GetTypeMaxLower (tok: CARDINAL; func, type: CARDINAL) : CARDINAL ; |
| 9858 |
VAR |
| 9859 |
min, max: CARDINAL ; |
| 9860 |
BEGIN |
| 9861 |
IF IsSubrange (type) |
| 9862 |
THEN |
| 9863 |
max := MakeTemporary (tok, ImmediateValue) ; |
| 9864 |
PutVar (max, type) ; |
| 9865 |
GenQuad (SubrangeHighOp, max, NulSym, type) ; |
| 9866 |
RETURN max |
| 9867 |
ELSIF IsSet (SkipType (type)) |
| 9868 |
THEN |
| 9869 |
RETURN GetTypeMax (tok, func, GetSType (SkipType (type))) |
| 9870 |
ELSIF IsBaseType (type) OR IsEnumeration (type) |
| 9871 |
THEN |
| 9872 |
GetBaseTypeMinMax (type, min, max) ; |
| 9873 |
min := CheckBaseTypeValue (tok, type, min, func) ; |
| 9874 |
RETURN max |
| 9875 |
ELSIF IsSystemType (type) |
| 9876 |
THEN |
| 9877 |
GetSystemTypeMinMax (type, min, max) ; |
| 9878 |
RETURN max |
| 9879 |
ELSIF GetSType (type) = NulSym |
| 9880 |
THEN |
| 9881 |
RETURN NulSym |
| 9882 |
ELSE |
| 9883 |
RETURN GetTypeMax (tok, func, GetSType (type)) |
| 9884 |
END |
| 9885 |
END GetTypeMaxLower ; |
| 9886 |
|
| 9887 |
|
| 9888 |
(* |
| 9889 |
BuildMinFunction - builds the pseudo function call Min. |
| 9890 |
|
| 9891 |
The Stack: |
| 9892 |
|
| 9893 |
Entry Exit |
| 9894 |
|
| 9895 |
Ptr -> |
| 9896 |
+----------------+ |
| 9897 |
| NoOfParam=1 | |
| 9898 |
|----------------| |
| 9899 |
| Param 1 | |
| 9900 |
|----------------| |
| 9901 |
| ProcSym | Type | Empty |
| 9902 |
|----------------| |
| 9903 |
*) |
| 9904 |
|
| 9905 |
PROCEDURE BuildMinFunction ; |
| 9906 |
VAR |
| 9907 |
combinedtok, |
| 9908 |
functok, |
| 9909 |
vartok : CARDINAL ; |
| 9910 |
func, |
| 9911 |
min, |
| 9912 |
NoOfParam, |
| 9913 |
Var : CARDINAL ; |
| 9914 |
BEGIN |
| 9915 |
PopT (NoOfParam) ; |
| 9916 |
func := OperandT (NoOfParam + 1) ; |
| 9917 |
functok := OperandTtok (NoOfParam + 1) ; |
| 9918 |
IF NoOfParam = 1 |
| 9919 |
THEN |
| 9920 |
Var := OperandT (1) ; |
| 9921 |
vartok := OperandTok (1) ; |
| 9922 |
PopN (NoOfParam+1) ; (* destroy arguments to this function *) |
| 9923 |
combinedtok := MakeVirtualTok (functok, functok, vartok) ; |
| 9924 |
IF IsAModula2Type (Var) |
| 9925 |
THEN |
| 9926 |
min := GetTypeMin (vartok, func, Var) ; |
| 9927 |
PushTFtok (min, GetSType (min), combinedtok) |
| 9928 |
ELSIF IsVar (Var) |
| 9929 |
THEN |
| 9930 |
min := GetTypeMin (vartok, func, GetSType (Var)) ; |
| 9931 |
PushTFtok (min, GetSType (Var), combinedtok) |
| 9932 |
ELSE |
| 9933 |
(* we dont know the type therefore cannot fake a return. *) |
| 9934 |
MetaErrorT1 (vartok, |
| 9935 |
'parameter to {%AkMIN} must be a type or a variable, seen {%1ad}', |
| 9936 |
Var) |
| 9937 |
(* non recoverable error. *) |
| 9938 |
END |
| 9939 |
ELSE |
| 9940 |
(* we dont know the type therefore cannot fake a return. *) |
| 9941 |
MetaErrorT1 (functok, |
| 9942 |
'the pseudo builtin procedure function {%AkMIN} only has one parameter, seen {%1n}', |
| 9943 |
NoOfParam) |
| 9944 |
(* non recoverable error. *) |
| 9945 |
END |
| 9946 |
END BuildMinFunction ; |
| 9947 |
|
| 9948 |
|
| 9949 |
(* |
| 9950 |
BuildMaxFunction - builds the pseudo function call Max. |
| 9951 |
|
| 9952 |
The Stack: |
| 9953 |
|
| 9954 |
Entry Exit |
| 9955 |
|
| 9956 |
Ptr -> |
| 9957 |
+----------------+ |
| 9958 |
| NoOfParam=1 | |
| 9959 |
|----------------| |
| 9960 |
| Param 1 | |
| 9961 |
|----------------| |
| 9962 |
| ProcSym | Type | Empty |
| 9963 |
|----------------| |
| 9964 |
*) |
| 9965 |
|
| 9966 |
PROCEDURE BuildMaxFunction ; |
| 9967 |
VAR |
| 9968 |
combinedtok, |
| 9969 |
functok, |
| 9970 |
vartok : CARDINAL ; |
| 9971 |
func, |
| 9972 |
max, |
| 9973 |
NoOfParam, |
| 9974 |
Var : CARDINAL ; |
| 9975 |
BEGIN |
| 9976 |
PopT (NoOfParam) ; |
| 9977 |
func := OperandT (NoOfParam + 1) ; |
| 9978 |
functok := OperandTtok (NoOfParam + 1) ; |
| 9979 |
IF NoOfParam = 1 |
| 9980 |
THEN |
| 9981 |
Var := OperandT (1) ; |
| 9982 |
vartok := OperandTok (1) ; |
| 9983 |
PopN (NoOfParam + 1) ; (* destroy arguments to this function *) |
| 9984 |
combinedtok := MakeVirtualTok (functok, functok, vartok) ; |
| 9985 |
IF IsAModula2Type (Var) |
| 9986 |
THEN |
| 9987 |
max := GetTypeMax (vartok, func, Var) ; |
| 9988 |
PushTFtok (max, GetSType (max), combinedtok) |
| 9989 |
ELSIF IsVar(Var) |
| 9990 |
THEN |
| 9991 |
max := GetTypeMax (vartok, func, GetSType (Var)) ; |
| 9992 |
PushTFtok (max, GetSType (Var), combinedtok) |
| 9993 |
ELSE |
| 9994 |
(* we dont know the type therefore cannot fake a return. *) |
| 9995 |
MetaErrorT1 (vartok, |
| 9996 |
'parameter to {%AkMAX} must be a type or a variable, seen {%1ad}', |
| 9997 |
Var) |
| 9998 |
(* non recoverable error. *) ; |
| 9999 |
END |
| 10000 |
ELSE |
| 10001 |
(* we dont know the type therefore cannot fake a return. *) |
| 10002 |
MetaErrorT1 (functok, |
| 10003 |
'the pseudo builtin procedure function {%AkMAX} only has one parameter, seen {%1n}', |
| 10004 |
NoOfParam) |
| 10005 |
(* non recoverable error. *) |
| 10006 |
END |
| 10007 |
END BuildMaxFunction ; |
| 10008 |
|
| 10009 |
|
| 10010 |
(* |
| 10011 |
BuildTruncFunction - builds the pseudo procedure call TRUNC. |
| 10012 |
This procedure is actually a "macro" for |
| 10013 |
TRUNC(x) --> CONVERT(INTEGER, x) |
| 10014 |
However we cannot push tokens back onto the input stack |
| 10015 |
because the compiler is currently building a function |
| 10016 |
call and expecting a ReturnVar on the stack. |
| 10017 |
Hence we manipulate the stack and call |
| 10018 |
BuildConvertFunction. |
| 10019 |
|
| 10020 |
The Stack: |
| 10021 |
|
| 10022 |
|
| 10023 |
Entry Exit |
| 10024 |
|
| 10025 |
Ptr -> |
| 10026 |
+----------------+ |
| 10027 |
| NoOfParam | |
| 10028 |
|----------------| |
| 10029 |
| Param 1 | |
| 10030 |
|----------------| |
| 10031 |
| Param 2 | |
| 10032 |
|----------------| |
| 10033 |
. . |
| 10034 |
. . |
| 10035 |
. . |
| 10036 |
|----------------| |
| 10037 |
| Param # | |
| 10038 |
|----------------| |
| 10039 |
| ProcSym | Type | Empty |
| 10040 |
|----------------| |
| 10041 |
*) |
| 10042 |
|
| 10043 |
PROCEDURE BuildTruncFunction (Sym: CARDINAL; ConstExpr: BOOLEAN) ; |
| 10044 |
VAR |
| 10045 |
combinedtok, |
| 10046 |
vartok, |
| 10047 |
functok : CARDINAL ; |
| 10048 |
NoOfParam : CARDINAL ; |
| 10049 |
ReturnVar, |
| 10050 |
ProcSym, |
| 10051 |
Type, |
| 10052 |
Var : CARDINAL ; |
| 10053 |
BEGIN |
| 10054 |
PopT (NoOfParam) ; |
| 10055 |
Assert (IsTrunc (OperandT (NoOfParam+1))) ; |
| 10056 |
functok := OperandTtok (NoOfParam + 1) ; |
| 10057 |
IF NoOfParam = 1 |
| 10058 |
THEN |
| 10059 |
ProcSym := RequestSym (functok, MakeKey ('CONVERT')) ; |
| 10060 |
IF (ProcSym # NulSym) AND IsProcedure (ProcSym) |
| 10061 |
THEN |
| 10062 |
Var := OperandT (1) ; |
| 10063 |
vartok := OperandTtok (1) ; |
| 10064 |
Type := GetSType (Sym) ; |
| 10065 |
PopN (NoOfParam + 1) ; (* destroy arguments to this function *) |
| 10066 |
IF ConstExprError (Sym, Var, vartok, ConstExpr) |
| 10067 |
THEN |
| 10068 |
(* Generate fake result. *) |
| 10069 |
combinedtok := MakeVirtual2Tok (functok, vartok) ; |
| 10070 |
ReturnVar := MakeTemporary (combinedtok, AreConstant (IsConst (Var))) ; |
| 10071 |
PutVar (ReturnVar, Type) ; |
| 10072 |
PushTFtok (ReturnVar, Type, combinedtok) |
| 10073 |
ELSIF IsVar (Var) OR IsConst (Var) |
| 10074 |
THEN |
| 10075 |
IF IsRealType (GetSType (Var)) |
| 10076 |
THEN |
| 10077 |
(* build macro: CONVERT( INTEGER, Var ). *) |
| 10078 |
PushTFtok (ProcSym, NulSym, functok) ; |
| 10079 |
PushTtok (Type, functok) ; |
| 10080 |
PushTtok (Var, vartok) ; |
| 10081 |
PushT (2) ; (* two parameters *) |
| 10082 |
BuildConvertFunction (Convert, ConstExpr) |
| 10083 |
ELSE |
| 10084 |
MetaErrorT1 (functok, |
| 10085 |
'argument to {%1Ead} must be a float point type', Sym) ; |
| 10086 |
PushTFtok (MakeConstLit (functok, MakeKey('0'), Type), Type, functok) |
| 10087 |
END |
| 10088 |
ELSE |
| 10089 |
MetaErrorT2 (vartok, |
| 10090 |
'argument to {%1Ead} must be a variable or constant, seen {%2ad}', |
| 10091 |
Sym, Var) ; |
| 10092 |
PushTFtok (MakeConstLit (functok, MakeKey('0'), Type), Type, functok) |
| 10093 |
END |
| 10094 |
ELSE |
| 10095 |
InternalError ('CONVERT procedure not found for TRUNC substitution') |
| 10096 |
END |
| 10097 |
ELSE |
| 10098 |
(* we dont know the type therefore cannot fake a return. *) |
| 10099 |
MetaErrorT1 (functok, |
| 10100 |
'the pseudo builtin procedure function {%AkTRUNC} only has one parameter, seen {%1n}', NoOfParam) |
| 10101 |
(* non recoverable error. *) |
| 10102 |
END |
| 10103 |
END BuildTruncFunction ; |
| 10104 |
|
| 10105 |
|
| 10106 |
(* |
| 10107 |
BuildFloatFunction - builds the pseudo procedure call FLOAT. |
| 10108 |
This procedure is actually a "macro" for |
| 10109 |
FLOAT(x) --> CONVERT(REAL, x) |
| 10110 |
However we cannot push tokens back onto the input stack |
| 10111 |
because the compiler is currently building a function |
| 10112 |
call and expecting a ReturnVar on the stack. |
| 10113 |
Hence we manipulate the stack and call |
| 10114 |
BuildConvertFunction. |
| 10115 |
|
| 10116 |
The Stack: |
| 10117 |
|
| 10118 |
|
| 10119 |
Entry Exit |
| 10120 |
|
| 10121 |
Ptr -> |
| 10122 |
+----------------+ |
| 10123 |
| NoOfParam | |
| 10124 |
|----------------| |
| 10125 |
| Param 1 | |
| 10126 |
|----------------| |
| 10127 |
| Param 2 | |
| 10128 |
|----------------| |
| 10129 |
. . |
| 10130 |
. . |
| 10131 |
. . |
| 10132 |
|----------------| |
| 10133 |
| Param # | |
| 10134 |
|----------------| |
| 10135 |
| ProcSym | Type | Empty |
| 10136 |
|----------------| |
| 10137 |
*) |
| 10138 |
|
| 10139 |
PROCEDURE BuildFloatFunction (Sym: CARDINAL; ConstExpr: BOOLEAN) ; |
| 10140 |
VAR |
| 10141 |
combinedtok, |
| 10142 |
vartok, |
| 10143 |
functok : CARDINAL ; |
| 10144 |
NoOfParam : CARDINAL ; |
| 10145 |
ReturnVar, |
| 10146 |
Type, |
| 10147 |
Var, |
| 10148 |
ProcSym : CARDINAL ; |
| 10149 |
BEGIN |
| 10150 |
PopT (NoOfParam) ; |
| 10151 |
functok := OperandTtok (NoOfParam + 1) ; |
| 10152 |
Type := GetSType (Sym) ; |
| 10153 |
IF NoOfParam = 1 |
| 10154 |
THEN |
| 10155 |
ProcSym := RequestSym (functok, MakeKey ('CONVERT')) ; |
| 10156 |
IF (ProcSym # NulSym) AND IsProcedure (ProcSym) |
| 10157 |
THEN |
| 10158 |
Var := OperandT (1) ; |
| 10159 |
vartok := OperandTtok (1) ; |
| 10160 |
PopN (NoOfParam + 1) ; (* destroy arguments to this function. *) |
| 10161 |
IF ConstExprError (Sym, Var, vartok, ConstExpr) |
| 10162 |
THEN |
| 10163 |
(* Generate fake result. *) |
| 10164 |
combinedtok := MakeVirtual2Tok (functok, vartok) ; |
| 10165 |
ReturnVar := MakeTemporary (combinedtok, AreConstant (IsConst (Var))) ; |
| 10166 |
PutVar (ReturnVar, Type) ; |
| 10167 |
PushTFtok (ReturnVar, Type, combinedtok) |
| 10168 |
ELSIF IsVar (Var) OR IsConst (Var) |
| 10169 |
THEN |
| 10170 |
(* build macro: CONVERT (REAL, Var). *) |
| 10171 |
PushTFtok (ProcSym, NulSym, functok) ; |
| 10172 |
PushTtok (Type, functok) ; |
| 10173 |
PushTtok (Var, vartok) ; |
| 10174 |
PushT(2) ; (* two parameters. *) |
| 10175 |
BuildConvertFunction (ProcSym, ConstExpr) |
| 10176 |
ELSE |
| 10177 |
MetaErrorT1 (vartok, |
| 10178 |
'argument to {%1Ead} must be a variable or constant', ProcSym) ; |
| 10179 |
PushTFtok (MakeConstLit (functok, MakeKey('0.0'), Type), Type, functok) |
| 10180 |
END |
| 10181 |
ELSE |
| 10182 |
InternalError ('CONVERT procedure not found for FLOAT substitution') |
| 10183 |
END |
| 10184 |
ELSE |
| 10185 |
PopN (NoOfParam + 1) ; (* destroy arguments to this function. *) |
| 10186 |
MetaErrorT1 (functok, |
| 10187 |
'the builtin procedure function {%1Ead} only has one parameter', |
| 10188 |
Sym) ; |
| 10189 |
PushTFtok (MakeConstLit (functok, MakeKey('0.0'), Type), Type, functok) |
| 10190 |
END |
| 10191 |
END BuildFloatFunction ; |
| 10192 |
|
| 10193 |
|
| 10194 |
(* |
| 10195 |
BuildReFunction - builds the pseudo procedure call RE. |
| 10196 |
|
| 10197 |
The Stack: |
| 10198 |
|
| 10199 |
|
| 10200 |
Entry Exit |
| 10201 |
|
| 10202 |
Ptr -> |
| 10203 |
+----------------+ |
| 10204 |
| NoOfParam | |
| 10205 |
|----------------| |
| 10206 |
| Param 1 | |
| 10207 |
|----------------| |
| 10208 |
| Param 2 | |
| 10209 |
|----------------| |
| 10210 |
. . |
| 10211 |
. . |
| 10212 |
. . |
| 10213 |
|----------------| |
| 10214 |
| Param # | |
| 10215 |
|----------------| |
| 10216 |
| ProcSym | Type | Empty |
| 10217 |
|----------------| |
| 10218 |
*) |
| 10219 |
|
| 10220 |
PROCEDURE BuildReFunction (Sym: CARDINAL; ConstExpr: BOOLEAN) ; |
| 10221 |
VAR |
| 10222 |
func, |
| 10223 |
combinedtok, |
| 10224 |
vartok, |
| 10225 |
functok : CARDINAL ; |
| 10226 |
NoOfParam : CARDINAL ; |
| 10227 |
ReturnVar, |
| 10228 |
Type, |
| 10229 |
Var : CARDINAL ; |
| 10230 |
BEGIN |
| 10231 |
PopT (NoOfParam) ; |
| 10232 |
functok := OperandTtok (NoOfParam + 1) ; |
| 10233 |
func := OperandT (NoOfParam + 1) ; |
| 10234 |
IF NoOfParam=1 |
| 10235 |
THEN |
| 10236 |
Var := OperandT (1) ; |
| 10237 |
vartok := OperandTok (1) ; |
| 10238 |
combinedtok := MakeVirtualTok (functok, functok, vartok) ; |
| 10239 |
Type := ComplexToScalar (GetDType (Var)) ; |
| 10240 |
PopN (NoOfParam+1) ; (* destroy arguments to this function *) |
| 10241 |
IF ConstExprError (Sym, Var, vartok, ConstExpr) |
| 10242 |
THEN |
| 10243 |
(* Generate fake result. *) |
| 10244 |
combinedtok := MakeVirtual2Tok (functok, vartok) ; |
| 10245 |
ReturnVar := MakeTemporary (combinedtok, AreConstant (IsConst (Var))) ; |
| 10246 |
PutVar (ReturnVar, Type) ; |
| 10247 |
PushTFtok (ReturnVar, Type, combinedtok) |
| 10248 |
ELSIF IsVar(Var) OR IsConst(Var) |
| 10249 |
THEN |
| 10250 |
ReturnVar := MakeTemporary (combinedtok, AreConstant (IsConst (Var))) ; |
| 10251 |
PutVar (ReturnVar, Type) ; |
| 10252 |
GenQuadO (combinedtok, StandardFunctionOp, ReturnVar, Re, Var, FALSE) ; |
| 10253 |
PushTFtok (ReturnVar, Type, combinedtok) |
| 10254 |
ELSE |
| 10255 |
PushTFtok (MakeConstLit (combinedtok, MakeKey ('1.0'), RType), RType, combinedtok) ; |
| 10256 |
MetaErrorT2 (vartok, |
| 10257 |
'the parameter to the builtin procedure function {%1Ead} must be a constant or a variable, seen {%2ad}', |
| 10258 |
func, Var) |
| 10259 |
END |
| 10260 |
ELSE |
| 10261 |
PopN (NoOfParam+1) ; (* destroy arguments to this function *) |
| 10262 |
PushTFtok (MakeConstLit (functok, MakeKey ('1.0'), RType), RType, functok) ; |
| 10263 |
MetaErrorT2 (functok, |
| 10264 |
'the builtin procedure function {%1Ead} only has one parameter, seen {%2n}', |
| 10265 |
func, NoOfParam) |
| 10266 |
END |
| 10267 |
END BuildReFunction ; |
| 10268 |
|
| 10269 |
|
| 10270 |
(* |
| 10271 |
BuildImFunction - builds the pseudo procedure call IM. |
| 10272 |
|
| 10273 |
The Stack: |
| 10274 |
|
| 10275 |
|
| 10276 |
Entry Exit |
| 10277 |
|
| 10278 |
Ptr -> |
| 10279 |
+----------------+ |
| 10280 |
| NoOfParam | |
| 10281 |
|----------------| |
| 10282 |
| Param 1 | |
| 10283 |
|----------------| |
| 10284 |
| Param 2 | |
| 10285 |
|----------------| |
| 10286 |
. . |
| 10287 |
. . |
| 10288 |
. . |
| 10289 |
|----------------| |
| 10290 |
| Param # | |
| 10291 |
|----------------| |
| 10292 |
| ProcSym | Type | Empty |
| 10293 |
|----------------| |
| 10294 |
*) |
| 10295 |
|
| 10296 |
PROCEDURE BuildImFunction (Sym: CARDINAL; ConstExpr: BOOLEAN) ; |
| 10297 |
VAR |
| 10298 |
func, |
| 10299 |
combinedtok, |
| 10300 |
vartok, |
| 10301 |
functok : CARDINAL ; |
| 10302 |
NoOfParam : CARDINAL ; |
| 10303 |
ReturnVar, |
| 10304 |
Type, |
| 10305 |
Var : CARDINAL ; |
| 10306 |
BEGIN |
| 10307 |
PopT (NoOfParam) ; |
| 10308 |
functok := OperandTtok (NoOfParam + 1) ; |
| 10309 |
func := OperandT (NoOfParam + 1) ; |
| 10310 |
IF NoOfParam=1 |
| 10311 |
THEN |
| 10312 |
Var := OperandT (1) ; |
| 10313 |
vartok := OperandTok (1) ; |
| 10314 |
Type := ComplexToScalar (GetDType (Var)) ; |
| 10315 |
combinedtok := MakeVirtualTok (functok, functok, vartok) ; |
| 10316 |
PopN (NoOfParam+1) ; (* destroy arguments to this function *) |
| 10317 |
IF ConstExprError (Sym, Var, vartok, ConstExpr) |
| 10318 |
THEN |
| 10319 |
(* Generate fake result. *) |
| 10320 |
combinedtok := MakeVirtual2Tok (functok, vartok) ; |
| 10321 |
ReturnVar := MakeTemporary (combinedtok, AreConstant (IsConst (Var))) ; |
| 10322 |
PutVar (ReturnVar, Type) ; |
| 10323 |
PushTFtok (ReturnVar, Type, combinedtok) |
| 10324 |
ELSIF IsVar(Var) OR IsConst(Var) |
| 10325 |
THEN |
| 10326 |
ReturnVar := MakeTemporary (combinedtok, AreConstant (IsConst (Var))) ; |
| 10327 |
PutVar (ReturnVar, ComplexToScalar (GetDType (Var))) ; |
| 10328 |
GenQuadO (combinedtok, StandardFunctionOp, ReturnVar, Im, Var, FALSE) ; |
| 10329 |
PushTFtok (ReturnVar, GetSType (ReturnVar), combinedtok) |
| 10330 |
ELSE |
| 10331 |
PushTFtok (MakeConstLit (combinedtok, MakeKey ('1.0'), RType), RType, combinedtok) ; |
| 10332 |
MetaErrorT2 (vartok, |
| 10333 |
'the parameter to the builtin procedure function {%1Ead} must be a constant or a variable, seen {%2ad}', |
| 10334 |
func, Var) |
| 10335 |
END |
| 10336 |
ELSE |
| 10337 |
PopN (NoOfParam+1) ; (* destroy arguments to this function *) |
| 10338 |
PushTFtok (MakeConstLit (functok, MakeKey ('1.0'), RType), RType, functok) ; |
| 10339 |
MetaErrorT2 (functok, |
| 10340 |
'the builtin procedure function {%1Ead} only has one parameter, seen {%2n}', |
| 10341 |
func, NoOfParam) |
| 10342 |
END |
| 10343 |
END BuildImFunction ; |
| 10344 |
|
| 10345 |
|
| 10346 |
(* |
| 10347 |
BuildCmplxFunction - builds the pseudo procedure call CMPLX. |
| 10348 |
|
| 10349 |
The Stack: |
| 10350 |
|
| 10351 |
|
| 10352 |
Entry Exit |
| 10353 |
|
| 10354 |
Ptr -> |
| 10355 |
+----------------+ |
| 10356 |
| NoOfParam | |
| 10357 |
|----------------| |
| 10358 |
| Param 1 | |
| 10359 |
|----------------| |
| 10360 |
| Param 2 | |
| 10361 |
|----------------| |
| 10362 |
. . |
| 10363 |
. . |
| 10364 |
. . |
| 10365 |
|----------------| |
| 10366 |
| Param # | |
| 10367 |
|----------------| |
| 10368 |
| ProcSym | Type | Empty |
| 10369 |
|----------------| |
| 10370 |
*) |
| 10371 |
|
| 10372 |
PROCEDURE BuildCmplxFunction (func: CARDINAL; ConstExpr: BOOLEAN) ; |
| 10373 |
VAR |
| 10374 |
failure : BOOLEAN ; |
| 10375 |
functok, |
| 10376 |
rtok, ltok, |
| 10377 |
combinedtok: CARDINAL ; |
| 10378 |
NoOfParam : CARDINAL ; |
| 10379 |
type, |
| 10380 |
ReturnVar, |
| 10381 |
l, r : CARDINAL ; |
| 10382 |
BEGIN |
| 10383 |
PopT (NoOfParam) ; |
| 10384 |
functok := OperandTtok (NoOfParam + 1) ; |
| 10385 |
IF NoOfParam = 2 |
| 10386 |
THEN |
| 10387 |
l := OperandT (2) ; |
| 10388 |
ltok := OperandTtok (2) ; |
| 10389 |
r := OperandT (1) ; |
| 10390 |
rtok := OperandTtok (1) ; |
| 10391 |
combinedtok := MakeVirtual2Tok (functok, rtok) ; |
| 10392 |
PopN (NoOfParam+1) ; (* Destroy arguments to this function. *) |
| 10393 |
type := GetCmplxReturnType (GetDType (l), GetDType (r)) ; |
| 10394 |
ReturnVar := MakeTemporary (combinedtok, AreConstant (IsConst (l) AND IsConst (r))) ; |
| 10395 |
PutVar (ReturnVar, type) ; |
| 10396 |
failure := FALSE ; |
| 10397 |
IF ConstExprError (func, l, ltok, ConstExpr) |
| 10398 |
THEN |
| 10399 |
(* ConstExprError has generated an error message we will fall through |
| 10400 |
and check the right operand. *) |
| 10401 |
failure := TRUE |
| 10402 |
END ; |
| 10403 |
IF ConstExprError (func, r, rtok, ConstExpr) |
| 10404 |
THEN |
| 10405 |
(* Right operand is in error as a variable. *) |
| 10406 |
failure := TRUE |
| 10407 |
END ; |
| 10408 |
IF failure |
| 10409 |
THEN |
| 10410 |
(* Generate a fake result if either operand was a variable (and we |
| 10411 |
are in a const expression). *) |
| 10412 |
PushTFtok (ReturnVar, type, combinedtok) |
| 10413 |
ELSIF (IsVar (l) OR IsConst (l)) AND |
| 10414 |
(IsVar (r) OR IsConst (r)) |
| 10415 |
THEN |
| 10416 |
CheckExpressionCompatible (combinedtok, GetSType(l), GetSType(r)) ; |
| 10417 |
GenQuadO (combinedtok, StandardFunctionOp, ReturnVar, Cmplx, Make2Tuple (l, r), TRUE) ; |
| 10418 |
PushTFtok (ReturnVar, type, combinedtok) |
| 10419 |
ELSE |
| 10420 |
IF IsVar (l) OR IsConst (l) |
| 10421 |
THEN |
| 10422 |
MetaErrorT2 (functok, |
| 10423 |
'the builtin procedure {%1Ead} requires two parameters, both must be variables or constants but the second parameter is {%2d}', |
| 10424 |
func, r) |
| 10425 |
ELSE |
| 10426 |
MetaErrorT2 (functok, |
| 10427 |
'the builtin procedure {%1Ead} requires two parameters, both must be variables or constants but the first parameter is {%2d}', |
| 10428 |
func, l) |
| 10429 |
END ; |
| 10430 |
PushTFtok (MakeConstLit (combinedtok, MakeKey ('1.0'), CType), CType, combinedtok) |
| 10431 |
END |
| 10432 |
ELSE |
| 10433 |
MetaErrorT2 (functok, |
| 10434 |
'the builtin procedure {%1Ead} requires two parameters, seen {%2n}', |
| 10435 |
func, NoOfParam) ; |
| 10436 |
PopN (NoOfParam + 1) ; (* destroy arguments to this function *) |
| 10437 |
PushTFtok (MakeConstLit (functok, MakeKey ('1.0'), CType), CType, functok) |
| 10438 |
END |
| 10439 |
END BuildCmplxFunction ; |
| 10440 |
|
| 10441 |
|
| 10442 |
(* |
| 10443 |
BuildAdrFunction - builds the pseudo function ADR |
| 10444 |
The Stack: |
| 10445 |
|
| 10446 |
|
| 10447 |
Entry Exit |
| 10448 |
|
| 10449 |
Ptr -> |
| 10450 |
+----------------+ |
| 10451 |
| NoOfParam | |
| 10452 |
|----------------| |
| 10453 |
| Param 1 | |
| 10454 |
|----------------| |
| 10455 |
| Param 2 | |
| 10456 |
|----------------| |
| 10457 |
. . |
| 10458 |
. . |
| 10459 |
. . |
| 10460 |
|----------------| |
| 10461 |
| Param # | <- Ptr |
| 10462 |
|----------------| +------------+ |
| 10463 |
| ProcSym | Type | | ReturnVar | |
| 10464 |
|----------------| |------------| |
| 10465 |
|
| 10466 |
*) |
| 10467 |
|
| 10468 |
PROCEDURE BuildAdrFunction ; |
| 10469 |
VAR |
| 10470 |
endtok, |
| 10471 |
combinedTok, |
| 10472 |
procTok, |
| 10473 |
t, |
| 10474 |
UnboundedSym, |
| 10475 |
Dim, |
| 10476 |
Field, |
| 10477 |
noOfParameters, |
| 10478 |
procSym, |
| 10479 |
returnVar, |
| 10480 |
Type, rw : CARDINAL ; |
| 10481 |
BEGIN |
| 10482 |
DisplayStack ; |
| 10483 |
PopT (noOfParameters) ; |
| 10484 |
procSym := OperandT (noOfParameters + 1) ; |
| 10485 |
procTok := OperandTok (noOfParameters + 1) ; (* token of procedure ADR. *) |
| 10486 |
endtok := OperandTok (1) ; (* last parameter. *) |
| 10487 |
combinedTok := MakeVirtualTok (procTok, procTok, endtok) ; |
| 10488 |
IF noOfParameters # 1 |
| 10489 |
THEN |
| 10490 |
MetaErrorNT0 (combinedTok, |
| 10491 |
'SYSTEM procedure ADR expects 1 parameter') ; |
| 10492 |
PopN (noOfParameters + 1) ; (* destroy the arguments and function *) |
| 10493 |
PushTF (Nil, Address) |
| 10494 |
ELSIF IsConstString (OperandT (1)) |
| 10495 |
THEN |
| 10496 |
returnVar := MakeLeftValue (combinedTok, OperandT (1), RightValue, |
| 10497 |
GetSType (procSym)) ; |
| 10498 |
PopN (noOfParameters + 1) ; (* destroy the arguments and function *) |
| 10499 |
PushTFtok (returnVar, GetSType (returnVar), combinedTok) |
| 10500 |
ELSIF (NOT IsVar(OperandT(1))) AND (NOT IsProcedure(OperandT(1))) |
| 10501 |
THEN |
| 10502 |
MetaErrorNT0 (combinedTok, |
| 10503 |
'SYSTEM procedure ADR expects a variable, procedure or a constant string as its parameter') ; |
| 10504 |
PopN (noOfParameters + 1) ; (* destroy the arguments and function *) |
| 10505 |
PushTFtok (Nil, Address, combinedTok) |
| 10506 |
ELSIF IsProcedure (OperandT (1)) |
| 10507 |
THEN |
| 10508 |
returnVar := MakeLeftValue (combinedTok, OperandT (1), RightValue, |
| 10509 |
GetSType (procSym)) ; |
| 10510 |
PopN (noOfParameters + 1) ; (* destroy the arguments and function *) |
| 10511 |
PushTFtok (returnVar, GetSType (returnVar), combinedTok) |
| 10512 |
ELSE |
| 10513 |
Type := GetSType (OperandT (1)) ; |
| 10514 |
Dim := OperandD (1) ; |
| 10515 |
MarkArrayWritten (OperandT (1)) ; |
| 10516 |
MarkArrayWritten (OperandA (1)) ; |
| 10517 |
(* if the operand is an unbounded which has not been indexed |
| 10518 |
then we will lookup its address from the unbounded record. |
| 10519 |
Otherwise we obtain the address of the operand. |
| 10520 |
*) |
| 10521 |
IF IsUnbounded (Type) AND (Dim = 0) |
| 10522 |
THEN |
| 10523 |
(* we will reference the address field of the unbounded structure *) |
| 10524 |
UnboundedSym := OperandT (1) ; |
| 10525 |
rw := OperandRW (1) ; |
| 10526 |
PushTFrw (UnboundedSym, GetSType (UnboundedSym), rw) ; |
| 10527 |
Field := GetUnboundedAddressOffset (GetSType (UnboundedSym)) ; |
| 10528 |
PushTF (Field, GetSType (Field)) ; |
| 10529 |
PushT (1) ; |
| 10530 |
BuildDesignatorRecord (combinedTok) ; |
| 10531 |
PopTrw (returnVar, rw) ; |
| 10532 |
IF GetMode (returnVar) = LeftValue |
| 10533 |
THEN |
| 10534 |
t := MakeTemporary (combinedTok, RightValue) ; |
| 10535 |
PutVar (t, GetSType (procSym)) ; |
| 10536 |
doIndrX (combinedTok, t, returnVar) ; |
| 10537 |
returnVar := t |
| 10538 |
ELSE |
| 10539 |
(* we need to cast returnVar into ADDRESS *) |
| 10540 |
t := MakeTemporary (combinedTok, RightValue) ; |
| 10541 |
PutVar (t, GetSType (procSym)) ; |
| 10542 |
GenQuadO (combinedTok, ConvertOp, t, GetSType (procSym), returnVar, FALSE) ; |
| 10543 |
returnVar := t |
| 10544 |
END |
| 10545 |
ELSE |
| 10546 |
returnVar := MakeTemporary (combinedTok, RightValue) ; |
| 10547 |
PutVar (returnVar, GetSType (procSym)) ; |
| 10548 |
IF GetMode (OperandT (1)) = LeftValue |
| 10549 |
THEN |
| 10550 |
PutVar (returnVar, GetSType (procSym)) ; |
| 10551 |
GenQuadO (combinedTok, ConvertOp, returnVar, GetSType (procSym), OperandT (1), FALSE) |
| 10552 |
ELSE |
| 10553 |
GenQuadO (combinedTok, AddrOp, returnVar, NulSym, OperandT (1), FALSE) |
| 10554 |
END ; |
| 10555 |
PutWriteQuad (OperandT (1), GetMode (OperandT (1)), NextQuad-1) ; |
| 10556 |
rw := OperandMergeRW (1) ; |
| 10557 |
Assert (IsLegal (rw)) |
| 10558 |
END ; |
| 10559 |
PopN (noOfParameters + 1) ; (* destroy the arguments and function *) |
| 10560 |
PushTFrwtok (returnVar, GetSType (returnVar), rw, combinedTok) |
| 10561 |
END |
| 10562 |
END BuildAdrFunction ; |
| 10563 |
|
| 10564 |
|
| 10565 |
(* |
| 10566 |
BuildSizeFunction - builds the pseudo function SIZE |
| 10567 |
The Stack: |
| 10568 |
|
| 10569 |
|
| 10570 |
Entry Exit |
| 10571 |
|
| 10572 |
Ptr -> |
| 10573 |
+----------------+ |
| 10574 |
| NoOfParam | |
| 10575 |
|----------------| |
| 10576 |
| Param 1 | |
| 10577 |
|----------------| |
| 10578 |
| Param 2 | |
| 10579 |
|----------------| |
| 10580 |
. . |
| 10581 |
. . |
| 10582 |
. . |
| 10583 |
|----------------| |
| 10584 |
| Param # | <- Ptr |
| 10585 |
|----------------| +------------+ |
| 10586 |
| ProcSym | Type | | ReturnVar | |
| 10587 |
|----------------| |------------| |
| 10588 |
*) |
| 10589 |
|
| 10590 |
PROCEDURE BuildSizeFunction ; |
| 10591 |
VAR |
| 10592 |
resulttok, |
| 10593 |
paramtok, |
| 10594 |
functok : CARDINAL ; |
| 10595 |
dim : CARDINAL ; |
| 10596 |
Type, |
| 10597 |
NoOfParam, |
| 10598 |
ProcSym, |
| 10599 |
ReturnVar : CARDINAL ; |
| 10600 |
BEGIN |
| 10601 |
PopT (NoOfParam) ; |
| 10602 |
ProcSym := OperandT (NoOfParam + 1) ; |
| 10603 |
functok := OperandTtok (NoOfParam + 1) ; |
| 10604 |
IF NoOfParam # 1 |
| 10605 |
THEN |
| 10606 |
MetaErrorT1 (functok, |
| 10607 |
'{%E} SYSTEM procedure function {%kSIZE} requires one parameter, seen {%1n}', |
| 10608 |
NoOfParam) ; |
| 10609 |
resulttok := functok ; |
| 10610 |
ReturnVar := MakeConstLit (resulttok, MakeKey('0'), Cardinal) |
| 10611 |
ELSIF IsAModula2Type (OperandT (1)) |
| 10612 |
THEN |
| 10613 |
paramtok := OperandTok (1) ; |
| 10614 |
resulttok := MakeVirtualTok (functok, functok, paramtok) ; |
| 10615 |
BuildSizeCheckEnd (ProcSym) ; (* Quadruple generation now on. *) |
| 10616 |
ReturnVar := MakeTemporary (resulttok, ImmediateValue) ; |
| 10617 |
GenQuadO (resulttok, SizeOp, ReturnVar, NulSym, OperandT(1), TRUE) |
| 10618 |
ELSIF IsVar (OperandT (1)) |
| 10619 |
THEN |
| 10620 |
BuildSizeCheckEnd (ProcSym) ; (* Quadruple generation now on. *) |
| 10621 |
Type := GetSType (OperandT (1)) ; |
| 10622 |
paramtok := OperandTok (1) ; |
| 10623 |
resulttok := MakeVirtualTok (functok, functok, paramtok) ; |
| 10624 |
IF IsUnbounded (Type) |
| 10625 |
THEN |
| 10626 |
(* Eg. SIZE(a) ; where a is unbounded dereference HIGH and multiply by the TYPE. *) |
| 10627 |
dim := OperandD (1) ; |
| 10628 |
IF dim = 0 |
| 10629 |
THEN |
| 10630 |
ReturnVar := calculateMultipicand (resulttok, OperandT (1), Type, dim) |
| 10631 |
ELSE |
| 10632 |
ReturnVar := calculateMultipicand (resulttok, OperandA (1), Type, dim) |
| 10633 |
END |
| 10634 |
ELSE |
| 10635 |
ReturnVar := MakeTemporary (resulttok, ImmediateValue) ; |
| 10636 |
IF Type = NulSym |
| 10637 |
THEN |
| 10638 |
MetaErrorT1 (resulttok, |
| 10639 |
'cannot get the type and size of {%1Ead}', OperandT (1)) |
| 10640 |
END ; |
| 10641 |
GenQuadO (resulttok, SizeOp, ReturnVar, NulSym, Type, TRUE) |
| 10642 |
END |
| 10643 |
ELSE |
| 10644 |
resulttok := functok ; |
| 10645 |
MetaErrorT1 (resulttok, |
| 10646 |
'{%E}SYSTEM procedure {%kSIZE} expects a variable as its parameter, seen {%1Ed}', |
| 10647 |
OperandT (1)) ; |
| 10648 |
ReturnVar := MakeConstLit (resulttok, MakeKey('0'), Cardinal) |
| 10649 |
END ; |
| 10650 |
PopN (NoOfParam+1) ; (* Destroy the arguments and function. *) |
| 10651 |
PushTFtok (ReturnVar, GetSType(ProcSym), resulttok) |
| 10652 |
END BuildSizeFunction ; |
| 10653 |
|
| 10654 |
|
| 10655 |
(* |
| 10656 |
BuildTSizeFunction - builds the pseudo function TSIZE |
| 10657 |
The Stack: |
| 10658 |
|
| 10659 |
|
| 10660 |
Entry Exit |
| 10661 |
|
| 10662 |
Ptr -> |
| 10663 |
+----------------+ |
| 10664 |
| NoOfParam | |
| 10665 |
|----------------| |
| 10666 |
| Param 1 | |
| 10667 |
|----------------| |
| 10668 |
| Param 2 | |
| 10669 |
|----------------| |
| 10670 |
. . |
| 10671 |
. . |
| 10672 |
. . |
| 10673 |
|----------------| |
| 10674 |
| Param # | <- Ptr |
| 10675 |
|----------------| +------------+ |
| 10676 |
| ProcSym | Type | | ReturnVar | |
| 10677 |
|----------------| |------------| |
| 10678 |
|
| 10679 |
*) |
| 10680 |
|
| 10681 |
PROCEDURE BuildTSizeFunction ; |
| 10682 |
VAR |
| 10683 |
resulttok, |
| 10684 |
paramtok, |
| 10685 |
functok : CARDINAL ; |
| 10686 |
NoOfParam: CARDINAL ; |
| 10687 |
ProcSym, |
| 10688 |
Record, |
| 10689 |
ReturnVar: CARDINAL ; |
| 10690 |
BEGIN |
| 10691 |
PopT (NoOfParam) ; |
| 10692 |
ProcSym := OperandT (NoOfParam + 1) ; |
| 10693 |
functok := OperandTtok (NoOfParam) ; |
| 10694 |
BuildSizeCheckEnd (ProcSym) ; (* quadruple generation now on *) |
| 10695 |
IF NoOfParam = 1 |
| 10696 |
THEN |
| 10697 |
paramtok := OperandTtok (1) ; |
| 10698 |
resulttok := MakeVirtualTok (functok, functok, paramtok) ; |
| 10699 |
IF IsAModula2Type (OperandT (1)) |
| 10700 |
THEN |
| 10701 |
ReturnVar := MakeTemporary (resulttok, ImmediateValue) ; |
| 10702 |
PutVar (ReturnVar, Cardinal) ; |
| 10703 |
GenQuadO (resulttok, SizeOp, ReturnVar, NulSym, OperandT (1), FALSE) |
| 10704 |
ELSIF IsVar (OperandT (1)) |
| 10705 |
THEN |
| 10706 |
ReturnVar := MakeTemporary (resulttok, ImmediateValue) ; |
| 10707 |
PutVar (ReturnVar, Cardinal) ; |
| 10708 |
GenQuadO (resulttok, SizeOp, ReturnVar, NulSym, GetSType (OperandT (1)), FALSE) |
| 10709 |
ELSE |
| 10710 |
MetaErrorT1 (resulttok, |
| 10711 |
'{%E}SYSTEM procedure function {%kTSIZE} expects a variable as its first parameter, seen {%1Ed}', |
| 10712 |
OperandT (1)) ; |
| 10713 |
ReturnVar := MakeConstLit (resulttok, MakeKey ('0'), Cardinal) |
| 10714 |
END |
| 10715 |
ELSIF NoOfParam = 0 |
| 10716 |
THEN |
| 10717 |
resulttok := functok ; |
| 10718 |
MetaErrorT0 (resulttok, |
| 10719 |
'{%E}SYSTEM procedure function {%kTSIZE} expects either one or two parameters, seen none') ; |
| 10720 |
ReturnVar := MakeConstLit (resulttok, MakeKey ('0'), Cardinal) |
| 10721 |
ELSE |
| 10722 |
Record := OperandT (NoOfParam) ; |
| 10723 |
paramtok := OperandTtok (1) ; |
| 10724 |
resulttok := OperandTtok (NoOfParam) ; |
| 10725 |
IF IsRecord (Record) |
| 10726 |
THEN |
| 10727 |
paramtok := OperandTtok (1) ; |
| 10728 |
resulttok := MakeVirtualTok (functok, functok, paramtok) ; |
| 10729 |
ReturnVar := MakeTemporary (resulttok, ImmediateValue) ; |
| 10730 |
PutVar (ReturnVar, Cardinal) ; |
| 10731 |
GenQuadO (resulttok, SizeOp, ReturnVar, NulSym, Record, FALSE) |
| 10732 |
ELSE |
| 10733 |
resulttok := MakeVirtualTok (functok, functok, paramtok) ; |
| 10734 |
MetaErrorT1 (resulttok, |
| 10735 |
'{%E}SYSTEM procedure function {%kTSIZE} expects the first parameter to be a record type, seen {%1d}', |
| 10736 |
Record) ; |
| 10737 |
ReturnVar := MakeConstLit (resulttok, MakeKey ('0'), Cardinal) |
| 10738 |
END |
| 10739 |
END ; |
| 10740 |
PopN (NoOfParam+1) ; (* destroy the arguments and function *) |
| 10741 |
PushTFtok (ReturnVar, GetSType (ProcSym), resulttok) |
| 10742 |
END BuildTSizeFunction ; |
| 10743 |
|
| 10744 |
|
| 10745 |
(* |
| 10746 |
BuildTBitSizeFunction - builds the pseudo function TBITSIZE |
| 10747 |
The Stack: |
| 10748 |
|
| 10749 |
|
| 10750 |
Entry Exit |
| 10751 |
|
| 10752 |
Ptr -> |
| 10753 |
+----------------+ |
| 10754 |
| NoOfParam | |
| 10755 |
|----------------| |
| 10756 |
| Param 1 | |
| 10757 |
|----------------| |
| 10758 |
| Param 2 | |
| 10759 |
|----------------| |
| 10760 |
. . |
| 10761 |
. . |
| 10762 |
. . |
| 10763 |
|----------------| |
| 10764 |
| Param # | <- Ptr |
| 10765 |
|----------------| +------------+ |
| 10766 |
| ProcSym | Type | | ReturnVar | |
| 10767 |
|----------------| |------------| |
| 10768 |
|
| 10769 |
*) |
| 10770 |
|
| 10771 |
PROCEDURE BuildTBitSizeFunction ; |
| 10772 |
VAR |
| 10773 |
resulttok, |
| 10774 |
paramtok, |
| 10775 |
functok : CARDINAL ; |
| 10776 |
NoOfParam: CARDINAL ; |
| 10777 |
ProcSym, |
| 10778 |
Record, |
| 10779 |
ReturnVar: CARDINAL ; |
| 10780 |
BEGIN |
| 10781 |
PopT (NoOfParam) ; |
| 10782 |
ProcSym := OperandT (NoOfParam + 1) ; |
| 10783 |
functok := OperandTtok (NoOfParam) ; |
| 10784 |
BuildSizeCheckEnd (ProcSym) ; (* quadruple generation now on *) |
| 10785 |
IF NoOfParam = 1 |
| 10786 |
THEN |
| 10787 |
paramtok := OperandTtok (1) ; |
| 10788 |
resulttok := MakeVirtualTok (functok, functok, paramtok) ; |
| 10789 |
IF IsAModula2Type (OperandT (1)) |
| 10790 |
THEN |
| 10791 |
ReturnVar := MakeTemporary (resulttok, ImmediateValue) ; |
| 10792 |
GenQuadO (resulttok, StandardFunctionOp, ReturnVar, ProcSym, OperandT (1), FALSE) |
| 10793 |
ELSIF IsVar (OperandT (1)) |
| 10794 |
THEN |
| 10795 |
ReturnVar := MakeTemporary (resulttok, ImmediateValue) ; |
| 10796 |
GenQuadO (resulttok, StandardFunctionOp, ReturnVar, ProcSym, OperandT(1), FALSE) |
| 10797 |
ELSE |
| 10798 |
MetaErrorT1 (resulttok, |
| 10799 |
'{%E}SYSTEM procedure function {%kTBITSIZE} expects a variable as its first parameter, seen {%1d}', |
| 10800 |
OperandT (1)) ; |
| 10801 |
ReturnVar := MakeConstLit (resulttok, MakeKey ('0'), Cardinal) |
| 10802 |
END |
| 10803 |
ELSIF NoOfParam = 0 |
| 10804 |
THEN |
| 10805 |
resulttok := functok ; |
| 10806 |
MetaErrorT0 (functok, |
| 10807 |
'{%E}SYSTEM procedure function {%kTBITSIZE} expects either one or two parameters, seen none') ; |
| 10808 |
ReturnVar := MakeConstLit (functok, MakeKey ('0'), Cardinal) |
| 10809 |
ELSE |
| 10810 |
Record := OperandT (NoOfParam) ; |
| 10811 |
paramtok := OperandTtok (1) ; |
| 10812 |
resulttok := OperandTtok (NoOfParam) ; |
| 10813 |
IF IsRecord (Record) |
| 10814 |
THEN |
| 10815 |
paramtok := OperandTtok (1) ; |
| 10816 |
resulttok := MakeVirtualTok (functok, functok, paramtok) ; |
| 10817 |
ReturnVar := MakeTemporary (resulttok, ImmediateValue) ; |
| 10818 |
GenQuad(StandardFunctionOp, ReturnVar, ProcSym, OperandT(1)) ; |
| 10819 |
ELSE |
| 10820 |
resulttok := MakeVirtualTok (functok, functok, paramtok) ; |
| 10821 |
MetaErrorT1 (resulttok, |
| 10822 |
'{%E}SYSTEM procedure function {%kTBITSIZE} expects the first parameter to be a record type, seen {%1d}', |
| 10823 |
Record) ; |
| 10824 |
ReturnVar := MakeConstLit (resulttok, MakeKey ('0'), Cardinal) |
| 10825 |
END |
| 10826 |
END ; |
| 10827 |
PopN (NoOfParam + 1) ; (* destroy the arguments and function *) |
| 10828 |
PushTFtok (ReturnVar, GetSType (ProcSym), resulttok) |
| 10829 |
END BuildTBitSizeFunction ; |
| 10830 |
|
| 10831 |
|
| 10832 |
(* |
| 10833 |
ExpectingParameterType - |
| 10834 |
*) |
| 10835 |
|
| 10836 |
PROCEDURE ExpectingParameterType (BlockSym, Type: CARDINAL) ; |
| 10837 |
BEGIN |
| 10838 |
IF NOT IsAModula2Type (Type) |
| 10839 |
THEN |
| 10840 |
IF (Type = NulSym) OR IsPartialUnbounded (Type) OR IsUnknown (Type) |
| 10841 |
THEN |
| 10842 |
MetaError1 ('the type used in the formal parameter declaration in {%1Md} {%1a} is unknown', |
| 10843 |
BlockSym) |
| 10844 |
ELSE |
| 10845 |
MetaError2 ('the type {%1Ead} used in the formal parameter declaration in {%2Md} {%2a} was not declared as a type', |
| 10846 |
Type, BlockSym) |
| 10847 |
END |
| 10848 |
END |
| 10849 |
END ExpectingParameterType ; |
| 10850 |
|
| 10851 |
|
| 10852 |
(* |
| 10853 |
ExpectingVariableType - |
| 10854 |
*) |
| 10855 |
|
| 10856 |
PROCEDURE ExpectingVariableType (BlockSym, Type: CARDINAL) ; |
| 10857 |
BEGIN |
| 10858 |
IF NOT IsAModula2Type(Type) |
| 10859 |
THEN |
| 10860 |
IF Type=NulSym |
| 10861 |
THEN |
| 10862 |
MetaError1 ('the type used during the variable declaration section in procedure {%1EMad} is unknown', |
| 10863 |
BlockSym) ; |
| 10864 |
MetaError1 ('the type used during the variable declaration section in procedure {%1Ead} is unknown', |
| 10865 |
BlockSym) |
| 10866 |
ELSIF IsPartialUnbounded(Type) OR IsUnknown(Type) |
| 10867 |
THEN |
| 10868 |
MetaError2 ('the type {%1EMad} used during variable declaration section in procedure {%2ad} is unknown', |
| 10869 |
Type, BlockSym) ; |
| 10870 |
MetaError2 ('the type {%1Ead} used during variable declaration section in procedure {%2Mad} is unknown', |
| 10871 |
Type, BlockSym) |
| 10872 |
ELSE |
| 10873 |
MetaError2 ('the {%1d} {%1Ea} is not a type and therefore cannot be used to declare a variable in {%2d} {%2a}', |
| 10874 |
Type, BlockSym) |
| 10875 |
END |
| 10876 |
END |
| 10877 |
END ExpectingVariableType ; |
| 10878 |
|
| 10879 |
|
| 10880 |
(* |
| 10881 |
CheckVariablesAndParameterTypesInBlock - checks to make sure that block, BlockSym, has |
| 10882 |
parameters types and variable types which are legal. |
| 10883 |
*) |
| 10884 |
|
| 10885 |
PROCEDURE CheckVariablesAndParameterTypesInBlock (BlockSym: CARDINAL) ; |
| 10886 |
VAR |
| 10887 |
i, n, |
| 10888 |
ParamNo: CARDINAL ; |
| 10889 |
BEGIN |
| 10890 |
IF IsProcedure(BlockSym) |
| 10891 |
THEN |
| 10892 |
ParamNo := NoOfParamAny (BlockSym) |
| 10893 |
ELSE |
| 10894 |
ParamNo := 0 |
| 10895 |
END ; |
| 10896 |
i := 1 ; |
| 10897 |
REPEAT |
| 10898 |
n := GetNth(BlockSym, i) ; |
| 10899 |
IF (n#NulSym) AND (NOT IsTemporary(n)) AND |
| 10900 |
(IsProcedure(BlockSym) OR ((IsDefImp(BlockSym) AND (GetMainModule()=BlockSym)) OR IsModule(BlockSym))) |
| 10901 |
THEN |
| 10902 |
IF i<=ParamNo |
| 10903 |
THEN |
| 10904 |
(* n is a parameter *) |
| 10905 |
ExpectingParameterType(BlockSym, GetSType(n)) |
| 10906 |
ELSE |
| 10907 |
(* n is a local variable *) |
| 10908 |
ExpectingVariableType(BlockSym, GetSType(n)) |
| 10909 |
END |
| 10910 |
END ; |
| 10911 |
INC(i) |
| 10912 |
UNTIL n=NulSym ; |
| 10913 |
END CheckVariablesAndParameterTypesInBlock ; |
| 10914 |
|
| 10915 |
|
| 10916 |
(* |
| 10917 |
BuildProcedureStart - Builds start of the procedure. Generates a |
| 10918 |
quadruple which indicated the start of |
| 10919 |
this procedure declarations scope. |
| 10920 |
The Stack is expected to contain: |
| 10921 |
|
| 10922 |
|
| 10923 |
Entry Exit |
| 10924 |
===== ==== |
| 10925 |
|
| 10926 |
Ptr -> <- Ptr |
| 10927 |
+------------+ +-----------+ |
| 10928 |
| ProcSym | | ProcSym | |
| 10929 |
|------------| |-----------| |
| 10930 |
| Name | | Name | |
| 10931 |
|------------| |-----------| |
| 10932 |
|
| 10933 |
|
| 10934 |
Quadruples: |
| 10935 |
|
| 10936 |
q ProcedureScopeOp Line# Scope ProcSym |
| 10937 |
*) |
| 10938 |
|
| 10939 |
PROCEDURE BuildProcedureStart ; |
| 10940 |
VAR |
| 10941 |
ProcSym: CARDINAL ; |
| 10942 |
BEGIN |
| 10943 |
PopT(ProcSym) ; |
| 10944 |
Assert(IsProcedure(ProcSym)) ; |
| 10945 |
PutProcedureScopeQuad(ProcSym, NextQuad) ; |
| 10946 |
GenQuad(ProcedureScopeOp, GetPreviousTokenLineNo(), GetScope(ProcSym), ProcSym) ; |
| 10947 |
PushT(ProcSym) |
| 10948 |
END BuildProcedureStart ; |
| 10949 |
|
| 10950 |
|
| 10951 |
(* |
| 10952 |
BuildProcedureBegin - determines the start of the BEGIN END block of |
| 10953 |
the procedure. |
| 10954 |
The Stack is expected to contain: |
| 10955 |
|
| 10956 |
|
| 10957 |
Entry Exit |
| 10958 |
===== ==== |
| 10959 |
|
| 10960 |
Ptr -> <- Ptr |
| 10961 |
+------------+ +-----------+ |
| 10962 |
| ProcSym | | ProcSym | |
| 10963 |
|------------| |-----------| |
| 10964 |
| Name | | Name | |
| 10965 |
|------------| |-----------| |
| 10966 |
|
| 10967 |
|
| 10968 |
Quadruples: |
| 10969 |
|
| 10970 |
q NewLocalVarOp TokenNo(BEGIN) _ ProcSym |
| 10971 |
*) |
| 10972 |
|
| 10973 |
PROCEDURE BuildProcedureBegin ; |
| 10974 |
VAR |
| 10975 |
ProcSym: CARDINAL ; |
| 10976 |
BEGIN |
| 10977 |
PopT(ProcSym) ; |
| 10978 |
Assert(IsProcedure(ProcSym)) ; |
| 10979 |
PutProcedureStartQuad(ProcSym, NextQuad) ; |
| 10980 |
PutProcedureBegin(ProcSym, GetTokenNo()) ; |
| 10981 |
GenQuad(NewLocalVarOp, GetTokenNo(), GetScope(ProcSym), ProcSym) ; |
| 10982 |
CurrentProc := ProcSym ; |
| 10983 |
PushWord(ReturnStack, 0) ; |
| 10984 |
PushT(ProcSym) ; |
| 10985 |
CheckVariablesAt(ProcSym) ; |
| 10986 |
CheckNeedPriorityBegin(GetTokenNo(), ProcSym, GetCurrentModule()) ; |
| 10987 |
PushWord(TryStack, NextQuad) ; |
| 10988 |
PushWord(CatchStack, 0) ; |
| 10989 |
IF HasExceptionBlock(ProcSym) |
| 10990 |
THEN |
| 10991 |
GenQuad(TryOp, NulSym, NulSym, 0) |
| 10992 |
END |
| 10993 |
END BuildProcedureBegin ; |
| 10994 |
|
| 10995 |
|
| 10996 |
(* |
| 10997 |
BuildProcedureEnd - Builds end of the procedure. Destroys space for |
| 10998 |
the local variables. |
| 10999 |
The Stack is expected to contain: |
| 11000 |
|
| 11001 |
|
| 11002 |
Entry Exit |
| 11003 |
===== ==== |
| 11004 |
|
| 11005 |
Ptr -> <- Ptr |
| 11006 |
+------------+ +-----------+ |
| 11007 |
| ProcSym | | ProcSym | |
| 11008 |
|------------| |-----------| |
| 11009 |
| Name | | Name | |
| 11010 |
|------------| |-----------| |
| 11011 |
|
| 11012 |
|
| 11013 |
Quadruples: |
| 11014 |
|
| 11015 |
q KillLocalVarOp TokenNo(END) _ ProcSym |
| 11016 |
*) |
| 11017 |
|
| 11018 |
PROCEDURE BuildProcedureEnd ; |
| 11019 |
VAR |
| 11020 |
tok : CARDINAL ; |
| 11021 |
ProcSym: CARDINAL ; |
| 11022 |
BEGIN |
| 11023 |
PopTtok(ProcSym, tok) ; |
| 11024 |
IF HasExceptionBlock(ProcSym) |
| 11025 |
THEN |
| 11026 |
BuildRTExceptLeave(tok, TRUE) ; |
| 11027 |
GenQuad(CatchEndOp, NulSym, NulSym, NulSym) |
| 11028 |
END ; |
| 11029 |
IF GetSType(ProcSym)#NulSym |
| 11030 |
THEN |
| 11031 |
BuildError(InitNoReturnRangeCheck()) |
| 11032 |
END ; |
| 11033 |
BackPatch(PopWord(ReturnStack), NextQuad) ; |
| 11034 |
CheckNeedPriorityEnd(tok, ProcSym, GetCurrentModule()) ; |
| 11035 |
CurrentProc := NulSym ; |
| 11036 |
PutProcedureEnd(ProcSym, GetTokenNo()-1) ; (* --fixme-- *) |
| 11037 |
GenQuad(KillLocalVarOp, GetTokenNo()-1, NulSym, ProcSym) ; |
| 11038 |
PutProcedureEndQuad(ProcSym, NextQuad) ; |
| 11039 |
GenQuad(ReturnOp, NulSym, NulSym, ProcSym) ; |
| 11040 |
CheckFunctionReturn(ProcSym) ; |
| 11041 |
CheckVariablesInBlock(ProcSym) ; |
| 11042 |
(* Call PutProcedureEndQuad so that any runtime procedure will be |
| 11043 |
seen as defined even if it not seen during pass 2 (which will also |
| 11044 |
call PutProcedureEndQuad). *) |
| 11045 |
PutProcedureParametersDefined (ProcSym, ProperProcedure) ; |
| 11046 |
PutProcedureDefined (ProcSym, ProperProcedure) ; |
| 11047 |
RemoveTop (CatchStack) ; |
| 11048 |
RemoveTop (TryStack) ; |
| 11049 |
PushT(ProcSym) |
| 11050 |
END BuildProcedureEnd ; |
| 11051 |
|
| 11052 |
|
| 11053 |
(* |
| 11054 |
IsNeverAltered - returns TRUE if variable, sym, is never altered |
| 11055 |
between quadruples: Start..End |
| 11056 |
*) |
| 11057 |
|
| 11058 |
PROCEDURE IsNeverAltered (sym: CARDINAL; Start, End: CARDINAL) : BOOLEAN ; |
| 11059 |
VAR |
| 11060 |
WriteStart, WriteEnd: CARDINAL ; |
| 11061 |
BEGIN |
| 11062 |
GetWriteLimitQuads (sym, GetMode (sym), Start, End, WriteStart, WriteEnd) ; |
| 11063 |
RETURN( (WriteStart = 0) AND (WriteEnd = 0) ) |
| 11064 |
END IsNeverAltered ; |
| 11065 |
|
| 11066 |
|
| 11067 |
(* |
| 11068 |
IsConditionVariable - returns TRUE if the condition at quadruple, q, is variable. |
| 11069 |
*) |
| 11070 |
|
| 11071 |
PROCEDURE IsConditionVariable (q: CARDINAL; Start, End: CARDINAL) : BOOLEAN ; |
| 11072 |
VAR |
| 11073 |
op : QuadOperator ; |
| 11074 |
op1, op2, op3: CARDINAL ; |
| 11075 |
LeftFixed, |
| 11076 |
RightFixed : BOOLEAN ; |
| 11077 |
BEGIN |
| 11078 |
GetQuad (q, op, op1, op2, op3) ; |
| 11079 |
IF op = GotoOp |
| 11080 |
THEN |
| 11081 |
RETURN( FALSE ) |
| 11082 |
ELSE |
| 11083 |
LeftFixed := IsConst(op1) ; |
| 11084 |
RightFixed := IsConst(op2) ; |
| 11085 |
IF NOT LeftFixed |
| 11086 |
THEN |
| 11087 |
LeftFixed := IsNeverAltered(op1, Start, End) |
| 11088 |
END ; |
| 11089 |
IF NOT RightFixed |
| 11090 |
THEN |
| 11091 |
RightFixed := IsNeverAltered(op2, Start, End) |
| 11092 |
END ; |
| 11093 |
RETURN( NOT (LeftFixed AND RightFixed) ) |
| 11094 |
END |
| 11095 |
END IsConditionVariable ; |
| 11096 |
|
| 11097 |
|
| 11098 |
(* |
| 11099 |
IsInfiniteLoop - returns TRUE if an infinite loop is found. |
| 11100 |
Given a backwards jump at, End, it returns a BOOLEAN which depends on |
| 11101 |
whether a jump is found to jump beyond, End. If a conditonal jump is found |
| 11102 |
to pass over, End, the condition is tested for global variables, procedure variables and |
| 11103 |
constants. |
| 11104 |
|
| 11105 |
constant - ignored |
| 11106 |
variables - tested to see whether they are altered inside the loop |
| 11107 |
global variable - the procedure tests to see whether it is altered as above |
| 11108 |
but will also test to see whether this loop calls a procedure |
| 11109 |
in which case it believes the loop NOT to be infinite |
| 11110 |
(as this procedure call might alter the global variable) |
| 11111 |
|
| 11112 |
Note that this procedure can easily be fooled by the user altering variables |
| 11113 |
with pointers. |
| 11114 |
*) |
| 11115 |
|
| 11116 |
PROCEDURE IsInfiniteLoop (End: CARDINAL) : BOOLEAN ; |
| 11117 |
VAR |
| 11118 |
SeenCall, |
| 11119 |
IsGlobal : BOOLEAN ; |
| 11120 |
Current, |
| 11121 |
Start : CARDINAL ; |
| 11122 |
op : QuadOperator ; |
| 11123 |
op1, op2, op3: CARDINAL ; |
| 11124 |
BEGIN |
| 11125 |
SeenCall := FALSE ; |
| 11126 |
IsGlobal := FALSE ; |
| 11127 |
GetQuad(End, op, op1, op2, Start) ; |
| 11128 |
Current := Start ; |
| 11129 |
WHILE Current#End DO |
| 11130 |
GetQuad(Current, op, op1, op2, op3) ; |
| 11131 |
(* remember that this function is only called once we have optimized the redundant gotos and conditionals *) |
| 11132 |
IF IsConditional(Current) AND (NOT IsGlobal) |
| 11133 |
THEN |
| 11134 |
IsGlobal := (IsVar(op1) AND (NOT IsProcedure(GetVarScope(op1)))) OR |
| 11135 |
(IsVar(op2) AND (NOT IsProcedure(GetVarScope(op2)))) |
| 11136 |
END ; |
| 11137 |
IF op=CallOp |
| 11138 |
THEN |
| 11139 |
SeenCall := TRUE |
| 11140 |
END ; |
| 11141 |
IF (op=GotoOp) OR (IsConditional(Current) AND IsConditionVariable(Current, Start, End)) |
| 11142 |
THEN |
| 11143 |
IF (op3>End) OR (op3<Start) |
| 11144 |
THEN |
| 11145 |
RETURN( FALSE ) (* may jump out of this loop, good *) |
| 11146 |
END |
| 11147 |
END ; |
| 11148 |
Current := GetNextQuad(Current) |
| 11149 |
END ; |
| 11150 |
GetQuad(End, op, op1, op2, op3) ; |
| 11151 |
IF IsConditional(End) |
| 11152 |
THEN |
| 11153 |
IF IsConditionVariable(End, Start, End) |
| 11154 |
THEN |
| 11155 |
RETURN( FALSE ) |
| 11156 |
ELSE |
| 11157 |
IF NOT IsGlobal |
| 11158 |
THEN |
| 11159 |
IsGlobal := (IsVar(op1) AND (NOT IsProcedure(GetVarScope(op1)))) OR |
| 11160 |
(IsVar(op2) AND (NOT IsProcedure(GetVarScope(op2)))) |
| 11161 |
END |
| 11162 |
END |
| 11163 |
END ; |
| 11164 |
(* we have found a likely infinite loop if no conditional uses a global and no procedure call was seen *) |
| 11165 |
RETURN( NOT (IsGlobal AND SeenCall) ) |
| 11166 |
END IsInfiniteLoop ; |
| 11167 |
|
| 11168 |
|
| 11169 |
(* |
| 11170 |
LoopAnalysis - checks whether an infinite loop exists. |
| 11171 |
*) |
| 11172 |
|
| 11173 |
PROCEDURE LoopAnalysis (Scope: CARDINAL; Current, End: CARDINAL) ; |
| 11174 |
VAR |
| 11175 |
op : QuadOperator ; |
| 11176 |
op1, op2, op3: CARDINAL ; |
| 11177 |
BEGIN |
| 11178 |
IF Pedantic |
| 11179 |
THEN |
| 11180 |
WHILE (Current<=End) AND (Current#0) DO |
| 11181 |
GetQuad(Current, op, op1, op2, op3) ; |
| 11182 |
IF (op=GotoOp) OR IsConditional(Current) |
| 11183 |
THEN |
| 11184 |
IF op3<=Current |
| 11185 |
THEN |
| 11186 |
(* found a loop - ie a branch which goes back in quadruple numbers *) |
| 11187 |
IF IsInfiniteLoop(Current) |
| 11188 |
THEN |
| 11189 |
MetaErrorT1 (QuadToTokenNo(op3), |
| 11190 |
'it is very likely (although not absolutely certain) that the top of an infinite loop exists here in {%1Wad}', |
| 11191 |
Scope) ; |
| 11192 |
MetaErrorT1 (QuadToTokenNo(Current), |
| 11193 |
'and the bottom of the infinite loop is ends here in {%1Wad} or alternatively a component of this loop is never executed', |
| 11194 |
Scope) ; |
| 11195 |
(* |
| 11196 |
WarnStringAt(InitString('it is very likely (although not absolutely certain) that the top of an infinite loop is here'), |
| 11197 |
QuadToTokenNo(op3)) ; |
| 11198 |
WarnStringAt(InitString('and the bottom of the infinite loop is ends here or alternatively a component of this loop is never executed'), |
| 11199 |
QuadToTokenNo(Current)) |
| 11200 |
*) |
| 11201 |
END |
| 11202 |
END |
| 11203 |
END ; |
| 11204 |
Current := GetNextQuad(Current) |
| 11205 |
END |
| 11206 |
END |
| 11207 |
END LoopAnalysis ; |
| 11208 |
|
| 11209 |
|
| 11210 |
(* |
| 11211 |
CheckVariablesInBlock - given a block, BlockSym, check whether all variables are used. |
| 11212 |
*) |
| 11213 |
|
| 11214 |
PROCEDURE CheckVariablesInBlock (BlockSym: CARDINAL) ; |
| 11215 |
BEGIN |
| 11216 |
CheckVariablesAndParameterTypesInBlock (BlockSym) |
| 11217 |
END CheckVariablesInBlock ; |
| 11218 |
|
| 11219 |
|
| 11220 |
(* |
| 11221 |
CheckFunctionReturn - checks to see that a RETURN statement was present in a function. |
| 11222 |
*) |
| 11223 |
|
| 11224 |
PROCEDURE CheckFunctionReturn (ProcSym: CARDINAL) ; |
| 11225 |
VAR |
| 11226 |
Op : QuadOperator ; |
| 11227 |
Op1, Op2, Op3, |
| 11228 |
Scope, |
| 11229 |
Start, End : CARDINAL ; |
| 11230 |
BEGIN |
| 11231 |
IF GetSType(ProcSym)#NulSym |
| 11232 |
THEN |
| 11233 |
(* yes it is a function *) |
| 11234 |
GetProcedureQuads(ProcSym, Scope, Start, End) ; |
| 11235 |
GetQuad(Start, Op, Op1, Op2, Op3) ; |
| 11236 |
IF Start=0 |
| 11237 |
THEN |
| 11238 |
InternalError ('incorrect start quad') |
| 11239 |
END ; |
| 11240 |
WHILE (Start#End) AND (Op#ReturnValueOp) AND (Op#InlineOp) DO |
| 11241 |
Start := GetNextQuad(Start) ; |
| 11242 |
GetQuad(Start, Op, Op1, Op2, Op3) |
| 11243 |
END ; |
| 11244 |
IF (Op#ReturnValueOp) AND (Op#InlineOp) |
| 11245 |
THEN |
| 11246 |
(* an InlineOp can always be used to emulate a RETURN *) |
| 11247 |
MetaError1 ('procedure function {%1Ea} does not RETURN a value', ProcSym) |
| 11248 |
END |
| 11249 |
END |
| 11250 |
END CheckFunctionReturn ; |
| 11251 |
|
| 11252 |
|
| 11253 |
(* |
| 11254 |
CheckReturnType - checks to see that the return type from currentProc is |
| 11255 |
assignment compatible with actualType. |
| 11256 |
*) |
| 11257 |
|
| 11258 |
PROCEDURE CheckReturnType (tokno: CARDINAL; currentProc, actualVal, actualType: CARDINAL) ; |
| 11259 |
VAR |
| 11260 |
procType: CARDINAL ; |
| 11261 |
s1, s2 : String ; |
| 11262 |
n1, n2 : Name ; |
| 11263 |
BEGIN |
| 11264 |
procType := GetSType (currentProc) ; |
| 11265 |
IF procType = NulSym |
| 11266 |
THEN |
| 11267 |
MetaError1 ('attempting to RETURN a value from procedure {%1Ea} which was not a declared as a procedure function', currentProc) |
| 11268 |
ELSIF AssignmentRequiresWarning (actualType, GetSType (currentProc)) |
| 11269 |
THEN |
| 11270 |
MetaError2 ('attempting to RETURN a value {%1Wa} with an incompatible type {%1Wtsa} from a procedure function {%1a} which returns {%1tsa}', actualVal, currentProc) |
| 11271 |
ELSIF NOT IsAssignmentCompatible (actualType, procType) |
| 11272 |
THEN |
| 11273 |
n1 := GetSymName(actualType) ; |
| 11274 |
n2 := GetSymName(procType) ; |
| 11275 |
WriteFormat2('attempting to RETURN a value with an incompatible type (%a) from a function which returns (%a)', |
| 11276 |
n1, n2) |
| 11277 |
ELSIF IsProcedure(actualVal) AND (NOT IsAssignmentCompatible(actualVal, procType)) |
| 11278 |
THEN |
| 11279 |
(* |
| 11280 |
MetaWarnings2('attempting to RETURN a value with an incompatible type {%1ad} from function {%2a} which returns {%2ta}', |
| 11281 |
actualVal, currentProc) |
| 11282 |
|
| 11283 |
--fixme-- introduce MetaWarning, MetaWarning2, MetaWarning3 into M2MetaError |
| 11284 |
*) |
| 11285 |
s1 := InitStringCharStar(KeyToCharStar(GetSymName(actualVal))) ; |
| 11286 |
s2 := InitStringCharStar(KeyToCharStar(GetSymName(procType))) ; |
| 11287 |
ErrorString(NewWarning(GetTokenNo()), |
| 11288 |
Sprintf2(Mark(InitString('attempting to RETURN a value with a (possibly on other targets) incompatible type (%s) from a function which returns (%s)')), |
| 11289 |
s1, s2)) |
| 11290 |
ELSIF IsProcedure(actualVal) AND (NOT IsAssignmentCompatible(actualVal, GetSType(CurrentProc))) |
| 11291 |
THEN |
| 11292 |
n1 := GetSymName(actualVal) ; |
| 11293 |
n2 := GetSymName(GetSType(currentProc)) ; |
| 11294 |
WriteFormat2('attempting to RETURN a value with an incompatible type (%a) from a function which returns (%a)', |
| 11295 |
n1, n2) |
| 11296 |
ELSE |
| 11297 |
(* this checks the types are compatible, not the data contents. *) |
| 11298 |
BuildRange (InitTypesReturnTypeCheck (tokno, currentProc, actualVal)) |
| 11299 |
END |
| 11300 |
END CheckReturnType ; |
| 11301 |
|
| 11302 |
|
| 11303 |
(* |
| 11304 |
BuildReturnLower - check the return type and value to ensure type |
| 11305 |
compatibility and no range overflow will occur. |
| 11306 |
*) |
| 11307 |
|
| 11308 |
PROCEDURE BuildReturnLower (tokcombined, tokexpr: CARDINAL; e1, t1: CARDINAL) ; |
| 11309 |
VAR |
| 11310 |
e2, t2: CARDINAL ; |
| 11311 |
BEGIN |
| 11312 |
(* This will check that the type returned is compatible with |
| 11313 |
the formal return type of the procedure. *) |
| 11314 |
CheckReturnType (tokcombined, CurrentProc, e1, t1) ; |
| 11315 |
(* Dereference LeftValue if necessary. *) |
| 11316 |
IF GetMode (e1) = LeftValue |
| 11317 |
THEN |
| 11318 |
t2 := GetSType (CurrentProc) ; |
| 11319 |
e2 := MakeTemporary (tokexpr, RightValue) ; |
| 11320 |
PutVar(e2, t2) ; |
| 11321 |
CheckPointerThroughNil (tokexpr, e1) ; |
| 11322 |
doIndrX (tokexpr, e2, e1) ; |
| 11323 |
e1 := e2 |
| 11324 |
END ; |
| 11325 |
(* Here we check the data contents to ensure no overflow. *) |
| 11326 |
BuildRange (InitReturnRangeCheck (tokcombined, CurrentProc, e1)) ; |
| 11327 |
GenQuadOtok (tokcombined, ReturnValueOp, e1, NulSym, CurrentProc, FALSE, |
| 11328 |
tokcombined, UnknownTokenNo, GetDeclaredMod (CurrentProc)) |
| 11329 |
END BuildReturnLower ; |
| 11330 |
|
| 11331 |
|
| 11332 |
(* |
| 11333 |
BuildReturn - Builds the Return part of the procedure. |
| 11334 |
tokreturn is the location of the RETURN keyword. |
| 11335 |
The Stack is expected to contain: |
| 11336 |
|
| 11337 |
|
| 11338 |
Entry Exit |
| 11339 |
===== ==== |
| 11340 |
|
| 11341 |
Ptr -> |
| 11342 |
+------------+ |
| 11343 |
| e1 | Empty |
| 11344 |
|------------| |
| 11345 |
*) |
| 11346 |
|
| 11347 |
PROCEDURE BuildReturn (tokreturn: CARDINAL) ; |
| 11348 |
VAR |
| 11349 |
tokcombined, |
| 11350 |
tokexpr : CARDINAL ; |
| 11351 |
e1, t1, |
| 11352 |
t, f, |
| 11353 |
Des : CARDINAL ; |
| 11354 |
BEGIN |
| 11355 |
IF IsBoolean (1) |
| 11356 |
THEN |
| 11357 |
PopBooltok (t, f, tokexpr) ; |
| 11358 |
(* Des will be a boolean type *) |
| 11359 |
Des := MakeTemporary (tokexpr, RightValue) ; |
| 11360 |
PutVar (Des, Boolean) ; |
| 11361 |
PushTFtok (Des, Boolean, tokexpr) ; |
| 11362 |
PushBooltok (t, f, tokexpr) ; |
| 11363 |
BuildAssignmentWithoutBounds (tokreturn, FALSE, TRUE) ; |
| 11364 |
PushTFtok (Des, Boolean, tokexpr) |
| 11365 |
END ; |
| 11366 |
PopTFtok (e1, t1, tokexpr) ; |
| 11367 |
tokcombined := MakeVirtualTok (tokreturn, tokreturn, tokexpr) ; |
| 11368 |
IF e1 # NulSym |
| 11369 |
THEN |
| 11370 |
(* Check we are in a procedure scope and that the procedure has a return type. *) |
| 11371 |
IF CurrentProc = NulSym |
| 11372 |
THEN |
| 11373 |
MetaErrorT0 (tokcombined, |
| 11374 |
'{%1E} attempting to return a value when not in a procedure scope') |
| 11375 |
ELSIF GetSType (CurrentProc) = NulSym |
| 11376 |
THEN |
| 11377 |
MetaErrorT1 (tokcombined, |
| 11378 |
'attempting to return a value from procedure {%1Ea} which does not have a return type', |
| 11379 |
CurrentProc) |
| 11380 |
ELSE |
| 11381 |
BuildReturnLower (tokcombined, tokexpr, e1, t1) |
| 11382 |
END |
| 11383 |
END ; |
| 11384 |
GenQuadO (tokcombined, GotoOp, NulSym, NulSym, PopWord (ReturnStack), FALSE) ; |
| 11385 |
PushWord (ReturnStack, NextQuad-1) |
| 11386 |
END BuildReturn ; |
| 11387 |
|
| 11388 |
|
| 11389 |
(* |
| 11390 |
IsReadOnly - a helper procedure function to detect constants. |
| 11391 |
*) |
| 11392 |
|
| 11393 |
PROCEDURE IsReadOnly (sym: CARDINAL) : BOOLEAN ; |
| 11394 |
BEGIN |
| 11395 |
RETURN IsConst (sym) OR (IsVar (sym) AND IsVarConst (sym)) |
| 11396 |
END IsReadOnly ; |
| 11397 |
|
| 11398 |
|
| 11399 |
(* |
| 11400 |
BuildDesignatorRecord - Builds the record referencing. |
| 11401 |
The Stack is expected to contain: |
| 11402 |
|
| 11403 |
|
| 11404 |
Entry Exit |
| 11405 |
===== ==== |
| 11406 |
|
| 11407 |
Ptr -> |
| 11408 |
+--------------+ |
| 11409 |
| n | |
| 11410 |
|--------------| |
| 11411 |
| fld1 | type1 | |
| 11412 |
|--------------| |
| 11413 |
. . |
| 11414 |
. . |
| 11415 |
. . |
| 11416 |
|--------------| |
| 11417 |
| fldn | typen | <- Ptr |
| 11418 |
|--------------| +-------------+ |
| 11419 |
| Sym | Type | | S | type1| |
| 11420 |
|--------------| |-------------| |
| 11421 |
*) |
| 11422 |
|
| 11423 |
PROCEDURE BuildDesignatorRecord (dottok: CARDINAL) ; |
| 11424 |
VAR |
| 11425 |
RecordTok, |
| 11426 |
FieldTok, |
| 11427 |
combinedtok: CARDINAL ; |
| 11428 |
n, rw, |
| 11429 |
Field, |
| 11430 |
FieldType, |
| 11431 |
RecordSym, |
| 11432 |
Res : CARDINAL ; |
| 11433 |
BEGIN |
| 11434 |
PopT(n) ; |
| 11435 |
RecordSym := OperandT (n+1) ; |
| 11436 |
(* RecordType could be found by: SkipType (OperandF (n+1)). *) |
| 11437 |
RecordTok := OperandTok (n+1) ; |
| 11438 |
rw := OperandMergeRW (n+1) ; |
| 11439 |
Assert (IsLegal (rw)) ; |
| 11440 |
Field := OperandT (n) ; |
| 11441 |
FieldType := SkipType (OperandF (n)) ; |
| 11442 |
FieldTok := OperandTok (n) ; |
| 11443 |
combinedtok := MakeVirtualTok (dottok, RecordTok, FieldTok) ; |
| 11444 |
IF n>1 |
| 11445 |
THEN |
| 11446 |
InternalError ('not expecting to see n>1') |
| 11447 |
END ; |
| 11448 |
IF IsUnused (Field) |
| 11449 |
THEN |
| 11450 |
MetaErrors1 ('record field {%1Dad} was declared as unused by a pragma', |
| 11451 |
'record field {%1ad} is being used after being declared as unused by a pragma', Field) |
| 11452 |
END ; |
| 11453 |
Res := MakeComponentRef (MakeComponentRecord (combinedtok, |
| 11454 |
RightValue, RecordSym), Field) ; |
| 11455 |
PutVarConst (Res, IsReadOnly (RecordSym)) ; |
| 11456 |
GenQuadO (combinedtok, RecordFieldOp, Res, RecordSym, Field, FALSE) ; |
| 11457 |
PopN (n+1) ; |
| 11458 |
PushTFrwtok (Res, FieldType, rw, combinedtok) |
| 11459 |
END BuildDesignatorRecord ; |
| 11460 |
|
| 11461 |
|
| 11462 |
(* |
| 11463 |
BuildDesignatorError - removes the designator from the stack and replaces |
| 11464 |
it with an error symbol. |
| 11465 |
*) |
| 11466 |
|
| 11467 |
PROCEDURE BuildDesignatorError (message: ARRAY OF CHAR) ; |
| 11468 |
VAR |
| 11469 |
combinedTok, |
| 11470 |
arrayTok, |
| 11471 |
exprTok : CARDINAL ; |
| 11472 |
e, d, error, |
| 11473 |
Sym, |
| 11474 |
Type : CARDINAL ; |
| 11475 |
BEGIN |
| 11476 |
PopTtok (e, exprTok) ; |
| 11477 |
PopTFDtok (Sym, Type, d, arrayTok) ; |
| 11478 |
combinedTok := MakeVirtualTok (arrayTok, arrayTok, exprTok) ; |
| 11479 |
error := MakeError (combinedTok, MakeKey (message)) ; |
| 11480 |
PushTFDtok (error, Type, d, arrayTok) |
| 11481 |
END BuildDesignatorError ; |
| 11482 |
|
| 11483 |
|
| 11484 |
(* |
| 11485 |
BuildDesignatorPointerError - removes the designator from the stack and replaces |
| 11486 |
it with an error symbol. |
| 11487 |
*) |
| 11488 |
|
| 11489 |
PROCEDURE BuildDesignatorPointerError (type, rw: CARDINAL; tokpos: CARDINAL; |
| 11490 |
message: ARRAY OF CHAR) ; |
| 11491 |
VAR |
| 11492 |
error: CARDINAL ; |
| 11493 |
BEGIN |
| 11494 |
error := MakeError (tokpos, MakeKey (message)) ; |
| 11495 |
IF GetSType (type) # NulSym |
| 11496 |
THEN |
| 11497 |
type := GetSType (type) |
| 11498 |
END ; |
| 11499 |
PushTFrwtok (error, type, rw, tokpos) |
| 11500 |
END BuildDesignatorPointerError ; |
| 11501 |
|
| 11502 |
|
| 11503 |
(* |
| 11504 |
BuildDesignatorArray - Builds the array referencing. |
| 11505 |
The purpose of this procedure is to work out |
| 11506 |
whether the DesignatorArray is a constant string or |
| 11507 |
dynamic array/static array and to call the appropriate |
| 11508 |
BuildRoutine. |
| 11509 |
|
| 11510 |
The Stack is expected to contain: |
| 11511 |
|
| 11512 |
Entry Exit |
| 11513 |
===== ==== |
| 11514 |
|
| 11515 |
Ptr -> |
| 11516 |
+--------------+ |
| 11517 |
| e | <- Ptr |
| 11518 |
|--------------| +------------+ |
| 11519 |
| Sym | Type | | S | T | |
| 11520 |
|--------------| |------------| |
| 11521 |
*) |
| 11522 |
|
| 11523 |
PROCEDURE BuildDesignatorArray ; |
| 11524 |
BEGIN |
| 11525 |
IF IsConst (OperandT (2)) AND IsConstString (OperandT (2)) |
| 11526 |
THEN |
| 11527 |
MetaErrorT1 (OperandTtok (2), |
| 11528 |
'{%1Ead} is not an array, but a constant string. Hint use a string constant created with an array constructor', |
| 11529 |
OperandT (2)) ; |
| 11530 |
BuildDesignatorError ('bad array access') |
| 11531 |
ELSE |
| 11532 |
BuildDesignatorArrayStaticDynamic |
| 11533 |
END |
| 11534 |
END BuildDesignatorArray ; |
| 11535 |
|
| 11536 |
|
| 11537 |
(* |
| 11538 |
BuildDesignatorArrayStaticDynamic - Builds the array referencing. |
| 11539 |
The purpose of this procedure is to work out |
| 11540 |
whether the DesignatorArray is a static or |
| 11541 |
dynamic array and to call the appropriate |
| 11542 |
BuildRoutine. |
| 11543 |
|
| 11544 |
The Stack is expected to contain: |
| 11545 |
|
| 11546 |
|
| 11547 |
Entry Exit |
| 11548 |
===== ==== |
| 11549 |
|
| 11550 |
Ptr -> |
| 11551 |
+--------------+ |
| 11552 |
| e | <- Ptr |
| 11553 |
|--------------| +------------+ |
| 11554 |
| Sym | Type | | S | T | |
| 11555 |
|--------------| |------------| |
| 11556 |
*) |
| 11557 |
|
| 11558 |
PROCEDURE BuildDesignatorArrayStaticDynamic ; |
| 11559 |
VAR |
| 11560 |
combinedTok, |
| 11561 |
arrayTok, |
| 11562 |
exprTok : CARDINAL ; |
| 11563 |
e, type, dim, |
| 11564 |
result, |
| 11565 |
Sym, |
| 11566 |
Type : CARDINAL ; |
| 11567 |
BEGIN |
| 11568 |
IF IsConst (OperandT (2)) |
| 11569 |
THEN |
| 11570 |
type := GetDType (OperandT (2)) ; |
| 11571 |
IF (type # NulSym) AND IsArray (type) |
| 11572 |
THEN |
| 11573 |
PopTtok (e, exprTok) ; |
| 11574 |
PopTFDtok (Sym, Type, dim, arrayTok) ; |
| 11575 |
result := MakeTemporary (exprTok, RightValue) ; |
| 11576 |
PutVar (result, Type) ; |
| 11577 |
PushTFtok (result, GetSType (result), exprTok) ; |
| 11578 |
PushTtok (Sym, arrayTok) ; |
| 11579 |
combinedTok := MakeVirtualTok (arrayTok, arrayTok, exprTok) ; |
| 11580 |
PutVarConst (result, TRUE) ; |
| 11581 |
BuildAssignConstant (combinedTok) ; |
| 11582 |
PushTFDtok (result, GetDType (result), dim, arrayTok) ; |
| 11583 |
PushTtok (e, exprTok) |
| 11584 |
END |
| 11585 |
END ; |
| 11586 |
IF (NOT IsVar (OperandT (2))) AND (NOT IsTemporary (OperandT (2))) |
| 11587 |
THEN |
| 11588 |
MetaErrorT1 (OperandTtok (2), |
| 11589 |
'can only access arrays using constants, variables or formal parameters not {%1Ead}', |
| 11590 |
OperandT (2)) ; |
| 11591 |
BuildDesignatorError ('bad array access') |
| 11592 |
END ; |
| 11593 |
Sym := OperandT (2) ; |
| 11594 |
Type := GetDType (Sym) ; |
| 11595 |
arrayTok := OperandTtok (2) ; |
| 11596 |
IF Type = NulSym |
| 11597 |
THEN |
| 11598 |
IF (arrayTok = UnknownTokenNo) OR (arrayTok = BuiltinTokenNo) |
| 11599 |
THEN |
| 11600 |
arrayTok := GetTokenNo () |
| 11601 |
END ; |
| 11602 |
MetaErrorT0 (arrayTok, "type of array is undefined") ; |
| 11603 |
BuildDesignatorError ('bad array access') |
| 11604 |
ELSIF IsUnbounded (Type) |
| 11605 |
THEN |
| 11606 |
BuildDynamicArray |
| 11607 |
ELSIF IsArray (Type) |
| 11608 |
THEN |
| 11609 |
BuildStaticArray |
| 11610 |
ELSE |
| 11611 |
MetaErrorT1 (arrayTok, |
| 11612 |
'can only index static or dynamic arrays, {%1Ead} is not an array but a {%tad}', |
| 11613 |
Sym) ; |
| 11614 |
BuildDesignatorError ('bad array access') |
| 11615 |
END |
| 11616 |
END BuildDesignatorArrayStaticDynamic ; |
| 11617 |
|
| 11618 |
|
| 11619 |
(* |
| 11620 |
BuildStaticArray - Builds the array referencing for static arrays. |
| 11621 |
The Stack is expected to contain: |
| 11622 |
|
| 11623 |
|
| 11624 |
Entry Exit |
| 11625 |
===== ==== |
| 11626 |
|
| 11627 |
Ptr -> |
| 11628 |
+--------------+ |
| 11629 |
| e | <- Ptr |
| 11630 |
|--------------| +------------+ |
| 11631 |
| Sym | Type | | S | T | |
| 11632 |
|--------------| |------------| |
| 11633 |
*) |
| 11634 |
|
| 11635 |
PROCEDURE BuildStaticArray ; |
| 11636 |
VAR |
| 11637 |
combinedTok, |
| 11638 |
indexTok, |
| 11639 |
arrayTok : CARDINAL ; |
| 11640 |
rw, |
| 11641 |
Dim, |
| 11642 |
Array, |
| 11643 |
Index, |
| 11644 |
BackEndType, |
| 11645 |
Type, Adr : CARDINAL ; |
| 11646 |
BEGIN |
| 11647 |
Index := OperandT (1) ; |
| 11648 |
indexTok := OperandTtok (1) ; |
| 11649 |
Array := OperandT (2) ; |
| 11650 |
arrayTok := OperandTtok (2) ; |
| 11651 |
Type := SkipType (OperandF (2)) ; |
| 11652 |
rw := OperandMergeRW (2) ; |
| 11653 |
Assert (IsLegal (rw)) ; |
| 11654 |
Dim := OperandD (2) ; |
| 11655 |
INC (Dim) ; |
| 11656 |
IF GetMode (Index)=LeftValue |
| 11657 |
THEN |
| 11658 |
Index := MakeRightValue (indexTok, Index, GetSType (Index)) |
| 11659 |
END ; |
| 11660 |
BuildRange (InitStaticArraySubscriptRangeCheck (GetArraySubscript (Type), Index, Dim)) ; |
| 11661 |
|
| 11662 |
(* now make Adr point to the address of the indexed element *) |
| 11663 |
combinedTok := MakeVirtualTok (arrayTok, arrayTok, indexTok) ; |
| 11664 |
Adr := MakeTemporary (combinedTok, LeftValue) ; |
| 11665 |
IF IsVar (Array) |
| 11666 |
THEN |
| 11667 |
(* BuildDesignatorArray may have detected des is a constant. *) |
| 11668 |
PutVarConst (Adr, IsVarConst (Array)) |
| 11669 |
END ; |
| 11670 |
PutVarArrayRef (Adr, TRUE) ; |
| 11671 |
(* |
| 11672 |
From now on it must reference the array element by its lvalue |
| 11673 |
- so we create the type of the referenced entity |
| 11674 |
*) |
| 11675 |
|
| 11676 |
BackEndType := MakePointer (combinedTok, NulName) ; |
| 11677 |
PutPointer (BackEndType, GetDType (Type)) ; |
| 11678 |
(* PutVar(Adr, BackEndType) ; *) |
| 11679 |
PutLeftValueFrontBackType (Adr, GetDType (Type), BackEndType) ; |
| 11680 |
|
| 11681 |
GenQuadO (combinedTok, ArrayOp, Adr, Index, Array, TRUE) ; |
| 11682 |
PopN (2) ; (* remove all parameters to this procedure *) |
| 11683 |
PushTFDrwtok (Adr, GetSType (Adr), Dim, rw, combinedTok) |
| 11684 |
END BuildStaticArray ; |
| 11685 |
|
| 11686 |
|
| 11687 |
(* |
| 11688 |
calculateMultipicand - generates quadruples which calculate the |
| 11689 |
multiplicand for the array at dimension, dim. |
| 11690 |
*) |
| 11691 |
|
| 11692 |
PROCEDURE calculateMultipicand (tok: CARDINAL; |
| 11693 |
arraySym, arrayType: CARDINAL; dim: CARDINAL) : CARDINAL ; |
| 11694 |
VAR |
| 11695 |
ti, tj, tk, tl: CARDINAL ; |
| 11696 |
BEGIN |
| 11697 |
IF dim = GetDimension (arrayType) |
| 11698 |
THEN |
| 11699 |
(* ti has no type since constant *) |
| 11700 |
ti := MakeTemporary (tok, ImmediateValue) ; |
| 11701 |
PutVar (ti, Cardinal) ; |
| 11702 |
GenQuadO (tok, ElementSizeOp, ti, arrayType, 1, TRUE) |
| 11703 |
ELSE |
| 11704 |
INC(dim) ; |
| 11705 |
tk := MakeTemporary (tok, RightValue) ; |
| 11706 |
PutVar (tk, Cardinal) ; |
| 11707 |
GenHigh (tok, tk, dim, arraySym) ; |
| 11708 |
tl := MakeTemporary (tok, RightValue) ; |
| 11709 |
PutVar (tl, Cardinal) ; |
| 11710 |
GenQuadOtok (tok, AddOp, tl, tk, MakeConstLit (tok, MakeKey ('1'), Cardinal), TRUE, |
| 11711 |
tok, tok, tok) ; |
| 11712 |
tj := calculateMultipicand (tok, arraySym, arrayType, dim) ; |
| 11713 |
ti := MakeTemporary (tok, RightValue) ; |
| 11714 |
PutVar (ti, Cardinal) ; |
| 11715 |
GenQuadO (tok, MultOp, ti, tj, tl, TRUE) |
| 11716 |
END ; |
| 11717 |
RETURN ti |
| 11718 |
END calculateMultipicand ; |
| 11719 |
|
| 11720 |
|
| 11721 |
(* |
| 11722 |
ConvertToAddress - convert sym to an address. |
| 11723 |
*) |
| 11724 |
|
| 11725 |
PROCEDURE ConvertToAddress (tokpos: CARDINAL; sym: CARDINAL) : CARDINAL ; |
| 11726 |
VAR |
| 11727 |
adr: CARDINAL ; |
| 11728 |
BEGIN |
| 11729 |
IF GetSType (sym) = Address |
| 11730 |
THEN |
| 11731 |
RETURN sym |
| 11732 |
ELSE |
| 11733 |
PushTF (RequestSym (tokpos, MakeKey ('CONVERT')), NulSym) ; |
| 11734 |
PushT (Address) ; |
| 11735 |
PushTtok (sym, tokpos) ; |
| 11736 |
PushT(2) ; (* Two parameters *) |
| 11737 |
BuildConvertFunction (Convert, FALSE) ; |
| 11738 |
PopT (adr) ; |
| 11739 |
RETURN adr |
| 11740 |
END |
| 11741 |
END ConvertToAddress ; |
| 11742 |
|
| 11743 |
|
| 11744 |
(* |
| 11745 |
BuildDynamicArray - Builds the array referencing for dynamic arrays. |
| 11746 |
The Stack is expected to contain: |
| 11747 |
|
| 11748 |
|
| 11749 |
Entry Exit |
| 11750 |
===== ==== |
| 11751 |
|
| 11752 |
Ptr -> |
| 11753 |
+-----------------------+ |
| 11754 |
| Index | <- Ptr |
| 11755 |
|-----------------------| +---------------------------+ |
| 11756 |
| ArraySym | Type | Dim | | S | T | ArraySym | Dim+1 | |
| 11757 |
|-----------------------| |---------------------------| |
| 11758 |
|
| 11759 |
|
| 11760 |
if Dim=1 |
| 11761 |
then |
| 11762 |
S := base of ArraySym + TSIZE(Type)*Index |
| 11763 |
else |
| 11764 |
S := S + TSIZE(Type)*Index |
| 11765 |
fi |
| 11766 |
*) |
| 11767 |
|
| 11768 |
PROCEDURE BuildDynamicArray ; |
| 11769 |
VAR |
| 11770 |
combinedTok, |
| 11771 |
arrayTok, |
| 11772 |
indexTok : CARDINAL ; |
| 11773 |
Sym, idx, |
| 11774 |
Type, Adr, |
| 11775 |
ArraySym, |
| 11776 |
BackEndType, |
| 11777 |
UnboundedType, |
| 11778 |
PtrToBase, |
| 11779 |
Base, |
| 11780 |
Dim, rw, |
| 11781 |
ti, tj, tk, |
| 11782 |
tka : CARDINAL ; |
| 11783 |
BEGIN |
| 11784 |
DisplayStack ; |
| 11785 |
Sym := OperandT (2) ; |
| 11786 |
Type := SkipType (OperandF (2)) ; |
| 11787 |
arrayTok := OperandTok (2) ; |
| 11788 |
indexTok := OperandTok (1) ; |
| 11789 |
combinedTok := MakeVirtualTok (arrayTok, arrayTok, indexTok) ; |
| 11790 |
Dim := OperandD (2) ; |
| 11791 |
rw := OperandMergeRW (2) ; |
| 11792 |
Assert (IsLegal (rw)) ; |
| 11793 |
INC (Dim) ; |
| 11794 |
IF Dim = 1 |
| 11795 |
THEN |
| 11796 |
(* |
| 11797 |
Base has type address since |
| 11798 |
BuildDesignatorRecord references by address. |
| 11799 |
|
| 11800 |
Build a record for retrieving the address of dynamic array. |
| 11801 |
BuildDesignatorRecord will generate the required quadruples, |
| 11802 |
therefore build sets up the stack for BuildDesignatorRecord |
| 11803 |
which will generate the quads to access the record. |
| 11804 |
*) |
| 11805 |
ArraySym := Sym ; |
| 11806 |
UnboundedType := GetUnboundedRecordType (GetSType (Sym)) ; |
| 11807 |
PushTFrwtok (Sym, UnboundedType, rw, arrayTok) ; |
| 11808 |
PushTF (GetUnboundedAddressOffset (GetSType (Sym)), |
| 11809 |
GetSType (GetUnboundedAddressOffset (GetSType (Sym)))) ; |
| 11810 |
PushT (1) ; (* One record field to dereference *) |
| 11811 |
BuildDesignatorRecord (combinedTok) ; |
| 11812 |
PopT (PtrToBase) ; |
| 11813 |
DisplayStack ; |
| 11814 |
(* Now actually copy Unbounded.ArrayAddress into base *) |
| 11815 |
IF GetMode(PtrToBase) = LeftValue |
| 11816 |
THEN |
| 11817 |
Base := MakeTemporary (arrayTok, RightValue) ; |
| 11818 |
PutVar (Base, Address) ; (* has type ADDRESS *) |
| 11819 |
CheckPointerThroughNil (arrayTok, PtrToBase) ; |
| 11820 |
GenQuad (IndrXOp, Base, Address, PtrToBase) (* Base = *PtrToBase *) |
| 11821 |
ELSE |
| 11822 |
Assert (GetMode (PtrToBase) # ImmediateValue) ; |
| 11823 |
Base := PtrToBase |
| 11824 |
END |
| 11825 |
ELSE |
| 11826 |
(* Base already calculated previously and pushed to stack *) |
| 11827 |
UnboundedType := SkipType (OperandF (2)) ; |
| 11828 |
Base := Sym ; |
| 11829 |
ArraySym := OperandA (2) |
| 11830 |
END ; |
| 11831 |
Assert (GetSType (Sym) = Type) ; |
| 11832 |
ti := calculateMultipicand (indexTok, Sym, Type, Dim) ; |
| 11833 |
idx := OperandT (1) ; |
| 11834 |
IF IsConst (idx) AND IsConst (ti) |
| 11835 |
THEN |
| 11836 |
(* tj has no type since constant *) |
| 11837 |
tj := MakeTemporary (indexTok, ImmediateValue) ; |
| 11838 |
tk := MakeTemporary (indexTok, ImmediateValue) ; |
| 11839 |
PutVar (tj, Cardinal) ; |
| 11840 |
PutVar (tk, Cardinal) |
| 11841 |
ELSE |
| 11842 |
(* tj has Cardinal type since we have multiplied array indices *) |
| 11843 |
tj := MakeTemporary (indexTok, RightValue) ; |
| 11844 |
IF GetSType (idx) # Cardinal |
| 11845 |
THEN |
| 11846 |
PushTF (RequestSym (indexTok, MakeKey ('CONVERT')), NulSym) ; |
| 11847 |
PushT (Cardinal) ; |
| 11848 |
PushTtok (idx, indexTok) ; |
| 11849 |
PushT(2) ; (* Two parameters *) |
| 11850 |
BuildConvertFunction (Convert, FALSE) ; |
| 11851 |
PopT (idx) |
| 11852 |
END ; |
| 11853 |
PutVar (tj, Cardinal) ; |
| 11854 |
tk := MakeTemporary (indexTok, RightValue) ; |
| 11855 |
PutVar (tk, Cardinal) |
| 11856 |
END ; |
| 11857 |
BuildRange (InitDynamicArraySubscriptRangeCheck (ArraySym, idx, Dim)) ; |
| 11858 |
|
| 11859 |
PushTtok (tj, indexTok) ; |
| 11860 |
PushTtok (idx, indexTok) ; |
| 11861 |
BuildAssignmentWithoutBounds (indexTok, FALSE, TRUE) ; |
| 11862 |
|
| 11863 |
GenQuad (MultOp, tk, ti, tj) ; |
| 11864 |
Adr := MakeTemporary (combinedTok, LeftValue) ; |
| 11865 |
PutVarArrayRef (Adr, TRUE) ; |
| 11866 |
(* |
| 11867 |
Ok must reference by address |
| 11868 |
- but we contain the type of the referenced entity |
| 11869 |
*) |
| 11870 |
BackEndType := MakePointer (combinedTok, NulName) ; |
| 11871 |
PutPointer (BackEndType, GetSType (Type)) ; |
| 11872 |
(* Create a temporary pointer for addition. *) |
| 11873 |
tka := ConvertToAddress (combinedTok, tk) ; |
| 11874 |
|
| 11875 |
IF Dim = GetDimension (Type) |
| 11876 |
THEN |
| 11877 |
PutLeftValueFrontBackType (Adr, GetSType(Type), BackEndType) ; |
| 11878 |
|
| 11879 |
GenQuadOtok (combinedTok, AddOp, Adr, Base, tka, FALSE, |
| 11880 |
combinedTok, combinedTok, combinedTok) ; |
| 11881 |
PopN (2) ; |
| 11882 |
PushTFADrwtok (Adr, GetSType(Adr), ArraySym, Dim, rw, combinedTok) |
| 11883 |
ELSE |
| 11884 |
(* more to index *) |
| 11885 |
PutLeftValueFrontBackType (Adr, Type, BackEndType) ; |
| 11886 |
|
| 11887 |
GenQuadOtok (combinedTok, AddOp, Adr, Base, tka, FALSE, |
| 11888 |
combinedTok, combinedTok, combinedTok) ; |
| 11889 |
PopN (2) ; |
| 11890 |
PushTFADrwtok (Adr, GetSType(Adr), ArraySym, Dim, rw, combinedTok) |
| 11891 |
END |
| 11892 |
END BuildDynamicArray ; |
| 11893 |
|
| 11894 |
|
| 11895 |
(* |
| 11896 |
DebugLocation - |
| 11897 |
*) |
| 11898 |
|
| 11899 |
PROCEDURE DebugLocation (tok: CARDINAL; message: ARRAY OF CHAR) ; |
| 11900 |
BEGIN |
| 11901 |
IF DebugTokPos |
| 11902 |
THEN |
| 11903 |
WarnStringAt (InitString (message), tok) |
| 11904 |
END |
| 11905 |
END DebugLocation ; |
| 11906 |
|
| 11907 |
|
| 11908 |
(* |
| 11909 |
BuildDesignatorPointer - Builds a pointer reference. |
| 11910 |
The Stack is expected to contain: |
| 11911 |
|
| 11912 |
|
| 11913 |
Entry Exit |
| 11914 |
===== ==== |
| 11915 |
|
| 11916 |
Ptr -> <- Ptr |
| 11917 |
+--------------+ +--------------+ |
| 11918 |
| Sym1 | Type1| | Sym2 | Type2| |
| 11919 |
|--------------| |--------------| |
| 11920 |
*) |
| 11921 |
|
| 11922 |
PROCEDURE BuildDesignatorPointer (ptrtok: CARDINAL) ; |
| 11923 |
VAR |
| 11924 |
combinedtok, |
| 11925 |
destok : CARDINAL ; |
| 11926 |
rw, |
| 11927 |
Sym1, Type1, |
| 11928 |
Sym2, Type2: CARDINAL ; |
| 11929 |
BEGIN |
| 11930 |
PopTFrwtok (Sym1, Type1, rw, destok) ; |
| 11931 |
DebugLocation (destok, "des ptr expression") ; |
| 11932 |
|
| 11933 |
Type1 := SkipType (Type1) ; |
| 11934 |
IF Type1 = NulSym |
| 11935 |
THEN |
| 11936 |
MetaErrorT1 (ptrtok, '{%1ad} has no type and therefore cannot be dereferenced by ^', Sym1) |
| 11937 |
ELSIF IsUnknown (Sym1) |
| 11938 |
THEN |
| 11939 |
MetaError1 ('{%1EMad} is undefined and therefore {%1ad}^ cannot be resolved', Sym1) |
| 11940 |
ELSE |
| 11941 |
combinedtok := MakeVirtual2Tok (destok, ptrtok) ; |
| 11942 |
IF IsPointer (Type1) |
| 11943 |
THEN |
| 11944 |
Type2 := GetSType (Type1) ; |
| 11945 |
Sym2 := MakeTemporary (ptrtok, LeftValue) ; |
| 11946 |
(* |
| 11947 |
Ok must reference by address |
| 11948 |
- but we contain the type of the referenced entity |
| 11949 |
*) |
| 11950 |
MarkAsRead (rw) ; |
| 11951 |
PutVarPointerCheck (Sym1, TRUE) ; |
| 11952 |
CheckPointerThroughNil (ptrtok, Sym1) ; |
| 11953 |
IF GetMode (Sym1) = LeftValue |
| 11954 |
THEN |
| 11955 |
rw := NulSym ; |
| 11956 |
PutLeftValueFrontBackType (Sym2, Type2, Type1) ; |
| 11957 |
GenQuadO (ptrtok, IndrXOp, Sym2, Type1, Sym1, FALSE) (* Sym2 := *Sym1. *) |
| 11958 |
ELSE |
| 11959 |
PutLeftValueFrontBackType (Sym2, Type2, NulSym) ; |
| 11960 |
GenQuadO (ptrtok, BecomesOp, Sym2, NulSym, Sym1, FALSE) (* Sym2 := Sym1. *) |
| 11961 |
END ; |
| 11962 |
(* We should check this for Sym2 later on (pointer via NIL). *) |
| 11963 |
PutVarPointerCheck (Sym2, TRUE) ; |
| 11964 |
PushTFrwtok (Sym2, Type2, rw, combinedtok) ; |
| 11965 |
DebugLocation (combinedtok, "pointer expression") |
| 11966 |
ELSIF IsHiddenType (Type1) AND (GetModuleScope (Type1) # GetCurrentModuleScope ()) |
| 11967 |
THEN |
| 11968 |
MetaErrorT1 (ptrtok, |
| 11969 |
'{%1Ead} is declared with an opaque type from a different module and cannot be dereferenced', |
| 11970 |
Sym1) ; |
| 11971 |
MarkAsRead (rw) ; |
| 11972 |
BuildDesignatorPointerError (Type1, rw, combinedtok, 'bad opaque pointer dereference') |
| 11973 |
ELSE |
| 11974 |
MetaError2 ('{%1Ead} is not a pointer type but a {%2d}', Sym1, Type1) ; |
| 11975 |
MarkAsRead (rw) ; |
| 11976 |
BuildDesignatorPointerError (Type1, rw, combinedtok, 'bad pointer dereference') |
| 11977 |
END |
| 11978 |
END |
| 11979 |
END BuildDesignatorPointer ; |
| 11980 |
|
| 11981 |
|
| 11982 |
(* |
| 11983 |
StartBuildWith - performs the with statement. |
| 11984 |
The Stack: |
| 11985 |
|
| 11986 |
Entry Exit |
| 11987 |
|
| 11988 |
+------------+ |
| 11989 |
| Sym | Type | Empty |
| 11990 |
|------------| |
| 11991 |
*) |
| 11992 |
|
| 11993 |
PROCEDURE StartBuildWith (withTok: CARDINAL) ; |
| 11994 |
VAR |
| 11995 |
tok : CARDINAL ; |
| 11996 |
Sym, Type, |
| 11997 |
Ref : CARDINAL ; |
| 11998 |
BEGIN |
| 11999 |
DebugLocation (withtok, "with") ; |
| 12000 |
BuildStmtNoteTok (withTok) ; |
| 12001 |
DisplayStack ; |
| 12002 |
PopTFtok (Sym, Type, tok) ; |
| 12003 |
DebugLocation (tok, "expression") ; |
| 12004 |
Type := SkipType (Type) ; |
| 12005 |
IF Type = NulSym |
| 12006 |
THEN |
| 12007 |
MetaErrorT1 (tok, |
| 12008 |
'{%1Aa} {%1d} has a no type, the {%kWITH} statement requires a variable or parameter of a {%kRECORD} type', |
| 12009 |
Sym) |
| 12010 |
ELSE |
| 12011 |
Ref := MakeTemporary (tok, LeftValue) ; |
| 12012 |
PutVar (Ref, Type) ; |
| 12013 |
IF GetMode (Sym) = LeftValue |
| 12014 |
THEN |
| 12015 |
(* Copy LeftValue. *) |
| 12016 |
GenQuadO (tok, BecomesOp, Ref, NulSym, Sym, TRUE) |
| 12017 |
ELSE |
| 12018 |
(* Calculate the address of Sym. *) |
| 12019 |
GenQuadO (tok, AddrOp, Ref, NulSym, Sym, TRUE) |
| 12020 |
END ; |
| 12021 |
|
| 12022 |
PushWith (Sym, Type, Ref, tok) ; |
| 12023 |
DebugLocation (tok, "with ref") ; |
| 12024 |
IF NOT IsRecord(Type) |
| 12025 |
THEN |
| 12026 |
MetaErrorT1 (tok, |
| 12027 |
'the {%kWITH} statement requires that {%1Ea} {%1d} be of a {%kRECORD} {%1tsa:type rather than {%1tsa}}', |
| 12028 |
Sym) |
| 12029 |
END ; |
| 12030 |
StartScope (Type) |
| 12031 |
END ; |
| 12032 |
DisplayStack ; |
| 12033 |
END StartBuildWith ; |
| 12034 |
|
| 12035 |
|
| 12036 |
(* |
| 12037 |
EndBuildWith - terminates the innermost with scope. |
| 12038 |
*) |
| 12039 |
|
| 12040 |
PROCEDURE EndBuildWith ; |
| 12041 |
BEGIN |
| 12042 |
DisplayStack ; |
| 12043 |
EndScope ; |
| 12044 |
PopWith |
| 12045 |
; DisplayStack ; |
| 12046 |
END EndBuildWith ; |
| 12047 |
|
| 12048 |
|
| 12049 |
(* |
| 12050 |
PushWith - pushes sym and type onto the with stack. It checks for |
| 12051 |
previous declaration of this record type. |
| 12052 |
*) |
| 12053 |
|
| 12054 |
PROCEDURE PushWith (Sym, Type, Ref, Tok: CARDINAL) ; |
| 12055 |
VAR |
| 12056 |
i, n: CARDINAL ; |
| 12057 |
f : WithFrame ; |
| 12058 |
BEGIN |
| 12059 |
IF Pedantic |
| 12060 |
THEN |
| 12061 |
n := NoOfItemsInStackAddress(WithStack) ; |
| 12062 |
i := 1 ; (* Top of the stack. *) |
| 12063 |
WHILE i <= n DO |
| 12064 |
(* Search for other declarations of the with using Type. *) |
| 12065 |
f := PeepAddress(WithStack, i) ; |
| 12066 |
IF f^.RecordSym=Type |
| 12067 |
THEN |
| 12068 |
MetaErrorT1 (Tok, |
| 12069 |
'cannot have nested {%kWITH} statements referencing the same {%kRECORD} {%1Ead}', |
| 12070 |
Sym) ; |
| 12071 |
MetaErrorT1 (f^.RecordTokPos, |
| 12072 |
'cannot have nested {%kWITH} statements referencing the same {%kRECORD} {%1Ead}', |
| 12073 |
f^.RecordSym) |
| 12074 |
END ; |
| 12075 |
INC (i) |
| 12076 |
END |
| 12077 |
END ; |
| 12078 |
NEW (f) ; |
| 12079 |
WITH f^ DO |
| 12080 |
RecordSym := Sym ; |
| 12081 |
RecordType := Type ; |
| 12082 |
RecordRef := Ref ; |
| 12083 |
rw := Sym ; |
| 12084 |
RecordTokPos := Tok |
| 12085 |
END ; |
| 12086 |
PushAddress (WithStack, f) |
| 12087 |
END PushWith ; |
| 12088 |
|
| 12089 |
|
| 12090 |
PROCEDURE PopWith ; |
| 12091 |
VAR |
| 12092 |
f: WithFrame ; |
| 12093 |
BEGIN |
| 12094 |
f := PopAddress (WithStack) ; |
| 12095 |
DISPOSE (f) |
| 12096 |
END PopWith ; |
| 12097 |
|
| 12098 |
|
| 12099 |
(* |
| 12100 |
CheckWithReference - performs the with statement. |
| 12101 |
The Stack: |
| 12102 |
|
| 12103 |
Entry Exit |
| 12104 |
|
| 12105 |
+------------+ +------------+ |
| 12106 |
| Sym | Type | | Sym | Type | |
| 12107 |
|------------| |------------| |
| 12108 |
*) |
| 12109 |
|
| 12110 |
PROCEDURE CheckWithReference ; |
| 12111 |
VAR |
| 12112 |
f : WithFrame ; |
| 12113 |
tokpos, |
| 12114 |
i, n, rw, |
| 12115 |
Sym, Type: CARDINAL ; |
| 12116 |
BEGIN |
| 12117 |
n := NoOfItemsInStackAddress(WithStack) ; |
| 12118 |
IF (n>0) AND (NOT SuppressWith) |
| 12119 |
THEN |
| 12120 |
PopTFrwtok (Sym, Type, rw, tokpos) ; |
| 12121 |
Assert (tokpos # UnknownTokenNo) ; |
| 12122 |
(* inner WITH always has precidence *) |
| 12123 |
i := 1 ; (* top of stack *) |
| 12124 |
WHILE i<=n DO |
| 12125 |
(* WriteString('Checking for a with') ; *) |
| 12126 |
f := PeepAddress (WithStack, i) ; |
| 12127 |
WITH f^ DO |
| 12128 |
IF IsRecordField (Sym) AND (GetRecord (GetParent (Sym)) = RecordType) |
| 12129 |
THEN |
| 12130 |
IF IsUnused (Sym) |
| 12131 |
THEN |
| 12132 |
MetaError1('record field {%1Dad} was declared as unused by a pragma', Sym) |
| 12133 |
END ; |
| 12134 |
(* Fake a RecordSym.op *) |
| 12135 |
PushTFrwtok (RecordRef, RecordType, rw, RecordTokPos) ; |
| 12136 |
PushTFtok (Sym, Type, tokpos) ; |
| 12137 |
BuildAccessWithField ; |
| 12138 |
PopTFrw (Sym, Type, rw) ; |
| 12139 |
i := n+1 (* Finish loop. *) |
| 12140 |
ELSE |
| 12141 |
INC (i) |
| 12142 |
END |
| 12143 |
END |
| 12144 |
END ; |
| 12145 |
PushTFrwtok (Sym, Type, rw, tokpos) |
| 12146 |
END |
| 12147 |
END CheckWithReference ; |
| 12148 |
|
| 12149 |
|
| 12150 |
(* |
| 12151 |
BuildAccessWithField - similar to BuildDesignatorRecord except it |
| 12152 |
does not perform the address operation. |
| 12153 |
The address will have been computed at the |
| 12154 |
beginning of the WITH statement. |
| 12155 |
It also stops the GenQuad procedure from examining the |
| 12156 |
with stack. |
| 12157 |
|
| 12158 |
The Stack |
| 12159 |
|
| 12160 |
Entry |
| 12161 |
|
| 12162 |
Ptr -> |
| 12163 |
+--------------+ |
| 12164 |
| Field | Type1| <- Ptr |
| 12165 |
|-------|------| +-------------+ |
| 12166 |
| Adr | Type2| | Sym | Type1| |
| 12167 |
|--------------| |-------------| |
| 12168 |
*) |
| 12169 |
|
| 12170 |
PROCEDURE BuildAccessWithField ; |
| 12171 |
VAR |
| 12172 |
rectok, fieldtok : CARDINAL ; |
| 12173 |
OldSuppressWith : BOOLEAN ; |
| 12174 |
rw, |
| 12175 |
Field, FieldType, |
| 12176 |
Record, RecordType, |
| 12177 |
Ref : CARDINAL ; |
| 12178 |
BEGIN |
| 12179 |
OldSuppressWith := SuppressWith ; |
| 12180 |
SuppressWith := TRUE ; |
| 12181 |
(* |
| 12182 |
now the WITH cannot look at the stack of outstanding WITH records. |
| 12183 |
*) |
| 12184 |
PopTFtok (Field, FieldType, fieldtok) ; |
| 12185 |
PopTFrwtok (Record, RecordType, rw, rectok) ; |
| 12186 |
|
| 12187 |
Ref := MakeComponentRef (MakeComponentRecord (fieldtok, |
| 12188 |
RightValue, Record), Field) ; |
| 12189 |
PutVarConst (Ref, IsReadOnly (Record)) ; |
| 12190 |
GenQuadO (fieldtok, |
| 12191 |
RecordFieldOp, Ref, Record, Field, TRUE) ; |
| 12192 |
|
| 12193 |
PushTFrwtok (Ref, FieldType, rw, fieldtok) ; |
| 12194 |
SuppressWith := OldSuppressWith |
| 12195 |
END BuildAccessWithField ; |
| 12196 |
|
| 12197 |
|
| 12198 |
(* |
| 12199 |
BuildNulExpression - Builds a nul expression on the stack. |
| 12200 |
The Stack: |
| 12201 |
|
| 12202 |
Entry Exit |
| 12203 |
|
| 12204 |
<- Ptr |
| 12205 |
Empty +------------+ |
| 12206 |
| NulSym | |
| 12207 |
|------------| |
| 12208 |
tokpos is the position of the RETURN token. |
| 12209 |
*) |
| 12210 |
|
| 12211 |
PROCEDURE BuildNulExpression (tokpos: CARDINAL) ; |
| 12212 |
BEGIN |
| 12213 |
PushTtok (NulSym, tokpos) |
| 12214 |
END BuildNulExpression ; |
| 12215 |
|
| 12216 |
|
| 12217 |
(* |
| 12218 |
BuildTypeForConstructor - pushes the type implied by the current constructor. |
| 12219 |
If no constructor is currently being built then |
| 12220 |
it Pushes a Bitset type. |
| 12221 |
*) |
| 12222 |
|
| 12223 |
PROCEDURE BuildTypeForConstructor (tokpos: CARDINAL) ; |
| 12224 |
VAR |
| 12225 |
c: ConstructorFrame ; |
| 12226 |
BEGIN |
| 12227 |
IF NoOfItemsInStackAddress(ConstructorStack)=0 |
| 12228 |
THEN |
| 12229 |
PushTtok (Bitset, tokpos) |
| 12230 |
ELSE |
| 12231 |
c := PeepAddress(ConstructorStack, 1) ; |
| 12232 |
WITH c^ DO |
| 12233 |
IF IsArray (type) OR IsSet (type) |
| 12234 |
THEN |
| 12235 |
PushTtok (GetSType (type), tokpos) |
| 12236 |
ELSIF IsRecord (type) |
| 12237 |
THEN |
| 12238 |
PushTtok (GetSType (GetNth (type, index)), tokpos) |
| 12239 |
ELSE |
| 12240 |
MetaError1 ('{%1ad} is not a set, record or array type which is expected when constructing an aggregate entity', |
| 12241 |
type) |
| 12242 |
END |
| 12243 |
END |
| 12244 |
END |
| 12245 |
END BuildTypeForConstructor ; |
| 12246 |
|
| 12247 |
|
| 12248 |
(* |
| 12249 |
BuildSetStart - Pushes a Bitset type on the stack. |
| 12250 |
|
| 12251 |
The Stack: |
| 12252 |
|
| 12253 |
Entry Exit |
| 12254 |
|
| 12255 |
Ptr -> <- Ptr |
| 12256 |
|
| 12257 |
Empty +--------------+ |
| 12258 |
| Bitset | |
| 12259 |
|--------------| |
| 12260 |
*) |
| 12261 |
|
| 12262 |
PROCEDURE BuildSetStart (tokpos: CARDINAL) ; |
| 12263 |
BEGIN |
| 12264 |
PushTtok (Bitset, tokpos) |
| 12265 |
END BuildSetStart ; |
| 12266 |
|
| 12267 |
|
| 12268 |
(* |
| 12269 |
BuildSetEnd - pops the set value and type from the stack |
| 12270 |
and pushes the value,type pair. |
| 12271 |
|
| 12272 |
Entry Exit |
| 12273 |
|
| 12274 |
Ptr -> |
| 12275 |
+--------------+ |
| 12276 |
| Set Value | <- Ptr |
| 12277 |
|--------------| +--------------+ |
| 12278 |
| Set Type | | Value | Type | |
| 12279 |
|--------------| |--------------| |
| 12280 |
*) |
| 12281 |
|
| 12282 |
PROCEDURE BuildSetEnd ; |
| 12283 |
VAR |
| 12284 |
valuepos, typepos, |
| 12285 |
combined, |
| 12286 |
value, type : CARDINAL ; |
| 12287 |
BEGIN |
| 12288 |
PopTtok (value, valuepos) ; |
| 12289 |
PopTtok (type, typepos) ; |
| 12290 |
combined := MakeVirtual2Tok (typepos, valuepos) ; |
| 12291 |
PushTFtok (value, type, combined) ; |
| 12292 |
Assert (IsSet (type)) |
| 12293 |
END BuildSetEnd ; |
| 12294 |
|
| 12295 |
|
| 12296 |
(* |
| 12297 |
BuildEmptySet - Builds an empty set on the stack. |
| 12298 |
The Stack: |
| 12299 |
|
| 12300 |
Entry Exit |
| 12301 |
|
| 12302 |
<- Ptr |
| 12303 |
+-------------+ |
| 12304 |
Ptr -> | Value | |
| 12305 |
+-----------+ |-------------| |
| 12306 |
| SetType | | SetType | |
| 12307 |
|-----------| |-------------| |
| 12308 |
|
| 12309 |
tokpos points to the opening '{'. |
| 12310 |
*) |
| 12311 |
|
| 12312 |
PROCEDURE BuildEmptySet (tokpos: CARDINAL) ; |
| 12313 |
VAR |
| 12314 |
n : Name ; |
| 12315 |
typepos, |
| 12316 |
Type : CARDINAL ; |
| 12317 |
NulSet : CARDINAL ; |
| 12318 |
BEGIN |
| 12319 |
PopTtok (Type, typepos) ; (* type of set we are building *) |
| 12320 |
IF (Type = NulSym) AND Pim |
| 12321 |
THEN |
| 12322 |
(* allowed generic {} in PIM Modula-2 *) |
| 12323 |
typepos := tokpos |
| 12324 |
ELSIF IsUnknown (Type) |
| 12325 |
THEN |
| 12326 |
n := GetSymName (Type) ; |
| 12327 |
WriteFormat1 ('set type %a is undefined', n) ; |
| 12328 |
Type := Bitset |
| 12329 |
ELSIF NOT IsSet (SkipType (Type)) |
| 12330 |
THEN |
| 12331 |
n := GetSymName (Type) ; |
| 12332 |
WriteFormat1('expecting a set type %a', n) ; |
| 12333 |
Type := Bitset |
| 12334 |
ELSE |
| 12335 |
Type := SkipType (Type) ; |
| 12336 |
Assert (Type # NulSym) |
| 12337 |
END ; |
| 12338 |
NulSet := MakeTemporary (typepos, ImmediateValue) ; |
| 12339 |
PutVar (NulSet, Type) ; |
| 12340 |
PutConstSet (NulSet) ; |
| 12341 |
IF CompilerDebugging |
| 12342 |
THEN |
| 12343 |
n := GetSymName (Type) ; |
| 12344 |
printf1 ('set type = %a\n', n) |
| 12345 |
END ; |
| 12346 |
PushNulSet (Type) ; (* onto the ALU stack *) |
| 12347 |
PopValue (NulSet) ; (* ALU -> symbol table *) |
| 12348 |
|
| 12349 |
(* and now construct the M2Quads stack as defined by the comments above *) |
| 12350 |
PushTtok (Type, typepos) ; |
| 12351 |
PushTtok (NulSet, typepos) ; |
| 12352 |
IF CompilerDebugging |
| 12353 |
THEN |
| 12354 |
n := GetSymName (Type) ; |
| 12355 |
printf2 ('Type = %a (%d) built empty set\n', n, Type) ; |
| 12356 |
DisplayStack (* Debugging info *) |
| 12357 |
END |
| 12358 |
END BuildEmptySet ; |
| 12359 |
|
| 12360 |
|
| 12361 |
(* |
| 12362 |
BuildInclRange - includes a set range with a set. |
| 12363 |
|
| 12364 |
|
| 12365 |
Entry Exit |
| 12366 |
===== ==== |
| 12367 |
|
| 12368 |
|
| 12369 |
Ptr -> |
| 12370 |
+------------+ |
| 12371 |
| El2 | |
| 12372 |
|------------| |
| 12373 |
| El1 | <- Ptr |
| 12374 |
|------------| +-------------------+ |
| 12375 |
| Set Value | | Value + {El1..El2}| |
| 12376 |
|------------| |-------------------| |
| 12377 |
|
| 12378 |
No quadruples produced as the range info is contained within |
| 12379 |
the set value. |
| 12380 |
*) |
| 12381 |
|
| 12382 |
PROCEDURE BuildInclRange ; |
| 12383 |
VAR |
| 12384 |
n : Name ; |
| 12385 |
el1, el2, |
| 12386 |
value : CARDINAL ; |
| 12387 |
BEGIN |
| 12388 |
PopT(el2) ; |
| 12389 |
PopT(el1) ; |
| 12390 |
PopT(value) ; |
| 12391 |
IF NOT IsConstSet(value) |
| 12392 |
THEN |
| 12393 |
n := GetSymName(el1) ; |
| 12394 |
WriteFormat1('can only add bit ranges to a constant set, %a is not a constant set', n) |
| 12395 |
END ; |
| 12396 |
IF IsConst(el1) AND IsConst(el2) |
| 12397 |
THEN |
| 12398 |
PushValue(value) ; (* onto ALU stack *) |
| 12399 |
AddBitRange(GetTokenNo(), el1, el2) ; |
| 12400 |
PopValue(value) (* ALU -> symboltable *) |
| 12401 |
ELSE |
| 12402 |
IF NOT IsConst(el1) |
| 12403 |
THEN |
| 12404 |
n := GetSymName(el1) ; |
| 12405 |
WriteFormat1('must use constants as ranges when defining a set constant, problem with the low value %a', n) |
| 12406 |
END ; |
| 12407 |
IF NOT IsConst(el2) |
| 12408 |
THEN |
| 12409 |
n := GetSymName(el2) ; |
| 12410 |
WriteFormat1('must use constants as ranges when defining a set constant, problem with the high value %a', n) |
| 12411 |
END |
| 12412 |
END ; |
| 12413 |
PushT(value) |
| 12414 |
END BuildInclRange ; |
| 12415 |
|
| 12416 |
|
| 12417 |
(* |
| 12418 |
BuildInclBit - includes a bit into the set. |
| 12419 |
|
| 12420 |
Entry Exit |
| 12421 |
===== ==== |
| 12422 |
|
| 12423 |
|
| 12424 |
Ptr -> |
| 12425 |
+------------+ |
| 12426 |
| Element | <- Ptr |
| 12427 |
|------------| +------------+ |
| 12428 |
| Value | | Value | |
| 12429 |
|------------| |------------| |
| 12430 |
|
| 12431 |
*) |
| 12432 |
|
| 12433 |
PROCEDURE BuildInclBit ; |
| 12434 |
VAR |
| 12435 |
tok : CARDINAL ; |
| 12436 |
el, value, t: CARDINAL ; |
| 12437 |
BEGIN |
| 12438 |
PopT(el) ; |
| 12439 |
PopT(value) ; |
| 12440 |
tok := GetTokenNo () ; |
| 12441 |
IF IsConst(el) |
| 12442 |
THEN |
| 12443 |
PushValue(value) ; (* onto ALU stack *) |
| 12444 |
AddBit(tok, el) ; |
| 12445 |
PopValue(value) (* ALU -> symboltable *) |
| 12446 |
ELSE |
| 12447 |
IF GetMode(el)=LeftValue |
| 12448 |
THEN |
| 12449 |
t := MakeTemporary(tok, RightValue) ; |
| 12450 |
PutVar(t, GetSType(el)) ; |
| 12451 |
CheckPointerThroughNil (tok, el) ; |
| 12452 |
doIndrX(tok, t, el) ; |
| 12453 |
el := t |
| 12454 |
END ; |
| 12455 |
IF IsConst(value) |
| 12456 |
THEN |
| 12457 |
(* move constant into a variable to achieve the include *) |
| 12458 |
t := MakeTemporary(tok, RightValue) ; |
| 12459 |
PutVar(t, GetSType(value)) ; |
| 12460 |
GenQuad(BecomesOp, t, NulSym, value) ; |
| 12461 |
value := t |
| 12462 |
END ; |
| 12463 |
GenQuad(InclOp, value, NulSym, el) |
| 12464 |
END ; |
| 12465 |
PushT(value) |
| 12466 |
END BuildInclBit ; |
| 12467 |
|
| 12468 |
|
| 12469 |
(* |
| 12470 |
PushConstructor - |
| 12471 |
*) |
| 12472 |
|
| 12473 |
PROCEDURE PushConstructor (sym: CARDINAL) ; |
| 12474 |
VAR |
| 12475 |
c: ConstructorFrame ; |
| 12476 |
BEGIN |
| 12477 |
NEW(c) ; |
| 12478 |
WITH c^ DO |
| 12479 |
type := SkipType(sym) ; |
| 12480 |
index := 1 |
| 12481 |
END ; |
| 12482 |
PushAddress(ConstructorStack, c) |
| 12483 |
END PushConstructor ; |
| 12484 |
|
| 12485 |
|
| 12486 |
(* |
| 12487 |
PopConstructor - removes the top constructor from the top of stack. |
| 12488 |
*) |
| 12489 |
|
| 12490 |
PROCEDURE PopConstructor ; |
| 12491 |
VAR |
| 12492 |
c: ConstructorFrame ; |
| 12493 |
BEGIN |
| 12494 |
c := PopAddress (ConstructorStack) ; |
| 12495 |
DISPOSE(c) |
| 12496 |
END PopConstructor ; |
| 12497 |
|
| 12498 |
|
| 12499 |
(* |
| 12500 |
NextConstructorField - increments the top of constructor stacks index by one. |
| 12501 |
*) |
| 12502 |
|
| 12503 |
PROCEDURE NextConstructorField ; |
| 12504 |
VAR |
| 12505 |
c: ConstructorFrame ; |
| 12506 |
BEGIN |
| 12507 |
c := PeepAddress(ConstructorStack, 1) ; |
| 12508 |
INC(c^.index) |
| 12509 |
END NextConstructorField ; |
| 12510 |
|
| 12511 |
|
| 12512 |
(* |
| 12513 |
SilentBuildConstructor - places NulSym into the constructor fifo queue. |
| 12514 |
*) |
| 12515 |
|
| 12516 |
PROCEDURE SilentBuildConstructor ; |
| 12517 |
BEGIN |
| 12518 |
PutConstructorIntoFifoQueue (NulSym) |
| 12519 |
END SilentBuildConstructor ; |
| 12520 |
|
| 12521 |
|
| 12522 |
(* |
| 12523 |
BuildConstructor - builds a constructor. |
| 12524 |
Stack |
| 12525 |
|
| 12526 |
Entry Exit |
| 12527 |
|
| 12528 |
Ptr -> |
| 12529 |
+------------+ |
| 12530 |
| Type | <- Ptr |
| 12531 |
|------------+ |
| 12532 |
*) |
| 12533 |
|
| 12534 |
PROCEDURE BuildConstructor (tokcbrpos: CARDINAL) ; |
| 12535 |
VAR |
| 12536 |
tok : CARDINAL ; |
| 12537 |
constValue, |
| 12538 |
type : CARDINAL ; |
| 12539 |
BEGIN |
| 12540 |
PopTtok (type, tok) ; |
| 12541 |
constValue := MakeTemporary (tok, ImmediateValue) ; |
| 12542 |
PutVar (constValue, type) ; |
| 12543 |
PutConstructor (constValue) ; |
| 12544 |
PushValue (constValue) ; |
| 12545 |
IF type = NulSym |
| 12546 |
THEN |
| 12547 |
MetaErrorT0 (tokcbrpos, |
| 12548 |
'{%E}constructor requires a type before the opening %{') |
| 12549 |
ELSE |
| 12550 |
ChangeToConstructor (tok, type) ; |
| 12551 |
PutConstructorFrom (constValue, type) ; |
| 12552 |
PopValue (constValue) ; |
| 12553 |
PutConstructorIntoFifoQueue (constValue) |
| 12554 |
END ; |
| 12555 |
PushConstructor (type) |
| 12556 |
END BuildConstructor ; |
| 12557 |
|
| 12558 |
|
| 12559 |
(* |
| 12560 |
SilentBuildConstructorStart - removes an entry from the constructor fifo queue. |
| 12561 |
*) |
| 12562 |
|
| 12563 |
PROCEDURE SilentBuildConstructorStart ; |
| 12564 |
VAR |
| 12565 |
constValue: CARDINAL ; |
| 12566 |
BEGIN |
| 12567 |
GetConstructorFromFifoQueue (constValue) |
| 12568 |
END SilentBuildConstructorStart ; |
| 12569 |
|
| 12570 |
|
| 12571 |
(* |
| 12572 |
BuildConstructorStart - builds a constructor. |
| 12573 |
Stack |
| 12574 |
|
| 12575 |
Entry Exit |
| 12576 |
|
| 12577 |
Ptr -> <- Ptr |
| 12578 |
+------------+ +----------------+ |
| 12579 |
| Type | | ConstructorSym | |
| 12580 |
|------------+ |----------------| |
| 12581 |
*) |
| 12582 |
|
| 12583 |
PROCEDURE BuildConstructorStart (cbratokpos: CARDINAL) ; |
| 12584 |
VAR |
| 12585 |
typepos, |
| 12586 |
constValue, |
| 12587 |
type : CARDINAL ; |
| 12588 |
BEGIN |
| 12589 |
PopTtok (type, typepos) ; (* we ignore the type as we already have the constructor symbol from pass C *) |
| 12590 |
GetConstructorFromFifoQueue (constValue) ; |
| 12591 |
IF type # GetSType (constValue) |
| 12592 |
THEN |
| 12593 |
MetaErrorT3 (cbratokpos, |
| 12594 |
'{%E}the constructor type is {%1ad} and this is different from the constant {%2ad} which has a type {%2tad}', |
| 12595 |
type, constValue, constValue) |
| 12596 |
END ; |
| 12597 |
PushTtok (constValue, cbratokpos) ; |
| 12598 |
PushConstructor (type) |
| 12599 |
END BuildConstructorStart ; |
| 12600 |
|
| 12601 |
|
| 12602 |
(* |
| 12603 |
BuildConstructorEnd - removes the current constructor frame from the |
| 12604 |
constructor stack (it does not effect the quad |
| 12605 |
stack) |
| 12606 |
|
| 12607 |
Entry Exit |
| 12608 |
|
| 12609 |
Ptr -> <- Ptr |
| 12610 |
+------------+ +------------+ |
| 12611 |
| const | | const | |
| 12612 |
|------------| |------------| |
| 12613 |
|
| 12614 |
startpos is the start of the constructor, either the typename or '{' |
| 12615 |
cbratokpos is the '}'. |
| 12616 |
*) |
| 12617 |
|
| 12618 |
PROCEDURE BuildConstructorEnd (startpos, cbratokpos: CARDINAL) ; |
| 12619 |
VAR |
| 12620 |
value, valtok: CARDINAL ; |
| 12621 |
BEGIN |
| 12622 |
IF DebugTokPos |
| 12623 |
THEN |
| 12624 |
WarnStringAt (InitString ('startpos'), startpos) ; |
| 12625 |
WarnStringAt (InitString ('cbratokpos'), cbratokpos) |
| 12626 |
END ; |
| 12627 |
PopTtok (value, valtok) ; |
| 12628 |
IF DebugTokPos |
| 12629 |
THEN |
| 12630 |
WarnStringAt (InitString ('value valtok'), valtok) |
| 12631 |
END ; |
| 12632 |
valtok := MakeVirtual2Tok (startpos, cbratokpos) ; |
| 12633 |
PutDeclared (valtok, value) ; |
| 12634 |
PushTtok (value, valtok) ; (* Use valtok as we now know it was a constructor. *) |
| 12635 |
PopConstructor ; |
| 12636 |
IF DebugTokPos |
| 12637 |
THEN |
| 12638 |
WarnStringAt (InitString ('aggregate constant'), valtok) |
| 12639 |
END |
| 12640 |
END BuildConstructorEnd ; |
| 12641 |
|
| 12642 |
|
| 12643 |
(* |
| 12644 |
AddFieldTo - adds field, e, to, value. |
| 12645 |
*) |
| 12646 |
|
| 12647 |
PROCEDURE AddFieldTo (value, e: CARDINAL) : CARDINAL ; |
| 12648 |
BEGIN |
| 12649 |
IF IsSet(GetDType(value)) |
| 12650 |
THEN |
| 12651 |
PutConstSet(value) ; |
| 12652 |
PushT(value) ; |
| 12653 |
PushT(e) ; |
| 12654 |
BuildInclBit ; |
| 12655 |
PopT(value) |
| 12656 |
ELSE |
| 12657 |
PushValue(value) ; |
| 12658 |
AddField(GetTokenNo(), e) ; |
| 12659 |
PopValue(value) |
| 12660 |
END ; |
| 12661 |
RETURN( value ) |
| 12662 |
END AddFieldTo ; |
| 12663 |
|
| 12664 |
|
| 12665 |
(* |
| 12666 |
BuildComponentValue - builds a component value. |
| 12667 |
|
| 12668 |
Entry Exit |
| 12669 |
|
| 12670 |
Ptr -> <- Ptr |
| 12671 |
|
| 12672 |
|
| 12673 |
+------------+ +------------+ |
| 12674 |
| const | | const | |
| 12675 |
|------------| |------------| |
| 12676 |
*) |
| 12677 |
|
| 12678 |
PROCEDURE BuildComponentValue ; |
| 12679 |
VAR |
| 12680 |
const, |
| 12681 |
e1, e2 : CARDINAL ; |
| 12682 |
nuldotdot, |
| 12683 |
nulby : Name ; |
| 12684 |
BEGIN |
| 12685 |
PopT(nulby) ; |
| 12686 |
IF nulby=NulTok |
| 12687 |
THEN |
| 12688 |
PopT(nuldotdot) ; |
| 12689 |
IF nuldotdot=NulTok |
| 12690 |
THEN |
| 12691 |
PopT(e1) ; |
| 12692 |
PopT(const) ; |
| 12693 |
PushT(AddFieldTo(const, e1)) |
| 12694 |
ELSE |
| 12695 |
PopT(e2) ; |
| 12696 |
PopT(e1) ; |
| 12697 |
PopT(const) ; |
| 12698 |
PushValue(const) ; |
| 12699 |
AddBitRange(GetTokenNo(), e1, e2) ; |
| 12700 |
PopValue(const) ; |
| 12701 |
PushT(const) |
| 12702 |
END |
| 12703 |
ELSE |
| 12704 |
PopT(e1) ; |
| 12705 |
PopT(nuldotdot) ; |
| 12706 |
IF nuldotdot=NulTok |
| 12707 |
THEN |
| 12708 |
PopT(e2) ; |
| 12709 |
PopT(const) ; |
| 12710 |
PushValue(const) ; |
| 12711 |
AddElements(GetTokenNo(), e2, e1) ; |
| 12712 |
PopValue(const) ; |
| 12713 |
PushT(const) |
| 12714 |
ELSE |
| 12715 |
PopT(e2) ; |
| 12716 |
PopT(e1) ; |
| 12717 |
PopT(const) ; |
| 12718 |
WriteFormat0('the constant must be either an array constructor or a set constructor') ; |
| 12719 |
PushT(const) |
| 12720 |
END |
| 12721 |
END |
| 12722 |
END BuildComponentValue ; |
| 12723 |
|
| 12724 |
|
| 12725 |
(* |
| 12726 |
RecordOp - Records the operator passed on the stack. |
| 12727 |
This is called when a boolean operator is found in an |
| 12728 |
expression. It is called just after the lhs has been built |
| 12729 |
and pushed to the quad stack and prior to the rhs build. |
| 12730 |
It checks to see if AND OR or equality tests are required. |
| 12731 |
It will short circuit AND and OR expressions. It also |
| 12732 |
converts a lhs to a boolean variable if an xor comparison |
| 12733 |
is about to be performed. |
| 12734 |
|
| 12735 |
Checks for AND operator or OR operator |
| 12736 |
if either of these operators are found then BackPatching |
| 12737 |
takes place. |
| 12738 |
The Expected Stack: |
| 12739 |
|
| 12740 |
Entry Exit |
| 12741 |
|
| 12742 |
Ptr -> <- Ptr |
| 12743 |
+-------------+ +-------------+ |
| 12744 |
| OperatorTok | | OperatorTok | |
| 12745 |
|-------------| |-------------| |
| 12746 |
| t | f | | t | f | |
| 12747 |
|-------------| |-------------| |
| 12748 |
|
| 12749 |
|
| 12750 |
If OperatorTok=AndTok |
| 12751 |
Then |
| 12752 |
BackPatch(f, NextQuad) |
| 12753 |
Elsif OperatorTok=OrTok |
| 12754 |
Then |
| 12755 |
BackPatch(t, NextQuad) |
| 12756 |
End |
| 12757 |
*) |
| 12758 |
|
| 12759 |
PROCEDURE RecordOp ; |
| 12760 |
VAR |
| 12761 |
Op : Name ; |
| 12762 |
tokno: CARDINAL ; |
| 12763 |
t, f : CARDINAL ; |
| 12764 |
BEGIN |
| 12765 |
PopTtok(Op, tokno) ; |
| 12766 |
IF (Op=AndTok) OR (Op=AmbersandTok) |
| 12767 |
THEN |
| 12768 |
CheckBooleanId ; |
| 12769 |
PopBool(t, f) ; |
| 12770 |
BackPatch(t, NextQuad) ; |
| 12771 |
PushBool(0, f) |
| 12772 |
ELSIF Op=OrTok |
| 12773 |
THEN |
| 12774 |
CheckBooleanId ; |
| 12775 |
PopBool(t, f) ; |
| 12776 |
BackPatch(f, NextQuad) ; |
| 12777 |
PushBool(t, 0) |
| 12778 |
ELSIF IsBoolean (1) AND |
| 12779 |
((Op = EqualTok) OR (Op = LessGreaterTok) OR (Op = HashTok) OR (Op = InTok)) |
| 12780 |
THEN |
| 12781 |
ConvertBooleanToVariable (tokno, 1) |
| 12782 |
END ; |
| 12783 |
PushTtok(Op, tokno) |
| 12784 |
END RecordOp ; |
| 12785 |
|
| 12786 |
|
| 12787 |
(* |
| 12788 |
CheckLogicalOperator - returns a logical operator if the operands imply |
| 12789 |
a logical operation should be performed. |
| 12790 |
*) |
| 12791 |
|
| 12792 |
PROCEDURE CheckLogicalOperator (Tok: Name; left, lefttype: CARDINAL) : Name ; |
| 12793 |
BEGIN |
| 12794 |
IF (Tok=PlusTok) OR (Tok=TimesTok) OR (Tok=DivideTok) OR (Tok=MinusTok) |
| 12795 |
THEN |
| 12796 |
(* --fixme-- when we add complex arithmetic, we must check constructor is not a complex constant. *) |
| 12797 |
IF ((lefttype#NulSym) AND IsSet(SkipType(lefttype))) OR |
| 12798 |
IsConstSet(left) OR IsConstructor(left) |
| 12799 |
THEN |
| 12800 |
IF Tok=PlusTok |
| 12801 |
THEN |
| 12802 |
RETURN( LogicalOrTok ) |
| 12803 |
ELSIF Tok=DivideTok |
| 12804 |
THEN |
| 12805 |
RETURN( LogicalXorTok ) |
| 12806 |
ELSIF Tok=TimesTok |
| 12807 |
THEN |
| 12808 |
RETURN( LogicalAndTok ) |
| 12809 |
ELSIF Tok=MinusTok |
| 12810 |
THEN |
| 12811 |
RETURN( LogicalDifferenceTok ) |
| 12812 |
END |
| 12813 |
END |
| 12814 |
END ; |
| 12815 |
RETURN( Tok ) |
| 12816 |
END CheckLogicalOperator ; |
| 12817 |
|
| 12818 |
|
| 12819 |
(* |
| 12820 |
doCheckGenericNulSet - checks to see whether e1 is a generic nul set and if so it alters it |
| 12821 |
to the nul set of t2. |
| 12822 |
*) |
| 12823 |
|
| 12824 |
(* |
| 12825 |
PROCEDURE doCheckGenericNulSet (e1: CARDINAL; VAR t1: CARDINAL; t2: CARDINAL) ; |
| 12826 |
BEGIN |
| 12827 |
IF IsConstSet (e1) |
| 12828 |
THEN |
| 12829 |
IF NOT IsSet (t2) |
| 12830 |
THEN |
| 12831 |
MetaError2 ('incompatibility between a set constant {%1Ea} of type {%1tsa} and an object of type {%2sa}', |
| 12832 |
e1, t2) |
| 12833 |
END ; |
| 12834 |
PushValue (e1) ; |
| 12835 |
IF IsGenericNulSet () |
| 12836 |
THEN |
| 12837 |
PopValue (e1) ; |
| 12838 |
PushNulSet (t2) ; |
| 12839 |
t1 := t2 |
| 12840 |
END ; |
| 12841 |
PopValue (e1) |
| 12842 |
END |
| 12843 |
END doCheckGenericNulSet ; |
| 12844 |
*) |
| 12845 |
|
| 12846 |
|
| 12847 |
(* |
| 12848 |
CheckGenericNulSet - if e1 or e2 is the generic nul set then |
| 12849 |
alter it to the nul set of the other operands type. |
| 12850 |
*) |
| 12851 |
|
| 12852 |
(* |
| 12853 |
PROCEDURE CheckGenericNulSet (e1, e2: CARDINAL; VAR t1, t2: CARDINAL) ; |
| 12854 |
BEGIN |
| 12855 |
IF t1#t2 |
| 12856 |
THEN |
| 12857 |
doCheckGenericNulSet(e1, t1, t2) ; |
| 12858 |
doCheckGenericNulSet(e2, t2, t1) |
| 12859 |
END |
| 12860 |
END CheckGenericNulSet ; |
| 12861 |
*) |
| 12862 |
|
| 12863 |
|
| 12864 |
(* |
| 12865 |
CheckDivModRem - initiates calls to check the divisor for DIV, MOD, REM |
| 12866 |
expressions. |
| 12867 |
*) |
| 12868 |
|
| 12869 |
PROCEDURE CheckDivModRem (TokPos: CARDINAL; tok: Name; d, e: CARDINAL) ; |
| 12870 |
BEGIN |
| 12871 |
IF tok=DivTok |
| 12872 |
THEN |
| 12873 |
BuildRange (InitWholeZeroDivisionCheck (TokPos, d, e)) |
| 12874 |
ELSIF tok=ModTok |
| 12875 |
THEN |
| 12876 |
BuildRange (InitWholeZeroDivisionCheck (TokPos, d, e)) |
| 12877 |
ELSIF tok=RemTok |
| 12878 |
THEN |
| 12879 |
BuildRange (InitWholeZeroRemainderCheck (TokPos, d, e)) |
| 12880 |
END |
| 12881 |
END CheckDivModRem ; |
| 12882 |
|
| 12883 |
|
| 12884 |
(* |
| 12885 |
doConvert - convert, sym, to a new symbol with, type. |
| 12886 |
Return the new symbol. |
| 12887 |
*) |
| 12888 |
|
| 12889 |
PROCEDURE doConvert (type: CARDINAL; sym: CARDINAL) : CARDINAL ; |
| 12890 |
BEGIN |
| 12891 |
IF GetSType(sym)#type |
| 12892 |
THEN |
| 12893 |
PushTF(Convert, NulSym) ; |
| 12894 |
PushT(type) ; |
| 12895 |
PushT(sym) ; |
| 12896 |
PushT(2) ; (* Two parameters *) |
| 12897 |
BuildConvertFunction (Convert, FALSE) ; |
| 12898 |
PopT(sym) |
| 12899 |
END ; |
| 12900 |
RETURN( sym ) |
| 12901 |
END doConvert ; |
| 12902 |
|
| 12903 |
|
| 12904 |
(* |
| 12905 |
BuildBinaryOp - Builds a binary operation from the quad stack. |
| 12906 |
Be aware that this procedure will check for |
| 12907 |
the overloading of the bitset operators + - \ *. |
| 12908 |
So do NOT call this procedure if you are building |
| 12909 |
a reference to an array which has a bitset type or |
| 12910 |
the address arithmetic will be wrongly coersed into |
| 12911 |
logical ORs. |
| 12912 |
|
| 12913 |
The Stack is expected to contain: |
| 12914 |
|
| 12915 |
|
| 12916 |
Entry Exit |
| 12917 |
===== ==== |
| 12918 |
|
| 12919 |
Ptr -> |
| 12920 |
+------------+ |
| 12921 |
| Sym1 | |
| 12922 |
|------------| |
| 12923 |
| Operator | <- Ptr |
| 12924 |
|------------| +------------+ |
| 12925 |
| Sym2 | | Temporary | |
| 12926 |
|------------| |------------| |
| 12927 |
|
| 12928 |
|
| 12929 |
Quadruples Produced |
| 12930 |
|
| 12931 |
q Operator Temporary Sym1 Sym2 |
| 12932 |
|
| 12933 |
|
| 12934 |
OR |
| 12935 |
|
| 12936 |
|
| 12937 |
Entry Exit |
| 12938 |
===== ==== |
| 12939 |
|
| 12940 |
Ptr -> |
| 12941 |
+------------+ |
| 12942 |
| T1 | F1 | |
| 12943 |
|------------| |
| 12944 |
| OrTok | <- Ptr |
| 12945 |
|------------| +------------+ |
| 12946 |
| T2 | F2 | | T1+T2| F1 | |
| 12947 |
|------------| |------------| |
| 12948 |
|
| 12949 |
|
| 12950 |
Quadruples Produced |
| 12951 |
|
| 12952 |
*) |
| 12953 |
|
| 12954 |
PROCEDURE BuildBinaryOp ; |
| 12955 |
BEGIN |
| 12956 |
doBuildBinaryOp (TRUE, TRUE) |
| 12957 |
END BuildBinaryOp ; |
| 12958 |
|
| 12959 |
|
| 12960 |
(* |
| 12961 |
doBuildBinaryOp - build the binary op, with or without type |
| 12962 |
checking. |
| 12963 |
*) |
| 12964 |
|
| 12965 |
PROCEDURE doBuildBinaryOp (checkTypes, checkOverflow: BOOLEAN) ; |
| 12966 |
VAR |
| 12967 |
s : String ; |
| 12968 |
NewOp, |
| 12969 |
Operator : Name ; |
| 12970 |
OperatorPos, |
| 12971 |
OldPos, |
| 12972 |
leftrw, rightrw, |
| 12973 |
t1, f1, |
| 12974 |
t2, f2, |
| 12975 |
lefttype, righttype, |
| 12976 |
left, right, |
| 12977 |
leftpos, rightpos : CARDINAL ; |
| 12978 |
value : CARDINAL ; |
| 12979 |
BEGIN |
| 12980 |
Operator := OperandT (2) ; |
| 12981 |
IF Operator = OrTok |
| 12982 |
THEN |
| 12983 |
CheckBooleanId ; |
| 12984 |
PopBooltok (t1, f1, rightpos) ; |
| 12985 |
PopTtok (Operator, OperatorPos) ; |
| 12986 |
PopBooltok (t2, f2, leftpos) ; |
| 12987 |
Assert (f2=0) ; |
| 12988 |
OperatorPos := MakeVirtualTok (OperatorPos, leftpos, rightpos) ; |
| 12989 |
PushBooltok (Merge (t1, t2), f1, OperatorPos) |
| 12990 |
ELSIF (Operator = AndTok) OR (Operator = AmbersandTok) |
| 12991 |
THEN |
| 12992 |
CheckBooleanId ; |
| 12993 |
PopBooltok (t1, f1, rightpos) ; |
| 12994 |
PopTtok (Operator, OperatorPos) ; |
| 12995 |
PopBooltok (t2, f2, leftpos) ; |
| 12996 |
Assert (t2=0) ; |
| 12997 |
OperatorPos := MakeVirtualTok (OperatorPos, leftpos, rightpos) ; |
| 12998 |
PushBooltok (t1, Merge (f1, f2), OperatorPos) |
| 12999 |
ELSE |
| 13000 |
PopTFrwtok (right, righttype, rightrw, rightpos) ; |
| 13001 |
PopTtok (Operator, OperatorPos) ; |
| 13002 |
PopTFrwtok (left, lefttype, leftrw, leftpos) ; |
| 13003 |
MarkAsRead (rightrw) ; |
| 13004 |
MarkAsRead (leftrw) ; |
| 13005 |
NewOp := CheckLogicalOperator (Operator, (* right, righttype, *) left, lefttype) ; |
| 13006 |
IF NewOp = Operator |
| 13007 |
THEN |
| 13008 |
(* |
| 13009 |
BinaryOps and UnaryOps only work with immediate and |
| 13010 |
offset addressing. This is fine for calculating |
| 13011 |
array and record offsets but we need to get the real |
| 13012 |
values to perform normal arithmetic. Not address |
| 13013 |
arithmetic. |
| 13014 |
|
| 13015 |
However the set operators will dereference LValues |
| 13016 |
(to optimize large set arithemetic) |
| 13017 |
*) |
| 13018 |
IF GetMode (right) = LeftValue |
| 13019 |
THEN |
| 13020 |
value := MakeTemporary (rightpos, RightValue) ; |
| 13021 |
PutVar (value, righttype) ; |
| 13022 |
CheckPointerThroughNil (rightpos, right) ; |
| 13023 |
doIndrX (rightpos, value, right) ; |
| 13024 |
right := value |
| 13025 |
END ; |
| 13026 |
IF GetMode (left) = LeftValue |
| 13027 |
THEN |
| 13028 |
value := MakeTemporary (leftpos, RightValue) ; |
| 13029 |
PutVar (value, lefttype) ; |
| 13030 |
CheckPointerThroughNil (leftpos, left) ; |
| 13031 |
doIndrX (leftpos, value, left) ; |
| 13032 |
left := value |
| 13033 |
END |
| 13034 |
ELSE |
| 13035 |
(* CheckForGenericNulSet(e1, e2, t1, t2) *) |
| 13036 |
END ; |
| 13037 |
OldPos := OperatorPos ; |
| 13038 |
OperatorPos := MakeVirtualTok (OperatorPos, leftpos, rightpos) ; |
| 13039 |
IF (Operator = PlusTok) AND IsConstString(left) AND IsConstString(right) |
| 13040 |
THEN |
| 13041 |
value := MakeConstString (OperatorPos, NulName) ; |
| 13042 |
PutConstStringKnown (OperatorPos, value, NulName, FALSE, FALSE) ; |
| 13043 |
GenQuadOtok (OperatorPos, MakeOp (PlusTok), value, left, right, FALSE, |
| 13044 |
OperatorPos, leftpos, rightpos) |
| 13045 |
ELSE |
| 13046 |
IF checkTypes |
| 13047 |
THEN |
| 13048 |
BuildRange (InitTypesExpressionCheck (OperatorPos, left, right, FALSE, FALSE)) |
| 13049 |
END ; |
| 13050 |
value := MakeTemporaryFromExpressions (OperatorPos, |
| 13051 |
right, left, |
| 13052 |
AreConstant (IsConst (left) AND IsConst (right))) ; |
| 13053 |
|
| 13054 |
CheckDivModRem (OperatorPos, NewOp, value, right) ; |
| 13055 |
|
| 13056 |
IF DebugTokPos |
| 13057 |
THEN |
| 13058 |
s := InitStringCharStar (KeyToCharStar (GetTokenName (Operator))) ; |
| 13059 |
WarnStringAt (s, OldPos) ; |
| 13060 |
s := InitString ('left') ; |
| 13061 |
WarnStringAt (s, leftpos) ; |
| 13062 |
s := InitString ('right') ; |
| 13063 |
WarnStringAt (s, rightpos) ; |
| 13064 |
s := InitString ('caret') ; |
| 13065 |
WarnStringAt (s, OldPos) ; |
| 13066 |
s := InitString ('combined') ; |
| 13067 |
WarnStringAt (s, OperatorPos) ; |
| 13068 |
(* MetaErrorT1 (GetDeclaredMod (t), 'in binary with a {%1a}', t) *) |
| 13069 |
END ; |
| 13070 |
GenQuadOtok (OperatorPos, MakeOp (NewOp), value, left, right, checkOverflow, |
| 13071 |
OperatorPos, leftpos, rightpos) |
| 13072 |
END ; |
| 13073 |
PushTFtok (value, GetSType (value), OperatorPos) |
| 13074 |
END |
| 13075 |
END doBuildBinaryOp ; |
| 13076 |
|
| 13077 |
|
| 13078 |
(* |
| 13079 |
BuildUnaryOp - Builds a unary operation from the quad stack. |
| 13080 |
The Stack is expected to contain: |
| 13081 |
|
| 13082 |
|
| 13083 |
Entry Exit |
| 13084 |
===== ==== |
| 13085 |
|
| 13086 |
Ptr -> |
| 13087 |
+------------+ |
| 13088 |
| Sym | |
| 13089 |
|------------| +------------+ |
| 13090 |
| Operator | | Temporary | <- Ptr |
| 13091 |
|------------| |------------| |
| 13092 |
|
| 13093 |
|
| 13094 |
Quadruples Produced |
| 13095 |
|
| 13096 |
q Operator Temporary _ Sym |
| 13097 |
|
| 13098 |
*) |
| 13099 |
|
| 13100 |
PROCEDURE BuildUnaryOp ; |
| 13101 |
VAR |
| 13102 |
sympos, |
| 13103 |
tokpos : CARDINAL ; |
| 13104 |
Tok : Name ; |
| 13105 |
type, |
| 13106 |
Sym, |
| 13107 |
SymT, r, t: CARDINAL ; |
| 13108 |
BEGIN |
| 13109 |
PopTrwtok (Sym, r, sympos) ; |
| 13110 |
PopTtok (Tok, tokpos) ; |
| 13111 |
IF Tok=MinusTok |
| 13112 |
THEN |
| 13113 |
MarkAsRead(r) ; |
| 13114 |
type := NegateType (GetSType (Sym) (* , sympos *) ) ; |
| 13115 |
tokpos := MakeVirtualTok (tokpos, tokpos, sympos) ; |
| 13116 |
|
| 13117 |
t := MakeTemporary (tokpos, AreConstant(IsConst(Sym))) ; |
| 13118 |
PutVar(t, type) ; |
| 13119 |
|
| 13120 |
(* |
| 13121 |
variables must have a type and REAL/LONGREAL constants must |
| 13122 |
be typed |
| 13123 |
*) |
| 13124 |
|
| 13125 |
IF NOT IsConst(Sym) |
| 13126 |
THEN |
| 13127 |
IF (type#NulSym) AND IsSet(SkipType(type)) |
| 13128 |
THEN |
| 13129 |
(* do not dereference set variables *) |
| 13130 |
ELSIF GetMode(Sym)=LeftValue |
| 13131 |
THEN |
| 13132 |
(* dereference symbols which are not sets and which are variables *) |
| 13133 |
|
| 13134 |
SymT := MakeTemporary (sympos, RightValue) ; |
| 13135 |
PutVar (SymT, GetSType (Sym)) ; |
| 13136 |
CheckPointerThroughNil (sympos, Sym) ; |
| 13137 |
doIndrX (sympos, SymT, Sym) ; |
| 13138 |
Sym := SymT |
| 13139 |
END |
| 13140 |
END ; |
| 13141 |
GenQuadO (tokpos, NegateOp, t, NulSym, Sym, TRUE) ; |
| 13142 |
PushTtok (t, tokpos) |
| 13143 |
ELSIF Tok=PlusTok |
| 13144 |
THEN |
| 13145 |
tokpos := MakeVirtualTok (tokpos, tokpos, sympos) ; |
| 13146 |
PushTrwtok (Sym, r, tokpos) |
| 13147 |
ELSE |
| 13148 |
MetaErrorNT1 (tokpos, |
| 13149 |
'expecting an unary operator, seen {%Ek%a}', Tok) |
| 13150 |
END |
| 13151 |
END BuildUnaryOp ; |
| 13152 |
|
| 13153 |
|
| 13154 |
(* |
| 13155 |
AreConstant - returns immediate addressing mode if b is true else |
| 13156 |
offset mode is returned. b determines whether the |
| 13157 |
operands are all constant - in which case we can use |
| 13158 |
a constant temporary variable. |
| 13159 |
*) |
| 13160 |
|
| 13161 |
PROCEDURE AreConstant (b: BOOLEAN) : ModeOfAddr ; |
| 13162 |
BEGIN |
| 13163 |
IF b |
| 13164 |
THEN |
| 13165 |
RETURN ImmediateValue |
| 13166 |
ELSE |
| 13167 |
RETURN RightValue |
| 13168 |
END |
| 13169 |
END AreConstant ; |
| 13170 |
|
| 13171 |
|
| 13172 |
(* |
| 13173 |
ConvertBooleanToVariable - converts a BoolStack(i) from a Boolean True|False |
| 13174 |
exit pair into a variable containing the value TRUE or |
| 13175 |
FALSE. The parameter i is relative to the top |
| 13176 |
of the stack. |
| 13177 |
*) |
| 13178 |
|
| 13179 |
PROCEDURE ConvertBooleanToVariable (tok: CARDINAL; i: CARDINAL) ; |
| 13180 |
VAR |
| 13181 |
Des: CARDINAL ; |
| 13182 |
f : BoolFrame ; |
| 13183 |
BEGIN |
| 13184 |
Assert (IsBoolean (i)) ; |
| 13185 |
(* We need to convert the boolean top of stack into a variable or |
| 13186 |
constant boolean. *) |
| 13187 |
Des := MakeTemporary (tok, AreConstant (IsInConstExpression ())) ; |
| 13188 |
PutVar (Des, Boolean) ; |
| 13189 |
PutVarConditional (Des, TRUE) ; |
| 13190 |
PushTtok (Des, tok) ; (* we have just increased the stack so we must use i+1 *) |
| 13191 |
f := PeepAddress (BoolStack, i+1) ; |
| 13192 |
PushBool (f^.TrueExit, f^.FalseExit) ; |
| 13193 |
BuildAssignmentWithoutBounds (tok, FALSE, TRUE) ; |
| 13194 |
(* Restored stack after the BuildAssign... above. *) |
| 13195 |
f := PeepAddress (BoolStack, i) ; |
| 13196 |
WITH f^ DO |
| 13197 |
TrueExit := Des ; (* Alter Stack(i) to contain the variable. *) |
| 13198 |
FalseExit := Boolean ; |
| 13199 |
BooleanOp := FALSE ; (* No longer a Boolean True|False pair. *) |
| 13200 |
Unbounded := NulSym ; |
| 13201 |
Dimension := 0 ; |
| 13202 |
ReadWrite := NulSym ; |
| 13203 |
tokenno := tok ; |
| 13204 |
Annotation := KillString (Annotation) ; |
| 13205 |
Annotation := InitString ('%1s(%1d)|%2s(%2d)||boolean var|type') ; |
| 13206 |
RangeDep := 0 |
| 13207 |
END |
| 13208 |
END ConvertBooleanToVariable ; |
| 13209 |
|
| 13210 |
|
| 13211 |
(* |
| 13212 |
BuildBooleanVariable - tests to see whether top of stack is a boolean |
| 13213 |
conditional and if so it converts it into a boolean |
| 13214 |
variable. |
| 13215 |
*) |
| 13216 |
|
| 13217 |
PROCEDURE BuildBooleanVariable ; |
| 13218 |
BEGIN |
| 13219 |
IF IsBoolean (1) |
| 13220 |
THEN |
| 13221 |
ConvertBooleanToVariable (OperandTtok (1), 1) |
| 13222 |
END |
| 13223 |
END BuildBooleanVariable ; |
| 13224 |
|
| 13225 |
|
| 13226 |
(* |
| 13227 |
DumpQuadSummary - |
| 13228 |
*) |
| 13229 |
|
| 13230 |
PROCEDURE DumpQuadSummary (quad: CARDINAL) ; |
| 13231 |
VAR |
| 13232 |
f: QuadFrame ; |
| 13233 |
BEGIN |
| 13234 |
IF quad # 0 |
| 13235 |
THEN |
| 13236 |
f := GetQF (quad) ; |
| 13237 |
printf2 ("%d op3 = %d\n", quad, f^.Operand3) |
| 13238 |
END |
| 13239 |
END DumpQuadSummary ; |
| 13240 |
|
| 13241 |
|
| 13242 |
|
| 13243 |
(* |
| 13244 |
BuildRelOpFromBoolean - builds a relational operator sequence of quadruples |
| 13245 |
instead of using a temporary boolean variable. |
| 13246 |
This function can only be used when we perform |
| 13247 |
the following translation: |
| 13248 |
|
| 13249 |
(a=b) # (c=d) alternatively (a=b) = (c=d) |
| 13250 |
^ ^ |
| 13251 |
|
| 13252 |
it only allows # = to be used as >= <= > < all |
| 13253 |
assume a particular value for TRUE and FALSE. |
| 13254 |
(In which case the user should specify ORD) |
| 13255 |
|
| 13256 |
|
| 13257 |
before |
| 13258 |
|
| 13259 |
q if r1 op1 op2 t2 |
| 13260 |
q+1 Goto f2 |
| 13261 |
... |
| 13262 |
q+n if r2 op3 op4 t1 |
| 13263 |
q+n+1 Goto f1 |
| 13264 |
|
| 13265 |
after (in case of =) |
| 13266 |
|
| 13267 |
q if r1 op1 op2 q+2 |
| 13268 |
q+1 Goto q+4 |
| 13269 |
q+2 if r2 op3 op4 t |
| 13270 |
q+3 Goto f |
| 13271 |
q+4 if r2 op3 op4 f |
| 13272 |
q+5 Goto t |
| 13273 |
|
| 13274 |
after (in case of #) |
| 13275 |
|
| 13276 |
q if r1 op1 op2 q+2 |
| 13277 |
q+1 Goto q+n+2 |
| 13278 |
q+2 ... |
| 13279 |
... ... |
| 13280 |
q+n if r2 op3 op4 f |
| 13281 |
q+n+1 Goto t |
| 13282 |
q+n+2 if r2 op3 op4 t |
| 13283 |
q+n+3 Goto f |
| 13284 |
|
| 13285 |
The Stack is expected to contain: |
| 13286 |
|
| 13287 |
|
| 13288 |
Entry Exit |
| 13289 |
===== ==== |
| 13290 |
|
| 13291 |
Ptr -> |
| 13292 |
+------------+ |
| 13293 |
| t1 | f1 | |
| 13294 |
|------------| |
| 13295 |
| Operator | <- Ptr |
| 13296 |
|------------| +------------+ |
| 13297 |
| t2 | f2 | | t | f | |
| 13298 |
|------------| |------------| |
| 13299 |
|
| 13300 |
|
| 13301 |
*) |
| 13302 |
|
| 13303 |
PROCEDURE BuildRelOpFromBoolean (tokpos: CARDINAL) ; |
| 13304 |
VAR |
| 13305 |
Tok, |
| 13306 |
t1, f1, |
| 13307 |
t2, f2: CARDINAL ; |
| 13308 |
f : QuadFrame ; |
| 13309 |
BEGIN |
| 13310 |
Assert (IsBoolean (1) AND IsBoolean (3)) ; |
| 13311 |
IF OperandT (2) = EqualTok |
| 13312 |
THEN |
| 13313 |
(* Are the two boolean expressions the same? *) |
| 13314 |
PopBool (t1, f1) ; |
| 13315 |
PopT (Tok) ; |
| 13316 |
PopBool (t2, f2) ; |
| 13317 |
(* Give the false exit a second chance. *) |
| 13318 |
BackPatch (t2, t1) ; (* q if _ _ q+2 *) |
| 13319 |
BackPatch (f2, NextQuad) ; (* q+1 if _ _ q+4 *) |
| 13320 |
Assert (NextQuad = f1+1) ; |
| 13321 |
f := GetQF (t1) ; |
| 13322 |
WITH f^ DO |
| 13323 |
GenQuadO (tokpos, Operator, Operand1, Operand2, 0, FALSE) |
| 13324 |
END ; |
| 13325 |
GenQuadO (tokpos, GotoOp, NulSym, NulSym, 0, FALSE) ; |
| 13326 |
PushBooltok (Merge (NextQuad-1, t1), Merge (NextQuad-2, f1), tokpos) |
| 13327 |
ELSIF (OperandT (2) = HashTok) OR (OperandT (2) = LessGreaterTok) |
| 13328 |
THEN |
| 13329 |
IF CompilerDebugging |
| 13330 |
THEN |
| 13331 |
printf0 ("BuildRelOpFromBoolean (NotEqualTok)\n") ; |
| 13332 |
DisplayStack |
| 13333 |
END ; |
| 13334 |
(* Are the two boolean expressions different? *) |
| 13335 |
PopBool (t1, f1) ; |
| 13336 |
PopT (Tok) ; |
| 13337 |
PopBool (t2, f2) ; |
| 13338 |
IF CompilerDebugging |
| 13339 |
THEN |
| 13340 |
printf2 ("t1 = %d, f1 = %d\n", t1, f1) ; |
| 13341 |
printf2 ("t2 = %d, f2 = %d\n", t2, f2) ; |
| 13342 |
DumpQuadSummary (t1) ; |
| 13343 |
DumpQuadSummary (f1) ; |
| 13344 |
DumpQuadSummary (t2) ; |
| 13345 |
DumpQuadSummary (f2) ; |
| 13346 |
END ; |
| 13347 |
(* Give the false exit a second chance. *) |
| 13348 |
BackPatch (t2, t1) ; (* q if _ _ q+2 *) |
| 13349 |
BackPatch (f2, NextQuad) ; (* q+1 if _ _ q+4 *) |
| 13350 |
Assert (NextQuad = f1+1) ; |
| 13351 |
f := GetQF (t1) ; |
| 13352 |
WITH f^ DO |
| 13353 |
GenQuadO (tokpos, Operator, Operand1, Operand2, 0, FALSE) |
| 13354 |
END ; |
| 13355 |
GenQuadO (tokpos, GotoOp, NulSym, NulSym, 0, FALSE) ; |
| 13356 |
PushBooltok (Merge (NextQuad-2, f1), Merge (NextQuad-1, t1), tokpos) |
| 13357 |
ELSE |
| 13358 |
MetaError0 ('only allowed to use the relation operators {%Ek=} {%Ek#} rather than {%Ek<} or {%Ek>} on {%EkBOOLEAN} expressions as these do not imply an ordinal value for {%kTRUE} or {%kFALSE}') |
| 13359 |
END |
| 13360 |
END BuildRelOpFromBoolean ; |
| 13361 |
|
| 13362 |
|
| 13363 |
(* |
| 13364 |
CheckVariableOrConstantOrProcedure - checks to make sure sym is a variable, constant or procedure. |
| 13365 |
*) |
| 13366 |
|
| 13367 |
PROCEDURE CheckVariableOrConstantOrProcedure (tokpos: CARDINAL; sym: CARDINAL) ; |
| 13368 |
VAR |
| 13369 |
type: CARDINAL ; |
| 13370 |
BEGIN |
| 13371 |
type := GetSType (sym) ; |
| 13372 |
IF IsUnknown (sym) |
| 13373 |
THEN |
| 13374 |
MetaErrorT1 (tokpos, '{%1EUad} has not been declared', sym) ; |
| 13375 |
UnknownReported (sym) |
| 13376 |
ELSIF IsPseudoSystemFunction (sym) OR IsPseudoBaseFunction (sym) |
| 13377 |
THEN |
| 13378 |
MetaErrorT1 (tokpos, |
| 13379 |
'{%1Ead} expected a variable, procedure, constant or expression, not an intrinsic procedure function', |
| 13380 |
sym) |
| 13381 |
ELSIF (NOT IsConst(sym)) AND (NOT IsVar(sym)) AND |
| 13382 |
(NOT IsProcedure(sym)) AND |
| 13383 |
(NOT IsTemporary(sym)) AND (NOT MustNotCheckBounds) |
| 13384 |
THEN |
| 13385 |
MetaErrorsT1 (tokpos, |
| 13386 |
'{%1Ead} expected a variable, procedure, constant or expression', |
| 13387 |
'and it was declared as a {%1Dd}', sym) ; |
| 13388 |
ELSIF (type#NulSym) AND IsArray(type) |
| 13389 |
THEN |
| 13390 |
MetaErrorsT1 (tokpos, |
| 13391 |
'{%1EU} not expecting an array variable as an operand for either comparison or binary operation', |
| 13392 |
'it was declared as a {%1Dd}', sym) |
| 13393 |
ELSIF IsConstString (sym) AND IsConstStringKnown (sym) AND (GetStringLength (tokpos, sym) > 1) |
| 13394 |
THEN |
| 13395 |
MetaErrorT1 (tokpos, |
| 13396 |
'{%1EU} not expecting a string constant as an operand for either comparison or binary operation', |
| 13397 |
sym) |
| 13398 |
END |
| 13399 |
END CheckVariableOrConstantOrProcedure ; |
| 13400 |
|
| 13401 |
|
| 13402 |
(* |
| 13403 |
BuildRelOp - Builds a relative operation from the quad stack. |
| 13404 |
The Stack is expected to contain: |
| 13405 |
|
| 13406 |
|
| 13407 |
Entry Exit |
| 13408 |
===== ==== |
| 13409 |
|
| 13410 |
Ptr -> |
| 13411 |
+------------+ |
| 13412 |
| e1 | |
| 13413 |
|------------| <- Ptr |
| 13414 |
| Operator | |
| 13415 |
|------------| +------------+ |
| 13416 |
| e2 | | t | f | |
| 13417 |
|------------| |------------| |
| 13418 |
|
| 13419 |
|
| 13420 |
Quadruples Produced |
| 13421 |
|
| 13422 |
q IFOperator e2 e1 TrueExit ; e2 e1 since |
| 13423 |
q+1 GotoOp FalseExit ; relation > etc |
| 13424 |
; requires order. |
| 13425 |
*) |
| 13426 |
|
| 13427 |
PROCEDURE BuildRelOp (optokpos: CARDINAL) ; |
| 13428 |
VAR |
| 13429 |
combinedTok, |
| 13430 |
rightpos, |
| 13431 |
leftpos : CARDINAL ; |
| 13432 |
Op : Name ; |
| 13433 |
t, |
| 13434 |
rightType, leftType, |
| 13435 |
right, left : CARDINAL ; |
| 13436 |
s : String ; |
| 13437 |
BEGIN |
| 13438 |
IF CompilerDebugging |
| 13439 |
THEN |
| 13440 |
DisplayStack (* Debugging info *) |
| 13441 |
END ; |
| 13442 |
IF IsInConstExpression () AND IsBoolean (1) AND IsBoolean (3) |
| 13443 |
THEN |
| 13444 |
(* |
| 13445 |
we allow # and = to be used with Boolean expressions. |
| 13446 |
we do not allow > < >= <= though. We only examine |
| 13447 |
this case if we are in a const expression as there will be |
| 13448 |
no dereferencing of operands. |
| 13449 |
*) |
| 13450 |
BuildRelOpFromBoolean (optokpos) |
| 13451 |
ELSE |
| 13452 |
IF IsBoolean (1) |
| 13453 |
THEN |
| 13454 |
ConvertBooleanToVariable (OperandTtok (1), 1) |
| 13455 |
END ; |
| 13456 |
IF IsBoolean (3) |
| 13457 |
THEN |
| 13458 |
ConvertBooleanToVariable (OperandTtok (3), 3) |
| 13459 |
END ; |
| 13460 |
PopTFtok (right, rightType, rightpos) ; |
| 13461 |
PopT (Op) ; |
| 13462 |
PopTFtok (left, leftType, leftpos) ; |
| 13463 |
|
| 13464 |
CheckVariableOrConstantOrProcedure (rightpos, right) ; |
| 13465 |
CheckVariableOrConstantOrProcedure (leftpos, left) ; |
| 13466 |
combinedTok := MakeVirtualTok (optokpos, leftpos, rightpos) ; |
| 13467 |
|
| 13468 |
IF (left#NulSym) AND (right#NulSym) |
| 13469 |
THEN |
| 13470 |
(* BuildRange will check the expression later on once gcc knows about all data types. *) |
| 13471 |
BuildRange (InitTypesExpressionCheck (combinedTok, left, right, TRUE, |
| 13472 |
Op = InTok)) |
| 13473 |
END ; |
| 13474 |
|
| 13475 |
(* Must dereference LeftValue operands. *) |
| 13476 |
IF GetMode(right) = LeftValue |
| 13477 |
THEN |
| 13478 |
t := MakeTemporary (rightpos, RightValue) ; |
| 13479 |
PutVar(t, GetSType(right)) ; |
| 13480 |
CheckPointerThroughNil (rightpos, right) ; |
| 13481 |
doIndrX (rightpos, t, right) ; |
| 13482 |
right := t |
| 13483 |
END ; |
| 13484 |
IF GetMode(left) = LeftValue |
| 13485 |
THEN |
| 13486 |
t := MakeTemporary (leftpos, RightValue) ; |
| 13487 |
PutVar (t, GetSType (left)) ; |
| 13488 |
CheckPointerThroughNil (leftpos, left) ; |
| 13489 |
doIndrX (leftpos, t, left) ; |
| 13490 |
left := t |
| 13491 |
END ; |
| 13492 |
|
| 13493 |
IF DebugTokPos |
| 13494 |
THEN |
| 13495 |
s := InitStringCharStar (KeyToCharStar (GetTokenName (Op))) ; |
| 13496 |
WarnStringAt (s, optokpos) ; |
| 13497 |
s := InitString ('left') ; |
| 13498 |
WarnStringAt (s, leftpos) ; |
| 13499 |
s := InitString ('right') ; |
| 13500 |
WarnStringAt (s, rightpos) ; |
| 13501 |
s := InitString ('caret') ; |
| 13502 |
WarnStringAt (s, optokpos) ; |
| 13503 |
s := InitString ('combined') ; |
| 13504 |
WarnStringAt (s, combinedTok) |
| 13505 |
END ; |
| 13506 |
|
| 13507 |
GenQuadOtok (combinedTok, MakeOp (Op), left, right, 0, FALSE, |
| 13508 |
leftpos, rightpos, UnknownTokenNo) ; (* True Exit *) |
| 13509 |
GenQuadO (combinedTok, GotoOp, NulSym, NulSym, 0, FALSE) ; (* False Exit *) |
| 13510 |
PushBooltok (NextQuad-2, NextQuad-1, combinedTok) |
| 13511 |
END |
| 13512 |
END BuildRelOp ; |
| 13513 |
|
| 13514 |
|
| 13515 |
(* |
| 13516 |
BuildNot - Builds a NOT operation from the quad stack. |
| 13517 |
The Stack is expected to contain: |
| 13518 |
|
| 13519 |
|
| 13520 |
Entry Exit |
| 13521 |
===== ==== |
| 13522 |
|
| 13523 |
Ptr -> <- Ptr |
| 13524 |
+------------+ +------------+ |
| 13525 |
| t | f | | f | t | |
| 13526 |
|------------| |------------| |
| 13527 |
*) |
| 13528 |
|
| 13529 |
PROCEDURE BuildNot (notTokPos: CARDINAL) ; |
| 13530 |
VAR |
| 13531 |
combinedTok, |
| 13532 |
exprTokPos : CARDINAL ; |
| 13533 |
t, f : CARDINAL ; |
| 13534 |
BEGIN |
| 13535 |
CheckBooleanId ; |
| 13536 |
PopBooltok (t, f, exprTokPos) ; |
| 13537 |
combinedTok := MakeVirtualTok (notTokPos, notTokPos, exprTokPos) ; |
| 13538 |
PushBooltok (f, t, combinedTok) |
| 13539 |
END BuildNot ; |
| 13540 |
|
| 13541 |
|
| 13542 |
(* |
| 13543 |
MakeOp - returns the equalent quadruple operator to a token, t. |
| 13544 |
*) |
| 13545 |
|
| 13546 |
PROCEDURE MakeOp (t: Name) : QuadOperator ; |
| 13547 |
BEGIN |
| 13548 |
IF t=ArithPlusTok |
| 13549 |
THEN |
| 13550 |
RETURN ArithAddOp |
| 13551 |
ELSIF t=PlusTok |
| 13552 |
THEN |
| 13553 |
RETURN( AddOp ) |
| 13554 |
ELSIF t=MinusTok |
| 13555 |
THEN |
| 13556 |
RETURN( SubOp ) |
| 13557 |
ELSIF t=DivTok |
| 13558 |
THEN |
| 13559 |
RETURN( DivM2Op ) |
| 13560 |
ELSIF t=DivideTok |
| 13561 |
THEN |
| 13562 |
RETURN( DivTruncOp ) |
| 13563 |
ELSIF t=RemTok |
| 13564 |
THEN |
| 13565 |
RETURN( ModTruncOp ) |
| 13566 |
ELSIF t=ModTok |
| 13567 |
THEN |
| 13568 |
RETURN( ModM2Op ) |
| 13569 |
ELSIF t=TimesTok |
| 13570 |
THEN |
| 13571 |
RETURN( MultOp ) |
| 13572 |
ELSIF t=HashTok |
| 13573 |
THEN |
| 13574 |
RETURN( IfNotEquOp ) |
| 13575 |
ELSIF t=LessGreaterTok |
| 13576 |
THEN |
| 13577 |
RETURN( IfNotEquOp ) |
| 13578 |
ELSIF t=GreaterEqualTok |
| 13579 |
THEN |
| 13580 |
RETURN( IfGreEquOp ) |
| 13581 |
ELSIF t=LessEqualTok |
| 13582 |
THEN |
| 13583 |
RETURN( IfLessEquOp ) |
| 13584 |
ELSIF t=EqualTok |
| 13585 |
THEN |
| 13586 |
RETURN( IfEquOp ) |
| 13587 |
ELSIF t=LessTok |
| 13588 |
THEN |
| 13589 |
RETURN( IfLessOp ) |
| 13590 |
ELSIF t=GreaterTok |
| 13591 |
THEN |
| 13592 |
RETURN( IfGreOp ) |
| 13593 |
ELSIF t=InTok |
| 13594 |
THEN |
| 13595 |
RETURN( IfInOp ) |
| 13596 |
ELSIF t=LogicalOrTok |
| 13597 |
THEN |
| 13598 |
RETURN( LogicalOrOp ) |
| 13599 |
ELSIF t=LogicalAndTok |
| 13600 |
THEN |
| 13601 |
RETURN( LogicalAndOp ) |
| 13602 |
ELSIF t=LogicalXorTok |
| 13603 |
THEN |
| 13604 |
RETURN( LogicalXorOp ) |
| 13605 |
ELSIF t=LogicalDifferenceTok |
| 13606 |
THEN |
| 13607 |
RETURN( LogicalDiffOp ) |
| 13608 |
ELSE |
| 13609 |
InternalError('binary operation not implemented yet') |
| 13610 |
END |
| 13611 |
END MakeOp ; |
| 13612 |
|
| 13613 |
|
| 13614 |
(* |
| 13615 |
GenQuadO - generate a quadruple with Operation, Op1, Op2, Op3, overflow. |
| 13616 |
*) |
| 13617 |
|
| 13618 |
PROCEDURE GenQuadO (TokPos: CARDINAL; |
| 13619 |
Operation: QuadOperator; |
| 13620 |
Op1, Op2, Op3: CARDINAL; overflow: BOOLEAN) ; |
| 13621 |
BEGIN |
| 13622 |
GenQuadOTrash (TokPos, Operation, Op1, Op2, Op3, overflow, NulSym) |
| 13623 |
END GenQuadO ; |
| 13624 |
|
| 13625 |
|
| 13626 |
(* |
| 13627 |
GenQuadOTrash - generate a quadruple with Operation, Op1, Op2, Op3, overflow. |
| 13628 |
*) |
| 13629 |
|
| 13630 |
PROCEDURE GenQuadOTrash (TokPos: CARDINAL; |
| 13631 |
Operation: QuadOperator; |
| 13632 |
Op1, Op2, Op3: CARDINAL; |
| 13633 |
overflow: BOOLEAN; trash: CARDINAL) ; |
| 13634 |
VAR |
| 13635 |
f: QuadFrame ; |
| 13636 |
BEGIN |
| 13637 |
(* WriteString('Potential Quad: ') ; *) |
| 13638 |
IF QuadrupleGeneration |
| 13639 |
THEN |
| 13640 |
IF NextQuad # Head |
| 13641 |
THEN |
| 13642 |
f := GetQF (NextQuad-1) ; |
| 13643 |
f^.Next := NextQuad |
| 13644 |
END ; |
| 13645 |
PutQuadO (NextQuad, Operation, Op1, Op2, Op3, overflow) ; |
| 13646 |
f := GetQF (NextQuad) ; |
| 13647 |
WITH f^ DO |
| 13648 |
Trash := trash ; |
| 13649 |
Next := 0 ; |
| 13650 |
LineNo := GetLineNo () ; |
| 13651 |
IF TokPos = UnknownTokenNo |
| 13652 |
THEN |
| 13653 |
TokenNo := GetTokenNo () |
| 13654 |
ELSE |
| 13655 |
TokenNo := TokPos |
| 13656 |
END ; |
| 13657 |
IF GetDebugTraceQuad () |
| 13658 |
THEN |
| 13659 |
printf0('generating: ') ; |
| 13660 |
DisplayQuad (NextQuad) ; |
| 13661 |
(* MetaErrorT1 (TokenNo, '{%1On}', NextQuad) *) |
| 13662 |
END |
| 13663 |
END ; |
| 13664 |
CheckBreak (NextQuad) ; |
| 13665 |
NewQuad (NextQuad) |
| 13666 |
END |
| 13667 |
END GenQuadOTrash ; |
| 13668 |
|
| 13669 |
|
| 13670 |
(* |
| 13671 |
GetQuadTrash - return the symbol associated with the trashed operand. |
| 13672 |
*) |
| 13673 |
|
| 13674 |
PROCEDURE GetQuadTrash (quad: CARDINAL) : CARDINAL ; |
| 13675 |
VAR |
| 13676 |
f: QuadFrame ; |
| 13677 |
BEGIN |
| 13678 |
f := GetQF (quad) ; |
| 13679 |
LastQuadNo := quad ; |
| 13680 |
RETURN f^.Trash |
| 13681 |
END GetQuadTrash ; |
| 13682 |
|
| 13683 |
|
| 13684 |
(* |
| 13685 |
GenQuad - Generate a quadruple with Operation, Op1, Op2, Op3. |
| 13686 |
*) |
| 13687 |
|
| 13688 |
PROCEDURE GenQuad (Operation: QuadOperator; |
| 13689 |
Op1, Op2, Op3: CARDINAL) ; |
| 13690 |
BEGIN |
| 13691 |
GenQuadO (UnknownTokenNo, Operation, Op1, Op2, Op3, TRUE) |
| 13692 |
END GenQuad ; |
| 13693 |
|
| 13694 |
|
| 13695 |
(* |
| 13696 |
GenQuadOtok - generate a quadruple with Operation, Op1, Op2, Op3, overflow. |
| 13697 |
*) |
| 13698 |
|
| 13699 |
PROCEDURE GenQuadOtok (TokPos: CARDINAL; |
| 13700 |
Operation: QuadOperator; |
| 13701 |
Op1, Op2, Op3: CARDINAL; overflow: BOOLEAN; |
| 13702 |
Op1Pos, Op2Pos, Op3Pos: CARDINAL) ; |
| 13703 |
BEGIN |
| 13704 |
GenQuadOTypetok (TokPos, Operation, Op1, Op2, Op3, overflow, TRUE, |
| 13705 |
Op1Pos, Op2Pos, Op3Pos) |
| 13706 |
END GenQuadOtok ; |
| 13707 |
|
| 13708 |
|
| 13709 |
(* |
| 13710 |
GenQuadOTypetok - assigns the fields of the quadruple with |
| 13711 |
the parameters. |
| 13712 |
*) |
| 13713 |
|
| 13714 |
PROCEDURE GenQuadOTypetok (TokPos: CARDINAL; |
| 13715 |
Operation: QuadOperator; |
| 13716 |
Op1, Op2, Op3: CARDINAL; |
| 13717 |
overflow, typecheck: BOOLEAN; |
| 13718 |
Op1Pos, Op2Pos, Op3Pos: CARDINAL) ; |
| 13719 |
VAR |
| 13720 |
f: QuadFrame ; |
| 13721 |
BEGIN |
| 13722 |
(* WriteString('Potential Quad: ') ; *) |
| 13723 |
IF QuadrupleGeneration |
| 13724 |
THEN |
| 13725 |
IF NextQuad # Head |
| 13726 |
THEN |
| 13727 |
f := GetQF (NextQuad-1) ; |
| 13728 |
f^.Next := NextQuad |
| 13729 |
END ; |
| 13730 |
PutQuadOType (NextQuad, Operation, Op1, Op2, Op3, overflow, typecheck) ; |
| 13731 |
f := GetQF (NextQuad) ; |
| 13732 |
WITH f^ DO |
| 13733 |
Next := 0 ; |
| 13734 |
LineNo := GetLineNo () ; |
| 13735 |
IF TokPos = UnknownTokenNo |
| 13736 |
THEN |
| 13737 |
TokenNo := GetTokenNo () |
| 13738 |
ELSE |
| 13739 |
TokenNo := TokPos |
| 13740 |
END ; |
| 13741 |
op1pos := Op1Pos ; |
| 13742 |
op2pos := Op2Pos ; |
| 13743 |
op3pos := Op3Pos ; |
| 13744 |
IF GetDebugTraceQuad () |
| 13745 |
THEN |
| 13746 |
printf0('generating: ') ; |
| 13747 |
DisplayQuad (NextQuad) ; |
| 13748 |
(* MetaErrorT1 (TokenNo, '{%1On}', NextQuad) *) |
| 13749 |
END |
| 13750 |
END ; |
| 13751 |
CheckBreak (NextQuad) ; |
| 13752 |
NewQuad (NextQuad) |
| 13753 |
END |
| 13754 |
END GenQuadOTypetok ; |
| 13755 |
|
| 13756 |
|
| 13757 |
(* |
| 13758 |
DumpUntil - dump all quadruples until we seen the ending quadruple |
| 13759 |
with procsym in the third operand. |
| 13760 |
Return the quad number containing the match. |
| 13761 |
*) |
| 13762 |
|
| 13763 |
PROCEDURE DumpUntil (ending: QuadOperator; |
| 13764 |
procsym: CARDINAL; quad: CARDINAL) : CARDINAL ; |
| 13765 |
VAR |
| 13766 |
op : QuadOperator ; |
| 13767 |
op1, op2, op3: CARDINAL ; |
| 13768 |
f : QuadFrame ; |
| 13769 |
BEGIN |
| 13770 |
fprintf0 (GetDumpFile (), '\n...\n\n'); |
| 13771 |
REPEAT |
| 13772 |
GetQuad (quad, op, op1, op2, op3) ; |
| 13773 |
DisplayQuad (quad) ; |
| 13774 |
f := GetQF (quad) ; |
| 13775 |
quad := f^.Next |
| 13776 |
UNTIL (op = ending) AND (op3 = procsym) ; |
| 13777 |
RETURN quad |
| 13778 |
END DumpUntil ; |
| 13779 |
|
| 13780 |
|
| 13781 |
(* |
| 13782 |
GetCtorInit - return the init procedure for the module. |
| 13783 |
*) |
| 13784 |
|
| 13785 |
PROCEDURE GetCtorInit (sym: CARDINAL) : CARDINAL ; |
| 13786 |
VAR |
| 13787 |
ctor, init, fini, dep: CARDINAL ; |
| 13788 |
BEGIN |
| 13789 |
GetModuleCtors (sym, ctor, init, fini, dep) ; |
| 13790 |
RETURN init |
| 13791 |
END GetCtorInit ; |
| 13792 |
|
| 13793 |
|
| 13794 |
(* |
| 13795 |
GetCtorFini - return the fini procedure for the module. |
| 13796 |
*) |
| 13797 |
|
| 13798 |
PROCEDURE GetCtorFini (sym: CARDINAL) : CARDINAL ; |
| 13799 |
VAR |
| 13800 |
ctor, init, fini, dep: CARDINAL ; |
| 13801 |
BEGIN |
| 13802 |
GetModuleCtors (sym, ctor, init, fini, dep) ; |
| 13803 |
RETURN fini |
| 13804 |
END GetCtorFini ; |
| 13805 |
|
| 13806 |
|
| 13807 |
(* |
| 13808 |
DumpQuadrupleFilter - |
| 13809 |
*) |
| 13810 |
|
| 13811 |
PROCEDURE DumpQuadrupleFilter ; |
| 13812 |
VAR |
| 13813 |
f : QuadFrame ; |
| 13814 |
i : CARDINAL ; |
| 13815 |
op : QuadOperator ; |
| 13816 |
op1, op2, op3: CARDINAL ; |
| 13817 |
BEGIN |
| 13818 |
i := Head ; |
| 13819 |
WHILE i # 0 DO |
| 13820 |
GetQuad (i, op, op1, op2, op3) ; |
| 13821 |
IF (op = ProcedureScopeOp) AND IsDumpRequired (op3, TRUE) |
| 13822 |
THEN |
| 13823 |
i := DumpUntil (KillLocalVarOp, op3, i) |
| 13824 |
ELSIF (op = InitStartOp) AND IsDumpRequired (GetCtorInit (op3), TRUE) |
| 13825 |
THEN |
| 13826 |
i := DumpUntil (InitEndOp, op3, i) |
| 13827 |
ELSIF (op = FinallyStartOp) AND IsDumpRequired (GetCtorFini (op3), TRUE) |
| 13828 |
THEN |
| 13829 |
i := DumpUntil (FinallyEndOp, op3, i) |
| 13830 |
ELSE |
| 13831 |
f := GetQF (i) ; |
| 13832 |
i := f^.Next |
| 13833 |
END |
| 13834 |
END |
| 13835 |
END DumpQuadrupleFilter ; |
| 13836 |
|
| 13837 |
|
| 13838 |
(* |
| 13839 |
DumpQuadrupleAll - dump all quadruples. |
| 13840 |
*) |
| 13841 |
|
| 13842 |
PROCEDURE DumpQuadrupleAll ; |
| 13843 |
VAR |
| 13844 |
f: QuadFrame ; |
| 13845 |
i: CARDINAL ; |
| 13846 |
BEGIN |
| 13847 |
i := Head ; |
| 13848 |
WHILE i # 0 DO |
| 13849 |
DisplayQuad (i) ; |
| 13850 |
f := GetQF (i) ; |
| 13851 |
i := f^.Next |
| 13852 |
END |
| 13853 |
END DumpQuadrupleAll ; |
| 13854 |
|
| 13855 |
|
| 13856 |
(* |
| 13857 |
DumpQuadruples - dump all quadruples providing the -fq, -fdump-lang-quad, |
| 13858 |
-fdump-lang-quad= or -fdump-lang-all were issued to the |
| 13859 |
command line. |
| 13860 |
*) |
| 13861 |
|
| 13862 |
PROCEDURE DumpQuadruples (title: ARRAY OF CHAR) ; |
| 13863 |
BEGIN |
| 13864 |
IF GetDumpQuad () |
| 13865 |
THEN |
| 13866 |
CreateDumpQuad (title) ; |
| 13867 |
IF GetM2DumpFilter () = NIL |
| 13868 |
THEN |
| 13869 |
DumpQuadrupleAll |
| 13870 |
ELSE |
| 13871 |
DumpQuadrupleFilter |
| 13872 |
END ; |
| 13873 |
CloseDumpQuad |
| 13874 |
END |
| 13875 |
END DumpQuadruples ; |
| 13876 |
|
| 13877 |
|
| 13878 |
(* |
| 13879 |
DisplayQuadRange - displays all quads in list range, start..end. |
| 13880 |
*) |
| 13881 |
|
| 13882 |
PROCEDURE DisplayQuadRange (scope: CARDINAL; start, end: CARDINAL) ; |
| 13883 |
VAR |
| 13884 |
f: QuadFrame ; |
| 13885 |
BEGIN |
| 13886 |
fprintf1 (GetDumpFile (), 'Quadruples for scope: %d\n', scope) ; |
| 13887 |
WHILE (start <= end) AND (start # 0) DO |
| 13888 |
DisplayQuad (start) ; |
| 13889 |
f := GetQF (start) ; |
| 13890 |
start := f^.Next |
| 13891 |
END |
| 13892 |
END DisplayQuadRange ; |
| 13893 |
|
| 13894 |
|
| 13895 |
(* |
| 13896 |
BackPatch - Makes each of the quadruples on the list pointed to by |
| 13897 |
QuadNo take quadruple Value as a target. |
| 13898 |
*) |
| 13899 |
|
| 13900 |
PROCEDURE BackPatch (QuadNo, Value: CARDINAL) ; |
| 13901 |
VAR |
| 13902 |
i: CARDINAL ; |
| 13903 |
f: QuadFrame ; |
| 13904 |
BEGIN |
| 13905 |
IF QuadrupleGeneration |
| 13906 |
THEN |
| 13907 |
WHILE QuadNo#0 DO |
| 13908 |
f := GetQF (QuadNo) ; |
| 13909 |
WITH f^ DO |
| 13910 |
i := Operand3 ; (* Next Link along the BackPatch *) |
| 13911 |
ManipulateReference (QuadNo, Value) (* Filling in the BackPatch. *) |
| 13912 |
END ; |
| 13913 |
QuadNo := i |
| 13914 |
END |
| 13915 |
END |
| 13916 |
END BackPatch ; |
| 13917 |
|
| 13918 |
|
| 13919 |
(* |
| 13920 |
Merge - joins two quad lists, QuadList2 to the end of QuadList1. |
| 13921 |
A QuadList of value zero is a nul list. |
| 13922 |
*) |
| 13923 |
|
| 13924 |
PROCEDURE Merge (QuadList1, QuadList2: CARDINAL) : CARDINAL ; |
| 13925 |
VAR |
| 13926 |
i, j: CARDINAL ; |
| 13927 |
f : QuadFrame ; |
| 13928 |
BEGIN |
| 13929 |
IF QuadList1=0 |
| 13930 |
THEN |
| 13931 |
RETURN( QuadList2 ) |
| 13932 |
ELSIF QuadList2=0 |
| 13933 |
THEN |
| 13934 |
RETURN( QuadList1 ) |
| 13935 |
ELSE |
| 13936 |
i := QuadList1 ; |
| 13937 |
REPEAT |
| 13938 |
j := i ; |
| 13939 |
f := GetQF(i) ; |
| 13940 |
i := f^.Operand3 |
| 13941 |
UNTIL i=0 ; |
| 13942 |
ManipulateReference(j, QuadList2) ; |
| 13943 |
RETURN( QuadList1 ) |
| 13944 |
END |
| 13945 |
END Merge ; |
| 13946 |
|
| 13947 |
|
| 13948 |
(* |
| 13949 |
Annotate - annotate the top of stack. |
| 13950 |
*) |
| 13951 |
|
| 13952 |
PROCEDURE Annotate (a: ARRAY OF CHAR) ; |
| 13953 |
VAR |
| 13954 |
f: BoolFrame ; |
| 13955 |
BEGIN |
| 13956 |
IF DebugStackOn AND CompilerDebugging AND (NoOfItemsInStackAddress(BoolStack)>0) |
| 13957 |
THEN |
| 13958 |
f := PeepAddress(BoolStack, 1) ; (* top of stack *) |
| 13959 |
WITH f^ DO |
| 13960 |
IF Annotation#NIL |
| 13961 |
THEN |
| 13962 |
Annotation := KillString(Annotation) |
| 13963 |
END ; |
| 13964 |
Annotation := InitString(a) |
| 13965 |
END |
| 13966 |
END |
| 13967 |
END Annotate ; |
| 13968 |
|
| 13969 |
|
| 13970 |
(* |
| 13971 |
OperandAnno - returns the annotation string associated with the |
| 13972 |
position, n, on the stack. |
| 13973 |
*) |
| 13974 |
|
| 13975 |
PROCEDURE OperandAnno (n: CARDINAL) : String ; |
| 13976 |
VAR |
| 13977 |
f: BoolFrame ; |
| 13978 |
BEGIN |
| 13979 |
f := PeepAddress (BoolStack, n) ; |
| 13980 |
RETURN f^.Annotation |
| 13981 |
END OperandAnno ; |
| 13982 |
|
| 13983 |
|
| 13984 |
(* |
| 13985 |
DisplayStack - displays the compile time symbol stack. |
| 13986 |
*) |
| 13987 |
|
| 13988 |
PROCEDURE DisplayStack ; |
| 13989 |
BEGIN |
| 13990 |
IF DebugStackOn AND CompilerDebugging |
| 13991 |
THEN |
| 13992 |
DebugStack (NoOfItemsInStackAddress (BoolStack), |
| 13993 |
OperandTno, OperandFno, OperandA, |
| 13994 |
OperandD, OperandRW, OperandTok, OperandAnno) |
| 13995 |
END |
| 13996 |
END DisplayStack ; |
| 13997 |
|
| 13998 |
|
| 13999 |
(* |
| 14000 |
ds - tiny procedure name, useful for calling from the gdb shell. |
| 14001 |
*) |
| 14002 |
|
| 14003 |
(* |
| 14004 |
PROCEDURE ds ; |
| 14005 |
BEGIN |
| 14006 |
DisplayStack |
| 14007 |
END ds ; |
| 14008 |
*) |
| 14009 |
|
| 14010 |
|
| 14011 |
(* |
| 14012 |
DisplayQuad - displays a quadruple, QuadNo. |
| 14013 |
*) |
| 14014 |
|
| 14015 |
PROCEDURE DisplayQuad (QuadNo: CARDINAL) ; |
| 14016 |
BEGIN |
| 14017 |
DSdbEnter ; |
| 14018 |
fprintf1 (GetDumpFile (), '%4d ', QuadNo) ; WriteQuad(QuadNo) ; fprintf0 (GetDumpFile (), '\n') ; |
| 14019 |
DSdbExit |
| 14020 |
END DisplayQuad ; |
| 14021 |
|
| 14022 |
|
| 14023 |
(* |
| 14024 |
DisplayProcedureAttributes - |
| 14025 |
*) |
| 14026 |
|
| 14027 |
PROCEDURE DisplayProcedureAttributes (proc: CARDINAL) ; |
| 14028 |
BEGIN |
| 14029 |
IF IsCtor (proc) |
| 14030 |
THEN |
| 14031 |
fprintf0 (GetDumpFile (), " (ctor)") |
| 14032 |
END ; |
| 14033 |
IF IsPublic (proc) |
| 14034 |
THEN |
| 14035 |
fprintf0 (GetDumpFile (), " (public)") |
| 14036 |
END ; |
| 14037 |
IF IsExtern (proc) |
| 14038 |
THEN |
| 14039 |
fprintf0 (GetDumpFile (), " (extern)") |
| 14040 |
END ; |
| 14041 |
IF IsMonoName (proc) |
| 14042 |
THEN |
| 14043 |
fprintf0 (GetDumpFile (), " (mononame)") |
| 14044 |
END |
| 14045 |
END DisplayProcedureAttributes ; |
| 14046 |
|
| 14047 |
|
| 14048 |
(* |
| 14049 |
WriteQuad - Writes out the Quad BufferQuad. |
| 14050 |
*) |
| 14051 |
|
| 14052 |
PROCEDURE WriteQuad (BufferQuad: CARDINAL) ; |
| 14053 |
VAR |
| 14054 |
n1, n2: Name ; |
| 14055 |
f : QuadFrame ; |
| 14056 |
n : Name ; |
| 14057 |
l : CARDINAL ; |
| 14058 |
BEGIN |
| 14059 |
f := GetQF(BufferQuad) ; |
| 14060 |
WITH f^ DO |
| 14061 |
WriteOperator(Operator) ; |
| 14062 |
fprintf1 (GetDumpFile (), ' [%d]', NoOfTimesReferenced) ; |
| 14063 |
IF ConstExpr |
| 14064 |
THEN |
| 14065 |
fprintf0 (GetDumpFile (), ' const ') |
| 14066 |
ELSE |
| 14067 |
fprintf0 (GetDumpFile (), ' ') |
| 14068 |
END ; |
| 14069 |
CASE Operator OF |
| 14070 |
|
| 14071 |
LastForIteratorOp: WriteOperand(Operand1) ; |
| 14072 |
fprintf0 (GetDumpFile (), ' ') ; |
| 14073 |
WriteOperand(Operand2) ; |
| 14074 |
fprintf0 (GetDumpFile (), ' ') ; |
| 14075 |
WriteOperand(Operand3) | |
| 14076 |
HighOp : WriteOperand(Operand1) ; |
| 14077 |
fprintf1 (GetDumpFile (), ' %4d ', Operand2) ; |
| 14078 |
WriteOperand(Operand3) | |
| 14079 |
InitAddressOp, |
| 14080 |
SavePriorityOp, |
| 14081 |
RestorePriorityOp, |
| 14082 |
SubrangeLowOp, |
| 14083 |
SubrangeHighOp, |
| 14084 |
BecomesOp, |
| 14085 |
InclOp, |
| 14086 |
ExclOp, |
| 14087 |
UnboundedOp, |
| 14088 |
ReturnValueOp, |
| 14089 |
FunctValueOp, |
| 14090 |
NegateOp, |
| 14091 |
AddrOp, |
| 14092 |
StringConvertCnulOp, |
| 14093 |
StringConvertM2nulOp, |
| 14094 |
StringLengthOp : WriteOperand(Operand1) ; |
| 14095 |
fprintf0 (GetDumpFile (), ' ') ; |
| 14096 |
WriteOperand(Operand3) | |
| 14097 |
ElementSizeOp, |
| 14098 |
IfInOp, |
| 14099 |
IfNotInOp, |
| 14100 |
IfNotEquOp, |
| 14101 |
IfEquOp, |
| 14102 |
IfLessOp, |
| 14103 |
IfGreOp, |
| 14104 |
IfLessEquOp, |
| 14105 |
IfGreEquOp : WriteOperand(Operand1) ; |
| 14106 |
fprintf0 (GetDumpFile (), ' ') ; |
| 14107 |
WriteOperand(Operand2) ; |
| 14108 |
fprintf1 (GetDumpFile (), ' %4d', Operand3) | |
| 14109 |
|
| 14110 |
InlineOp, |
| 14111 |
RetryOp, |
| 14112 |
TryOp, |
| 14113 |
GotoOp : fprintf1 (GetDumpFile (), '%4d', Operand3) | |
| 14114 |
|
| 14115 |
StatementNoteOp : l := TokenToLineNo(Operand3, 0) ; |
| 14116 |
n := GetTokenName (Operand3) ; |
| 14117 |
fprintf4 (GetDumpFile (), '%a:%d:%a (tokenno %d)', Operand1, l, n, Operand3) | |
| 14118 |
LineNumberOp : fprintf2 (GetDumpFile (), '%a:%d', Operand1, Operand3) | |
| 14119 |
|
| 14120 |
EndFileOp : n1 := GetSymName(Operand3) ; |
| 14121 |
fprintf1 (GetDumpFile (), '%a', n1) | |
| 14122 |
|
| 14123 |
ThrowOp, |
| 14124 |
ReturnOp, |
| 14125 |
CallOp, |
| 14126 |
KillLocalVarOp : WriteOperand(Operand3) | |
| 14127 |
|
| 14128 |
ProcedureScopeOp : n1 := GetSymName(Operand2) ; |
| 14129 |
n2 := GetSymName(Operand3) ; |
| 14130 |
fprintf4 (GetDumpFile (), ' %4d %a %a(%d)', Operand1, n1, n2, Operand3) ; |
| 14131 |
DisplayProcedureAttributes (Operand3) | |
| 14132 |
NewLocalVarOp, |
| 14133 |
FinallyStartOp, |
| 14134 |
FinallyEndOp, |
| 14135 |
InitEndOp, |
| 14136 |
InitStartOp : n1 := GetSymName(Operand2) ; |
| 14137 |
n2 := GetSymName(Operand3) ; |
| 14138 |
fprintf3 (GetDumpFile (), ' %4d %a %a', Operand1, n1, n2) | |
| 14139 |
|
| 14140 |
ModuleScopeOp, |
| 14141 |
StartModFileOp : n1 := GetSymName(Operand3) ; |
| 14142 |
fprintf4 (GetDumpFile (), '%a:%d %a(%d)', Operand2, Operand1, n1, Operand3) | |
| 14143 |
|
| 14144 |
StartDefFileOp : n1 := GetSymName(Operand3) ; |
| 14145 |
fprintf2 (GetDumpFile (), ' %4d %a', Operand1, n1) | |
| 14146 |
|
| 14147 |
OptParamOp, |
| 14148 |
ParamOp : fprintf1 (GetDumpFile (), '%4d ', Operand1) ; |
| 14149 |
WriteOperand(Operand2) ; |
| 14150 |
fprintf0 (GetDumpFile (), ' ') ; |
| 14151 |
WriteOperand(Operand3) | |
| 14152 |
SizeOp, |
| 14153 |
RecordFieldOp, |
| 14154 |
IndrXOp, |
| 14155 |
XIndrOp, |
| 14156 |
ArrayOp, |
| 14157 |
LogicalShiftOp, |
| 14158 |
LogicalRotateOp, |
| 14159 |
LogicalOrOp, |
| 14160 |
LogicalAndOp, |
| 14161 |
LogicalXorOp, |
| 14162 |
LogicalDiffOp, |
| 14163 |
ArithAddOp, |
| 14164 |
CoerceOp, |
| 14165 |
ConvertOp, |
| 14166 |
CastOp, |
| 14167 |
AddOp, |
| 14168 |
SubOp, |
| 14169 |
MultOp, |
| 14170 |
DivM2Op, |
| 14171 |
ModM2Op, |
| 14172 |
ModFloorOp, |
| 14173 |
DivCeilOp, |
| 14174 |
ModCeilOp, |
| 14175 |
DivFloorOp, |
| 14176 |
ModTruncOp, |
| 14177 |
DivTruncOp : WriteOperand(Operand1) ; |
| 14178 |
fprintf0 (GetDumpFile (), ' ') ; |
| 14179 |
WriteOperand(Operand2) ; |
| 14180 |
fprintf0 (GetDumpFile (), ' ') ; |
| 14181 |
WriteOperand(Operand3) | |
| 14182 |
DummyOp, |
| 14183 |
CodeOnOp, |
| 14184 |
CodeOffOp, |
| 14185 |
ProfileOnOp, |
| 14186 |
ProfileOffOp, |
| 14187 |
OptimizeOnOp, |
| 14188 |
OptimizeOffOp : | |
| 14189 |
BuiltinConstOp : WriteOperand(Operand1) ; |
| 14190 |
fprintf1 (GetDumpFile (), ' %a', Operand3) | |
| 14191 |
BuiltinTypeInfoOp : WriteOperand(Operand1) ; |
| 14192 |
fprintf1 (GetDumpFile (), ' %a', Operand2) ; |
| 14193 |
fprintf1 (GetDumpFile (), ' %a', Operand3) | |
| 14194 |
StandardFunctionOp: WriteOperand(Operand1) ; |
| 14195 |
fprintf0 (GetDumpFile (), ' ') ; |
| 14196 |
WriteOperand(Operand2) ; |
| 14197 |
fprintf0 (GetDumpFile (), ' ') ; |
| 14198 |
WriteOperand(Operand3) | |
| 14199 |
CatchBeginOp, |
| 14200 |
CatchEndOp : | |
| 14201 |
|
| 14202 |
RangeCheckOp, |
| 14203 |
ErrorOp : WriteRangeCheck (Operand3) | |
| 14204 |
SaveExceptionOp, |
| 14205 |
RestoreExceptionOp: WriteOperand(Operand1) ; |
| 14206 |
fprintf0 (GetDumpFile (), ' ') ; |
| 14207 |
WriteOperand(Operand3) |
| 14208 |
|
| 14209 |
ELSE |
| 14210 |
InternalError ('quadruple not recognised') |
| 14211 |
END |
| 14212 |
END |
| 14213 |
END WriteQuad ; |
| 14214 |
|
| 14215 |
|
| 14216 |
(* |
| 14217 |
WriteOperator - writes the name of the quadruple operator. |
| 14218 |
*) |
| 14219 |
|
| 14220 |
PROCEDURE WriteOperator (Operator: QuadOperator) ; |
| 14221 |
BEGIN |
| 14222 |
CASE Operator OF |
| 14223 |
|
| 14224 |
ArithAddOp : fprintf0 (GetDumpFile (), 'Arith + ') | |
| 14225 |
InitAddressOp : fprintf0 (GetDumpFile (), 'InitAddress ') | |
| 14226 |
LastForIteratorOp : fprintf0 (GetDumpFile (), 'LastForIterator ') | |
| 14227 |
LogicalOrOp : fprintf0 (GetDumpFile (), 'Or ') | |
| 14228 |
LogicalAndOp : fprintf0 (GetDumpFile (), 'And ') | |
| 14229 |
LogicalXorOp : fprintf0 (GetDumpFile (), 'Xor ') | |
| 14230 |
LogicalDiffOp : fprintf0 (GetDumpFile (), 'Ldiff ') | |
| 14231 |
LogicalShiftOp : fprintf0 (GetDumpFile (), 'Shift ') | |
| 14232 |
LogicalRotateOp : fprintf0 (GetDumpFile (), 'Rotate ') | |
| 14233 |
BecomesOp : fprintf0 (GetDumpFile (), 'Becomes ') | |
| 14234 |
IndrXOp : fprintf0 (GetDumpFile (), 'IndrX ') | |
| 14235 |
XIndrOp : fprintf0 (GetDumpFile (), 'XIndr ') | |
| 14236 |
ArrayOp : fprintf0 (GetDumpFile (), 'Array ') | |
| 14237 |
ElementSizeOp : fprintf0 (GetDumpFile (), 'ElementSize ') | |
| 14238 |
RecordFieldOp : fprintf0 (GetDumpFile (), 'RecordField ') | |
| 14239 |
AddrOp : fprintf0 (GetDumpFile (), 'Addr ') | |
| 14240 |
SizeOp : fprintf0 (GetDumpFile (), 'Size ') | |
| 14241 |
IfInOp : fprintf0 (GetDumpFile (), 'If IN ') | |
| 14242 |
IfNotInOp : fprintf0 (GetDumpFile (), 'If NOT IN ') | |
| 14243 |
IfNotEquOp : fprintf0 (GetDumpFile (), 'If <> ') | |
| 14244 |
IfEquOp : fprintf0 (GetDumpFile (), 'If = ') | |
| 14245 |
IfLessEquOp : fprintf0 (GetDumpFile (), 'If <= ') | |
| 14246 |
IfGreEquOp : fprintf0 (GetDumpFile (), 'If >= ') | |
| 14247 |
IfGreOp : fprintf0 (GetDumpFile (), 'If > ') | |
| 14248 |
IfLessOp : fprintf0 (GetDumpFile (), 'If < ') | |
| 14249 |
GotoOp : fprintf0 (GetDumpFile (), 'Goto ') | |
| 14250 |
DummyOp : fprintf0 (GetDumpFile (), 'Dummy ') | |
| 14251 |
ModuleScopeOp : fprintf0 (GetDumpFile (), 'ModuleScopeOp ') | |
| 14252 |
StartDefFileOp : fprintf0 (GetDumpFile (), 'StartDefFile ') | |
| 14253 |
StartModFileOp : fprintf0 (GetDumpFile (), 'StartModFile ') | |
| 14254 |
EndFileOp : fprintf0 (GetDumpFile (), 'EndFileOp ') | |
| 14255 |
InitStartOp : fprintf0 (GetDumpFile (), 'InitStart ') | |
| 14256 |
InitEndOp : fprintf0 (GetDumpFile (), 'InitEnd ') | |
| 14257 |
FinallyStartOp : fprintf0 (GetDumpFile (), 'FinallyStart ') | |
| 14258 |
FinallyEndOp : fprintf0 (GetDumpFile (), 'FinallyEnd ') | |
| 14259 |
RetryOp : fprintf0 (GetDumpFile (), 'Retry ') | |
| 14260 |
TryOp : fprintf0 (GetDumpFile (), 'Try ') | |
| 14261 |
ThrowOp : fprintf0 (GetDumpFile (), 'Throw ') | |
| 14262 |
CatchBeginOp : fprintf0 (GetDumpFile (), 'CatchBegin ') | |
| 14263 |
CatchEndOp : fprintf0 (GetDumpFile (), 'CatchEnd ') | |
| 14264 |
AddOp : fprintf0 (GetDumpFile (), '+ ') | |
| 14265 |
SubOp : fprintf0 (GetDumpFile (), '- ') | |
| 14266 |
DivM2Op : fprintf0 (GetDumpFile (), 'DIV M2 ') | |
| 14267 |
ModM2Op : fprintf0 (GetDumpFile (), 'MOD M2 ') | |
| 14268 |
DivCeilOp : fprintf0 (GetDumpFile (), 'DIV ceil ') | |
| 14269 |
ModCeilOp : fprintf0 (GetDumpFile (), 'MOD ceil ') | |
| 14270 |
DivFloorOp : fprintf0 (GetDumpFile (), 'DIV floor ') | |
| 14271 |
ModFloorOp : fprintf0 (GetDumpFile (), 'MOD floor ') | |
| 14272 |
DivTruncOp : fprintf0 (GetDumpFile (), 'DIV trunc ') | |
| 14273 |
ModTruncOp : fprintf0 (GetDumpFile (), 'MOD trunc ') | |
| 14274 |
MultOp : fprintf0 (GetDumpFile (), '* ') | |
| 14275 |
NegateOp : fprintf0 (GetDumpFile (), 'Negate ') | |
| 14276 |
InclOp : fprintf0 (GetDumpFile (), 'Incl ') | |
| 14277 |
ExclOp : fprintf0 (GetDumpFile (), 'Excl ') | |
| 14278 |
ReturnOp : fprintf0 (GetDumpFile (), 'Return ') | |
| 14279 |
ReturnValueOp : fprintf0 (GetDumpFile (), 'ReturnValue ') | |
| 14280 |
FunctValueOp : fprintf0 (GetDumpFile (), 'FunctValue ') | |
| 14281 |
CallOp : fprintf0 (GetDumpFile (), 'Call ') | |
| 14282 |
ParamOp : fprintf0 (GetDumpFile (), 'Param ') | |
| 14283 |
OptParamOp : fprintf0 (GetDumpFile (), 'OptParam ') | |
| 14284 |
NewLocalVarOp : fprintf0 (GetDumpFile (), 'NewLocalVar ') | |
| 14285 |
KillLocalVarOp : fprintf0 (GetDumpFile (), 'KillLocalVar ') | |
| 14286 |
ProcedureScopeOp : fprintf0 (GetDumpFile (), 'ProcedureScope ') | |
| 14287 |
UnboundedOp : fprintf0 (GetDumpFile (), 'Unbounded ') | |
| 14288 |
CoerceOp : fprintf0 (GetDumpFile (), 'Coerce ') | |
| 14289 |
ConvertOp : fprintf0 (GetDumpFile (), 'Convert ') | |
| 14290 |
CastOp : fprintf0 (GetDumpFile (), 'Cast ') | |
| 14291 |
HighOp : fprintf0 (GetDumpFile (), 'High ') | |
| 14292 |
CodeOnOp : fprintf0 (GetDumpFile (), 'CodeOn ') | |
| 14293 |
CodeOffOp : fprintf0 (GetDumpFile (), 'CodeOff ') | |
| 14294 |
ProfileOnOp : fprintf0 (GetDumpFile (), 'ProfileOn ') | |
| 14295 |
ProfileOffOp : fprintf0 (GetDumpFile (), 'ProfileOff ') | |
| 14296 |
OptimizeOnOp : fprintf0 (GetDumpFile (), 'OptimizeOn ') | |
| 14297 |
OptimizeOffOp : fprintf0 (GetDumpFile (), 'OptimizeOff ') | |
| 14298 |
InlineOp : fprintf0 (GetDumpFile (), 'Inline ') | |
| 14299 |
StatementNoteOp : fprintf0 (GetDumpFile (), 'StatementNote ') | |
| 14300 |
LineNumberOp : fprintf0 (GetDumpFile (), 'LineNumber ') | |
| 14301 |
BuiltinConstOp : fprintf0 (GetDumpFile (), 'BuiltinConst ') | |
| 14302 |
BuiltinTypeInfoOp : fprintf0 (GetDumpFile (), 'BuiltinTypeInfo ') | |
| 14303 |
StandardFunctionOp : fprintf0 (GetDumpFile (), 'StandardFunction ') | |
| 14304 |
SavePriorityOp : fprintf0 (GetDumpFile (), 'SavePriority ') | |
| 14305 |
RestorePriorityOp : fprintf0 (GetDumpFile (), 'RestorePriority ') | |
| 14306 |
RangeCheckOp : fprintf0 (GetDumpFile (), 'RangeCheck ') | |
| 14307 |
ErrorOp : fprintf0 (GetDumpFile (), 'Error ') | |
| 14308 |
SaveExceptionOp : fprintf0 (GetDumpFile (), 'SaveException ') | |
| 14309 |
RestoreExceptionOp : fprintf0 (GetDumpFile (), 'RestoreException ') | |
| 14310 |
StringConvertCnulOp : fprintf0 (GetDumpFile (), 'StringConvertCnul ') | |
| 14311 |
StringConvertM2nulOp : fprintf0 (GetDumpFile (), 'StringConvertM2nul') | |
| 14312 |
StringLengthOp : fprintf0 (GetDumpFile (), 'StringLength ') | |
| 14313 |
SubrangeHighOp : fprintf0 (GetDumpFile (), 'SubrangeHigh ') | |
| 14314 |
SubrangeLowOp : fprintf0 (GetDumpFile (), 'SubrangeLow ') |
| 14315 |
|
| 14316 |
ELSE |
| 14317 |
InternalError ('operator not expected') |
| 14318 |
END |
| 14319 |
END WriteOperator ; |
| 14320 |
|
| 14321 |
|
| 14322 |
(* |
| 14323 |
WriteOperand - displays the operands name, symbol id and mode of addressing. |
| 14324 |
*) |
| 14325 |
|
| 14326 |
PROCEDURE WriteOperand (Sym: CARDINAL) ; |
| 14327 |
VAR |
| 14328 |
n: Name ; |
| 14329 |
BEGIN |
| 14330 |
IF Sym = NulSym |
| 14331 |
THEN |
| 14332 |
fprintf0 (GetDumpFile (), '<nulsym>') |
| 14333 |
ELSE |
| 14334 |
n := GetSymName (Sym) ; |
| 14335 |
fprintf1 (GetDumpFile (), '%a', n) ; |
| 14336 |
IF IsVar (Sym) OR IsConst (Sym) |
| 14337 |
THEN |
| 14338 |
fprintf0 (GetDumpFile (), '[') ; WriteMode (GetMode (Sym)) ; fprintf0 (GetDumpFile (), ']') |
| 14339 |
END ; |
| 14340 |
fprintf1 (GetDumpFile (), '(%d)', Sym) |
| 14341 |
END |
| 14342 |
END WriteOperand ; |
| 14343 |
|
| 14344 |
|
| 14345 |
PROCEDURE WriteMode (Mode: ModeOfAddr) ; |
| 14346 |
BEGIN |
| 14347 |
CASE Mode OF |
| 14348 |
|
| 14349 |
ImmediateValue: fprintf0 (GetDumpFile (), 'i') | |
| 14350 |
NoValue : fprintf0 (GetDumpFile (), 'n') | |
| 14351 |
RightValue : fprintf0 (GetDumpFile (), 'r') | |
| 14352 |
LeftValue : fprintf0 (GetDumpFile (), 'l') |
| 14353 |
|
| 14354 |
ELSE |
| 14355 |
InternalError ('unrecognised mode') |
| 14356 |
END |
| 14357 |
END WriteMode ; |
| 14358 |
|
| 14359 |
|
| 14360 |
(* |
| 14361 |
GetQuadOp - returns the operator for quad. |
| 14362 |
*) |
| 14363 |
|
| 14364 |
PROCEDURE GetQuadOp (quad: CARDINAL) : QuadOperator ; |
| 14365 |
VAR |
| 14366 |
f: QuadFrame ; |
| 14367 |
BEGIN |
| 14368 |
f := GetQF (quad) ; |
| 14369 |
RETURN f^.Operator |
| 14370 |
END GetQuadOp ; |
| 14371 |
|
| 14372 |
|
| 14373 |
(* |
| 14374 |
GetM2OperatorDesc - returns the Modula-2 string associated with the quad operator |
| 14375 |
(if possible). It returns NIL if no there is not an obvious match |
| 14376 |
in Modula-2. It is assummed that the string will be used during |
| 14377 |
construction of error messages and therefore keywords are |
| 14378 |
wrapped with a format specifier. |
| 14379 |
*) |
| 14380 |
|
| 14381 |
PROCEDURE GetM2OperatorDesc (op: QuadOperator) : String ; |
| 14382 |
BEGIN |
| 14383 |
CASE op OF |
| 14384 |
|
| 14385 |
NegateOp : RETURN InitString ('-') | |
| 14386 |
AddOp : RETURN InitString ('+') | |
| 14387 |
SubOp : RETURN InitString ('-') | |
| 14388 |
MultOp : RETURN InitString ('*') | |
| 14389 |
DivM2Op, |
| 14390 |
DivCeilOp, |
| 14391 |
DivFloorOp, |
| 14392 |
DivTruncOp : RETURN InitString ('{%kDIV}') | |
| 14393 |
ModM2Op, |
| 14394 |
ModCeilOp, |
| 14395 |
ModFloorOp : RETURN InitString ('{%kMOD}') | |
| 14396 |
ModTruncOp : RETURN InitString ('{%kREM}') | |
| 14397 |
LogicalOrOp : RETURN InitString ('{%kOR}') | |
| 14398 |
LogicalAndOp: RETURN InitString ('{%kAND}') | |
| 14399 |
InclOp : RETURN InitString ('{%kINCL}') | |
| 14400 |
ExclOp : RETURN InitString ('{%kEXCL}') | |
| 14401 |
IfEquOp : RETURN InitString ('=') | |
| 14402 |
IfLessEquOp : RETURN InitString ('<=') | |
| 14403 |
IfGreEquOp : RETURN InitString ('>=') | |
| 14404 |
IfGreOp : RETURN InitString ('>') | |
| 14405 |
IfLessOp : RETURN InitString ('<') | |
| 14406 |
IfNotEquOp : RETURN InitString ('#') | |
| 14407 |
IfInOp : RETURN InitString ('IN') | |
| 14408 |
IfNotInOp : RETURN InitString ('NOT IN') |
| 14409 |
|
| 14410 |
ELSE |
| 14411 |
RETURN NIL |
| 14412 |
END |
| 14413 |
END GetM2OperatorDesc ; |
| 14414 |
|
| 14415 |
|
| 14416 |
|
| 14417 |
(* |
| 14418 |
PushExit - pushes the exit value onto the EXIT stack. |
| 14419 |
*) |
| 14420 |
|
| 14421 |
PROCEDURE PushExit (Exit: CARDINAL) ; |
| 14422 |
BEGIN |
| 14423 |
PushWord(ExitStack, Exit) |
| 14424 |
END PushExit ; |
| 14425 |
|
| 14426 |
|
| 14427 |
(* |
| 14428 |
PopExit - pops the exit value from the EXIT stack. |
| 14429 |
*) |
| 14430 |
|
| 14431 |
PROCEDURE PopExit() : WORD ; |
| 14432 |
BEGIN |
| 14433 |
RETURN( PopWord(ExitStack) ) |
| 14434 |
END PopExit ; |
| 14435 |
|
| 14436 |
|
| 14437 |
(* |
| 14438 |
PushFor - pushes the exit value onto the FOR stack. |
| 14439 |
*) |
| 14440 |
|
| 14441 |
PROCEDURE PushFor (Exit: CARDINAL) ; |
| 14442 |
BEGIN |
| 14443 |
PushWord(ForStack, Exit) |
| 14444 |
END PushFor ; |
| 14445 |
|
| 14446 |
|
| 14447 |
(* |
| 14448 |
PopFor - pops the exit value from the FOR stack. |
| 14449 |
*) |
| 14450 |
|
| 14451 |
PROCEDURE PopFor() : WORD ; |
| 14452 |
BEGIN |
| 14453 |
RETURN( PopWord(ForStack) ) |
| 14454 |
END PopFor ; |
| 14455 |
|
| 14456 |
|
| 14457 |
(* |
| 14458 |
OperandTno - returns the ident operand stored in the true position |
| 14459 |
on the boolean stack. This is exactly the same as |
| 14460 |
OperandT but it has no IsBoolean checking. |
| 14461 |
*) |
| 14462 |
|
| 14463 |
PROCEDURE OperandTno (pos: CARDINAL) : WORD ; |
| 14464 |
VAR |
| 14465 |
f: BoolFrame ; |
| 14466 |
BEGIN |
| 14467 |
Assert(pos>0) ; |
| 14468 |
f := PeepAddress(BoolStack, pos) ; |
| 14469 |
RETURN( f^.TrueExit ) |
| 14470 |
END OperandTno ; |
| 14471 |
|
| 14472 |
|
| 14473 |
(* |
| 14474 |
OperandFno - returns the ident operand stored in the false position |
| 14475 |
on the boolean stack. This is exactly the same as |
| 14476 |
OperandF but it has no IsBoolean checking. |
| 14477 |
*) |
| 14478 |
|
| 14479 |
PROCEDURE OperandFno (pos: CARDINAL) : WORD ; |
| 14480 |
VAR |
| 14481 |
f: BoolFrame ; |
| 14482 |
BEGIN |
| 14483 |
Assert(pos>0) ; |
| 14484 |
f := PeepAddress (BoolStack, pos) ; |
| 14485 |
RETURN f^.FalseExit |
| 14486 |
END OperandFno ; |
| 14487 |
|
| 14488 |
|
| 14489 |
(* |
| 14490 |
OperandTtok - returns the token associated with the position, pos |
| 14491 |
on the boolean stack. |
| 14492 |
*) |
| 14493 |
|
| 14494 |
PROCEDURE OperandTtok (pos: CARDINAL) : CARDINAL ; |
| 14495 |
VAR |
| 14496 |
f: BoolFrame ; |
| 14497 |
BEGIN |
| 14498 |
Assert (pos > 0) ; |
| 14499 |
f := PeepAddress (BoolStack, pos) ; |
| 14500 |
RETURN f^.tokenno |
| 14501 |
END OperandTtok ; |
| 14502 |
|
| 14503 |
|
| 14504 |
(* |
| 14505 |
PopBooltok - Pops a True and a False exit quad number from the True/False |
| 14506 |
stack. |
| 14507 |
*) |
| 14508 |
|
| 14509 |
PROCEDURE PopBooltok (VAR True, False: CARDINAL; VAR tokno: CARDINAL) ; |
| 14510 |
VAR |
| 14511 |
f: BoolFrame ; |
| 14512 |
BEGIN |
| 14513 |
f := PopAddress (BoolStack) ; |
| 14514 |
WITH f^ DO |
| 14515 |
True := TrueExit ; |
| 14516 |
False := FalseExit ; |
| 14517 |
tokno := tokenno ; |
| 14518 |
Assert (BooleanOp) |
| 14519 |
END ; |
| 14520 |
DISPOSE (f) |
| 14521 |
END PopBooltok ; |
| 14522 |
|
| 14523 |
|
| 14524 |
(* |
| 14525 |
PushBooltok - Push a True and a False exit quad numbers onto the |
| 14526 |
True/False stack. |
| 14527 |
*) |
| 14528 |
|
| 14529 |
PROCEDURE PushBooltok (True, False: CARDINAL; tokno: CARDINAL) ; |
| 14530 |
VAR |
| 14531 |
f: BoolFrame ; |
| 14532 |
BEGIN |
| 14533 |
Assert (True<=NextQuad) ; |
| 14534 |
Assert (False<=NextQuad) ; |
| 14535 |
f := newBoolFrame () ; |
| 14536 |
WITH f^ DO |
| 14537 |
TrueExit := True ; |
| 14538 |
FalseExit := False ; |
| 14539 |
BooleanOp := TRUE ; |
| 14540 |
tokenno := tokno ; |
| 14541 |
Annotation := NIL ; |
| 14542 |
RangeDep := 0 |
| 14543 |
END ; |
| 14544 |
PushAddress (BoolStack, f) ; |
| 14545 |
Annotate ('<q%1d>|<q%2d>||true quad|false quad') |
| 14546 |
END PushBooltok ; |
| 14547 |
|
| 14548 |
|
| 14549 |
(* |
| 14550 |
PopBool - Pops a True and a False exit quad number from the True/False |
| 14551 |
stack. |
| 14552 |
*) |
| 14553 |
|
| 14554 |
PROCEDURE PopBool (VAR True, False: CARDINAL) ; |
| 14555 |
VAR |
| 14556 |
tokno: CARDINAL ; |
| 14557 |
BEGIN |
| 14558 |
PopBooltok (True, False, tokno) |
| 14559 |
END PopBool ; |
| 14560 |
|
| 14561 |
|
| 14562 |
(* |
| 14563 |
PushBool - Push a True and a False exit quad numbers onto the |
| 14564 |
True/False stack. |
| 14565 |
*) |
| 14566 |
|
| 14567 |
PROCEDURE PushBool (True, False: CARDINAL) ; |
| 14568 |
BEGIN |
| 14569 |
PushBooltok (True, False, UnknownTokenNo) |
| 14570 |
END PushBool ; |
| 14571 |
|
| 14572 |
|
| 14573 |
(* |
| 14574 |
IsBoolean - returns true is the Stack position pos contains a Boolean |
| 14575 |
Exit. False is returned if an Ident is stored. |
| 14576 |
*) |
| 14577 |
|
| 14578 |
PROCEDURE IsBoolean (pos: CARDINAL) : BOOLEAN ; |
| 14579 |
VAR |
| 14580 |
f: BoolFrame ; |
| 14581 |
BEGIN |
| 14582 |
Assert(pos>0) ; |
| 14583 |
f := PeepAddress(BoolStack, pos) ; |
| 14584 |
RETURN( f^.BooleanOp ) |
| 14585 |
END IsBoolean ; |
| 14586 |
|
| 14587 |
|
| 14588 |
(* |
| 14589 |
OperandD - returns possible array dimension associated with the ident |
| 14590 |
operand stored on the boolean stack. |
| 14591 |
*) |
| 14592 |
|
| 14593 |
PROCEDURE OperandD (pos: CARDINAL) : WORD ; |
| 14594 |
VAR |
| 14595 |
f: BoolFrame ; |
| 14596 |
BEGIN |
| 14597 |
Assert(pos>0) ; |
| 14598 |
Assert(NOT IsBoolean (pos)) ; |
| 14599 |
f := PeepAddress(BoolStack, pos) ; |
| 14600 |
RETURN( f^.Dimension ) |
| 14601 |
END OperandD ; |
| 14602 |
|
| 14603 |
|
| 14604 |
(* |
| 14605 |
OperandA - returns possible array symbol associated with the ident |
| 14606 |
operand stored on the boolean stack. |
| 14607 |
*) |
| 14608 |
|
| 14609 |
PROCEDURE OperandA (pos: CARDINAL) : WORD ; |
| 14610 |
VAR |
| 14611 |
f: BoolFrame ; |
| 14612 |
BEGIN |
| 14613 |
Assert(pos>0) ; |
| 14614 |
Assert(NOT IsBoolean (pos)) ; |
| 14615 |
f := PeepAddress(BoolStack, pos) ; |
| 14616 |
RETURN( f^.Unbounded ) |
| 14617 |
END OperandA ; |
| 14618 |
|
| 14619 |
|
| 14620 |
(* |
| 14621 |
OperandT - returns the ident operand stored in the true position on the boolean stack. |
| 14622 |
*) |
| 14623 |
|
| 14624 |
PROCEDURE OperandT (pos: CARDINAL) : WORD ; |
| 14625 |
BEGIN |
| 14626 |
Assert(NOT IsBoolean (pos)) ; |
| 14627 |
RETURN( OperandTno(pos) ) |
| 14628 |
END OperandT ; |
| 14629 |
|
| 14630 |
|
| 14631 |
(* |
| 14632 |
OperandF - returns the ident operand stored in the false position on the boolean stack. |
| 14633 |
*) |
| 14634 |
|
| 14635 |
PROCEDURE OperandF (pos: CARDINAL) : WORD ; |
| 14636 |
BEGIN |
| 14637 |
Assert(NOT IsBoolean (pos)) ; |
| 14638 |
RETURN( OperandFno(pos) ) |
| 14639 |
END OperandF ; |
| 14640 |
|
| 14641 |
|
| 14642 |
(* |
| 14643 |
OperandRW - returns the rw operand stored on the boolean stack. |
| 14644 |
*) |
| 14645 |
|
| 14646 |
PROCEDURE OperandRW (pos: CARDINAL) : WORD ; |
| 14647 |
VAR |
| 14648 |
f: BoolFrame ; |
| 14649 |
BEGIN |
| 14650 |
Assert(pos>0) ; |
| 14651 |
Assert(NOT IsBoolean (pos)) ; |
| 14652 |
f := PeepAddress(BoolStack, pos) ; |
| 14653 |
RETURN( f^.ReadWrite ) |
| 14654 |
END OperandRW ; |
| 14655 |
|
| 14656 |
|
| 14657 |
(* |
| 14658 |
OperandMergeRW - returns the rw operand if not NulSym else it |
| 14659 |
returns True. |
| 14660 |
*) |
| 14661 |
|
| 14662 |
PROCEDURE OperandMergeRW (pos: CARDINAL) : WORD ; |
| 14663 |
BEGIN |
| 14664 |
IF OperandRW (pos) = NulSym |
| 14665 |
THEN |
| 14666 |
RETURN OperandT (pos) |
| 14667 |
ELSE |
| 14668 |
RETURN OperandRW (pos) |
| 14669 |
END |
| 14670 |
END OperandMergeRW ; |
| 14671 |
|
| 14672 |
|
| 14673 |
(* |
| 14674 |
OperandTok - returns the token associated with pos, on the stack. |
| 14675 |
*) |
| 14676 |
|
| 14677 |
PROCEDURE OperandTok (pos: CARDINAL) : WORD ; |
| 14678 |
BEGIN |
| 14679 |
Assert (NOT IsBoolean (pos)) ; |
| 14680 |
RETURN OperandTtok (pos) |
| 14681 |
END OperandTok ; |
| 14682 |
|
| 14683 |
|
| 14684 |
(* |
| 14685 |
OperandRangeDep - return the range dependant associated with the quad stack. |
| 14686 |
*) |
| 14687 |
|
| 14688 |
PROCEDURE OperandRangeDep (pos: CARDINAL) : CARDINAL ; |
| 14689 |
VAR |
| 14690 |
f: BoolFrame ; |
| 14691 |
BEGIN |
| 14692 |
Assert (NOT IsBoolean (pos)) ; |
| 14693 |
f := PeepAddress (BoolStack, pos) ; |
| 14694 |
RETURN f^.RangeDep |
| 14695 |
END OperandRangeDep ; |
| 14696 |
|
| 14697 |
|
| 14698 |
(* |
| 14699 |
PutRangeDep - assigns the quad stack pos RangeDep to dep. |
| 14700 |
*) |
| 14701 |
|
| 14702 |
PROCEDURE PutRangeDep (pos: CARDINAL; dep: CARDINAL) ; |
| 14703 |
VAR |
| 14704 |
f: BoolFrame ; |
| 14705 |
BEGIN |
| 14706 |
Assert (NOT IsBoolean (pos)) ; |
| 14707 |
f := PeepAddress (BoolStack, pos) ; |
| 14708 |
f^.RangeDep := dep |
| 14709 |
END PutRangeDep ; |
| 14710 |
|
| 14711 |
|
| 14712 |
(* |
| 14713 |
BuildCodeOn - generates a quadruple declaring that code should be |
| 14714 |
emmitted from henceforth. |
| 14715 |
|
| 14716 |
The Stack is unnaffected. |
| 14717 |
*) |
| 14718 |
|
| 14719 |
PROCEDURE BuildCodeOn ; |
| 14720 |
BEGIN |
| 14721 |
GenQuad(CodeOnOp, NulSym, NulSym, NulSym) |
| 14722 |
END BuildCodeOn ; |
| 14723 |
|
| 14724 |
|
| 14725 |
(* |
| 14726 |
BuildCodeOff - generates a quadruple declaring that code should not be |
| 14727 |
emmitted from henceforth. |
| 14728 |
|
| 14729 |
The Stack is unnaffected. |
| 14730 |
*) |
| 14731 |
|
| 14732 |
PROCEDURE BuildCodeOff ; |
| 14733 |
BEGIN |
| 14734 |
GenQuad(CodeOffOp, NulSym, NulSym, NulSym) |
| 14735 |
END BuildCodeOff ; |
| 14736 |
|
| 14737 |
|
| 14738 |
(* |
| 14739 |
BuildProfileOn - generates a quadruple declaring that profile timings |
| 14740 |
should be emmitted from henceforth. |
| 14741 |
|
| 14742 |
The Stack is unnaffected. |
| 14743 |
*) |
| 14744 |
|
| 14745 |
PROCEDURE BuildProfileOn ; |
| 14746 |
BEGIN |
| 14747 |
GenQuad(ProfileOnOp, NulSym, NulSym, NulSym) |
| 14748 |
END BuildProfileOn ; |
| 14749 |
|
| 14750 |
|
| 14751 |
(* |
| 14752 |
BuildProfileOn - generates a quadruple declaring that profile timings |
| 14753 |
should be emmitted from henceforth. |
| 14754 |
|
| 14755 |
The Stack is unnaffected. |
| 14756 |
*) |
| 14757 |
|
| 14758 |
PROCEDURE BuildProfileOff ; |
| 14759 |
BEGIN |
| 14760 |
GenQuad(ProfileOffOp, NulSym, NulSym, NulSym) |
| 14761 |
END BuildProfileOff ; |
| 14762 |
|
| 14763 |
|
| 14764 |
(* |
| 14765 |
BuildOptimizeOn - generates a quadruple declaring that optimization |
| 14766 |
should occur from henceforth. |
| 14767 |
|
| 14768 |
The Stack is unnaffected. |
| 14769 |
*) |
| 14770 |
|
| 14771 |
PROCEDURE BuildOptimizeOn ; |
| 14772 |
BEGIN |
| 14773 |
GenQuad(OptimizeOnOp, NulSym, NulSym, NulSym) |
| 14774 |
END BuildOptimizeOn ; |
| 14775 |
|
| 14776 |
|
| 14777 |
(* |
| 14778 |
BuildOptimizeOff - generates a quadruple declaring that optimization |
| 14779 |
should not occur from henceforth. |
| 14780 |
|
| 14781 |
The Stack is unnaffected. |
| 14782 |
*) |
| 14783 |
|
| 14784 |
PROCEDURE BuildOptimizeOff ; |
| 14785 |
BEGIN |
| 14786 |
GenQuad (OptimizeOffOp, NulSym, NulSym, NulSym) |
| 14787 |
END BuildOptimizeOff ; |
| 14788 |
|
| 14789 |
|
| 14790 |
(* |
| 14791 |
BuildAsm - builds an Inline pseudo quadruple operator. |
| 14792 |
The inline interface, Sym, is stored as the operand |
| 14793 |
to the operator InlineOp. |
| 14794 |
|
| 14795 |
The stack is expected to contain: |
| 14796 |
|
| 14797 |
|
| 14798 |
Entry Exit |
| 14799 |
===== ==== |
| 14800 |
|
| 14801 |
Ptr -> |
| 14802 |
+--------------+ |
| 14803 |
| Sym | Empty |
| 14804 |
|--------------| |
| 14805 |
*) |
| 14806 |
|
| 14807 |
PROCEDURE BuildAsm (tok: CARDINAL) ; |
| 14808 |
VAR |
| 14809 |
Sym: CARDINAL ; |
| 14810 |
BEGIN |
| 14811 |
PopT (Sym) ; |
| 14812 |
GenQuadO (tok, InlineOp, NulSym, NulSym, Sym, FALSE) |
| 14813 |
END BuildAsm ; |
| 14814 |
|
| 14815 |
|
| 14816 |
(* |
| 14817 |
BuildLineNo - builds a LineNumberOp pseudo quadruple operator. |
| 14818 |
This quadruple indicates which source line has been |
| 14819 |
processed, these quadruples are only generated if we |
| 14820 |
are producing runtime debugging information. |
| 14821 |
|
| 14822 |
The stack is not affected, read or altered in any way. |
| 14823 |
|
| 14824 |
|
| 14825 |
Entry Exit |
| 14826 |
===== ==== |
| 14827 |
|
| 14828 |
Ptr -> <- Ptr |
| 14829 |
*) |
| 14830 |
|
| 14831 |
PROCEDURE BuildLineNo ; |
| 14832 |
VAR |
| 14833 |
filename: Name ; |
| 14834 |
f : QuadFrame ; |
| 14835 |
BEGIN |
| 14836 |
IF (NextQuad#Head) AND (GenerateLineDebug OR GenerateDebugging) AND FALSE |
| 14837 |
THEN |
| 14838 |
filename := makekey (string (GetFileName ())) ; |
| 14839 |
f := GetQF (NextQuad-1) ; |
| 14840 |
IF NOT ((f^.Operator = LineNumberOp) AND (f^.Operand1 = WORD (filename))) |
| 14841 |
THEN |
| 14842 |
GenQuad (LineNumberOp, WORD (filename), NulSym, WORD (GetLineNo ())) |
| 14843 |
END |
| 14844 |
END |
| 14845 |
END BuildLineNo ; |
| 14846 |
|
| 14847 |
|
| 14848 |
(* |
| 14849 |
UseLineNote - uses the line note and returns it to the free list. |
| 14850 |
*) |
| 14851 |
|
| 14852 |
PROCEDURE UseLineNote (l: LineNote) ; |
| 14853 |
VAR |
| 14854 |
f: QuadFrame ; |
| 14855 |
BEGIN |
| 14856 |
WITH l^ DO |
| 14857 |
f := GetQF (NextQuad-1) ; |
| 14858 |
IF (f^.Operator = LineNumberOp) AND (f^.Operand1 = WORD (File)) |
| 14859 |
THEN |
| 14860 |
(* do nothing *) |
| 14861 |
ELSE |
| 14862 |
IF FALSE |
| 14863 |
THEN |
| 14864 |
GenQuad (LineNumberOp, WORD (File), NulSym, WORD (Line)) |
| 14865 |
END |
| 14866 |
END ; |
| 14867 |
Next := FreeLineList |
| 14868 |
END ; |
| 14869 |
FreeLineList := l |
| 14870 |
END UseLineNote ; |
| 14871 |
|
| 14872 |
|
| 14873 |
(* |
| 14874 |
PopLineNo - pops a line note from the line stack. |
| 14875 |
*) |
| 14876 |
|
| 14877 |
PROCEDURE PopLineNo () : LineNote ; |
| 14878 |
VAR |
| 14879 |
l: LineNote ; |
| 14880 |
BEGIN |
| 14881 |
l := PopAddress(LineStack) ; |
| 14882 |
IF l=NIL |
| 14883 |
THEN |
| 14884 |
InternalError ('no line note available') |
| 14885 |
END ; |
| 14886 |
RETURN( l ) |
| 14887 |
END PopLineNo ; |
| 14888 |
|
| 14889 |
|
| 14890 |
(* |
| 14891 |
InitLineNote - creates a line note and initializes it to |
| 14892 |
contain, file, line. |
| 14893 |
*) |
| 14894 |
|
| 14895 |
PROCEDURE InitLineNote (file: Name; line: CARDINAL) : LineNote ; |
| 14896 |
VAR |
| 14897 |
l: LineNote ; |
| 14898 |
BEGIN |
| 14899 |
IF FreeLineList=NIL |
| 14900 |
THEN |
| 14901 |
NEW(l) |
| 14902 |
ELSE |
| 14903 |
l := FreeLineList ; |
| 14904 |
FreeLineList := FreeLineList^.Next |
| 14905 |
END ; |
| 14906 |
WITH l^ DO |
| 14907 |
File := file ; |
| 14908 |
Line := line |
| 14909 |
END ; |
| 14910 |
RETURN( l ) |
| 14911 |
END InitLineNote ; |
| 14912 |
|
| 14913 |
|
| 14914 |
(* |
| 14915 |
PushLineNote - |
| 14916 |
*) |
| 14917 |
|
| 14918 |
PROCEDURE PushLineNote (l: LineNote) ; |
| 14919 |
BEGIN |
| 14920 |
PushAddress(LineStack, l) |
| 14921 |
END PushLineNote ; |
| 14922 |
|
| 14923 |
|
| 14924 |
(* |
| 14925 |
PushLineNo - pushes the current file and line number to the stack. |
| 14926 |
*) |
| 14927 |
|
| 14928 |
PROCEDURE PushLineNo ; |
| 14929 |
BEGIN |
| 14930 |
PushLineNote(InitLineNote(makekey(string(GetFileName())), GetLineNo())) |
| 14931 |
END PushLineNo ; |
| 14932 |
|
| 14933 |
|
| 14934 |
(* |
| 14935 |
BuildStmtNote - builds a StatementNoteOp pseudo quadruple operator. |
| 14936 |
This quadruple indicates which source line has been |
| 14937 |
processed and it represents the start of a statement |
| 14938 |
sequence. |
| 14939 |
It differs from LineNumberOp in that multiple successive |
| 14940 |
LineNumberOps will be removed and the final one is attached to |
| 14941 |
the next real GCC tree. Whereas a StatementNoteOp is always left |
| 14942 |
alone. Depending upon the debugging level it will issue a nop |
| 14943 |
instruction to ensure that the gdb single step will step into |
| 14944 |
this line. Practically it allows pedalogical debugging to |
| 14945 |
occur when there is syntax sugar such as: |
| 14946 |
|
| 14947 |
|
| 14948 |
END (* step *) |
| 14949 |
END (* step *) |
| 14950 |
END ; (* step *) |
| 14951 |
a := 1 ; (* step *) |
| 14952 |
|
| 14953 |
REPEAT (* step *) |
| 14954 |
i := 1 (* step *) |
| 14955 |
|
| 14956 |
The stack is not affected, read or altered in any way. |
| 14957 |
|
| 14958 |
|
| 14959 |
Entry Exit |
| 14960 |
===== ==== |
| 14961 |
|
| 14962 |
Ptr -> <- Ptr |
| 14963 |
*) |
| 14964 |
|
| 14965 |
PROCEDURE BuildStmtNote (offset: INTEGER) ; |
| 14966 |
VAR |
| 14967 |
tokenno: INTEGER ; |
| 14968 |
BEGIN |
| 14969 |
IF NextQuad#Head |
| 14970 |
THEN |
| 14971 |
tokenno := offset ; |
| 14972 |
INC (tokenno, GetTokenNo ()) ; |
| 14973 |
BuildStmtNoteTok (VAL(CARDINAL, tokenno)) |
| 14974 |
END |
| 14975 |
END BuildStmtNote ; |
| 14976 |
|
| 14977 |
|
| 14978 |
(* |
| 14979 |
BuildStmtNoteTok - adds a nop (with an assigned tokenno location) to the code. |
| 14980 |
*) |
| 14981 |
|
| 14982 |
PROCEDURE BuildStmtNoteTok (tokenno: CARDINAL) ; |
| 14983 |
VAR |
| 14984 |
filename: Name ; |
| 14985 |
f : QuadFrame ; |
| 14986 |
BEGIN |
| 14987 |
f := GetQF (NextQuad-1) ; |
| 14988 |
(* no need to have multiple notes at the same position. *) |
| 14989 |
IF (f^.Operator # StatementNoteOp) OR (f^.Operand3 # tokenno) |
| 14990 |
THEN |
| 14991 |
filename := makekey (string (GetFileName ())) ; |
| 14992 |
GenQuad (StatementNoteOp, WORD (filename), NulSym, tokenno) |
| 14993 |
END |
| 14994 |
END BuildStmtNoteTok ; |
| 14995 |
|
| 14996 |
|
| 14997 |
(* |
| 14998 |
AddRecordToList - adds the record held on the top of stack to the |
| 14999 |
list of records and varient fields. |
| 15000 |
*) |
| 15001 |
|
| 15002 |
PROCEDURE AddRecordToList ; |
| 15003 |
VAR |
| 15004 |
r: CARDINAL ; |
| 15005 |
n: CARDINAL ; |
| 15006 |
BEGIN |
| 15007 |
r := OperandT(1) ; |
| 15008 |
Assert(IsRecord(r) OR IsFieldVarient(r)) ; |
| 15009 |
(* |
| 15010 |
r might be a field varient if the declaration consists of nested |
| 15011 |
varients. However ISO TSIZE can only utilise record types, we store |
| 15012 |
a varient field anyway as the next pass would not know whether to |
| 15013 |
ignore a varient field. |
| 15014 |
*) |
| 15015 |
PutItemIntoList (VarientFields, r) ; |
| 15016 |
IF DebugVarients |
| 15017 |
THEN |
| 15018 |
n := NoOfItemsInList(VarientFields) ; |
| 15019 |
IF IsRecord(r) |
| 15020 |
THEN |
| 15021 |
printf2('in list: record %d is %d\n', n, r) |
| 15022 |
ELSE |
| 15023 |
printf2('in list: varient field %d is %d\n', n, r) |
| 15024 |
END |
| 15025 |
END |
| 15026 |
END AddRecordToList ; |
| 15027 |
|
| 15028 |
|
| 15029 |
(* |
| 15030 |
AddVarientToList - adds varient held on the top of stack to the list. |
| 15031 |
*) |
| 15032 |
|
| 15033 |
PROCEDURE AddVarientToList ; |
| 15034 |
VAR |
| 15035 |
v, n: CARDINAL ; |
| 15036 |
BEGIN |
| 15037 |
v := OperandT(1) ; |
| 15038 |
Assert(IsVarient(v)) ; |
| 15039 |
PutItemIntoList(VarientFields, v) ; |
| 15040 |
IF DebugVarients |
| 15041 |
THEN |
| 15042 |
n := NoOfItemsInList(VarientFields) ; |
| 15043 |
printf2('in list: varient %d is %d\n', n, v) |
| 15044 |
END |
| 15045 |
END AddVarientToList ; |
| 15046 |
|
| 15047 |
|
| 15048 |
(* |
| 15049 |
AddVarientFieldToList - adds varient field, f, to the list of all varient |
| 15050 |
fields created. |
| 15051 |
*) |
| 15052 |
|
| 15053 |
PROCEDURE AddVarientFieldToList (f: CARDINAL) ; |
| 15054 |
VAR |
| 15055 |
n: CARDINAL ; |
| 15056 |
BEGIN |
| 15057 |
Assert(IsFieldVarient(f)) ; |
| 15058 |
PutItemIntoList(VarientFields, f) ; |
| 15059 |
IF DebugVarients |
| 15060 |
THEN |
| 15061 |
n := NoOfItemsInList(VarientFields) ; |
| 15062 |
printf2('in list: varient field %d is %d\n', n, f) |
| 15063 |
END |
| 15064 |
END AddVarientFieldToList ; |
| 15065 |
|
| 15066 |
|
| 15067 |
(* |
| 15068 |
GetRecordOrField - |
| 15069 |
*) |
| 15070 |
|
| 15071 |
PROCEDURE GetRecordOrField () : CARDINAL ; |
| 15072 |
VAR |
| 15073 |
f: CARDINAL ; |
| 15074 |
BEGIN |
| 15075 |
INC(VarientFieldNo) ; |
| 15076 |
f := GetItemFromList(VarientFields, VarientFieldNo) ; |
| 15077 |
IF DebugVarients |
| 15078 |
THEN |
| 15079 |
IF IsRecord(f) |
| 15080 |
THEN |
| 15081 |
printf2('out list: record %d is %d\n', VarientFieldNo, f) |
| 15082 |
ELSE |
| 15083 |
printf2('out list: varient field %d is %d\n', VarientFieldNo, f) |
| 15084 |
END |
| 15085 |
END ; |
| 15086 |
RETURN( f ) |
| 15087 |
END GetRecordOrField ; |
| 15088 |
|
| 15089 |
|
| 15090 |
(* |
| 15091 |
BeginVarient - begin a varient record. |
| 15092 |
*) |
| 15093 |
|
| 15094 |
PROCEDURE BeginVarient ; |
| 15095 |
VAR |
| 15096 |
r, v: CARDINAL ; |
| 15097 |
BEGIN |
| 15098 |
r := GetRecordOrField() ; |
| 15099 |
Assert(IsRecord(r) OR IsFieldVarient(r)) ; |
| 15100 |
v := GetRecordOrField() ; |
| 15101 |
Assert(IsVarient(v)) ; |
| 15102 |
BuildRange(InitCaseBounds(PushCase(r, v, NulSym))) |
| 15103 |
END BeginVarient ; |
| 15104 |
|
| 15105 |
|
| 15106 |
(* |
| 15107 |
EndVarient - end a varient record. |
| 15108 |
*) |
| 15109 |
|
| 15110 |
PROCEDURE EndVarient ; |
| 15111 |
BEGIN |
| 15112 |
PopCase |
| 15113 |
END EndVarient ; |
| 15114 |
|
| 15115 |
|
| 15116 |
(* |
| 15117 |
ElseVarient - associate an ELSE clause with a varient record. |
| 15118 |
*) |
| 15119 |
|
| 15120 |
PROCEDURE ElseVarient ; |
| 15121 |
VAR |
| 15122 |
f: CARDINAL ; |
| 15123 |
BEGIN |
| 15124 |
f := GetRecordOrField() ; |
| 15125 |
Assert(IsFieldVarient(f)) ; |
| 15126 |
ElseCase(f) |
| 15127 |
END ElseVarient ; |
| 15128 |
|
| 15129 |
|
| 15130 |
|
| 15131 |
(* |
| 15132 |
BeginVarientList - begin an ident list containing ranges belonging to a |
| 15133 |
varient list. |
| 15134 |
*) |
| 15135 |
|
| 15136 |
PROCEDURE BeginVarientList ; |
| 15137 |
VAR |
| 15138 |
f: CARDINAL ; |
| 15139 |
BEGIN |
| 15140 |
f := GetRecordOrField() ; |
| 15141 |
Assert(IsFieldVarient(f)) ; |
| 15142 |
BeginCaseList(f) |
| 15143 |
END BeginVarientList ; |
| 15144 |
|
| 15145 |
|
| 15146 |
(* |
| 15147 |
EndVarientList - end a range list for a varient field. |
| 15148 |
*) |
| 15149 |
|
| 15150 |
PROCEDURE EndVarientList ; |
| 15151 |
BEGIN |
| 15152 |
EndCaseList |
| 15153 |
END EndVarientList ; |
| 15154 |
|
| 15155 |
|
| 15156 |
(* |
| 15157 |
AddVarientRange - creates a range from the top two contant expressions |
| 15158 |
on the stack which are recorded with the current |
| 15159 |
varient field. The stack is unaltered. |
| 15160 |
*) |
| 15161 |
|
| 15162 |
PROCEDURE AddVarientRange ; |
| 15163 |
VAR |
| 15164 |
r1, r2: CARDINAL ; |
| 15165 |
BEGIN |
| 15166 |
PopT(r2) ; |
| 15167 |
PopT(r1) ; |
| 15168 |
AddRange(r1, r2, GetTokenNo()) |
| 15169 |
END AddVarientRange ; |
| 15170 |
|
| 15171 |
|
| 15172 |
(* |
| 15173 |
AddVarientEquality - adds the contant expression on the top of the stack |
| 15174 |
to the current varient field being recorded. |
| 15175 |
The stack is unaltered. |
| 15176 |
*) |
| 15177 |
|
| 15178 |
PROCEDURE AddVarientEquality ; |
| 15179 |
VAR |
| 15180 |
r1: CARDINAL ; |
| 15181 |
BEGIN |
| 15182 |
PopT(r1) ; |
| 15183 |
AddRange(r1, NulSym, GetTokenNo()) |
| 15184 |
END AddVarientEquality ; |
| 15185 |
|
| 15186 |
|
| 15187 |
(* |
| 15188 |
BuildAsmElement - the stack is expected to contain: |
| 15189 |
|
| 15190 |
|
| 15191 |
Entry Exit |
| 15192 |
===== ==== |
| 15193 |
|
| 15194 |
Ptr -> |
| 15195 |
+------------------+ |
| 15196 |
| expr | tokpos | |
| 15197 |
|------------------| |
| 15198 |
| str | |
| 15199 |
|------------------| |
| 15200 |
| name | |
| 15201 |
|------------------| +------------------+ |
| 15202 |
| CurrentInterface | | CurrentInterface | |
| 15203 |
|------------------| |------------------| |
| 15204 |
| CurrentAsm | | CurrentAsm | |
| 15205 |
|------------------| |------------------| |
| 15206 |
| n | | n | |
| 15207 |
|------------------| |------------------| |
| 15208 |
*) |
| 15209 |
|
| 15210 |
PROCEDURE BuildAsmElement (input, output: BOOLEAN) ; |
| 15211 |
CONST |
| 15212 |
DebugAsmTokPos = FALSE ; |
| 15213 |
VAR |
| 15214 |
s : String ; |
| 15215 |
n, str, expr, tokpos, |
| 15216 |
CurrentInterface, |
| 15217 |
CurrentAsm, name : CARDINAL ; |
| 15218 |
BEGIN |
| 15219 |
PopTtok (expr, tokpos) ; |
| 15220 |
PopT (str) ; |
| 15221 |
PopT (name) ; |
| 15222 |
PopT (CurrentInterface) ; |
| 15223 |
PopT (CurrentAsm) ; |
| 15224 |
Assert (IsGnuAsm (CurrentAsm) OR IsGnuAsmVolatile (CurrentAsm)) ; |
| 15225 |
PopT (n) ; |
| 15226 |
INC (n) ; |
| 15227 |
IF CurrentInterface = NulSym |
| 15228 |
THEN |
| 15229 |
CurrentInterface := MakeRegInterface () |
| 15230 |
END ; |
| 15231 |
IF input |
| 15232 |
THEN |
| 15233 |
PutRegInterface (tokpos, CurrentInterface, n, name, str, expr, |
| 15234 |
NextQuad, 0) ; |
| 15235 |
IF DebugAsmTokPos |
| 15236 |
THEN |
| 15237 |
s := InitString ('input expression') ; |
| 15238 |
WarnStringAt (s, tokpos) |
| 15239 |
END |
| 15240 |
END ; |
| 15241 |
IF output |
| 15242 |
THEN |
| 15243 |
PutRegInterface (tokpos, CurrentInterface, n, name, str, expr, |
| 15244 |
0, NextQuad) ; |
| 15245 |
IF DebugAsmTokPos |
| 15246 |
THEN |
| 15247 |
s := InitString ('output expression') ; |
| 15248 |
WarnStringAt (s, tokpos) |
| 15249 |
END |
| 15250 |
END ; |
| 15251 |
PushT (n) ; |
| 15252 |
PushT (CurrentAsm) ; |
| 15253 |
PushT (CurrentInterface) |
| 15254 |
END BuildAsmElement ; |
| 15255 |
|
| 15256 |
|
| 15257 |
(* |
| 15258 |
BuildAsmTrash - the stack is expected to contain: |
| 15259 |
|
| 15260 |
|
| 15261 |
Entry Exit |
| 15262 |
===== ==== |
| 15263 |
|
| 15264 |
Ptr -> |
| 15265 |
+------------------+ |
| 15266 |
| expr | tokpos | |
| 15267 |
|------------------| +------------------+ |
| 15268 |
| CurrentInterface | | CurrentInterface | |
| 15269 |
|------------------| |------------------| |
| 15270 |
| CurrentAsm | | CurrentAsm | |
| 15271 |
|------------------| |------------------| |
| 15272 |
| n | | n | |
| 15273 |
|------------------| |------------------| |
| 15274 |
*) |
| 15275 |
|
| 15276 |
PROCEDURE BuildAsmTrash ; |
| 15277 |
VAR |
| 15278 |
n, expr, tokpos, |
| 15279 |
CurrentInterface, |
| 15280 |
CurrentAsm : CARDINAL ; |
| 15281 |
BEGIN |
| 15282 |
PopTtok (expr, tokpos) ; |
| 15283 |
PopT (CurrentInterface) ; |
| 15284 |
PopT (CurrentAsm) ; |
| 15285 |
Assert (IsGnuAsm (CurrentAsm) OR IsGnuAsmVolatile (CurrentAsm)) ; |
| 15286 |
PopT (n) ; |
| 15287 |
INC (n) ; |
| 15288 |
IF CurrentInterface = NulSym |
| 15289 |
THEN |
| 15290 |
CurrentInterface := MakeRegInterface () |
| 15291 |
END ; |
| 15292 |
PutRegInterface (tokpos, CurrentInterface, n, NulName, NulSym, expr, |
| 15293 |
0, NextQuad) ; |
| 15294 |
PushT (n) ; |
| 15295 |
PushT (CurrentAsm) ; |
| 15296 |
PushT (CurrentInterface) |
| 15297 |
END BuildAsmTrash ; |
| 15298 |
|
| 15299 |
|
| 15300 |
(* |
| 15301 |
IncOperandD - increment the dimension number associated with symbol |
| 15302 |
at, pos, on the boolean stack. |
| 15303 |
*) |
| 15304 |
|
| 15305 |
(* |
| 15306 |
PROCEDURE IncOperandD (pos: CARDINAL) ; |
| 15307 |
VAR |
| 15308 |
f: BoolFrame ; |
| 15309 |
BEGIN |
| 15310 |
f := PeepAddress(BoolStack, pos) ; |
| 15311 |
INC(f^.Dimension) |
| 15312 |
END IncOperandD ; |
| 15313 |
*) |
| 15314 |
|
| 15315 |
|
| 15316 |
(* |
| 15317 |
PushTFA - Push True, False, Array, numbers onto the |
| 15318 |
True/False stack. True and False are assumed to |
| 15319 |
contain Symbols or Ident etc. |
| 15320 |
*) |
| 15321 |
|
| 15322 |
PROCEDURE PushTFA (True, False, Array: WORD) ; |
| 15323 |
VAR |
| 15324 |
f: BoolFrame ; |
| 15325 |
BEGIN |
| 15326 |
f := newBoolFrame () ; |
| 15327 |
WITH f^ DO |
| 15328 |
TrueExit := True ; |
| 15329 |
FalseExit := False ; |
| 15330 |
Unbounded := Array |
| 15331 |
END ; |
| 15332 |
PushAddress(BoolStack, f) |
| 15333 |
END PushTFA ; |
| 15334 |
|
| 15335 |
|
| 15336 |
(* |
| 15337 |
PushTFAD - Push True, False, Array, Dim, numbers onto the |
| 15338 |
True/False stack. True and False are assumed to |
| 15339 |
contain Symbols or Ident etc. |
| 15340 |
*) |
| 15341 |
|
| 15342 |
PROCEDURE PushTFAD (True, False, Array, Dim: WORD) ; |
| 15343 |
VAR |
| 15344 |
f: BoolFrame ; |
| 15345 |
BEGIN |
| 15346 |
f := newBoolFrame () ; |
| 15347 |
WITH f^ DO |
| 15348 |
TrueExit := True ; |
| 15349 |
FalseExit := False ; |
| 15350 |
Unbounded := Array ; |
| 15351 |
Dimension := Dim |
| 15352 |
END ; |
| 15353 |
PushAddress(BoolStack, f) |
| 15354 |
END PushTFAD ; |
| 15355 |
|
| 15356 |
|
| 15357 |
(* |
| 15358 |
PushTFADtok - Push True, False, Array, Dim, numbers onto the |
| 15359 |
True/False stack. True and False are assumed to |
| 15360 |
contain Symbols or Ident etc. |
| 15361 |
*) |
| 15362 |
|
| 15363 |
PROCEDURE PushTFADtok (True, False, Array, Dim: WORD; tokno: CARDINAL) ; |
| 15364 |
VAR |
| 15365 |
f: BoolFrame ; |
| 15366 |
BEGIN |
| 15367 |
f := newBoolFrame () ; |
| 15368 |
WITH f^ DO |
| 15369 |
TrueExit := True ; |
| 15370 |
FalseExit := False ; |
| 15371 |
Unbounded := Array ; |
| 15372 |
Dimension := Dim ; |
| 15373 |
tokenno := tokno |
| 15374 |
END ; |
| 15375 |
PushAddress (BoolStack, f) |
| 15376 |
END PushTFADtok ; |
| 15377 |
|
| 15378 |
|
| 15379 |
(* |
| 15380 |
PushTFADrwtok - Push True, False, Array, Dim, rw, numbers onto the |
| 15381 |
True/False stack. True and False are assumed to |
| 15382 |
contain Symbols or Ident etc. |
| 15383 |
*) |
| 15384 |
|
| 15385 |
PROCEDURE PushTFADrwtok (True, False, Array, Dim, rw: WORD; Tok: CARDINAL) ; |
| 15386 |
VAR |
| 15387 |
f: BoolFrame ; |
| 15388 |
BEGIN |
| 15389 |
f := newBoolFrame () ; |
| 15390 |
WITH f^ DO |
| 15391 |
TrueExit := True ; |
| 15392 |
FalseExit := False ; |
| 15393 |
Unbounded := Array ; |
| 15394 |
Dimension := Dim ; |
| 15395 |
ReadWrite := rw ; |
| 15396 |
tokenno := Tok |
| 15397 |
END ; |
| 15398 |
PushAddress (BoolStack, f) |
| 15399 |
END PushTFADrwtok ; |
| 15400 |
|
| 15401 |
|
| 15402 |
(* |
| 15403 |
PopTFrwtok - Pop a True and False number from the True/False stack. |
| 15404 |
True and False are assumed to contain Symbols or Ident etc. |
| 15405 |
*) |
| 15406 |
|
| 15407 |
PROCEDURE PopTFrwtok (VAR True, False, rw: WORD; VAR tokno: CARDINAL) ; |
| 15408 |
VAR |
| 15409 |
f: BoolFrame ; |
| 15410 |
BEGIN |
| 15411 |
f := PopAddress(BoolStack) ; |
| 15412 |
WITH f^ DO |
| 15413 |
True := TrueExit ; |
| 15414 |
False := FalseExit ; |
| 15415 |
Assert(NOT BooleanOp) ; |
| 15416 |
rw := ReadWrite ; |
| 15417 |
tokno := tokenno |
| 15418 |
END ; |
| 15419 |
DISPOSE(f) |
| 15420 |
END PopTFrwtok ; |
| 15421 |
|
| 15422 |
|
| 15423 |
(* |
| 15424 |
PushTFrwtok - Push an item onto the stack in the T (true) position, |
| 15425 |
it is assummed to be a token and its token location is recorded. |
| 15426 |
*) |
| 15427 |
|
| 15428 |
PROCEDURE PushTFrwtok (True, False, rw: WORD; tokno: CARDINAL) ; |
| 15429 |
VAR |
| 15430 |
f: BoolFrame ; |
| 15431 |
BEGIN |
| 15432 |
f := newBoolFrame () ; |
| 15433 |
WITH f^ DO |
| 15434 |
TrueExit := True ; |
| 15435 |
FalseExit := False ; |
| 15436 |
ReadWrite := rw ; |
| 15437 |
tokenno := tokno |
| 15438 |
END ; |
| 15439 |
PushAddress(BoolStack, f) |
| 15440 |
END PushTFrwtok ; |
| 15441 |
|
| 15442 |
|
| 15443 |
(* |
| 15444 |
PushTFDtok - Push True, False, Dim, numbers onto the |
| 15445 |
True/False stack. True and False are assumed to |
| 15446 |
contain Symbols or Ident etc. |
| 15447 |
*) |
| 15448 |
|
| 15449 |
PROCEDURE PushTFDtok (True, False, Dim: WORD; Tok: CARDINAL) ; |
| 15450 |
VAR |
| 15451 |
f: BoolFrame ; |
| 15452 |
BEGIN |
| 15453 |
f := newBoolFrame () ; |
| 15454 |
WITH f^ DO |
| 15455 |
TrueExit := True ; |
| 15456 |
FalseExit := False ; |
| 15457 |
Dimension := Dim ; |
| 15458 |
tokenno := Tok |
| 15459 |
END ; |
| 15460 |
PushAddress (BoolStack, f) |
| 15461 |
END PushTFDtok ; |
| 15462 |
|
| 15463 |
|
| 15464 |
(* |
| 15465 |
PopTFDtok - Pop a True, False, Dim number from the True/False stack. |
| 15466 |
True and False are assumed to contain Symbols or Ident etc. |
| 15467 |
*) |
| 15468 |
|
| 15469 |
PROCEDURE PopTFDtok (VAR True, False, Dim: WORD; VAR Tok: CARDINAL) ; |
| 15470 |
VAR |
| 15471 |
f: BoolFrame ; |
| 15472 |
BEGIN |
| 15473 |
f := PopAddress(BoolStack) ; |
| 15474 |
WITH f^ DO |
| 15475 |
True := TrueExit ; |
| 15476 |
False := FalseExit ; |
| 15477 |
Dim := Dimension ; |
| 15478 |
Tok := tokenno ; |
| 15479 |
Assert(NOT BooleanOp) |
| 15480 |
END ; |
| 15481 |
DISPOSE(f) |
| 15482 |
END PopTFDtok ; |
| 15483 |
|
| 15484 |
|
| 15485 |
(* |
| 15486 |
PushTFDrwtok - Push True, False, Dim, numbers onto the |
| 15487 |
True/False stack. True and False are assumed to |
| 15488 |
contain Symbols or Ident etc. |
| 15489 |
*) |
| 15490 |
|
| 15491 |
PROCEDURE PushTFDrwtok (True, False, Dim, rw: WORD; Tok: CARDINAL) ; |
| 15492 |
VAR |
| 15493 |
f: BoolFrame ; |
| 15494 |
BEGIN |
| 15495 |
f := newBoolFrame () ; |
| 15496 |
WITH f^ DO |
| 15497 |
TrueExit := True ; |
| 15498 |
FalseExit := False ; |
| 15499 |
Dimension := Dim ; |
| 15500 |
ReadWrite := rw ; |
| 15501 |
tokenno := Tok |
| 15502 |
END ; |
| 15503 |
PushAddress (BoolStack, f) |
| 15504 |
END PushTFDrwtok ; |
| 15505 |
|
| 15506 |
|
| 15507 |
(* |
| 15508 |
PushTFrw - Push a True and False numbers onto the True/False stack. |
| 15509 |
True and False are assumed to contain Symbols or Ident etc. |
| 15510 |
It also pushes the higher level symbol which is associated |
| 15511 |
with the True symbol. Eg record variable or array variable. |
| 15512 |
*) |
| 15513 |
|
| 15514 |
PROCEDURE PushTFrw (True, False: WORD; rw: CARDINAL) ; |
| 15515 |
VAR |
| 15516 |
f: BoolFrame ; |
| 15517 |
BEGIN |
| 15518 |
f := newBoolFrame () ; |
| 15519 |
WITH f^ DO |
| 15520 |
TrueExit := True ; |
| 15521 |
FalseExit := False ; |
| 15522 |
ReadWrite := rw |
| 15523 |
END ; |
| 15524 |
PushAddress(BoolStack, f) |
| 15525 |
END PushTFrw ; |
| 15526 |
|
| 15527 |
|
| 15528 |
(* |
| 15529 |
PopTFrw - Pop a True and False number from the True/False stack. |
| 15530 |
True and False are assumed to contain Symbols or Ident etc. |
| 15531 |
*) |
| 15532 |
|
| 15533 |
PROCEDURE PopTFrw (VAR True, False, rw: WORD) ; |
| 15534 |
VAR |
| 15535 |
f: BoolFrame ; |
| 15536 |
BEGIN |
| 15537 |
f := PopAddress(BoolStack) ; |
| 15538 |
WITH f^ DO |
| 15539 |
True := TrueExit ; |
| 15540 |
False := FalseExit ; |
| 15541 |
Assert(NOT BooleanOp) ; |
| 15542 |
rw := ReadWrite |
| 15543 |
END ; |
| 15544 |
DISPOSE(f) |
| 15545 |
END PopTFrw ; |
| 15546 |
|
| 15547 |
|
| 15548 |
(* |
| 15549 |
PushTF - Push a True and False numbers onto the True/False stack. |
| 15550 |
True and False are assumed to contain Symbols or Ident etc. |
| 15551 |
*) |
| 15552 |
|
| 15553 |
PROCEDURE PushTF (True, False: WORD) ; |
| 15554 |
VAR |
| 15555 |
f: BoolFrame ; |
| 15556 |
BEGIN |
| 15557 |
f := newBoolFrame () ; |
| 15558 |
WITH f^ DO |
| 15559 |
TrueExit := True ; |
| 15560 |
FalseExit := False |
| 15561 |
END ; |
| 15562 |
PushAddress(BoolStack, f) |
| 15563 |
END PushTF ; |
| 15564 |
|
| 15565 |
|
| 15566 |
(* |
| 15567 |
PopTF - Pop a True and False number from the True/False stack. |
| 15568 |
True and False are assumed to contain Symbols or Ident etc. |
| 15569 |
*) |
| 15570 |
|
| 15571 |
PROCEDURE PopTF (VAR True, False: WORD) ; |
| 15572 |
VAR |
| 15573 |
f: BoolFrame ; |
| 15574 |
BEGIN |
| 15575 |
f := PopAddress(BoolStack) ; |
| 15576 |
WITH f^ DO |
| 15577 |
True := TrueExit ; |
| 15578 |
False := FalseExit ; |
| 15579 |
Assert(NOT BooleanOp) |
| 15580 |
END ; |
| 15581 |
DISPOSE(f) |
| 15582 |
END PopTF ; |
| 15583 |
|
| 15584 |
|
| 15585 |
(* |
| 15586 |
DupFrame - duplicate the top of stack and push the new frame. |
| 15587 |
*) |
| 15588 |
|
| 15589 |
PROCEDURE DupFrame ; |
| 15590 |
VAR |
| 15591 |
f, newf: BoolFrame ; |
| 15592 |
BEGIN |
| 15593 |
f := PopAddress (BoolStack) ; |
| 15594 |
PushAddress (BoolStack, f) ; |
| 15595 |
newf := newBoolFrame () ; |
| 15596 |
newf^ := f^ ; |
| 15597 |
PushAddress (BoolStack, newf) |
| 15598 |
END DupFrame ; |
| 15599 |
|
| 15600 |
|
| 15601 |
(* |
| 15602 |
newBoolFrame - creates a new BoolFrame with all fields initialised to their defaults. |
| 15603 |
*) |
| 15604 |
|
| 15605 |
PROCEDURE newBoolFrame () : BoolFrame ; |
| 15606 |
VAR |
| 15607 |
f: BoolFrame ; |
| 15608 |
BEGIN |
| 15609 |
NEW (f) ; |
| 15610 |
WITH f^ DO |
| 15611 |
TrueExit := 0 ; |
| 15612 |
FalseExit := 0 ; |
| 15613 |
Unbounded := NulSym ; |
| 15614 |
BooleanOp := FALSE ; |
| 15615 |
Dimension := 0 ; |
| 15616 |
ReadWrite := NulSym ; |
| 15617 |
name := NulSym ; |
| 15618 |
Annotation := NIL ; |
| 15619 |
tokenno := UnknownTokenNo |
| 15620 |
END ; |
| 15621 |
RETURN f |
| 15622 |
END newBoolFrame ; |
| 15623 |
|
| 15624 |
|
| 15625 |
(* |
| 15626 |
PushTtok - Push an item onto the stack in the T (true) position, |
| 15627 |
it is assummed to be a token and its token location is recorded. |
| 15628 |
*) |
| 15629 |
|
| 15630 |
PROCEDURE PushTtok (True: WORD; tokno: CARDINAL) ; |
| 15631 |
VAR |
| 15632 |
f: BoolFrame ; |
| 15633 |
BEGIN |
| 15634 |
(* PrintTokenNo (tokno) ; *) |
| 15635 |
f := newBoolFrame () ; |
| 15636 |
WITH f^ DO |
| 15637 |
TrueExit := True ; |
| 15638 |
tokenno := tokno |
| 15639 |
END ; |
| 15640 |
PushAddress (BoolStack, f) |
| 15641 |
END PushTtok ; |
| 15642 |
|
| 15643 |
|
| 15644 |
(* |
| 15645 |
PushT - Push an item onto the stack in the T (true) position. |
| 15646 |
*) |
| 15647 |
|
| 15648 |
PROCEDURE PushT (True: WORD) ; |
| 15649 |
VAR |
| 15650 |
f: BoolFrame ; |
| 15651 |
BEGIN |
| 15652 |
f := newBoolFrame () ; |
| 15653 |
WITH f^ DO |
| 15654 |
TrueExit := True |
| 15655 |
END ; |
| 15656 |
PushAddress (BoolStack, f) |
| 15657 |
END PushT ; |
| 15658 |
|
| 15659 |
|
| 15660 |
(* |
| 15661 |
PopT - Pops the T value from the stack. |
| 15662 |
*) |
| 15663 |
|
| 15664 |
PROCEDURE PopT (VAR True: WORD) ; |
| 15665 |
VAR |
| 15666 |
f: BoolFrame ; |
| 15667 |
BEGIN |
| 15668 |
f := PopAddress (BoolStack) ; |
| 15669 |
WITH f^ DO |
| 15670 |
True := TrueExit ; |
| 15671 |
Assert(NOT BooleanOp) |
| 15672 |
END ; |
| 15673 |
DISPOSE(f) |
| 15674 |
END PopT ; |
| 15675 |
|
| 15676 |
|
| 15677 |
(* |
| 15678 |
PopTtok - Pops the T value from the stack and token position. |
| 15679 |
*) |
| 15680 |
|
| 15681 |
PROCEDURE PopTtok (VAR True: WORD; VAR tok: CARDINAL) ; |
| 15682 |
VAR |
| 15683 |
f: BoolFrame ; |
| 15684 |
BEGIN |
| 15685 |
f := PopAddress(BoolStack) ; |
| 15686 |
WITH f^ DO |
| 15687 |
True := TrueExit ; |
| 15688 |
tok := tokenno ; |
| 15689 |
Assert(NOT BooleanOp) |
| 15690 |
END ; |
| 15691 |
DISPOSE(f) |
| 15692 |
END PopTtok ; |
| 15693 |
|
| 15694 |
|
| 15695 |
(* |
| 15696 |
PushTrw - Push an item onto the True/False stack. The False value will be zero. |
| 15697 |
*) |
| 15698 |
|
| 15699 |
(* |
| 15700 |
PROCEDURE PushTrw (True: WORD; rw: WORD) ; |
| 15701 |
VAR |
| 15702 |
f: BoolFrame ; |
| 15703 |
BEGIN |
| 15704 |
f := newBoolFrame () ; |
| 15705 |
WITH f^ DO |
| 15706 |
TrueExit := True ; |
| 15707 |
ReadWrite := rw |
| 15708 |
END ; |
| 15709 |
PushAddress(BoolStack, f) |
| 15710 |
END PushTrw ; |
| 15711 |
*) |
| 15712 |
|
| 15713 |
|
| 15714 |
(* |
| 15715 |
PushTrwtok - Push an item onto the True/False stack. The False value will be zero. |
| 15716 |
*) |
| 15717 |
|
| 15718 |
PROCEDURE PushTrwtok (True: WORD; rw: WORD; tok: CARDINAL) ; |
| 15719 |
VAR |
| 15720 |
f: BoolFrame ; |
| 15721 |
BEGIN |
| 15722 |
f := newBoolFrame () ; |
| 15723 |
WITH f^ DO |
| 15724 |
TrueExit := True ; |
| 15725 |
ReadWrite := rw ; |
| 15726 |
tokenno := tok |
| 15727 |
END ; |
| 15728 |
PushAddress(BoolStack, f) |
| 15729 |
END PushTrwtok ; |
| 15730 |
|
| 15731 |
|
| 15732 |
(* |
| 15733 |
PopTrw - Pop a True field and rw symbol from the stack. |
| 15734 |
*) |
| 15735 |
|
| 15736 |
PROCEDURE PopTrw (VAR True, rw: WORD) ; |
| 15737 |
VAR |
| 15738 |
f: BoolFrame ; |
| 15739 |
BEGIN |
| 15740 |
f := PopAddress(BoolStack) ; |
| 15741 |
WITH f^ DO |
| 15742 |
True := TrueExit ; |
| 15743 |
Assert(NOT BooleanOp) ; |
| 15744 |
rw := ReadWrite |
| 15745 |
END ; |
| 15746 |
DISPOSE(f) |
| 15747 |
END PopTrw ; |
| 15748 |
|
| 15749 |
|
| 15750 |
(* |
| 15751 |
PopTrwtok - Pop a True field and rw symbol from the stack. |
| 15752 |
*) |
| 15753 |
|
| 15754 |
PROCEDURE PopTrwtok (VAR True, rw: WORD; VAR tok: CARDINAL) ; |
| 15755 |
VAR |
| 15756 |
f: BoolFrame ; |
| 15757 |
BEGIN |
| 15758 |
f := PopAddress(BoolStack) ; |
| 15759 |
WITH f^ DO |
| 15760 |
True := TrueExit ; |
| 15761 |
Assert(NOT BooleanOp) ; |
| 15762 |
rw := ReadWrite ; |
| 15763 |
tok := tokenno |
| 15764 |
END ; |
| 15765 |
DISPOSE(f) |
| 15766 |
END PopTrwtok ; |
| 15767 |
|
| 15768 |
|
| 15769 |
(* |
| 15770 |
PushTFn - Push a True and False numbers onto the True/False stack. |
| 15771 |
True and False are assumed to contain Symbols or Ident etc. |
| 15772 |
*) |
| 15773 |
|
| 15774 |
PROCEDURE PushTFn (True, False, n: WORD) ; |
| 15775 |
VAR |
| 15776 |
f: BoolFrame ; |
| 15777 |
BEGIN |
| 15778 |
f := newBoolFrame () ; |
| 15779 |
WITH f^ DO |
| 15780 |
TrueExit := True ; |
| 15781 |
FalseExit := False ; |
| 15782 |
name := n |
| 15783 |
END ; |
| 15784 |
PushAddress(BoolStack, f) |
| 15785 |
END PushTFn ; |
| 15786 |
|
| 15787 |
|
| 15788 |
(* |
| 15789 |
PushTFntok - Push a True and False numbers onto the True/False stack. |
| 15790 |
True and False are assumed to contain Symbols or Ident etc. |
| 15791 |
*) |
| 15792 |
|
| 15793 |
PROCEDURE PushTFntok (True, False, n: WORD; tokno: CARDINAL) ; |
| 15794 |
VAR |
| 15795 |
f: BoolFrame ; |
| 15796 |
BEGIN |
| 15797 |
f := newBoolFrame () ; |
| 15798 |
WITH f^ DO |
| 15799 |
TrueExit := True ; |
| 15800 |
FalseExit := False ; |
| 15801 |
name := n ; |
| 15802 |
tokenno := tokno |
| 15803 |
END ; |
| 15804 |
PushAddress (BoolStack, f) |
| 15805 |
END PushTFntok ; |
| 15806 |
|
| 15807 |
|
| 15808 |
(* |
| 15809 |
PopTFn - Pop a True and False number from the True/False stack. |
| 15810 |
True and False are assumed to contain Symbols or Ident etc. |
| 15811 |
*) |
| 15812 |
|
| 15813 |
PROCEDURE PopTFn (VAR True, False, n: WORD) ; |
| 15814 |
VAR |
| 15815 |
f: BoolFrame ; |
| 15816 |
BEGIN |
| 15817 |
f := PopAddress(BoolStack) ; |
| 15818 |
WITH f^ DO |
| 15819 |
True := TrueExit ; |
| 15820 |
False := FalseExit ; |
| 15821 |
n := name ; |
| 15822 |
Assert(NOT BooleanOp) |
| 15823 |
END ; |
| 15824 |
DISPOSE(f) |
| 15825 |
END PopTFn ; |
| 15826 |
|
| 15827 |
|
| 15828 |
(* |
| 15829 |
PopNothing - pops the top element on the boolean stack. |
| 15830 |
*) |
| 15831 |
|
| 15832 |
PROCEDURE PopNothing ; |
| 15833 |
VAR |
| 15834 |
f: BoolFrame ; |
| 15835 |
BEGIN |
| 15836 |
f := PopAddress(BoolStack) ; |
| 15837 |
DISPOSE(f) |
| 15838 |
END PopNothing ; |
| 15839 |
|
| 15840 |
|
| 15841 |
(* |
| 15842 |
PopN - pops multiple elements from the BoolStack. |
| 15843 |
*) |
| 15844 |
|
| 15845 |
PROCEDURE PopN (n: CARDINAL) ; |
| 15846 |
BEGIN |
| 15847 |
WHILE n>0 DO |
| 15848 |
PopNothing ; |
| 15849 |
DEC(n) |
| 15850 |
END |
| 15851 |
END PopN ; |
| 15852 |
|
| 15853 |
|
| 15854 |
(* |
| 15855 |
PushTFtok - Push an item onto the stack in the T (true) position, |
| 15856 |
it is assummed to be a token and its token location is recorded. |
| 15857 |
*) |
| 15858 |
|
| 15859 |
PROCEDURE PushTFtok (True, False: WORD; tokno: CARDINAL) ; |
| 15860 |
VAR |
| 15861 |
f: BoolFrame ; |
| 15862 |
BEGIN |
| 15863 |
f := newBoolFrame () ; |
| 15864 |
WITH f^ DO |
| 15865 |
TrueExit := True ; |
| 15866 |
FalseExit := False ; |
| 15867 |
tokenno := tokno |
| 15868 |
END ; |
| 15869 |
PushAddress(BoolStack, f) |
| 15870 |
END PushTFtok ; |
| 15871 |
|
| 15872 |
|
| 15873 |
(* |
| 15874 |
PopTFtok - Pop T/F/tok from the stack. |
| 15875 |
*) |
| 15876 |
|
| 15877 |
PROCEDURE PopTFtok (VAR True, False: WORD; VAR tokno: CARDINAL) ; |
| 15878 |
VAR |
| 15879 |
f: BoolFrame ; |
| 15880 |
BEGIN |
| 15881 |
f := PopAddress(BoolStack) ; |
| 15882 |
WITH f^ DO |
| 15883 |
True := TrueExit ; |
| 15884 |
False := FalseExit ; |
| 15885 |
tokno := tokenno |
| 15886 |
END |
| 15887 |
END PopTFtok ; |
| 15888 |
|
| 15889 |
|
| 15890 |
(* |
| 15891 |
PushTFAtok - Push T/F/A/tok to the stack. |
| 15892 |
*) |
| 15893 |
|
| 15894 |
PROCEDURE PushTFAtok (True, False, Array: WORD; tokno: CARDINAL) ; |
| 15895 |
VAR |
| 15896 |
f: BoolFrame ; |
| 15897 |
BEGIN |
| 15898 |
f := newBoolFrame () ; |
| 15899 |
WITH f^ DO |
| 15900 |
TrueExit := True ; |
| 15901 |
FalseExit := False ; |
| 15902 |
Unbounded := Array ; |
| 15903 |
tokenno := tokno |
| 15904 |
END ; |
| 15905 |
PushAddress(BoolStack, f) |
| 15906 |
END PushTFAtok ; |
| 15907 |
|
| 15908 |
|
| 15909 |
(* |
| 15910 |
Top - returns the no of items held in the stack. |
| 15911 |
*) |
| 15912 |
|
| 15913 |
PROCEDURE Top () : CARDINAL ; |
| 15914 |
BEGIN |
| 15915 |
RETURN( NoOfItemsInStackAddress(BoolStack) ) |
| 15916 |
END Top ; |
| 15917 |
|
| 15918 |
|
| 15919 |
(* |
| 15920 |
PushAutoOn - push the auto flag and then set it to TRUE. |
| 15921 |
Any call to ident in the parser will result in the token being pushed. |
| 15922 |
*) |
| 15923 |
|
| 15924 |
PROCEDURE PushAutoOn ; |
| 15925 |
BEGIN |
| 15926 |
PushWord(AutoStack, IsAutoOn) ; |
| 15927 |
IsAutoOn := TRUE |
| 15928 |
END PushAutoOn ; |
| 15929 |
|
| 15930 |
|
| 15931 |
(* |
| 15932 |
PushAutoOff - push the auto flag and then set it to FALSE. |
| 15933 |
*) |
| 15934 |
|
| 15935 |
PROCEDURE PushAutoOff ; |
| 15936 |
BEGIN |
| 15937 |
PushWord(AutoStack, IsAutoOn) ; |
| 15938 |
IsAutoOn := FALSE |
| 15939 |
END PushAutoOff ; |
| 15940 |
|
| 15941 |
|
| 15942 |
(* |
| 15943 |
IsAutoPushOn - returns the value of the current Auto ident push flag. |
| 15944 |
*) |
| 15945 |
|
| 15946 |
PROCEDURE IsAutoPushOn () : BOOLEAN ; |
| 15947 |
BEGIN |
| 15948 |
RETURN( IsAutoOn ) |
| 15949 |
END IsAutoPushOn ; |
| 15950 |
|
| 15951 |
|
| 15952 |
(* |
| 15953 |
PopAuto - restores the previous value of the Auto flag. |
| 15954 |
*) |
| 15955 |
|
| 15956 |
PROCEDURE PopAuto ; |
| 15957 |
BEGIN |
| 15958 |
IsAutoOn := PopWord(AutoStack) |
| 15959 |
END PopAuto ; |
| 15960 |
|
| 15961 |
|
| 15962 |
(* |
| 15963 |
PushInConstExpression - push the InConstExpression flag and then set it to TRUE. |
| 15964 |
*) |
| 15965 |
|
| 15966 |
PROCEDURE PushInConstExpression ; |
| 15967 |
BEGIN |
| 15968 |
PushWord(ConstExprStack, InConstExpression) ; |
| 15969 |
InConstExpression := TRUE |
| 15970 |
END PushInConstExpression ; |
| 15971 |
|
| 15972 |
|
| 15973 |
(* |
| 15974 |
PopInConstExpression - restores the previous value of the InConstExpression. |
| 15975 |
*) |
| 15976 |
|
| 15977 |
PROCEDURE PopInConstExpression ; |
| 15978 |
BEGIN |
| 15979 |
InConstExpression := PopWord(ConstExprStack) |
| 15980 |
END PopInConstExpression ; |
| 15981 |
|
| 15982 |
|
| 15983 |
(* |
| 15984 |
IsInConstExpression - returns the value of the InConstExpression. |
| 15985 |
*) |
| 15986 |
|
| 15987 |
PROCEDURE IsInConstExpression () : BOOLEAN ; |
| 15988 |
BEGIN |
| 15989 |
RETURN( InConstExpression ) |
| 15990 |
END IsInConstExpression ; |
| 15991 |
|
| 15992 |
|
| 15993 |
(* |
| 15994 |
PushInConstParameters - push the InConstParameters flag and then set it to TRUE. |
| 15995 |
*) |
| 15996 |
|
| 15997 |
PROCEDURE PushInConstParameters ; |
| 15998 |
BEGIN |
| 15999 |
PushWord (ConstParamStack, InConstParameters) ; |
| 16000 |
InConstParameters := TRUE |
| 16001 |
END PushInConstParameters ; |
| 16002 |
|
| 16003 |
|
| 16004 |
(* |
| 16005 |
PopInConstParameters - restores the previous value of the InConstParameters. |
| 16006 |
*) |
| 16007 |
|
| 16008 |
PROCEDURE PopInConstParameters ; |
| 16009 |
BEGIN |
| 16010 |
InConstParameters := PopWord(ConstParamStack) |
| 16011 |
END PopInConstParameters ; |
| 16012 |
|
| 16013 |
|
| 16014 |
(* |
| 16015 |
IsInConstParameters - returns the value of the InConstParameters. |
| 16016 |
*) |
| 16017 |
|
| 16018 |
PROCEDURE IsInConstParameters () : BOOLEAN ; |
| 16019 |
BEGIN |
| 16020 |
RETURN( InConstParameters ) |
| 16021 |
END IsInConstParameters ; |
| 16022 |
|
| 16023 |
|
| 16024 |
(* |
| 16025 |
MustCheckOverflow - returns TRUE if the quadruple should test for overflow. |
| 16026 |
*) |
| 16027 |
|
| 16028 |
PROCEDURE MustCheckOverflow (q: CARDINAL) : BOOLEAN ; |
| 16029 |
VAR |
| 16030 |
f: QuadFrame ; |
| 16031 |
BEGIN |
| 16032 |
f := GetQF(q) ; |
| 16033 |
RETURN( f^.CheckOverflow ) |
| 16034 |
END MustCheckOverflow ; |
| 16035 |
|
| 16036 |
|
| 16037 |
(* |
| 16038 |
StressStack - |
| 16039 |
*) |
| 16040 |
|
| 16041 |
(* |
| 16042 |
PROCEDURE StressStack ; |
| 16043 |
CONST |
| 16044 |
Maxtries = 1000 ; |
| 16045 |
VAR |
| 16046 |
n, i, j: CARDINAL ; |
| 16047 |
BEGIN |
| 16048 |
PushT(1) ; |
| 16049 |
PopT(i) ; |
| 16050 |
Assert(i=1) ; |
| 16051 |
FOR n := 1 TO Maxtries DO |
| 16052 |
FOR i := n TO 1 BY -1 DO |
| 16053 |
PushT(i) |
| 16054 |
END ; |
| 16055 |
FOR i := n TO 1 BY -1 DO |
| 16056 |
Assert(OperandT(i)=i) |
| 16057 |
END ; |
| 16058 |
FOR i := 1 TO n DO |
| 16059 |
Assert(OperandT(i)=i) |
| 16060 |
END ; |
| 16061 |
FOR i := 1 TO n BY 10 DO |
| 16062 |
Assert(OperandT(i)=i) |
| 16063 |
END ; |
| 16064 |
IF (n>1) AND (n MOD 2 = 0) |
| 16065 |
THEN |
| 16066 |
FOR i := 1 TO n DIV 2 DO |
| 16067 |
PopT(j) ; |
| 16068 |
Assert(j=i) |
| 16069 |
END ; |
| 16070 |
FOR i := n DIV 2 TO 1 BY -1 DO |
| 16071 |
PushT(i) |
| 16072 |
END |
| 16073 |
END ; |
| 16074 |
FOR i := 1 TO n DO |
| 16075 |
PopT(j) ; |
| 16076 |
Assert(j=i) |
| 16077 |
END |
| 16078 |
END |
| 16079 |
END StressStack ; |
| 16080 |
*) |
| 16081 |
|
| 16082 |
|
| 16083 |
(* |
| 16084 |
gdbhook - a debugger convenience hook. |
| 16085 |
*) |
| 16086 |
|
| 16087 |
PROCEDURE gdbhook ; |
| 16088 |
END gdbhook ; |
| 16089 |
|
| 16090 |
|
| 16091 |
(* |
| 16092 |
BreakWhenQuadCreated - to be called interactively by gdb. |
| 16093 |
*) |
| 16094 |
|
| 16095 |
PROCEDURE BreakWhenQuadCreated (quad: CARDINAL) ; |
| 16096 |
BEGIN |
| 16097 |
BreakQuad := quad |
| 16098 |
END BreakWhenQuadCreated ; |
| 16099 |
|
| 16100 |
|
| 16101 |
(* |
| 16102 |
CheckBreak - if quad = BreakQuad then call gdbhook. |
| 16103 |
*) |
| 16104 |
|
| 16105 |
PROCEDURE CheckBreak (quad: CARDINAL) ; |
| 16106 |
BEGIN |
| 16107 |
IF quad = BreakQuad |
| 16108 |
THEN |
| 16109 |
gdbhook |
| 16110 |
END |
| 16111 |
END CheckBreak ; |
| 16112 |
|
| 16113 |
|
| 16114 |
(* |
| 16115 |
Init - initialize the M2Quads module, all the stacks, all the lists |
| 16116 |
and the quads list. |
| 16117 |
*) |
| 16118 |
|
| 16119 |
PROCEDURE Init ; |
| 16120 |
BEGIN |
| 16121 |
BreakWhenQuadCreated (0) ; (* Disable the intereactive quad watch. *) |
| 16122 |
(* To examine the quad table when a quad is created run cc1gm2 from gdb |
| 16123 |
and set a break point on gdbhook. |
| 16124 |
(gdb) break gdbhook |
| 16125 |
(gdb) run |
| 16126 |
Now below interactively call BreakWhenQuadCreated with the quad |
| 16127 |
under investigation. *) |
| 16128 |
gdbhook ; |
| 16129 |
(* Now is the time to interactively call gdb, for example: |
| 16130 |
(gdb) print BreakWhenQuadCreated (1234) |
| 16131 |
(gdb) cont |
| 16132 |
and you will arrive at gdbhook when this quad is created. *) |
| 16133 |
LogicalOrTok := MakeKey('_LOR') ; |
| 16134 |
LogicalAndTok := MakeKey('_LAND') ; |
| 16135 |
LogicalXorTok := MakeKey('_LXOR') ; |
| 16136 |
LogicalDifferenceTok := MakeKey('_LDIFF') ; |
| 16137 |
ArithPlusTok := MakeKey ('_ARITH_+') ; |
| 16138 |
QuadArray := InitIndexTuned (1, 1024*1024 DIV 16, 16) ; |
| 16139 |
FreeList := 1 ; |
| 16140 |
NewQuad(NextQuad) ; |
| 16141 |
Assert(NextQuad=1) ; |
| 16142 |
BoolStack := InitStackAddress() ; |
| 16143 |
ExitStack := InitStackWord() ; |
| 16144 |
RepeatStack := InitStackWord() ; |
| 16145 |
WhileStack := InitStackWord() ; |
| 16146 |
ForStack := InitStackWord() ; |
| 16147 |
WithStack := InitStackAddress() ; |
| 16148 |
ReturnStack := InitStackWord() ; |
| 16149 |
LineStack := InitStackAddress() ; |
| 16150 |
PriorityStack := InitStackWord() ; |
| 16151 |
TryStack := InitStackWord() ; |
| 16152 |
CatchStack := InitStackWord() ; |
| 16153 |
ExceptStack := InitStackWord() ; |
| 16154 |
ConstructorStack := InitStackAddress() ; |
| 16155 |
ConstParamStack := InitStackWord () ; |
| 16156 |
ConstExprStack := InitStackWord () ; |
| 16157 |
(* StressStack ; *) |
| 16158 |
SuppressWith := FALSE ; |
| 16159 |
Head := 1 ; |
| 16160 |
LastQuadNo := 0 ; |
| 16161 |
MustNotCheckBounds := FALSE ; |
| 16162 |
InitQuad := 0 ; |
| 16163 |
GrowInitialization := 0 ; |
| 16164 |
ForInfo := InitIndex (1) ; |
| 16165 |
QuadrupleGeneration := TRUE ; |
| 16166 |
BuildingHigh := FALSE ; |
| 16167 |
BuildingSize := FALSE ; |
| 16168 |
AutoStack := InitStackWord() ; |
| 16169 |
IsAutoOn := TRUE ; |
| 16170 |
InConstExpression := FALSE ; |
| 16171 |
InConstParameters := FALSE ; |
| 16172 |
FreeLineList := NIL ; |
| 16173 |
InitList(VarientFields) ; |
| 16174 |
VarientFieldNo := 0 ; |
| 16175 |
NoOfQuads := 0 ; |
| 16176 |
END Init ; |
| 16177 |
|
| 16178 |
|
| 16179 |
BEGIN |
| 16180 |
Init |
| 16181 |
END M2Quads. |