-
Notifications
You must be signed in to change notification settings - Fork 2
/
print.c
173 lines (129 loc) · 4.2 KB
/
print.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#include "print.h"
#include "debug.h"
void print_slot (uint64_t slot) {
if( is_small_int(slot) ) {
printf("i%d", get_small_int(slot));
return;
}
if(is_nil(slot)) {
printf("n0");
return;
}
if(is_fnew(slot)) {
printf("fn%d", get_fnew(slot));
return;
}
if(is_builtin(slot)) {
printf("bfn%d", get_builtin(slot));
return;
}
if(is_type(slot)) {
printf("t%d", get_type(slot));
return;
}
if(is_pointer(slot)) {
//printf("P");
uint64_t* header_ptr = (uint64_t*) slot;
struct obj_stub *obj = (struct obj_stub *) (void *) header_ptr;
//printf(" pheader: %016"PRIx64" ", header);
//< mpstype: %02"PRIx64", _: %02"PRIx64" cljtype: %04"PRIx64", size: %08"PRIx64">
printf("( [cljtype: %d, size: %d] ", obj->cljtype,obj->size );
for(int i = 0; i != ((obj->size / 8) - 1); i++) {
//printf(" <field %i: %016"PRIx64"> ", i, obj->ref[i] );
print_slot( (uintptr_t) (void *) obj->ref[i]);
}
printf(") ");
return;
}
if( is_double(slot) ) {
printf("f%.2f", get_double(slot));
return;
}
printf("-");
}
// ------------------------- Print Slots ------------------------
void print_slots(Slots* s, uint64_t base) {
int index = 0;
//printf("Slots<s:%d/b:%d>: ", s->size, base_slot);
while (1) {
if(base == index)
printf("| ");
if ( !(index >= s->size || index < 0) ) {
//printf("<%d:",index);
print_slot(slots_get(s, index));
printf(" ");
}
index++;
if(index == s->size) {
printf("\n");
return;
}
}
}
void println_slot (uint64_t slot) {
if( is_small_int(slot) ) {
printf("%d", get_small_int(slot));
return;
}
if(is_nil(slot)) {
printf("nil");
return;
}
if(is_fnew(slot)) {
printf("fn%d", get_fnew(slot));
return;
}
if(is_builtin(slot)) {
printf("bfn%d", get_builtin(slot));
return;
}
if(is_type(slot)) {
printf("t%d", get_type(slot));
return;
}
if(is_pointer(slot)) {
//printf("P");
uint64_t* header_ptr = (uint64_t*) slot;
struct obj_stub *obj = (struct obj_stub *) (void *) header_ptr;
//printf(" pheader: %016"PRIx64" ", header);
//< mpstype: %02"PRIx64", _: %02"PRIx64" cljtype: %04"PRIx64", size: %08"PRIx64">
printf("( [cljtype: %d, size: %d] ", obj->cljtype,obj->size );
for(int i = 0; i != ((obj->size / 8) - 1); i++) {
//printf(" <field %i: %016"PRIx64"> ", i, obj->ref[i] );
print_slot( (uintptr_t) (void *) obj->ref[i]);
}
printf(") ");
return;
}
if( is_double(slot) ) {
printf("f%", get_double(slot));
return;
}
}
/*
static void rust_mps_debug_print_formatted_object(mps_addr_t addr,
mps_fmt_t fmt,
mps_pool_t pool,
void *p, size_t s) {
assert(p == fmt);
struct obj_stub *obj = addr;
assert(obj->type < ARRAY_LEN(OBJ_MPS_TYPE_NAMES));
const char *mps_type = OBJ_MPS_TYPE_NAMES[obj->type];
fprintf(stderr, "%s(0x%012"PRIxPTR") [%"PRIu32" bytes] ", mps_type, (uintptr_t)addr, obj->size);
if (obj->type == OBJ_MPS_TYPE_OBJECT || obj->type == OBJ_MPS_TYPE_ARRAY) {
fprintf(stderr, "[type: %"PRIu16"]", obj->cljtype);
}
fprintf(stderr, "\n");
if (obj->type == OBJ_MPS_TYPE_OBJECT) {
size_t count = (obj->size - HEADER_SIZE) / WORD_SIZE;
for (size_t i=0; i<count; i++) {
uint16_t tag = ((uintptr_t)obj->ref[i] & TAG_MASK) >> VAL_BITS;
uint64_t val = (uintptr_t)obj->ref[i] & ~TAG_MASK;
fprintf(stderr, " 0x%04"PRIx16":%012"PRIx64"\n", tag, val);
}
}
}
void rust_mps_debug_print_reachable(mps_arena_t _arena, mps_fmt_t fmt) {
fprintf(stderr, "==== Walking Reachable Objects ====\n");
mps_arena_formatted_objects_walk(_arena, rust_mps_debug_print_formatted_object, fmt, 0);
}*/