summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Build.Tasks
diff options
context:
space:
mode:
authorStephane Delcroix <stephane@delcroix.org>2016-12-12 10:57:01 +0100
committerGitHub <noreply@github.com>2016-12-12 10:57:01 +0100
commit22bdca32339838702920802e49465264fcccd48b (patch)
treed4379b92dd8f59ca18a47f6ea5a3276535150686 /Xamarin.Forms.Build.Tasks
parentf0ea0fa4bf86c7b641d0ddc3c734a5b7971c90f7 (diff)
downloadxamarin-forms-22bdca32339838702920802e49465264fcccd48b.tar.gz
xamarin-forms-22bdca32339838702920802e49465264fcccd48b.tar.bz2
xamarin-forms-22bdca32339838702920802e49465264fcccd48b.zip
[XamlC] fix loading ulongs, optimize bytecode for ulongs (#611)
Diffstat (limited to 'Xamarin.Forms.Build.Tasks')
-rw-r--r--Xamarin.Forms.Build.Tasks/NodeILExtensions.cs4
-rw-r--r--Xamarin.Forms.Build.Tasks/XamlCTask.cs23
2 files changed, 25 insertions, 2 deletions
diff --git a/Xamarin.Forms.Build.Tasks/NodeILExtensions.cs b/Xamarin.Forms.Build.Tasks/NodeILExtensions.cs
index 0c9b9e6b..ec068797 100644
--- a/Xamarin.Forms.Build.Tasks/NodeILExtensions.cs
+++ b/Xamarin.Forms.Build.Tasks/NodeILExtensions.cs
@@ -128,11 +128,11 @@ namespace Xamarin.Forms.Build.Tasks
else if (targetTypeRef.FullName == "System.Byte")
yield return Instruction.Create(OpCodes.Ldc_I4, Byte.Parse(str, CultureInfo.InvariantCulture));
else if (targetTypeRef.FullName == "System.UInt16")
- yield return Instruction.Create(OpCodes.Ldc_I4, UInt16.Parse(str, CultureInfo.InvariantCulture));
+ yield return Instruction.Create(OpCodes.Ldc_I4, unchecked((int)UInt16.Parse(str, CultureInfo.InvariantCulture)));
else if (targetTypeRef.FullName == "System.UInt32")
yield return Instruction.Create(OpCodes.Ldc_I4, UInt32.Parse(str, CultureInfo.InvariantCulture));
else if (targetTypeRef.FullName == "System.UInt64")
- yield return Instruction.Create(OpCodes.Ldc_I8, UInt64.Parse(str, CultureInfo.InvariantCulture));
+ yield return Instruction.Create(OpCodes.Ldc_I8, unchecked((long)UInt64.Parse(str, CultureInfo.InvariantCulture)));
else if (targetTypeRef.FullName == "System.Single")
yield return Instruction.Create(OpCodes.Ldc_R4, Single.Parse(str, CultureInfo.InvariantCulture));
else if (targetTypeRef.FullName == "System.Double")
diff --git a/Xamarin.Forms.Build.Tasks/XamlCTask.cs b/Xamarin.Forms.Build.Tasks/XamlCTask.cs
index eda44a9a..5127efda 100644
--- a/Xamarin.Forms.Build.Tasks/XamlCTask.cs
+++ b/Xamarin.Forms.Build.Tasks/XamlCTask.cs
@@ -185,6 +185,7 @@ namespace Xamarin.Forms.Build.Tasks
if (OptimizeIL)
{
Logger.LogString(2, " Optimizing IL... ");
+ OptimizeLongs(initComp.Body);
initComp.Body.OptimizeMacros();
Logger.LogLine(2, "done");
}
@@ -236,6 +237,28 @@ namespace Xamarin.Forms.Build.Tasks
return success;
}
+ static void ExpandMacro(Instruction instruction, OpCode opcode, object operand)
+ {
+ instruction.OpCode = opcode;
+ instruction.Operand = operand;
+ }
+
+ //this can be removed if/when https://github.com/jbevain/cecil/pull/307 is released in a nuget we consume
+ static void OptimizeLongs(MethodBody self)
+ {
+ var method = self.Method;
+ for (var i = 0; i < self.Instructions.Count; i++) {
+ var instruction = self.Instructions[i];
+ if (instruction.OpCode.Code != Code.Ldc_I8)
+ continue;
+ var l = (long)instruction.Operand;
+ if (l < int.MinValue || l > int.MaxValue)
+ continue;
+ ExpandMacro(instruction, OpCodes.Ldc_I4, unchecked((int)l));
+ self.Instructions.Insert(++i, Instruction.Create(OpCodes.Conv_I8));
+ }
+ }
+
bool TryCoreCompile(MethodDefinition initComp, MethodDefinition initCompRuntime, ILRootNode rootnode, out Exception exception)
{
try {