[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/beardbolt cf7d2787bc 027/323: Implement line number par
From: |
ELPA Syncer |
Subject: |
[elpa] externals/beardbolt cf7d2787bc 027/323: Implement line number parsing |
Date: |
Thu, 9 Mar 2023 10:57:56 -0500 (EST) |
branch: externals/beardbolt
commit cf7d2787bce4ba509325d642e31b32960a64c985
Author: Jay Kamat <jaygkamat@gmail.com>
Commit: Jay Kamat <jaygkamat@gmail.com>
Implement line number parsing
---
rmsbolt.el | 76 +++++++++++++++++++++++++++++++++++++++++++++++---------------
1 file changed, 58 insertions(+), 18 deletions(-)
diff --git a/rmsbolt.el b/rmsbolt.el
index aca6b84313..effa8170d7 100644
--- a/rmsbolt.el
+++ b/rmsbolt.el
@@ -86,7 +86,8 @@
(expand-file-name "rmsbolt.out" rmsbolt-temp-dir)
(expand-file-name "rmsbolt.s" rmsbolt-temp-dir)))
-(defvar-local rmsbolt-dissasemble nil)
+(defvar-local rmsbolt-line-mapping nil
+ "Line mapping hashtable from source lines -> asm lines")
;;;; Regexes
@@ -139,6 +140,14 @@
(opt " ")))
(0+ space)
(group (0+ any))))
+(defvar rmsbolt-source-tag (rx bol (0+ space) ".loc" (1+ space)
+ (group (1+ digit)) (1+ space)
+ (group (1+ digit))
+ (0+ any)))
+(defvar rmsbolt-source-stab (rx bol (0+ any) ".stabn" (1+ space)
+ (group (1+ digit)) ",0,"
+ (group (1+ digit)) "," (0+ any)))
+
;;;; Classes
@@ -200,6 +209,7 @@
"frame_dummy"
(and ".plt" (0+ any)))
eol))
+;;;; Language Definitions
(defvar rmsbolt-languages)
(setq
rmsbolt-languages
@@ -397,9 +407,7 @@ int main() {
(push (concat "\t" (match-string 3 line)) result)
(go continue))
continue))
- (mapconcat 'identity
- (nreverse result)
- "\n")))
+ (nreverse result)))
(cl-defun rmsbolt--process-asm-lines (src-buffer asm-lines)
"Process and filter a set of asm lines."
@@ -407,7 +415,8 @@ int main() {
(rmsbolt--process-dissasembled-lines src-buffer asm-lines)
(let ((used-labels (rmsbolt--find-used-labels src-buffer asm-lines))
(result nil)
- (prev-label nil))
+ (prev-label nil)
+ (source-linum nil))
(dolist (line asm-lines)
(let* ((raw-match (or (string-match rmsbolt-label-def line)
(string-match rmsbolt-assignment-def line)))
@@ -415,7 +424,18 @@ int main() {
(match-string 1 line)))
(used-label (cl-find match used-labels :test #'equal)))
(cl-tagbody
- ;; TODO process line numbers
+ ;; Process any line number hints
+ (when (string-match rmsbolt-source-tag line)
+ (setq source-linum
+ (string-to-number
+ (match-string 2 line))))
+ (when (string-match rmsbolt-source-stab line)
+ (pcase (string-to-number (match-string 1 line))
+ (68
+ (setq source-linum (match-string 2 line)))
+ ((or 100 132)
+ (setq source-linum nil))))
+
;; End block, reset prev-label and source
(when (string-match-p rmsbolt-endblock line)
(setq prev-label nil))
@@ -440,11 +460,16 @@ int main() {
nil
(when (string-match-p rmsbolt-directive line)
(go continue))))
+ ;; Add line numbers to mapping
+ (when (and source-linum
+ (rmsbolt--has-opcode-p line))
+ (add-text-properties 0 (length line)
+ `(rmsbolt-src-line ,source-linum) line))
+ ;; Add line
(push line result)
+
continue)))
- (mapconcat 'identity
- (nreverse result)
- "\n"))))
+ (nreverse result))))
;;;;; Handlers
(defun rmsbolt--handle-finish-compile (buffer _str)
@@ -460,15 +485,30 @@ int main() {
(cond ((not compilation-fail)
(if (not (file-exists-p (rmsbolt-output-filename src-buffer t)))
(message "Error reading from output file.")
- (delete-region (point-min) (point-max))
- (insert
- (rmsbolt--process-asm-lines
- src-buffer
- (with-temp-buffer
- (insert-file-contents (rmsbolt-output-filename src-buffer
t))
- (split-string (buffer-string) "\n" t))))
- (asm-mode)
- (display-buffer (current-buffer))))
+ (let ((lines
+ (rmsbolt--process-asm-lines
+ src-buffer
+ (with-temp-buffer
+ (insert-file-contents (rmsbolt-output-filename
src-buffer t))
+ (split-string (buffer-string) "\n" t))))
+ (ht (make-hash-table))
+ (linum 0))
+ ;; Add lines to hashtable
+ (dolist (line lines)
+ (cl-pushnew
+ linum
+ (gethash
+ (get-text-property
+ 0 'rmsbolt-src-line line)
+ ht))
+ (incf linum))
+ (with-current-buffer src-buffer
+ (setq-local rmsbolt-line-mapping ht))
+ (delete-region (point-min) (point-max))
+ (insert
+ (mapconcat 'identity lines "\n"))
+ (asm-mode)
+ (display-buffer (current-buffer)))))
(t
;; Display compilation output
(display-buffer buffer))))))
- [elpa] externals/beardbolt 3ca3f35cdb 050/323: Add very basic support for rust, (continued)
- [elpa] externals/beardbolt 3ca3f35cdb 050/323: Add very basic support for rust, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 65a1ac7b6e 054/323: Add support for demangling, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt bb64352f8d 034/323: Store and use ranges to view highlighted regions, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 1419a90465 040/323: Add C/C++ demo, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 39f1e05667 009/323: Add filter for commentOnly, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 4a35528d7d 021/323: Configure all variables with buffer-local values, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 3bfc7ed2e3 012/323: Allow custom functions to parse arguments, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 98cea6e8e0 023/323: Simplify creation of new starters with a macro, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 547a47e58f 022/323: Fix default commands, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 2530003c71 020/323: Remove rmsbolt-options, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt cf7d2787bc 027/323: Implement line number parsing,
ELPA Syncer <=
- [elpa] externals/beardbolt 8fc36eacd8 044/323: Add option to force assembling, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt d37f8a0ebf 042/323: Remove reliance on hl-line-mode, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt a0527f16af 045/323: Add very basic support for common lisp, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt d7acfdd127 041/323: Fix rmsbolt temp directory generation being too late, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt f0d13c4ac2 036/323: Add a stronger blacklist for ocaml asm, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 22810d69a7 062/323: Add docs for python, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 503b51ecb8 066/323: Fix typo, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt ca92d533ad 061/323: Add basic support for python, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt fef52d3de3 057/323: Update readme, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 1f50b7bb7f 069/323: Add java framework, ELPA Syncer, 2023/03/09