* lisp/menu-bar.el: Use function variable instead of switch-to-buffer.
[emacs.git] / lisp / progmodes / ld-script.el
blobc682bfa0280357492feeb2767d29209fe998ea0c
1 ;;; ld-script.el --- GNU linker script editing mode for Emacs
3 ;; Copyright (C) 2001-2011 Free Software Foundation, Inc.
5 ;; Author: Masatake YAMATO<jet@gyve.org>
6 ;; Keywords: languages, faces
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;;; Commentary:
25 ;; Major mode for editing GNU linker (ld) scripts.
27 ;;; Code:
29 ;; Custom
30 (defgroup ld-script nil
31 "GNU linker script code editing commands for Emacs."
32 :prefix "ld-script-"
33 :group 'languages)
35 (defvar ld-script-location-counter-face 'ld-script-location-counter)
36 (defface ld-script-location-counter
37 '((t :weight bold :inherit font-lock-builtin-face))
38 "Face for location counter in GNU ld script."
39 :group 'ld-script)
41 ;; Syntax rules
42 (defvar ld-script-mode-syntax-table
43 (let ((st (make-syntax-table)))
44 (modify-syntax-entry ?\ "-" st)
45 (modify-syntax-entry ?{ "(}" st)
46 (modify-syntax-entry ?} "){" st)
47 (modify-syntax-entry ?\( "()" st)
48 (modify-syntax-entry ?\) ")(" st)
49 (modify-syntax-entry ?\[ "(]" st)
50 (modify-syntax-entry ?\] ")[" st)
51 (modify-syntax-entry ?_ "w" st)
52 (modify-syntax-entry ?. "_" st)
53 (modify-syntax-entry ?\\ "\\" st)
54 (modify-syntax-entry ?: "." st)
55 (modify-syntax-entry ?, "." st)
56 (modify-syntax-entry ?? "." st)
57 (modify-syntax-entry ?= "." st)
58 (modify-syntax-entry ?* ". 23" st)
59 (modify-syntax-entry ?/ ". 14" st)
60 (modify-syntax-entry ?+ "." st)
61 (modify-syntax-entry ?- "." st)
62 (modify-syntax-entry ?! "." st)
63 (modify-syntax-entry ?~ "." st)
64 (modify-syntax-entry ?% "." st)
65 (modify-syntax-entry ?< "." st)
66 (modify-syntax-entry ?> "." st)
67 (modify-syntax-entry ?& "." st)
68 (modify-syntax-entry ?| "." st)
69 (modify-syntax-entry ?\" "\"" st)
70 st)
71 "Syntax table used while in `ld-script-mode'.")
73 ;; Font lock keywords
74 ;; (The section number comes from ld's info.)
75 (defvar ld-script-keywords
77 ;; 3.4.1 Setting the Entry Point
78 "ENTRY"
79 ;; 3.4.2 Commands Dealing with Files
80 "INCLUDE" "INPUT" "GROUP" "AS_NEEDED" "OUTPUT" "SEARCH_DIR" "STARTUP"
81 ;; 3.4.3 Commands Dealing with Object File Formats
82 "OUTPUT_FORMAT" "TARGET"
83 ;; 3.4.4 Assign alias names to memory regions
84 "REGION_ALIAS"
85 ;; 3.4.5 Other Linker Script Commands
86 "ASSERT" "EXTERN" "FORCE_COMMON_ALLOCATION"
87 "INHIBIT_COMMON_ALLOCATION" "INSERT" "AFTER" "BEFORE"
88 "NOCROSSREFS" "OUTPUT_ARCH" "LD_FEATURE"
89 ;; 3.5.2 PROVIDE
90 "PROVIDE"
91 ;; 3.5.3 PROVIDE_HIDDEN
92 "PROVIDE_HIDDEN"
93 ;; 3.6 SECTIONS Command
94 "SECTIONS"
95 ;; 3.6.4.2 Input Section Wildcard Patterns
96 "SORT" "SORT_BY_NAME" "SORT_BY_ALIGNMENT" "SORT_BY_INIT_PRIORITY"
97 ;; 3.6.4.3 Input Section for Common Symbols
98 "COMMON"
99 ;; 3.6.4.4 Input Section and Garbage Collection
100 "KEEP"
101 ;; 3.6.5 Output Section Data
102 "BYTE" "SHORT" "LONG" "QUAD" "SQUAD" "FILL"
103 ;; 3.6.6 Output Section Keywords
104 "CREATE_OBJECT_SYMBOLS" "CONSTRUCTORS"
105 "__CTOR_LIST__" "__CTOR_END__" "__DTOR_LIST__" "__DTOR_END__"
106 ;; 3.6.7 Output Section Discarding
107 ;; See `ld-script-font-lock-keywords'
108 ;; 3.6.8.1 Output Section Type
109 "NOLOAD" "DSECT" "COPY" "INFO" "OVERLAY"
110 ;; 3.6.8.2 Output Section LMA
111 "AT"
112 ;; 3.6.8.4 Forced Input Alignment
113 "SUBALIGN"
114 ;; 3.6.8.5 Output Section Constraint
115 "ONLY_IF_RO" "ONLY_IF_RW"
116 ;; 3.6.8.7 Output Section Phdr
117 ":PHDR"
118 ;; 3.7 MEMORY Command
119 "MEMORY"
120 ;; 3.8 PHDRS Command
121 "PHDRS" "FILEHDR" "FLAGS"
122 "PT_NULL" "PT_LOAD" "PT_DYNAMIC" "PT_INTERP" "PT_NOTE" "PT_SHLIB" "PT_PHDR"
123 ;; 3.9 VERSION Command
124 "VERSION")
125 "Keywords used of GNU ld script.")
128 ;; 3.10.2 Symbolic Constants
129 ;; 3.10.9 Builtin Functions
130 (defvar ld-script-builtins
131 '("CONSTANT"
132 "MAXPAGESIZE"
133 "COMMONPAGESIZE"
134 "ABSOLUTE"
135 "ADDR"
136 "ALIGN"
137 "ALIGNOF"
138 "BLOCK"
139 "DATA_SEGMENT_ALIGN"
140 "DATA_SEGMENT_END"
141 "DATA_SEGMENT_RELRO_END"
142 "DEFINED"
143 "LENGTH" "len" "l"
144 "LOADADDR"
145 "MAX"
146 "MIN"
147 "NEXT"
148 "ORIGIN" "org" "o"
149 "SEGMENT_START"
150 "SIZEOF"
151 "SIZEOF_HEADERS"
152 "sizeof_headers")
153 "Builtin functions of GNU ld script.")
155 (defvar ld-script-font-lock-keywords
156 (append
157 `((,(regexp-opt ld-script-keywords 'words)
158 1 font-lock-keyword-face)
159 (,(regexp-opt ld-script-builtins 'words)
160 1 font-lock-builtin-face)
161 ;; 3.6.7 Output Section Discarding
162 ;; 3.6.4.1 Input Section Basics
163 ;; 3.6.8.7 Output Section Phdr
164 ("/DISCARD/\\|EXCLUDE_FILE\\|:NONE" . font-lock-warning-face)
165 ("\\W\\(\\.\\)\\W" 1 ld-script-location-counter-face)
167 cpp-font-lock-keywords)
168 "Default font-lock-keywords for `ld-script-mode'.")
170 ;;;###autoload
171 (define-derived-mode ld-script-mode prog-mode "LD-Script"
172 "A major mode to edit GNU ld script files"
173 (set (make-local-variable 'comment-start) "/* ")
174 (set (make-local-variable 'comment-end) " */")
175 (set (make-local-variable 'font-lock-defaults)
176 '(ld-script-font-lock-keywords nil)))
178 (provide 'ld-script)
180 ;;; ld-script.el ends here