[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/beardbolt 627dd4c1c9 059/323: Allow for custom asm proc
From: |
ELPA Syncer |
Subject: |
[elpa] externals/beardbolt 627dd4c1c9 059/323: Allow for custom asm processing functions |
Date: |
Thu, 9 Mar 2023 10:58:16 -0500 (EST) |
branch: externals/beardbolt
commit 627dd4c1c9650818b587ddb891eefb3b8699819e
Author: Jay Kamat <jaygkamat@gmail.com>
Commit: Jay Kamat <jaygkamat@gmail.com>
Allow for custom asm processing functions
Useful for bytecode
---
rmsbolt.el | 185 +++++++++++++++++++++++++++++++++++--------------------------
1 file changed, 107 insertions(+), 78 deletions(-)
diff --git a/rmsbolt.el b/rmsbolt.el
index 702d601af0..f1fb2b288c 100644
--- a/rmsbolt.el
+++ b/rmsbolt.el
@@ -229,7 +229,7 @@ Outputs assembly file if ASM."
:type 'symbol
:documentation "The object dumper to use if disassembling binary.")
(demangler
- "c++filt"
+ nil
:type 'string
:documentation "The command of the demangler to use for this source code.")
(starter-file-name
@@ -247,7 +247,13 @@ Outputs assembly file if ASM."
(compile-cmd-function
nil
:type 'function
- :documentation "A function which takes in a compile command (could be the
default) and adds needed args to it."))
+ :documentation "A function which takes in a compile command
+(could be the default) and adds needed args to it.")
+ (process-asm-custom-fn
+ nil
+ :type 'function
+ :documentation "A custom function used for parsing asm lines
+ instead of the default assembly one." ))
(cl-defun rmsbolt--c-compile-cmd (&key src-buffer)
@@ -337,6 +343,13 @@ Outputs assembly file if ASM."
"-Cllvm-args=--x86-asm-syntax=intel"))
" ")))
cmd))
+(cl-defun rmsbolt--py-compile-cmd (&key src-buffer)
+ "Process a compile command for rustc."
+ (let* ((cmd (buffer-local-value 'rmsbolt-command src-buffer)))
+ (mapconcat 'identity
+ (list cmd "-m" "dis" (buffer-file-name)
+ ">" (rmsbolt-output-filename src-buffer))
+ " ")))
(defvar rmsbolt--hidden-func-c
(rx bol (or (and "__" (0+ any))
@@ -371,6 +384,7 @@ Outputs assembly file if ASM."
:compile-cmd "gcc"
:supports-asm t
:supports-disass t
+ :demangler "c++filt"
:starter-file-name "rmsbolt.c"
:compile-cmd-function #'rmsbolt--c-compile-cmd
:disass-hidden-funcs rmsbolt--hidden-func-c))
@@ -379,6 +393,7 @@ Outputs assembly file if ASM."
:compile-cmd "g++"
:supports-asm t
:supports-disass t
+ :demangler "c++filt"
:starter-file-name "rmsbolt.cpp"
:compile-cmd-function #'rmsbolt--c-compile-cmd
:disass-hidden-funcs rmsbolt--hidden-func-c))
@@ -388,7 +403,6 @@ Outputs assembly file if ASM."
:compile-cmd "ocamlopt"
:supports-asm t
:supports-disass t
- :demangler nil
:starter-file-name "rmsbolt.ml"
:compile-cmd-function #'rmsbolt--ocaml-compile-cmd
:disass-hidden-funcs rmsbolt--hidden-func-ocaml))
@@ -398,7 +412,6 @@ Outputs assembly file if ASM."
:supports-asm t
:supports-disass nil
:objdumper 'cat
- :demangler nil
:starter-file-name "rmsbolt.lisp"
:compile-cmd-function #'rmsbolt--lisp-compile-cmd
:disass-hidden-funcs nil))
@@ -412,6 +425,15 @@ Outputs assembly file if ASM."
:starter-file-name "rmsbolt.rs"
:compile-cmd-function #'rmsbolt--rust-compile-cmd
:disass-hidden-funcs nil))
+ ;; ONLY SUPPORTS PYTHON 3
+ (python-mode
+ . ,(make-rmsbolt-lang :mode 'python-mode
+ :compile-cmd "python3"
+ :supports-asm t
+ :supports-disass nil
+ :starter-file-name "rmsbolt.py"
+ :compile-cmd-function #'rmsbolt--py-compile-cmd
+ :disass-hidden-funcs nil))
))
;;;; Macros
@@ -561,80 +583,87 @@ Outputs assembly file if ASM."
(cl-defun rmsbolt--process-asm-lines (src-buffer asm-lines)
"Process and filter a set of asm lines."
- (if (buffer-local-value 'rmsbolt-disassemble src-buffer)
- (rmsbolt--process-disassembled-lines src-buffer asm-lines)
- (let ((used-labels (rmsbolt--find-used-labels src-buffer asm-lines))
- (result nil)
- (prev-label nil)
- (source-linum nil)
- (source-file nil)
- (skip-file-match
- ;; Skip file match if we don't have a current filename
- (not (buffer-file-name src-buffer))))
- (dolist (line asm-lines)
- (let* ((raw-match (or (string-match rmsbolt-label-def line)
- (string-match rmsbolt-assignment-def line)))
- (match (when raw-match
- (match-string 1 line)))
- (used-label (cl-find match used-labels :test #'equal)))
- (cl-tagbody
- ;; Process file name hints
- (when (string-match rmsbolt-source-file line)
- (if (match-string 3 line)
- ;; Clang style match
- (setq source-file (expand-file-name
- (match-string 3 line)
- (match-string 2 line)))
- (setq source-file (match-string 2 line))))
- ;; Process any line number hints
- (when (string-match rmsbolt-source-tag line)
- (if (or skip-file-match
- (file-equal-p (buffer-file-name src-buffer) source-file))
- (setq source-linum (string-to-number
- (match-string 2 line)))
- (setq source-linum nil)))
- (when (string-match rmsbolt-source-stab line)
- (pcase (string-to-number (match-string 1 line))
- ;; http://www.math.utah.edu/docs/info/stabs_11.html
- (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))
-
- (when (and (buffer-local-value 'rmsbolt-filter-comment-only
src-buffer)
- (string-match-p rmsbolt-comment-only line))
- (go continue))
-
- ;; continue means we don't add to the ouptut
- (when match
- (if (not used-label)
- ;; Unused label
- (when (buffer-local-value 'rmsbolt-filter-labels src-buffer)
- (go continue))
- ;; Real label, set prev-label
- (setq prev-label raw-match)))
- (when (and (buffer-local-value 'rmsbolt-filter-directives
src-buffer)
- (not match))
- (if (and (string-match-p rmsbolt-data-defn line)
- prev-label)
- ;; data is being used
- 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)))
- (nreverse result))))
+ (let* ((lang (with-current-buffer src-buffer
+ (rmsbolt--get-lang)))
+ (process-asm-fn (rmsbolt-l-process-asm-custom-fn lang)))
+ (cond
+ (process-asm-fn
+ (funcall process-asm-fn src-buffer asm-lines))
+ ((buffer-local-value 'rmsbolt-disassemble src-buffer)
+ (rmsbolt--process-disassembled-lines src-buffer asm-lines))
+ (t
+ (let ((used-labels (rmsbolt--find-used-labels src-buffer asm-lines))
+ (result nil)
+ (prev-label nil)
+ (source-linum nil)
+ (source-file nil)
+ (skip-file-match
+ ;; Skip file match if we don't have a current filename
+ (not (buffer-file-name src-buffer))))
+ (dolist (line asm-lines)
+ (let* ((raw-match (or (string-match rmsbolt-label-def line)
+ (string-match rmsbolt-assignment-def line)))
+ (match (when raw-match
+ (match-string 1 line)))
+ (used-label (cl-find match used-labels :test #'equal)))
+ (cl-tagbody
+ ;; Process file name hints
+ (when (string-match rmsbolt-source-file line)
+ (if (match-string 3 line)
+ ;; Clang style match
+ (setq source-file (expand-file-name
+ (match-string 3 line)
+ (match-string 2 line)))
+ (setq source-file (match-string 2 line))))
+ ;; Process any line number hints
+ (when (string-match rmsbolt-source-tag line)
+ (if (or skip-file-match
+ (file-equal-p (buffer-file-name src-buffer)
source-file))
+ (setq source-linum (string-to-number
+ (match-string 2 line)))
+ (setq source-linum nil)))
+ (when (string-match rmsbolt-source-stab line)
+ (pcase (string-to-number (match-string 1 line))
+ ;; http://www.math.utah.edu/docs/info/stabs_11.html
+ (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))
+
+ (when (and (buffer-local-value 'rmsbolt-filter-comment-only
src-buffer)
+ (string-match-p rmsbolt-comment-only line))
+ (go continue))
+
+ ;; continue means we don't add to the ouptut
+ (when match
+ (if (not used-label)
+ ;; Unused label
+ (when (buffer-local-value 'rmsbolt-filter-labels src-buffer)
+ (go continue))
+ ;; Real label, set prev-label
+ (setq prev-label raw-match)))
+ (when (and (buffer-local-value 'rmsbolt-filter-directives
src-buffer)
+ (not match))
+ (if (and (string-match-p rmsbolt-data-defn line)
+ prev-label)
+ ;; data is being used
+ 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)))
+ (nreverse result))))))
;;;;; Handlers
(defun rmsbolt--handle-finish-compile (buffer _str)
- [elpa] externals/beardbolt 9f6d1cf10c 269/323: Remove some rmsbolt remnants, (continued)
- [elpa] externals/beardbolt 9f6d1cf10c 269/323: Remove some rmsbolt remnants, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 5deed3972e 276/323: * beardbolt.el (bb--reachable-p, bb--process-asm): Use obarrays., ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 291f82a324 266/323: Continue rewriting, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 3195997ccd 275/323: * beardbolt.el (bb--synch-relation-overlays): Rework and bugfix., ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt a13f8fe7f4 287/323: Reset beardbolt-specific locals before hacking them in, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 85d24d69f1 286/323: Add bb-kill-symbol-re option, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 10fe7307c3 291/323: Get a better C++ starter example, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 5324775417 321/323: Add beardbolt-shuffle-rainbow option, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 90b5cad9c1 016/323: Finish initial implementation of dissasembly, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt de183bea12 010/323: Add support for c++ and c, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 627dd4c1c9 059/323: Allow for custom asm processing functions,
ELPA Syncer <=
- [elpa] externals/beardbolt 978d8290a1 067/323: Add guide on adding new languages, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt f911321a02 058/323: Add support for automatically hot recompiling, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 86742e7b76 055/323: Merge branch 'master' of gitlab.com:jgkamat/rmsbolt, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 01f7664eda 060/323: Fix tests, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 36b701d70e 072/323: Fix broken tests, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 8d992d1da7 103/323: Add links to README, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt a74d54e764 109/323: Fix tests, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 859722f7e0 084/323: Add back support for Emacs 25, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 2eca2d59dd 100/323: Merge branch 'patch-2' into 'master', ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt a85b457e81 108/323: Fix typo, ELPA Syncer, 2023/03/09