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

Method edges_row

tangle/src/select.rs:478–529  ·  view source on GitHub ↗
(&self, region: &Region)

Source from the content-addressed store, hash-verified

476
477impl PatternManager {
478 fn edges_row(&self, region: &Region) -> (
479 Vec<(crate::port::PortEdge, Option<NodeIdx>, Option<NodeIdx>, usize, VReg)>,
480 Vec<(crate::port::PortEdge, Option<NodeIdx>, Option<NodeIdx>, Option<usize>, Option<usize>, u16)>
481 ) {
482 let Region { nodes, ports, sinks, .. } = region;
483 let mut edges = Vec::with_capacity(nodes.edge_count());
484 let mut states = Vec::new();
485 // hook up all the edges to node inputs. this includes from the region sources
486 for local in nodes.node_indices() {
487 for (i, p) in nodes[local].inputs.iter().enumerate() {
488 let vreg: Result<VReg, u16> = match ports[*p].storage{
489 OptionalStorage(Some(Storage::Immaterial(Some(state)))) => Err(state),
490 OptionalStorage(Some(Storage::Virtual(vreg))) => Ok(VReg(vreg)),
491 _ => panic!(),
492 };
493 for e in ports.edges_directed(*p, Direction::Outgoing) {
494 let neighbor_port = &ports[e.target()];
495 match vreg {
496 Ok(vreg) => {
497 let new_edge = (e.id(), neighbor_port.node, Some(local), i, vreg);
498 println!("new edge {:?}", new_edge);
499 edges.push(new_edge);
500 },
501 Err(state) => {
502 let output_idx = neighbor_port.node.map(|node| {
503 nodes[node].outputs.iter().enumerate().find(|(i, p)| **p == e.target())
504 .unwrap().0
505 });
506 let new_state = (e.id(), neighbor_port.node, Some(local), output_idx, Some(i), state);
507 println!("new state {:?}", new_state);
508 states.push(new_state);
509 },
510 }
511 }
512 }
513 }
514 // we also hook up edges to the region sinks
515 for (i, output) in sinks.iter().enumerate() {
516 let vreg: VReg = match ports[*output].storage{
517 OptionalStorage(Some(Storage::Immaterial(state))) => continue,
518 OptionalStorage(Some(Storage::Virtual(vreg))) => VReg(vreg),
519 _ => panic!(),
520 };
521 for e in ports.edges_directed(*output, Direction::Outgoing) {
522 let neighbor_port = &ports[e.target()];
523 let new_edge = (e.id(), neighbor_port.node, None, i, vreg);
524 println!("new sink edge {:?}", new_edge);
525 edges.push(new_edge);
526 }
527 }
528 (edges, states)
529 }
530
531 pub fn run(&mut self, token: &NodeOwner, region: &mut Region, virt_map: &mut VirtualRegisterMap) {
532 let (mut edges, states) = self.edges_row(region);

Callers 2

runMethod · 0.80
codegenMethod · 0.80

Calls 2

VRegClass · 0.85
pushMethod · 0.80

Tested by

no test coverage detected