summaryrefslogtreecommitdiff
path: root/gen/docs/main.c
diff options
context:
space:
mode:
authorallexanderbergmans <allexander.bergmans@student.elisa.be>2026-07-03 12:17:10 +0200
committerallexanderbergmans <allexander.bergmans@student.elisa.be>2026-07-03 12:17:10 +0200
commit887875959aa84af92291db334898aaa20956e632 (patch)
tree62f68d6e93cf444e5605a40c3e8ea7ec0bd89f49 /gen/docs/main.c
Diffstat (limited to 'gen/docs/main.c')
-rw-r--r--gen/docs/main.c83
1 files changed, 83 insertions, 0 deletions
diff --git a/gen/docs/main.c b/gen/docs/main.c
new file mode 100644
index 0000000..760253e
--- /dev/null
+++ b/gen/docs/main.c
@@ -0,0 +1,83 @@
+#include "parser.h"
+#include "generator.h"
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+static void print_usage(const char *prog) {
+ fprintf(stderr, "Usage: %s [options] <isa_defs_dir>\n\n", prog);
+ fprintf(stderr, "Options:\n");
+ fprintf(stderr, " -o <file> Output Markdown file (default: doc/spec/isa_reference.md)\n");
+ fprintf(stderr, " --html Also generate HTML output\n");
+ fprintf(stderr, " --help Show this help\n\n");
+ fprintf(stderr, "Generates professional ISA reference documentation from .isa definition files.\n");
+}
+
+int main(int argc, char **argv) {
+ const char *defs_dir = NULL;
+ const char *output = "doc/spec/isa_reference.md";
+ int gen_html_flag = 0;
+
+ for (int i = 1; i < argc; i++) {
+ if (strcmp(argv[i], "--help") == 0) {
+ print_usage(argv[0]);
+ return 0;
+ } else if (strcmp(argv[i], "-o") == 0 && i + 1 < argc) {
+ output = argv[++i];
+ } else if (strcmp(argv[i], "--html") == 0) {
+ gen_html_flag = 1;
+ } else if (argv[i][0] != '-') {
+ defs_dir = argv[i];
+ } else {
+ fprintf(stderr, "Unknown option: %s\n", argv[i]);
+ print_usage(argv[0]);
+ return 1;
+ }
+ }
+
+ if (!defs_dir) {
+ fprintf(stderr, "Error: no ISA definitions directory specified.\n\n");
+ print_usage(argv[0]);
+ return 1;
+ }
+
+ IsaDb db;
+ memset(&db, 0, sizeof(db));
+
+ printf("ISA Documentation Generator\n");
+ printf("Reading definitions from: %s\n", defs_dir);
+
+ if (isa_parse_dir(defs_dir, &db) != 0) {
+ fprintf(stderr, "Error: failed to parse ISA definitions.\n");
+ return 1;
+ }
+
+ printf("\nParsed:\n");
+ printf(" %d format(s)\n", db.num_formats);
+ printf(" %d register(s)\n", db.num_registers);
+ printf(" %d instruction(s)\n", db.num_instructions);
+ printf(" %d CSR(s)\n", db.num_csrs);
+
+ if (db.num_instructions == 0) {
+ fprintf(stderr, "Warning: no instructions loaded. Output will be sparse.\n");
+ }
+
+ if (gen_markdown(&db, output) != 0) {
+ fprintf(stderr, "Error: failed to generate Markdown.\n");
+ return 1;
+ }
+
+ if (gen_html_flag) {
+ char html_path[1024];
+ snprintf(html_path, sizeof(html_path), "%s.html", output);
+ const char *ext = strrchr(output, '.');
+ if (ext) {
+ size_t len = ext - output;
+ snprintf(html_path, sizeof(html_path), "%.*s.html", (int)len, output);
+ }
+ gen_html(&db, html_path);
+ }
+
+ printf("\nDone. Output: %s\n", output);
+ return 0;
+}