Debian Codegraph @

codemirror-legacy-modes/mode/gas.js

raw
1 function mkGas(arch) {
2 // If an architecture is specified, its initialization function may
3 // populate this array with custom parsing functions which will be
4 // tried in the event that the standard functions do not find a match.
5 var custom = [];
6
7 // The symbol used to start a line comment changes based on the target
8 // architecture.
9 // If no architecture is pased in "parserConfig" then only multiline
10 // comments will have syntax support.
11 var lineCommentStartSymbol = "";
12
13 // These directives are architecture independent.
14 // Machine specific directives should go in their respective
15 // architecture initialization function.
16 // Reference:
17 // http://sourceware.org/binutils/docs/as/Pseudo-Ops.html#Pseudo-Ops
18 var directives = {
19 ".abort" : "builtin",
20 ".align" : "builtin",
21 ".altmacro" : "builtin",
22 ".ascii" : "builtin",
23 ".asciz" : "builtin",
24 ".balign" : "builtin",
25 ".balignw" : "builtin",
26 ".balignl" : "builtin",
27 ".bundle_align_mode" : "builtin",
28 ".bundle_lock" : "builtin",
29 ".bundle_unlock" : "builtin",
30 ".byte" : "builtin",
31 ".cfi_startproc" : "builtin",
32 ".comm" : "builtin",
33 ".data" : "builtin",
34 ".def" : "builtin",
35 ".desc" : "builtin",
36 ".dim" : "builtin",
37 ".double" : "builtin",
38 ".eject" : "builtin",
39 ".else" : "builtin",
40 ".elseif" : "builtin",
41 ".end" : "builtin",
42 ".endef" : "builtin",
43 ".endfunc" : "builtin",
44 ".endif" : "builtin",
45 ".equ" : "builtin",
46 ".equiv" : "builtin",
47 ".eqv" : "builtin",
48 ".err" : "builtin",
49 ".error" : "builtin",
50 ".exitm" : "builtin",
51 ".extern" : "builtin",
52 ".fail" : "builtin",
53 ".file" : "builtin",
54 ".fill" : "builtin",
55 ".float" : "builtin",
56 ".func" : "builtin",
57 ".global" : "builtin",
58 ".gnu_attribute" : "builtin",
59 ".hidden" : "builtin",
60 ".hword" : "builtin",
61 ".ident" : "builtin",
62 ".if" : "builtin",
63 ".incbin" : "builtin",
64 ".include" : "builtin",
65 ".int" : "builtin",
66 ".internal" : "builtin",
67 ".irp" : "builtin",
68 ".irpc" : "builtin",
69 ".lcomm" : "builtin",
70 ".lflags" : "builtin",
71 ".line" : "builtin",
72 ".linkonce" : "builtin",
73 ".list" : "builtin",
74 ".ln" : "builtin",
75 ".loc" : "builtin",
76 ".loc_mark_labels" : "builtin",
77 ".local" : "builtin",
78 ".long" : "builtin",
79 ".macro" : "builtin",
80 ".mri" : "builtin",
81 ".noaltmacro" : "builtin",
82 ".nolist" : "builtin",
83 ".octa" : "builtin",
84 ".offset" : "builtin",
85 ".org" : "builtin",
86 ".p2align" : "builtin",
87 ".popsection" : "builtin",
88 ".previous" : "builtin",
89 ".print" : "builtin",
90 ".protected" : "builtin",
91 ".psize" : "builtin",
92 ".purgem" : "builtin",
93 ".pushsection" : "builtin",
94 ".quad" : "builtin",
95 ".reloc" : "builtin",
96 ".rept" : "builtin",
97 ".sbttl" : "builtin",
98 ".scl" : "builtin",
99 ".section" : "builtin",
100 ".set" : "builtin",
101 ".short" : "builtin",
102 ".single" : "builtin",
103 ".size" : "builtin",
104 ".skip" : "builtin",
105 ".sleb128" : "builtin",
106 ".space" : "builtin",
107 ".stab" : "builtin",
108 ".string" : "builtin",
109 ".struct" : "builtin",
110 ".subsection" : "builtin",
111 ".symver" : "builtin",
112 ".tag" : "builtin",
113 ".text" : "builtin",
114 ".title" : "builtin",
115 ".type" : "builtin",
116 ".uleb128" : "builtin",
117 ".val" : "builtin",
118 ".version" : "builtin",
119 ".vtable_entry" : "builtin",
120 ".vtable_inherit" : "builtin",
121 ".warning" : "builtin",
122 ".weak" : "builtin",
123 ".weakref" : "builtin",
124 ".word" : "builtin"
125 };
126
127 var registers = {};
128
129 function x86() {
130 lineCommentStartSymbol = "#";
131
132 registers.al = "variable";
133 registers.ah = "variable";
134 registers.ax = "variable";
135 registers.eax = "variableName.special";
136 registers.rax = "variableName.special";
137
138 registers.bl = "variable";
139 registers.bh = "variable";
140 registers.bx = "variable";
141 registers.ebx = "variableName.special";
142 registers.rbx = "variableName.special";
143
144 registers.cl = "variable";
145 registers.ch = "variable";
146 registers.cx = "variable";
147 registers.ecx = "variableName.special";
148 registers.rcx = "variableName.special";
149
150 registers.dl = "variable";
151 registers.dh = "variable";
152 registers.dx = "variable";
153 registers.edx = "variableName.special";
154 registers.rdx = "variableName.special";
155
156 registers.si = "variable";
157 registers.esi = "variableName.special";
158 registers.rsi = "variableName.special";
159
160 registers.di = "variable";
161 registers.edi = "variableName.special";
162 registers.rdi = "variableName.special";
163
164 registers.sp = "variable";
165 registers.esp = "variableName.special";
166 registers.rsp = "variableName.special";
167
168 registers.bp = "variable";
169 registers.ebp = "variableName.special";
170 registers.rbp = "variableName.special";
171
172 registers.ip = "variable";
173 registers.eip = "variableName.special";
174 registers.rip = "variableName.special";
175
176 registers.cs = "keyword";
177 registers.ds = "keyword";
178 registers.ss = "keyword";
179 registers.es = "keyword";
180 registers.fs = "keyword";
181 registers.gs = "keyword";
182 }
183
184 function armv6() {
185 // Reference:
186 // http://infocenter.arm.com/help/topic/com.arm.doc.qrc0001l/QRC0001_UAL.pdf
187 // http://infocenter.arm.com/help/topic/com.arm.doc.ddi0301h/DDI0301H_arm1176jzfs_r0p7_trm.pdf
188 lineCommentStartSymbol = "@";
189 directives.syntax = "builtin";
190
191 registers.r0 = "variable";
192 registers.r1 = "variable";
193 registers.r2 = "variable";
194 registers.r3 = "variable";
195 registers.r4 = "variable";
196 registers.r5 = "variable";
197 registers.r6 = "variable";
198 registers.r7 = "variable";
199 registers.r8 = "variable";
200 registers.r9 = "variable";
201 registers.r10 = "variable";
202 registers.r11 = "variable";
203 registers.r12 = "variable";
204
205 registers.sp = "variableName.special";
206 registers.lr = "variableName.special";
207 registers.pc = "variableName.special";
208 registers.r13 = registers.sp;
209 registers.r14 = registers.lr;
210 registers.r15 = registers.pc;
211
212 custom.push(function(ch, stream) {
213 if (ch === '#') {
214 stream.eatWhile(/\w/);
215 return "number";
216 }
217 });
218 }
219
220 if (arch === "x86") {
221 x86();
222 } else if (arch === "arm" || arch === "armv6") {
223 armv6();
224 }
225
226 function nextUntilUnescaped(stream, end) {
227 var escaped = false, next;
228 while ((next = stream.next()) != null) {
229 if (next === end && !escaped) {
230 return false;
231 }
232 escaped = !escaped && next === "\\";
233 }
234 return escaped;
235 }
236
237 function clikeComment(stream, state) {
238 var maybeEnd = false, ch;
239 while ((ch = stream.next()) != null) {
240 if (ch === "/" && maybeEnd) {
241 state.tokenize = null;
242 break;
243 }
244 maybeEnd = (ch === "*");
245 }
246 return "comment";
247 }
248
249 return {
250 name: "gas",
251 startState: function() {
252 return {
253 tokenize: null
254 };
255 },
256
257 token: function(stream, state) {
258 if (state.tokenize) {
259 return state.tokenize(stream, state);
260 }
261
262 if (stream.eatSpace()) {
263 return null;
264 }
265
266 var style, cur, ch = stream.next();
267
268 if (ch === "/") {
269 if (stream.eat("*")) {
270 state.tokenize = clikeComment;
271 return clikeComment(stream, state);
272 }
273 }
274
275 if (ch === lineCommentStartSymbol) {
276 stream.skipToEnd();
277 return "comment";
278 }
279
280 if (ch === '"') {
281 nextUntilUnescaped(stream, '"');
282 return "string";
283 }
284
285 if (ch === '.') {
286 stream.eatWhile(/\w/);
287 cur = stream.current().toLowerCase();
288 style = directives[cur];
289 return style || null;
290 }
291
292 if (ch === '=') {
293 stream.eatWhile(/\w/);
294 return "tag";
295 }
296
297 if (ch === '{') {
298 return "bracket";
299 }
300
301 if (ch === '}') {
302 return "bracket";
303 }
304
305 if (/\d/.test(ch)) {
306 if (ch === "0" && stream.eat("x")) {
307 stream.eatWhile(/[0-9a-fA-F]/);
308 return "number";
309 }
310 stream.eatWhile(/\d/);
311 return "number";
312 }
313
314 if (/\w/.test(ch)) {
315 stream.eatWhile(/\w/);
316 if (stream.eat(":")) {
317 return 'tag';
318 }
319 cur = stream.current().toLowerCase();
320 style = registers[cur];
321 return style || null;
322 }
323
324 for (var i = 0; i < custom.length; i++) {
325 style = custom[i](ch, stream, state);
326 if (style) {
327 return style;
328 }
329 }
330 },
331
332 languageData: {
333 commentTokens: {
334 line: lineCommentStartSymbol,
335 block: {open: "/*", close: "*/"}
336 }
337 }
338 };
339 };
340
341 export const gas = mkGas("x86")
342 export const gasArm = mkGas("arm")