|
@@ -4612,8 +4612,6 @@ char *escape(char *s) {
|
|
|
return buffer_read(buf);
|
|
|
}
|
|
|
|
|
|
-int NOSTD = 0;
|
|
|
-
|
|
|
char *compile(char *source, list_t *required) {
|
|
|
list_t *ctx = list_new();
|
|
|
table_t *ltab = table_new();
|
|
@@ -4627,9 +4625,6 @@ char *compile(char *source, list_t *required) {
|
|
|
|
|
|
compile_into("const __QIC = \"" QIC_VERSION "\"", gbuf, buf, ctx, ltab, lstk, sstk, lbl);
|
|
|
|
|
|
- if (!NOSTD)
|
|
|
- require_once(gbuf, buf, ctx, ltab, lstk, sstk, lbl, "std");
|
|
|
-
|
|
|
if (required && required->length)
|
|
|
for (size_t i = 0; i < required->length; i++)
|
|
|
if (require_once(gbuf, buf, ctx, ltab, lstk, sstk, lbl, required->data[i]) < 0) {
|
|
@@ -4721,6 +4716,7 @@ int main(int argc, char **argv) {
|
|
|
|
|
|
char *out;
|
|
|
char *main = NULL;
|
|
|
+ char *outf = NULL;
|
|
|
list_t *required = NULL;
|
|
|
int readstdin = 0;
|
|
|
|
|
@@ -4730,15 +4726,21 @@ int main(int argc, char **argv) {
|
|
|
DEBUG = 1;
|
|
|
else if (strcmp(argv[i], "-s") == 0 || strcmp(argv[i], "--stdin") == 0)
|
|
|
readstdin = 1;
|
|
|
- else if (strcmp(argv[i], "-N") == 0 || strcmp(argv[i], "--no-std") == 0)
|
|
|
- NOSTD = 1;
|
|
|
- else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "-?") == 0 || strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--version") == 0) {
|
|
|
+ else if (strcmp(argv[i], "-o") == 0 || strcmp(argv[i], "--output") == 0) {
|
|
|
+ if (i+1 >= argc) {
|
|
|
+ fprintf(stderr, "fatal: missing argument after '-o/--output' parameter\n");
|
|
|
+
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ outf = argv[++i];
|
|
|
+ } else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "-?") == 0 || strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--version") == 0) {
|
|
|
fprintf(stderr, "qilang compiler, " QIC_VERSION "\n");
|
|
|
- fprintf(stderr, "usage: %s [-dsh] [input0.qi input1.qi ... inputN.qi]\n", argv[0]);
|
|
|
+ fprintf(stderr, "usage: %s [-dsh] [-o out.c] [input0.qi input1.qi ... inputN.qi]\n", argv[0]);
|
|
|
fprintf(stderr, "-h --help\tprint this message and exit\n");
|
|
|
fprintf(stderr, "-d --debug\tenable debug mode\n");
|
|
|
fprintf(stderr, "-s --stdin\tread stdin as input\n");
|
|
|
- fprintf(stderr, "-N --no-std\tdont automatically require std\n");
|
|
|
+ fprintf(stderr, "-o --outout path\toutput generated C code to 'path'\n");
|
|
|
|
|
|
return 0;
|
|
|
} else {
|
|
@@ -4776,7 +4778,19 @@ int main(int argc, char **argv) {
|
|
|
fclose(fd);
|
|
|
}
|
|
|
|
|
|
- fwrite(out, sizeof(char), strlen(out), stdout);
|
|
|
+ if (outf) {
|
|
|
+ FILE *fd = fopen(outf, "wb");
|
|
|
+ if (!fd) {
|
|
|
+ fprintf(stderr, "fatal: unable to open output file: '%s'\n", outf);
|
|
|
+
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ fwrite(out, sizeof(char), strlen(out), fd);
|
|
|
+
|
|
|
+ fclose(fd);
|
|
|
+ } else
|
|
|
+ fwrite(out, sizeof(char), strlen(out), stdout);
|
|
|
|
|
|
return 0;
|
|
|
}
|