Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Can't get this to work, even though it finds the correct assembly, it refuses to discover the attribute classes.
<#@ assembly name="System.Runtime.Serialization"#>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="System.Runtime.Serialization"#>
<#@ import namespace="System.Runtime.Serialization.Json"#>
<#
var json = new DataContractJsonSerializer(typeof(SPIRVGrammar));
var file = File.Open("spirv.core.grammar.json", FileMode.Open);
var grammar = (SPIRVGrammar) json.ReadObject(file);
//Sanitize operand names
grammar.Instructions.ForEach(op =>
op.Operands?.ForEach(operand => operand.Name = operand.Name?.
Replace(" ", "").
Replace("'", "").
Replace(".", "").
Replace(",", "").
Replace("+", "").
Replace(">", "").
Replace("<", "").
Replace("\n", "").
Replace("~", "").
Replace("...", "").
Replace("ref", "")
));
//Sanitize names starting with numbers
grammar.OperandKinds.ForEach(kind =>
kind.Enumerants?.ForEach(e =>
e.Name = char.IsDigit(e.Name[0]) ? "_" + e.Name : e.Name));
#>
<#+
[DataContract]
private class SPIRVGrammar
{
[DataMember(Name = "instructions")]
public List<SPIRVOp> Instructions { get; set; }
[DataMember(Name = "operand_kinds")]
public List<SPIRVOperandKind> OperandKinds { get; set; }
}
[DataContract]
private class SPIRVOp
{
[DataMember(Name = "opname")]
public string OpName { get; set; }
[DataMember(Name = "opcode")]
public int OpCode { get; set; }
[DataMember(Name = "operands")]
public List<SPIRVOpKind> Operands { get; set; }
}
[DataContract]
private class SPIRVOpKind
{
[DataMember(Name = "kind")]
public string Kind { get; set; }
[DataMember(Name = "name")]
public string Name { get; set; }
[DataMember(Name = "quantifier")]
public string Quantifier { get; set; }
}
[DataContract]
private class SPIRVOperandKind
{
[DataMember(Name = "category")]
public string Category { get; set; }
[DataMember(Name = "kind")]
public string Name { get; set; }
[DataMember(Name = "bases")]
public List<string> Bases { get; set; }
[DataMember(Name = "enumerants")]
public List<SPIRVEnumerant> Enumerants { get; set; }
}
[DataContract]
private class SPIRVEnumerant
{
[DataMember(Name = "enumerant")]
public string Name { get; set; }
[DataMember(Name = "value")]
public string Value { get; set; }
}
#>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment