-
Notifications
You must be signed in to change notification settings - Fork 870
Expand file tree
/
Copy pathilprint.fs
More file actions
974 lines (805 loc) · 30.8 KB
/
Copy pathilprint.fs
File metadata and controls
974 lines (805 loc) · 30.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
module internal FSharp.Compiler.AbstractIL.ILAsciiWriter
open System.IO
open System.Reflection
open FSharp.Compiler.IO
open Internal.Utilities.Library
open FSharp.Compiler.AbstractIL.ILX.Types
open FSharp.Compiler.AbstractIL.IL
#if DEBUG
// --------------------------------------------------------------------
// Pretty printing
// --------------------------------------------------------------------
let tyvar_generator =
let mutable i = 0
fun n ->
i <- i + 1
n + string i
// Carry an environment because the way we print method variables
// depends on the gparams of the current scope.
type ppenv =
{
ilGlobals: ILGlobals
ppenvClassFormals: int
ppenvMethodFormals: int
}
let ppenv_enter_method mgparams env =
{ env with
ppenvMethodFormals = mgparams
}
let ppenv_enter_tdef gparams env =
{ env with
ppenvClassFormals = List.length gparams
ppenvMethodFormals = 0
}
let mk_ppenv ilg =
{
ilGlobals = ilg
ppenvClassFormals = 0
ppenvMethodFormals = 0
}
let ppenv_enter_modul env =
{ env with
ppenvClassFormals = 0
ppenvMethodFormals = 0
}
// --------------------------------------------------------------------
// Pretty printing - output streams
// --------------------------------------------------------------------
let output_string (os: TextWriter) (s: string) = os.Write s
let output_char (os: TextWriter) (c: char) = os.Write c
let output_int os (i: int) = output_string os (string i)
let output_hex_digit os i =
assert (i >= 0 && i < 16)
if i > 9 then
output_char os (char (int32 'A' + (i - 10)))
else
output_char os (char (int32 '0' + i))
let output_qstring os s =
output_char os '"'
for i = 0 to String.length s - 1 do
let c = String.get s i
if (c >= '\000' && c <= '\031') || (c >= '\127' && c <= '\255') then
let c' = int32 c
output_char os '\\'
output_int os (c' / 64)
output_int os ((c' % 64) / 8)
output_int os (c' % 8)
else if (c = '"') then
output_char os '\\'
output_char os '"'
else if (c = '\\') then
output_char os '\\'
output_char os '\\'
else
output_char os c
output_char os '"'
let output_sqstring os s =
output_char os '\''
for i = 0 to String.length s - 1 do
let c = s[i]
if (c >= '\000' && c <= '\031') || (c >= '\127' && c <= '\255') then
let c' = int32 c
output_char os '\\'
output_int os (c' / 64)
output_int os ((c' % 64) / 8)
output_int os (c' % 8)
else if (c = '\\') then
output_char os '\\'
output_char os '\\'
else if (c = '\'') then
output_char os '\\'
output_char os '\''
else
output_char os c
output_char os '\''
let output_seq sep f os (a: seq<_>) =
use e = a.GetEnumerator()
if e.MoveNext() then
f os e.Current
while e.MoveNext() do
output_string os sep
f os e.Current
let output_parens f os a =
output_string os "("
f os a
output_string os ")"
let output_angled f os a =
output_string os "<"
f os a
output_string os ">"
let output_id os n = output_sqstring os n
let output_byte os i =
output_hex_digit os (i / 16)
output_hex_digit os (i % 16)
let output_bytes os (bytes: byte[]) =
for i = 0 to bytes.Length - 1 do
output_byte os (Bytes.get bytes i)
output_string os " "
let bits_of_float32 (x: float32) =
System.BitConverter.ToInt32(System.BitConverter.GetBytes(x), 0)
let bits_of_float (x: float) =
System.BitConverter.DoubleToInt64Bits(x)
let output_u8 os (x: byte) = output_string os (string (int x))
let output_i8 os (x: sbyte) = output_string os (string (int x))
let output_u16 os (x: uint16) = output_string os (string (int x))
let output_i16 os (x: int16) = output_string os (string (int x))
let output_u32 os (x: uint32) = output_string os (string (int64 x))
let output_i32 os (x: int32) = output_string os (string x)
let output_u64 os (x: uint64) = output_string os (string (int64 x))
let output_i64 os (x: int64) = output_string os (string x)
let output_ieee32 os (x: float32) =
output_string os "float32 ("
output_string os (string (bits_of_float32 x))
output_string os ")"
let output_ieee64 os (x: float) =
output_string os "float64 ("
output_string os (string (bits_of_float x))
output_string os ")"
let rec goutput_scoref env os =
function
| ILScopeRef.Local -> ()
| ILScopeRef.Assembly aref ->
output_string os "["
output_sqstring os aref.Name
output_string os "]"
| ILScopeRef.Module mref ->
output_string os "[.module "
output_sqstring os mref.Name
output_string os "]"
| ILScopeRef.PrimaryAssembly ->
output_string os "["
output_sqstring os env.ilGlobals.primaryAssemblyName
output_string os "]"
and goutput_type_name_ref env os (scoref, enc, n) =
goutput_scoref env os scoref
output_seq "/" output_sqstring os (enc @ [ n ])
and goutput_tref env os (x: ILTypeRef) =
goutput_type_name_ref env os (x.Scope, x.Enclosing, x.Name)
and goutput_typ env os ty =
match ty with
| ILType.Boxed tr -> goutput_tspec env os tr
| ILType.TypeVar tv ->
// Special rule to print method type variables in Generic EE preferred form
// when an environment is available to help us do this.
let cgparams = env.ppenvClassFormals
let mgparams = env.ppenvMethodFormals
if int tv < cgparams then
output_string os "!"
output_tyvar os tv
elif int tv - cgparams < mgparams then
output_string os "!!"
output_int os (int tv - cgparams)
else
output_string os "!"
output_tyvar os tv
output_int os (int tv)
| ILType.Byref typ ->
goutput_typ env os typ
output_string os "&"
| ILType.Ptr typ ->
goutput_typ env os typ
output_string os "*"
| ILType.Value tspec when tspec.Name = PrimaryAssemblyILGlobals.typ_SByte.TypeSpec.Name -> output_string os "int8"
| ILType.Value tspec when tspec.Name = PrimaryAssemblyILGlobals.typ_Int16.TypeSpec.Name -> output_string os "int16"
| ILType.Value tspec when tspec.Name = PrimaryAssemblyILGlobals.typ_Int32.TypeSpec.Name -> output_string os "int32"
| ILType.Value tspec when tspec.Name = PrimaryAssemblyILGlobals.typ_Int64.TypeSpec.Name -> output_string os "int64"
| ILType.Value tspec when tspec.Name = PrimaryAssemblyILGlobals.typ_IntPtr.TypeSpec.Name -> output_string os "native int"
| ILType.Value tspec when tspec.Name = PrimaryAssemblyILGlobals.typ_Byte.TypeSpec.Name -> output_string os "unsigned int8"
| ILType.Value tspec when tspec.Name = PrimaryAssemblyILGlobals.typ_UInt16.TypeSpec.Name -> output_string os "unsigned int16"
| ILType.Value tspec when tspec.Name = PrimaryAssemblyILGlobals.typ_UInt32.TypeSpec.Name -> output_string os "unsigned int32"
| ILType.Value tspec when tspec.Name = PrimaryAssemblyILGlobals.typ_UInt64.TypeSpec.Name -> output_string os "unsigned int64"
| ILType.Value tspec when tspec.Name = PrimaryAssemblyILGlobals.typ_UIntPtr.TypeSpec.Name -> output_string os "native unsigned int"
| ILType.Value tspec when tspec.Name = PrimaryAssemblyILGlobals.typ_Double.TypeSpec.Name -> output_string os "float64"
| ILType.Value tspec when tspec.Name = PrimaryAssemblyILGlobals.typ_Single.TypeSpec.Name -> output_string os "float32"
| ILType.Value tspec when tspec.Name = PrimaryAssemblyILGlobals.typ_Bool.TypeSpec.Name -> output_string os "bool"
| ILType.Value tspec when tspec.Name = PrimaryAssemblyILGlobals.typ_Char.TypeSpec.Name -> output_string os "char"
| ILType.Value tspec ->
output_string os "value class "
goutput_tref env os tspec.TypeRef
output_string os " "
goutput_gactuals env os tspec.GenericArgs
| ILType.Void -> output_string os "void"
| ILType.Array(bounds, ty) ->
goutput_typ env os ty
output_string os "["
output_arr_bounds os bounds
output_string os "]"
| ILType.FunctionPointer csig ->
output_string os "method "
goutput_typ env os csig.ReturnType
output_string os " *("
output_seq ", " (goutput_typ env) os csig.ArgTypes
output_string os ")"
| _ -> output_string os "NaT"
and output_tyvar os d =
output_u16 os d
()
and goutput_typ_with_shortened_class_syntax env os =
function
| ILType.Boxed tspec when List.isEmpty tspec.GenericArgs -> goutput_tref env os tspec.TypeRef
| typ2 -> goutput_typ env os typ2
and goutput_gactuals env os inst =
if not (List.isEmpty inst) then
output_string os "<"
output_seq ", " (goutput_gactual env) os inst
output_string os ">"
and goutput_gactual env os ty = goutput_typ env os ty
and goutput_tspec env os tspec =
output_string os "class "
goutput_tref env os tspec.TypeRef
output_string os " "
goutput_gactuals env os tspec.GenericArgs
and output_arr_bounds os =
function
| bounds when bounds = ILArrayShape.SingleDimensional -> ()
| ILArrayShape l ->
output_seq
", "
(fun os ->
function
| None, None -> output_string os ""
| None, Some sz -> output_int os sz
| Some lower, None ->
output_int os lower
output_string os " ... "
| Some lower, Some d ->
output_int os lower
output_string os " ... "
output_int os d)
os
l
and goutput_permission _env os p =
let output_security_action os x =
output_string
os
(match x with
| ILSecurityAction.Request -> "request"
| ILSecurityAction.Demand -> "demand"
| ILSecurityAction.Assert -> "assert"
| ILSecurityAction.Deny -> "deny"
| ILSecurityAction.PermitOnly -> "permitonly"
| ILSecurityAction.LinkCheck -> "linkcheck"
| ILSecurityAction.InheritCheck -> "inheritcheck"
| ILSecurityAction.ReqMin -> "reqmin"
| ILSecurityAction.ReqOpt -> "reqopt"
| ILSecurityAction.ReqRefuse -> "reqrefuse"
| ILSecurityAction.PreJitGrant -> "prejitgrant"
| ILSecurityAction.PreJitDeny -> "prejitdeny"
| ILSecurityAction.NonCasDemand -> "noncasdemand"
| ILSecurityAction.NonCasLinkDemand -> "noncaslinkdemand"
| ILSecurityAction.NonCasInheritance -> "noncasinheritance"
| ILSecurityAction.LinkDemandChoice -> "linkdemandchoice"
| ILSecurityAction.InheritanceDemandChoice -> "inheritancedemandchoice"
| ILSecurityAction.DemandChoice -> "demandchoice")
match p with
| ILSecurityDecl.ILSecurityDecl(sa, b) ->
output_string os " .permissionset "
output_security_action os sa
output_string os " = ("
output_bytes os b
output_string os ")"
and goutput_security_decls env os (ps: ILSecurityDecls) =
output_seq " " (goutput_permission env) os (ps.AsList())
and goutput_gparam env os (gf: ILGenericParameterDef) =
output_string os (tyvar_generator gf.Name)
output_parens (output_seq ", " (goutput_typ env)) os gf.Constraints
and goutput_gparams env os b =
if not (isNil b) then
output_string os "<"
output_seq ", " (goutput_gparam env) os b
output_string os ">"
()
and output_bcc os bcc =
output_string
os
(match bcc with
| ILArgConvention.FastCall -> "fastcall "
| ILArgConvention.StdCall -> "stdcall "
| ILArgConvention.ThisCall -> "thiscall "
| ILArgConvention.CDecl -> "cdecl "
| ILArgConvention.Default -> " "
| ILArgConvention.VarArg -> "vararg ")
and output_callconv os (Callconv(hasthis, cc)) =
output_string
os
(match hasthis with
| ILThisConvention.Instance -> "instance "
| ILThisConvention.InstanceExplicit -> "explicit "
| ILThisConvention.Static -> "")
output_bcc os cc
and goutput_dlocref env os (dref: ILType) =
match dref with
| dref when
dref.IsNominal
&& isTypeNameForGlobalFunctions dref.TypeRef.Name
&& dref.TypeRef.Scope = ILScopeRef.Local
->
()
| dref when dref.IsNominal && isTypeNameForGlobalFunctions dref.TypeRef.Name ->
goutput_scoref env os dref.TypeRef.Scope
output_string os "::"
| ty ->
goutput_typ_with_shortened_class_syntax env os ty
output_string os "::"
and goutput_mref env os (mref: ILMethodRef) =
output_callconv os mref.CallingConv
output_string os " "
goutput_typ_with_shortened_class_syntax env os mref.ReturnType
output_string os " "
// no quotes for ".ctor"
let name = mref.Name
if name = ".ctor" || name = ".cctor" then
output_string os name
else
output_id os name
output_parens (output_seq ", " (goutput_typ env)) os mref.ArgTypes
and goutput_mspec env os (mspec: ILMethodSpec) =
let fenv =
ppenv_enter_method mspec.GenericArity (ppenv_enter_tdef (mkILFormalTypars mspec.DeclaringType.GenericArgs) env)
output_callconv os mspec.CallingConv
output_string os " "
goutput_typ fenv os mspec.FormalReturnType
output_string os " "
goutput_dlocref env os mspec.DeclaringType
output_string os " "
let name = mspec.Name
if name = ".ctor" || name = ".cctor" then
output_string os name
else
output_id os name
goutput_gactuals env os mspec.GenericArgs
output_parens (output_seq ", " (goutput_typ fenv)) os mspec.FormalArgTypes
let output_member_access os access =
output_string
os
(match access with
| ILMemberAccess.Public -> "public"
| ILMemberAccess.Private -> "private"
| ILMemberAccess.Family -> "family"
| ILMemberAccess.CompilerControlled -> "privatescope"
| ILMemberAccess.FamilyAndAssembly -> "famandassem"
| ILMemberAccess.FamilyOrAssembly -> "famorassem"
| ILMemberAccess.Assembly -> "assembly")
let output_type_access os access =
match access with
| ILTypeDefAccess.Public -> output_string os "public"
| ILTypeDefAccess.Private -> output_string os "private"
| ILTypeDefAccess.Nested ilMemberAccess ->
output_string os "nested "
output_member_access os ilMemberAccess
let output_encoding os e =
match e with
| ILDefaultPInvokeEncoding.Ansi -> output_string os " ansi "
| ILDefaultPInvokeEncoding.Auto -> output_string os " autochar "
| ILDefaultPInvokeEncoding.Unicode -> output_string os " unicode "
let output_field_init os =
function
| ILFieldInit.String s ->
output_string os "= "
output_string os s
| ILFieldInit.Bool x ->
output_string os "= bool"
output_parens output_string os (if x then "true" else "false")
| ILFieldInit.Char x ->
output_string os "= char"
output_parens output_u16 os x
| ILFieldInit.Int8 x ->
output_string os "= int8"
output_parens output_i8 os x
| ILFieldInit.Int16 x ->
output_string os "= int16"
output_parens output_i16 os x
| ILFieldInit.Int32 x ->
output_string os "= int32"
output_parens output_i32 os x
| ILFieldInit.Int64 x ->
output_string os "= int64"
output_parens output_i64 os x
| ILFieldInit.UInt8 x ->
output_string os "= uint8"
output_parens output_u8 os x
| ILFieldInit.UInt16 x ->
output_string os "= uint16"
output_parens output_u16 os x
| ILFieldInit.UInt32 x ->
output_string os "= uint32"
output_parens output_u32 os x
| ILFieldInit.UInt64 x ->
output_string os "= uint64"
output_parens output_u64 os x
| ILFieldInit.Single x ->
output_string os "= float32"
output_parens output_ieee32 os x
| ILFieldInit.Double x ->
output_string os "= float64"
output_parens output_ieee64 os x
| ILFieldInit.Null -> output_string os "= nullref"
let output_at os b =
Printf.fprintf os " at (* no labels for data available, data = %a *)" (output_parens output_bytes) b
let output_option f os =
function
| None -> ()
| Some x -> f os x
let output_custom_attr_data os data =
output_string os " = "
output_parens output_bytes os data
let goutput_custom_attr env os (attr: ILAttribute) =
output_string os " .custom "
goutput_mspec env os attr.Method
let data = getCustomAttrData attr
output_custom_attr_data os data
let goutput_custom_attrs env os (attrs: ILAttributes) =
Array.iter
(fun attr ->
goutput_custom_attr env os attr
output_string os "\n")
(attrs.AsArray())
let goutput_fdef _tref env os (fd: ILFieldDef) =
output_string os " .field "
match fd.Offset with
| Some i ->
output_string os "["
output_i32 os i
output_string os "] "
| None -> ()
match fd.Marshal with
| Some _i -> output_string os "// marshal attribute not printed\n"
| None -> ()
output_member_access os fd.Access
output_string os " "
if fd.IsStatic then
output_string os " static "
if fd.IsLiteral then
output_string os " literal "
if fd.IsSpecialName then
output_string os " specialname rtspecialname "
if fd.IsInitOnly then
output_string os " initonly "
if fd.NotSerialized then
output_string os " notserialized "
goutput_typ env os fd.FieldType
output_string os " "
output_id os fd.Name
output_option output_at os fd.Data
output_option output_field_init os fd.LiteralValue
output_string os "\n"
goutput_custom_attrs env os fd.CustomAttrs
let rec goutput_apps env os =
function
| Apps_tyapp(actual, cs) ->
output_angled (goutput_gactual env) os actual
output_string os " "
output_angled (goutput_gparam env) os (mkILSimpleTypar "T")
output_string os " "
goutput_apps env os cs
| Apps_app(ty, cs) ->
output_parens (goutput_typ env) os ty
output_string os " "
goutput_apps env os cs
| Apps_done ty ->
output_string os "--> "
goutput_typ env os ty
let goutput_local env os (l: ILLocal) =
goutput_typ env os l.Type
if l.IsPinned then
output_string os " pinned"
let goutput_param env os (l: ILParameter) =
match l.Name with
| None -> goutput_typ env os l.Type
| Some n ->
goutput_typ env os l.Type
output_string os " "
output_sqstring os n
let goutput_params env os ps =
output_parens (output_seq ", " (goutput_param env)) os ps
let goutput_ilmbody env os (il: ILMethodBody) =
if il.IsZeroInit then
output_string os " .zeroinit\n"
output_string os " .maxstack "
output_i32 os il.MaxStack
output_string os "\n"
if il.Locals.Length <> 0 then
output_string os " .locals("
output_seq ", \n " (goutput_local env) os il.Locals
output_string os ")\n"
let goutput_mbody is_entrypoint env os (md: ILMethodDef) =
if md.ImplAttributes &&& MethodImplAttributes.Native <> enum 0 then
output_string os "native "
elif md.ImplAttributes &&& MethodImplAttributes.IL <> enum 0 then
output_string os "cil "
else
output_string os "runtime "
output_string os (if md.IsInternalCall then "internalcall " else " ")
output_string os (if md.IsManaged then "managed " else " ")
output_string os (if md.IsForwardRef then "forwardref " else " ")
output_string os " \n{ \n"
goutput_security_decls env os md.SecurityDecls
goutput_custom_attrs env os md.CustomAttrs
match md.Body with
| MethodBody.IL il -> goutput_ilmbody env os il.Value
| _ -> ()
if is_entrypoint then
output_string os " .entrypoint"
output_string os "\n"
output_string os "}\n"
let goutput_mdef env os (md: ILMethodDef) =
let attrs =
if md.IsVirtual then
"virtual "
+ (if md.IsFinal then "final " else "")
+ (if md.IsNewSlot then "newslot " else "")
+ (if md.IsCheckAccessOnOverride then " strict " else "")
+ (if md.IsAbstract then " abstract " else "")
+ " "
elif md.IsNonVirtualInstance then
""
elif md.IsConstructor then
"rtspecialname"
elif md.IsStatic then
"static "
+ (match md.Body with
| MethodBody.PInvoke attrLazy ->
let attr = attrLazy.Value
"pinvokeimpl(\""
+ attr.Where.Name
+ "\" as \""
+ attr.Name
+ "\""
+ (match attr.CallingConv with
| PInvokeCallingConvention.None -> ""
| PInvokeCallingConvention.Cdecl -> " cdecl"
| PInvokeCallingConvention.Stdcall -> " stdcall"
| PInvokeCallingConvention.Thiscall -> " thiscall"
| PInvokeCallingConvention.Fastcall -> " fastcall"
| PInvokeCallingConvention.WinApi -> " winapi")
+
(match attr.CharEncoding with
| PInvokeCharEncoding.None -> ""
| PInvokeCharEncoding.Ansi -> " ansi"
| PInvokeCharEncoding.Unicode -> " unicode"
| PInvokeCharEncoding.Auto -> " autochar")
+
(if attr.NoMangle then " nomangle" else "")
+ (if attr.LastError then " lasterr" else "")
+ ")"
| _ -> "")
elif md.IsClassInitializer then
"specialname rtspecialname static"
else
""
let is_entrypoint = md.IsEntryPoint
let menv = ppenv_enter_method (List.length md.GenericParams) env
output_string os " .method "
if md.IsHideBySig then
output_string os "hidebysig "
if md.IsReqSecObj then
output_string os "reqsecobj "
if md.IsSpecialName then
output_string os "specialname "
if md.IsUnmanagedExport then
output_string os "unmanagedexp "
output_member_access os md.Access
output_string os " "
output_string os attrs
output_string os " "
output_callconv os md.CallingConv
output_string os " "
(goutput_typ menv) os md.Return.Type
output_string os " "
output_id os md.Name
output_string os " "
(goutput_gparams env) os md.GenericParams
output_string os " "
(goutput_params menv) os md.Parameters
output_string os " "
if md.IsSynchronized then
output_string os "synchronized "
if md.IsMustRun then
output_string os "/* mustrun */ "
if md.IsPreserveSig then
output_string os "preservesig "
if md.IsNoInline then
output_string os "noinlining "
if md.IsAggressiveInline then
output_string os "aggressiveinlining "
(goutput_mbody is_entrypoint menv) os md
output_string os "\n"
let goutput_pdef env os (pd: ILPropertyDef) =
output_string os "property\n\tgetter: "
(match pd.GetMethod with
| None -> ()
| Some mref -> goutput_mref env os mref)
output_string os "\n\tsetter: "
(match pd.SetMethod with
| None -> ()
| Some mref -> goutput_mref env os mref)
let goutput_superclass env os =
function
| None -> ()
| Some typ ->
output_string os "extends "
(goutput_typ_with_shortened_class_syntax env) os typ
let goutput_implements env os (imp: InterfaceImpl list) =
if not (List.isEmpty imp) then
let imp = imp |> Seq.map _.Type
output_string os "implements "
output_seq ", " (goutput_typ_with_shortened_class_syntax env) os imp
let the =
function
| Some x -> x
| None -> failwith "the"
let output_type_layout_info os info =
if info.Size <> None then
(output_string os " .size "
output_i32 os (the info.Size))
if info.Pack <> None then
(output_string os " .pack "
output_u16 os (the info.Pack))
let splitTypeLayout =
function
| ILTypeDefLayout.Auto -> "auto", (fun _os () -> ())
| ILTypeDefLayout.Sequential info -> "sequential", (fun os () -> output_type_layout_info os info)
| ILTypeDefLayout.Explicit info -> "explicit", (fun os () -> output_type_layout_info os info)
let goutput_fdefs tref env os (fdefs: ILFieldDefs) =
for f in fdefs.AsList() do
goutput_fdef tref env os f
output_string os "\n"
let goutput_mdefs env os (mdefs: ILMethodDefs) =
for f in mdefs.AsArray() do
goutput_mdef env os f
output_string os "\n"
let goutput_pdefs env os (pdefs: ILPropertyDefs) =
for f in pdefs.AsList() do
goutput_pdef env os f
output_string os "\n"
let rec goutput_tdef enc env contents os (cd: ILTypeDef) =
let env = ppenv_enter_tdef cd.GenericParams env
let layout_attr, pp_layout_decls = splitTypeLayout cd.Layout
if isTypeNameForGlobalFunctions cd.Name then
if contents then
let tref = (mkILNestedTyRef (ILScopeRef.Local, enc, cd.Name))
goutput_mdefs env os cd.Methods
goutput_fdefs tref env os cd.Fields
goutput_pdefs env os cd.Properties
else
output_string os "\n"
if cd.IsInterface then
output_string os ".class interface "
else
output_string os ".class "
output_init_semantics os cd.Attributes
output_string os " "
output_type_access os cd.Access
output_string os " "
output_encoding os cd.Encoding
output_string os " "
output_string os layout_attr
output_string os " "
if cd.IsSealed then
output_string os "sealed "
if cd.IsAbstract then
output_string os "abstract "
if cd.IsSerializable then
output_string os "serializable "
if cd.IsComInterop then
output_string os "import "
output_sqstring os cd.Name
goutput_gparams env os cd.GenericParams
output_string os "\n\t"
goutput_superclass env os cd.Extends.Value
output_string os "\n\t"
goutput_implements env os cd.Implements.Value
output_string os "\n{\n "
if contents then
let tref = (mkILNestedTyRef (ILScopeRef.Local, enc, cd.Name))
goutput_custom_attrs env os cd.CustomAttrs
goutput_security_decls env os cd.SecurityDecls
pp_layout_decls os ()
goutput_fdefs tref env os cd.Fields
goutput_mdefs env os cd.Methods
goutput_tdefs contents (enc @ [ cd.Name ]) env os cd.NestedTypes
output_string os "\n}"
and output_init_semantics os f =
if f &&& TypeAttributes.BeforeFieldInit <> enum 0 then
output_string os "beforefieldinit"
and goutput_lambdas env os lambdas =
match lambdas with
| Lambdas_forall(gf, l) ->
output_angled (goutput_gparam env) os gf
output_string os " "
(goutput_lambdas env) os l
| Lambdas_lambda(ps, l) ->
output_parens (goutput_param env) os ps
output_string os " "
(goutput_lambdas env) os l
| Lambdas_return typ ->
output_string os "--> "
(goutput_typ env) os typ
and goutput_tdefs contents enc env os (tds: ILTypeDefs) =
for td in tds.AsList() do
goutput_tdef enc env contents os td
let output_ver os (version: ILVersionInfo) =
output_string os " .ver "
output_u16 os version.Major
output_string os " : "
output_u16 os version.Minor
output_string os " : "
output_u16 os version.Build
output_string os " : "
output_u16 os version.Revision
let output_locale os s =
output_string os " .Locale "
output_qstring os s
let output_publickey os x =
output_string os " .publickey = "
output_parens output_bytes os x
let goutput_resource env os r =
output_string os " .mresource "
output_string
os
(match r.Access with
| ILResourceAccess.Public -> " public "
| ILResourceAccess.Private -> " private ")
output_sqstring os r.Name
output_string os " { "
goutput_custom_attrs env os r.CustomAttrs
match r.Location with
| ILResourceLocation.Local _ -> output_string os " /* loc nyi */ "
| ILResourceLocation.File(mref, off) ->
output_string os " .file "
output_sqstring os mref.Name
output_string os " at "
output_i32 os off
| ILResourceLocation.Assembly aref ->
output_string os " .assembly extern "
output_sqstring os aref.Name
output_string os " }\n "
let goutput_manifest env os m =
output_string os " .assembly "
match m.AssemblyLongevity with
| ILAssemblyLongevity.Unspecified -> ()
| ILAssemblyLongevity.Library -> output_string os "library "
| ILAssemblyLongevity.PlatformAppDomain -> output_string os "platformappdomain "
| ILAssemblyLongevity.PlatformProcess -> output_string os "platformprocess "
| ILAssemblyLongevity.PlatformSystem -> output_string os "platformmachine "
output_sqstring os m.Name
output_string os " { \n"
output_string os ".hash algorithm "
output_i32 os m.AuxModuleHashAlgorithm
output_string os "\n"
goutput_custom_attrs env os m.CustomAttrs
output_option output_publickey os m.PublicKey
output_option output_ver os m.Version
output_option output_locale os m.Locale
output_string os " } \n"
let output_module_fragment_aux os (ilg: ILGlobals) modul =
let env = mk_ppenv ilg
let env = ppenv_enter_modul env
goutput_tdefs false [] env os modul.TypeDefs
goutput_tdefs true [] env os modul.TypeDefs
let goutput_module_manifest env os modul =
output_string os " .module "
output_sqstring os modul.Name
goutput_custom_attrs env os modul.CustomAttrs
output_string os " .imagebase "
output_i32 os modul.ImageBase
output_string os " .file alignment "
output_i32 os modul.PhysicalAlignment
output_string os " .subsystem "
output_i32 os modul.SubSystemFlags
output_string os " .corflags "
output_i32
os
((if modul.IsILOnly then 0x0001 else 0)
||| (if modul.Is32Bit then 0x0002 else 0)
||| (if modul.Is32BitPreferred then 0x00020003 else 0))
List.iter (fun r -> goutput_resource env os r) (modul.Resources.AsList())
output_string os "\n"
output_option (goutput_manifest env) os modul.Manifest
let output_module os (ilg: ILGlobals) modul =
let env = mk_ppenv ilg
let env = ppenv_enter_modul env
goutput_module_manifest env os modul
output_module_fragment_aux os ilg modul
#endif