MCPcopy Create free account
hub / github.com/chc4/lineiform / function_bb_simple

Function function_bb_simple

tangle/src/ir.rs:444–485  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

442
443 #[test]
444 pub fn function_bb_simple() {
445 let mut ir = IR::new();
446 let mut f = Node::function::<1, 1>(&mut ir);
447 let input = f.add_argument(&mut ir);
448 let output = f.add_return(&mut ir);
449
450 // entry[input]: br_call bb1, input;
451 // bb1[bp0]: add bp0, 2; mov output, bp0;
452
453 let mut bb = Node::bb();
454 let (bb0, bp_0) = f.add_body(bb, &mut ir, |bb, mut r| {
455 // create basic block parameter
456 (bb.sinks()[0], bb.add_output(&mut r))
457 }).1;
458
459 let mut two = Node::constant(2);
460 let mut add = Node::simple(Operation::Add);
461 let mut two_const = None;
462 f.add_body(two, &mut ir, |two, r| {
463 two_const = Some(two.sinks()[0]);
464 });
465 f.add_body(add, &mut ir, |add, r| {
466 add.connect_input(0, bp_0, r);
467 add.connect_input(1, two_const.unwrap(), r);
468 add.connect_output(0, output, r);
469 });
470
471 let mut bcall = Node::bcall();
472 f.add_body(bcall, &mut ir, |bcall, mut r| {
473 // call bb0
474 bcall.connect_input(0, bb0, r);
475 // with arg0 = input
476 let arg = r.add_port();
477 r.connect_ports(input, arg);
478 bcall.add_input(arg, &mut r);
479 });
480
481 ir.set_body(f);
482 let hello_fn: extern "C" fn(usize) -> usize = ir.compile_fn().unwrap().0;
483 assert_eq!(hello_fn(0), 2);
484 assert_eq!(hello_fn(1), 3);
485 }
486
487 #[test]
488 pub fn function_bb_if_always_0() {

Callers

nothing calls this directly

Calls 12

add_argumentMethod · 0.80
add_returnMethod · 0.80
add_bodyMethod · 0.80
sinksMethod · 0.80
add_outputMethod · 0.80
connect_inputMethod · 0.80
connect_outputMethod · 0.80
add_portMethod · 0.80
connect_portsMethod · 0.80
add_inputMethod · 0.80
set_bodyMethod · 0.80
compile_fnMethod · 0.80

Tested by

no test coverage detected