Skip to content

Commit

Permalink
[WIP] Implement live variable analysis
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Laszlo Kulcsar <kuladam@inf.u-szeged.hu>
  • Loading branch information
kulcsaradam committed Apr 8, 2024
1 parent a22a568 commit 2b9957b
Show file tree
Hide file tree
Showing 9 changed files with 1,087 additions and 4 deletions.
133 changes: 133 additions & 0 deletions notes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
live_analysis

get-ből való kiindulás azért jobb mert valaminek be kell állítania az értékét

egy adott getből keresem vissza hogy milyen utakon lehet visszamenni az őt beállító utasításokig
multimap jó

listákban tartom az összes változóra a set-jeit és a get-jeit

jump + sets [T,p]
T - target, ahova ugrunk
p - position, ahonnan ugrottunk
+ listában a set-ek amelyek abban a blokban vannak

dump!!! - variableRange

required stack size: 104 bytes
stack: [(parameter 0, i32, pos 0) (parameter 1, i32, pos 8) (parameter 2, i32, pos 16)
(local 0, i32, pos 24) (local 1, i32, pos 28) (local 2, i32, pos 32)
(local 3, i32, pos 36) (local 4, i32, pos 40) (local 5, i32, pos 44)
(local 6, i32, pos 48) (local 7, i32, pos 52) (constant 1, i32, pos 56)
(constant 2, i32, pos 60) (constant 0, i32, pos 64) (constant 4, i32, pos 68) ....]
bytecode size: 936 bytes

0 const32 dstOffset: 24 value: 0
16 const32 dstOffset: 28 value: 0
32 const32 dstOffset: 32 value: 0
48 const32 dstOffset: 36 value: 0
64 const32 dstOffset: 40 value: 0
80 const32 dstOffset: 44 value: 0
96 const32 dstOffset: 48 value: 0
112 const32 dstOffset: 56 value: 1
128 const32 dstOffset: 60 value: 2
144 const32 dstOffset: 64 value: 0
160 const32 dstOffset: 68 value: 4
176 I32LtS src1: 8 src2: 16 dst: 72
192 jump_if_false srcOffset: 72 dst: 920
208 I32Shl src1: 16 src2: 60 dst: 80
224 I32Add src1: 0 src2: 80 dst: 40
240 move32 srcOffset: 64 dstOffset: 24
256 I32Sub src1: 16 src2: 8 dst: 72
272 move32 srcOffset: 72 dstOffset: 44
288 I32GtS src1: 72 src2: 64 dst: 72
304 jump_if_false srcOffset: 72 dst: 752
320 load32 srcOffset: 40 dstOffset: 36
336 move32 srcOffset: 64 dstOffset: 28
352 I32Add src1: 8 src2: 24 dst: 88
368 I32Shl src1: 88 src2: 60 dst: 88
384 I32Add src1: 0 src2: 88 dst: 80
400 move32 srcOffset: 80 dstOffset: 32
416 load32 srcOffset: 80 dstOffset: 80
432 move32 srcOffset: 80 dstOffset: 48
448 I32GtS src1: 36 src2: 80 dst: 72
464 jump_if_false srcOffset: 72 dst: 512
480 I32Add src1: 24 src2: 56 dst: 24
496 jump dst: 704
512 move32 srcOffset: 32 dstOffset: 72
528 I32Sub src1: 16 src2: 28 dst: 88
544 I32Shl src1: 88 src2: 60 dst: 88
560 I32Add src1: 0 src2: 88 dst: 80
576 move32 srcOffset: 80 dstOffset: 32
592 I32Sub src1: 80 src2: 68 dst: 80
608 move32 srcOffset: 80 dstOffset: 52
624 load32 srcOffset: 80 dstOffset: 80
640 store32 src0Offset: 72 src1Offset: 80
656 store32 src0Offset: 32 src1Offset: 48
672 store32 src0Offset: 52 src1Offset: 36
688 I32Add src1: 28 src2: 56 dst: 28
704 I32Add src1: 24 src2: 28 dst: 72
720 I32LtS src1: 72 src2: 44 dst: 72
736 jump_if_true srcOffset: 72 dst: 352
752 move32 srcOffset: 8 dstOffset: 80
768 move32 srcOffset: 8 dstOffset: 88
784 I32Add src1: 88 src2: 24 dst: 88
800 move32 srcOffset: 88 dstOffset: 8
816 I32Sub src1: 88 src2: 56 dst: 88
832 call index: 1 paramOffsets: 0 80 88 resultOffsets:
856 I32Add src1: 8 src2: 56 dst: 72
872 move32 srcOffset: 72 dstOffset: 8
888 I32LtS src1: 72 src2: 16 dst: 72
904 jump_if_true srcOffset: 72 dst: 240
920 end


