asar coverage - build #


src/asar/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
37 of 37, 0 excluded
100.0%
Functions:
6 of 6, 0 excluded
100.0%
Branches:
14 of 22, 0 excluded
63.6%

asar.h
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 10715 inline void verify_paren(autoptr<char **> &ptr)
26 {
27
2/4
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 7 taken 5318 times.
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 8 taken 5397 times.
10715 if(!ptr) throw_err_block(0, err_mismatched_parentheses);
28 10715 }
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 114635 recurseblock()
73 {
74 114635 recursioncount++;
75 #if !defined(_WIN32) && defined(NO_USE_THREADS)
76 if(recursioncount > 500)
77 #else
78
10/12
recurseblock::recurseblock():
✓ Branch 3 → 4 taken 57029 times.
✗ Branch 3 → 5 not taken.
✓ Branch 4 → 5 taken 1 time.
✓ Branch 4 → 6 taken 57028 times.
✓ Branch 7 → 8 taken 1 time.
✓ Branch 7 → 11 taken 57028 times.
recurseblock::recurseblock():
✓ Branch 3 → 4 taken 57606 times.
✗ Branch 3 → 5 not taken.
✓ Branch 4 → 5 taken 1 time.
✓ Branch 4 → 6 taken 57605 times.
✓ Branch 7 → 8 taken 1 time.
✓ Branch 7 → 11 taken 57605 times.
114635 if(!have_enough_stack_left() || recursioncount > 5000)
79 #endif
80 2 throw_err_fatal(pass, err_recursion_limit);
81 114633 }
82 114633 ~recurseblock()
83 {
84 114633 recursioncount--;
85 114633 }
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 extern int cur_logical_lineno;
109
110 extern bool for_loop_expansion_warning;
111
112 //this is a trick to namespace an enum to avoid name collision without too much verbosity
113 //could technically name the enum too but this is fine for now.
114 namespace optimize_dp_flag {
115 enum : int {
116 NONE, //don't optimize
117 RAM, //bank 7E only (always uses dp base)
118 ALWAYS //bank 00-3F[|80] and 7E (always uses dp base)
119 };
120 }
121
122 extern int optimize_dp;
123 extern int dp_base;
124
125 namespace optimize_address_flag {
126 enum : int {
127 DEFAULT,//simply use optimizeforbank
128 RAM, //default+bank 7E only RAM address < $2000
129 MIRRORS //ram+if optimizeforbank is 00-3F[|80] and address < $8000
130 };
131 }
132
133 extern int optimize_address;
134
135 extern bool errored;
136
137 extern assocarr<string> clidefines;
138
139 extern virtual_filesystem* filesystem;
140
141 extern assocarr<string> defines;
142
143 extern assocarr<string> builtindefines;
144
145
146 enum class callstack_entry_type : int {
147 FILE,
148 MACRO_CALL,
149 LINE,
150 BLOCK,
151 };
152
153 struct callstack_entry {
154 callstack_entry_type type;
155 const char* content;
156 int lineno;
157
158 143487 callstack_entry(callstack_entry_type type, const char* content, int lineno)
159 143487 : type(type), content(content), lineno(lineno)
160 143487 {}
161 };
162
163
164 struct printable_callstack_entry {
165 string fullpath;
166 string prettypath;
167 int lineno;
168 string details;
169 };
170
171
172 extern std::vector<callstack_entry> callstack;
173 extern bool simple_callstacks;
174
175 class callstack_push {
176 public:
177 // the `content` here MUST outlive the callstack_push object, and must not be mutated after passing it to callstack_push.
178 143487 callstack_push(callstack_entry_type type, const char* content, int lineno=-1)
179 {
180
2/6
callstack_push::callstack_push(callstack_entry_type, char const*, int):
✓ Branch 3 → 4 taken 71285 times.
✗ Branch 3 → 5 not taken.
callstack_push::callstack_push(callstack_entry_type, char const*, int):
✗ Branch 3 → 4 not taken.
✗ Branch 3 → 5 not taken.
✓ Branch 6 → 7 taken 72202 times.
✗ Branch 6 → 9 not taken.
143487 callstack.emplace_back(callstack_entry(type, content, lineno));
181 143487 }
182
183 143487 ~callstack_push()
184 {
185 143487 callstack.pop_back();
186 143487 }
187 };
188
189 bool in_top_level_file();
190 const char* get_current_file_name();
191 int get_current_line();
192 const char* get_current_block();
193
194 void get_full_printable_callstack(autoarray<printable_callstack_entry>* out, int indentation, bool add_lines);
195
196 #if !defined(NO_USE_THREADS) && !defined(RUN_VIA_THREAD)
197 // RPG Hacker: This is currently disabled for debug builds, because it causes random crashes
198 // when used in combination with -fsanitize=address.
199 # if defined(_WIN32) && defined(NDEBUG)
200 # define RUN_VIA_FIBER
201 # else
202 # define RUN_VIA_THREAD
203 # endif
204 #endif
205