1 //===- FIRContextTest.cpp -------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "flang/Optimizer/Support/FIRContext.h"
10 #include "flang/Optimizer/Support/KindMapping.h"
11 #include "mlir/IR/BuiltinAttributes.h"
12 #include "mlir/IR/BuiltinOps.h"
13 #include "llvm/Support/Host.h"
14 #include "gtest/gtest.h"
15 #include <string>
16
17 using namespace fir;
18
19 struct StringAttributesTests : public testing::Test {
20 public:
SetUpStringAttributesTests21 void SetUp() {
22 kindMap = new KindMapping(&context, kindMapInit, "r42a10c14d28i40l41");
23 mod = mlir::ModuleOp::create(mlir::UnknownLoc::get(&context));
24 }
25
TearDownStringAttributesTests26 void TearDown() { delete kindMap; }
27
28 mlir::MLIRContext context;
29 KindMapping *kindMap{};
30 std::string kindMapInit =
31 "i10:80,l3:24,a1:8,r54:Double,r62:X86_FP80,r11:PPC_FP128";
32 std::string target = "powerpc64le-unknown-linux-gnu";
33 mlir::ModuleOp mod;
34 };
35
TEST_F(StringAttributesTests,moduleStringAttrTest)36 TEST_F(StringAttributesTests, moduleStringAttrTest) {
37 setTargetTriple(mod, target);
38 setKindMapping(mod, *kindMap);
39
40 auto triple = getTargetTriple(mod);
41 EXPECT_EQ(triple.getArch(), llvm::Triple::ArchType::ppc64le);
42 EXPECT_EQ(triple.getOS(), llvm::Triple::OSType::Linux);
43
44 auto map = getKindMapping(mod);
45 EXPECT_EQ(map.defaultsToString(), "a10c14d28i40l41r42");
46
47 auto mapStr = map.mapToString();
48 EXPECT_EQ(mapStr.size(), kindMapInit.size());
49 EXPECT_TRUE(mapStr.find("a1:8") != std::string::npos);
50 EXPECT_TRUE(mapStr.find("l3:24") != std::string::npos);
51 EXPECT_TRUE(mapStr.find("i10:80") != std::string::npos);
52 EXPECT_TRUE(mapStr.find("r11:PPC_FP128") != std::string::npos);
53 EXPECT_TRUE(mapStr.find("r54:Double") != std::string::npos);
54 EXPECT_TRUE(mapStr.find("r62:X86_FP80") != std::string::npos);
55 }
56
57 // main() from gtest_main
58