[MIParser] Set RegClassOrRegBank during instruction parsing
[llvm-complete.git] / utils / emacs / llvm-mode.el
blob73b02763d0166d3aa6d08d2766768f05bd4ef8c5
1 ;;; llvm-mode.el --- Major mode for the LLVM assembler language.
3 ;; Maintainer: The LLVM team, http://llvm.org/
4 ;; Version: 1.0
6 ;;; Commentary:
8 ;; Major mode for editing LLVM IR files.
10 ;;; Code:
12 (defvar llvm-mode-syntax-table
13 (let ((table (make-syntax-table)))
14 (modify-syntax-entry ?% "_" table)
15 (modify-syntax-entry ?. "_" table)
16 (modify-syntax-entry ?\; "< " table)
17 (modify-syntax-entry ?\n "> " table)
18 table)
19 "Syntax table used while in LLVM mode.")
21 (defvar llvm-font-lock-keywords
22 (list
23 ;; Attributes
24 `(,(regexp-opt
25 '("alwaysinline" "argmemonly" "builtin" "cold" "convergent" "inaccessiblememonly"
26 "inaccessiblemem_or_argmemonly" "inlinehint" "jumptable" "minsize" "naked" "nobuiltin"
27 "noduplicate" "noimplicitfloat" "noinline" "nonlazybind" "noredzone" "noreturn"
28 "norecurse" "nounwind" "optnone" "optsize" "readnone" "readonly" "returns_twice"
29 "speculatable" "ssp" "sspreq" "sspstrong" "safestack" "sanitize_address" "sanitize_hwaddress" "sanitize_memtag"
30 "sanitize_thread" "sanitize_memory" "strictfp" "uwtable" "writeonly" "immarg") 'symbols) . font-lock-constant-face)
31 ;; Variables
32 '("%[-a-zA-Z$._][-a-zA-Z$._0-9]*" . font-lock-variable-name-face)
33 ;; Labels
34 '("[-a-zA-Z$._0-9]+:" . font-lock-variable-name-face)
35 ;; Unnamed variable slots
36 '("%[-]?[0-9]+" . font-lock-variable-name-face)
37 ;; Types
38 `(,(regexp-opt '("void" "i1" "i8" "i16" "i32" "i64" "i128" "float" "double" "type" "label" "opaque") 'symbols) . font-lock-type-face)
39 ;; Integer literals
40 '("\\b[-]?[0-9]+\\b" . font-lock-preprocessor-face)
41 ;; Floating point constants
42 '("\\b[-+]?[0-9]+.[0-9]*\\([eE][-+]?[0-9]+\\)?\\b" . font-lock-preprocessor-face)
43 ;; Hex constants
44 '("\\b0x[0-9A-Fa-f]+\\b" . font-lock-preprocessor-face)
45 ;; Keywords
46 `(,(regexp-opt
47 '(;; Toplevel entities
48 "declare" "define" "module" "target" "source_filename" "global" "constant" "const"
49 "attributes" "uselistorder" "uselistorder_bb"
50 ;; Linkage types
51 "private" "internal" "weak" "weak_odr" "linkonce" "linkonce_odr" "available_externally" "appending" "common" "extern_weak" "external"
52 "uninitialized" "implementation" "..."
53 ;; Values
54 "true" "false" "null" "undef" "zeroinitializer" "none" "c" "asm" "blockaddress"
56 ;; Calling conventions
57 "ccc" "fastcc" "coldcc" "webkit_jscc" "anyregcc" "preserve_mostcc" "preserve_allcc"
58 "cxx_fast_tlscc" "swiftcc"
60 "atomic" "volatile" "personality" "prologue" "section") 'symbols) . font-lock-keyword-face)
61 ;; Arithmetic and Logical Operators
62 `(,(regexp-opt '("add" "sub" "mul" "sdiv" "udiv" "urem" "srem" "and" "or" "xor"
63 "setne" "seteq" "setlt" "setgt" "setle" "setge") 'symbols) . font-lock-keyword-face)
64 ;; Floating-point operators
65 `(,(regexp-opt '("fadd" "fsub" "fneg" "fmul" "fdiv" "frem") 'symbols) . font-lock-keyword-face)
66 ;; Special instructions
67 `(,(regexp-opt '("phi" "tail" "call" "select" "to" "shl" "lshr" "ashr" "fcmp" "icmp" "va_arg" "landingpad") 'symbols) . font-lock-keyword-face)
68 ;; Control instructions
69 `(,(regexp-opt '("ret" "br" "switch" "invoke" "resume" "unwind" "unreachable" "indirectbr") 'symbols) . font-lock-keyword-face)
70 ;; Memory operators
71 `(,(regexp-opt '("malloc" "alloca" "free" "load" "store" "getelementptr" "fence" "cmpxchg" "atomicrmw") 'symbols) . font-lock-keyword-face)
72 ;; Casts
73 `(,(regexp-opt '("bitcast" "inttoptr" "ptrtoint" "trunc" "zext" "sext" "fptrunc" "fpext" "fptoui" "fptosi" "uitofp" "sitofp" "addrspacecast") 'symbols) . font-lock-keyword-face)
74 ;; Vector ops
75 `(,(regexp-opt '("extractelement" "insertelement" "shufflevector") 'symbols) . font-lock-keyword-face)
76 ;; Aggregate ops
77 `(,(regexp-opt '("extractvalue" "insertvalue") 'symbols) . font-lock-keyword-face)
78 ;; Metadata types
79 `(,(regexp-opt '("distinct") 'symbols) . font-lock-keyword-face)
80 ;; Use-list order directives
81 `(,(regexp-opt '("uselistorder" "uselistorder_bb") 'symbols) . font-lock-keyword-face))
82 "Syntax highlighting for LLVM.")
84 ;; Emacs 23 compatibility.
85 (defalias 'llvm-mode-prog-mode
86 (if (fboundp 'prog-mode)
87 'prog-mode
88 'fundamental-mode))
90 ;;;###autoload
91 (define-derived-mode llvm-mode llvm-mode-prog-mode "LLVM"
92 "Major mode for editing LLVM source files.
93 \\{llvm-mode-map}
94 Runs `llvm-mode-hook' on startup."
95 (setq font-lock-defaults `(llvm-font-lock-keywords))
96 (setq-local comment-start ";"))
98 ;; Associate .ll files with llvm-mode
99 ;;;###autoload
100 (add-to-list 'auto-mode-alist (cons "\\.ll\\'" 'llvm-mode))
102 (provide 'llvm-mode)
104 ;;; llvm-mode.el ends here