forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Label support in new ILGenerator (dotnet#93565)
* Emit Label/Branching IL * Throw when OpCode is not Switch Co-authored-by: Jan Kotas <[email protected]> * Add protected factory to ILGenerator instead of making the Label constructor public * Update test to assert label.Id instead of label.GetHashCode --------- Co-authored-by: Jan Kotas <[email protected]>
- Loading branch information
Showing
8 changed files
with
225 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/libraries/System.Reflection.Emit.ILGeneration/tests/Label/LabelId.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Xunit; | ||
|
||
namespace System.Reflection.Emit.Tests | ||
{ | ||
public class LabelId | ||
{ | ||
[Fact] | ||
public void LabelId_DefaultConstuctor_ReturnsZero() | ||
{ | ||
Label label1 = new Label(); | ||
Label label2 = new Label(); | ||
|
||
Assert.Equal(0, label1.Id); | ||
Assert.Equal(label2.Id, label1.Id); | ||
} | ||
|
||
[Fact] | ||
public void LabelId_CreatedByILGenerator_ReturnsId() | ||
{ | ||
TypeBuilder type = Helpers.DynamicType(TypeAttributes.NotPublic); | ||
MethodBuilder method = type.DefineMethod("Method", MethodAttributes.Public); | ||
ILGenerator ilGenerator = method.GetILGenerator(); | ||
for (int i = 0; i < 100; i++) | ||
{ | ||
Label label = ilGenerator.DefineLabel(); | ||
Assert.Equal(i, label.Id); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters