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 #include "mir_builder.h"
17 #include "debug_info.h"
18 #include "global_tables.h"
19 #include "mir_type.h"
20
21 namespace maple {
22 #define TOSTR(s) #s
23 // utility functions to get the string from tag value etc.
24 // GetDwTagName(unsigned n)
GetDwTagName(unsigned n)25 const char *GetDwTagName(unsigned n)
26 {
27 switch (n) {
28 #define DW_TAG(ID, NAME) \
29 case DW_TAG_##NAME: \
30 return TOSTR(DW_TAG_##NAME);
31 #include "dwarf.def"
32 case DW_TAG_lo_user:
33 return "DW_TAG_lo_user";
34 case DW_TAG_hi_user:
35 return "DW_TAG_hi_user";
36 case DW_TAG_user_base:
37 return "DW_TAG_user_base";
38 default:
39 return nullptr;
40 }
41 }
42
43 // GetDwFormName(unsigned n)
GetDwFormName(unsigned n)44 const char *GetDwFormName(unsigned n)
45 {
46 switch (n) {
47 #define DW_FORM(ID, NAME) \
48 case DW_FORM_##NAME: \
49 return TOSTR(DW_FORM_##NAME);
50 #include "dwarf.def"
51 case DW_FORM_lo_user:
52 return "DW_FORM_lo_user";
53 default:
54 return nullptr;
55 }
56 }
57
58 // GetDwAtName(unsigned n)
GetDwAtName(unsigned n)59 const char *GetDwAtName(unsigned n)
60 {
61 switch (n) {
62 #define DW_AT(ID, NAME) \
63 case DW_AT_##NAME: \
64 return TOSTR(DW_AT_##NAME);
65 #include "dwarf.def"
66 case DW_AT_lo_user:
67 return "DW_AT_lo_user";
68 default:
69 return nullptr;
70 }
71 }
72
73 // GetDwOpName(unsigned n)
GetDwOpName(unsigned n)74 const char *GetDwOpName(unsigned n)
75 {
76 switch (n) {
77 #define DW_OP(ID, NAME) \
78 case DW_OP_##NAME: \
79 return TOSTR(DW_OP_##NAME);
80 #include "dwarf.def"
81 case DW_OP_hi_user:
82 return "DW_OP_hi_user";
83 default:
84 return nullptr;
85 }
86 }
87
88 const unsigned kDwAteVoid = 0x20;
89 // GetDwAteName(unsigned n)
GetDwAteName(unsigned n)90 const char *GetDwAteName(unsigned n)
91 {
92 switch (n) {
93 #define DW_ATE(ID, NAME) \
94 case DW_ATE_##NAME: \
95 return TOSTR(DW_ATE_##NAME);
96 #include "dwarf.def"
97 case DW_ATE_lo_user:
98 return "DW_ATE_lo_user";
99 case DW_ATE_hi_user:
100 return "DW_ATE_hi_user";
101 case kDwAteVoid:
102 return "kDwAteVoid";
103 default:
104 return nullptr;
105 }
106 }
107
GetAteFromPTY(PrimType pty)108 DwAte GetAteFromPTY(PrimType pty)
109 {
110 switch (pty) {
111 case PTY_u1:
112 return DW_ATE_boolean;
113 case PTY_u8:
114 return DW_ATE_unsigned_char;
115 case PTY_u16:
116 case PTY_u32:
117 case PTY_u64:
118 return DW_ATE_unsigned;
119 case PTY_i8:
120 return DW_ATE_signed_char;
121 case PTY_i16:
122 case PTY_i32:
123 case PTY_i64:
124 return DW_ATE_signed;
125 case PTY_f32:
126 case PTY_f64:
127 case PTY_f128:
128 return DW_ATE_float;
129 case PTY_agg:
130 case PTY_ref:
131 case PTY_ptr:
132 case PTY_a32:
133 case PTY_a64:
134 return DW_ATE_address;
135 case PTY_c64:
136 case PTY_c128:
137 return DW_ATE_complex_float;
138 case PTY_void:
139 return kDwAteVoid;
140 default:
141 return kDwAteVoid;
142 }
143 }
144 } // namespace maple
145