il.fsi 72.1 KB
Newer Older
1
// Copyright (c) Microsoft Corporation.  All Rights Reserved.  See License.txt in the project root for license information.
L
latkin 已提交
2 3 4

/// The "unlinked" view of .NET metadata and code.  Central to 
///  to Abstract IL library
D
Don Syme 已提交
5
module public Microsoft.FSharp.Compiler.AbstractIL.IL 
L
latkin 已提交
6 7 8

open Internal.Utilities
open System.Collections.Generic
A
Avi Avni 已提交
9
open System.Reflection
L
latkin 已提交
10

11
[<RequireQualifiedAccess>]
D
desco 已提交
12 13
type PrimaryAssembly = 
    | Mscorlib
14 15
    | System_Runtime
    | NetStandard
D
desco 已提交
16 17

    member Name: string
L
latkin 已提交
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

// ====================================================================
// .NET binaries can be converted to the data structures below by using 
// the functions in the "Ilread" module. 
//
// Constituent types are listed in ascending order of complexity, 
// all the way up to the type ILModuleDef, representing the read of an IL 
// assembly (.dll or .exe), or part of a multi-module assembly.  Types are 
// often specified via a concrete representation for the type (e.g. a record), 
// though some types are abstract. 
//
// The second part of the file (after the definition of all the types) 
// specifies a large set of utilities for building objects belonging to 
// the types.  You will only need to become familiar with these if you 
// are transforming code or writing a code-generating compiler.
// 
// Several other utilities are also defined in this file:
//   1. A code builder for turning linear sequences of instructions 
//      augmented with exception tables into the more structured 
//      format used for code.  
//
//   2. The "typ_XYZ", "tspec_XYZ" and "mspec_XYZ" values which 
//      can be used to reference types in the "primary assembly (either System.Runtime or mscorlib)" assembly.
//
//   3. The "rescopeXYZ" functions which can be used to lift a piece of
//      metadata from one assembly and transform it to a piece of metadata
//      suitable for use from another assembly.  The transformation adjusts
//      references in the metadata to take into account the assembly
//      where the metadata will now be located.
//
//   4. The "instantiateXYZ" utilities to replace type variables
//      by types.  These are associated with generics.
//
//   5. The "intern_XYZ" tables for reducing the memory used by 
//      generated constructs.
//
//   6. The "refs_of_XYZ" utilities for finding all the assemblies 
//      referenced by a module.
//
//   7. A somewhat obscure facility to allow new instructions and types
//      to be added to the   This is only used by ILX.
// ==================================================================== 

// Guids (Note: consider adjusting these to the System.Guid type)
D
Don Syme 已提交
62
type ILGuid = byte[]
L
latkin 已提交
63 64 65 66 67 68 69 70 71 72 73

[<StructuralEquality; StructuralComparison>]
type ILPlatform = 
    | X86
    | AMD64
    | IA64

/// Debug info.  Values of type "source" can be attached at sequence 
/// points and some other locations. 
[<Sealed>]
type ILSourceDocument =
D
Don Syme 已提交
74 75 76 77
    static member Create : language: ILGuid option * vendor: ILGuid option * documentType: ILGuid option * file: string -> ILSourceDocument
    member Language: ILGuid option
    member Vendor: ILGuid option
    member DocumentType: ILGuid option
L
latkin 已提交
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
    member File: string


[<Sealed>]
type ILSourceMarker =
    static member Create : document: ILSourceDocument * line: int * column: int * endLine:int * endColumn: int-> ILSourceMarker
    member Document: ILSourceDocument
    member Line: int
    member Column: int
    member EndLine: int
    member EndColumn: int

[<StructuralEquality; StructuralComparison>]
type PublicKey = 
    | PublicKey of byte[]
    | PublicKeyToken of byte[]
    member IsKey: bool
    member IsKeyToken: bool
    member Key: byte[]
    member KeyToken: byte[]
D
Don Syme 已提交
98
    static member KeyAsToken: byte[] -> PublicKey 
L
latkin 已提交
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

type ILVersionInfo = uint16 * uint16 * uint16 * uint16

[<Sealed>]
type ILAssemblyRef =
    static member Create : name: string * hash: byte[] option * publicKey: PublicKey option * retargetable: bool * version: ILVersionInfo option * locale: string option -> ILAssemblyRef
    static member FromAssemblyName : System.Reflection.AssemblyName -> ILAssemblyRef
    member Name: string;
    /// The fully qualified name of the assembly reference, e.g. mscorlib, Version=1.0.3705 etc.
    member QualifiedName: string; 
    member Hash: byte[] option;
    member PublicKey: PublicKey option;
    /// CLI says this indicates if the assembly can be retargeted (at runtime) to be from a different publisher. 
    member Retargetable: bool;
    member Version: ILVersionInfo option;
    member Locale: string option
    interface System.IComparable

[<Sealed>]
type ILModuleRef =
    static member Create : name: string * hasMetadata: bool * hash: byte[] option -> ILModuleRef
    member Name: string
    member HasMetadata: bool
    member Hash: byte[] option
    interface System.IComparable

// Scope references
//
// Scope references are the bits of metadata attached to type names
// that indicate where a type can be found. CIL has three 
// kinds: local, module and assembly references:
//   o Local: the type must reside in the same module as the scope reference
//   o Module: the type must reside in the indicated module in the same
//     assembly as the scope reference
//   o Assembly: The type must reside in the indicated assembly.
//     These have no implicit context. Assembly references can end up 
//     binding to the assembly containing the reference, i.e. 
//     may be self or mutually referential.
//
//     Assembly reference may also resolve to type in an 
//     auxiliary module of an assembly when the assembly 
//     has an "exported types" (here called "classes elsewhere") table.
//
// We represent these references by values embedded within type
// references.  These values are usually "shared" across the data
// structures for a module, i.e. one such value is created for each
// assembly or module reference, and this value is reused within each
// type object.
//
// Note that as with method references the term structure is not 
// _linked_, i.e. a "ILScopeRef" is still a _reference_ to a scope, 
// not the scope itself.  Because the structure is not linked, 
// the Abstract IL toolset does not require 
// strongly connected inputs: you can manipulate an assembly
// without loading all its dependent assemblies.  This is the primary
// difference between Abstract IL and Reflection, and it can be both
// a blessing and a curse depending on the kind of manipulation you
// wish to perform.
//
// Similarly, you can manipulate individual modules within
// an assembly without having the whole assembly loaded.  (But note that
// most assemblies are single-module in any case).
//
// [ILScopeRef]'s _cannot_ be compared for equality in the way that
// might be expected, in these sense that two ILScopeRef's may 
// resolve to the same assembly/module even though they are not equal.  
//
//   Aside: People have suggested normalizing all scope references
//          so that this would be possible, and early versions of this
//          toolkit did this.  However, this meant that in order to load
//          each module you had to tell the toolkit which assembly it belonged to.
//          Furthermore, you had to know the exact resolved details of 
//          each assembly the module refers to.  This is
//          effectively like having a "fully-linked" view of the graph
//          of assemblies, like that provided in the Ilbind module.  This is really problematic for compile-time tools,
//          as, for example, the policy for linking at the runtime-machine
//          may actually alter the results of linking.  If such compile-time
//          assumptions are to be made then the tool built on top
//          of the toolkit rather than the toolkit itself should
//          make them.
//
// Scope references, type references, field references and method references
// can be "bound" to particular assemblies using the functions in "Ilbind".  
// This simulates the resolution/binding process performed by a Common Language
// Runtime during execution.  Various tests and derived operations
// can then be performed on the results of binding.  
[<StructuralEquality; StructuralComparison>]
[<RequireQualifiedAccess>]
type ILScopeRef = 
    /// A reference to the type in the current module
    | Local 
    /// A reference to a type in a module in the same assembly
    | Module of ILModuleRef   
    /// A reference to a type in another assembly
    | Assembly of ILAssemblyRef  
    member IsLocalRef: bool
    member IsModuleRef: bool
    member IsAssemblyRef: bool
    member ModuleRef: ILModuleRef
    member AssemblyRef: ILAssemblyRef
    member QualifiedName: string

// Calling conventions.  
//
// For nearly all purposes you simply want to use ILArgConvention.Default combined
// with ILThisConvention.Instance or ILThisConvention.Static, i.e.
//   ILCallingConv.Instance == Callconv(ILThisConvention.Instance, ILArgConvention.Default): for an instance method
//   ILCallingConv.Static   == Callconv(ILThisConvention.Static, ILArgConvention.Default): for a static method
//
// ILThisConvention.InstanceExplicit is only used by Managed C++, and indicates 
// that the 'this' pointer is actually explicit in the signature. 
[<StructuralEquality; StructuralComparison; RequireQualifiedAccess>]
type ILArgConvention = 
    | Default
    | CDecl 
    | StdCall 
    | ThisCall 
    | FastCall 
    | VarArg
      
[<StructuralEquality; StructuralComparison; RequireQualifiedAccess>]
type ILThisConvention =
    /// accepts an implicit 'this' pointer 
    | Instance           
    /// accepts an explicit 'this' pointer 
    | InstanceExplicit  
    /// no 'this' pointer is passed
    | Static             

[<StructuralEquality; StructuralComparison>]
type ILCallingConv =
    | Callconv of ILThisConvention * ILArgConvention
    member IsInstance : bool
    member IsInstanceExplicit : bool
    member IsStatic : bool
    member ThisConv : ILThisConvention
    member BasicConv : ILArgConvention
    static member Instance : ILCallingConv
    static member Static   : ILCallingConv

/// Array shapes. For most purposes, including verification, the
/// rank is the only thing that matters.
 
type ILArrayBound = int32 option 
type ILArrayBounds = ILArrayBound * ILArrayBound

[<StructuralEquality; StructuralComparison>]
type ILArrayShape =
    | ILArrayShape of ILArrayBounds list // lobound/size pairs 
    member Rank : int
    /// Bounds for a single dimensional, zero based array 
    static member SingleDimensional: ILArrayShape
    static member FromRank : int -> ILArrayShape

[<StructuralEquality; StructuralComparison>]
type ILBoxity = 
    | AsObject
    | AsValue

type ILGenericVariance = 
    | NonVariant            
    | CoVariant             
    | ContraVariant         

/// Type refs, i.e. references to types in some .NET assembly
[<Sealed>]
type ILTypeRef =
266

W
WilliamBerryiii 已提交
267
    /// Create a ILTypeRef.
L
latkin 已提交
268 269 270 271
    static member Create : scope: ILScopeRef * enclosing: string list * name: string -> ILTypeRef

    /// Where is the type, i.e. is it in this module, in another module in this assembly or in another assembly? 
    member Scope: ILScopeRef
272

L
latkin 已提交
273 274
    /// The list of enclosing type names for a nested type. If non-nil then the first of these also contains the namespace.
    member Enclosing: string list
275

W
WilliamBerryiii 已提交
276
    /// The name of the type. This also contains the namespace if Enclosing is empty.
L
latkin 已提交
277
    member Name: string
278

W
WilliamBerryiii 已提交
279
    /// The name of the type in the assembly using the '.' notation for nested types.
L
latkin 已提交
280
    member FullName: string
