| ... |
... |
@@ -6,6 +6,9 @@ |
|
6
|
6
|
-- of bytecode files. It is the backbone of the @--show-byte-code@ option.
|
|
7
|
7
|
module GHC.ByteCode.Show (showByteCode) where
|
|
8
|
8
|
|
|
|
9
|
+-- The output generated by 'showByteCode' shall follow some general guidelines.
|
|
|
10
|
+-- See Note [Guidelines for the output of @--show-byte-code@] for details.
|
|
|
11
|
+
|
|
9
|
12
|
-- Prelude
|
|
10
|
13
|
import GHC.Prelude
|
|
11
|
14
|
|
| ... |
... |
@@ -35,28 +38,29 @@ import GHC.Data.FastString (unpackFS) |
|
35
|
38
|
import GHC.Data.FlatBag (FlatBag, elemsFlatBag)
|
|
36
|
39
|
import GHC.Fingerprint (Fingerprint)
|
|
37
|
40
|
import GHC.Types.SrcLoc (noSrcSpan)
|
|
38
|
|
-import GHC.Types.Name (Name, nameOccName)
|
|
39
|
|
-import GHC.Types.Name.Occurrence (OccName, isSymOcc)
|
|
|
41
|
+import GHC.Types.Name (Name)
|
|
|
42
|
+import GHC.Types.Name.Occurrence (OccName, HasOccName, occName, parenSymOcc)
|
|
40
|
43
|
import GHC.Types.Tickish (BreakTickIndex, BreakpointId (..))
|
|
41
|
44
|
import GHC.Types.SptEntry (SptEntry (..))
|
|
42
|
45
|
import GHC.Types.Error (MessageClass (MCDump))
|
|
43
|
46
|
import GHC.Utils.Panic.Plain (assert)
|
|
|
47
|
+import GHC.Utils.Encoding.UTF8 (utf8DecodeShortByteString, utf8DecodeByteString)
|
|
44
|
48
|
import GHC.Utils.Logger (Logger, logMsg)
|
|
45
|
49
|
import GHC.Utils.Binary (BinSrcSpan (..))
|
|
46
|
|
-import GHC.Utils.Encoding.UTF8 (utf8DecodeShortByteString, utf8DecodeByteString)
|
|
47
|
50
|
import GHC.Utils.Outputable
|
|
48
|
51
|
(
|
|
|
52
|
+ Outputable,
|
|
49
|
53
|
defaultDumpStyle,
|
|
50
|
54
|
SDoc,
|
|
51
|
55
|
text,
|
|
52
|
56
|
(<>),
|
|
53
|
57
|
(<+>),
|
|
54
|
|
- quotes,
|
|
55
|
58
|
hsep,
|
|
|
59
|
+ quotes,
|
|
56
|
60
|
vcat,
|
|
57
|
61
|
hang,
|
|
58
|
|
- withPprStyle,
|
|
59
|
|
- ppr
|
|
|
62
|
+ ppr,
|
|
|
63
|
+ withPprStyle
|
|
60
|
64
|
)
|
|
61
|
65
|
import GHC.Unit.Types (Module, moduleName)
|
|
62
|
66
|
import GHC.Iface.Type (IfaceType, IfaceTvBndr, IfaceIdBndr)
|
| ... |
... |
@@ -68,6 +72,7 @@ import Language.Haskell.Syntax.Module.Name (moduleNameString) |
|
68
|
72
|
|
|
69
|
73
|
-- Basic things
|
|
70
|
74
|
import Control.Arrow ((>>>))
|
|
|
75
|
+import Data.Bool (bool)
|
|
71
|
76
|
import Data.List (zipWith4)
|
|
72
|
77
|
import Data.ByteString (ByteString)
|
|
73
|
78
|
import Data.ByteString.Short (ShortByteString)
|
| ... |
... |
@@ -101,9 +106,9 @@ rules: |
|
101
|
106
|
literals are output without quotes, because they stick out by themselves.
|
|
102
|
107
|
|
|
103
|
108
|
* Infix operators are output with parentheses around them. To ensure that this
|
|
104
|
|
- is always the case, all textual representations of names are generated using
|
|
105
|
|
- the 'pprName' operation, defined in this module, instead of the 'ppr'
|
|
106
|
|
- operation.
|
|
|
109
|
+ is always the case, all textual representations of 'OccName' and 'Name'
|
|
|
110
|
+ values are generated using the 'pprNameProperly' operation, defined in this
|
|
|
111
|
+ module, instead of the 'pprNameProperly' operation.
|
|
107
|
112
|
|
|
108
|
113
|
-}
|
|
109
|
114
|
|
| ... |
... |
@@ -115,8 +120,6 @@ showByteCode logger env path = do |
|
115
|
120
|
MCDump
|
|
116
|
121
|
noSrcSpan
|
|
117
|
122
|
(withPprStyle defaultDumpStyle $ pprOnDiskModuleByteCode byteCode)
|
|
118
|
|
--- The output generated by 'showByteCode' shall follow some general guidelines.
|
|
119
|
|
--- See Note [Guidelines for the output of @--show-byte-code@] for details.
|
|
120
|
123
|
|
|
121
|
124
|
-- | Constructs textual information about the contents of a bytecode file.
|
|
122
|
125
|
pprOnDiskModuleByteCode :: OnDiskModuleByteCode -> SDoc
|
| ... |
... |
@@ -139,48 +142,48 @@ pprOnDiskModuleByteCodeHash = entry (text "hash") . ppr |
|
139
|
142
|
pprCompiledByteCode :: Module -- ^ The enclosing module
|
|
140
|
143
|
-> CompiledByteCode -- ^ The bytecode
|
|
141
|
144
|
-> SDoc -- ^ The textual information
|
|
142
|
|
-pprCompiledByteCode current_module CompiledByteCode {..}
|
|
|
145
|
+pprCompiledByteCode enclosing_module CompiledByteCode {..}
|
|
143
|
146
|
= vcat [
|
|
144
|
|
- pprByteCodeObjects current_module $ bc_bcos,
|
|
145
|
|
- pprDataConstructorInfoTables $ bc_itbls,
|
|
146
|
|
- pprTopLevelStrings $ bc_strs,
|
|
147
|
|
- pprBreakpoints current_module $ bc_breaks,
|
|
148
|
|
- pprStaticPointerTableEntries $ bc_spt_entries,
|
|
149
|
|
- pprHPCInfo current_module $ bc_hpc_info
|
|
|
147
|
+ pprByteCodeObjects enclosing_module $ bc_bcos,
|
|
|
148
|
+ pprDataConstructorInfoTables $ bc_itbls,
|
|
|
149
|
+ pprTopLevelStrings $ bc_strs,
|
|
|
150
|
+ pprBreakpoints enclosing_module $ bc_breaks,
|
|
|
151
|
+ pprStaticPointerTableEntries $ bc_spt_entries,
|
|
|
152
|
+ pprHPCInfo enclosing_module $ bc_hpc_info
|
|
150
|
153
|
]
|
|
151
|
154
|
|
|
152
|
155
|
-- | Constructs textual information about bytecode objects.
|
|
153
|
156
|
pprByteCodeObjects :: Module -- ^ The enlosing module
|
|
154
|
157
|
-> FlatBag UnlinkedBCO -- ^ The bytecode objects
|
|
155
|
158
|
-> SDoc -- ^ The textual information
|
|
156
|
|
-pprByteCodeObjects current_module = entry (text "objects") .
|
|
157
|
|
- vcatOrNone .
|
|
158
|
|
- map (pprByteCodeObject current_module) .
|
|
159
|
|
- elemsFlatBag
|
|
|
159
|
+pprByteCodeObjects enclosing_module = entry (text "objects") .
|
|
|
160
|
+ vcatOrNone .
|
|
|
161
|
+ map (pprByteCodeObject enclosing_module) .
|
|
|
162
|
+ elemsFlatBag
|
|
160
|
163
|
|
|
161
|
164
|
-- | Constructs textual information about a single bytecode object.
|
|
162
|
165
|
pprByteCodeObject :: Module -- ^ The enclosing module
|
|
163
|
166
|
-> UnlinkedBCO -- ^ The bytecode object
|
|
164
|
167
|
-> SDoc -- ^ The textual information
|
|
165
|
|
-pprByteCodeObject current_module byte_code_object = case byte_code_object of
|
|
|
168
|
+pprByteCodeObject enclosing_module byte_code_object = case byte_code_object of
|
|
166
|
169
|
UnlinkedBCO {..}
|
|
167
|
|
- -> entry (text "object" <+> quotes (pprName unlinkedBCOName)) $
|
|
|
170
|
+ -> entry (text "object" <+> quotes (pprNameProperly unlinkedBCOName)) $
|
|
168
|
171
|
vcat [
|
|
169
|
|
- pprArity $ unlinkedBCOArity,
|
|
170
|
|
- pprLiterals current_module $ unlinkedBCOLits,
|
|
171
|
|
- pprUsedItems current_module $ unlinkedBCOPtrs
|
|
|
172
|
+ pprArity $ unlinkedBCOArity,
|
|
|
173
|
+ pprLiterals enclosing_module $ unlinkedBCOLits,
|
|
|
174
|
+ pprUsedItems enclosing_module $ unlinkedBCOPtrs
|
|
172
|
175
|
]
|
|
173
|
176
|
UnlinkedStaticCon {..}
|
|
174
|
177
|
-> entry (
|
|
175
|
178
|
text "static-construction object" <+>
|
|
176
|
|
- quotes (pprName unlinkedStaticConName)
|
|
|
179
|
+ quotes (pprNameProperly unlinkedStaticConName)
|
|
177
|
180
|
)
|
|
178
|
181
|
$
|
|
179
|
182
|
vcat [
|
|
180
|
|
- pprDataConstructor $ unlinkedStaticConDataConName,
|
|
181
|
|
- pprLiftedness $ not unlinkedStaticConIsUnlifted,
|
|
182
|
|
- pprLiterals current_module $ unlinkedStaticConLits,
|
|
183
|
|
- pprUsedItems current_module $ unlinkedStaticConPtrs
|
|
|
183
|
+ pprDataConstructor $ unlinkedStaticConDataConName,
|
|
|
184
|
+ pprLiftedness $ not unlinkedStaticConIsUnlifted,
|
|
|
185
|
+ pprLiterals enclosing_module $ unlinkedStaticConLits,
|
|
|
186
|
+ pprUsedItems enclosing_module $ unlinkedStaticConPtrs
|
|
184
|
187
|
]
|
|
185
|
188
|
|
|
186
|
189
|
-- | Constructs textual information about the arity of a bytecode object.
|
| ... |
... |
@@ -190,7 +193,7 @@ pprArity = entry (text "arity") . ppr |
|
190
|
193
|
-- | Constructs textual information about the data constructor of a
|
|
191
|
194
|
-- static-construction bytecode object.
|
|
192
|
195
|
pprDataConstructor :: Name -> SDoc
|
|
193
|
|
-pprDataConstructor = entry (text "data constructor") . pprName
|
|
|
196
|
+pprDataConstructor = entry (text "data constructor") . pprNameProperly
|
|
194
|
197
|
|
|
195
|
198
|
-- | Constructs textual information about the liftedness of a
|
|
196
|
199
|
-- static-construction bytecode object.
|
| ... |
... |
@@ -201,16 +204,16 @@ pprLiftedness = entry (text "lifted") . noOrYes |
|
201
|
204
|
pprLiterals :: Module -- ^ The enclosing module
|
|
202
|
205
|
-> FlatBag BCONPtr -- ^ The literals
|
|
203
|
206
|
-> SDoc -- ^ The textual information
|
|
204
|
|
-pprLiterals current_module = entry (text "literals") .
|
|
205
|
|
- vcatOrNone .
|
|
206
|
|
- map (pprLiteral current_module) .
|
|
207
|
|
- elemsFlatBag
|
|
|
207
|
+pprLiterals enclosing_module = entry (text "literals") .
|
|
|
208
|
+ vcatOrNone .
|
|
|
209
|
+ map (pprLiteral enclosing_module) .
|
|
|
210
|
+ elemsFlatBag
|
|
208
|
211
|
|
|
209
|
212
|
-- | Constructs textual information about a single literal.
|
|
210
|
213
|
pprLiteral :: Module -- ^ The enclosing module
|
|
211
|
214
|
-> BCONPtr -- ^ The literal
|
|
212
|
215
|
-> SDoc -- ^ The textual information
|
|
213
|
|
-pprLiteral current_module literal = case literal of
|
|
|
216
|
+pprLiteral enclosing_module literal = case literal of
|
|
214
|
217
|
BCONPtrWord word
|
|
215
|
218
|
-> text "word" <+>
|
|
216
|
219
|
ppr word
|
| ... |
... |
@@ -219,10 +222,10 @@ pprLiteral current_module literal = case literal of |
|
219
|
222
|
quotes (ppr label)
|
|
220
|
223
|
BCONPtrItbl infoTableName
|
|
221
|
224
|
-> text "info table of" <+>
|
|
222
|
|
- quotes (pprName infoTableName)
|
|
|
225
|
+ quotes (pprNameProperly infoTableName)
|
|
223
|
226
|
BCONPtrAddr addrName
|
|
224
|
227
|
-> text "address" <+>
|
|
225
|
|
- quotes (pprName addrName)
|
|
|
228
|
+ quotes (pprNameProperly addrName)
|
|
226
|
229
|
BCONPtrStr encoded_string
|
|
227
|
230
|
-> text "top-level string" <+>
|
|
228
|
231
|
text (show (utf8DecodeByteString encoded_string))
|
| ... |
... |
@@ -234,7 +237,7 @@ pprLiteral current_module literal = case literal of |
|
234
|
237
|
quotes (pprFFIInfo ffiInfo)
|
|
235
|
238
|
BCONPtrCostCentre breakpointID
|
|
236
|
239
|
-> text "cost center of breakpoint" <+>
|
|
237
|
|
- pprInternalBreakpointID current_module breakpointID
|
|
|
240
|
+ pprInternalBreakpointID enclosing_module breakpointID
|
|
238
|
241
|
|
|
239
|
242
|
-- | Constructs textual information about FFI info.
|
|
240
|
243
|
pprFFIInfo :: FFIInfo -> SDoc
|
| ... |
... |
@@ -254,11 +257,11 @@ pprInternalBreakpointID |
|
254
|
257
|
:: Module -- ^ The enclosing module
|
|
255
|
258
|
-> InternalBreakpointId -- ^ The ID of the bytecode breakpoint
|
|
256
|
259
|
-> SDoc -- ^ The textual information
|
|
257
|
|
-pprInternalBreakpointID current_module InternalBreakpointId {..}
|
|
258
|
|
- | ibi_info_mod == current_module = index_doc
|
|
259
|
|
- | otherwise = index_doc <+>
|
|
260
|
|
- text "in" <+>
|
|
261
|
|
- quotes (ppr ibi_info_mod)
|
|
|
260
|
+pprInternalBreakpointID enclosing_module InternalBreakpointId {..}
|
|
|
261
|
+ | ibi_info_mod == enclosing_module = index_doc
|
|
|
262
|
+ | otherwise = index_doc <+>
|
|
|
263
|
+ text "in" <+>
|
|
|
264
|
+ quotes (ppr ibi_info_mod)
|
|
262
|
265
|
where
|
|
263
|
266
|
|
|
264
|
267
|
index_doc :: SDoc
|
| ... |
... |
@@ -268,22 +271,22 @@ pprInternalBreakpointID current_module InternalBreakpointId {..} |
|
268
|
271
|
pprUsedItems :: Module -- ^ The enclosing module
|
|
269
|
272
|
-> FlatBag BCOPtr -- ^ The used items
|
|
270
|
273
|
-> SDoc -- ^ The textual information
|
|
271
|
|
-pprUsedItems current_module = entry (text "used items") .
|
|
272
|
|
- vcatOrNone .
|
|
273
|
|
- map (pprUsedItem current_module) .
|
|
274
|
|
- elemsFlatBag
|
|
|
274
|
+pprUsedItems enclosing_module = entry (text "used items") .
|
|
|
275
|
+ vcatOrNone .
|
|
|
276
|
+ map (pprUsedItem enclosing_module) .
|
|
|
277
|
+ elemsFlatBag
|
|
275
|
278
|
|
|
276
|
279
|
-- | Constructs textual information about a single used item.
|
|
277
|
280
|
pprUsedItem :: Module -- ^ The enclosing module
|
|
278
|
281
|
-> BCOPtr -- ^ The used item
|
|
279
|
282
|
-> SDoc -- ^ The textual information
|
|
280
|
|
-pprUsedItem current_module usedItem = case usedItem of
|
|
|
283
|
+pprUsedItem enclosing_module used_item = case used_item of
|
|
281
|
284
|
BCOPtrName name
|
|
282
|
|
- -> text "named item" <+> quotes (pprName name)
|
|
|
285
|
+ -> text "named item" <+> quotes (pprNameProperly name)
|
|
283
|
286
|
BCOPtrPrimOp primOp
|
|
284
|
287
|
-> text "primitive operation" <+> quotes (ppr primOp)
|
|
285
|
288
|
BCOPtrBCO byte_code_object
|
|
286
|
|
- -> pprByteCodeObject current_module byte_code_object
|
|
|
289
|
+ -> pprByteCodeObject enclosing_module byte_code_object
|
|
287
|
290
|
BCOPtrBreakArray breakArrayModule
|
|
288
|
291
|
-> text "break array of module" <+> quotes (ppr breakArrayModule)
|
|
289
|
292
|
|
| ... |
... |
@@ -295,8 +298,8 @@ pprDataConstructorInfoTables = entry (text "data constructor info tables") . |
|
295
|
298
|
|
|
296
|
299
|
-- | Constructs textual information about a single data constructor info table.
|
|
297
|
300
|
pprDataConstructorInfoTable :: Name -> ConInfoTable -> SDoc
|
|
298
|
|
-pprDataConstructorInfoTable dataConstrName ConInfoTable {..}
|
|
299
|
|
- = entry (text "info table of" <+> quotes (pprName dataConstrName)) $
|
|
|
301
|
+pprDataConstructorInfoTable data_constr_name ConInfoTable {..}
|
|
|
302
|
+ = entry (text "info table of" <+> quotes (pprNameProperly data_constr_name)) $
|
|
300
|
303
|
vcat [
|
|
301
|
304
|
pprPointerWordCount $ conItblPtrs,
|
|
302
|
305
|
pprNonPointerWordCount $ conItblNPtrs
|
| ... |
... |
@@ -318,37 +321,38 @@ pprTopLevelStrings = entry (text "top-level strings") . |
|
318
|
321
|
|
|
319
|
322
|
-- | Constructs textual information about a single top-level string.
|
|
320
|
323
|
pprTopLevelString :: Name -> ByteString -> SDoc
|
|
321
|
|
-pprTopLevelString string_name encoded_string = entry (pprName string_name) $
|
|
322
|
|
- text $
|
|
323
|
|
- show $
|
|
324
|
|
- utf8DecodeByteString $
|
|
325
|
|
- encoded_string
|
|
|
324
|
+pprTopLevelString string_name encoded_string
|
|
|
325
|
+ = entry (pprNameProperly string_name) $
|
|
|
326
|
+ text $
|
|
|
327
|
+ show $
|
|
|
328
|
+ utf8DecodeByteString $
|
|
|
329
|
+ encoded_string
|
|
326
|
330
|
|
|
327
|
331
|
-- | Constructs textual information about breakpoints.
|
|
328
|
332
|
pprBreakpoints :: Module -- ^ The enclosing module
|
|
329
|
333
|
-> Maybe InternalModBreaks -- ^ The breakpoints
|
|
330
|
334
|
-> SDoc -- ^ The textual information
|
|
331
|
|
-pprBreakpoints current_module
|
|
|
335
|
+pprBreakpoints enclosing_module
|
|
332
|
336
|
= entry (text "breakpoints") .
|
|
333
|
|
- maybe (text "<none>") (pprActualBreakpoints current_module)
|
|
|
337
|
+ maybe (text "<none>") (pprActualBreakpoints enclosing_module)
|
|
334
|
338
|
|
|
335
|
339
|
-- | Constructs textual information about actual breakpoints.
|
|
336
|
340
|
pprActualBreakpoints :: Module -- ^ The enclosing module
|
|
337
|
341
|
-> InternalModBreaks -- ^ The actual breakpoints
|
|
338
|
342
|
-> SDoc -- ^ The textual information
|
|
339
|
|
-pprActualBreakpoints current_module InternalModBreaks {..}
|
|
|
343
|
+pprActualBreakpoints enclosing_module InternalModBreaks {..}
|
|
340
|
344
|
= vcat [
|
|
341
|
|
- pprSourceBreakpoints current_module $ imodBreaks_modBreaks,
|
|
342
|
|
- pprByteCodeBreakpoints current_module $ imodBreaks_breakInfo
|
|
|
345
|
+ pprSourceBreakpoints enclosing_module $ imodBreaks_modBreaks,
|
|
|
346
|
+ pprByteCodeBreakpoints enclosing_module $ imodBreaks_breakInfo
|
|
343
|
347
|
]
|
|
344
|
348
|
|
|
345
|
349
|
-- | Constructs textual information about source breakpoints.
|
|
346
|
350
|
pprSourceBreakpoints :: Module -- ^ The enclosing module
|
|
347
|
351
|
-> ModBreaks -- ^ The source breakpoints
|
|
348
|
352
|
-> SDoc -- ^ The textual information
|
|
349
|
|
-pprSourceBreakpoints current_module ModBreaks {..}
|
|
|
353
|
+pprSourceBreakpoints enclosing_module ModBreaks {..}
|
|
350
|
354
|
= entry (text "source breakpoints") $
|
|
351
|
|
- assert (modBreaks_module == current_module) $
|
|
|
355
|
+ assert (modBreaks_module == enclosing_module) $
|
|
352
|
356
|
assert (bounds modBreaks_locs_ == bounds modBreaks_decls) $
|
|
353
|
357
|
assert (bounds modBreaks_locs_ == bounds modBreaks_vars) $
|
|
354
|
358
|
vcatOrNone $
|
| ... |
... |
@@ -361,39 +365,43 @@ pprSourceBreakpoints current_module ModBreaks {..} |
|
361
|
365
|
-- the source spans in 'modBreaks_locs_' and are therefore never shown.
|
|
362
|
366
|
|
|
363
|
367
|
-- | Constructs textual information about a single source breakpoint.
|
|
364
|
|
-pprSourceBreakpoint :: BreakTickIndex
|
|
365
|
|
- -> BinSrcSpan
|
|
366
|
|
- -> [String]
|
|
367
|
|
- -> [OccName]
|
|
368
|
|
- -> SDoc
|
|
369
|
|
-pprSourceBreakpoint ix srcSpan declarationPath freeVars
|
|
|
368
|
+pprSourceBreakpoint
|
|
|
369
|
+ :: BreakTickIndex -- ^ The index of the source breakpoint
|
|
|
370
|
+ -> BinSrcSpan -- ^ The source span of the source breakpoint
|
|
|
371
|
+ -> [String] -- ^ The names declared by the surrounding declarations
|
|
|
372
|
+ -> [OccName] -- ^ The free variables of the source breakpoint
|
|
|
373
|
+ -> SDoc -- ^ The textual information
|
|
|
374
|
+pprSourceBreakpoint ix src_span declaration_path free_vars
|
|
370
|
375
|
= entry (text "source breakpoint" <+> ppr ix) $
|
|
371
|
376
|
vcat [
|
|
372
|
|
- pprSrcSpan $ srcSpan,
|
|
373
|
|
- pprDeclarationPath $ declarationPath,
|
|
374
|
|
- pprFreeVariables $ freeVars
|
|
|
377
|
+ pprSrcSpan $ src_span,
|
|
|
378
|
+ pprDeclarationPath $ declaration_path,
|
|
|
379
|
+ pprFreeVariables $ free_vars
|
|
375
|
380
|
]
|
|
376
|
381
|
|
|
377
|
382
|
-- | Constructs textual information about a source span.
|
|
378
|
383
|
pprSrcSpan :: BinSrcSpan -> SDoc
|
|
379
|
384
|
pprSrcSpan = entry (text "source span") . ppr . unBinSrcSpan
|
|
380
|
385
|
|
|
381
|
|
--- | Constructs textual information about a declaration path.
|
|
|
386
|
+-- | Constructs textual information about a declaration path, which is the list
|
|
|
387
|
+-- of names declared by the declarations surrounding a source breakpoint.
|
|
382
|
388
|
pprDeclarationPath :: [String] -> SDoc
|
|
383
|
389
|
pprDeclarationPath = entry (text "declaration path") . vcatOrEmpty . map text
|
|
384
|
390
|
|
|
385
|
391
|
-- | Constructs textual information about free variables.
|
|
386
|
392
|
pprFreeVariables :: [OccName] -> SDoc
|
|
387
|
|
-pprFreeVariables = entry (text "free variables") . vcatOrNone . map ppr
|
|
|
393
|
+pprFreeVariables = entry (text "free variables") .
|
|
|
394
|
+ vcatOrNone .
|
|
|
395
|
+ map pprNameProperly
|
|
388
|
396
|
|
|
389
|
397
|
-- | Constructs textual information about bytecode breakpoints.
|
|
390
|
398
|
pprByteCodeBreakpoints :: Module -- ^ The enclosing module
|
|
391
|
399
|
-> IntMap CgBreakInfo -- ^ The bytecode breakpoints
|
|
392
|
400
|
-> SDoc -- ^ The textual information
|
|
393
|
|
-pprByteCodeBreakpoints current_module
|
|
394
|
|
- = entry (text "bytecode breakpoints") .
|
|
395
|
|
- vcatOrNone .
|
|
396
|
|
- map (uncurry (pprByteCodeBreakpoint current_module)) .
|
|
|
401
|
+pprByteCodeBreakpoints enclosing_module
|
|
|
402
|
+ = entry (text "bytecode breakpoints") .
|
|
|
403
|
+ vcatOrNone .
|
|
|
404
|
+ map (uncurry (pprByteCodeBreakpoint enclosing_module)) .
|
|
397
|
405
|
IntMap.toList
|
|
398
|
406
|
|
|
399
|
407
|
-- | Constructs textual information about a single bytecode breakpoint.
|
| ... |
... |
@@ -401,13 +409,13 @@ pprByteCodeBreakpoint :: Module -- ^ The enclosing module |
|
401
|
409
|
-> Int -- ^ The index of the bytecode breakpoint
|
|
402
|
410
|
-> CgBreakInfo -- ^ The bytecode breakpoint
|
|
403
|
411
|
-> SDoc -- ^ The textual information
|
|
404
|
|
-pprByteCodeBreakpoint current_module ix CgBreakInfo {..}
|
|
|
412
|
+pprByteCodeBreakpoint enclosing_module ix CgBreakInfo {..}
|
|
405
|
413
|
= entry (text "bytecode breakpoint" <+> ppr ix) $
|
|
406
|
414
|
vcat [
|
|
407
|
|
- pprType $ cgb_resty,
|
|
408
|
|
- pprTypeVariables $ cgb_tyvars,
|
|
409
|
|
- pprVariables $ cgb_vars,
|
|
410
|
|
- pprCorrespondingSourceBreakpoint current_module $ cgb_tick_id
|
|
|
415
|
+ pprType $ cgb_resty,
|
|
|
416
|
+ pprTypeVariables $ cgb_tyvars,
|
|
|
417
|
+ pprVariables $ cgb_vars,
|
|
|
418
|
+ pprCorrespondingSourceBreakpoint enclosing_module $ cgb_tick_id
|
|
411
|
419
|
]
|
|
412
|
420
|
-- That the 'cgb_resty' field holds the type of the breakpoint is apparent
|
|
413
|
421
|
-- from the fact that this field is set by
|
| ... |
... |
@@ -453,20 +461,20 @@ pprCorrespondingSourceBreakpoint :: Module |
|
453
|
461
|
-- ^ A reference to the source breakpoint
|
|
454
|
462
|
-> SDoc
|
|
455
|
463
|
-- ^ The textual information
|
|
456
|
|
-pprCorrespondingSourceBreakpoint current_module
|
|
|
464
|
+pprCorrespondingSourceBreakpoint enclosing_module
|
|
457
|
465
|
= entry (text "corresponding source breakpoint") .
|
|
458
|
|
- pprBreakpointID current_module .
|
|
|
466
|
+ pprBreakpointID enclosing_module .
|
|
459
|
467
|
either internalBreakLoc id
|
|
460
|
468
|
|
|
461
|
469
|
-- | Constructs textual information about the ID of a source breakpoint.
|
|
462
|
470
|
pprBreakpointID :: Module -- ^ The enclosing module
|
|
463
|
471
|
-> BreakpointId -- ^ The ID of the source breakpoint
|
|
464
|
472
|
-> SDoc -- ^ The textual information
|
|
465
|
|
-pprBreakpointID current_module BreakpointId {..}
|
|
466
|
|
- | bi_tick_mod == current_module = index_doc
|
|
467
|
|
- | otherwise = index_doc <+>
|
|
468
|
|
- text "in" <+>
|
|
469
|
|
- quotes (ppr bi_tick_mod)
|
|
|
473
|
+pprBreakpointID enclosing_module BreakpointId {..}
|
|
|
474
|
+ | bi_tick_mod == enclosing_module = index_doc
|
|
|
475
|
+ | otherwise = index_doc <+>
|
|
|
476
|
+ text "in" <+>
|
|
|
477
|
+ quotes (ppr bi_tick_mod)
|
|
470
|
478
|
where
|
|
471
|
479
|
|
|
472
|
480
|
index_doc :: SDoc
|
| ... |
... |
@@ -481,25 +489,25 @@ pprStaticPointerTableEntries = entry (text "static-pointer table entries") . |
|
481
|
489
|
-- | Constructs textual information about a single static-pointer table entry.
|
|
482
|
490
|
pprStaticPointerTableEntry :: SptEntry -> SDoc
|
|
483
|
491
|
pprStaticPointerTableEntry (SptEntry name fingerprint)
|
|
484
|
|
- = ppr fingerprint <> text ":" <+> pprName name
|
|
|
492
|
+ = entry (ppr fingerprint) (pprNameProperly name)
|
|
485
|
493
|
|
|
486
|
494
|
-- | Constructs textual information about HPC info.
|
|
487
|
495
|
pprHPCInfo :: Module -- ^ The enclosing module
|
|
488
|
496
|
-> Strict.Maybe ByteCodeHpcInfo -- ^ The HPC info
|
|
489
|
497
|
-> SDoc -- ^ The textual information
|
|
490
|
|
-pprHPCInfo current_module
|
|
|
498
|
+pprHPCInfo enclosing_module
|
|
491
|
499
|
= entry (text "HPC information") .
|
|
492
|
|
- Strict.maybe (text "<none>") (pprActualHPCInfo current_module)
|
|
|
500
|
+ Strict.maybe (text "<none>") (pprActualHPCInfo enclosing_module)
|
|
493
|
501
|
|
|
494
|
502
|
-- | Constructs textual information about actual HPC info.
|
|
495
|
503
|
pprActualHPCInfo :: Module -- ^ The enclosing module
|
|
496
|
504
|
-> ByteCodeHpcInfo -- ^ The actual HPC info
|
|
497
|
505
|
-> SDoc -- ^ The textual information
|
|
498
|
|
-pprActualHPCInfo current_module ByteCodeHpcInfo {..}
|
|
|
506
|
+pprActualHPCInfo enclosing_module ByteCodeHpcInfo {..}
|
|
499
|
507
|
= assert (
|
|
500
|
508
|
utf8DecodeShortByteString bchi_module_name
|
|
501
|
509
|
==
|
|
502
|
|
- moduleNameString (moduleName current_module)
|
|
|
510
|
+ moduleNameString (moduleName enclosing_module)
|
|
503
|
511
|
)
|
|
504
|
512
|
$
|
|
505
|
513
|
vcat [
|
| ... |
... |
@@ -516,14 +524,15 @@ pprHPCInfoHash = entry (text "hash") . pprFixedSizeNatural . intToWord |
|
516
|
524
|
pprTickBox :: ShortByteString -> SDoc
|
|
517
|
525
|
pprTickBox = entry (text "tick box") . text . utf8DecodeShortByteString
|
|
518
|
526
|
|
|
519
|
|
--- | Constructs textual information about a number of tick counts.
|
|
|
527
|
+-- | Constructs textual information about a number of ticks.
|
|
520
|
528
|
pprTickCount :: Int -> SDoc
|
|
521
|
529
|
pprTickCount = entry (text "number of ticks") . ppr
|
|
522
|
530
|
|
|
523
|
|
--- | Constructs the Haskell representation of a name.
|
|
524
|
|
-pprName :: Name -> SDoc
|
|
525
|
|
-pprName name | isSymOcc (nameOccName name) = text "(" <> ppr name <> text ")"
|
|
526
|
|
- | otherwise = ppr name
|
|
|
531
|
+-- | Constructs the Haskell representation of a name. This includes putting
|
|
|
532
|
+-- parentheses around operators. The given name is supposed to be of type
|
|
|
533
|
+-- 'OccName' or 'Name'.
|
|
|
534
|
+pprNameProperly :: (HasOccName a, Outputable a) => a -> SDoc
|
|
|
535
|
+pprNameProperly name = parenSymOcc (occName name) (ppr name)
|
|
527
|
536
|
|
|
528
|
537
|
-- | Constructs a hexadecimal representation of a natural number such that the
|
|
529
|
538
|
-- number of hexadecimal digits fits the number of bits used to represent the
|
| ... |
... |
@@ -547,22 +556,22 @@ intToWord (I# int#) = W# (int2Word# int#) |
|
547
|
556
|
-- | Constructs a textual representation of a boolean, interpreting 'True' and
|
|
548
|
557
|
-- 'False' as “yes” and “no”, respectively.
|
|
549
|
558
|
noOrYes :: Bool -> SDoc
|
|
550
|
|
-noOrYes bool = text (if bool then "yes" else "no")
|
|
|
559
|
+noOrYes = text . bool "no" "yes"
|
|
551
|
560
|
|
|
552
|
561
|
-- | Constructs an entry in a list of textual data representations.
|
|
553
|
562
|
entry :: SDoc -- ^ The title of the entry
|
|
554
|
563
|
-> SDoc -- ^ The contents of the entry
|
|
555
|
564
|
-> SDoc -- ^ The entry
|
|
556
|
|
-entry title content = hang (title <> text ":") 2 content
|
|
|
565
|
+entry title contents = hang (title <> text ":") 2 contents
|
|
557
|
566
|
|
|
558
|
567
|
-- | Composes documents vertically in general, but presents an empty document
|
|
559
|
|
--- list as `<none`>.
|
|
|
568
|
+-- list as @<none>@.
|
|
560
|
569
|
vcatOrNone :: [SDoc] -> SDoc
|
|
561
|
570
|
vcatOrNone [] = text "<none>"
|
|
562
|
571
|
vcatOrNone docs = vcat docs
|
|
563
|
572
|
|
|
564
|
573
|
-- | Composes documents vertically in general, but presents an empty document
|
|
565
|
|
--- list as `<empty`>.
|
|
|
574
|
+-- list as @<empty>@.
|
|
566
|
575
|
vcatOrEmpty :: [SDoc] -> SDoc
|
|
567
|
576
|
vcatOrEmpty [] = text "<empty>"
|
|
568
|
577
|
vcatOrEmpty docs = vcat docs |