-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
1,592 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,7 @@ libsrc/_wasm/libc.c | |
|
||
*.wasm | ||
/wcc | ||
/wcc-ld | ||
/cc.wasm | ||
/gen3cc.wasm | ||
/tests/*.wasm | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
#include "unistd.h" | ||
#include "../wasi.h" | ||
|
||
off_t lseek(int fd, off_t offset, int whence) { | ||
size_t size; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
#include "unistd.h" | ||
#include "errno.h" | ||
#include "string.h" | ||
#include "../wasi.h" | ||
|
||
extern int max_preopen_fd; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#include "../config.h" | ||
|
||
#include <assert.h> | ||
#include <stdbool.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> // atoi | ||
|
||
#include "../wcc/wasm.h" | ||
#include "../wcc/wasm_linker.h" | ||
#include "../wcc/wcc.h" | ||
#include "table.h" | ||
#include "util.h" | ||
|
||
static void init(void) { | ||
out_type = OutExecutable; | ||
functypes = new_vector(); | ||
tags = new_vector(); | ||
table_init(&indirect_function_table); | ||
} | ||
|
||
int main(int argc, char *argv[]) { | ||
const char *ofn = "a.wasm"; | ||
const char *entry_point = "_start"; | ||
uint32_t stack_size = DEFAULT_STACK_SIZE; | ||
|
||
init(); | ||
|
||
enum { | ||
OPT_VERBOSE = 256, | ||
OPT_ENTRY_POINT, | ||
OPT_STACK_SIZE, | ||
}; | ||
static const struct option options[] = { | ||
{"o", required_argument}, // Specify output filename | ||
{"-verbose", no_argument, OPT_VERBOSE}, | ||
{"-entry-point", required_argument, OPT_ENTRY_POINT}, | ||
{"-stack-size", required_argument, OPT_STACK_SIZE}, | ||
|
||
{NULL}, | ||
}; | ||
|
||
int opt; | ||
while ((opt = optparse(argc, argv, options)) != -1) { | ||
switch (opt) { | ||
default: assert(false); break; | ||
case 'o': | ||
ofn = optarg; | ||
break; | ||
case OPT_VERBOSE: | ||
verbose = true; | ||
break; | ||
case OPT_ENTRY_POINT: | ||
entry_point = optarg; | ||
break; | ||
case OPT_STACK_SIZE: | ||
{ | ||
int size = atoi(optarg); | ||
if (size <= 0) { | ||
error("stack-size must be positive"); | ||
} | ||
stack_size = size; | ||
} | ||
break; | ||
case '?': | ||
fprintf(stderr, "Warning: unknown option: %s\n", argv[optind - 1]); | ||
break; | ||
} | ||
} | ||
int iarg = optind; | ||
|
||
WasmLinker linker_body; | ||
WasmLinker *linker = &linker_body; | ||
linker_init(linker); | ||
|
||
bool result = true; | ||
for (int i = iarg; i < argc; ++i) { | ||
const char *src = argv[i]; | ||
if (!read_wasm_obj(linker, src)) { | ||
fprintf(stderr, "error: failed to read wasm object file: %s\n", src); | ||
result = false; | ||
break; | ||
} | ||
} | ||
if (!result) | ||
return 1; | ||
|
||
Vector *exports = new_vector(); | ||
if (*entry_point != '\0') | ||
vec_push(exports, alloc_name(entry_point, NULL, false)); | ||
|
||
if (!link_wasm_objs(linker, exports, stack_size) || | ||
!linker_emit_wasm(linker, ofn, exports)) | ||
return 1; | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.