281

W
WilliamBerryiii 已提交
282
    /// The name of the type in the assembly using the '+' notation for nested types.
L
latkin 已提交
283
    member BasicQualifiedName : string
284

L
latkin 已提交
285
    member QualifiedName: string
286

287
#if !NO_EXTENSIONTYPING
L
latkin 已提交
288 289
    member QualifiedNameWithNoShortPrimaryAssembly: string
#endif
290

L
latkin 已提交
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307
    interface System.IComparable
    
/// Type specs and types.  
///
/// These are the types that appear syntactically in .NET binaries.  
///
/// Generic type definitions must be combined with
/// an instantiation to form a type.  Throughout this file, 
/// a "ref" refers to something that is uninstantiated, and
/// a "spec" to a ref that is combined with the relevant instantiations.
 
[<Sealed>]
type ILTypeSpec =
    static member Create : typeRef:ILTypeRef * instantiation:ILGenericArgs -> ILTypeSpec

    /// Which type is being referred to?
    member TypeRef: ILTypeRef
308

L
latkin 已提交
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
    /// The type instantiation if the type is generic, otherwise empty
    member GenericArgs: ILGenericArgs
    member Scope: ILScopeRef
    member Enclosing: string list
    member Name: string
    member FullName: string
    interface System.IComparable

and 
    [<RequireQualifiedAccess; StructuralEquality; StructuralComparison>]
    ILType =
    /// Used only in return and pointer types.
    | Void                   
    /// Array types 
    | Array of ILArrayShape * ILType 
    /// Unboxed types, including builtin types.
    | Value of ILTypeSpec     
    /// Reference types.  Also may be used for parents of members even if for members in value types. 
    | Boxed of ILTypeSpec     
    /// Unmanaged pointers.  Nb. the type is used by tools and for binding only, not by the verifier.
    | Ptr of ILType             
    /// Managed pointers.
    | Byref of ILType           
    /// ILCode pointers. 
    | FunctionPointer of ILCallingSignature        
    /// Reference a generic arg. 
    | TypeVar of uint16           
    /// Custom modifiers. 
    | Modified of            
W
WilliamBerryiii 已提交
338
          /// True if modifier is "required". 
L
latkin 已提交
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361
          bool *                  
          /// The class of the custom modifier. 
          ILTypeRef *                   
          /// The type being modified. 
          ILType                     
    member TypeSpec : ILTypeSpec
    member Boxity : ILBoxity
    member TypeRef : ILTypeRef
    member IsNominal : bool
    member GenericArgs : ILGenericArgs
    member IsTyvar : bool
    member BasicQualifiedName : string
    member QualifiedNameWithNoShortPrimaryAssembly : string

and [<StructuralEquality; StructuralComparison>]
    ILCallingSignature =  
    { CallingConv: ILCallingConv;
      ArgTypes: ILTypes;
      ReturnType: ILType }

/// Actual generic parameters are  always types.  


362 363
and ILGenericArgs = list<ILType>
and ILTypes = list<ILType>
L
latkin 已提交
364 365 366 367 368 369 370 371 372 373 374 375

/// Formal identities of methods.  Method refs refer to methods on 
/// named types.  In general you should work with ILMethodSpec objects
/// rather than MethodRef objects, because ILMethodSpec objects carry
/// information about how generic methods are instantiated.  MethodRef
/// objects are only used at a few places in the Abstract IL syntax
/// and if analyzing or generating IL you will be unlikely to come across
/// these.

[<Sealed>]
type ILMethodRef =
     static member Create : enclosingTypeRef: ILTypeRef * callingConv: ILCallingConv * name: string * genericArity: int * argTypes: ILTypes * returnType: ILType -> ILMethodRef
376
     member DeclaringTypeRef: ILTypeRef
L
latkin 已提交
377 378 379 380 381 382 383 384 385 386 387 388 389
     member CallingConv: ILCallingConv
     member Name: string
     member GenericArity: int
     member ArgCount: int
     member ArgTypes: ILTypes
     member ReturnType: ILType
     member CallingSignature: ILCallingSignature
     interface System.IComparable
     
/// Formal identities of fields.
 
[<StructuralEquality; StructuralComparison>]
type ILFieldRef = 
390
    { DeclaringTypeRef: ILTypeRef;
L
latkin 已提交
391 392 393 394 395 396
      Name: string;
      Type: ILType }

/// The information at the callsite of a method
//
// A ILMethodSpec is everything given at the callsite (apart from whether the call is a tailcall and whether it is passing
W
WilliamBerryiii 已提交
397
// varargs - see the instruction set below).  It is made up of: 
L
latkin 已提交
398 399 400 401 402 403 404 405 406 407 408 409 410
//   1) a (possibly generic) ILMethodRef
//   2) a "usage type" that indicates the how the type containing the declaration is being used (as
//      a value class, a boxed value class, an instantiated generic class or whatever - see below)
//   3) an instantiation in the case where the method is generic.
//
// In this unbound form of the metadata, the enclosing type may be ILType.Boxed even when the member is a member of a value type or
// enumeration.  This is because the binary format of the metadata does not carry enough information in a MemberRefParent to determine
// from the binary alone whether the enclosing type is a value type or not.

[<Sealed>]
type ILMethodSpec =
     static member Create : ILType * ILMethodRef * ILGenericArgs -> ILMethodSpec
     member MethodRef: ILMethodRef
411
     member DeclaringType: ILType 
L
latkin 已提交
412 413 414 415 416 417 418 419 420 421 422 423 424
     member GenericArgs: ILGenericArgs
     member CallingConv: ILCallingConv
     member GenericArity: int
     member Name: string
     member FormalArgTypes: ILTypes
     member FormalReturnType: ILType
     interface System.IComparable
      

/// Field specs.  The data given for a ldfld, stfld etc. instruction.
[<StructuralEquality; StructuralComparison>]    
type ILFieldSpec =
    { FieldRef: ILFieldRef;
425 426
      DeclaringType: ILType }    
    member DeclaringTypeRef: ILTypeRef
L
latkin 已提交
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
    member Name: string
    member FormalType: ILType
    member ActualType : ILType

/// ILCode labels.  In structured code each code label
/// refers to a basic block somewhere in the code of the method.

type ILCodeLabel = int

[<StructuralEquality; StructuralComparison>]
type ILBasicType =
    | DT_R
    | DT_I1
    | DT_U1
    | DT_I2
    | DT_U2
    | DT_I4
    | DT_U4
    | DT_I8
    | DT_U8
    | DT_R4
    | DT_R8
    | DT_I
    | DT_U
    | DT_REF

[<StructuralEquality; StructuralComparison; RequireQualifiedAccess>]
type ILToken = 
    | ILType of ILType 
    | ILMethod of ILMethodSpec 
    | ILField of ILFieldSpec

[<StructuralEquality; StructuralComparison; RequireQualifiedAccess>]
type ILConst = 
    | I4 of int32
    | I8 of int64
    | R4 of single
    | R8 of double

type ILTailcall = 
    | Tailcall
    | Normalcall

type ILAlignment = 
    | Aligned
    | Unaligned1
    | Unaligned2
    | Unaligned4

type ILVolatility = 
    | Volatile
    | Nonvolatile

type ILReadonly = 
    | ReadonlyAddress
    | NormalAddress

type ILVarArgs = ILTypes option

[<StructuralEquality; StructuralComparison>]
type ILComparisonInstr = 
    | BI_beq        
    | BI_bge        
    | BI_bge_un     
    | BI_bgt        
    | BI_bgt_un        
    | BI_ble        
    | BI_ble_un        
    | BI_blt        
    | BI_blt_un 
    | BI_bne_un 
    | BI_brfalse 
    | BI_brtrue 

/// The instruction set.                                                     
///
/// In general we don't categorize instructions, as different 
/// instruction groups are relevant for different types of operations. 
/// However we do collect the branch and compare instructions together 
/// because they all take an address, and the ILArithInstr ones because 
/// none of them take any direct arguments. 
[<StructuralEquality; NoComparison>]
type ILInstr = 
    // Basic 
    | AI_add    
    | AI_add_ovf
    | AI_add_ovf_un
    | AI_and    
    | AI_div   
    | AI_div_un
    | AI_ceq      
    | AI_cgt      
    | AI_cgt_un   
    | AI_clt     
    | AI_clt_un  
    | AI_conv      of ILBasicType
    | AI_conv_ovf  of ILBasicType
    | AI_conv_ovf_un  of ILBasicType
    | AI_mul       
    | AI_mul_ovf   
    | AI_mul_ovf_un
    | AI_rem       
    | AI_rem_un       
    | AI_shl       
    | AI_shr       
    | AI_shr_un
    | AI_sub       
    | AI_sub_ovf   
    | AI_sub_ovf_un   
    | AI_xor       
    | AI_or        
    | AI_neg       
    | AI_not       
    | AI_ldnull    
    | AI_dup       
    | AI_pop
    | AI_ckfinite 
    | AI_nop
    | AI_ldc       of ILBasicType * ILConst
    | I_ldarg     of uint16
    | I_ldarga    of uint16
    | I_ldind     of ILAlignment * ILVolatility * ILBasicType
    | I_ldloc     of uint16
    | I_ldloca    of uint16
    | I_starg     of uint16
    | I_stind     of  ILAlignment * ILVolatility * ILBasicType
    | I_stloc     of uint16

    // Control transfer 
    | I_br    of  ILCodeLabel
    | I_jmp   of ILMethodSpec
D
Don Syme 已提交
558 559
    | I_brcmp of ILComparisonInstr * ILCodeLabel 
    | I_switch    of ILCodeLabel list 
L
latkin 已提交
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
    | I_ret 

     // Method call 
    | I_call     of ILTailcall * ILMethodSpec * ILVarArgs
    | I_callvirt of ILTailcall * ILMethodSpec * ILVarArgs
    | I_callconstraint of ILTailcall * ILType * ILMethodSpec * ILVarArgs
    | I_calli    of ILTailcall * ILCallingSignature * ILVarArgs
    | I_ldftn    of ILMethodSpec
    | I_newobj   of ILMethodSpec  * ILVarArgs
    
    // Exceptions 
    | I_throw
    | I_endfinally
    | I_endfilter
    | I_leave     of  ILCodeLabel
    | I_rethrow

    // Object instructions 
    | I_ldsfld      of ILVolatility * ILFieldSpec
    | I_ldfld       of ILAlignment * ILVolatility * ILFieldSpec
    | I_ldsflda     of ILFieldSpec
    | I_ldflda      of ILFieldSpec 
    | I_stsfld      of ILVolatility  *  ILFieldSpec
    | I_stfld       of ILAlignment * ILVolatility * ILFieldSpec
    | I_ldstr       of string
    | I_isinst      of ILType
    | I_castclass   of ILType
    | I_ldtoken     of ILToken
    | I_ldvirtftn   of ILMethodSpec

    // Value type instructions 
    | I_cpobj       of ILType
    | I_initobj     of ILType
    | I_ldobj       of ILAlignment * ILVolatility * ILType
    | I_stobj       of ILAlignment * ILVolatility * ILType
    | I_box         of ILType
    | I_unbox       of ILType
    | I_unbox_any   of ILType
    | I_sizeof      of ILType

    // Generalized array instructions. In AbsIL these instructions include 
    // both the single-dimensional variants (with ILArrayShape == ILArrayShape.SingleDimensional) 
W
WilliamBerryiii 已提交
602
    // and calls to the "special" multi-dimensional "methods" such as: 
L
latkin 已提交
603 604 605 606
    //   newobj void string[,]::.ctor(int32, int32) 
    //   call string string[,]::Get(int32, int32) 
    //   call string& string[,]::Address(int32, int32) 
    //   call void string[,]::Set(int32, int32,string) 
W
WilliamBerryiii 已提交
607
    //
L
latkin 已提交
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
    // The IL reader transforms calls of this form to the corresponding 
    // generalized instruction with the corresponding ILArrayShape 
    // argument. This is done to simplify the IL and make it more uniform. 
    // The IL writer then reverses this when emitting the binary. 
    | I_ldelem      of ILBasicType
    | I_stelem      of ILBasicType
    | I_ldelema     of ILReadonly * bool * ILArrayShape * ILType (* ILArrayShape = ILArrayShape.SingleDimensional for single dimensional arrays *)
    | I_ldelem_any  of ILArrayShape * ILType (* ILArrayShape = ILArrayShape.SingleDimensional for single dimensional arrays *)
    | I_stelem_any  of ILArrayShape * ILType (* ILArrayShape = ILArrayShape.SingleDimensional for single dimensional arrays *)
    | I_newarr      of ILArrayShape * ILType (* ILArrayShape = ILArrayShape.SingleDimensional for single dimensional arrays *)
    | I_ldlen

    // "System.TypedReference" related instructions: almost 
    // no languages produce these, though they do occur in mscorlib.dll 
    // System.TypedReference represents a pair of a type and a byref-pointer
    // to a value of that type. 
    | I_mkrefany    of ILType
    | I_refanytype  
    | I_refanyval   of ILType
    
    // Debug-specific 
    // I_seqpoint is a fake instruction to represent a sequence point: 
    // the next instruction starts the execution of the 
    // statement covered by the given range - this is a 
    // dummy instruction and is not emitted 
    | I_break 
    | I_seqpoint of ILSourceMarker 

    // Varargs - C++ only 
    | I_arglist  

    // Local aggregates, i.e. stack allocated data (alloca) : C++ only 
    | I_localloc
    | I_cpblk of ILAlignment * ILVolatility
    | I_initblk of ILAlignment  * ILVolatility

    // EXTENSIONS, e.g. MS-ILX 
    | EI_ilzero of ILType
    | EI_ldlen_multi      of int32 * int32


D
Don Syme 已提交
649 650 651 652 653 654
[<RequireQualifiedAccess>]
type ILExceptionClause = 
    | Finally of (ILCodeLabel * ILCodeLabel)
    | Fault  of (ILCodeLabel * ILCodeLabel)
    | FilterCatch of (ILCodeLabel * ILCodeLabel) * (ILCodeLabel * ILCodeLabel)
    | TypeCatch of ILType * (ILCodeLabel * ILCodeLabel)
L
latkin 已提交
655

D
Don Syme 已提交
656 657 658 659
[<RequireQualifiedAccess; NoEquality; NoComparison>]
type ILExceptionSpec = 
    { Range: (ILCodeLabel * ILCodeLabel);
      Clause: ILExceptionClause }
L
latkin 已提交
660 661

/// Indicates that a particular local variable has a particular source 
D
Don Syme 已提交
662
/// language name within a given set of ranges. This does not effect local 
L
latkin 已提交
663
/// variable numbering, which is global over the whole method. 
D
Don Syme 已提交
664 665
[<RequireQualifiedAccess; NoEquality; NoComparison>]
type ILLocalDebugMapping =
L
latkin 已提交
666 667 668
    { LocalIndex: int;
      LocalName: string; }

D
Don Syme 已提交
669 670 671 672
[<RequireQualifiedAccess; NoEquality; NoComparison>]
type ILLocalDebugInfo = 
    { Range: (ILCodeLabel * ILCodeLabel);
      DebugMappings: ILLocalDebugMapping list }
L
latkin 已提交
673

D
Don Syme 已提交
674 675 676 677 678 679
[<RequireQualifiedAccess; NoEquality; NoComparison>]
type ILCode = 
    { Labels: Dictionary<ILCodeLabel,int> 
      Instrs:ILInstr[] 
      Exceptions: ILExceptionSpec list 
      Locals: ILLocalDebugInfo list }
L
latkin 已提交
680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699

/// Field Init

[<RequireQualifiedAccess; StructuralEquality; StructuralComparison>]
type ILFieldInit = 
    | String of string
    | Bool of bool
    | Char of uint16
    | Int8 of sbyte
    | Int16 of int16
    | Int32 of int32
    | Int64 of int64
    | UInt8 of byte
    | UInt16 of uint16
    | UInt32 of uint32
    | UInt64 of uint64
    | Single of single
    | Double of double
    | Null

D
Don Syme 已提交
700
[<RequireQualifiedAccess; StructuralEquality; StructuralComparison>]
L
latkin 已提交
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
type ILNativeVariant = 
    | Empty
    | Null
    | Variant
    | Currency
    | Decimal               
    | Date               
    | BSTR               
    | LPSTR               
    | LPWSTR               
    | IUnknown               
    | IDispatch               
    | SafeArray               
    | Error               
    | HRESULT               
    | CArray               
    | UserDefined               
    | Record               
    | FileTime
    | Blob               
    | Stream               
    | Storage               
    | StreamedObject               
    | StoredObject               
    | BlobObject               
    | CF                
    | CLSID
    | Void 
    | Bool
    | Int8
    | Int16                
    | Int32                
    | Int64                
    | Single                
    | Double                
    | UInt8                
    | UInt16                
    | UInt32                
    | UInt64                
    | PTR                
    | Array of ILNativeVariant                
    | Vector of ILNativeVariant                
    | Byref of ILNativeVariant                
    | Int                
    | UInt                

/// Native Types, for marshalling to the native C interface.
/// These are taken directly from the ILASM syntax, see ECMA Spec (Partition II, 7.4).  

[<RequireQualifiedAccess; StructuralEquality; StructuralComparison>]
type ILNativeType = 
    | Empty
D
Don Syme 已提交
753
    | Custom of ILGuid * string * string * byte[] (* guid,nativeTypeName,custMarshallerName,cookieString *)
L
latkin 已提交
754 755 756 757 758 759
    | FixedSysString of int32
    | FixedArray of int32
    | Currency
    | LPSTR
    | LPWSTR
    | LPTSTR
760
    | LPUTF8STR
L
latkin 已提交
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
    | ByValStr
    | TBSTR
    | LPSTRUCT
    | Struct
    | Void
    | Bool
    | Int8
    | Int16
    | Int32
    | Int64
    | Single
    | Double
    | Byte
    | UInt16
    | UInt32
    | UInt64
    | Array of ILNativeType option * (int32 * int32 option) option (* optional idx of parameter giving size plus optional additive i.e. num elems *)
    | Int
    | UInt
    | Method
    | AsAny
    | BSTR
    | IUnknown
    | IDispatch
    | Interface
    | Error               
    | SafeArray of ILNativeVariant * string option 
    | ANSIBSTR
    | VariantBool


/// Local variables
D
Don Syme 已提交
793
[<RequireQualifiedAccess; NoComparison; NoEquality>]
L
latkin 已提交
794 795
type ILLocal = 
    { Type: ILType;
L
latkin 已提交
796 797
      IsPinned: bool;
      DebugInfo: (string * int * int) option }
L
latkin 已提交
798
     
799
type ILLocals = list<ILLocal>
L
latkin 已提交
800 801

/// IL method bodies
D
Don Syme 已提交
802
[<RequireQualifiedAccess; NoComparison; NoEquality>]
L
latkin 已提交
803 804
type ILMethodBody = 
    { IsZeroInit: bool;
805
      /// strictly speaking should be a uint16 
L
latkin 已提交
806 807
      MaxStack: int32; 
      NoInlining: bool;
808
      AggressiveInlining: bool;
L
latkin 已提交
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
      Locals: ILLocals;
      Code: ILCode;
      SourceMarker: ILSourceMarker option }

/// Member Access
[<RequireQualifiedAccess>]
type ILMemberAccess = 
    | Assembly
    | FamilyAndAssembly
    | FamilyOrAssembly
    | Family
    | Private 
    | Public 

[<RequireQualifiedAccess>]
type ILAttribElem = 
    /// Represents a custom attribute parameter of type 'string'. These may be null, in which case they are encoded in a special
    /// way as indicated by Ecma-335 Partition II.
    | String of string  option 
    | Bool of bool
    | Char of char
    | SByte of sbyte
    | Int16 of int16
    | Int32 of int32
    | Int64 of int64
    | Byte of byte
    | UInt16 of uint16
    | UInt32 of uint32
    | UInt64 of uint64
    | Single of single
    | Double of double
    | Null 
    | Type of ILType option
    | TypeRef of ILTypeRef option
    | Array of ILType * ILAttribElem list

W
WilliamBerryiii 已提交
845
/// Named args: values and flags indicating if they are fields or properties.
L
latkin 已提交
846 847 848 849 850
type ILAttributeNamedArg = string * ILType * bool * ILAttribElem

/// Custom attributes.  See 'decodeILAttribData' for a helper to parse the byte[] 
/// to ILAttribElem's as best as possible.  
type ILAttribute =
D
Don Syme 已提交
851
    { Method: ILMethodSpec;  
852 853
      Data: byte[] 
      Elements: ILAttribElem list}
L
latkin 已提交
854 855 856

[<NoEquality; NoComparison; Sealed>]
type ILAttributes =
857
    member AsArray : ILAttribute []
L
latkin 已提交
858 859
    member AsList : ILAttribute list

W
WilliamBerryiii 已提交
860
/// Method parameters and return values.
L
latkin 已提交
861

D
Don Syme 已提交
862
[<RequireQualifiedAccess; NoEquality; NoComparison>]
L
latkin 已提交
863 864 865 866 867 868 869 870 871 872 873
type ILParameter = 
    { Name: string option;
      Type: ILType;
      Default: ILFieldInit option;  
      /// Marshalling map for parameters. COM Interop only. 
      Marshal: ILNativeType option; 
      IsIn: bool;
      IsOut: bool;
      IsOptional: bool;
      CustomAttrs: ILAttributes }

874
type ILParameters = list<ILParameter>
L
latkin 已提交
875

876
val typesOfILParams : ILParameters -> ILType list
L
latkin 已提交
877

W
WilliamBerryiii 已提交
878
/// Method return values.
D
Don Syme 已提交
879
[<RequireQualifiedAccess; NoEquality; NoComparison>]
L
latkin 已提交
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
type ILReturn = 
    { Marshal: ILNativeType option;
      Type: ILType; 
      CustomAttrs: ILAttributes }

