Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 8 additions & 19 deletions docs/src/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,14 @@ generated schema is available with `cl-cc docs markdown`.
| `compile-commands [path]` | Generate `compile_commands.json`; `-o` changes its output path. |
| `install <system.asd>` | Register or compile a local ASDF system. |
| `uninstall <system>` | Remove a registered local system. |
| `fuzz [--seed N]` | Placeholder handler; reports a fuzzing completion message. |
| `reduce <file>` | Placeholder handler; reports a reduction completion message. |
| `audit` | Placeholder handler; reports a dependency-audit completion message. |
| `doc <path>` | Generate API documentation; `-o` selects the output. |
| `doctest <path>` | Placeholder handler; reports zero failures. |
| `show-types <file>` | Placeholder handler; reports no file specified. |
| `assert-density <path>` | Placeholder handler; reports a fixed result. |
| `abi-dump <file>` | Placeholder handler; reports completion. |
| `abi-check <old> <new>` | Placeholder handler; reports compatibility. |
| `demangle <name>` | Placeholder handler; echoes the supplied name. |
| `show-types <file>` | Infer and print the type of a source file. |
| `abi-dump <file>` | Write the current ABI manifest to a file. |
| `abi-check <old> <new>` | Compare two ABI manifest files; incompatible manifests fail. |
| `demangle <name>` | Demangle a CL-CC ABI symbol. |
| `disasm <wasm>` | Disassemble Wasm; `--wat` emits WAT and `--decompile` uses wasm-decompile. |
| `inspect <wasm>` | Inspect Wasm sections and disassembly. |
| `objdump <file>` | Placeholder handler; prints a fixed section summary. |
| `macrostep <file>` | Placeholder handler; reports expansion completion. |
| `bisect [range]` | Placeholder handler; reports a fixed result. |
| `features` | Print the handler's static feature list. |
| `dep-graph` | Render the ASDF dependency graph as DOT by default. |
| `generate <schema>` | Placeholder handler; reports code-generation completion. |
| `dep-graph [--format F]` | Render the ASDF dependency graph as `dot`, `json`, `mermaid`, or `topo`. |
| `update [pkg]` | Update dependencies. |
| `completion <shell>` | Emit completion for `bash`, `zsh`, `fish`, `powershell`, `nushell`, or `elvish`. |
| `docs [format]` | Emit CLI reference as `markdown`, `man`, or `json` (default `markdown`). |
Expand All @@ -59,8 +49,8 @@ otherwise Lisp) and can be overridden with `--lang lisp|elisp|php|js|javascript`
| `--core <file>` | Load a core image before running. |
| `--dump-image <file>` | Dump an initialized image. |
| `--script` | Use script mode. |
| `--seed <N>` | Fuzzing seed. |
| `--lang <value>` | Select the source language. |
| `--format <value>` | `dep-graph` output format: `dot`, `json`, `mermaid`, or `topo`. |

The normal architecture default is `x86-64`; `--aot` selects the Wasm path and
defaults it to `wasm32`. Native compilation uses the selected native backend,
Expand Down Expand Up @@ -129,6 +119,5 @@ The accepted options are:
alias for `--debug-info`. `--help` and `-h` display the global or command help.

