IAsmInstructionArg[] ParseInstructionArgs(string raw) { string[] tokens = raw.Split(InstructionArgsSeparator, StringSplitOptions.RemoveEmptyEntries); IAsmInstructionArg[] args = new IAsmInstructionArg[tokens.Length]; for (int i = 0; i < tokens.Length; ++i) { string token = tokens[i]; if (token.Contains("[")) { // It must be indirect addressing argument. args[i] = new AsmInstructionIndirectAddressArg() { Unparsed = token }; } else { // Either register, constant or label. if (long.TryParse(token, out long value)) { args[i] = new AsmInstructionConstantArg() { Value = value }; } else { // Either register or label. if (token.IndexOf(' ') != -1) { string[] split = token.Split(' '); args[i] = new AsmInstructionLabelArg() { Prefix = split[0], Name = split[1] }; } else { args[i] = new AsmInstructionRegisterArg() { Name = token }; } } } } return(args); }
Run CreateInstructionArg(IAsmInstructionArg arg) { Run run = null; switch (arg.Type) { case InstructionArgType.Constant: { AsmInstructionConstantArg constant = (AsmInstructionConstantArg)arg; run = new Run(constant.Value.ToString()) { Foreground = ConstantForeground }; break; } case InstructionArgType.IndirectAddress: { AsmInstructionIndirectAddressArg indirect = (AsmInstructionIndirectAddressArg)arg; run = new Run(indirect.Unparsed) { Foreground = IndirectForeground }; break; } case InstructionArgType.Register: { AsmInstructionRegisterArg register = (AsmInstructionRegisterArg)arg; run = new Run(register.Name) { Foreground = RegisterForeground }; break; } case InstructionArgType.Label: { AsmInstructionLabelArg label = (AsmInstructionLabelArg)arg; run = new Run(label.Prefix + " " + label.Name) { Foreground = LabelArgForeground }; break; } } return(run); }