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 |
|
|
|
21 |
|
|
extern unsigned const char * romdata_r; |
22 |
|
|
extern int romlen_r; |
23 |
|
|
|
24 |
|
11018 |
inline void verify_paren(autoptr<char **> &ptr) |
25 |
|
|
{ |
26 |
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11018 times.
|
11018 |
if(!ptr) asar_throw_error(0, error_type_block, error_id_mismatched_parentheses); |
27 |
|
11018 |
} |
28 |
|
|
|
29 |
|
|
int getlen(const char * str, bool optimizebankextraction=false); |
30 |
|
|
bool is_hex_constant(const char * str); |
31 |
|
|
int getlenforlabel(snes_label thislabel, bool exists); |
32 |
|
|
|
33 |
|
|
bool validatedefinename(const char * name); |
34 |
|
|
|
35 |
|
|
string create_symbols_file(string format, uint32_t romCrc); |
36 |
|
|
|
37 |
|
|
void parse_std_includes(const char* textfile, autoarray<string>& outarray); |
38 |
|
|
void parse_std_defines(const char* textfile); |
39 |
|
|
|
40 |
|
|
void reseteverything(); |
41 |
|
|
|
42 |
|
|
void resolvedefines(string& out, const char * start); |
43 |
|
|
|
44 |
|
|
int get_version_int(); |
45 |
|
|
|
46 |
|
|
bool setmapper(); |
47 |
|
|
|
48 |
|
|
void assemblefile(const char * filename); |
49 |
|
|
void assembleline(const char * fname, int linenum, const char * line, int& single_line_for_tracker); |
50 |
|
|
|
51 |
|
|
bool do_line_logic(const char* line, const char* filename, int lineno); |
52 |
|
|
|
53 |
|
|
bool file_included_once(const char* file); |
54 |
|
|
|
55 |
|
|
void get_current_line_details(string* location, string* details, bool exclude_block=false); |
56 |
|
|
string get_callstack(); |
57 |
|
|
|
58 |
|
|
asar_error_id vfile_error_to_error_id(virtual_file_error vfile_error); |
59 |
|
|
|
60 |
|
|
virtual_file_error asar_get_last_io_error(); |
61 |
|
|
|
62 |
|
|
extern int recursioncount; |
63 |
|
|
extern int pass; |
64 |
|
|
|
65 |
|
|
void init_stack_use_check(); |
66 |
|
|
void deinit_stack_use_check(); |
67 |
|
|
bool have_enough_stack_left(); |
68 |
|
|
|
69 |
|
|
class recurseblock { |
70 |
|
|
public: |
71 |
|
132634 |
recurseblock() |
72 |
|
|
{ |
73 |
|
132634 |
recursioncount++; |
74 |
|
|
#if !defined(_WIN32) && defined(NO_USE_THREADS) |
75 |
|
|
if(recursioncount > 500) |
76 |
|
|
#else |
77 |
5/6
✓ Branch 0 taken 132632 times.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 132632 times.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 132632 times.
|
132634 |
if(!have_enough_stack_left() || recursioncount > 5000) |
78 |
|
|
#endif |
79 |
|
2 |
asar_throw_error(pass, error_type_fatal, error_id_recursion_limit); |
80 |
|
132632 |
} |
81 |
|
132632 |
~recurseblock() |
82 |
|
|
{ |
83 |
|
132632 |
recursioncount--; |
84 |
|
132632 |
} |
85 |
|
|
}; |
86 |
|
|
|
87 |
|
|
extern const int asarver_maj; |
88 |
|
|
extern const int asarver_min; |
89 |
|
|
extern const int asarver_bug; |
90 |
|
|
extern const bool asarver_beta; |
91 |
|
|
|
92 |
|
|
extern bool asarverallowed; |
93 |
|
|
|
94 |
|
|
extern bool moreonline; |
95 |
|
|
|
96 |
|
|
extern bool checksum_fix_enabled; |
97 |
|
|
extern bool force_checksum_fix; |
98 |
|
|
|
99 |
|
|
extern int incsrcdepth; |
100 |
|
|
|
101 |
|
|
extern bool ignoretitleerrors; |
102 |
|
|
|
103 |
|
|
extern int optimizeforbank; |
104 |
|
|
|
105 |
|
|
extern int in_macro_def; |
106 |
|
|
|
107 |
|
|
//this is a trick to namespace an enum to avoid name collision without too much verbosity |
108 |
|
|
//could technically name the enum too but this is fine for now. |
109 |
|
|
namespace optimize_dp_flag { |
110 |
|
|
enum : int { |
111 |
|
|
NONE, //don't optimize |
112 |
|
|
RAM, //bank 7E only (always uses dp base) |
113 |
|
|
ALWAYS //bank 00-3F[|80] and 7E (always uses dp base) |
114 |
|
|
}; |
115 |
|
|
} |
116 |
|
|
|
117 |
|
|
extern int optimize_dp; |
118 |
|
|
extern int dp_base; |
119 |
|
|
|
120 |
|
|
namespace optimize_address_flag { |
121 |
|
|
enum : int { |
122 |
|
|
DEFAULT,//simply use optimizeforbank |
123 |
|
|
RAM, //default+bank 7E only RAM address < $2000 |
124 |
|
|
MIRRORS //ram+if optimizeforbank is 00-3F[|80] and address < $8000 |
125 |
|
|
}; |
126 |
|
|
} |
127 |
|
|
|
128 |
|
|
extern int optimize_address; |
129 |
|
|
|
130 |
|
|
extern bool errored; |
131 |
|
|
|
132 |
|
|
extern assocarr<string> clidefines; |
133 |
|
|
|
134 |
|
|
extern virtual_filesystem* filesystem; |
135 |
|
|
|
136 |
|
|
extern assocarr<string> defines; |
137 |
|
|
|
138 |
|
|
extern assocarr<string> builtindefines; |
139 |
|
|
|
140 |
|
|
|
141 |
|
|
namespace callstack_entry_type { |
142 |
|
|
enum e : int { |
143 |
|
|
FILE, |
144 |
|
|
MACRO_CALL, |
145 |
|
|
LINE, |
146 |
|
|
BLOCK, |
147 |
|
|
}; |
148 |
|
|
} |
149 |
|
|
|
150 |
|
|
struct callstack_entry { |
151 |
|
|
callstack_entry_type::e type; |
152 |
|
|
string content; |
153 |
|
|
int lineno; |
154 |
|
|
|
155 |
|
214999 |
callstack_entry(callstack_entry_type::e type, const char* content, int lineno) |
156 |
|
214999 |
{ |
157 |
|
214999 |
this->type = type; |
158 |
1/2
✓ Branch 0 taken 214999 times.
✗ Branch 1 not taken.
|
214999 |
this->content = content; |
159 |
|
214999 |
this->lineno = lineno; |
160 |
|
214999 |
} |
161 |
|
|
|
162 |
|
239274 |
callstack_entry() |
163 |
|
239274 |
{ |
164 |
|
239274 |
} |
165 |
|
|
}; |
166 |
|
|
|
167 |
|
|
|
168 |
|
|
struct printable_callstack_entry { |
169 |
|
|
string fullpath; |
170 |
|
|
string prettypath; |
171 |
|
|
int lineno; |
172 |
|
|
string details; |
173 |
|
|
}; |
174 |
|
|
|
175 |
|
|
|
176 |
|
|
extern autoarray<callstack_entry> callstack; |
177 |
|
|
extern bool simple_callstacks; |
178 |
|
|
|
179 |
|
|
class callstack_push { |
180 |
|
|
public: |
181 |
|
214999 |
callstack_push(callstack_entry_type::e type, const char* content, int lineno=-1) |
182 |
|
|
{ |
183 |
2/4
✓ Branch 0 taken 214999 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 214999 times.
✗ Branch 3 not taken.
|
214999 |
callstack.append(callstack_entry(type, content, lineno)); |
184 |
|
214999 |
} |
185 |
|
|
|
186 |
|
214999 |
~callstack_push() |
187 |
|
|
{ |
188 |
|
214999 |
callstack.remove(callstack.count-1); |
189 |
|
214999 |
} |
190 |
|
|
}; |
191 |
|
|
|
192 |
|
|
bool in_top_level_file(); |
193 |
|
|
const char* get_current_file_name(); |
194 |
|
|
int get_current_line(); |
195 |
|
|
const char* get_current_block(); |
196 |
|
|
|
197 |
|
|
void get_full_printable_callstack(autoarray<printable_callstack_entry>* out, int indentation, bool add_lines); |
198 |
|
|
|
199 |
|
|
#if !defined(NO_USE_THREADS) && !defined(RUN_VIA_THREAD) |
200 |
|
|
// RPG Hacker: This is currently disabled for debug builds, because it causes random crashes |
201 |
|
|
// when used in combination with -fsanitize=address. |
202 |
|
|
# if defined(_WIN32) && defined(NDEBUG) |
203 |
|
|
# define RUN_VIA_FIBER |
204 |
|
|
# else |
205 |
|
|
# define RUN_VIA_THREAD |
206 |
|
|
# endif |
207 |
|
|
#endif |
208 |
|
|
|