mirror of
https://github.com/pestctrl/emacs-config.git
synced 2026-06-14 04:11:18 +00:00
ugh
This commit is contained in:
parent
a9ac44b961
commit
43b38d29a2
3 changed files with 154 additions and 155 deletions
|
|
@ -23,7 +23,10 @@
|
|||
;;; Commentary:
|
||||
|
||||
;;; Code:
|
||||
(require 'clang-option-sets)
|
||||
(require 'compiler-option-sets)
|
||||
|
||||
(defclass clang-option-config (compiler-option-config)
|
||||
nil)
|
||||
|
||||
(defvar clang-subtargets
|
||||
(make-hash-table :test #'equal))
|
||||
|
|
@ -31,23 +34,23 @@
|
|||
(defvar clang-options-extensions
|
||||
(make-hash-table :test #'equal))
|
||||
|
||||
(defvar cc/all-target-options
|
||||
(defvar clang/all-target-options
|
||||
(make-hash-table))
|
||||
|
||||
(defvar cc/current-target-optionset
|
||||
(defvar clang/current-target-optionset
|
||||
(make-hash-table))
|
||||
|
||||
(defun cc/push-new-target-option (target name option-set)
|
||||
(defun clang/push-new-target-option (target name option-set)
|
||||
(puthash target
|
||||
(cons (cons name option-set)
|
||||
(gethash target cc/all-target-options))
|
||||
cc/all-target-options))
|
||||
(gethash target clang/all-target-options))
|
||||
clang/all-target-options))
|
||||
|
||||
(defun cc/add-and-set-target-option (target name option-set)
|
||||
(puthash target name cc/current-target-optionset)
|
||||
(cc/push-new-target-option target name option-set))
|
||||
(defun clang/add-and-set-target-option (target name option-set)
|
||||
(puthash target name clang/current-target-optionset)
|
||||
(clang/push-new-target-option target name option-set))
|
||||
|
||||
(defvar cc/file-specific-options
|
||||
(defvar clang/file-specific-options
|
||||
(make-hash-table :test #'equal))
|
||||
|
||||
(defun my/completing-read-formatter (formatter prompt list)
|
||||
|
|
@ -60,7 +63,7 @@
|
|||
alist
|
||||
nil nil #'equal)))
|
||||
|
||||
(defun cc/make-clang-option-set (target)
|
||||
(defun clang/make-clang-option-set (target)
|
||||
(let ((subtargets (hash-table-values clang-subtargets))
|
||||
primary extensions)
|
||||
(setq primary
|
||||
|
|
@ -73,118 +76,143 @@
|
|||
subtargets)))
|
||||
(cons primary extensions)))
|
||||
|
||||
(defun cc/get-named-target-clang-optionset (target option-name)
|
||||
(defun clang/get-named-target-clang-optionset (target option-name)
|
||||
(when-let ((target-options
|
||||
(gethash target cc/all-target-options)))
|
||||
(gethash target clang/all-target-options)))
|
||||
(and target-options
|
||||
(alist-get option-name target-options nil nil #'equal))))
|
||||
|
||||
(defun cc/reinitialize-clang-options (target)
|
||||
(defun clang/reinitialize-clang-options (target)
|
||||
(interactive (list (intern (lls/conf-get 'target))))
|
||||
(let ((option-name (or (gethash target cc/current-target-optionset)
|
||||
(puthash target "default" cc/current-target-optionset))))
|
||||
(aprog1 (cc/make-clang-option-set target)
|
||||
(cc/push-new-target-option target option-name it))))
|
||||
(let ((option-name (or (gethash target clang/current-target-optionset)
|
||||
(puthash target "default" clang/current-target-optionset))))
|
||||
(aprog1 (clang/make-clang-option-set target)
|
||||
(clang/push-new-target-option target option-name it))))
|
||||
|
||||
;;; THE function
|
||||
(defun cc/get-clang-options-for-target (target &optional option-name)
|
||||
(defun clang/get-clang-options-for-target (target &optional option-name)
|
||||
(let ((option-name (or option-name
|
||||
(gethash target cc/current-target-optionset)
|
||||
(puthash target "default" cc/current-target-optionset))))
|
||||
(or (gethash (buffer-file-name) cc/file-specific-options)
|
||||
(cc/get-named-target-clang-optionset target option-name)
|
||||
(aprog1 (cc/make-clang-option-set target)
|
||||
(cc/push-new-target-option target option-name it)))))
|
||||
(gethash target clang/current-target-optionset)
|
||||
(puthash target "default" clang/current-target-optionset))))
|
||||
(or (gethash (buffer-file-name) clang/file-specific-options)
|
||||
(clang/get-named-target-clang-optionset target option-name)
|
||||
(aprog1 (clang/make-clang-option-set target)
|
||||
(clang/push-new-target-option target option-name it)))))
|
||||
|
||||
;; (cc/get-clang-options-for-target "c29")
|
||||
;; (clang/get-clang-options-for-target "c29")
|
||||
|
||||
(defun cc/new-clang-option-set (target name &optional optionset)
|
||||
;; (defun clang/new-clang-option-set (target name &optional optionset)
|
||||
;; (interactive
|
||||
;; (list (intern (lls/conf-get 'target))
|
||||
;; (read-string "Name for new optionset? ")))
|
||||
;; (let ((optionset (or optionset (clang/make-clang-option-set target))))
|
||||
;; (clang/add-and-set-target-option target name optionset)))
|
||||
|
||||
;; (defun clang/copy-clang-option-set (target name &optional optionset)
|
||||
;; (interactive
|
||||
;; (list (intern (lls/conf-get 'target))
|
||||
;; (read-string "Name for new optionset? ")))
|
||||
;; (let ((optionset (clang/get-clang-options-for-target target)))
|
||||
;; (clang/add-and-set-target-option target name optionset)))
|
||||
|
||||
;; (defun clang/file-specific-option-set (target &optional optionset)
|
||||
;; (interactive
|
||||
;; (list (intern (lls/conf-get 'target))))
|
||||
;; ;; TODO: might need to garbage collect these
|
||||
;; (or (gethash (buffer-file-name)
|
||||
;; clang/file-specific-options)
|
||||
;; (let ((optionset (clang/get-clang-options-for-target target)))
|
||||
;; (puthash (buffer-file-name)
|
||||
;; optionset
|
||||
;; clang/file-specific-options))))
|
||||
|
||||
;; (clang/new-clang-option-set "c29" "toyota")
|
||||
|
||||
(defun clang/switch-clang-option-set (target name)
|
||||
(interactive
|
||||
(list (intern (lls/conf-get 'target))
|
||||
(read-string "Name for new optionset? ")))
|
||||
(let ((optionset (or optionset (cc/make-clang-option-set target))))
|
||||
(cc/add-and-set-target-option target name optionset)))
|
||||
|
||||
(defun cc/copy-clang-option-set (target name &optional optionset)
|
||||
(interactive
|
||||
(list (intern (lls/conf-get 'target))
|
||||
(read-string "Name for new optionset? ")))
|
||||
(let ((optionset (cc/get-clang-options-for-target target)))
|
||||
(cc/add-and-set-target-option target name optionset)))
|
||||
|
||||
(defun cc/file-specific-option-set (target &optional optionset)
|
||||
(interactive
|
||||
(list (intern (lls/conf-get 'target))))
|
||||
;; TODO: might need to garbage collect these
|
||||
(or (gethash (buffer-file-name)
|
||||
cc/file-specific-options)
|
||||
(let ((optionset (cc/get-clang-options-for-target target)))
|
||||
(puthash (buffer-file-name)
|
||||
optionset
|
||||
cc/file-specific-options))))
|
||||
|
||||
;; (cc/new-clang-option-set "c29" "toyota")
|
||||
|
||||
(defun cc/switch-clang-option-set (target name)
|
||||
(interactive
|
||||
(let ((target (lls/conf-get 'target)))
|
||||
(let ((target lls/conf-get 'target))
|
||||
(list target
|
||||
(--> (intern target)
|
||||
(gethash it cc/all-target-options)
|
||||
(gethash it clang/all-target-options)
|
||||
(mapcar #'car it)
|
||||
(completing-read "Optionset? " it)))))
|
||||
(remhash (buffer-file-name)
|
||||
cc/file-specific-options)
|
||||
(cc/get-clang-options-for-target target name)
|
||||
(puthash (intern target) name cc/current-target-optionset))
|
||||
clang/file-specific-options)
|
||||
(clang/get-clang-options-for-target target name)
|
||||
(puthash (intern target) name clang/current-target-optionset))
|
||||
|
||||
(defun cc/edit-clang-options (prefix)
|
||||
(defun clang/edit-clang-options (prefix)
|
||||
(interactive "P")
|
||||
(let* ((target (intern (lls/conf-get 'target)))
|
||||
(options-config
|
||||
(->>
|
||||
target
|
||||
(cc/get-clang-options-for-target)
|
||||
(clang/get-clang-options-for-target)
|
||||
(car)))
|
||||
(current-name
|
||||
(or (and (gethash (buffer-file-name) cc/file-specific-options )
|
||||
(or (and (gethash (buffer-file-name) clang/file-specific-options )
|
||||
"file-specific")
|
||||
(gethash target cc/current-target-optionset))))
|
||||
(dolist (slot (cddr (eieio-class-slots 'clang-option-config)))
|
||||
(let* ((slot-sym (eieio-slot-descriptor-name slot))
|
||||
(slot-val (and (slot-boundp options-config slot-sym)
|
||||
(slot-value options-config slot-sym))))
|
||||
(when slot-val
|
||||
(pcase (cl--slot-descriptor-type slot)
|
||||
('list
|
||||
(when (or prefix
|
||||
(not (zerop (length slot-val))))
|
||||
(setf (slot-value options-config slot-sym)
|
||||
(read
|
||||
(read-string (format "Edit '%s' for optionset '%s': "
|
||||
(symbol-name slot-sym)
|
||||
current-name)
|
||||
(prin1-to-string slot-val))))))
|
||||
('string
|
||||
(when (or prefix
|
||||
(not (string= slot-val "")))
|
||||
(setf (slot-value options-config slot-sym)
|
||||
(read-string (format "Edit '%s' for optionset '%s': "
|
||||
(symbol-name slot-sym)
|
||||
current-name)
|
||||
slot-val))))))))))
|
||||
(gethash target clang/current-target-optionset))))
|
||||
(cos/edit-compiler-options options-config current-name)))
|
||||
|
||||
(defvar cc/detect-extensions-function nil)
|
||||
(defun clang/clang-options-merge (primary secondary)
|
||||
(make-instance
|
||||
'clang-option-config
|
||||
:target-str (slot-value primary 'target-str)
|
||||
:binary (or (slot-value primary 'binary-path)
|
||||
(car (mapcar #'(lambda (x) (slot-value x 'binary-path))) ))
|
||||
:target (slot-value primary 'target-options)
|
||||
:lang (slot-value primary 'lang-options)
|
||||
:optimization (slot-value primary 'optimization-level)
|
||||
:other (-->
|
||||
(cons primary secondary)
|
||||
(mapconcat
|
||||
(lambda (x)
|
||||
(when (slot-boundp x 'other-options)
|
||||
(slot-value x 'other-options)))
|
||||
it
|
||||
" "))
|
||||
:include-dirs (-->
|
||||
(cons primary secondary)
|
||||
(apply #'append
|
||||
(mapcar
|
||||
(lambda (x)
|
||||
(when (slot-boundp x 'include-dirs)
|
||||
(slot-value x 'include-dirs)))
|
||||
it)))))
|
||||
|
||||
(cl-defun cc/get-clang-options (&key filename compiler action)
|
||||
(defun clang/clang-options->string (opts)
|
||||
(with-slots
|
||||
(binary-path
|
||||
target-options lang-options
|
||||
other-options optimization-level
|
||||
include-dirs)
|
||||
opts
|
||||
(-->
|
||||
(list
|
||||
(or binary-path "")
|
||||
target-options
|
||||
lang-options
|
||||
optimization-level
|
||||
other-options
|
||||
(mapconcat (lambda (x)
|
||||
(format "-I\"%s\"" x))
|
||||
include-dirs
|
||||
" "))
|
||||
(remove-if #'string-empty-p it)
|
||||
(string-join it " "))))
|
||||
|
||||
(defvar clang/detect-extensions-function nil)
|
||||
|
||||
(cl-defun clang/get-clang-options (&key filename compiler action)
|
||||
(interactive)
|
||||
(let* ((filename (or filename (buffer-file-name)))
|
||||
(target-str (lls/conf-get 'target))
|
||||
(target (intern target-str))
|
||||
(options-config
|
||||
(cc/get-clang-options-for-target target))
|
||||
(clang/get-clang-options-for-target target))
|
||||
(detected-extensions
|
||||
(awhen cc/detect-extensions-function
|
||||
(awhen clang/detect-extensions-function
|
||||
(funcall it compiler action filename target-str))))
|
||||
(cos/clang-options->string
|
||||
(cos/clang-options-merge
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
;;; clang-option-sets.el --- -*- lexical-binding: t -*-
|
||||
;;; compiler-option-sets.el --- -*- lexical-binding: t -*-
|
||||
|
||||
;; Copyright (C) 2024 Benson Chu
|
||||
|
||||
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
;;; Code:
|
||||
|
||||
(defclass clang-option-config ()
|
||||
(defclass compiler-option-config ()
|
||||
((target-str :initarg :target-str :type string :initform "")
|
||||
(binary-path :initarg :binary :type string :initform "")
|
||||
(target-options :initarg :target :type string :initform "")
|
||||
|
|
@ -37,57 +37,37 @@
|
|||
(defmacro register-prebaked-optionset (hashmap target-str key &rest options)
|
||||
(declare (indent 3))
|
||||
`(puthash ',key
|
||||
(make-instance 'clang-option-config
|
||||
(make-instance 'compiler-option-config
|
||||
:target-str ,target-str
|
||||
,@options)
|
||||
,hashmap))
|
||||
|
||||
(defun cos/clang-options-merge (primary secondary)
|
||||
(make-instance
|
||||
'clang-option-config
|
||||
:target-str (slot-value primary 'target-str)
|
||||
:binary (or (slot-value primary 'binary-path)
|
||||
(car (mapcar #'(lambda (x) (slot-value x 'binary-path))) ))
|
||||
:target (slot-value primary 'target-options)
|
||||
:lang (slot-value primary 'lang-options)
|
||||
:optimization (slot-value primary 'optimization-level)
|
||||
:other (-->
|
||||
(cons primary secondary)
|
||||
(mapconcat
|
||||
(lambda (x)
|
||||
(when (slot-boundp x 'other-options)
|
||||
(slot-value x 'other-options)))
|
||||
it
|
||||
" "))
|
||||
:include-dirs (-->
|
||||
(cons primary secondary)
|
||||
(apply #'append
|
||||
(mapcar
|
||||
(lambda (x)
|
||||
(when (slot-boundp x 'include-dirs)
|
||||
(slot-value x 'include-dirs)))
|
||||
it)))))
|
||||
(defun cos/edit-compiler-options (optionset current-name)
|
||||
(dolist (slot (cddr (eieio-class-slots 'compiler-option-config)))
|
||||
(let* ((slot-sym (eieio-slot-descriptor-name slot))
|
||||
(slot-val (and (slot-boundp optionsset slot-sym)
|
||||
(slot-value optionsset slot-sym))))
|
||||
(when slot-val
|
||||
(pcase (cl--slot-descriptor-type slot)
|
||||
('list
|
||||
(when (or prefix
|
||||
(not (zerop (length slot-val))))
|
||||
(setf (slot-value optionsset slot-sym)
|
||||
(read
|
||||
(read-string (format "Edit '%s' for optionset '%s': "
|
||||
(symbol-name slot-sym)
|
||||
current-name)
|
||||
(prin1-to-string slot-val))))))
|
||||
('string
|
||||
(when (or prefix
|
||||
(not (string= slot-val "")))
|
||||
(setf (slot-value optionsset slot-sym)
|
||||
(read-string (format "Edit '%s' for optionset '%s': "
|
||||
(symbol-name slot-sym)
|
||||
current-name)
|
||||
slot-val)))))))))
|
||||
|
||||
(defun cos/clang-options->string (opts)
|
||||
(with-slots
|
||||
(binary-path
|
||||
target-options lang-options
|
||||
other-options optimization-level
|
||||
include-dirs)
|
||||
opts
|
||||
(-->
|
||||
(list
|
||||
(or binary-path "")
|
||||
target-options
|
||||
lang-options
|
||||
optimization-level
|
||||
other-options
|
||||
(mapconcat (lambda (x)
|
||||
(format "-I\"%s\"" x))
|
||||
include-dirs
|
||||
" "))
|
||||
(remove-if #'string-empty-p it)
|
||||
(string-join it " "))))
|
||||
(cl-defgeneric cos/process-c-file (optionset result file output))
|
||||
|
||||
(provide 'clang-option-sets)
|
||||
;;; clang-option-sets.el ends here
|
||||
(provide 'compiler-option-sets)
|
||||
;;; compiler-option-sets.el ends here
|
||||
|
|
|
|||
|
|
@ -50,24 +50,17 @@
|
|||
|
||||
;; =============================== Init ==============================
|
||||
|
||||
(defclass llvm-config ()
|
||||
(defclass comp-dev-config ()
|
||||
((root-dir :initarg :root-dir :type string)
|
||||
(bin-dirs-fun :initarg :bin-dirs-fun :type function)
|
||||
(build-dirs-fun :initarg :build-dirs-fun :type function)
|
||||
(build-release-dir :initarg :build-release-dir :type string)
|
||||
(build-debug-dir :initarg :build-debug-dir :type string)
|
||||
(target :initarg :target :type string)
|
||||
(compile-command-fun :initarg :cc :type function :initform (lambda ()))
|
||||
(dis-command-fun :initarg :dc :type function :initform (lambda ()))
|
||||
(llc-command-fun :initarg :llc :type function :initform (lambda ()))
|
||||
(tramp-connection :initarg :tramp :type list :initform nil)
|
||||
;; Target + CPU -> compilation command options
|
||||
(target-clang-opts-fun :initarg :clang-opts-fun :type function :initform (lambda ()))
|
||||
(aux-props :initarg :aux-props :type list :initform nil)))
|
||||
|
||||
;; (defvar lls/llvm-config nil)
|
||||
(cl-defgeneric comp-dev/get-bin-dirs (config))
|
||||
(cl-defgeneric comp-dev/get-build-dirs (config))
|
||||
|
||||
(defvar lls/llvm-configs (make-hash-table :test #'equal))
|
||||
(defvar comp-dev/configs (make-hash-table :test #'equal))
|
||||
|
||||
(defvar lls/target-init-fun nil)
|
||||
|
||||
|
|
@ -83,6 +76,8 @@
|
|||
conf
|
||||
lls/llvm-configs))
|
||||
|
||||
;; (defvar lls/llvm-config nil)
|
||||
|
||||
(defun lls/conf-get (sym)
|
||||
(lls/ensure-initialized)
|
||||
(slot-value (lls/get-llvm-config) sym))
|
||||
|
|
@ -210,10 +205,6 @@
|
|||
(cons dir
|
||||
(lls/conf-get 'build-dirs))))
|
||||
|
||||
(defun lls/get-clang-options (&rest args)
|
||||
(apply (lls/conf-get 'target-clang-opts-fun)
|
||||
args))
|
||||
|
||||
;; =============================== Misc ==============================
|
||||
|
||||
(defun my/completing-read (prompt collection &optional initial-input)
|
||||
|
|
|
|||
Loading…
Reference in a new issue