Skip to content

Commit

Permalink
[DIS] Add upper-hex and upper-case options
Browse files Browse the repository at this point in the history
  • Loading branch information
tgtakaoka committed Sep 28, 2024
1 parent ec32b78 commit 96c3fbc
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 12 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ It can read Intel HEX or Motorola S-Record input.
-v : print progress verbosely
--<name>=<vale>
: extra options (<type> [, <CPU>])
upper-hex : use upper case letter for hexadecimal (bool)
upper-case : use upper case letter for output (bool)
list-radix : set listing radix (8, 16) (int)
relative : program counter relative branch target (bool)
c-style : C language style number constant (bool)
Expand Down
2 changes: 2 additions & 0 deletions README_.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ usage: dis -C <CPU> [-o <output>] [-l <list>] <input>
-v : print progress verbosely
--<name>=<vale>
: extra options (<type> [, <CPU>])
upper-hex : use upper case letter for hexadecimal (bool)
upper-case : use upper case letter for output (bool)
list-radix : set listing radix (8, 16) (int)
relative : program counter relative branch target (bool)
c-style : C language style number constant (bool)
Expand Down
10 changes: 9 additions & 1 deletion src/dis_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ namespace libasm {

namespace {

constexpr char OPT_BOOL_UPPER_HEX[] PROGMEM = "upper-hex";
constexpr char OPT_DESC_UPPER_HEX[] PROGMEM = "use upper case letter for hexadecimal";
constexpr char OPT_BOOL_UPPERCASE[] PROGMEM = "upper-case";
constexpr char OPT_DESC_UPPERCASE[] PROGMEM = "use upper case letter for output";
constexpr char OPT_INT_LIST_RADIX[] PROGMEM = "list-radix";
constexpr char OPT_DESC_LIST_RADIX[] PROGMEM = "set listing radix (8, 16)";
constexpr char OPT_BOOL_RELATIVE[] PROGMEM = "relative";
Expand All @@ -35,8 +39,12 @@ constexpr char OPT_DESC_ORIGIN[] PROGMEM = "letter for origin symbol";

Disassembler::Disassembler(const ValueFormatter::Plugins &plugins, const OptionBase *option)
: _formatter(plugins),
_commonOptions(&_opt_listRadix),
_commonOptions(&_opt_upperHex),
_options(option),
_opt_upperHex(this, &Disassembler::setUpperHex, OPT_BOOL_UPPER_HEX, OPT_DESC_UPPER_HEX,
&_opt_uppercase),
_opt_uppercase(this, &Disassembler::setUppercase, OPT_BOOL_UPPERCASE, OPT_DESC_UPPERCASE,
&_opt_listRadix),
_opt_listRadix(this, &Disassembler::setListRadix, OPT_INT_LIST_RADIX, OPT_DESC_LIST_RADIX,
&_opt_relative),
_opt_relative(this, &Disassembler::setRelativeTarget, OPT_BOOL_RELATIVE, OPT_DESC_RELATIVE,
Expand Down
2 changes: 2 additions & 0 deletions src/dis_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ struct Disassembler {
protected:
const Options _commonOptions;
const Options _options;
const BoolOption<Disassembler> _opt_upperHex;
const BoolOption<Disassembler> _opt_uppercase;
const IntOption<Disassembler> _opt_listRadix;
const BoolOption<Disassembler> _opt_relative;
const BoolOption<Disassembler> _opt_cstyle;
Expand Down
2 changes: 0 additions & 2 deletions test/test_dis_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ static char actual_opr[128];
void dis_assert(const char *file, int line, const ErrorAt &error, const ArrayMemory &memory,
const char *expected_name, const char *expected_opr) {
Insn insn(memory.origin() / disassembler.config().addressUnit());
disassembler.setOption("upper-hex", "yes");
disassembler.setOption("uppercase", "yes");
auto mem = memory.iterator();
disassembler.decode(mem, insn, actual_opr, sizeof(actual_opr), &symtab);

Expand Down
20 changes: 11 additions & 9 deletions test/test_dis_mc68000.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2625,24 +2625,26 @@ static void test_float_move() {
0xF200|074, 0x4000|(3<<10)|(1<<7), 0x0019, 0x000A, 0x1200, 0x0000, 0x0000, 0x0000);

EQUALS("gnu-as", OK, disassembler.setOption("gnu-as", "on"));
EQUALS("upper-hex", OK, disassembler.setOption("upper-hex", "off"));
EQUALS("upper-case", OK, disassembler.setOption("upper-case", "off"));

TEST("FMOVEL", "#0x6789ABCD, FP6",
TEST("fmovel", "#0x6789abcd, fp6",
0xF200|074, 0x4000|(0<<10)|(6<<7), 0x6789, 0xABCD);
TEST("FMOVES", "#0x3058E0F0, FP7",
TEST("fmoves", "#0x3058e0f0, fp7",
0xF200|074, 0x4000|(1<<10)|(7<<7), 0x3058, 0xE0F0);
TEST("FMOVEX", "#0xFFFF00008000000000000000, FP0",
TEST("fmovex", "#0xffff00008000000000000000, fp0",
0xF200|074, 0x4000|(2<<10)|(0<<7), 0xFFFF, 0x0000, 0x8000, 0x0000, 0x0000, 0x0000);
TEST("FMOVEX", "#0xC0230000A5C681D100000000, FP0",
TEST("fmovex", "#0xc0230000a5c681d100000000, fp0",
0xF200|074, 0x4000|(2<<10)|(0<<7), 0xC023, 0x0000, 0xA5C6, 0x81D1, 0x0000, 0x0000);
TEST("FMOVEP", "#0xFFFF00000000000000000001, FP1",
TEST("fmovep", "#0xffff00000000000000000001, fp1",
0xF200|074, 0x4000|(3<<10)|(1<<7), 0xFFFF, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001);
TEST("FMOVEP", "#0x002000091200000000000000, FP1",
TEST("fmovep", "#0x002000091200000000000000, fp1",
0xF200|074, 0x4000|(3<<10)|(1<<7), 0x0020, 0x0009, 0x1200, 0x0000, 0x0000, 0x0000);
TEST("FMOVEW", "#0x1234, FP2",
TEST("fmovew", "#0x1234, fp2",
0xF200|074, 0x4000|(4<<10)|(2<<7), 0x1234);
TEST("FMOVED", "#0xC020800000000000, FP3",
TEST("fmoved", "#0xc020800000000000, fp3",
0xF200|074, 0x4000|(5<<10)|(3<<7), 0xC020, 0x8000, 0x0000, 0x0000);
TEST("FMOVEB", "#0x23, FP4",
TEST("fmoveb", "#0x23, fp4",
0xF200|074, 0x4000|(6<<10)|(4<<7), 0x0023);
}

Expand Down

0 comments on commit 96c3fbc

Please sign in to comment.