-
Notifications
You must be signed in to change notification settings - Fork 221
Expand file tree
/
Copy pathmode-asm.ts
More file actions
73 lines (61 loc) · 2.96 KB
/
mode-asm.ts
File metadata and controls
73 lines (61 loc) · 2.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
import CodeMirror from 'codemirror';
import instructionsRegex from './mode-asm-instructions';
CodeMirror.defineMode('asm', () => {
const grammar = {
builtin: instructionsRegex
};
const specifiers = [ 'byte', 'dword', 'ptr', 'qword', 'short', 'tbyte', 'word' ];
// In order to match longest possible register name, this array is pre-sorted using naturalSort function:
// https://github.com/Bill4Time/javascript-natural-sort/blob/master/naturalSort.js
const registers = [ 'xmm15', 'xmm14', 'xmm13', 'xmm12', 'xmm11', 'xmm10', 'xmm9', 'xmm8', 'xmm7', 'xmm6', 'xmm5',
'xmm4', 'xmm3', 'xmm2', 'xmm1', 'xmm0', 'st7', 'st6', 'st5', 'st4', 'st3', 'st2', 'st1', 'st0', 'ss', 'spl', 'sp',
'sil', 'si', 'rsp', 'rsi', 'rip', 'rdx', 'rdi', 'rcx', 'rbx', 'rbp', 'rax', 'r15w', 'r15d', 'r15b', 'r15', 'r14w',
'r14d', 'r14b', 'r14', 'r13w', 'r13d', 'r13b', 'r13', 'r12w', 'r12d', 'r12b', 'r12', 'r11w', 'r11d', 'r11b', 'r11',
'r10w', 'r10d', 'r10b', 'r10', 'r9w', 'r9d', 'r9b', 'r9', 'r8w', 'r8d', 'r8b', 'r8', 'mm7', 'mm6', 'mm5', 'mm4',
'mm3', 'mm2', 'mm1', 'mm0', 'ip', 'gs', 'fs', 'fp6', 'fp5', 'fp4', 'fp3', 'fp2', 'fp1', 'fp0', 'esp', 'esi', 'es',
'eip', 'eflags', 'edx', 'edi', 'ecx', 'ebx', 'ebp', 'eax', 'dx', 'ds', 'dl', 'dil', 'di', 'dh', 'cx', 'cs', 'cl',
'ch', 'bx', 'bpl', 'bp', 'bl', 'bh', 'ax', 'al', 'ah' ];
return {
startState() {
return {};
},
token(stream) {
if (stream.eatSpace() || stream.eat(/[[\]+-]/)) {
return null;
}
if (stream.eat(';')) {
stream.skipToEnd();
return 'comment';
}
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (stream.match(/L[0-9a-f]{4,}:?/)) {
return 'tag';
}
for (const index in specifiers) {
if (stream.match(specifiers[index], true, true)) {
return 'keyword';
}
}
for (const index in registers) {
if (stream.match(registers[index], true, true)) {
return 'type';
}
}
for (const key in grammar) {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (stream.match(grammar[key as keyof typeof grammar])) {
return key;
}
}
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (stream.match(/(0x)?[0-9a-f]+/)) {
return 'string';
}
stream.match(/\S+/);
return null;
}
};
});
CodeMirror.defineMIME('text/x-asm', 'asm');