writing to output buffer now only happens in final pass

git-svn-id: https://svn.code.sf.net/p/acme-crossass/code-0/trunk@401 4df02467-bbd4-4a76-a152-e7ce94205b78
This commit is contained in:
marcobaye 2024-08-21 00:00:31 +00:00
parent df7f1bf06b
commit d0b1ad84b7
4 changed files with 30 additions and 20 deletions

View File

@ -333,6 +333,7 @@ static void save_output_file(void)
#define PF_COMPLAIN_ABOUT_UNDEFINEDS (1u << 0) // throw "Symbol not defined" errors
#define PF_THROW_SEGMENT_MESSAGES (1u << 1) // throw segment warnings/errors
#define PF_GENERATE_OUTPUT (1u << 2) // generate output and/or report file
// perform a single pass
static void perform_pass(bits passflags)
{
@ -399,8 +400,8 @@ static void perform_pass(bits passflags)
++pass.number;
}
static struct report global_report;
// do passes until done (or errors occurred).
static void do_actual_work(void)
{
@ -413,6 +414,9 @@ static void do_actual_work(void)
sanity.source_recursions_left = config.sanity_limit;
sanity.passes_left = config.sanity_limit;
// init output system
output_init();
// first pass:
perform_pass(PF_THROW_SEGMENT_MESSAGES); // FIXME - check segments in all passes, but only throw errors/warnings in final pass!
// pretend there has been a previous pass, with one more undefined result
@ -813,8 +817,6 @@ int main(int argc, const char *argv[])
exit(EXIT_FAILURE);
}
// init output buffer
output_createbuffer();
// do the actual work
do_actual_work();
return ACME_finalize(EXIT_SUCCESS); // dump labels, if wanted

View File

@ -124,10 +124,14 @@ static void real_output(intval_t byte)
// new maximum address?
if (out->write_idx > out->highest_written)
out->highest_written = out->write_idx;
// write byte and advance ptrs
// tell report listing about byte
if (report->fd)
report_binary(byte & 0xff); // file for reporting
out->buffer[out->write_idx++] = (byte & 0xff) ^ out->xor;
// write byte to output buffer
if (out->buffer)
out->buffer[out->write_idx] = (byte & 0xff) ^ out->xor;
// advance pointer
out->write_idx++;
++statement_size; // count this byte
}
@ -204,17 +208,6 @@ void outbuf_set_outfile_limit(void)
}
// init output struct
// FIXME - remove this, create the buffer at start of final pass instead!
void output_createbuffer(void)
{
out->buffer = safe_malloc(config.outbuf_size);
// init ring list of segments
out->segm.list_head.next = &out->segm.list_head;
out->segm.list_head.prev = &out->segm.list_head;
}
// link segment data into segment ring
static void link_segment(intval_t start, intval_t length)
{
@ -264,6 +257,16 @@ static void check_segment(intval_t new_pc)
}
// init structs
void output_init(void)
{
out->buffer = NULL;
// init ring list of segments (FIXME - move to passinit)
out->segm.list_head.next = &out->segm.list_head;
out->segm.list_head.prev = &out->segm.list_head;
}
// clear segment list and disable output
void output_passinit(void)
{
@ -271,7 +274,9 @@ void output_passinit(void)
// are we supposed to actually generate correct output?
if (pass.flags.generate_output) {
// FIXME - allocate output buffer using size info gathered in previous pass!
// allocate output buffer
// FIXME - use size info gathered in previous pass!
out->buffer = safe_malloc(config.outbuf_size);
// fill output buffer with initial byte value
if (config.mem_init_value == NO_VALUE_GIVEN) {
memset(out->buffer, 0, config.outbuf_size); // default value
@ -491,6 +496,9 @@ void output_get_result(const char **ptr, intval_t *size, intval_t *loadaddr)
limit, // end+1
amount;
if (out->buffer == NULL)
BUG("noOutBuf", 0);
start = out->lowest_written;
limit = out->highest_written + 1;
// if pseudo opcodes were used, they override the actual values:

View File

@ -19,8 +19,8 @@
// prototypes
// alloc and init mem buffer (called once on startup)
extern void output_createbuffer(void);
// init structs (called once on startup)
extern void output_init(void);
// clear segment list and disable output (called on each pass)
extern void output_passinit(void);

View File

@ -9,7 +9,7 @@
#define RELEASE "0.97" // update before release FIXME
#define CODENAME "Zem" // update before release
#define CHANGE_DATE "3 Aug" // update before release FIXME
#define CHANGE_DATE "4 Aug" // update before release FIXME
#define CHANGE_YEAR "2024" // update before release
//#define HOME_PAGE "http://home.pages.de/~mac_bacon/smorbrod/acme/"
#define HOME_PAGE "http://sourceforge.net/p/acme-crossass/" // FIXME