<> <> <> <> DIRECTORY BasicTime USING [GMT, Now], CommandTool USING [ArgumentVector], FS USING [ComponentPositions, Error, OpenFile, ExpandName, GetInfo, Open, StreamOpen], IO, Loader USING [BCDBuildTime], Rope, ViewerClasses USING [Viewer], ViewerIO USING [CreateViewerStreams], ViewerOps USING [FindViewer, OpenIcon], MDDefs, MDGlobalVars, MDOps; MDInitImpl: CEDAR PROGRAM IMPORTS BasicTime, FS, IO, Loader, Rope, ViewerIO, ViewerOps, MDGlobalVars, MDOps EXPORTS MDOps = BEGIN OPEN MDDefs, MDGlobalVars; savedWDir: ROPE _ NIL; InitMicroDVars: PUBLIC PROC[cmdLine, wDir: ROPE, argv: CommandTool.ArgumentVector] RETURNS[srcFileList: SrcFile, ok: BOOL, start: BasicTime.GMT] = { lastFileName: ROPE; i: NAT _ 1; lastSrcFile: SrcFile _ NIL; ok _ FALSE; fatalErrors _ FALSE; listingLevel _ listFull; srcFileList _ NIL; outFile _ NEW[OutputFileRec]; savedWDir _ wDir; reportStrm _ TSStream["MicroD"]; StartupMessage[reportStrm, cmdLine, start _ BasicTime.Now[]]; IF argv.argc = 1 THEN { reportStrm.PutRope["Command line is empty - quitting\n"]; RETURN }; DO -- global switches arg: ROPE = argv[i]; IF arg.Fetch[0] # '- THEN EXIT; ParseGlobalFlags[arg]; i _ i + 1; ENDLOOP; <<>> <> DO arg: ROPE; arg _ argv[i]; IF arg.Fetch[0] = '- THEN { <> ch: CHAR; SELECT ch _ arg.Fetch[1] FROM -- is switch '~ => ParseGlobalFlags[arg]; 'A, 'a => lastSrcFile.listingFlag _ listAbsOnly; 'C, 'c => lastSrcFile.listingFlag _ listConcise; 'L, 'l => lastSrcFile.listingFlag _ listFull; 'N, 'n => lastSrcFile.listingFlag _ listNotIM; 'O, 'o => { outFile.fullName _ FullNameWithExt[NIL, lastFileName, wDir, "MB"]; lastFileName _ NIL }; ENDCASE => MDOps.Report[infoOnly, IO.PutFR["\n Unknown local switch (%g)\n", IO.char[ch]]]; } ELSE { -- fileName IF lastFileName # NIL THEN { srcFile: SrcFile _ NEW[SrcFileRec _ [fullName: lastFileName, listingFlag: listingLevel]]; IF srcFileList = NIL THEN srcFileList _ lastSrcFile _ srcFile ELSE { lastSrcFile.next _ srcFile; lastSrcFile _ lastSrcFile.next }; }; lastFileName _ arg; }; i _ i + 1; IF i >= argv.argc THEN EXIT; -- finished ENDLOOP; IF lastFileName # NIL THEN { srcFile: SrcFile _ NEW[SrcFileRec _ [fullName: lastFileName]]; IF srcFileList = NIL THEN srcFileList _ lastSrcFile _ srcFile ELSE { lastSrcFile.next _ srcFile; lastSrcFile _ lastSrcFile.next }; }; IF srcFileList = NIL THEN { reportStrm.PutRope["No source files - quitting\n"]; RETURN }; <<>> lastFileName _ lastSrcFile.fullName; IF listingLevel # -2 AND outFile.fullName = NIL THEN { outFile.fullName _ FullNameWithExt[NIL, lastFileName, wDir, "mb"]; }; listingFile _ NEW[OutputFileRec]; listingFile.fullName _ FullNameWithExt[outFile.fullName, lastFileName, wDir, "dls"]; listingFile.strm _ FS.StreamOpen[listingFile.fullName, $create]; StartupMessage[listingFile.strm, cmdLine, start]; IF mapIM THEN { mapFile _ NEW[OutputFileRec]; mapFile.fullName _ FullNameWithExt[outFile.fullName, lastFileName, wDir, "csMap"]; } ELSE mapFile _ NIL; IF mapRM THEN { regsFile _ NEW[OutputFileRec]; regsFile.fullName _ FullNameWithExt[outFile.fullName, lastFileName, wDir, "regs"]; } ELSE regsFile _ NIL; IF mapOccupied THEN { occupiedFile _ NEW[OutputFileRec]; occupiedFile.fullName _ FullNameWithExt[outFile.fullName, lastFileName, wDir, "occupiedMC"]; } ELSE occupiedFile _ NIL; IF mapChart THEN { chartFile _ NEW[OutputFileRec]; chartFile.fullName _ FullNameWithExt[outFile.fullName, lastFileName, wDir, "csChart"]; } ELSE chartFile _ NIL; IF listAbs THEN { absFile _ NEW[OutputFileRec]; absFile.fullName _ FullNameWithExt[outFile.fullName, lastFileName, wDir, "absDLS"]; } ELSE absFile _ NIL; ok _ TRUE; FOR sfl: SrcFile _ srcFileList, sfl.next UNTIL sfl = NIL DO sfl.fullName _ FullNameWithExt[sfl.fullName, NIL, wDir, "dib"]; sfl.of _ FS.Open[sfl.fullName ! FS.Error => { MDOps.Report[infoOnly, error.explanation]; ok _ FALSE; CONTINUE } ]; IF ~ok THEN RETURN; sfl.createDate _ FS.GetInfo[sfl.of].created; ENDLOOP; ok _ TRUE; }; TSStream: PROC[name: ROPE] RETURNS [out: STREAM] = { v: ViewerClasses.Viewer _ ViewerOps.FindViewer[name]; out _ ViewerIO.CreateViewerStreams[name, v].out; IF v#NIL THEN IF v.iconic THEN ViewerOps.OpenIcon[v]; }; StartupMessage: PROC[out: STREAM, cmdLine: ROPE, start: BasicTime.GMT] = { out.PutRope["\n\n**********************************************************\n"]; out.PutF["\t\t MicroD (microcode placer) of %g, started @ %g\n", IO.time[Loader.BCDBuildTime[MDInitImpl.StartupMessage]], IO.time[start]]; out.PutRope["Command is: "]; out.PutRope[cmdLine]; out.PutChar['\n]; }; FullNameWithExt: PUBLIC PROC[preferred, other, wDir, ext: ROPE] RETURNS[fullName: ROPE] = { <> <> forceExt: BOOL _ ext # NIL; basis: ROPE _ IF preferred # NIL THEN preferred ELSE other; cp: FS.ComponentPositions; IF basis = NIL THEN RETURN; [fullName, cp, ] _ FS.ExpandName[basis, wDir]; IF cp.ext.length # 0 THEN IF ~forceExt THEN RETURN ELSE fullName _ Rope.Substr[fullName, 0, cp.ext.start-1]; RETURN[IF ext.Length[] = 0 THEN fullName ELSE fullName.Cat[".", ext] ] }; ParseGlobalFlags: PROC[arg: ROPE] = { ch: CHAR; FOR j: INT IN [1..arg.Length[]) DO SELECT ch _ arg.Fetch[j] FROM 'A, 'a => listingLevel _ listAbsOnly; 'C, 'C => listingLevel _ listConcise; 'E, 'e => mapChart _ TRUE; -- chart Every location 'H, 'h => listAbs _ TRUE; -- abs listing for Hardware debugging 'I, 'i => ignoreOnPage _ TRUE; -- Ignore OnPage directives 'M, 'm => mapIM _ TRUE; -- Map of IM by page 'N, 'n => listingLevel _ listNotIM; -- No IM listing 'O, 'o => mapOccupied _ TRUE; -- write Occupied location map 'P, 'P => listingLevel _ listPrintMB; -- just Print the .MBs 'R, 'r => mapRM _ TRUE; -- RM Map 'S, 's => listSymbols _ TRUE; -- Symbols for all memories 'X, 'x => external _ TRUE; -- allow eXternal references '~ => NULL; -- signals additional global switches ENDCASE => MDOps.Report[infoOnly, IO.PutFR["\n Unknown global switch (%g)\n", IO.char[ch]]]; ENDLOOP; }; END.