Browse Source

Added a new pass to check for ABI-specific parameters.

pull/1/head
triton 12 years ago
parent
commit
2a52c2e8b1
  1. 3
      src/Generator/Driver.cs
  2. 60
      src/Generator/Passes/CheckAbiParameters.cs

3
src/Generator/Driver.cs

@ -102,6 +102,9 @@ namespace Cxxi @@ -102,6 +102,9 @@ namespace Cxxi
passes.CheckTypeReferences();
passes.CheckFlagEnums();
if (Options.GeneratorKind == LanguageGeneratorKind.CSharp)
passes.CheckAbiParameters(Options);
if (Transform != null)
Transform.SetupPasses(this, passes);

60
src/Generator/Passes/CheckAbiParameters.cs

@ -0,0 +1,60 @@ @@ -0,0 +1,60 @@
namespace Cxxi.Passes
{
public class CheckAbiParameters : TranslationUnitPass
{
private readonly DriverOptions options;
public CheckAbiParameters(DriverOptions options)
{
this.options = options;
}
public override bool VisitMethodDecl(Method method)
{
if (!NeedsHiddenStructParameterReturn(method, options))
return true;
var structParameter = new Parameter()
{
Kind = ParameterKind.HiddenStructureReturn,
QualifiedType = new QualifiedType(
new BuiltinType(PrimitiveType.IntPtr)),
Name = "return",
IgnoreFlags = IgnoreFlags.Generation
};
method.Parameters.Insert(0, structParameter);
return true;
}
public static bool NeedsHiddenStructParameterReturn(Method method, DriverOptions options)
{
// In both the Microsoft and Itanium ABI, functions returning
// structure types by value have an extra parameter
// Itanium ABI reference (3.1.4 Return values):
// http://refspecs.linux-foundation.org/cxxabi-1.83.html#calls
// Microsoft ABI reference:
// http://blog.aaronballman.com/2012/02/describing-the-msvc-abi-for-structure-return-types/
Class retClass;
if (!method.ReturnType.IsTagDecl(out retClass))
return false;
// TODO: Add the various combinations for that need hidden parameter
var needsMSHiddenPtr = options.IsMicrosoftAbi && method.IsThisCall;
return needsMSHiddenPtr || options.IsItaniumAbi;
}
}
public static class CheckAbiParametersExtensions
{
public static void CheckAbiParameters(this PassBuilder builder,
DriverOptions options)
{
var pass = new CheckAbiParameters(options);
builder.AddPass(pass);
}
}
}
Loading…
Cancel
Save