public static string GetNodeType(SpirvOperand operand) { if (!string.IsNullOrWhiteSpace(operand.OperandType)) { return(operand.OperandType.Substring(2)); } return("Node"); }
public static string CastNodeType(SpirvOperand operand) { var t = GetNodeType(operand); if (t == "Node") { return(""); } return("(" + t + ")"); }
private string GetOperandName(Instruction instruction, SpirvOperand spirvOperand) { string name; if (spirvOperand.SpirvName == null) { name = spirvOperand.Kind.ToString(); if (name == instruction.opname.Substring(2)) { return("Value"); } return(name); } name = spirvOperand.SpirvName; name = name.Trim('\'').Trim('.'); if (name.StartsWith("id> ")) { name = name.Substring("id> ".Length); } name = name.Replace(" ", ""); name = name.Replace("<<Invocation,invocations>>", "Invocations"); name = name.Replace("-", ""); name = name.Replace(",", ""); name = name.Replace("~ref~", "_ref"); { var collectionIndex = name.IndexOf("0\'"); if (collectionIndex > 0) { name = name.Substring(0, collectionIndex) + "s"; } } { var collectionIndex = name.IndexOf("1\'"); if (collectionIndex > 0) { name = name.Substring(0, collectionIndex) + "s"; } } { var collectionIndex = name.IndexOf("0Type\'", StringComparison.InvariantCultureIgnoreCase); if (collectionIndex > 0) { name = name.Substring(0, collectionIndex) + "Types"; } } if (name == instruction.opname.Substring(2)) { return("Value"); } return(name); }
private static string GetBasePropertyType(SpirvOperand op) { switch (op.Category) { case SpirvOperandCategory.Id: return("uint"); case SpirvOperandCategory.BitEnum: case SpirvOperandCategory.ValueEnum: return("Spv." + op.Kind); case SpirvOperandCategory.Composite: switch (op.Kind) { case SpirvOperandKind.PairIdRefLiteralInteger: return("Spv.PairIdRefLiteralInteger"); case SpirvOperandKind.PairIdRefIdRef: return("Spv.PairIdRefIdRef"); case SpirvOperandKind.PairLiteralIntegerIdRef: return("Spv.PairLiteralIntegerIdRef"); } return("object"); case SpirvOperandCategory.Literal: if (op.Kind == SpirvOperandKind.LiteralExtInstInteger) { return("uint"); } if (op.Kind == SpirvOperandKind.LiteralSpecConstantOpInteger) { return("NestedNode"); } if (op.Kind == SpirvOperandKind.LiteralInteger) { return("uint"); } if (op.Kind == SpirvOperandKind.LiteralString) { return("string"); } if (op.Kind == SpirvOperandKind.LiteralContextDependentNumber) { return("Spv." + op.Kind); } break; } return("object"); }
public static string GetOperandParser(SpirvOperand operand) { if (operand.Kind == SpirvOperandKind.LiteralContextDependentNumber) { return("Spv." + operand.Kind + ".ParseOptional(reader, end-reader.Position, IdResultType.Instruction)"); } if (operand.Quantifier == SpirvOperandQuantifier.Optional) { return("Spv." + operand.Kind + ".ParseOptional(reader, end-reader.Position)"); } if (operand.Quantifier == SpirvOperandQuantifier.Repeated) { return("Spv." + operand.Kind + ".ParseCollection(reader, end-reader.Position)"); } return("Spv." + operand.Kind + ".Parse(reader, end-reader.Position)"); }
private SpirvOperand CreateOperand(Instruction instruction, Operand operand) { var spirvOperandKind = GetKind(operand.kind); var spirvOperand = new SpirvOperand() { Kind = spirvOperandKind, SpirvName = operand.name, Quantifier = GetQuantifier(operand.quantifier), Category = _operandKindCategories[spirvOperandKind] }; var name = GetOperandName(instruction, spirvOperand); spirvOperand.Name = name; SetOperandClass(instruction, spirvOperand); return(spirvOperand); }
private KeyValuePair <string, string> MakeOperandKeyValue(SpirvOperand op) { switch (op.Class) { case SpirvOperandClassification.Type: return(new KeyValuePair <string, string>(op.Name, "SpirvTypeBase")); case SpirvOperandClassification.Exit: case SpirvOperandClassification.Input: return(new KeyValuePair <string, string>(op.Name, GetNodeType(op))); case SpirvOperandClassification.RepeatedInput: return(new KeyValuePair <string, string>(op.Name, $"IEnumerable<{GetNodeType(op)}>")); default: return(new KeyValuePair <string, string>(op.Name, GetPropertyType(op))); } }
public static string GetOperandType(SpirvOperand operand) { var type = ViewUtils.GetTypeName(operand.Kind); if (operand.Quantifier == SpirvOperandQuantifier.Optional) { if (type == "uint") { return("uint?"); } return(type); } if (operand.Quantifier == SpirvOperandQuantifier.Repeated) { return("IList<" + type + ">"); } return(type); }
public static string GetPropertyType(SpirvOperand op) { var baseType = GetBasePropertyType(op); switch (baseType) { case "Spv.LiteralContextDependentNumber": baseType = "Operands.NumberLiteral"; break; case "Spv.PairLiteralIntegerIdRef": baseType = "Operands.PairLiteralIntegerNode"; break; case "Spv.PairIdRefLiteralInteger": baseType = "Operands.PairNodeLiteralInteger"; break; case "Spv.PairIdRefIdRef": baseType = "Operands.PairNodeNode"; break; } switch (op.Quantifier) { case SpirvOperandQuantifier.Required: return(baseType); case SpirvOperandQuantifier.Optional: if (baseType == "uint") { return("uint?"); } return(baseType); case SpirvOperandQuantifier.Repeated: return("IList<" + baseType + ">"); default: throw new ArgumentOutOfRangeException(); } }
private void SetOperandClass(Instruction instruction, SpirvOperand spirvOperand) { if (spirvOperand.Kind == SpirvOperandKind.IdRef) { switch (instruction.opname) { case "OpEntryPoint": if (spirvOperand.Name == "Value") { spirvOperand.Class = SpirvOperandClassification.Exit; spirvOperand.OperandType = "OpFunction"; return; } break; case "OpFunction": if (spirvOperand.Name == "FunctionType") { spirvOperand.Class = SpirvOperandClassification.Type; return; } break; case "OpFunctionCall": if (spirvOperand.Name == "Function") { spirvOperand.Class = SpirvOperandClassification.Input; spirvOperand.OperandType = "OpFunction"; return; } break; case "OpSelectionMerge": if (spirvOperand.Name == "MergeBlock") { spirvOperand.Class = SpirvOperandClassification.Exit; spirvOperand.OperandType = "OpLabel"; return; } break; case "OpLoopMerge": if (spirvOperand.Name == "MergeBlock") { spirvOperand.Class = SpirvOperandClassification.Exit; spirvOperand.OperandType = "OpLabel"; return; } if (spirvOperand.Name == "ContinueTarget") { spirvOperand.Class = SpirvOperandClassification.Exit; spirvOperand.OperandType = "OpLabel"; return; } break; case "OpBranchConditional": if (spirvOperand.Name == "TrueLabel") { spirvOperand.Class = SpirvOperandClassification.Exit; spirvOperand.OperandType = "OpLabel"; return; } if (spirvOperand.Name == "FalseLabel") { spirvOperand.Class = SpirvOperandClassification.Exit; spirvOperand.OperandType = "OpLabel"; return; } break; case "OpBranch": if (spirvOperand.Name == "TargetLabel") { spirvOperand.Class = SpirvOperandClassification.Exit; spirvOperand.OperandType = "OpLabel"; return; } break; case "OpMemberName": if (spirvOperand.Name == "Type") { spirvOperand.Class = SpirvOperandClassification.Type; return; } break; case "OpMemberDecorate": if (spirvOperand.Name == "StructureType") { spirvOperand.Class = SpirvOperandClassification.Type; return; } break; case "OpDecorate": case "OpDecorateId": case "OpDecorateString": if (spirvOperand.Name == "Target") { spirvOperand.Class = SpirvOperandClassification.Exit; spirvOperand.OperandType = "OpNode"; return; } break; case "OpTypeForwardPointer": if (spirvOperand.Name == "PointerType") { spirvOperand.Class = SpirvOperandClassification.Type; return; } break; case "OpTypePointer": if (spirvOperand.Name == "Type") { spirvOperand.Class = SpirvOperandClassification.Type; return; } break; case "OpTypeImage": if (spirvOperand.Name == "SampledType") { spirvOperand.Class = SpirvOperandClassification.Type; return; } break; case "OpTypeRuntimeArray": if (spirvOperand.Name == "ElementType") { spirvOperand.Class = SpirvOperandClassification.Type; return; } break; case "OpTypeSampledImage": if (spirvOperand.Name == "ImageType") { spirvOperand.Class = SpirvOperandClassification.Type; return; } break; case "OpSwitch": if (spirvOperand.Name == "Default") { spirvOperand.Class = SpirvOperandClassification.Exit; return; } break; } if (spirvOperand.Quantifier == SpirvOperandQuantifier.Repeated) { spirvOperand.Class = SpirvOperandClassification.RepeatedInput; } else { spirvOperand.Class = SpirvOperandClassification.Input; } return; } spirvOperand.Class = SpirvOperandClassification.Other; //switch (spirvOperand.Category) //{ // case SpirvOperandCategory.BitEnum: // case SpirvOperandCategory.ValueEnum: // spirvOperand.OperandType = spirvOperand.Category + ".Enumerant"; // break; // default: // break; //} spirvOperand.Class = SpirvOperandClassification.Other; }