/// Security ILPermissions
/// Attached to various structures...
[<RequireQualifiedAccess>]
type ILSecurityAction = 
    | Request 
    | Demand
    | Assert
    | Deny
    | PermitOnly
    | LinkCheck 
    | InheritCheck
    | ReqMin
    | ReqOpt
    | ReqRefuse
    | PreJitGrant
    | PreJitDeny
    | NonCasDemand
    | NonCasLinkDemand
    | NonCasInheritance
    | LinkDemandChoice
    | InheritanceDemandChoice
    | DemandChoice

type ILPermission =
    | PermissionSet of ILSecurityAction * byte[]

/// Abstract type equivalent to ILPermission list - use helpers 
W
WilliamBerryiii 已提交
912
/// below to construct/destruct these.
L
latkin 已提交
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
[<NoComparison; NoEquality; Sealed>]
type ILPermissions =
    member AsList : ILPermission list

/// PInvoke attributes.
[<RequireQualifiedAccess>]
type PInvokeCallingConvention =
    | None
    | Cdecl
    | Stdcall
    | Thiscall
    | Fastcall
    | WinApi

[<RequireQualifiedAccess>]
type PInvokeCharEncoding =
    | None
    | Ansi
    | Unicode
    | Auto

[<RequireQualifiedAccess>]
type PInvokeCharBestFit =
    | UseAssembly
    | Enabled
    | Disabled

[<RequireQualifiedAccess>]
type PInvokeThrowOnUnmappableChar =
    | UseAssembly
    | Enabled
    | Disabled

D
Don Syme 已提交
946
[<RequireQualifiedAccess; NoComparison; NoEquality>]
L
latkin 已提交
947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966
type PInvokeMethod =
    { Where: ILModuleRef;
      Name: string;
      CallingConv: PInvokeCallingConvention;
      CharEncoding: PInvokeCharEncoding;
      NoMangle: bool;
      LastError: bool;
      ThrowOnUnmappableChar: PInvokeThrowOnUnmappableChar;
      CharBestFit: PInvokeCharBestFit }


/// [OverridesSpec] - refer to a method declaration in a superclass 
/// or superinterface. Used for overriding/method impls.  Includes
/// a type for the parent for the same reason that a method specs
/// includes the type of the enclosing type, i.e. the type
/// gives the "ILGenericArgs" at which the parent type is being used.

type ILOverridesSpec =
    | OverridesSpec of ILMethodRef * ILType
    member MethodRef: ILMethodRef
967
    member DeclaringType: ILType 
L
latkin 已提交
968

W
WilliamBerryiii 已提交
969
// REVIEW: fold this into ILMethodDef.
L
latkin 已提交
970 971 972 973 974 975 976 977 978 979 980 981 982 983
type ILMethodVirtualInfo =
    { IsFinal: bool; 
      IsNewSlot: bool; 
      IsCheckAccessOnOverride: bool;
      IsAbstract: bool; }

[<RequireQualifiedAccess>]
type MethodKind =
    | Static 
    | Cctor 
    | Ctor 
    | NonVirtual 
    | Virtual of ILMethodVirtualInfo

W
WilliamBerryiii 已提交
984
// REVIEW: fold this into ILMethodDef.
L
latkin 已提交
985 986 987 988 989 990 991
[<RequireQualifiedAccess>]
type MethodBody =
    | IL of ILMethodBody
    | PInvoke of PInvokeMethod       (* platform invoke to native  *)
    | Abstract
    | Native

W
WilliamBerryiii 已提交
992
// REVIEW: fold this into ILMethodDef.
L
latkin 已提交
993 994 995 996 997 998 999 1000 1001 1002
[<RequireQualifiedAccess>]
type MethodCodeKind =
    | IL
    | Native
    | Runtime

/// Generic parameters.  Formal generic parameter declarations
/// may include the bounds, if any, on the generic parameter.
type ILGenericParameterDef =
    { Name: string;
W
WilliamBerryiii 已提交
1003
    /// At most one is the parent type, the others are interface types.
L
latkin 已提交
1004
      Constraints: ILTypes; 
W
WilliamBerryiii 已提交
1005
      /// Variance of type parameters, only applicable to generic parameters for generic interfaces and delegates.
L
latkin 已提交
1006
      Variance: ILGenericVariance; 
W
WilliamBerryiii 已提交
1007
      /// Indicates the type argument must be a reference type.
L
latkin 已提交
1008 1009
      HasReferenceTypeConstraint: bool;     
      CustomAttrs : ILAttributes;
W
WilliamBerryiii 已提交
1010
      /// Indicates the type argument must be a value type, but not Nullable.
L
latkin 已提交
1011
      HasNotNullableValueTypeConstraint: bool;  
W
WilliamBerryiii 已提交
1012
      /// Indicates the type argument must have a public nullary constructor.
L
latkin 已提交
1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031
      HasDefaultConstructorConstraint: bool; }


type ILGenericParameterDefs = ILGenericParameterDef list

[<NoComparison; NoEquality; Sealed>]
type ILLazyMethodBody = 
    member Contents : MethodBody 

/// Method definitions.
///
/// There are several different flavours of methods (constructors,
/// abstract, virtual, static, instance, class constructors).  There
/// is no perfect factorization of these as the combinations are not
/// independent.  

[<NoComparison; NoEquality>]
type ILMethodDef = 
    { Name: string;
A
Avi Avni 已提交
1032 1033
      Attributes: MethodAttributes;
      ImplAttributes: MethodImplAttributes;
L
latkin 已提交
1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049
      CallingConv: ILCallingConv;
      Parameters: ILParameters;
      Return: ILReturn;
      mdBody: ILLazyMethodBody;   
      SecurityDecls: ILPermissions;
      IsEntryPoint:bool;
      GenericParams: ILGenericParameterDefs;
      CustomAttrs: ILAttributes; }
      
    member ParameterTypes: ILTypes;
    member IsIL : bool
    member Code : ILCode option
    member Locals : ILLocals
    member MaxStack : int32
    member IsZeroInit : bool
    
W
WilliamBerryiii 已提交
1050 1051
    /// .cctor methods.  The predicates (IsClassInitializer,IsConstructor,IsStatic,IsNonVirtualInstance,IsVirtual) 
    /// form a complete, non-overlapping classification of this type.
L
latkin 已提交
1052
    member IsClassInitializer: bool
W
WilliamBerryiii 已提交
1053 1054
    /// .ctor methods.  The predicates (IsClassInitializer,IsConstructor,IsStatic,IsNonVirtualInstance,IsVirtual) 
    /// form a complete, non-overlapping classification of this type.
L
latkin 已提交
1055
    member IsConstructor: bool
W
WilliamBerryiii 已提交
1056 1057
    /// static methods.  The predicates (IsClassInitializer,IsConstructor,IsStatic,IsNonVirtualInstance,IsVirtual) 
    /// form a complete, non-overlapping classification of this type.
L
latkin 已提交
1058
    member IsStatic: bool
W
WilliamBerryiii 已提交
1059 1060
    /// instance methods that are not virtual.  The predicates (IsClassInitializer,IsConstructor,IsStatic,IsNonVirtualInstance,IsVirtual) 
    /// form a complete, non-overlapping classification of this type.
L
latkin 已提交
1061
    member IsNonVirtualInstance: bool
W
WilliamBerryiii 已提交
1062 1063 1064
    /// instance methods that are virtual or abstract or implement an interface slot.  
    /// The predicates (IsClassInitializer,IsConstructor,IsStatic,IsNonVirtualInstance,IsVirtual) 
    /// form a complete, non-overlapping classification of this type.
L
latkin 已提交
1065 1066 1067 1068
    member IsVirtual: bool
    
    member IsFinal: bool
    member IsNewSlot: bool
A
Avi Avni 已提交
1069
    member IsCheckAccessOnOverride: bool
L
latkin 已提交
1070
    member IsAbstract: bool
A
Avi Avni 已提交
1071
    member MethodBody: ILMethodBody
L
latkin 已提交
1072
    member CallingSignature: ILCallingSignature
A
Avi Avni 已提交
1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104
    member Access: ILMemberAccess
    member IsHideBySig: bool
    member IsSpecialName: bool
    /// The method is exported to unmanaged code using COM interop.
    member IsUnmanagedExport: bool
    member IsReqSecObj: bool
    /// Some methods are marked "HasSecurity" even if there are no permissions attached, e.g. if they use SuppressUnmanagedCodeSecurityAttribute 
    member HasSecurity: bool
    member IsManaged: bool
    member IsForwardRef: bool
    member IsInternalCall: bool
    member IsPreserveSig: bool
    member IsSynchronized: bool
    member IsNoInline: bool
    member IsAggressiveInline: bool
    /// .NET 2.0 feature: SafeHandle finalizer must be run.
    member IsMustRun: bool
    
    member WithSpecialName: ILMethodDef
    member WithHideBySig: unit -> ILMethodDef
    member WithHideBySig: bool -> ILMethodDef
    member WithFinal: bool -> ILMethodDef
    member WithAbstract: bool -> ILMethodDef
    member WithAccess: ILMemberAccess -> ILMethodDef
    member WithNewSlot: ILMethodDef
    member WithSecurity: bool -> ILMethodDef
    member WithPInvoke: bool -> ILMethodDef
    member WithPreserveSig: bool -> ILMethodDef
    member WithSynchronized: bool -> ILMethodDef
    member WithNoInlining: bool -> ILMethodDef
    member WithAggressiveInlining: bool -> ILMethodDef
    member WithRuntime: bool -> ILMethodDef
L
latkin 已提交
1105 1106 1107 1108 1109 1110 1111 1112 1113

/// Tables of methods.  Logically equivalent to a list of methods but
/// the table is kept in a form optimized for looking up methods by 
/// name and arity.

/// abstract type equivalent to [ILMethodDef list] 
[<NoEquality; NoComparison; Sealed>]
type ILMethodDefs =
    interface IEnumerable<ILMethodDef>
1114
    member AsArray : ILMethodDef[]
L
latkin 已提交
1115 1116 1117
    member AsList : ILMethodDef list
    member FindByName : string -> ILMethodDef list

W
WilliamBerryiii 已提交
1118
/// Field definitions.
L
latkin 已提交
1119 1120 1121 1122
[<NoComparison; NoEquality>]
type ILFieldDef = 
    { Name: string;
      Type: ILType;
A
Avi Avni 已提交
1123
      Attributes: FieldAttributes;
L
latkin 已提交
1124 1125 1126 1127 1128 1129
      Data:  byte[] option;
      LiteralValue: ILFieldInit option;  
      /// The explicit offset in bytes when explicit layout is used.
      Offset:  int32 option; 
      Marshal: ILNativeType option; 
      CustomAttrs: ILAttributes; }
A
Avi Avni 已提交
1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143
        member IsStatic: bool
        member IsSpecialName: bool
        member IsLiteral: bool
        member NotSerialized: bool
        member IsInitOnly: bool
        member Access: ILMemberAccess
        member WithAccess: ILMemberAccess -> ILFieldDef
        member WithInitOnly: bool -> ILFieldDef
        member WithStatic: bool -> ILFieldDef
        member WithSpecialName: bool -> ILFieldDef
        member WithNotSerialized: bool -> ILFieldDef
        member WithLiteral: bool -> ILFieldDef
        member WithHasDefault: bool -> ILFieldDef
        member WithHasFieldMarshal: bool -> ILFieldDef
