MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / metadata_records

Function metadata_records

cranelift/codegen/src/machinst/buffer.rs:2938–3007  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2936
2937 #[test]
2938 fn metadata_records() {
2939 let mut buf = MachBuffer::<Inst>::new();
2940 let ctrl_plane = &mut Default::default();
2941 let constants = Default::default();
2942
2943 buf.reserve_labels_for_blocks(3);
2944
2945 buf.bind_label(label(0), ctrl_plane);
2946 buf.put1(1);
2947 buf.add_trap(TrapCode::HEAP_OUT_OF_BOUNDS);
2948 buf.put1(2);
2949 buf.add_trap(TrapCode::INTEGER_OVERFLOW);
2950 buf.add_trap(TrapCode::INTEGER_DIVISION_BY_ZERO);
2951 buf.add_try_call_site(
2952 Some(0x10),
2953 [
2954 MachExceptionHandler::Tag(ExceptionTag::new(42), label(2)),
2955 MachExceptionHandler::Default(label(1)),
2956 ]
2957 .into_iter(),
2958 );
2959 buf.add_reloc(
2960 Reloc::Abs4,
2961 &ExternalName::User(UserExternalNameRef::new(0)),
2962 0,
2963 );
2964 buf.put1(3);
2965 buf.add_reloc(
2966 Reloc::Abs8,
2967 &ExternalName::User(UserExternalNameRef::new(1)),
2968 1,
2969 );
2970 buf.put1(4);
2971 buf.bind_label(label(1), ctrl_plane);
2972 buf.put1(0xff);
2973 buf.bind_label(label(2), ctrl_plane);
2974 buf.put1(0xff);
2975
2976 let buf = buf.finish(&constants, ctrl_plane);
2977
2978 assert_eq!(buf.data(), &[1, 2, 3, 4, 0xff, 0xff]);
2979 assert_eq!(
2980 buf.traps()
2981 .iter()
2982 .map(|trap| (trap.offset, trap.code))
2983 .collect::<Vec<_>>(),
2984 vec![
2985 (1, TrapCode::HEAP_OUT_OF_BOUNDS),
2986 (2, TrapCode::INTEGER_OVERFLOW),
2987 (2, TrapCode::INTEGER_DIVISION_BY_ZERO)
2988 ]
2989 );
2990 let call_sites: Vec<_> = buf.call_sites().collect();
2991 assert_eq!(call_sites[0].ret_addr, 2);
2992 assert_eq!(call_sites[0].frame_offset, Some(0x10));
2993 assert_eq!(
2994 call_sites[0].exception_handlers,
2995 &[

Callers

nothing calls this directly

Calls 13

labelFunction · 0.85
bind_labelMethod · 0.80
add_try_call_siteMethod · 0.80
add_relocMethod · 0.80
collectMethod · 0.80
call_sitesMethod · 0.80
newFunction · 0.50
TagClass · 0.50
put1Method · 0.45
add_trapMethod · 0.45
into_iterMethod · 0.45

Tested by

no test coverage detected