-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrewriter-gdbarch.el
81 lines (73 loc) · 2.2 KB
/
rewriter-gdbarch.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
;; rewrite a single gdbarch method.
;; Usage: emacs --script rewriter.el gdbarch
(defvar rw-arch-method)
(defvar rw-arch-setter)
(defvar rw-arch-getter)
(defvar rw-arch-p)
(defun rw-arch-setter ()
(while (re-search-forward rw-arch-setter nil t)
(let ((start (match-beginning 0))
lhs)
(goto-char (match-end 0))
(skip-syntax-forward " ")
(when (looking-at "(")
(forward-char)
(setq lhs (rw-extract-and-skip-expr ","))
;; Skip the ",".
(forward-char)
(skip-syntax-forward " ")
(delete-region start (point))
(insert lhs "->" rw-arch-method ".set (")))))
(defun rw-arch-getter ()
(while (re-search-forward rw-arch-getter nil t)
(let ((start (match-beginning 0))
(is-p-form (match-beginning 1))
lhs)
(goto-char (match-end 0))
(skip-syntax-forward " ")
(when (looking-at "(")
(forward-char)
(setq lhs (rw-extract-and-skip-expr "[,)]"))
(when (looking-at ",")
;; Skip the ",".
(forward-char)
(skip-syntax-forward " "))
(delete-region start (point))
(insert lhs "->" rw-arch-method
(if is-p-form
".is_set"
"")
" (")))))
(defun rw-arch-process ()
(let ((rw-arch-setter (concat "\\_<set_gdbarch_" rw-arch-method "\\_>"))
(rw-arch-getter (concat "\\_<gdbarch_" rw-arch-method "\\(_p\\)?\\_>"))
(rw-arch-p (concat "\\_<gdbarch_" rw-arch-method "\\_>")))
(unless buffer-read-only
(rw-arch-setter)
(goto-char (point-min))
(rw-arch-getter))))
(defun rw-scan-gdbarch.sh ()
(find-file "gdbarch.sh")
(goto-char (point-min))
(re-search-forward "cat <<EOF")
(forward-line)
(while (not (looking-at "EOF"))
;; Treat non-matching lines as comments.
(when (looking-at "^[^;\n]+;[^;\n]+;\\([^;\n]+\\);")
(let ((rw-arch-method (match-string 1))
(changed nil))
(message "Processing %s" rw-arch-method)
(save-excursion
(dolist (file (rw-files))
(find-file file)
(goto-char (point-min))
(rw-arch-process)
(when (buffer-modified-p)
(setq changed t)
(save-buffer))))
(if changed
(rw-git-commit (concat "Changes for " rw-arch-method))
;; This shouldn't happen, but let's check.
(message (concat "!!!! No changes for " rw-arch-method)))))
(forward-line)))
(rw-scan-gdbarch.sh)