L
latkin 已提交
1144 1145 1146 1147 1148 1149 1150 1151 1152

/// Tables of fields.  Logically equivalent to a list of fields but
/// the table is kept in a form optimized for looking up fields by 
/// name.
[<NoEquality; NoComparison; Sealed>]
type ILFieldDefs =
    member AsList : ILFieldDef list
    member LookupByName : string -> ILFieldDef list

W
WilliamBerryiii 已提交
1153
/// Event definitions.
L
latkin 已提交
1154 1155
[<NoComparison; NoEquality>]
type ILEventDef =
A
Avi Avni 已提交
1156
    { Type: ILType option;
L
latkin 已提交
1157
      Name: string;
A
Avi Avni 已提交
1158
      Attributes: EventAttributes
L
latkin 已提交
1159 1160 1161 1162 1163
      AddMethod: ILMethodRef; 
      RemoveMethod: ILMethodRef;
      FireMethod: ILMethodRef option;
      OtherMethods: ILMethodRef list;
      CustomAttrs: ILAttributes; }
A
Avi Avni 已提交
1164 1165
        member IsSpecialName : bool
        member IsRTSpecialName : bool
L
latkin 已提交
1166 1167 1168 1169 1170 1171 1172

/// Table of those events in a type definition.
[<NoEquality; NoComparison; Sealed>]
type ILEventDefs =
    member AsList : ILEventDef list
    member LookupByName : string -> ILEventDef list

W
WilliamBerryiii 已提交
1173
/// Property definitions.
L
latkin 已提交
1174 1175 1176
[<NoComparison; NoEquality>]
type ILPropertyDef =
    { Name: string;
A
Avi Avni 已提交
1177
      Attributes: PropertyAttributes;
L
latkin 已提交
1178 1179 1180 1181 1182 1183 1184
      SetMethod: ILMethodRef option;
      GetMethod: ILMethodRef option;
      CallingConv: ILThisConvention;
      Type: ILType;          
      Init: ILFieldInit option;
      Args: ILTypes;
      CustomAttrs: ILAttributes; }
A
Avi Avni 已提交
1185 1186
        member IsSpecialName : bool
        member IsRTSpecialName : bool
L
latkin 已提交
1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207

/// Table of those properties in a type definition.
[<NoEquality; NoComparison>]
[<Sealed>]
type ILPropertyDefs =
    member AsList : ILPropertyDef list
    member LookupByName : string -> ILPropertyDef list

/// Method Impls
///
/// If there is an entry (pms --&gt; ms) in this table, then method [ms] 
/// is used to implement method [pms] for the purposes of this class 
/// and its subclasses. 
type ILMethodImplDef =
    { Overrides: ILOverridesSpec;
      OverrideBy: ILMethodSpec }

[<NoEquality; NoComparison; Sealed>]
type ILMethodImplDefs =
    member AsList : ILMethodImplDef list

W
WilliamBerryiii 已提交
1208
/// Type Layout information.
L
latkin 已提交
1209 1210 1211 1212 1213 1214 1215 1216 1217 1218
[<RequireQualifiedAccess>]
type ILTypeDefLayout =
    | Auto
    | Sequential of ILTypeDefLayoutInfo
    | Explicit of ILTypeDefLayoutInfo 

and ILTypeDefLayoutInfo =
    { Size: int32 option;
      Pack: uint16 option } 

W
WilliamBerryiii 已提交
1219
/// Indicate the initialization semantics of a type.
L
latkin 已提交
1220 1221 1222 1223 1224
[<RequireQualifiedAccess>]
type ILTypeInit =
    | BeforeField
    | OnAny

W
WilliamBerryiii 已提交
1225
/// Default Unicode encoding for P/Invoke  within a type.
L
latkin 已提交
1226 1227 1228 1229 1230 1231
[<RequireQualifiedAccess>]
type ILDefaultPInvokeEncoding =
    | Ansi
    | Auto
    | Unicode

W
WilliamBerryiii 已提交
1232
/// Type Access.
L
latkin 已提交
1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266
[<RequireQualifiedAccess>]
type ILTypeDefAccess =
    | Public 
    | Private
    | Nested of ILMemberAccess 

/// A categorization of type definitions into "kinds"

//-------------------------------------------------------------------
// A note for the nit-picky.... In theory, the "kind" of a type 
// definition can only be  partially determined prior to binding.  
// For example, you cannot really, absolutely tell if a type is 
// really, absolutely a value type until you bind the 
// super class and test it for type equality against System.ValueType.  
// However, this is unbearably annoying, as it means you 
// have to load "primary runtime assembly (System.Runtime or mscorlib)" and perform bind operations 
// in order to be able to determine some quite simple 
// things.  So we approximate by simply looking at the name
// of the superclass when loading.
// ------------------------------------------------------------------ 

[<RequireQualifiedAccess>]
type ILTypeDefKind =
    | Class
    | ValueType
    | Interface
    | Enum 
    | Delegate 

/// Tables of named type definitions.  The types and table may contain on-demand
/// (lazy) computations, e.g. the actual reading of some aspects
/// of a type definition may be delayed if the reader being used supports
/// this.
///
W
WilliamBerryiii 已提交
1267
/// This is an abstract type equivalent to "ILTypeDef list".
L
latkin 已提交
1268 1269 1270 1271
[<NoEquality; NoComparison>]
[<Sealed>]
type ILTypeDefs =
    interface IEnumerable<ILTypeDef>
1272
    member AsArray : ILTypeDef[]
L
latkin 已提交
1273 1274
    member AsList : ILTypeDef list

W
WilliamBerryiii 已提交
1275
    /// Get some information about the type defs, but do not force the read of the type defs themselves.
D
Don Syme 已提交
1276
    member AsArrayOfLazyTypeDefs : (string list * string * ILAttributes * Lazy<ILTypeDef>) array
L
latkin 已提交
1277

W
WilliamBerryiii 已提交
1278
    /// Calls to <c>FindByName</c> will result in any laziness in the overall 
L
latkin 已提交
1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291
    /// set of ILTypeDefs being read in in addition 
    /// to the details for the type found, but the remaining individual 
    /// type definitions will not be read. 
    member FindByName : string -> ILTypeDef

/// Type Definitions 
///
/// As for methods there are several important constraints not encoded 
/// in the type definition below, for example that the super class of
/// an interface type is always None, or that enumerations always
/// have a very specific form.
and [<NoComparison; NoEquality>]
    ILTypeDef =  
A
Avi Avni 已提交
1292 1293
    { Name: string;  
      Attributes: TypeAttributes;
L
latkin 已提交
1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306
      GenericParams: ILGenericParameterDefs;  
      Layout: ILTypeDefLayout;
      NestedTypes: ILTypeDefs;
      Implements: ILTypes;  
      Extends: ILType option; 
      Methods: ILMethodDefs;
      SecurityDecls: ILPermissions;
      Fields: ILFieldDefs;
      MethodImpls: ILMethodImplDefs;
      Events: ILEventDefs;
      Properties: ILPropertyDefs;
      CustomAttrs: ILAttributes; }
    member IsClass: bool;
A
Avi Avni 已提交
1307
    member IsStruct: bool;
L
latkin 已提交
1308 1309 1310 1311
    member IsInterface: bool;
    member IsEnum: bool;
    member IsDelegate: bool;
    member IsStructOrEnum : bool
A
Avi Avni 已提交
1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334
    member Access: ILTypeDefAccess
    member IsAbstract: bool
    member IsSealed: bool
    member IsSerializable: bool
    /// Class or interface generated for COM interop. 
    member IsComInterop: bool
    member IsSpecialName: bool
    /// Some classes are marked "HasSecurity" even if there are no permissions attached, 
    /// e.g. if they use SuppressUnmanagedCodeSecurityAttribute 
    member HasSecurity: bool
    member Encoding: ILDefaultPInvokeEncoding;
    member WithAccess: ILTypeDefAccess -> ILTypeDef
    member WithNestedAccess: ILMemberAccess -> ILTypeDef
    member WithSealed: bool -> ILTypeDef
    member WithSerializable: bool -> ILTypeDef
    member WithAbstract: bool -> ILTypeDef
    member WithImport: bool -> ILTypeDef
    member WithHasSecurity: bool -> ILTypeDef
    member WithLayout: ILTypeDefLayout -> ILTypeDef
    member WithKind: ILTypeDefKind -> ILTypeDef
    member WithEncoding: ILDefaultPInvokeEncoding -> ILTypeDef
    member WithSpecialName: bool -> ILTypeDef
    member WithInitSemantics: ILTypeInit -> ILTypeDef
L
latkin 已提交
1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379

[<NoEquality; NoComparison>]
[<Sealed>]
type ILNestedExportedTypes =
    member AsList : ILNestedExportedType  list

/// "Classes Elsewhere" - classes in auxiliary modules.
///
/// Manifests include declarations for all the classes in an 
/// assembly, regardless of which module they are in.
///
/// The ".class extern" construct describes so-called exported types -- 
/// these are public classes defined in the auxiliary modules of this assembly,
/// i.e. modules other than the manifest-carrying module. 
/// 
/// For example, if you have a two-module 
/// assembly (A.DLL and B.DLL), and the manifest resides in the A.DLL, 
/// then in the manifest all the public classes declared in B.DLL should
/// be defined as exported types, i.e., as ".class extern". The public classes 
/// defined in A.DLL should not be defined as ".class extern" -- they are 
/// already available in the manifest-carrying module. The union of all 
/// public classes defined in the manifest-carrying module and all 
/// exported types defined there is the set of all classes exposed by 
/// this assembly. Thus, by analysing the metadata of the manifest-carrying 
/// module of an assembly, you can identify all the classes exposed by 
/// this assembly, and where to find them.
///
/// Nested classes found in external modules should also be located in 
/// this table, suitably nested inside another "ILExportedTypeOrForwarder"
/// definition.

/// these are only found in the "Nested" field of ILExportedTypeOrForwarder objects 
// REVIEW: fold this into ILExportedTypeOrForwarder. There's not much value in keeping these distinct
and ILNestedExportedType =
    { Name: string;
      Access: ILMemberAccess;
      Nested: ILNestedExportedTypes;
      CustomAttrs: ILAttributes } 

/// these are only found in the ILExportedTypesAndForwarders table in the manifest 
[<NoComparison; NoEquality>]
type ILExportedTypeOrForwarder =
    { ScopeRef: ILScopeRef;
      /// [Namespace.]Name
      Name: string;
A
Avi Avni 已提交
1380
      Attributes: TypeAttributes
L
latkin 已提交
1381
      Nested: ILNestedExportedTypes;
A
Avi Avni 已提交
1382 1383 1384
      CustomAttrs: ILAttributes }
    member Access: ILTypeDefAccess
    member IsForwarder: bool
L
latkin 已提交
1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402

[<NoEquality; NoComparison>]
[<Sealed>]
type ILExportedTypesAndForwarders =
    member AsList : ILExportedTypeOrForwarder  list

[<RequireQualifiedAccess>]
type ILResourceAccess = 
    | Public 
    | Private 

