Lexer: Suggest adding 'let' on unexpected '=' token
[ghc.git] / compiler / nativeGen / Dwarf / Constants.hs
1 -- | Constants describing the DWARF format. Most of this simply
2 -- mirrors /usr/include/dwarf.h.
3
4 module Dwarf.Constants where
5
6 import FastString
7 import Platform
8 import Outputable
9
10 import Reg
11 import X86.Regs
12
13 import Data.Word
14
15 -- | Language ID used for Haskell.
16 dW_LANG_Haskell :: Word
17 dW_LANG_Haskell = 0x18
18 -- Thanks to Nathan Howell for getting us our very own language ID!
19
20 -- | Dwarf tags
21 dW_TAG_compile_unit, dW_TAG_subroutine_type,
22 dW_TAG_file_type, dW_TAG_subprogram, dW_TAG_lexical_block,
23 dW_TAG_base_type, dW_TAG_structure_type, dW_TAG_pointer_type,
24 dW_TAG_array_type, dW_TAG_subrange_type, dW_TAG_typedef,
25 dW_TAG_variable, dW_TAG_arg_variable, dW_TAG_auto_variable :: Word
26 dW_TAG_array_type = 1
27 dW_TAG_lexical_block = 11
28 dW_TAG_pointer_type = 15
29 dW_TAG_compile_unit = 17
30 dW_TAG_structure_type = 19
31 dW_TAG_typedef = 22
32 dW_TAG_subroutine_type = 32
33 dW_TAG_subrange_type = 33
34 dW_TAG_base_type = 36
35 dW_TAG_file_type = 41
36 dW_TAG_subprogram = 46
37 dW_TAG_variable = 52
38 dW_TAG_auto_variable = 256
39 dW_TAG_arg_variable = 257
40
41 -- | Dwarf attributes
42 dW_AT_name, dW_AT_stmt_list, dW_AT_low_pc, dW_AT_high_pc, dW_AT_language,
43 dW_AT_comp_dir, dW_AT_producer, dW_AT_external, dW_AT_frame_base,
44 dW_AT_use_UTF8, dW_AT_MIPS_linkage_name :: Word
45 dW_AT_name = 0x03
46 dW_AT_stmt_list = 0x10
47 dW_AT_low_pc = 0x11
48 dW_AT_high_pc = 0x12
49 dW_AT_language = 0x13
50 dW_AT_comp_dir = 0x1b
51 dW_AT_producer = 0x25
52 dW_AT_external = 0x3f
53 dW_AT_frame_base = 0x40
54 dW_AT_use_UTF8 = 0x53
55 dW_AT_MIPS_linkage_name = 0x2007
56
57 -- | Abbrev declaration
58 dW_CHILDREN_no, dW_CHILDREN_yes :: Word8
59 dW_CHILDREN_no = 0
60 dW_CHILDREN_yes = 1
61
62 dW_FORM_addr, dW_FORM_data4, dW_FORM_string, dW_FORM_flag,
63 dW_FORM_block1, dW_FORM_ref4 :: Word
64 dW_FORM_addr = 0x01
65 dW_FORM_data4 = 0x06
66 dW_FORM_string = 0x08
67 dW_FORM_flag = 0x0c
68 dW_FORM_block1 = 0x0a
69 dW_FORM_ref4 = 0x13
70
71 -- | Dwarf native types
72 dW_ATE_address, dW_ATE_boolean, dW_ATE_float, dW_ATE_signed,
73 dW_ATE_signed_char, dW_ATE_unsigned, dW_ATE_unsigned_char :: Word
74 dW_ATE_address = 1
75 dW_ATE_boolean = 2
76 dW_ATE_float = 4
77 dW_ATE_signed = 5
78 dW_ATE_signed_char = 6
79 dW_ATE_unsigned = 7
80 dW_ATE_unsigned_char = 8
81
82 -- | Call frame information
83 dW_CFA_set_loc, dW_CFA_undefined, dW_CFA_same_value,
84 dW_CFA_def_cfa, dW_CFA_def_cfa_offset, dW_CFA_def_cfa_expression,
85 dW_CFA_expression, dW_CFA_offset_extended_sf, dW_CFA_def_cfa_offset_sf,
86 dW_CFA_def_cfa_sf, dW_CFA_val_offset, dW_CFA_val_expression,
87 dW_CFA_offset :: Word8
88 dW_CFA_set_loc = 0x01
89 dW_CFA_undefined = 0x07
90 dW_CFA_same_value = 0x08
91 dW_CFA_def_cfa = 0x0c
92 dW_CFA_def_cfa_offset = 0x0e
93 dW_CFA_def_cfa_expression = 0x0f
94 dW_CFA_expression = 0x10
95 dW_CFA_offset_extended_sf = 0x11
96 dW_CFA_def_cfa_sf = 0x12
97 dW_CFA_def_cfa_offset_sf = 0x13
98 dW_CFA_val_offset = 0x14
99 dW_CFA_val_expression = 0x16
100 dW_CFA_offset = 0x80
101
102 -- | Operations
103 dW_OP_deref, dW_OP_consts,
104 dW_OP_minus, dW_OP_mul, dW_OP_plus,
105 dW_OP_lit0, dW_OP_breg0, dW_OP_call_frame_cfa :: Word8
106 dW_OP_deref = 0x06
107 dW_OP_consts = 0x11
108 dW_OP_minus = 0x1c
109 dW_OP_mul = 0x1e
110 dW_OP_plus = 0x22
111 dW_OP_lit0 = 0x30
112 dW_OP_breg0 = 0x70
113 dW_OP_call_frame_cfa = 0x9c
114
115 -- | Dwarf section declarations
116 dwarfInfoSection, dwarfAbbrevSection, dwarfLineSection,
117 dwarfFrameSection, dwarfGhcSection :: SDoc
118 dwarfInfoSection = dwarfSection "info"
119 dwarfAbbrevSection = dwarfSection "abbrev"
120 dwarfLineSection = dwarfSection "line"
121 dwarfFrameSection = dwarfSection "frame"
122 dwarfGhcSection = dwarfSection "ghc"
123
124 dwarfSection :: String -> SDoc
125 dwarfSection name = sdocWithPlatform $ \plat -> ftext $ mkFastString $
126 case platformOS plat of
127 os | osElfTarget os
128 -> "\t.section .debug_" ++ name ++ ",\"\",@progbits"
129 | osMachOTarget os
130 -> "\t.section __DWARF,__debug_" ++ name ++ ",regular,debug"
131 | otherwise
132 -> "\t.section .debug_" ++ name ++ ",\"dr\""
133
134 -- | Dwarf section labels
135 dwarfInfoLabel, dwarfAbbrevLabel, dwarfLineLabel, dwarfFrameLabel :: LitString
136 dwarfInfoLabel = sLit ".Lsection_info"
137 dwarfAbbrevLabel = sLit ".Lsection_abbrev"
138 dwarfLineLabel = sLit ".Lsection_line"
139 dwarfFrameLabel = sLit ".Lsection_frame"
140
141 -- | Mapping of registers to DWARF register numbers
142 dwarfRegNo :: Platform -> Reg -> Word8
143 dwarfRegNo p r = case platformArch p of
144 ArchX86
145 | r == eax -> 0
146 | r == ecx -> 1 -- yes, no typo
147 | r == edx -> 2
148 | r == ebx -> 3
149 | r == esp -> 4
150 | r == ebp -> 5
151 | r == esi -> 6
152 | r == edi -> 7
153 ArchX86_64
154 | r == rax -> 0
155 | r == rdx -> 1 -- this neither. The order GCC allocates registers in?
156 | r == rcx -> 2
157 | r == rbx -> 3
158 | r == rsi -> 4
159 | r == rdi -> 5
160 | r == rbp -> 6
161 | r == rsp -> 7
162 | r == r8 -> 8
163 | r == r9 -> 9
164 | r == r10 -> 10
165 | r == r11 -> 11
166 | r == r12 -> 12
167 | r == r13 -> 13
168 | r == r14 -> 14
169 | r == r15 -> 15
170 | r == xmm0 -> 17
171 | r == xmm1 -> 18
172 | r == xmm2 -> 19
173 | r == xmm3 -> 20
174 | r == xmm4 -> 21
175 | r == xmm5 -> 22
176 | r == xmm6 -> 23
177 | r == xmm7 -> 24
178 | r == xmm8 -> 25
179 | r == xmm9 -> 26
180 | r == xmm10 -> 27
181 | r == xmm11 -> 28
182 | r == xmm12 -> 29
183 | r == xmm13 -> 30
184 | r == xmm14 -> 31
185 | r == xmm15 -> 32
186 _other -> error "dwarfRegNo: Unsupported platform or unknown register!"
187
188 -- | Virtual register number to use for return address.
189 dwarfReturnRegNo :: Platform -> Word8
190 dwarfReturnRegNo p
191 -- We "overwrite" IP with our pseudo register - that makes sense, as
192 -- when using this mechanism gdb already knows the IP anyway. Clang
193 -- does this too, so it must be safe.
194 = case platformArch p of
195 ArchX86 -> 8 -- eip
196 ArchX86_64 -> 16 -- rip
197 _other -> error "dwarfReturnRegNo: Unsupported platform!"