Skip to content

Commit 285492e

Browse files
committed
Refactor out EntryPage and Cpu from Table
1 parent 1d6b050 commit 285492e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+906
-986
lines changed

src/asm_mc6809.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,9 @@ void AsmMc6809::encodeIndexed(AsmInsn &insn, const Operand &op) const {
182182
}
183183
spec.size = size;
184184
}
185-
const auto postSpec = TABLE.searchPostSpec(cpuType(), spec);
186-
if (postSpec < 0)
185+
if (TABLE.searchPostSpec(cpuType(), spec))
187186
insn.setErrorIf(op, UNKNOWN_OPERAND);
188-
uint8_t post = postSpec;
187+
uint8_t post = spec.post;
189188
const auto size = spec.size;
190189
if (size == 5)
191190
post |= disp & 0x1F;

src/table_cdp1802.cpp

+15-21
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,19 @@
1616

1717
#include "table_cdp1802.h"
1818
#include "entry_cdp1802.h"
19-
#include "entry_table.h"
2019
#include "text_cdp1802.h"
2120

2221
using namespace libasm::text::cdp1802;
2322

2423
namespace libasm {
2524
namespace cdp1802 {
2625

27-
#define E2(_opc, _name, _op1, _op2) \
28-
{ _opc, Entry::Flags::create(_op1, _op2), _name }
26+
#define E2(_opc, _name, _op1, _op2) {_opc, Entry::Flags::create(_op1, _op2), _name}
2927
#define E1(_opc, _name, _op1) E2(_opc, _name, _op1, M_NONE)
3028
#define E0(_opc, _name) E1(_opc, _name, M_NONE)
3129

3230
// clang-format off
33-
static constexpr Entry TABLE_CDP1802[] PROGMEM = {
31+
constexpr Entry TABLE_CDP1802[] PROGMEM = {
3432
E0(0x00, TEXT_IDL),
3533
E1(0x00, TEXT_LDN, M_REG1),
3634
E1(0x10, TEXT_INC, M_REGN),
@@ -124,7 +122,7 @@ static constexpr Entry TABLE_CDP1802[] PROGMEM = {
124122
E1(0xFF, TEXT_SMI, M_IMM8),
125123
};
126124

127-
static constexpr uint8_t INDEX_CDP1802[] PROGMEM = {
125+
constexpr uint8_t INDEX_CDP1802[] PROGMEM = {
128126
34, // TEXT_ADC
129127
43, // TEXT_ADCI
130128
79, // TEXT_ADD
@@ -218,7 +216,7 @@ static constexpr uint8_t INDEX_CDP1802[] PROGMEM = {
218216
86, // TEXT_XRI
219217
};
220218

221-
static constexpr Entry TABLE_CDP1804[] PROGMEM = {
219+
constexpr Entry TABLE_CDP1804[] PROGMEM = {
222220
E0(0x00, TEXT_STPC),
223221
E0(0x01, TEXT_DTC),
224222
E0(0x02, TEXT_SPM2),
@@ -243,7 +241,7 @@ static constexpr Entry TABLE_CDP1804[] PROGMEM = {
243241
E2(0xC0, TEXT_RLDI, M_REGN, M_ADDR),
244242
};
245243

246-
static constexpr uint8_t INDEX_CDP1804[] PROGMEM = {
244+
constexpr uint8_t INDEX_CDP1804[] PROGMEM = {
247245
14, // TEXT_BCI
248246
15, // TEXT_BXI
249247
13, // TEXT_CID
@@ -268,7 +266,7 @@ static constexpr uint8_t INDEX_CDP1804[] PROGMEM = {
268266
10, // TEXT_XIE
269267
};
270268

271-
static constexpr Entry TABLE_CDP1804A[] PROGMEM = {
269+
constexpr Entry TABLE_CDP1804A[] PROGMEM = {
272270
E2(0x20, TEXT_DBNZ, M_REGN, M_ADDR),
273271
E0(0x74, TEXT_DADC),
274272
E0(0x76, TEXT_DSAV),
@@ -281,7 +279,7 @@ static constexpr Entry TABLE_CDP1804A[] PROGMEM = {
281279
E1(0xFF, TEXT_DSMI, M_IMM8),
282280
};
283281

284-
static constexpr uint8_t INDEX_CDP1804A[] PROGMEM = {
282+
constexpr uint8_t INDEX_CDP1804A[] PROGMEM = {
285283
4, // TEXT_DACI
286284
1, // TEXT_DADC
287285
6, // TEXT_DADD
@@ -295,36 +293,32 @@ static constexpr uint8_t INDEX_CDP1804A[] PROGMEM = {
295293
};
296294
// clang-format on
297295

298-
using EntryPage = entry::PrefixTableBase<Entry>;
299-
300-
static constexpr EntryPage CDP1802_PAGES[] PROGMEM = {
296+
constexpr EntryPage CDP1802_PAGES[] PROGMEM = {
301297
{0x00, ARRAY_RANGE(TABLE_CDP1802), ARRAY_RANGE(INDEX_CDP1802)},
302298
};
303299

304-
static constexpr EntryPage CDP1804_PAGES[] PROGMEM = {
300+
constexpr EntryPage CDP1804_PAGES[] PROGMEM = {
305301
{0x00, ARRAY_RANGE(TABLE_CDP1802), ARRAY_RANGE(INDEX_CDP1802)},
306302
{0x68, ARRAY_RANGE(TABLE_CDP1804), ARRAY_RANGE(INDEX_CDP1804)},
307303
};
308304

309-
static constexpr EntryPage CDP1804A_PAGES[] PROGMEM = {
305+
constexpr EntryPage CDP1804A_PAGES[] PROGMEM = {
310306
{0x00, ARRAY_RANGE(TABLE_CDP1802), ARRAY_RANGE(INDEX_CDP1802)},
311307
{0x68, ARRAY_RANGE(TABLE_CDP1804), ARRAY_RANGE(INDEX_CDP1804)},
312308
{0x68, ARRAY_RANGE(TABLE_CDP1804A), ARRAY_RANGE(INDEX_CDP1804A)},
313309
};
314310

315-
using Cpu = entry::CpuBase<CpuType, EntryPage>;
316-
317-
static constexpr Cpu CPU_TABLE[] PROGMEM = {
311+
constexpr Cpu CPU_TABLE[] PROGMEM = {
318312
{CDP1802, TEXT_CPU_1802, ARRAY_RANGE(CDP1802_PAGES)},
319313
{CDP1804, TEXT_CPU_1804, ARRAY_RANGE(CDP1804_PAGES)},
320314
{CDP1804A, TEXT_CPU_1804A, ARRAY_RANGE(CDP1804A_PAGES)},
321315
};
322316

323-
static const Cpu *cpu(CpuType cpuType) {
317+
const Cpu *cpu(CpuType cpuType) {
324318
return Cpu::search(cpuType, ARRAY_RANGE(CPU_TABLE));
325319
}
326320

327-
static bool acceptMode(AddrMode opr, AddrMode table) {
321+
bool acceptMode(AddrMode opr, AddrMode table) {
328322
if (opr == table)
329323
return true;
330324
if (opr == M_REGN)
@@ -335,7 +329,7 @@ static bool acceptMode(AddrMode opr, AddrMode table) {
335329
return false;
336330
}
337331

338-
static bool acceptModes(AsmInsn &insn, const Entry *entry) {
332+
bool acceptModes(AsmInsn &insn, const Entry *entry) {
339333
const auto table = entry->readFlags();
340334
return acceptMode(insn.op1.mode, table.mode1()) && acceptMode(insn.op2.mode, table.mode2());
341335
}
@@ -345,7 +339,7 @@ Error TableCdp1802::searchName(CpuType cpuType, AsmInsn &insn) const {
345339
return insn.getError();
346340
}
347341

348-
static bool matchOpCode(DisInsn &insn, const Entry *entry, const EntryPage *) {
342+
bool matchOpCode(DisInsn &insn, const Entry *entry, const EntryPage *) {
349343
auto opc = insn.opCode();
350344
auto flags = entry->readFlags();
351345
auto mode = flags.mode1();

src/table_cdp1802.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,15 @@
1818
#define __LIBASM_TABLE_CDP1802_H__
1919

2020
#include "config_cdp1802.h"
21+
#include "entry_table.h"
2122
#include "insn_cdp1802.h"
22-
#include "str_buffer.h"
2323

2424
namespace libasm {
2525
namespace cdp1802 {
2626

27+
using EntryPage = entry::PrefixTableBase<Entry>;
28+
using Cpu = entry::CpuBase<CpuType, EntryPage>;
29+
2730
struct TableCdp1802 final : InsnTable<CpuType> {
2831
const /*PROGMEM*/ char *listCpu_P() const override;
2932
const /*PROGMEM*/ char *cpuName_P(CpuType cpuType) const override;

src/table_f3850.cpp

+9-15
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,19 @@
1616

1717
#include "table_f3850.h"
1818
#include "entry_f3850.h"
19-
#include "entry_table.h"
2019
#include "text_f3850.h"
2120

2221
using namespace libasm::text::f3850;
2322

2423
namespace libasm {
2524
namespace f3850 {
2625

27-
#define E2(_opc, _name, _mode1, _mode2) \
28-
{ _opc, Entry::Flags::create(_mode1, _mode2), _name }
26+
#define E2(_opc, _name, _mode1, _mode2) {_opc, Entry::Flags::create(_mode1, _mode2), _name}
2927
#define E1(_opc, _name, _mode1) E2(_opc, _name, _mode1, M_NONE)
3028
#define E0(_opc, _name) E1(_opc, _name, M_NONE)
3129

3230
// clang-format off
33-
static constexpr Entry TABLE_3850[] PROGMEM = {
31+
constexpr Entry TABLE_3850[] PROGMEM = {
3432
E2(0x00, TEXT_LR, M_A, M_KU),
3533
E2(0x01, TEXT_LR, M_A, M_KL),
3634
E2(0x02, TEXT_LR, M_A, M_QU),
@@ -109,7 +107,7 @@ static constexpr Entry TABLE_3850[] PROGMEM = {
109107
E1(0xF0, TEXT_NS, M_REG),
110108
};
111109

112-
static constexpr uint8_t INDEX_3850[] PROGMEM = {
110+
constexpr uint8_t INDEX_3850[] PROGMEM = {
113111
61, // TEXT_ADC
114112
36, // TEXT_AI
115113
55, // TEXT_AM
@@ -190,19 +188,15 @@ static constexpr uint8_t INDEX_3850[] PROGMEM = {
190188

191189
// clang-format on
192190

193-
using EntryPage = entry::TableBase<Entry>;
194-
195-
static constexpr EntryPage F3850_PAGES[] PROGMEM = {
191+
constexpr EntryPage F3850_PAGES[] PROGMEM = {
196192
{ARRAY_RANGE(TABLE_3850), ARRAY_RANGE(INDEX_3850)},
197193
};
198194

199-
using Cpu = entry::CpuBase<CpuType, EntryPage>;
200-
201-
static constexpr Cpu CPU_TABLE[] PROGMEM = {
195+
constexpr Cpu CPU_TABLE[] PROGMEM = {
202196
{F3850, TEXT_CPU_3850, ARRAY_RANGE(F3850_PAGES)},
203197
};
204198

205-
static const Cpu *cpu(CpuType) {
199+
const Cpu *cpu(CpuType) {
206200
return &CPU_TABLE[0];
207201
}
208202

@@ -211,7 +205,7 @@ bool TableF3850::hasOperand(CpuType cpuType, AsmInsn &insn) const {
211205
return insn.isOK() && insn.mode1() != M_NONE;
212206
}
213207

214-
static bool acceptMode(AddrMode opr, AddrMode table) {
208+
bool acceptMode(AddrMode opr, AddrMode table) {
215209
if (opr == table)
216210
return true;
217211
if (opr == M_J)
@@ -223,7 +217,7 @@ static bool acceptMode(AddrMode opr, AddrMode table) {
223217
return false;
224218
}
225219

226-
static bool acceptModes(AsmInsn &insn, const Entry *entry) {
220+
bool acceptModes(AsmInsn &insn, const Entry *entry) {
227221
const auto table = entry->readFlags();
228222
return acceptMode(insn.op1.mode, table.mode1()) && acceptMode(insn.op2.mode, table.mode2());
229223
}
@@ -233,7 +227,7 @@ Error TableF3850::searchName(CpuType cpuType, AsmInsn &insn) const {
233227
return insn.getError();
234228
}
235229

236-
static bool matchOpCode(DisInsn &insn, const Entry *entry, const EntryPage *) {
230+
bool matchOpCode(DisInsn &insn, const Entry *entry, const EntryPage *) {
237231
auto opCode = insn.opCode();
238232
const auto flags = entry->readFlags();
239233
const auto mode1 = flags.mode1();

src/table_f3850.h

+4
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,15 @@
1818
#define __LIBASM_TABLE_F3850_H__
1919

2020
#include "config_f3850.h"
21+
#include "entry_table.h"
2122
#include "insn_f3850.h"
2223

2324
namespace libasm {
2425
namespace f3850 {
2526

27+
using EntryPage = entry::TableBase<Entry>;
28+
using Cpu = entry::CpuBase<CpuType, EntryPage>;
29+
2630
struct TableF3850 final : InsnTable<CpuType> {
2731
const /*PROGMEM*/ char *listCpu_P() const override;
2832
const /*PROGMEM*/ char *cpuName_P(CpuType cpuType) const override;

src/table_i8048.cpp

+21-27
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,19 @@
1616

1717
#include "table_i8048.h"
1818
#include "entry_i8048.h"
19-
#include "entry_table.h"
2019
#include "text_i8048.h"
2120

2221
using namespace libasm::text::i8048;
2322

2423
namespace libasm {
2524
namespace i8048 {
2625

27-
#define E2(_opc, _name, _dst, _src) \
28-
{ _opc, Entry::Flags::create(_dst, _src), _name }
26+
#define E2(_opc, _name, _dst, _src) {_opc, Entry::Flags::create(_dst, _src), _name}
2927
#define E1(_opc, _name, _dst) E2(_opc, _name, _dst, M_NONE)
3028
#define E0(_opc, _name) E1(_opc, _name, M_NONE)
3129

3230
// clang-format off
33-
static constexpr Entry TABLE_I8039[] PROGMEM = {
31+
constexpr Entry TABLE_I8039[] PROGMEM = {
3432
E2(0x68, TEXT_ADD, M_A, M_R),
3533
E2(0x60, TEXT_ADD, M_A, M_IR),
3634
E2(0x03, TEXT_ADD, M_A, M_IMM8),
@@ -121,7 +119,7 @@ static constexpr Entry TABLE_I8039[] PROGMEM = {
121119
E0(0x00, TEXT_NOP),
122120
};
123121

124-
static constexpr uint8_t INDEX_I8039[] PROGMEM = {
122+
constexpr uint8_t INDEX_I8039[] PROGMEM = {
125123
0, // TEXT_ADD
126124
1, // TEXT_ADD
127125
2, // TEXT_ADD
@@ -212,29 +210,29 @@ static constexpr uint8_t INDEX_I8039[] PROGMEM = {
212210
14, // TEXT_XRL
213211
};
214212

215-
static constexpr Entry TABLE_I8048[] PROGMEM = {
213+
constexpr Entry TABLE_I8048[] PROGMEM = {
216214
E2(0x08, TEXT_INS, M_A, M_BUS),
217215
E2(0x02, TEXT_OUTL, M_BUS, M_A),
218216
E2(0x98, TEXT_ANL, M_BUS, M_BIT8),
219217
E2(0x88, TEXT_ORL, M_BUS, M_BIT8),
220218
};
221219

222-
static constexpr uint8_t INDEX_I8048[] PROGMEM = {
220+
constexpr uint8_t INDEX_I8048[] PROGMEM = {
223221
2, // TEXT_ANL
224222
0, // TEXT_INS
225223
3, // TEXT_ORL
226224
1, // TEXT_OUTL
227225
};
228226

229-
static constexpr Entry TABLE_I80C39[] PROGMEM = {
227+
constexpr Entry TABLE_I80C39[] PROGMEM = {
230228
E0(0x01, TEXT_HALT),
231229
};
232230

233-
static constexpr uint8_t INDEX_I80C39[] PROGMEM = {
231+
constexpr uint8_t INDEX_I80C39[] PROGMEM = {
234232
0, // TEXT_HALT
235233
};
236234

237-
static constexpr Entry TABLE_MSM80C39[] PROGMEM = {
235+
constexpr Entry TABLE_MSM80C39[] PROGMEM = {
238236
E2(0x63, TEXT_MOV, M_A, M_P1),
239237
E2(0x73, TEXT_MOV, M_A, M_P2),
240238
E1(0xC0, TEXT_DEC, M_IR),
@@ -247,7 +245,7 @@ static constexpr Entry TABLE_MSM80C39[] PROGMEM = {
247245
E0(0xE2, TEXT_FRES),
248246
};
249247

250-
static constexpr uint8_t INDEX_MSM80C39[] PROGMEM = {
248+
constexpr uint8_t INDEX_MSM80C39[] PROGMEM = {
251249
2, // TEXT_DEC
252250
3, // TEXT_DJNZ
253251
7, // TEXT_FLT
@@ -261,31 +259,27 @@ static constexpr uint8_t INDEX_MSM80C39[] PROGMEM = {
261259
};
262260
// clang-format on
263261

264-
using EntryPage = entry::TableBase<Entry>;
265-
266-
static constexpr EntryPage INST_PAGES[] PROGMEM = {
262+
constexpr EntryPage INST_PAGES[] PROGMEM = {
267263
{ARRAY_RANGE(TABLE_I8048), ARRAY_RANGE(INDEX_I8048)}, // 0
268264
{ARRAY_RANGE(TABLE_I8039), ARRAY_RANGE(INDEX_I8039)}, // 1
269265
{ARRAY_RANGE(TABLE_I80C39), ARRAY_RANGE(INDEX_I80C39)}, // 2
270266
{ARRAY_RANGE(TABLE_MSM80C39), ARRAY_RANGE(INDEX_MSM80C39)}, // 3
271267
};
272268

273-
using Cpu = entry::CpuBase<CpuType, EntryPage>;
274-
275-
static constexpr Cpu CPU_TABLE[] PROGMEM = {
276-
{I8039, TEXT_CPU_8039, &INST_PAGES[1], &INST_PAGES[2]},
277-
{I80C39, TEXT_CPU_80C39, &INST_PAGES[1], &INST_PAGES[3]},
278-
{MSM80C39, TEXT_CPU_MSM80C39, &INST_PAGES[1], &INST_PAGES[4]},
279-
{I8048, TEXT_CPU_8048, &INST_PAGES[0], &INST_PAGES[2]},
280-
{I80C48, TEXT_CPU_80C48, &INST_PAGES[0], &INST_PAGES[3]},
281-
{MSM80C48, TEXT_CPU_MSM80C48, &INST_PAGES[0], &INST_PAGES[4]},
269+
constexpr Cpu CPU_TABLE[] PROGMEM = {
270+
{I8039, TEXT_CPU_8039, &INST_PAGES[1], &INST_PAGES[2]},
271+
{I80C39, TEXT_CPU_80C39, &INST_PAGES[1], &INST_PAGES[3]},
272+
{MSM80C39, TEXT_CPU_MSM80C39, &INST_PAGES[1], &INST_PAGES[4]},
273+
{I8048, TEXT_CPU_8048, &INST_PAGES[0], &INST_PAGES[2]},
274+
{I80C48, TEXT_CPU_80C48, &INST_PAGES[0], &INST_PAGES[3]},
275+
{MSM80C48, TEXT_CPU_MSM80C48, &INST_PAGES[0], &INST_PAGES[4]},
282276
};
283277

284-
static const Cpu *cpu(CpuType cpuType) {
278+
const Cpu *cpu(CpuType cpuType) {
285279
return Cpu::search(cpuType, ARRAY_RANGE(CPU_TABLE));
286280
}
287281

288-
static bool acceptMode(AddrMode opr, AddrMode table) {
282+
bool acceptMode(AddrMode opr, AddrMode table) {
289283
if (opr == table)
290284
return true;
291285
if (opr == M_IMM8)
@@ -297,7 +291,7 @@ static bool acceptMode(AddrMode opr, AddrMode table) {
297291
return false;
298292
}
299293

300-
static bool acceptModes(AsmInsn &insn, const Entry *entry) {
294+
bool acceptModes(AsmInsn &insn, const Entry *entry) {
301295
const auto table = entry->readFlags();
302296
return acceptMode(insn.dstOp.mode, table.dst()) && acceptMode(insn.srcOp.mode, table.src());
303297
}
@@ -307,7 +301,7 @@ Error TableI8048::searchName(CpuType cpuType, AsmInsn &insn) const {
307301
return insn.getError();
308302
}
309303

310-
static bool matchOpCode(DisInsn &insn, const Entry *entry, const EntryPage *) {
304+
bool matchOpCode(DisInsn &insn, const Entry *entry, const EntryPage *) {
311305
auto opc = insn.opCode();
312306
const auto flags = entry->readFlags();
313307
const auto dst = flags.dst();

0 commit comments

Comments
 (0)