Refactoring part 1

This commit is contained in:
Benson Chu 2022-12-17 09:24:16 -06:00
parent 5fc6a6f418
commit 9254d03956
4 changed files with 29 additions and 63 deletions

View file

@ -58,10 +58,10 @@
(defun ll/get-required-binaries-for-test (file)
(->> (ll/get-test-run-commands file)
(mapcan #'(lambda (x) (string-split x "|")))
(mapcan #'(lambda (x) (split-string x "|")))
(mapcar #'string-trim)
(mapcar #'(lambda (x)
(let ((str (car (string-split x " "))))
(let ((str (car (split-string x " "))))
(if (string= str "%clang_cc1")
"clang"
str))))

View file

@ -1,50 +0,0 @@
;;; llvm-lib.el --- -*- lexical-binding: t -*-
;; Copyright (C) 2022 Benson Chu
;; Author: Benson Chu <bensonchu457@gmail.com>
;; Created: [2022-12-16 18:46]
;; This file is not part of GNU Emacs
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;;; Code:
(require 'llvm-shared)
(require 'act-on-test-file)
(require 'act-on-c-file)
(require 'act-on-ll-file)
(define-prefix-command '*llvm-map*)
(define-key *root-map* (kbd "C-w") '*llvm-map*)
(define-key *llvm-map* (kbd "a") #'ll/act-on-file)
(defun ll/act-on-file (file)
(interactive (list (or (buffer-file-name (current-buffer))
(read-file-name "File? "))))
(when (null file)
(setq file (make-temp-file nil nil ".ll"))
(write-file file))
(pcase (file-name-extension file)
((and _ (guard (ll/is-test-file file)))
(ll/act-on-test-file file))
("c" (ll/act-on-c-file file))
("ll" (ll/act-on-ll-file file))
(_ (message "Not sure what you'd like me to do with this file"))))
(provide 'llvm-lib)
;;; llvm-lib.el ends here

View file

@ -39,25 +39,42 @@
(defvar lls/llvm-root-dir nil)
(defvar lls/llvm-build-dirs nil)
(defvar lls/llvm-bin-dirs nil)
(defvar lls/target-init-fun
nil)
(defun lls/init-llvm-shared (root-dir build-dirs)
(setq lls/llvm-build-dirs (or build-dirs
(read-file-name "build directory? "))
lls/llvm-root-dir (or root-dir
(read-file-name "llvm-project directory? "))))
(defun lls/init-llvm-shared (root-dir build-dirs &optional bindirs)
(let ((r (rx (or "RelWithAsserts" "Release"))))
(setq lls/llvm-root-dir (or root-dir
(read-file-name "llvm-project directory? "))
lls/llvm-build-dirs
(sort build-dirs
#'(lambda (x y)
(cond ((string-match-p r y) nil)
((string-match-p r x) t)
(t (string< x y)))))
lls/llvm-bin-dirs bindirs)))
(defun lls/get-llvm-root-dir ()
(or lls/llvm-root-dir
(funcall lls/target-init-fun #'lls/init-llvm-shared)
lls/llvm-root-dir))
(and (funcall lls/target-init-fun #'lls/init-llvm-shared)
lls/llvm-root-dir)))
(defun lls/get-llvm-build-dirs ()
(or lls/llvm-build-dirs
(funcall lls/target-init-fun #'lls/init-llvm-shared)
lls/llvm-build-dirs))
(and (funcall lls/target-init-fun #'lls/init-llvm-shared)
lls/llvm-build-dirs)))
(defun lls/get-llvm-bin-dir ()
(car (lls/get-llvm-bin-dirs)))
(defun lls/get-llvm-bin-dirs ()
(append (mapcar #'(lambda (x) (expand-file-name "bin" x))
(lls/get-llvm-build-dirs))
(or lls/llvm-bin-dirs
(and (funcall lls/target-init-fun #'lls/init-llvm-shared)
lls/llvm-bin-dirs))))
(defun lls/get-llvm-build-dir ()
(car (lls/get-llvm-build-dirs)))
@ -74,7 +91,7 @@
(cl-mapcan #'(lambda (dir)
(directory-files dir t tool-regexp))
(or directories
(lls/get-llvm-build-dirs))))
(lls/get-llvm-bin-dirs))))
(defvar lls/get-clang-command-fun
(lambda (compiler file action &optional rest)

View file

@ -30,7 +30,6 @@
(require 'ti-keymap)
(require 'ti-lib)
(require 'ti-build-tool)
(require 'ti-debug-compile)
(require 'ti-tools-backup)
(require 'argo-fastsim-dump-mode)
(require 'frame-restore)