From 480a06f26058030f671f74ced6bdc22d5f002bef Mon Sep 17 00:00:00 2001 From: Tomi Valkeinen Date: Tue, 13 May 2014 14:41:29 +0300 Subject: [PATCH] Generator: Remove DriverOptions.Is32Bit DriverOptions.Is32Bit is used to decide whether to use 4 or 8 byte pointer size in VTable calculations. Instead of having a settable Is32Bit property, use TargetInfo.PointerWidth for this. This allows us to remove the whole Is32Bit property, and the IS_64_BIT define. Signed-off-by: Tomi Valkeinen --- build/premake4.lua | 5 +---- .../Generators/CSharp/CSharpTextTemplate.cs | 14 +++++++------- src/Generator/Options.cs | 7 ------- 3 files changed, 8 insertions(+), 18 deletions(-) diff --git a/build/premake4.lua b/build/premake4.lua index 20f70cf4..6d30be19 100644 --- a/build/premake4.lua +++ b/build/premake4.lua @@ -30,9 +30,6 @@ solution "CppSharp" configuration "windows" defines { "WINDOWS" } - configuration "x64" - defines { "IS_64_BIT" } - configuration {} if string.starts(action, "vs") then @@ -55,4 +52,4 @@ solution "CppSharp" if string.starts(action, "vs") and os.is_windows() then include (srcdir .. "/Parser/Parser.lua") - end \ No newline at end of file + end diff --git a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs index f97d191a..c357463e 100644 --- a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs +++ b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs @@ -1404,14 +1404,14 @@ namespace CppSharp.Generators.CSharp var vfptr = @class.Layout.VFTables[tableIndex]; var size = vfptr.Layout.Components.Count; WriteLine("var vfptr{0} = Marshal.AllocHGlobal({1} * {2});", - tableIndex, size, Driver.Options.Is32Bit ? 4 : 8); + tableIndex, size, Driver.TargetInfo.PointerWidth / 8); WriteLine("_NewVTables[{0}] = vfptr{0}.ToPointer();", tableIndex); for (int entryIndex = 0; entryIndex < vfptr.Layout.Components.Count; entryIndex++) { var entry = vfptr.Layout.Components[entryIndex]; var offsetInBytes = VTables.GetVTableComponentIndex(@class, entry) - * (Driver.Options.Is32Bit ? 4 : 8); + * (Driver.TargetInfo.PointerWidth / 8); if (entry.Ignore) WriteLine("*(void**)(vfptr{0} + {1}) = *(void**)(native->vfptr{0} + {1});", tableIndex, offsetInBytes); @@ -1434,14 +1434,14 @@ namespace CppSharp.Generators.CSharp // reserve space for the offset-to-top and RTTI pointers as well var size = entries.Count; - WriteLine("var vfptr{0} = Marshal.AllocHGlobal({1} * {2});", 0, size, Driver.Options.Is32Bit ? 4 : 8); + WriteLine("var vfptr{0} = Marshal.AllocHGlobal({1} * {2});", 0, size, Driver.TargetInfo.PointerWidth / 8); WriteLine("_NewVTables[0] = vfptr0.ToPointer();"); for (int i = 0; i < entries.Count; i++) { var entry = entries[i]; var offsetInBytes = VTables.GetVTableComponentIndex(@class, entry) - * (Driver.Options.Is32Bit ? 4 : 8); + * (Driver.TargetInfo.PointerWidth / 8); if (entry.Ignore) WriteLine("*(void**)(vfptr0 + {0}) = *(void**)(native->vfptr0 + {0});", offsetInBytes); else @@ -2104,17 +2104,17 @@ namespace CppSharp.Generators.CSharp private void GenerateVirtualTableFunctionCall(Method method, Class @class) { string delegateId; - Write(GetVirtualCallDelegate(method, @class, Driver.Options.Is32Bit, out delegateId)); + Write(GetVirtualCallDelegate(method, @class, out delegateId)); GenerateFunctionCall(delegateId, method.Parameters, method); } public string GetVirtualCallDelegate(Method method, Class @class, - bool is32Bit, out string delegateId) + out string delegateId) { var virtualCallBuilder = new StringBuilder(); var i = VTables.GetVTableIndex(method, @class); virtualCallBuilder.AppendFormat("void* slot = *(void**) ((({0}.Internal*) {1})->vfptr0 + {2} * {3});", - @class.BaseClass.Name, Helpers.InstanceIdentifier, i, is32Bit ? 4 : 8); + @class.BaseClass.Name, Helpers.InstanceIdentifier, i, Driver.TargetInfo.PointerWidth / 8); virtualCallBuilder.AppendLine(); string @delegate = GetVTableMethodDelegateName((Method) method.OriginalFunction); diff --git a/src/Generator/Options.cs b/src/Generator/Options.cs index c1a1d93a..3f1d617f 100644 --- a/src/Generator/Options.cs +++ b/src/Generator/Options.cs @@ -44,11 +44,6 @@ namespace CppSharp Encoding = Encoding.ASCII; CodeFiles = new List(); - - Is32Bit = true; -#if IS_64_BIT - Is32Bit = false; -#endif } // General options @@ -173,8 +168,6 @@ namespace CppSharp get { return GeneratorKind == GeneratorKind.CLI; } } - public bool Is32Bit { get; set; } - public List CodeFiles { get; private set; } public readonly List DependentNameSpaces = new List(); public bool MarshalCharAsManagedChar { get; set; }