1
- use crate :: { FunctionSignature , CLRMethod } ;
2
1
use crate :: IString ;
2
+ use crate :: { CLRMethod , FunctionSignature } ;
3
3
use rustc_middle:: {
4
4
mir:: mono:: MonoItem ,
5
5
ty:: { Instance , ParamEnv , TyCtxt } ,
@@ -9,10 +9,9 @@ pub(crate) struct Assembly {
9
9
name : IString ,
10
10
}
11
11
impl Assembly {
12
-
13
12
pub ( crate ) fn into_il_ir ( & self ) -> IString {
14
13
let mut methods = String :: new ( ) ;
15
- for method in & self . methods {
14
+ for method in & self . methods {
16
15
methods. push_str ( & method. into_il_ir ( ) ) ;
17
16
}
18
17
let methods = format ! ( ".class {name} {{{methods}}}" , name = self . name) ;
@@ -22,33 +21,39 @@ impl Assembly {
22
21
impl Assembly {
23
22
pub ( crate ) fn new ( name : & str ) -> Self {
24
23
let name: String = name. chars ( ) . take_while ( |c| * c != '.' ) . collect ( ) ;
25
- let name = name. replace ( "-" , "_" ) ;
24
+ let name = name. replace ( '-' , "_" ) ;
26
25
Self {
27
26
methods : Vec :: with_capacity ( 0x100 ) ,
28
27
name : name. into ( ) ,
29
28
}
30
29
}
31
- pub ( crate ) fn add_fn < ' tcx > ( & mut self , instance : Instance < ' tcx > , tcx : TyCtxt < ' tcx > , name : & str ) {
30
+ pub ( crate ) fn add_fn < ' tcx > ( & mut self , instance : Instance < ' tcx > , tcx : TyCtxt < ' tcx > , name : & str ) {
32
31
// TODO: figure out: What should it be???
33
32
let param_env = ParamEnv :: empty ( ) ;
34
33
35
34
let def_id = instance. def_id ( ) ;
36
35
let mir = tcx. optimized_mir ( def_id) ;
37
36
let blocks = & ( * mir. basic_blocks ) ;
38
37
let sig = instance. ty ( tcx, param_env) . fn_sig ( tcx) ;
39
- let mut clr_method = CLRMethod :: new ( FunctionSignature :: from_poly_sig ( sig) . expect ( "Could not resolve the function signature" ) , name) ;
38
+ let mut clr_method = CLRMethod :: new (
39
+ FunctionSignature :: from_poly_sig ( sig)
40
+ . expect ( "Could not resolve the function signature" ) ,
41
+ name,
42
+ ) ;
40
43
for block_data in blocks {
44
+ clr_method. begin_bb ( ) ;
41
45
for statement in & block_data. statements {
42
- clr_method. add_statement ( statement) ;
46
+ clr_method. add_statement ( statement, mir , & tcx ) ;
43
47
}
44
48
match & block_data. terminator {
45
- Some ( term) => clr_method. add_terminator ( term) ,
49
+ Some ( term) => clr_method. add_terminator ( term, mir , & tcx ) ,
46
50
None => ( ) ,
47
51
}
48
52
}
49
- // Optimization is currently broken, and may produce invalid IR.
53
+ // Optimization is currently broken, and may produce invalid IR.
50
54
//clr_method.opt();
51
- clr_method. typecheck ( ) ;
55
+ //clr_method.typecheck();
56
+ clr_method. add_locals ( & mir. local_decls ) ;
52
57
println ! ( "clr_method:{clr_method:?}" ) ;
53
58
println ! ( "instance:{instance:?}\n " ) ;
54
59
self . methods . push ( clr_method) ;
@@ -57,7 +62,9 @@ impl Assembly {
57
62
println ! ( "adding item:{}" , item. symbol_name( tcx) ) ;
58
63
59
64
match item {
60
- MonoItem :: Fn ( instance) => self . add_fn ( instance, tcx, & format ! ( "{}" , item. symbol_name( tcx) ) ) ,
65
+ MonoItem :: Fn ( instance) => {
66
+ self . add_fn ( instance, tcx, & format ! ( "{}" , item. symbol_name( tcx) ) )
67
+ }
61
68
_ => todo ! ( "Unsupported item:\" {item:?}\" !" ) ,
62
69
}
63
70
}
0 commit comments