2006-03-14 05:54:52 +00:00
|
|
|
;; Maintainer: The LLVM team, http://llvm.org/
|
2003-08-11 19:10:02 +00:00
|
|
|
;; Description: Major mode for TableGen description files (part of LLVM project)
|
2007-12-19 06:20:05 +00:00
|
|
|
;; Updated: 2007-12-18
|
2007-03-27 20:23:56 +00:00
|
|
|
|
|
|
|
(require 'comint)
|
|
|
|
(require 'custom)
|
|
|
|
(require 'ansi-color)
|
2003-08-11 19:10:02 +00:00
|
|
|
|
|
|
|
;; Create mode-specific tables.
|
2007-03-27 20:23:56 +00:00
|
|
|
(defvar td-decorators-face 'td-decorators-face
|
|
|
|
"Face method decorators.")
|
|
|
|
(make-face 'td-decorators-face)
|
|
|
|
|
2003-08-11 19:10:02 +00:00
|
|
|
(defvar tablegen-font-lock-keywords
|
2007-03-27 20:23:56 +00:00
|
|
|
(let ((kw (mapconcat 'identity
|
2007-12-08 23:58:46 +00:00
|
|
|
'("class" "defm" "def" "field" "include" "in"
|
2007-03-27 20:23:56 +00:00
|
|
|
"let" "multiclass")
|
|
|
|
"\\|"))
|
|
|
|
(type-kw (mapconcat 'identity
|
|
|
|
'("bit" "bits" "code" "dag" "int" "list" "string")
|
|
|
|
"\\|"))
|
|
|
|
)
|
|
|
|
(list
|
|
|
|
;; Comments
|
2007-12-19 06:20:05 +00:00
|
|
|
;; '("\/\/" . font-lock-comment-face)
|
2007-03-27 20:23:56 +00:00
|
|
|
;; Strings
|
|
|
|
'("\"[^\"]+\"" . font-lock-string-face)
|
|
|
|
;; Hex constants
|
2008-07-23 04:49:20 +00:00
|
|
|
'("\\<0x[0-9A-Fa-f]+\\>" . font-lock-preprocessor-face)
|
2007-03-27 20:23:56 +00:00
|
|
|
;; Binary constants
|
2008-07-23 04:49:20 +00:00
|
|
|
'("\\<0b[01]+\\>" . font-lock-preprocessor-face)
|
2007-03-27 20:23:56 +00:00
|
|
|
;; Integer literals
|
2008-07-23 04:49:20 +00:00
|
|
|
'("\\<[-]?[0-9]+\\>" . font-lock-preprocessor-face)
|
2007-03-27 20:23:56 +00:00
|
|
|
;; Floating point constants
|
2008-07-23 04:49:20 +00:00
|
|
|
'("\\<[-+]?[0-9]+\.[0-9]*\([eE][-+]?[0-9]+\)?\\>" . font-lock-preprocessor-face)
|
2007-03-27 20:23:56 +00:00
|
|
|
|
|
|
|
'("^[ \t]*\\(@.+\\)" 1 'td-decorators-face)
|
|
|
|
;; Keywords
|
|
|
|
(cons (concat "\\<\\(" kw "\\)\\>[ \n\t(]") 1)
|
|
|
|
|
|
|
|
;; Type keywords
|
|
|
|
(cons (concat "\\<\\(" type-kw "\\)[ \n\t(]") 1)
|
|
|
|
))
|
|
|
|
"Additional expressions to highlight in TableGen mode.")
|
|
|
|
(put 'tablegen-mode 'font-lock-defaults '(tablegen-font-lock-keywords))
|
2003-08-11 19:10:02 +00:00
|
|
|
|
|
|
|
;; ---------------------- Syntax table ---------------------------
|
|
|
|
;; Shamelessly ripped from jasmin.el
|
2007-12-08 23:58:46 +00:00
|
|
|
;; URL: http://www.neilvandyke.org/jasmin-emacs/jasmin.el
|
2003-08-11 19:10:02 +00:00
|
|
|
|
2007-12-19 06:20:05 +00:00
|
|
|
(defvar tablegen-mode-syntax-table nil
|
|
|
|
"Syntax table used in `tablegen-mode' buffers.")
|
|
|
|
(when (not tablegen-mode-syntax-table)
|
|
|
|
(setq tablegen-mode-syntax-table (make-syntax-table))
|
|
|
|
;; whitespace (` ')
|
|
|
|
(modify-syntax-entry ?\ " " tablegen-mode-syntax-table)
|
|
|
|
(modify-syntax-entry ?\t " " tablegen-mode-syntax-table)
|
|
|
|
(modify-syntax-entry ?\r " " tablegen-mode-syntax-table)
|
|
|
|
(modify-syntax-entry ?\n " " tablegen-mode-syntax-table)
|
|
|
|
(modify-syntax-entry ?\f " " tablegen-mode-syntax-table)
|
|
|
|
;; word constituents (`w')
|
|
|
|
(modify-syntax-entry ?\% "w" tablegen-mode-syntax-table)
|
|
|
|
(modify-syntax-entry ?\_ "w" tablegen-mode-syntax-table)
|
|
|
|
;; comments
|
|
|
|
(modify-syntax-entry ?/ ". 124b" tablegen-mode-syntax-table)
|
|
|
|
(modify-syntax-entry ?* ". 23" tablegen-mode-syntax-table)
|
|
|
|
(modify-syntax-entry ?\n "> b" tablegen-mode-syntax-table)
|
|
|
|
;; open paren (`(')
|
|
|
|
(modify-syntax-entry ?\( "(" tablegen-mode-syntax-table)
|
|
|
|
(modify-syntax-entry ?\[ "(" tablegen-mode-syntax-table)
|
|
|
|
(modify-syntax-entry ?\{ "(" tablegen-mode-syntax-table)
|
|
|
|
(modify-syntax-entry ?\< "(" tablegen-mode-syntax-table)
|
|
|
|
;; close paren (`)')
|
|
|
|
(modify-syntax-entry ?\) ")" tablegen-mode-syntax-table)
|
|
|
|
(modify-syntax-entry ?\] ")" tablegen-mode-syntax-table)
|
|
|
|
(modify-syntax-entry ?\} ")" tablegen-mode-syntax-table)
|
|
|
|
(modify-syntax-entry ?\> ")" tablegen-mode-syntax-table)
|
|
|
|
;; string quote ('"')
|
|
|
|
(modify-syntax-entry ?\" "\"" tablegen-mode-syntax-table)
|
|
|
|
)
|
2003-08-11 19:10:02 +00:00
|
|
|
|
|
|
|
;; --------------------- Abbrev table -----------------------------
|
|
|
|
|
|
|
|
(defvar tablegen-mode-abbrev-table nil
|
|
|
|
"Abbrev table used while in TableGen mode.")
|
|
|
|
(define-abbrev-table 'tablegen-mode-abbrev-table ())
|
|
|
|
|
|
|
|
(defvar tablegen-mode-hook nil)
|
|
|
|
(defvar tablegen-mode-map nil) ; Create a mode-specific keymap.
|
|
|
|
|
|
|
|
(if (not tablegen-mode-map)
|
|
|
|
() ; Do not change the keymap if it is already set up.
|
|
|
|
(setq tablegen-mode-map (make-sparse-keymap))
|
2007-12-08 23:58:46 +00:00
|
|
|
(define-key tablegen-mode-map "\t" 'tab-to-tab-stop)
|
2003-08-11 19:10:02 +00:00
|
|
|
(define-key tablegen-mode-map "\es" 'center-line)
|
|
|
|
(define-key tablegen-mode-map "\eS" 'center-paragraph))
|
|
|
|
|
|
|
|
(defun tablegen-mode ()
|
|
|
|
"Major mode for editing TableGen description files.
|
|
|
|
\\{tablegen-mode-map}
|
|
|
|
Runs tablegen-mode-hook on startup."
|
|
|
|
(interactive)
|
|
|
|
(kill-all-local-variables)
|
2007-12-19 06:20:05 +00:00
|
|
|
(use-local-map tablegen-mode-map) ; Provides the local keymap.
|
2007-12-08 23:58:46 +00:00
|
|
|
(make-local-variable 'font-lock-defaults)
|
2007-12-19 06:20:05 +00:00
|
|
|
(setq major-mode 'tablegen-mode ; This is how describe-mode
|
|
|
|
; finds the doc string to print.
|
|
|
|
mode-name "TableGen" ; This name goes into the modeline.
|
|
|
|
local-abbrev-table tablegen-mode-abbrev-table
|
|
|
|
font-lock-defaults `(tablegen-font-lock-keywords)
|
|
|
|
require-final-newline t
|
|
|
|
)
|
2003-08-11 19:10:02 +00:00
|
|
|
|
|
|
|
(set-syntax-table tablegen-mode-syntax-table)
|
2007-12-19 06:20:05 +00:00
|
|
|
(run-hooks 'tablegen-mode-hook)) ; Finally, this permits the user to
|
|
|
|
; customize the mode with a hook.
|
2003-08-11 19:10:02 +00:00
|
|
|
|
|
|
|
;; Associate .td files with tablegen-mode
|
|
|
|
(setq auto-mode-alist (append '(("\\.td$" . tablegen-mode)) auto-mode-alist))
|
|
|
|
|
|
|
|
(provide 'tablegen-mode)
|
|
|
|
;; end of tablegen-mode.el
|