required stack size: 48 bytes
stack: [(local 0, i32, pos 0) (local 1, i32, pos 8) (constant 4, i32, pos 16) (constant 1, i32, pos 24) ....]
bytecode size: 200 bytes

0 const32 dstOffset: 0 value: 0
16 const32 dstOffset: 16 value: 4
32 const32 dstOffset: 24 value: 1
48 global.get32 dstOffset: 8 index: 0
64 I32Mul src1: 0 src2: 16 dst: 32
80 load32 srcOffset: 32 dstOffset: 32
96 call index: 0 paramOffsets: 32 resultOffsets:
120 I32Add src1: 0 src2: 24 dst: 32
136 move32 srcOffset: 32 dstOffset: 0
152 I32Ne src1: 32 src2: 8 dst: 32
168 jump_if_true srcOffset: 32 dst: 64
184 end


required stack size: 64 bytes
stack: [(local 0, i32, pos 0) (local 1, i32, pos 8) (constant 0, i32, pos 16) (constant 4, i32, pos 24) (constant 1, i32, pos 32) ....]
bytecode size: 248 bytes

0 const32 dstOffset: 0 value: 0
16 const32 dstOffset: 16 value: 0
32 const32 dstOffset: 24 value: 4
48 const32 dstOffset: 32 value: 1
64 global.get32 dstOffset: 8 index: 0
80 I32Mul src1: 0 src2: 24 dst: 40
96 I32Sub src1: 8 src2: 0 dst: 48
112 store32 src0Offset: 40 src1Offset: 48
128 I32Add src1: 0 src2: 32 dst: 40
144 move32 srcOffset: 40 dstOffset: 0
160 I32Ne src1: 40 src2: 8 dst: 40
176 jump_if_true srcOffset: 40 dst: 80
192 global.get32 dstOffset: 56 index: 0
208 call index: 1 paramOffsets: 16 16 56 resultOffsets:
232 end


required stack size: 16 bytes
stack: [(parameter 0, i32, pos 0) ....]
bytecode size: 40 bytes

0 load32 srcOffset: 0 dstOffset: 8
16 end resultOffsets: 8

