Skip to content

Commit

Permalink
refactor: move ProcessorHandler::getCurrentProgramSize to Program
Browse files Browse the repository at this point in the history
Signed-off-by: Bhavy Airi <airiragahv@gmail.com>
  • Loading branch information
Bhavy Airi committed Aug 13, 2023
1 parent c36b9c7 commit e7631a6
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 19 deletions.
11 changes: 10 additions & 1 deletion src/assembler/program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const DisassembledProgram &Program::getDisassembled() const {
const VInt textSectionBaseAddr = textSection->address;
unsigned line = 0;
for (AInt addr = 0;
addr < static_cast<AInt>(ProcessorHandler::getCurrentProgramSize());) {
addr < static_cast<AInt>(Program::getCurrentProgramSize());) {
const VInt disassembleAddr = addr + textSectionBaseAddr;
auto disRes =
assembler->disassemble(memory.readMem(disassembleAddr, instrBytes),
Expand All @@ -98,6 +98,15 @@ const DisassembledProgram &Program::getDisassembled() const {
return disassembled;
}

int Program::_getCurrentProgramSize() const {
const auto *textSection = getSection(TEXT_SECTION_NAME);

if (textSection)
return textSection->data.length();

return 0;
}

QString Program::calculateHash(const QByteArray &data) {
return QCryptographicHash::hash(data, QCryptographicHash::Sha1);
}
Expand Down
15 changes: 15 additions & 0 deletions src/assembler/program.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ class DisassembledProgram {
*/
class Program {
public:
/// Returns a pointer to this class singleton.
static Program *get() {
static auto *handler = new Program;
return handler;
}

// A source mapping is a mapping from {instruction address : source code
// lines}
using SourceMapping = std::map<VInt, std::set<unsigned>>;
Expand Down Expand Up @@ -148,9 +154,18 @@ class Program {
/// Calculates a hash used for source identification.
static QString calculateHash(const QByteArray &data);

/**
* @brief getCurrentProgramSize
* @return size (in bytes) of the currently loaded .text segment
*/
static int getCurrentProgramSize() { return get()->_getCurrentProgramSize(); }

private:
/// A caching of the disassembled version of this program.
mutable DisassembledProgram disassembled;

/// Returns the current program size.
int _getCurrentProgramSize() const;
};

} // namespace Ripes
Expand Down
2 changes: 1 addition & 1 deletion src/pipelinediagrammodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ QVariant PipelineDiagramModel::headerData(int section,
}

int PipelineDiagramModel::rowCount(const QModelIndex &) const {
return ProcessorHandler::getCurrentProgramSize() /
return Program::getCurrentProgramSize() /
ProcessorHandler::currentISA()->instrBytes();
}

Expand Down
10 changes: 0 additions & 10 deletions src/processorhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,16 +361,6 @@ void ProcessorHandler::_selectProcessor(const ProcessorID &id,
RipesSettings::getObserver(RIPES_GLOBALSIGNAL_REQRESET)->trigger();
}

int ProcessorHandler::_getCurrentProgramSize() const {
if (m_program) {
const auto *textSection = m_program->getSection(TEXT_SECTION_NAME);
if (textSection)
return textSection->data.length();
}

return 0;
}

AInt ProcessorHandler::_getTextStart() const {
if (m_program) {
const auto *textSection = m_program->getSection(TEXT_SECTION_NAME);
Expand Down
7 changes: 0 additions & 7 deletions src/processorhandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,6 @@ class ProcessorHandler : public QObject {
return get()->_isExecutableAddress(address);
}

/**
* @brief getCurrentProgramSize
* @return size (in bytes) of the currently loaded .text segment
*/
static int getCurrentProgramSize() { return get()->_getCurrentProgramSize(); }

/**
* @brief getEntryPoint
* @return address of the entry point of the currently loaded program
Expand Down Expand Up @@ -290,7 +284,6 @@ private slots:
const ProcessorID &id, const QStringList &extensions = {},
const RegisterInitialization &setup = RegisterInitialization());
bool _isExecutableAddress(AInt address) const;
int _getCurrentProgramSize() const;
AInt _getTextStart() const;
QString _disassembleInstr(const AInt address) const;
vsrtl::core::AddressSpaceMM &_getMemory();
Expand Down

0 comments on commit e7631a6

Please sign in to comment.