[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/beardbolt 93f3cad769 017/323: Use local variables inste
From: |
ELPA Syncer |
Subject: |
[elpa] externals/beardbolt 93f3cad769 017/323: Use local variables instead of custom parsing |
Date: |
Thu, 9 Mar 2023 10:57:53 -0500 (EST) |
branch: externals/beardbolt
commit 93f3cad769b53e39d93890ebf08f6f5c446ba562
Author: Jay Kamat <jaygkamat@gmail.com>
Commit: Jay Kamat <jaygkamat@gmail.com>
Use local variables instead of custom parsing
---
rmsbolt.el | 97 ++++++++++++++++++++++++++++++++++++++------------------------
1 file changed, 60 insertions(+), 37 deletions(-)
diff --git a/rmsbolt.el b/rmsbolt.el
index b7583c694c..ef8a7bb103 100644
--- a/rmsbolt.el
+++ b/rmsbolt.el
@@ -30,6 +30,21 @@
(require 'map)
;;; Code:
+;;;; Customize:
+(defgroup rmsbolt nil
+ "rmsbolt customization options"
+ :group 'applications)
+
+(defcustom rmsbolt-dissasemble nil
+ "Whether we should dissasemble an output binary."
+ :type 'boolean
+ :safe 'booleanp)
+(defcustom rmsbolt-command nil
+ "The base command to run rmsbolt from."
+ :type 'string
+ :safe 'stringp)
+
+
;;;; Variables:
(defvar rmsbolt-temp-dir nil
"Temporary directory to use for compilation and other reasons.")
@@ -42,14 +57,16 @@
(defvar rmsbolt-filter-asm-directives t)
(defvar rmsbolt-filter-unused-labels t)
(defvar rmsbolt-filter-comment-only t)
-(defvar rmsbolt-dissasemble nil)
(defvar rmsbolt-binary-asm-limit 5000)
-(defun rmsbolt-output-filename (&optional asm)
- (if (and rmsbolt-dissasemble
- (not asm))
+(defun rmsbolt-output-filename (options &optional asm)
+ (if (and (not asm)
+ (rmsbolt-o-dissasemble options))
(expand-file-name "rmsbolt.out" rmsbolt-temp-dir)
(expand-file-name "rmsbolt.s" rmsbolt-temp-dir)))
+(defvar-local rmsbolt-dissasemble nil)
+
+
;;;; Regexes
(defvar rmsbolt-label-def (rx bol (group (any ".a-zA-Z_$@")
@@ -114,7 +131,7 @@
:type 'symbol
:documentation "The major mode language we are compiling in."
)
- (binary-compile
+ (dissasemble
nil
:type 'bool
:documentation "Whether we should compile to binary and dissasemble that."))
@@ -161,11 +178,11 @@
(cmd (mapconcat 'identity
(list cmd
"-g"
- (if rmsbolt-dissasemble
+ (if (rmsbolt-o-dissasemble options)
""
"-S")
(buffer-file-name)
- "-o" (rmsbolt-output-filename)
+ "-o" (rmsbolt-output-filename options)
(when rmsbolt-intel-x86
"-masm=intel"))
" ")))
@@ -192,7 +209,10 @@
:starter-file
"#include <stdio.h>
-// RMS: gcc -O3
+// Local Variables:
+// rmsbolt-command: \"gcc -O3\"
+// rmsbolt-dissasemble: nil
+// End:
int isRMS(int a) {
switch (a) {
@@ -226,7 +246,10 @@ int main() {
:starter-file
"#include <iostream>
-// RMS: g++ -O3
+// Local Variables:
+// rmsbolt-command: \"g++ -O3\"
+// rmsbolt-dissasemble: nil
+// End:
int isRMS(int a) {
switch (a) {
@@ -381,7 +404,7 @@ int main() {
(cl-defun rmsbolt--process-asm-lines (opts asm-lines)
"Process and filter a set of asm lines."
- (if rmsbolt-dissasemble
+ (if (rmsbolt-o-dissasemble opts)
(rmsbolt--process-dissasembled-lines opts asm-lines)
(let ((used-labels (rmsbolt--find-used-labels asm-lines))
(result nil)
@@ -436,14 +459,14 @@ int main() {
(with-current-buffer (get-buffer-create rmsbolt-output-buffer)
(cond ((not compilation-fail)
- (if (not (file-exists-p (rmsbolt-output-filename t)))
+ (if (not (file-exists-p (rmsbolt-output-filename opts t)))
(message "Error reading from output file.")
(delete-region (point-min) (point-max))
(insert
(rmsbolt--process-asm-lines
opts
(with-temp-buffer
- (insert-file-contents (rmsbolt-output-filename t))
+ (insert-file-contents (rmsbolt-output-filename opts t))
(split-string (buffer-string) "\n" t))))
(asm-mode)
(display-buffer (current-buffer))))
@@ -454,19 +477,17 @@ int main() {
;;;;; Parsing Options
(defun rmsbolt--get-lang (&optional language)
(cdr-safe (assoc (or language major-mode) rmsbolt-languages)))
-(defun rmsbolt--get-cmd ()
- "Gets the rms command from the buffer, if available."
- (save-excursion
- (goto-char (point-min))
- (re-search-forward (rx "RMS:" (1+ space) (group (1+ (any "-" "+" alnum
space)))) nil t)
- (match-string-no-properties 1)))
(defun rmsbolt--parse-options ()
"Parse RMS options from file."
(let* ((lang (rmsbolt--get-lang))
- (options (copy-rmsbolt-options (rmsbolt-l-options lang)))
- (cmd (rmsbolt--get-cmd)))
+ (options (copy-rmsbolt-options
+ (rmsbolt-l-options lang)))
+ (cmd rmsbolt-command))
(when cmd
(setf (rmsbolt-o-compile-cmd options) cmd))
+ (setf (rmsbolt-o-dissasemble options)
+ rmsbolt-dissasemble)
+ (prin1 (rmsbolt-o-dissasemble options))
options))
;;;;; UI Functions
@@ -475,27 +496,29 @@ int main() {
"Compile the current rmsbolt buffer."
(interactive)
(save-some-buffers nil (lambda () rmsbolt-mode))
+ (hack-local-variables)
(let* ((options (rmsbolt--parse-options))
(lang (rmsbolt--get-lang))
- (options (rmsbolt-l-options lang))
(func (rmsbolt-l-compile-cmd-function lang))
(cmd (funcall func options)))
- (when rmsbolt-dissasemble
- (cond
- ((eq (rmsbolt-l-objdumper lang) 'objdump)
- (setq cmd
- (mapconcat 'identity
- (list cmd
- "&&"
- "objdump" "-d" (rmsbolt-output-filename)
- "-C" "--insn-width=16" "-l"
- "-M" (if rmsbolt-intel-x86
- "intel"
- "att")
- ">" (rmsbolt-output-filename t))
- " ")))
- (t
- (error "Objdumper not recognized"))))
+
+ (when (rmsbolt-o-dissasemble options)
+ (pcase
+ (rmsbolt-l-objdumper lang)
+ ('objdump
+ (setq cmd
+ (mapconcat 'identity
+ (list cmd
+ "&&"
+ "objdump" "-d" (rmsbolt-output-filename
options)
+ "-C" "--insn-width=16" "-l"
+ "-M" (if rmsbolt-intel-x86
+ "intel"
+ "att")
+ ">" (rmsbolt-output-filename options t))
+ " ")))
+ (_
+ (error "Objdumper not recognized"))))
(rmsbolt-with-display-buffer-no-window
(with-current-buffer (compilation-start cmd)
(add-hook 'compilation-finish-functions
- [elpa] externals/beardbolt 5ab75b7f56 014/323: Add stubs for dissasembly, (continued)
- [elpa] externals/beardbolt 5ab75b7f56 014/323: Add stubs for dissasembly, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 0a55783f33 029/323: Add skeleton for font-lock, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 8dcd74b511 031/323: Clean up rmsbolt.c by moving starters into helper files, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt aea0966e9d 035/323: Don't add binary asm line data when viewing different files, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt c066da01c4 052/323: Fix ocaml def, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 83e29706f5 005/323: Work on porting used label finder, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 58c77d90c3 008/323: Add outshine comments, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 1545531849 006/323: Add initial implementation of filter, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt d604adae64 015/323: Add initial functions for processing binary asm, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt e0bc9fc409 013/323: Fix starters, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 93f3cad769 017/323: Use local variables instead of custom parsing,
ELPA Syncer <=
- [elpa] externals/beardbolt ce6511f715 024/323: Fix compiler warnings, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 55c26882cd 025/323: Fix crash on quit, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 6239f41d9d 033/323: Add a goto-match feature for easily traversing matches, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt e6081fae6b 032/323: Add unrefined support for ocaml, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt a638324882 039/323: Add OCaml demo, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt e0d917206e 038/323: Improve quality of default matching faces, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt a950515dfc 043/323: Fix spelling mistake, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 4213316f23 037/323: Fix recentering when not needed, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 545a366472 049/323: Add more tests, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 2e6163c95a 047/323: Add testing framework, ELPA Syncer, 2023/03/09