main.cpp 1.36 KB
Newer Older
1
// Headers are available because we added the pls target
2 3
#include <string>
#include <cstdio>
4
#include <tuple>
5
#include <array>
6

7 8
#include <pls/dataflow/inputs.h>
#include <pls/dataflow/outputs.h>
9
#include <pls/dataflow/internal/function_node.h>
10
#include <pls/dataflow/internal/out_port.h>
11

12
int main() {
13
  using namespace pls::dataflow;
14 15
  using namespace pls::dataflow::internal;

16 17
  out_port<int> external1;
  out_port<int> external2;
18

19 20 21 22 23 24 25 26 27
  auto func1 = [](const int &i1, const int &i2, int &o1) {
    std::cout << "Hello! " << i1 << ", " << i2 << std::endl;
    o1 = i1 + i2;
  };
  function_node<inputs<int, int>, outputs<int>, decltype(func1)> node1{func1};
  auto func2 = [](const int &i1, int &o1) {
    std::cout << "We get! " << i1 << std::endl;
  };
  function_node<inputs<int>, outputs<int>, decltype(func2)> node2{func2};
28

29 30 31
  external1 >> node1.in_port<0>();
  external2 >> node1.in_port<1>();
  node1.out_port<0>() >> node2.in_port<0>();
32

33 34 35 36 37 38 39 40
  // Simulate execution environment
  void *buffer1 = malloc(node1.instance_buffer_size());
  void *buffer2 = malloc(node2.instance_buffer_size());
  void *memory[] = {buffer1, buffer2};
  node1.init_instance_buffer(memory[0]);
  node1.set_memory_index(0);
  node2.init_instance_buffer(memory[1]);
  node2.set_memory_index(1);
41

42 43 44
  invocation_info invocation{memory};
  external1.push_token({1, invocation});
  external2.push_token({2, invocation});
45
}