[<RequireQualifiedAccess>]
type ILResourceLocation = 
    | Local of (unit -> byte[])  (* resources may be re-read each time this function is called *)
    | File of ILModuleRef * int32
    | Assembly of ILAssemblyRef

/// "Manifest ILResources" are chunks of resource data, being one of:
W
WilliamBerryiii 已提交
1403 1404
///   - the data section of the current module (byte[] of resource given directly).
///   - in an external file in this assembly (offset given in the ILResourceLocation field). 
L
latkin 已提交
1405 1406 1407 1408 1409 1410
///   - as a resources in another assembly of the same name.  
type ILResource =
    { Name: string;
      Location: ILResourceLocation;
      Access: ILResourceAccess;
      CustomAttrs: ILAttributes }
D
Don Syme 已提交
1411 1412
    /// Read the bytes from a resource local to an assembly
    member Bytes : byte[]
L
latkin 已提交
1413

W
WilliamBerryiii 已提交
1414
/// Table of resources in a module.
L
latkin 已提交
1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431
[<NoEquality; NoComparison>]
[<Sealed>]
type ILResources =
    member AsList : ILResource  list


[<RequireQualifiedAccess>]
type ILAssemblyLongevity =
    | Unspecified
    | Library
    | PlatformAppDomain
    | PlatformProcess
    | PlatformSystem

/// The main module of an assembly is a module plus some manifest information.
type ILAssemblyManifest = 
    { Name: string;
W
WilliamBerryiii 已提交
1432
      /// This is the ID of the algorithm used for the hashes of auxiliary 
L
latkin 已提交
1433
      /// files in the assembly.   These hashes are stored in the 
W
WilliamBerryiii 已提交
1434 1435 1436
      /// <c>ILModuleRef.Hash</c> fields of this assembly. These are not 
      /// cryptographic hashes: they are simple file hashes. The algorithm 
      /// is normally <c>0x00008004</c> indicating the SHA1 hash algorithm.  
L
latkin 已提交
1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450
      AuxModuleHashAlgorithm: int32; 
      SecurityDecls: ILPermissions;
      /// This is the public key used to sign this 
      /// assembly (the signature itself is stored elsewhere: see the 
      /// binary format, and may not have been written if delay signing 
      /// is used).  (member Name, member PublicKey) forms the full 
      /// public name of the assembly.  
      PublicKey: byte[] option;  
      Version: ILVersionInfo option;
      Locale: string option;
      CustomAttrs: ILAttributes;
      AssemblyLongevity: ILAssemblyLongevity; 
      DisableJitOptimizations: bool;
      JitTracking: bool;
1451
      IgnoreSymbolStoreSequencePoints: bool;
L
latkin 已提交
1452
      Retargetable: bool;
1453
      /// Records the types implemented by this assembly in auxiliary 
L
latkin 已提交
1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484
      /// modules. 
      ExportedTypes: ILExportedTypesAndForwarders;
      /// Records whether the entrypoint resides in another module. 
      EntrypointElsewhere: ILModuleRef option;
    } 
    
/// One module in the "current" assembly, either a main-module or
/// an auxiliary module.  The main module will have a manifest.
///
/// An assembly is built by joining together a "main" module plus 
/// several auxiliary modules. 
type ILModuleDef = 
    { Manifest: ILAssemblyManifest option;
      CustomAttrs: ILAttributes;
      Name: string;
      TypeDefs: ILTypeDefs;
      SubsystemVersion : int * int
      UseHighEntropyVA : bool
      SubSystemFlags: int32;
      IsDLL: bool;
      IsILOnly: bool;
      Platform: ILPlatform option;
      StackReserveSize: int32 option;
      Is32Bit: bool;
      Is32BitPreferred: bool;
      Is64Bit: bool;
      VirtualAlignment: int32;
      PhysicalAlignment: int32;
      ImageBase: int32;
      MetadataVersion: string;
      Resources: ILResources; 
W
WilliamBerryiii 已提交
1485
      /// e.g. win86 resources, as the exact contents of a .res or .obj file. 
L
latkin 已提交
1486 1487 1488 1489 1490 1491 1492 1493 1494
      NativeResources: Lazy<byte[]> list;  }
    member ManifestOfAssembly: ILAssemblyManifest 
    member HasManifest : bool

/// Find the method definition corresponding to the given property or 
/// event operation. These are always in the same class as the property 
/// or event. This is useful especially if your code is not using the Ilbind 
/// API to bind references. 
val resolveILMethodRef: ILTypeDef -> ILMethodRef -> ILMethodDef
1495
val resolveILMethodRefWithRescope: (ILType -> ILType) -> ILTypeDef -> ILMethodRef -> ILMethodDef
L
latkin 已提交
1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511

// ------------------------------------------------------------------ 
// Type Names
//
// The name of a type stored in the Name field is as follows:
//   - For outer types it is, for example, System.String, i.e.
//     the namespace followed by the type name.
//   - For nested types, it is simply the type name.  The namespace
//     must be gleaned from the context in which the nested type
//     lies.
// ------------------------------------------------------------------ 

val splitNamespace: string -> string list

val splitNamespaceToArray: string -> string[]

W
WilliamBerryiii 已提交
1512
/// The <c>splitILTypeName</c> utility helps you split a string representing
L
latkin 已提交
1513 1514 1515 1516 1517 1518 1519 1520
/// a type name into the leading namespace elements (if any), the
/// names of any nested types and the type name itself.  This function
/// memoizes and interns the splitting of the namespace portion of
/// the type name. 
val splitILTypeName: string -> string list * string

val splitILTypeNameWithPossibleStaticArguments: string -> string[] * string

W
WilliamBerryiii 已提交
1521
/// <c>splitTypeNameRight</c> is like <c>splitILTypeName</c> except the 
L
latkin 已提交
1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539
/// namespace is kept as a whole string, rather than split at dots.
val splitTypeNameRight: string -> string option * string


val typeNameForGlobalFunctions: string
val isTypeNameForGlobalFunctions: string -> bool

