wasm_interp: implement indirect_call

This commit is contained in:
Brian Carroll 2022-11-27 12:46:30 +00:00
parent 468be47da2
commit c2fb626c17
No known key found for this signature in database
GPG key ID: 5C7B2EC4101703C0
3 changed files with 165 additions and 31 deletions

View file

@ -194,7 +194,7 @@ pub fn update_section_size<T: SerialBuffer>(buffer: &mut T, header_indices: Sect
*
*******************************************************************/
#[derive(PartialEq, Eq, Debug)]
#[derive(PartialEq, Eq, Debug, Clone)]
pub struct Signature<'a> {
pub param_types: Vec<'a, ValueType>,
pub ret_type: Option<ValueType>,
@ -1165,6 +1165,13 @@ pub struct ElementSegment<'a> {
}
impl<'a> ElementSegment<'a> {
pub fn new(arena: &'a Bump) -> Self {
ElementSegment {
offset: ConstExpr::I32(0),
fn_indices: Vec::new_in(arena),
}
}
fn size(&self) -> usize {
let variant_id = 1;
let constexpr_opcode = 1;
@ -1267,6 +1274,14 @@ impl<'a> ElementSection<'a> {
pub fn is_empty(&self) -> bool {
self.segments.iter().all(|seg| seg.fn_indices.is_empty())
}
/// Look up a "function pointer" (element index) and return the function index.
pub fn lookup(&self, element_index: u32) -> Option<u32> {
self.segments.iter().find_map(|seg| {
let adjusted_index = element_index as usize - seg.offset.unwrap_i32() as usize;
seg.fn_indices.get(adjusted_index).copied()
})
}
}
impl<'a> Parse<&'a Bump> for ElementSection<'a> {