ProcDecoder Refactor Redux#2651
Conversation
| } | ||
| case ProcOperandShape.RepeatedString: { | ||
| string[] values = operand0.Strings!; | ||
| for (int i = 0; i < values.Length; i++) { |
There was a problem hiding this comment.
I don't see why you wouldn't use a foreach here, though I'd be fine with disabling the inspection if others don't like it.
| } | ||
| case ProcOperandShape.RepeatedResource: { | ||
| string[] values = operand0.Strings!; | ||
| for (int i = 0; i < values.Length; i++) { |
| } | ||
| case ProcOperandShape.RepeatedReference: { | ||
| DMReference[] values = operand0.References!; | ||
| for (int i = 0; i < values.Length; i++) { |
| /// <summary> | ||
| /// Stringifies a <see cref="ProcInstruction"/> and its operands | ||
| /// </summary> | ||
| public static string Format(ProcInstruction instruction, Func<int, string> getTypePath) { |
There was a problem hiding this comment.
Can't the caller call Format() on the instruction directly?
| return instruction.Format(getTypePath); | ||
| } | ||
|
|
||
| public static int? GetJumpDestination(ProcInstruction instruction) { |
| ProcOperand operand0 = default, | ||
| ProcOperand operand1 = default, | ||
| ProcOperand operand2 = default, | ||
| ProcOperand operand3 = default) { |
There was a problem hiding this comment.
Could this be an array instead? I don't like how you have to write out behavior for every possible argument length.
| opcodesBytes.AddRange(BitConverter.GetBytes(metadata.StackDelta)); | ||
| opcodesBytes.Add((byte)(metadata.VariableArgs ? 1 : 0)); | ||
| AddArgTypes(opcodesBytes, metadata.RequiredArgs); | ||
| AddArgTypes(opcodesBytes, metadata.RepeatedArgs); |
There was a problem hiding this comment.
I would rather override OpcodeMetadata.GetHashCode() and use that here, so that it's clearer that this needs updated if the metadata's fields change.
| using System.Text; | ||
| using DMCompiler.DM; | ||
|
|
||
| // ReSharper disable UnusedMember.Global |
There was a problem hiding this comment.
Is this doing anything? Removing it isn't showing me any new warnings.
| foreach (var t in values) | ||
| { |
There was a problem hiding this comment.
| foreach (var t in values) | |
| { | |
| foreach (var t in values) { |
| } | ||
| case ProcOperandShape.RepeatedString: { | ||
| string[] values = operand0.Strings!; | ||
| for (int i = 0; i < values.Length; i++) { |
There was a problem hiding this comment.
I don't see why you wouldn't use a foreach here, though I'd be fine with disabling the inspection if others don't like it.
This PR has a few main changes:
ProcDecoderwas moved from the runtime to the compiler.DMDisassemblernow depends on the compiler instead of the runtime.ITupleis now aProcInstructioncomprised ofProcOperands that store the argument values.Format()andDecodeInstruction()now utilize opcode metadata to figure out how to handle each opcode rather than using user-definedswitch()cases for each opcode.Most of that handling diverges depending on whether the opcode has a fixed-length argument count or a variable-length argument count (
N-variant opcodes). There's also a fair bit of code repetition for the tradeoff of not having to do a ton of typechecking on what types the arguments actually are.Tested with DM disassembly of /tg/station before and after this PR. Didn't see any non-whitespace diffs.
See my first comment below as well.