branch: externals/beardbolt commit 3ca3f35cdb14a27eaef9f58db1bbb0fb508cc649 Author: Jay Kamat <jaygka...@gmail.com> Commit: Jay Kamat <jaygka...@gmail.com>
Add very basic support for rust --- README.org | 2 +- rmsbolt.el | 37 +++++++++++++++++++++++++++++++------ starters/rmsbolt.c | 2 +- starters/rmsbolt.cpp | 2 +- starters/rmsbolt.ml | 2 +- starters/rmsbolt.rs | 35 +++++++++++++++++++++++++++++++++++ 6 files changed, 70 insertions(+), 10 deletions(-) diff --git a/README.org b/README.org index 85395517ef..2a9207b33f 100644 --- a/README.org +++ b/README.org @@ -1,7 +1,7 @@ * RMSbolt -A basic implementation of the [[https://github.com/mattgodbolt/compiler-explorer][godbolt compiler-exporter]] for Emacs. +A basic implementation of the [[https://github.com/mattgodbolt/compiler-explorer][godbolt compiler-explorer]] for Emacs. RMSBolt tries to make it easy to see what your compiler is doing. It does this by showing you the assembly output of a given source code file. It also diff --git a/rmsbolt.el b/rmsbolt.el index 0de2ad2637..2e5ed91bd5 100644 --- a/rmsbolt.el +++ b/rmsbolt.el @@ -1,11 +1,11 @@ -;;; rmsbolt.el --- A compiler output viewer for Emacs -*- lexical-binding: t; -*- +;;; rmsbolt.el --- A compiler output viewer -*- lexical-binding: t; -*- ;; Copyright (C) 2018 Jay Kamat ;; Author: Jay Kamat <jaygka...@gmail.com> -;; Version: 0.0.1 -;; Keywords: compilation +;; Version: 0.1.0 +;; Keywords: compilation, tools ;; URL: http://gitlab.com/jgkamat/rmsbolt -;; Package-Requires: ((emacs "25.0")) +;; Package-Requires: ((emacs "25.1")) ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU Affero General Public License as published by @@ -300,6 +300,22 @@ Assumes function name to dissasemble is 'main'." " ")) (_ (error "This Common Lisp interpreter is not supported"))))) +(cl-defun rmsbolt--rust-compile-cmd (&key src-buffer) + "Process a compile command for rustc." + (let* ((cmd (buffer-local-value 'rmsbolt-command src-buffer)) + (cmd (mapconcat 'identity + (list cmd + "-g" + "--emit" + (if (buffer-local-value 'rmsbolt-disassemble src-buffer) + "link" + "asm") + (buffer-file-name) + "-o" (rmsbolt-output-filename src-buffer) + (when (buffer-local-value 'rmsbolt-intel-x86 src-buffer) + "-Cllvm-args=--x86-asm-syntax=intel")) + " "))) + cmd)) (defvar rmsbolt--hidden-func-c (rx bol (or (and "__" (0+ any)) @@ -364,6 +380,15 @@ Assumes function name to dissasemble is 'main'." :starter-file-name "rmsbolt.lisp" :compile-cmd-function #'rmsbolt--lisp-compile-cmd :disass-hidden-funcs nil)) + (rust-mode + . ,(make-rmsbolt-lang :mode 'rust-mode + :compile-cmd "rustc" + :supports-asm t + :supports-disass nil + :objdumper 'objdump + :starter-file-name "rmsbolt.rs" + :compile-cmd-function #'rmsbolt--rust-compile-cmd + :disass-hidden-funcs nil)) )) ;;;; Macros @@ -379,7 +404,7 @@ Assumes function name to dissasemble is 'main'." ;;;; Functions -;; Functions to parse and lint assembly were lifted almost directly from the compiler-exporter +;; Functions to parse and lint assembly were lifted almost directly from the compiler-explorer (defun rmsbolt-re-seq (regexp string) "Get list of all REGEXP match in STRING." @@ -393,7 +418,7 @@ Assumes function name to dissasemble is 'main'." ;;;;; Filter Functions -;; Filtering functions were more or less lifted from the godbolt compiler exporter to maintain compatiblity. +;; Filtering functions were more or less lifted from the godbolt compiler explorer to maintain compatiblity. ;; https://github.com/mattgodbolt/compiler-explorer/blob/master/lib/asm.js (defun rmsbolt--has-opcode-p (line) diff --git a/starters/rmsbolt.c b/starters/rmsbolt.c index 63dc6d69cc..65103434ba 100644 --- a/starters/rmsbolt.c +++ b/starters/rmsbolt.c @@ -4,7 +4,7 @@ // Local Variables: // rmsbolt-command: "gcc -O0" -// rmsbolt-dissasemble: nil +// rmsbolt-disassemble: nil // End: int isRMS(int a) { diff --git a/starters/rmsbolt.cpp b/starters/rmsbolt.cpp index aa4dee0f0e..40cc5a94b2 100644 --- a/starters/rmsbolt.cpp +++ b/starters/rmsbolt.cpp @@ -4,7 +4,7 @@ // Local Variables: // rmsbolt-command: "g++ -O0" -// rmsbolt-dissasemble: nil +// rmsbolt-disassemble: nil // End: int isRMS(int a) { diff --git a/starters/rmsbolt.ml b/starters/rmsbolt.ml index 23872d40de..4cb5fe07db 100644 --- a/starters/rmsbolt.ml +++ b/starters/rmsbolt.ml @@ -5,7 +5,7 @@ (* Local Variables: rmsbolt-command: "ocamlopt" -rmsbolt-dissasemble: nil +rmsbolt-disassemble: nil End: *) diff --git a/starters/rmsbolt.rs b/starters/rmsbolt.rs new file mode 100644 index 0000000000..80e90ed5b5 --- /dev/null +++ b/starters/rmsbolt.rs @@ -0,0 +1,35 @@ +// rust rmsbolt starter file + +// Local Variables: +// rmsbolt-command: "rustc -C opt-level=0" +// rmsbolt-disassemble: nil +// End: + + +fn main() { + let number = 13; + // TODO ^ Try different values for `number` + + println!("Tell me about {}", number); + match number { + // Match a single value + 1 => println!("One!"), + // Match several values + 2 | 3 | 5 | 7 | 11 => println!("This is a prime"), + // Match an inclusive range + 13...19 => println!("A teen"), + // Handle the rest of cases + _ => println!("Ain't special"), + } + + let boolean = true; + // Match is an expression too + let binary = match boolean { + // The arms of a match must cover all the possible values + false => 0, + true => 1, + // TODO ^ Try commenting out one of these arms + }; + + println!("{} -> {}", boolean, binary); +}