invoke read(0) expect value(0) (line: 212) : OK
invoke read(4) expect value(1) (line: 213) : OK
invoke read(8) expect value(2) (line: 214) : OK
32 changes: 31 additions & 1 deletion src/interpreter/ByteCode.h
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,7 @@ class BinaryOperation : public ByteCode {
const ByteCodeStackOffset* srcOffset() const { return m_srcOffset; }
ByteCodeStackOffset dstOffset() const { return m_dstOffset; }
void setDstOffset(ByteCodeStackOffset o) { m_dstOffset = o; }
void setSrcOffset(ByteCodeStackOffset o, size_t index) { m_srcOffset[index] = o; }
#if !defined(NDEBUG)
void dump(size_t pos)
{
Expand Down Expand Up @@ -705,6 +706,14 @@ class UnaryOperation : public ByteCode {
}
ByteCodeStackOffset srcOffset() const { return m_srcOffset; }
ByteCodeStackOffset dstOffset() const { return m_dstOffset; }
void setDstOffset(ByteCodeStackOffset newOffset)
{
m_dstOffset = newOffset;
}
void setSrcOffset(ByteCodeStackOffset newOffset)
{
m_srcOffset = newOffset;
}
#if !defined(NDEBUG)
void dump(size_t pos)
{
Expand Down Expand Up @@ -874,6 +883,14 @@ class Move32 : public ByteCode {

ByteCodeStackOffset srcOffset() const { return m_srcOffset; }
ByteCodeStackOffset dstOffset() const { return m_dstOffset; }
void setDstOffset(ByteCodeStackOffset newOffset)
{
m_dstOffset = newOffset;
}
void setSrcOffset(ByteCodeStackOffset newOffset)
{
m_srcOffset = newOffset;
}

#if !defined(NDEBUG)
void dump(size_t pos)
Expand Down Expand Up @@ -951,7 +968,9 @@ class Load32 : public ByteCode {
}

ByteCodeStackOffset srcOffset() const { return m_srcOffset; }
void setSrcOffset(ByteCodeStackOffset o) { m_srcOffset = o; }
ByteCodeStackOffset dstOffset() const { return m_dstOffset; }
void setDstOffset(ByteCodeStackOffset o) { m_dstOffset = o; }

#if !defined(NDEBUG)
void dump(size_t pos)
Expand Down Expand Up @@ -1003,7 +1022,9 @@ class Store32 : public ByteCode {
}

ByteCodeStackOffset src0Offset() const { return m_src0Offset; }
void setSrc0Offset(ByteCodeStackOffset o) { m_src0Offset = o; }
ByteCodeStackOffset src1Offset() const { return m_src1Offset; }
void setSrc1Offset(ByteCodeStackOffset o) { m_src1Offset = o; }

#if !defined(NDEBUG)
void dump(size_t pos)
Expand Down Expand Up @@ -1144,11 +1165,15 @@ class Select : public ByteCode {
}

ByteCodeStackOffset condOffset() const { return m_condOffset; }
void setCondOffset(ByteCodeStackOffset o) { m_condOffset = o; }
uint16_t valueSize() const { return m_valueSize; }
bool isFloat() const { return m_isFloat != 0; }
ByteCodeStackOffset src0Offset() const { return m_src0Offset; }
void setSrc0Offset(ByteCodeStackOffset o) { m_src0Offset = o; }
ByteCodeStackOffset src1Offset() const { return m_src1Offset; }
void setSrc1Offset(ByteCodeStackOffset o) { m_src1Offset = o; }
ByteCodeStackOffset dstOffset() const { return m_dstOffset; }
void setDstOffset(ByteCodeStackOffset o) { m_dstOffset = o; }

#if !defined(NDEBUG)
void dump(size_t pos)
Expand Down Expand Up @@ -1388,7 +1413,9 @@ class MemoryLoad : public ByteCode {

uint32_t offset() const { return m_offset; }
ByteCodeStackOffset srcOffset() const { return m_srcOffset; }
void setSrcOffset(ByteCodeStackOffset o) { m_srcOffset = o; }
ByteCodeStackOffset dstOffset() const { return m_dstOffset; }
void setDstOffset(ByteCodeStackOffset o) { m_dstOffset = o; }

#if !defined(NDEBUG)
void dump(size_t pos)
Expand Down Expand Up @@ -1486,7 +1513,9 @@ class MemoryStore : public ByteCode {

uint32_t offset() const { return m_offset; }
ByteCodeStackOffset src0Offset() const { return m_src0Offset; }
void setSrc0Offset(ByteCodeStackOffset o) { m_src0Offset = o; }
ByteCodeStackOffset src1Offset() const { return m_src1Offset; }
void setSrc1Offset(ByteCodeStackOffset o) { m_src1Offset = o; }

#if !defined(NDEBUG)
void dump(size_t pos)
Expand Down Expand Up @@ -2037,6 +2066,7 @@ class GlobalGet32 : public ByteCode {
}

ByteCodeStackOffset dstOffset() const { return m_dstOffset; }
void setDstOffset(ByteCodeStackOffset o) { m_dstOffset = o; }
uint32_t index() const { return m_index; }

#if !defined(NDEBUG)
Expand Down Expand Up @@ -2255,7 +2285,7 @@ class End : public ByteCode {
{
}

ByteCodeStackOffset* resultOffsets() const
ByteCodeStackOffset* resultOffsets()
{
return reinterpret_cast<ByteCodeStackOffset*>(reinterpret_cast<size_t>(this) + sizeof(End));
}
Expand Down
Loading

0 comments on commit 2b9957b

Please sign in to comment.