FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
daScript/src/simulate/debug_info.cpp at split-heap · Bais/daScript · GitHub
Bais
/
daScript
Public
forked from
GaijinEntertainment/daScript
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
daScript
/
src
/
simulate
/
debug_info.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
377 lines (352 loc) · 16.4 KB
Breadcrumbs
daScript
/
src
/
simulate
/
debug_info.cpp
Copy path
File metadata and controls
377 lines (352 loc) · 16.4 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
#
include
"
daScript/misc/platform.h
"
#
include
"
daScript/simulate/debug_info.h
"
#
include
"
daScript/misc/enums.h
"
#
include
"
daScript/simulate/cast.h
"
#
include
"
daScript/simulate/runtime_string.h
"
#
include
"
daScript/misc/arraytype.h
"
namespace
das
{
Enum<Type> g_typeTable = {
{ Type::autoinfer,
"
auto
"
},
{ Type::alias,
"
alias
"
},
{ Type::anyArgument,
"
any
"
},
{ Type::tVoid,
"
void
"
},
{ Type::tBool,
"
bool
"
},
{ Type::tInt64,
"
int64
"
},
{ Type::tUInt64,
"
uint64
"
},
{ Type::tString,
"
string
"
},
{ Type::tPointer,
"
pointer
"
},
{ Type::tIterator,
"
iterator
"
},
{ Type::tArray,
"
array
"
},
{ Type::tTable,
"
table
"
},
{ Type::tInt,
"
int
"
},
{ Type::tInt2,
"
int2
"
},
{ Type::tInt3,
"
int3
"
},
{ Type::tInt4,
"
int4
"
},
{ Type::tUInt,
"
uint
"
},
{ Type::tUInt2,
"
uint2
"
},
{ Type::tUInt3,
"
uint3
"
},
{ Type::tUInt4,
"
uint4
"
},
{ Type::tFloat,
"
float
"
},
{ Type::tFloat2,
"
float2
"
},
{ Type::tFloat3,
"
float3
"
},
{ Type::tFloat4,
"
float4
"
},
{ Type::tRange,
"
range
"
},
{ Type::tURange,
"
urange
"
}
};
string
to_string
( Type t ) {
return
g_typeTable.
find
(t);
}
Type
nameToBasicType
(
const
string & name) {
return
g_typeTable.
find
(name, Type::none);
}
int
getTypeBaseSize
( Type type ) {
switch
( type ) {
case
tPointer:
return
sizeof
(
void
*);
case
tIterator:
return
sizeof
(
void
*);
//
Iterator *
case
tHandle:
assert
(
0
&&
"
we should not be here
"
);
return
sizeof
(
void
*);
case
tString:
return
sizeof
(
char
*);
case
tBool:
return
sizeof
(
bool
);
static_assert
(
sizeof
(
bool
)==
1
,
"
4 byte bool
"
);
case
tInt64:
return
sizeof
(
int64_t
);
case
tUInt64:
return
sizeof
(
uint64_t
);
case
tInt:
return
sizeof
(
int
);
case
tInt2:
return
sizeof
(int2);
case
tInt3:
return
sizeof
(int3);
case
tInt4:
return
sizeof
(int4);
case
tUInt:
return
sizeof
(
uint32_t
);
case
tUInt2:
return
sizeof
(uint2);
case
tUInt3:
return
sizeof
(uint3);
case
tUInt4:
return
sizeof
(uint4);
case
tFloat:
return
sizeof
(
float
);
case
tFloat2:
return
sizeof
(float2);
case
tFloat3:
return
sizeof
(float3);
case
tFloat4:
return
sizeof
(float4);
case
tRange:
return
sizeof
(range);
case
tURange:
return
sizeof
(urange);
case
tArray:
return
sizeof
(Array);
case
tTable:
return
sizeof
(Table);
case
tStructure:
return
0
;
case
tVoid:
return
0
;
case
tBlock:
return
sizeof
(Block);
default
:
assert
(
0
&&
"
not implemented
"
);
return
0
;
}
}
int
getTypeBaseAlign
( Type type ) {
switch
( type ) {
case
tPointer:
return
alignof
(
void
*);
case
tIterator:
return
alignof
(
void
*);
//
Iterator *
case
tHandle:
assert
(
0
&&
"
we should not be here
"
);
return
alignof
(
void
*);
case
tString:
return
alignof
(
char
*);
case
tBool:
return
alignof
(
bool
);
static_assert
(
alignof
(
bool
)==
1
,
"
4 byte bool
"
);
case
tInt64:
return
alignof
(
int64_t
);
case
tUInt64:
return
alignof
(
uint64_t
);
case
tInt:
return
alignof
(
int32_t
);
case
tInt2:
return
alignof
(int2);
case
tInt3:
return
alignof
(int3);
case
tInt4:
return
alignof
(int4);
case
tUInt:
return
alignof
(
uint32_t
);
case
tUInt2:
return
alignof
(uint2);
case
tUInt3:
return
alignof
(uint3);
case
tUInt4:
return
alignof
(uint4);
case
tFloat:
return
alignof
(
float
);
case
tFloat2:
return
alignof
(float2);
case
tFloat3:
return
alignof
(float3);
case
tFloat4:
return
alignof
(float4);
case
tRange:
return
alignof
(range);
case
tURange:
return
alignof
(urange);
case
tArray:
return
alignof
(Array);
case
tTable:
return
alignof
(Table);
case
tStructure:
return
1
;
case
tVoid:
return
1
;
case
tBlock:
return
alignof
(Block);
default
:
assert
(
0
&&
"
not implemented
"
);
return
0
;
}
}
int
getStructAlign
( StructInfo * info ) {
int
al =
0
;
for
(
uint32_t
i=
0
; i!=info->
fieldsSize
; ++i ) {
al =
max
( al,
getTypeAlign
(info->
fields
[i]) );
}
return
al;
}
int
getStructSize
( StructInfo * info ) {
int
size =
0
;
for
(
uint32_t
i=
0
; i!=info->
fieldsSize
; ++i ) {
int
al =
getTypeAlign
(info->
fields
[i]) -
1
;
size = (size + al) & ~al;
size +=
getTypeSize
(info->
fields
[i]);
}
int
al =
getStructAlign
(info) -
1
;
size = (size + al) & ~al;
return
size;
}
int
getTypeBaseSize
( TypeInfo * info ) {
return
info->
type
!=Type::tStructure ?
getTypeBaseSize
(info->
type
) :
getStructSize
(info->
structType
);
}
int
getTypeBaseAlign
( TypeInfo * info ) {
return
info->
type
!=Type::tStructure ?
getTypeBaseAlign
(info->
type
) :
getStructAlign
(info->
structType
);
}
int
getDimSize
( TypeInfo * info ) {
int
size =
1
;
if
( info->
dimSize
) {
for
(
uint32_t
i=
0
; i!=info->
dimSize
; ++i ) {
size *= info->
dim
[i];
}
}
return
size;
}
int
getTypeSize
( TypeInfo * info ) {
return
getDimSize
(info) *
getTypeBaseSize
(info);
}
int
getTypeAlign
( TypeInfo * info ) {
return
getTypeBaseAlign
(info);
}
void
debugType
( TypeAnnotation *, stringstream & ,
void
*, PrintFlags );
void
debugType
( TypeAnnotation *, stringstream &, vec4f, PrintFlags );
void
debug_structure
( stringstream & ss,
char
* ps, StructInfo * info, PrintFlags flags );
void
debug_value
( stringstream & ss,
void
* pX, TypeInfo * info, PrintFlags flags );
void
debug_structure
( stringstream & ss,
char
* ps, StructInfo * info, PrintFlags flags ) {
ss <<
"
(
"
;
for
(
uint32_t
i=
0
; i!=info->
fieldsSize
; ++i ) {
VarInfo * vi = info->
fields
[i];
char
* pf = ps + vi->
offset
;
if
( i ) ss <<
"
"
;
ss <<
"
(
"
<< vi->
name
;
ss <<
"
"
;
debug_value
(ss, pf, vi, flags);
ss <<
"
)
"
;
}
ss <<
"
)
"
;
}
void
debug_array_value
( stringstream & ss,
void
* pX,
int
stride,
int
count, TypeInfo * info, PrintFlags flags ) {
char
* pA = (
char
*) pX;
ss <<
"
(
"
;
if
(
int
(flags) &
int
(PrintFlags::debugger) ) {
ss <<
"
[size=
"
<< count <<
"
,stride=
"
<< stride <<
"
]
"
;
}
for
(
int
i=
0
; i!=count; ++i ) {
if
( i ) ss <<
"
"
;
debug_value
(ss, pA, info, flags);
pA += stride;
}
ss <<
"
)
"
;
}
void
debug_dim_value
( stringstream & ss,
void
* pX, TypeInfo * info, PrintFlags flags ) {
TypeInfo copyInfo = *info;
assert
(copyInfo.
dimSize
);
copyInfo.
dimSize
--;
int
stride =
getTypeBaseSize
(info);
int
count =
getDimSize
(info);
debug_array_value
(ss, pX, stride, count, ©Info, flags);
}
void
debug_value
( stringstream & ss,
void
* pX, TypeInfo * info, PrintFlags flags ) {
if
( pX ==
nullptr
) {
ss <<
"
null
"
;
return
;
}
if
( info->
ref
) {
TypeInfo ti = *info;
ti.
ref
=
false
;
debug_value
(ss, *(
void
**)pX, &ti, flags);
}
else
if
( info->
dimSize
) {
debug_dim_value
(ss, pX, info, flags);
}
else
if
( info->
type
==Type::tArray ) {
auto
arr = (Array *) pX;
debug_array_value
(ss, arr->
data
,
getTypeSize
(info->
firstType
), arr->
size
, info->
firstType
, flags);
}
else
{
switch
( info->
type
) {
case
Type::tBool: ss << *((
bool
*)pX);
break
;
case
Type::tInt64: ss << *((
int64_t
*)pX);
break
;
case
Type::tUInt64: ss <<
"
0x
"
<< hex << *((
uint64_t
*)pX) << dec;
break
;
case
Type::tString:
if
(
int
(flags) &
int
(PrintFlags::escapeString) ) {
ss <<
"
\"
"
<<
escapeString
(
safe_str
(pX)) <<
"
\"
"
;
}
else
{
ss <<
safe_str
(pX);
}
break
;
case
Type::tInt: ss << *((
int32_t
*)pX);
break
;
case
Type::tInt2: ss << *((int2 *)pX);
break
;
case
Type::tInt3: ss << *((int3 *)pX);
break
;
case
Type::tInt4: ss << *((int4 *)pX);
break
;
case
Type::tUInt: ss << *((
uint32_t
*)pX);
break
;
case
Type::tUInt2: ss << *((uint2 *)pX);
break
;
case
Type::tUInt3: ss << *((uint3 *)pX);
break
;
case
Type::tUInt4: ss << *((uint4 *)pX);
break
;
case
Type::tFloat: ss << *((
float
*)pX);
break
;
case
Type::tFloat2: ss << *((float2 *)pX);
break
;
case
Type::tFloat3: ss << *((float3 *)pX);
break
;
case
Type::tFloat4: ss << *((float4 *)pX);;
break
;
case
Type::tRange: ss << *((range *)pX);
break
;
case
Type::tURange: ss << *((urange *)pX);
break
;
case
Type::tIterator: ss <<
"
iterator
"
;
break
;
case
Type::tPointer: ss <<
"
*
"
<< hex <<
intptr_t
(pX) << dec;
if
( info->
firstType
) {
ss <<
"
-> (
"
;
debug_value
(ss, *(
void
**)pX, info->
firstType
, flags);
ss <<
"
)
"
;
}
break
;
case
Type::tStructure:
debug_structure
(ss, (
char
*)pX, info->
structType
, flags);
break
;
case
Type::tBlock: ss <<
"
block
"
<< hex <<
intptr_t
(((Block *)pX)->
body
) << dec;
case
Type::tHandle:
debugType
(info->
annotation
, ss, pX, flags);
break
;
default
:
assert
(
0
&&
"
unsupported print type
"
);
break
;
}
}
}
void
debug_table_value
( stringstream & ss, Table & tab, TypeInfo * info, PrintFlags flags ) {
ss <<
"
([
"
<< tab.
size
<<
"
of
"
<< tab.
capacity
<<
"
]
"
;
bool
first =
true
;
int
keySize =
getTypeSize
(info->
firstType
);
int
valueSize =
getTypeSize
(info->
secondType
);
for
(
uint32_t
i=
0
; i!=tab.
capacity
; ++i ) {
if
( tab.
distance
[i]>=
0
) {
if
( !first ) ss <<
"
"
; first =
false
;
ss <<
"
(
"
;
//
ss << "(@ " << i << " ";
debug_value
( ss, tab.
keys
+ i*keySize, info->
firstType
, flags );
ss <<
"
->
"
;
debug_value
( ss, tab.
data
+ i*valueSize, info->
secondType
, flags );
ss <<
"
)
"
;
}
}
ss <<
"
)
"
;
}
void
debug_value
( stringstream & ss, vec4f x, TypeInfo * info, PrintFlags flags ) {
if
( info->
ref
) {
TypeInfo ti = *info;
ti.
ref
=
false
;
debug_value
(ss, cast<
void
*>::
to
(x), &ti, flags);
}
else
if
( info->
dimSize
) {
debug_dim_value
(ss, cast<
void
*>::
to
(x), info, flags);
}
else
if
( info->
type
==Type::tArray ) {
auto
arr = cast<Array *>::
to
(x);
debug_array_value
(ss, arr->
data
,
getTypeSize
(info->
firstType
), arr->
size
, info->
firstType
, flags);
}
else
if
( info->
type
==Type::tTable ) {
auto
tab = cast<Table *>::
to
(x);
debug_table_value
(ss, *tab, info, flags);
}
else
{
switch
( info->
type
) {
case
Type::tBool: ss << cast<
bool
>::
to
(x);
break
;
case
Type::tInt64: ss << cast<
int64_t
>::
to
(x);
break
;
case
Type::tUInt64: ss <<
"
0x
"
<< hex << cast<
uint64_t
>::
to
(x) << dec;
break
;
case
Type::tString:
if
(
int
(flags) &
int
(PrintFlags::escapeString) ) {
ss <<
"
\"
"
<<
escapeString
(
to_rts
(x)) <<
"
\"
"
;
}
else
{
ss <<
to_rts
(x);
}
break
;
case
Type::tInt: ss << cast<
int32_t
>::
to
(x);
break
;
case
Type::tInt2: ss << cast<int2>::
to
(x);
break
;
case
Type::tInt3: ss << cast<int3>::
to
(x);
break
;
case
Type::tInt4: ss << cast<int4>::
to
(x);
break
;
case
Type::tUInt: ss << cast<
uint32_t
>::
to
(x);
break
;
case
Type::tUInt2: ss << cast<uint2>::
to
(x);
break
;
case
Type::tUInt3: ss << cast<uint3>::
to
(x);
break
;
case
Type::tUInt4: ss << cast<uint4>::
to
(x);
break
;
case
Type::tFloat: ss << cast<
float
>::
to
(x);
break
;
case
Type::tFloat2: ss << cast<float2>::
to
(x);
break
;
case
Type::tFloat3: ss << cast<float3>::
to
(x);
break
;
case
Type::tFloat4: ss << cast<float4>::
to
(x);
break
;
case
Type::tRange: ss << cast<range>::
to
(x);
break
;
case
Type::tURange: ss << cast<urange>::
to
(x);
break
;
case
Type::tIterator: ss <<
"
iterator
"
;
break
;
case
Type::tPointer: ss <<
"
*
"
<< hex <<
intptr_t
(cast<
void
*>::
to
(x)) << dec <<
"
"
;
if
( info->
firstType
) {
ss <<
"
-> (
"
;
debug_value
(ss, cast<
void
*>::
to
(x), info->
firstType
, flags);
ss <<
"
)
"
;
}
break
;
case
Type::tStructure:
debug_structure
(ss, cast<
char
*>::
to
(x), info->
structType
, flags);
break
;
case
Type::tVoid: ss <<
"
void
"
;
break
;
case
Type::tBlock: ss <<
"
block
"
;
break
;
case
Type::tHandle:
debugType
(info->
annotation
, ss, x, flags);
break
;
default
:
assert
(
0
&&
"
unsupported print type
"
);
break
;
}
}
}
string
debug_value
( vec4f x, TypeInfo * info, PrintFlags flags ) {
stringstream ss;
debug_value
(ss, x, info, flags);
return
ss.
str
();
}
string
debug_value
(
void
* pX, TypeInfo * info, PrintFlags flags ) {
stringstream ss;
debug_value
(ss, pX, info, flags);
return
ss.
str
();
}
string
debug_type
( TypeInfo * info ) {
stringstream stream;
if
( info->
type
==Type::tHandle ) {
stream <<
"
handle
"
;
//
TODO: << info->annotation->name << ">";
}
else
if
( info->
type
==Type::tStructure ) {
stream << info->
structType
->
name
;
}
else
if
( info->
type
==Type::tPointer ) {
stream <<
debug_type
(info->
firstType
) <<
"
*
"
;
}
else
if
( info->
type
==Type::tArray ) {
stream <<
"
array <
"
<<
debug_type
(info->
firstType
) <<
"
>
"
;
}
else
if
( info->
type
==Type::tTable ) {
stream <<
"
table <
"
<<
debug_type
(info->
firstType
) <<
"
,
"
<<
debug_type
(info->
secondType
) <<
"
>
"
;
}
else
if
( info->
type
==Type::tIterator ) {
stream <<
"
iterator <
"
<<
debug_type
(info->
firstType
) <<
"
>
"
;
}
else
{
stream <<
to_string
(info->
type
);
}
for
(
uint32_t
i=
0
; i!=info->
dimSize
; ++i ) {
stream <<
"
"
<< info->
dim
[i];
}
if
( info->
ref
)
stream <<
"
&
"
;
return
stream.
str
();
}
string
LineInfo::describe
()
const
{
stringstream ss;
ss <<
"
line
"
<< line <<
"
column
"
<< column;
return
ss.
str
();
}
}
Back
|
FazBrowse Home
|
New Git URL