-
Notifications
You must be signed in to change notification settings - Fork 1
/
qbe-mode.el
91 lines (85 loc) · 2.9 KB
/
qbe-mode.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
;;; qbe-mode.el --- Major mode for editing QBE IL -*- lexical-binding: t; -*-
;;
;; Copyright (C) 2022
;;
;; Author: Maksymilian Bentje Knust <[email protected]>
;; Version: 0.0.1
;; Keywords: languages
;; Homepage: https://github.com/mbknust/qbe-mode
;; Package-Requires: ((emacs "24.3"))
;;
;; This file is not part of GNU Emacs.
;;
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
;;
;;; Commentary:
;;
;; A major mode for the QBE IL (see https://c9x.me/compile/).
;;
;;; Code:
(defvar qbe-mode-keywords
'("export" "section" "type" "align" "function" "data")
"List of QBE IL keywords")
(defvar qbe-mode-opcodes
'("add" "sub" "div" "mul"
"neg" "udiv" "rem" "urem"
"or" "xor" "and"
"sar" "shr" "shl"
"stored" "stores" "storel"
"storew" "storeh" "storeb"
"loadd" "loads" "loadl"
"loadsw" "loadsh" "loadsb"
"loaduw" "loaduh" "loadub"
"alloc4" "alloc8" "alloc16"
"ceqd" "ceql" "ceqs" "ceqw"
"cged" "cges" "cgtd" "cgts"
"cled" "cles" "cltd" "clts"
"cned" "cnel" "cnes" "cnew"
"cod" "cos" "cuod" "cuos"
"csgel" "csgew" "csgtl" "csgtw"
"cslel" "cslew" "csltl" "csltw"
"cugel" "cugew" "cugtl" "cugtw"
"culel" "culew" "cultl" "cultw"
"dtosi" "dtoui" "stosi" "stoui"
"exts" "extsb" "extsh" "extsw"
"extub" "extuh" "extuw"
"sltof" "ultof" "swtof" "uwtof"
"truncd" "cast" "copy" "phi"
"vastart" "vaarg"
"call" "jmp" "jnz" "ret")
"List of QBE IL instructions")
(defvar qbe-mode-font-lock-defaults
`((("[sd]_-?[[:digit:]]+\\(\\.[[:digit:]]+\\)?"
. 'font-lock-constant-face)
("#.*$" . 'font-lock-comment-face)
("\\(:[[:alnum:]]+\\|\\<[wlsdbh]\\>\\)"
. 'font-lock-type-face)
("[%\\$][[:alnum:]]*"
. 'font-lock-variable-name-face)
(,(format "\\<%s\\>" (regexp-opt qbe-mode-opcodes))
. 'font-lock-builtin-face)
(,(format "\\<%s\\>" (regexp-opt qbe-mode-keywords))
. 'font-lock-keyword-face)
("\\(@[[:alnum:]]+\\|-?[[:digit:]]+\\)"
. 'font-lock-constant-face))))
;;;###autoload
(define-derived-mode qbe-mode fundamental-mode "QBE"
"major mode for editing QBE IL"
(setq-local font-lock-defaults qbe-mode-font-lock-defaults)
(setq-local comment-start "# ")
(setq-local comment-end ""))
;;;###autoload
(add-to-list 'auto-mode-alist '("\\.ssa" . qbe-mode))
(provide 'qbe-mode)
;;; qbe-mode.el ends here