DIRECTORY BasicTime: TYPE USING [], Alloc: TYPE USING [ Handle, Selector, TableInfo, Chunkify, Create, Destroy, Failure, Reset], CBinary: TYPE USING [DebugTab, ErrorTab, MesaTab], CompilerOps: TYPE USING [LetterSwitches, StreamId, Transaction], CompilerUtil: TYPE USING [ TableId, InstallParseTables, PrefillSymbols, P1Unit, P2Unit, P3Unit, P3Postlude, P4Unit, P5module, EndObjectFile, PrintBodies, PrintSymbols, PrintTree, StartObjectFile, TableOut], ComData: TYPE USING [ bcdSeg, codeSeg, compilerVersion, globalFrameSize, interface, linkCount, matched, nErrors, nWarnings, objectBytes, objectStamp, objectVersion, ownSymbols, pattern, source, sourceTokens, symSeg, switches, table, textIndex], Copier: TYPE USING [FileInit, FileReset], DebuggerSwap: TYPE USING [CallDebugger], FS: TYPE USING [StreamFromOpenFile, nullOpenFile], FileParmOps: TYPE USING [AcquireOutput, ReleaseOutput], IO: TYPE USING [Close, Flush, PutChar, Put, PutRope, rope, STREAM, time, Error], LiteralOps: TYPE USING [Initialize, Finalize], Loader: TYPE USING [BCDBuildTime], Log: TYPE USING [Error], OSMiscOps: TYPE USING [ GenerateUniqueId, MergeStamps, StampToTime, TimeToStamp], PrincOpsUtils: TYPE USING [Codebase], Rope: TYPE USING [ROPE], RuntimeError: TYPE USING [UNCAUGHT], SymLiteralOps: TYPE USING [Finalize, Initialize], SymbolPack: TYPE, SymbolOps: TYPE USING [Finalize, Initialize], SymbolSegment: TYPE USING [Tables, treeType], TimeStamp: TYPE USING [Stamp], Tree: TYPE USING [Link], TreeOps: TYPE USING [Finalize, Initialize, PopTree, Reset]; Sequencer: MONITOR IMPORTS Alloc, CBinary, CompilerUtil, Copier, DebuggerSwap, FS, FileParmOps, IO, Log, LiteralOps, Loader, OSMiscOps, PrincOpsUtils, RuntimeError, SymLiteralOps, SymbolOps, TreeOps, ownSymbols: SymbolPack, dataPtr: ComData EXPORTS CompilerOps, CompilerUtil = { table: Alloc.Handle _ NIL; StreamId: TYPE = CompilerOps.StreamId; TransactionPtr: TYPE = REF CompilerOps.Transaction; getStream: PROC [StreamId] RETURNS [IO.STREAM]; streamInfo: ARRAY StreamId[$source .. $log] OF RECORD [ access: {read, write}, stream: IO.STREAM, status: RECORD [count: NAT, open: BOOL]]; AcquireStream: PUBLIC PROC [id: StreamId] RETURNS [stream: IO.STREAM] = { IF streamInfo[id].stream = NIL THEN { streamInfo[id].stream _ getStream[id]; streamInfo[id].status _ [count:0, open:TRUE]}; stream _ streamInfo[id].stream; IF streamInfo[id].status = [count: 0, open: FALSE] THEN streamInfo[id].status.open _ TRUE; streamInfo[id].status.count _ streamInfo[id].status.count + 1}; ReleaseStream: PUBLIC PROC [id: StreamId] = { streamInfo[id].status.count _ streamInfo[id].status.count - 1; IF streamInfo[id].status.count = 0 THEN { IF streamInfo[id].access = $write THEN streamInfo[id].stream.Flush[]; streamInfo[id].status.open _ FALSE}}; tableBase: ARRAY CompilerUtil.TableId [$error..$debug] OF LONG POINTER; AcquireTable: PUBLIC PROC [id: CompilerUtil.TableId] RETURNS [LONG POINTER] = { RETURN [tableBase[id]]}; ReleaseTable: PUBLIC PROC [id: CompilerUtil.TableId] = {}; DefaultSwitches: PUBLIC PROC RETURNS [CompilerOps.LetterSwitches] = { RETURN [[ TRUE , -- A Address fault for NIL checks TRUE , -- B Bounds checking TRUE , -- C compile for Cedar (special FORK) FALSE, -- D call Debugger on compiler error (FALSE => just log error) TRUE , -- E fixed (big Eval stack) TRUE , -- F Floating point microcode TRUE , -- G TRUE => loG goes to compiler.log, FALSE => use foo.errlog FALSE, -- H unused FALSE, -- I unused FALSE, -- J cross-Jumping optimization FALSE, -- K unused TRUE , -- L allocate space for code Links TRUE , -- M reference counting Microcode TRUE , -- N Nil pointer checking FALSE, -- O unused FALSE, -- P Pause after compilation with errors FALSE, -- Q unused FALSE, -- R unused TRUE , -- S Sort (by static frequency) global vars & entry indexes FALSE, -- T unused FALSE, -- U uninitialized variable checking FALSE, -- V unused TRUE , -- W log Warning messages FALSE, -- X unused FALSE, -- Y complain about KFCB FALSE -- Z unused ]]}; CompilerVersion: PUBLIC PROC RETURNS [TimeStamp.Stamp] = { RETURN [dataPtr.compilerVersion]}; AppendHerald: PUBLIC PROC [s: IO.STREAM] = { s.Put[IO.rope["Cedar 5.0 Compiler of "], IO.time[Loader.BCDBuildTime[]]]}; pass: CHARACTER ['1..'5]; ExtendedTables: TYPE = Alloc.Selector[SymbolSegment.Tables.FIRST .. SymbolSegment.Tables.LAST+1]; Initialize: PROC = { weights: ARRAY ExtendedTables OF Alloc.TableInfo _ [ [30], [20], [4], [4], [4], [2], [4], [1], [2], [1], [2], [2], [20]]; -- empirical IF table = NIL THEN { table _ Alloc.Create[weights: DESCRIPTOR[weights]]; table.Chunkify[SymbolSegment.treeType]; table.Chunkify[SymbolSegment.Tables.LAST+1]} -- codeType ELSE table.Reset[]; SymbolOps.Initialize[table, NIL]; LiteralOps.Initialize[table]; TreeOps.Initialize[table]}; Finalize: PROC [parms: TransactionPtr, ownedObject: BOOL] = { parms.objectVersion _ dataPtr.objectVersion; parms.interface _ dataPtr.interface; parms.matched _ dataPtr.matched AND (dataPtr.nErrors = 0); parms.sourceTokens _ dataPtr.sourceTokens; parms.nErrors _ dataPtr.nErrors; parms.nWarnings _ dataPtr.nWarnings; parms.objectBytes _ dataPtr.objectBytes; parms.objectFrameSize _ dataPtr.globalFrameSize; parms.linkCount _ dataPtr.linkCount; parms.bcdPages _ [base: dataPtr.bcdSeg.base, pages: dataPtr.bcdSeg.pages]; parms.codePages _ [base: dataPtr.codeSeg.base, pages: dataPtr.codeSeg.pages]; parms.symbolPages _ [base: dataPtr.symSeg.base, pages: dataPtr.symSeg.pages]; CompilerUtil.EndObjectFile[dataPtr.nErrors=0]; IF streamInfo[$object].stream # NIL THEN { IO.Close[streamInfo[$object].stream ! IO.Error => CONTINUE]; streamInfo[$object].stream _ NIL}; IF ownedObject THEN { IF parms.objectFile = FS.nullOpenFile THEN DebuggerSwap.CallDebugger["Compiler bug: please call Paul Rovner"]; FileParmOps.ReleaseOutput[parms.objectFile]; }; TreeOps.Finalize[]; LiteralOps.Finalize[]; SymbolOps.Finalize[]; table.Reset[]}; Debug: PROC [tree, symbols: PROC [Alloc.Handle]] = { tree[table]; symbols[table]}; Punt: PUBLIC ERROR = CODE; started: BOOL _ FALSE; Start: PUBLIC ENTRY PROC = { ENABLE UNWIND => NULL; IF started AND table # NIL THEN Alloc.Destroy[table]; table _ NIL; started _ TRUE}; Stop: PUBLIC ENTRY PROC = { ENABLE UNWIND => NULL; IF started THEN { IF table # NIL THEN {Alloc.Destroy[table]; table _ NIL}; started _ FALSE}}; DoTransaction: PUBLIC ENTRY PROC [parms: TransactionPtr] = { ENABLE UNWIND => NULL; root: Tree.Link; debug: BOOL; nParseErrors: CARDINAL; parsed, aborted: BOOL; ownedObject: BOOL _ FALSE; PrintTreeRoot: PROC [table: Alloc.Handle] = {CompilerUtil.PrintTree[table, root]}; PrintSymbols: PROC [table: Alloc.Handle] = { CompilerUtil.PrintSymbols[table, dataPtr.interface]}; IF ~started THEN RETURN WITH ERROR Punt[]; getStream _ parms.getStream; dataPtr.source _ parms.source; dataPtr.switches _ parms.switches; dataPtr.matched _ parms.op = replace; dataPtr.pattern _ parms.pattern; debug _ dataPtr.switches['d]; dataPtr.switches['d] _ FALSE; dataPtr.objectVersion _ OSMiscOps.GenerateUniqueId[]; dataPtr.objectStamp _ OSMiscOps.TimeToStamp[dataPtr.source.version]; dataPtr.objectStamp _ OSMiscOps.MergeStamps[ dataPtr.objectStamp, OSMiscOps.TimeToStamp[[0, 0, LOOPHOLE[dataPtr.switches]]]]; dataPtr.objectStamp _ OSMiscOps.MergeStamps[ dataPtr.objectStamp, OSMiscOps.TimeToStamp[dataPtr.compilerVersion]]; dataPtr.nErrors _ dataPtr.nWarnings _ 0; aborted _ FALSE; streamInfo[$source] _ [access: $read, stream: parms.sourceStream, status: [count: 0, open: FALSE]]; streamInfo[$object] _ streamInfo[$log] _ [access: $write, stream: NIL, status: [count: 0, open: FALSE]]; Initialize[]; { ENABLE { ABORTED => NULL; UNWIND => Finalize[parms, ownedObject]; Alloc.Failure => {IF ~debug THEN GOTO storageFull}; RuntimeError.UNCAUGHT => IF ~debug THEN GOTO uncaughtSignal; }; dataPtr.table _ table; CompilerUtil.PrefillSymbols[]; dataPtr.textIndex _ 0; IF parms.startPass # NIL AND ~parms.startPass[1] THEN GOTO cancel; pass _ '1; parsed _ CompilerUtil.P1Unit[]; nParseErrors _ dataPtr.nErrors; IF ~parsed THEN GOTO failed; root _ TreeOps.PopTree[]; TreeOps.Reset[]; IF parms.debugPass <= 1 THEN Debug[PrintTreeRoot, PrintSymbols]; IF parms.startPass # NIL AND ~parms.startPass[2] THEN GOTO cancel; pass _ '2; root _ CompilerUtil.P2Unit[root]; IF parms.debugPass <= 2 THEN Debug[PrintTreeRoot, PrintSymbols]; IF parms.startPass # NIL AND ~parms.startPass[3] THEN GOTO cancel; SymLiteralOps.Initialize[table]; { ENABLE UNWIND => SymLiteralOps.Finalize[]; Copier.FileInit[[dataPtr.objectVersion, parms.objectName], table, parms.fileParms]; { ENABLE UNWIND => Copier.FileReset[]; BEGIN ENABLE Alloc.Failure => {Copier.FileReset[]; SymLiteralOps.Finalize[]; GOTO storageFull}; pass _ '3; root _ CompilerUtil.P3Unit[root]; CompilerUtil.P3Postlude[dataPtr.nErrors <= nParseErrors]; IF parms.debugPass <= 3 THEN Debug[PrintTreeRoot, PrintSymbols]; IF dataPtr.nErrors > nParseErrors THEN GOTO deleteFiles; dataPtr.objectVersion _ OSMiscOps.StampToTime[dataPtr.objectStamp]; parms.fileParms.Forget[[dataPtr.objectVersion, parms.objectName]]; IF parms.objectFile # FS.nullOpenFile THEN DebuggerSwap.CallDebugger["Compiler bug: please call Paul Rovner"]; parms.objectFile _ FileParmOps.AcquireOutput[parms.objectName]; ownedObject _ TRUE; IF parms.objectFile = FS.nullOpenFile THEN DebuggerSwap.CallDebugger["Compiler bug: please call Paul Rovner"]; streamInfo[$object].stream _ FS.StreamFromOpenFile[openFile: parms.objectFile, accessRights: $write]; IF parms.startPass # NIL AND ~parms.startPass[4] THEN {Copier.FileReset[]; SymLiteralOps.Finalize[]; GOTO cancel}; pass _ '4; CompilerUtil.StartObjectFile[AcquireStream[$object]]; CompilerUtil.P4Unit[root]; IF parms.debugPass <= 4 THEN Debug[CompilerUtil.PrintBodies, PrintSymbols]; EXITS deleteFiles => NULL; END; }; -- end ENABLE UNWIND => Copier.FileReset[]; Copier.FileReset[]; IF dataPtr.nErrors # 0 THEN {SymLiteralOps.Finalize[]; GOTO failed}; IF ~dataPtr.interface THEN { IF parms.startPass # NIL AND ~parms.startPass[5] THEN {SymLiteralOps.Finalize[]; GOTO cancel}; pass _ '5; CompilerUtil.P5module[]; }; }; -- end ENABLE UNWIND => SymLiteralOps.Finalize[]; SymLiteralOps.Finalize[]; IF parms.startPass # NIL AND ~parms.startPass[6] THEN GOTO cancel; CompilerUtil.TableOut[table]; IF dataPtr.nErrors # 0 THEN aborted _ TRUE; EXITS failed => aborted _ TRUE; cancel => {Log.Error[aborted]; aborted _ TRUE}; uncaughtSignal => { errorStream: IO.STREAM = AcquireStream[$log]; aborted _ TRUE; Log.Error[compilerError]; IO.PutRope[errorStream, "in Pass "]; IO.PutChar[errorStream, pass]; IO.PutChar[errorStream, '\n]; ReleaseStream[$log]; Finalize[parms, ownedObject]; RETURN WITH ERROR Punt[]; }; storageFull => { errorStream: IO.STREAM = AcquireStream[$log]; aborted _ TRUE; dataPtr.nErrors _ dataPtr.nErrors+1; IO.PutRope[errorStream, "\nStorage "]; IO.PutRope[errorStream, "overflow"]; IO.PutRope[errorStream, " in Pass "]; IO.PutChar[errorStream, pass]; IO.PutChar[errorStream, '\n]; ReleaseStream[$log]; }; }; -- end ENABLE UNWIND => Finalize[parms, ownedObject]; etc. Finalize[parms, ownedObject]; }; -- end DoTransaction START dataPtr; -- initialize STRING variables, etc. START ownSymbols; dataPtr.ownSymbols _ ownSymbols; dataPtr.compilerVersion _ [net: 0Ch, host: 0Ch, time: 0F0010004h]; -- Cedar release CompilerUtil.InstallParseTables[PrincOpsUtils.Codebase[LOOPHOLE[CBinary.MesaTab]]] ; tableBase[$error] _ PrincOpsUtils.Codebase[LOOPHOLE[CBinary.ErrorTab]]; tableBase[$debug] _ PrincOpsUtils.Codebase[LOOPHOLE[CBinary.DebugTab]]; }. dfile Sequencer.mesa last modified by Satterthwaite, June 8, 1983 4:27 pm last modified by Russ Atkinson, 10-Dec-80 10:53:50 Last Edited by: Maxwell, August 2, 1983 3:06 pm Last Edited by: Paul Rovner, November 21, 1983 11:10 am stream management table segment management compiler inquiries compiler sequencing encode switches, compiler version (see DIRECTORY processing also) first pass second pass third and fourth passes SymbolTable.Forget[[parms.objectFile, SymbolTable.anySpan]]; fifth pass IF parms.startPass # NIL THEN [] _ parms.startPass[0]; * * * * * * M A I N B O D Y C O D E * * * * * * Ê ´˜Jšœ™Jšœ4™4Jšœ2™2J™/Jšœ7™7J™šÏk ˜ Jšœ œœ˜šœœœ˜J˜H—Jšœ œœ˜2Jšœ œœ)˜@šœœœ˜J˜J˜YJ˜P—šœ œœ˜J˜QJ˜šœ!œ˜)Jšœ œ˜EJšœœ˜%J˜J˜———Jšœ™˜Jš œ œ'œœœ˜GJ˜š ž œœœœœœ˜OJšœ˜J˜—Jšž œœœ!˜:J˜J˜—Jšœ™˜šžœœœœ!˜Ešœ˜ JšœÏc"˜)JšœŸ˜JšœŸ&˜-JšœŸ?˜FJšœŸ˜#JšœŸ˜%JšœŸ?˜FJšœŸ ˜JšœŸ ˜JšœŸ ˜'JšœŸ ˜JšœŸ#˜*JšœŸ"˜)JšœŸ˜!JšœŸ ˜JšœŸ)˜0JšœŸ ˜JšœŸ ˜JšœŸ<˜CJšœŸ ˜JšœŸ%˜,JšœŸ ˜JšœŸ˜!JšœŸ ˜JšœŸ˜ JšœŸ ˜J˜J˜——šžœœœœ˜:Jšœ˜"J˜—š ž œœœœœ˜,Jšœœ!œ˜JJ˜J˜——Jšœ™˜Jšœ œ ˜J˜Jšœœ'œœ˜aJ˜šž œœ˜šœ œœ˜4JšœEŸ ˜Q—šœ œœ˜Jšœ œ ˜4J˜'Jšœ$œŸ ˜8—Jšœ˜J˜@J˜J˜—šžœœ&œ˜=J˜,J˜$Jšœ œ˜:J˜*J˜FJ˜(J˜2J˜$J˜JJ˜MJ˜MJ˜.šœœœ˜*Jšœ$œ œ˜