For the generated schema from the parser's registered command and flag set, run
`cl-cc docs markdown`. The `dep-graph` helper contains a separate `--format`
parser, but `--format` is not registered in `packages/cli/src/args.lisp`; it is
therefore not listed as a generally accepted CLI option here.
`cl-cc docs markdown`. The `--format` flag is registered globally and is used by
`dep-graph`.
2 changes: 1 addition & 1 deletion packages/cli/cl-cc-cli.asd
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
(:file "handlers-compile") ; compile handler
(:file "handlers-eval") ; eval handler
(:file "handlers-repl") ; REPL handler
(:file "handlers-advanced") ; check and advanced/stub handlers
(:file "handlers-advanced") ; check and implemented advanced handlers
(:file "dep-graph") ; FR-361: Dependency graph visualization
(:file "cli-spec"))) ; cl-cli app spec: completion/docs/version
3 changes: 1 addition & 2 deletions packages/cli/src/args.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
("--verbose" . :bool)
("--strict" . :bool)
("--strict-no-alloc" . :bool)
("--format" . :string)
("--pass-pipeline" . :string)
("--opt-bisect-limit" . :string)
("--debug-info" . :bool)
Expand Down Expand Up @@ -114,8 +115,6 @@
("--executable" . :bool)
("--toplevel" . :string)
("--compression" . :string)
;; fuzz: deterministic seed
("--seed" . :string)
;; FR-276: optimization level
("-O" . :string)
("--opt-level" . :string)
Expand Down
8 changes: 5 additions & 3 deletions packages/cli/src/cli-spec.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ reserved cl-cli key (:help / :version).")
("--no-stdlib" . "Disable lazy stdlib auto-require")
("--verbose" . "Show compilation details on stderr")
("--strict" . "Treat type warnings as errors (check only)")
("--strict-no-alloc" . "Treat no-allocation violations as compilation errors")
("--format" . "dep-graph output: dot | json | mermaid | topo")
("--tier" . "Compilation tier: 0 fast, 1 optimized")
("--timeout" . "Maximum execution time in seconds")
("--no-timeout" . "Disable the CLI timeout")
Expand Down Expand Up @@ -120,8 +122,8 @@ key->legacy-hash)."
here fall back to a generated one-liner.")

(defparameter *cli-file-commands*
'("run" "compile" "check" "doc" "doctest" "show-types" "objdump"
"macrostep" "reduce" "disasm" "inspect" "abi-dump")
'("run" "compile" "check" "doc" "show-types"
"disasm" "inspect" "abi-dump" "abi-check")
"Commands whose positional argument is a file path — flagged with a :file
completion hint so shells offer path completion.")

Expand Down Expand Up @@ -197,7 +199,7 @@ keyed by the canonical flag strings (only options actually supplied are set, so
(when command
(setf (parsed-args-command result) (cl-cli:command-name command))
(setf (parsed-args-positional result)
(copy-list (ignore-errors (cl-cli:positional-value inv :args)))))
(copy-list (or (cl-cli:positional-value inv :args) nil))))
(maphash (lambda (key legacy-keys)
(let ((source (cl-cli:option-value-source inv key)))
(when (and source (not (eq source :default)))
Expand Down
48 changes: 24 additions & 24 deletions packages/cli/src/dep-graph.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,9 @@
(dolist (sys-name (asdf:registered-systems))
(unless (gethash sys-name seen)
(setf (gethash sys-name seen) t)
(handler-case
(let ((sys (asdf:find-system sys-name nil)))
(when sys
(setf edges (nconc edges (%asdf-system-dependencies sys)))))
(error () nil))))
(let ((sys (asdf:find-system sys-name nil)))
(when sys
(setf edges (nconc edges (%asdf-system-dependencies sys)))))))
edges))

(defun %dep-node-name (name)
Expand All @@ -58,7 +56,7 @@ dependency becomes a node, and each dependency becomes a directed edge."
(to (%dep-node-name (cdr edge))))
(ensure-node from)
(ensure-node to)
(ignore-errors (cl-dataflow-kit:add-edge graph from to)))))
(cl-dataflow-kit:add-edge graph from to))))
graph))

