asar coverage - build #274


src/asar/
File: src/asar/assembleblock.h
Date: 2025-03-04 15:06:12
Lines:
7/7
100.0%
Functions:
1/1
100.0%
Branches:
0/0
-%

Line Branch Exec Source
1 #pragma once
2 #include "libstr.h"
3 #include "assocarr.h"
4 #include "autoarray.h"
5
6 enum { arch_65816, arch_spc700, arch_superfx };
7 extern int arch;
8
9 bool assemblemapper(char** word, int numwords);
10
11 struct snes_struct {
12 string parent;
13 int base_end;
14 int struct_size;
15 int object_size;
16 bool is_static;
17 };
18
19 extern assocarr<snes_struct> structs;
20 extern int label_counter;
21
22
23 struct snes_label {
24 unsigned int pos;
25 int id;
26 int freespace_id;
27 bool is_static;
28
29 2736 snes_label()
30 2736 {
31 2736 pos = 0;
32 2736 is_static = false;
33 2736 freespace_id = 0;
34 2736 id = label_counter++;
35 2736 }
36 };
37
38 // data necessary for one freespace block
39 struct freespace_data {
40 // snespos of the start of the freespace block. set to the found freespace
41 // block during the `freespace` command in pass 1.
42 int pos;
43 // length of the freespace block
44 int len;
45 // whether this freespace is leaked (no autocleans pointing at it)
46 bool leaked;
47 // position of the previous version of this freespace
48 // -2 means "never searched", -1 is "searched but didn't find anything",
49 // nonnegative is previous location
50 int orgpos;
51 // length of previous version
52 int orglen;
53 // whether this freespace is static, i.e. can't be relocated when reinserting
54 bool is_static;
55
56 // options only used for finding freespace:
57
58 // if this freespace is pinned to another one, this holds the name of the label of the target.
59 // we can't resolve this into a freespace number earlier since it could be a forward reference.
60 // we also need to keep the current namespace around since this is necessary for resolving label references.
61 string pin_target;
62 string pin_target_ns;
63 // computed at the end of pass 0. this is the freespace id of the final pin
64 // target, in case of multiple "nested" pins or whatnot.
65 int pin_target_id;
66 // what address to start searching for freespace at
67 int search_start;
68 // what bank to search for freespace in: -1 for any bank, -2 for banks with
69 // code mirrors, positive for specific bank
70 int bank;
71 bool write_rats;
72 // should rework this...
73 bool flag_align;
74 // whether the `cleaned` argument was given
75 bool flag_cleaned;
76 // pinned freespaces: how much space is actually needed for this freespace
77 int total_len;
78 // pinned freespaces: how much of this block we've already used
79 int used_len;
80 bool allow_bankcross;
81 };
82 extern autoarray<freespace_data> freespaces;
83
84 struct whiletracker {
85 bool iswhile;
86 int startline;
87 bool cond;
88 bool is_for;
89 string for_variable;
90 string for_var_backup;
91 bool for_has_var_backup;
92 int for_start;
93 int for_end;
94 int for_cur;
95 };
96
97 extern autoarray<whiletracker> whilestatus;
98
99 bool confirmname(const char * name);
100 string posneglabelname(const char ** input, bool define);
101
102 void write1(unsigned int num);
103 void write2(unsigned int num);
104 void write3(unsigned int num);
105 void write4(unsigned int num);
106
107 int snestopc(int addr);
108
109 int getlenfromchar(char c);
110
111 string labelname(const char ** rawname, bool define=false, bool is_addlabel=false);
112 snes_label labelval(const char ** rawname, bool define = false);
113 snes_label labelval(string name, bool define = false);
114 bool labelval(const char ** rawname, snes_label * rval, bool define = false);
115 bool labelval(string name, snes_label * rval, bool define = false);
116
117 const char * safedequote(char * str);
118
119 void checkbankcross();
120
121 void initstuff();
122 void finishpass();
123
124 void handle_autoclean(string& arg, int checkbyte, int orgpos);
125
126 void assembleblock(const char * block, int& single_line_for_tracker);
127
128 extern int snespos;
129 extern int realsnespos;
130 extern int startpos;
131 extern int realstartpos;
132
133 extern int bytes;
134
135 extern int numif;
136 extern int numtrue;
137
138 extern int freespaceid;
139
140 extern assocarr<snes_label> labels;
141
142 extern autoarray<int>* macroposlabels;
143 extern autoarray<int>* macroneglabels;
144 extern autoarray<string>* macrosublabels;
145
146 extern autoarray<string> sublabels;
147 extern string ns;
148 extern autoarray<string> namespace_list;
149
150 extern autoarray<string> includeonce;
151