2016-12-28 20:32:00 +00:00
|
|
|
// ACME - a crossassembler for producing 6502/65c02/65816/65ce02 code.
|
2016-08-05 09:59:07 +00:00
|
|
|
// Copyright (C) 1998-2016 Marco Baye
|
2012-02-27 21:14:46 +00:00
|
|
|
// Have a look at "acme.c" for further info
|
|
|
|
//
|
2016-08-05 09:59:07 +00:00
|
|
|
// section stuff (move to symbol.h?)
|
2014-12-22 00:47:52 +00:00
|
|
|
#include "section.h"
|
2012-02-27 21:14:46 +00:00
|
|
|
#include "config.h"
|
|
|
|
#include "dynabuf.h"
|
2014-12-03 22:18:06 +00:00
|
|
|
#include "global.h" // FIXME - remove when no longer needed
|
2012-02-27 21:14:46 +00:00
|
|
|
#include "input.h"
|
2016-08-05 09:59:07 +00:00
|
|
|
#include "symbol.h"
|
2012-02-27 21:14:46 +00:00
|
|
|
#include "tree.h"
|
|
|
|
|
|
|
|
|
|
|
|
// fake section structure (for error msgs before any real section is in use)
|
2014-03-11 12:07:11 +00:00
|
|
|
static struct section initial_section = {
|
2016-08-05 09:59:07 +00:00
|
|
|
0, // scope value
|
2012-02-27 21:14:46 +00:00
|
|
|
"during", // "type" => normally "zone Title" or
|
|
|
|
"init", // "title" => "macro test", now "during init"
|
|
|
|
FALSE, // no, title was not malloc'd
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-08-05 09:59:07 +00:00
|
|
|
// variables
|
|
|
|
struct section *section_now = &initial_section; // current section
|
2014-03-11 12:07:11 +00:00
|
|
|
static struct section outer_section; // outermost section struct
|
2016-08-05 09:59:07 +00:00
|
|
|
static scope_t scope_localcount; // highest scope number yet
|
2012-02-27 21:14:46 +00:00
|
|
|
|
2016-08-05 09:59:07 +00:00
|
|
|
|
|
|
|
// write given info into given structure and activate it
|
|
|
|
void section_new(struct section *section, const char *type, char *title, int allocated)
|
2012-02-27 21:14:46 +00:00
|
|
|
{
|
2016-08-05 09:59:07 +00:00
|
|
|
section->scope = ++scope_localcount;
|
2012-02-27 21:14:46 +00:00
|
|
|
section->type = type;
|
|
|
|
section->title = title;
|
|
|
|
section->allocated = allocated;
|
|
|
|
// activate new section
|
2016-08-05 09:59:07 +00:00
|
|
|
section_now = section;
|
|
|
|
//printf("[new zone %d: %s, %s]\n", section->scope, section->type, section->title);
|
2012-02-27 21:14:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Tidy up: If necessary, release section title.
|
|
|
|
// Warning - the state of the component "Allocd" may have
|
|
|
|
// changed in the meantime, so don't rely on a local variable.
|
2016-08-05 09:59:07 +00:00
|
|
|
void section_finalize(struct section *section)
|
2012-02-27 21:14:46 +00:00
|
|
|
{
|
|
|
|
if (section->allocated)
|
|
|
|
free(section->title);
|
|
|
|
}
|
|
|
|
|
2016-08-05 09:59:07 +00:00
|
|
|
// setup outermost section
|
|
|
|
void section_passinit(void)
|
2012-02-27 21:14:46 +00:00
|
|
|
{
|
2016-08-05 09:59:07 +00:00
|
|
|
scope_localcount = SCOPE_GLOBAL; // will be incremented by next line
|
|
|
|
section_new(&outer_section, s_Zone, s_untitled, FALSE);
|
2012-02-27 21:14:46 +00:00
|
|
|
}
|