2 (* ================================================================ *)
4 (* Module of the V1.4+ gpcp tool to create symbol files from *)
5 (* the metadata of .NET assemblies, using the PERWAPI interface. *)
7 (* Copyright QUT 2004 - 2005. *)
9 (* This code released under the terms of the GPCP licence. *)
11 (* This Module: <N2State> *)
12 (* Holds global state for the process, plus utilities. *)
13 (* Original module, kjg December 2004 *)
15 (* ================================================================ *)
31 Sys
:= "[mscorlib]System",
34 (* ---------------------------------------------------------- *)
36 CONST prefix
= "PeToCps: ";
37 abtMsg
= " ... Aborting";
38 usgMsg
= 'Usage
: "PeToCps [options] filenames"'
;
40 (* ---------------------------------------------------------- *)
42 TYPE CharOpen
* = POINTER TO ARRAY OF CHAR;
44 (* ---------------------------------------------------------- *)
46 TYPE CleanDump
= POINTER TO RECORD (Sy
.SymForAll
) END;
48 (* ---------------------------------------------------------- *)
50 VAR netDflt
- : BOOLEAN;
58 (* ---------------------------------------------------------- *)
60 VAR thisMod
- : Id
.BlkId
;
70 (* ---------------------------------------------------------- *)
72 PROCEDURE^ AbortMsg
*(IN str
: ARRAY OF CHAR);
73 PROCEDURE^ Message
*(IN str
: ARRAY OF CHAR);
75 (* ---------------------------------------------------------- *)
77 PROCEDURE ListTy
*(ty
: Sy
.Type
);
79 Sy
.AppendType(typSeq
, ty
);
82 (* ---------------------------------------------------------- *)
84 PROCEDURE AddMangledNames(mod
: Id
.BlkId
; asm
, nms
: CharOpen
);
86 mod
.hash
:= Nh
.enterStr(ForeignName
.MangledName(asm
, nms
));
87 mod
.scopeNm
:= ForeignName
.QuotedName(asm
, nms
);
90 (* ---------------------------------------------------------- *)
92 PROCEDURE GlobInit
*(IN src
, bas
: ARRAY OF CHAR);
94 Nh
.InitNameHash(hashSize
);
97 isCorLib
:= (bas
= "mscorlib");
99 CompState
.CreateThisMod
;
100 thisMod
:= CompState
.thisMod
;
102 Sy
.ResetScpSeq(impSeq
);
103 ctorBkt
:= Nh
.enterStr(".ctor");
104 initBkt
:= Nh
.enterStr("init");
107 (* ------------------------------------- *)
109 PROCEDURE BlkIdInit
*(blk
: Id
.BlkId
; asm
, nms
: CharOpen
);
111 blk
.SetKind(Id
.impId
);
112 AddMangledNames(blk
, asm
, nms
);
113 IF Sy
.refused(blk
, thisMod
) THEN
114 AbortMsg("BlkId insert failure -- " + Nh
.charOpenOfHash(blk
.hash
)^
);
116 Sy
.AppendScope(impSeq
, blk
)
119 (* ------------------------------------- *)
121 PROCEDURE InsertImport
*(blk
: Id
.BlkId
);
123 IF Sy
.refused(blk
, thisMod
) THEN
124 AbortMsg("BlkId insert failure in <thisMod>");
126 Sy
.AppendScope(impSeq
, blk
)
129 (* ------------------------------------- *)
131 PROCEDURE (dmpr
: CleanDump
)Op
*(id
: Sy
.Idnt
);
133 WITH id
: Id
.TypId
DO
134 IF id
.type
.dump
>= Sy
.tOffset
THEN id
.type
.dump
:= 0 END;
139 (* ------------------------------------- *)
141 PROCEDURE ResetBlkIdFlags
*(mod
: Id
.BlkId
);
148 * Clear the "dump" marker from non built-in types
150 FOR indx
:= 0 TO typSeq
.tide
- 1 DO
151 typI
:= typSeq
.a
[indx
];
152 IF typI
.dump
>= Sy
.tOffset
THEN
154 typI
.force
:= Sy
.noEmit
;
157 mod
.SetKind(Id
.modId
);
160 Message("Preparing symfile <" + Nh
.charOpenOfHash(mod
.hash
)^
+ ">");
162 FOR indx
:= 0 TO impSeq
.tide
- 1 DO
163 impB
:= impSeq
.a
[indx
];
165 impB
.SetKind(Id
.impId
);
170 (* ---------------------------------------------------------- *)
172 PROCEDURE WLn(IN str
: ARRAY OF CHAR);
174 Console
.WriteString(str
); Console
.WriteLn
;
177 PROCEDURE Message
*(IN str
: ARRAY OF CHAR);
179 Console
.WriteString(prefix
);
180 Console
.WriteString(str
);
184 PROCEDURE CondMsg
*(IN str
: ARRAY OF CHAR);
186 IF verbose
THEN Message(str
) END;
189 PROCEDURE AbortMsg
*(IN str
: ARRAY OF CHAR);
191 Error
.WriteString(prefix
);
192 Error
.WriteString(str
);
200 Message("filenames should have explicit .EXE or .DLL extension");
202 WLn("Options: /big ==> allocate huge hash table");
203 WLn(" /copyright ==> display copyright notice");
204 WLn(" /generics ==> enable CLI v2.0 generics");
205 WLn(" /help ==> display this message");
206 WLn(" /legacy ==> produce compatible symbol file");
207 WLn(" /verbose ==> chatter on about progress");
208 WLn(" /Verbose ==> go on and on and on about progress");
210 WLn("Options: -big ==> allocate huge hash table");
211 WLn(" -copyright ==> display copyright notice");
212 WLn(" -generics ==> enable CLI v2.0 generics");
213 WLn(" -help ==> display this message");
214 WLn(" -legacy ==> produce compatible symbol file");
215 WLn(" -verbose ==> chatter on about progress");
216 WLn(" -Verbose ==> go on and on and on about progress");
220 (* ---------------------------------------------------------- *)
222 PROCEDURE ReportTim(tim
: LONGINT);
223 CONST millis
= " mSec";
225 Console
.WriteInt(SHORT(tim
), 0);
226 Console
.WriteString(millis
);
229 PROCEDURE Report
*(IN nam
, res
: ARRAY OF CHAR; tim
: LONGINT);
231 Console
.WriteString(prefix
);
232 Console
.WriteString(" Input file <");
233 Console
.WriteString(nam
);
234 Console
.WriteString("> ");
235 Console
.WriteString(res
);
237 Console
.WriteString(", time: ");
243 PROCEDURE Summary
*(flNm
, okNm
: INTEGER; tim
: LONGINT);
244 CONST sumPre
= " Summary: ";
246 Console
.WriteString(prefix
);
247 Console
.WriteString(sumPre
);
249 Console
.WriteString(" No input files specified");
251 Console
.WriteInt(flNm
,1);
252 Console
.WriteString(" input files");
254 Console
.WriteInt(flNm
- okNm
, 0);
255 Console
.WriteString(" failed");
259 Console
.WriteString(prefix
);
260 Console
.WriteString(sumPre
);
261 Console
.WriteString("Total elapsed time: ");
268 (* ---------------------------------------------------------- *)
270 PROCEDURE ParseOption
*(IN arg
: ARRAY OF CHAR);
274 ELSIF arg
= "-verbose" THEN
278 ELSIF arg
= "-Verbose" THEN
282 ELSIF arg
= "-generics" THEN
284 ELSIF arg
= "-legacy" THEN
286 CompState
.legacy
:= TRUE
;
287 ELSIF arg
= "-VERBOSE" THEN
291 ELSIF arg
= "-help" THEN
293 ELSIF arg
= "-copyright" THEN
294 GPCPcopyright
.Write();
296 Message("Bad Option " + arg
); Usage
;
300 (* ---------------------------------------------------------- *)
302 PROCEDURE EmitSymbolfile
*(blk
: Id
.BlkId
);
305 Message(" Output file <" +
306 Nh
.charOpenOfHash(blk
.hash
)^
+
310 (* ---------------------------------------------------------- *)
313 netDflt
:= (RTS
.defaultTarget
= "net");
319 cpCmpld
:= FALSE
; (* pending the custom attribute *)
321 Sy
.InitScpSeq(impSeq
, 10);
322 Sy
.InitTypeSeq(typSeq
, 10);
323 CompState
.ParseOption("/special");