1 CodeMirror.defineMode("gas", function(_config, parserConfig) {
4 // If an architecture is specified, its initialization function may
5 // populate this array with custom parsing functions which will be
6 // tried in the event that the standard functions do not find a match.
9 // The symbol used to start a line comment changes based on the target
11 // If no architecture is pased in "parserConfig" then only multiline
12 // comments will have syntax support.
13 var lineCommentStartSymbol = "";
15 // These directives are architecture independent.
16 // Machine specific directives should go in their respective
17 // architecture initialization function.
19 // http://sourceware.org/binutils/docs/as/Pseudo-Ops.html#Pseudo-Ops
23 ".altmacro" : "builtin",
26 ".balign" : "builtin",
27 ".balignw" : "builtin",
28 ".balignl" : "builtin",
29 ".bundle_align_mode" : "builtin",
30 ".bundle_lock" : "builtin",
31 ".bundle_unlock" : "builtin",
33 ".cfi_startproc" : "builtin",
39 ".double" : "builtin",
42 ".elseif" : "builtin",
45 ".endfunc" : "builtin",
53 ".extern" : "builtin",
59 ".global" : "builtin",
60 ".gnu_attribute" : "builtin",
61 ".hidden" : "builtin",
65 ".incbin" : "builtin",
66 ".include" : "builtin",
68 ".internal" : "builtin",
72 ".lflags" : "builtin",
74 ".linkonce" : "builtin",
78 ".loc_mark_labels" : "builtin",
83 ".noaltmacro" : "builtin",
84 ".nolist" : "builtin",
86 ".offset" : "builtin",
88 ".p2align" : "builtin",
89 ".popsection" : "builtin",
90 ".previous" : "builtin",
92 ".protected" : "builtin",
94 ".purgem" : "builtin",
95 ".pushsection" : "builtin",
101 ".section" : "builtin",
103 ".short" : "builtin",
104 ".single" : "builtin",
107 ".sleb128" : "builtin",
108 ".space" : "builtin",
110 ".string" : "builtin",
111 ".struct" : "builtin",
112 ".subsection" : "builtin",
113 ".symver" : "builtin",
116 ".title" : "builtin",
118 ".uleb128" : "builtin",
120 ".version" : "builtin",
121 ".vtable_entry" : "builtin",
122 ".vtable_inherit" : "builtin",
123 ".warning" : "builtin",
125 ".weakref" : "builtin",
131 function x86(_parserConfig) {
132 lineCommentStartSymbol = "#";
134 registers.ax = "variable";
135 registers.eax = "variable-2";
136 registers.rax = "variable-3";
138 registers.bx = "variable";
139 registers.ebx = "variable-2";
140 registers.rbx = "variable-3";
142 registers.cx = "variable";
143 registers.ecx = "variable-2";
144 registers.rcx = "variable-3";
146 registers.dx = "variable";
147 registers.edx = "variable-2";
148 registers.rdx = "variable-3";
150 registers.si = "variable";
151 registers.esi = "variable-2";
152 registers.rsi = "variable-3";
154 registers.di = "variable";
155 registers.edi = "variable-2";
156 registers.rdi = "variable-3";
158 registers.sp = "variable";
159 registers.esp = "variable-2";
160 registers.rsp = "variable-3";
162 registers.bp = "variable";
163 registers.ebp = "variable-2";
164 registers.rbp = "variable-3";
166 registers.ip = "variable";
167 registers.eip = "variable-2";
168 registers.rip = "variable-3";
170 registers.cs = "keyword";
171 registers.ds = "keyword";
172 registers.ss = "keyword";
173 registers.es = "keyword";
174 registers.fs = "keyword";
175 registers.gs = "keyword";
178 function armv6(_parserConfig) {
180 // http://infocenter.arm.com/help/topic/com.arm.doc.qrc0001l/QRC0001_UAL.pdf
181 // http://infocenter.arm.com/help/topic/com.arm.doc.ddi0301h/DDI0301H_arm1176jzfs_r0p7_trm.pdf
182 lineCommentStartSymbol = "@";
183 directives.syntax = "builtin";
185 registers.r0 = "variable";
186 registers.r1 = "variable";
187 registers.r2 = "variable";
188 registers.r3 = "variable";
189 registers.r4 = "variable";
190 registers.r5 = "variable";
191 registers.r6 = "variable";
192 registers.r7 = "variable";
193 registers.r8 = "variable";
194 registers.r9 = "variable";
195 registers.r10 = "variable";
196 registers.r11 = "variable";
197 registers.r12 = "variable";
199 registers.sp = "variable-2";
200 registers.lr = "variable-2";
201 registers.pc = "variable-2";
202 registers.r13 = registers.sp;
203 registers.r14 = registers.lr;
204 registers.r15 = registers.pc;
206 custom.push(function(ch, stream) {
208 stream.eatWhile(/\w/);
214 var arch = parserConfig.architecture.toLowerCase();
215 if (arch === "x86") {
217 } else if (arch === "arm" || arch === "armv6") {
221 function nextUntilUnescaped(stream, end) {
222 var escaped = false, next;
223 while ((next = stream.next()) != null) {
224 if (next === end && !escaped) {
227 escaped = !escaped && next === "\\";
232 function clikeComment(stream, state) {
233 var maybeEnd = false, ch;
234 while ((ch = stream.next()) != null) {
235 if (ch === "/" && maybeEnd) {
236 state.tokenize = null;
239 maybeEnd = (ch === "*");
245 startState: function() {
251 token: function(stream, state) {
252 if (state.tokenize) {
253 return state.tokenize(stream, state);
256 if (stream.eatSpace()) {
260 var style, cur, ch = stream.next();
263 if (stream.eat("*")) {
264 state.tokenize = clikeComment;
265 return clikeComment(stream, state);
269 if (ch === lineCommentStartSymbol) {
275 nextUntilUnescaped(stream, '"');
280 stream.eatWhile(/\w/);
281 cur = stream.current().toLowerCase();
282 style = directives[cur];
283 return style || null;
287 stream.eatWhile(/\w/);
300 if (ch === "0" && stream.eat("x")) {
301 stream.eatWhile(/[0-9a-fA-F]/);
304 stream.eatWhile(/\d/);
309 stream.eatWhile(/\w/);
310 if (stream.eat(":")) {
313 cur = stream.current().toLowerCase();
314 style = registers[cur];
315 return style || null;
318 for (var i = 0; i < custom.length; i++) {
319 style = custom[i](ch, stream, state);
326 lineComment: lineCommentStartSymbol,
327 blockCommentStart: "/*",
328 blockCommentEnd: "*/"