Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: move ProcessorHandler::getCurrentProgramSize to Program #292

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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