From 19d13c8339ee990fba358417a54aa6f1c94c7bca Mon Sep 17 00:00:00 2001 From: bd Date: Sun, 16 Mar 2025 19:32:12 -0400 Subject: Add clingon command-line arg parser, finish test harness setup --- src/main.lisp | 68 ++++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 49 insertions(+), 19 deletions(-) (limited to 'src/main.lisp') 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))) -- cgit v1.2.3