| 1 | //cxx . . $ `<file>/src/asm/input.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 | // Input stuff |
| 7 | |
| 8 | #include "config.h"cxx . . $ `<file>/src/asm/config.h`/ |
| 9 | #include "alu.h"cxx . . $ `<file>/src/asm/alu.h`/ |
| 10 | #include "dynabuf.h"cxx . . $ `<file>/src/asm/dynabuf.h`/ |
| 11 | #include "global.h"cxx . . $ `<file>/src/asm/global.h`/ |
| 12 | #include "input.h"cxx . . $ `<file>/src/asm/input.h`/ |
| 13 | #include "platform.h"cxx . . $ `<file>/src/asm/platform.h`/ |
| 14 | #include "section.h"cxx . . $ `<file>/src/asm/section.h`/ |
| 15 | #include "tree.h"cxx . . $ `<file>/src/asm/tree.h`/ |
| 16 | |
| 17 | |
| 18 | // Constants |
| 19 | const char FILE_READBINARYcxx . . $ FILE_READBINARY.[] = "rb"; |
| 20 | #define CHAR_TABcxx . . $ `src/asm/input.c:20:9`! (9) // Tab character |
| 21 | #define CHAR_LFcxx . . $ `src/asm/input.c:21:9`! (10) // line feed (in file) |
| 22 | // (10) // start of line (in high-level format) |
| 23 | #define CHAR_CRcxx . . $ `src/asm/input.c:23:9`! (13) // carriage return (in file) |
| 24 | // (13) // end of file (in high-level format) |
| 25 | #define CHAR_STATEMENT_DELIMITERcxx . . $ `src/asm/input.c:25:9`! ':' |
| 26 | #define CHAR_COMMENT_SEPARATORcxx . . $ `src/asm/input.c:26:9`! ';' |
| 27 | // If the characters above are changed, don't forget to adjust ByteFlags[]! |
| 28 | |
| 29 | // fake input structure (for error msgs before any real input is established) |
| 30 | static input_tcxx . . $ input_t# outermostcxx . . $ outermost. = { |
| 31 | "<none>", // file name |
| 32 | 0, // line number |
| 33 | FALSEcxx . . $ `src/asm/config.h:54:9`!, // Faked file access, so no RAM read |
| 34 | INPUTSTATE_EOFcxx . . $ INPUTSTATE_EOF., // state of input |
| 35 | { |
| 36 | NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`! // RAM read pointer or file handle |
| 37 | } |
| 38 | }; |
| 39 | |
| 40 | |
| 41 | // Variables |
| 42 | input_tcxx . . $ input_t#* Input_nowcxx . . $ Input_now. = &outermostcxx . . $ outermost.; // current input structure |
| 43 | |
| 44 | |
| 45 | // End of source file ("!endoffile" or "!eof") |
| 46 | static enum eos_tcxx . . $ eos_t# PO_eofcxx . . $ PO_eof(6522f478c9c0d97c).(void) { |
| 47 | // Well, it doesn't end right here and now, but at end-of-line! :-) |
| 48 | Input_ensure_EOScxx . . $ Input_ensure_EOS(49f6e7a06ebc5aa8).(); |
| 49 | Input_nowcxx . . $ Input_now.->statecxx . . $ $anonymous_type_5e15f442b66098d4_0#state. = INPUTSTATE_EOFcxx . . $ INPUTSTATE_EOF.; |
| 50 | return(AT_EOS_ANYWAYcxx . . $ AT_EOS_ANYWAY.); |
| 51 | } |
| 52 | |
| 53 | // predefined stuff |
| 54 | static node_tcxx . . $ node_t# pseudo_opcodescxx . . $ pseudo_opcodes.[] = { |
| 55 | PREDEFNODEcxx . . $ `src/asm/tree.h:15:9`!("eof", PO_eof), |
| 56 | PREDEFLASTcxx . . $ `src/asm/tree.h:16:9`!("endoffile", PO_eof), |
| 57 | // ^^^^ this marks the last element |
| 58 | }; |
| 59 | |
| 60 | |
| 61 | // Functions |
| 62 | |
| 63 | // register pseudo opcodes |
| 64 | void Input_initcxx . . $ Input_init(49f6e7a06ebc5aa8).(void) { |
| 65 | Tree_add_tablecxx . . $ Tree_add_table(90ba9e887489f1c).(&pseudo_opcode_treecxx . . $ pseudo_opcode_tree., pseudo_opcodescxx . . $ pseudo_opcodes.); |
| 66 | } |
| 67 | |
| 68 | // Let current input point to start of file |
| 69 | void Input_new_filecxx . . $ Input_new_file(fda57c8427c60377).(char *src) { |
| 70 | /* |
| 71 | Input_now->original_filename = ""; //filename; |
| 72 | Input_now->line_number = 1; |
| 73 | Input_now->source_is_ram = FALSE; |
| 74 | Input_now->state = INPUTSTATE_NORMAL; |
| 75 | Input_now->src.fd = NULL; |
| 76 | */ |
| 77 | Input_nowcxx . . $ Input_now.->original_filenamecxx . . $ $anonymous_type_5e15f442b66098d4_0#original_filename. = ""; //filename; |
| 78 | Input_nowcxx . . $ Input_now.->line_numbercxx . . $ $anonymous_type_5e15f442b66098d4_0#line_number. = 1; |
| 79 | Input_nowcxx . . $ Input_now.->source_is_ramcxx . . $ $anonymous_type_5e15f442b66098d4_0#source_is_ram. = FALSEcxx . . $ `src/asm/config.h:54:9`!; |
| 80 | Input_nowcxx . . $ Input_now.->statecxx . . $ $anonymous_type_5e15f442b66098d4_0#state. = INPUTSTATE_NORMALcxx . . $ INPUTSTATE_NORMAL.; |
| 81 | Input_nowcxx . . $ Input_now.->srccxx . . $ $anonymous_type_5e15f442b66098d4_0#src..fdcxx . . $ $anonymous_type_5e15f442b66098d4_0#$anonymous_type_1#fd. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 82 | Input_nowcxx . . $ Input_now.->string_sourcecxx . . $ $anonymous_type_5e15f442b66098d4_0#string_source. = src; |
| 83 | Input_nowcxx . . $ Input_now.->string_source_lengthcxx . . $ $anonymous_type_5e15f442b66098d4_0#string_source_length. = strlencxx . . $ strlen(751346f8406fd082).(src); |
| 84 | Input_nowcxx . . $ Input_now.->string_source_positioncxx . . $ $anonymous_type_5e15f442b66098d4_0#string_source_position. = 0; |
| 85 | } |
| 86 | |
| 87 | int hacked_getccxx . . $ hacked_getc(60a5e5c04382a159).(input_tcxx . . $ input_t# *Input) { |
| 88 | if(Input->string_source_positioncxx . . $ $anonymous_type_5e15f442b66098d4_0#string_source_position. >= |
| 89 | Input->string_source_lengthcxx . . $ $anonymous_type_5e15f442b66098d4_0#string_source_length.) |
| 90 | return EOFcxx . . $ `<external>/232824719582829767/stdio.h:109:9`!; |
| 91 | int byte = *(Input->string_sourcecxx . . $ $anonymous_type_5e15f442b66098d4_0#string_source.++); |
| 92 | Input->string_source_positioncxx . . $ $anonymous_type_5e15f442b66098d4_0#string_source_position.++; |
| 93 | return byte; |
| 94 | } |
| 95 | |
| 96 | // Deliver source code from current file (!) in shortened high-level format |
| 97 | static char get_processed_from_filecxx . . $ get_processed_from_file(6e9c618e4dd2eafc).(void) { |
| 98 | int from_file; |
| 99 | |
| 100 | do { |
| 101 | switch(Input_nowcxx . . $ Input_now.->statecxx . . $ $anonymous_type_5e15f442b66098d4_0#state.) { |
| 102 | |
| 103 | case INPUTSTATE_NORMALcxx . . $ INPUTSTATE_NORMAL.: |
| 104 | // fetch a fresh byte from the current source file |
| 105 | //from_file = getc(Input_now->src.fd); |
| 106 | from_file = hacked_getccxx . . $ hacked_getc(60a5e5c04382a159).(Input_nowcxx . . $ Input_now.); |
| 107 | // now process it |
| 108 | /*FALLTHROUGH*/ |
| 109 | |
| 110 | case INPUTSTATE_AGAINcxx . . $ INPUTSTATE_AGAIN.: |
| 111 | // Process the latest byte again. Of course, this only |
| 112 | // makes sense if the loop has executed at least once, |
| 113 | // otherwise the contents of from_file are undefined. |
| 114 | // If the source is changed so there is a possibility |
| 115 | // to enter INPUTSTATE_AGAIN mode without first having |
| 116 | // defined "from_file", trouble may arise... |
| 117 | Input_nowcxx . . $ Input_now.->statecxx . . $ $anonymous_type_5e15f442b66098d4_0#state. = INPUTSTATE_NORMALcxx . . $ INPUTSTATE_NORMAL.; |
| 118 | // EOF must be checked first because it cannot be used |
| 119 | // as an index into Byte_flags[] |
| 120 | if(from_file == EOFcxx . . $ `<external>/232824719582829767/stdio.h:109:9`!) { |
| 121 | // remember to send an end-of-file |
| 122 | Input_nowcxx . . $ Input_now.->statecxx . . $ $anonymous_type_5e15f442b66098d4_0#state. = INPUTSTATE_EOFcxx . . $ INPUTSTATE_EOF.; |
| 123 | return(CHAR_EOScxx . . $ `src/asm/input.h:48:9`!);// end of statement |
| 124 | } |
| 125 | // check whether character is special one |
| 126 | // if not, everything's cool and froody, so return it |
| 127 | if((BYTEFLAGScxx . . $ `src/asm/global.h:42:9`!(from_file) & BYTEIS_SYNTAXcxx . . $ `src/asm/global.h:47:9`!) == 0) |
| 128 | return((char) from_file); |
| 129 | // check special characters ("0x00 TAB LF CR SPC :;}") |
| 130 | switch(from_file) { |
| 131 | |
| 132 | case CHAR_TABcxx . . $ `src/asm/input.c:20:9`!:// TAB character |
| 133 | case ' ': |
| 134 | // remember to skip all following blanks |
| 135 | Input_nowcxx . . $ Input_now.->statecxx . . $ $anonymous_type_5e15f442b66098d4_0#state. = INPUTSTATE_SKIPBLANKScxx . . $ INPUTSTATE_SKIPBLANKS.; |
| 136 | return(' '); |
| 137 | |
| 138 | case CHAR_LFcxx . . $ `src/asm/input.c:21:9`!:// LF character |
| 139 | // remember to send a start-of-line |
| 140 | Input_nowcxx . . $ Input_now.->statecxx . . $ $anonymous_type_5e15f442b66098d4_0#state. = INPUTSTATE_LFcxx . . $ INPUTSTATE_LF.; |
| 141 | return(CHAR_EOScxx . . $ `src/asm/input.h:48:9`!);// end of statement |
| 142 | |
| 143 | case CHAR_CRcxx . . $ `src/asm/input.c:23:9`!:// CR character |
| 144 | // remember to check CRLF + send start-of-line |
| 145 | Input_nowcxx . . $ Input_now.->statecxx . . $ $anonymous_type_5e15f442b66098d4_0#state. = INPUTSTATE_CRcxx . . $ INPUTSTATE_CR.; |
| 146 | return(CHAR_EOScxx . . $ `src/asm/input.h:48:9`!);// end of statement |
| 147 | |
| 148 | case CHAR_EOBcxx . . $ `src/asm/input.h:50:9`!: |
| 149 | // remember to send an end-of-block |
| 150 | Input_nowcxx . . $ Input_now.->statecxx . . $ $anonymous_type_5e15f442b66098d4_0#state. = INPUTSTATE_EOBcxx . . $ INPUTSTATE_EOB.; |
| 151 | return(CHAR_EOScxx . . $ `src/asm/input.h:48:9`!);// end of statement |
| 152 | |
| 153 | case CHAR_STATEMENT_DELIMITERcxx . . $ `src/asm/input.c:25:9`!: |
| 154 | // just deliver an EOS instead |
| 155 | return(CHAR_EOScxx . . $ `src/asm/input.h:48:9`!);// end of statement |
| 156 | |
| 157 | case CHAR_COMMENT_SEPARATORcxx . . $ `src/asm/input.c:26:9`!: |
| 158 | // remember to skip remainder of line |
| 159 | Input_nowcxx . . $ Input_now.->statecxx . . $ $anonymous_type_5e15f442b66098d4_0#state. = INPUTSTATE_COMMENTcxx . . $ INPUTSTATE_COMMENT.; |
| 160 | return(CHAR_EOScxx . . $ `src/asm/input.h:48:9`!);// end of statement |
| 161 | |
| 162 | default: |
| 163 | // complain if byte is 0 |
| 164 | Throw_errorcxx . . $ Throw_error(85c52e162fed56f9).("Source file contains illegal character."); |
| 165 | return((char) from_file); |
| 166 | } |
| 167 | |
| 168 | case INPUTSTATE_SKIPBLANKScxx . . $ INPUTSTATE_SKIPBLANKS.: |
| 169 | // read until non-blank, then deliver that |
| 170 | do { |
| 171 | // from_file = getc(Input_now->src.fd); |
| 172 | from_file = hacked_getccxx . . $ hacked_getc(60a5e5c04382a159).(Input_nowcxx . . $ Input_now.); |
| 173 | } while((from_file == CHAR_TABcxx . . $ `src/asm/input.c:20:9`!) || (from_file == ' ')); |
| 174 | // re-process last byte |
| 175 | Input_nowcxx . . $ Input_now.->statecxx . . $ $anonymous_type_5e15f442b66098d4_0#state. = INPUTSTATE_AGAINcxx . . $ INPUTSTATE_AGAIN.; |
| 176 | break; |
| 177 | |
| 178 | case INPUTSTATE_LFcxx . . $ INPUTSTATE_LF.: |
| 179 | // return start-of-line, then continue in normal mode |
| 180 | Input_nowcxx . . $ Input_now.->statecxx . . $ $anonymous_type_5e15f442b66098d4_0#state. = INPUTSTATE_NORMALcxx . . $ INPUTSTATE_NORMAL.; |
| 181 | return(CHAR_SOLcxx . . $ `src/asm/input.h:51:9`!);// new line |
| 182 | |
| 183 | case INPUTSTATE_CRcxx . . $ INPUTSTATE_CR.: |
| 184 | // return start-of-line, remember to check for LF |
| 185 | Input_nowcxx . . $ Input_now.->statecxx . . $ $anonymous_type_5e15f442b66098d4_0#state. = INPUTSTATE_SKIPLFcxx . . $ INPUTSTATE_SKIPLF.; |
| 186 | return(CHAR_SOLcxx . . $ `src/asm/input.h:51:9`!);// new line |
| 187 | |
| 188 | case INPUTSTATE_SKIPLFcxx . . $ INPUTSTATE_SKIPLF.: |
| 189 | from_file = hacked_getccxx . . $ hacked_getc(60a5e5c04382a159).(Input_nowcxx . . $ Input_now.); |
| 190 | // if LF, ignore it and fetch another byte |
| 191 | // otherwise, process current byte |
| 192 | if(from_file == CHAR_LFcxx . . $ `src/asm/input.c:21:9`!) |
| 193 | Input_nowcxx . . $ Input_now.->statecxx . . $ $anonymous_type_5e15f442b66098d4_0#state. = INPUTSTATE_NORMALcxx . . $ INPUTSTATE_NORMAL.; |
| 194 | else |
| 195 | Input_nowcxx . . $ Input_now.->statecxx . . $ $anonymous_type_5e15f442b66098d4_0#state. = INPUTSTATE_AGAINcxx . . $ INPUTSTATE_AGAIN.; |
| 196 | break; |
| 197 | |
| 198 | case INPUTSTATE_COMMENTcxx . . $ INPUTSTATE_COMMENT.: |
| 199 | // read until end-of-line or end-of-file |
| 200 | do |
| 201 | from_file = hacked_getccxx . . $ hacked_getc(60a5e5c04382a159).(Input_nowcxx . . $ Input_now.); |
| 202 | while((from_file != EOFcxx . . $ `<external>/232824719582829767/stdio.h:109:9`!) && (from_file != CHAR_CRcxx . . $ `src/asm/input.c:23:9`!) && (from_file != CHAR_LFcxx . . $ `src/asm/input.c:21:9`!)); |
| 203 | // re-process last byte |
| 204 | Input_nowcxx . . $ Input_now.->statecxx . . $ $anonymous_type_5e15f442b66098d4_0#state. = INPUTSTATE_AGAINcxx . . $ INPUTSTATE_AGAIN.; |
| 205 | break; |
| 206 | |
| 207 | case INPUTSTATE_EOBcxx . . $ INPUTSTATE_EOB.: |
| 208 | // deliver EOB |
| 209 | Input_nowcxx . . $ Input_now.->statecxx . . $ $anonymous_type_5e15f442b66098d4_0#state. = INPUTSTATE_NORMALcxx . . $ INPUTSTATE_NORMAL.; |
| 210 | return(CHAR_EOBcxx . . $ `src/asm/input.h:50:9`!);// end of block |
| 211 | |
| 212 | case INPUTSTATE_EOFcxx . . $ INPUTSTATE_EOF.: |
| 213 | // deliver EOF |
| 214 | Input_nowcxx . . $ Input_now.->statecxx . . $ $anonymous_type_5e15f442b66098d4_0#state. = INPUTSTATE_NORMALcxx . . $ INPUTSTATE_NORMAL.; |
| 215 | return(CHAR_EOFcxx . . $ `src/asm/input.h:52:9`!);// end of file |
| 216 | |
| 217 | default: |
| 218 | Bug_foundcxx . . $ Bug_found(34d26762b42c433a).("StrangeInputMode", Input_nowcxx . . $ Input_now.->statecxx . . $ $anonymous_type_5e15f442b66098d4_0#state.); |
| 219 | } |
| 220 | } while(TRUEcxx . . $ `src/asm/config.h:55:9`!); |
| 221 | } |
| 222 | |
| 223 | // This function delivers the next byte from the currently active byte source |
| 224 | // in shortened high-level format. FIXME - use fn ptr? |
| 225 | // When inside quotes, use GetQuotedByte() instead! |
| 226 | char GetBytecxx . . $ GetByte(6e9c618e4dd2eafc).(void) { |
| 227 | // do { |
| 228 | // If byte source is RAM, then no conversions are |
| 229 | // necessary, because in RAM the source already has |
| 230 | // high-level format |
| 231 | // Otherwise, the source is a file. This means we will call |
| 232 | // GetFormatted() which will do a shit load of conversions. |
| 233 | if(Input_nowcxx . . $ Input_now.->source_is_ramcxx . . $ $anonymous_type_5e15f442b66098d4_0#source_is_ram.) |
| 234 | GotBytecxx . . $ GotByte. = *(Input_nowcxx . . $ Input_now.->srccxx . . $ $anonymous_type_5e15f442b66098d4_0#src..ram_ptrcxx . . $ $anonymous_type_5e15f442b66098d4_0#$anonymous_type_1#ram_ptr.++); |
| 235 | else |
| 236 | GotBytecxx . . $ GotByte. = get_processed_from_filecxx . . $ get_processed_from_file(6e9c618e4dd2eafc).(); |
| 237 | // // if start-of-line was read, increment line counter and repeat |
| 238 | // if(GotByte != CHAR_SOL) |
| 239 | // return(GotByte); |
| 240 | // Input_now->line_number++; |
| 241 | // } while(TRUE); |
| 242 | if(GotBytecxx . . $ GotByte. == CHAR_SOLcxx . . $ `src/asm/input.h:51:9`!) |
| 243 | Input_nowcxx . . $ Input_now.->line_numbercxx . . $ $anonymous_type_5e15f442b66098d4_0#line_number.++; |
| 244 | return(GotBytecxx . . $ GotByte.); |
| 245 | } |
| 246 | |
| 247 | // This function delivers the next byte from the currently active byte source |
| 248 | // in un-shortened high-level format. |
| 249 | // This function complains if CHAR_EOS (end of statement) is read. |
| 250 | char GetQuotedBytecxx . . $ GetQuotedByte(6e9c618e4dd2eafc).(void) { |
| 251 | int from_file; // must be an int to catch EOF |
| 252 | |
| 253 | // If byte source is RAM, then no conversion is necessary, |
| 254 | // because in RAM the source already has high-level format |
| 255 | if(Input_nowcxx . . $ Input_now.->source_is_ramcxx . . $ $anonymous_type_5e15f442b66098d4_0#source_is_ram.) |
| 256 | GotBytecxx . . $ GotByte. = *(Input_nowcxx . . $ Input_now.->srccxx . . $ $anonymous_type_5e15f442b66098d4_0#src..ram_ptrcxx . . $ $anonymous_type_5e15f442b66098d4_0#$anonymous_type_1#ram_ptr.++); |
| 257 | // Otherwise, the source is a file. |
| 258 | else { |
| 259 | // fetch a fresh byte from the current source file |
| 260 | from_file = hacked_getccxx . . $ hacked_getc(60a5e5c04382a159).(Input_nowcxx . . $ Input_now.); |
| 261 | switch(from_file) { |
| 262 | |
| 263 | case EOFcxx . . $ `<external>/232824719582829767/stdio.h:109:9`!: |
| 264 | // remember to send an end-of-file |
| 265 | Input_nowcxx . . $ Input_now.->statecxx . . $ $anonymous_type_5e15f442b66098d4_0#state. = INPUTSTATE_EOFcxx . . $ INPUTSTATE_EOF.; |
| 266 | GotBytecxx . . $ GotByte. = CHAR_EOScxx . . $ `src/asm/input.h:48:9`!; // end of statement |
| 267 | break; |
| 268 | |
| 269 | case CHAR_LFcxx . . $ `src/asm/input.c:21:9`!:// LF character |
| 270 | // remember to send a start-of-line |
| 271 | Input_nowcxx . . $ Input_now.->statecxx . . $ $anonymous_type_5e15f442b66098d4_0#state. = INPUTSTATE_LFcxx . . $ INPUTSTATE_LF.; |
| 272 | GotBytecxx . . $ GotByte. = CHAR_EOScxx . . $ `src/asm/input.h:48:9`!; // end of statement |
| 273 | break; |
| 274 | |
| 275 | case CHAR_CRcxx . . $ `src/asm/input.c:23:9`!:// CR character |
| 276 | // remember to check for CRLF + send a start-of-line |
| 277 | Input_nowcxx . . $ Input_now.->statecxx . . $ $anonymous_type_5e15f442b66098d4_0#state. = INPUTSTATE_CRcxx . . $ INPUTSTATE_CR.; |
| 278 | GotBytecxx . . $ GotByte. = CHAR_EOScxx . . $ `src/asm/input.h:48:9`!; // end of statement |
| 279 | break; |
| 280 | |
| 281 | default: |
| 282 | GotBytecxx . . $ GotByte. = from_file; |
| 283 | } |
| 284 | |
| 285 | } |
| 286 | // now check for end of statement |
| 287 | if(GotBytecxx . . $ GotByte. == CHAR_EOScxx . . $ `src/asm/input.h:48:9`!) |
| 288 | Throw_errorcxx . . $ Throw_error(85c52e162fed56f9).("Quotes still open at end of line."); |
| 289 | return(GotBytecxx . . $ GotByte.); |
| 290 | } |
| 291 | |
| 292 | // Skip remainder of statement, for example on error |
| 293 | void Input_skip_remaindercxx . . $ Input_skip_remainder(49f6e7a06ebc5aa8).(void) { |
| 294 | while(GotBytecxx . . $ GotByte.) |
| 295 | GetBytecxx . . $ GetByte(6e9c618e4dd2eafc).();// Read characters until end-of-statement |
| 296 | } |
| 297 | |
| 298 | // Ensure that the remainder of the current statement is empty, for example |
| 299 | // after mnemonics using implied addressing. |
| 300 | void Input_ensure_EOScxx . . $ Input_ensure_EOS(49f6e7a06ebc5aa8).(void) {// Now GotByte = first char to test |
| 301 | SKIPSPACEcxx . . $ `src/asm/global.h:75:9`!(); |
| 302 | if(GotBytecxx . . $ GotByte.) { |
| 303 | Throw_errorcxx . . $ Throw_error(85c52e162fed56f9).("Garbage data at end of statement."); |
| 304 | Input_skip_remaindercxx . . $ Input_skip_remainder(49f6e7a06ebc5aa8).(); |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | // Skip or store block (starting with next byte, so call directly after |
| 309 | // reading opening brace). |
| 310 | // If "Store" is TRUE, the block is read into GlobalDynaBuf, then a copy |
| 311 | // is made and a pointer to that is returned. |
| 312 | // If "Store" is FALSE, NULL is returned. |
| 313 | // After calling this function, GotByte holds '}'. Unless EOF was found first, |
| 314 | // but then a serious error would have been thrown. |
| 315 | char* Input_skip_or_store_blockcxx . . $ Input_skip_or_store_block(cd68a792b21c61df).(boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! store) { |
| 316 | char byte; |
| 317 | int depth = 1; // to find matching block end |
| 318 | |
| 319 | // prepare global dynamic buffer |
| 320 | DYNABUF_CLEARcxx . . $ `src/asm/dynabuf.h:14:9`!(GlobalDynaBuf); |
| 321 | do { |
| 322 | byte = GetBytecxx . . $ GetByte(6e9c618e4dd2eafc).(); |
| 323 | // if wanted, store |
| 324 | if(store) |
| 325 | DYNABUF_APPENDcxx . . $ `src/asm/dynabuf.h:15:9`!(GlobalDynaBuf, byte); |
| 326 | // now check for some special characters |
| 327 | switch(byte) { |
| 328 | |
| 329 | case CHAR_EOFcxx . . $ `src/asm/input.h:52:9`!: // End-of-file in block? Sorry, no way. |
| 330 | Throw_serious_errorcxx . . $ Throw_serious_error(85c52e162fed56f9).(exception_no_right_bracecxx . . $ exception_no_right_brace.); |
| 331 | |
| 332 | case '"': // Quotes? Okay, read quoted stuff. |
| 333 | case '\'': |
| 334 | do { |
| 335 | GetQuotedBytecxx . . $ GetQuotedByte(6e9c618e4dd2eafc).(); |
| 336 | // if wanted, store |
| 337 | if(store) |
| 338 | DYNABUF_APPENDcxx . . $ `src/asm/dynabuf.h:15:9`!(GlobalDynaBuf, GotByte); |
| 339 | } while((GotBytecxx . . $ GotByte. != CHAR_EOScxx . . $ `src/asm/input.h:48:9`!) && (GotBytecxx . . $ GotByte. != byte)); |
| 340 | break; |
| 341 | |
| 342 | case CHAR_SOBcxx . . $ `src/asm/input.h:49:9`!: |
| 343 | depth++; |
| 344 | break; |
| 345 | |
| 346 | case CHAR_EOBcxx . . $ `src/asm/input.h:50:9`!: |
| 347 | depth--; |
| 348 | break; |
| 349 | |
| 350 | } |
| 351 | } while(depth); |
| 352 | // in case of skip, return now |
| 353 | if(!store) |
| 354 | return(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!); |
| 355 | // otherwise, prepare to return copy of block |
| 356 | // add EOF, just to make sure block is never read too far |
| 357 | DynaBuf_appendcxx . . $ DynaBuf_append(11d1e1bb7092144).(GlobalDynaBufcxx . . $ GlobalDynaBuf., CHAR_EOScxx . . $ `src/asm/input.h:48:9`!); |
| 358 | DynaBuf_appendcxx . . $ DynaBuf_append(11d1e1bb7092144).(GlobalDynaBufcxx . . $ GlobalDynaBuf., CHAR_EOFcxx . . $ `src/asm/input.h:52:9`!); |
| 359 | // return pointer to copy |
| 360 | return(DynaBuf_get_copycxx . . $ DynaBuf_get_copy(d7229e135d075701).(GlobalDynaBufcxx . . $ GlobalDynaBuf.)); |
| 361 | } |
| 362 | |
| 363 | // Read bytes and add to GlobalDynaBuf until the given terminator (or CHAR_EOS) |
| 364 | // is found. Act upon single and double quotes by entering (and leaving) quote |
| 365 | // mode as needed (So the terminator does not terminate when inside quotes). |
| 366 | void Input_until_terminatorcxx . . $ Input_until_terminator(44b6ea1973a07080).(char terminator) { |
| 367 | char byte = GotBytecxx . . $ GotByte.; |
| 368 | |
| 369 | do { |
| 370 | // Terminator? Exit. EndOfStatement? Exit. |
| 371 | if((byte == terminator) || (byte == CHAR_EOScxx . . $ `src/asm/input.h:48:9`!)) |
| 372 | return; |
| 373 | // otherwise, append to GlobalDynaBuf and check for quotes |
| 374 | DYNABUF_APPENDcxx . . $ `src/asm/dynabuf.h:15:9`!(GlobalDynaBuf, byte); |
| 375 | if((byte == '"') || (byte == '\'')) { |
| 376 | do { |
| 377 | // Okay, read quoted stuff. |
| 378 | GetQuotedBytecxx . . $ GetQuotedByte(6e9c618e4dd2eafc).();// throws error on EOS |
| 379 | DYNABUF_APPENDcxx . . $ `src/asm/dynabuf.h:15:9`!(GlobalDynaBuf, GotByte); |
| 380 | } while((GotBytecxx . . $ GotByte. != CHAR_EOScxx . . $ `src/asm/input.h:48:9`!) && (GotBytecxx . . $ GotByte. != byte)); |
| 381 | // on error, exit now, before calling GetByte() |
| 382 | if(GotBytecxx . . $ GotByte. != byte) |
| 383 | return; |
| 384 | } |
| 385 | byte = GetBytecxx . . $ GetByte(6e9c618e4dd2eafc).(); |
| 386 | } while(TRUEcxx . . $ `src/asm/config.h:55:9`!); |
| 387 | } |
| 388 | |
| 389 | // Append to GlobalDynaBuf while characters are legal for keywords. |
| 390 | // Throws "missing string" error if none. |
| 391 | // Returns number of characters added. |
| 392 | int Input_append_keyword_to_global_dynabufcxx . . $ Input_append_keyword_to_global_dynabuf(b126dc7c1de90089).(void) { |
| 393 | int length = 0; |
| 394 | |
| 395 | // add characters to buffer until an illegal one comes along |
| 396 | while(BYTEFLAGScxx . . $ `src/asm/global.h:42:9`!(GotByte) & CONTS_KEYWORDcxx . . $ `src/asm/global.h:44:9`!) { |
| 397 | DYNABUF_APPENDcxx . . $ `src/asm/dynabuf.h:15:9`!(GlobalDynaBuf, GotByte); |
| 398 | length++; |
| 399 | GetBytecxx . . $ GetByte(6e9c618e4dd2eafc).(); |
| 400 | } |
| 401 | if(length == 0) |
| 402 | Throw_errorcxx . . $ Throw_error(85c52e162fed56f9).(exception_missing_stringcxx . . $ exception_missing_string.); |
| 403 | return(length); |
| 404 | } |
| 405 | |
| 406 | // Check whether GotByte is a dot. |
| 407 | // If not, store global zone value. |
| 408 | // If yes, store current zone value and read next byte. |
| 409 | // Then jump to Input_read_keyword(), which returns length of keyword. |
| 410 | int Input_read_zone_and_keywordcxx . . $ Input_read_zone_and_keyword(4ebf403dd87dd80).(zone_tcxx . . $ zone_t# *zone) { |
| 411 | SKIPSPACEcxx . . $ `src/asm/global.h:75:9`!(); |
| 412 | if(GotBytecxx . . $ GotByte. == '.') { |
| 413 | GetBytecxx . . $ GetByte(6e9c618e4dd2eafc).(); |
| 414 | *zone = Section_nowcxx . . $ Section_now.->zonecxx . . $ $anonymous_type_4270326a5ce8d2d2_0#zone.; |
| 415 | } else |
| 416 | *zone = ZONE_GLOBALcxx . . $ `src/asm/section.h:23:9`!; |
| 417 | return(Input_read_keywordcxx . . $ Input_read_keyword(b126dc7c1de90089).()); |
| 418 | } |
| 419 | |
| 420 | // Clear dynamic buffer, then append to it until an illegal (for a keyword) |
| 421 | // character is read. Zero-terminate the string. Return its length (without |
| 422 | // terminator). |
| 423 | // Zero lengths will produce a "missing string" error. |
| 424 | int Input_read_keywordcxx . . $ Input_read_keyword(b126dc7c1de90089).(void) { |
| 425 | int length; |
| 426 | |
| 427 | DYNABUF_CLEARcxx . . $ `src/asm/dynabuf.h:14:9`!(GlobalDynaBuf); |
| 428 | length = Input_append_keyword_to_global_dynabufcxx . . $ Input_append_keyword_to_global_dynabuf(b126dc7c1de90089).(); |
| 429 | // add terminator to buffer (increments buffer's length counter) |
| 430 | DynaBuf_appendcxx . . $ DynaBuf_append(11d1e1bb7092144).(GlobalDynaBufcxx . . $ GlobalDynaBuf., '\0'); |
| 431 | return(length); |
| 432 | } |
| 433 | |
| 434 | // Clear dynamic buffer, then append to it until an illegal (for a keyword) |
| 435 | // character is read. Zero-terminate the string, then convert to lower case. |
| 436 | // Return its length (without terminator). |
| 437 | // Zero lengths will produce a "missing string" error. |
| 438 | int Input_read_and_lower_keywordcxx . . $ Input_read_and_lower_keyword(b126dc7c1de90089).(void) { |
| 439 | int length; |
| 440 | |
| 441 | DYNABUF_CLEARcxx . . $ `src/asm/dynabuf.h:14:9`!(GlobalDynaBuf); |
| 442 | length = Input_append_keyword_to_global_dynabufcxx . . $ Input_append_keyword_to_global_dynabuf(b126dc7c1de90089).(); |
| 443 | // add terminator to buffer (increments buffer's length counter) |
| 444 | DynaBuf_appendcxx . . $ DynaBuf_append(11d1e1bb7092144).(GlobalDynaBufcxx . . $ GlobalDynaBuf., '\0'); |
| 445 | DynaBuf_to_lowercxx . . $ DynaBuf_to_lower(a0224c2fdd28a46d).(GlobalDynaBufcxx . . $ GlobalDynaBuf., GlobalDynaBufcxx . . $ GlobalDynaBuf.);// convert to lower case |
| 446 | return(length); |
| 447 | } |
| 448 | |
| 449 | // Try to read a file name. If "allow_library" is TRUE, library access by using |
| 450 | // <...> quoting is possible as well. The file name given in the assembler |
| 451 | // source code is converted from UNIX style to platform style. |
| 452 | // Returns whether error occurred (TRUE on error). Filename in GlobalDynaBuf. |
| 453 | // Errors are handled and reported, but caller should call |
| 454 | // Input_skip_remainder() then. |
| 455 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! Input_read_filenamecxx . . $ Input_read_filename(efaadfb7dc14930a).(boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! allow_library) { |
| 456 | char *lib_prefix, |
| 457 | end_quote; |
| 458 | |
| 459 | DYNABUF_CLEARcxx . . $ `src/asm/dynabuf.h:14:9`!(GlobalDynaBuf); |
| 460 | SKIPSPACEcxx . . $ `src/asm/global.h:75:9`!(); |
| 461 | // check for library access |
| 462 | if(GotBytecxx . . $ GotByte. == '<') { |
| 463 | // if library access forbidden, complain |
| 464 | if(allow_library == FALSEcxx . . $ `src/asm/config.h:54:9`!) { |
| 465 | Throw_errorcxx . . $ Throw_error(85c52e162fed56f9).("Writing to library not supported."); |
| 466 | return(TRUEcxx . . $ `src/asm/config.h:55:9`!); |
| 467 | } |
| 468 | // read platform's lib prefix |
| 469 | lib_prefix = PLATFORM_LIBPREFIXcxx . . $ `src/asm/_std.h:20:9`!; |
| 470 | #ifndef NO_NEED_FOR_ENV_VAR |
| 471 | // if lib prefix not set, complain |
| 472 | if(lib_prefix == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) { |
| 473 | Throw_errorcxx . . $ Throw_error(85c52e162fed56f9).("\"ACME\" environment variable not found."); |
| 474 | return(TRUEcxx . . $ `src/asm/config.h:55:9`!); |
| 475 | } |
| 476 | #endif |
| 477 | // copy lib path and set quoting char |
| 478 | DynaBuf_add_stringcxx . . $ DynaBuf_add_string(9294670b9d26a99f).(GlobalDynaBufcxx . . $ GlobalDynaBuf., lib_prefix); |
| 479 | end_quote = '>'; |
| 480 | } else { |
| 481 | if(GotBytecxx . . $ GotByte. == '"') |
| 482 | end_quote = '"'; |
| 483 | else { |
| 484 | Throw_errorcxx . . $ Throw_error(85c52e162fed56f9).("File name quotes not found (\"\" or <>)."); |
| 485 | return(TRUEcxx . . $ `src/asm/config.h:55:9`!); |
| 486 | } |
| 487 | } |
| 488 | // read first character, complain if closing quote |
| 489 | if(GetQuotedBytecxx . . $ GetQuotedByte(6e9c618e4dd2eafc).() == end_quote) { |
| 490 | Throw_errorcxx . . $ Throw_error(85c52e162fed56f9).("No file name given."); |
| 491 | return(TRUEcxx . . $ `src/asm/config.h:55:9`!); |
| 492 | } |
| 493 | // read characters until closing quote (or EOS) is reached |
| 494 | // append platform-converted characters to current string |
| 495 | while((GotBytecxx . . $ GotByte. != CHAR_EOScxx . . $ `src/asm/input.h:48:9`!) && (GotBytecxx . . $ GotByte. != end_quote)) { |
| 496 | DYNABUF_APPENDcxx . . $ `src/asm/dynabuf.h:15:9`!(GlobalDynaBuf, PLATFORM_CONVERTPATHCHARcxx . . $ `src/asm/_std.h:17:9`!(GotByte)); |
| 497 | GetQuotedBytecxx . . $ GetQuotedByte(6e9c618e4dd2eafc).(); |
| 498 | } |
| 499 | // on error, return |
| 500 | if(GotBytecxx . . $ GotByte. == CHAR_EOScxx . . $ `src/asm/input.h:48:9`!) |
| 501 | return(TRUEcxx . . $ `src/asm/config.h:55:9`!); |
| 502 | GetBytecxx . . $ GetByte(6e9c618e4dd2eafc).(); // fetch next to forget closing quote |
| 503 | // terminate string |
| 504 | DynaBuf_appendcxx . . $ DynaBuf_append(11d1e1bb7092144).(GlobalDynaBufcxx . . $ GlobalDynaBuf., '\0'); // add terminator |
| 505 | return(FALSEcxx . . $ `src/asm/config.h:54:9`!); // no error |
| 506 | } |
| 507 | |
| 508 | // Try to read a comma, skipping spaces before and after. Return TRUE if comma |
| 509 | // found, otherwise FALSE. |
| 510 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! Input_accept_commacxx . . $ Input_accept_comma(c9857a73d68e59ba).(void) { |
| 511 | SKIPSPACEcxx . . $ `src/asm/global.h:75:9`!(); |
| 512 | if(GotBytecxx . . $ GotByte. != ',') |
| 513 | return(FALSEcxx . . $ `src/asm/config.h:54:9`!); |
| 514 | NEXTANDSKIPSPACEcxx . . $ `src/asm/global.h:76:9`!(); |
| 515 | return(TRUEcxx . . $ `src/asm/config.h:55:9`!); |
| 516 | } |
| 517 | |
| 518 | // read optional info about parameter length |
| 519 | int Input_get_force_bitcxx . . $ Input_get_force_bit(b126dc7c1de90089).(void) { |
| 520 | char byte; |
| 521 | int force_bit = 0; |
| 522 | |
| 523 | if(GotBytecxx . . $ GotByte. == '+') { |
| 524 | byte = GetBytecxx . . $ GetByte(6e9c618e4dd2eafc).(); |
| 525 | if(byte == '1') |
| 526 | force_bit = MVALUE_FORCE08cxx . . $ `src/asm/alu.h:35:9`!; |
| 527 | else if(byte == '2') |
| 528 | force_bit = MVALUE_FORCE16cxx . . $ `src/asm/alu.h:33:9`!; |
| 529 | else if(byte == '3') |
| 530 | force_bit = MVALUE_FORCE24cxx . . $ `src/asm/alu.h:31:9`!; |
| 531 | if(force_bit) |
| 532 | GetBytecxx . . $ GetByte(6e9c618e4dd2eafc).(); |
| 533 | else |
| 534 | Throw_errorcxx . . $ Throw_error(85c52e162fed56f9).("Illegal postfix."); |
| 535 | } |
| 536 | SKIPSPACEcxx . . $ `src/asm/global.h:75:9`!(); |
| 537 | return(force_bit); |
| 538 | } |