Jlm
Loading...
Searching...
No Matches
ThreeAddressCodeTests.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/llvm/ir/tac.hpp>
11
12TEST(ThreeAddressCodeTests, ToAscii)
13{
14 using namespace jlm::llvm;
15 using namespace jlm::rvsdg;
16
17 // Arrange
19
20 Variable v0(valueType, "v0");
21 Variable v1(valueType, "v1");
22
23 auto tac0 = ThreeAddressCode::create(TestOperation::create({}, {}), {});
24 auto tac1 = ThreeAddressCode::create(TestOperation::create({ valueType }, {}), { &v0 });
25 auto tac2 =
26 ThreeAddressCode::create(TestOperation::create({ valueType, valueType }, {}), { &v0, &v1 });
27 auto tac3 = ThreeAddressCode::create(TestOperation::create({}, { valueType }), {});
28 auto tac4 = ThreeAddressCode::create(TestOperation::create({}, { valueType, valueType }), {});
29 auto tac5 = ThreeAddressCode::create(
30 TestOperation::create({ valueType, valueType }, { valueType, valueType }),
31 { &v0, &v1 });
32
33 // Act
34 auto tac0String = ThreeAddressCode::ToAscii(*tac0);
35 std::cout << tac0String << "\n" << std::flush;
36
37 auto tac1String = ThreeAddressCode::ToAscii(*tac1);
38 std::cout << tac1String << "\n" << std::flush;
39
40 auto tac2String = ThreeAddressCode::ToAscii(*tac2);
41 std::cout << tac2String << "\n" << std::flush;
42
43 auto tac3String = ThreeAddressCode::ToAscii(*tac3);
44 std::cout << tac3String << "\n" << std::flush;
45
46 auto tac4String = ThreeAddressCode::ToAscii(*tac4);
47 std::cout << tac4String << "\n" << std::flush;
48
49 auto tac5String = ThreeAddressCode::ToAscii(*tac5);
50 std::cout << tac5String << "\n" << std::flush;
51
52 // Assert
53 EXPECT_EQ(tac0String, "TestOperation");
54 EXPECT_EQ(tac1String, "TestOperation v0");
55 EXPECT_EQ(tac2String, "TestOperation v0, v1");
56 // FIXME: We use a global static counter for the tv identifiers of the results. This means with
57 // all the unit tests being merged into a single test executable that the counter is not
58 // "predictable" any longer. The solution here is to get rid of this counter.
59 // EXPECT_EQ(tac3String, "tv0 = TestOperation");
60 // EXPECT_EQ(tac4String, "tv1, tv2 = TestOperation");
61 // EXPECT_EQ(tac5String, "tv3, tv4 = TestOperation v0, v1");
62}
TEST(ThreeAddressCodeTests, ToAscii)
static std::shared_ptr< const TestType > createValueType()
Definition TestType.cpp:67
Global memory state passed between functions.