From 1838a9da475f163cec7ec6e599b0ec1620bd6cc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Park=20=28=EB=B0=95=EC=84=B1=EB=B2=94=29?= Date: Sat, 5 Oct 2024 11:59:54 +0900 Subject: [PATCH] feat: add MIPS Assembly language (#95) --- packages/tm-grammars/README.md | 1 + packages/tm-grammars/grammars/mipsasm.json | 125 ++++++++++++++++++++ packages/tm-grammars/index.js | 13 +++ packages/tm-grammars/raw/mipsasm.json | 127 +++++++++++++++++++++ samples/mipsasm.sample | 24 ++++ sources-grammars.ts | 6 + 6 files changed, 296 insertions(+) create mode 100644 packages/tm-grammars/grammars/mipsasm.json create mode 100644 packages/tm-grammars/raw/mipsasm.json create mode 100644 samples/mipsasm.sample diff --git a/packages/tm-grammars/README.md b/packages/tm-grammars/README.md index 77047d2..6c503db 100644 --- a/packages/tm-grammars/README.md +++ b/packages/tm-grammars/README.md @@ -138,6 +138,7 @@ import { grammars } from 'tm-grammars' | `mdc` | | [nuxtlabs/vscode-mdc](https://github.com/nuxtlabs/vscode-mdc/blob/6294dbce9706f538a521e7dccce9609e928dc3be/syntaxes/mdc.tmLanguage.json) | [MIT](https://raw.githubusercontent.com/nuxtlabs/vscode-mdc/main/LICENSE) | `markdown` `yaml` `html-derivative` | 18.85 kB | | `mdx` | | [wooorm/markdown-tm-language](https://github.com/wooorm/markdown-tm-language/blob/5caa71e2bbddea59b27c6a5a346881cd10fa0f5f/source.mdx.tmLanguage) | [MIT](https://raw.githubusercontent.com/wooorm/markdown-tm-language/main/license) | `tsx` `toml` `yaml` `c` `clojure` `coffee` `cpp` `csharp` `css` `diff` `docker` `elixir` `elm` `erlang` `go` `graphql` `haskell` `html` `ini` `java` `javascript` `json` `julia` `kotlin` `less` `lua` `make` `markdown` `objective-c` `perl` `python` `r` `ruby` `rust` `scala` `scss` `shellscript` `shellsession` `sql` `xml` `swift` `typescript` | 130.88 kB | | `mermaid` | `mmd` | [bpruitt-goddard/vscode-mermaid-syntax-highlight](https://github.com/bpruitt-goddard/vscode-mermaid-syntax-highlight/blob/8b62f487cb7a89afcd152febfbf47f5d4787657f/syntaxes/mermaid.tmLanguage.yaml) | [MIT](https://raw.githubusercontent.com/bpruitt-goddard/vscode-mermaid-syntax-highlight/master/LICENSE) | | 27.89 kB | +| `mipsasm` | `mips` | [textmate/mips.tmbundle](https://github.com/textmate/mips.tmbundle/blob/eb7601016a109bf912a48a1c21988f3c4a59fb3a/Syntaxes/MIPS.tmLanguage) | | | 3.04 kB | | `mojo` | | [modularml/mojo-syntax](https://github.com/modularml/mojo-syntax/blob/46eccdaeda2b1587e9b82808cdb35670f359d16d/syntaxes/mojo.syntax.json) | [MIT](https://raw.githubusercontent.com/modularml/mojo-syntax/main/LICENSE) | | 68.68 kB | | `move` | | [damirka/move-syntax](https://github.com/damirka/move-syntax/blob/4b04e9d614901097ffc0663fef40bd3e5d87779e/syntaxes/move.tmLanguage.json) | [MIT](https://raw.githubusercontent.com/damirka/move-syntax/main/LICENSE) | | 19.27 kB | | `narrat` | `nar` | [liana-p/narrat-syntax-highlighting-vscode](https://github.com/liana-p/narrat-syntax-highlighting-vscode/blob/00d4b410338fc50ca0ce77a1f7e873c1fb66d376/syntaxes/narrat.tmLanguage.yaml) | [MIT](https://raw.githubusercontent.com/liana-p/narrat-syntax-highlighting-vscode/main/LICENSE) | | 3.39 kB | diff --git a/packages/tm-grammars/grammars/mipsasm.json b/packages/tm-grammars/grammars/mipsasm.json new file mode 100644 index 0000000..f0e0faa --- /dev/null +++ b/packages/tm-grammars/grammars/mipsasm.json @@ -0,0 +1,125 @@ +{ + "displayName": "MIPS Assembly", + "fileTypes": [ + "s", + "mips", + "spim", + "asm" + ], + "name": "mipsasm", + "patterns": [ + { + "comment": "ok actually this are instructions, but one also could call them funtions…", + "match": "\\b(mul|abs|div|divu|mulo|mulou|neg|negu|not|rem|remu|rol|ror|li|seq|sge|sgeu|sgt|sgtu|sle|sleu|sne|b|beqz|bge|bgeu|bgt|bgtu|ble|bleu|blt|bltu|bnez|la|ld|ulh|ulhu|ulw|sd|ush|usw|move|mfc1\\.d|l\\.d|l\\.s|s\\.d|s\\.s)\\b", + "name": "support.function.pseudo.mips" + }, + { + "match": "\\b(abs\\.d|abs\\.s|add|add\\.d|add\\.s|addi|addiu|addu|and|andi|bc1f|bc1t|beq|bgez|bgezal|bgtz|blez|bltz|bltzal|bne|break|c\\.eq\\.d|c\\.eq\\.s|c\\.le\\.d|c\\.le\\.s|c\\.lt\\.d|c\\.lt\\.s|ceil\\.w\\.d|ceil\\.w\\.s|clo|clz|cvt\\.d\\.s|cvt\\.d\\.w|cvt\\.s\\.d|cvt\\.s\\.w|cvt\\.w\\.d|cvt\\.w\\.s|div|div\\.d|div\\.s|divu|eret|floor\\.w\\.d|floor\\.w\\.s|j|jal|jalr|jr|lb|lbu|lh|lhu|ll|lui|lw|lwc1|lwl|lwr|madd|maddu|mfc0|mfc1|mfhi|mflo|mov\\.d|mov\\.s|movf|movf\\.d|movf\\.s|movn|movn\\.d|movn\\.s|movt|movt\\.d|movt\\.s|movz|movz\\.d|movz\\.s|msub|mtc0|mtc1|mthi|mtlo|mul|mul\\.d|mul\\.s|mult|multu|neg\\.d|neg\\.s|nop|nor|or|ori|round\\.w\\.d|round\\.w\\.s|sb|sc|sdc1|sh|sll|sllv|slt|slti|sltiu|sltu|sqrt\\.d|sqrt\\.s|sra|srav|srl|srlv|sub|sub\\.d|sub\\.s|subu|sw|swc1|swl|swr|syscall|teq|teqi|tge|tgei|tgeiu|tgeu|tlt|tlti|tltiu|tltu|trunc\\.w\\.d|trunc\\.w\\.s|xor|xori)\\b", + "name": "support.function.mips" + }, + { + "match": "\\.(ascii|asciiz|byte|data|double|float|half|kdata|ktext|space|text|word|set\\s*(noat|at))\\b", + "name": "storage.type.mips" + }, + { + "match": "\\.(align|extern||globl)\\b", + "name": "storage.modifier.mips" + }, + { + "captures": { + "1": { + "name": "entity.name.function.label.mips" + } + }, + "match": "\\b([A-Za-z0-9_]+):", + "name": "meta.function.label.mips" + }, + { + "captures": { + "1": { + "name": "punctuation.definition.variable.mips" + } + }, + "match": "(\\$)(0|[2-9]|1\\d|2[0-5]|2[89]|3[0-1])\\b", + "name": "variable.other.register.usable.by-number.mips" + }, + { + "captures": { + "1": { + "name": "punctuation.definition.variable.mips" + } + }, + "match": "(\\$)(zero|v[01]|a[0-3]|t\\d|s[0-7]|gp|sp|fp|ra)\\b", + "name": "variable.other.register.usable.by-name.mips" + }, + { + "captures": { + "1": { + "name": "punctuation.definition.variable.mips" + } + }, + "match": "(\\$)(at|k[01]|1|2[67])\\b", + "name": "variable.other.register.reserved.mips" + }, + { + "captures": { + "1": { + "name": "punctuation.definition.variable.mips" + } + }, + "match": "(\\$)f(\\d|1\\d|2\\d|3[0-1])\\b", + "name": "variable.other.register.usable.floating-point.mips" + }, + { + "match": "\\b\\d+\\.\\d+\\b", + "name": "constant.numeric.float.mips" + }, + { + "match": "\\b(\\d+|0(x|X)[a-fA-F0-9]+)\\b", + "name": "constant.numeric.integer.mips" + }, + { + "begin": "\"", + "beginCaptures": { + "0": { + "name": "punctuation.definition.string.begin.mips" + } + }, + "end": "\"", + "endCaptures": { + "0": { + "name": "punctuation.definition.string.end.mips" + } + }, + "name": "string.quoted.double.mips", + "patterns": [ + { + "match": "\\\\[rnt\\\\\"]", + "name": "constant.character.escape.mips" + } + ] + }, + { + "begin": "(^[ \\t]+)?(?=#)", + "beginCaptures": { + "1": { + "name": "punctuation.whitespace.comment.leading.mips" + } + }, + "end": "(?!\\G)", + "patterns": [ + { + "begin": "#", + "beginCaptures": { + "0": { + "name": "punctuation.definition.comment.mips" + } + }, + "end": "\\n", + "name": "comment.line.number-sign.mips" + } + ] + } + ], + "scopeName": "source.mips" +} diff --git a/packages/tm-grammars/index.js b/packages/tm-grammars/index.js index 3bfe1fe..3dcc2fc 100644 --- a/packages/tm-grammars/index.js +++ b/packages/tm-grammars/index.js @@ -2081,6 +2081,19 @@ export const grammars = [ sha: '8b62f487cb7a89afcd152febfbf47f5d4787657f', source: 'https://github.com/bpruitt-goddard/vscode-mermaid-syntax-highlight/blob/8b62f487cb7a89afcd152febfbf47f5d4787657f/syntaxes/mermaid.tmLanguage.yaml', }, + { + aliases: [ + 'mips', + ], + byteSize: 3114, + displayName: 'MIPS Assembly', + hash: 'd2an1tiAGG', + lastUpdate: '2011-11-14T07:25:17Z', + name: 'mipsasm', + scopeName: 'source.mips', + sha: 'eb7601016a109bf912a48a1c21988f3c4a59fb3a', + source: 'https://github.com/textmate/mips.tmbundle/blob/eb7601016a109bf912a48a1c21988f3c4a59fb3a/Syntaxes/MIPS.tmLanguage', + }, { byteSize: 70326, displayName: 'Mojo', diff --git a/packages/tm-grammars/raw/mipsasm.json b/packages/tm-grammars/raw/mipsasm.json new file mode 100644 index 0000000..5729619 --- /dev/null +++ b/packages/tm-grammars/raw/mipsasm.json @@ -0,0 +1,127 @@ +{ + "displayName": "MIPS Assembly", + "fileTypes": [ + "s", + "mips", + "spim", + "asm" + ], + "keyEquivalent": "^~M", + "name": "mipsasm", + "patterns": [ + { + "comment": "ok actually this are instructions, but one also could call them funtions…", + "match": "\\b(mul|abs|div|divu|mulo|mulou|neg|negu|not|rem|remu|rol|ror|li|seq|sge|sgeu|sgt|sgtu|sle|sleu|sne|b|beqz|bge|bgeu|bgt|bgtu|ble|bleu|blt|bltu|bnez|la|ld|ulh|ulhu|ulw|sd|ush|usw|move|mfc1\\.d|l\\.d|l\\.s|s\\.d|s\\.s)\\b", + "name": "support.function.pseudo.mips" + }, + { + "match": "\\b(abs\\.d|abs\\.s|add|add\\.d|add\\.s|addi|addiu|addu|and|andi|bc1f|bc1t|beq|bgez|bgezal|bgtz|blez|bltz|bltzal|bne|break|c\\.eq\\.d|c\\.eq\\.s|c\\.le\\.d|c\\.le\\.s|c\\.lt\\.d|c\\.lt\\.s|ceil\\.w\\.d|ceil\\.w\\.s|clo|clz|cvt\\.d\\.s|cvt\\.d\\.w|cvt\\.s\\.d|cvt\\.s\\.w|cvt\\.w\\.d|cvt\\.w\\.s|div|div\\.d|div\\.s|divu|eret|floor\\.w\\.d|floor\\.w\\.s|j|jal|jalr|jr|lb|lbu|lh|lhu|ll|lui|lw|lwc1|lwl|lwr|madd|maddu|mfc0|mfc1|mfhi|mflo|mov\\.d|mov\\.s|movf|movf\\.d|movf\\.s|movn|movn\\.d|movn\\.s|movt|movt\\.d|movt\\.s|movz|movz\\.d|movz\\.s|msub|mtc0|mtc1|mthi|mtlo|mul|mul\\.d|mul\\.s|mult|multu|neg\\.d|neg\\.s|nop|nor|or|ori|round\\.w\\.d|round\\.w\\.s|sb|sc|sdc1|sh|sll|sllv|slt|slti|sltiu|sltu|sqrt\\.d|sqrt\\.s|sra|srav|srl|srlv|sub|sub\\.d|sub\\.s|subu|sw|swc1|swl|swr|syscall|teq|teqi|tge|tgei|tgeiu|tgeu|tlt|tlti|tltiu|tltu|trunc\\.w\\.d|trunc\\.w\\.s|xor|xori)\\b", + "name": "support.function.mips" + }, + { + "match": "\\.(ascii|asciiz|byte|data|double|float|half|kdata|ktext|space|text|word|set\\s*(noat|at))\\b", + "name": "storage.type.mips" + }, + { + "match": "\\.(align|extern||globl)\\b", + "name": "storage.modifier.mips" + }, + { + "captures": { + "1": { + "name": "entity.name.function.label.mips" + } + }, + "match": "\\b([A-Za-z0-9_]+):", + "name": "meta.function.label.mips" + }, + { + "captures": { + "1": { + "name": "punctuation.definition.variable.mips" + } + }, + "match": "(\\$)(0|[2-9]|1[0-9]|2[0-5]|2[89]|3[0-1])\\b", + "name": "variable.other.register.usable.by-number.mips" + }, + { + "captures": { + "1": { + "name": "punctuation.definition.variable.mips" + } + }, + "match": "(\\$)(zero|v[01]|a[0-3]|t[0-9]|s[0-7]|gp|sp|fp|ra)\\b", + "name": "variable.other.register.usable.by-name.mips" + }, + { + "captures": { + "1": { + "name": "punctuation.definition.variable.mips" + } + }, + "match": "(\\$)(at|k[01]|1|2[67])\\b", + "name": "variable.other.register.reserved.mips" + }, + { + "captures": { + "1": { + "name": "punctuation.definition.variable.mips" + } + }, + "match": "(\\$)f([0-9]|1[0-9]|2[0-9]|3[0-1])\\b", + "name": "variable.other.register.usable.floating-point.mips" + }, + { + "match": "\\b\\d+\\.\\d+\\b", + "name": "constant.numeric.float.mips" + }, + { + "match": "\\b(\\d+|0(x|X)[a-fA-F0-9]+)\\b", + "name": "constant.numeric.integer.mips" + }, + { + "begin": "\"", + "beginCaptures": { + "0": { + "name": "punctuation.definition.string.begin.mips" + } + }, + "end": "\"", + "endCaptures": { + "0": { + "name": "punctuation.definition.string.end.mips" + } + }, + "name": "string.quoted.double.mips", + "patterns": [ + { + "match": "\\\\[rnt\\\\\"]", + "name": "constant.character.escape.mips" + } + ] + }, + { + "begin": "(^[ \\t]+)?(?=#)", + "beginCaptures": { + "1": { + "name": "punctuation.whitespace.comment.leading.mips" + } + }, + "end": "(?!\\G)", + "patterns": [ + { + "begin": "#", + "beginCaptures": { + "0": { + "name": "punctuation.definition.comment.mips" + } + }, + "end": "\\n", + "name": "comment.line.number-sign.mips" + } + ] + } + ], + "scopeName": "source.mips", + "uuid": "7FD88C2E-6BE3-11D9-9A40-0011242E4184" +} diff --git a/samples/mipsasm.sample b/samples/mipsasm.sample new file mode 100644 index 0000000..fa6b04b --- /dev/null +++ b/samples/mipsasm.sample @@ -0,0 +1,24 @@ +.text +.global AckermannFunc + +# Preconditions: +# 1st parameter ($a0) m +# 2nd parameter ($a1) n +# Postconditions: +# result in ($v0) = value of A(m,n) + +AckermannFunc: + addi $sp, $sp, -8 + sw $s0, 4($sp) + sw $ra, 0($sp) + + # move the parameter registers to temporary - no, only when nec. + +LABEL_IF: bne $a0, $zero, LABEL_ELSE_IF + + addi $v0, $a1, 1 + + # jump to LABEL_DONE + j LABEL_DONE + +# From https://github.com/highlightjs/highlight.js/blob/81e450f3eba5c3e9112a249ae85b696371d738f9/test/markup/mipsasm/default.txt diff --git a/sources-grammars.ts b/sources-grammars.ts index 0e86205..59ea3c8 100644 --- a/sources-grammars.ts +++ b/sources-grammars.ts @@ -745,6 +745,12 @@ export const sourcesCommunity: GrammarSource[] = [ source: 'https://github.com/wooorm/markdown-tm-language/blob/main/source.mdx.tmLanguage', categories: ['web', 'markup'], }, + { + name: 'mipsasm', + displayName: 'MIPS Assembly', + aliases: ['mips'], + source: 'https://github.com/textmate/mips.tmbundle/blob/master/Syntaxes/MIPS.tmLanguage', + }, { name: 'mojo', displayName: 'Mojo',