1 /* Copyright (C) 1999-2006, 2008 Henry Cejtin, Matthew Fluet, Suresh
2 * Jagannathan, and Stephen Weeks.
3 * Copyright (C) 1997-2000 NEC Research Institute.
5 * MLton is released under a BSD-style license.
6 * See the file MLton-LICENSE for details.
9 GC_sourceSeqIndex
getCachedStackTopFrameSourceSeqIndex (GC_state s
) {
12 i
= getCachedStackTopFrameIndex (s
);
13 assert(i
< s
->sourceMaps
.frameSourcesLength
);
14 return s
->sourceMaps
.frameSources
[i
];
17 char* getSourceName (GC_state s
, GC_sourceIndex i
) {
18 assert (i
< s
->sourceMaps
.sourcesLength
);
19 return s
->sourceMaps
.sourceNames
[s
->sourceMaps
.sources
[i
].sourceNameIndex
];
22 char* GC_sourceName (GC_state s
, GC_sourceIndex i
) {
23 return getSourceName (s
, i
);
26 #if HAS_TIME_PROFILING
28 int compareSourceLabels (const void *v1
, const void *v2
) {
29 const struct GC_sourceLabel
* l1
= (const struct GC_sourceLabel
*)v1
;
30 const struct GC_sourceLabel
* l2
= (const struct GC_sourceLabel
*)v2
;
31 uintptr_t ui1
= (uintptr_t)(l1
->label
);
32 uintptr_t ui2
= (uintptr_t)(l2
->label
);
38 else /* if (ui1 > ui2) */
42 void sortSourceLabels (GC_state s
) {
43 GC_sourceLabelIndex i
;
45 /* Sort sourceLabels by address. */
46 qsort (s
->sourceMaps
.sourceLabels
,
47 s
->sourceMaps
.sourceLabelsLength
,
48 sizeof (*s
->sourceMaps
.sourceLabels
),
50 if (0 == s
->sourceMaps
.sourceLabels
[s
->sourceMaps
.sourceLabelsLength
- 1].label
)
51 die ("Max source label is 0 -- something is wrong.");
53 for (i
= 1; i
< s
->sourceMaps
.sourceLabelsLength
; i
++)
54 assert (s
->sourceMaps
.sourceLabels
[i
-1].label
55 <= s
->sourceMaps
.sourceLabels
[i
].label
);
58 void compressSourceLabels (GC_state s
) {
59 GC_sourceLabelIndex in
, out
, i
;
60 GC_sourceSeqIndex sourceSeqIndex
;
62 /* Eliminate duplicate sourceLabels */
64 sourceSeqIndex
= SOURCE_SEQ_UNKNOWN
;
65 for (in
= 0; in
< s
->sourceMaps
.sourceLabelsLength
; ++in
) {
66 if (s
->sourceMaps
.sourceLabels
[in
].sourceSeqIndex
!= sourceSeqIndex
) {
67 s
->sourceMaps
.sourceLabels
[out
++] = s
->sourceMaps
.sourceLabels
[in
];
68 sourceSeqIndex
= s
->sourceMaps
.sourceLabels
[in
].sourceSeqIndex
;
72 s
->sourceMaps
.sourceLabelsLength
= out
;
75 for (i
= 0; i
< s
->sourceMaps
.sourceLabelsLength
; i
++)
76 fprintf (stderr
, FMTPTR
" "FMTSSI
"\n",
77 (uintptr_t)s
->sourceMaps
.sourceLabels
[i
].label
,
78 s
->sourceMaps
.sourceLabels
[i
].sourceSeqIndex
);
81 void initSourceLabels (GC_state s
) {
83 compressSourceLabels (s
);
88 void showSources (GC_state s
) {
92 fprintf (stdout
, "0x%08"PRIx32
"\n", s
->magic
);
93 fprintf (stdout
, "%"PRIu32
"\n", s
->sourceMaps
.sourceNamesLength
);
94 for (i
= 0; i
< s
->sourceMaps
.sourceNamesLength
; i
++)
95 fprintf (stdout
, "%s\n", s
->sourceMaps
.sourceNames
[i
]);
96 fprintf (stdout
, "%"PRIu32
"\n", s
->sourceMaps
.sourcesLength
);
97 for (i
= 0; i
< s
->sourceMaps
.sourcesLength
; i
++)
98 fprintf (stdout
, "%"PRIu32
" %"PRIu32
"\n",
99 s
->sourceMaps
.sources
[i
].sourceNameIndex
,
100 s
->sourceMaps
.sources
[i
].successorSourceSeqIndex
);
101 fprintf (stdout
, "%"PRIu32
"\n", s
->sourceMaps
.sourceSeqsLength
);
102 for (i
= 0; i
< s
->sourceMaps
.sourceSeqsLength
; i
++) {
105 sourceSeq
= s
->sourceMaps
.sourceSeqs
[i
];
106 for (j
= 1; j
<= sourceSeq
[0]; j
++)
107 fprintf (stdout
, "%"PRIu32
" ", sourceSeq
[j
]);
108 fprintf (stdout
, "\n");