Skip to content

Commit 65c23af

Browse files
committed
Cleaned up spin2cpp --optimize flag handling
1 parent de05b12 commit 65c23af

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

Changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ Version 6.6.2
22
- Added warning (-Warray-index) for constant array indices out of bounds
33
- Allow warnings and optimizations to be turned off with a `no-` prefix (so `warn(no-init-vars)` is like `warn(!init-vars)`).
44
- Added some peephole optimizations to remove unnecessary sign extension
5+
- Parse --optimize= flag (spin2cpp) in a slightly more flexible way
56
- Some internal changes to make recovering from missing xxd easier
67

78
Version 6.6.1

spin2cpp.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,8 @@ main(int argc, const char **argv)
180180
const char *outname = NULL;
181181
const char *listFile = NULL;
182182
int wantcse = -1;
183-
183+
bool optimize_set = false;
184+
184185
gl_max_errors = 1;
185186
gl_src_charset = CHARSET_UTF8;
186187
gl_run_charset = CHARSET_UTF8;
@@ -280,7 +281,9 @@ main(int argc, const char **argv)
280281
outputAsm = 1;
281282
gl_output = OUTPUT_ASM;
282283
argv++; --argc;
283-
gl_optimize_flags = (DEFAULT_ASM_OPTS & ~OPT_REMOVE_UNUSED_FUNCS);
284+
if (!optimize_set) {
285+
gl_optimize_flags = (DEFAULT_ASM_OPTS & ~OPT_REMOVE_UNUSED_FUNCS);
286+
}
284287
} else if (!strcmp(argv[0], "--list")) {
285288
gl_listing = 1;
286289
argv++; --argc;
@@ -314,13 +317,20 @@ main(int argc, const char **argv)
314317
gl_intstring = "intptr_t"; // for 64 bit targets
315318
argv++; --argc;
316319
} else if (!strncmp(argv[0], "--optimize", 5)) {
317-
/* for debug purpose only: override optimize flags with hex */
318-
argv++; --argc;
319-
if (argv[0] == NULL) {
320-
fprintf(stderr, "Error: expected another argument after --optimize\n");
321-
exit(2);
320+
/* for debug purpose only: override optimize flags */
321+
const char *optstring;
322+
if (!strncmp(argv[0], "--optimize=", 11)) {
323+
optstring = argv[0]+11;
324+
} else {
325+
argv++; --argc;
326+
if (argv[0] == NULL) {
327+
fprintf(stderr, "Error: expected another argument after --optimize\n");
328+
exit(2);
329+
}
330+
optstring = argv[0];
322331
}
323-
ParseOptimizeString(NULL, argv[0], &gl_optimize_flags);
332+
ParseOptimizeString(NULL, optstring, &gl_optimize_flags);
333+
optimize_set = true;
324334
argv++; --argc;
325335
} else if (!strncmp(argv[0], "--files", 7)) {
326336
outputFiles = 1;

0 commit comments

Comments
 (0)