Path: blob/master/web-gui/buildyourownbotnet/assets/js/codemirror/mode/gas/gas.js
1293 views
CodeMirror.defineMode("gas", function(_config, parserConfig) {1'use strict';23// If an architecture is specified, its initialization function may4// populate this array with custom parsing functions which will be5// tried in the event that the standard functions do not find a match.6var custom = [];78// The symbol used to start a line comment changes based on the target9// architecture.10// If no architecture is pased in "parserConfig" then only multiline11// comments will have syntax support.12var lineCommentStartSymbol = "";1314// These directives are architecture independent.15// Machine specific directives should go in their respective16// architecture initialization function.17// Reference:18// http://sourceware.org/binutils/docs/as/Pseudo-Ops.html#Pseudo-Ops19var directives = {20".abort" : "builtin",21".align" : "builtin",22".altmacro" : "builtin",23".ascii" : "builtin",24".asciz" : "builtin",25".balign" : "builtin",26".balignw" : "builtin",27".balignl" : "builtin",28".bundle_align_mode" : "builtin",29".bundle_lock" : "builtin",30".bundle_unlock" : "builtin",31".byte" : "builtin",32".cfi_startproc" : "builtin",33".comm" : "builtin",34".data" : "builtin",35".def" : "builtin",36".desc" : "builtin",37".dim" : "builtin",38".double" : "builtin",39".eject" : "builtin",40".else" : "builtin",41".elseif" : "builtin",42".end" : "builtin",43".endef" : "builtin",44".endfunc" : "builtin",45".endif" : "builtin",46".equ" : "builtin",47".equiv" : "builtin",48".eqv" : "builtin",49".err" : "builtin",50".error" : "builtin",51".exitm" : "builtin",52".extern" : "builtin",53".fail" : "builtin",54".file" : "builtin",55".fill" : "builtin",56".float" : "builtin",57".func" : "builtin",58".global" : "builtin",59".gnu_attribute" : "builtin",60".hidden" : "builtin",61".hword" : "builtin",62".ident" : "builtin",63".if" : "builtin",64".incbin" : "builtin",65".include" : "builtin",66".int" : "builtin",67".internal" : "builtin",68".irp" : "builtin",69".irpc" : "builtin",70".lcomm" : "builtin",71".lflags" : "builtin",72".line" : "builtin",73".linkonce" : "builtin",74".list" : "builtin",75".ln" : "builtin",76".loc" : "builtin",77".loc_mark_labels" : "builtin",78".local" : "builtin",79".long" : "builtin",80".macro" : "builtin",81".mri" : "builtin",82".noaltmacro" : "builtin",83".nolist" : "builtin",84".octa" : "builtin",85".offset" : "builtin",86".org" : "builtin",87".p2align" : "builtin",88".popsection" : "builtin",89".previous" : "builtin",90".print" : "builtin",91".protected" : "builtin",92".psize" : "builtin",93".purgem" : "builtin",94".pushsection" : "builtin",95".quad" : "builtin",96".reloc" : "builtin",97".rept" : "builtin",98".sbttl" : "builtin",99".scl" : "builtin",100".section" : "builtin",101".set" : "builtin",102".short" : "builtin",103".single" : "builtin",104".size" : "builtin",105".skip" : "builtin",106".sleb128" : "builtin",107".space" : "builtin",108".stab" : "builtin",109".string" : "builtin",110".struct" : "builtin",111".subsection" : "builtin",112".symver" : "builtin",113".tag" : "builtin",114".text" : "builtin",115".title" : "builtin",116".type" : "builtin",117".uleb128" : "builtin",118".val" : "builtin",119".version" : "builtin",120".vtable_entry" : "builtin",121".vtable_inherit" : "builtin",122".warning" : "builtin",123".weak" : "builtin",124".weakref" : "builtin",125".word" : "builtin"126};127128var registers = {};129130function x86(_parserConfig) {131lineCommentStartSymbol = "#";132133registers.ax = "variable";134registers.eax = "variable-2";135registers.rax = "variable-3";136137registers.bx = "variable";138registers.ebx = "variable-2";139registers.rbx = "variable-3";140141registers.cx = "variable";142registers.ecx = "variable-2";143registers.rcx = "variable-3";144145registers.dx = "variable";146registers.edx = "variable-2";147registers.rdx = "variable-3";148149registers.si = "variable";150registers.esi = "variable-2";151registers.rsi = "variable-3";152153registers.di = "variable";154registers.edi = "variable-2";155registers.rdi = "variable-3";156157registers.sp = "variable";158registers.esp = "variable-2";159registers.rsp = "variable-3";160161registers.bp = "variable";162registers.ebp = "variable-2";163registers.rbp = "variable-3";164165registers.ip = "variable";166registers.eip = "variable-2";167registers.rip = "variable-3";168169registers.cs = "keyword";170registers.ds = "keyword";171registers.ss = "keyword";172registers.es = "keyword";173registers.fs = "keyword";174registers.gs = "keyword";175}176177function armv6(_parserConfig) {178// Reference:179// http://infocenter.arm.com/help/topic/com.arm.doc.qrc0001l/QRC0001_UAL.pdf180// http://infocenter.arm.com/help/topic/com.arm.doc.ddi0301h/DDI0301H_arm1176jzfs_r0p7_trm.pdf181lineCommentStartSymbol = "@";182directives.syntax = "builtin";183184registers.r0 = "variable";185registers.r1 = "variable";186registers.r2 = "variable";187registers.r3 = "variable";188registers.r4 = "variable";189registers.r5 = "variable";190registers.r6 = "variable";191registers.r7 = "variable";192registers.r8 = "variable";193registers.r9 = "variable";194registers.r10 = "variable";195registers.r11 = "variable";196registers.r12 = "variable";197198registers.sp = "variable-2";199registers.lr = "variable-2";200registers.pc = "variable-2";201registers.r13 = registers.sp;202registers.r14 = registers.lr;203registers.r15 = registers.pc;204205custom.push(function(ch, stream) {206if (ch === '#') {207stream.eatWhile(/\w/);208return "number";209}210});211}212213var arch = parserConfig.architecture.toLowerCase();214if (arch === "x86") {215x86(parserConfig);216} else if (arch === "arm" || arch === "armv6") {217armv6(parserConfig);218}219220function nextUntilUnescaped(stream, end) {221var escaped = false, next;222while ((next = stream.next()) != null) {223if (next === end && !escaped) {224return false;225}226escaped = !escaped && next === "\\";227}228return escaped;229}230231function clikeComment(stream, state) {232var maybeEnd = false, ch;233while ((ch = stream.next()) != null) {234if (ch === "/" && maybeEnd) {235state.tokenize = null;236break;237}238maybeEnd = (ch === "*");239}240return "comment";241}242243return {244startState: function() {245return {246tokenize: null247};248},249250token: function(stream, state) {251if (state.tokenize) {252return state.tokenize(stream, state);253}254255if (stream.eatSpace()) {256return null;257}258259var style, cur, ch = stream.next();260261if (ch === "/") {262if (stream.eat("*")) {263state.tokenize = clikeComment;264return clikeComment(stream, state);265}266}267268if (ch === lineCommentStartSymbol) {269stream.skipToEnd();270return "comment";271}272273if (ch === '"') {274nextUntilUnescaped(stream, '"');275return "string";276}277278if (ch === '.') {279stream.eatWhile(/\w/);280cur = stream.current().toLowerCase();281style = directives[cur];282return style || null;283}284285if (ch === '=') {286stream.eatWhile(/\w/);287return "tag";288}289290if (ch === '{') {291return "braket";292}293294if (ch === '}') {295return "braket";296}297298if (/\d/.test(ch)) {299if (ch === "0" && stream.eat("x")) {300stream.eatWhile(/[0-9a-fA-F]/);301return "number";302}303stream.eatWhile(/\d/);304return "number";305}306307if (/\w/.test(ch)) {308stream.eatWhile(/\w/);309if (stream.eat(":")) {310return 'tag';311}312cur = stream.current().toLowerCase();313style = registers[cur];314return style || null;315}316317for (var i = 0; i < custom.length; i++) {318style = custom[i](ch, stream, state);319if (style) {320return style;321}322}323},324325lineComment: lineCommentStartSymbol,326blockCommentStart: "/*",327blockCommentEnd: "*/"328};329});330331332