| 1 | //cxx . . $ `<file>/src/asm/flow.c`/ |
| 2 | // ACME - a crossassembler for producing 6502/65c02/65816 code. |
| 3 | // Copyright (C) 1998-2006 Marco Baye |
| 4 | // Have a look at "acme.c" for further info |
| 5 | // |
| 6 | // Flow control stuff (loops, conditional assembly etc.) |
| 7 | // |
| 8 | // Macros, conditional assembly, loops and sourcefile-includes are all based on |
| 9 | // parsing blocks of code. When defining macros or using loops or conditional |
| 10 | // assembly, the block starts with "{" and ends with "}". In the case of |
| 11 | // "!source", the given file is treated like a block - the outermost assembler |
| 12 | // function uses the same technique to parse the top level file. |
| 13 | |
| 14 | #include <string.h> |
| 15 | #include "acme.h"cxx . . $ `<file>/src/asm/acme.h`/ |
| 16 | #include "alu.h"cxx . . $ `<file>/src/asm/alu.h`/ |
| 17 | #include "config.h"cxx . . $ `<file>/src/asm/config.h`/ |
| 18 | #include "dynabuf.h"cxx . . $ `<file>/src/asm/dynabuf.h`/ |
| 19 | #include "global.h"cxx . . $ `<file>/src/asm/global.h`/ |
| 20 | #include "input.h"cxx . . $ `<file>/src/asm/input.h`/ |
| 21 | #include "label.h"cxx . . $ `<file>/src/asm/label.h`/ |
| 22 | #include "macro.h"cxx . . $ `<file>/src/asm/macro.h`/ |
| 23 | #include "mnemo.h"cxx . . $ `<file>/src/asm/mnemo.h`/ |
| 24 | #include "tree.h"cxx . . $ `<file>/src/asm/tree.h`/ |
| 25 | |
| 26 | |
| 27 | // type definitions |
| 28 | enum cond_key_tcxx . . $ cond_key_t# { |
| 29 | ID_UNTILcxx . . $ ID_UNTIL., // Handles to store instead of |
| 30 | ID_WHILEcxx . . $ ID_WHILE., // the UNTIL and WHILE keywords |
| 31 | }; |
| 32 | typedef structcxx . . $ $anonymous_type_7487c5d3db32feae_0# { |
| 33 | enum cond_key_tcxx . . $ cond_key_t# typecxx . . $ $anonymous_type_7487c5d3db32feae_0#type.; // either ID_UNTIL or ID_WHILE |
| 34 | int linecxx . . $ $anonymous_type_7487c5d3db32feae_0#line.; // original line number |
| 35 | char* bodycxx . . $ $anonymous_type_7487c5d3db32feae_0#body.; // pointer to actual expression |
| 36 | } loopcond_tcxx . . $ loopcond_t#; |
| 37 | |
| 38 | |
| 39 | // Variables |
| 40 | |
| 41 | // predefined stuff |
| 42 | static node_tcxx . . $ node_t#* condkey_treecxx . . $ condkey_tree. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;// tree to hold UNTIL and WHILE |
| 43 | static node_tcxx . . $ node_t# condkeyscxx . . $ condkeys.[] = { |
| 44 | PREDEFNODEcxx . . $ `src/asm/tree.h:15:9`!("until", ID_UNTIL), |
| 45 | PREDEFLASTcxx . . $ `src/asm/tree.h:16:9`!("while", ID_WHILE), |
| 46 | // ^^^^ this marks the last element |
| 47 | }; |
| 48 | |
| 49 | |
| 50 | // Helper functions for "!for" and "!do" |
| 51 | |
| 52 | // Parse a loop body (could also be used for macro body) |
| 53 | static void parse_ram_blockcxx . . $ parse_ram_block(577809987ad7a468).(int line_number, char* body) { |
| 54 | Input_nowcxx . . $ Input_now.->line_numbercxx . . $ $anonymous_type_5e15f442b66098d4_0#line_number. = line_number;// set line number to loop start |
| 55 | Input_nowcxx . . $ Input_now.->srccxx . . $ $anonymous_type_5e15f442b66098d4_0#src..ram_ptrcxx . . $ $anonymous_type_5e15f442b66098d4_0#$anonymous_type_1#ram_ptr. = body;// set RAM read pointer to loop |
| 56 | // Parse loop body |
| 57 | Parse_until_eob_or_eofcxx . . $ Parse_until_eob_or_eof(49f6e7a06ebc5aa8).(); |
| 58 | if(GotBytecxx . . $ GotByte. != CHAR_EOBcxx . . $ `src/asm/input.h:50:9`!) |
| 59 | Bug_foundcxx . . $ Bug_found(34d26762b42c433a).("IllegalBlockTerminator", GotBytecxx . . $ GotByte.); |
| 60 | } |
| 61 | |
| 62 | // Try to read a condition into DynaBuf and store copy pointer in |
| 63 | // given loopcond_t structure. |
| 64 | // If no condition given, NULL is written to structure. |
| 65 | // Call with GotByte = first interesting character |
| 66 | static void store_conditioncxx . . $ store_condition(baa7a02c323fcf6).(loopcond_tcxx . . $ loopcond_t#* condition, char terminator) { |
| 67 | void* node_body; |
| 68 | |
| 69 | // write line number |
| 70 | condition->linecxx . . $ $anonymous_type_7487c5d3db32feae_0#line. = Input_nowcxx . . $ Input_now.->line_numbercxx . . $ $anonymous_type_5e15f442b66098d4_0#line_number.; |
| 71 | // Check for empty condition |
| 72 | if(GotBytecxx . . $ GotByte. == terminator) { |
| 73 | // Write NULL condition, then return |
| 74 | condition->bodycxx . . $ $anonymous_type_7487c5d3db32feae_0#body. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 75 | return; |
| 76 | } |
| 77 | // Seems as if there really *is* a condition. |
| 78 | // Read UNTIL/WHILE keyword |
| 79 | if(Input_read_and_lower_keywordcxx . . $ Input_read_and_lower_keyword(b126dc7c1de90089).()) { |
| 80 | // Search for new tree item |
| 81 | if(!Tree_easy_scancxx . . $ Tree_easy_scan(7f10be3e8224db50).(condkey_treecxx . . $ condkey_tree., &node_body, GlobalDynaBufcxx . . $ GlobalDynaBuf.)) { |
| 82 | Throw_errorcxx . . $ Throw_error(85c52e162fed56f9).(exception_syntaxcxx . . $ exception_syntax.); |
| 83 | condition->bodycxx . . $ $anonymous_type_7487c5d3db32feae_0#body. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 84 | return; |
| 85 | } |
| 86 | condition->typecxx . . $ $anonymous_type_7487c5d3db32feae_0#type. = (enum cond_key_tcxx . . $ cond_key_t#) node_body; |
| 87 | // Write given condition into buffer |
| 88 | SKIPSPACEcxx . . $ `src/asm/global.h:75:9`!(); |
| 89 | DYNABUF_CLEARcxx . . $ `src/asm/dynabuf.h:14:9`!(GlobalDynaBuf); |
| 90 | Input_until_terminatorcxx . . $ Input_until_terminator(44b6ea1973a07080).(terminator); |
| 91 | DynaBuf_appendcxx . . $ DynaBuf_append(11d1e1bb7092144).(GlobalDynaBufcxx . . $ GlobalDynaBuf., CHAR_EOScxx . . $ `src/asm/input.h:48:9`!);// ensure terminator |
| 92 | condition->bodycxx . . $ $anonymous_type_7487c5d3db32feae_0#body. = DynaBuf_get_copycxx . . $ DynaBuf_get_copy(d7229e135d075701).(GlobalDynaBufcxx . . $ GlobalDynaBuf.); |
| 93 | } |
| 94 | return; |
| 95 | } |
| 96 | |
| 97 | // Check a condition expression |
| 98 | static boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! check_conditioncxx . . $ check_condition(5ec2af355f63863f).(loopcond_tcxx . . $ loopcond_t#* condition) { |
| 99 | intval_tcxx . . $ intval_t# expression; |
| 100 | |
| 101 | // First, check whether there actually *is* a condition |
| 102 | if(condition->bodycxx . . $ $anonymous_type_7487c5d3db32feae_0#body. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) |
| 103 | return(TRUEcxx . . $ `src/asm/config.h:55:9`!); // non-existant conditions are always true |
| 104 | // set up input for expression evaluation |
| 105 | Input_nowcxx . . $ Input_now.->line_numbercxx . . $ $anonymous_type_5e15f442b66098d4_0#line_number. = condition->linecxx . . $ $anonymous_type_7487c5d3db32feae_0#line.; |
| 106 | Input_nowcxx . . $ Input_now.->srccxx . . $ $anonymous_type_5e15f442b66098d4_0#src..ram_ptrcxx . . $ $anonymous_type_5e15f442b66098d4_0#$anonymous_type_1#ram_ptr. = condition->bodycxx . . $ $anonymous_type_7487c5d3db32feae_0#body.; |
| 107 | GetBytecxx . . $ GetByte(6e9c618e4dd2eafc).(); // proceed with next char |
| 108 | expression = ALU_defined_intcxx . . $ ALU_defined_int(da6335ded91d79c2).(); |
| 109 | if(GotBytecxx . . $ GotByte.) |
| 110 | Throw_serious_errorcxx . . $ Throw_serious_error(85c52e162fed56f9).(exception_syntaxcxx . . $ exception_syntax.); |
| 111 | if(condition->typecxx . . $ $anonymous_type_7487c5d3db32feae_0#type. == ID_UNTILcxx . . $ ID_UNTIL.) |
| 112 | return(!expression); |
| 113 | return(!!expression); |
| 114 | } |
| 115 | |
| 116 | // Looping assembly ("!do"). Has to be re-entrant. |
| 117 | static enum eos_tcxx . . $ eos_t# PO_docxx . . $ PO_do(6522f478c9c0d97c).(void) { // Now GotByte = illegal char |
| 118 | loopcond_tcxx . . $ loopcond_t# condition1, |
| 119 | condition2; |
| 120 | input_tcxx . . $ input_t# loop_input, |
| 121 | *outer_input; |
| 122 | char* loop_body; |
| 123 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! go_on; |
| 124 | int loop_start;// line number of loop pseudo opcode |
| 125 | |
| 126 | // Read head condition to buffer |
| 127 | SKIPSPACEcxx . . $ `src/asm/global.h:75:9`!(); |
| 128 | store_conditioncxx . . $ store_condition(baa7a02c323fcf6).(&condition1, CHAR_SOBcxx . . $ `src/asm/input.h:49:9`!); |
| 129 | if(GotBytecxx . . $ GotByte. != CHAR_SOBcxx . . $ `src/asm/input.h:49:9`!) |
| 130 | Throw_serious_errorcxx . . $ Throw_serious_error(85c52e162fed56f9).(exception_no_left_bracecxx . . $ exception_no_left_brace.); |
| 131 | // Remember line number of loop body, |
| 132 | // then read block and get copy |
| 133 | loop_start = Input_nowcxx . . $ Input_now.->line_numbercxx . . $ $anonymous_type_5e15f442b66098d4_0#line_number.; |
| 134 | loop_body = Input_skip_or_store_blockcxx . . $ Input_skip_or_store_block(cd68a792b21c61df).(TRUEcxx . . $ `src/asm/config.h:55:9`!); // changes line number! |
| 135 | // now GotByte = '}' |
| 136 | NEXTANDSKIPSPACEcxx . . $ `src/asm/global.h:76:9`!();// Now GotByte = first non-blank char after block |
| 137 | // Read tail condition to buffer |
| 138 | store_conditioncxx . . $ store_condition(baa7a02c323fcf6).(&condition2, CHAR_EOScxx . . $ `src/asm/input.h:48:9`!); |
| 139 | // now GotByte = CHAR_EOS |
| 140 | // set up new input |
| 141 | loop_input = *Input_nowcxx . . $ Input_now.;// copy current input structure into new |
| 142 | loop_input.source_is_ramcxx . . $ $anonymous_type_5e15f442b66098d4_0#source_is_ram. = TRUEcxx . . $ `src/asm/config.h:55:9`!; // set new byte source |
| 143 | // remember old input |
| 144 | outer_input = Input_nowcxx . . $ Input_now.; |
| 145 | // activate new input (not useable yet, as pointer and |
| 146 | // line number are not yet set up) |
| 147 | Input_nowcxx . . $ Input_now. = &loop_input; |
| 148 | do { |
| 149 | // Check head condition |
| 150 | go_on = check_conditioncxx . . $ check_condition(5ec2af355f63863f).(&condition1); |
| 151 | if(go_on) { |
| 152 | parse_ram_blockcxx . . $ parse_ram_block(577809987ad7a468).(loop_start, loop_body); |
| 153 | // Check tail condition |
| 154 | go_on = check_conditioncxx . . $ check_condition(5ec2af355f63863f).(&condition2); |
| 155 | } |
| 156 | } while(go_on); |
| 157 | // Free memory |
| 158 | freecxx . . $ free(5d22bdacc48458e8).(condition1.bodycxx . . $ $anonymous_type_7487c5d3db32feae_0#body.); |
| 159 | freecxx . . $ free(5d22bdacc48458e8).(loop_body); |
| 160 | freecxx . . $ free(5d22bdacc48458e8).(condition2.bodycxx . . $ $anonymous_type_7487c5d3db32feae_0#body.); |
| 161 | // restore previous input: |
| 162 | Input_nowcxx . . $ Input_now. = outer_input; |
| 163 | GotBytecxx . . $ GotByte. = CHAR_EOScxx . . $ `src/asm/input.h:48:9`!; // CAUTION! Very ugly kluge. |
| 164 | // But by switching input, we lost the outer input's GotByte. We know |
| 165 | // it was CHAR_EOS. We could just call GetByte() to get real input, but |
| 166 | // then the main loop could choke on unexpected bytes. So we pretend |
| 167 | // that we got the outer input's GotByte value magically back. |
| 168 | return(AT_EOS_ANYWAYcxx . . $ AT_EOS_ANYWAY.); |
| 169 | } |
| 170 | |
| 171 | // Looping assembly ("!for"). Has to be re-entrant. |
| 172 | static enum eos_tcxx . . $ eos_t# PO_forcxx . . $ PO_for(6522f478c9c0d97c).(void) {// Now GotByte = illegal char |
| 173 | input_tcxx . . $ input_t# loop_input, |
| 174 | *outer_input; |
| 175 | result_tcxx . . $ result_t# loop_counter; |
| 176 | intval_tcxx . . $ intval_t# maximum; |
| 177 | char* loop_body;// pointer to loop's body block |
| 178 | label_tcxx . . $ label_t#* label; |
| 179 | zone_tcxx . . $ zone_t# zone; |
| 180 | int force_bit, |
| 181 | loop_start;// line number of "!for" pseudo opcode |
| 182 | |
| 183 | if(Input_read_zone_and_keywordcxx . . $ Input_read_zone_and_keyword(4ebf403dd87dd80).(&zone) == 0) // skips spaces before |
| 184 | return(SKIP_REMAINDERcxx . . $ SKIP_REMAINDER.); |
| 185 | // Now GotByte = illegal char |
| 186 | force_bit = Input_get_force_bitcxx . . $ Input_get_force_bit(b126dc7c1de90089).(); // skips spaces after |
| 187 | label = Label_findcxx . . $ Label_find(dc7499a14ef462f5).(zone, force_bit); |
| 188 | if(Input_accept_commacxx . . $ Input_accept_comma(c9857a73d68e59ba).() == FALSEcxx . . $ `src/asm/config.h:54:9`!) { |
| 189 | Throw_errorcxx . . $ Throw_error(85c52e162fed56f9).(exception_syntaxcxx . . $ exception_syntax.); |
| 190 | return(SKIP_REMAINDERcxx . . $ SKIP_REMAINDER.); |
| 191 | } |
| 192 | maximum = ALU_defined_intcxx . . $ ALU_defined_int(da6335ded91d79c2).(); |
| 193 | if(maximum < 0) |
| 194 | Throw_serious_errorcxx . . $ Throw_serious_error(85c52e162fed56f9).("Loop count is negative."); |
| 195 | if(GotBytecxx . . $ GotByte. != CHAR_SOBcxx . . $ `src/asm/input.h:49:9`!) |
| 196 | Throw_serious_errorcxx . . $ Throw_serious_error(85c52e162fed56f9).(exception_no_left_bracecxx . . $ exception_no_left_brace.); |
| 197 | // remember line number of loop pseudo opcode |
| 198 | loop_start = Input_nowcxx . . $ Input_now.->line_numbercxx . . $ $anonymous_type_5e15f442b66098d4_0#line_number.; |
| 199 | // read loop body into DynaBuf and get copy |
| 200 | loop_body = Input_skip_or_store_blockcxx . . $ Input_skip_or_store_block(cd68a792b21c61df).(TRUEcxx . . $ `src/asm/config.h:55:9`!); // changes line number! |
| 201 | // switching input makes us lose GotByte. But we know it's '}' anyway! |
| 202 | // set up new input |
| 203 | loop_input = *Input_nowcxx . . $ Input_now.;// copy current input structure into new |
| 204 | loop_input.source_is_ramcxx . . $ $anonymous_type_5e15f442b66098d4_0#source_is_ram. = TRUEcxx . . $ `src/asm/config.h:55:9`!; // set new byte source |
| 205 | // remember old input |
| 206 | outer_input = Input_nowcxx . . $ Input_now.; |
| 207 | // activate new input |
| 208 | // (not yet useable; pointer and line number are still missing) |
| 209 | Input_nowcxx . . $ Input_now. = &loop_input; |
| 210 | // init counter |
| 211 | loop_counter.flagscxx . . $ result_t#flags. = MVALUE_DEFINEDcxx . . $ `src/asm/alu.h:27:9`! | MVALUE_EXISTScxx . . $ `src/asm/alu.h:20:9`!; |
| 212 | loop_counter.valcxx . . $ result_t#val..intvalcxx . . $ result_t#$anonymous_type_0#intval. = 0; |
| 213 | // if count == 0, skip loop |
| 214 | if(maximum) { |
| 215 | do { |
| 216 | loop_counter.valcxx . . $ result_t#val..intvalcxx . . $ result_t#$anonymous_type_0#intval.++;// increment counter |
| 217 | Label_set_valuecxx . . $ Label_set_value(7d459e0ebbb639fe).(label, &loop_counter, TRUEcxx . . $ `src/asm/config.h:55:9`!); |
| 218 | parse_ram_blockcxx . . $ parse_ram_block(577809987ad7a468).(loop_start, loop_body); |
| 219 | } while(loop_counter.valcxx . . $ result_t#val..intvalcxx . . $ result_t#$anonymous_type_0#intval. < maximum); |
| 220 | } else |
| 221 | Label_set_valuecxx . . $ Label_set_value(7d459e0ebbb639fe).(label, &loop_counter, TRUEcxx . . $ `src/asm/config.h:55:9`!); |
| 222 | // Free memory |
| 223 | freecxx . . $ free(5d22bdacc48458e8).(loop_body); |
| 224 | // restore previous input: |
| 225 | Input_nowcxx . . $ Input_now. = outer_input; |
| 226 | // GotByte of OuterInput would be '}' (if it would still exist) |
| 227 | GetBytecxx . . $ GetByte(6e9c618e4dd2eafc).(); // fetch next byte |
| 228 | return(ENSURE_EOScxx . . $ ENSURE_EOS.); |
| 229 | } |
| 230 | |
| 231 | // Helper functions for "!if" and "!ifdef" |
| 232 | |
| 233 | // Parse or skip a block. Returns whether block's '}' terminator was missing. |
| 234 | // Afterwards: GotByte = '}' |
| 235 | static boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! skip_or_parse_blockcxx . . $ skip_or_parse_block(efaadfb7dc14930a).(boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! parse) { |
| 236 | if(!parse) { |
| 237 | Input_skip_or_store_blockcxx . . $ Input_skip_or_store_block(cd68a792b21c61df).(FALSEcxx . . $ `src/asm/config.h:54:9`!); |
| 238 | return(FALSEcxx . . $ `src/asm/config.h:54:9`!); |
| 239 | } |
| 240 | // if block was correctly terminated, return FALSE |
| 241 | Parse_until_eob_or_eofcxx . . $ Parse_until_eob_or_eof(49f6e7a06ebc5aa8).(); |
| 242 | // if block isn't correctly terminated, complain and exit |
| 243 | if(GotBytecxx . . $ GotByte. != CHAR_EOBcxx . . $ `src/asm/input.h:50:9`!) |
| 244 | Throw_serious_errorcxx . . $ Throw_serious_error(85c52e162fed56f9).(exception_no_right_bracecxx . . $ exception_no_right_brace.); |
| 245 | return(FALSEcxx . . $ `src/asm/config.h:54:9`!); |
| 246 | } |
| 247 | |
| 248 | // Parse {block} [else {block}] |
| 249 | static void parse_block_else_blockcxx . . $ parse_block_else_block(b45ddcbc8423892c).(boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! parse_first) { |
| 250 | // Parse first block. |
| 251 | // If it's not correctly terminated, return immediately (because |
| 252 | // in that case, there's no use in checking for an "else" part). |
| 253 | if(skip_or_parse_blockcxx . . $ skip_or_parse_block(efaadfb7dc14930a).(parse_first)) |
| 254 | return; |
| 255 | // now GotByte = '}'. Check for "else" part. |
| 256 | // If end of statement, return immediately. |
| 257 | NEXTANDSKIPSPACEcxx . . $ `src/asm/global.h:76:9`!(); |
| 258 | if(GotBytecxx . . $ GotByte. == CHAR_EOScxx . . $ `src/asm/input.h:48:9`!) |
| 259 | return; |
| 260 | // read keyword and check whether really "else" |
| 261 | if(Input_read_and_lower_keywordcxx . . $ Input_read_and_lower_keyword(b126dc7c1de90089).()) { |
| 262 | if(strcmpcxx . . $ strcmp(5ae29d726ae57f88).(GlobalDynaBufcxx . . $ GlobalDynaBuf.->buffercxx . . $ dynabuf_t#buffer., "else")) |
| 263 | Throw_errorcxx . . $ Throw_error(85c52e162fed56f9).(exception_syntaxcxx . . $ exception_syntax.); |
| 264 | else { |
| 265 | SKIPSPACEcxx . . $ `src/asm/global.h:75:9`!(); |
| 266 | if(GotBytecxx . . $ GotByte. != CHAR_SOBcxx . . $ `src/asm/input.h:49:9`!) |
| 267 | Throw_serious_errorcxx . . $ Throw_serious_error(85c52e162fed56f9).(exception_no_left_bracecxx . . $ exception_no_left_brace.); |
| 268 | skip_or_parse_blockcxx . . $ skip_or_parse_block(efaadfb7dc14930a).(!parse_first); |
| 269 | // now GotByte = '}' |
| 270 | GetBytecxx . . $ GetByte(6e9c618e4dd2eafc).(); |
| 271 | } |
| 272 | } |
| 273 | Input_ensure_EOScxx . . $ Input_ensure_EOS(49f6e7a06ebc5aa8).(); |
| 274 | } |
| 275 | |
| 276 | // Conditional assembly ("!if"). Has to be re-entrant. |
| 277 | static enum eos_tcxx . . $ eos_t# PO_ifcxx . . $ PO_if(6522f478c9c0d97c).(void) {// Now GotByte = illegal char |
| 278 | intval_tcxx . . $ intval_t# cond; |
| 279 | |
| 280 | cond = ALU_defined_intcxx . . $ ALU_defined_int(da6335ded91d79c2).(); |
| 281 | if(GotBytecxx . . $ GotByte. != CHAR_SOBcxx . . $ `src/asm/input.h:49:9`!) |
| 282 | Throw_serious_errorcxx . . $ Throw_serious_error(85c52e162fed56f9).(exception_no_left_bracecxx . . $ exception_no_left_brace.); |
| 283 | parse_block_else_blockcxx . . $ parse_block_else_block(b45ddcbc8423892c).(!!cond); |
| 284 | return(ENSURE_EOScxx . . $ ENSURE_EOS.); |
| 285 | } |
| 286 | |
| 287 | // Conditional assembly ("!ifdef"). Has to be re-entrant. |
| 288 | static enum eos_tcxx . . $ eos_t# PO_ifdefcxx . . $ PO_ifdef(6522f478c9c0d97c).(void) {// Now GotByte = illegal char |
| 289 | node_ra_tcxx . . $ node_ra_t#* node; |
| 290 | label_tcxx . . $ label_t#* label; |
| 291 | zone_tcxx . . $ zone_t# zone; |
| 292 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! defined = FALSEcxx . . $ `src/asm/config.h:54:9`!; |
| 293 | |
| 294 | if(Input_read_zone_and_keywordcxx . . $ Input_read_zone_and_keyword(4ebf403dd87dd80).(&zone) == 0) // skips spaces before |
| 295 | return(SKIP_REMAINDERcxx . . $ SKIP_REMAINDER.); |
| 296 | Tree_hard_scancxx . . $ Tree_hard_scan(fbd309352d4134f6).(&node, Label_forestcxx . . $ Label_forest., zone, FALSEcxx . . $ `src/asm/config.h:54:9`!); |
| 297 | if(node) { |
| 298 | label = (label_tcxx . . $ label_t#*) node->bodycxx . . $ node_ra_t#body.; |
| 299 | // in first pass, count usage |
| 300 | if(pass_countcxx . . $ pass_count. == 0) |
| 301 | label->usagecxx . . $ label_t#usage.++; |
| 302 | if(label->resultcxx . . $ label_t#result..flagscxx . . $ result_t#flags. & MVALUE_DEFINEDcxx . . $ `src/asm/alu.h:27:9`!) |
| 303 | defined = TRUEcxx . . $ `src/asm/config.h:55:9`!; |
| 304 | } |
| 305 | SKIPSPACEcxx . . $ `src/asm/global.h:75:9`!(); |
| 306 | if(GotBytecxx . . $ GotByte. == CHAR_SOBcxx . . $ `src/asm/input.h:49:9`!) |
| 307 | parse_block_else_blockcxx . . $ parse_block_else_block(b45ddcbc8423892c).(defined); |
| 308 | else { |
| 309 | if(defined) |
| 310 | return(PARSE_REMAINDERcxx . . $ PARSE_REMAINDER.); |
| 311 | return(SKIP_REMAINDERcxx . . $ SKIP_REMAINDER.); |
| 312 | } |
| 313 | return(ENSURE_EOScxx . . $ ENSURE_EOS.); |
| 314 | } |
| 315 | |
| 316 | // Macro definition ("!macro"). |
| 317 | static enum eos_tcxx . . $ eos_t# PO_macrocxx . . $ PO_macro(6522f478c9c0d97c).(void) {// Now GotByte = illegal char |
| 318 | // In first pass, parse. In all other passes, skip. |
| 319 | if(pass_countcxx . . $ pass_count. == 0) |
| 320 | Macro_parse_definitioncxx . . $ Macro_parse_definition(49f6e7a06ebc5aa8).(); // now GotByte = '}' |
| 321 | else { |
| 322 | // skip until CHAR_SOB ('{') is found. |
| 323 | // no need to check for end-of-statement, because such an |
| 324 | // error would already have been detected in first pass. |
| 325 | // for the same reason, there is no need to check for quotes. |
| 326 | while(GotBytecxx . . $ GotByte. != CHAR_SOBcxx . . $ `src/asm/input.h:49:9`!) |
| 327 | GetBytecxx . . $ GetByte(6e9c618e4dd2eafc).(); |
| 328 | Input_skip_or_store_blockcxx . . $ Input_skip_or_store_block(cd68a792b21c61df).(FALSEcxx . . $ `src/asm/config.h:54:9`!); // now GotByte = '}' |
| 329 | } |
| 330 | GetBytecxx . . $ GetByte(6e9c618e4dd2eafc).(); // Proceed with next character |
| 331 | return(ENSURE_EOScxx . . $ ENSURE_EOS.); |
| 332 | } |
| 333 | |
| 334 | // Parse a whole source code file |
| 335 | void Parse_sourcecxx . . $ Parse_source(fda57c8427c60377).(char *source) { |
| 336 | // be verbose |
| 337 | if(Process_verbositycxx . . $ Process_verbosity. > 2) |
| 338 | printfcxx . . $ printf(581fddd72a8db8fc).("Parsing source file!\n"); |
| 339 | // set up new input |
| 340 | Input_new_filecxx . . $ Input_new_file(fda57c8427c60377).(source); |
| 341 | // Parse block and check end reason |
| 342 | Parse_until_eob_or_eofcxx . . $ Parse_until_eob_or_eof(49f6e7a06ebc5aa8).(); |
| 343 | if(GotBytecxx . . $ GotByte. != CHAR_EOFcxx . . $ `src/asm/input.h:52:9`!) |
| 344 | Throw_errorcxx . . $ Throw_error(85c52e162fed56f9).("Found '}' instead of end-of-file."); |
| 345 | // close sublevel src |
| 346 | //fclose(Input_now->src.fd); |
| 347 | } |
| 348 | |
| 349 | // Include source file ("!source" or "!src"). Has to be re-entrant. |
| 350 | static enum eos_tcxx . . $ eos_t# PO_sourcecxx . . $ PO_source(6522f478c9c0d97c).(void) {// Now GotByte = illegal char |
| 351 | Throw_errorcxx . . $ Throw_error(85c52e162fed56f9).("PO_SOURCE not implemented"); |
| 352 | return 0; |
| 353 | } |
| 354 | /* |
| 355 | static enum eos_t X_PO_source(void) {// Now GotByte = illegal char |
| 356 | FILE* fd; |
| 357 | char local_gotbyte; |
| 358 | input_t new_input, |
| 359 | *outer_input; |
| 360 | |
| 361 | // Enter new nesting level. |
| 362 | // Quit program if recursion too deep. |
| 363 | if(--source_recursions_left < 0) |
| 364 | Throw_serious_error("Too deeply nested. Recursive \"!source\"?"); |
| 365 | // Read file name. Quit function on error. |
| 366 | if(Input_read_filename(TRUE)) |
| 367 | return(SKIP_REMAINDER); |
| 368 | // If file could be opened, parse it. Otherwise, complain. |
| 369 | if((fd = fopen(GLOBALDYNABUF_CURRENT, FILE_READBINARY))) { |
| 370 | char filename[GlobalDynaBuf->size]; |
| 371 | |
| 372 | strcpy(filename, GLOBALDYNABUF_CURRENT); |
| 373 | outer_input = Input_now;// remember old input |
| 374 | local_gotbyte = GotByte;// CAUTION - ugly kluge |
| 375 | Input_now = &new_input;// activate new input |
| 376 | Parse_and_close_file(fd, filename); |
| 377 | Input_now = outer_input;// restore previous input |
| 378 | GotByte = local_gotbyte;// CAUTION - ugly kluge |
| 379 | } else |
| 380 | Throw_error(exception_cannot_open_input_file); |
| 381 | // Leave nesting level |
| 382 | source_recursions_left++; |
| 383 | return(ENSURE_EOS); |
| 384 | } |
| 385 | */ |
| 386 | // pseudo opcode table |
| 387 | static node_tcxx . . $ node_t# pseudo_opcodescxx . . $ pseudo_opcodes.[] = { |
| 388 | PREDEFNODEcxx . . $ `src/asm/tree.h:15:9`!("do", PO_do), |
| 389 | PREDEFNODEcxx . . $ `src/asm/tree.h:15:9`!("for", PO_for), |
| 390 | PREDEFNODEcxx . . $ `src/asm/tree.h:15:9`!("if", PO_if), |
| 391 | PREDEFNODEcxx . . $ `src/asm/tree.h:15:9`!("ifdef", PO_ifdef), |
| 392 | PREDEFNODEcxx . . $ `src/asm/tree.h:15:9`!("macro", PO_macro), |
| 393 | PREDEFNODEcxx . . $ `src/asm/tree.h:15:9`!("source", PO_source), |
| 394 | PREDEFLASTcxx . . $ `src/asm/tree.h:16:9`!("src", PO_source), |
| 395 | // ^^^^ this marks the last element |
| 396 | }; |
| 397 | |
| 398 | // register pseudo opcodes and build keyword tree for until/while |
| 399 | void Flow_initcxx . . $ Flow_init(49f6e7a06ebc5aa8).(void) { |
| 400 | Tree_add_tablecxx . . $ Tree_add_table(90ba9e887489f1c).(&condkey_treecxx . . $ condkey_tree., condkeyscxx . . $ condkeys.); |
| 401 | Tree_add_tablecxx . . $ Tree_add_table(90ba9e887489f1c).(&pseudo_opcode_treecxx . . $ pseudo_opcode_tree., pseudo_opcodescxx . . $ pseudo_opcodes.); |
| 402 | } |