xref: /aosp_15_r20/external/llvm/utils/emacs/llvm-mode.el (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker;;; llvm-mode.el --- Major mode for the LLVM assembler language.
2*9880d681SAndroid Build Coastguard Worker
3*9880d681SAndroid Build Coastguard Worker;; Maintainer:  The LLVM team, http://llvm.org/
4*9880d681SAndroid Build Coastguard Worker
5*9880d681SAndroid Build Coastguard Worker;;; Commentary:
6*9880d681SAndroid Build Coastguard Worker
7*9880d681SAndroid Build Coastguard Worker;; Major mode for editing LLVM IR files.
8*9880d681SAndroid Build Coastguard Worker
9*9880d681SAndroid Build Coastguard Worker;;; Code:
10*9880d681SAndroid Build Coastguard Worker
11*9880d681SAndroid Build Coastguard Worker(defvar llvm-mode-syntax-table
12*9880d681SAndroid Build Coastguard Worker  (let ((table (make-syntax-table)))
13*9880d681SAndroid Build Coastguard Worker    (modify-syntax-entry ?% "_" table)
14*9880d681SAndroid Build Coastguard Worker    (modify-syntax-entry ?. "_" table)
15*9880d681SAndroid Build Coastguard Worker    (modify-syntax-entry ?\; "< " table)
16*9880d681SAndroid Build Coastguard Worker    (modify-syntax-entry ?\n "> " table)
17*9880d681SAndroid Build Coastguard Worker    table)
18*9880d681SAndroid Build Coastguard Worker  "Syntax table used while in LLVM mode.")
19*9880d681SAndroid Build Coastguard Worker
20*9880d681SAndroid Build Coastguard Worker(defvar llvm-font-lock-keywords
21*9880d681SAndroid Build Coastguard Worker  (list
22*9880d681SAndroid Build Coastguard Worker   ;; Variables
23*9880d681SAndroid Build Coastguard Worker   '("%[-a-zA-Z$\._][-a-zA-Z$\._0-9]*" . font-lock-variable-name-face)
24*9880d681SAndroid Build Coastguard Worker   ;; Labels
25*9880d681SAndroid Build Coastguard Worker   '("[-a-zA-Z$\._0-9]+:" . font-lock-variable-name-face)
26*9880d681SAndroid Build Coastguard Worker   ;; Unnamed variable slots
27*9880d681SAndroid Build Coastguard Worker   '("%[-]?[0-9]+" . font-lock-variable-name-face)
28*9880d681SAndroid Build Coastguard Worker   ;; Types
29*9880d681SAndroid Build Coastguard Worker   `(,(regexp-opt '("void" "i1" "i8" "i16" "i32" "i64" "i128" "float" "double" "type" "label" "opaque") 'symbols) . font-lock-type-face)
30*9880d681SAndroid Build Coastguard Worker   ;; Integer literals
31*9880d681SAndroid Build Coastguard Worker   '("\\b[-]?[0-9]+\\b" . font-lock-preprocessor-face)
32*9880d681SAndroid Build Coastguard Worker   ;; Floating point constants
33*9880d681SAndroid Build Coastguard Worker   '("\\b[-+]?[0-9]+\.[0-9]*\([eE][-+]?[0-9]+\)?\\b" . font-lock-preprocessor-face)
34*9880d681SAndroid Build Coastguard Worker   ;; Hex constants
35*9880d681SAndroid Build Coastguard Worker   '("\\b0x[0-9A-Fa-f]+\\b" . font-lock-preprocessor-face)
36*9880d681SAndroid Build Coastguard Worker   ;; Keywords
37*9880d681SAndroid Build Coastguard Worker   `(,(regexp-opt '("begin" "end" "true" "false" "zeroinitializer" "declare"
38*9880d681SAndroid Build Coastguard Worker                    "define" "global" "constant" "const" "internal" "linkonce" "linkonce_odr"
39*9880d681SAndroid Build Coastguard Worker                    "weak" "weak_odr" "appending" "uninitialized" "implementation" "..."
40*9880d681SAndroid Build Coastguard Worker                    "null" "undef" "to" "except" "not" "target" "endian" "little" "big"
41*9880d681SAndroid Build Coastguard Worker                    "pointersize" "volatile" "fastcc" "coldcc" "cc" "personality") 'symbols) . font-lock-keyword-face)
42*9880d681SAndroid Build Coastguard Worker   ;; Arithmetic and Logical Operators
43*9880d681SAndroid Build Coastguard Worker   `(,(regexp-opt '("add" "sub" "mul" "sdiv" "udiv" "urem" "srem" "and" "or" "xor"
44*9880d681SAndroid Build Coastguard Worker                    "setne" "seteq" "setlt" "setgt" "setle" "setge") 'symbols) . font-lock-keyword-face)
45*9880d681SAndroid Build Coastguard Worker   ;; Floating-point operators
46*9880d681SAndroid Build Coastguard Worker   `(,(regexp-opt '("fadd" "fsub" "fmul" "fdiv" "frem") 'symbols) . font-lock-keyword-face)
47*9880d681SAndroid Build Coastguard Worker   ;; Special instructions
48*9880d681SAndroid Build Coastguard Worker   `(,(regexp-opt '("phi" "tail" "call" "select" "to" "shl" "lshr" "ashr" "fcmp" "icmp" "va_arg" "landingpad") 'symbols) . font-lock-keyword-face)
49*9880d681SAndroid Build Coastguard Worker   ;; Control instructions
50*9880d681SAndroid Build Coastguard Worker   `(,(regexp-opt '("ret" "br" "switch" "invoke" "resume" "unwind" "unreachable" "indirectbr") 'symbols) . font-lock-keyword-face)
51*9880d681SAndroid Build Coastguard Worker   ;; Memory operators
52*9880d681SAndroid Build Coastguard Worker   `(,(regexp-opt '("malloc" "alloca" "free" "load" "store" "getelementptr" "fence" "cmpxchg" "atomicrmw") 'symbols) . font-lock-keyword-face)
53*9880d681SAndroid Build Coastguard Worker   ;; Casts
54*9880d681SAndroid Build Coastguard Worker   `(,(regexp-opt '("bitcast" "inttoptr" "ptrtoint" "trunc" "zext" "sext" "fptrunc" "fpext" "fptoui" "fptosi" "uitofp" "sitofp" "addrspacecast") 'symbols) . font-lock-keyword-face)
55*9880d681SAndroid Build Coastguard Worker   ;; Vector ops
56*9880d681SAndroid Build Coastguard Worker   `(,(regexp-opt '("extractelement" "insertelement" "shufflevector") 'symbols) . font-lock-keyword-face)
57*9880d681SAndroid Build Coastguard Worker   ;; Aggregate ops
58*9880d681SAndroid Build Coastguard Worker   `(,(regexp-opt '("extractvalue" "insertvalue") 'symbols) . font-lock-keyword-face)
59*9880d681SAndroid Build Coastguard Worker   ;; Metadata types
60*9880d681SAndroid Build Coastguard Worker   `(,(regexp-opt '("distinct") 'symbols) . font-lock-keyword-face)
61*9880d681SAndroid Build Coastguard Worker   ;; Use-list order directives
62*9880d681SAndroid Build Coastguard Worker   `(,(regexp-opt '("uselistorder" "uselistorder_bb") 'symbols) . font-lock-keyword-face))
63*9880d681SAndroid Build Coastguard Worker  "Syntax highlighting for LLVM.")
64*9880d681SAndroid Build Coastguard Worker
65*9880d681SAndroid Build Coastguard Worker;; Emacs 23 compatibility.
66*9880d681SAndroid Build Coastguard Worker(defalias 'llvm-mode-prog-mode
67*9880d681SAndroid Build Coastguard Worker  (if (fboundp 'prog-mode)
68*9880d681SAndroid Build Coastguard Worker      'prog-mode
69*9880d681SAndroid Build Coastguard Worker    'fundamental-mode))
70*9880d681SAndroid Build Coastguard Worker
71*9880d681SAndroid Build Coastguard Worker;;;###autoload
72*9880d681SAndroid Build Coastguard Worker(define-derived-mode llvm-mode llvm-mode-prog-mode "LLVM"
73*9880d681SAndroid Build Coastguard Worker  "Major mode for editing LLVM source files.
74*9880d681SAndroid Build Coastguard Worker\\{llvm-mode-map}
75*9880d681SAndroid Build Coastguard Worker  Runs `llvm-mode-hook' on startup."
76*9880d681SAndroid Build Coastguard Worker  (setq font-lock-defaults `(llvm-font-lock-keywords))
77*9880d681SAndroid Build Coastguard Worker  (setq comment-start ";"))
78*9880d681SAndroid Build Coastguard Worker
79*9880d681SAndroid Build Coastguard Worker;; Associate .ll files with llvm-mode
80*9880d681SAndroid Build Coastguard Worker;;;###autoload
81*9880d681SAndroid Build Coastguard Worker(add-to-list 'auto-mode-alist (cons (purecopy "\\.ll\\'")  'llvm-mode))
82*9880d681SAndroid Build Coastguard Worker
83*9880d681SAndroid Build Coastguard Worker(provide 'llvm-mode)
84*9880d681SAndroid Build Coastguard Worker
85*9880d681SAndroid Build Coastguard Worker;;; llvm-mode.el ends here
86