Skip to content

Commit 4026e76

Browse files
authored
Merge pull request #99 from akisari/master
Add support for builds without mnemonics.
2 parents ed19a46 + 68166ad commit 4026e76

File tree

6 files changed

+25
-4
lines changed

6 files changed

+25
-4
lines changed

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ option(BDD_INCLUDE_ISAGENERATOR_X86 "Include the x86 isagenerator target (if a p
55
option(BDD_INCLUDE_FUZZERS "Include the bdshemu fuzzer" OFF)
66
option(BDD_USE_EXTERNAL_VSNPRINTF "Expect nd_vsnprintf_s implementation from the integrator" OFF)
77
option(BDD_USE_EXTERNAL_MEMSET "Expect nd_memset implementation from the integrator" OFF)
8+
option(BDD_NO_MNEMONIC "Exclude mnemonics - this option involves setting the BDDISASM_NO_FORMAT flag" OFF)
89
option(BDD_ASAN "Build with ASAN" OFF)
910
option(BDD_UBSAN "Build with UBSAN" OFF)
1011

@@ -143,6 +144,11 @@ if (NOT BDD_USE_EXTERNAL_MEMSET)
143144
endif ()
144145
endif ()
145146

147+
if (BDD_NO_MNEMONIC)
148+
target_compile_definitions(bddisasm PUBLIC -DBDDISASM_NO_MNEMONIC)
149+
target_compile_definitions(bddisasm PUBLIC -DBDDISASM_NO_FORMAT)
150+
endif()
151+
146152
set_target_properties(
147153
bddisasm
148154
PROPERTIES POSITION_INDEPENDENT_CODE ON

bddisasm/bdx86_decoder.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4308,7 +4308,9 @@ NdCopyInstructionInfo(
43084308
ND_IDBE *Idbe
43094309
)
43104310
{
4311+
#ifndef BDDISASM_NO_MNEMONIC
43114312
Instrux->Mnemonic = gMnemonics[Idbe->Mnemonic];
4313+
#endif // !BDDISASM_NO_MNEMONIC
43124314
Instrux->Attributes = Idbe->Attributes;
43134315
Instrux->Instruction = (ND_INS_CLASS)Idbe->Instruction;
43144316
Instrux->Category = (ND_INS_CATEGORY)Idbe->Category;

bddisasm/bdx86_formatter.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
#include "../inc/bddisasm.h"
77

88

9-
10-
#ifndef BDDISASM_NO_FORMAT
9+
#if !defined(BDDISASM_NO_MNEMONIC) && !defined(BDDISASM_NO_FORMAT)
1110

1211
static const char *const gReg8Bit[] =
1312
{
@@ -1033,4 +1032,4 @@ NdToText(
10331032

10341033
return ND_STATUS_SUCCESS;
10351034
}
1036-
#endif // !BDDISASM_NO_FORMAT
1035+
#endif // !defined(BDDISASM_NO_MNEMONIC) && !defined(BDDISASM_NO_FORMAT)

bddisasm/include/bdx86_mnemonics.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#ifndef BDX86_MNEMONICS_H
1111
#define BDX86_MNEMONICS_H
1212

13+
#ifndef BDDISASM_NO_MNEMONIC
14+
1315
const char *gMnemonics[1786] =
1416
{
1517
"AAA", "AAD", "AADD", "AAM", "AAND", "AAS", "ADC", "ADCX", "ADD",
@@ -320,6 +322,8 @@ const char *gMnemonics[1786] =
320322
"XSAVES", "XSAVES64", "XSETBV", "XSUSLDTRK", "XTEST",
321323
};
322324

325+
#endif // !BDDISASM_NO_MNEMONIC
326+
323327

324328
#endif
325329

inc/bdx86_core.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,7 +1439,9 @@ typedef struct _INSTRUX
14391439
// Aliased over low 4 bits inside the main opcode.
14401440
};
14411441

1442+
#ifndef BDDISASM_NO_MNEMONIC
14421443
const char *Mnemonic; // Instruction mnemonic.
1444+
#endif // !BDDISASM_NO_MNEMONIC
14431445
ND_UINT8 InstructionBytes[16]; // The entire instruction.
14441446
ND_UINT8 OpCodeBytes[3]; // Opcode bytes - escape codes and main opcode.
14451447

isagenerator/generate_tables.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,8 @@ def dump_mnemonics(mnemonics, prefixes, fname):
801801
f.write('#ifndef BDX86_MNEMONICS_H\n')
802802
f.write('#define BDX86_MNEMONICS_H\n')
803803
f.write('\n')
804+
f.write('#ifndef BDDISASM_NO_MNEMONIC\n')
805+
f.write('\n')
804806
f.write('const char *gMnemonics[%d] = \n' % len(mnemonics))
805807
f.write('{\n')
806808
f.write(' ')
@@ -815,7 +817,13 @@ def dump_mnemonics(mnemonics, prefixes, fname):
815817
ln = 0
816818
f.write('\n ')
817819

818-
f.write('\n};\n\n\n')
820+
821+
f.write('\n};\n')
822+
823+
f.write('\n')
824+
f.write('#endif // !BDDISASM_NO_MNEMONIC\n')
825+
826+
f.write('\n\n')
819827

820828
f.write('#endif\n\n')
821829

0 commit comments

Comments
 (0)