Skip to content

Commit 78b6571

Browse files
committed
Split compile_fn out of codegen_fn
1 parent 5f6c59e commit 78b6571

File tree

1 file changed

+35
-8
lines changed

1 file changed

+35
-8
lines changed

src/base.rs

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@ use rustc_index::vec::IndexVec;
66
use rustc_middle::ty::adjustment::PointerCast;
77
use rustc_middle::ty::layout::FnAbiOf;
88

9+
use indexmap::IndexSet;
10+
911
use crate::constant::ConstantCx;
1012
use crate::prelude::*;
13+
use crate::pretty_clif::CommentWriter;
1114

1215
pub(crate) fn codegen_fn<'tcx>(
1316
cx: &mut crate::CodegenCx<'tcx>,
@@ -99,7 +102,7 @@ pub(crate) fn codegen_fn<'tcx>(
99102

100103
// Recover all necessary data from fx, before accessing func will prevent future access to it.
101104
let instance = fx.instance;
102-
let mut clif_comments = fx.clif_comments;
105+
let clif_comments = fx.clif_comments;
103106
let source_info_set = fx.source_info_set;
104107
let local_map = fx.local_map;
105108

@@ -114,13 +117,40 @@ pub(crate) fn codegen_fn<'tcx>(
114117
&clif_comments,
115118
);
116119

120+
// Verify function
121+
verify_func(tcx, &clif_comments, &func);
122+
123+
compile_fn(
124+
cx,
125+
module,
126+
instance,
127+
symbol_name.name,
128+
func_id,
129+
func,
130+
clif_comments,
131+
source_info_set,
132+
local_map,
133+
);
134+
}
135+
136+
fn compile_fn<'tcx>(
137+
cx: &mut crate::CodegenCx<'tcx>,
138+
module: &mut dyn Module,
139+
instance: Instance<'tcx>,
140+
symbol_name: &str,
141+
func_id: FuncId,
142+
func: Function,
143+
mut clif_comments: CommentWriter,
144+
source_info_set: IndexSet<SourceInfo>,
145+
local_map: IndexVec<mir::Local, CPlace<'tcx>>,
146+
) {
147+
let tcx = cx.tcx;
148+
117149
// Store function in context
118150
let context = &mut cx.cached_context;
151+
context.clear();
119152
context.func = func;
120153

121-
// Verify function
122-
verify_func(tcx, &clif_comments, &context.func);
123-
124154
// If the return block is not reachable, then the SSA builder may have inserted an `iconst.i128`
125155
// instruction, which doesn't have an encoding.
126156
context.compute_cfg();
@@ -177,7 +207,7 @@ pub(crate) fn codegen_fn<'tcx>(
177207
debug_context.define_function(
178208
instance,
179209
func_id,
180-
symbol_name.name,
210+
symbol_name,
181211
isa,
182212
context,
183213
&source_info_set,
@@ -186,9 +216,6 @@ pub(crate) fn codegen_fn<'tcx>(
186216
}
187217
unwind_context.add_function(func_id, &context, isa);
188218
});
189-
190-
// Clear context to make it usable for the next function
191-
context.clear();
192219
}
193220

194221
pub(crate) fn verify_func(

0 commit comments

Comments
 (0)