@@ -28,7 +28,7 @@ impl AssemblyExporter for ILASMExporter {
28
28
Self { encoded_asm }
29
29
}
30
30
fn add_type ( & mut self , tpe : & TypeDef ) {
31
- type_def_cli ( & mut self . encoded_asm , tpe) . expect ( "Error" ) ;
31
+ type_def_cli ( & mut self . encoded_asm , tpe) . expect ( "Error" ) ;
32
32
//let _ = self.types.push(tpe.clone());
33
33
}
34
34
fn add_method ( & mut self , method : & Method ) {
@@ -84,33 +84,36 @@ impl AssemblyExporter for ILASMExporter {
84
84
}
85
85
}
86
86
87
- fn type_def_cli ( mut w : impl Write , tpe : & TypeDef ) -> Result < ( ) , super :: AssemblyExportError > {
87
+ fn type_def_cli ( mut w : impl Write , tpe : & TypeDef ) -> Result < ( ) , super :: AssemblyExportError > {
88
88
let name = tpe. name ( ) ;
89
89
let mut generics = String :: new ( ) ;
90
- if tpe. gargc ( ) != 0 {
90
+ if tpe. gargc ( ) != 0 {
91
91
generics. push ( '<' ) ;
92
92
}
93
- for i in 0 ..tpe. gargc ( ) {
94
- if i != 0 {
93
+ for i in 0 ..tpe. gargc ( ) {
94
+ if i != 0 {
95
95
generics. push ( ',' ) ;
96
96
}
97
97
generics. push_str ( & format ! ( "G{i}" ) ) ;
98
98
}
99
- if tpe. gargc ( ) != 0 {
99
+ if tpe. gargc ( ) != 0 {
100
100
generics. push ( '>' ) ;
101
101
}
102
- let extended = if let Some ( extended) = tpe. extends ( ) {
102
+ let extended = if let Some ( extended) = tpe. extends ( ) {
103
103
todo ! ( "Can't handle inheretence yet!" ) ;
104
- }
105
- else {
104
+ } else {
106
105
"[System.Runtime]System.ValueType"
107
106
} ;
108
- writeln ! ( w, "\n .class {name}{generics} extends {extended}{{" ) ;
107
+ writeln ! ( w, "\n .class {name}{generics} extends {extended}{{" ) ;
109
108
let mut field_string = String :: new ( ) ;
110
- for ( field_name, field_type) in tpe. fields ( ) . iter ( ) {
111
- writeln ! ( w, "\t .field {field_type_name} {field_name}" , field_type_name = prefixed_type_cli( field_type) ) ;
109
+ for ( field_name, field_type) in tpe. fields ( ) . iter ( ) {
110
+ writeln ! (
111
+ w,
112
+ "\t .field {field_type_name} {field_name}" ,
113
+ field_type_name = prefixed_type_cli( field_type)
114
+ ) ;
112
115
}
113
- writeln ! ( w, "}}" ) ;
116
+ writeln ! ( w, "}}" ) ;
114
117
Ok ( ( ) )
115
118
}
116
119
fn absolute_path ( path : & std:: path:: Path ) -> std:: io:: Result < std:: path:: PathBuf > {
@@ -133,16 +136,24 @@ fn method_cil(mut w: impl Write, method: &Method) -> std::io::Result<()> {
133
136
write ! ( w, ".method {access} static hidebysig {output} {name}" ) ?;
134
137
args_cli ( & mut w, method. sig ( ) . inputs ( ) ) ?;
135
138
writeln ! ( w, "{{" ) ?;
136
- if method. is_entrypoint ( ) {
137
- writeln ! ( w, ".entrypoint" ) ?;
139
+ if method. is_entrypoint ( ) {
140
+ writeln ! ( w, ".entrypoint" ) ?;
138
141
}
139
142
writeln ! ( w, "\t .locals (" ) ?;
140
143
let mut locals_iter = method. locals ( ) . iter ( ) . enumerate ( ) ;
141
- if let Some ( ( local_id, local) ) = locals_iter. next ( ) {
142
- write ! ( w, "\t \t [{local_id}] {escaped_type}" , escaped_type = arg_type_cli( local) ) ?;
144
+ if let Some ( ( local_id, local) ) = locals_iter. next ( ) {
145
+ write ! (
146
+ w,
147
+ "\t \t [{local_id}] {escaped_type}" ,
148
+ escaped_type = arg_type_cli( local)
149
+ ) ?;
143
150
}
144
- for ( local_id, local) in locals_iter{
145
- write ! ( w, ",\n \t \t [{local_id}] {escaped_type}" , escaped_type = arg_type_cli( local) ) ?;
151
+ for ( local_id, local) in locals_iter {
152
+ write ! (
153
+ w,
154
+ ",\n \t \t [{local_id}] {escaped_type}" ,
155
+ escaped_type = arg_type_cli( local)
156
+ ) ?;
146
157
}
147
158
writeln ! ( w, "\n \t )" ) ?;
148
159
for op in method. get_ops ( ) {
@@ -289,95 +300,95 @@ fn op_cli(op: &crate::cil_op::CILOp) -> Cow<'static, str> {
289
300
//Debug
290
301
CILOp :: Comment ( comment) => format ! ( "//{comment}" ) . into ( ) ,
291
302
//Convertions
292
- CILOp :: ConvISize ( checked) =>
293
- if * checked{
303
+ CILOp :: ConvISize ( checked) => {
304
+ if * checked {
294
305
"conv.ovf.i" . into ( )
295
- }
296
- else {
306
+ } else {
297
307
"conv.i" . into ( )
298
308
}
299
- CILOp :: ConvI8 ( checked) =>
300
- if * checked{
309
+ }
310
+ CILOp :: ConvI8 ( checked) => {
311
+ if * checked {
301
312
"conv.ovf.i1" . into ( )
302
- }
303
- else {
313
+ } else {
304
314
"conv.i1" . into ( )
305
- }
306
- CILOp :: ConvI16 ( checked) =>
307
- if * checked{
308
- "conv.ovf.i2" . into ( )
309
315
}
310
- else {
316
+ }
317
+ CILOp :: ConvI16 ( checked) => {
318
+ if * checked {
319
+ "conv.ovf.i2" . into ( )
320
+ } else {
311
321
"conv.i2" . into ( )
312
- }
313
- CILOp :: ConvI32 ( checked) =>
314
- if * checked{
315
- "conv.ovf.i4" . into ( )
316
322
}
317
- else {
323
+ }
324
+ CILOp :: ConvI32 ( checked) => {
325
+ if * checked {
326
+ "conv.ovf.i4" . into ( )
327
+ } else {
318
328
"conv.i4" . into ( )
319
- }
320
- CILOp :: ConvI64 ( checked) =>
321
- if * checked{
322
- "conv.ovf.i8" . into ( )
323
329
}
324
- else {
330
+ }
331
+ CILOp :: ConvI64 ( checked) => {
332
+ if * checked {
333
+ "conv.ovf.i8" . into ( )
334
+ } else {
325
335
"conv.i8" . into ( )
326
- }
327
- CILOp :: ConvUSize ( checked) =>
328
- if * checked{
329
- "conv.ovf.u" . into ( )
330
336
}
331
- else {
337
+ }
338
+ CILOp :: ConvUSize ( checked) => {
339
+ if * checked {
340
+ "conv.ovf.u" . into ( )
341
+ } else {
332
342
"conv.u" . into ( )
333
343
}
334
- CILOp :: ConvU8 ( checked) =>
335
- if * checked{
344
+ }
345
+ CILOp :: ConvU8 ( checked) => {
346
+ if * checked {
336
347
"conv.ovf.u1" . into ( )
337
- }
338
- else {
348
+ } else {
339
349
"conv.u1" . into ( )
340
- }
341
- CILOp :: ConvU16 ( checked) =>
342
- if * checked{
343
- "conv.ovf.u2" . into ( )
344
350
}
345
- else {
351
+ }
352
+ CILOp :: ConvU16 ( checked) => {
353
+ if * checked {
354
+ "conv.ovf.u2" . into ( )
355
+ } else {
346
356
"conv.u2" . into ( )
347
- }
348
- CILOp :: ConvU32 ( checked) =>
349
- if * checked{
350
- "conv.ovf.u4" . into ( )
351
357
}
352
- else {
358
+ }
359
+ CILOp :: ConvU32 ( checked) => {
360
+ if * checked {
361
+ "conv.ovf.u4" . into ( )
362
+ } else {
353
363
"conv.u4" . into ( )
354
- }
355
- CILOp :: ConvU64 ( checked) =>
356
- if * checked{
357
- "conv.ovf.u8" . into ( )
358
364
}
359
- else {
365
+ }
366
+ CILOp :: ConvU64 ( checked) => {
367
+ if * checked {
368
+ "conv.ovf.u8" . into ( )
369
+ } else {
360
370
"conv.u8" . into ( )
361
- }
362
- CILOp :: ConvF32 ( checked) =>
363
- if * checked{
364
- "conv.ovf.r4" . into ( )
365
371
}
366
- else {
372
+ }
373
+ CILOp :: ConvF32 ( checked) => {
374
+ if * checked {
375
+ "conv.ovf.r4" . into ( )
376
+ } else {
367
377
"conv.r4" . into ( )
368
- }
369
- CILOp :: ConvU64 ( checked) =>
370
- if * checked{
371
- "conv.ovf.r8" . into ( )
372
378
}
373
- else {
374
- "conv.r8" . into ( )
375
- }
379
+ }
376
380
// Pointer stuff
377
381
CILOp :: LDIndI8 => "ldind.i1" . into ( ) ,
378
- CILOp :: Pop =>"pop" . into ( ) ,
379
- CILOp :: Throw =>"throw" . into ( ) ,
380
- CILOp :: LdStr ( str) =>format ! ( "ldstr {str:?}" ) . into ( ) ,
382
+ CILOp :: Pop => "pop" . into ( ) ,
383
+ CILOp :: Throw => "throw" . into ( ) ,
384
+ CILOp :: LdStr ( str) => format ! ( "ldstr {str:?}" ) . into ( ) ,
385
+ CILOp :: LDField ( descr) => format ! (
386
+ "ldfld {prefixed_type} {owner}::{field_name}" ,
387
+ prefixed_type = prefixed_type_cli( descr. tpe( ) ) ,
388
+ owner = dotnet_type_ref_cli( descr. owner( ) ) ,
389
+ field_name = descr. name( )
390
+ )
391
+ . into ( ) ,
381
392
CILOp :: NewObj ( call_site) => {
382
393
if call_site. is_nop ( ) {
383
394
"" . into ( )
@@ -460,7 +471,7 @@ fn type_cli(tpe: &Type) -> Cow<'static, str> {
460
471
Type :: Unresolved => "Unresolved" . into ( ) ,
461
472
Type :: Bool => "bool" . into ( ) ,
462
473
Type :: DotnetChar => "char" . into ( ) ,
463
- Type :: GenericArg ( idx) => format ! ( "G{idx}" ) . into ( ) ,
474
+ Type :: GenericArg ( idx) => format ! ( "! G{idx}" ) . into ( ) ,
464
475
Type :: Foreign => "valuetype Foreign" . into ( ) ,
465
476
//_ => todo!("Unsuported type {tpe:?}"),
466
477
}
@@ -483,13 +494,15 @@ fn prefixed_type_cli(tpe: &Type) -> Cow<'static, str> {
483
494
Type :: ISize => "native int" . into ( ) ,
484
495
Type :: USize => "native uint" . into ( ) ,
485
496
Type :: Ptr ( inner) => format ! ( "{inner}*" , inner = prefixed_type_cli( inner) ) . into ( ) ,
486
- Type :: DotnetType ( dotnet_type) => format ! ( "valuetype {}" , dotnet_type_ref_cli( dotnet_type) ) . into ( ) ,
497
+ Type :: DotnetType ( dotnet_type) => {
498
+ format ! ( "valuetype {}" , dotnet_type_ref_cli( dotnet_type) ) . into ( )
499
+ }
487
500
//Special type
488
501
Type :: Unresolved => "valuetype Unresolved" . into ( ) ,
489
502
Type :: Foreign => "valuetype Foreign" . into ( ) ,
490
503
Type :: Bool => "bool" . into ( ) ,
491
504
Type :: DotnetChar => "char" . into ( ) ,
492
- Type :: GenericArg ( idx) => format ! ( "G{idx}" ) . into ( ) ,
505
+ Type :: GenericArg ( idx) => format ! ( "! G{idx}" ) . into ( ) ,
493
506
//_ => todo!("Unsuported type {tpe:?}"),
494
507
}
495
508
}
@@ -512,7 +525,10 @@ fn generics_str(generics: &[Type]) -> Cow<'static, str> {
512
525
let mut garg_string = String :: new ( ) ;
513
526
let mut generic_iter = generics. iter ( ) ;
514
527
if let Some ( first_generic) = generic_iter. next ( ) {
515
- garg_string. push_str ( & format ! ( "{type_cli}" , type_cli = prefixed_type_cli( & first_generic) ) ) ;
528
+ garg_string. push_str ( & format ! (
529
+ "{type_cli}" ,
530
+ type_cli = prefixed_type_cli( & first_generic)
531
+ ) ) ;
516
532
}
517
533
for arg in generic_iter {
518
534
garg_string. push_str ( & format ! ( ",{type_cli}" , type_cli = prefixed_type_cli( & arg) ) ) ;
0 commit comments