Skip to content

Commit

Permalink
Codegen C - Support const_eval_select
Browse files Browse the repository at this point in the history
  • Loading branch information
thepowersgang committed Jan 14, 2024
1 parent 247a345 commit a39cfc9
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/trans/codegen_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5493,6 +5493,25 @@ namespace {
else if( name == "assert_uninit_valid" ) {
// TODO: Detect nonzero or enum within
}
else if( name == "const_eval_select" ) {
const auto& arg_ty_tuple = params.m_types.at(0).data().as_Tuple();
const auto& arg = e.args.at(0).as_LValue();
// Note: arg 1 is the constant function
const auto& fcn_path = *e.args.at(2).as_Constant().as_ItemAddr();

// HACK: Just make a path terminator and call into that
::std::vector<MIR::Param> args;
args.reserve(arg_ty_tuple.size());
for(size_t i = 0; i < arg_ty_tuple.size(); i ++) {
args.push_back(MIR::LValue::new_Field(arg.clone(), i));
}
auto pseudo_term = MIR::Terminator::Data_Call {
e.ret_block, e.panic_block, e.ret_val.clone(),
MIR::CallTarget::make_Path(fcn_path.clone()),
std::move(args)
};
emit_term_call(mir_res, pseudo_term, 1);
}
// --- Type identity ---
else if( name == "type_id" ) {
const auto& ty = params.m_types.at(0);
Expand Down

0 comments on commit a39cfc9

Please sign in to comment.