-
Notifications
You must be signed in to change notification settings - Fork 1
/
fdefault.c
161 lines (132 loc) · 4.34 KB
/
fdefault.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/****************************************************************************
*
* Code to provide default (nul) behavior for backends.
* Copyright (C) 2023 Sean Conner
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Comments, questions and criticisms can be sent to: sean@conman.org
*
****************************************************************************/
#include <stdlib.h>
#include <string.h>
#include "a09.h"
/**************************************************************************/
bool fdefault_cmdline(struct format *fmt,struct a09 *a09,struct arg *arg,char c)
{
(void)fmt;
(void)a09;
(void)arg;
(void)c;
return false;
}
/**************************************************************************/
bool fdefault_pass(struct format *fmt,struct a09 *a09,int pass)
{
(void)fmt;
(void)pass;
(void)a09;
return true;
}
/**************************************************************************/
bool fdefault(struct format *fmt,struct opcdata *opd)
{
(void)fmt;
(void)opd;
return true;
}
/**************************************************************************/
bool fdefault_end(struct format *fmt,struct opcdata *opd,struct symbol const *sym)
{
(void)fmt;
(void)opd;
(void)sym;
return true;
}
/**************************************************************************/
bool fdefault_write(
struct format *fmt,
struct opcdata *opd,
void const *buffer,
size_t len,
bool instruction
)
{
(void)fmt;
assert(opd != NULL);
assert(opd->pass == 2);
assert(buffer != NULL);
(void)instruction;
if (fwrite(buffer,1,len,opd->a09->out) != len)
{
if (ferror(opd->a09->out))
return message(opd->a09,MSG_ERROR,"E0040: failed writing object file");
else
return message(opd->a09,MSG_ERROR,"E0041: truncated output to object file");
}
return true;
}
/**************************************************************************/
bool fdefault__opt(struct format *fmt,struct opcdata *opd,label *tmp)
{
(void)fmt;
(void)opd;
(void)tmp;
return true;
}
/**************************************************************************/
bool fdefault__test(struct format *fmt,struct opcdata *opd)
{
(void)fmt;
assert(opd != NULL);
assert(opd->a09 != NULL);
assert((opd->pass == 1) || (opd->pass == 2));
print_list(opd->a09,opd,false);
while(!feof(opd->a09->in))
{
struct opcode const *op;
label label;
char c;
if (!read_line(opd->a09->in,&opd->a09->inbuf))
return false;
opd->a09->lnum++;
print_list(opd->a09,opd,false); // XXX extra line in list file
parse_label(&label,&opd->a09->inbuf,opd->a09,opd->pass);
c = skip_space(&opd->a09->inbuf);
if ((c == ';') || (c == '\0'))
continue;
opd->a09->inbuf.ridx--;
if (!parse_op(&opd->a09->inbuf,&op))
return message(opd->a09,MSG_ERROR,"E0003: unknown opcode");
if (memcmp(op->name,".ENDTST",8) == 0)
return true;
//print_list(opd->a09,opd,false); // XXX missing line in list file
}
return message(opd->a09,MSG_ERROR,"E0010: unexpected end of input");
}
/**************************************************************************/
bool fdefault_fini(struct format *fmt,struct a09 *a09)
{
assert(fmt != NULL);
(void)a09;
/*-----------------------------------------------------------------------
; The bin backend uses fmt->data as a flag, NOT a pointer, so we have to
; special case this here. Sigh.
;------------------------------------------------------------------------*/
if (fmt->data != NULL)
if (fmt->data != fmt)
free(fmt->data);
return true;
}
/**************************************************************************/