MODULE------------------------------------------------------ set up/tear down ---; IMPORT Word, Target, M3Buf, M3ID, Value, Scope, Module, Scanner; IMPORT Expr, UserProc, Wr; VAR info: M3Buf.T := NIL; WebInfo
PROCEDURE----------------------------------------------------- compilation units ---Reset () = CONST Tag = ARRAY BOOLEAN OF CHAR { 'A', 'B' }; VAR file: TEXT; line: INTEGER; BEGIN IF (info = NIL) THEN info := M3Buf.New (); END; Scanner.LocalHere (file, line); OutC ('@'); OutT (file); NL (); OutC (Tag [Module.IsInterface ()]); OutN (Module.Name (NIL)); NL (); END Reset; PROCEDUREFinish (): TEXT = BEGIN RETURN M3Buf.ToText (info); END Finish;
PROCEDURE------------------------------------------- debugging type declarations ---Import_unit (n: Name) = BEGIN OutC ('C'); OutN (n); NL (); END Import_unit; PROCEDUREExport_unit (n: Name) = BEGIN OutC ('D'); OutN (n); NL (); END Export_unit;
PROCEDURE--------------------------------------------------------- low-level I/O ---Declare_typename (t: TypeUID; x: Value.T) = BEGIN OutX (t, 'E'); OutV (x); NL (); END Declare_typename; PROCEDUREDeclare_array (t: TypeUID; index, elt: TypeUID; s: Size) = BEGIN OutX (t, 'F'); OutU (index); OutU (elt); OutI (s); NL (); END Declare_array; PROCEDUREDeclare_open_array (t: TypeUID; elt: TypeUID; s: Size) = BEGIN OutX (t, 'G'); OutU (elt); OutI (s); NL (); END Declare_open_array; PROCEDUREDeclare_enum (t: TypeUID; n_elts: INTEGER; s: Size) = BEGIN OutX (t, 'H'); OutI (n_elts); OutI (s); NL (); END Declare_enum; PROCEDUREDeclare_enum_elt (n: Name) = BEGIN OutC ('I'); OutN (n); NL (); END Declare_enum_elt; PROCEDUREDeclare_packed (t: TypeUID; s: Size; base: TypeUID) = BEGIN OutX (t, 'J'); OutI (s); OutU (base); NL (); END Declare_packed ; PROCEDUREDeclare_record (t: TypeUID; s: Size; n_fields: INTEGER) = BEGIN OutX (t, 'K'); OutI (s); OutI (n_fields); NL (); END Declare_record; PROCEDUREDeclare_field (n: Name; o: Offset; s: Size; t: TypeUID) = BEGIN OutC ('L'); OutN (n); OutI (o); OutI (s); OutU (t); NL (); END Declare_field; PROCEDUREDeclare_set (t, domain: TypeUID; s: Size) = BEGIN OutX (t, 'M'); OutU (domain); OutI (s); NL (); END Declare_set; PROCEDUREDeclare_subrange (t, domain: TypeUID; READONLY min, max: Target.Int; s: Size) = BEGIN OutX (t, 'N'); OutU (domain); OutZ (min); OutZ (max); OutI (s); NL (); END Declare_subrange; PROCEDUREDeclare_pointer (t, target: TypeUID; brand: TEXT; traced: BOOLEAN) = CONST Tag = ARRAY BOOLEAN OF CHAR { 'O', 'P' }; BEGIN OutX (t, Tag [traced]); OutU (target); IF (brand # NIL) THEN OutC (' '); OutT (brand); END; NL (); END Declare_pointer; PROCEDUREDeclare_indirect (t, target: TypeUID) = BEGIN OutX (t, 'Q'); OutU (target); NL (); END Declare_indirect; PROCEDUREDeclare_proctype (t: TypeUID; n_formals: INTEGER; result: TypeUID; n_raises: INTEGER) = BEGIN OutX (t, 'R'); OutI (n_formals); OutU (result); OutI (n_raises); NL (); END Declare_proctype; PROCEDUREDeclare_formal (n: Name; t: TypeUID) = BEGIN OutC ('S'); OutN (n); OutU (t); NL (); END Declare_formal; PROCEDUREDeclare_raises (n: Name) = BEGIN OutC ('T'); OutN (n); NL (); END Declare_raises; PROCEDUREDeclare_object (t, super: TypeUID; brand: TEXT; traced: BOOLEAN; n_fields, n_methods, n_overrides: INTEGER; field_size: Size) = CONST Tag = ARRAY BOOLEAN OF CHAR { 'U', 'V' }; BEGIN OutX (t, Tag[traced]); OutU (super); OutI (n_fields); OutI (n_methods); OutI (n_overrides); OutI (field_size); IF (brand # NIL) THEN OutC (' '); OutT (brand); END; NL (); END Declare_object; PROCEDUREDeclare_method (n: Name; signature: TypeUID; dfault: Expr.T) = VAR proc: Value.T; BEGIN OutC ('W'); OutN (n); OutU (signature); IF (dfault = NIL) THEN (* skip *) ELSIF UserProc.IsProcedureLiteral (dfault, proc) THEN OutV (proc); ELSE OutT (" NIL"); END; NL (); END Declare_method; PROCEDUREDeclare_override (n: Name; dfault: Expr.T) = VAR proc: Value.T; BEGIN OutC ('X'); OutN (n); IF (dfault = NIL) THEN OutT (" (??)"); ELSIF UserProc.IsProcedureLiteral (dfault, proc) THEN OutV (proc); ELSE OutT (" NIL"); END; NL (); END Declare_override; PROCEDUREDeclare_opaque (t, super: TypeUID) = BEGIN OutX (t, 'Y'); OutU (super); NL (); END Declare_opaque; PROCEDUREReveal_opaque (lhs, rhs: TypeUID) = BEGIN OutX (lhs, 'Z'); OutU (rhs); NL (); END Reveal_opaque;
PROCEDUREOutC (c: CHAR) = BEGIN M3Buf.PutChar (info, c); END OutC; PROCEDUREOutI (i: INTEGER) = BEGIN M3Buf.PutChar (info, ' '); M3Buf.PutInt (info, i); END OutI; PROCEDUREOutU (t: TypeUID) = BEGIN M3Buf.PutChar (info, ' '); PutHex (t); END OutU; PROCEDUREOutN (n: Name) = BEGIN M3ID.Put (info, n); END OutN; PROCEDUREOutX (t: TypeUID; c: CHAR) = BEGIN M3Buf.PutChar (info, c); PutHex (t); END OutX; PROCEDUREOutV (v: Value.T) = VAR s: Scope.IDStack; BEGIN M3Buf.PutChar (info, ' '); s.top := 0; Scope.NameToPrefix (v, s, dots := TRUE, with_module := TRUE); Scope.PutStack (info, s); END OutV; PROCEDUREOutZ (READONLY i: Target.Int) = BEGIN M3Buf.PutChar (info, ' '); M3Buf.PutIntt (info, i); END OutZ; PROCEDUREOutT (t: TEXT) = BEGIN M3Buf.PutText (info, t); END OutT; CONST HexDigit = ARRAY [0..15] OF CHAR { '0','1','2','3','4','5','6','7', '8','9','a','b','c','d','e','f' }; PROCEDUREPutHex (i: INTEGER) = VAR buf: ARRAY [0..7] OF CHAR; BEGIN FOR j := 7 TO 0 BY -1 DO buf[j] := HexDigit [Word.Mod (i, 16)]; i := Word.Divide (i, 16); END; M3Buf.PutSub (info, buf); END PutHex; PROCEDURENL () = BEGIN M3Buf.PutText (info, Wr.EOL); END NL; BEGIN END WebInfo.