Debian Codegraph @

src/asm/acme.c

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 //cxx . . $ `<file>/src/asm/acme.c`/
2 // ACME - a crossassembler for producing 6502/65c02/65816 code.
3 // Copyright (C) 1998-2006 Marco Baye
4 //
5 // Modified by abaddon 2013
6 //
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either version 2 of the License, or
10 // (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
21 #define RELEASEcxx . . $ `src/asm/acme.c:21:9`! "0.93" // update before release (FIXME)
22 #define CODENAMEcxx . . $ `src/asm/acme.c:22:9`! "Zarquon" // update before release
23 #define CHANGE_DATEcxx . . $ `src/asm/acme.c:23:9`! "11 Oct" // update before release
24 #define CHANGE_YEARcxx . . $ `src/asm/acme.c:24:9`! "2006" // update before release
25 #define HOME_PAGEcxx . . $ `src/asm/acme.c:25:9`! "http://home.pages.de/~mac_bacon/smorbrod/acme/"
26
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include <setjmp.h>
31 #include "acme.h"cxx . . $ `<file>/src/asm/acme.h`/
32 #include "alu.h"cxx . . $ `<file>/src/asm/alu.h`/
33 #include "basics.h"cxx . . $ `<file>/src/asm/basics.h`/
34 #include "config.h"cxx . . $ `<file>/src/asm/config.h`/
35 #include "cpu.h"cxx . . $ `<file>/src/asm/cpu.h`/
36 #include "dynabuf.h"cxx . . $ `<file>/src/asm/dynabuf.h`/
37 #include "encoding.h"cxx . . $ `<file>/src/asm/encoding.h`/
38 #include "flow.h"cxx . . $ `<file>/src/asm/flow.h`/
39 #include "global.h"cxx . . $ `<file>/src/asm/global.h`/
40 #include "input.h"cxx . . $ `<file>/src/asm/input.h`/
41 #include "label.h"cxx . . $ `<file>/src/asm/label.h`/
42 #include "macro.h"cxx . . $ `<file>/src/asm/macro.h`/
43 #include "mnemo.h"cxx . . $ `<file>/src/asm/mnemo.h`/
44 #include "output.h"cxx . . $ `<file>/src/asm/output.h`/
45 #include "platform.h"cxx . . $ `<file>/src/asm/platform.h`/
46 #include "section.h"cxx . . $ `<file>/src/asm/section.h`/
47
48
49 // Constants
50 static const char FILE_WRITETEXTcxx . . $ FILE_WRITETEXT.[] = "w";
51 static const char FILE_WRITEBINARYcxx . . $ FILE_WRITEBINARY.[] = "wb";
52 // names for error messages
53 static const char name_outfilecxx . . $ name_outfile.[] = "output filename";
54 static const char name_dumpfilecxx . . $ name_dumpfile.[] = "label dump filename";
55 // long options
56 #define OPTION_HELPcxx . . $ `src/asm/acme.c:56:9`! "help"
57 #define OPTION_FORMATcxx . . $ `src/asm/acme.c:57:9`! "format"
58 #define OPTION_OUTFILEcxx . . $ `src/asm/acme.c:58:9`! "outfile"
59 #define OPTION_LABELDUMPcxx . . $ `src/asm/acme.c:59:9`! "labeldump"
60 #define OPTION_SETPCcxx . . $ `src/asm/acme.c:60:9`! "setpc"
61 #define OPTION_CPUcxx . . $ `src/asm/acme.c:61:9`! "cpu"
62 #define OPTION_INITMEMcxx . . $ `src/asm/acme.c:62:9`! "initmem"
63 #define OPTION_MAXERRORScxx . . $ `src/asm/acme.c:63:9`! "maxerrors"
64 #define OPTION_MAXDEPTHcxx . . $ `src/asm/acme.c:64:9`! "maxdepth"
65 #define OPTION_USE_STDOUTcxx . . $ `src/asm/acme.c:65:9`! "use-stdout"
66 #define OPTION_VERSIONcxx . . $ `src/asm/acme.c:66:9`! "version"
67
68
69 // Variables
70 static signed long start_addrcxx . . $ start_addr. = -1; // <0 is illegal
71 static signed long fill_valuecxx . . $ fill_value. = MEMINIT_USE_DEFAULTcxx . . $ `src/asm/output.h:15:9`!;
72 static struct cpu_tcxx . . $ cpu_t# *default_cpucxx . . $ default_cpu. = NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!;
73 const char* labeldump_filenamecxx . . $ labeldump_filename. = NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!;
74 const char* output_filenamecxx . . $ output_filename. = NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!;
75 const char* sourcecxx . . $ source. = NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!;
76 // maximum recursion depth for macro calls and "!source"
77 signed long macro_recursions_leftcxx . . $ macro_recursions_left. = MAX_NESTINGcxx . . $ `src/asm/config.h:42:9`!;
78 signed long source_recursions_leftcxx . . $ source_recursions_left. = MAX_NESTINGcxx . . $ `src/asm/config.h:42:9`!;
79
80
81 // Perform a single pass. Returns number of "NeedValue" type errors.
82 static int perform_passcxx . . $ perform_pass(b126dc7c1de90089).(void) {
83 // call modules' "pass init" functions
84 CPU_passinitcxx . . $ CPU_passinit(39d502d8bb4d749b).(default_cpucxx . . $ default_cpu.);// set default cpu values (PC undefined)
85 Output_passinitcxx . . $ Output_passinit(1624ee8275b10bda).(start_addrcxx . . $ start_addr.);// call after CPU_passinit(), to define PC
86 Encoding_passinitcxx . . $ Encoding_passinit(49f6e7a06ebc5aa8).(); // set default encoding
87 Section_passinitcxx . . $ Section_passinit(49f6e7a06ebc5aa8).(); // set initial zone (untitled)
88 // init variables
89 pass_undefined_countcxx . . $ pass_undefined_count. = 0; // no "NeedValue" errors yet
90 pass_real_errorscxx . . $ pass_real_errors. = 0; // no real errors yet
91 Parse_sourcecxx . . $ Parse_source(85c52e162fed56f9).(sourcecxx . . $ source.);
92 if(pass_real_errorscxx . . $ pass_real_errors.) {
93 longjmpcxx . . $ longjmp(d25daf25a2f573dc).(exception_envcxx . . $ exception_env., 0);
94 } else
95 Output_end_segmentcxx . . $ Output_end_segment(49f6e7a06ebc5aa8).();
96 return(pass_undefined_countcxx . . $ pass_undefined_count.);
97 }
98
99 // do passes until done (or errors occured). Return whether output is ready.
100 static boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! do_actual_workcxx . . $ do_actual_work(c9857a73d68e59ba).(void) {
101 int undefined_prev, // "NeedValue" errors of previous pass
102 undefined_curr; // "NeedValue" errors of current pass
103
104 if(Process_verbositycxx . . $ Process_verbosity. > 1)
105 putscxx . . $ puts(5c4306d8553b3696).("First pass.");
106 pass_countcxx . . $ pass_count. = 0;
107 undefined_curr = perform_passcxx . . $ perform_pass(b126dc7c1de90089).(); // First pass
108 // now pretend there has been a pass before the first one
109 undefined_prev = undefined_curr + 1;
110 // As long as the number of "NeedValue" errors is decreasing but
111 // non-zero, keep doing passes.
112 while(undefined_curr && (undefined_curr < undefined_prev)) {
113 pass_countcxx . . $ pass_count.++;
114 undefined_prev = undefined_curr;
115 if(Process_verbositycxx . . $ Process_verbosity. > 1)
116 putscxx . . $ puts(5c4306d8553b3696).("Further pass.");
117 undefined_curr = perform_passcxx . . $ perform_pass(b126dc7c1de90089).();
118 }
119 // If still errors (unsolvable by doing further passes),
120 // perform additional pass to find and show them
121 if(undefined_curr == 0)
122 return(TRUEcxx . . $ `src/asm/config.h:55:9`!);
123 if(Process_verbositycxx . . $ Process_verbosity. > 1)
124 putscxx . . $ puts(5c4306d8553b3696).("Further pass needed to find error.");
125 ALU_throw_errorscxx . . $ ALU_throw_errors(49f6e7a06ebc5aa8).(); // activate error output (CAUTION - one-way!)
126 pass_countcxx . . $ pass_count.++;
127 perform_passcxx . . $ perform_pass(b126dc7c1de90089).(); // perform pass, but now show "value undefined"
128 return(FALSEcxx . . $ `src/asm/config.h:54:9`!);
129 }
130
•131 char* acme_assemblecxx . . $ acme_assemble(18337976b12b149b).(const char* src, int *length, char *error) {
132 error_messagecxx . . $ error_message. = error;
133 sourcecxx . . $ source. = src;
134 msg_streamcxx . . $ msg_stream. = stdoutcxx . . $ `<external>/232824719582829767/stdio.h:158:9`!;
135 DynaBuf_initcxx . . $ DynaBuf_init(49f6e7a06ebc5aa8).();// inits *global* dynamic buffer - important, so first
136 // Init platform-specific stuff.
137 // For example, this could read the library path from an
138 // environment variable, which in turn may need DynaBuf already.
139 PLATFORM_INITcxx . . $ `src/asm/_std.h:14:9`!;
140 // init some keyword trees needed for argument handling
141 CPUtype_initcxx . . $ CPUtype_init(49f6e7a06ebc5aa8).();
142 Outputfile_initcxx . . $ Outputfile_init(49f6e7a06ebc5aa8).();
143 // Init modules (most of them will just build keyword trees)
144 ALU_initcxx . . $ ALU_init(49f6e7a06ebc5aa8).();
145 Basics_initcxx . . $ Basics_init(49f6e7a06ebc5aa8).();
146 CPU_initcxx . . $ CPU_init(49f6e7a06ebc5aa8).();
147 Encoding_initcxx . . $ Encoding_init(49f6e7a06ebc5aa8).();
148 Flow_initcxx . . $ Flow_init(49f6e7a06ebc5aa8).();
149 Input_initcxx . . $ Input_init(49f6e7a06ebc5aa8).();
150 Label_initcxx . . $ Label_init(49f6e7a06ebc5aa8).();
151 Macro_initcxx . . $ Macro_init(49f6e7a06ebc5aa8).();
152 Mnemo_initcxx . . $ Mnemo_init(49f6e7a06ebc5aa8).();
153 Output_initcxx . . $ Output_init(1624ee8275b10bda).(fill_valuecxx . . $ fill_value.);
154 Section_initcxx . . $ Section_init(49f6e7a06ebc5aa8).();
155 if(!setjmpcxx . . $ `<external>/4367339001007250937/setjmp.h:53:9`!(exception_env)) {
156 if(do_actual_workcxx . . $ do_actual_work(c9857a73d68e59ba).()) {
157 return Output_get_final_datacxx . . $ Output_get_final_data(3f31f7b3b80edb32).(length);
158 }
159 }
160 return NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!;
161 }