From d7192e0ac9ee43683286a448911511b1485ae388 Mon Sep 17 00:00:00 2001 From: Benson Chu Date: Sun, 5 Apr 2026 10:29:24 -0500 Subject: [PATCH] Fixup home stuff --- lisp/llvm-lib/c-compiler-option-sets.el | 4 +- lisp/llvm-lib/clang-command.el | 2 +- lisp/llvm-lib/lib-comp-dev.el | 4 +- .../llvm-act-on-file/act-on-ll-file.el | 23 +++---- lisp/llvm-lib/llvm-comp-dev.el | 65 +++++++++++-------- lisp/llvm-lib/my-clang-options.el | 16 ++--- 6 files changed, 62 insertions(+), 52 deletions(-) diff --git a/lisp/llvm-lib/c-compiler-option-sets.el b/lisp/llvm-lib/c-compiler-option-sets.el index 2228fa3..b7133be 100644 --- a/lisp/llvm-lib/c-compiler-option-sets.el +++ b/lisp/llvm-lib/c-compiler-option-sets.el @@ -34,10 +34,10 @@ (include-dirs :initarg :include-dirs :type list :initform nil) (system-include-dirs :initarg :isystem :type list :initform nil))) -(defmacro register-prebaked-optionset (hashmap target-str key &rest options) +(defmacro register-prebaked-optionset (hashmap type target-str key &rest options) (declare (indent 3)) `(puthash ',key - (make-instance 'compiler-option-config + (make-instance ,type :target-str ,target-str ,@options) ,hashmap)) diff --git a/lisp/llvm-lib/clang-command.el b/lisp/llvm-lib/clang-command.el index 1e5c7a7..64578f3 100644 --- a/lisp/llvm-lib/clang-command.el +++ b/lisp/llvm-lib/clang-command.el @@ -34,7 +34,7 @@ target-options lang-options other-options optimization-level include-dirs) - opts + config (--> (list (or binary-path "") diff --git a/lisp/llvm-lib/lib-comp-dev.el b/lisp/llvm-lib/lib-comp-dev.el index 4e58b72..71e1548 100644 --- a/lisp/llvm-lib/lib-comp-dev.el +++ b/lisp/llvm-lib/lib-comp-dev.el @@ -158,7 +158,7 @@ (t (completing-read (format "Which %s? " prompt) collection nil nil initial-input))))) -(defun comp-dev/prompt-tool (tool-regexp &optional directories) +(defun comp-dev/get-tools (tool-regexp &optional directories) (cl-mapcan #'(lambda (dir) (when (file-exists-p dir) (when (string-match-p "/sim/sds11.*" dir) @@ -171,7 +171,7 @@ (let (;;(vertico-sort-function nil) ) (my/completing-read tool-regexp - (comp-dev/prompt-tool tool-regexp + (comp-dev/get-tools tool-regexp (or (and (eq 'string (type-of directories)) (list directories))))))) diff --git a/lisp/llvm-lib/llvm-act-on-file/act-on-ll-file.el b/lisp/llvm-lib/llvm-act-on-file/act-on-ll-file.el index 006fae0..489404f 100644 --- a/lisp/llvm-lib/llvm-act-on-file/act-on-ll-file.el +++ b/lisp/llvm-lib/llvm-act-on-file/act-on-ll-file.el @@ -28,17 +28,17 @@ (require 'make-tmp-output-file) (defvar ll/ll-file-action-map - '((assembly :key ?a :major-mode asm-mode :buffer-string "assembly" :description "[a]ssembly") - (run-pass :key ?o :major-mode llvm-mode :buffer-string "run-%s" :description "run-[o]ne-pass") - (run-pass-diff :key ?d :major-mode llvm-mode :buffer-string "diff-%s" :description "[d]iff-one-pass") - (stop-after :key ?a :major-mode llvm-mode :buffer-string "stop-after-%s" :description "stop-[a]fter") - (stop-before :key ?b :major-mode llvm-mode :buffer-string "stop-before-%s" :description "stop-[b]efore") - (start-after :key ?A :major-mode llvm-mode :buffer-string "start-after-%s" :description "start-[A]fter") - (start-before :key ?B :major-mode llvm-mode :buffer-string "start-before-%s" :description "start-[B]efore"))) + '((assembly :key ?a :major-mode asm-mode :end-state 'asm :buffer-string "assembly" :description "[a]ssembly") + (run-pass :key ?o :major-mode llvm-mode :end-state 'llvm-ir :buffer-string "run-%s" :description "run-[o]ne-pass") + (run-pass-diff :key ?d :major-mode llvm-mode :end-state 'llvm-ir :buffer-string "diff-%s" :description "[d]iff-one-pass") + (stop-after :key ?a :major-mode llvm-mode :end-state 'llvm-ir :buffer-string "stop-after-%s" :description "stop-[a]fter") + (stop-before :key ?b :major-mode llvm-mode :end-state 'llvm-ir :buffer-string "stop-before-%s" :description "stop-[b]efore") + (start-after :key ?A :major-mode llvm-mode :end-state 'llvm-ir :buffer-string "start-after-%s" :description "start-[A]fter") + (start-before :key ?B :major-mode llvm-mode :end-state 'llvm-ir :buffer-string "start-before-%s" :description "start-[B]efore"))) -(defun ll/build-llc-command (file action &optional output pass) - (lls/get-llc-command-fun :file file :action action :output output :pass pass - :llc (comp-dev/prompt-tool "llc$"))) +(defun ll/build-llc-command (file end-state &optional output pass) + (comp-dev/process-file + (comp-dev/get-config) 'llvm-ir end-state (comp-dev/prompt-tool "llc$") file output nil)) (defun ll/ll-file-diff-action (file action) ) @@ -57,7 +57,8 @@ (t ".mir"))))) (aprog1 (compilation-start - (ll/build-llc-command file action output pass) + (ll/build-llc-command + file (aml/get-map-prop ll/ll-file-action-map action :end-state) output pass) (aml/get-map-prop ll/ll-file-action-map action :major-mode) (lambda (_) (format "*%s-%s*" diff --git a/lisp/llvm-lib/llvm-comp-dev.el b/lisp/llvm-lib/llvm-comp-dev.el index abc0ab7..f0596c9 100644 --- a/lisp/llvm-lib/llvm-comp-dev.el +++ b/lisp/llvm-lib/llvm-comp-dev.el @@ -62,8 +62,8 @@ 'llvm-comp-dev-config :root-dir root-dir :target (completing-read "Which target? " '("X86" "ARM" "Hexagon" "AIE" "RISCV")) - :tramp tramp-conn + ;; :tramp tramp-conn ;; :build-dirs-fun (lls/guess-build-dirs-fun root-dir) ;; :cc #'lls/default-comp-fun ;; :dc #'lls/default-dis-comm @@ -74,47 +74,71 @@ (add-to-list 'comp-dev/init-functions 'llvm/default-target-init) +(defun lls/llvm-build-dirs (root-dir) + (let ((build-dir (expand-file-name "build" root-dir))) + (when (file-exists-p build-dir) + (--> build-dir + (directory-files it t) + (remove-if-not #'(lambda (dir) + (file-exists-p + (expand-file-name "build.ninja" dir))) + it) + (sort it #'(lambda (x y) + (cond ((string-match-p "^Release$" (file-name-nondirectory y)) nil) + ((string-match-p "^Release$" (file-name-nondirectory x)) t) + (t (string< x y))))))))) + +(defun lls/llvm-bin-dirs (root-dir) + (mapcar #'(lambda (dir) + (expand-file-name "bin" dir)) + (lls/llvm-build-dirs root-dir))) + (cl-defmethod comp-dev/get-bin-dirs ((config llvm-comp-dev-config)) - (list - "/usr/bin/")) + (cons + "/usr/bin/" + (lls/llvm-bin-dirs (comp-dev/conf-get 'root-dir)))) (cl-defmethod comp-dev/get-file-types ((config llvm-comp-dev-config)) '(c pp-c llvm-ir asm obj exe)) (cl-defmethod comp-dev/get-c-action-table ((config llvm-comp-dev-config)) - '((assembly :key ?a :major-mode asm-mode :buffer-string "assembly" :description "[a]ssembly" :end-state asm) + '((assembly :key ?a :major-mode asm-mode :buffer-string "assembly" :description "[a]ssembly" :end-state asm) (debug :key ?d :major-mode llvm-mode :buffer-string "debug" :description "[d]ebug pass" :end-state asm) (LLVMIR :key ?l :major-mode llvm-mode :buffer-string "llvm-ir" :description "[l]lvm-ir" :end-state llvm-ir) (before-after :key ?p :major-mode llvm-mode :buffer-string "print-before-after" :description "[p]rint before/after" :end-state asm) - (changed :key ?P :major-mode llvm-mode :buffer-string "print-changed" :description "[P]rint before/after all" :end-state asm) - (assembly :key ?a :major-mode asm-mode :buffer-string "assembly" :description "[a]ssembly" :end-state asm))) + (changed :key ?P :major-mode llvm-mode :buffer-string "print-changed" :description "[P]rint before/after all" :end-state asm))) + +(cl-defmethod comp-dev/tool-name ((config llvm-comp-dev-config) type) + (pcase type + ('compiler "clang"))) ;; (output-dis :key ?A :major-mode asm-mode :buffer-string "dissasembly" :description "output-dis[A]ssemble" :end-state nil) -(cl-defmethod comp-dev/process-file ((config llvm-comp-dev-config) start-type end-type compiler file output flags) - (pcase start +(cl-defmethod comp-dev/process-file ((config llvm-comp-dev-config) start-type end-type tool file output flags) + (pcase start-type ('c (--> - (list compiler + (list tool (clang/get-clang-options) - (string-join rest " ") file + flags (pcase end-type ('pp-c "-E") ('llvm-ir "-S -emit-llvm") ('asm "-S") ('obj "-c") ('exe (error "unimplemented"))) - flags "-o -" (or (and output (format "| tee %s" output)) "")) (flatten-list it) + (string-join it " "))) + ('llvm-ir + (--> + (list tool file "-o -") (string-join it " "))))) - - (defun lls/get-llvm-root-dir () (comp-dev/ensure-initialized) (comp-dev/conf-get 'root-dir)) @@ -194,21 +218,6 @@ (format "lldb %s" binary))) -(defun lls/guess-build-dirs-fun (root-dir) - (lambda () - (let ((build-dir (expand-file-name "build" root-dir))) - (when (file-exists-p build-dir) - (--> build-dir - (directory-files it t) - (remove-if-not #'(lambda (dir) - (file-exists-p - (expand-file-name "build.ninja" dir))) - it) - (sort it #'(lambda (x y) - (cond ((string-match-p "^Release$" (file-name-nondirectory y)) nil) - ((string-match-p "^Release$" (file-name-nondirectory x)) t) - (t (string< x y)))))))))) - (defun lls/cmake-here (directory build-type target) (interactive (list (expand-file-name "llvm" diff --git a/lisp/llvm-lib/my-clang-options.el b/lisp/llvm-lib/my-clang-options.el index 4626eb8..bdf5d8b 100644 --- a/lisp/llvm-lib/my-clang-options.el +++ b/lisp/llvm-lib/my-clang-options.el @@ -25,29 +25,29 @@ ;;; Code: (require 'clang-command) -(register-prebaked-optionset clang-subtargets "ARM" cortex-r4-soft-float +(register-prebaked-optionset clang-subtargets 'clang-option-config "ARM" cortex-r4-soft-float :target "-target arm -mcpu=cortex-r4 -mfpu=none -mfloat-abi=soft -mlittle-endian") -(register-prebaked-optionset clang-subtargets "ARM" cortex-hard-float +(register-prebaked-optionset clang-subtargets 'clang-option-config "ARM" cortex-hard-float :target "-target arm -mcpu=cortex-r4 -mfpu=vfpv3-d16 -mfloat-abi=hard -mlittle-endian") -(register-prebaked-optionset clang-subtargets "ARM" cortex-hard-float-tmu +(register-prebaked-optionset clang-subtargets 'clang-option-config "ARM" cortex-hard-float-tmu :target "-target arm -mcpu=cortex-r4 -mfpu=vfpv3-d16 -mfloat-abi=hard -mlittle-endian") -(register-prebaked-optionset clang-subtargets "ARM" cortex-m0 +(register-prebaked-optionset clang-subtargets 'clang-option-config "ARM" cortex-m0 :target "-target arm -mcpu=cortex-m0 -mlittle-endian -mthumb") -(register-prebaked-optionset clang-subtargets "ARM" cortex-m4 +(register-prebaked-optionset clang-subtargets 'clang-option-config "ARM" cortex-m4 :target "-target arm -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16") -(register-prebaked-optionset clang-subtargets "ARM" cortex-m33 +(register-prebaked-optionset clang-subtargets 'clang-option-config "ARM" cortex-m33 :target "-target arm -mcpu=cortex-m33 -mfpu=vfpv3-d16 -mfloat-abi=hard -mlittle-endian") -(register-prebaked-optionset clang-subtargets "RISCV" rv32im +(register-prebaked-optionset clang-subtargets 'clang-option-config "RISCV" rv32im :target "-target riscv32-unknown-elf -march=rv32im -mabi=ilp32" :optimization "-O3") -(register-prebaked-optionset clang-subtargets "RISCV" rv32imafc +(register-prebaked-optionset clang-subtargets 'clang-option-config "RISCV" rv32imafc :target "-target riscv32-unknown-elf -march=rv32imafc -mabi=ilp32f -mno-relax" :optimization "-O3")