1 ;; Maintainer: The LLVM team, http://llvm.org/ 2 ;; Description: Major mode for the LLVM assembler language. 3 ;; Updated: 2007-09-19 4 5 ;; Create mode-specific tables. 6 (defvar llvm-mode-syntax-table nil 7 "Syntax table used while in LLVM mode.") 8 (defvar llvm-font-lock-keywords 9 (list 10 ;; Comments 11 '(";.*" . font-lock-comment-face) 12 ;; Variables 13 '("%[-a-zA-Z$\._][-a-zA-Z$\._0-9]*" . font-lock-variable-name-face) 14 ;; Labels 15 '("[-a-zA-Z$\._0-9]+:" . font-lock-variable-name-face) 16 ;; Strings 17 '("\"[^\"]+\"" . font-lock-string-face) 18 ;; Unnamed variable slots 19 '("%[-]?[0-9]+" . font-lock-variable-name-face) 20 ;; Types 21 `(,(regexp-opt '("void" "i[0-9]+" "float" "double" "type" "label" "opaque") 'words) . font-lock-type-face) 22 ;; Integer literals 23 '("\\b[-]?[0-9]+\\b" . font-lock-preprocessor-face) 24 ;; Floating point constants 25 '("\\b[-+]?[0-9]+\.[0-9]*\([eE][-+]?[0-9]+\)?\\b" . font-lock-preprocessor-face) 26 ;; Hex constants 27 '("\\b0x[0-9A-Fa-f]+\\b" . font-lock-preprocessor-face) 28 ;; Keywords 29 `(,(regexp-opt '("begin" "end" "true" "false" "zeroinitializer" "declare" 30 "define" "global" "constant" "const" "internal" "linkonce" "linkonce_odr" 31 "weak" "weak_odr" "appending" "uninitialized" "implementation" "..." 32 "null" "undef" "to" "except" "not" "target" "endian" "little" "big" 33 "pointersize" "volatile" "fastcc" "coldcc" "cc") 'words) . font-lock-keyword-face) 34 ;; Arithmetic and Logical Operators 35 `(,(regexp-opt '("add" "sub" "mul" "sdiv" "udiv" "urem" "srem" "and" "or" "xor" 36 "setne" "seteq" "setlt" "setgt" "setle" "setge") 'words) . font-lock-keyword-face) 37 ;; Floating-point operators 38 `(,(regexp-opt '("fadd" "fsub" "fmul" "fdiv" "frem") 'words) . font-lock-keyword-face) 39 ;; Special instructions 40 `(,(regexp-opt '("phi" "tail" "call" "select" "to" "shl" "lshr" "ashr" "fcmp" "icmp" "va_arg" "landingpad") 'words) . font-lock-keyword-face) 41 ;; Control instructions 42 `(,(regexp-opt '("ret" "br" "switch" "invoke" "resume" "unwind" "unreachable" "indirectbr") 'words) . font-lock-keyword-face) 43 ;; Memory operators 44 `(,(regexp-opt '("malloc" "alloca" "free" "load" "store" "getelementptr" "fence" "cmpxchg" "atomicrmw") 'words) . font-lock-keyword-face) 45 ;; Casts 46 `(,(regexp-opt '("bitcast" "inttoptr" "ptrtoint" "trunc" "zext" "sext" "fptrunc" "fpext" "fptoui" "fptosi" "uitofp" "sitofp" "addrspacecast") 'words) . font-lock-keyword-face) 47 ;; Vector ops 48 `(,(regexp-opt '("extractelement" "insertelement" "shufflevector") 'words) . font-lock-keyword-face) 49 ;; Aggregate ops 50 `(,(regexp-opt '("extractvalue" "insertvalue") 'words) . font-lock-keyword-face) 51 52 ) 53 "Syntax highlighting for LLVM" 54 ) 55 56 ;; ---------------------- Syntax table --------------------------- 57 ;; Shamelessly ripped from jasmin.el 58 ;; URL: http://www.neilvandyke.org/jasmin-emacs/jasmin.el.html 59 60 (if (not llvm-mode-syntax-table) 61 (progn 62 (setq llvm-mode-syntax-table (make-syntax-table)) 63 (mapcar (function (lambda (n) 64 (modify-syntax-entry (aref n 0) 65 (aref n 1) 66 llvm-mode-syntax-table))) 67 '( 68 ;; whitespace (` ') 69 [?\^m " "] 70 [?\f " "] 71 [?\n " "] 72 [?\t " "] 73 [?\ " "] 74 ;; word constituents (`w') 75 ;;[?< "w"] 76 ;;[?> "w"] 77 [?\% "w"] 78 ;;[?_ "w "] 79 ;; comments 80 [?\; "< "] 81 [?\n "> "] 82 ;;[?\r "> "] 83 ;;[?\^m "> "] 84 ;; symbol constituents (`_') 85 ;; punctuation (`.') 86 ;; open paren (`(') 87 [?\( "("] 88 [?\[ "("] 89 [?\{ "("] 90 ;; close paren (`)') 91 [?\) ")"] 92 [?\] ")"] 93 [?\} ")"] 94 ;; string quote ('"') 95 [?\" "\""] 96 )))) 97 98 ;; --------------------- Abbrev table ----------------------------- 99 100 (defvar llvm-mode-abbrev-table nil 101 "Abbrev table used while in LLVM mode.") 102 (define-abbrev-table 'llvm-mode-abbrev-table ()) 103 104 (defvar llvm-mode-hook nil) 105 (defvar llvm-mode-map nil) ; Create a mode-specific keymap. 106 107 (if (not llvm-mode-map) 108 () ; Do not change the keymap if it is already set up. 109 (setq llvm-mode-map (make-sparse-keymap)) 110 (define-key llvm-mode-map "\t" 'tab-to-tab-stop) 111 (define-key llvm-mode-map "\es" 'center-line) 112 (define-key llvm-mode-map "\eS" 'center-paragraph)) 113 114 115 (defun llvm-mode () 116 "Major mode for editing LLVM source files. 117 \\{llvm-mode-map} 118 Runs llvm-mode-hook on startup." 119 (interactive) 120 (kill-all-local-variables) 121 (use-local-map llvm-mode-map) ; Provides the local keymap. 122 (setq major-mode 'llvm-mode) 123 124 (make-local-variable 'font-lock-defaults) 125 (setq major-mode 'llvm-mode ; This is how describe-mode 126 ; finds the doc string to print. 127 mode-name "LLVM" ; This name goes into the modeline. 128 font-lock-defaults `(llvm-font-lock-keywords)) 129 130 (setq local-abbrev-table llvm-mode-abbrev-table) 131 (set-syntax-table llvm-mode-syntax-table) 132 (setq comment-start ";") 133 (run-hooks 'llvm-mode-hook)) ; Finally, this permits the user to 134 ; customize the mode with a hook. 135 136 ;; Associate .ll files with llvm-mode 137 (setq auto-mode-alist 138 (append '(("\\.ll$" . llvm-mode)) auto-mode-alist)) 139 140 (provide 'llvm-mode) 141 ;; end of llvm-mode.el 142