Theeree: Common Language InfraSTrucTure (CLI)

ETymoLogy Uv Prefix infra-

word-forming element meaning "below, beneath," from Latin infra (adverb and preposition) "below, underneath, on the under side, beneath," also "later than; smaller than; inferior to," related to infernus "low, below," from PIE *ndher "under" (source also of Sanskrit adnah "below," Old English under "under, among;" see under). Modern popular use of it dates from the 1920s, as an opposite to super-, often in science fiction. "This use of infra- is scarcely a Latin one" [OED].

Thus, Thuh PreFix Infra- Meenz Less SmahL.

Standard ECMA-335: Common Language Infrastructure (CLI)

6th edition (June 2012)

This Standard defines the Common Language Infrastructure (CLI) in which applications written in multiple high-level languages can be executed in different system environments without the need to rewrite those applications to take into consideration the unique characteristics of those environments. This Standard consists of the following parts:

Partition I: Concepts and Architecture – Describes the overall architecture of the CLI, and provides the normative description of the Common Type System (CTS), the Virtual Execution System (VES), and the Common Language Specification (CLS). It also provides an informative description of the metadata.

Partition II: Metadata Definition and Semantics (MDS) – Provides the normative description of the metadata: its physical layout (as a file format), its logical contents (as a set of tables and their relationships), and its semantics (as seen from a hypothetical assembler, ilasm).

Partition III: CIL Instruction Set – Describes the Common Intermediate Language (CIL) instruction set.

Partition IV: Profiles and Libraries – Provides an overview of the CLI Libraries, and a specification of their factoring into Profiles and Libraries. A companion file, CLILibrary.xml, considered to be part of this Partition, but distributed in XML format, provides details of each class, value type, and interface in the CLI Libraries.

Partition V: Debug Interchange Format (DIF) – Describes a standard way to interchange debugging information between CLI producers and consumers.

