Skip to content

Commit e4b130f

Browse files
authored
[emacs] Handle vector types, arbitary integer types and function names (#88246)
Resurrecting this patch from https://reviews.llvm.org/D158321 This adds a few more regexp patterns for llvm-mode-syntax-table. The primitive type regexp was split out so it could be reused when handling vectors. Also worth noting is that the vector regexp needs to come before the primitive types, otherwise they will match first.
1 parent 117921e commit e4b130f

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

llvm/utils/emacs/llvm-mode.el

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@
1818
table)
1919
"Syntax table used while in LLVM mode.")
2020

21+
(defconst llvm-mode-primitive-type-regexp
22+
(concat
23+
"\\(i[0-9]+\\|"
24+
(regexp-opt
25+
'("void" "half" "bfloat" "float" "double" "fp128" "x86_fp80" "ppc_fp128"
26+
"x86_mmx" "x86_amx" "ptr" "type" "label" "opaque" "token") t)
27+
"\\)"))
28+
2129
(defvar llvm-font-lock-keywords
2230
(list
2331
;; Attributes
@@ -34,10 +42,23 @@
3442
'("[-a-zA-Z$._0-9]+:" . font-lock-variable-name-face)
3543
;; Unnamed variable slots
3644
'("%[-]?[0-9]+" . font-lock-variable-name-face)
37-
;; Types
38-
`(,(regexp-opt
39-
'("void" "i1" "i8" "i16" "i32" "i64" "i128" "half" "bfloat" "float" "double" "fp128" "x86_fp80" "ppc_fp128" "x86_mmx" "x86_amx" "ptr"
40-
"type" "label" "opaque" "token") 'symbols) . font-lock-type-face)
45+
;; Function names
46+
'("@[-a-zA-Z$._][-a-zA-Z$._0-9]*" . font-lock-function-name-face)
47+
;; Fixed vector types
48+
`(,(concat "<[ \t]*\\([0-9]+\\)[ \t]*x[ \t]+"
49+
llvm-mode-primitive-type-regexp
50+
"[ \t]*>")
51+
(1 'font-lock-type-face)
52+
(2 'font-lock-type-face))
53+
;; Scalable vector types
54+
`(,(concat "<[ \t]*\\(vscale[ \t]\\)+x[ \t]+\\([0-9]+\\)[ \t]*x[ \t]+"
55+
llvm-mode-primitive-type-regexp
56+
"[ \t]*>")
57+
(1 'font-lock-keyword-face)
58+
(2 'font-lock-type-face)
59+
(3 'font-lock-type-face))
60+
;; Primitive types
61+
`(,(concat "\\<" llvm-mode-primitive-type-regexp "\\>") . font-lock-type-face)
4162
;; Integer literals
4263
'("\\b[-]?[0-9]+\\b" . font-lock-preprocessor-face)
4364
;; Floating point constants

0 commit comments

Comments
 (0)