17
17
#ifndef __WalrusByteCode__
18
18
#define __WalrusByteCode__
19
19
20
+ #include " Walrus.h"
20
21
#if !defined(NDEBUG)
21
22
#include < cinttypes>
22
23
#include " runtime/Module.h"
@@ -932,6 +933,12 @@ class ByteCode {
932
933
933
934
Opcode opcode () const ;
934
935
size_t getSize () const ;
936
+ std::vector<Walrus::ByteCodeStackOffset> getByteCodeStackOffsets (FunctionType* funcType) const ;
937
+ void setByteCodeOffset (size_t index, Walrus::ByteCodeStackOffset offset, Walrus::ByteCodeStackOffset original);
938
+ void dump () const
939
+ {
940
+ return ;
941
+ }
935
942
936
943
protected:
937
944
friend class Interpreter ;
@@ -964,6 +971,8 @@ class ByteCodeOffset2 : public ByteCode {
964
971
965
972
ByteCodeStackOffset stackOffset1 () const { return m_stackOffset1; }
966
973
ByteCodeStackOffset stackOffset2 () const { return m_stackOffset2; }
974
+ void setStackOffset1 (Walrus::ByteCodeStackOffset o) { m_stackOffset1 = o; }
975
+ void setStackOffset2 (Walrus::ByteCodeStackOffset o) { m_stackOffset2 = o; }
967
976
968
977
protected:
969
978
ByteCodeStackOffset m_stackOffset1;
@@ -982,6 +991,7 @@ class ByteCodeOffset3 : public ByteCode {
982
991
ByteCodeStackOffset stackOffset1 () const { return m_stackOffsets[0 ]; }
983
992
ByteCodeStackOffset stackOffset2 () const { return m_stackOffsets[1 ]; }
984
993
ByteCodeStackOffset stackOffset3 () const { return m_stackOffsets[2 ]; }
994
+ void setStackOffset (uint8_t index, Walrus::ByteCodeStackOffset o) { m_stackOffsets[index] = o; }
985
995
986
996
protected:
987
997
ByteCodeStackOffset m_stackOffsets[3 ];
@@ -997,6 +1007,7 @@ class ByteCodeOffsetValue : public ByteCode {
997
1007
}
998
1008
999
1009
ByteCodeStackOffset stackOffset () const { return m_stackOffset; }
1010
+ void setStackOffset (ByteCodeStackOffset o) { m_stackOffset = o; }
1000
1011
uint32_t uint32Value () const { return m_value; }
1001
1012
int32_t int32Value () const { return static_cast <int32_t >(m_value); }
1002
1013
@@ -1016,7 +1027,9 @@ class ByteCodeOffset2Value : public ByteCode {
1016
1027
}
1017
1028
1018
1029
ByteCodeStackOffset stackOffset1 () const { return m_stackOffset1; }
1030
+ void setStackOffset1 (ByteCodeStackOffset o) { m_stackOffset1 = o; }
1019
1031
ByteCodeStackOffset stackOffset2 () const { return m_stackOffset2; }
1032
+ void setStackOffset2 (ByteCodeStackOffset o) { m_stackOffset2 = o; }
1020
1033
uint32_t uint32Value () const { return m_value; }
1021
1034
int32_t int32Value () const { return static_cast <int32_t >(m_value); }
1022
1035
@@ -1041,7 +1054,9 @@ class ByteCodeOffset2ValueMemIdx : public ByteCode {
1041
1054
uint16_t memIndex () const { return m_memIndex; }
1042
1055
uint16_t alignment () const { return m_alignment; }
1043
1056
ByteCodeStackOffset stackOffset1 () const { return m_stackOffset1; }
1057
+ void setStackOffset1 (ByteCodeStackOffset o) { m_stackOffset1 = o; }
1044
1058
ByteCodeStackOffset stackOffset2 () const { return m_stackOffset2; }
1059
+ void setStackOffset2 (ByteCodeStackOffset o) { m_stackOffset2 = o; }
1045
1060
uint32_t uint32Value () const { return m_value; }
1046
1061
int32_t int32Value () const { return static_cast <int32_t >(m_value); }
1047
1062
@@ -1066,6 +1081,7 @@ class ByteCodeOffset4 : public ByteCode {
1066
1081
ByteCodeStackOffset src1Offset () const { return m_stackOffsets[1 ]; }
1067
1082
ByteCodeStackOffset src2Offset () const { return m_stackOffsets[2 ]; }
1068
1083
ByteCodeStackOffset dstOffset () const { return m_stackOffsets[3 ]; }
1084
+ void setStackOffset (size_t index, ByteCodeStackOffset o) { m_stackOffsets[index] = o; }
1069
1085
1070
1086
protected:
1071
1087
ByteCodeStackOffset m_stackOffsets[4 ];
@@ -1235,6 +1251,7 @@ class BinaryOperation : public ByteCodeOffset3 {
1235
1251
const ByteCodeStackOffset* srcOffset () const { return stackOffsets (); }
1236
1252
ByteCodeStackOffset dstOffset () const { return stackOffset3 (); }
1237
1253
void setDstOffset (ByteCodeStackOffset o) { m_stackOffsets[2 ] = o; }
1254
+ void setSrcOffsset (ByteCodeStackOffset o, size_t index) { m_stackOffsets[index] = o; }
1238
1255
#if !defined(NDEBUG)
1239
1256
void dump (size_t pos)
1240
1257
{
@@ -1394,6 +1411,11 @@ class Call : public ByteCode {
1394
1411
return reinterpret_cast <ByteCodeStackOffset*>(reinterpret_cast <size_t >(this ) + sizeof (Call));
1395
1412
}
1396
1413
1414
+ void setStackOffset (size_t index, ByteCodeStackOffset o)
1415
+ {
1416
+ reinterpret_cast <ByteCodeStackOffset*>(reinterpret_cast <size_t >(this ) + sizeof (Call))[index] = o;
1417
+ }
1418
+
1397
1419
uint16_t parameterOffsetsSize () const
1398
1420
{
1399
1421
return m_parameterOffsetsSize;
@@ -1444,13 +1466,21 @@ class CallIndirect : public ByteCode {
1444
1466
}
1445
1467
1446
1468
ByteCodeStackOffset calleeOffset () const { return m_calleeOffset; }
1469
+ void setCalleeOffset (ByteCodeStackOffset o) { m_calleeOffset = o; }
1447
1470
uint32_t tableIndex () const { return m_tableIndex; }
1448
1471
FunctionType* functionType () const { return m_functionType; }
1449
1472
ByteCodeStackOffset* stackOffsets () const
1450
1473
{
1451
1474
return reinterpret_cast <ByteCodeStackOffset*>(reinterpret_cast <size_t >(this ) + sizeof (CallIndirect));
1452
1475
}
1453
1476
1477
+ void setStackOffset (size_t index, ByteCodeStackOffset o)
1478
+ {
1479
+ (reinterpret_cast <ByteCodeStackOffset*>(reinterpret_cast <size_t >(this ) + sizeof (CallIndirect)))[index] = o;
1480
+
1481
+ // *(reinterpret_cast<ByteCodeStackOffset*>(reinterpret_cast<size_t>(this) + sizeof(Call) + index * sizeof(ByteCodeStackOffset))) = o;
1482
+ }
1483
+
1454
1484
uint16_t parameterOffsetsSize () const
1455
1485
{
1456
1486
return m_parameterOffsetsSize;
@@ -1761,11 +1791,15 @@ class Select : public ByteCode {
1761
1791
}
1762
1792
1763
1793
ByteCodeStackOffset condOffset () const { return m_condOffset; }
1794
+ void setCondOffset (ByteCodeStackOffset o) { m_condOffset = o; }
1764
1795
uint16_t valueSize () const { return m_valueSize; }
1765
1796
bool isFloat () const { return m_isFloat != 0 ; }
1766
1797
ByteCodeStackOffset src0Offset () const { return m_src0Offset; }
1798
+ void setSrc0Offset (ByteCodeStackOffset o) { m_src0Offset = o; }
1767
1799
ByteCodeStackOffset src1Offset () const { return m_src1Offset; }
1800
+ void setSrc1Offset (ByteCodeStackOffset o) { m_src1Offset = o; }
1768
1801
ByteCodeStackOffset dstOffset () const { return m_dstOffset; }
1802
+ void setDstOffset (ByteCodeStackOffset o) { m_dstOffset = o; }
1769
1803
1770
1804
#if !defined(NDEBUG)
1771
1805
void dump (size_t pos)
@@ -1798,6 +1832,7 @@ class BrTable : public ByteCode {
1798
1832
}
1799
1833
1800
1834
ByteCodeStackOffset condOffset () const { return m_condOffset; }
1835
+ void setCondOffset (ByteCodeStackOffset o) { m_condOffset = o; }
1801
1836
int32_t defaultOffset () const { return m_defaultOffset; }
1802
1837
static inline size_t offsetOfDefault () { return offsetof (BrTable, m_defaultOffset); }
1803
1838
@@ -1871,6 +1906,10 @@ class MemoryInit : public ByteCode {
1871
1906
{
1872
1907
return m_srcOffsets;
1873
1908
}
1909
+ void setStackOffset (size_t index, ByteCodeStackOffset o)
1910
+ {
1911
+ m_srcOffsets[index] = o;
1912
+ }
1874
1913
1875
1914
uint16_t memIndex () const { return m_memIndex; }
1876
1915
@@ -3110,6 +3149,10 @@ class TableCopy : public ByteCode {
3110
3149
{
3111
3150
return m_srcOffsets;
3112
3151
}
3152
+ void setStackOffset (size_t index, ByteCodeStackOffset o)
3153
+ {
3154
+ m_srcOffsets[index] = o;
3155
+ }
3113
3156
3114
3157
#if !defined(NDEBUG)
3115
3158
void dump (size_t pos)
@@ -3174,6 +3217,11 @@ class TableInit : public ByteCode {
3174
3217
{
3175
3218
return m_srcOffsets;
3176
3219
}
3220
+ void setStackOffset (size_t index, ByteCodeStackOffset o)
3221
+ {
3222
+ m_srcOffsets[index] = o;
3223
+ }
3224
+
3177
3225
#if !defined(NDEBUG)
3178
3226
void dump (size_t pos)
3179
3227
{
@@ -3391,6 +3439,10 @@ class Throw : public ByteCode {
3391
3439
{
3392
3440
return reinterpret_cast <ByteCodeStackOffset*>(reinterpret_cast <size_t >(this ) + sizeof (Throw));
3393
3441
}
3442
+ void setDataOffset (size_t index, ByteCodeStackOffset o)
3443
+ {
3444
+ reinterpret_cast <ByteCodeStackOffset*>(reinterpret_cast <size_t >(this ) + sizeof (Throw))[index] = o;
3445
+ }
3394
3446
3395
3447
uint32_t offsetsSize () const
3396
3448
{
@@ -3466,6 +3518,11 @@ class End : public ByteCode {
3466
3518
return reinterpret_cast <ByteCodeStackOffset*>(reinterpret_cast <size_t >(this ) + sizeof (End));
3467
3519
}
3468
3520
3521
+ void setResultOffset (size_t index, ByteCodeStackOffset o)
3522
+ {
3523
+ reinterpret_cast <ByteCodeStackOffset*>(reinterpret_cast <size_t >(this ) + sizeof (End))[index] = o;
3524
+ }
3525
+
3469
3526
uint32_t offsetsSize () const
3470
3527
{
3471
3528
return m_offsetsSize;
0 commit comments