diff options
author | bd <bdunahu@operationnull.com> | 2025-03-16 19:32:12 -0400 |
---|---|---|
committer | bd <bdunahu@operationnull.com> | 2025-03-16 19:32:12 -0400 |
commit | 19d13c8339ee990fba358417a54aa6f1c94c7bca (patch) | |
tree | 9e5d2e3e937fa7a2f76c995cb44b90623424208c /src | |
parent | aca2504eec49f140c76b668b6949ba767746a847 (diff) |
Add clingon command-line arg parser, finish test harness setup
Diffstat (limited to 'src')
-rw-r--r-- | src/main.lisp | 68 | ||||
-rw-r--r-- | src/package.lisp | 4 | ||||
-rw-r--r-- | src/util.lisp | 5 |
3 files changed, 58 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))) diff --git a/src/package.lisp b/src/package.lisp index 78eb546..9d21293 100644 --- a/src/package.lisp +++ b/src/package.lisp @@ -1,3 +1,7 @@ (defpackage #:rva (:use #:cl) (:export #:main)) + +(defpackage #:util + (:use #:cl) + (:export #:asm-extension?)) diff --git a/src/util.lisp b/src/util.lisp new file mode 100644 index 0000000..87e4df9 --- /dev/null +++ b/src/util.lisp @@ -0,0 +1,5 @@ +(in-package #:util) + +(defun asm-extension? (file) + "Returns t if FILE is extended with .asm, nil otherwise." + (string= (pathname-type file) "asm")) |