Skip to content

Commit

Permalink
Add FormatUID and NO_UID to m3middle/arc/M3CG.[im]3.
Browse files Browse the repository at this point in the history
FormatUID converts a UID to the base-62 Character form used in linker
symbols in stabs debug format.  Apparently, a Modula3-coded version of
this function did not exist.  It is needed by M3CG_LLVM.  (A C-coded
version already exists in parse.c).

There are duplicate declarations of NO_UID in m3front/src/type/TypeRep.i3,
m3front/src/misc/M3String.m3, and m3front/src/misc/M3WString.m3.
Also, m3cc/gcc*/gcc/m3cg/parse.c contain C declarations, and
cm3ide/src/nodes/Type.i3 contains a declaration with zero as value,
while the others are all minus one.

This should be consistified and centralized.  This commit puts a
Modula-3 declaration in M3CG, where it can be centrally referenced,
and an initial use of it in FormatUID.
  • Loading branch information
RodneyBates committed Feb 22, 2016
1 parent e852529 commit e6d9a9f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
9 changes: 9 additions & 0 deletions m3-sys/m3middle/src/M3CG.i3
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,15 @@ TYPE
TypeUID = (* BITS 32 FOR *) [-16_7fffffff-1 .. 16_7fffffff];
(* a 32-bit unique id (fingerprint) for each type. *)
TypeUIDBits = BITS 32 FOR TypeUID;
CONST NO_UID : TypeUID = -1;
(* TODO: There are duplicate declarations of NO_UID in m3front/src/type/TypeRep.i3,
m3front/src/misc/M3String.m3, and m3front/src/misc/M3WString.m3.
Also, m3cc/gcc*/gcc/m3cg/parse.c contain C declarations, and
cm3ide/src/nodes/Type.i3 contains a declaration with zero as value.
Consistify and centralize this.
*)

PROCEDURE FormatUID(tUID: TypeUID) : TEXT;

TYPE
Label = INTEGER;
Expand Down
29 changes: 29 additions & 0 deletions m3-sys/m3middle/src/M3CG.m3
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

MODULE M3CG EXPORTS M3CG, M3CG_Ops;

IMPORT Text, Word;
IMPORT Target;

REVEAL
Expand Down Expand Up @@ -154,6 +155,34 @@ REVEAL
fetch_and_op := fetch_and_op;
END;

(*----------------------------------------------------------- UIDs ----------*)

CONST UIDCharTbl
= ARRAY [0..61] OF CHAR
{'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};

PROCEDURE FormatUID(tUID: TypeUID) : TEXT =
VAR resultChars : ARRAY [ 0 .. 5 ] OF CHAR;
remainder: Word.T;
BEGIN
IF tUID = NO_UID THEN
RETURN "zzzzzz"
ELSE
remainder := Word.And(tUID,16_FFFFFFFF);
(* ^In case this runs on a 64-bit machine. *)
FOR RI := 5 TO 0 BY -1 DO
resultChars[RI] := UIDCharTbl [Word.Mod(remainder, 62)];
remainder := Word.Divide(remainder, 62);
END;
<*ASSERT remainder = 0*>
RETURN Text.FromChars(resultChars);
END;
END FormatUID;

(*----------------------------------------------------------- ID counters ---*)

PROCEDURE next_label (xx: T; n: INTEGER := 1): Label =
Expand Down

0 comments on commit e6d9a9f

Please sign in to comment.