blob: cde66d122866f359366a994da555f56db2eeb557 [file] [log] [blame]
Rafael Espindola1763c0a2015-01-07 15:52:51 +00001;;; llvm-mode.el --- Major mode for the LLVM assembler language.
Misha Brukmand9b11cf2002-10-09 00:30:20 +00002
Rafael Espindola1763c0a2015-01-07 15:52:51 +00003;; Maintainer: The LLVM team, http://llvm.org/
Rafael Espindola4aef7d12018-01-29 22:56:41 +00004;; Version: 1.0
Rafael Espindola1763c0a2015-01-07 15:52:51 +00005
6;;; Commentary:
7
8;; Major mode for editing LLVM IR files.
9
10;;; Code:
11
Rafael Espindola7ad3ef02015-09-10 13:44:28 +000012(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)
Misha Brukmand9b11cf2002-10-09 00:30:20 +000019 "Syntax table used while in LLVM mode.")
Rafael Espindola7ad3ef02015-09-10 13:44:28 +000020
Misha Brukmand9b11cf2002-10-09 00:30:20 +000021(defvar llvm-font-lock-keywords
22 (list
Fangrui Songa385fd72018-03-08 01:28:45 +000023 ;; 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"
30 "sanitize_thread" "sanitize_memory" "strictfp" "uwtable" "writeonly") 'symbols) . font-lock-constant-face)
Misha Brukmand9b11cf2002-10-09 00:30:20 +000031 ;; Variables
Rafael Espindola4aef7d12018-01-29 22:56:41 +000032 '("%[-a-zA-Z$._][-a-zA-Z$._0-9]*" . font-lock-variable-name-face)
Misha Brukmand9b11cf2002-10-09 00:30:20 +000033 ;; Labels
Rafael Espindola4aef7d12018-01-29 22:56:41 +000034 '("[-a-zA-Z$._0-9]+:" . font-lock-variable-name-face)
Misha Brukmand9b11cf2002-10-09 00:30:20 +000035 ;; Unnamed variable slots
36 '("%[-]?[0-9]+" . font-lock-variable-name-face)
Misha Brukmand9b11cf2002-10-09 00:30:20 +000037 ;; Types
Rafael Espindola7ad3ef02015-09-10 13:44:28 +000038 `(,(regexp-opt '("void" "i1" "i8" "i16" "i32" "i64" "i128" "float" "double" "type" "label" "opaque") 'symbols) . font-lock-type-face)
Anton Korobeynikova98c7b32007-10-19 16:54:13 +000039 ;; Integer literals
40 '("\\b[-]?[0-9]+\\b" . font-lock-preprocessor-face)
41 ;; Floating point constants
Rafael Espindola4aef7d12018-01-29 22:56:41 +000042 '("\\b[-+]?[0-9]+.[0-9]*\\([eE][-+]?[0-9]+\\)?\\b" . font-lock-preprocessor-face)
Anton Korobeynikova98c7b32007-10-19 16:54:13 +000043 ;; Hex constants
44 '("\\b0x[0-9A-Fa-f]+\\b" . font-lock-preprocessor-face)
45 ;; Keywords
Fangrui Songa385fd72018-03-08 01:28:45 +000046 `(,(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"
55
56 ;; Calling conventions
57 "ccc" "fastcc" "coldcc" "webkit_jscc" "anyregcc" "preserve_mostcc" "preserve_allcc"
58 "cxx_fast_tlscc" "swiftcc"
59
60 "atomic" "volatile" "personality" "prologue" "section") 'symbols) . font-lock-keyword-face)
Misha Brukmand9b11cf2002-10-09 00:30:20 +000061 ;; Arithmetic and Logical Operators
Matt Arsenault0ea3ce92013-11-14 02:03:02 +000062 `(,(regexp-opt '("add" "sub" "mul" "sdiv" "udiv" "urem" "srem" "and" "or" "xor"
Rafael Espindola3fb6dcc2015-02-06 13:57:58 +000063 "setne" "seteq" "setlt" "setgt" "setle" "setge") 'symbols) . font-lock-keyword-face)
Michael Ilseman1854e142012-12-01 00:42:27 +000064 ;; Floating-point operators
Matt Arsenault7ff33d42018-11-13 19:50:38 +000065 `(,(regexp-opt '("fadd" "fsub" "fneg" "fmul" "fdiv" "frem") 'symbols) . font-lock-keyword-face)
Misha Brukmand9b11cf2002-10-09 00:30:20 +000066 ;; Special instructions
Rafael Espindola3fb6dcc2015-02-06 13:57:58 +000067 `(,(regexp-opt '("phi" "tail" "call" "select" "to" "shl" "lshr" "ashr" "fcmp" "icmp" "va_arg" "landingpad") 'symbols) . font-lock-keyword-face)
Misha Brukmand9b11cf2002-10-09 00:30:20 +000068 ;; Control instructions
Rafael Espindola3fb6dcc2015-02-06 13:57:58 +000069 `(,(regexp-opt '("ret" "br" "switch" "invoke" "resume" "unwind" "unreachable" "indirectbr") 'symbols) . font-lock-keyword-face)
Misha Brukmand9b11cf2002-10-09 00:30:20 +000070 ;; Memory operators
Rafael Espindola3fb6dcc2015-02-06 13:57:58 +000071 `(,(regexp-opt '("malloc" "alloca" "free" "load" "store" "getelementptr" "fence" "cmpxchg" "atomicrmw") 'symbols) . font-lock-keyword-face)
Matt Arsenault0ea3ce92013-11-14 02:03:02 +000072 ;; Casts
Rafael Espindola3fb6dcc2015-02-06 13:57:58 +000073 `(,(regexp-opt '("bitcast" "inttoptr" "ptrtoint" "trunc" "zext" "sext" "fptrunc" "fpext" "fptoui" "fptosi" "uitofp" "sitofp" "addrspacecast") 'symbols) . font-lock-keyword-face)
Matt Arsenault0ea3ce92013-11-14 02:03:02 +000074 ;; Vector ops
Rafael Espindola3fb6dcc2015-02-06 13:57:58 +000075 `(,(regexp-opt '("extractelement" "insertelement" "shufflevector") 'symbols) . font-lock-keyword-face)
Matt Arsenault0ea3ce92013-11-14 02:03:02 +000076 ;; Aggregate ops
Rafael Espindola3fb6dcc2015-02-06 13:57:58 +000077 `(,(regexp-opt '("extractvalue" "insertvalue") 'symbols) . font-lock-keyword-face)
Duncan P. N. Exon Smithf416d722015-01-08 22:38:29 +000078 ;; Metadata types
Rafael Espindola3fb6dcc2015-02-06 13:57:58 +000079 `(,(regexp-opt '("distinct") 'symbols) . font-lock-keyword-face)
Duncan P. N. Exon Smith78388182014-08-19 21:30:15 +000080 ;; Use-list order directives
Rafael Espindola7ad3ef02015-09-10 13:44:28 +000081 `(,(regexp-opt '("uselistorder" "uselistorder_bb") 'symbols) . font-lock-keyword-face))
82 "Syntax highlighting for LLVM.")
Matt Arsenault0ea3ce92013-11-14 02:03:02 +000083
Rafael Espindola7ad3ef02015-09-10 13:44:28 +000084;; Emacs 23 compatibility.
85(defalias 'llvm-mode-prog-mode
86 (if (fboundp 'prog-mode)
87 'prog-mode
88 'fundamental-mode))
Misha Brukmand9b11cf2002-10-09 00:30:20 +000089
Rafael Espindola1763c0a2015-01-07 15:52:51 +000090;;;###autoload
Rafael Espindola7ad3ef02015-09-10 13:44:28 +000091(define-derived-mode llvm-mode llvm-mode-prog-mode "LLVM"
Misha Brukmand9b11cf2002-10-09 00:30:20 +000092 "Major mode for editing LLVM source files.
Rafael Espindola1763c0a2015-01-07 15:52:51 +000093\\{llvm-mode-map}
94 Runs `llvm-mode-hook' on startup."
Rafael Espindola7ad3ef02015-09-10 13:44:28 +000095 (setq font-lock-defaults `(llvm-font-lock-keywords))
Rafael Espindola4aef7d12018-01-29 22:56:41 +000096 (setq-local comment-start ";"))
Misha Brukmand9b11cf2002-10-09 00:30:20 +000097
98;; Associate .ll files with llvm-mode
Rafael Espindola1763c0a2015-01-07 15:52:51 +000099;;;###autoload
Rafael Espindola4aef7d12018-01-29 22:56:41 +0000100(add-to-list 'auto-mode-alist (cons "\\.ll\\'" 'llvm-mode))
Misha Brukmand9b11cf2002-10-09 00:30:20 +0000101
102(provide 'llvm-mode)
Rafael Espindola1763c0a2015-01-07 15:52:51 +0000103
104;;; llvm-mode.el ends here