summaryrefslogtreecommitdiff
path: root/src/main.lisp
diff options
context:
space:
mode:
authorbd <bdunahu@operationnull.com>2025-03-16 19:32:12 -0400
committerbd <bdunahu@operationnull.com>2025-03-16 19:32:12 -0400
commit19d13c8339ee990fba358417a54aa6f1c94c7bca (patch)
tree9e5d2e3e937fa7a2f76c995cb44b90623424208c /src/main.lisp
parentaca2504eec49f140c76b668b6949ba767746a847 (diff)
Add clingon command-line arg parser, finish test harness setup
Diffstat (limited to 'src/main.lisp')
-rw-r--r--src/main.lisp68
1 files changed, 49 insertions, 19 deletions
diff --git a/src/main.lisp b/src/main.lisp
index ddb8b8d..c85e392 100644
--- a/src/main.lisp
+++ b/src/main.lisp
@@ -1,29 +1,59 @@
(in-package #:rva)
(defparameter *banner*
- " _/_/ _/_/
- _/ _/
- _/ _/ _/_/ _/ _/ _/_/_/ _/
- _/ _/_/ _/ _/ _/ _/ _/
- _/ _/ _/ _/ _/ _/ _/
- _/ _/ _/ _/_/_/ _/
+ " _/_/ _/_/
+ _/ _/
+ _/ _/ _/_/ _/ _/ _/_/_/ _/
+ _/ _/_/ _/ _/ _/ _/ _/
+ _/ _/ _/ _/ _/ _/ _/
+ _/ _/ _/ _/_/_/ _/
_/_/ _/_/ "
"Stylized ASCII logo.")
-(defun print-version-number ()
+(defun print-splash ()
"Prints a pretty splash-screen."
- (let ((system (asdf:find-system "rva" nil)))
- (format t "~av~a~%" *banner* (asdf:component-version system))))
+ (format t "~a~%" *banner*))
-(defun error-cli (message)
- "Prints MESSAGE and usage information to stderr
-and exits with error code 1."
- (format *error-output*
- "~a~%Usage:
- rva file~%"
- message)
- (sb-ext:exit :code 1))
+(defun cli/options ()
+ "Returns options for the `rva' assembler."
+ (list
+ (clingon:make-option
+ :flag
+ :description "run the lexer, but stop before parsing"
+ :long-name "lex"
+ :short-name #\l
+ :required nil
+ :key :lex)
+ (clingon:make-option
+ :flag
+ :description "run the parser, but stop before emission"
+ :long-name "parse"
+ :short-name #\p
+ :required nil
+ :key :parse)))
-(defun main ()
- (print-version-number)
+(defun driver (cmd)
+ "Reads in a file and directs lexing, parsing, and binary emission."
+ (print-splash)
+ (let ((args (clingon:command-arguments cmd))
+ (parse? (not (clingon:getopt cmd :lex)))
+ (emit? (not (clingon:getopt cmd :parse))))
+ (cond
+ ;; complain about num arguments
+ ((/= (length args) 1) (error "Wrong number of arguments."))
+ ((not (util:asm-extension? (car args))) (error "The file is not an asm source code file."))))
(error-cli "Nitimur in Vetitum"))
+
+(defun cli/command ()
+ "Returns a clingon command."
+ (clingon:make-command
+ :name "rva"
+ :description "generates a binary compatible with the RISC V[ECTOR] simulator"
+ :usage "[options] file"
+ :version(asdf:component-version
+ (asdf:find-system "rva" nil))
+ :options (cli/options)
+ :handler #'driver))
+
+(defun main ()
+ (clingon:run (cli/command)))