Permalink
Browse files

Don't assume all short inline branch targets are the same opcode.

  • Loading branch information...
1 parent 9902de7 commit a4ff409341651f5a1b4c637fa9e09de1c84084a3 @polyethene committed Nov 20, 2011
Showing with 17 additions and 1 deletion.
  1. +17 −1 Scripting/Compiler/Bundling/CopyBody.cs
View
18 Scripting/Compiler/Bundling/CopyBody.cs
@@ -186,7 +186,23 @@ void CopyOpcode(byte[] Bytes, ref int i, ILGenerator Gen, Module Origin, List<in
if(!LabelOrigins.ContainsKey(i))
throw new Exception("No label origin found for RVA "+i.ToString("X"));
- Code = OpCodes.Br;
+ // messy fix to convert short branch targets to normal ones, since there's no easy way to calculate offsets via reflection
+ const string s = ".s";
+ string name = Code.Name;
+ if (name.EndsWith(s))
+ {
+ name = name.Substring(0, name.Length - s.Length);
+ foreach (var field in typeof(OpCodes).GetFields(BindingFlags.Public | BindingFlags.Static))
+ {
+ var opcode = (OpCode)field.GetValue(null);
+ if (opcode.Name.Equals(name))
+ {
+ Code = opcode;
+ break;
+ }
+ }
+ }
+
Gen.Emit(Code, LabelOrigins[i][0]);
i++;

0 comments on commit a4ff409

Please sign in to comment.