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
|
/*
* Copyright 2006 The Android Open Source Project
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkScript2.h"
#ifdef SK_DEBUG
#define TypeOpName(op) {SkScriptEngine2::op, #op }
static const struct OpName {
SkScriptEngine2::TypeOp fOp;
const char* fName;
} gOpNames[] = {
TypeOpName(kNop), // should never get generated
TypeOpName(kAccumulatorPop),
TypeOpName(kAccumulatorPush),
TypeOpName(kAddInt),
TypeOpName(kAddScalar),
TypeOpName(kAddString), // string concat
TypeOpName(kArrayIndex),
TypeOpName(kArrayParam),
TypeOpName(kArrayToken),
TypeOpName(kBitAndInt),
TypeOpName(kBitNotInt),
TypeOpName(kBitOrInt),
TypeOpName(kBoxToken),
TypeOpName(kCallback),
TypeOpName(kDivideInt),
TypeOpName(kDivideScalar),
TypeOpName(kDotOperator),
TypeOpName(kElseOp),
TypeOpName(kEnd),
TypeOpName(kEqualInt),
TypeOpName(kEqualScalar),
TypeOpName(kEqualString),
TypeOpName(kFunctionCall),
TypeOpName(kFlipOpsOp),
TypeOpName(kFunctionToken),
TypeOpName(kGreaterEqualInt),
TypeOpName(kGreaterEqualScalar),
TypeOpName(kGreaterEqualString),
TypeOpName(kIfOp),
TypeOpName(kIntToScalar),
TypeOpName(kIntToScalar2),
TypeOpName(kIntToString),
TypeOpName(kIntToString2),
TypeOpName(kIntegerAccumulator),
TypeOpName(kIntegerOperand),
TypeOpName(kLogicalAndInt),
TypeOpName(kLogicalNotInt),
TypeOpName(kLogicalOrInt),
TypeOpName(kMemberOp),
TypeOpName(kMinusInt),
TypeOpName(kMinusScalar),
TypeOpName(kModuloInt),
TypeOpName(kModuloScalar),
TypeOpName(kMultiplyInt),
TypeOpName(kMultiplyScalar),
TypeOpName(kPropertyOp),
TypeOpName(kScalarAccumulator),
TypeOpName(kScalarOperand),
TypeOpName(kScalarToInt),
TypeOpName(kScalarToInt2),
TypeOpName(kScalarToString),
TypeOpName(kScalarToString2),
TypeOpName(kShiftLeftInt),
TypeOpName(kShiftRightInt), // signed
TypeOpName(kStringAccumulator),
TypeOpName(kStringOperand),
TypeOpName(kStringToInt),
TypeOpName(kStringToScalar),
TypeOpName(kStringToScalar2),
TypeOpName(kStringTrack),
TypeOpName(kSubtractInt),
TypeOpName(kSubtractScalar),
TypeOpName(kToBool),
TypeOpName(kUnboxToken),
TypeOpName(kUnboxToken2),
TypeOpName(kXorInt)
};
static size_t gOpNamesSize = sizeof(gOpNames) / sizeof(gOpNames[0]);
#define OperandName(op) {SkOperand2::op, #op }
static const struct OperName {
SkOperand2::OpType fType;
const char* fName;
} gOperandNames[] = {
OperandName(kNoType),
OperandName(kS32),
OperandName(kScalar),
OperandName(kString),
OperandName(kArray),
OperandName(kObject)
};
static size_t gOperandNamesSize = sizeof(gOperandNames) / sizeof(gOperandNames[0]);
// check to see that there are no missing or duplicate entries
void SkScriptEngine2::ValidateDecompileTable() {
SkScriptEngine2::TypeOp op = SkScriptEngine2::kNop;
size_t index;
for (index = 0; index < gOpNamesSize; index++) {
SkASSERT(gOpNames[index].fOp == op);
op = (SkScriptEngine2::TypeOp) (op + 1);
}
index = 0;
SkOperand2::OpType type = SkOperand2::kNoType;
SkASSERT(gOperandNames[index].fType == type);
for (; index < gOperandNamesSize - 1; ) {
type = (SkOperand2::OpType) (1 << index);
SkASSERT(gOperandNames[++index].fType == type);
}
}
void SkScriptEngine2::decompile(const unsigned char* start, size_t length) {
SkASSERT(length > 0);
const unsigned char* opCode = start;
do {
SkASSERT((size_t)(opCode - start) < length);
SkScriptEngine2::TypeOp op = (SkScriptEngine2::TypeOp) *opCode++;
SkASSERT((size_t)op < gOpNamesSize);
SkDebugf("%d: %s", opCode - start - 1, gOpNames[op].fName);
switch (op) {
case SkScriptEngine2::kCallback: {
int index;
memcpy(&index, opCode, sizeof(index));
opCode += sizeof(index);
SkDebugf(" index: %d", index);
} break;
case SkScriptEngine2::kFunctionCall:
case SkScriptEngine2::kMemberOp:
case SkScriptEngine2::kPropertyOp: {
size_t ref;
memcpy(&ref, opCode, sizeof(ref));
opCode += sizeof(ref);
SkDebugf(" ref: %d", ref);
} break;
case SkScriptEngine2::kIntegerAccumulator:
case SkScriptEngine2::kIntegerOperand: {
int32_t integer;
memcpy(&integer, opCode, sizeof(integer));
opCode += sizeof(int32_t);
SkDebugf(" integer: %d", integer);
} break;
case SkScriptEngine2::kScalarAccumulator:
case SkScriptEngine2::kScalarOperand: {
SkScalar scalar;
memcpy(&scalar, opCode, sizeof(scalar));
opCode += sizeof(SkScalar);
SkDebugf(" scalar: %g", SkScalarToFloat(scalar));
} break;
case SkScriptEngine2::kStringAccumulator:
case SkScriptEngine2::kStringOperand: {
int size;
SkString* strPtr = new SkString();
memcpy(&size, opCode, sizeof(size));
opCode += sizeof(size);
strPtr->set((char*) opCode, size);
opCode += size;
SkDebugf(" string: %s", strPtr->c_str());
delete strPtr;
} break;
case SkScriptEngine2::kBoxToken: {
SkOperand2::OpType type;
memcpy(&type, opCode, sizeof(type));
opCode += sizeof(type);
size_t index = 0;
if (type == 0)
SkDebugf(" type: %s", gOperandNames[index].fName);
else {
while (type != 0) {
SkASSERT(index + 1 < gOperandNamesSize);
if (type & (1 << index)) {
type = (SkOperand2::OpType) (type & ~(1 << index));
SkDebugf(" type: %s", gOperandNames[index + 1].fName);
}
index++;
}
}
} break;
case SkScriptEngine2::kIfOp:
case SkScriptEngine2::kLogicalAndInt:
case SkScriptEngine2::kElseOp:
case SkScriptEngine2::kLogicalOrInt: {
int size;
memcpy(&size, opCode, sizeof(size));
opCode += sizeof(size);
SkDebugf(" offset (address): %d (%d)", size, opCode - start + size);
} break;
case SkScriptEngine2::kEnd:
goto done;
case SkScriptEngine2::kNop:
SkASSERT(0);
default:
break;
}
SkDebugf("\n");
} while (true);
done:
SkDebugf("\n");
}
#endif
|