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_IR_INCLUDE_MIR_PRAGMA_H
17 #define MAPLE_IR_INCLUDE_MIR_PRAGMA_H
18 #include "types_def.h"
19 #include "prim_types.h"
20 #include "mir_module.h"
21 #include "mpl_logging.h"
22 #include "mempool_allocator.h"
23 
24 namespace maple {
25 class MIRModule;         // circular dependency exists, no other choice
26 class MIRType;           // circular dependency exists, no other choice
27 class MIRFunction;       // circular dependency exists, no other choice
28 class MIRSymbol;         // circular dependency exists, no other choice
29 class MIRSymbolTable;    // circular dependency exists, no other choice
30 class MIRTypeNameTable;  // circular dependency exists, no other choice
31 enum PragmaKind {
32     kPragmaUnknown,
33     kPragmaClass,
34     kPragmaFunc,
35     kPragmaField,
36     kPragmaParam,
37     kPragmaVar,
38     kPragmaFuncExecptioni,
39     kPragmaFuncVar
40 };
41 
42 enum PragmaValueType {
43     kValueByte = 0x00,          // (none; must be 0)  ubyte[1]
44     kValueShort = 0x02,         // size - 1 (0…1)  ubyte[size]
45     kValueChar = 0x03,          // size - 1 (0…1)  ubyte[size]
46     kValueInt = 0x04,           // size - 1 (0…3)  ubyte[size]
47     kValueLong = 0x06,          // size - 1 (0…7)  ubyte[size]
48     kValueFloat = 0x10,         // size - 1 (0…3)  ubyte[size]
49     kValueDouble = 0x11,        // size - 1 (0…7)  ubyte[size]
50     kValueMethodType = 0x15,    // size - 1 (0…3)  ubyte[size]
51     kValueMethodHandle = 0x16,  // size - 1 (0…3)  ubyte[size]
52     kValueString = 0x17,        // size - 1 (0…3)  ubyte[size]
53     kValueType = 0x18,          // size - 1 (0…3)  ubyte[size]
54     kValueField = 0x19,         // size - 1 (0…3)  ubyte[size]
55     kValueMethod = 0x1a,        // size - 1 (0…3)  ubyte[size]
56     kValueEnum = 0x1b,          // size - 1 (0…3)  ubyte[size]
57     kValueArray = 0x1c,         // (none; must be 0) encoded_array
58     kValueAnnotation = 0x1d,    // (none; must be 0) encoded_annotation
59     kValueNull = 0x1e,          // (none; must be 0) (none)
60     kValueBoolean = 0x1f        // boolean (0…1)   (none)
61 };
62 
63 class MIRPragmaElement {
64 public:
MIRPragmaElement(MIRModule &m)65     explicit MIRPragmaElement(MIRModule &m) : MIRPragmaElement(m.GetPragmaMPAllocator())
66     {
67         d = 0;
68     }
69 
MIRPragmaElement(MapleAllocator &subElemAllocator)70     explicit MIRPragmaElement(MapleAllocator &subElemAllocator) : subElemVec(subElemAllocator.Adapter())
71     {
72         subElemVec.clear();
73         d = 0;
74     }
75 
76     ~MIRPragmaElement() = default;
SubElemVecPushBack(MIRPragmaElement *elem)77     void SubElemVecPushBack(MIRPragmaElement *elem)
78     {
79         subElemVec.push_back(elem);
80     }
81 
82 private:
83     double d;
84     MapleVector<MIRPragmaElement *> subElemVec;
85 };
86 }  // namespace maple
87 #endif  // MAPLE_IR_INCLUDE_MIR_PRAGMA_H
88