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