| Line |
Branch |
Exec |
Source |
| 1 |
|
|
#if (defined(__sun__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__)) && !defined(linux) |
| 2 |
|
|
#error Please use -Dlinux on non-Linux Unix-likes. |
| 3 |
|
|
#endif |
| 4 |
|
|
|
| 5 |
|
|
#if defined(linux) && !defined(stricmp) |
| 6 |
|
|
#error Please use -Dstricmp=strcasecmp on Unix-like systems. |
| 7 |
|
|
#endif |
| 8 |
|
|
|
| 9 |
|
|
#pragma once |
| 10 |
|
|
#define Asar |
| 11 |
|
|
|
| 12 |
|
|
#include "assocarr.h" |
| 13 |
|
|
#include "libstr.h" |
| 14 |
|
|
#include "libsmw.h" |
| 15 |
|
|
#include "errors.h" |
| 16 |
|
|
#include "warnings.h" |
| 17 |
|
|
#include "virtualfile.h" |
| 18 |
|
|
#include "assembleblock.h" // for snes_label - TODO do we want this here??? |
| 19 |
|
|
#include <cstdint> |
| 20 |
|
|
#include <vector> |
| 21 |
|
|
|
| 22 |
|
|
extern unsigned const char * romdata_r; |
| 23 |
|
|
extern int romlen_r; |
| 24 |
|
|
|
| 25 |
|
10697 |
inline void verify_paren(autoptr<char **> &ptr) |
| 26 |
|
|
{ |
| 27 |
2/3
✗ Branch 0 not taken.
✓ Branch 1 taken 5309 times.
✓ Branch 2 taken 5388 times.
|
10697 |
if(!ptr) throw_err_block(0, err_mismatched_parentheses); |
| 28 |
|
10697 |
} |
| 29 |
|
|
|
| 30 |
|
|
bool is_hex_constant(const char * str); |
| 31 |
|
|
int getlenforlabel(snes_label thislabel, bool exists); |
| 32 |
|
|
int getlenforlabel(int labelpos, int labelfreespace, bool exists); |
| 33 |
|
|
|
| 34 |
|
|
bool validatedefinename(const char * name); |
| 35 |
|
|
|
| 36 |
|
|
string create_symbols_file(string format, uint32_t romCrc); |
| 37 |
|
|
|
| 38 |
|
|
void parse_std_includes(const char* textfile, autoarray<string>& outarray); |
| 39 |
|
|
void parse_std_defines(const char* textfile); |
| 40 |
|
|
|
| 41 |
|
|
void reseteverything(); |
| 42 |
|
|
|
| 43 |
|
|
void resolvedefines(string& out, const char * start); |
| 44 |
|
|
|
| 45 |
|
|
int get_version_int(); |
| 46 |
|
|
|
| 47 |
|
|
bool setmapper(); |
| 48 |
|
|
|
| 49 |
|
|
void assemblefile(const char * filename); |
| 50 |
|
|
void assembleline(const char * fname, int linenum, const string& line, int& single_line_for_tracker); |
| 51 |
|
|
|
| 52 |
|
|
bool do_line_logic(const string& line, const char* filename, int lineno); |
| 53 |
|
|
|
| 54 |
|
|
bool file_included_once(const char* file); |
| 55 |
|
|
|
| 56 |
|
|
void get_current_line_details(string* location, string* details, bool exclude_block=false); |
| 57 |
|
|
string get_callstack(); |
| 58 |
|
|
|
| 59 |
|
|
void throw_vfile_error(int whichpass, virtual_file_error vfile_error, const char* filename); |
| 60 |
|
|
|
| 61 |
|
|
virtual_file_error asar_get_last_io_error(); |
| 62 |
|
|
|
| 63 |
|
|
extern int recursioncount; |
| 64 |
|
|
extern int pass; |
| 65 |
|
|
|
| 66 |
|
|
void init_stack_use_check(); |
| 67 |
|
|
void deinit_stack_use_check(); |
| 68 |
|
|
bool have_enough_stack_left(); |
| 69 |
|
|
|
| 70 |
|
|
class recurseblock { |
| 71 |
|
|
public: |
| 72 |
|
144965 |
recurseblock() |
| 73 |
|
|
{ |
| 74 |
|
144965 |
recursioncount++; |
| 75 |
|
|
#if !defined(_WIN32) && defined(NO_USE_THREADS) |
| 76 |
|
|
if(recursioncount > 500) |
| 77 |
|
|
#else |
| 78 |
5/6
✓ Branch 0 taken 144965 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 144963 times.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 144963 times.
|
144965 |
if(!have_enough_stack_left() || recursioncount > 5000) |
| 79 |
|
|
#endif |
| 80 |
|
2 |
throw_err_fatal(pass, err_recursion_limit); |
| 81 |
|
144963 |
} |
| 82 |
|
144963 |
~recurseblock() |
| 83 |
|
|
{ |
| 84 |
|
144963 |
recursioncount--; |
| 85 |
|
144963 |
} |
| 86 |
|
|
}; |
| 87 |
|
|
|
| 88 |
|
|
extern const int asarver_maj; |
| 89 |
|
|
extern const int asarver_min; |
| 90 |
|
|
extern const int asarver_bug; |
| 91 |
|
|
extern const bool asarver_beta; |
| 92 |
|
|
|
| 93 |
|
|
extern bool asarverallowed; |
| 94 |
|
|
|
| 95 |
|
|
extern bool moreonline; |
| 96 |
|
|
|
| 97 |
|
|
extern bool checksum_fix_enabled; |
| 98 |
|
|
extern bool force_checksum_fix; |
| 99 |
|
|
|
| 100 |
|
|
extern int incsrcdepth; |
| 101 |
|
|
|
| 102 |
|
|
extern bool ignoretitleerrors; |
| 103 |
|
|
|
| 104 |
|
|
extern int optimizeforbank; |
| 105 |
|
|
|
| 106 |
|
|
extern int in_macro_def; |
| 107 |
|
|
|
| 108 |
|
|
//this is a trick to namespace an enum to avoid name collision without too much verbosity |
| 109 |
|
|
//could technically name the enum too but this is fine for now. |
| 110 |
|
|
namespace optimize_dp_flag { |
| 111 |
|
|
enum : int { |
| 112 |
|
|
NONE, //don't optimize |
| 113 |
|
|
RAM, //bank 7E only (always uses dp base) |
| 114 |
|
|
ALWAYS //bank 00-3F[|80] and 7E (always uses dp base) |
| 115 |
|
|
}; |
| 116 |
|
|
} |
| 117 |
|
|
|
| 118 |
|
|
extern int optimize_dp; |
| 119 |
|
|
extern int dp_base; |
| 120 |
|
|
|
| 121 |
|
|
namespace optimize_address_flag { |
| 122 |
|
|
enum : int { |
| 123 |
|
|
DEFAULT,//simply use optimizeforbank |
| 124 |
|
|
RAM, //default+bank 7E only RAM address < $2000 |
| 125 |
|
|
MIRRORS //ram+if optimizeforbank is 00-3F[|80] and address < $8000 |
| 126 |
|
|
}; |
| 127 |
|
|
} |
| 128 |
|
|
|
| 129 |
|
|
extern int optimize_address; |
| 130 |
|
|
|
| 131 |
|
|
extern bool errored; |
| 132 |
|
|
|
| 133 |
|
|
extern assocarr<string> clidefines; |
| 134 |
|
|
|
| 135 |
|
|
extern virtual_filesystem* filesystem; |
| 136 |
|
|
|
| 137 |
|
|
extern assocarr<string> defines; |
| 138 |
|
|
|
| 139 |
|
|
extern assocarr<string> builtindefines; |
| 140 |
|
|
|
| 141 |
|
|
|
| 142 |
|
|
enum class callstack_entry_type : int { |
| 143 |
|
|
FILE, |
| 144 |
|
|
MACRO_CALL, |
| 145 |
|
|
LINE, |
| 146 |
|
|
BLOCK, |
| 147 |
|
|
}; |
| 148 |
|
|
|
| 149 |
|
|
struct callstack_entry { |
| 150 |
|
|
callstack_entry_type type; |
| 151 |
|
|
const char* content; |
| 152 |
|
|
int lineno; |
| 153 |
|
|
|
| 154 |
|
189925 |
callstack_entry(callstack_entry_type type, const char* content, int lineno) |
| 155 |
|
189925 |
: type(type), content(content), lineno(lineno) |
| 156 |
|
189925 |
{} |
| 157 |
|
|
}; |
| 158 |
|
|
|
| 159 |
|
|
|
| 160 |
|
|
struct printable_callstack_entry { |
| 161 |
|
|
string fullpath; |
| 162 |
|
|
string prettypath; |
| 163 |
|
|
int lineno; |
| 164 |
|
|
string details; |
| 165 |
|
|
}; |
| 166 |
|
|
|
| 167 |
|
|
|
| 168 |
|
|
extern std::vector<callstack_entry> callstack; |
| 169 |
|
|
extern bool simple_callstacks; |
| 170 |
|
|
|
| 171 |
|
|
class callstack_push { |
| 172 |
|
|
public: |
| 173 |
|
|
// the `content` here MUST outlive the callstack_push object, and must not be mutated after passing it to callstack_push. |
| 174 |
|
189925 |
callstack_push(callstack_entry_type type, const char* content, int lineno=-1) |
| 175 |
|
|
{ |
| 176 |
2/4
✓ Branch 0 taken 94441 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 95484 times.
✗ Branch 3 not taken.
|
189925 |
callstack.emplace_back(callstack_entry(type, content, lineno)); |
| 177 |
|
189925 |
} |
| 178 |
|
|
|
| 179 |
|
189925 |
~callstack_push() |
| 180 |
|
|
{ |
| 181 |
|
189925 |
callstack.pop_back(); |
| 182 |
|
189925 |
} |
| 183 |
|
|
}; |
| 184 |
|
|
|
| 185 |
|
|
bool in_top_level_file(); |
| 186 |
|
|
const char* get_current_file_name(); |
| 187 |
|
|
int get_current_line(); |
| 188 |
|
|
const char* get_current_block(); |
| 189 |
|
|
|
| 190 |
|
|
void get_full_printable_callstack(autoarray<printable_callstack_entry>* out, int indentation, bool add_lines); |
| 191 |
|
|
|
| 192 |
|
|
#if !defined(NO_USE_THREADS) && !defined(RUN_VIA_THREAD) |
| 193 |
|
|
// RPG Hacker: This is currently disabled for debug builds, because it causes random crashes |
| 194 |
|
|
// when used in combination with -fsanitize=address. |
| 195 |
|
|
# if defined(_WIN32) && defined(NDEBUG) |
| 196 |
|
|
# define RUN_VIA_FIBER |
| 197 |
|
|
# else |
| 198 |
|
|
# define RUN_VIA_THREAD |
| 199 |
|
|
# endif |
| 200 |
|
|
#endif |
| 201 |
|
|
|