Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions src/Decompiler/Analysis/DeclarationInserter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using Reko.Core.Lib;
using System;
using System.Collections.Generic;
using System.Linq;

namespace Reko.Analysis
{
Expand All @@ -47,7 +48,7 @@ public void InsertDeclaration(Web web)
{
if (sid.DefStatement != null)
{
if (sid.DefStatement.Instruction is DefInstruction)
if (IsImplicitDeclaration(sid.DefStatement))
return;
blocks.Add(sid.DefStatement.Block);
foreach (Statement u in sid.Uses)
Expand Down Expand Up @@ -87,5 +88,23 @@ public void InsertDeclaration(Web web)
new Declaration(web.Identifier!, null));
}
}
}

static private bool IsImplicitDeclaration(Statement stm)
{
if (stm.Instruction is not DefInstruction def)
return false;
// Do not add declarations for global variables
if (def.Identifier.Storage is GlobalStorage)
return true;
// Do not add declarations for parameters of procedure
var sig = stm.Block.Procedure.Signature;
if (
sig.ParametersValid &&
sig.Parameters!.Any(p => p.Name == def.Identifier.Name))
{
return true;
}
return false;
}
}
}
1 change: 1 addition & 0 deletions src/tests/Analysis/DfaReg00015.exp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// Return size: 0
void fn0C00_0000(word16 ax, word16 dx, word16 bx)
fn0C00_0000_entry:
selector ss
// succ: l0C00_0000
l0C00_0000:
Mem8[ss:0x6B6<16>:word16] = bx
Expand Down
1 change: 1 addition & 0 deletions src/tests/Analysis/DfaRegPairReturn.exp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// Return size: 0
void fn0C00_0000()
fn0C00_0000_entry:
selector cs
// succ: l0C00_0000
l0C00_0000:
Mem12[cs:0x2C<16>:word16] = SLICE(fn0C00_001B(cs), word16, 0)
Expand Down
2 changes: 2 additions & 0 deletions src/tests/Analysis/DfaStackPointerMessing.exp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ fn0C00_0000_exit:
// Return size: 0
word16 fn0C00_0008(word16 bx, selector ds)
fn0C00_0008_entry:
mp16 fp
selector ss
// succ: l0C00_0008
l0C00_0008:
Mem5[ds:0x300<16>:word16] = fp
Expand Down
4 changes: 4 additions & 0 deletions src/tests/Structure/StrReg00013.exp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Return size: 0
void fn0C00_0000(selector ds)
fn0C00_0000_entry:
selector ss
selector cs
Mem10[0C00:0001:word16] = 0x800<16>
Mem11[0800:5422:word16] = ds
Mem17[0800:0066:word16] = Mem11[0800:5420:word16]
Expand Down Expand Up @@ -228,6 +230,8 @@ fn0C00_0000_exit:

