1;;; llvm-mode.el --- Major mode for the LLVM assembler language. 2 3;; Maintainer: The LLVM team, http://llvm.org/ 4 5;;; Commentary: 6 7;; Major mode for editing LLVM IR files. 8 9;;; Code: 10 11(defvar llvm-mode-syntax-table 12 (let ((table (make-syntax-table))) 13 (modify-syntax-entry ?% "_" table) 14 (modify-syntax-entry ?. "_" table) 15 (modify-syntax-entry ?\; "< " table) 16 (modify-syntax-entry ?\n "> " table) 17 table) 18 "Syntax table used while in LLVM mode.") 19 20(defvar llvm-font-lock-keywords 21 (list 22 ;; Variables 23 '("%[-a-zA-Z$\._][-a-zA-Z$\._0-9]*" . font-lock-variable-name-face) 24 ;; Labels 25 '("[-a-zA-Z$\._0-9]+:" . font-lock-variable-name-face) 26 ;; Unnamed variable slots 27 '("%[-]?[0-9]+" . font-lock-variable-name-face) 28 ;; Types 29 `(,(regexp-opt '("void" "i1" "i8" "i16" "i32" "i64" "i128" "float" "double" "type" "label" "opaque") 'symbols) . font-lock-type-face) 30 ;; Integer literals 31 '("\\b[-]?[0-9]+\\b" . font-lock-preprocessor-face) 32 ;; Floating point constants 33 '("\\b[-+]?[0-9]+\.[0-9]*\([eE][-+]?[0-9]+\)?\\b" . font-lock-preprocessor-face) 34 ;; Hex constants 35 '("\\b0x[0-9A-Fa-f]+\\b" . font-lock-preprocessor-face) 36 ;; Keywords 37 `(,(regexp-opt '("begin" "end" "true" "false" "zeroinitializer" "declare" 38 "define" "global" "constant" "const" "internal" "linkonce" "linkonce_odr" 39 "weak" "weak_odr" "appending" "uninitialized" "implementation" "..." 40 "null" "undef" "to" "except" "not" "target" "endian" "little" "big" 41 "pointersize" "volatile" "fastcc" "coldcc" "cc" "personality") 'symbols) . font-lock-keyword-face) 42 ;; Arithmetic and Logical Operators 43 `(,(regexp-opt '("add" "sub" "mul" "sdiv" "udiv" "urem" "srem" "and" "or" "xor" 44 "setne" "seteq" "setlt" "setgt" "setle" "setge") 'symbols) . font-lock-keyword-face) 45 ;; Floating-point operators 46 `(,(regexp-opt '("fadd" "fsub" "fmul" "fdiv" "frem") 'symbols) . font-lock-keyword-face) 47 ;; Special instructions 48 `(,(regexp-opt '("phi" "tail" "call" "select" "to" "shl" "lshr" "ashr" "fcmp" "icmp" "va_arg" "landingpad") 'symbols) . font-lock-keyword-face) 49 ;; Control instructions 50 `(,(regexp-opt '("ret" "br" "switch" "invoke" "resume" "unwind" "unreachable" "indirectbr") 'symbols) . font-lock-keyword-face) 51 ;; Memory operators 52 `(,(regexp-opt '("malloc" "alloca" "free" "load" "store" "getelementptr" "fence" "cmpxchg" "atomicrmw") 'symbols) . font-lock-keyword-face) 53 ;; Casts 54 `(,(regexp-opt '("bitcast" "inttoptr" "ptrtoint" "trunc" "zext" "sext" "fptrunc" "fpext" "fptoui" "fptosi" "uitofp" "sitofp" "addrspacecast") 'symbols) . font-lock-keyword-face) 55 ;; Vector ops 56 `(,(regexp-opt '("extractelement" "insertelement" "shufflevector") 'symbols) . font-lock-keyword-face) 57 ;; Aggregate ops 58 `(,(regexp-opt '("extractvalue" "insertvalue") 'symbols) . font-lock-keyword-face) 59 ;; Metadata types 60 `(,(regexp-opt '("distinct") 'symbols) . font-lock-keyword-face) 61 ;; Use-list order directives 62 `(,(regexp-opt '("uselistorder" "uselistorder_bb") 'symbols) . font-lock-keyword-face)) 63 "Syntax highlighting for LLVM.") 64 65;; Emacs 23 compatibility. 66(defalias 'llvm-mode-prog-mode 67 (if (fboundp 'prog-mode) 68 'prog-mode 69 'fundamental-mode)) 70 71;;;###autoload 72(define-derived-mode llvm-mode llvm-mode-prog-mode "LLVM" 73 "Major mode for editing LLVM source files. 74\\{llvm-mode-map} 75 Runs `llvm-mode-hook' on startup." 76 (setq font-lock-defaults `(llvm-font-lock-keywords)) 77 (setq comment-start ";")) 78 79;; Associate .ll files with llvm-mode 80;;;###autoload 81(add-to-list 'auto-mode-alist (cons (purecopy "\\.ll\\'") 'llvm-mode)) 82 83(provide 'llvm-mode) 84 85;;; llvm-mode.el ends here 86