Skip to content

Commit

Permalink
Some means of enabling and disabling warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
RPGHacker committed May 10, 2018
1 parent a9e5169 commit 44899c6
Show file tree
Hide file tree
Showing 17 changed files with 403 additions and 23 deletions.
1 change: 1 addition & 0 deletions docs/changelog/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ <h3>New features:</h3>
<li>Opcode length specifiers (<code>.b</code>, <code>.w</code> and <code>.l</code>) are now also supported for the SPC700 architecture. (KungFuFurby)</li>
<li>Added <code class="65c816_asar">stringsequal()</code> and <code class="65c816_asar">stringsequalnocase()</code> functions. (RPG Hacker)</li>
<li>Added support for some built-in defines. Currently, <code class="65c816_asar">!assembler</code> and <code class="65c816_asar">!assembler_ver</code> are supported. Trying to modify those defines will throw an error. (RPG Hacker)</li>
<li>Added IDs to all warnings and errors, together with functionality to enable or disable specific warnings. (RPG Hacker)</li>
</ul>

<h3>Bug fixes:</h3>
Expand Down
56 changes: 56 additions & 0 deletions docs/manual/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,14 @@ <h1>Asar</h1>
<li><a href="#check-bankcross">check bankcross</a></li>
</ul>
</li>
<li>
<a href="#warnings">Warnings</a>
<ul>
<li><a href="#disabled-warnings">Disabled Warnings</a></li>
<li><a href="#warnings-push-pull">warnings {push/pull}</a></li>
<li><a href="#warnings-enable-disable">warnings {enable/disable}</a></li>
</ul>
</li>
</ul>
</div>
<hr />
Expand Down Expand Up @@ -258,6 +266,18 @@ <h1>Asar</h1>
--symbols-path=C:/homebrew/my_game/symbols/main.symbols
C:/homebrew/my_game/main.asm</code></pre></td>
</tr>
<tr>
<td><code class="powershell">-w{id}</code></td>
<td>Input</td>
<td>Enables the warning with the specified ID. See section <a href="#warnings">Warnings</a> for details.</td>
<td><pre><code class="powershell">asar.exe -wW1023 C:/homebrew/my_game/main.asm</code></pre></td>
</tr>
<tr>
<td><code class="powershell">-wno{id}</code></td>
<td>Input</td>
<td>Disables the warning with the specified ID. See section <a href="#warnings">Warnings</a> for details.</td>
<td><pre><code class="powershell">asar.exe -wnoW1013 C:/homebrew/my_game/main.asm</code></pre></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
Expand Down Expand Up @@ -3102,5 +3122,41 @@ <h4 id="check-bankcross">check bankcross</h4>

print pc ; Will print 818001 when using LoROM mapper</code></pre>
<a href="#contents">Return to top</a></div>
<hr />
<div id="warnings"><h3>Warnings</h3>
Warnings are messages that Asar outputs to inform the user about potentially unintended or risky code that isn't critical and thus doesn't cause assembly to fail on its own. These messages can be useful for detecting potential problems in the code, but in some situations may be undesirable. For this reason, Asar supports a few methods of explicitly enabling or disabling certain warnings (see section <a href="#usage">Usage</a> for details on how to configure warnings via the command line). Additionally, there are warnings which may be useful in some situations, but would be intrusive in most other situations. They are disabled by default and have to be enabled explicitly to be used. Commands that enable or disable warnings refer to them via their ID. This ID is in the format <code>WXXXX</code>, where <code>XXXX</code> is a number uniquely identifying a warning. The easiest way of finding the ID for a specific warning is to look at the console output of a patch producing it. Asar will always output the warning ID along with the respective warning.
<h4 id="disabled-warnings">Disabled Warnings</h4>
This is a list of all warnings that are disabled by default and have to be enabled explicitly.<br/><br/>
<table>
<tr>
<th style="width:150px">Warning ID</th>
<th>Details</th>
</tr>
<tr>
<td><code></code></td>
<td></td>
</tr>
</table>
<h4 id="warnings-push-pull">warnings {push/pull}</h4>
<pre><code class="65c816_asar">warnings {push/pull}</code></pre>
The <code class="65c816_asar">warnings push</code> command pushes the current state of enabled and disabled warnings to the stack. The <code class="65c816_asar">warnings pull</code> command pulls it back from the stack.
<pre><code class="65c816_asar">warnings push
; Disable "freespace leaked" warning
warnings disable W1011