val ungenericizeTypeName: string -> string (* e.g. List`1 --> List *)


// ====================================================================
// PART 2
// 
// Making metadata.  Where no explicit constructor
// is given, you should create the concrete datatype directly, 
// e.g. by filling in all appropriate record fields.
// ==================================================================== *)

1540
/// A table of common references to items in primary assembly (System.Runtime or mscorlib).
W
WilliamBerryiii 已提交
1541 1542
/// If a particular version of System.Runtime.dll has been loaded then you should 
/// reference items from it via an ILGlobals for that specific version built using mkILGlobals. 
1543
[<NoEquality; NoComparison; Class>]
L
latkin 已提交
1544
type ILGlobals = 
1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570
    member primaryAssemblyScopeRef : ILScopeRef
    member primaryAssemblyName : string
    member typ_Object: ILType
    member typ_String: ILType
    member typ_Type: ILType
    member typ_Array: ILType
    member typ_IntPtr: ILType
    member typ_UIntPtr: ILType
    member typ_Byte: ILType
    member typ_Int16: ILType
    member typ_Int32: ILType
    member typ_Int64: ILType
    member typ_SByte: ILType
    member typ_UInt16: ILType
    member typ_UInt32: ILType
    member typ_UInt64: ILType
    member typ_Single: ILType
    member typ_Double: ILType
    member typ_Bool: ILType
    member typ_Char: ILType


/// Build the table of commonly used references given functions to find types in system assemblies
val mkILGlobals: ILScopeRef -> ILGlobals

val EcmaMscorlibILGlobals : ILGlobals
L
latkin 已提交
1571 1572

/// When writing a binary the fake "toplevel" type definition (called <Module>)
W
WilliamBerryiii 已提交
1573 1574
/// must come first. This function puts it first, and creates it in the returned 
/// list as an empty typedef if it doesn't already exist.
L
latkin 已提交
1575 1576
val destTypeDefsWithGlobalFunctionsFirst: ILGlobals -> ILTypeDefs -> ILTypeDef list

W
WilliamBerryiii 已提交
1577
/// Not all custom attribute data can be decoded without binding types.  In particular 
L
latkin 已提交
1578 1579 1580 1581 1582 1583 1584 1585
/// enums must be bound in order to discover the size of the underlying integer. 
/// The following assumes enums have size int32. 
val decodeILAttribData: 
    ILGlobals -> 
    ILAttribute -> 
      ILAttribElem list *  (* fixed args *)
      ILAttributeNamedArg list (* named args: values and flags indicating if they are fields or properties *) 

W
WilliamBerryiii 已提交
1586
/// Generate simple references to assemblies and modules.
L
latkin 已提交
1587 1588 1589 1590 1591
val mkSimpleAssRef: string -> ILAssemblyRef
val mkSimpleModRef: string -> ILModuleRef

val mkILTyvarTy: uint16 -> ILType

W
WilliamBerryiii 已提交
1592
/// Make type refs.
L
latkin 已提交
1593 1594 1595 1596 1597
val mkILNestedTyRef: ILScopeRef * string list * string -> ILTypeRef
val mkILTyRef: ILScopeRef * string -> ILTypeRef
val mkILTyRefInTyRef: ILTypeRef * string -> ILTypeRef

type ILGenericArgsList = ILType list
1598

W
WilliamBerryiii 已提交
1599
/// Make type specs.
L
latkin 已提交
1600 1601 1602
val mkILNonGenericTySpec: ILTypeRef -> ILTypeSpec
val mkILTySpec: ILTypeRef * ILGenericArgsList -> ILTypeSpec

W
WilliamBerryiii 已提交
1603
/// Make types.
L
latkin 已提交
1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615
val mkILTy: ILBoxity -> ILTypeSpec -> ILType
val mkILNamedTy: ILBoxity -> ILTypeRef -> ILGenericArgsList -> ILType
val mkILBoxedTy: ILTypeRef -> ILGenericArgsList -> ILType
val mkILValueTy: ILTypeRef -> ILGenericArgsList -> ILType
val mkILNonGenericBoxedTy: ILTypeRef -> ILType
val mkILNonGenericValueTy: ILTypeRef -> ILType
val mkILArrTy: ILType * ILArrayShape -> ILType
val mkILArr1DTy: ILType -> ILType
val isILArrTy: ILType -> bool
val destILArrTy: ILType -> ILArrayShape * ILType 
val mkILBoxedType : ILTypeSpec -> ILType

W
WilliamBerryiii 已提交
1616
/// Make method references and specs.
L
latkin 已提交
1617 1618 1619 1620 1621
val mkILMethRef: ILTypeRef * ILCallingConv * string * int * ILType list * ILType -> ILMethodRef
val mkILMethSpec: ILMethodRef * ILBoxity * ILGenericArgsList * ILGenericArgsList -> ILMethodSpec
val mkILMethSpecForMethRefInTy: ILMethodRef * ILType * ILGenericArgsList -> ILMethodSpec
val mkILMethSpecInTy: ILType * ILCallingConv * string * ILType list * ILType * ILGenericArgsList -> ILMethodSpec

W
WilliamBerryiii 已提交
1622
/// Construct references to methods on a given type .
L
latkin 已提交
1623 1624
val mkILNonGenericMethSpecInTy: ILType * ILCallingConv * string * ILType list * ILType -> ILMethodSpec

W
WilliamBerryiii 已提交
1625
/// Construct references to instance methods.
L
latkin 已提交
1626 1627
val mkILInstanceMethSpecInTy: ILType * string * ILType list * ILType * ILGenericArgsList -> ILMethodSpec

W
WilliamBerryiii 已提交
1628
/// Construct references to instance methods.
L
latkin 已提交
1629 1630
val mkILNonGenericInstanceMethSpecInTy: ILType * string * ILType list * ILType -> ILMethodSpec

W
WilliamBerryiii 已提交
1631
/// Construct references to static methods.
L
latkin 已提交
1632 1633
val mkILStaticMethSpecInTy: ILType * string * ILType list * ILType * ILGenericArgsList -> ILMethodSpec

W
WilliamBerryiii 已提交
1634
/// Construct references to static, non-generic methods.
L
latkin 已提交
1635 1636
val mkILNonGenericStaticMethSpecInTy: ILType * string * ILType list * ILType -> ILMethodSpec

W
WilliamBerryiii 已提交
1637
/// Construct references to constructors.
L
latkin 已提交
1638 1639
val mkILCtorMethSpecForTy: ILType * ILType list -> ILMethodSpec

W
WilliamBerryiii 已提交
1640
/// Construct references to fields.
L
latkin 已提交
1641 1642 1643 1644 1645 1646
val mkILFieldRef: ILTypeRef * string * ILType -> ILFieldRef
val mkILFieldSpec: ILFieldRef * ILType -> ILFieldSpec
val mkILFieldSpecInTy: ILType * string * ILType -> ILFieldSpec

val mkILCallSig: ILCallingConv * ILType list * ILType -> ILCallingSignature

1647
/// Make generalized versions of possibly-generic types,
L
latkin 已提交
1648 1649
/// e.g. Given the ILTypeDef for List, return the type "List<T>".
val mkILFormalBoxedTy: ILTypeRef -> ILGenericParameterDef list -> ILType
D
Don Syme 已提交
1650
val mkILFormalNamedTy: ILBoxity -> ILTypeRef -> ILGenericParameterDef list -> ILType
L
latkin 已提交
1651 1652

val mkILFormalTypars: ILType list -> ILGenericParameterDefs
1653
val mkILFormalGenericArgs: int -> ILGenericParameterDefs -> ILGenericArgsList
L
latkin 已提交
1654
val mkILSimpleTypar : string -> ILGenericParameterDef
W
WilliamBerryiii 已提交
1655
/// Make custom attributes.
L
latkin 已提交
1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676
val mkILCustomAttribMethRef: 
    ILGlobals 
    -> ILMethodSpec 
       * ILAttribElem list (* fixed args: values and implicit types *) 
       * ILAttributeNamedArg list (* named args: values and flags indicating if they are fields or properties *) 
      -> ILAttribute

val mkILCustomAttribute: 
    ILGlobals 
    -> ILTypeRef * ILType list * 
       ILAttribElem list (* fixed args: values and implicit types *) * 
       ILAttributeNamedArg list (* named args: values and flags indicating if they are fields or properties *) 
         -> ILAttribute

val mkPermissionSet : ILGlobals -> ILSecurityAction * (ILTypeRef * (string * ILType * ILAttribElem) list) list -> ILPermission

/// Making code.
val generateCodeLabel: unit -> ILCodeLabel
val formatCodeLabel : ILCodeLabel -> string

/// Make some code that is a straight line sequence of instructions. 
W
WilliamBerryiii 已提交
1677
/// The function will add a "return" if the last instruction is not an exiting instruction.
L
latkin 已提交
1678 1679 1680 1681 1682 1683 1684 1685
val nonBranchingInstrsToCode: ILInstr list -> ILCode 

/// Helpers for codegen: scopes for allocating new temporary variables.
type ILLocalsAllocator =
    new : preAlloc: int -> ILLocalsAllocator
    member AllocLocal : ILLocal -> uint16
    member Close : unit -> ILLocal list

W
WilliamBerryiii 已提交
1686
/// Derived functions for making some common patterns of instructions.
L
latkin 已提交
1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712
val mkNormalCall: ILMethodSpec -> ILInstr
val mkNormalCallvirt: ILMethodSpec -> ILInstr
val mkNormalCallconstraint: ILType * ILMethodSpec -> ILInstr
val mkNormalNewobj: ILMethodSpec -> ILInstr
val mkCallBaseConstructor : ILType * ILType list -> ILInstr list
val mkNormalStfld: ILFieldSpec -> ILInstr
val mkNormalStsfld: ILFieldSpec -> ILInstr
val mkNormalLdsfld: ILFieldSpec -> ILInstr
val mkNormalLdfld: ILFieldSpec -> ILInstr
val mkNormalLdflda: ILFieldSpec -> ILInstr
val mkNormalLdobj: ILType -> ILInstr
val mkNormalStobj: ILType -> ILInstr 
val mkLdcInt32: int32 -> ILInstr
val mkLdarg0: ILInstr
val mkLdloc: uint16 -> ILInstr
val mkStloc: uint16 -> ILInstr
val mkLdarg: uint16 -> ILInstr

val andTailness: ILTailcall -> bool -> ILTailcall

/// Derived functions for making return, parameter and local variable
/// objects for use in method definitions.
val mkILParam: string option * ILType -> ILParameter
val mkILParamAnon: ILType -> ILParameter
val mkILParamNamed: string * ILType -> ILParameter
val mkILReturn: ILType -> ILReturn
L
latkin 已提交
1713
val mkILLocal: ILType -> (string * int * int) option -> ILLocal
L
latkin 已提交
1714

W
WilliamBerryiii 已提交
1715
/// Make a formal generic parameters.
L
latkin 已提交
1716 1717
val mkILEmptyGenericParams: ILGenericParameterDefs

W
WilliamBerryiii 已提交
1718
/// Make method definitions.
L
latkin 已提交
1719 1720 1721 1722 1723 1724 1725 1726
val mkILMethodBody: initlocals:bool * ILLocals * int * ILCode * ILSourceMarker option -> ILMethodBody
val mkMethodBody: bool * ILLocals * int * ILCode * ILSourceMarker option -> MethodBody

val mkILCtor: ILMemberAccess * ILParameter list * MethodBody -> ILMethodDef
val mkILClassCtor: MethodBody -> ILMethodDef
val mkILNonGenericEmptyCtor: ILSourceMarker option -> ILType -> ILMethodDef
val mkILStaticMethod: ILGenericParameterDefs * string * ILMemberAccess * ILParameter list * ILReturn * MethodBody -> ILMethodDef
val mkILNonGenericStaticMethod: string * ILMemberAccess * ILParameter list * ILReturn * MethodBody -> ILMethodDef
A
Avi Avni 已提交
1727 1728
val mkILGenericVirtualMethod: string * ILMemberAccess  * ILGenericParameterDefs * ILParameter list * ILReturn * MethodBody -> ILMethodDef
val mkILGenericNonVirtualMethod: string * ILMemberAccess  * ILGenericParameterDefs * ILParameter list * ILReturn * MethodBody -> ILMethodDef
L
latkin 已提交
1729
val mkILNonGenericVirtualMethod: string * ILMemberAccess * ILParameter list * ILReturn * MethodBody -> ILMethodDef
A
Avi Avni 已提交
1730
val mkILNonGenericInstanceMethod: string * ILMemberAccess  * ILParameter list * ILReturn * MethodBody -> ILMethodDef
L
latkin 已提交
1731 1732


W
WilliamBerryiii 已提交
1733
/// Make field definitions.
L
latkin 已提交
1734 1735 1736 1737
val mkILInstanceField: string * ILType * ILFieldInit option * ILMemberAccess -> ILFieldDef
val mkILStaticField: string * ILType * ILFieldInit option * byte[] option * ILMemberAccess -> ILFieldDef
val mkILLiteralField: string * ILType * ILFieldInit * byte[] option * ILMemberAccess -> ILFieldDef

W
WilliamBerryiii 已提交
1738
/// Make a type definition.
L
latkin 已提交
1739 1740 1741 1742 1743 1744 1745 1746 1747 1748
val mkILGenericClass: string * ILTypeDefAccess * ILGenericParameterDefs * ILType * ILType list * ILMethodDefs * ILFieldDefs * ILTypeDefs * ILPropertyDefs * ILEventDefs * ILAttributes * ILTypeInit -> ILTypeDef
val mkILSimpleClass: ILGlobals -> string * ILTypeDefAccess * ILMethodDefs * ILFieldDefs * ILTypeDefs * ILPropertyDefs * ILEventDefs * ILAttributes * ILTypeInit  -> ILTypeDef
val mkILTypeDefForGlobalFunctions: ILGlobals -> ILMethodDefs * ILFieldDefs -> ILTypeDef

/// Make a type definition for a value type used to point to raw data.
/// These are useful when generating array initialization code 
/// according to the 
///   ldtoken    field valuetype '<PrivateImplementationDetails>'/'$$struct0x6000127-1' '<PrivateImplementationDetails>'::'$$method0x6000127-1'
///   call       void System.Runtime.CompilerServices.RuntimeHelpers::InitializeArray(class System.Array,valuetype System.RuntimeFieldHandle)
/// idiom.
1749
val mkRawDataValueTypeDef:  ILType -> string * size:int32 * pack:uint16 -> ILTypeDef
L
latkin 已提交
1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765

/// Injecting code into existing code blocks.  A branch will
/// be added from the given instructions to the (unique) entry of
/// the code, and the first instruction will be the new entry
/// of the method.  The instructions should be non-branching.

val prependInstrsToCode: ILInstr list -> ILCode -> ILCode
val prependInstrsToMethod: ILInstr list -> ILMethodDef -> ILMethodDef

/// Injecting initialization code into a class.
/// Add some code to the end of the .cctor for a type.  Create a .cctor
/// if one doesn't exist already.
val prependInstrsToClassCtor: ILInstr list -> ILSourceMarker option -> ILTypeDef -> ILTypeDef

/// Derived functions for making some simple constructors
val mkILStorageCtor: ILSourceMarker option * ILInstr list * ILType * (string * ILType) list * ILMemberAccess -> ILMethodDef
D
Don Syme 已提交
1766 1767
val mkILSimpleStorageCtor: ILSourceMarker option * ILTypeSpec option * ILType * ILParameter list * (string * ILType) list * ILMemberAccess -> ILMethodDef
val mkILSimpleStorageCtorWithParamNames: ILSourceMarker option * ILTypeSpec option * ILType * ILParameter list * (string * string * ILType) list * ILMemberAccess -> ILMethodDef
L
latkin 已提交
1768

A
Avi Avni 已提交
1769
val mkILDelegateMethods: ILMemberAccess -> ILGlobals -> ILType * ILType -> ILParameter list * ILReturn -> ILMethodDef list
L
latkin 已提交
1770 1771

/// Given a delegate type definition which lies in a particular scope, 
W
WilliamBerryiii 已提交
1772
/// make a reference to its constructor.
L
latkin 已提交
1773 1774 1775 1776 1777 1778 1779
val mkCtorMethSpecForDelegate: ILGlobals -> ILType * bool -> ILMethodSpec 

/// The toplevel "class" for a module or assembly.
val mkILTypeForGlobalFunctions: ILScopeRef -> ILType

/// Making tables of custom attributes, etc.
val mkILCustomAttrs: ILAttribute list -> ILAttributes
1780 1781
val mkILCustomAttrsFromArray: ILAttribute[] -> ILAttributes
val mkILComputedCustomAttrs: (unit -> ILAttribute[]) -> ILAttributes
L
latkin 已提交
1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799
val emptyILCustomAttrs: ILAttributes

val mkILSecurityDecls: ILPermission list -> ILPermissions
val mkILLazySecurityDecls: Lazy<ILPermission list> -> ILPermissions
val emptyILSecurityDecls: ILPermissions

val mkMethBodyAux : MethodBody -> ILLazyMethodBody
val mkMethBodyLazyAux : Lazy<MethodBody> -> ILLazyMethodBody

val mkILEvents: ILEventDef list -> ILEventDefs
val mkILEventsLazy: Lazy<ILEventDef list> -> ILEventDefs
val emptyILEvents: ILEventDefs

val mkILProperties: ILPropertyDef list -> ILPropertyDefs
val mkILPropertiesLazy: Lazy<ILPropertyDef list> -> ILPropertyDefs
val emptyILProperties: ILPropertyDefs

val mkILMethods: ILMethodDef list -> ILMethodDefs
1800 1801
val mkILMethodsFromArray: ILMethodDef[] -> ILMethodDefs
val mkILMethodsComputed: (unit -> ILMethodDef[]) -> ILMethodDefs
L
latkin 已提交
1802 1803 1804 1805 1806 1807 1808 1809 1810 1811
val emptyILMethods: ILMethodDefs

val mkILFields: ILFieldDef list -> ILFieldDefs
val mkILFieldsLazy: Lazy<ILFieldDef list> -> ILFieldDefs
val emptyILFields: ILFieldDefs

val mkILMethodImpls: ILMethodImplDef list -> ILMethodImplDefs
val mkILMethodImplsLazy: Lazy<ILMethodImplDef list> -> ILMethodImplDefs
val emptyILMethodImpls: ILMethodImplDefs

1812 1813
val mkILTypeDefs: ILTypeDef list -> ILTypeDefs
val mkILTypeDefsFromArray: ILTypeDef[] -> ILTypeDefs
L
latkin 已提交
1814 1815 1816 1817 1818 1819 1820 1821 1822 1823
val emptyILTypeDefs: ILTypeDefs

/// Create table of types which is loaded/computed on-demand, and whose individual 
/// elements are also loaded/computed on-demand. Any call to tdefs.AsList will 
/// result in the laziness being forced.  Operations can examine the
/// custom attributes and name of each type in order to decide whether
/// to proceed with examining the other details of the type.
/// 
/// Note that individual type definitions may contain further delays 
/// in their method, field and other tables. 
D
Don Syme 已提交
1824
val mkILTypeDefsComputed: (unit -> (string list * string * ILAttributes * Lazy<ILTypeDef>) array) -> ILTypeDefs
L
latkin 已提交
1825 1826
val addILTypeDef: ILTypeDef -> ILTypeDefs -> ILTypeDefs

A
Avi Avni 已提交
1827
val mkTypeForwarder: ILScopeRef -> string -> ILNestedExportedTypes -> ILAttributes -> ILTypeDefAccess -> ILExportedTypeOrForwarder
L
latkin 已提交
1828 1829 1830 1831 1832 1833 1834 1835 1836
val mkILNestedExportedTypes: ILNestedExportedType list -> ILNestedExportedTypes
val mkILNestedExportedTypesLazy: Lazy<ILNestedExportedType list> -> ILNestedExportedTypes

val mkILExportedTypes: ILExportedTypeOrForwarder list -> ILExportedTypesAndForwarders
val mkILExportedTypesLazy: Lazy<ILExportedTypeOrForwarder list> ->   ILExportedTypesAndForwarders

val mkILResources: ILResource list -> ILResources
val mkILResourcesLazy: Lazy<ILResource list> -> ILResources

W
WilliamBerryiii 已提交
1837
/// Making modules.
L
latkin 已提交
1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891
val mkILSimpleModule: assemblyName:string -> moduleName:string -> dll:bool -> subsystemVersion : (int * int) -> useHighEntropyVA : bool -> ILTypeDefs -> int32 option -> string option -> int -> ILExportedTypesAndForwarders -> string -> ILModuleDef

/// Generate references to existing type definitions, method definitions
/// etc.  Useful for generating references, e.g. to a  class we're processing
/// Also used to reference type definitions that we've generated.  [ILScopeRef] 
/// is normally ILScopeRef.Local, unless we've generated the ILTypeDef in
/// an auxiliary module or are generating multiple assemblies at 
/// once.

val mkRefForNestedILTypeDef : ILScopeRef -> ILTypeDef list * ILTypeDef -> ILTypeRef
val mkRefForILMethod        : ILScopeRef -> ILTypeDef list * ILTypeDef -> ILMethodDef -> ILMethodRef
val mkRefForILField        : ILScopeRef -> ILTypeDef list * ILTypeDef -> ILFieldDef  -> ILFieldRef

val mkRefToILMethod: ILTypeRef * ILMethodDef -> ILMethodRef
val mkRefToILField: ILTypeRef * ILFieldDef -> ILFieldRef

val mkRefToILAssembly: ILAssemblyManifest -> ILAssemblyRef
val mkRefToILModule: ILModuleDef -> ILModuleRef


// -------------------------------------------------------------------- 
// Rescoping.
//
// Given an object O1 referenced from where1 (e.g. O1 binds to some  
// result R when referenced from where1), and given that SR2 resolves to where1 from where2, 
// produce a new O2 for use from where2 (e.g. O2 binds to R from where2)
//
// So, ILScopeRef tells you how to reference the original scope from 
// the new scope. e.g. if ILScopeRef is:
//    [ILScopeRef.Local] then the object is returned unchanged
//    [ILScopeRef.Module m] then an object is returned 
//                        where all ILScopeRef.Local references 
//                        become ILScopeRef.Module m
//    [ILScopeRef.Assembly m] then an object is returned 
//                         where all ILScopeRef.Local and ILScopeRef.Module references 
//                        become ILScopeRef.Assembly m
// -------------------------------------------------------------------- 

/// Rescoping. The first argument tells the function how to reference the original scope from 
/// the new scope. 
val rescopeILScopeRef: ILScopeRef -> ILScopeRef -> ILScopeRef
/// Rescoping. The first argument tells the function how to reference the original scope from 
/// the new scope. 
val rescopeILTypeSpec: ILScopeRef -> ILTypeSpec -> ILTypeSpec
/// Rescoping. The first argument tells the function how to reference the original scope from 
/// the new scope. 
val rescopeILType: ILScopeRef -> ILType -> ILType
/// Rescoping. The first argument tells the function how to reference the original scope from 
/// the new scope. 
val rescopeILMethodRef: ILScopeRef -> ILMethodRef -> ILMethodRef 
/// Rescoping. The first argument tells the function how to reference the original scope from 
/// the new scope. 
val rescopeILFieldRef: ILScopeRef -> ILFieldRef -> ILFieldRef

D
Don Syme 已提交
1892 1893 1894
/// Unscoping. Clears every scope information, use for looking up IL method references only.
val unscopeILType: ILType -> ILType

L
latkin 已提交
1895 1896 1897 1898
//-----------------------------------------------------------------------
// The ILCode Builder utility.
//----------------------------------------------------------------------

D
Don Syme 已提交
1899
val buildILCode: string -> lab2pc: Dictionary<ILCodeLabel,int> -> instrs:ILInstr[] -> ILExceptionSpec list -> ILLocalDebugInfo list -> ILCode
L
latkin 已提交
1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917

// -------------------------------------------------------------------- 
// The instantiation utilities.
// -------------------------------------------------------------------- 

/// Instantiate type variables that occur within types and other items. 
val instILTypeAux: int -> ILGenericArgs -> ILType -> ILType

/// Instantiate type variables that occur within types and other items. 
val instILType: ILGenericArgs -> ILType -> ILType

// -------------------------------------------------------------------- 
// ECMA globals
// -------------------------------------------------------------------- 

/// This is a 'vendor neutral' way of referencing mscorlib. 
val ecmaPublicKey: PublicKey

W
WilliamBerryiii 已提交
1918
/// Discriminating different important built-in types.
D
desco 已提交
1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935
val isILObjectTy: ILType -> bool
val isILStringTy: ILType -> bool
val isILSByteTy: ILType -> bool
val isILByteTy: ILType -> bool
val isILInt16Ty: ILType -> bool
val isILUInt16Ty: ILType -> bool
val isILInt32Ty: ILType -> bool
val isILUInt32Ty: ILType -> bool
val isILInt64Ty: ILType -> bool
val isILUInt64Ty: ILType -> bool
val isILIntPtrTy: ILType -> bool
val isILUIntPtrTy: ILType -> bool
val isILBoolTy: ILType -> bool
val isILCharTy: ILType -> bool
val isILTypedReferenceTy: ILType -> bool
val isILDoubleTy: ILType -> bool
val isILSingleTy: ILType -> bool
L
latkin 已提交
1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953

/// Get a public key token from a public key.
val sha1HashBytes : byte[] -> byte[] (* SHA1 hash *)

/// Get a version number from a CLR version string, e.g. 1.0.3705.0
val parseILVersion: string -> ILVersionInfo
val formatILVersion: ILVersionInfo -> string
val compareILVersions: ILVersionInfo -> ILVersionInfo -> int

/// Decompose a type definition according to its kind.
type ILEnumInfo =
    { enumValues: (string * ILFieldInit) list;  
      enumType: ILType }

val getTyOfILEnumInfo: ILEnumInfo -> ILType

val computeILEnumInfo: string * ILFieldDefs -> ILEnumInfo

1954 1955

// --------------------------------------------------------------------
L
latkin 已提交
1956 1957 1958
// For completeness.  These do not occur in metadata but tools that
// care about the existence of properties and events in the metadata
// can benefit from them.
1959
// --------------------------------------------------------------------
L
latkin 已提交
1960 1961 1962 1963

[<Sealed>]
type ILEventRef =
    static member Create : ILTypeRef * string -> ILEventRef
1964
    member DeclaringTypeRef: ILTypeRef
L
latkin 已提交
1965 1966 1967 1968 1969
    member Name: string

[<Sealed>]
type ILPropertyRef =
     static member Create : ILTypeRef * string -> ILPropertyRef
1970
     member DeclaringTypeRef: ILTypeRef
L
latkin 已提交
1971 1972 1973 1974 1975 1976 1977 1978 1979
     member Name: string
     interface System.IComparable

val runningOnMono: bool

type ILReferences = 
    { AssemblyReferences: ILAssemblyRef list; 
      ModuleReferences: ILModuleRef list; }

W
WilliamBerryiii 已提交
1980
/// Find the full set of assemblies referenced by a module.
L
latkin 已提交
1981 1982 1983
val computeILRefs: ILModuleDef -> ILReferences
val emptyILRefs: ILReferences