Debian Codegraph @

src/section.c

raw symbols SCIP
1 // ACME - a crossassembler for producing 6502/65c02/65816/65ce02 code.
2 // Copyright (C) 1998-2020 Marco Baye
3 // Have a look at "acme.c" for further info
4 //
5 // section stuff (move to symbol.h?)
6 #include "section.h"
7 #include "config.h"
8 #include "dynabuf.h"
9 #include "global.h"
10 #include "input.h"
11 #include "symbol.h"
12 #include "tree.h"
13
14
15 #define SCOPE_INCREMENT 2 // inc by 2 so locals are even and cheaps are odd
16
17 // fake section structure (for error msgs before any real section is in use)
18 static struct section initial_section = {
19 0, // local scope value
20 1, // cheap scope value
21 "during", // "type" => normally "zone Title" or
22 "init", // "title" => "macro test", now "during init"
23 FALSE, // no, title was not malloc'd
24 };
25
26
27 // variables
28 struct section *section_now = &initial_section; // current section
29 static struct section outer_section; // outermost section struct
30 static scope_t local_scope_max; // highest scope number yet
31 static scope_t cheap_scope_max; // highest scope number yet
32
33
34 // write given info into given structure and activate it
35 void section_new(struct section *section, const char *type, char *title, boolean allocated)
36 {
37 // new scope for locals
38 local_scope_max += SCOPE_INCREMENT;
39 section->local_scope = local_scope_max;
40 // keep scope for cheap locals
41 section->cheap_scope = section_now->cheap_scope;
42 // copy other data
43 section->type = type;
44 section->title = title;
45 section->allocated = allocated;
46 // activate new section
47 section_now = section;
48 //printf("[new section %d: %s, %s]\n", section->local_scope, section->type, section->title);
49 }
50
51
52 // change scope of cheap locals in given section
53 void section_new_cheap_scope(struct section *section)
54 {
55 // new scope for cheap locals
56 cheap_scope_max += SCOPE_INCREMENT;
57 section->cheap_scope = cheap_scope_max;
58 }
59
60
61 // Tidy up: If necessary, release section title.
62 // Warning - the state of the component "Allocd" may have
63 // changed in the meantime, so don't rely on a local variable.
64 void section_finalize(struct section *section)
65 {
66 if (section->allocated)
67 free(section->title);
68 }
69
70
71 // setup outermost section
72 void section_passinit(void)
73 {
74 //printf("[old maxima: locals=%d, cheap=%d]\n", local_scope_max, cheap_scope_max);
75 local_scope_max = 0; // will be incremented by 2 by next line
76 section_new(&outer_section, "Zone", s_untitled, FALSE);
77 cheap_scope_max = -1; // will be incremented by 2 by next line
78 section_new_cheap_scope(&outer_section);
79 }