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

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

[nongnu] elpa/treesit-fold 07da6590aa 348/417: feat: Add LLVM MIR suppor


From: ELPA Syncer
Subject: [nongnu] elpa/treesit-fold 07da6590aa 348/417: feat: Add LLVM MIR support
Date: Mon, 1 Jul 2024 10:03:03 -0400 (EDT)

branch: elpa/treesit-fold
commit 07da6590aaf0b121dff97fe4bc12fa6486fadcde
Author: JenChieh <jcs090218@gmail.com>
Commit: Jen-Chieh Shen <jcs090218@gmail.com>

    feat: Add LLVM MIR support
---
 CHANGELOG.md       |  1 +
 ts-fold-parsers.el |  8 ++++++++
 ts-fold-summary.el |  1 +
 ts-fold-util.el    |  7 +++++--
 ts-fold.el         | 14 ++++++++++++++
 5 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index ef8c67b03b..c18154d950 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for 
recommendations on how
 * Add `LLVM` support (#103)
 * Add `ActionScript` support (#106)
 * Add `Tablegen` support (#107)
+* Add `LLVM MIR` support (#108)
 
 ## 0.3.0
 > Released Nov 29, 2023
diff --git a/ts-fold-parsers.el b/ts-fold-parsers.el
index 09a0841591..870f16d287 100644
--- a/ts-fold-parsers.el
+++ b/ts-fold-parsers.el
@@ -61,6 +61,7 @@
 (declare-function ts-fold-range-kotlin-when "ts-fold.el")
 (declare-function ts-fold-range-lisp-function "ts-fold.el")
 (declare-function ts-fold-range-llvm-label "ts-fold.el")
+(declare-function ts-fold-range-llvm-mir-label "ts-fold.el")
 (declare-function ts-fold-range-lua-comment "ts-fold.el")
 (declare-function ts-fold-range-lua-function "ts-fold.el")
 (declare-function ts-fold-range-lua-if "ts-fold.el")
@@ -377,6 +378,13 @@
      . (lambda (node offset)
          (ts-fold-range-line-comment node offset ";;")))))
 
+(defun ts-fold-parsers-llvm-mir ()
+  "Rule set for LLVM MIR."
+  '((basic_block . ts-fold-range-llvm-mir-label)
+    (comment
+     . (lambda (node offset)
+         (ts-fold-range-line-comment node offset ";;")))))
+
 (defun ts-fold-parsers-lua ()
   "Rule set for Lua."
   '((expression_list      . ts-fold-range-seq)
diff --git a/ts-fold-summary.el b/ts-fold-summary.el
index 8629c53223..ffd9b9ad15 100644
--- a/ts-fold-summary.el
+++ b/ts-fold-summary.el
@@ -260,6 +260,7 @@ type of content by checking the word boundary's existence."
     (lisp-mode              . ts-fold-summary-elisp)
     (lisp-interaction-mode  . ts-fold-summary-elisp)
     (llvm-mode              . ts-fold-summary-elisp)
+    (llvm-mir-mode          . ts-fold-summary-elisp)
     (lua-mode               . ts-fold-summary-lua-doc)
     (makefile-mode          . ts-fold-summary-ruby-doc)
     (makefile-automake-mode . ts-fold-summary-ruby-doc)
diff --git a/ts-fold-util.el b/ts-fold-util.el
index d360369028..5cf772d50d 100644
--- a/ts-fold-util.el
+++ b/ts-fold-util.el
@@ -96,8 +96,11 @@ Like function `s-count-matches' but faster."
 (defun ts-fold--get-face (obj trim)
   "Return face name from OBJ.
 If argument TRIM is non-nil, trim the OBJ."
-  (let ((obj (if trim (string-trim obj) obj)))
-    (get-text-property 0 'face obj)))
+  (let* ((obj (if trim (string-trim obj) obj))
+         (len (length obj)))
+    (or (get-text-property 0 'face obj)
+        (and (<= 1 len)
+             (get-text-property 1 'face obj)))))
 
 (defun ts-fold--is-face (obj lst-face &optional trim)
   "Return non-nil if OBJ's face is define inside list LST-FACE.
diff --git a/ts-fold.el b/ts-fold.el
index 92f6ea932c..b3e53bcb22 100644
--- a/ts-fold.el
+++ b/ts-fold.el
@@ -102,6 +102,7 @@
     (lisp-mode              . ,(ts-fold-parsers-lisp))
     (lisp-interaction-mode  . ,(ts-fold-parsers-lisp))
     (llvm-mode              . ,(ts-fold-parsers-llvm))
+    (llvm-mir-mode          . ,(ts-fold-parsers-llvm-mir))
     (lua-mode               . ,(ts-fold-parsers-lua))
     (makefile-mode          . ,(ts-fold-parsers-make))
     (makefile-automake-mode . ,(ts-fold-parsers-make))
@@ -861,6 +862,19 @@ more information."
               (end (tsc-node-end-position end)))
     (ts-fold--cons-add (cons beg end) offset)))
 
+(defun ts-fold-range-llvm-mir-label (node offset)
+  "Define fold range for `label' in LLVM MIR.
+
+For arguments NODE and OFFSET, see function `ts-fold-range-seq' for
+more information."
+  (when-let* ((label (car (ts-fold-find-children node "label")))
+              (colon (tsc-get-next-sibling label))
+              (beg (tsc-node-end-position colon))
+              (beg (ts-fold--eol beg))
+              (end (ts-fold-range-llvm--find-last-instruction label))
+              (end (tsc-node-end-position end)))
+    (ts-fold--cons-add (cons beg end) offset)))
+
 (defun ts-fold-range-lua-comment (node offset)
   "Define fold range for Lua comemnt.
 



reply via email to

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