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], 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], SourceMap: TYPE USING [Cons, Init, Reset], 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]; CompilerSequencer: MONITOR IMPORTS Alloc, CBinary, CompilerUtil, Copier, FS, FileParmOps, IO, Log, LiteralOps, Loader, OSMiscOps, PrincOpsUtils, RuntimeError, SourceMap, 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 TRUE => append to compiler.log, FALSE => write new compiler.log 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 TRUE -- Z FALSE => use old-style method to access ROPE & ATOM literals ]] }; CompilerVersion: PUBLIC PROC RETURNS[TimeStamp.Stamp] = { RETURN[dataPtr.compilerVersion]}; AppendHerald: PUBLIC PROC[s: IO.STREAM] = { s.Put[IO.rope["Cedar 6.0 Compiler of "], IO.time[Loader.BCDBuildTime[]]]}; pass: CHAR ['1..'5]; ExtendedTables: TYPE = Alloc.Selector[SymbolSegment.Tables.FIRST .. SymbolSegment.Tables.LAST+1]; Initialize: PROC = { weights: ARRAY ExtendedTables OF Alloc.TableInfo _ [ [30, 16], [20], [4], [4], [4], [2], [4], [1], [2], [1], [2], [2], [20, 15]]; -- empirical IF table = NIL THEN { table _ Alloc.Create[weights: DESCRIPTOR[weights]]; table.Chunkify[table: SymbolSegment.treeType, firstSmall: 4, nSmall: 7]; table.Chunkify[table: SymbolSegment.Tables.LAST+1, nSmall: 5]} -- codeType ELSE table.Reset[]; SymbolOps.Initialize[table, NIL]; LiteralOps.Initialize[table]; TreeOps.Initialize[table]; SourceMap.Init[]}; 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 ERROR; FileParmOps.ReleaseOutput[parms.objectFile]}; SourceMap.Reset[]; 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.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 _ SourceMap.Cons[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 ERROR; parms.objectFile _ FileParmOps.AcquireOutput[parms.objectName]; ownedObject _ TRUE; IF parms.objectFile = FS.nullOpenFile THEN ERROR; 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]]; }. ŠCompilerSequencer.mesa Copyright c 1985 by Xerox Corporation. All rights reserved. Satterthwaite, March 27, 1986 1:45:46 pm PST Russ Atkinson, 10-Dec-80 10:53:50 Maxwell, August 2, 1983 3:06 pm Paul Rovner, November 21, 1983 11:10 am Russ Atkinson (RRA) April 3, 1985 4:16:54 pm PST Bob Hagmann March 24, 1986 8:50:18 am PST 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 fifth pass IF parms.startPass # NIL THEN [] _ parms.startPass[0]; * * * * * * M A I N B O D Y C O D E * * * * * * Κ ž˜codešœ™Kšœ Οmœ1™šžœ!žœ˜)Kšžœ žœ˜EKšœžœ˜#—šœ˜K˜K˜———Kšœ™˜Kš œ žœ'žœžœžœ˜GK˜š Ÿ œžœžœžœžœžœ˜MKšžœ˜K˜—KšŸ œžœžœ ˜9K˜K˜—Kšœ™˜šŸœžœžœžœ ˜Dšžœ˜KšžœΟc"˜)Kšžœ ˜Kšžœ &˜-Kšžœ ?˜FKšžœ ˜#Kšžœ ˜%Kšžœ ?˜FKšžœ E˜LKšžœ  ˜Kšžœ  ˜'Kšžœ  ˜Kšžœ #˜*Kšžœ "˜)Kšžœ ˜!Kšžœ  ˜Kšžœ )˜0Kšžœ  ˜Kšžœ  ˜Kšžœ <˜CKšžœ  ˜Kšžœ %˜,Kšžœ  ˜Kšžœ ˜!Kšžœ  ˜Kšžœ ˜ Kšžœ B˜IK˜—˜K˜——šŸœžœžœžœ˜9Kšžœ˜!K˜—š Ÿ œžœžœžœžœ˜+Kšœžœ!žœ˜JK˜K˜——Kšœ™˜Kšœžœ ˜K˜Kšœžœ'žœžœ˜aK˜šŸ œžœ˜šœ žœžœ˜4KšœM  ˜Y—šžœ žœ˜Kšœž œ ˜4KšœH˜HKšœ+žœ  ˜M—Kšžœ˜Kšœžœ!˜@K˜.K˜—šŸœžœ%žœ˜˜QšŸ œžœ˜+K˜5K˜—Kš žœ žœžœžœžœ˜*K˜K˜K˜"K˜%K˜ Kšœ˜K˜K˜5K˜DšœA™A˜,Kšœ2žœ˜P—˜,K˜EK˜——Kšœ3žœ˜9˜KšœEžœ˜M—˜(Kšœžœžœ˜?—K˜ —šœžœ˜ Kšœžœžœ˜šœžœ!˜*Kšœžœžœžœ˜3Kš œ žœžœžœžœ˜>K˜—K˜K˜K˜˜&K˜—Kšœ ™ Kš žœžœžœžœžœ˜BK˜ K˜K˜Kšžœ žœžœ˜K˜+šžœžœ$˜@K˜—Kšœ ™ Kš žœžœžœžœžœ˜BK˜ K˜!šžœžœ$˜@K˜—Kšœ™Kš žœžœžœžœžœ˜BK˜K˜ —šœžœžœ˜,K˜KšœS˜S—šœžœžœ˜&šž˜Kšžœ&žœžœ˜Y—˜K˜ K˜!K˜9K˜Kšžœžœ$˜@Kšžœ žœžœ ˜8K˜K˜CKšœB˜BKšžœžœ žœžœ˜1K˜?Kšœžœ˜Kšžœžœ žœžœ˜1šœ˜KšœžœF˜J—K˜šžœžœžœžœ˜7Kšœžœžœ ˜;—K˜ K˜5K˜Kšžœžœ/˜KK˜šž˜Kšœžœ˜——Kšžœ˜—šœ +˜/˜K˜—šžœžœžœ ˜DK˜—Kšœ ™ šžœžœ˜šžœžœžœžœ˜7Kšœžœ ˜'—K˜ K˜——šœ 1˜5K˜K˜Kš žœžœžœžœžœ˜BK˜—™Kšœ6™6Kšžœžœ žœ˜+—˜šž˜Kšœžœ˜Kšœ*žœ˜0˜Kšœ žœžœ˜-Kšœ žœ˜Kšœ˜Kšžœ$žœ˜DKšžœ˜K˜Kšœ˜Kšžœžœžœ ˜—˜Kšœ žœžœ˜-Kšœ žœ˜K˜$Kšžœ&žœ"˜LKšžœ%žœ˜EKšžœ˜K˜———K˜Kšœ :˜=K˜Kšœ ˜K˜—Kšœ5™5˜Kšžœ  $˜4Kšžœ ˜K˜ KšœC ˜SK˜Kšœ7žœ˜TKšœ+žœ˜GKšœ+žœ˜GK˜K˜—K™—…—-0