1 ;;; llvm-mode.el --- Major mode for the LLVM assembler language.
3 ;; Maintainer: The LLVM team, http://llvm.org/
8 ;; Major mode for editing LLVM IR files.
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
)
19 "Syntax table used while in LLVM mode.")
21 (defvar llvm-font-lock-keywords
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
)
32 '("%[-a-zA-Z$._][-a-zA-Z$._0-9]*" . font-lock-variable-name-face
)
34 '("[-a-zA-Z$._0-9]+:" . font-lock-variable-name-face
)
35 ;; Unnamed variable slots
36 '("%[-]?[0-9]+" . font-lock-variable-name-face
)
38 `(,(regexp-opt '("void" "i1" "i8" "i16" "i32" "i64" "i128" "float" "double" "type" "label" "opaque") 'symbols
) . font-lock-type-face
)
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
)
44 '("\\b0x[0-9A-Fa-f]+\\b" . font-lock-preprocessor-face
)
47 '(;; Toplevel entities
48 "declare" "define" "module" "target" "source_filename" "global" "constant" "const"
49 "attributes" "uselistorder" "uselistorder_bb"
51 "private" "internal" "weak" "weak_odr" "linkonce" "linkonce_odr" "available_externally" "appending" "common" "extern_weak" "external"
52 "uninitialized" "implementation" "..."
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" "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
)
71 `(,(regexp-opt '("malloc" "alloca" "free" "load" "store" "getelementptr" "fence" "cmpxchg" "atomicrmw") 'symbols
) . font-lock-keyword-face
)
73 `(,(regexp-opt '("bitcast" "inttoptr" "ptrtoint" "trunc" "zext" "sext" "fptrunc" "fpext" "fptoui" "fptosi" "uitofp" "sitofp" "addrspacecast") 'symbols
) . font-lock-keyword-face
)
75 `(,(regexp-opt '("extractelement" "insertelement" "shufflevector") 'symbols
) . font-lock-keyword-face
)
77 `(,(regexp-opt '("extractvalue" "insertvalue") 'symbols
) . font-lock-keyword-face
)
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
)
91 (define-derived-mode llvm-mode llvm-mode-prog-mode
"LLVM"
92 "Major mode for editing LLVM source files.
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
100 (add-to-list 'auto-mode-alist
(cons "\\.ll\\'" 'llvm-mode
))
104 ;;; llvm-mode.el ends here