Skip to content

Commit

Permalink
Merge branch 'feature/wasm-obj'
Browse files Browse the repository at this point in the history
  • Loading branch information
tyfkda committed Feb 5, 2024
2 parents dffe95b + e8fa8fe commit 237de8e
Show file tree
Hide file tree
Showing 11 changed files with 893 additions and 148 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ Command line options:
* `-o <filename>`: Set output filename (default: `a.wasm`)
* `-I <path>`: Add include path
* `-D <label>(=value)`: Define macro
* `-c`: Output object file
* `--entry-point=func_name`: Specify entry point (default: `_start`)
* `-e func_name,...`: Export function names (comma separated)
* `--stack-size=<size>`: Set stack size (default: 8192)
Expand Down
2 changes: 2 additions & 0 deletions src/cc/frontend/cc_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ void construct_initial_value(const Type *type, const Initializer *init,
if (init->kind == IK_SINGLE) {
Expr *e = strip_cast(init->single);
if (e->kind == EX_STR && is_char_type(type->pa.ptrof, e->str.kind)) {
assert(vtable->emit_string != NULL);
(*vtable->emit_string)(ud, e, type_size(type));
break;
}
Expand Down Expand Up @@ -198,6 +199,7 @@ void construct_initial_value(const Type *type, const Initializer *init,
if (mem_init != NULL || !sinfo->is_union) {
int align = align_size(member->type);
if (offset % align != 0) {
assert(vtable->emit_align != NULL);
(*vtable->emit_align)(ud, align);
offset = ALIGN(offset, align);
}
Expand Down
13 changes: 12 additions & 1 deletion src/cc/frontend/fe_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1408,6 +1408,17 @@ static void check_func_return(Function *func) {
Type *type = func->type;
Type *rettype = type->func.ret;
const Token *rbrace = func->body_block->block.rbrace;

static const Name *main_name;
if (main_name == NULL)
main_name = alloc_name("main", NULL, false);
if (equal_name(func->name, main_name)) {
if (rettype->kind == TY_VOID) {
// Force return type to `int' for `main' function.
type->func.ret = rettype = &tyInt;
}
}

if (func->flag & FUNCF_NORETURN) {
if (rettype->kind != TY_VOID) {
parse_error(PE_WARNING, rbrace, "`noreturn' function should not return value");
Expand All @@ -1420,7 +1431,7 @@ static void check_func_return(Function *func) {
} else if (rettype->kind != TY_VOID && !(func->body_block->reach & REACH_STOP)) {
Vector *stmts = func->body_block->block.stmts;
if (stmts->len == 0 || ((Stmt*)stmts->data[stmts->len - 1])->kind != ST_ASM) {
if (equal_name(func->name, alloc_name("main", NULL, false))) {
if (equal_name(func->name, main_name)) {
// Return 0 if `return` statement is omitted in `main` function.
if (!is_fixnum(rettype->kind) || rettype->fixnum.kind != FX_INT) {
parse_error(PE_WARNING, rbrace, "`main' return type should be `int'");
Expand Down
Loading

0 comments on commit 237de8e

Please sign in to comment.