1;;; llvm-mode.el --- Major mode for the LLVM assembler language. 2 3;; Maintainer: The LLVM team, http://llvm.org/ 4;; Version: 1.0 5 6;;; Commentary: 7 8;; Major mode for editing LLVM IR files. 9 10;;; Code: 11 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.") 20 21(defvar llvm-font-lock-keywords 22 (list 23 ;; Attributes 24 `(,(regexp-opt 25 '("alwaysinline" "argmemonly" "allocsize" "builtin" "cold" "convergent" "dereferenceable" "dereferenceable_or_null" "hot" "inaccessiblememonly" 26 "inaccessiblemem_or_argmemonly" "inalloca" "inlinehint" "jumptable" "minsize" "mustprogress" "naked" "nobuiltin" "nonnull" 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" "optforfuzzing" "optnone" "optsize" "preallocated" "readnone" "readonly" "returned" "returns_twice" 29 "shadowcallstack" "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" "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 39 '("void" "i1" "i8" "i16" "i32" "i64" "i128" "half" "bfloat" "float" "double" "fp128" "x86_fp80" "ppc_fp128" "x86_mmx" "x86_amx" 40 "type" "label" "opaque" "token") 'symbols) . font-lock-type-face) 41 ;; Integer literals 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) 45 ;; Hex constants 46 '("\\b0x[0-9A-Fa-f]+\\b" . font-lock-preprocessor-face) 47 ;; Keywords 48 `(,(regexp-opt 49 '(;; Toplevel entities 50 "declare" "define" "module" "target" "source_filename" "global" "constant" "const" "alias" "ifunc" "comdat" 51 "attributes" "uselistorder" "uselistorder_bb" 52 ;; Linkage types 53 "private" "internal" "weak" "weak_odr" "linkonce" "linkonce_odr" "available_externally" "appending" "common" "extern_weak" "external" 54 "uninitialized" "implementation" "..." 55 ;; Values 56 "true" "false" "null" "undef" "zeroinitializer" "none" "c" "asm" "blockaddress" "poison" 57 58 ;; Calling conventions 59 "ccc" "fastcc" "coldcc" "webkit_jscc" "anyregcc" "preserve_mostcc" "preserve_allcc" 60 "cxx_fast_tlscc" "swiftcc" "tailcc" "swifttailcc" "cfguard_checkcc" 61 ;; Visibility styles 62 "default" "hidden" "protected" 63 ;; DLL storages 64 "dllimport" "dllexport" 65 ;; Thread local 66 "thread_local" "localdynamic" "initialexec" "localexec" 67 ;; Runtime preemption specifiers 68 "dso_preemptable" "dso_local" "dso_local_equivalent" 69 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) 80 ;; Memory operators 81 `(,(regexp-opt '("malloc" "alloca" "free" "load" "store" "getelementptr" "fence" "cmpxchg" "atomicrmw") 'symbols) . font-lock-keyword-face) 82 ;; Casts 83 `(,(regexp-opt '("bitcast" "inttoptr" "ptrtoint" "trunc" "zext" "sext" "fptrunc" "fpext" "fptoui" "fptosi" "uitofp" "sitofp" "addrspacecast") 'symbols) . font-lock-keyword-face) 84 ;; Vector ops 85 `(,(regexp-opt '("extractelement" "insertelement" "shufflevector") 'symbols) . font-lock-keyword-face) 86 ;; Aggregate ops 87 `(,(regexp-opt '("extractvalue" "insertvalue") 'symbols) . font-lock-keyword-face) 88 ;; Metadata types 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) 92 ;; Fast-math flags 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.") 97 98;;;###autoload 99(define-derived-mode llvm-mode prog-mode "LLVM" 100 "Major mode for editing LLVM source files. 101\\{llvm-mode-map} 102 Runs `llvm-mode-hook' on startup." 103 (setq font-lock-defaults `(llvm-font-lock-keywords)) 104 (setq-local comment-start ";")) 105 106;; Associate .ll files with llvm-mode 107;;;###autoload 108(add-to-list 'auto-mode-alist (cons "\\.ll\\'" 'llvm-mode)) 109 110(provide 'llvm-mode) 111 112;;; llvm-mode.el ends here 113