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