Debian Codegraph @

src/asm/section.c

raw symbols SCIP
1 //cxx . . $ `<file>/src/asm/section.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 // Section stuff
7
8 #include "config.h"cxx . . $ `<file>/src/asm/config.h`/
9 #include "dynabuf.h"cxx . . $ `<file>/src/asm/dynabuf.h`/
10 #include "global.h"cxx . . $ `<file>/src/asm/global.h`/
11 #include "input.h"cxx . . $ `<file>/src/asm/input.h`/
12 #include "tree.h"cxx . . $ `<file>/src/asm/tree.h`/
13 #include "section.h"cxx . . $ `<file>/src/asm/section.h`/
14
15
16 // Constants
17 static const char type_zonecxx . . $ type_zone.[] = "Zone";
18 static const char s_subzonecxx . . $ s_subzone.[] = "subzone";
19 #define s_zonecxx . . $ `src/asm/section.c:19:9`! (s_subzone+3) // Yes, I know I'm sick
20 static char untitledcxx . . $ untitled.[] = "<untitled>";
21 // ...is actually constant, but flagging it "const" results in heap of warnings
22
23 // fake section structure (for error msgs before any real section is in use)
24 static section_tcxx . . $ section_t# initial_sectioncxx . . $ initial_section. = {
25 0, // zone value
26 "during", // "type" => normally "zone Title" or
27 "init", // "title" => "macro test", now "during init"
28 FALSEcxx . . $ `src/asm/config.h:54:9`!, // no, title was not malloc'd
29 };
30
31
32 // Variables
33 section_tcxx . . $ section_t#* Section_nowcxx . . $ Section_now. = &initial_sectioncxx . . $ initial_section.;// current section
34 static section_tcxx . . $ section_t# outer_sectioncxx . . $ outer_section.; // outermost section struct
35 static zone_tcxx . . $ zone_t# zone_maxcxx . . $ zone_max.; // Highest zone number yet
36
37 // Write given info into given zone structure and activate it
38 void Section_new_zonecxx . . $ Section_new_zone(ef0b653b3680aef).(section_tcxx . . $ section_t#* section, const char* type, char* title, boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! allocated) {
39 section->zonecxx . . $ $anonymous_type_4270326a5ce8d2d2_0#zone. = ++zone_maxcxx . . $ zone_max.;
40 section->typecxx . . $ $anonymous_type_4270326a5ce8d2d2_0#type. = type;
41 section->titlecxx . . $ $anonymous_type_4270326a5ce8d2d2_0#title. = title;
42 section->allocatedcxx . . $ $anonymous_type_4270326a5ce8d2d2_0#allocated. = allocated;
43 // activate new section
44 Section_nowcxx . . $ Section_now. = section;
45 }
46
47 // Tidy up: If necessary, release section title.
48 // Warning - the state of the component "Allocd" may have
49 // changed in the meantime, so don't rely on a local variable.
50 void Section_finalizecxx . . $ Section_finalize(91b759fd9e8cb2c0).(section_tcxx . . $ section_t#* section) {
51 if(section->allocatedcxx . . $ $anonymous_type_4270326a5ce8d2d2_0#allocated.)
52 freecxx . . $ free(5d22bdacc48458e8).(section->titlecxx . . $ $anonymous_type_4270326a5ce8d2d2_0#title.);
53 }
54
55 // Switch to new zone ("!zone" or "!zn"). Has to be re-entrant.
56 static enum eos_tcxx . . $ eos_t# PO_zonecxx . . $ PO_zone(6522f478c9c0d97c).(void) {
57 section_tcxx . . $ section_t# entry_values;// buffer for outer zone
58 char* new_title;
59 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! allocated;
60
61 // remember everything about current structure
62 entry_values = *Section_nowcxx . . $ Section_now.;
63 // set default values in case there is no valid title
64 new_title = untitledcxx . . $ untitled.;
65 allocated = FALSEcxx . . $ `src/asm/config.h:54:9`!;
66 // Check whether a zone title is given. If yes and it can be read,
67 // get copy, remember pointer and remember to free it later on.
68 if(BYTEFLAGScxx . . $ `src/asm/global.h:42:9`!(GotByte) & CONTS_KEYWORDcxx . . $ `src/asm/global.h:44:9`!) {
69 // Because we know of one character for sure,
70 // there's no need to check the return value.
71 Input_read_keywordcxx . . $ Input_read_keyword(b126dc7c1de90089).();
72 new_title = DynaBuf_get_copycxx . . $ DynaBuf_get_copy(d7229e135d075701).(GlobalDynaBufcxx . . $ GlobalDynaBuf.);
73 allocated = TRUEcxx . . $ `src/asm/config.h:55:9`!;
74 }
75 // setup new section
76 // section type is "subzone", just in case a block follows
77 Section_new_zonecxx . . $ Section_new_zone(ef0b653b3680aef).(Section_nowcxx . . $ Section_now., "Subzone", new_title, allocated);
78 if(Parse_optional_blockcxx . . $ Parse_optional_block(c9857a73d68e59ba).()) {
79 // Block has been parsed, so it was a SUBzone.
80 Section_finalizecxx . . $ Section_finalize(91b759fd9e8cb2c0).(Section_nowcxx . . $ Section_now.);// end inner zone
81 *Section_nowcxx . . $ Section_now. = entry_values;// restore entry values
82 } else {
83 // no block found, so it's a normal zone change
84 Section_finalizecxx . . $ Section_finalize(91b759fd9e8cb2c0).(&entry_values);// end outer zone
85 Section_nowcxx . . $ Section_now.->typecxx . . $ $anonymous_type_4270326a5ce8d2d2_0#type. = type_zonecxx . . $ type_zone.;// change type to "zone"
86 }
87 return(ENSURE_EOScxx . . $ ENSURE_EOS.);
88 }
89
90 // Start subzone ("!subzone" or "!sz"). Has to be re-entrant.
91 static enum eos_tcxx . . $ eos_t# PO_subzonecxx . . $ PO_subzone(6522f478c9c0d97c).(void) {
92 // output deprecation warning
93 Throw_first_pass_warningcxx . . $ Throw_first_pass_warning(85c52e162fed56f9).("\"!subzone {}\" is deprecated; use \"!zone {}\" instead.");
94 // call "!zone" instead
95 return(PO_zonecxx . . $ PO_zone(6522f478c9c0d97c).());
96 }
97
98 // predefined stuff
99 static node_tcxx . . $ node_t# pseudo_opcodescxx . . $ pseudo_opcodes.[] = {
100 PREDEFNODEcxx . . $ `src/asm/tree.h:15:9`!(s_zonecxx . . $ `src/asm/section.c:19:9`!, PO_zone),
101 PREDEFNODEcxx . . $ `src/asm/tree.h:15:9`!("zn", PO_zone),
102 PREDEFNODEcxx . . $ `src/asm/tree.h:15:9`!(s_subzone, PO_subzone),
103 PREDEFLASTcxx . . $ `src/asm/tree.h:16:9`!("sz", PO_subzone),
104 // ^^^^ this marks the last element
105 };
106
107 // register pseudo opcodes
108 void Section_initcxx . . $ Section_init(49f6e7a06ebc5aa8).(void) {
109 Tree_add_tablecxx . . $ Tree_add_table(90ba9e887489f1c).(&pseudo_opcode_treecxx . . $ pseudo_opcode_tree., pseudo_opcodescxx . . $ pseudo_opcodes.);
110 }
111
112 // Setup outermost section
113 void Section_passinitcxx . . $ Section_passinit(49f6e7a06ebc5aa8).(void) {
114 zone_maxcxx . . $ zone_max. = ZONE_GLOBALcxx . . $ `src/asm/section.h:23:9`!;// will be incremented by next line
115 Section_new_zonecxx . . $ Section_new_zone(ef0b653b3680aef).(&outer_sectioncxx . . $ outer_section., type_zonecxx . . $ type_zone., untitledcxx . . $ untitled., FALSEcxx . . $ `src/asm/config.h:54:9`!);
116 }