branch: externals/beardbolt commit 2bb741e6f19a29021833f83c56eb451c860dc443 Merge: 73dcaca98d 73a547856c Author: Jay Kamat <jaygka...@gmail.com> Commit: Jay Kamat <jaygka...@gmail.com>
Merge branch 'add-swift-support' into 'master' Add Swift language support See merge request jgkamat/rmsbolt!9 --- README.org | 2 ++ rmsbolt.el | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++ starters/rmsbolt.swift | 28 ++++++++++++++++++++++++++ 3 files changed, 83 insertions(+) diff --git a/README.org b/README.org index 82cd4d752c..bd11419b80 100644 --- a/README.org +++ b/README.org @@ -113,6 +113,8 @@ The main knobs are described in the full documentation. [[https://i.imgur.com/uYrQ7En.gif][https://i.imgur.com/uYrQ7En.gif]] ** Common Lisp [[https://i.imgur.com/36aNVvf.gif][https://i.imgur.com/36aNVvf.gif]] +** Swift +[[https://gitlab.com/jgkamat/rmsbolt/uploads/80d38e840a149c77951891c3623ca2f2/lFG72Lv_-_Imgur.gif][https://gitlab.com/jgkamat/rmsbolt/uploads/80d38e840a149c77951891c3623ca2f2/lFG72Lv_-_Imgur.gif]] * Community and Support diff --git a/rmsbolt.el b/rmsbolt.el index d220d6f58b..aa574cf4dd 100644 --- a/rmsbolt.el +++ b/rmsbolt.el @@ -667,6 +667,23 @@ https://github.com/derickr/vld" " "))) cmd))) +(cl-defun rmsbolt--swift-compile-cmd (&key src-buffer) + "Process a compile command for swiftc." + (rmsbolt--with-files + src-buffer + (let* ((asm-format (buffer-local-value 'rmsbolt-asm-format src-buffer)) + (cmd (buffer-local-value 'rmsbolt-command src-buffer)) + (cmd (mapconcat #'identity + (list cmd + "-g" + "-emit-assembly" + src-filename + "-o" output-filename + (when (not (booleanp asm-format)) + (concat "-Xllvm --x86-asm-syntax=" asm-format))) + " "))) + cmd))) + ;;;;; Hidden Function Definitions (defvar rmsbolt--hidden-func-c @@ -701,7 +718,35 @@ https://github.com/derickr/vld" (and (0+ any) "@plt" (0+ any))) eol)) +;;;;; Demangling Functions + +(defun rmsbolt--path-to-swift-demangler () + "Return the path to the configured Swift demangler, depending + on the active toolchain." + (rmsbolt--path-to-swift-tool "swift-demangle")) + ;;;;; Language Integrations + +(defun rmsbolt--path-to-swift-compiler () + "Return the path to the configured Swift compiler, depending on + the active toolchain." + (rmsbolt--path-to-swift-tool "swiftc")) + +(defun rmsbolt--path-to-swift-tool (swift-tool) + "Return the path to SWIFT-TOOL, depending on the active +toolchain." + (let* ((swift-tool-binary swift-tool) + (swift-tool-toolchain-path (shell-command-to-string (format "echo -n `xcrun --find %s`" swift-tool-binary)))) + ;; If we have the Swift tool in PATH, just return it (this is the + ;; typical case in Linux systems). If it's not in PATH, look for a + ;; toolchain-specific path. + (cond + ((executable-find swift-tool-binary) + swift-tool-binary) + ((executable-find swift-tool-toolchain-path) + swift-tool-toolchain-path) + (t nil)))) + (defun rmsbolt--parse-compile-commands (comp-cmds file) "Parse COMP-CMDS and extract a compilation dir and command for FILE." (when-let ((json-object-type 'alist) @@ -839,6 +884,13 @@ return t if successful." :objdumper 'go-objdump :compile-cmd-function #'rmsbolt--go-compile-cmd :process-asm-custom-fn #'rmsbolt--process-go-asm-lines)) + (swift-mode + . ,(make-rmsbolt-lang :compile-cmd (rmsbolt--path-to-swift-compiler) + :supports-asm t + :supports-disass nil + :objdumper 'objdump + :demangler (rmsbolt--path-to-swift-demangler) + :compile-cmd-function #'rmsbolt--swift-compile-cmd)) )) (make-obsolete-variable 'rmsbolt-languages 'rmsbolt-language-descriptor "RMSBolt-0.2") @@ -1477,6 +1529,7 @@ Are you running two compilations at the same time?")) ("d" . "rmsbolt.d") ("zig" . "rmsbolt.zig") ("go" . "rmsbolt.go") + ("swift" . "rmsbolt.swift") ;; Rmsbolt is capitalized here because of Java convention of Capitalized ;; class names. ("java" . "Rmsbolt.java"))) diff --git a/starters/rmsbolt.swift b/starters/rmsbolt.swift new file mode 100644 index 0000000000..9ecd0c6920 --- /dev/null +++ b/starters/rmsbolt.swift @@ -0,0 +1,28 @@ +import Foundation + +// Swift rmsbolt starter file + +// Local Variables: +// rmsbolt-disassemble: nil +// End: + +func isRMS(_ a: Character) -> Int { + switch (a) { + case "R": + return 1 + case "M": + return 2 + case "S": + return 3 + default: + return 0 + } +} + +func main() -> Int { + let a: Character = "N" + if isRMS(a) == 0 { + print(a) + } + return 0 +}