Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
Signed-off-by: Shaw Summa <[email protected]>
  • Loading branch information
ShawSumma committed Feb 11, 2024
1 parent 2de95d6 commit 9acbc5c
Show file tree
Hide file tree
Showing 12 changed files with 90 additions and 316 deletions.
27 changes: 27 additions & 0 deletions main/minivm.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,33 @@ int main(int argc, char **argv) {
fprintf(stderr, "cannot use have as a number type: %s\n", arg);
return 1;
}
} else if (!strncmp(arg, "--target-", 9) || !strncmp(arg, "--target=", 9)) {
arg += 9;
#if defined(EMSCRIPTEN)
if (!strcmp(arg, "emcc")) {
config->target = VM_TARGET_TB_EMCC;
} else if (!strcmp(arg, "js")) {
config->target = VM_TARGET_TB_JS;
} else {
fprintf(stderr, "cannot target: %s\n", arg);
return 1;
}
#else
if (!strcmp(arg, "tb")) {
config->target = VM_TARGET_TB;
} else if (!strcmp(arg, "tb-cc")) {
config->target = VM_TARGET_TB_CC;
} else if (!strcmp(arg, "tb-tcc")) {
config->target = VM_TARGET_TB_TCC;
} else if (!strcmp(arg, "tb-gcc")) {
config->target = VM_TARGET_TB_GCC;
} else if (!strcmp(arg, "tb-clang")) {
config->target = VM_TARGET_TB_CLANG;
} else {
fprintf(stderr, "cannot target: %s\n", arg);
return 1;
}
#endif
} else if (!strncmp(arg, "--dump-", 7) || !strncmp(arg, "--dump=", 7)) {
arg += 7;
if (!strcmp(arg, "src")) {
Expand Down
2 changes: 2 additions & 0 deletions vendor/tb/include/tb.h
Original file line number Diff line number Diff line change
Expand Up @@ -1426,6 +1426,8 @@ TB_API void tb_pass_optimize(TB_Passes* p);
TB_API void tb_pass_print(TB_Passes* opt);
TB_API char *tb_pass_c_prelude(TB_Module *mod);
TB_API char *tb_pass_c_fmt(TB_Passes* opt);
TB_API char *tb_pass_js_prelude(TB_Module *mod);
TB_API char *tb_pass_js_fmt(TB_Passes* opt);
// print-dot: prints IR as DOT
TB_API void tb_pass_print_dot(TB_Passes* opt, TB_PrintCallback callback, void* user_data);

Expand Down
31 changes: 23 additions & 8 deletions vm/backend/tb.c
Original file line number Diff line number Diff line change
Expand Up @@ -1670,14 +1670,29 @@ void *vm_tb_rfunc_comp(vm_rblock_t *rblock) {
}
#endif
#if defined(EMSCRIPTEN)
const char *cs[] = {
tb_pass_c_prelude(state->module),
tb_pass_c_fmt(passes),
NULL
};
void *code = vm_cache_comp("emcc", cs, name);
rblock->code = code;
return code;
if (state->config->target == VM_TARGET_TB_EMCC) {
const char *cs[] = {
tb_pass_c_prelude(state->module),
tb_pass_c_fmt(passes),
NULL,
};
void *code = vm_cache_comp("emcc", cs, name);
rblock->code = code;
return code;
} else if (state->config->target == VM_TARGET_TB_JS) {
const char *js1 = tb_pass_js_prelude(state->module);
const char *js2 = tb_pass_js_fmt(passes);
size_t len1 = strlen(js1);
size_t len2 = strlen(js2);
char *buf = vm_malloc(len1 + len2 + 1);
memcpy(buf, js1, len1);
memcpy(buf + len1, js2, len2);
buf[len1 + len2] = '\0';
rblock->code = buf;
return buf;
} else {
__builtin_trap();
}
#else
if (state->config->target == VM_TARGET_TB_TCC) {
const char *c_header = tb_pass_c_prelude(state->module);
Expand Down
1 change: 1 addition & 0 deletions vm/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ enum {
enum {
#if defined(EMSCRIPTEN)
VM_TARGET_TB_EMCC,
VM_TARGET_TB_JS,
#else
VM_TARGET_TB,
VM_TARGET_TB_CC,
Expand Down
16 changes: 0 additions & 16 deletions web/clang.py

This file was deleted.

8 changes: 7 additions & 1 deletion web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@
"babel-loader": "^9.1.3",
"compression-webpack-plugin": "^11.0.0",
"copy-webpack-plugin": "^12.0.2",
"css-loader": "^6.10.0",
"emception": "^1.0.11",
"mini-css-extract-plugin": "^2.8.0",
"svelte": "^4.2.10",
"svelte-loader": "^3.1.9",
"webpack": "^5.90.1",
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^4.15.1",
"webpack-node": "^0.0.0",
"worker-loader": "^3.0.8"
"worker-loader": "^3.0.8",
"xterm": "^5.3.0",
"xterm-addon-fit": "^0.8.0"
},
"type": "module"
}
168 changes: 0 additions & 168 deletions web/src/emception.js

This file was deleted.

81 changes: 0 additions & 81 deletions web/src/example.js

This file was deleted.

1 change: 1 addition & 0 deletions web/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<meta charset="utf-8">
<title>MiniVM</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="stylesheet" href="main.css">
</head>

<body>
Expand Down
Loading

0 comments on commit 9acbc5c

Please sign in to comment.