Skip to content

Commit

Permalink
Add support for rem opcode
Browse files Browse the repository at this point in the history
  • Loading branch information
hazzik committed Aug 24, 2013
1 parent e0ac979 commit f678998
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
3 changes: 3 additions & 0 deletions DelegateDecompiler.sln.DotSettings
@@ -0,0 +1,3 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateConstants/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateInstanceFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String></wpf:ResourceDictionary>
8 changes: 8 additions & 0 deletions src/DelegateDecompiler.Tests/DecompileExtensionsTests.cs
Expand Up @@ -23,6 +23,14 @@ public void ShouldBeAbleToDecompileExpressionWithAdd()
Test(expected, compiled);
}

[Fact]
public void ShouldBeAbleToDecompileExpressionWithRem()
{
Expression<Func<int, int, int>> expected = (x, y) => x % y;
Func<int, int, int> compiled = (x, y) => x % y;
Test(expected, compiled);
}

[Fact]
public void ShouldBeAbleToDecompileExpressionWithAddConstant()
{
Expand Down
14 changes: 11 additions & 3 deletions src/DelegateDecompiler/Processor.cs
Expand Up @@ -84,7 +84,7 @@ public Expression Process(Instruction instruction, Instruction last = null)
{
LdArg((int) instruction.Operand);
}
else if (instruction.OpCode == OpCodes.Ldarga_S || instruction.OpCode == OpCodes.Ldarga)
else if (instruction.OpCode == OpCodes.Ldarga || instruction.OpCode == OpCodes.Ldarga_S)
{
var operand = (ParameterInfo) instruction.Operand;
stack.Push(args.Single(x => x.Name == operand.Name));
Expand Down Expand Up @@ -245,12 +245,14 @@ public Expression Process(Instruction instruction, Instruction last = null)
instruction = (Instruction) instruction.Operand;
continue;
}
else if (instruction.OpCode == OpCodes.Brfalse_S || instruction.OpCode == OpCodes.Brfalse)
else if (instruction.OpCode == OpCodes.Brfalse ||
instruction.OpCode == OpCodes.Brfalse_S)
{
instruction = ConditionalBranch(instruction, val => Expression.Equal(val, Default(val.Type)));
continue;
}
else if (instruction.OpCode == OpCodes.Brtrue || instruction.OpCode == OpCodes.Brtrue_S)
else if (instruction.OpCode == OpCodes.Brtrue ||
instruction.OpCode == OpCodes.Brtrue_S)
{
var target = ((Instruction)instruction.Operand);

Expand Down Expand Up @@ -366,6 +368,12 @@ public Expression Process(Instruction instruction, Instruction last = null)
var val2 = stack.Pop();
stack.Push(Expression.Divide(val2, val1));
}
else if (instruction.OpCode == OpCodes.Rem || instruction.OpCode == OpCodes.Rem_Un)
{
var val1 = stack.Pop();
var val2 = stack.Pop();
stack.Push(Expression.Modulo(val2, val1));
}
else if (instruction.OpCode == OpCodes.Conv_I)
{
var val1 = stack.Pop();
Expand Down

0 comments on commit f678998

Please sign in to comment.