armasm.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. Language: ARM Assembly
  3. Author: Dan Panzarella <alsoelp@gmail.com>
  4. Description: ARM Assembly including Thumb and Thumb2 instructions
  5. Category: assembler
  6. */
  7. /** @type LanguageFn */
  8. function armasm(hljs) {
  9. // local labels: %?[FB]?[AT]?\d{1,2}\w+
  10. const COMMENT = {
  11. variants: [
  12. hljs.COMMENT('^[ \\t]*(?=#)', '$', {
  13. relevance: 0,
  14. excludeBegin: true
  15. }),
  16. hljs.COMMENT('[;@]', '$', {
  17. relevance: 0
  18. }),
  19. hljs.C_LINE_COMMENT_MODE,
  20. hljs.C_BLOCK_COMMENT_MODE
  21. ]
  22. };
  23. return {
  24. name: 'ARM Assembly',
  25. case_insensitive: true,
  26. aliases: ['arm'],
  27. keywords: {
  28. $pattern: '\\.?' + hljs.IDENT_RE,
  29. meta:
  30. // GNU preprocs
  31. '.2byte .4byte .align .ascii .asciz .balign .byte .code .data .else .end .endif .endm .endr .equ .err .exitm .extern .global .hword .if .ifdef .ifndef .include .irp .long .macro .rept .req .section .set .skip .space .text .word .arm .thumb .code16 .code32 .force_thumb .thumb_func .ltorg ' +
  32. // ARM directives
  33. 'ALIAS ALIGN ARM AREA ASSERT ATTR CN CODE CODE16 CODE32 COMMON CP DATA DCB DCD DCDU DCDO DCFD DCFDU DCI DCQ DCQU DCW DCWU DN ELIF ELSE END ENDFUNC ENDIF ENDP ENTRY EQU EXPORT EXPORTAS EXTERN FIELD FILL FUNCTION GBLA GBLL GBLS GET GLOBAL IF IMPORT INCBIN INCLUDE INFO KEEP LCLA LCLL LCLS LTORG MACRO MAP MEND MEXIT NOFP OPT PRESERVE8 PROC QN READONLY RELOC REQUIRE REQUIRE8 RLIST FN ROUT SETA SETL SETS SN SPACE SUBT THUMB THUMBX TTL WHILE WEND ',
  34. built_in:
  35. 'r0 r1 r2 r3 r4 r5 r6 r7 r8 r9 r10 r11 r12 r13 r14 r15 ' + // standard registers
  36. 'pc lr sp ip sl sb fp ' + // typical regs plus backward compatibility
  37. 'a1 a2 a3 a4 v1 v2 v3 v4 v5 v6 v7 v8 f0 f1 f2 f3 f4 f5 f6 f7 ' + // more regs and fp
  38. 'p0 p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 p12 p13 p14 p15 ' + // coprocessor regs
  39. 'c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12 c13 c14 c15 ' + // more coproc
  40. 'q0 q1 q2 q3 q4 q5 q6 q7 q8 q9 q10 q11 q12 q13 q14 q15 ' + // advanced SIMD NEON regs
  41. // program status registers
  42. 'cpsr_c cpsr_x cpsr_s cpsr_f cpsr_cx cpsr_cxs cpsr_xs cpsr_xsf cpsr_sf cpsr_cxsf ' +
  43. 'spsr_c spsr_x spsr_s spsr_f spsr_cx spsr_cxs spsr_xs spsr_xsf spsr_sf spsr_cxsf ' +
  44. // NEON and VFP registers
  45. 's0 s1 s2 s3 s4 s5 s6 s7 s8 s9 s10 s11 s12 s13 s14 s15 ' +
  46. 's16 s17 s18 s19 s20 s21 s22 s23 s24 s25 s26 s27 s28 s29 s30 s31 ' +
  47. 'd0 d1 d2 d3 d4 d5 d6 d7 d8 d9 d10 d11 d12 d13 d14 d15 ' +
  48. 'd16 d17 d18 d19 d20 d21 d22 d23 d24 d25 d26 d27 d28 d29 d30 d31 ' +
  49. '{PC} {VAR} {TRUE} {FALSE} {OPT} {CONFIG} {ENDIAN} {CODESIZE} {CPU} {FPU} {ARCHITECTURE} {PCSTOREOFFSET} {ARMASM_VERSION} {INTER} {ROPI} {RWPI} {SWST} {NOSWST} . @'
  50. },
  51. contains: [
  52. {
  53. className: 'keyword',
  54. begin: '\\b(' + // mnemonics
  55. 'adc|' +
  56. '(qd?|sh?|u[qh]?)?add(8|16)?|usada?8|(q|sh?|u[qh]?)?(as|sa)x|' +
  57. 'and|adrl?|sbc|rs[bc]|asr|b[lx]?|blx|bxj|cbn?z|tb[bh]|bic|' +
  58. 'bfc|bfi|[su]bfx|bkpt|cdp2?|clz|clrex|cmp|cmn|cpsi[ed]|cps|' +
  59. 'setend|dbg|dmb|dsb|eor|isb|it[te]{0,3}|lsl|lsr|ror|rrx|' +
  60. 'ldm(([id][ab])|f[ds])?|ldr((s|ex)?[bhd])?|movt?|mvn|mra|mar|' +
  61. 'mul|[us]mull|smul[bwt][bt]|smu[as]d|smmul|smmla|' +
  62. 'mla|umlaal|smlal?([wbt][bt]|d)|mls|smlsl?[ds]|smc|svc|sev|' +
  63. 'mia([bt]{2}|ph)?|mrr?c2?|mcrr2?|mrs|msr|orr|orn|pkh(tb|bt)|rbit|' +
  64. 'rev(16|sh)?|sel|[su]sat(16)?|nop|pop|push|rfe([id][ab])?|' +
  65. 'stm([id][ab])?|str(ex)?[bhd]?|(qd?)?sub|(sh?|q|u[qh]?)?sub(8|16)|' +
  66. '[su]xt(a?h|a?b(16)?)|srs([id][ab])?|swpb?|swi|smi|tst|teq|' +
  67. 'wfe|wfi|yield' +
  68. ')' +
  69. '(eq|ne|cs|cc|mi|pl|vs|vc|hi|ls|ge|lt|gt|le|al|hs|lo)?' + // condition codes
  70. '[sptrx]?' + // legal postfixes
  71. '(?=\\s)' // followed by space
  72. },
  73. COMMENT,
  74. hljs.QUOTE_STRING_MODE,
  75. {
  76. className: 'string',
  77. begin: '\'',
  78. end: '[^\\\\]\'',
  79. relevance: 0
  80. },
  81. {
  82. className: 'title',
  83. begin: '\\|',
  84. end: '\\|',
  85. illegal: '\\n',
  86. relevance: 0
  87. },
  88. {
  89. className: 'number',
  90. variants: [
  91. { // hex
  92. begin: '[#$=]?0x[0-9a-f]+'
  93. },
  94. { // bin
  95. begin: '[#$=]?0b[01]+'
  96. },
  97. { // literal
  98. begin: '[#$=]\\d+'
  99. },
  100. { // bare number
  101. begin: '\\b\\d+'
  102. }
  103. ],
  104. relevance: 0
  105. },
  106. {
  107. className: 'symbol',
  108. variants: [
  109. { // GNU ARM syntax
  110. begin: '^[ \\t]*[a-z_\\.\\$][a-z0-9_\\.\\$]+:'
  111. },
  112. { // ARM syntax
  113. begin: '^[a-z_\\.\\$][a-z0-9_\\.\\$]+'
  114. },
  115. { // label reference
  116. begin: '[=#]\\w+'
  117. }
  118. ],
  119. relevance: 0
  120. }
  121. ]
  122. };
  123. }
  124. module.exports = armasm;