freecode

; [...]

warnings pull</code></pre>
<h4 id="warnings-enable-disable">warnings {enable/disable}</h4>
<pre><code class="65c816_asar">warnings {enable/disable} {id}</code></pre>
The <code class="65c816_asar">warnings enable</code> command enables the warning with the specified ID, the <code class="65c816_asar">warnings disable</code> command disables it. Warnings enabled or disabled via this command override warnings enabled or disabled via the command line (see section <a href="#usage">Usage</a> for details). When using these commands inside shared code, it's recommended to do so in conjunction with <a href="#warnings-push-pull">warnings {push/pull}</a> to prevent the modified settings from leaking into other files.
<pre><code class="65c816_asar">warnings disable W1012

warn "This text in invisible!"

warn enable W1012</code></pre>
<a href="#contents">Return to top</a></div>
</body>
</html>
2 changes: 1 addition & 1 deletion docs/shared/highlight_js/highlight.pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ hljs.registerLanguage("powershell", function(e) {
// I know this is ugly, but I don't know how else to solve Asar's label rules...
var asar_opcodes = ["db", "dw", "dl", "dd", "adc", "and", "asl", "bcc", "blt", "bcs", "bge", "beq", "bit", "bmi", "bne", "bpl", "bra", "brk", "brl", "bvc", "bvs", "clc", "cld", "cli", "clv", "cmp", "cop", "cpx", "cpy", "dec", "dea", "dex", "dey", "eor", "inc", "ina", "inx", "iny", "jmp", "jml", "jsr", "jsl", "lda", "ldx", "ldy", "lsr", "mvn", "mvp", "nop", "ora", "pea", "pei", "per", "pha", "phb", "phd", "phk", "php", "phx", "phy", "pla", "plb", "pld", "plp", "plx", "ply", "rep", "rol", "ror", "rti", "rtl", "rts", "sbc", "sec", "sed", "sei", "sep", "sta", "stp", "stx", "sty", "stz", "tax", "tay", "tcd", "tcs", "tdc", "trb", "tsc", "tsb", "tsx", "txa", "txs", "txy", "tya", "tyx", "wai", "wdm", "xba", "xce", "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", "add", "alt1", "alt2", "alt3", "asr", "bic", "cache", "cmode", "color", "div2", "fmult", "from", "getb", "getbh", "getbl", "getbs", "getc", "hib", "ibt", "iwt", "ldb", "ldw", "link", "ljmp", "lm", "lms", "lmult", "lob", "loop", "merge", "mult", "not", "or", "plot", "ramb", "romb", "rpix", "sbk", "sex", "sm", "sms", "stb", "stop", "stw", "sub", "swap", "to", "umult", "with", "xor", "addw", "ya", "and1", "bbc0", "bbc1", "bbc2", "bbc3", "bbc4", "bbc5", "bbc6", "bbc7", "bbs0", "bbs1", "bbs2", "bbs3", "bbs4", "bbs5", "bbs6", "bbs7", "call", "cbne", "clr0", "clr1", "clr2", "clr3", "clr4", "clr5", "clr6", "clr7", "clrc", "clrp", "clrv", "cmpw", "daa", "das", "dbnz", "decw", "di", "div", "ei", "eor1", "incw", "mov", "sp", "mov1", "movw", "mul", "not1", "notc", "or1", "pcall", "pop", "push", "ret", "reti", "set0", "set1", "set2", "set3", "set4", "set5", "set6", "set7", "setc", "setp", "sleep", "subw", "tcall", "tclr", "tset", "xcn", "lea", "move", "moves", "moveb", "movew"];

var asar_keywords = ["lorom", "hirom", "exlorom", "exhirom", "sa1rom", "fullsa1rom", "sfxrom", "norom", "macro", "endmacro", "struct", "endstruct", "extends", "incbin", "incsrc", "fillbyte", "fillword", "filllong", "filldword", "fill", "padbyte", "pad", "padword", "padlong", "paddword", "table", "cleartable", "ltr", "rtl", "skip", "namespace", "import", "print", "org", "warnpc", "base", "on", "off", "reset", "freespaceuse", "pc", "bytes", "hex", "freespace", "freecode", "freedata", "ram", "noram", "align", "cleaned", "static", "autoclean", "autoclear", "prot", "pushpc", "pullpc", "pushbase", "pullbase", "function", "if", "else", "elseif", "endif", "while", "assert", "arch", "65816", "spc700", "spc700", "inline", "superfx", "math", "pri", "round", "warn", "xkas", "bankcross", "bank", "noassume", "auto", "asar", "includefrom", "includeonce", "include", "error", "warn", "skip", "double", "round", "pushtable", "pulltable", "undef", "check", "title", "nested"];
var asar_keywords = ["lorom", "hirom", "exlorom", "exhirom", "sa1rom", "fullsa1rom", "sfxrom", "norom", "macro", "endmacro", "struct", "endstruct", "extends", "incbin", "incsrc", "fillbyte", "fillword", "filllong", "filldword", "fill", "padbyte", "pad", "padword", "padlong", "paddword", "table", "cleartable", "ltr", "rtl", "skip", "namespace", "import", "print", "org", "warnpc", "base", "on", "off", "reset", "freespaceuse", "pc", "bytes", "hex", "freespace", "freecode", "freedata", "ram", "noram", "align", "cleaned", "static", "autoclean", "autoclear", "prot", "pushpc", "pullpc", "pushbase", "pullbase", "function", "if", "else", "elseif", "endif", "while", "assert", "arch", "65816", "spc700", "spc700", "inline", "superfx", "math", "pri", "round", "xkas", "bankcross", "bank", "noassume", "auto", "asar", "includefrom", "includeonce", "include", "error", "skip", "double", "round", "pushtable", "pulltable", "undef", "check", "title", "nested", "warnings", "push", "pull", "disable", "enable", "warn" ];

var asar_intrinsic_functions = ["read1", "read2", "read3", "read4", "canread1", "canread2", "canread4", "sqrt", "sin", "cos", "tan", "asin", "acos", "atan", "arcsin", "arccos", "arctan", "log", "log10", "log2", "_read1", "_read2", "_read3", "_read4", "_canread1", "_canread2", "_canread4", "_sqrt", "_sin", "_cos", "_tan", "_asin", "_acos", "_atan", "_arcsin", "_arccos", "_arctan", "_log", "_log10", "_log2", "readfile1", "_readfile1", "readfile2", "_readfile2", "readfile3", "_readfile3", "readfile4", "_readfile4", "canreadfile1", "_canreadfile1", "canreadfile2", "_canreadfile2", "canreadfile3", "_canreadfile3", "canreadfile4", "_canreadfile4", "canreadfile", "_canreadfile", "filesize", "_filesize", "getfilestatus", "_getfilestatus", "snestopc", "_snestopc", "pctosnes", "_pctosnes", "max", "_max", "min", "_min", "clamp", "_clamp", "safediv", "_safediv", "select", "_select", "not", "_not", "equal", "_equal", "notequal", "_notequal", "less", "_less", "lessequal", "_lessequal", "greater", "_greater", "greaterequal", "_greaterequal", "and", "_and", "or", "_or", "nand", "_nand", "nor", "_nor", "xor", "_xor", "defined", "_defined", "sizeof", "_sizeof", "objectsize", "_objectsize", "stringsequal", "_stringsequal", "stringsequalnocase", "_stringsequalnocase"];

Expand Down
2 changes: 1 addition & 1 deletion ext/notepad-plus-plus/syntax-highlighting.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<Keywords name="Folders in comment, close"></Keywords>
<Keywords name="Keywords1">! ?</Keywords>
<Keywords name="Keywords2">@</Keywords>
<Keywords name="Keywords3">lorom hirom exlorom exhirom sa1rom fullsa1rom sfxrom norom macro endmacro incbin incsrc fillbyte fillword filllong filldword fill pad padbyte padword padlong paddword table cleartable ltr rtl skip namespace import print org warnpc base on off reset bytes freespaceuse pc hex freespace freecode freedata ram noram align cleaned static autoclean autoclear prot pushpc pullpc pushbase pullbase function if else elseif endif assert arch 65816 spc700 spc700-inline superfx math pri round warn xkas bank noassume auto asar include includefrom includeonce error warn skip double round pushtable pulltable undef extends check title nested bankcross</Keywords>
<Keywords name="Keywords3">lorom hirom exlorom exhirom sa1rom fullsa1rom sfxrom norom macro endmacro incbin incsrc fillbyte fillword filllong filldword fill pad padbyte padword padlong paddword table cleartable ltr rtl skip namespace import print org warnpc base on off reset bytes freespaceuse pc hex freespace freecode freedata ram noram align cleaned static autoclean autoclear prot pushpc pullpc pushbase pullbase function if else elseif endif assert arch 65816 spc700 spc700-inline superfx math pri round warn xkas bank noassume auto asar include includefrom includeonce error warn skip double round pushtable pulltable undef extends check title nested bankcross warnings push pull disable enable</Keywords>
<Keywords name="Keywords4">db dw dl dd adc and asl bcc blt bcs bge beq bit bmi bne bpl bra brk brl bvc bvs clc cld cli clv cmp cop cpx cpy dec dea dex dey eor inc ina inx iny jmp jml jsr jsl lda ldx ldy lsr mvn mvp nop ora pea pei per pha phb phd phk php phx phy pla plb pld plp plx ply rep rol ror rti rtl rts sbc sec sed sei sep sta stp stx sty stz tax tay tcd tcs tdc trb tsc tsb tsx txa txs txy tya tyx wai wdm xba xce s x y b w l a r0 r1 r2 r3 r4 r5 r6 r7 r8 r9 r10 r11 r12 r13 r14 r15 add alt1 alt2 alt3 asr bic cache cmode color div2 fmult from getb getbh getbl getbs getc hib ibt iwt ldb ldw link ljmp lm lms lmult lob loop merge mult not or plot ramb romb rpix sbk sex sm sms stb stop stw sub swap to umult with xor addw ya and1 c bbc0 bbc1 bbc2 bbc3 bbc4 bbc5 bbc6 bbc7 bbs0 bbs1 bbs2 bbs3 bbs4 bbs5 bbs6 bbs7 call cbne clr0 clr1 clr2 clr3 clr4 clr5 clr6 clr7 clrc clrp clrv cmpw daa das dbnz decw di div ei eor1 incw mov sp mov1 movw mul not1 notc or1 pcall pop p push ret reti set0 set1 set2 set3 set4 set5 set6 set7 setc setp sleep subw tcall tclr tset xcn lea move moves moveb movew</Keywords>
<Keywords name="Keywords5">read1 read2 read3 read4 canread1 canread2 canread4 sqrt sin cos tan asin acos atan arcsin arccos arctan log log10 log2 _read1 _read2 _read3 _read4 _canread1 _canread2 _canread4 _sqrt _sin _cos _tan _asin _acos _atan _arcsin _arccos _arctan _log _log10 _log2 readfile1 _readfile1 readfile2 _readfile2 readfile3 _readfile3 readfile4 _readfile4 canreadfile1 _canreadfile1 canreadfile2 _canreadfile2 canreadfile3 _canreadfile3 canreadfile4 _canreadfile4 canreadfile _canreadfile snestopc _snestopc pctosnes _pctosnes max _max min _min clamp _clamp safediv _safediv select _select not _not equal _equal notequal _notequal less _less lessequal _lessequal greater _greater greaterequal _greaterequal and _and or _or nand _nand nor _nor xor _xor defined _defined filesize _filesize getfilestatus _getfilestatus sizeof _sizeof objectsize _objectsize stringsequal _stringsequal stringsequalnocase _stringsequalnocase</Keywords>
<Keywords name="Keywords6">%</Keywords>
Expand Down
11 changes: 11 additions & 0 deletions src/asar-dll-bindings/asardll.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ enum mappertype {
norom
};

struct warnsetting {
const char * warnid;
bool enabled;
};



struct patchparams
{
Expand Down Expand Up @@ -80,6 +86,11 @@ struct patchparams
// Path to a text file to parse standard defines from.
// Set to NULL to not use any standard defines.
const char* stddefinesfile;

// A list of warnings to enable or disable.
// Specify warnings in the format "WXXXX" where XXXX = warning ID.
const struct warnsetting * warning_settings;
int warning_setting_count;
};


Expand Down
3 changes: 3 additions & 0 deletions src/asar-tests/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,9 @@ int main(int argc, char * argv[])

asar_patch_params.additional_defines = libdefines;
asar_patch_params.additional_define_count = sizeof(libdefines) / sizeof(libdefines[0]);

asar_patch_params.warning_settings = nullptr;
asar_patch_params.warning_setting_count = 0;

for (int i = 0;i < numiter;i++)
{
Expand Down
45 changes: 45 additions & 0 deletions src/asar/assembleblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -676,13 +676,18 @@ void initstuff()
thisfilename = "";

includeonce.reset();

push_warnings(false);
}


//void nerf(const string& left, string& right){puts(S left+" = "+right);}

void finishpass()
{
verify_warnings();
pull_warnings(false);

//defines.traverse(nerf);
if (in_struct || in_sub_struct) asar_throw_error(pass, error_type_null, error_id_struct_without_endstruct);
else if (pushpcnum && pass == 0) asar_throw_error(pass, error_type_null, error_id_pushpc_without_pullpc);
Expand Down Expand Up @@ -1031,6 +1036,46 @@ void assembleblock(const char * block)
{
asar_throw_warning(2, warning_id_warn_command, (string(": ") + dequote(par)).str);
}
else if (is1("warnings"))
{
if (stricmp(word[1], "push") == 0)
{
push_warnings();
}
else if (stricmp(word[1], "pull") == 0)
{
pull_warnings();
}
}
else if (is2("warnings"))
{
if (stricmp(word[1], "enable") == 0)
{
asar_warning_id warnid = parse_warning_id_from_string(word[2]);

if (warnid != warning_id_end)
{
set_warning_enabled(warnid, true);
}
else
{
asar_throw_error(pass, error_type_null, error_id_invalid_warning_id, "warnings enable", (int)(warning_id_start + 1), (int)(warning_id_end - 1));
}
}
else if (stricmp(word[1], "disable") == 0)
{
asar_warning_id warnid = parse_warning_id_from_string(word[2]);

if (warnid != warning_id_end)
{
set_warning_enabled(warnid, false);
}
else
{
asar_throw_error(pass, error_type_null, error_id_invalid_warning_id, "warnings disable", (int)(warning_id_start + 1), (int)(warning_id_end - 1));
}
}
}
else if (is2("check"))
{
if (stricmp(word[1], "title") == 0)
Expand Down
7 changes: 7 additions & 0 deletions src/asar/errors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,11 @@ static asar_error_mapping asar_errors[] =

{ error_id_invalid_print_function_syntax, "Invalid print function syntax." },
{ error_id_unknown_variable, "Unknown variable." },

{ error_id_invalid_warning_id, "Invalid warning ID passed to %s. Expected format is WXXXX where %d <= XXXX <= %d." },

{ error_id_pushwarnings_without_pullwarnings, "warnings push without matching warnings pull." },
{ error_id_pullwarnings_without_pushwarnings, "warnings pull without matching warnings push." },
};

// RPG Hacker: Sanity check. This makes sure that the element count of asar_warnings
Expand All @@ -254,6 +259,8 @@ void(*shutupgcc4)(asar_error_id, int, const char*) = asar_error_template<errfata

void asar_throw_error(int whichpass, asar_error_type type, asar_error_id errid, ...)
{
assert(errid > error_id_start && errid < error_id_end);

const asar_error_mapping& error = asar_errors[errid - error_id_start - 1];

char error_buffer[1024];
Expand Down
5 changes: 5 additions & 0 deletions src/asar/errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,11 @@ enum asar_error_id : int
error_id_invalid_print_function_syntax,
error_id_unknown_variable,

error_id_invalid_warning_id,

error_id_pushwarnings_without_pullwarnings,
error_id_pullwarnings_without_pushwarnings,

error_id_end,
error_id_count = error_id_end - error_id_start - 1,
};
Expand Down
Loading

0 comments on commit 44899c6

Please sign in to comment.