Skip to content

Commit

Permalink
dumpversion
Browse files Browse the repository at this point in the history
  • Loading branch information
tyfkda committed Mar 19, 2024
1 parent ce82cdf commit b4137d9
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/util/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,10 @@ bool is_file(const char *path) {
}

void show_version(const char *exe) {
printf("%s %s\n", exe, VERSION);
if (exe != NULL)
printf("%s %s\n", exe, VERSION);
else
printf("%s\n", VERSION);
}

void error(const char *fmt, ...) {
Expand Down
33 changes: 31 additions & 2 deletions src/wcc/wcc.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ static const char DEFAULT_IMPORT_MODULE_NAME[] = "env";

static Vector remove_on_exit;

static void usage(FILE *fp) {
fprintf(
fp,
"Usage: wcc [options] file...\n"
"Options:\n"
" -I <path> Add include path\n"
" -D <label[=value]> Define label\n"
" -o <filename> Set output filename (Default: a.wasm)\n"
" -c Output object file\n"
" --entry-point=<name> Specify entry point (Defulat: _start)\n"
" --stack-size=<size> Output object file (Default: 8192)\n"
);
}

static void remove_tmp_files(void) {
for (int i = 0; i < remove_on_exit.len; ++i) {
const char *fn = remove_on_exit.data[i];
Expand Down Expand Up @@ -194,7 +208,10 @@ typedef struct {

static void parse_options(int argc, char *argv[], Options *opts) {
enum {
OPT_VERBOSE = 256,
OPT_HELP = 128,
OPT_VERSION,
OPT_DUMP_VERSION,
OPT_VERBOSE,
OPT_ENTRY_POINT,
OPT_STACK_SIZE,
OPT_IMPORT_MODULE_NAME,
Expand Down Expand Up @@ -230,6 +247,9 @@ static void parse_options(int argc, char *argv[], Options *opts) {
{"-verbose", no_argument, OPT_VERBOSE},
{"-entry-point", required_argument, OPT_ENTRY_POINT},
{"-stack-size", required_argument, OPT_STACK_SIZE},
{"-help", no_argument, OPT_HELP},
{"-version", no_argument, OPT_VERSION},
{"dumpversion", no_argument, OPT_DUMP_VERSION},

// Suppress warnings
{"O", required_argument, OPT_OPTIMIZE},
Expand All @@ -253,6 +273,15 @@ static void parse_options(int argc, char *argv[], Options *opts) {

switch (opt) {
default: assert(false); break;
case OPT_HELP:
usage(stdout);
exit(0);
case OPT_VERSION:
show_version("wcc");
exit(0);
case OPT_DUMP_VERSION:
show_version(NULL);
exit(0);
case 'o':
opts->ofn = optarg;
break;
Expand Down Expand Up @@ -492,7 +521,7 @@ int main(int argc, char *argv[]) {

if (opts.sources->len == 0) {
fprintf(stderr, "No input files\n\n");
// usage(stderr);
usage(stderr);
return 1;
}

Expand Down
5 changes: 5 additions & 0 deletions src/xcc/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ static void parse_options(int argc, char *argv[], Options *opts) {
enum {
OPT_HELP = 128,
OPT_VERSION,
OPT_DUMP_VERSION,
OPT_NODEFAULTLIBS,
OPT_NOSTDLIB,
OPT_NOSTDINC,
Expand Down Expand Up @@ -318,6 +319,7 @@ static void parse_options(int argc, char *argv[], Options *opts) {
{"Xlinker", required_argument, OPT_LINKOPTION},
{"-help", no_argument, OPT_HELP},
{"-version", no_argument, OPT_VERSION},
{"dumpversion", no_argument, OPT_DUMP_VERSION},

// Suppress warnings
{"W", required_argument},
Expand Down Expand Up @@ -351,6 +353,9 @@ static void parse_options(int argc, char *argv[], Options *opts) {
case OPT_VERSION:
show_version("xcc");
exit(0);
case OPT_DUMP_VERSION:
show_version(NULL);
exit(0);
case 'I':
vec_push(opts->cpp_cmd, "-I");
vec_push(opts->cpp_cmd, optarg);
Expand Down

0 comments on commit b4137d9

Please sign in to comment.