1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef MAPLE_TRIPLE_H 17 #define MAPLE_TRIPLE_H 18 19 #include <string_utils.h> 20 #include <utils.h> 21 22 #include <string> 23 #include <string_view> 24 #include <vector> 25 26 namespace maple { 27 28 class Triple { 29 public: 30 /* Currently, only aarch64 is supported */ 31 enum ArchType { UnknownArch, aarch64, aarch64_be, LastArchType }; 32 33 /* Currently, only ILP32 and LP64 are supported */ 34 enum EnvironmentType { UnknownEnvironment, GNU, GNUILP32, LastEnvironmentType }; 35 GetArch()36 ArchType GetArch() const 37 { 38 return arch; 39 } GetEnvironment()40 EnvironmentType GetEnvironment() const 41 { 42 return environment; 43 } 44 IsBigEndian()45 bool IsBigEndian() const 46 { 47 return (GetArch() == ArchType::aarch64_be); 48 } 49 50 std::string Str() const; 51 std::string GetArchName() const; 52 std::string GetEnvironmentName() const; 53 GetTriple()54 static Triple &GetTriple() 55 { 56 static Triple triple; 57 return triple; 58 } 59 Triple(const Triple &) = delete; 60 Triple &operator=(const Triple &) = delete; 61 62 void Init(const std::string &target); 63 void Init(); 64 65 private: 66 std::string data; 67 ArchType arch; 68 EnvironmentType environment; 69 Triple()70 Triple() : arch(UnknownArch), environment(UnknownEnvironment) {} 71 72 Triple::ArchType ParseArch(std::string_view archStr); 73 Triple::EnvironmentType ParseEnvironment(std::string_view environmentType); 74 }; 75 76 } // namespace maple 77 78 #endif /* MAPLE_TRIPLE_H */ 79