Jlm
ResultTests.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2024 Nico Reißmann <nico.reissmann@gmail.com>
3  * See COPYING for terms of redistribution.
4  */
5 
6 #include <gtest/gtest.h>
7 
8 #include <jlm/rvsdg/graph.hpp>
11 #include <jlm/rvsdg/TestType.hpp>
12 
13 #include <cassert>
14 
18 TEST(ResultTests, ResultNodeMismatch)
19 {
20  using namespace jlm::rvsdg;
21 
22  // Arrange
23  auto valueType = TestType::createValueType();
24 
25  Graph graph;
26  auto & import = jlm::rvsdg::GraphImport::Create(graph, valueType, "import");
27 
28  auto structuralNode1 = TestStructuralNode::create(&graph.GetRootRegion(), 1);
29  auto structuralNode2 = TestStructuralNode::create(&graph.GetRootRegion(), 1);
30 
31  auto input = structuralNode1->addInputWithArguments(import);
32 
33  // Act & Assert
34  EXPECT_THROW(structuralNode2->addOutputWithResults({ input.argument[0] }), jlm::util::Error);
35 }
36 
37 TEST(ResultTests, ResultInputTypeMismatch)
38 {
39  using namespace jlm::rvsdg;
40  using namespace jlm::util;
41 
42  // Arrange
43  auto valueType = jlm::rvsdg::TestType::createValueType();
44  auto stateType = jlm::rvsdg::TestType::createStateType();
45 
46  jlm::rvsdg::Graph rvsdg;
47  auto structuralNode = TestStructuralNode::create(&rvsdg.GetRootRegion(), 2);
48  auto simpleNode0 = TestOperation::createNode(structuralNode->subregion(0), {}, { stateType });
49  auto simpleNode1 = TestOperation::createNode(structuralNode->subregion(1), {}, { valueType });
50 
51  // Act & Assert
52  EXPECT_THROW(
53  structuralNode->addOutputWithResults({ simpleNode0->output(0), simpleNode1->output(0) }),
54  TypeError);
55 }
TEST(ResultTests, ResultNodeMismatch)
Definition: ResultTests.cpp:18
static GraphImport & Create(Graph &graph, std::shared_ptr< const rvsdg::Type > type, std::string name)
Definition: graph.cpp:36
Region & GetRootRegion() const noexcept
Definition: graph.hpp:99
static SimpleNode * createNode(Region *region, const std::vector< Output * > &operands, std::vector< std::shared_ptr< const Type >> resultTypes)
static TestStructuralNode * create(Region *parent, const size_t numSubregions)
Definition: TestNodes.hpp:152
static std::shared_ptr< const TestType > createStateType()
Definition: TestType.cpp:60
static std::shared_ptr< const TestType > createValueType()
Definition: TestType.cpp:67