meson,parseinstrs: Make decode and encode optional
This commit is contained in:
6
decode.c
6
decode.c
@@ -11,7 +11,7 @@
|
||||
|
||||
// Defines FD_TABLE_OFFSET_32 and FD_TABLE_OFFSET_64, if available
|
||||
#define FD_DECODE_TABLE_DEFINES
|
||||
#include <fadec-table.inc>
|
||||
#include <fadec-decode-private.inc>
|
||||
#undef FD_DECODE_TABLE_DEFINES
|
||||
|
||||
enum DecodeMode {
|
||||
@@ -35,7 +35,7 @@ static unsigned
|
||||
table_walk(unsigned cur_idx, unsigned entry_idx, unsigned* out_kind) {
|
||||
static __attribute__((aligned(16))) const uint16_t _decode_table[] = {
|
||||
#define FD_DECODE_TABLE_DATA
|
||||
#include <fadec-table.inc>
|
||||
#include <fadec-decode-private.inc>
|
||||
#undef FD_DECODE_TABLE_DATA
|
||||
};
|
||||
unsigned entry = _decode_table[cur_idx + entry_idx];
|
||||
@@ -273,7 +273,7 @@ prefix_end:
|
||||
|
||||
static __attribute__((aligned(16))) const struct InstrDesc descs[] = {
|
||||
#define FD_DECODE_TABLE_DESCS
|
||||
#include <fadec-table.inc>
|
||||
#include <fadec-decode-private.inc>
|
||||
#undef FD_DECODE_TABLE_DESCS
|
||||
};
|
||||
const struct InstrDesc* desc = &descs[table_idx >> 2];
|
||||
|
||||
2
encode.c
2
encode.c
@@ -311,7 +311,7 @@ struct EncodeDesc {
|
||||
};
|
||||
|
||||
static const struct EncodeDesc descs[] = {
|
||||
#include <fadec-enc-cases.inc>
|
||||
#include <fadec-encode-private.inc>
|
||||
};
|
||||
|
||||
int
|
||||
|
||||
@@ -46,7 +46,7 @@ typedef int64_t FeOp;
|
||||
|
||||
enum {
|
||||
#define FE_MNEMONIC(name,value) name = value,
|
||||
#include <fadec-enc-mnems.inc>
|
||||
#include <fadec-encode-public.inc>
|
||||
#undef FE_MNEMONIC
|
||||
FE_MNEM_MAX
|
||||
};
|
||||
|
||||
2
fadec.h
2
fadec.h
@@ -30,7 +30,7 @@ typedef enum {
|
||||
|
||||
typedef enum {
|
||||
#define FD_MNEMONIC(name,value) FDI_ ## name = value,
|
||||
#include <fadec-mnems.inc>
|
||||
#include <fadec-decode-public.inc>
|
||||
#undef FD_MNEMONIC
|
||||
} FdInstrType;
|
||||
|
||||
|
||||
6
format.c
6
format.c
@@ -135,19 +135,19 @@ static char*
|
||||
fd_mnemonic(char buf[restrict static 48], const FdInstr* instr) {
|
||||
#define FD_DECODE_TABLE_STRTAB1
|
||||
static const char* mnemonic_str =
|
||||
#include <fadec-table.inc>
|
||||
#include <fadec-decode-private.inc>
|
||||
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; // 15 NULL Bytes to prevent overflow
|
||||
#undef FD_DECODE_TABLE_STRTAB1
|
||||
|
||||
#define FD_DECODE_TABLE_STRTAB2
|
||||
static const uint16_t mnemonic_offs[] = {
|
||||
#include <fadec-table.inc>
|
||||
#include <fadec-decode-private.inc>
|
||||
};
|
||||
#undef FD_DECODE_TABLE_STRTAB2
|
||||
|
||||
#define FD_DECODE_TABLE_STRTAB3
|
||||
static const uint8_t mnemonic_lens[] = {
|
||||
#include <fadec-table.inc>
|
||||
#include <fadec-decode-private.inc>
|
||||
};
|
||||
#undef FD_DECODE_TABLE_STRTAB3
|
||||
|
||||
|
||||
56
meson.build
56
meson.build
@@ -31,6 +31,21 @@ if get_option('warning_level').to_int() >= 3
|
||||
endforeach
|
||||
endif
|
||||
|
||||
sources = []
|
||||
headers = []
|
||||
components = []
|
||||
|
||||
if get_option('with_decode')
|
||||
components += 'decode'
|
||||
headers += files('fadec.h')
|
||||
sources += files('decode.c', 'format.c')
|
||||
endif
|
||||
if get_option('with_encode')
|
||||
components += 'encode'
|
||||
headers += files('fadec-enc.h')
|
||||
sources += files('encode.c')
|
||||
endif
|
||||
|
||||
generate_args = []
|
||||
if get_option('archmode') != 'only64'
|
||||
generate_args += ['--32']
|
||||
@@ -42,33 +57,34 @@ if get_option('with_undoc')
|
||||
generate_args += ['--with-undoc']
|
||||
endif
|
||||
|
||||
instr_data = custom_target('tables',
|
||||
command: [python3, '@INPUT0@', '@INPUT1@', '@OUTPUT@'] + generate_args,
|
||||
input: files('parseinstrs.py', 'instrs.txt'),
|
||||
output: [
|
||||
'fadec-mnems.inc', 'fadec-table.inc',
|
||||
'fadec-enc-mnems.inc', 'fadec-enc-cases.inc',
|
||||
],
|
||||
install: true,
|
||||
install_dir: [
|
||||
get_option('includedir'), false,
|
||||
get_option('includedir'), false,
|
||||
])
|
||||
tables = []
|
||||
foreach component : components
|
||||
tables += custom_target('@0@_table'.format(component),
|
||||
command: [python3, '@INPUT0@', component,
|
||||
'@INPUT1@', '@OUTPUT@'] + generate_args,
|
||||
input: files('parseinstrs.py', 'instrs.txt'),
|
||||
output: ['fadec-@0@-public.inc'.format(component),
|
||||
'fadec-@0@-private.inc'.format(component)],
|
||||
install: true,
|
||||
install_dir: [get_option('includedir'), false])
|
||||
endforeach
|
||||
|
||||
libfadec = static_library('fadec', 'decode.c', 'encode.c', 'format.c', instr_data,
|
||||
install: true)
|
||||
libfadec = static_library('fadec', sources, tables, install: true)
|
||||
fadec = declare_dependency(link_with: libfadec,
|
||||
include_directories: include_directories('.'),
|
||||
sources: instr_data)
|
||||
sources: tables)
|
||||
install_headers(headers)
|
||||
|
||||
foreach component : components
|
||||
test(component, executable('@0@-test'.format(component),
|
||||
'@0@-test.c'.format(component),
|
||||
dependencies: fadec))
|
||||
endforeach
|
||||
|
||||
if meson.version().version_compare('>=0.54.0')
|
||||
meson.override_dependency('fadec', fadec)
|
||||
endif
|
||||
|
||||
test('decode', executable('decode-test', 'decode-test.c', dependencies: fadec))
|
||||
test('encode', executable('encode-test', 'encode-test.c', dependencies: fadec))
|
||||
|
||||
install_headers('fadec.h', 'fadec-enc.h')
|
||||
|
||||
pkg = import('pkgconfig')
|
||||
pkg.generate(libraries: libfadec,
|
||||
version: '0.1',
|
||||
|
||||
@@ -1,2 +1,4 @@
|
||||
option('archmode', type: 'combo', choices: ['both', 'only32', 'only64'])
|
||||
option('with_undoc', type: 'boolean', value: false)
|
||||
option('with_decode', type: 'boolean', value: true)
|
||||
option('with_encode', type: 'boolean', value: true)
|
||||
|
||||
@@ -499,7 +499,9 @@ def superstring(strs):
|
||||
realstrs.remove(s)
|
||||
return merged
|
||||
|
||||
def decode_table(entries, modes):
|
||||
def decode_table(entries, args):
|
||||
modes = args.modes
|
||||
|
||||
trie = Trie(root_count=len(modes))
|
||||
mnems, descs, desc_map = set(), [], {}
|
||||
for weak, opcode, desc in entries:
|
||||
@@ -568,7 +570,7 @@ def decode_table(entries, modes):
|
||||
#endif
|
||||
"""
|
||||
|
||||
def encode_table(entries):
|
||||
def encode_table(entries, args):
|
||||
mnemonics = defaultdict(list)
|
||||
mnemonics["FE_NOP"].append(("NP", 0, 0, "0x90"))
|
||||
for weak, opcode, desc in entries:
|
||||
@@ -686,15 +688,19 @@ def encode_table(entries):
|
||||
return mnem_tab, descs
|
||||
|
||||
if __name__ == "__main__":
|
||||
generators = {
|
||||
"decode": decode_table,
|
||||
"encode": encode_table,
|
||||
}
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--32", dest="modes", action="append_const", const=32)
|
||||
parser.add_argument("--64", dest="modes", action="append_const", const=64)
|
||||
parser.add_argument("--with-undoc", action="store_true")
|
||||
parser.add_argument("mode", choices=generators.keys())
|
||||
parser.add_argument("table", type=argparse.FileType('r'))
|
||||
parser.add_argument("decode_mnems", type=argparse.FileType('w'))
|
||||
parser.add_argument("decode_table", type=argparse.FileType('w'))
|
||||
parser.add_argument("encode_mnems", type=argparse.FileType('w'))
|
||||
parser.add_argument("encode_table", type=argparse.FileType('w'))
|
||||
parser.add_argument("out_public", type=argparse.FileType('w'))
|
||||
parser.add_argument("out_private", type=argparse.FileType('w'))
|
||||
args = parser.parse_args()
|
||||
|
||||
entries = []
|
||||
@@ -706,10 +712,6 @@ if __name__ == "__main__":
|
||||
if "UNDOC" not in desc.flags or args.with_undoc:
|
||||
entries.append((weak, opcode, desc))
|
||||
|
||||
fd_mnem_list, fd_table = decode_table(entries, args.modes)
|
||||
args.decode_mnems.write(fd_mnem_list)
|
||||
args.decode_table.write(fd_table)
|
||||
|
||||
fe_mnem_list, fe_code = encode_table(entries)
|
||||
args.encode_mnems.write(fe_mnem_list)
|
||||
args.encode_table.write(fe_code)
|
||||
res_public, res_private = generators[args.mode](entries, args)
|
||||
args.out_public.write(res_public)
|
||||
args.out_private.write(res_private)
|
||||
|
||||
Reference in New Issue
Block a user