Skip to content

Commit

Permalink
disasm: Separated Instruction class
Browse files Browse the repository at this point in the history
  • Loading branch information
mefistotelis committed Jan 8, 2024
1 parent 55e46af commit ffa4feb
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 53 deletions.
2 changes: 2 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ bindir = $(prefix)/usr/$(PACKAGE)
swdisasm_SOURCES = \
disassembler.h \
disassembler.cpp \
instruction.h \
instruction.cpp \
image.h \
image.cpp \
le.h \
Expand Down
26 changes: 1 addition & 25 deletions src/disassembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <stdexcept>

#include "disassembler.h"
#include "instruction.h"
#include "util.h"

static std::string
Expand Down Expand Up @@ -56,31 +57,6 @@ lower (const std::string &str)
}


Instruction::Type
Instruction::get_type (void)
{
return this->type;
}

std::string
Instruction::get_string (void)
{
return this->string;
}

uint32_t
Instruction::get_target (void)
{
return this->target;
}

size_t
Instruction::get_size (void)
{
return this->size;
}


struct DisassemblerContext
{
std::ostringstream string;
Expand Down
29 changes: 1 addition & 28 deletions src/disassembler.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,35 +26,8 @@
#include "config.h"
#include "dis-asm.h"

struct Instruction
{
protected:
friend class Disassembler;

public:
enum Type
{
MISC,
COND_JUMP,
JUMP,
CALL,
RET
};

protected:
Type type;
std::string string;
uint32_t target;
size_t size;

public:
Type get_type (void);
std::string get_string (void);
uint32_t get_target (void);
size_t get_size (void);
};

struct disassemble_info;
class Instruction;

class Disassembler
{
Expand Down
43 changes: 43 additions & 0 deletions src/instruction.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* swdisasm - LE disassembler for Syndicate Wars
*
* Copyright (C) 2010 Unavowed <unavowed@vexillium.org>
*
* 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/>.
*/
#include "instruction.h"

Instruction::Type
Instruction::get_type (void)
{
return this->type;
}

std::string
Instruction::get_string (void)
{
return this->string;
}

uint32_t
Instruction::get_target (void)
{
return this->target;
}

size_t
Instruction::get_size (void)
{
return this->size;
}
53 changes: 53 additions & 0 deletions src/instruction.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* swdisasm - LE disassembler for Syndicate Wars
*
* Copyright (C) 2010 Unavowed <unavowed@vexillium.org>
*
* 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/>.
*/
#ifndef LEDISASM_INSTRUCTION_H
#define LEDISASM_INSTRUCTION_H

#include <inttypes.h>
#include <string>

struct Instruction
{
protected:
friend class Disassembler;

public:
enum Type
{
MISC,
COND_JUMP,
JUMP,
CALL,
RET
};

protected:
Type type;
std::string string;
uint32_t target;
size_t size;

public:
Type get_type (void);
std::string get_string (void);
uint32_t get_target (void);
size_t get_size (void);
};

#endif
1 change: 1 addition & 0 deletions src/swdisasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <sstream>

#include "disassembler.h"
#include "instruction.h"
#include "le.h"
#include "le_image.h"
#include "util.h"
Expand Down

0 comments on commit ffa4feb

Please sign in to comment.