[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/beardbolt 0d61c2edac 311/323: Add support for rustc
From: |
ELPA Syncer |
Subject: |
[elpa] externals/beardbolt 0d61c2edac 311/323: Add support for rustc |
Date: |
Thu, 9 Mar 2023 10:58:59 -0500 (EST) |
branch: externals/beardbolt
commit 0d61c2edac562c4769436cea7a3a4f62ce617a25
Author: João Távora <joaotavora@gmail.com>
Commit: João Távora <joaotavora@gmail.com>
Add support for rustc
* README.md: Mention rust.
* starters/beardbolt.rs: New file.
* beardbolt.el (bb--c/c++-compile-specs): Adjust.
(bb--rust-compile-specs): New function.
(bb-languages): Add rust-mode entry. Adjust docstring.
(bb--process-disassembled-lines): Adjust.
(bb--process-asm): Adjust.
(bb--handle-finish-compile): Adjust.
(bb-starter-files): Add "beardbolt.rs"
---
README.md | 11 ++++----
beardbolt.el | 74 +++++++++++++++++++++++++++++++++++++--------------
starters/beardbolt.rs | 26 ++++++++++++++++++
3 files changed, 85 insertions(+), 26 deletions(-)
diff --git a/README.md b/README.md
index b9d67a7e0b..c4588751da 100644
--- a/README.md
+++ b/README.md
@@ -14,12 +14,6 @@ easy to see what the compiler is doing.
It also highlights which source code corresponds to a given assembly,
and vice versa.
-### Why RMSbolt over Beardbolt
-
-- Supports more languages/compilers. Beardbolt only C++/C clang/gcc for now.
-- Has good documentation and a proper API.
-- Supports more Emacs versions. Beardbolt probably only 28+
-
### Why Beardbolt over RMSbolt
- Doesn't require file to be saved.
@@ -28,6 +22,11 @@ and vice versa.
- Has more useful Godbolt features like "execute program" and "preserve/filter
library functions" .
- Simpler code (less than half the LOC, but also less funcional in some
regards if we're honest).
+### Why RMSbolt over Beardbolt
+
+- Supports way more languages/compilers. Beardbolt only C, C++ and Rust.
+- Supports more Emacs versions. Beardbolt probably only 28+
+
### Installation
```sh
diff --git a/beardbolt.el b/beardbolt.el
index 818ce94451..172ba471d3 100644
--- a/beardbolt.el
+++ b/beardbolt.el
@@ -219,14 +219,15 @@ Useful if you have multiple objdumpers and want to select
between them")
,(tmp "beardbolt.o") "--insn-width=16" "-l"
,(when bb-asm-format (format "-M %s"
bb-asm-format))
">" ,(tmp "beardbolt.o.disass"))))
- `((:compile ,(lambda (dump-file)
+ `((:compile
+ ,(lambda (dump-file)
(cons
(munch `(,(compile dump-file)
,(assemble)
,@(when bb-execute `(,(link)
,(execute)))))
(tmp "beardbolt.s")))
- ,#'bb--process-asm)
+ ,(lambda (_dump-file) (bb--process-asm "<stdin>")))
(:compile-assemble-disassemble
,(lambda (dump-file)
(cons
@@ -236,27 +237,59 @@ Useful if you have multiple objdumpers and want to select
between them")
,@(when bb-execute `(,(link)
,(execute)))))
(tmp "beardbolt.o.disass")))
+ ,(lambda (_dump-file)
+ (bb--process-disassembled-lines "<stdin>")))))))
+
+(cl-defun bb--rust-compile-specs () "Get compile specs for rustc"
+ (let* ((base (ensure-list (or bb-command "rustc"))))
+ (cl-labels ((tmp (f) (expand-file-name f (bb--sandbox-dir)))
+ (join (l &optional (sep " ")) (mapconcat #'identity l sep))
+ (munch (l) (join (mapcar #'join l) " \\\n"))
+ (disassemble () `("&&" ,bb-objdump-binary "-d"
+ ,(tmp "beardbolt.o") "--insn-width=16" "-l"
+ ,(when bb-asm-format (format "-M %s"
bb-asm-format))
+ ">" ,(tmp "beardbolt.o.disass")))
+ (link (dump)
+ `(,@base "-C debuginfo=1" "--emit" "link" ,dump "-o" ,(tmp
"beardbolt.o")))
+ (compile (dump)
+ `(,@base "-C debuginfo=1" "--emit" "asm" ,dump
+ ,(when bb-asm-format (format
+
"-Cllvm-args=--x86-asm-syntax=%s"
+ bb-asm-format))
+ "-o" ,(tmp "beardbolt.s"))))
+ `((:compile ,(lambda (dump-file)
+ (cons
+ (munch `(,(compile dump-file)))
+ (tmp "beardbolt.s")))
+ ,#'bb--process-asm)
+ (:compile-assemble-disassemble
+ ,(lambda (dump-file)
+ (cons
+ (munch `(,(link dump-file)
+ ,(disassemble)))
+ (tmp "beardbolt.o.disass")))
,#'bb--process-disassembled-lines)))))
(defvar bb-languages
`((c-mode ,#'bb--c/c++-compile-specs :base-cmd "gcc" :language "c")
- (c++-mode ,#'bb--c/c++-compile-specs :base-cmd "g++" :language "c++"))
- "Alist of (MAJOR-MODE SETUP . PLIST).
+ (c++-mode ,#'bb--c/c++-compile-specs :base-cmd "g++" :language "c++")
+ (rust-mode ,#'bb--rust-compile-specs))
+ "Alist of (MAJOR-MODE SETUP . SETUP-ARGS).
-SETUP is a function called with `apply' on PLIST.
+SETUP is a function called with `apply' on SETUP-ARGS.
-It returns a list (SPEC ...) where SPEC is (WHAT CMD-FN PROCESS).
+It returns a list (SPEC ...) where SPEC is (WHAT CMD-FN GROK).
WHAT is a symbol `:compile' or `:compile-assemble-disassemble'.
-CMD-FN is a function taking DUMP-FILE, name of the temp file
-with the current buffer's content and returning a cons
-cell (CMD . DECLARED-OUTPUT) where CMD is a string to pass to
+CMD-FN is a function taking DUMP-FILE, name of the temp file with
+the current buffer's content, and returning a cons cell (CMD
+. DECLARED-OUTPUT) where CMD is a string to pass to
`compilation-start' and DECLARED-OUTPUT is the name of the file
containing the output to insert into the asm buffer.
-PROCESS is a nullary function to run in the asm buffer. It
-should clean up the buffer and setup a buffer-local value of
+GROK is a function taking DUMP-FILE, to run in the asm buffer.
+It should clean up the buffer and setup a buffer-local value of
`beardbolt--line-mappings' (which see).")
(defmacro bb--get (sym) `(buffer-local-value ',sym bb--source-buffer))
@@ -295,8 +328,8 @@ should clean up the buffer and setup a buffer-local value of
(push (cons (cons l l) source-linum)
bb--line-mappings))))
-(cl-defun bb--process-disassembled-lines ()
- (let* ((src-file-name "<stdin>") (func nil) (source-linum nil))
+(cl-defun bb--process-disassembled-lines (main-file-name)
+ (let* ((func nil) (source-linum nil))
(cl-flet ((bb--user-func-p (func)
(let* ((regexp (rx bol (or (and "__" (0+ any))
(and "_" (or "init" "start" "fini"))
@@ -308,7 +341,7 @@ should clean up the buffer and setup a buffer-local value of
(if regexp (not (string-match-p regexp func)) t))))
(bb--sweeping
((match bb-disass-line)
- (setq source-linum (and (equal src-file-name
+ (setq source-linum (and (equal (file-name-base main-file-name) ;;
brittle
(file-name-base (match-string 1)))
(string-to-number (match-string 2))))
:kill)
@@ -324,10 +357,9 @@ should clean up the buffer and setup a buffer-local value
of
(replace-match (concat (match-string 1) "\t" (match-string 3)))
:preserve)))))
-(defun bb--process-asm ()
+(defun bb--process-asm (main-file-name)
(let* ((used-labels (obarray-make))
(routines (make-hash-table :test #'equal))
- (main-file-name "<stdin>")
main-file-tag
main-file-routines
source-linum
@@ -481,12 +513,13 @@ should clean up the buffer and setup a buffer-local value
of
(cl-defun bb--handle-finish-compile (compilation-buffer str)
"Finish hook for compilations. Runs in buffer COMPILATION-BUFFER.
Argument STR compilation finish status."
- (delete-file bb--dump-file)
- (let* ((src-buffer bb--source-buffer)
+ (let* ((dump-file-name bb--dump-file)
+ (src-buffer bb--source-buffer)
(compile-spec bb--compile-spec)
(declared-output bb--declared-output)
(asm-buffer (bb--asm-buffer src-buffer))
(split-width-threshold (min split-width-threshold 100)))
+ (delete-file dump-file-name)
(with-current-buffer asm-buffer
(bb--asm-mode)
(setq bb--source-buffer src-buffer)
@@ -499,7 +532,7 @@ Argument STR compilation finish status."
(mapc #'delete-overlay (overlays-in (point-min) (point-max)))
(insert-file-contents declared-output)
(setq bb--line-mappings nil)
- (save-excursion (funcall (cadr compile-spec)))
+ (save-excursion (funcall (cadr compile-spec) dump-file-name))
(setq bb--line-mappings (reverse bb--line-mappings))
(when (bb--get bb-demangle)
(shell-command-on-region (point-min) (point-max) "c++filt"
@@ -579,7 +612,8 @@ determine LANG from `major-mode'."
(defvar bb-starter-files
'(("c++" . "beardbolt.cpp")
- ("c" . "beardbolt.c")))
+ ("c" . "beardbolt.c")
+ ("rust" . "beardbolt.rs")))
;;;###autoload
(defun bb-starter (lang-name)
diff --git a/starters/beardbolt.rs b/starters/beardbolt.rs
new file mode 100644
index 0000000000..883d15f5fa
--- /dev/null
+++ b/starters/beardbolt.rs
@@ -0,0 +1,26 @@
+fn is_rms(a: char) -> i32 {
+ match a {
+ 'R' => 1,
+ 'M' => 2,
+ 'S' => 3,
+ _ => 0,
+ }
+}
+
+fn main() {
+ let a: u8 = 1 + 1;
+ if is_rms(a as char) != 0 {
+ println!("{}", a);
+ };
+ 42;
+}
+// rust beardbolt starter file
+
+// Local Variables:
+// beardbolt-command: "rustc -C opt-level=0"
+// beardbolt-preserve-library-functions: nil
+// beardbolt-demangle: t
+// beardbolt-disassemble: nil
+// End:
+
+
- [elpa] externals/beardbolt 2542f24813 285/323: Tweak, rework, speed up main algorithm again, (continued)
- [elpa] externals/beardbolt 2542f24813 285/323: Tweak, rework, speed up main algorithm again, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 85bc714336 295/323: Simplify source file tracking, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt c5086ea624 294/323: bb--output-mode now a major mode, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 298a5fe6a2 296/323: Fix starter/beardbolt.cpp, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 067096f3b9 299/323: Friendlier beardbolt--output-mode, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 0ae21a302a 302/323: Simplify window management in preparation of beardbolt-execute-program, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 842b2159da 305/323: More simplification, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 60d189b0a6 310/323: Advertise beardbolt-execute and a few other things, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt c374b17f5c 314/323: Don't require file to be saved, but do take advantage if it is, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 4a050afaaa 315/323: Attempt to fix more window management bugs, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 0d61c2edac 311/323: Add support for rustc,
ELPA Syncer <=
- [elpa] externals/beardbolt be3cf0a712 318/323: Fix problems with beardbolt-compile when file is saved, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 349ace7310 164/323: Merge branch 'master' of gitlab.com:jgkamat/rmsbolt, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 5aeda6f846 155/323: Add basic documentation for compile_commands.json, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 246377bbff 173/323: Add dummy panic handler to reduce size of zig diassembly, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 73dcaca98d 177/323: Remove unneeded variables, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 28ccabf318 190/323: Clean up overlays and simplify hook when asm buffer is closed, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 3a8964d537 204/323: Update Readme, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 7c81d55d3e 202/323: Format go block, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 9b1a5abbdf 208/323: Strip -flto flag from compile_commands.json by default, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt d257e51fce 244/323: starters/zig: Automatically export functions, ELPA Syncer, 2023/03/09