1
0
forked from M-Labs/nac3

nac3artiq: fixed RPC codegen for lists

This commit is contained in:
pca006132 2022-03-10 16:48:28 +08:00
parent 2f85bb3837
commit 94aac16cc5

View File

@ -20,7 +20,6 @@ use crate::timeline::TimeFns;
use std::{ use std::{
collections::hash_map::DefaultHasher, collections::hash_map::DefaultHasher,
collections::HashMap, collections::HashMap,
convert::TryInto,
hash::{Hash, Hasher}, hash::{Hash, Hasher},
sync::Arc, sync::Arc,
}; };
@ -381,13 +380,8 @@ fn rpc_codegen_callback_fn<'ctx, 'a>(
} }
for (i, arg) in real_params.iter().enumerate() { for (i, arg) in real_params.iter().enumerate() {
let arg_slot = if arg.is_pointer_value() { let arg_slot = ctx.builder.build_alloca(arg.get_type(), &format!("rpc.arg{}", i));
arg.into_pointer_value() ctx.builder.build_store(arg_slot, *arg);
} else {
let arg_slot = ctx.builder.build_alloca(arg.get_type(), &format!("rpc.arg{}", i));
ctx.builder.build_store(arg_slot, *arg);
arg_slot
};
let arg_slot = ctx.builder.build_bitcast(arg_slot, ptr_type, "rpc.arg"); let arg_slot = ctx.builder.build_bitcast(arg_slot, ptr_type, "rpc.arg");
let arg_ptr = unsafe { let arg_ptr = unsafe {
ctx.builder.build_gep( ctx.builder.build_gep(
@ -451,11 +445,8 @@ fn rpc_codegen_callback_fn<'ctx, 'a>(
let alloc_bb = ctx.ctx.append_basic_block(current_function, "rpc.continue"); let alloc_bb = ctx.ctx.append_basic_block(current_function, "rpc.continue");
let tail_bb = ctx.ctx.append_basic_block(current_function, "rpc.tail"); let tail_bb = ctx.ctx.append_basic_block(current_function, "rpc.tail");
let mut ret_ty = ctx.get_llvm_type(generator, fun.0.ret); let ret_ty = ctx.get_llvm_type(generator, fun.0.ret);
let need_load = !ret_ty.is_pointer_type(); let need_load = !ret_ty.is_pointer_type();
if ret_ty.is_pointer_type() {
ret_ty = ret_ty.into_pointer_type().get_element_type().try_into().unwrap();
}
let slot = ctx.builder.build_alloca(ret_ty, "rpc.ret.slot"); let slot = ctx.builder.build_alloca(ret_ty, "rpc.ret.slot");
let slotgen = ctx.builder.build_bitcast(slot, ptr_type, "rpc.ret.ptr"); let slotgen = ctx.builder.build_bitcast(slot, ptr_type, "rpc.ret.ptr");
ctx.builder.build_unconditional_branch(head_bb); ctx.builder.build_unconditional_branch(head_bb);
@ -484,17 +475,15 @@ fn rpc_codegen_callback_fn<'ctx, 'a>(
ctx.builder.position_at_end(tail_bb); ctx.builder.position_at_end(tail_bb);
Ok(if need_load { let result = ctx.builder.build_load(slot, "rpc.result");
let result = ctx.builder.build_load(slot, "rpc.result"); if need_load {
ctx.builder.build_call( ctx.builder.build_call(
stackrestore, stackrestore,
&[stackptr.try_as_basic_value().unwrap_left().into()], &[stackptr.try_as_basic_value().unwrap_left().into()],
"rpc.stackrestore", "rpc.stackrestore",
); );
Some(result) }
} else { Ok(Some(result))
Some(slot.into())
})
} }
pub fn rpc_codegen_callback() -> Arc<GenCall> { pub fn rpc_codegen_callback() -> Arc<GenCall> {