mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-01-22 21:51:08 +00:00
Initial work on OpenCL binding generation.
This commit is contained in:
parent
a2ea5f719d
commit
65dc4140ab
122
Source/Bind/CL/CLGenerator.cs
Normal file
122
Source/Bind/CL/CLGenerator.cs
Normal file
|
@ -0,0 +1,122 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System.Xml;
|
||||
using System.Xml.XPath;
|
||||
using Bind.Structures;
|
||||
|
||||
namespace Bind.CL
|
||||
{
|
||||
class CLGenerator : Bind.GL2.Generator
|
||||
{
|
||||
public CLGenerator(string name)
|
||||
{
|
||||
if (String.IsNullOrEmpty(name))
|
||||
throw new ArgumentNullException("name");
|
||||
|
||||
glTypemap = "GL2/gl.tm";
|
||||
csTypemap = "csharp.tm";
|
||||
|
||||
enumSpec = name + "/signatures.xml";
|
||||
enumSpecExt = String.Empty;
|
||||
glSpec = name + "/signatures.xml";
|
||||
glSpecExt = String.Empty;
|
||||
functionOverridesFile = name + "/overrides.xml";
|
||||
|
||||
importsFile = "Core.cs";
|
||||
delegatesFile = "Delegates.cs";
|
||||
enumsFile = "Enums.cs";
|
||||
wrappersFile = "CL.cs";
|
||||
Settings.ImportsClass = "Core";
|
||||
Settings.DelegatesClass = "Delegates";
|
||||
|
||||
Settings.OutputClass = "CL";
|
||||
Settings.OutputNamespace = "OpenTK.Compute." + name;
|
||||
Settings.OutputPath = Path.Combine(Directory.GetParent(Settings.OutputPath).FullName, name);
|
||||
}
|
||||
|
||||
public override Bind.Structures.DelegateCollection ReadDelegates(System.IO.StreamReader specFile)
|
||||
{
|
||||
DelegateCollection delegates = new DelegateCollection();
|
||||
|
||||
XPathDocument overrides = new XPathDocument(new StreamReader(Path.Combine(Settings.InputPath, functionOverridesFile)));
|
||||
|
||||
XPathNavigator nav = new XPathDocument(specFile).CreateNavigator().SelectSingleNode("/signatures");
|
||||
|
||||
foreach (XPathNavigator node in nav.SelectChildren("function", String.Empty))
|
||||
{
|
||||
Bind.Structures.Delegate d = new Bind.Structures.Delegate();
|
||||
d.Name = node.GetAttribute("name", String.Empty);
|
||||
//d.Extension = node.GetAttribute("extension");
|
||||
d.Version = node.GetAttribute("version", String.Empty);
|
||||
d.Category = node.GetAttribute("category", String.Empty);
|
||||
foreach (XPathNavigator param in node.SelectChildren(XPathNodeType.Element))
|
||||
{
|
||||
switch (param.Name)
|
||||
{
|
||||
case "returns":
|
||||
d.ReturnType.CurrentType = param.GetAttribute("type", String.Empty);
|
||||
break;
|
||||
|
||||
case "param":
|
||||
Parameter p = new Parameter();
|
||||
p.CurrentType = param.GetAttribute("type", String.Empty);
|
||||
p.Name = param.GetAttribute("name", String.Empty);
|
||||
|
||||
string element_count = param.GetAttribute("elementcount", String.Empty);
|
||||
if (!String.IsNullOrEmpty(element_count))
|
||||
p.ElementCount = Int32.Parse(element_count);
|
||||
|
||||
p.Flow = Parameter.GetFlowDirection(param.GetAttribute("flow", String.Empty));
|
||||
|
||||
d.Parameters.Add(p);
|
||||
break;
|
||||
}
|
||||
}
|
||||
d.Translate(overrides);
|
||||
delegates.Add(d);
|
||||
}
|
||||
|
||||
return delegates;
|
||||
}
|
||||
|
||||
public override Dictionary<string, string> ReadTypeMap(StreamReader specFile)
|
||||
{
|
||||
return base.ReadTypeMap(specFile);
|
||||
}
|
||||
|
||||
public override Dictionary<string, string> ReadCSTypeMap(StreamReader specFile)
|
||||
{
|
||||
return base.ReadCSTypeMap(specFile);
|
||||
}
|
||||
|
||||
public override Bind.Structures.EnumCollection ReadEnums(StreamReader specFile)
|
||||
{
|
||||
EnumCollection enums = new EnumCollection();
|
||||
Bind.Structures.Enum all = new Bind.Structures.Enum(Settings.CompleteEnumName);
|
||||
XPathDocument doc = new XPathDocument(specFile);
|
||||
XPathNavigator nav = doc.CreateNavigator().SelectSingleNode("/signatures");
|
||||
|
||||
foreach (XPathNavigator node in nav.SelectChildren("enum", String.Empty))
|
||||
{
|
||||
Bind.Structures.Enum e = new Bind.Structures.Enum(node.GetAttribute("name", String.Empty));
|
||||
if (String.IsNullOrEmpty(e.Name))
|
||||
throw new InvalidOperationException(String.Format("Empty name for enum element {0}", node.ToString()));
|
||||
|
||||
foreach (XPathNavigator param in node.SelectChildren(XPathNodeType.Element))
|
||||
{
|
||||
Constant c = new Constant(param.GetAttribute("name", String.Empty), param.GetAttribute("value", String.Empty));
|
||||
Utilities.Merge(all, c);
|
||||
e.ConstantCollection.Add(c.Name, c);
|
||||
}
|
||||
|
||||
Utilities.Merge(enums, e);
|
||||
}
|
||||
|
||||
Utilities.Merge(enums, all);
|
||||
enums.Translate();
|
||||
return enums;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -24,9 +24,10 @@ namespace Bind
|
|||
ES10,
|
||||
ES11,
|
||||
ES20,
|
||||
Wgl,
|
||||
Glx,
|
||||
Glu,
|
||||
CL,
|
||||
[Obsolete] Wgl,
|
||||
[Obsolete] Glx,
|
||||
[Obsolete] Glu,
|
||||
}
|
||||
|
||||
static class MainClass
|
||||
|
@ -81,6 +82,8 @@ namespace Bind
|
|||
mode = GeneratorMode.ES11;
|
||||
else if (arg == "es20")
|
||||
mode = GeneratorMode.ES20;
|
||||
else if (arg == "cl10")
|
||||
mode = GeneratorMode.CL;
|
||||
else
|
||||
throw new NotImplementedException();
|
||||
break;
|
||||
|
@ -144,6 +147,10 @@ namespace Bind
|
|||
case GeneratorMode.ES20:
|
||||
Generator = new Bind.ES.ESGenerator("ES20");
|
||||
break;
|
||||
|
||||
case GeneratorMode.CL:
|
||||
Generator = new Bind.CL.CLGenerator("CL");
|
||||
break;
|
||||
|
||||
case GeneratorMode.Wgl:
|
||||
Generator = new Bind.Wgl.Generator();
|
||||
|
|
Loading…
Reference in a new issue