branch: externals/beardbolt
commit 43f0eac016f2d09531fdf03962bbc1768a840cc5
Author: Jay Kamat <[email protected]>
Commit: Jay Kamat <[email protected]>
Add support for changing compiler and flags
---
README.org | 2 ++
rmsbolt.el | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++-----
2 files changed, 54 insertions(+), 5 deletions(-)
diff --git a/README.org b/README.org
index 11bd429529..e041f7da80 100644
--- a/README.org
+++ b/README.org
@@ -9,3 +9,5 @@ A basic implementation of the
[[https://github.com/mattgodbolt/compiler-explorer
- Compilation runs entirely on your machine
- Faster results
- Infinitely hackable!
+- Write your code in your preferred editing environment
+- Runs entirely with 0 js
diff --git a/rmsbolt.el b/rmsbolt.el
index e1b8505334..2a9aef760d 100644
--- a/rmsbolt.el
+++ b/rmsbolt.el
@@ -41,11 +41,41 @@
"Shell rmsbolt will use to split paths.")
(defvar rmsbolt-output-buffer "*rmsbolt-output*")
-(defvar rmsbolt-output-filename "rmsbolt.s")
+(defun rmsbolt-output-filename ()
+ (expand-file-name "rmsbolt.s" rmsbolt-temp-dir))
(defvar rmsbolt-hide-compile t)
(defvar rmsbolt-intel-x86 t)
(defvar rmsbolt-filter-asm-directives t)
+;;;; Classes
+
+(cl-defstruct (rmsbolt-options
+ (:conc-name rmsbolt-o-))
+ (compile-cmd
+ ""
+ :type string
+ :documentation "The command used to compile this file")
+ )
+
+(cl-defstruct (rmsbolt-lang
+ (:conc-name rmsbolt-l-))
+ (options
+ nil
+ :type 'rmsbolt-options
+ :documentation "The default options object to use.")
+ (mode
+ 'fundamental-mode
+ :type 'symbol
+ :documentation "The mode to activate this language in."))
+
+(defvar rmsbolt-languages
+ `((c-mode .
+ ,(make-rmsbolt-lang :mode 'c-mode
+ :options (make-rmsbolt-options
+ :compile-cmd "gcc -g -O0")) )
+ ))
+
+
;;;; Macros
(defmacro rmsbolt-with-display-buffer-no-window (&rest body)
@@ -80,13 +110,13 @@
(with-current-buffer (get-buffer-create rmsbolt-output-buffer)
(cond ((not compilation-fail)
- (if (not (file-exists-p rmsbolt-output-filename))
+ (if (not (file-exists-p (rmsbolt-output-filename)))
(message "Error reading from output file.")
(delete-region (point-min) (point-max))
(insert
(rmsbolt--process-asm-lines
(with-temp-buffer
- (insert-file-contents rmsbolt-output-filename)
+ (insert-file-contents (rmsbolt-output-filename))
(split-string (buffer-string) "\n" t))))
(asm-mode)
(display-buffer (current-buffer))))
@@ -94,15 +124,32 @@
;; Display compilation output
(display-buffer buffer))))))
+(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 (cdr-safe (assoc major-mode rmsbolt-languages)))
+ (options (copy-rmsbolt-options (rmsbolt-l-options lang)))
+ (cmd (rmsbolt--get-cmd)))
+ (when cmd
+ (setf (rmsbolt-ro-compile-cmd options) cmd))
+ options))
+
(defun rmsbolt-compile ()
"Compile the current rmsbolt buffer."
(interactive)
(save-some-buffers nil (lambda () rmsbolt-mode))
- (let* ((cmd "gcc -O0")
+ (let* ((options (rmsbolt--parse-options))
+ (cmd (rmsbolt-o-compile-cmd options))
(cmd (mapconcat 'identity
(list cmd
+ "-g"
"-S" (buffer-file-name)
- "-o" rmsbolt-output-filename
+ "-o" (rmsbolt-output-filename)
(when rmsbolt-intel-x86
"-masm=intel"))
" ")))