(defun %dep-graph-json (graph)
Expand Down Expand Up @@ -105,18 +103,26 @@ OUTPUT-FORMAT is :dot, :json, :mermaid, or :topo."
;;; CLI entry point
;;; ─────────────────────────────────────────────────────────────────────────

(defun %parse-dep-graph-format (value)
"Parse and validate the --format value for dep-graph."
(let ((name (or value "dot")))
(cond
((string-equal name "dot") :dot)
((string-equal name "json") :json)
((string-equal name "mermaid") :mermaid)
((string-equal name "topo") :topo)
(t (error "Invalid dep-graph format ~S (expected dot, json, mermaid, or topo)"
name)))))

(defun %parse-dep-graph-args (args)
"Parse --format dot|json|mermaid|topo from ARGS. Returns a keyword."
(let ((format :dot))
(loop for arg in args
for next-arg = (nth (1+ (position arg args :test #'string=)) args)
when (string= arg "--format")
do (cond
((string-equal next-arg "json") (setf format :json))
((string-equal next-arg "mermaid") (setf format :mermaid))
((string-equal next-arg "topo") (setf format :topo))
((string-equal next-arg "dot") (setf format :dot))))
format))
"Parse --format from PARSED-ARGS or a legacy raw argument list."
(%parse-dep-graph-format
(if (typep args 'parsed-args)
(flag args "--format")
(let ((position (position "--format" args :test #'string=)))
(when position
(or (nth (1+ position) args)
(error "--format requires a value")))))))

(defun %handle-dep-graph (args)
"CLI handler for `cl-cc dep-graph [--format dot|json|mermaid|topo]`."
Expand All @@ -125,10 +131,4 @@ OUTPUT-FORMAT is :dot, :json, :mermaid, or :topo."
(progn
(format *error-output* "; FR-361: generating dependency graph (~A)...~%" format)
(dep-graph :output-format format))
(progn
(format *error-output* "ERROR: ASDF not available.~%")
(cond
((eq format :json)
(format t "{~% \"error\": \"ASDF not loaded\"~%}~%"))
(t
(format t "digraph { node [shape=box]; ERROR [label=\"ASDF not loaded\"]; }~%")))))))
(error "ASDF not available."))))
14 changes: 10 additions & 4 deletions packages/cli/src/flamegraph.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,17 @@
(incf (gethash stack samples 0) count)
samples)

(defun %parse-flamegraph-integer (text &key (radix 10))
"Parse a perf field, returning NIL only for a malformed field."
(handler-case
(parse-integer text :radix radix :junk-allowed nil)
(parse-error () nil)))

(defun %perf-map-line->sample (line samples)
"Add one sample from a perf-map line to SAMPLES when LINE is valid."
(let ((parts (uiop:split-string line :separator '(#\Space #\Tab))))
(when (>= (length parts) 3)
(let ((size (ignore-errors (parse-integer (second parts) :radix 16)))
(let ((size (%parse-flamegraph-integer (second parts) :radix 16))
(name (third parts)))
(when (and size name)
(%flamegraph-inc-sample samples (format nil "jit;~A" name) (max 1 size))))))
Expand All @@ -101,7 +107,7 @@
(parts (uiop:split-string trimmed :separator '(#\Space #\Tab)))
(last-part (car (last parts)))
(count (and (> (length parts) 1)
(ignore-errors (parse-integer last-part :junk-allowed nil))))
(%parse-flamegraph-integer last-part)))
(stack (if count
(subseq trimmed 0 (position-if (lambda (ch) (member ch '(#\Space #\Tab)))
trimmed :from-end t))
Expand All @@ -121,15 +127,15 @@
(loop for line = (read-line in nil nil)
while line
for parts = (uiop:split-string line :separator '(#\Space #\Tab))
do (if (and parts (ignore-errors (parse-integer (first parts) :radix 16)))
do (if (and parts (%parse-flamegraph-integer (first parts) :radix 16))
(%perf-map-line->sample line samples)
(%perf-script-line->sample line samples)))))
samples))

(defun %default-perf-map-path ()
(parse-namestring
(format nil "/tmp/perf-~D.map"
(or (ignore-errors
(or (progn
(require :sb-posix)
(let* ((pkg (find-package "SB-POSIX"))
(sym (and pkg (find-symbol "GETPID" pkg))))
Expand Down
Loading
Loading