Skip to content

Commit

Permalink
Fix disassembling of pointer-to-pointer types
Browse files Browse the repository at this point in the history
Fix disassembling of pointer-to-pointer types when used as operand of instruction
Issue: #147
  • Loading branch information
MSDN-WhiteKnight committed Mar 16, 2024
1 parent 8ea62d3 commit 67a67a7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,8 @@ public IEnumerable<SyntaxNode> GetDefinedTypeSyntax(Type t)

if (et != null)
{
IEnumerable<SyntaxNode> nodes;

if (et is TypeSpec) nodes = this.GetSignatureTypeSyntax(et);
else nodes = this.GetDefinedTypeSyntax(et);
//arrays are always in signature
IEnumerable<SyntaxNode> nodes = this.GetSignatureTypeSyntax(et);

foreach (SyntaxNode x in nodes) yield return x;
}
Expand All @@ -125,7 +123,8 @@ public IEnumerable<SyntaxNode> GetDefinedTypeSyntax(Type t)

if (et != null)
{
IEnumerable<SyntaxNode> nodes = this.GetDefinedTypeSyntax(et);
//pointers are always in signature
IEnumerable<SyntaxNode> nodes = this.GetSignatureTypeSyntax(et);
foreach (SyntaxNode x in nodes) yield return x;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class SyntaxGenerationTests
// Tests that verify disassembler output in different cases

[TestMethod]
[MethodTestData(typeof(SampleMethods), "TestArrayOfArrays", BytecodeProviders.Metadata)]
[MethodTestData(typeof(SampleMethods), "TestArrayOfArrays", BytecodeProviders.All)]
public void Test_Operand_ArrayOfArrays(MethodBase mi)
{
CilGraph graph = CilGraph.Create(mi);
Expand All @@ -27,5 +27,17 @@ public void Test_Operand_ArrayOfArrays(MethodBase mi)
Text.Any, "newarr", Text.Any, "uint8[]", Text.Any
});
}

[TestMethod]
[MethodTestData(typeof(SampleMethods), "TestPointerToPointer", BytecodeProviders.All)]
public void Test_Operand_PointerToPointer(MethodBase mi)
{
CilGraph graph = CilGraph.Create(mi);
string str = graph.ToText();

AssertThat.IsMatch(str, new Text[] {
Text.Any, "ldtoken", Text.Any, "int32**", Text.Any
});
}
}
}
5 changes: 5 additions & 0 deletions tests/CilTools.Tests.Common/TestData/SampleMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,11 @@ public static byte[][] TestArrayOfArrays()
{
return new byte[0][];
}

public static void TestPointerToPointer()
{
Console.Write(typeof(int**));
}
}

public class MyPoint
Expand Down

0 comments on commit 67a67a7

Please sign in to comment.