armasm.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 = { variants: [
  11. hljs.COMMENT('^[ \\t]*(?=#)', '$', {
  12. relevance: 0,
  13. excludeBegin: true
  14. }),
  15. hljs.COMMENT('[;@]', '$', { relevance: 0 }),
  16. hljs.C_LINE_COMMENT_MODE,
  17. hljs.C_BLOCK_COMMENT_MODE
  18. ] };
  19. return {
  20. name: 'ARM Assembly',
  21. case_insensitive: true,
  22. aliases: [ 'arm' ],
  23. keywords: {
  24. $pattern: '\\.?' + hljs.IDENT_RE,
  25. meta:
  26. // GNU preprocs
  27. '.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 '
  28. // ARM directives
  29. + '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 ',
  30. built_in:
  31. 'r0 r1 r2 r3 r4 r5 r6 r7 r8 r9 r10 r11 r12 r13 r14 r15 ' // standard registers
  32. + 'w0 w1 w2 w3 w4 w5 w6 w7 w8 w9 w10 w11 w12 w13 w14 w15 ' // 32 bit ARMv8 registers
  33. + 'w16 w17 w18 w19 w20 w21 w22 w23 w24 w25 w26 w27 w28 w29 w30 '
  34. + 'x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 ' // 64 bit ARMv8 registers
  35. + 'x16 x17 x18 x19 x20 x21 x22 x23 x24 x25 x26 x27 x28 x29 x30 '
  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. { // bin
  94. begin: '[#$=]?0b[01]+' },
  95. { // literal
  96. begin: '[#$=]\\d+' },
  97. { // bare number
  98. begin: '\\b\\d+' }
  99. ],
  100. relevance: 0
  101. },
  102. {
  103. className: 'symbol',
  104. variants: [
  105. { // GNU ARM syntax
  106. begin: '^[ \\t]*[a-z_\\.\\$][a-z0-9_\\.\\$]+:' },
  107. { // ARM syntax
  108. begin: '^[a-z_\\.\\$][a-z0-9_\\.\\$]+' },
  109. { // label reference
  110. begin: '[=#]\\w+' }
  111. ],
  112. relevance: 0
  113. }
  114. ]
  115. };
  116. }
  117. export { armasm as default };