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

Function do_case

cranelift/frontend/src/switch.rs:541–572  ·  view source on GitHub ↗
(keys: &[u128], typ: Type)

Source from the content-addressed store, hash-verified

539 }
540
541 fn do_case(keys: &[u128], typ: Type) {
542 let mut func = Function::new();
543 let mut builder_ctx = FunctionBuilderContext::new();
544 let mut builder = FunctionBuilder::new(&mut func, &mut builder_ctx);
545
546 let root_block = builder.create_block();
547 let default_block = builder.create_block();
548 let mut switch = Switch::new();
549
550 let case_blocks = keys
551 .iter()
552 .map(|key| {
553 let block = builder.create_block();
554 switch.set_entry(*key, block);
555 block
556 })
557 .collect::<Vec<_>>();
558
559 builder.seal_block(root_block);
560 builder.switch_to_block(root_block);
561
562 let val = builder.ins().iconst(typ, 1);
563 switch.emit(&mut builder, val, default_block);
564
565 for &block in case_blocks.iter().chain(std::iter::once(&default_block)) {
566 builder.seal_block(block);
567 builder.switch_to_block(block);
568 builder.ins().return_(&[]);
569 }
570
571 builder.finalize(); // Will panic if some blocks are not sealed
572 }
573 }
574
575 #[test]

Callers 1

Calls 11

create_blockMethod · 0.80
switch_to_blockMethod · 0.80
chainMethod · 0.80
newFunction · 0.50
mapMethod · 0.45
iterMethod · 0.45
set_entryMethod · 0.45
seal_blockMethod · 0.45
insMethod · 0.45
emitMethod · 0.45
finalizeMethod · 0.45

Tested by 1