UNPKG

68kcounter

Version:
74 lines (73 loc) 2.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const syntax_1 = require("../syntax"); /** * Look up addressing mode of an operand string */ function operandMode(operand) { const match = addressingModePatterns.find((t) => t.exp.exec(operand)); return match ? match.type : syntax_1.AddressingModes.AbsL; } exports.default = operandMode; // Common regex components const dn = "(d[0-7])"; const an = "(a[0-7]|sp)"; const rn = "([ad][0-7]|sp)"; const pc = "pc"; const op = "\\(\\s*"; const cp = "\\s*\\)"; const comma = "\\s*,\\s*"; const idx = `${rn}(\\.(w|l))?`; /** * Regular expressions to identify operand type from text. */ const addressingModePatterns = [ { type: syntax_1.AddressingModes.Dn, exp: new RegExp(`^${dn}$`, "i") }, { type: syntax_1.AddressingModes.An, exp: new RegExp(`^${an}$`, "i") }, { type: syntax_1.AddressingModes.AnIndir, exp: new RegExp(`^${op + an + cp}$`, "i"), }, { type: syntax_1.AddressingModes.AnPostInc, // (An)+ exp: new RegExp(`^${op + an + cp}\\+$`, "i"), }, { type: syntax_1.AddressingModes.AnPreDec, // -(An) exp: new RegExp(`^-${op + an + cp}$`, "i"), }, { type: syntax_1.AddressingModes.AnDispIx, // An,Idx) exp: new RegExp(an + comma + idx + cp, "i"), }, { type: syntax_1.AddressingModes.AnDisp, exp: new RegExp( // d(An) | (d,An) `(\\w${op + an}|${op}[-\\w]+${comma + an + cp}$)`, "i"), }, { type: syntax_1.AddressingModes.PcDispIx, // PC,Idx) exp: new RegExp(pc + comma + idx + cp, "i"), }, { type: syntax_1.AddressingModes.PcDisp, exp: new RegExp( // d(PC) | (d,PC) `(\\w${op + pc}|${op}[-\\w]+${comma + pc + cp}$)`, "i"), }, { type: syntax_1.AddressingModes.Imm, exp: /^#./i }, { type: syntax_1.AddressingModes.RegList, // Rn[/-]Rn exp: new RegExp(`${rn}[\\/-]${rn}`, "i"), }, { type: syntax_1.AddressingModes.CCR, exp: /^ccr$/i }, { type: syntax_1.AddressingModes.SR, exp: /^sr$/i }, { type: syntax_1.AddressingModes.USP, exp: /^usp$/i }, { type: syntax_1.AddressingModes.AbsW, exp: /\.W$/i }, ];