Mercurial > hg > CbC > CbC_llvm
comparison utils/emacs/llvm-mode.el @ 95:afa8332a0e37 LLVM3.8
LLVM 3.8
author | Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 13 Oct 2015 17:48:58 +0900 |
parents | 60c9769439b8 |
children | 3a76565eade5 |
comparison
equal
deleted
inserted
replaced
84:f3e34b893a5f | 95:afa8332a0e37 |
---|---|
6 | 6 |
7 ;; Major mode for editing LLVM IR files. | 7 ;; Major mode for editing LLVM IR files. |
8 | 8 |
9 ;;; Code: | 9 ;;; Code: |
10 | 10 |
11 (defvar llvm-mode-syntax-table nil | 11 (defvar llvm-mode-syntax-table |
12 (let ((table (make-syntax-table))) | |
13 (modify-syntax-entry ?% "_" table) | |
14 (modify-syntax-entry ?. "_" table) | |
15 (modify-syntax-entry ?\; "< " table) | |
16 (modify-syntax-entry ?\n "> " table) | |
17 table) | |
12 "Syntax table used while in LLVM mode.") | 18 "Syntax table used while in LLVM mode.") |
19 | |
13 (defvar llvm-font-lock-keywords | 20 (defvar llvm-font-lock-keywords |
14 (list | 21 (list |
15 ;; Comments | |
16 '(";.*" . font-lock-comment-face) | |
17 ;; Variables | 22 ;; Variables |
18 '("%[-a-zA-Z$\._][-a-zA-Z$\._0-9]*" . font-lock-variable-name-face) | 23 '("%[-a-zA-Z$\._][-a-zA-Z$\._0-9]*" . font-lock-variable-name-face) |
19 ;; Labels | 24 ;; Labels |
20 '("[-a-zA-Z$\._0-9]+:" . font-lock-variable-name-face) | 25 '("[-a-zA-Z$\._0-9]+:" . font-lock-variable-name-face) |
21 ;; Strings | |
22 '("\"[^\"]+\"" . font-lock-string-face) | |
23 ;; Unnamed variable slots | 26 ;; Unnamed variable slots |
24 '("%[-]?[0-9]+" . font-lock-variable-name-face) | 27 '("%[-]?[0-9]+" . font-lock-variable-name-face) |
25 ;; Types | 28 ;; Types |
26 `(,(regexp-opt '("void" "i1" "i8" "i16" "i32" "i64" "i128" "float" "double" "type" "label" "opaque") 'symbol) . font-lock-type-face) | 29 `(,(regexp-opt '("void" "i1" "i8" "i16" "i32" "i64" "i128" "float" "double" "type" "label" "opaque") 'symbols) . font-lock-type-face) |
27 ;; Integer literals | 30 ;; Integer literals |
28 '("\\b[-]?[0-9]+\\b" . font-lock-preprocessor-face) | 31 '("\\b[-]?[0-9]+\\b" . font-lock-preprocessor-face) |
29 ;; Floating point constants | 32 ;; Floating point constants |
30 '("\\b[-+]?[0-9]+\.[0-9]*\([eE][-+]?[0-9]+\)?\\b" . font-lock-preprocessor-face) | 33 '("\\b[-+]?[0-9]+\.[0-9]*\([eE][-+]?[0-9]+\)?\\b" . font-lock-preprocessor-face) |
31 ;; Hex constants | 34 ;; Hex constants |
54 ;; Aggregate ops | 57 ;; Aggregate ops |
55 `(,(regexp-opt '("extractvalue" "insertvalue") 'symbols) . font-lock-keyword-face) | 58 `(,(regexp-opt '("extractvalue" "insertvalue") 'symbols) . font-lock-keyword-face) |
56 ;; Metadata types | 59 ;; Metadata types |
57 `(,(regexp-opt '("distinct") 'symbols) . font-lock-keyword-face) | 60 `(,(regexp-opt '("distinct") 'symbols) . font-lock-keyword-face) |
58 ;; Use-list order directives | 61 ;; Use-list order directives |
59 `(,(regexp-opt '("uselistorder" "uselistorder_bb") 'symbols) . font-lock-keyword-face) | 62 `(,(regexp-opt '("uselistorder" "uselistorder_bb") 'symbols) . font-lock-keyword-face)) |
63 "Syntax highlighting for LLVM.") | |
60 | 64 |
61 ) | 65 ;; Emacs 23 compatibility. |
62 "Syntax highlighting for LLVM." | 66 (defalias 'llvm-mode-prog-mode |
63 ) | 67 (if (fboundp 'prog-mode) |
64 | 68 'prog-mode |
65 ;; ---------------------- Syntax table --------------------------- | 69 'fundamental-mode)) |
66 ;; Shamelessly ripped from jasmin.el | |
67 ;; URL: http://www.neilvandyke.org/jasmin-emacs/jasmin.el.html | |
68 | |
69 (if (not llvm-mode-syntax-table) | |
70 (progn | |
71 (setq llvm-mode-syntax-table (make-syntax-table)) | |
72 (mapc (function (lambda (n) | |
73 (modify-syntax-entry (aref n 0) | |
74 (aref n 1) | |
75 llvm-mode-syntax-table))) | |
76 '( | |
77 ;; whitespace (` ') | |
78 [?\^m " "] | |
79 [?\f " "] | |
80 [?\n " "] | |
81 [?\t " "] | |
82 [?\ " "] | |
83 ;; word constituents (`w') | |
84 ;;[?< "w"] | |
85 ;;[?> "w"] | |
86 [?% "w"] | |
87 ;;[?_ "w "] | |
88 ;; comments | |
89 [?\; "< "] | |
90 [?\n "> "] | |
91 ;;[?\r "> "] | |
92 ;;[?\^m "> "] | |
93 ;; symbol constituents (`_') | |
94 ;; punctuation (`.') | |
95 ;; open paren (`(') | |
96 ;; close paren (`)') | |
97 ;; string quote ('"') | |
98 [?\" "\""])))) | |
99 | |
100 ;; --------------------- Abbrev table ----------------------------- | |
101 | |
102 (defvar llvm-mode-abbrev-table nil | |
103 "Abbrev table used while in LLVM mode.") | |
104 (define-abbrev-table 'llvm-mode-abbrev-table ()) | |
105 | |
106 (defvar llvm-mode-hook nil) | |
107 (defvar llvm-mode-map nil) ; Create a mode-specific keymap. | |
108 | |
109 (if (not llvm-mode-map) | |
110 () ; Do not change the keymap if it is already set up. | |
111 (setq llvm-mode-map (make-sparse-keymap)) | |
112 (define-key llvm-mode-map "\t" 'tab-to-tab-stop) | |
113 (define-key llvm-mode-map "\es" 'center-line) | |
114 (define-key llvm-mode-map "\eS" 'center-paragraph)) | |
115 | 70 |
116 ;;;###autoload | 71 ;;;###autoload |
117 (defun llvm-mode () | 72 (define-derived-mode llvm-mode llvm-mode-prog-mode "LLVM" |
118 "Major mode for editing LLVM source files. | 73 "Major mode for editing LLVM source files. |
119 \\{llvm-mode-map} | 74 \\{llvm-mode-map} |
120 Runs `llvm-mode-hook' on startup." | 75 Runs `llvm-mode-hook' on startup." |
121 (interactive) | 76 (setq font-lock-defaults `(llvm-font-lock-keywords)) |
122 (kill-all-local-variables) | 77 (setq comment-start ";")) |
123 (use-local-map llvm-mode-map) ; Provides the local keymap. | |
124 (setq major-mode 'llvm-mode) | |
125 | |
126 (make-local-variable 'font-lock-defaults) | |
127 (setq major-mode 'llvm-mode ; This is how describe-mode | |
128 ; finds the doc string to print. | |
129 mode-name "LLVM" ; This name goes into the modeline. | |
130 font-lock-defaults `(llvm-font-lock-keywords)) | |
131 | |
132 (setq local-abbrev-table llvm-mode-abbrev-table) | |
133 (set-syntax-table llvm-mode-syntax-table) | |
134 (setq comment-start ";") | |
135 (run-hooks 'llvm-mode-hook)) ; Finally, this permits the user to | |
136 ; customize the mode with a hook. | |
137 | 78 |
138 ;; Associate .ll files with llvm-mode | 79 ;; Associate .ll files with llvm-mode |
139 ;;;###autoload | 80 ;;;###autoload |
140 (add-to-list 'auto-mode-alist (cons (purecopy "\\.ll\\'") 'llvm-mode)) | 81 (add-to-list 'auto-mode-alist (cons (purecopy "\\.ll\\'") 'llvm-mode)) |
141 | 82 |