diff options
Diffstat (limited to 'Spv.Generator')
| -rw-r--r-- | Spv.Generator/Instruction.cs | 15 | ||||
| -rw-r--r-- | Spv.Generator/InstructionOperands.cs | 19 | ||||
| -rw-r--r-- | Spv.Generator/LiteralInteger.cs | 2 | ||||
| -rw-r--r-- | Spv.Generator/LiteralString.cs | 2 |
4 files changed, 38 insertions, 0 deletions
diff --git a/Spv.Generator/Instruction.cs b/Spv.Generator/Instruction.cs index 27190f05..8ecfe683 100644 --- a/Spv.Generator/Instruction.cs +++ b/Spv.Generator/Instruction.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Diagnostics; using System.IO; @@ -228,5 +229,19 @@ namespace Spv.Generator { return obj is Instruction instruction && Equals(instruction); } + + private static readonly Dictionary<Specification.Op, string[]> _operandLabels = new() + { + { Specification.Op.OpConstant, new [] { "Value" } }, + { Specification.Op.OpTypeInt, new [] { "Width", "Signed" } }, + { Specification.Op.OpTypeFloat, new [] { "Width" } } + }; + + public override string ToString() + { + var labels = _operandLabels.TryGetValue(Opcode, out var opLabels) ? opLabels : Array.Empty<string>(); + var result = _resultType == null ? string.Empty : $"{_resultType} "; + return $"{result}{Opcode}{_operands.ToString(labels)}"; + } } } diff --git a/Spv.Generator/InstructionOperands.cs b/Spv.Generator/InstructionOperands.cs index a349827a..c48b004f 100644 --- a/Spv.Generator/InstructionOperands.cs +++ b/Spv.Generator/InstructionOperands.cs @@ -1,4 +1,6 @@ using System; +using System.Collections.Generic; +using System.Linq; using System.Runtime.InteropServices; namespace Spv.Generator @@ -49,5 +51,22 @@ namespace Spv.Generator Overflow[Count++] = operand; } } + + private IEnumerable<Operand> AllOperands => new[] { Operand1, Operand2, Operand3, Operand4, Operand5 } + .Concat(Overflow ?? Array.Empty<Operand>()) + .Take(Count); + + public override string ToString() + { + return $"({string.Join(", ", AllOperands)})"; + } + + public string ToString(string[] labels) + { + var labeledParams = AllOperands.Zip(labels, (op, label) => $"{label}: {op}"); + var unlabeledParams = AllOperands.Skip(labels.Length).Select(op => op.ToString()); + var paramsToPrint = labeledParams.Concat(unlabeledParams); + return $"({string.Join(", ", paramsToPrint)})"; + } } } diff --git a/Spv.Generator/LiteralInteger.cs b/Spv.Generator/LiteralInteger.cs index 3193ed6e..22cb5484 100644 --- a/Spv.Generator/LiteralInteger.cs +++ b/Spv.Generator/LiteralInteger.cs @@ -99,5 +99,7 @@ namespace Spv.Generator { return obj is LiteralInteger literalInteger && Equals(literalInteger); } + + public override string ToString() => $"{_integerType} {_data}"; } } diff --git a/Spv.Generator/LiteralString.cs b/Spv.Generator/LiteralString.cs index 4ed9e52b..629ff7bf 100644 --- a/Spv.Generator/LiteralString.cs +++ b/Spv.Generator/LiteralString.cs @@ -48,5 +48,7 @@ namespace Spv.Generator { return obj is LiteralString literalString && Equals(literalString); } + + public override string ToString() => _value; } } |
