mipsasm.js 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. module.exports = function(hljs) {
  2. //local labels: %?[FB]?[AT]?\d{1,2}\w+
  3. return {
  4. case_insensitive: true,
  5. aliases: ['mips'],
  6. lexemes: '\\.?' + hljs.IDENT_RE,
  7. keywords: {
  8. meta:
  9. //GNU preprocs
  10. '.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 .ltorg ',
  11. built_in:
  12. '$0 $1 $2 $3 $4 $5 $6 $7 $8 $9 $10 $11 $12 $13 $14 $15 ' + // integer registers
  13. '$16 $17 $18 $19 $20 $21 $22 $23 $24 $25 $26 $27 $28 $29 $30 $31 ' + // integer registers
  14. 'zero at v0 v1 a0 a1 a2 a3 a4 a5 a6 a7 ' + // integer register aliases
  15. 't0 t1 t2 t3 t4 t5 t6 t7 t8 t9 s0 s1 s2 s3 s4 s5 s6 s7 s8 ' + // integer register aliases
  16. 'k0 k1 gp sp fp ra ' + // integer register aliases
  17. '$f0 $f1 $f2 $f2 $f4 $f5 $f6 $f7 $f8 $f9 $f10 $f11 $f12 $f13 $f14 $f15 ' + // floating-point registers
  18. '$f16 $f17 $f18 $f19 $f20 $f21 $f22 $f23 $f24 $f25 $f26 $f27 $f28 $f29 $f30 $f31 ' + // floating-point registers
  19. 'Context Random EntryLo0 EntryLo1 Context PageMask Wired EntryHi ' + // Coprocessor 0 registers
  20. 'HWREna BadVAddr Count Compare SR IntCtl SRSCtl SRSMap Cause EPC PRId ' + // Coprocessor 0 registers
  21. 'EBase Config Config1 Config2 Config3 LLAddr Debug DEPC DESAVE CacheErr ' + // Coprocessor 0 registers
  22. 'ECC ErrorEPC TagLo DataLo TagHi DataHi WatchLo WatchHi PerfCtl PerfCnt ' // Coprocessor 0 registers
  23. },
  24. contains: [
  25. {
  26. className: 'keyword',
  27. begin: '\\b('+ //mnemonics
  28. // 32-bit integer instructions
  29. 'addi?u?|andi?|b(al)?|beql?|bgez(al)?l?|bgtzl?|blezl?|bltz(al)?l?|' +
  30. 'bnel?|cl[oz]|divu?|ext|ins|j(al)?|jalr(\.hb)?|jr(\.hb)?|lbu?|lhu?|' +
  31. 'll|lui|lw[lr]?|maddu?|mfhi|mflo|movn|movz|move|msubu?|mthi|mtlo|mul|' +
  32. 'multu?|nop|nor|ori?|rotrv?|sb|sc|se[bh]|sh|sllv?|slti?u?|srav?|' +
  33. 'srlv?|subu?|sw[lr]?|xori?|wsbh|' +
  34. // floating-point instructions
  35. 'abs\.[sd]|add\.[sd]|alnv.ps|bc1[ft]l?|' +
  36. 'c\.(s?f|un|u?eq|[ou]lt|[ou]le|ngle?|seq|l[et]|ng[et])\.[sd]|' +
  37. '(ceil|floor|round|trunc)\.[lw]\.[sd]|cfc1|cvt\.d\.[lsw]|' +
  38. 'cvt\.l\.[dsw]|cvt\.ps\.s|cvt\.s\.[dlw]|cvt\.s\.p[lu]|cvt\.w\.[dls]|' +
  39. 'div\.[ds]|ldx?c1|luxc1|lwx?c1|madd\.[sd]|mfc1|mov[fntz]?\.[ds]|' +
  40. 'msub\.[sd]|mth?c1|mul\.[ds]|neg\.[ds]|nmadd\.[ds]|nmsub\.[ds]|' +
  41. 'p[lu][lu]\.ps|recip\.fmt|r?sqrt\.[ds]|sdx?c1|sub\.[ds]|suxc1|' +
  42. 'swx?c1|' +
  43. // system control instructions
  44. 'break|cache|d?eret|[de]i|ehb|mfc0|mtc0|pause|prefx?|rdhwr|' +
  45. 'rdpgpr|sdbbp|ssnop|synci?|syscall|teqi?|tgei?u?|tlb(p|r|w[ir])|' +
  46. 'tlti?u?|tnei?|wait|wrpgpr'+
  47. ')',
  48. end: '\\s'
  49. },
  50. // lines ending with ; or # aren't really comments, probably auto-detect fail
  51. hljs.COMMENT('[;#](?!\s*$)', '$'),
  52. hljs.C_BLOCK_COMMENT_MODE,
  53. hljs.QUOTE_STRING_MODE,
  54. {
  55. className: 'string',
  56. begin: '\'',
  57. end: '[^\\\\]\'',
  58. relevance: 0
  59. },
  60. {
  61. className: 'title',
  62. begin: '\\|', end: '\\|',
  63. illegal: '\\n',
  64. relevance: 0
  65. },
  66. {
  67. className: 'number',
  68. variants: [
  69. {begin: '0x[0-9a-f]+'}, //hex
  70. {begin: '\\b-?\\d+'} //bare number
  71. ],
  72. relevance: 0
  73. },
  74. {
  75. className: 'symbol',
  76. variants: [
  77. {begin: '^\\s*[a-z_\\.\\$][a-z0-9_\\.\\$]+:'}, //GNU MIPS syntax
  78. {begin: '^\\s*[0-9]+:'}, // numbered local labels
  79. {begin: '[0-9]+[bf]' } // number local label reference (backwards, forwards)
  80. ],
  81. relevance: 0
  82. }
  83. ],
  84. illegal: '\/'
  85. };
  86. };