stage2 提供近乎完整的功能但出现严重性能问题 添加stage0的原生性能记录 stage1添加更多内置函数 nob重构代码使其更加健壮

This commit is contained in:
zzy committed 2026-09-19 18:08:43 +08:00
1 parent b5a7a811b3
commit e02b0c633a
35 files changed
+14018 -216

No files matched your search

+32
View File
@@ -30,6 +30,9 @@ typedef struct {
int debug_cli;
int trace;
int disasm;
int profile;
int profile_interval;
const char *profile_out;
const char *entry;
const char *path; /* file.sir */
const char **args; /* spl 程序参数(file.sir 之后) */
@@ -43,6 +46,8 @@ static void usage(void) {
" --disasm disasm dump sir\n"
" --entry <name> entry function (default: main)\n"
" --trace print every instruction\n"
" --profile[=N] native sampling profiler (every N insns, default 10000)\n"
" --profile-out <p> profile output prefix (default build/profile)\n"
" -h, --help show help\n");
}
@@ -67,6 +72,17 @@ static int parse_args(int argc, const char **argv, cli_opts_t *o) {
o->trace = 1;
} else if (strcmp(a, "--disasm") == 0) {
o->disasm = 1;
} else if (strcmp(a, "--profile") == 0) {
o->profile = 1;
} else if (strncmp(a, "--profile=", 10) == 0) {
o->profile = 1;
o->profile_interval = (int)strtol(a + 10, NULL, 10);
} else if (strcmp(a, "--profile-out") == 0) {
if (i + 1 >= argc) {
fprintf(stderr, "spl_cli: --profile-out needs a prefix\n");
return -1;
}
o->profile_out = argv[++i];
} else if (strcmp(a, "--entry") == 0) {
if (i + 1 >= argc) {
fprintf(stderr, "spl_cli: --entry needs a name\n");
@@ -651,6 +667,11 @@ int main(int argc, const char **argv) {
spl_prog_drop(&prog);
return 1;
}
if (o.profile) {
usize interval = o.profile_interval > 0 ? (usize)o.profile_interval : 10000;
spl_vm_profile_enable(&vm, interval);
fprintf(stderr, "spl_cli: profile mode on (interval=%zu)\n", interval);
}
/* spl 程序 argv:argv[0]=file.sir(程序名),argv[1..]=args */
const char **spl_argv = (const char **)malloc(sizeof(char *) * (size_t)(o.nargs + 1));
@@ -689,6 +710,17 @@ int main(int argc, const char **argv) {
fprintf(stderr, "spl_cli: hit breakpoint (run with -g to debug)\n");
}
if (o.profile) {
const char *prefix = o.profile_out ? o.profile_out : "build/profile";
char folded[1024];
char table[1024];
snprintf(folded, sizeof folded, "%s.folded", prefix);
snprintf(table, sizeof table, "%s.table", prefix);
spl_vm_profile_dump_folded(&vm, folded);
spl_vm_profile_dump_table(&vm, table);
fprintf(stderr, "spl_cli: profile written to %s / %s\n", folded, table);
}
free(spl_argv);
spl_vm_drop(&vm);
spl_prog_drop(&prog);