void fn0C00_0000(selector ds)
{
selector ss;
selector cs;
Mem10[0C00:0001:word16] = 0x800<16>;
Mem11[0800:5422:word16] = ds;
Mem17[0800:0066:word16] = Mem11[0800:5420:word16];
Expand Down
46 changes: 24 additions & 22 deletions src/tests/Typing/DtbArrayAccess.exp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Return size: 0
void ArrayAccess()
ArrayAccess_entry:
word32 r
word32 i
// succ: l1
l1:
(r + 0x14<32>)[i * 0xA<32>] = 0<i32>
Expand All @@ -12,17 +14,17 @@ ArrayAccess_exit:
// Equivalence classes ////////////
Eq_1: (ptr32 (struct "Globals"))
globals_t (in globals : (ptr32 (struct "Globals")))
Eq_2: int32
T_2 (in 0<i32> : int32)
T_9 (in (r + 0x14<32>)[i * 0xA<32>] : int32)
Eq_3: (ptr32 (struct (10 T_18 t0010) (14 T_16 t0014)))
T_3 (in r : word32)
Eq_2: (ptr32 (struct (10 T_18 t0010) (14 T_16 t0014)))
T_2 (in r : word32)
Eq_3: ui32
T_3 (in i : word32)
Eq_4: int32
T_4 (in 0x14<32> : word32)
Eq_5: (ptr32 T_16)
T_5 (in r + 0x14<32> : word32)
Eq_6: ui32
T_6 (in i : word32)
T_4 (in 0<i32> : int32)
T_9 (in (r + 0x14<32>)[i * 0xA<32>] : int32)
Eq_5: int32
T_5 (in 0x14<32> : word32)
Eq_6: (ptr32 T_16)
T_6 (in r + 0x14<32> : word32)
Eq_7: ui32
T_7 (in 0xA<32> : word32)
Eq_8: ui32
Expand Down Expand Up @@ -50,26 +52,26 @@ globals_t: (in globals : (ptr32 (struct "Globals")))
Class: Eq_1
DataType: (ptr32 (struct "Globals"))
OrigDataType: (ptr32 (struct "Globals"))
T_2: (in 0<i32> : int32)
T_2: (in r : word32)
Class: Eq_2
DataType: int32
OrigDataType: int32
T_3: (in r : word32)
Class: Eq_3
DataType: (ptr32 (struct (10 T_18 t0010) (14 T_16 t0014)))
OrigDataType: (ptr32 (struct (10 T_18 t0010) (14 T_16 t0014)))
T_4: (in 0x14<32> : word32)
T_3: (in i : word32)
Class: Eq_3
DataType: ui32
OrigDataType: ui32
T_4: (in 0<i32> : int32)
Class: Eq_4
DataType: int32
OrigDataType: int32
T_5: (in r + 0x14<32> : word32)
T_5: (in 0x14<32> : word32)
Class: Eq_5
DataType: int32
OrigDataType: int32
T_6: (in r + 0x14<32> : word32)
Class: Eq_6
DataType: (ptr32 T_16)
OrigDataType: (ptr32 T_16)
T_6: (in i : word32)
Class: Eq_6
DataType: ui32
OrigDataType: ui32
T_7: (in 0xA<32> : word32)
Class: Eq_7
DataType: ui32
Expand All @@ -79,7 +81,7 @@ T_8: (in i * 0xA<32> : word32)
DataType: ui32
OrigDataType: ui32
T_9: (in (r + 0x14<32>)[i * 0xA<32>] : int32)
Class: Eq_2
Class: Eq_4
DataType: int32
OrigDataType: int32
T_10: (in 0x10<32> : word32)
Expand Down
21 changes: 11 additions & 10 deletions src/tests/Typing/DtbGlobalVariables.exp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Return size: 0
void GlobalVariablesMock()
GlobalVariablesMock_entry:
word32 ptr
// succ: l1
l1:
Mem4[ptr + 0<32>:real32] = 0.75F
Expand All @@ -11,11 +12,11 @@ GlobalVariablesMock_exit:
// Equivalence classes ////////////
Eq_1: (ptr32 (struct "Globals"))
globals_t (in globals : (ptr32 (struct "Globals")))
Eq_2: real32
T_2 (in 0.75F : real32)
Eq_2: (ptr32 (struct (0 T_6 t0000)))
T_2 (in ptr : word32)
Eq_3: real32
T_3 (in 0.75F : real32)
T_6 (in Mem4[ptr + 0<32>:real32] : real32)
Eq_3: (ptr32 (struct (0 T_6 t0000)))
T_3 (in ptr : word32)
Eq_4: word32
T_4 (in 0<32> : word32)
Eq_5: word32
Expand All @@ -30,14 +31,14 @@ globals_t: (in globals : (ptr32 (struct "Globals")))
Class: Eq_1
DataType: (ptr32 (struct "Globals"))
OrigDataType: (ptr32 (struct "Globals"))
T_2: (in 0.75F : real32)
T_2: (in ptr : word32)
Class: Eq_2
DataType: real32
OrigDataType: real32
T_3: (in ptr : word32)
Class: Eq_3
DataType: (ptr32 (struct (0 T_6 t0000)))
OrigDataType: (ptr32 (struct (0 T_6 t0000)))
T_3: (in 0.75F : real32)
Class: Eq_3
DataType: real32
OrigDataType: real32
T_4: (in 0<32> : word32)
Class: Eq_4
DataType: word32
Expand All @@ -47,7 +48,7 @@ T_5: (in ptr + 0<32> : word32)
DataType: word32
OrigDataType: word32
T_6: (in Mem4[ptr + 0<32>:real32] : real32)
Class: Eq_2
Class: Eq_3
DataType: real32
OrigDataType: real32
T_7: (in 0.5F : real32)
Expand Down
1 change: 1 addition & 0 deletions src/tests/Typing/DtbSegmentedDoubleReference.exp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Return size: 0
void SegmentedDoubleReferenceMock()
SegmentedDoubleReferenceMock_entry:
word16 ds
// succ: l1
l1:
Mem6[ds:0x100<16>:word16] = Mem0[ds:Mem0[ds:0x300<16>:word16] + 4<16>:word16]
Expand Down
64 changes: 33 additions & 31 deletions src/tests/Typing/DtbTreeFind.exp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Return size: 0
void TreeFindMock()
TreeFindMock_entry:
word32 t
word32 v
// succ: l0
l0:
// succ: l0_seek
Expand Down Expand Up @@ -30,21 +32,21 @@ TreeFindMock_exit:
// Equivalence classes ////////////
Eq_1: (ptr32 (struct "Globals"))
globals_t (in globals : (ptr32 (struct "Globals")))
Eq_2: (ptr32 (struct (0 T_8 t0000) (4 T_14 t0004) (8 T_17 t0008)))
Eq_2: (ptr32 (struct (0 T_9 t0000) (4 T_14 t0004) (8 T_17 t0008)))
T_2 (in t : word32)
T_3 (in 0<32> : word32)
T_4 (in 0<32> : word32)
T_14 (in Mem0[t + 4<32>:word32] : word32)
T_17 (in Mem0[t + 8<32>:word32] : word32)
Eq_4: bool
T_4 (in t == 0<32> : bool)
Eq_5: int32
T_5 (in vv_5 : word32)
T_8 (in Mem0[t + 0<32>:word32] : word32)
T_9 (in v : word32)
Eq_6: word32
T_6 (in 0<32> : word32)
Eq_3: int32
T_3 (in v : word32)
T_6 (in vv_5 : word32)
T_9 (in Mem0[t + 0<32>:word32] : word32)
Eq_5: bool
T_5 (in t == 0<32> : bool)
Eq_7: word32
T_7 (in t + 0<32> : word32)
T_7 (in 0<32> : word32)
Eq_8: word32
T_8 (in t + 0<32> : word32)
Eq_10: bool
T_10 (in v == vv_5 : bool)
Eq_11: bool
Expand All @@ -64,36 +66,36 @@ globals_t: (in globals : (ptr32 (struct "Globals")))
OrigDataType: (ptr32 (struct "Globals"))
T_2: (in t : word32)
Class: Eq_2
DataType: (ptr32 (struct (0 T_8 t0000) (4 T_14 t0004) (8 T_17 t0008)))
OrigDataType: (ptr32 (struct (0 T_8 t0000) (4 T_14 t0004) (8 T_17 t0008)))
T_3: (in 0<32> : word32)
DataType: (ptr32 (struct (0 T_9 t0000) (4 T_14 t0004) (8 T_17 t0008)))
OrigDataType: (ptr32 (struct (0 T_9 t0000) (4 T_14 t0004) (8 T_17 t0008)))
T_3: (in v : word32)
Class: Eq_3
DataType: int32
OrigDataType: int32
T_4: (in 0<32> : word32)
Class: Eq_2
DataType: (ptr32 (struct (0 T_8 t0000) (4 T_14 t0004) (8 T_17 t0008)))
DataType: (ptr32 (struct (0 T_9 t0000) (4 T_14 t0004) (8 T_17 t0008)))
OrigDataType: word32
T_4: (in t == 0<32> : bool)
Class: Eq_4
T_5: (in t == 0<32> : bool)
Class: Eq_5
DataType: bool
OrigDataType: bool
T_5: (in vv_5 : word32)
Class: Eq_5
T_6: (in vv_5 : word32)
Class: Eq_3
DataType: int32
OrigDataType: int32
T_6: (in 0<32> : word32)
Class: Eq_6
T_7: (in 0<32> : word32)
Class: Eq_7
DataType: word32
OrigDataType: word32
T_7: (in t + 0<32> : word32)
Class: Eq_7
T_8: (in t + 0<32> : word32)
Class: Eq_8
DataType: word32
OrigDataType: word32
T_8: (in Mem0[t + 0<32>:word32] : word32)
Class: Eq_5
T_9: (in Mem0[t + 0<32>:word32] : word32)
Class: Eq_3
DataType: int32
OrigDataType: word32
T_9: (in v : word32)
Class: Eq_5
DataType: int32
OrigDataType: int32
T_10: (in v == vv_5 : bool)
Class: Eq_10
DataType: bool
Expand All @@ -112,7 +114,7 @@ T_13: (in t + 4<32> : word32)
OrigDataType: ptr32
T_14: (in Mem0[t + 4<32>:word32] : word32)
Class: Eq_2
DataType: (ptr32 (struct (0 T_8 t0000) (4 T_14 t0004) (8 T_17 t0008)))
DataType: (ptr32 (struct (0 T_9 t0000) (4 T_14 t0004) (8 T_17 t0008)))
OrigDataType: word32
T_15: (in 8<32> : word32)
Class: Eq_15
Expand All @@ -124,5 +126,5 @@ T_16: (in t + 8<32> : word32)
OrigDataType: ptr32
T_17: (in Mem0[t + 8<32>:word32] : word32)
Class: Eq_2
DataType: (ptr32 (struct (0 T_8 t0000) (4 T_14 t0004) (8 T_17 t0008)))
DataType: (ptr32 (struct (0 T_9 t0000) (4 T_14 t0004) (8 T_17 t0008)))
OrigDataType: word32
Loading