From ab53e43bd389dc2dfe3f2d8bbb9043a832fa9e35 Mon Sep 17 00:00:00 2001 From: Benson Chu Date: Tue, 21 Feb 2023 13:31:57 -0600 Subject: [PATCH] Compile executable --- .../llvm-act-on-file/act-on-c-file.el | 38 +++++++++---------- lisp/llvm-lib/llvm-shared.el | 7 +++- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/lisp/llvm-lib/llvm-act-on-file/act-on-c-file.el b/lisp/llvm-lib/llvm-act-on-file/act-on-c-file.el index 6f715b7..4b63c61 100644 --- a/lisp/llvm-lib/llvm-act-on-file/act-on-c-file.el +++ b/lisp/llvm-lib/llvm-act-on-file/act-on-c-file.el @@ -29,13 +29,14 @@ (require 'anaphora) (defvar ll/c-file-action-map - '((debug :key ?d :major-mode llvm-mode :buffer-string "debug" :description "[d]ebug pass" :compiler-action assemble) - (assembly :key ?a :major-mode asm-mode :buffer-string "assembly" :description "[a]ssembly" :compiler-action assemble) - (output-dis :key ?A :major-mode asm-mode :buffer-string "dissasembly" :description "output-dis[A]ssemble" :compiler-action nil) - (preprocess :key ?e :major-mode c-mode :buffer-string "preprocess" :description "pr[e]process" :compiler-action preprocess) - (LLVMIR :key ?l :major-mode llvm-mode :buffer-string "llvm-ir" :description "[l]lvm-ir" :compiler-action llvm-ir) - (before-after :key ?p :major-mode llvm-mode :buffer-string "print-before-after" :description "[p]rint before/after" :compiler-action assemble) - (changed :key ?P :major-mode llvm-mode :buffer-string "print-changed" :description "[P]rint before/after all" :compiler-action assemble))) + '((debug :key ?d :major-mode llvm-mode :buffer-string "debug" :description "[d]ebug pass" :compiler-action assemble) + (assembly :key ?a :major-mode asm-mode :buffer-string "assembly" :description "[a]ssembly" :compiler-action assemble) + (output-dis :key ?A :major-mode asm-mode :buffer-string "dissasembly" :description "output-dis[A]ssemble" :compiler-action nil) + (preprocess :key ?e :major-mode c-mode :buffer-string "preprocess" :description "pr[e]process" :compiler-action preprocess) + (LLVMIR :key ?l :major-mode llvm-mode :buffer-string "llvm-ir" :description "[l]lvm-ir" :compiler-action llvm-ir) + (before-after :key ?p :major-mode llvm-mode :buffer-string "print-before-after" :description "[p]rint before/after" :compiler-action assemble) + (changed :key ?P :major-mode llvm-mode :buffer-string "print-changed" :description "[P]rint before/after all" :compiler-action assemble) + (executable :key ?\^M :major-mode nil :buffer-string "executable" :description "Executable" :compiler-action executable))) (defun ll/ensure-clang-binary-built (dir) ;; TODO: assumed build-dir constant, should take as argument and prompt @@ -56,20 +57,15 @@ (ll/clang-output-disassemble-command file) (let ((compiler-action (aml/get-map-prop ll/c-file-action-map action :compiler-action)) (compiler (lls/prompt-tool "clang$"))) - (concat ;; (ll/ensure-clang-binary-built - ;; (file-name-directory - ;; (directory-file-name - ;; (file-name-directory compiler)))) - ;; " && " - (string-join - (list (funcall lls/get-clang-command-fun compiler file compiler-action) - (pcase action - ('debug (format "-mllvm -debug-only=%s" (read-string "Which pass? "))) - ('before-after (let ((pass (read-string "Which pass? "))) - (format "-mllvm -print-before=%s -mllvm -print-after=%s" pass pass))) - ('changed "-mllvm -print-before-all")) - " ") - " "))))) + (string-join + (list (funcall lls/get-clang-command-fun compiler file compiler-action) + (pcase action + ('debug (format "-mllvm -debug-only=%s" (read-string "Which pass? "))) + ('before-after (let ((pass (read-string "Which pass? "))) + (format "-mllvm -print-before=%s -mllvm -print-after=%s" pass pass))) + ('changed "-mllvm -print-before-all")) + " ") + " ")))) (defun ll/buffer-has-include-error (buffer) (with-current-buffer buffer diff --git a/lisp/llvm-lib/llvm-shared.el b/lisp/llvm-lib/llvm-shared.el index cb5fd14..407059f 100644 --- a/lisp/llvm-lib/llvm-shared.el +++ b/lisp/llvm-lib/llvm-shared.el @@ -125,9 +125,12 @@ ('compile "-c") ('assemble "-S") ('preprocess "-E") - ('llvm-ir "-S -emit-llvm")) + ('llvm-ir "-S -emit-llvm") + ('executable "")) (format "-o %s" - (or output "-"))) + (or output + (and (eq action 'executable) "a.out") + "-"))) " ")))) (defvar lls/get-llc-command-fun