FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
daScript/src/simulate/simulate_instrument.cpp at master · rburkholder/daScript · GitHub
rburkholder
/
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
/
simulate_instrument.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
113 lines (105 loc) · 4.31 KB
Breadcrumbs
daScript
/
src
/
simulate
/
simulate_instrument.cpp
Copy path
File metadata and controls
113 lines (105 loc) · 4.31 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
#
include
"
daScript/misc/platform.h
"
#
include
"
daScript/simulate/simulate.h
"
#
include
"
daScript/simulate/simulate_nodes.h
"
namespace
das
{
#
if
DAS_DEBUGGER
struct
SimInstVisitor
: SimVisitor {
bool
isCorrectFileAndLine
(
const
LineInfo & info ) {
if
( cmpBlk ) {
vec4f args[
1
];
args[
0
] = cast<LineInfo&>::
from
(info);
auto
res = blkContext->
invoke
(*cmpBlk, args,
nullptr
, blkLine);
//
note: no line-info
return
cast<
bool
>::
to
(res);
}
else
{
return
true
;
}
}
SimNode *
instrumentNode
( SimNode * expr ) {
if
( !expr->
rtti_node_isInstrument
() ) {
return
context->
code
->
makeNode
<SimNodeDebug_Instrument>(expr->
debugInfo
, expr);
}
else
{
return
expr;
}
}
SimNode *
clearNode
( SimNode * expr ) {
if
( expr->
rtti_node_isInstrument
() ) {
auto
si = (SimNodeDebug_Instrument *) expr;
return
si->
subexpr
;
}
else
{
return
expr;
}
}
virtual
SimNode *
visit
( SimNode * node )
override
{
if
( node->
rtti_node_isBlock
() ) {
SimNode_Block * blk = (SimNode_Block *) node;
for
(
uint32_t
i=
0
, is=blk->
total
; i!=is; ++i ) {
auto
& expr = blk->
list
[i];
if
( anyLine ||
isCorrectFileAndLine
(expr->
debugInfo
) ) {
expr = isInstrumenting ?
instrumentNode
(expr) :
clearNode
(expr);
}
}
for
(
uint32_t
i=
0
, is=blk->
totalFinal
; i!=is; ++i ) {
auto
& expr = blk->
finalList
[i];
if
( anyLine ||
isCorrectFileAndLine
(expr->
debugInfo
) ) {
expr = isInstrumenting ?
instrumentNode
(expr) :
clearNode
(expr);
}
}
}
return
node;
}
Context * context =
nullptr
;
const
Block * cmpBlk =
nullptr
;
Context * blkContext =
nullptr
;
LineInfo * blkLine =
nullptr
;
bool
isInstrumenting =
true
;
bool
anyLine =
false
;
};
void
Context::instrumentContextNode
(
const
Block & blk,
bool
isInstrumenting, Context * context, LineInfo * line ) {
SimInstVisitor instrument;
instrument.
context
=
this
;
instrument.
cmpBlk
= &blk;
instrument.
blkContext
= context;
instrument.
blkLine
= line;
instrument.
isInstrumenting
= isInstrumenting;
runVisitor
(&instrument);
}
void
Context::clearInstruments
() {
SimInstVisitor instrument;
instrument.
context
=
this
;
instrument.
isInstrumenting
=
false
;
instrument.
anyLine
=
true
;
runVisitor
(&instrument);
instrumentFunction
(
0u
,
false
,
0ul
,
false
);
}
void
Context::instrumentFunction
( SimFunction *
FNPTR
,
bool
isInstrumenting,
uint64_t
userData,
bool
threadLocal ) {
auto
instFn = [&](SimFunction * fun,
uint64_t
fnMnh) {
if
( !fun->
code
)
return
;
if
( isInstrumenting ) {
if
( !fun->
code
->
rtti_node_isInstrumentFunction
() ) {
if
( threadLocal ) {
fun->
code
= code->
makeNode
<SimNodeDebug_InstrumentFunctionThreadLocal>(fun->
code
->
debugInfo
, fun, fnMnh, fun->
code
, userData);
}
else
{
fun->
code
= code->
makeNode
<SimNodeDebug_InstrumentFunction>(fun->
code
->
debugInfo
, fun, fnMnh, fun->
code
, userData);
}
}
}
else
{
if
( fun->
code
->
rtti_node_isInstrumentFunction
() ) {
auto
inode = (SimNodeDebug_InstrumentFunction *) fun->
code
;
fun->
code
= inode->
subexpr
;
}
}
};
if
(
FNPTR
==
nullptr
) {
for
(
int
fni=
0
, fnis=totalFunctions; fni!=fnis; ++fni ) {
instFn
(&functions[fni], functions[fni].
mangledNameHash
);
}
}
else
{
instFn
(
FNPTR
,
FNPTR
->
mangledNameHash
);
}
}
#
else
void
Context::instrumentFunction
( SimFunction *,
bool
,
uint64_t
,
bool
) {}
void
Context::instrumentContextNode
(
const
Block &,
bool
, Context *, LineInfo * ) {}
void
Context::clearInstruments
() {}
#
endif
}
Back
|
FazBrowse Home
|
New Git URL