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" "allocsize" "builtin" "cold" "convergent" "dereferenceable" "dereferenceable_or_null" "hot" "immarg" "inaccessiblememonly"
26 "inaccessiblemem_or_argmemonly" "inalloca" "inlinehint" "jumptable" "minsize" "mustprogress" "naked" "nobuiltin" "nonnull" "nocapture"
27 "nocallback" "nocf_check" "noduplicate" "nofree" "noimplicitfloat" "noinline" "nomerge" "nonlazybind" "noprofile" "noredzone" "noreturn"
28 "norecurse" "nosync" "noundef" "nounwind" "nosanitize_bounds" "nosanitize_coverage" "null_pointer_is_valid" "optdebug" "optforfuzzing" "optnone" "optsize" "preallocated" "readnone" "readonly" "returned" "returns_twice"
29 "shadowcallstack" "signext" "speculatable" "speculative_load_hardening" "ssp" "sspreq" "sspstrong" "safestack" "sanitize_address" "sanitize_hwaddress" "sanitize_memtag"
30 "sanitize_thread" "sanitize_memory" "strictfp" "swifterror" "uwtable" "vscale_range" "willreturn" "writeonly" "zeroext") '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
)
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
)
42 '("\\b[-]?[0-9]+\\b" . font-lock-preprocessor-face
)
43 ;; Floating point constants
44 '("\\b[-+]?[0-9]+.[0-9]*\\([eE][-+]?[0-9]+\\)?\\b" . font-lock-preprocessor-face
)
46 '("\\b[us]?0x[0-9A-Fa-f]+\\b" . font-lock-preprocessor-face
)
49 '(;; Toplevel entities
50 "declare" "define" "module" "target" "source_filename" "global" "constant" "const" "alias" "ifunc" "comdat"
51 "attributes" "uselistorder" "uselistorder_bb"
53 "private" "internal" "weak" "weak_odr" "linkonce" "linkonce_odr" "available_externally" "appending" "common" "extern_weak" "external"
54 "uninitialized" "implementation" "..."
56 "true" "false" "null" "undef" "zeroinitializer" "none" "c" "asm" "blockaddress" "poison"
58 ;; Calling conventions
59 "ccc" "fastcc" "coldcc" "anyregcc" "preserve_mostcc" "preserve_allcc"
60 "cxx_fast_tlscc" "swiftcc" "tailcc" "swifttailcc" "cfguard_checkcc"
62 "default" "hidden" "protected"
64 "dllimport" "dllexport"
66 "thread_local" "localdynamic" "initialexec" "localexec"
67 ;; Runtime preemption specifiers
68 "dso_preemptable" "dso_local" "dso_local_equivalent"
70 "gc" "atomic" "no_cfi" "volatile" "personality" "prologue" "section") 'symbols
) . font-lock-keyword-face
)
71 ;; Arithmetic and Logical Operators
72 `(,(regexp-opt '("add" "sub" "mul" "sdiv" "udiv" "urem" "srem" "and" "or" "xor"
73 "setne" "seteq" "setlt" "setgt" "setle" "setge") 'symbols
) . font-lock-keyword-face
)
74 ;; Floating-point operators
75 `(,(regexp-opt '("fadd" "fsub" "fneg" "fmul" "fdiv" "frem") 'symbols
) . font-lock-keyword-face
)
76 ;; Special instructions
77 `(,(regexp-opt '("phi" "tail" "call" "select" "to" "shl" "lshr" "ashr" "fcmp" "icmp" "va_arg" "landingpad" "freeze") 'symbols
) . font-lock-keyword-face
)
78 ;; Control instructions
79 `(,(regexp-opt '("ret" "br" "switch" "invoke" "resume" "unwind" "unreachable" "indirectbr" "callbr") 'symbols
) . font-lock-keyword-face
)
81 `(,(regexp-opt '("malloc" "alloca" "free" "load" "store" "getelementptr" "fence" "cmpxchg" "atomicrmw") 'symbols
) . font-lock-keyword-face
)
83 `(,(regexp-opt '("bitcast" "inttoptr" "ptrtoint" "trunc" "zext" "sext" "fptrunc" "fpext" "fptoui" "fptosi" "uitofp" "sitofp" "addrspacecast") 'symbols
) . font-lock-keyword-face
)
85 `(,(regexp-opt '("extractelement" "insertelement" "shufflevector") 'symbols
) . font-lock-keyword-face
)
87 `(,(regexp-opt '("extractvalue" "insertvalue") 'symbols
) . font-lock-keyword-face
)
89 `(,(regexp-opt '("distinct") 'symbols
) . font-lock-keyword-face
)
90 ;; Atomic memory ordering constraints
91 `(,(regexp-opt '("unordered" "monotonic" "acquire" "release" "acq_rel" "seq_cst") 'symbols
) . font-lock-keyword-face
)
93 `(,(regexp-opt '("nnan" "ninf" "nsz" "arcp" "contract" "afn" "reassoc" "fast") 'symbols
) . font-lock-keyword-face
)
94 ;; Use-list order directives
95 `(,(regexp-opt '("uselistorder" "uselistorder_bb") 'symbols
) . font-lock-keyword-face
))
96 "Syntax highlighting for LLVM.")
98 (defun llvm-current-defun-name ()
99 "The `add-log-current-defun' function in LLVM mode."
102 (if (re-search-backward "^[ \t]*define[ \t]+.+[ \t]+@\\(.+\\)(.*)" nil t
)
103 (match-string-no-properties 1))))
106 (define-derived-mode llvm-mode prog-mode
"LLVM"
107 "Major mode for editing LLVM source files.
109 Runs `llvm-mode-hook' on startup."
110 (setq font-lock-defaults
`(llvm-font-lock-keywords))
111 (setq-local defun-prompt-regexp
"^[ \t]*define[ \t]+.+[ \t]+@.+(.*).+")
112 (setq-local add-log-current-defun-function
#'llvm-current-defun-name
)
113 (setq-local comment-start
";"))
115 ;; Associate .ll files with llvm-mode
117 (add-to-list 'auto-mode-alist
(cons "\\.ll\\'" 'llvm-mode
))
121 ;;; llvm-mode.el ends here