• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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, x64, 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 
IsAarch64BeOrLe()50     bool IsAarch64BeOrLe() const
51     {
52         return (GetArch() == ArchType::aarch64_be) || (GetArch() == ArchType::aarch64);
53     }
54 
GetTriple()55     static Triple &GetTriple()
56     {
57         static Triple triple;
58         return triple;
59     }
60     Triple(const Triple &) = delete;
61     Triple &operator=(const Triple &) = delete;
62 
63     void Init(bool isAArch64);
64 
65 private:
66     std::string data;
67     ArchType arch;
68     EnvironmentType environment;
69 
Triple()70     Triple() : arch(UnknownArch), environment(UnknownEnvironment) {}
71 };
72 }  // namespace maple
73 
74 #endif /* MAPLE_TRIPLE_H */
75