"\t -VV Very verbose output\n"
"\t -VVV Very very verbose output (to be used by compiler developers)\n"
"\t--use-post-mvp-features Enables post MVP WASM features such as memory.copy and memory.fill\n"
+ "\t--doc <doc_file>"
"\n"
"Developer flags:\n"
"\t--print-function-mappings Prints a mapping from WASM function index to source location.\n"
.files = NULL,
.target_file = "out.wasm",
+
+ .documentation_file = NULL,
};
bh_arr_new(alloc, options.files, 2);
if (argc == 1) return options;
- if (!strcmp(argv[1], "help")) options.action = ONYX_COMPILE_ACTION_PRINT_HELP;
- // else if (!strcmp(argv[1], "doc")) {
- // options.action = ONYX_COMPILE_ACTION_DOCUMENT;
- // }
+ if (!strcmp(argv[1], "help")) options.action = ONYX_COMPILE_ACTION_PRINT_HELP;
else options.action = ONYX_COMPILE_ACTION_COMPILE;
- if (options.action == ONYX_COMPILE_ACTION_COMPILE) {
+ if (options.action != ONYX_COMPILE_ACTION_PRINT_HELP) {
fori(i, 1, argc) {
if (!strcmp(argv[i], "-o")) {
options.target_file = argv[++i];
options.runtime = Runtime_Wasi;
}
}
+ else if (!strcmp(argv[i], "--doc")) {
+ options.documentation_file = argv[++i];
+ }
#if defined(_BH_LINUX)
// NOTE: Fun output is only enabled for Linux because Windows command line
// is not ANSI compatible and for a silly feature, I don't want to learn
printf("\n");
}
+ if (context.options->documentation_file != NULL) {
+ OnyxDocumentation docs = onyx_docs_generate();
+ docs.format = Doc_Format_Human;
+ onyx_docs_emit(&docs, context.options->documentation_file);
+ }
+
return ONYX_COMPILER_PROGRESS_SUCCESS;
}
}
}
- strncat(buf, ")", 1023);
-
- if (func->type->Function.return_type != &basic_types[Basic_Kind_Void]) {
- strncat(buf, " -> ", 1023);
- strncat(buf, type_get_name(func->type->Function.return_type), 1023);
- }
+ strncat(buf, ") -> ", 1023);
+ strncat(buf, type_get_name(func->type->Function.return_type), 1023);
break;
}
bh_table_each_start(AstNode *, p->scope->symbols)
DocEntry de;
- de.pos = value->token->pos;
+ if (value->token) de.pos = value->token->pos;
de.def = node_to_doc_def(key, value, a);
de.sym = (char *) key;
de.additional = NULL;
bh_table_each_start(AstNode *, p->private_scope->symbols)
DocEntry de;
- de.pos = value->token->pos;
+ if (value->token) de.pos = value->token->pos;
de.def = node_to_doc_def(key, value, a);
de.sym = (char *) key;
de.additional = NULL;
return doc;
}
-static void onyx_docs_emit_human(OnyxDocumentation* doc) {
+static void onyx_docs_emit_human(OnyxDocumentation* doc, bh_file* file) {
// NOTE: Disabling fancy line printing until I can make it better
#if 0
bh_arr_each(DocPackage, dp, doc->package_docs) {
}
#else
bh_arr_each(DocPackage, dp, doc->package_docs) {
- bh_printf("Package '%s'\n", dp->name);
+ bh_fprintf(file, "Package '%s'\n", dp->name);
if (bh_arr_length(dp->public_entries) > 0) {
- bh_printf(" Public symbols\n");
+ bh_fprintf(file, " Public symbols\n");
bh_arr_each(DocEntry, de, dp->public_entries) {
- bh_printf(" %s\n", de->def);
+ bh_fprintf(file, " %s\n", de->def);
if (de->pos.filename != NULL)
- bh_printf(" at %s:%d,%d\n", de->pos.filename, de->pos.line, de->pos.column);
+ bh_fprintf(file, " at %s:%d,%d\n", de->pos.filename, de->pos.line, de->pos.column);
else
- bh_printf(" compiler built-in\n");
+ bh_fprintf(file, " compiler built-in\n");
- bh_printf(" \n");
+ bh_fprintf(file, " \n");
}
}
if (bh_arr_length(dp->private_entries) > 0) {
- bh_printf(" Private symbols\n");
+ bh_fprintf(file, " Private symbols\n");
bh_arr_each(DocEntry, de, dp->private_entries) {
- bh_printf(" %s\n", de->def);
+ bh_fprintf(file, " %s\n", de->def);
if (de->pos.filename != NULL)
- bh_printf(" at %s:%d,%d\n", de->pos.filename, de->pos.line, de->pos.column);
+ bh_fprintf(file, " at %s:%d,%d\n", de->pos.filename, de->pos.line, de->pos.column);
else
- bh_printf(" compiler built-in\n");
+ bh_fprintf(file, " compiler built-in\n");
- bh_printf(" \n");
+ bh_fprintf(file, " \n");
}
- bh_printf("\n");
+ bh_fprintf(file, "\n");
}
}
#endif
bh_file_close(&tags_file);
}
-static void onyx_docs_emit_html(OnyxDocumentation* doc) {
- bh_printf("HTML documentation output not supported yet.\n");
+static void onyx_docs_emit_html(OnyxDocumentation* doc, bh_file* file) {
+ bh_fprintf(file, "HTML documentation output not supported yet.\n");
return;
}
-void onyx_docs_emit(OnyxDocumentation* doc) {
+void onyx_docs_emit(OnyxDocumentation* doc, const char* filename) {
+ bh_file file;
+ if (bh_file_create(&file, filename) != BH_FILE_ERROR_NONE) {
+ bh_printf("ERROR: Failed to open file '%s' for writing documentation.\n", filename);
+ return;
+ }
+
switch (doc->format) {
- case Doc_Format_Human: onyx_docs_emit_human(doc); break;
+ case Doc_Format_Human: onyx_docs_emit_human(doc, &file); break;
+ case Doc_Format_Html: onyx_docs_emit_html(doc, &file); break;
case Doc_Format_Tags: onyx_docs_emit_tags(doc); break;
- case Doc_Format_Html: onyx_docs_emit_html(doc); break;
}
+
+ bh_file_close(&file);
}