Partition VI: Annexes – Contains some sample programs written in CIL Assembly Language (ILAsm), information about a particular implementation of an assembler, a machine-readable description of the [[[CIL instruction set]] which can be used to derive parts of the grammar used by this assembler as well as other tools that manipulate CIL, a set of guidelines used in the design of the libraries of Partition IV, and portability considerations.

The following files can be freely downloaded:

Common Language Infrastructure (CLI)

Table of Contents

Foreword xxi
I.1 Scope 1
I.2 Conformance 2
I.3 Normative references 3
I.4 Conventions 5
I .4.1 Organizat ion 5
I .4.2 Informat ive text 5
I.5 Terms and def ini t ions 6
I.6 Overview of the Common Language Inf rast ructure 9
I .6.1 Relationship to type safety 9
I .6.2 Relationship to managed metadata -dr iven execut ion 10
I .6.2.1 Managed code 10
I .6.2.2 Managed data 11
I .6.2.3 Summary 11
I.7 Common Language Specification Ohr Kom Lang Spek 12
I .7.1 Introduction 12
I .7.2 Views of CLS compliance 12
I .7.2.1 CLS framework 12
I .7.2.2 CLS consumer 13
I .7.2.3 CLS extender 13
I .7.3 CLS compliance 14
I .7.3.1 Marking items as CLS-compliant 14
I.8 Common Type System (CTS 16
I.8.1 Relationship to object-oriented programming 19
I.8.2 Values and types 19
I.8.2.1 Value types and reference types 19
I.8.2.2 Built-in value and reference types 20
I.8.2.3 Classes interfaces and objects 21
I .8.2.4 Boxing and unboxing of values 21
I .8.2.5 Identity and equality of values 22
I .8.3 Locat ions 23
I .8.3.1 As s ignment -compat ible locat ions 23
I .8.3.2 Coer cion 23
iv © Ecma International 2012
I .8.3.3 Cas t ing 24
I .8.4 Type member s 24
I .8.4.1 Fields, ar ray element s, and values 24
I .8.4.2 Methods 24
I .8.4.3 Stat ic f ields and stat ic methods 25
I .8.4.4 Vi r tual methods 25
I .8.5 Naming 25
I .8.5.1 Val id names 25
I .8.5.2 As sembl ies and scoping 26
I .8.5.3 Vi sibi l i ty, acces s ibi l i ty, and secur i ty 27
I .8.6 Cont racts 29
I .8.6.1 Signatures 30
I .8.7 As s ignment compat ibi l i ty 34
I .8.7.1 As s ignment compat ibi l i ty for s ignature types 37
I .8.7.2 As s ignment compat ibi l i ty for locat ion type s 38
I .8.7.3 Gener al as s ignment compat ibi l i ty 38
I .8.8 Type safety and ver i f icat ion 39
I .8.9 Type def iner s 39
I .8.9.1 Ar ray types 40
I .8.9.2 Unmanaged pointer types 41
I .8.9.3 Delegates 41
I .8.9.4 Inter face type def ini t ion 42
I .8.9.5 Class type def ini t ion 43
I .8.9.6 Object type def ini t ions 44
I .8.9.7 Value type def ini t ion 47
I .8.9.8 Type inher i tance 47
I .8.9.9 Object type inher i tance 47
I .8.9.10 Value type inher i tance 48
I .8.9.11 Inter face type der ivat ion 48
I .8.10 Member inher i tance 48
I .8.10.1 Field inher i tance 48
I .8.10.2 Method inher i tance 48
I .8.10.3 Proper ty and event inher i tance 49
I .8.10.4 Hiding, over r iding, and layo ut 49
I .8.11 Member def ini t ions 50
I .8.11.1 Method def ini t ions 50
I .8.11.2 Field def ini t ions 51
I .8.11.3 Proper ty def ini t ions 51
I .8.11.4 Event def ini t ions 52
I .8.11.5 Nested type def ini t ions 52
© Ecma International 2012 v
I.9 Metadata 53
I .9.1 Component s and as sembl ies 53
I .9.2 Acces s ing metadata 53
I .9.2.1 Metadata tokens 54
I .9.2.2 Member s ignatures in metadata 54
I .9.3 Unmanaged code 54
I .9.4 Method implementat ion metadata 54
I .9.5 Class layout 55
I .9.6 As sembl ies: name scopes for types 55
I .9.7 Metadata extensibi l i ty 56
I .9.8 Global s, impor t s, and expor ts 57
I .9.9 Scoped s tat ics 58
I.10 Name and type rules for the Common Language
Speci f icat ion 59
I .10.1 Ident i f ier s 59
I .10.2 Over loading 59
I .10.3 Operator over loading 60
I .10.3.1 Unary operator s 60
I .10.3.2 Binary oper ator s 61
I .10.3.3 Conver s ion oper ator s 62
I .10.4 Naming pat terns 62
I .10.5 Except ions 63
I .10.6 Custom at t r ibutes 63
I .10.7 Gener ic types and methods 64
I .10.7.1 Nested type parameter r e -declarat ion 64
I .10.7.2 Type names and ar i ty encoding 65
I .10.7.3 Type const r aint re -declarat ion 66
I .10.7.4 Const r aint type rest r ict ions 67
I .10.7.5 Frameworks and access ibi l i ty of nes ted types 67
I .10.7.6 Frameworks and abst r act or vi r tual methods 68
I.11 Col lect ed Common Language Speci f icat ion rules 69
I.12 Virtual Execut ion Syst em 72
I .12.1 Suppor ted data types 72
I .12.1.1 Nat ive s ize: nat ive int , nat ive unsigned int , O and & 73
I .12.1.2 Handl ing of shor t integer data types 74
I .12.1.3 Handl ing of f loat ing -point data types 75
I .12.1.4 CIL inst ruct ions and numer ic types 76
I .12.1.5 CIL inst ruct ions and pointer types 77
I .12.1.6 Aggregate data 78
vi © Ecma International 2012
I .12.2 Module informat ion 81
I .12.3 Machine state 81
I .12.3.1 The global state 81
I .12.3.2 Method s tate 82
I .12.4 Cont rol f low 85
I .12.4.1 Method cal l s 86
I .12.4.2 Except ion handl ing 89
I .12.5 Proxies and remot ing 99
I .12.6 Memory model and opt imizat ions 100
I .12.6.1 The memory s tore 100
I .12.6.2 Al ignment 100
I .12.6.3 Byte order ing 100
I .12.6.4 Opt imizat ion 100
I .12.6.5 Locks and threads 101
I .12.6.6 Atomic r eads and wr i tes 102
I .12.6.7 Volat i le r eads and wr i tes 102
I .12.6.8 Other memory model i s sues 103
I I.1 Introduction 105
I I.2 Overview 106
I I.3 Validation and verificat ion 107
I I.4 Introductory examples 108
I I .4.1 “ H e l l o wo r l d ! ” 108
I I .4.2 Other examples 108
I I.5 General syntax 109
I I .5.1 Gener al syntax notat ion 109
I I .5.2 Bas ic syntax categor ies 109
I I .5.3 Ident i f ier s 110
I I .5.4 Label s and l i st s of label s 111
I I .5.5 Lis t s of hex bytes 111
I I .5.6 Float ing-point number s 111
I I .5.7 Source l ine informat ion 112
I I .5.8 Fi le names 112
I I .5.9 At t r ibutes and metadata 112
I I .5.10 i lasm sour ce f i les 112
I I.6 As sembl ies, mani f est s and modules 114
I I .6.1 Overview of modules , as sembl ies, and f i les 114
I I .6.2 Def ining an assembly 115
I I .6.2.1 Informat ion about the as sembly (AsmDecl ) 115
© Ecma International 2012 vii
I I .6.2.2 Mani fes t resour ces 118
I I .6.2.3 As sociat ing f i les wi th an as sembly 118
I I .6.3 Referencing as sembl ies 118
I I .6.4 Declar ing modules 119
I I .6.5 Referencing modules 120
I I .6.6 Declarat ions inside a module or as sembly 120
I I .6.7 Expor ted type def ini t ions 120
I I .6.8 Type forwarder s 121
I I.7 Types and s ignatures 122
I I .7.1 Types 122
I I .7.1.1 modr eq and modopt 123
I I .7.1.2 pinned 123
I I .7.2 Bui l t - in types 124
I I .7.3 References to user -def ined types (TypeReference ) 124
I I .7.4 Nat ive data types 125
I I.8 Vi sibi l i ty, access ibi l i ty and hiding 127
I I .8.1 Vi sibi l i ty of top - level types and acces sibi l i ty of nes ted types 127
I I .8.2 Acces s ibi l i ty 127
I I .8.3 Hiding 127
I I.9 Generics 128
I I .9.1 Gener ic type def ini t ions 128
I I .9.2 Gener ics and recur s ive inher i tance graphs 129
I I .9.3 Gener ic method def ini t ions 130
I I .9.4 Instant iat ing gener ic types 131
I I .9.5 Gener ics var iance 132
I I .9.6 As s ignment compat ibi l i ty of instant iated types 132
I I .9.7 Val idi ty of member s ignatures 133
I I .9.8 Signatures and binding 134
I I .9.9 Inher i tance and over r iding 135
I I .9.10 Expl ici t method over r ides 136
I I .9.11 Const r aints on gener ic parameter s 137
I I .9.12 References to member s of gener ic types 138
I I.10 Def ining types 139
I I .10.1 Type header (Clas sHeader ) 139
I I .10.1.1 Vi sibi l i ty and acces sibi l i ty at t r ibutes 140
I I .10.1.2 Type layout at t r ibutes 141
I I .10.1.3 Type semant ics at t r ibutes 141
I I .10.1.4 Inher i tance at t r ibutes 142
viii © Ecma International 2012
I I .10.1.5 Interoper at ion at t r ibutes 142
I I .10.1.6 Special handl ing at t r ibutes 142
I I .10.1.7 Gener ic parameter s (GenPar s ) 143
I I .10.2 Body of a type def ini t ion 146
I I .10.3 Int roducing and over r idi ng vi r tual methods 147
I I .10.3.1 Int roducing a vi r tual me thod 147
I I .10.3.2 The .over r ide di rect ive 147
I I .10.3.3 Acces s ibi l i ty and over r iding 148
I I .10.3.4 Impact of over r ides on der ived clas ses 149
I I .10.4 Method implementat ion requi rement s 150
I I .10.5 Special member s 150
I I .10.5.1 Instance const ructor 150
I I .10.5.2 Instance f inal izer 151
I I .10.5.3 Type ini t ial izer 151
I I .10.6 Nested types 153
I I .10.7 Cont rol l ing ins tance layout 153
I I .10.8 Global f ields and methods 154
I I.11 Semant ics of clas ses 156
I I.12 Semant ics of interfaces 157
I I .12.1 Implement ing inter faces 157
I I .12.2 Implement ing vi r tual methods on inter faces 157
I I .12.2.1 Inter face Implementat ion Examples 159
I I.13 Semant ics of value types 162
I I .13.1 Referencing value types 163
I I .13.2 Ini t ial izing value types 163
I I .13.3 Methods of value types 164
I I.14 Semant ics of special types 166
I I .14.1 Vector s 166
I I .14.2 Ar rays 166
I I .14.3 Enums 168
I I .14.4 Pointer types 169
I I .14.4.1 Unmanaged pointer s 170
I I .14.4.2 Managed pointer s 171
I I .14.5 Method pointer s 171
I I .14.6 Delegates 172
I I .14.6.1 Delegate signature compat ibi l i ty 173
I I .14.6.2 Synchronous cal ls to delegates 174
I I .14.6.3 Asynchronous cal l s to delegates 175
© Ecma International 2012 ix
I I.15 Def ining, ref erencing, and cal l ing methods 177
I I .15.1 Method descr iptor s 177
I I .15.1.1 Method declarat ions 177
I I .15.1.2 Method def ini t ions 177
I I .15.1.3 Method refer ences 177
I I .15.1.4 Method implementat ions 177
I I .15.2 Stat ic, ins tance, and vi r tual methods 177
I I .15.3 Cal l ing convent ion 178
I I .15.4 Def ining methods 179
I I .15.4.1 Method body 180
I I .15.4.2 Predef ined at t r ibutes on methods 182
I I .15.4.3 Implementat ion at t r ibutes of methods 184
I I .15.4.4 Scope blocks 186
I I .15.4.5 var arg methods 186
I I .15.5 Unmanaged methods 187
I I .15.5.1 Method t rans i t ion thunks 187
I I .15.5.2 Plat form invoke 188
I I .15.5.3 Method cal l s via funct ion pointer s 189
I I .15.5.4 Data type mar shal ing 189
I I.16 Def ining and referencing f ields 190
I I .16.1 At t r ibutes of f ields 190
I I .16.1.1 Acces s ibi l i ty informat ion 191
I I .16.1.2 Field cont ract at t r ibutes 191
I I .16.1.3 Interoper at ion at t r ibutes 191
I I .16.1.4 Other at t r ibutes 192
I I .16.2 Field ini t metadata 192
I I .16.3 Embedding data in a PE f i le 193
I I .16.3.1 Data declar at ion 193
I I .16.3.2 Acces s ing data f rom the PE f i le 194
I I .16.4 Ini t ial izat ion of non - l i teral stat ic data 194
I I .16.4.1 Data known at l ink t ime 194
I I .16.5 Data known at load t ime 195
I I .16.5.1 Data known at run t ime 195
I I.17 Def ining propert ies 196
I I.18 Def ining event s 198
I I.19 Except ion handl ing 201
I I .19.1 Protected blocks 201
I I .19.2 Handler blocks 201
x © Ecma International 2012
I I .19.3 Catch blocks 202
I I .19.4 Fi l ter blocks 202
I I .19.5 Final ly blocks 203
I I .19.6 Faul t handler s 203
I I.20 Declarat ive securi ty 204
I I.21 Custom at tributes 205
I I .21.1 CLS convent ions : cus tom at t r ibute usage 205
I I .21.2 At t r ibutes used by the CLI 205
I I .21.2.1 Pseudo cus tom at t r ibutes 206
I I .21.2.2 Custom at t r ibutes def ined by the CLS 207
I I .21.2.3 Custom at t r ibutes for secur i ty 207
I I .21.2.4 Custom at t r ibutes for TLS 207
I I .21.2.5 Custom at t r ibutes, var ious 208
I I.22 Metadata logical forma t : tables 209
I I .22.1 Metadata val idat ion rules 210
I I .22.2 As sembly : 0 x20 211
I I .22.3 As semblyOS : 0x22 212
I I .22.4 As semblyProces sor : 0x21 212
I I .22.5 As semblyRef : 0x23 212
I I .22.6 As semblyRefOS : 0x25 213
I I .22.7 As semblyRefProcessor : 0x24 213
I I .22.8 ClassLayout : 0x0F 214
I I .22.9 Constant : 0x0B 216
I I .22.10 CustomAt t r ibute : 0x0C 216
I I .22.11 DeclSecur i ty : 0x0E 218
I I .22.12 EventMap : 0x12 220
I I .22.13 Event : 0x14 220
I I .22.14 Expor tedType : 0x27 222
I I .22.15 Field : 0x04 223
I I .22.16 FieldLayout : 0x10 225
I I .22.17 FieldMar shal : 0x0D 226
I I .22.18 FieldRVA : 0x1D 227
I I .22.19 Fi le : 0x26 227
I I .22.20 Gener icParam : 0x2A 228
I I .22.21 Gener icParamCons t raint : 0x2C 229
I I .22.22 ImplMap : 0x1C 230
I I .22.23 Inter faceImpl : 0x09 231
I I .22.24 Mani fes tResource : 0x28 231
I I .22.25 MemberRef : 0x0A 232
© Ecma International 2012 xi
I I .22.26 MethodDef : 0x06 233
I I .22.27 MethodImpl : 0x19 236
I I .22.28 MethodSemant ics : 0x18 237
I I .22.29 MethodSpec : 0x2B 238
I I .22.30 Module : 0x00 239
I I .22.31 ModuleRef : 0x1A 239
I I .22.32 NestedClas s : 0x29 240
I I .22.33 Param : 0x08 240
I I .22.34 Proper ty : 0x17 241
I I .22.35 Proper tyMap : 0x15 242
I I .22.36 StandAloneSig : 0x11 243
I I .22.37 TypeDef : 0x02 243
I I .22.38 TypeRef : 0x01 247
I I .22.39 TypeSpec : 0x1B 248
I I.23 Metadata logical forma t : other structures 249
I I .23.1 Bi tmasks and f lags 249
I I .23.1.1 Values for As semblyHashAlgor i thm 249
I I .23.1.2 Values for As semblyFlags 249
I I .23.1.3 Values for Cul ture 249
I I .23.1.4 Flags for event s [EventAt t r ibutes] 250
I I .23.1.5 Flags for f ields [FieldAt t r ibutes] 250
I I .23.1.6 Flags for f i les [Fi leAt t r ibutes] 251
I I .23.1.7 Flags for Gener ic Par ameter s [Gener icPar amAt t r ibutes] 251
I I .23.1.8 Flags for ImplMap [PInvokeAt t r ibutes] 251
I I .23.1.9 Flags for Mani fes tResource [Mani fes tResourceAt t r ibutes] 252
I I .23.1.10 Flags for methods [MethodAt t r ibutes] 252
I I .23.1.11 Flags for methods [MethodImplAt t r ibutes] 253
I I .23.1.12 Flags for MethodSemant ics [MethodSemant icsAt t r ibutes] 253
I I .23.1.13 Flags for par ams [ParamAt t r ibutes] 253
I I .23.1.14 Flags for proper t ies [Proper tyAt t r ibutes] 254
I I .23.1.15 Flags for types [TypeAt t r ibutes] 254
I I .23.1.16 Element types used in signatures 255
I I .23.2 Blobs and signatures 257
I I .23.2.1 MethodDefSig 259
I I .23.2.2 MethodRefSig 260
I I .23.2.3 StandAloneMethodSig 261
I I .23.2.4 FieldSig 262
I I .23.2.5 Proper tySig 262
I I .23.2.6 LocalVarSig 263
xii © Ecma International 2012
I I .23.2.7 CustomMod 263
I I .23.2.8 TypeDefOrRefOrSpecEncoded 264
I I .23.2.9 Const r aint 264
I I .23.2.10 Param 264
I I .23.2.11 RetType 265
I I .23.2.12 Type 265
I I .23.2.13 ArrayShape 265
I I .23.2.14 TypeSpec 266
I I .23.2.15 MethodSpec 266
I I .23.2.16 Shor t form signatures 267
I I .23.3 Custom at t r ibutes 267
I I .23.4 Mar shal l ing descr iptor s 269
I I.24 Metadata phys ical layout 271
I I .24.1 Fixed f ields 271
I I .24.2 Fi le header s 271
I I .24.2.1 Metadata root 271
I I .24.2.2 St r eam header 272
I I .24.2.3 #St r ings heap 272
I I .24.2.4 #US and #Blob heaps 272
I I .24.2.5 #GUID heap 272
I I .24.2.6 #~ s t ream 273
I I.25 Fi le format extens ions to PE 277
I I .25.1 St ructure of the runt ime f i le format 277
I I .25.2 PE header s 277
I I .25.2.1 MS-DOS header 278
I I .25.2.2 PE f i le header 278
I I .25.2.3 PE opt ional header 279
I I .25.3 Sect ion header s 281
I I .25.3.1 Impor t Table and Impor t Addres s Table ( IAT) 282
I I .25.3.2 Relocat ions 282
I I .25.3.3 CLI header 283
I I .25.4 Common Intermediate Language phys ical layout 284
I I .25.4.1 Method header type values 285
I I .25.4.2 Tiny format 285
I I .25.4.3 Fat format 285
I I .25.4.4 Flags for method header s 285
I I .25.4.5 Method data sect ion 286
I I .25.4.6 Except ion handl ing clauses 286
I II.1 Introduct ion 290
© Ecma International 2012 xiii
I I I .1.1 Data types 290
I I I .1.1.1 Numer ic data types 291
I I I .1.1.2 Boolean data type 293
III.1.1.3 Char acter data type 293
I I I .1.1.4 Object r efer ences 293
I I I .1.1.5 Runt ime pointer types 293
I I I .1.2 Inst ruct ion var iant table 295
I I I .1.2.1 Opcode encodings 295
I I I .1.3 Stack t ransi t ion diagr am 301
I I I .1.4 Engl i sh descr ipt ion 302
I I I .1.5 Operand type table 302
I I I .1.6 Impl ici t argument coercion 305
I I I .1.7 Res t r ict ions on CIL code sequences 306
I I I .1.7.1 The inst ruct ion st r eam 307
I I I .1.7.2 Val id branch targets 307
I I I .1.7.3 Except ion ranges 307
I I I .1.7.4 Mus t provide maxs tac k 308
I I I .1.7.5 Backward branch const r aint s 308
I I I .1.7.6 Branch ver i f icat ion cons t raint s 308
I I I .1.8 Ver i f iabi l i ty and cor r ectnes s 308
I I I .1.8.1 Flow cont rol rest r ict ions for ver i f iable CIL 309
I I I .1.9 Metadata tokens 313
I I I .1.10 Except ions thrown 314
I II.2 Pref ixes to instruct ions 315
I I I .2.1 const rained. – (pref ix) invoke a member on a value of a
var iable type 316
I I I .2.2 no. – (pr ef ix) pos s ibly skip a faul t check 318
I I I .2.3 readonly. (pr ef ix) – fol lowing inst ruct ion returns a cont rol led -
mutabi l i ty managed pointer 319
I I I .2.4 tai l . (pref ix) – cal l terminates cur rent method 320
I I I .2.5 unal igned. (pr ef ix) – pointer inst ruct ion might be unal igned 321
I I I .2.6 volat i le. (pref ix) – pointer reference is volat i le 322
I II.3 Base inst ruct ions 323
I I I .3.1 add – add numer ic values 324
I I I .3.2 add.ovf .<signed> – add integer values wi th over f low check 325
I I I .3.3 and – bi twi se AND 326
I I I .3.4 argl ist – get argument l i st 327
I I I .3.5 beq.<length> – branch on equal 328
I I I .3.6 bge.<length> – branch on gr eater than or equal to 329
xiv © Ecma International 2012
I I I .3.7 bge.un.<length> – branch on greater than or equal to,
unsigned or unordered 330
I I I .3.8 bgt .<length> – branch on gr eater than 331
I I I .3.9 bgt .un.<length> – branch on greater than, uns igned or
unordered 332
I I I .3.10 ble.<length> – br anch on les s than or equal to 333
I I I .3.11 ble.un.<length> – branch on les s than or equal to, unsigned or
unordered 334
I I I .3.12 bl t .<length> – branch on les s than 335
I I I .3.13 bl t .un.<length> – branch on les s than, unsigned or unordered 336
I I I .3.14 bne.un<length> – br anch on not equal or unordered 337
I I I .3.15 br .<length> – uncondi t ional branch 338
I I I .3.16 break – breakpoint inst ruct ion 339
I I I .3.17 br false.<length> – br anch on false, nul l , or zero 340
I I I .3.18 br t rue.<length> – branch on non- false or non-nul l 341
I I I .3.19 cal l – cal l a method 342
I I I .3.20 cal l i – indi rect method cal l 344
I I I .3.21 ceq – compare equal 346
I I I .3.22 cgt – compar e greater than 347
I I I .3.23 cgt .un – compar e greater than, uns igned or unordered 348
I I I .3.24 ckf ini te – check for a f ini te real number 349
I I I .3.25 cl t – compare less than 350
I I I .3.26 cl t .un – compar e less than, uns igned or unorder ed 351
I I I .3.27 conv.<to type> – data conver s ion 352
I I I .3.28 conv.ovf .<to type> – data conver sion wi th over f low detect ion 353
I I I .3.29 conv.ovf .<to type>.un – unsigned data conver s ion wi th
over f low detect ion 354
I I I .3.30 cpblk – copy data f rom memory to memory 355
I I I .3.31 div – divide values 356
I I I .3.32 div.un – divide integer values, uns igned 357
I I I .3.33 dup – dupl icate the top value of the s tack 358
I I I .3.34 endf i l ter – end except ion handl ing f i l ter clause 359
I I I .3.35 endf inal ly – end the f inal ly or faul t clause of an except ion
block 360
I I I .3.36 ini tblk – ini t ial ize a block of memory to a value 361
III .3.37 jmp – jump to method 362
I I I .3.38 ldarg.<length> – load argument onto the stack 363
I I I .3.39 ldarga.<length> – load an argument addr ess 364
I I I .3.40 ldc.<type> – load nume r ic cons tant 365
I I I .3.41 ldf tn – load method pointer 366
I I I .3.42 ldind.<type> – load value indi rect onto the s tack 367
© Ecma International 2012 xv
I I I .3.43 ldloc – load local var iable onto the s tack 369
I I I .3.44 ldloca.<length> – load local var iable addr ess 370
I I I .3.45 ldnul l – load a nul l pointer 371
I I I .3.46 leave.<length> – exi t a protected r egion of code 372
I I I .3.47 local loc – al locate space in the local dynamic memory pool 373
I I I .3.48 mul – mul t iply values 374
I I I .3.49 mul .ovf .<type> – mul t iply integer values wi th over f low check 375
I I I .3.50 neg – negate 376
I I I .3.51 nop – no operat ion 377
I I I .3.52 not – bi twi se complement 378
I I I .3.53 or – bi twi se OR 379
I I I .3.54 pop – r emove the top element of the s tack 380
I I I .3.55 rem – compute r emainder 381
I I I .3.56 rem.un – compute integer remainder , uns igned 382
I I I .3.57 ret – return f rom method 383
I I I .3.58 shl – shi f t integer lef t 384
I I I .3.59 shr – shi f t integer r ight 385
I I I .3.60 shr .un – shi f t integer r ight , unsigned 386
I I I .3.61 starg.<length> – stor e a value in an argument s lot 387
I I I .3.62 st ind.<type> – s tore value indi rect f rom s tack 388
I I I .3.63 st loc – pop value f rom s tack to local var iable 389
I I I .3.64 sub – subt ract numer ic values 390
I I I .3.65 sub.ovf .<type> – subt r act integer values, checking for
over f low 391
I I I .3.66 swi tch – table swi tch based on value 392
III.3.67 xor – bi twi se XOR 393
I II.4 Object model inst ruct ions 394
I I I .4.1 box – conver t a boxable value to i t s boxed form 394
I I I .4.2 cal lvi r t – cal l a method as sociated, at runt ime, wi th an object 396
I I I .4.3 castclass – cas t an object to a clas s 398
I I I .4.4 cpobj – copy a value f rom one addr es s to another 399
I I I .4.5 ini tobj – ini t ial ize the value at an addr es s 400
I I I .4.6 isinst – test i f an object is an ins tance of a class or inter face 401
I I I .4.7 ldelem – load element f rom ar ray 402
I I I .4.8 ldelem.<type> – load an element of an ar ray 403
I I I .4.9 ldelema – load addres s of an element of an ar r ay 405
I I I .4.10 ldf ld – load f ield of an object 406
I I I .4.11 ldf lda – load f ield addres s 407
I I I .4.12 ldlen – load the length of an ar r ay 408
I I I .4.13 ldobj – copy a value f rom an addr es s to the stack 409
xvi © Ecma International 2012
I I I .4.14 ldsf ld – load stat ic f ield of a clas s 410
I I I .4.15 ldsf lda – load s tat ic f ield address 411
I I I .4.16 ldst r – load a l i teral st r ing 412
I I I .4.17 ldtoken – load the runt ime representat ion of a metadata token 413
I I I .4.18 ldvi r t f tn – load a vi r tual method pointer 414
I I I .4.19 mkrefany – push a typed reference on the s tack 415
I I I .4.20 newar r – cr eate a zero -based, one -dimensional ar ray 416
I I I .4.21 newobj – create a new object 417
I I I .4.22 refanytype – load the type out of a typed refer ence 420
I I I .4.23 refanyval – load the addres s out of a typed reference 421
I I I .4.24 rethrow – rethrow the cur r ent except ion 422
I I I .4.25 sizeof – load the size, in bytes,of a type 423
I I I .4.26 stelem – store element to ar ray 424
I I I .4.27 stelem.<type> – store an element of an ar ray 425
I I I .4.28 st f ld – stor e into a f ield of an object 427
I I I .4.29 stobj – stor e a value at an addres s 428
I I I .4.30 stsf ld – stor e a stat ic f ield of a class 429
I I I .4.31 throw – throw an except ion 430
I I I .4.32 unbox – conver t boxed value type to i t s raw form 431
I I I .4.33 unbox.any – conver t boxed type to value 432
IV.1 Overview 434
IV.2 Libraries and Prof i les 435
IV.2.1 Librar ies 435
IV.2.2 Prof i les 435
IV.2.3 The relat ionship between Librar ies and Prof i les 436
IV.3 The Standard Prof i les 437
IV.3.1 The Kernel Prof i le 437
IV.3.2 The Compact Prof i le 437
IV.4 Kernel Prof i le feature requirement s 438
IV.4.1 Features excluded f rom the Kernel Prof i le 438
IV.4.1.1 Float ing point 438
IV.4.1.2 Non-vector ar rays 438
IV.4.1.3 Ref lect ion 438
IV.4.1.4 Appl icat ion domains 439
IV.4.1.5 Remot ing 439
IV.4.1.6 Vararg 439
IV.4.1.7 Frame growth 439
IV.4.1.8 Fi l tered except ions 439
© Ecma International 2012 xvii
IV.5 The standard l ibraries 440
IV.5.1 Gener al comments 440
IV.5.2 Runt ime inf r as t ructure l ibrary 440
IV.5.3 Base Clas s Library (BCL) 440
IV.5.4 Network l ibr ary 440
IV.5.5 Ref lect ion l ibrary 440
IV.5.6 XML l ibr ary 440
IV.5.7 Extended numer ics l ibrary 441
IV.5.8 Extended ar ray l ibrary 441
IV.5.9 Vararg l ibrary 441
IV.5.10 Paral lel l ibr ary 441
IV.6 Implementat ion- speci f ic modi f icat ions to the system
l ibraries 443
IV.7 The XML speci f icat ion 444
IV.7.1 Semant ics 444
IV.7.1.1 Value types as object s 452
IV.7.1.2 Except ions 452
IV.7.2 XML s ignature notat ion is sues 452
IV.7.2.1 Ser ial izat ion 452
IV.7.2.2 Delegates 452
IV.7.2.3 Proper t ies 453
IV.7.2.4 Nested types 453
V.1 Portable CILDB f i les 455
V.1.1 Encoding of integer s 455
V.1.2 CILDB header 455
V.1.2.1 Ver sion GUID 455
V.1.3 Tables and heaps 455
V.1.3.1 SymConstant table 456
V.1.3.2 SymDocument t able 456
V.1.3.3 SymMethod table 456
V.1.3.4 SymSequencePoint table 457
V.1.3.5 SymScope table 457
V.1.3.6 SymVar iable table 457
V.1.3.7 SymUs ing table 458
V.1.3.8 SymMi sc heap 458
V.1.3.9 SymSt r ing heap 458
V.1.4 Signatures 458
VI.Annex A Introduct ion 461
xviii © Ecma International 2012
VI.Annex B Sample programs 462
VI .B.1 Mutual ly r ecur sive program (wi th tai l cal l s) 462
VI .B.2 Us ing value types 463
VI .B.3 Custom at t r ibutes 465
VI .B.4 Gener ics code and metadata 468
VI .B.4.1 ILAsm ver s ion 468
VI .B.4.2 C# ver s ion 469
VI .B.4.3 Metadata 469
VI.Annex C CIL as sembler implementat ion 471
VI .C.1 ILAsm keywords 471
VI .C.2 CIL opcode descr ipt ions 483
VI .C.3 Complete grammar 494
VI .C.4 Inst ruct ion syntax 509
VI .C.4.1 Top- level ins t ruct ion syntax 510
VI .C.4.2 Inst ruct ions wi th no operand 510
VI .C.4.3 Inst ruct io ns that r efer to parameter s or local var iables 511
VI .C.4.4 Inst ruct ions that take a single 32 -bi t integer argument 512
VI .C.4.5 Inst ruct ions that take a single 64 -bi t integer argument 512
VI .C.4.6 Inst ruct ions that take a single f loat ing -point argument 512
VI .C.4.7 Branch ins t ruct ions 513
VI .C.4.8 Inst ruct ions that take a method as an argument 513
VI .C.4.9 Inst ruct ions that take a f ield of a clas s as an argument 513
VI .C.4.10 Inst ruct ions that take a type as an argument 513
VI .C.4.11 Inst ruct ions that take a st r ing as an argument 514
VI .C.4.12 Inst ruct ions that take a signature as an argument 514
VI .C.4.13 Inst ruct ions that take a metadata token as an argument 514
VI .C.4.14 Swi tch inst ruct ion 515
VI.Annex D Clas s l ibrary design guidel ines 516
VI.Annex E Portabi l i ty considerat ions 517
VI .E.1 Uncont rol lable behavior 517
VI .E.2 Language - and compi ler -cont rol lable behavior 517
VI .E.3 Programmer -cont rol lable behavior 517
VI.Annex F Imprecise faul t s 519
VI .F.1 Inst ruct ion reorder ing 519
VI .F.2 Inl ining 519
VI .F.3 Final ly handler s st i l l guaranteed once a t ry block is entere d 519
VI .F.4 Inter leaved cal l s 520
VI .F.4.1 Rejected not ions for fencing 520
© Ecma International 2012 xix
VI .F.5 Examples 520
VI .F.5.1 Hoi st ing checks out of a loop 521
VI .F.5.2 Vector izing a loop 521
VI .F.5.3 Autothreading a loop 521
VI.Annex G Paral lel l ibrary 523
VI .G.1 Considerat ions 523
VI .G.2 Paral lelFor 523
VI .G.3 Paral lelForEach 523
VI .G.4 Paral lelWhi le 524
VI .G.5 Debugging 524
Index 525