shithub: rgbds

Download patch

ref: e9bfe849adfee7d9b7ef2dfef9f1896bda8a5a9b
parent: 665eb916a204fa559a30648a08272c84a562c41c
author: Rangi <[email protected]>
date: Sat May 1 19:04:57 EDT 2021

Allow `OPT` to toggle `-h`

--- a/src/asm/opt.c
+++ b/src/asm/opt.c
@@ -14,6 +14,7 @@
 	char binary[2];
 	char gbgfx[4];
 	int32_t fillByte;
+	bool haltnop;
 	bool optimizeLoads;
 	bool warningsAreErrors;
 	enum WarningState warningStates[NB_WARNINGS];
@@ -37,6 +38,11 @@
 	fillByte = fill;
 }
 
+void opt_h(bool halt)
+{
+	haltnop = halt;
+}
+
 void opt_L(bool optimize)
 {
 	optimizeLoads = optimize;
@@ -79,6 +85,13 @@
 		}
 		break;
 
+	case 'h':
+		if (s[1] == '\0')
+			opt_h(false);
+		else
+			error("Option 'h' does not take an argument\n");
+		break;
+
 	case 'L':
 		if (s[1] == '\0')
 			opt_L(false);
@@ -95,6 +108,13 @@
 
 	case '!': // negates flag options that do not take an argument
 		switch (s[1]) {
+		case 'h':
+			if (s[2] == '\0')
+				opt_h(true);
+			else
+				error("Option '!h' does not take an argument\n");
+			break;
+
 		case 'L':
 			if (s[2] == '\0')
 				opt_L(true);
@@ -132,6 +152,8 @@
 
 	entry->fillByte = fillByte; // Pulled from section.h
 
+	entry->haltnop = haltnop; // Pulled from main.h
+
 	entry->optimizeLoads = optimizeLoads; // Pulled from main.h
 
 	// Both of these pulled from warning.h
@@ -154,6 +176,7 @@
 	opt_B(entry->binary);
 	opt_G(entry->gbgfx);
 	opt_P(entry->fillByte);
+	opt_h(entry->haltnop);
 	opt_L(entry->optimizeLoads);
 
 	// opt_W does not apply a whole warning state; it processes one flag string
--- a/src/asm/rgbasm.5
+++ b/src/asm/rgbasm.5
@@ -1957,15 +1957,18 @@
 .Ed
 .Pp
 The options that OPT can modify are currently:
-.Cm b , g , p , L ,
+.Cm b , g , p , h , L ,
 and
 .Cm W .
-The Boolean flag option
+The Boolean flag options
+.Cm h
+and
 .Cm L
-can be specified as
-.Ql OPT L
-or
-.Ql OPT !L .
+can be negated as
+.Ql OPT !h
+and
+.Ql OPT !L
+to act like omitting them from the command-line.
 .Pp
 .Ic POPO
 and
--- a/test/asm/opt.asm
+++ b/test/asm/opt.asm
@@ -1,14 +1,16 @@
 SECTION "test", ROM0
 
-	opt !L ; already the default, but tests parsing "!L"
+	opt !h, !L ; already the default, but tests parsing "!"
 
 pusho
-	opt p42, L, Wno-div
+	opt p42, h, L, Wno-div
 	ds 1
 	ld [$ff88], a
+	halt
 	println $8000_0000 / -1
 popo
 
 	ds 1
 	ld [$ff88], a
+	halt
 	println $8000_0000 / -1
--- a/test/asm/opt.err
+++ b/test/asm/opt.err
@@ -1,2 +1,2 @@
-warning: opt.asm(14): [-Wdiv]
+warning: opt.asm(16): [-Wdiv]
     Division of -2147483648 by -1 yields -2147483648
binary files a/test/asm/opt.out.bin b/test/asm/opt.out.bin differ