@exercism/codemirror-lang-assembly 0.0.0-stage → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,1914 @@
1
+ import { ExternalTokenizer, LRParser } from '@lezer/lr';
2
+ import { LRLanguage, foldNodeProp, foldInside, LanguageSupport, syntaxTree, foldService, indentService, getIndentUnit } from '@codemirror/language';
3
+ import { styleTags, tags } from '@lezer/highlight';
4
+ import { completeFromList, snippetCompletion } from '@codemirror/autocomplete';
5
+
6
+ // This file was generated by lezer-generator. You probably shouldn't edit it.
7
+ const RawString = 1,
8
+ BlockOpen = 2,
9
+ BraceOpen = 3,
10
+ Mnemonic = 4,
11
+ DirectiveName = 5,
12
+ MacroName = 6,
13
+ Label = 7,
14
+ Register = 8,
15
+ SizeKeyword = 9,
16
+ Identifier = 10,
17
+ Number = 11,
18
+ ImmediatePrefix = 12,
19
+ Here = 13,
20
+ Star = 14,
21
+ Slash = 15,
22
+ Percent = 16,
23
+ StatementComment = 17,
24
+ AssignOp = 18,
25
+ Equals = 19,
26
+ OperandDirective = 20,
27
+ MacroParameter = 21,
28
+ Dialect_x86 = 0,
29
+ Dialect_arm64 = 1,
30
+ Dialect_mips = 2;
31
+
32
+ function wordSet(from) {
33
+ return new Set(from.split(/\s+/).filter(Boolean));
34
+ }
35
+ function numbered(prefixes, from, to) {
36
+ const out = [];
37
+ for (const prefix of prefixes.split(" ")) {
38
+ for (let index = from; index <= to; index++)
39
+ out.push(prefix + index);
40
+ }
41
+ return out.join(" ");
42
+ }
43
+
44
+ /** The data directives, which NASM also accepts after `times` and `at`. */
45
+ const DATA_DIRECTIVES = /*@__PURE__*/wordSet(`
46
+ db dw dd dq dt do dy dz
47
+ resb resw resd resq rest reso resy resz
48
+ `);
49
+ /** NASM's own directives, written without a `%` in front. */
50
+ const DIRECTIVES$3 = /*@__PURE__*/wordSet(`
51
+ ${/*@__PURE__*/[...DATA_DIRECTIVES].join(" ")}
52
+ equ times incbin
53
+ section segment global extern common static required
54
+ default bits use16 use32 use64 cpu float org absolute
55
+ align alignb sectalign
56
+ struc endstruc istruc at iend
57
+ `);
58
+ /** The section names that a Linux program uses. */
59
+ const SECTIONS$1 = /*@__PURE__*/wordSet(`.text .data .bss .rodata .note.GNU-stack`);
60
+ /** NASM's preprocessor directives. */
61
+ const PREPROCESSOR = /*@__PURE__*/wordSet(`
62
+ %define %xdefine %idefine %ixdefine %undef %defstr %deftok %defalias
63
+ %assign %iassign %strcat %strlen %substr
64
+ %macro %imacro %endmacro %unmacro %rotate %exitmacro
65
+ %rep %endrep %exitrep
66
+ %if %ifn %elif %elifn %else %endif
67
+ %ifdef %ifndef %elifdef %elifndef
68
+ %ifidn %ifidni %ifnidn %ifnidni %elifidn %elifidni
69
+ %ifmacro %ifnmacro %ifnum %ifstr %ifid %iftoken %ifempty %ifenv %ifctx
70
+ %include %pathsearch %depend %use
71
+ %push %pop %repl %arg %stacksize %local
72
+ %error %warning %fatal %line %pragma %clear
73
+ `);
74
+ const REGISTERS$3 = /*@__PURE__*/wordSet(`
75
+ rax rbx rcx rdx rsi rdi rbp rsp ${/*@__PURE__*/numbered("r", 8, 15)} rip
76
+ eax ebx ecx edx esi edi ebp esp ${/*@__PURE__*/numbered("r", 8, 15).replace(/(\d+)/g, "$1d")} eip
77
+ ax bx cx dx si di bp sp ${/*@__PURE__*/numbered("r", 8, 15).replace(/(\d+)/g, "$1w")} ip
78
+ al ah bl bh cl ch dl dh sil dil spl bpl
79
+ ${/*@__PURE__*/numbered("r", 8, 15).replace(/(\d+)/g, "$1b")}
80
+ ${/*@__PURE__*/numbered("r", 8, 15).replace(/(\d+)/g, "$1l")}
81
+ cs ds es fs gs ss
82
+ ${/*@__PURE__*/numbered("cr dr", 0, 15)}
83
+ st ${/*@__PURE__*/numbered("st mm", 0, 7)}
84
+ ${/*@__PURE__*/numbered("xmm ymm zmm", 0, 31)}
85
+ ${/*@__PURE__*/numbered("k tmm", 0, 7)} ${/*@__PURE__*/numbered("bnd", 0, 3)}
86
+ `);
87
+ /** The words NASM writes in front of an operand to qualify it. */
88
+ const SIZE_KEYWORDS$1 = /*@__PURE__*/wordSet(`
89
+ byte word dword qword tword oword yword zword
90
+ rel abs strict near far short wrt seg nosplit
91
+ `);
92
+ const PREFIXES = /*@__PURE__*/wordSet(`
93
+ rep repe repz repne repnz lock xacquire xrelease bnd notrack
94
+ `);
95
+ const x86Vocabulary = {
96
+ directives: DIRECTIVES$3,
97
+ dotDirectives: null,
98
+ definitionDirectives: /*@__PURE__*/wordSet(`${/*@__PURE__*/[...DATA_DIRECTIVES].join(" ")} equ times istruc incbin`),
99
+ qualifiesAnOperand: /*@__PURE__*/new Set(),
100
+ sizeKeywords: SIZE_KEYWORDS$1,
101
+ registers: REGISTERS$3,
102
+ operandDirectives: /*@__PURE__*/wordSet(`${/*@__PURE__*/[...DATA_DIRECTIVES].join(" ")} times`),
103
+ prefixes: PREFIXES,
104
+ nasmMacros: true
105
+ };
106
+
107
+ /** The GNU assembler's directives, as AArch64 code uses them. */
108
+ const DIRECTIVES$2 = /*@__PURE__*/wordSet(`
109
+ .text .data .bss .section .pushsection .popsection .previous .subsection
110
+ .global .globl .local .weak .weakref .hidden .protected .internal
111
+ .type .size .extern .ident .file .loc .end
112
+ .equ .set .equiv .eqv .req .unreq
113
+ .byte .hword .short .2byte .word .int .long .4byte .quad .xword .dword .8byte
114
+ .octa .ascii .asciz .string .float .single .double
115
+ .zero .space .skip .fill .lcomm .comm .sleb128 .uleb128
116
+ .align .balign .balignw .balignl .p2align .p2alignw .p2alignl .org
117
+ .macro .endm .exitm .purgem .altmacro .noaltmacro
118
+ .rept .irp .irpc .endr
119
+ .if .ifdef .ifndef .ifeq .ifne .ifgt .ifge .iflt .ifle .ifb .ifnb .ifc .ifnc
120
+ .else .elseif .endif
121
+ .include .incbin .err .error .warning .print .abort
122
+ .arch .arch_extension .cpu .inst .ltorg .pool .variant_pcs .tlsdesccall
123
+ .func .endfunc .struct
124
+ `);
125
+ /** The directives that write data, which make the label in front a variable. */
126
+ /*@__PURE__*/wordSet(`
127
+ .byte .hword .short .2byte .word .int .long .4byte .quad .xword .dword .8byte
128
+ .octa .ascii .asciz .string .float .single .double .zero .space .skip .fill
129
+ `);
130
+ /** The section names that a Linux program uses. */
131
+ const SECTIONS = /*@__PURE__*/wordSet(`.text .data .bss .rodata .note.GNU-stack`);
132
+ /**
133
+ * The general purpose registers and their aliases, the floating point and
134
+ * vector registers, the SVE registers, and the system registers that a user
135
+ * program can read.
136
+ */
137
+ const REGISTERS$2 = /*@__PURE__*/wordSet(`
138
+ ${/*@__PURE__*/numbered("x w", 0, 30)} sp wsp xzr wzr lr fp ip0 ip1
139
+ ${/*@__PURE__*/numbered("v b h s d q z", 0, 31)} ${/*@__PURE__*/numbered("p", 0, 15)}
140
+ nzcv fpcr fpsr tpidr_el0 tpidrro_el0 cntvct_el0 cntfrq_el0 dczid_el0 ctr_el0
141
+ `);
142
+ /** Shifts and extensions that follow an operand: `x1, lsl #3`. */
143
+ const SHIFTS = /*@__PURE__*/wordSet(`
144
+ lsl lsr asr ror msl
145
+ uxtb uxth uxtw uxtx sxtb sxth sxtw sxtx
146
+ `);
147
+ /** The relocation operators written between colons: `:lo12:msg`. */
148
+ const RELOCATIONS = /*@__PURE__*/wordSet(`
149
+ lo12 got got_lo12 pg_hi21 pg_hi21_nc
150
+ abs_g0 abs_g0_nc abs_g0_s abs_g1 abs_g1_nc abs_g1_s
151
+ abs_g2 abs_g2_nc abs_g2_s abs_g3
152
+ tlsdesc tlsdesc_lo12 gottprel gottprel_lo12
153
+ tprel_hi12 tprel_lo12 tprel_lo12_nc tprel_g0 tprel_g0_nc tprel_g1 tprel_g1_nc tprel_g2
154
+ dtprel_hi12 dtprel_lo12 dtprel_lo12_nc dtprel_g0 dtprel_g0_nc dtprel_g1 dtprel_g1_nc dtprel_g2
155
+ `);
156
+ /** The condition codes, written after `b.` and as the last operand of `csel`. */
157
+ const CONDITIONS$1 = /*@__PURE__*/wordSet(`eq ne cs hs cc lo mi pl vs vc hi ls ge lt gt le al nv`);
158
+ const arm64Vocabulary = {
159
+ // The GNU assembler spells every directive with a dot.
160
+ directives: /*@__PURE__*/new Set(),
161
+ dotDirectives: DIRECTIVES$2,
162
+ // `count .req x19` names `count` as an alias for a register.
163
+ definitionDirectives: /*@__PURE__*/wordSet(".req"),
164
+ qualifiesAnOperand: /*@__PURE__*/new Set(),
165
+ sizeKeywords: /*@__PURE__*/new Set([...SHIFTS, ...RELOCATIONS]),
166
+ registers: REGISTERS$2,
167
+ operandDirectives: /*@__PURE__*/new Set(),
168
+ prefixes: /*@__PURE__*/new Set(),
169
+ nasmMacros: false,
170
+ // `v0.16b`, `v1.4s` and `v2.d` are `v0`, `v1` and `v2`.
171
+ registerSuffix: /\.\d*[bhsdq]$/,
172
+ lineEndKeywords: CONDITIONS$1,
173
+ numericLabelReferences: true
174
+ };
175
+
176
+ /** The directives of MARS, the MIPS simulator used by Exercism's test runner. */
177
+ const DIRECTIVES$1 = /*@__PURE__*/wordSet(`
178
+ .text .data .ktext .kdata .globl .extern
179
+ .word .half .byte .float .double .ascii .asciiz .space .align
180
+ .eqv .macro .end_macro .include .set
181
+ `);
182
+ /** The directives that write data, which make the label in front a variable. */
183
+ /*@__PURE__*/wordSet(`.word .half .byte .float .double .ascii .asciiz .space`);
184
+ /**
185
+ * The registers by number and by name, and the floating point registers. They
186
+ * are listed without the `$` that MIPS writes in front of every register.
187
+ */
188
+ const REGISTER_NAMES = /*@__PURE__*/wordSet(`
189
+ zero at v0 v1 ${/*@__PURE__*/numbered("a", 0, 3)} ${/*@__PURE__*/numbered("t", 0, 9)} ${/*@__PURE__*/numbered("s", 0, 7)}
190
+ k0 k1 gp sp fp ra
191
+ `);
192
+ const REGISTERS$1 = /*@__PURE__*/new Set([
193
+ ...REGISTER_NAMES,
194
+ .../*@__PURE__*/wordSet(/*@__PURE__*/numbered("", 0, 31)),
195
+ .../*@__PURE__*/wordSet(/*@__PURE__*/numbered("f", 0, 31))
196
+ ]);
197
+ /** The registers as they are written, with the `$`, for completion. */
198
+ const WRITTEN_REGISTERS = [
199
+ .../*@__PURE__*/[...REGISTER_NAMES].map((name) => "$" + name),
200
+ .../*@__PURE__*/numbered("$f", 0, 31).split(" "),
201
+ .../*@__PURE__*/numbered("$", 0, 31).split(" ")
202
+ ];
203
+ const mipsVocabulary = {
204
+ // MARS spells every directive with a dot, and every label has a colon.
205
+ directives: /*@__PURE__*/new Set(),
206
+ dotDirectives: DIRECTIVES$1,
207
+ definitionDirectives: /*@__PURE__*/new Set(),
208
+ qualifiesAnOperand: /*@__PURE__*/new Set(),
209
+ sizeKeywords: /*@__PURE__*/new Set(),
210
+ registers: REGISTERS$1,
211
+ operandDirectives: /*@__PURE__*/new Set(),
212
+ prefixes: /*@__PURE__*/new Set(),
213
+ nasmMacros: false,
214
+ dollarRegisters: true,
215
+ hashComments: true,
216
+ percentParameters: true
217
+ };
218
+
219
+ /**
220
+ * Each dialect of the grammar, with the vocabulary its tokenizer reads. To add
221
+ * an instruction set, name a dialect in `@dialects` in assembly.grammar, write
222
+ * its vocabulary in a file of its own, and list it here.
223
+ */
224
+ const dialectVocabularies = [
225
+ [Dialect_x86, x86Vocabulary],
226
+ [Dialect_arm64, arm64Vocabulary],
227
+ [Dialect_mips, mipsVocabulary]
228
+ ];
229
+
230
+ function isDigit(ch) {
231
+ return ch >= 48 /* Ch.Zero */ && ch <= 57 /* Ch.Nine */;
232
+ }
233
+ function isHexDigit(ch) {
234
+ return (isDigit(ch) ||
235
+ (ch >= 65 /* Ch.UpperA */ && ch <= 70 /* Ch.UpperF */) ||
236
+ (ch >= 97 /* Ch.LowerA */ && ch <= 102 /* Ch.LowerF */));
237
+ }
238
+ // Anything above ASCII counts as a letter. Assembly has no character set worth
239
+ // the name, and a symbol with an accent in it, or a zero-width space that a
240
+ // listing dragged in, is still part of the word it stands inside.
241
+ function isLetter(ch) {
242
+ return ((ch >= 65 /* Ch.UpperA */ && ch <= 90 /* Ch.UpperZ */) || (ch >= 97 /* Ch.LowerA */ && ch <= 122 /* Ch.LowerZ */) || ch > 127);
243
+ }
244
+ // A word may open with a dot, because that is how gas spells a directive and
245
+ // how NASM spells a local label; with an `@` or a `?`, because that is how MASM
246
+ // spells a name the programmer did not choose; and with a backslash, because
247
+ // that is how a gas macro spells its own arguments (`\1`, `\@`).
248
+ function isWordStart(ch) {
249
+ return (isLetter(ch) ||
250
+ ch == 95 /* Ch.Underscore */ ||
251
+ ch == 46 /* Ch.Dot */ ||
252
+ ch == 63 /* Ch.Question */ ||
253
+ ch == 64 /* Ch.At */ ||
254
+ ch == 92 /* Ch.Backslash */);
255
+ }
256
+ // `@` closes a word as well as opening one: `printf@PLT` is one symbol, and the
257
+ // relocation on the end of it is not a comment.
258
+ function isWordChar(ch) {
259
+ return (isLetter(ch) ||
260
+ isDigit(ch) ||
261
+ ch == 95 /* Ch.Underscore */ ||
262
+ ch == 46 /* Ch.Dot */ ||
263
+ ch == 63 /* Ch.Question */ ||
264
+ ch == 36 /* Ch.Dollar */ ||
265
+ ch == 64 /* Ch.At */);
266
+ }
267
+ function pastesAName(ch) {
268
+ return isLetter(ch) || ch == 95 /* Ch.Underscore */ || ch == 64 /* Ch.At */;
269
+ }
270
+ function isSpace(ch) {
271
+ return ch == 32 /* Ch.Space */ || ch == 9 /* Ch.Tab */ || ch == 11 /* Ch.VerticalTab */ || ch == 12 /* Ch.FormFeed */;
272
+ }
273
+ /**
274
+ * What an assembler does with a word that stands where a statement stands, and
275
+ * which no instruction set can claim. Everything here is the assembler's own
276
+ * vocabulary: reserving storage, naming a section, opening a macro.
277
+ *
278
+ * `set` and `res` are missing on purpose. Both are directives to some
279
+ * assemblers and instructions to the Z80, and an instruction is the commoner
280
+ * reading; a directive spelt `set` is nearly always preceded by the name it
281
+ * sets, which the label rule catches first.
282
+ */
283
+ const DIRECTIVES = /*@__PURE__*/wordSet(`
284
+ db dw dd dq dt do ddq dqword dz
285
+ defb defw defl defs defm dm dc ds dcb
286
+ resb resw resd resq rest reso resy resz rb rw rd rq rt
287
+ byte sbyte word sword dword sdword fword qword tbyte oword
288
+ real4 real8 real10
289
+ equ label textequ catstr
290
+ struc endstruc struct ends union record
291
+ macro endmacro endm rept endr irp irpc times purge
292
+ proc endp local
293
+ section segment org end entry format model stack heap assume invoke
294
+ public global globl extern extrn common comm static
295
+ include includelib incbin
296
+ bits use16 use32 use64 cpu default
297
+ align alignb even cnop
298
+ if else elseif endif ifdef ifndef ife
299
+ list nolist page title subttl xdef xref opt
300
+ `);
301
+ /**
302
+ * The dot-prefixed vocabulary: the GNU assembler's, and the MASM, LC-3 and VAX
303
+ * words that borrowed the spelling. It is a closed list because a dot-prefixed
304
+ * word that is not on it is a label: NASM spells a local label `.loop` and
305
+ * writes no colon after it, and every assembler that took the convention did
306
+ * the same.
307
+ */
308
+ const DOT_DIRECTIVES = /*@__PURE__*/wordSet(`
309
+ .model .stack .code .const .startup .exit .dosseg .fardata .radix .seq
310
+ .alpha .cref .nocref .lall .sall .xall .listall .repeat .until .untilcxz
311
+ .while .endw .break .continue .186 .286 .386 .386p .486 .586 .686 .8086
312
+ .8087 .mmx .xmm .k3d .no87
313
+ .orig .stringz .blkw .blkb .blkl .blkd .entry .rsset .rsreset .definelabel
314
+ .align16 .asg .eval .newblock .usect .sect .label .field .bes
315
+
316
+ .abort .align .altmacro .arch .arch_extension .arm .ascii .asciz .asciiz
317
+ .att_syntax .balign .balignw .balignl .bss .byte .code .code16 .code32
318
+ .code64 .comm .common .cpu .data .dc .dcb .double .ds .eabi_attribute .eject
319
+ .else .elseif .end .endef .endfunc .endif .endm .endmacro .endr .equ .equiv
320
+ .eqv .err .error .exitm .extern .fail .file .fill .float .fnend .fnstart
321
+ .fpu .func .global .globl .gnu_attribute .handlerdata .hidden .hword .ident
322
+ .if .ifb .ifc .ifdef .ifeq .ifge .ifgt .ifle .iflt .ifnb .ifnc .ifndef
323
+ .ifne .incbin .include .inst .int .intel_syntax .internal .irp .irpc .lcomm
324
+ .line .linkonce .list .llong .loc .local .long .ltorg .macro .movsp .mri
325
+ .noaltmacro .nolist .octa .org .p2align .p2alignl .p2alignw .pad
326
+ .personality .personalityindex .pool .popsection .previous .print
327
+ .protected .psize .purgem .pushsection .quad .rept .req .rodata .save
328
+ .sbttl .scl .section .seh_endprologue .seh_endproc .seh_proc .seh_pushreg
329
+ .seh_stackalloc .set .setfp .short .single .size .skip .sleb128 .space
330
+ .stabd .stabn .stabs .string .string8 .string16 .struct .subsection .symver
331
+ .syntax .tag .text .thumb .thumb_func .thumb_set .title .type .uleb128
332
+ .unreq .val .version .vsave .warning .weak .weakref .word .zero
333
+ `);
334
+ /**
335
+ * A directive that can only follow the name it is about. This is what tells a
336
+ * label from a mnemonic on a line that writes no colon: `bdos equ 5h` names
337
+ * `bdos`, and `message db 'x'` names `message`, because neither `equ` nor `db`
338
+ * can open a statement of its own once a word already has.
339
+ */
340
+ const DEFINITION_DIRECTIVES = /*@__PURE__*/wordSet(`
341
+ db dw dd dq dt do ddq dz defb defw defl defs defm dm
342
+ dc dcb dc.b dc.w dc.l dc.s dc.d ds.b ds.w ds.l ds.s ds.d dcb.b dcb.w dcb.l
343
+ resb resw resd resq rest reso resy resz rb rw rq
344
+ byte sbyte word sword dword sdword fword qword tbyte oword
345
+ real4 real8 real10
346
+ equ set assign label textequ catstr
347
+ proc macro struc struct segment section union record ends endp endm
348
+ .equ .set .equiv .byte .word .long .quad .short .hword .int .octa .single
349
+ .double .float .ascii .asciz .asciiz .string .space .skip .zero .fill
350
+ .comm .lcomm .globl .global .type .size .req .struct
351
+ `);
352
+ /**
353
+ * The subset of the above that is also written in front of an operand rather
354
+ * than in front of a name. `msg BYTE "hi"` declares `msg`, and
355
+ * `mov byte ptr [x], 1` does not declare `mov`; the `ptr` behind it is what
356
+ * says so.
357
+ */
358
+ const QUALIFIES_AN_OPERAND = /*@__PURE__*/wordSet(`
359
+ byte sbyte word sword dword sdword fword qword tbyte oword
360
+ real4 real8 real10
361
+ `);
362
+ /**
363
+ * A word that qualifies an operand rather than being one. Intel syntax writes
364
+ * the width of a memory reference in front of it, and MASM writes several more
365
+ * things the same way.
366
+ */
367
+ const SIZE_KEYWORDS = /*@__PURE__*/wordSet(`
368
+ byte sbyte word sword dword sdword fword qword tbyte oword yword zword
369
+ xmmword ymmword zmmword real4 real8 real10
370
+ ptr offset short near far dup rel seg wrt strict abs sizeof lengthof
371
+ `);
372
+ /**
373
+ * Registers, from every instruction set the corpus this was measured against
374
+ * carries. A list is the only way to know one: a register is spelt like any
375
+ * other word, and the assembler that reads it is the only thing that knows
376
+ * `d0` names one and `msg` does not.
377
+ *
378
+ * A prefix is stripped before the lookup, so `%eax`, `$t0` and `eax` all land
379
+ * on the same entry, and an assembler that writes no prefix is read as well as
380
+ * one that insists on it. The cost is a label named `a` or `x` read as a
381
+ * register, which is the trade every assembly highlighter makes.
382
+ */
383
+ const REGISTERS = /*@__PURE__*/wordSet(`
384
+ ${/*@__PURE__*/numbered("r", 0, 31)} ${/*@__PURE__*/numbered("x w", 0, 31)} ${/*@__PURE__*/numbered("f", 0, 31)}
385
+ ${/*@__PURE__*/numbered("d", 0, 31)} ${/*@__PURE__*/numbered("s", 0, 31)} ${/*@__PURE__*/numbered("q", 0, 31)}
386
+ ${/*@__PURE__*/numbered("b h v", 0, 31)} ${/*@__PURE__*/numbered("t", 0, 9)} ${/*@__PURE__*/numbered("a", 0, 7)}
387
+ ${/*@__PURE__*/numbered("v", 0, 1)} ${/*@__PURE__*/numbered("k", 0, 7)} ${/*@__PURE__*/numbered("cr", 0, 8)}
388
+ ${/*@__PURE__*/numbered("dr", 0, 7)} ${/*@__PURE__*/numbered("st mm", 0, 7)}
389
+ ${/*@__PURE__*/numbered("xmm ymm zmm", 0, 31)} ${/*@__PURE__*/numbered("ft fs fa", 0, 11)}
390
+ al ah bl bh cl ch dl dh sil dil spl bpl
391
+ ax bx cx dx si di sp bp ip
392
+ eax ebx ecx edx esi edi esp ebp eip eflags
393
+ rax rbx rcx rdx rsi rdi rsp rbp rip rflags flags
394
+ r8b r9b r10b r11b r12b r13b r14b r15b
395
+ r8w r9w r10w r11w r12w r13w r14w r15w
396
+ r8d r9d r10d r11d r12d r13d r14d r15d
397
+ cs ds es fs gs ss st
398
+ lr pc fp sb sl cpsr spsr apsr xzr wzr wsp
399
+ a1 a2 a3 a4 v1 v2 v3 v4 v5 v6 v7 v8
400
+ sr ccr usp ssp vbr sfc dfc
401
+ a b c d e f h l i m p r s x y z
402
+ af bc de hl ix iy ixh ixl iyh iyl psw acc dptr
403
+ zero at gp tp ra hi lo ctr xer msr
404
+ xl xh yl yh zl zh
405
+ `);
406
+ /** The shared vocabulary, which reads every assembler at once. */
407
+ const generic = {
408
+ directives: DIRECTIVES,
409
+ dotDirectives: DOT_DIRECTIVES,
410
+ definitionDirectives: DEFINITION_DIRECTIVES,
411
+ qualifiesAnOperand: QUALIFIES_AN_OPERAND,
412
+ sizeKeywords: SIZE_KEYWORDS,
413
+ registers: REGISTERS,
414
+ operandDirectives: /*@__PURE__*/new Set(),
415
+ prefixes: /*@__PURE__*/new Set(),
416
+ nasmMacros: false
417
+ };
418
+ function vocabularyFor(stack) {
419
+ for (const [dialect, vocabulary] of dialectVocabularies) {
420
+ if (stack.dialectEnabled(dialect))
421
+ return vocabulary;
422
+ }
423
+ return generic;
424
+ }
425
+ /**
426
+ * Every word, number and sigil, read against the slot it stands in. The parser
427
+ * is asked which slot that is rather than told: a mnemonic can only stand where
428
+ * a statement can begin, so `stack.canShift(Mnemonic)` is the question, and the
429
+ * answer separates `byte` the directive from `byte` the size, and `a` the
430
+ * mnemonic-shaped word from `a` the accumulator.
431
+ */
432
+ const words = /*@__PURE__*/new ExternalTokenizer((input, stack) => {
433
+ const start = input.next;
434
+ if (start == -1 /* Ch.EOF */)
435
+ return;
436
+ const statement = stack.canShift(Mnemonic);
437
+ const vocabulary = vocabularyFor(stack);
438
+ if (isDigit(start)) {
439
+ // `1:` and `2:` are how gas writes a label it does not want to name.
440
+ if (statement && digitsThenColon(input))
441
+ return acceptLabel(input);
442
+ // `1b` and `1f` jump back and forward to the nearest `1:`.
443
+ if (!statement && vocabulary.numericLabelReferences && numericLabelReference(input)) {
444
+ return input.acceptToken(Identifier);
445
+ }
446
+ scanNumber(input);
447
+ return input.acceptToken(Number);
448
+ }
449
+ if (start == 36 /* Ch.Dollar */)
450
+ return dollar(input, statement, vocabulary);
451
+ if (start == 37 /* Ch.Percent */)
452
+ return percent(input, statement, vocabulary);
453
+ if (start == 35 /* Ch.Hash */) {
454
+ if (vocabulary.hashComments)
455
+ return operatorOrComment(input, true, StatementComment);
456
+ return hash(input, statement);
457
+ }
458
+ // A star in column one is a comment to the 68000 assemblers and to MASM, and
459
+ // a slash in column one is one to the PDP-8's. Anywhere else the one
460
+ // multiplies and the other divides, and anywhere else is where the parser has
461
+ // already begun reading operands.
462
+ if (start == 42 /* Ch.Star */)
463
+ return operatorOrComment(input, statement, Star);
464
+ if (start == 47 /* Ch.Slash */)
465
+ return operatorOrComment(input, statement, Slash);
466
+ // A capital C opening a statement is GNU MP's comment character, and GNU MP
467
+ // is the assembly that ships inside everybody else's tree. It has to be the
468
+ // whole of the word: `CALL` is a mnemonic and `C:` is a label.
469
+ if (start == 67 /* Ch.UpperC */ && statement && isSpace(input.peek(1))) {
470
+ input.advance();
471
+ return operatorOrComment(input, true, StatementComment);
472
+ }
473
+ // `=` opens a statement or stands inside an operand, and the two are told
474
+ // apart here rather than in the grammar, where one rule would have to guess.
475
+ if (start == 61 /* Ch.Equals */) {
476
+ input.advance();
477
+ return input.acceptToken(statement ? AssignOp : Equals);
478
+ }
479
+ // gas writes the location counter as a bare dot, which is a word start
480
+ // everywhere else.
481
+ if (start == 46 /* Ch.Dot */ && !isWordChar(input.peek(1))) {
482
+ input.advance();
483
+ return input.acceptToken(Here);
484
+ }
485
+ if (isWordStart(start)) {
486
+ const word = scanWord(input);
487
+ return statement
488
+ ? acceptStatementWord(input, word, vocabulary)
489
+ : acceptOperandWord(input, word, vocabulary);
490
+ }
491
+ });
492
+ /** `$1F` is hexadecimal, `$t0` is a register and `$` alone is here. */
493
+ function dollar(input, statement, vocabulary) {
494
+ if (input.peek(1) == 36 /* Ch.Dollar */) {
495
+ input.advance();
496
+ input.advance();
497
+ return input.acceptToken(Here);
498
+ }
499
+ // To MIPS, `$a0` and `$31` are registers, and `$` opens nothing else.
500
+ if (vocabulary.dollarRegisters && isWordChar(input.peek(1))) {
501
+ input.advance();
502
+ const word = scanWord(input);
503
+ return input.acceptToken(vocabulary.registers.has(word.toLowerCase()) ? Register : Identifier);
504
+ }
505
+ if (isHexDigit(input.peek(1))) {
506
+ let offset = 1;
507
+ while (isHexDigit(input.peek(offset)))
508
+ offset++;
509
+ // `$a0` is a MIPS register and `$a0` is a 6502 address, and only a word
510
+ // that cannot be read as hexadecimal settles it. Hexadecimal wins the tie,
511
+ // because an assembler that prefixes its registers writes far fewer of
512
+ // them than one that prefixes its addresses writes addresses.
513
+ if (!isWordChar(input.peek(offset))) {
514
+ while (offset-- > 0)
515
+ input.advance();
516
+ return input.acceptToken(Number);
517
+ }
518
+ }
519
+ if (isWordStart(input.peek(1)) || isHexDigit(input.peek(1))) {
520
+ input.advance();
521
+ const word = scanWord(input);
522
+ return statement
523
+ ? acceptStatementWord(input, word, vocabulary)
524
+ : acceptOperandWord(input, word, vocabulary);
525
+ }
526
+ input.advance();
527
+ input.acceptToken(Here);
528
+ }
529
+ /** `%macro` opens a statement, `%eax` is a register and `%1010` is binary. */
530
+ function percent(input, statement, vocabulary) {
531
+ const after = input.peek(1);
532
+ if (vocabulary.nasmMacros && nasmMacroWord(input, statement))
533
+ return;
534
+ if (statement && (isWordStart(after) || after == 37 /* Ch.Percent */)) {
535
+ input.advance();
536
+ if (input.next == 37 /* Ch.Percent */)
537
+ input.advance();
538
+ scanWord(input);
539
+ return input.acceptToken(MacroName);
540
+ }
541
+ if (isWordStart(after)) {
542
+ input.advance();
543
+ const word = scanWord(input);
544
+ if (vocabulary.percentParameters)
545
+ return input.acceptToken(MacroParameter);
546
+ return acceptOperandWord(input, word, vocabulary);
547
+ }
548
+ // `%1010` is binary to a Motorola assembler and `7%3` is a remainder to
549
+ // everyone else, and what stands in front of the sign is what tells them
550
+ // apart: a literal opens an operand and a remainder joins two.
551
+ if (isDigit(after) && !followsAValue(input)) {
552
+ input.advance();
553
+ scanNumber(input);
554
+ return input.acceptToken(Number);
555
+ }
556
+ input.advance();
557
+ input.acceptToken(Percent);
558
+ }
559
+ /**
560
+ * NASM gives `%` three more jobs inside a macro. `%1` is a parameter, `%%end`
561
+ * is a label local to one expansion of the macro, and `%$x` is local to a
562
+ * context. A label of either kind may open a statement: `%%end:`.
563
+ */
564
+ function nasmMacroWord(input, statement) {
565
+ const after = input.peek(1);
566
+ if (isDigit(after) || ((after == 43 /* Ch.Plus */ || after == 45 /* Ch.Minus */) && isDigit(input.peek(2)))) {
567
+ if (followsAValue(input))
568
+ return false;
569
+ input.advance();
570
+ if (!isDigit(input.next))
571
+ input.advance();
572
+ while (isDigit(input.next))
573
+ input.advance();
574
+ input.acceptToken(MacroParameter);
575
+ return true;
576
+ }
577
+ let offset = 1;
578
+ if (after == 37 /* Ch.Percent */)
579
+ offset = 2;
580
+ else if (after == 36 /* Ch.Dollar */) {
581
+ offset = 2;
582
+ while (input.peek(offset) == 36 /* Ch.Dollar */)
583
+ offset++;
584
+ }
585
+ else
586
+ return false;
587
+ if (!isWordStart(input.peek(offset)))
588
+ return false;
589
+ for (let i = 0; i < offset; i++)
590
+ input.advance();
591
+ scanWord(input);
592
+ if (statement) {
593
+ if (input.next == 58 /* Ch.Colon */)
594
+ input.advance();
595
+ input.acceptToken(Label);
596
+ }
597
+ else {
598
+ input.acceptToken(Identifier);
599
+ }
600
+ return true;
601
+ }
602
+ function followsAValue(input) {
603
+ const behind = input.peek(-1);
604
+ return isWordChar(behind) || behind == 41 /* Ch.ParenR */ || behind == 93 /* Ch.BracketR */;
605
+ }
606
+ function operatorOrComment(input, statement, operator) {
607
+ input.advance();
608
+ if (!statement)
609
+ return input.acceptToken(operator);
610
+ while (input.next != 10 /* Ch.Newline */ && input.next != 13 /* Ch.Return */ && input.next != -1 /* Ch.EOF */) {
611
+ input.advance();
612
+ }
613
+ input.acceptToken(StatementComment);
614
+ }
615
+ /** `#define` opens a statement; `#42` prefixes an immediate. */
616
+ function hash(input, statement) {
617
+ if (statement && isWordStart(input.peek(1))) {
618
+ input.advance();
619
+ scanWord(input);
620
+ return input.acceptToken(MacroName);
621
+ }
622
+ input.advance();
623
+ input.acceptToken(ImmediatePrefix);
624
+ }
625
+ function scanWord(input) {
626
+ let word = String.fromCharCode(input.next);
627
+ input.advance();
628
+ // A gas macro pastes its arguments into a name: `.copy_\str:` and
629
+ // `.loop\@:` are one label each.
630
+ while (isWordChar(input.next) || (input.next == 92 /* Ch.Backslash */ && pastesAName(input.peek(1)))) {
631
+ word += String.fromCharCode(input.next);
632
+ input.advance();
633
+ }
634
+ return word;
635
+ }
636
+ /**
637
+ * A number is read to the end of what it is spelt with rather than by radix,
638
+ * because the radix is written in four places: in front (`0x1F`), behind
639
+ * (`1Fh`), as a sigil (`$1F`) and nowhere at all. Nothing that opens with a
640
+ * digit is a symbol in any assembler, so reading the whole run costs nothing
641
+ * and spares the tokenizer four spellings of the same thing.
642
+ */
643
+ function scanNumber(input) {
644
+ input.advance();
645
+ for (;;) {
646
+ const ch = input.next;
647
+ if (isLetter(ch) || isDigit(ch) || ch == 95 /* Ch.Underscore */)
648
+ input.advance();
649
+ else if (ch == 46 /* Ch.Dot */ && isDigit(input.peek(1)))
650
+ input.advance();
651
+ else
652
+ break;
653
+ }
654
+ }
655
+ function numericLabelReference(input) {
656
+ let offset = 0;
657
+ while (isDigit(input.peek(offset)))
658
+ offset++;
659
+ const suffix = input.peek(offset);
660
+ if ((suffix != 98 /* Ch.LowerB */ && suffix != 102 /* Ch.LowerF */) || isWordChar(input.peek(offset + 1))) {
661
+ return false;
662
+ }
663
+ for (let i = 0; i <= offset; i++)
664
+ input.advance();
665
+ return true;
666
+ }
667
+ function digitsThenColon(input) {
668
+ let offset = 0;
669
+ while (isDigit(input.peek(offset)))
670
+ offset++;
671
+ return input.peek(offset) == 58 /* Ch.Colon */;
672
+ }
673
+ function acceptLabel(input) {
674
+ while (isDigit(input.next))
675
+ input.advance();
676
+ input.advance();
677
+ input.acceptToken(Label);
678
+ }
679
+ function acceptStatementWord(input, word, vocabulary) {
680
+ // A colon behind it settles the question and no assembler disagrees.
681
+ if (input.next == 58 /* Ch.Colon */) {
682
+ input.advance();
683
+ if (input.next == 58 /* Ch.Colon */)
684
+ input.advance();
685
+ return input.acceptToken(Label);
686
+ }
687
+ const lower = word.toLowerCase();
688
+ if (lower.charCodeAt(0) == 46 /* Ch.Dot */) {
689
+ const dots = vocabulary.dotDirectives;
690
+ const directive = dots != null && (dots.has(lower) || lower.startsWith(".cfi_"));
691
+ return input.acceptToken(directive ? DirectiveName : Label);
692
+ }
693
+ if (vocabulary.directives.has(lower))
694
+ return input.acceptToken(DirectiveName);
695
+ // Nothing behind it but a directive that needs a name in front: the word is
696
+ // that name.
697
+ if (definitionFollows(input, vocabulary))
698
+ return input.acceptToken(Label);
699
+ // `rep movsb` is one instruction, so the prefix takes the mnemonic behind it.
700
+ if (vocabulary.prefixes.has(lower)) {
701
+ const offset = skipSpace(input, 0);
702
+ const next = peekWord(input, offset);
703
+ if (offset > 0 && next && !vocabulary.registers.has(next.toLowerCase())) {
704
+ for (let i = 0; i < offset + next.length; i++)
705
+ input.advance();
706
+ }
707
+ }
708
+ input.acceptToken(Mnemonic);
709
+ }
710
+ /**
711
+ * The IBM assemblers ask a symbol about itself with a letter and an apostrophe
712
+ * that never closes: `L'TBL` is the length of `TBL`, and `T'`, `S'`, `I'`, `K'`,
713
+ * `N'`, `D'` and `O'` ask the other questions. Left to the character literal
714
+ * rule, that apostrophe opens a literal that runs to the end of the line and
715
+ * takes the rest of the statement with it.
716
+ */
717
+ const ATTRIBUTE_LETTERS = /*@__PURE__*/wordSet("l t s i k n d o");
718
+ function acceptOperandWord(input, word, vocabulary) {
719
+ var _a;
720
+ const lower = word.toLowerCase();
721
+ if (input.next == 39 /* Ch.Apostrophe */ &&
722
+ ATTRIBUTE_LETTERS.has(lower) &&
723
+ isWordStart(input.peek(1))) {
724
+ input.advance();
725
+ scanWord(input);
726
+ return input.acceptToken(Identifier);
727
+ }
728
+ if (vocabulary.sizeKeywords.has(lower))
729
+ return input.acceptToken(SizeKeyword);
730
+ if (((_a = vocabulary.lineEndKeywords) === null || _a === void 0 ? void 0 : _a.has(lower)) && endsTheStatement(input)) {
731
+ return input.acceptToken(SizeKeyword);
732
+ }
733
+ let register = strip(lower);
734
+ if (vocabulary.registerSuffix)
735
+ register = register.replace(vocabulary.registerSuffix, "");
736
+ if (!vocabulary.dollarRegisters && vocabulary.registers.has(register)) {
737
+ return input.acceptToken(Register);
738
+ }
739
+ if (vocabulary.operandDirectives.has(lower))
740
+ return input.acceptToken(OperandDirective);
741
+ input.acceptToken(Identifier);
742
+ }
743
+ /** A register prefix is decoration; `%eax`, `$t0` and `eax` are one register. */
744
+ function strip(word) {
745
+ const first = word.charCodeAt(0);
746
+ return first == 37 /* Ch.Percent */ || first == 36 /* Ch.Dollar */ ? word.slice(1) : word;
747
+ }
748
+ function definitionFollows(input, vocabulary) {
749
+ let offset = skipSpace(input, 0);
750
+ // `message_len = $ - message` declares as surely as `equ` does.
751
+ if (input.peek(offset) == 61 /* Ch.Equals */)
752
+ return input.peek(offset + 1) != 61 /* Ch.Equals */;
753
+ const word = peekWord(input, offset);
754
+ if (!vocabulary.definitionDirectives.has(word.toLowerCase()))
755
+ return false;
756
+ if (!vocabulary.qualifiesAnOperand.has(word.toLowerCase()))
757
+ return true;
758
+ // `mov byte ptr [x], 1` in MASM and `mov byte [x], 1` in NASM both qualify
759
+ // an operand, so the word in front is a mnemonic.
760
+ offset = skipSpace(input, offset + word.length);
761
+ if (input.peek(offset) == 91 /* Ch.BracketL */)
762
+ return false;
763
+ return peekWord(input, offset).toLowerCase() != "ptr";
764
+ }
765
+ /** Whether only space and a comment stand between the cursor and the line's end. */
766
+ function endsTheStatement(input) {
767
+ const offset = skipSpace(input, 0);
768
+ const opensABlockComment = input.peek(offset) == 47 /* Ch.Slash */ && input.peek(offset + 1) == 42 /* Ch.Star */;
769
+ return endsTheLine(input.peek(offset)) || opensAComment(input, offset) || opensABlockComment;
770
+ }
771
+ function skipSpace(input, offset) {
772
+ while (isSpace(input.peek(offset)))
773
+ offset++;
774
+ return offset;
775
+ }
776
+ function peekWord(input, offset) {
777
+ if (!isWordStart(input.peek(offset)))
778
+ return "";
779
+ let word = "";
780
+ while (isWordChar(input.peek(offset))) {
781
+ word += String.fromCharCode(input.peek(offset));
782
+ offset++;
783
+ }
784
+ return word;
785
+ }
786
+ // bass and armips brace a run of lines, `scope AA {` and `if cond {`, where
787
+ // A backtick opens a quote, and what closes it depends on who is reading. An
788
+ // assembler closes it with another backtick and never crosses a line. m4
789
+ // closes it with an apostrophe, counts the pairs on the way, and thinks
790
+ // nothing of running over twenty lines: `ifdef(`OPERATION_addlsh2_n',`` opens a
791
+ // block of assembly that ends in `')` further down, and GNU MP's `.asm` files
792
+ // are written that way from top to bottom.
793
+ //
794
+ // So the quote is read as m4's when an apostrophe closes it and as the
795
+ // assembler's otherwise, and an unbalanced one ends at its line rather than
796
+ // taking the rest of the file with it.
797
+ const rawString = /*@__PURE__*/new ExternalTokenizer((input) => {
798
+ if (input.next != 96 /* Ch.Backtick */)
799
+ return;
800
+ const end = quoteEnd(input);
801
+ for (let i = 0; i < end; i++)
802
+ input.advance();
803
+ input.acceptToken(RawString);
804
+ });
805
+ /**
806
+ How far a quote may be looked ahead for its close. The whole file would be
807
+ the honest answer and a quadratic one, since a file that leaves a backtick
808
+ unbalanced usually leaves several.
809
+ */
810
+ const quoteReach = 65536;
811
+ /**
812
+ How far the quote opening at the cursor runs. m4's balanced apostrophe wins
813
+ where there is one, the assembler's closing backtick on the same line comes
814
+ next, and a quote that neither closes ends where its line does.
815
+ */
816
+ function quoteEnd(input) {
817
+ let depth = 0;
818
+ let lineEnd = -1;
819
+ let sameLineBacktick = -1;
820
+ for (let ahead = 0;; ahead++) {
821
+ const ch = input.peek(ahead);
822
+ if (ch == -1 /* Ch.EOF */ || ahead > quoteReach) {
823
+ return sameLineBacktick > 0 ? sameLineBacktick : lineEnd < 0 ? ahead : lineEnd;
824
+ }
825
+ if (lineEnd < 0 && endsTheLine(ch))
826
+ lineEnd = ahead;
827
+ if (ch == 92 /* Ch.Backslash */ && input.peek(ahead + 1) != -1 /* Ch.EOF */) {
828
+ ahead++;
829
+ continue;
830
+ }
831
+ if (ch == 96 /* Ch.Backtick */) {
832
+ depth++;
833
+ if (depth == 2 && lineEnd < 0 && sameLineBacktick < 0)
834
+ sameLineBacktick = ahead + 1;
835
+ }
836
+ else if (ch == 39 /* Ch.Apostrophe */ && !--depth) {
837
+ return ahead + 1;
838
+ }
839
+ }
840
+ }
841
+ // every other assembler's brace holds operands: a register list to ARM, a mask
842
+ // to AVX. The two are the same character and only what follows it says which.
843
+ // A brace that ends its own line opens the block, because a list has its
844
+ // contents behind it and a block has them underneath.
845
+ const braces = /*@__PURE__*/new ExternalTokenizer((input, stack) => {
846
+ if (input.next != 123 /* Ch.BraceL */)
847
+ return;
848
+ input.advance();
849
+ input.acceptToken(opensABlock(input) ? BlockOpen : BraceOpen);
850
+ });
851
+ function opensABlock(input) {
852
+ let ahead = 0;
853
+ while (input.peek(ahead) == 32 /* Ch.Space */ || input.peek(ahead) == 9 /* Ch.Tab */)
854
+ ahead++;
855
+ if (opensAComment(input, ahead)) {
856
+ while (!endsTheLine(input.peek(ahead)))
857
+ ahead++;
858
+ }
859
+ return endsTheLine(input.peek(ahead));
860
+ }
861
+ function endsTheLine(ch) {
862
+ return ch == 10 /* Ch.Newline */ || ch == 13 /* Ch.Return */ || ch == -1 /* Ch.EOF */;
863
+ }
864
+ function opensAComment(input, at) {
865
+ const ch = input.peek(at);
866
+ if (ch == 59 /* Ch.Semicolon */)
867
+ return true;
868
+ return ch == 47 /* Ch.Slash */ && input.peek(at + 1) == 47 /* Ch.Slash */;
869
+ }
870
+
871
+ // This file was generated by lezer-generator. You probably shouldn't edit it.
872
+ const parser = /*@__PURE__*/LRParser.deserialize({
873
+ version: 14,
874
+ states: "(QOfQ_OOOOQ^'#Db'#DbO%lQ_O'#DiO'dQ_O'#DTO'kQ_O'#DWO'rQ_O'#DYOOQ^'#Dk'#DkOOQ^'#Dc'#DcO)dQ_O'#CyO)}Q_O'#DdO*hQ]O'#CxO*hQ]O'#CxO+PQ_O'#CwO+^Q_O'#D[O+kQ_O'#D]O+xQ_O'#D^OOQ['#D_'#D_OOQ['#Dj'#DjO,VQXO'#D`OOQW'#Di'#DiO,[Q]O'#DiQ,gQXO'#DaOfQ_OOOOQ^-E7`-E7`OOQW,5:T,5:TO,lQ]O,5:TOOQ^,59o,59oO,wQXO,59oOOQ^,59r,59rO,|QXO,59rOOQ^,59t,59tO-RQXO,59tOOQ^-E7a-E7aOOQ[,5:O,5:OOOQ[-E7b-E7bO-WQ]O,59dOOQ[,59c,59cOOQ[,59v,59vOOQ[,59w,59wOOQ[,59x,59xO-oQ_O,59zO-yQXO,59zOOQ^,59{,59{OOQ^-E7_-E7_OOQW1G/o1G/oOOQ^1G/Z1G/ZOOQ^1G/^1G/^OOQ^1G/`1G/`OOQW,5:P,5:POOQW1G/f1G/fO.OQ_O1G/fOOQW-E7c-E7cOOQW7+%Q7+%QP-rQ_O'#De",
875
+ stateData: ".a~O![OSfOSgOShOSaOSiOS~OPUOQbORTOS[OT]OU^OVPOWUOXUOYUOZUO[UO]UO^UO_UO`UOb_OcUOdUOeUOnUOoUOpUOqUOrUOsUOtUOvROySO}XO!Y!]P!`!]P~OPUOQbORTOS[OT]OU^OVPOWUOXUOYUOZUO[UO]UO^UO_UO`UOb_OcUOdUOeUOnUOoUOpUOqUOrUOsUOtUOvROySO}XO~O!Y!]X!`!]X~P#lOPUORTOWUOXUOYUOZUO[UO]UO^UO_UO`UOcUOdUOeUOnUOoUOpUOqUOrUOsUOtUOvROySO}XO~OujO~P%vOxlO~P%vO{nO~P%vOPUORTOWUOXUOYUOZUO[UO]UO^UO_UO`UOcUOdUOeUOnUOoUOpUOqUOrUOsUOtUOvROySO~OQmX}mX!YmX!`mXumXxmX{mX~P'yOQ!WX}!WX!Y!WX!`!WXu!WXx!WX{!WX~P'yO}XOQlX!YlX!`lXulXxlX{lX~OQkX!YkX!`kX~P%vOQ!OX!Y!OX!`!OX~P%vOQ!PX!Y!PX!`!PX~P%vOQ!QX!Y!QX!`!QX~P%vO!`xO~OQbO!Y!]X!`!]X~O!`zO~OQbO!Y!]a!`!]a~Ou}O~Ox!OO~O{!PO~O}XOQla!Yla!`laulaxla{la~O{!RO!`!]P~P#lO!`!SO~O{!UO!`!]P~P#lOghqpqs~",
876
+ goto: "&b!`PPPPPPPPPPPPPPPPPPPPPPPPPPP!a!i#WPPPPPPPPP#jPP#jP#jP!a!a!a!a#{$Z$a$k%O%fPPP%l%u&P]aOQfx!S!V[`OQfx!S!VQkRQmSQoTQt[Qu]Qv^Rw_jZOQRST[]^_fx!S!VRqXoUOQRSTWX[]^_fx!S!VYcOfx!S!VShQdR|iQfOR{fYQOfx!S!VRgQlWOQRSTX[]^_fx!S!VRpWjYOQRST[]^_fx!S!VSrYsRsZQybR!TySeOfV!Qx!S!VYdOfx!S!VRiQoVOQRSTWX[]^_fx!S!V",
877
+ nodeNames: "⚠ RawString { { Mnemonic DirectiveName MacroName Label Register SizeKeyword Identifier Number ImmediatePrefix Here Star Slash Percent StatementComment AssignOp Equals DirectiveName MacroParameter Continuation BlockComment LineComment EndMarker Program Instruction Operands Operand String Char ArithOp CompareOp : Bang ? ) ( Parens ] [ Brackets } Braces , Directive Preprocessor Assignment Data Block",
878
+ maxTerm: 62,
879
+ nodeProps: [
880
+ ["openedBy", 37,"(",40,"["],
881
+ ["closedBy", 38,")",41,"]"]
882
+ ],
883
+ skippedNodes: [0,17,22,23,24,25],
884
+ repeatNodeCount: 5,
885
+ tokenData: ".T~RqXY#YYZ#kZ[#Y[]#Y]^#pjk#xpq#Yqr$irs$vst&Pvw'mwx'rxy({yz)Q{|'m|})V}!O'm!P!Q)[![!]*l!]!^'U!^!_*q!_!`*|!`!a+S!a!b+_!b!c+d!}#O,Y#O#P,_#P#Q,{#Q#R'm#W#X-Q#p#q'm#q#r.O#r#s'm~#_S![~XY#YZ[#Y[]#Ypq#Y~#pO!`~~#uP!`~YZ#k~#}Ri~O;'S#x;'S;=`$W;=`O#x~$]Si~O;'S#x;'S;=`$W;=`<%l#x<%lO#x~$nPs~!_!`$q~$vOq~~${Wn~OY$vZr$vrs%es#O$v#O#P%j#P;'S$v;'S;=`%y<%lO$v~%jOn~~%mSOY$vZ;'S$v;'S;=`%y<%lO$v~%|P;=`<%l$v~&S`OY'UZ]'U^r'Ust'Uvw'Uy{'U|}'U!O!Q'U!]!c'U!}#O'U#P#R'U#S#T'U#o#r'U#s;'S'U;'S;=`'g<%lO'U~'ZSh~OY'UZ;'S'U;'S;=`'g<%lO'U~'jP;=`<%l'U~'rOp~~'wWo~OY'rZw'rwx(ax#O'r#O#P(f#P;'S'r;'S;=`(u<%lO'r~(fOo~~(iSOY'rZ;'S'r;'S;=`(u<%lO'r~(xP;=`<%l'r~)QOv~~)VOu~~)[O}~~)_Qz{)e!P!Q'U~)hTOz)ez{)w{;'S)e;'S;=`*f<%lO)e~)zVOz)ez{)w{!P)e!P!Q*a!Q;'S)e;'S;=`*f<%lO)e~*fOg~~*iP;=`<%l)e~*qOr~~*vQq~!^!_$q!_!`$q~+PP!_!`$q~+XQq~!_!`$q!`!a$q~+dOt~~+gZOY'UZ]'U^t'Uu!O'U!P!Q'U![!a'U!}#R'U#S#T'U#o;'S'U;'S;=`'g<%lO'U~,_Oy~~,bSXY,_YZ,n]^,spq,_~,sOf~~,xPf~YZ,n~-QOx~~-TP#b#c-W~-ZP#`#a-^~-cXh~OY'UZ]'U^!Q'U![!c'U!}#R'U#S#T'U#o;'S'U;'S;=`'g<%lO'U~.TO{~",
886
+ tokenizers: [0, rawString, braces, words],
887
+ topRules: {"Program":[0,26]},
888
+ dialects: {x86: 0, arm64: 0, mips: 0},
889
+ tokenPrec: 608
890
+ });
891
+
892
+ const assemblyLanguage = /*@__PURE__*/LRLanguage.define({
893
+ name: "assembly",
894
+ parser: /*@__PURE__*/parser.configure({
895
+ props: [
896
+ /*@__PURE__*/foldNodeProp.add({
897
+ Parens: foldInside,
898
+ Brackets: foldInside,
899
+ Braces: foldInside,
900
+ BlockComment: foldInside
901
+ }),
902
+ /*@__PURE__*/styleTags({
903
+ Mnemonic: tags.keyword,
904
+ DirectiveName: tags.meta,
905
+ MacroName: tags.macroName,
906
+ Label: /*@__PURE__*/tags.definition(tags.labelName),
907
+ Register: /*@__PURE__*/tags.special(tags.variableName),
908
+ SizeKeyword: tags.typeName,
909
+ Identifier: tags.variableName,
910
+ Number: tags.number,
911
+ "String RawString": tags.string,
912
+ Char: tags.character,
913
+ Here: tags.atom,
914
+ MacroParameter: /*@__PURE__*/tags.local(tags.variableName),
915
+ ImmediatePrefix: tags.operator,
916
+ // The Ctrl-Z a DOS assembler wrote at the end of a file, and
917
+ // whatever somebody left behind it.
918
+ EndMarker: tags.comment,
919
+ "LineComment StatementComment": tags.lineComment,
920
+ BlockComment: tags.blockComment,
921
+ Continuation: tags.escape,
922
+ "ArithOp Star Slash Percent": tags.arithmeticOperator,
923
+ CompareOp: tags.compareOperator,
924
+ AssignOp: tags.definitionOperator,
925
+ Equals: tags.operator,
926
+ ",": tags.separator,
927
+ ": ? Bang": tags.punctuation,
928
+ "( )": tags.paren,
929
+ "[ ]": tags.squareBracket,
930
+ "{ }": tags.brace
931
+ })
932
+ ]
933
+ }),
934
+ languageData: {
935
+ // Every assembler in the corpus this was measured against takes a
936
+ // semicolon, and the ones that take something else take it as well.
937
+ commentTokens: { line: ";" },
938
+ closeBrackets: { brackets: ["(", "[", "{", '"', "'"] }
939
+ }
940
+ });
941
+ function proposals(from, type) {
942
+ return [...from].map((label) => ({ label, type }));
943
+ }
944
+ /**
945
+ Autocompletion for the assembler's own vocabulary: the directives that
946
+ reserve storage and open sections, the GNU assembler's dot-prefixed set, the
947
+ widths an Intel-syntax operand can carry, and the registers of every
948
+ instruction set the grammar knows. Mnemonics are not proposed, because a
949
+ mnemonic belongs to a processor rather than to assembly.
950
+ */
951
+ const assemblyCompletion = /*@__PURE__*/completeFromList([
952
+ .../*@__PURE__*/proposals(DIRECTIVES, "keyword"),
953
+ .../*@__PURE__*/proposals(DOT_DIRECTIVES, "keyword"),
954
+ .../*@__PURE__*/proposals(SIZE_KEYWORDS, "type"),
955
+ .../*@__PURE__*/proposals(REGISTERS, "variable")
956
+ ]);
957
+ /**
958
+ Assembly language support, with completion for directives, operand widths
959
+ and registers.
960
+ */
961
+ function assembly() {
962
+ return new LanguageSupport(assemblyLanguage, [
963
+ assemblyLanguage.data.of({ autocomplete: assemblyCompletion })
964
+ ]);
965
+ }
966
+
967
+ const DATA = /^(d[bwdqtoyz]|res[bwdqtoyz]|times|incbin|istruc|\.(byte|word|long|quad|ascii|asciz|asciiz|string|zero|space|skip|fill|int|short|hword|octa|float|double|single|half|dword|xword|[248]byte))$/i;
968
+ const CONSTANT = /^(equ|\.equ|\.set|\.equiv|set)$/i;
969
+ const ALIAS = /^\.req$/i;
970
+ const DEFINE = /^%[ix]?(define|xdefine|assign|deftok|defstr|strlen|strcat|substr)$|^%i?xdefine$|^#define$|^\.(equ|set|equiv|eqv)$/i;
971
+ const MACRO_OPEN = /^(%i?macro|\.macro|macro)$/i;
972
+ const MACRO_CLOSE = /^(%endmacro|\.endm|\.endmacro|\.end_macro|endm|endmacro)$/i;
973
+ function text(doc, node) {
974
+ return doc.sliceString(node.from, node.to);
975
+ }
976
+ /** The name of a statement node: its mnemonic, directive or preprocessor word. */
977
+ function statementWord(doc, node) {
978
+ const first = node.firstChild;
979
+ return first ? text(doc, first).toLowerCase() : "";
980
+ }
981
+ /** The first word in a statement's operands, such as `SIZE` in `%define SIZE 8`. */
982
+ function firstOperandWord(doc, node) {
983
+ var _a;
984
+ const operand = (_a = node.getChild("Operands")) === null || _a === void 0 ? void 0 : _a.getChild("Operand");
985
+ const first = operand === null || operand === void 0 ? void 0 : operand.firstChild;
986
+ if (!first)
987
+ return null;
988
+ return first.name == "Identifier" || first.name == "Register" || first.name == "Mnemonic"
989
+ ? first
990
+ : null;
991
+ }
992
+ /**
993
+ * Whether a label belongs to the function around it: `.loop`, and `%%end`
994
+ * inside a NASM macro. To gas, `1:` belongs to it as well.
995
+ */
996
+ function isLocalLabel(name, style = "nasm") {
997
+ if (style == "gas" && /^\d+$/.test(name))
998
+ return true;
999
+ return (name.startsWith(".") && !name.startsWith("..@")) || name.startsWith("%%");
1000
+ }
1001
+ const caches = {
1002
+ nasm: /*@__PURE__*/new WeakMap(),
1003
+ gas: /*@__PURE__*/new WeakMap()
1004
+ };
1005
+ /**
1006
+ * The names declared in the file. A label, an `equ` constant, a `%define`
1007
+ * and a macro are global. A local label such as `.loop` belongs to the global
1008
+ * label before it, as NASM reads it. A `%%end` label belongs to the macro it
1009
+ * is written in. A field such as `.size` inside `struc item` is offered as
1010
+ * `item.size`, and the structure also gives `item_size`.
1011
+ */
1012
+ function declaredNames(tree, doc, style = "nasm") {
1013
+ const cache = caches[style];
1014
+ const cached = cache.get(tree);
1015
+ if (cached)
1016
+ return cached;
1017
+ const names = [];
1018
+ const end = doc.length;
1019
+ let ownerFrom = 0;
1020
+ let pendingLocals = [];
1021
+ let macro = null;
1022
+ let struc = null;
1023
+ const closeOwner = (at) => {
1024
+ for (const local of pendingLocals)
1025
+ local.to = at;
1026
+ pendingLocals = [];
1027
+ };
1028
+ for (let node = tree.topNode.firstChild; node; node = node.nextSibling) {
1029
+ if (node.name == "Label") {
1030
+ const name = text(doc, node).replace(/:+$/, "");
1031
+ const next = node.nextSibling;
1032
+ const nextWord = next && sameLine(doc, node, next) ? statementWord(doc, next) : "";
1033
+ const type = CONSTANT.test(nextWord) || (next === null || next === void 0 ? void 0 : next.name) == "Assignment"
1034
+ ? "constant"
1035
+ : DATA.test(nextWord) || ALIAS.test(nextWord) ? "variable" : null;
1036
+ if (style == "gas") {
1037
+ // gas labels are global, and a numeric one is kept as its digits for
1038
+ // namesInScope to turn into `1b` or `1f`.
1039
+ names.push({ name, type: type !== null && type !== void 0 ? type : (/^\d+$/.test(name) ? "label" : "function"), at: node.from, from: 0, to: end });
1040
+ }
1041
+ else if (struc && name.startsWith(".")) {
1042
+ names.push({ name: struc + name, type: "constant", at: node.from, from: 0, to: end });
1043
+ }
1044
+ else if (name.startsWith("%%")) {
1045
+ if (macro) {
1046
+ const label = { name, type: "label", at: node.from, from: macro.from, to: end };
1047
+ macro.labels.push(label);
1048
+ names.push(label);
1049
+ }
1050
+ }
1051
+ else if (isLocalLabel(name)) {
1052
+ const local = { name, type: type !== null && type !== void 0 ? type : "label", at: node.from, from: ownerFrom, to: end };
1053
+ pendingLocals.push(local);
1054
+ names.push(local);
1055
+ }
1056
+ else {
1057
+ if (!type) {
1058
+ closeOwner(node.from);
1059
+ ownerFrom = node.from;
1060
+ }
1061
+ names.push({ name, type: type !== null && type !== void 0 ? type : "function", at: node.from, from: 0, to: end });
1062
+ }
1063
+ continue;
1064
+ }
1065
+ if (node.name != "Preprocessor" && node.name != "Directive" && node.name != "Instruction")
1066
+ continue;
1067
+ const word = statementWord(doc, node);
1068
+ const named = firstOperandWord(doc, node);
1069
+ if (DEFINE.test(word) && named) {
1070
+ names.push({ name: text(doc, named), type: "constant", at: named.from, from: 0, to: end });
1071
+ }
1072
+ else if (MACRO_OPEN.test(word) && named) {
1073
+ names.push({ name: text(doc, named), type: "macro", at: named.from, from: 0, to: end });
1074
+ macro = { from: node.from, labels: [], parameters: [] };
1075
+ if (word == ".macro") {
1076
+ for (const parameter of macroParameters(doc, node, named)) {
1077
+ const name = { name: parameter, type: "variable", at: node.from, from: node.from, to: end, macroParameter: true };
1078
+ macro.parameters.push(name);
1079
+ names.push(name);
1080
+ }
1081
+ }
1082
+ }
1083
+ else if (MACRO_CLOSE.test(word) && macro) {
1084
+ for (const label of [...macro.labels, ...macro.parameters])
1085
+ label.to = node.to;
1086
+ macro = null;
1087
+ }
1088
+ else if (word == "struc" && named) {
1089
+ struc = text(doc, named);
1090
+ names.push({ name: struc, type: "type", at: named.from, from: 0, to: end });
1091
+ names.push({ name: struc + "_size", type: "constant", at: named.from, from: 0, to: end });
1092
+ }
1093
+ else if (word == "endstruc") {
1094
+ struc = null;
1095
+ }
1096
+ else if ((word == "extern" || word == "extrn" || word == ".extern") && node.getChild("Operands")) {
1097
+ for (const operand of node.getChild("Operands").getChildren("Operand")) {
1098
+ const first = operand.firstChild;
1099
+ if ((first === null || first === void 0 ? void 0 : first.name) == "Identifier") {
1100
+ names.push({ name: text(doc, first), type: "function", at: first.from, from: 0, to: end });
1101
+ }
1102
+ }
1103
+ }
1104
+ }
1105
+ cache.set(tree, names);
1106
+ return names;
1107
+ }
1108
+ /**
1109
+ * The parameters of a gas macro: `source`, `count` and `size` in
1110
+ * `.macro COPY source, count=1, size:req`. MARS writes them in brackets
1111
+ * behind the name, as `%from` and `%to` in `.macro copy(%from, %to)`.
1112
+ */
1113
+ function macroParameters(doc, node, name) {
1114
+ var _a, _b, _c, _d, _e;
1115
+ const out = [];
1116
+ for (const operand of (_b = (_a = node.getChild("Operands")) === null || _a === void 0 ? void 0 : _a.getChildren("Operand")) !== null && _b !== void 0 ? _b : []) {
1117
+ for (let part = operand.firstChild; part; part = part.nextSibling) {
1118
+ if (part.name == "Parens") {
1119
+ for (const inner of (_d = (_c = part.getChild("Operands")) === null || _c === void 0 ? void 0 : _c.getChildren("Operand")) !== null && _d !== void 0 ? _d : []) {
1120
+ for (const parameter of inner.getChildren("MacroParameter"))
1121
+ out.push(text(doc, parameter));
1122
+ }
1123
+ continue;
1124
+ }
1125
+ if (part.from == name.from)
1126
+ continue;
1127
+ const before = (_e = part.prevSibling) === null || _e === void 0 ? void 0 : _e.name;
1128
+ if (before == "Equals" || before == ":")
1129
+ continue;
1130
+ if (part.name == "Identifier" || part.name == "Register" || part.name == "SizeKeyword") {
1131
+ out.push(text(doc, part));
1132
+ }
1133
+ }
1134
+ }
1135
+ return out;
1136
+ }
1137
+ function sameLine(doc, a, b) {
1138
+ return doc.lineAt(a.from).number == doc.lineAt(b.from).number;
1139
+ }
1140
+ /**
1141
+ * The names that can be used at `pos`, with the newest declaration of each.
1142
+ * In the gas style, a numeric label `1:` is offered as `1b` below it and as
1143
+ * `1f` above it.
1144
+ */
1145
+ function namesInScope(tree, doc, pos, style = "nasm") {
1146
+ const seen = new Map();
1147
+ for (const declared of declaredNames(tree, doc, style)) {
1148
+ if (pos < declared.from || pos > declared.to)
1149
+ continue;
1150
+ let name = declared;
1151
+ if (style == "gas" && /^\d+$/.test(declared.name)) {
1152
+ if (doc.lineAt(declared.at).number == doc.lineAt(pos).number)
1153
+ continue;
1154
+ name = Object.assign(Object.assign({}, declared), { name: declared.name + (declared.at < pos ? "b" : "f") });
1155
+ }
1156
+ if (!seen.has(name.name))
1157
+ seen.set(name.name, name);
1158
+ }
1159
+ return [...seen.values()];
1160
+ }
1161
+
1162
+ const DONT_COMPLETE_IN = /*@__PURE__*/new Set([
1163
+ "LineComment",
1164
+ "BlockComment",
1165
+ "StatementComment",
1166
+ "String",
1167
+ "Char",
1168
+ "RawString",
1169
+ "EndMarker"
1170
+ ]);
1171
+ const WORD = /[%$.\w?@]*$/;
1172
+ // The text in front of the word on its line, when the word starts a statement:
1173
+ // nothing, or labels such as `main:` and `.loop:`.
1174
+ const STATEMENT_START = /^\s*((%%|\.\.@|\.)?[\w$?@.]+::?\s*)*$/;
1175
+ // A statement whose next word is a new name, which completion can't know.
1176
+ const NAMES_SOMETHING = /^\s*(%[ix]?(define|xdefine|assign|macro|imacro|undef|deftok|defstr|strlen)|struc|\.macro|\.set|\.equ|\.eqv)\s+$/i;
1177
+ function options(words, type) {
1178
+ return [...words].map((label) => ({ label, type }));
1179
+ }
1180
+ /**
1181
+ * A completion source for one instruction set. Where a statement starts, it
1182
+ * offers the mnemonics, directives, macros declared in the file and snippets.
1183
+ * After `%` it offers the preprocessor words. In an operand it offers the
1184
+ * registers, size keywords, and the labels and constants in scope. Local labels
1185
+ * such as `.loop` are offered only after the global label they belong to.
1186
+ * Nothing is offered in comments and strings, or where a new name is being
1187
+ * written.
1188
+ */
1189
+ function assemblyCompletionSource(vocabulary) {
1190
+ var _a, _b, _c, _d, _e, _f, _g, _h;
1191
+ const statement = [
1192
+ ...options(vocabulary.mnemonics, "keyword"),
1193
+ ...options(vocabulary.directives, "keyword"),
1194
+ ...((_a = vocabulary.snippets) !== null && _a !== void 0 ? _a : [])
1195
+ ];
1196
+ const mnemonics = options(vocabulary.mnemonics, "keyword");
1197
+ const preprocessor = options((_b = vocabulary.preprocessor) !== null && _b !== void 0 ? _b : [], "keyword");
1198
+ const operand = [
1199
+ ...options(vocabulary.registers, "variable"),
1200
+ ...options((_c = vocabulary.sizeKeywords) !== null && _c !== void 0 ? _c : [], "type"),
1201
+ ...options((_d = vocabulary.operandDirectives) !== null && _d !== void 0 ? _d : [], "keyword")
1202
+ ];
1203
+ const sections = options((_e = vocabulary.sections) !== null && _e !== void 0 ? _e : [], "namespace");
1204
+ const relocations = options((_f = vocabulary.relocations) !== null && _f !== void 0 ? _f : [], "type");
1205
+ const style = (_g = vocabulary.labels) !== null && _g !== void 0 ? _g : "nasm";
1206
+ const prefixes = [...((_h = vocabulary.prefixes) !== null && _h !== void 0 ? _h : [])];
1207
+ const afterPrefix = prefixes.length
1208
+ ? new RegExp(`^\\s*((%%|\\.)?[\\w$?@.]+:\\s*)*(${prefixes.join("|")})\\s+$`, "i")
1209
+ : null;
1210
+ return (context) => {
1211
+ const { state, pos } = context;
1212
+ const tree = syntaxTree(state);
1213
+ const inner = tree.resolveInner(pos, -1);
1214
+ for (let node = inner; node; node = node.parent) {
1215
+ if (DONT_COMPLETE_IN.has(node.name))
1216
+ return null;
1217
+ }
1218
+ const word = context.matchBefore(WORD);
1219
+ if (!word || (word.from == word.to && !context.explicit))
1220
+ return null;
1221
+ const line = state.doc.lineAt(pos);
1222
+ const before = line.text.slice(0, word.from - line.from);
1223
+ if (NAMES_SOMETHING.test(before))
1224
+ return null;
1225
+ const result = (list) => ({
1226
+ from: word.from,
1227
+ options: list,
1228
+ validFor: /^[%$.\w?@]*$/
1229
+ });
1230
+ if (/(^|\s)\.?(section|segment)\s+$/i.test(before))
1231
+ return result(sections);
1232
+ if (afterPrefix === null || afterPrefix === void 0 ? void 0 : afterPrefix.test(before))
1233
+ return result(mnemonics);
1234
+ if (relocations.length && /(^|[\s,#]):$/.test(before))
1235
+ return result(relocations);
1236
+ const names = namesInScope(tree, state.doc, pos, style);
1237
+ const parameters = names
1238
+ .filter((name) => name.macroParameter)
1239
+ .map((name) => ({ label: name.name, type: name.type }));
1240
+ // A gas macro writes its parameters as `\name`.
1241
+ if (before.endsWith("\\"))
1242
+ return result(parameters);
1243
+ if (STATEMENT_START.test(before)) {
1244
+ if (word.text.startsWith("%") && !word.text.startsWith("%%"))
1245
+ return result(preprocessor);
1246
+ const macros = names
1247
+ .filter((name) => name.type == "macro")
1248
+ .map((name) => ({ label: name.name, type: "function" }));
1249
+ return result([...statement, ...macros]);
1250
+ }
1251
+ const declared = names
1252
+ .filter((name) => name.type != "macro" && !name.macroParameter)
1253
+ .map((name) => ({ label: name.name, type: name.type }));
1254
+ // MARS writes a macro's parameters as `%name`.
1255
+ if (word.text.startsWith("%") && parameters.some((name) => name.label.startsWith("%"))) {
1256
+ return result(parameters.filter((name) => name.label.startsWith("%")));
1257
+ }
1258
+ // An immediate such as `#SIZE` can only be a number or a constant.
1259
+ if (before.endsWith("#"))
1260
+ return result(declared.filter((name) => name.type == "constant"));
1261
+ return result([...operand, ...declared]);
1262
+ };
1263
+ }
1264
+
1265
+ const STATEMENTS = /*@__PURE__*/new Set(["Instruction", "Directive", "Preprocessor", "Assignment", "Data", "Label", "Block"]);
1266
+ function lineEndBefore(state, pos) {
1267
+ const line = state.doc.lineAt(pos);
1268
+ return line.number > 1 ? state.doc.line(line.number - 1).to : line.from;
1269
+ }
1270
+ function blockOf(options, word, side) {
1271
+ var _a;
1272
+ return (_a = options.blocks.find((block) => block[side].test(word))) !== null && _a !== void 0 ? _a : null;
1273
+ }
1274
+ /**
1275
+ * Folding for a flat tree. Every statement is a child of the program, so a
1276
+ * block is found by walking along the statements. A block such as `%macro`
1277
+ * folds to its closing word. A global code label folds to the last statement
1278
+ * before the next global label or section directive, which is the body of the
1279
+ * function it names.
1280
+ */
1281
+ function foldStatements(options) {
1282
+ return foldService.of((state, lineStart, lineEnd) => {
1283
+ const tree = syntaxTree(state);
1284
+ let first = tree.topNode.childAfter(lineStart);
1285
+ while (first && !STATEMENTS.has(first.name) && first.from < lineEnd)
1286
+ first = first.nextSibling;
1287
+ if (!first || first.from >= lineEnd)
1288
+ return null;
1289
+ const doc = state.doc;
1290
+ const word = statementWord(doc, first);
1291
+ const block = first.name == "Label" ? null : blockOf(options, word, "open");
1292
+ if (block) {
1293
+ let depth = 0;
1294
+ for (let node = first.nextSibling; node; node = node.nextSibling) {
1295
+ const next = statementWord(doc, node);
1296
+ if (block.open.test(next))
1297
+ depth++;
1298
+ else if (block.close.test(next) && depth-- == 0) {
1299
+ const to = lineEndBefore(state, node.from);
1300
+ return to > lineEnd ? { from: lineEnd, to } : null;
1301
+ }
1302
+ }
1303
+ return null;
1304
+ }
1305
+ if (first.name != "Label")
1306
+ return null;
1307
+ const name = doc.sliceString(first.from, first.to).replace(/:+$/, "");
1308
+ if (isLocalLabel(name, options.labels))
1309
+ return null;
1310
+ let last = null;
1311
+ for (let node = first.nextSibling; node; node = node.nextSibling) {
1312
+ if (!STATEMENTS.has(node.name))
1313
+ continue;
1314
+ if (node.name == "Label") {
1315
+ const other = doc.sliceString(node.from, node.to).replace(/:+$/, "");
1316
+ if (!isLocalLabel(other, options.labels))
1317
+ break;
1318
+ }
1319
+ else if (options.sectionBreaks.test(statementWord(doc, node))) {
1320
+ break;
1321
+ }
1322
+ last = node;
1323
+ }
1324
+ if (!last)
1325
+ return null;
1326
+ const to = doc.lineAt(last.to).to;
1327
+ return to > lineEnd ? { from: lineEnd, to } : null;
1328
+ });
1329
+ }
1330
+ // A label alone on its line, such as `main:` or `.loop:`.
1331
+ const LABEL_LINE = /^\s*(%%|\.\.@|\.)?[\w$?@.]+::?\s*$/;
1332
+ const LABEL_START = /^\s*(%%|\.\.@|\.)?[\w$?@.]+::?/;
1333
+ /** A line without its comment, for reading its first word. */
1334
+ function code(line, comments) {
1335
+ let quote = "";
1336
+ for (let i = 0; i < line.length; i++) {
1337
+ const ch = line[i];
1338
+ if (quote) {
1339
+ if (ch == quote)
1340
+ quote = "";
1341
+ }
1342
+ else if (ch == '"' || ch == "'" || ch == "`") {
1343
+ quote = ch;
1344
+ }
1345
+ else if (comments.some((comment) => line.startsWith(comment, i))) {
1346
+ return line.slice(0, i).trimEnd();
1347
+ }
1348
+ }
1349
+ return line.trimEnd();
1350
+ }
1351
+ function firstWord(line) {
1352
+ var _a, _b, _c;
1353
+ return (_c = (_b = (_a = /^\s*([%.\w$?@]+)/.exec(line.replace(LABEL_START, ""))) === null || _a === void 0 ? void 0 : _a[1]) === null || _b === void 0 ? void 0 : _b.toLowerCase()) !== null && _c !== void 0 ? _c : "";
1354
+ }
1355
+ function indentOf(state, text) {
1356
+ let column = 0;
1357
+ for (const ch of text) {
1358
+ if (ch == " ")
1359
+ column++;
1360
+ else if (ch == "\t")
1361
+ column += state.tabSize - (column % state.tabSize);
1362
+ else
1363
+ break;
1364
+ }
1365
+ return column;
1366
+ }
1367
+ /**
1368
+ * Indentation as assembly is written: labels and section directives at the
1369
+ * margin, and instructions one unit in. A line after a label on its own is
1370
+ * indented, and the body of a block such as `%macro` is indented one unit
1371
+ * further than its opening line. A label or a closing word such as
1372
+ * `%endmacro` lines up with the block's opening line.
1373
+ */
1374
+ function indentStatements(options) {
1375
+ return indentService.of((context, pos) => {
1376
+ var _a;
1377
+ const { state } = context;
1378
+ const unit = getIndentUnit(state);
1379
+ const line = state.doc.lineAt(pos);
1380
+ const comments = (_a = options.lineComments) !== null && _a !== void 0 ? _a : [";"];
1381
+ const current = code(line.text.slice(pos - line.from), comments);
1382
+ const currentWord = firstWord(current);
1383
+ // The block that the line is in: its opening line's indent, or -1 at the top.
1384
+ let depth = 0;
1385
+ let blockIndent = -1;
1386
+ let previous = null;
1387
+ for (let number = line.number - 1; number >= 1; number--) {
1388
+ const text = code(state.doc.line(number).text, comments);
1389
+ if (!text.trim())
1390
+ continue;
1391
+ if (previous == null)
1392
+ previous = text;
1393
+ const word = firstWord(text);
1394
+ if (options.blocks.some((block) => block.close.test(word)))
1395
+ depth++;
1396
+ else if (options.blocks.some((block) => block.open.test(word)) && depth-- == 0) {
1397
+ blockIndent = indentOf(state, text);
1398
+ break;
1399
+ }
1400
+ }
1401
+ const base = blockIndent < 0 ? 0 : blockIndent;
1402
+ if (options.blocks.some((block) => block.close.test(currentWord)))
1403
+ return base;
1404
+ if (LABEL_START.test(current))
1405
+ return base;
1406
+ if (options.sectionBreaks.test(currentWord))
1407
+ return base;
1408
+ if (previous == null)
1409
+ return 0;
1410
+ const previousIndent = indentOf(state, previous);
1411
+ const previousWord = firstWord(previous);
1412
+ if (LABEL_LINE.test(previous))
1413
+ return previousIndent + unit;
1414
+ if (options.blocks.some((block) => block.open.test(previousWord)))
1415
+ return previousIndent + unit;
1416
+ if (blockIndent >= 0 && previousIndent <= blockIndent)
1417
+ return blockIndent + unit;
1418
+ return previousIndent;
1419
+ });
1420
+ }
1421
+ /** Folding and indentation for the blocks and labels of one assembler. */
1422
+ function assemblyLayout(options) {
1423
+ return [foldStatements(options), indentStatements(options)];
1424
+ }
1425
+
1426
+ const CONDITIONS = "o no b nb c nc ae nae z nz e ne be nbe a na s ns p np pe po l nl ge nge le nle g ng";
1427
+ function conditional$1(prefix) {
1428
+ return CONDITIONS.split(" ").map((cc) => prefix + cc).join(" ");
1429
+ }
1430
+ /**
1431
+ * The x86-64 instructions offered by completion. It covers the general
1432
+ * purpose instructions, x87, SSE to SSE4.2, the common AVX, AVX2 and AVX-512
1433
+ * instructions, BMI, AES and SHA. Instructions that are invalid in 64-bit mode,
1434
+ * such as `aaa` and `pusha`, are left out.
1435
+ */
1436
+ const MNEMONICS$2 = /*@__PURE__*/wordSet(`
1437
+ mov movzx movsx movsxd lea xchg xadd cmpxchg cmpxchg8b cmpxchg16b bswap movbe
1438
+ push pop pushf pushfq popf popfq lahf sahf
1439
+ add adc sub sbb imul mul idiv div inc dec neg cmp
1440
+ and or xor not test
1441
+ shl shr sal sar rol ror rcl rcr shld shrd
1442
+ bt bts btr btc bsf bsr popcnt lzcnt tzcnt
1443
+ andn bextr blsi blsmsk blsr bzhi mulx pdep pext rorx sarx shlx shrx
1444
+ adcx adox crc32
1445
+ cbw cwde cdqe cwd cdq cqo
1446
+ jmp call ret leave enter loop loope loopne loopz loopnz jrcxz jecxz
1447
+ ${/*@__PURE__*/conditional$1("j")} ${/*@__PURE__*/conditional$1("set")} ${/*@__PURE__*/conditional$1("cmov")}
1448
+ movsb movsw movsd movsq cmpsb cmpsw cmpsd cmpsq scasb scasw scasd scasq
1449
+ lodsb lodsw lodsd lodsq stosb stosw stosd stosq
1450
+ rep repe repz repne repnz lock
1451
+ clc stc cmc cld std cli sti
1452
+ nop pause hlt int int3 syscall sysret cpuid rdtsc rdtscp rdrand rdseed
1453
+ lfence mfence sfence prefetcht0 prefetcht1 prefetcht2 prefetchnta prefetchw
1454
+ clflush clflushopt xlatb ud2 endbr64
1455
+
1456
+ fld fst fstp fild fist fistp fisttp fxch fldz fld1 fldpi fldl2e fldln2
1457
+ fadd faddp fsub fsubp fsubr fsubrp fmul fmulp fdiv fdivp fdivr fdivrp
1458
+ fabs fchs fsqrt fsin fcos fsincos fptan fpatan fprem frndint fscale
1459
+ fcom fcomp fcompp fcomi fcomip fucomi fucomip ftst fxam
1460
+ finit fninit fldcw fstcw fnstcw fstsw fnstsw fwait
1461
+
1462
+ emms movd movq
1463
+ movaps movups movapd movupd movss movsd movhlps movlhps movhps movlps
1464
+ movhpd movlpd movmskps movmskpd movdqa movdqu movntdq movnti movntps lddqu
1465
+ movddup movshdup movsldup movdq2q movq2dq
1466
+ addps addss addpd addsd subps subss subpd subsd mulps mulss mulpd mulsd
1467
+ divps divss divpd divsd sqrtps sqrtss sqrtpd sqrtsd rcpps rcpss rsqrtps rsqrtss
1468
+ maxps maxss maxpd maxsd minps minss minpd minsd
1469
+ addsubps addsubpd haddps haddpd hsubps hsubpd dpps dppd
1470
+ andps andpd andnps andnpd orps orpd xorps xorpd
1471
+ cmpps cmpss cmppd cmpsd cmpeqps cmpltps cmpleps cmpneqps cmpnltps cmpnleps
1472
+ cmpeqss cmpltss cmpless cmpneqss cmpeqpd cmpltpd cmplepd cmpeqsd cmpltsd cmplesd
1473
+ comiss comisd ucomiss ucomisd
1474
+ shufps shufpd unpcklps unpckhps unpcklpd unpckhpd
1475
+ blendps blendpd blendvps blendvpd insertps extractps
1476
+ roundps roundss roundpd roundsd
1477
+ cvtsi2ss cvtsi2sd cvtss2si cvtsd2si cvttss2si cvttsd2si cvtss2sd cvtsd2ss
1478
+ cvtps2pd cvtpd2ps cvtdq2ps cvtps2dq cvttps2dq cvtdq2pd cvtpd2dq cvttpd2dq
1479
+ ldmxcsr stmxcsr
1480
+ paddb paddw paddd paddq paddsb paddsw paddusb paddusw
1481
+ psubb psubw psubd psubq psubsb psubsw psubusb psubusw
1482
+ pmullw pmulld pmulhw pmulhuw pmuludq pmuldq pmaddwd pmaddubsw pmulhrsw
1483
+ pand pandn por pxor
1484
+ psllw pslld psllq psrlw psrld psrlq psraw psrad pslldq psrldq
1485
+ pcmpeqb pcmpeqw pcmpeqd pcmpeqq pcmpgtb pcmpgtw pcmpgtd pcmpgtq
1486
+ pmaxsb pmaxsw pmaxsd pmaxub pmaxuw pmaxud pminsb pminsw pminsd pminub pminuw pminud
1487
+ pabsb pabsw pabsd psignb psignw psignd pavgb pavgw psadbw
1488
+ packsswb packssdw packuswb packusdw
1489
+ punpcklbw punpcklwd punpckldq punpcklqdq punpckhbw punpckhwd punpckhdq punpckhqdq
1490
+ pshufb pshufd pshufhw pshuflw palignr pblendw pblendvb
1491
+ pextrb pextrw pextrd pextrq pinsrb pinsrw pinsrd pinsrq
1492
+ pmovmskb pmovsxbw pmovsxbd pmovsxbq pmovsxwd pmovsxwq pmovsxdq
1493
+ pmovzxbw pmovzxbd pmovzxbq pmovzxwd pmovzxwq pmovzxdq
1494
+ phaddw phaddd phaddsw phsubw phsubd phsubsw phminposuw
1495
+ ptest mpsadbw pcmpestri pcmpestrm pcmpistri pcmpistrm pclmulqdq
1496
+ aesenc aesenclast aesdec aesdeclast aesimc aeskeygenassist
1497
+ sha1rnds4 sha1nexte sha1msg1 sha1msg2 sha256rnds2 sha256msg1 sha256msg2
1498
+
1499
+ vzeroupper vzeroall
1500
+ vmovaps vmovups vmovapd vmovupd vmovss vmovsd vmovd vmovq vmovdqa vmovdqu
1501
+ vmovdqa32 vmovdqa64 vmovdqu8 vmovdqu16 vmovdqu32 vmovdqu64 vmovmskps vmovmskpd
1502
+ vaddps vaddss vaddpd vaddsd vsubps vsubss vsubpd vsubsd
1503
+ vmulps vmulss vmulpd vmulsd vdivps vdivss vdivpd vdivsd
1504
+ vsqrtps vsqrtss vsqrtpd vsqrtsd vmaxps vmaxpd vminps vminpd
1505
+ vandps vandpd vorps vorpd vxorps vxorpd vandnps vandnpd
1506
+ vcmpps vcmppd vcmpss vcmpsd vcomiss vcomisd vucomiss vucomisd
1507
+ vshufps vshufpd vpermilps vpermilpd vperm2f128 vperm2i128 vpermd vpermq vpermps
1508
+ vbroadcastss vbroadcastsd vbroadcastf128 vpbroadcastb vpbroadcastw vpbroadcastd vpbroadcastq
1509
+ vextractf128 vextracti128 vinsertf128 vinserti128 vblendps vblendpd vblendvps vblendvpd
1510
+ vhaddps vhaddpd vroundps vroundpd vroundss vroundsd
1511
+ vcvtsi2ss vcvtsi2sd vcvtss2si vcvtsd2si vcvttss2si vcvttsd2si vcvtss2sd vcvtsd2ss
1512
+ vcvtdq2ps vcvtps2dq vcvttps2dq vcvtps2pd vcvtpd2ps vcvtph2ps vcvtps2ph
1513
+ vfmadd132ps vfmadd213ps vfmadd231ps vfmadd132pd vfmadd213pd vfmadd231pd
1514
+ vfmadd132ss vfmadd213ss vfmadd231ss vfmadd132sd vfmadd213sd vfmadd231sd
1515
+ vfmsub132ps vfmsub213ps vfmsub231ps vfmsub132sd vfmsub213sd vfmsub231sd
1516
+ vfnmadd132ps vfnmadd213ps vfnmadd231ps vfnmadd132sd vfnmadd213sd vfnmadd231sd
1517
+ vpaddb vpaddw vpaddd vpaddq vpsubb vpsubw vpsubd vpsubq
1518
+ vpmullw vpmulld vpmuludq vpand vpandn vpor vpxor vpandd vpandq vpord vporq vpxord vpxorq
1519
+ vpsllw vpslld vpsllq vpsrlw vpsrld vpsrlq vpsraw vpsrad vpsllvd vpsllvq vpsrlvd vpsrlvq
1520
+ vpcmpeqb vpcmpeqw vpcmpeqd vpcmpeqq vpcmpgtb vpcmpgtw vpcmpgtd vpcmpgtq
1521
+ vpcmpb vpcmpub vpcmpd vpcmpud vpcmpq vpcmpuq
1522
+ vpmaxsd vpmaxud vpminsd vpminud vpabsb vpabsw vpabsd
1523
+ vpshufb vpshufd vpalignr vpblendd vpblendvb vpmovmskb vptest
1524
+ vpunpcklbw vpunpckhbw vpunpckldq vpunpckhdq vpackuswb vpacksswb
1525
+ vpgatherdd vpgatherqq vgatherdps vgatherdpd vpcompressd vpexpandd
1526
+ vpternlogd vpternlogq vptestmb vptestmd vptestnmb vpconflictd vplzcntd vpopcntd vpopcntb
1527
+ kmovb kmovw kmovd kmovq kandw kandd kandq korw kord korq kxorw kxord kxorq
1528
+ knotw knotd knotq kortestw kortestd kortestq ktestw ktestd ktestq kshiftlw kshiftrw
1529
+ `);
1530
+
1531
+ /**
1532
+ The assembly language with the `x86` dialect, which reads NASM as written
1533
+ for x86-64.
1534
+ */
1535
+ const x86_64AssemblyLanguage = /*@__PURE__*/assemblyLanguage.configure({ dialect: "x86" }, "x86-64-assembly");
1536
+ /**
1537
+ Snippets for the common shapes of an x86-64 NASM program.
1538
+ */
1539
+ const snippets$2 = [
1540
+ /*@__PURE__*/snippetCompletion("section .text\nglobal ${name}\n${name}:\n\t${}\n\tret", {
1541
+ label: "section .text",
1542
+ detail: "with a global function",
1543
+ type: "keyword"
1544
+ }),
1545
+ /*@__PURE__*/snippetCompletion("section .data\n${name}: db ${\"text\"}, 0\n${name}_len: equ $ - ${name}", {
1546
+ label: "section .data",
1547
+ detail: "with a string",
1548
+ type: "keyword"
1549
+ }),
1550
+ /*@__PURE__*/snippetCompletion("section .bss\n${name}: resb ${64}", {
1551
+ label: "section .bss",
1552
+ detail: "with a buffer",
1553
+ type: "keyword"
1554
+ }),
1555
+ /*@__PURE__*/snippetCompletion("${name}:\n\tpush rbp\n\tmov rbp, rsp\n\t${}\n\tmov rsp, rbp\n\tpop rbp\n\tret", {
1556
+ label: "function",
1557
+ detail: "with prologue and epilogue",
1558
+ type: "keyword"
1559
+ }),
1560
+ /*@__PURE__*/snippetCompletion("\tmov rcx, ${count}\n.${loop}:\n\t${}\n\tdec rcx\n\tjnz .${loop}", {
1561
+ label: "loop",
1562
+ detail: "counting down rcx",
1563
+ type: "keyword"
1564
+ }),
1565
+ /*@__PURE__*/snippetCompletion("\tcmp ${rax}, ${0}\n\tj${e} .${label}", {
1566
+ label: "cmp",
1567
+ detail: "and jump",
1568
+ type: "keyword"
1569
+ }),
1570
+ /*@__PURE__*/snippetCompletion("%macro ${name} ${1}\n\t${}\n%endmacro", {
1571
+ label: "%macro",
1572
+ detail: "block",
1573
+ type: "keyword"
1574
+ }),
1575
+ /*@__PURE__*/snippetCompletion("struc ${name}\n\t.${field}: resq 1\nendstruc", {
1576
+ label: "struc",
1577
+ detail: "block",
1578
+ type: "keyword"
1579
+ })
1580
+ ];
1581
+ /**
1582
+ Completion for x86-64 NASM. Where a statement starts it offers the x86-64
1583
+ mnemonics, NASM's directives, the macros declared in the file and the
1584
+ snippets. In an operand it offers the registers, the size keywords and the
1585
+ labels and constants declared in the file.
1586
+ */
1587
+ const x86_64Completion = /*@__PURE__*/assemblyCompletionSource({
1588
+ mnemonics: MNEMONICS$2,
1589
+ directives: DIRECTIVES$3,
1590
+ preprocessor: PREPROCESSOR,
1591
+ registers: REGISTERS$3,
1592
+ sizeKeywords: SIZE_KEYWORDS$1,
1593
+ operandDirectives: [...DATA_DIRECTIVES, "times"],
1594
+ sections: SECTIONS$1,
1595
+ prefixes: PREFIXES,
1596
+ snippets: snippets$2
1597
+ });
1598
+ /**
1599
+ Folding and indentation for NASM's blocks, and for a function's body under
1600
+ its label.
1601
+ */
1602
+ const x86_64Layout = /*@__PURE__*/assemblyLayout({
1603
+ blocks: [
1604
+ { open: /^%i?macro$/, close: /^%endmacro$/ },
1605
+ { open: /^%rep$/, close: /^%endrep$/ },
1606
+ { open: /^%if/, close: /^%endif$/ },
1607
+ { open: /^struc$/, close: /^endstruc$/ },
1608
+ { open: /^istruc$/, close: /^iend$/ }
1609
+ ],
1610
+ sectionBreaks: /^(section|segment|global|extern|default|bits)$/
1611
+ });
1612
+ /**
1613
+ x86-64 assembly support for NASM, as used on Exercism's x86-64 Assembly
1614
+ track.
1615
+ */
1616
+ function x86_64Assembly() {
1617
+ return new LanguageSupport(x86_64AssemblyLanguage, [
1618
+ x86_64AssemblyLanguage.data.of({
1619
+ autocomplete: x86_64Completion,
1620
+ // Typing the colon of a label or the end of a block moves it back to
1621
+ // the margin of its block.
1622
+ indentOnInput: /^\s*(%end\w*|%else|%elif\w*|endstruc|iend|(%%|\.)?[\w$?@.]+:)$/i
1623
+ }),
1624
+ x86_64Layout
1625
+ ]);
1626
+ }
1627
+
1628
+ function conditional(prefix) {
1629
+ return [...CONDITIONS$1].map((cc) => prefix + cc).join(" ");
1630
+ }
1631
+ /**
1632
+ * The AArch64 instructions offered by completion. It covers the base
1633
+ * instructions, the aliases the GNU assembler accepts, the atomics, the
1634
+ * floating point instructions and the common Advanced SIMD (NEON)
1635
+ * instructions. `b.eq` and the other conditional branches are listed one by
1636
+ * one, so typing `b.` offers them all.
1637
+ */
1638
+ const MNEMONICS$1 = /*@__PURE__*/wordSet(`
1639
+ mov movz movn movk mvn adr adrp
1640
+ add adds sub subs neg negs adc adcs sbc sbcs ngc ngcs cmp cmn
1641
+ mul madd msub mneg smull umull smaddl umaddl smsubl umsubl smnegl umnegl smulh umulh
1642
+ sdiv udiv
1643
+ and ands orr orn eor eon bic bics tst
1644
+ lsl lsr asr ror lslv lsrv asrv rorv
1645
+ sxtb sxth sxtw uxtb uxth
1646
+ sbfm ubfm bfm sbfx ubfx bfi bfxil sbfiz ubfiz bfc extr
1647
+ clz cls rbit rev rev16 rev32 rev64 cnt abs smax smin umax umin
1648
+ csel csinc csinv csneg cset csetm cinc cinv cneg ccmp ccmn
1649
+ b bl br blr ret cbz cbnz tbz tbnz
1650
+ ${/*@__PURE__*/conditional("b.")} ${/*@__PURE__*/conditional("bc.")}
1651
+ beq bne bcs bhs bcc blo bmi bpl bvs bvc bhi bls bge blt bgt ble bal
1652
+ ldr ldrb ldrh ldrsb ldrsh ldrsw str strb strh
1653
+ ldur ldurb ldurh ldursb ldursh ldursw stur sturb sturh
1654
+ ldp ldpsw stp ldnp stnp ldtr ldtrb ldtrh sttr sttrb sttrh
1655
+ ldxr ldxrb ldxrh ldxp stxr stxrb stxrh stxp
1656
+ ldaxr ldaxrb ldaxrh ldaxp stlxr stlxrb stlxrh stlxp
1657
+ ldar ldarb ldarh stlr stlrb stlrh ldapr ldaprb ldaprh
1658
+ cas casa casl casal casp swp swpa swpl swpal
1659
+ ldadd ldadda ldaddl ldaddal ldclr ldeor ldset ldsmax ldsmin ldumax ldumin
1660
+ stadd stclr steor stset
1661
+ prfm prfum
1662
+ svc hvc smc brk hlt nop yield wfe wfi sev sevl isb dsb dmb
1663
+ mrs msr sys sysl ic dc tlbi at hint clrex
1664
+ paciasp autiasp pacibsp autibsp bti
1665
+ fmov fadd fsub fmul fdiv fnmul fmadd fmsub fnmadd fnmsub fneg fabs fsqrt
1666
+ fmax fmin fmaxnm fminnm fcmp fcmpe fccmp fccmpe fcsel
1667
+ fcvt fcvtzs fcvtzu fcvtas fcvtau fcvtms fcvtmu fcvtns fcvtnu fcvtps fcvtpu
1668
+ scvtf ucvtf frinta frinti frintm frintn frintp frintx frintz
1669
+ ld1 ld2 ld3 ld4 ld1r st1 st2 st3 st4
1670
+ movi mvni dup ins umov smov ext zip1 zip2 uzp1 uzp2 trn1 trn2 tbl tbx
1671
+ addv addp uaddlv saddlv umaxv uminv smaxv sminv umaxp uminp smaxp sminp
1672
+ cmeq cmge cmgt cmhi cmhs cmle cmlt cmtst
1673
+ mla mls uaddl uaddw usubl usubw saddl saddw ssubl ssubw
1674
+ shl ushr sshr ushl sshl uqadd sqadd uqsub sqsub
1675
+ xtn uxtl sxtl not bsl bit bif
1676
+ faddp fmaxv fminv fmla fmls frecpe frsqrte
1677
+ `);
1678
+
1679
+ /**
1680
+ The assembly language with the `arm64` dialect, which reads the GNU
1681
+ assembler as written for AArch64.
1682
+ */
1683
+ const arm64AssemblyLanguage = /*@__PURE__*/assemblyLanguage.configure({ dialect: "arm64" }, "arm64-assembly");
1684
+ /**
1685
+ Snippets for the common shapes of an AArch64 program.
1686
+ */
1687
+ const snippets$1 = [
1688
+ /*@__PURE__*/snippetCompletion(".text\n.globl ${name}\n${name}:\n\t${}\n\tret", {
1689
+ label: ".text",
1690
+ detail: "with a global function",
1691
+ type: "keyword"
1692
+ }),
1693
+ /*@__PURE__*/snippetCompletion(".data\n${name}: .asciz ${\"text\"}\n.equ ${name}_len, . - ${name}", {
1694
+ label: ".data",
1695
+ detail: "with a string",
1696
+ type: "keyword"
1697
+ }),
1698
+ /*@__PURE__*/snippetCompletion(".bss\n${name}: .skip ${64}", {
1699
+ label: ".bss",
1700
+ detail: "with a buffer",
1701
+ type: "keyword"
1702
+ }),
1703
+ /*@__PURE__*/snippetCompletion("${name}:\n\tstp x29, x30, [sp, #-16]!\n\tmov x29, sp\n\t${}\n\tldp x29, x30, [sp], #16\n\tret", {
1704
+ label: "function",
1705
+ detail: "with prologue and epilogue",
1706
+ type: "keyword"
1707
+ }),
1708
+ /*@__PURE__*/snippetCompletion("\tmov x9, #${count}\n1:\n\t${}\n\tsubs x9, x9, #1\n\tb.ne 1b", {
1709
+ label: "loop",
1710
+ detail: "counting down x9",
1711
+ type: "keyword"
1712
+ }),
1713
+ /*@__PURE__*/snippetCompletion("\tcmp ${x0}, #${0}\n\tb.${eq} ${label}", {
1714
+ label: "cmp",
1715
+ detail: "and branch",
1716
+ type: "keyword"
1717
+ }),
1718
+ /*@__PURE__*/snippetCompletion("\tcbz ${x0}, ${label}", {
1719
+ label: "cbz",
1720
+ detail: "branch if zero",
1721
+ type: "keyword"
1722
+ }),
1723
+ /*@__PURE__*/snippetCompletion("\tadrp ${x0}, ${label}\n\tadd ${x0}, ${x0}, :lo12:${label}", {
1724
+ label: "adrp",
1725
+ detail: "load an address",
1726
+ type: "keyword"
1727
+ }),
1728
+ /*@__PURE__*/snippetCompletion(".macro ${name} ${arg}\n\t${}\n.endm", {
1729
+ label: ".macro",
1730
+ detail: "block",
1731
+ type: "keyword"
1732
+ })
1733
+ ];
1734
+ /**
1735
+ Completion for AArch64 in GNU assembler syntax. Where a statement starts it
1736
+ offers the AArch64 mnemonics, the GNU assembler's directives, the macros
1737
+ declared in the file and the snippets. In an operand it offers the
1738
+ registers, shifts, condition codes, and the labels, `.equ` constants and
1739
+ `.req` aliases declared in the file. A numeric label `1:` is offered as `1b`
1740
+ below it and `1f` above it.
1741
+ */
1742
+ const arm64Completion = /*@__PURE__*/assemblyCompletionSource({
1743
+ mnemonics: MNEMONICS$1,
1744
+ directives: DIRECTIVES$2,
1745
+ registers: REGISTERS$2,
1746
+ sizeKeywords: [...SHIFTS, ...CONDITIONS$1],
1747
+ sections: SECTIONS,
1748
+ relocations: RELOCATIONS,
1749
+ snippets: snippets$1,
1750
+ labels: "gas"
1751
+ });
1752
+ /**
1753
+ Folding and indentation for the GNU assembler's blocks, and for a
1754
+ function's body under its label.
1755
+ */
1756
+ const arm64Layout = /*@__PURE__*/assemblyLayout({
1757
+ blocks: [
1758
+ { open: /^\.macro$/, close: /^\.endm$/ },
1759
+ { open: /^\.(rept|irpc?)$/, close: /^\.endr$/ },
1760
+ { open: /^\.if/, close: /^\.endif$/ }
1761
+ ],
1762
+ sectionBreaks: /^\.(section|text|data|bss|pushsection|popsection|globl|global|extern|type|size|equ|set)$/,
1763
+ labels: "gas",
1764
+ lineComments: ["//", "/*", ";"]
1765
+ });
1766
+ /**
1767
+ AArch64 assembly support for the GNU assembler, as used on Exercism's
1768
+ ARM64 Assembly track.
1769
+ */
1770
+ function arm64Assembly() {
1771
+ return new LanguageSupport(arm64AssemblyLanguage, [
1772
+ arm64AssemblyLanguage.data.of({
1773
+ autocomplete: arm64Completion,
1774
+ commentTokens: { line: "//", block: { open: "/*", close: "*/" } },
1775
+ // Typing the colon of a label or the end of a block moves it back to
1776
+ // the margin of its block.
1777
+ indentOnInput: /^\s*(\.endm|\.endr|\.endif|[\w$.\\@]+:)$/i
1778
+ }),
1779
+ arm64Layout
1780
+ ]);
1781
+ }
1782
+
1783
+ /** The MIPS32 instructions that MARS assembles, offered where a statement starts. */
1784
+ const INSTRUCTIONS = /*@__PURE__*/wordSet(`
1785
+ add addu addi addiu sub subu and andi or ori xor xori nor
1786
+ sll srl sra sllv srlv srav slt sltu slti sltiu lui
1787
+ mult multu div divu mfhi mflo mthi mtlo madd maddu msub msubu mul clo clz
1788
+ movn movz movf movt
1789
+ beq bne bgez bgezal bgtz blez bltz bltzal j jal jr jalr
1790
+ lb lbu lh lhu lw lwl lwr ll sb sh sw swl swr sc
1791
+ syscall break eret nop
1792
+ teq teqi tne tnei tge tgeu tgei tgeiu tlt tltu tlti tltiu
1793
+ mfc0 mtc0 mfc1 mtc1 lwc1 swc1 ldc1 sdc1 bc1t bc1f
1794
+ add.s add.d sub.s sub.d mul.s mul.d div.s div.d
1795
+ abs.s abs.d neg.s neg.d mov.s mov.d sqrt.s sqrt.d
1796
+ movn.s movn.d movz.s movz.d movf.s movf.d movt.s movt.d
1797
+ cvt.s.d cvt.d.s cvt.w.s cvt.w.d cvt.s.w cvt.d.w
1798
+ c.eq.s c.eq.d c.lt.s c.lt.d c.le.s c.le.d
1799
+ ceil.w.s ceil.w.d floor.w.s floor.w.d round.w.s round.w.d trunc.w.s trunc.w.d
1800
+ `);
1801
+ /** The pseudo-instructions that MARS expands into one or more instructions. */
1802
+ const PSEUDO_INSTRUCTIONS = /*@__PURE__*/wordSet(`
1803
+ li la move not neg negu abs
1804
+ b beqz bnez bge bgeu bgt bgtu ble bleu blt bltu
1805
+ subi subiu seq sne sge sgeu sgt sgtu sle sleu
1806
+ rem remu mulo mulou mulu rol ror
1807
+ ld sd ulw usw ulh ulhu ush
1808
+ l.s l.d s.s s.d
1809
+ `);
1810
+ const MNEMONICS = [...INSTRUCTIONS, ...PSEUDO_INSTRUCTIONS];
1811
+
1812
+ /**
1813
+ The assembly language with the `mips` dialect, which reads MIPS32 as the
1814
+ MARS simulator assembles it.
1815
+ */
1816
+ const mipsAssemblyLanguage = /*@__PURE__*/assemblyLanguage.configure({ dialect: "mips" }, "mips-assembly");
1817
+ /**
1818
+ Snippets for the common shapes of a MIPS program.
1819
+ */
1820
+ const snippets = [
1821
+ /*@__PURE__*/snippetCompletion(".text\n.globl ${name}\n${name}:\n\t${}\n\tjr $ra", {
1822
+ label: ".text",
1823
+ detail: "with a global function",
1824
+ type: "keyword"
1825
+ }),
1826
+ /*@__PURE__*/snippetCompletion(".data\n${name}: .asciiz ${\"text\"}", {
1827
+ label: ".data",
1828
+ detail: "with a string",
1829
+ type: "keyword"
1830
+ }),
1831
+ /*@__PURE__*/snippetCompletion("${name}:\n\taddi $sp, $sp, -8\n\tsw $ra, 4($sp)\n\tsw $s0, 0($sp)\n\t${}\n" +
1832
+ "\tlw $s0, 0($sp)\n\tlw $ra, 4($sp)\n\taddi $sp, $sp, 8\n\tjr $ra", {
1833
+ label: "function",
1834
+ detail: "with a stack frame",
1835
+ type: "keyword"
1836
+ }),
1837
+ /*@__PURE__*/snippetCompletion("\tli $t0, 0\n${loop}:\n\tbge $t0, ${count}, ${done}\n\t${}\n\taddi $t0, $t0, 1\n\tj ${loop}\n${done}:", {
1838
+ label: "loop",
1839
+ detail: "counting up $t0",
1840
+ type: "keyword"
1841
+ }),
1842
+ /*@__PURE__*/snippetCompletion("\tbne ${$t0}, ${$t1}, ${else}\n\t${}\n\tj ${done}\n${else}:\n\t\n${done}:", {
1843
+ label: "if",
1844
+ detail: "branch on equal and else",
1845
+ type: "keyword"
1846
+ }),
1847
+ /*@__PURE__*/snippetCompletion("\tli $v0, 4\n\tla $a0, ${msg}\n\tsyscall", {
1848
+ label: "print_string",
1849
+ detail: "syscall 4",
1850
+ type: "keyword"
1851
+ }),
1852
+ /*@__PURE__*/snippetCompletion("\tli $v0, 1\n\tmove $a0, ${$t0}\n\tsyscall", {
1853
+ label: "print_int",
1854
+ detail: "syscall 1",
1855
+ type: "keyword"
1856
+ }),
1857
+ /*@__PURE__*/snippetCompletion("\tli $v0, 5\n\tsyscall\n\tmove ${$t0}, $v0", {
1858
+ label: "read_int",
1859
+ detail: "syscall 5",
1860
+ type: "keyword"
1861
+ }),
1862
+ /*@__PURE__*/snippetCompletion("\tli $v0, 10\n\tsyscall", {
1863
+ label: "exit",
1864
+ detail: "syscall 10",
1865
+ type: "keyword"
1866
+ }),
1867
+ /*@__PURE__*/snippetCompletion(".macro ${name}(%${arg})\n\t${}\n.end_macro", {
1868
+ label: ".macro",
1869
+ detail: "block",
1870
+ type: "keyword"
1871
+ })
1872
+ ];
1873
+ /**
1874
+ Completion for MIPS32 as MARS assembles it. Where a statement starts it
1875
+ offers the instructions and pseudo-instructions, the directives, the
1876
+ macros declared in the file and the snippets. In an operand it offers the
1877
+ registers, and the labels and `.eqv` constants declared in the file. After
1878
+ `%` inside a macro, it offers the macro's parameters.
1879
+ */
1880
+ const mipsCompletion = /*@__PURE__*/assemblyCompletionSource({
1881
+ mnemonics: MNEMONICS,
1882
+ directives: DIRECTIVES$1,
1883
+ registers: WRITTEN_REGISTERS,
1884
+ snippets,
1885
+ labels: "gas"
1886
+ });
1887
+ /**
1888
+ Folding and indentation for MARS macros, and for a function's body under
1889
+ its label.
1890
+ */
1891
+ const mipsLayout = /*@__PURE__*/assemblyLayout({
1892
+ blocks: [{ open: /^\.macro$/, close: /^\.end_macro$/ }],
1893
+ sectionBreaks: /^\.(text|data|ktext|kdata|globl|extern|eqv|include)$/,
1894
+ labels: "gas",
1895
+ lineComments: ["#"]
1896
+ });
1897
+ /**
1898
+ MIPS32 assembly support for MARS, as used on Exercism's MIPS Assembly
1899
+ track.
1900
+ */
1901
+ function mipsAssembly() {
1902
+ return new LanguageSupport(mipsAssemblyLanguage, [
1903
+ mipsAssemblyLanguage.data.of({
1904
+ autocomplete: mipsCompletion,
1905
+ commentTokens: { line: "#" },
1906
+ // Typing the colon of a label or the end of a macro moves it back to the
1907
+ // margin of its block.
1908
+ indentOnInput: /^\s*(\.end_macro|[\w$.]+:)$/i
1909
+ }),
1910
+ mipsLayout
1911
+ ]);
1912
+ }
1913
+
1914
+ export { arm64Assembly, arm64AssemblyLanguage, arm64Completion, arm64Layout, snippets$1 as arm64Snippets, assembly, assemblyCompletion, assemblyCompletionSource, assemblyLanguage, assemblyLayout, declaredNames, mipsAssembly, mipsAssemblyLanguage, mipsCompletion, mipsLayout, snippets as mipsSnippets, namesInScope, parser, x86_64Assembly, x86_64AssemblyLanguage, x86_64Completion, x86_64Layout, snippets$2 as x86_64Snippets };