Browse Source

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 <tomi.valkeinen@iki.fi>
pull/251/head
Tomi Valkeinen 12 years ago
parent
commit
480a06f260
  1. 5
      build/premake4.lua
  2. 14
      src/Generator/Generators/CSharp/CSharpTextTemplate.cs
  3. 7
      src/Generator/Options.cs

5
build/premake4.lua

@ -30,9 +30,6 @@ solution "CppSharp" @@ -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" @@ -55,4 +52,4 @@ solution "CppSharp"
if string.starts(action, "vs") and os.is_windows() then
include (srcdir .. "/Parser/Parser.lua")
end
end

14
src/Generator/Generators/CSharp/CSharpTextTemplate.cs

@ -1404,14 +1404,14 @@ namespace CppSharp.Generators.CSharp @@ -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 @@ -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 @@ -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);

7
src/Generator/Options.cs

@ -44,11 +44,6 @@ namespace CppSharp @@ -44,11 +44,6 @@ namespace CppSharp
Encoding = Encoding.ASCII;
CodeFiles = new List<string>();
Is32Bit = true;
#if IS_64_BIT
Is32Bit = false;
#endif
}
// General options
@ -173,8 +168,6 @@ namespace CppSharp @@ -173,8 +168,6 @@ namespace CppSharp
get { return GeneratorKind == GeneratorKind.CLI; }
}
public bool Is32Bit { get; set; }
public List<string> CodeFiles { get; private set; }
public readonly List<string> DependentNameSpaces = new List<string>();
public bool MarshalCharAsManagedChar { get; set; }

Loading…
Cancel
Save