brintos

brintos / llvm-project-archived public Read only

0
0
Text · 6.9 KiB · 240c133 Raw
147 lines · plain
1;;; llvm-mode.el --- Major mode for the LLVM assembler language.2 3;; Maintainer:  The LLVM team, http://llvm.org/4;; Version: 1.05 6;;; Commentary:7 8;; Major mode for editing LLVM IR files.9 10;;; Code:11 12(defvar llvm-mode-syntax-table13  (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(defconst llvm-mode-primitive-type-regexp22  (concat23   "\\(i[0-9]+\\|"24   (regexp-opt25    '("void" "half" "bfloat" "float" "double" "fp128" "x86_fp80" "ppc_fp128"26      "x86_mmx" "x86_amx" "ptr" "type" "label" "opaque" "token") t)27   "\\)"))28 29(defvar llvm-font-lock-keywords30  (list31   ;; Attributes32   `(,(regexp-opt33       '("alwaysinline" "argmemonly" "allocsize" "builtin" "cold" "convergent" "dereferenceable" "dereferenceable_or_null" "hot" "immarg" "inaccessiblememonly"34         "inaccessiblemem_or_argmemonly" "inalloca" "inlinehint" "jumptable" "minsize" "mustprogress" "naked" "nobuiltin" "nonnull" "nocapture"35         "nocallback" "nocf_check" "noduplicate" "noext" "nofree" "noimplicitfloat" "noinline" "nomerge" "nonlazybind" "noprofile" "noredzone" "noreturn"36         "norecurse" "nosync" "noundef" "nounwind" "nosanitize_bounds" "nosanitize_coverage" "null_pointer_is_valid" "optdebug" "optforfuzzing" "optnone" "optsize" "preallocated" "readnone" "readonly" "returned" "returns_twice"37         "shadowcallstack" "signext" "speculatable" "speculative_load_hardening" "ssp" "sspreq" "sspstrong" "safestack" "sanitize_address" "sanitize_alloc_token" "sanitize_hwaddress" "sanitize_memtag"38         "sanitize_thread" "sanitize_memory" "strictfp" "swifterror" "uwtable" "vscale_range" "willreturn" "writeonly" "zeroext") 'symbols) . font-lock-constant-face)39   ;; Variables40   '("%[-a-zA-Z$._][-a-zA-Z$._0-9]*" . font-lock-variable-name-face)41   ;; Labels42   '("[-a-zA-Z$._0-9]+:" . font-lock-variable-name-face)43   ;; Unnamed variable slots44   '("%[-]?[0-9]+" . font-lock-variable-name-face)45   ;; Function names46   '("@[-a-zA-Z$._][-a-zA-Z$._0-9]*" . font-lock-function-name-face)47   ;; Fixed vector types48   `(,(concat "<[ \t]*\\([0-9]+\\)[ \t]*x[ \t]+"49	      llvm-mode-primitive-type-regexp50	      "[ \t]*>")51     (1 'font-lock-type-face)52     (2 'font-lock-type-face))53   ;; Scalable vector types54   `(,(concat "<[ \t]*\\(vscale[ \t]\\)+x[ \t]+\\([0-9]+\\)[ \t]*x[ \t]+"55	      llvm-mode-primitive-type-regexp56	      "[ \t]*>")57     (1 'font-lock-keyword-face)58     (2 'font-lock-type-face)59     (3 'font-lock-type-face))60   ;; Primitive types61   `(,(concat "\\<" llvm-mode-primitive-type-regexp "\\>") . font-lock-type-face)62   ;; Integer literals63   '("\\b[-]?[0-9]+\\b" . font-lock-preprocessor-face)64   ;; Values that can appear in a vec65   '("\\b\\(true\\|false\\|null\\|undef\\|poison\\|none\\)\\b" . font-lock-keyword-face)66   ;; Floating point constants67   '("\\b[-+]?[0-9]+.[0-9]*\\([eE][-+]?[0-9]+\\)?\\b" . font-lock-preprocessor-face)68   ;; Hex constants69   '("\\b[us]?0x[0-9A-Fa-f]+\\b" . font-lock-preprocessor-face)70   ;; Keywords71   `(,(regexp-opt72       '(;; Toplevel entities73         "declare" "define" "module" "target" "source_filename" "global" "constant" "const" "alias" "ifunc" "comdat"74         "attributes" "uselistorder" "uselistorder_bb"75         ;; Linkage types76         "private" "internal" "weak" "weak_odr" "linkonce" "linkonce_odr" "available_externally" "appending" "common" "extern_weak" "external"77         "uninitialized" "implementation" "..."78         ;; Values79         "zeroinitializer" "c" "asm" "blockaddress"80 81         ;; Calling conventions82         "ccc" "fastcc" "coldcc" "anyregcc" "preserve_mostcc" "preserve_allcc"83         "cxx_fast_tlscc" "swiftcc" "tailcc" "swifttailcc" "cfguard_checkcc"84         ;; Visibility styles85         "default" "hidden" "protected"86         ;; DLL storages87         "dllimport" "dllexport"88         ;; Thread local89         "thread_local" "localdynamic" "initialexec" "localexec"90         ;; Runtime preemption specifiers91         "dso_preemptable" "dso_local" "dso_local_equivalent"92 93         "gc" "atomic" "no_cfi" "volatile" "personality" "prologue" "section") 'symbols) . font-lock-keyword-face)94   ;; Arithmetic and Logical Operators95   `(,(regexp-opt '("add" "sub" "mul" "sdiv" "udiv" "urem" "srem" "and" "or" "xor"96                    "setne" "seteq" "setlt" "setgt" "setle" "setge") 'symbols) . font-lock-keyword-face)97   ;; Floating-point operators98   `(,(regexp-opt '("fadd" "fsub" "fneg" "fmul" "fdiv" "frem") 'symbols) . font-lock-keyword-face)99   ;; Special instructions100   `(,(regexp-opt '("phi" "tail" "call" "select" "to" "shl" "lshr" "ashr" "fcmp" "icmp" "va_arg" "landingpad" "freeze") 'symbols) . font-lock-keyword-face)101   ;; Control instructions102   `(,(regexp-opt '("ret" "br" "switch" "invoke" "resume" "unwind" "unreachable" "indirectbr" "callbr") 'symbols) . font-lock-keyword-face)103   ;; Memory operators104   `(,(regexp-opt '("malloc" "alloca" "free" "load" "store" "getelementptr" "fence" "cmpxchg" "atomicrmw") 'symbols) . font-lock-keyword-face)105   ;; Casts106   `(,(regexp-opt '("bitcast" "inttoptr" "ptrtoint" "trunc" "zext" "sext" "fptrunc" "fpext" "fptoui" "fptosi" "uitofp" "sitofp" "addrspacecast") 'symbols) . font-lock-keyword-face)107   ;; Vector ops108   `(,(regexp-opt '("extractelement" "insertelement" "shufflevector") 'symbols) . font-lock-keyword-face)109   ;; Aggregate ops110   `(,(regexp-opt '("extractvalue" "insertvalue") 'symbols) . font-lock-keyword-face)111   ;; Metadata types112   `(,(regexp-opt '("distinct") 'symbols) . font-lock-keyword-face)113   ;; Debug records114   `(,(concat "#" (regexp-opt '("dbg_assign" "dbg_declare" "dbg_label" "dbg_value") 'symbols)) . font-lock-keyword-face)115   ;; Atomic memory ordering constraints116   `(,(regexp-opt '("unordered" "monotonic" "acquire" "release" "acq_rel" "seq_cst") 'symbols) . font-lock-keyword-face)117   ;; Fast-math flags118   `(,(regexp-opt '("nnan" "ninf" "nsz" "arcp" "contract" "afn" "reassoc" "fast") 'symbols) . font-lock-keyword-face)119   ;; Use-list order directives120   `(,(regexp-opt '("uselistorder" "uselistorder_bb") 'symbols) . font-lock-keyword-face))121  "Syntax highlighting for LLVM.")122 123(defun llvm-current-defun-name ()124  "The `add-log-current-defun' function in LLVM mode."125  (save-excursion126    (end-of-line)127    (if (re-search-backward "^[ \t]*define[ \t]+.+[ \t]+@\\(.+\\)(.*)" nil t)128	(match-string-no-properties 1))))129 130;;;###autoload131(define-derived-mode llvm-mode prog-mode "LLVM"132  "Major mode for editing LLVM source files.133\\{llvm-mode-map}134  Runs `llvm-mode-hook' on startup."135  (setq font-lock-defaults `(llvm-font-lock-keywords))136  (setq-local defun-prompt-regexp "^[ \t]*define[ \t]+.+[ \t]+@.+(.*).+")137  (setq-local add-log-current-defun-function #'llvm-current-defun-name)138  (setq-local comment-start ";"))139 140;; Associate .ll files with llvm-mode141;;;###autoload142(add-to-list 'auto-mode-alist (cons "\\.ll\\'" 'llvm-mode))143 144(provide 'llvm-mode)145 146;;; llvm-mode.el ends here147