emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/beardbolt b7d318dfe1 178/323: Add Swift language suppor


From: ELPA Syncer
Subject: [elpa] externals/beardbolt b7d318dfe1 178/323: Add Swift language support
Date: Thu, 9 Mar 2023 10:58:29 -0500 (EST)

branch: externals/beardbolt
commit b7d318dfe147456bb8ca039db282fbd9a57a07c9
Author: Daniel Martín <mardani29@yahoo.es>
Commit: Daniel Martín <mardani29@yahoo.es>

    Add Swift language support
    
    Adds support for .swift files, including demangling symbols with
    swift-demangle.
---
 README.org             |  2 ++
 rmsbolt.el             | 41 +++++++++++++++++++++++++++++++++++++++++
 starters/rmsbolt.swift | 29 +++++++++++++++++++++++++++++
 3 files changed, 72 insertions(+)

diff --git a/README.org b/README.org
index 82cd4d752c..a0a706b609 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
 
 * Community and Support
 
diff --git a/rmsbolt.el b/rmsbolt.el
index d220d6f58b..bd2daf09ea 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,6 +718,22 @@ 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."
+  (let* ((swift-demangle-binary "swift-demangle")
+         (swift-demangle-toolchain-path (shell-command-to-string (format "echo 
-n `xcrun --find %s`" swift-demangle-binary))))
+    ;; If we have swift-demangle in PATH, just return it (this is the
+    ;; typical case in Linux systems).
+    (if (executable-find swift-demangle-binary)
+        swift-demangle-binary
+      ;; If it's not in PATH, look for a toolchain-specific path.
+      (if (executable-find swift-demangle-toolchain-path)
+          swift-demangle-toolchain-path
+        nil))))
+
 ;;;;; Language Integrations
 (defun rmsbolt--parse-compile-commands (comp-cmds file)
   "Parse COMP-CMDS and extract a compilation dir and command for FILE."
@@ -839,6 +872,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 "swiftc"
+                          :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 +1517,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..900aceef5b
--- /dev/null
+++ b/starters/rmsbolt.swift
@@ -0,0 +1,29 @@
+import Foundation
+
+// Swift rmsbolt starter file
+
+// Local Variables:
+// rmsbolt-command: "swiftc"
+// 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
+}



reply via email to

[Prev in Thread] Current Thread [Next in Thread]