Skip to content
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
29 changes: 29 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,35 @@ endif()
set(APP_NAME Ripes)
qt_add_executable(${APP_NAME} ${SYSTEM_FLAGS} ${ICONS_SRC} ${EXAMPLES_SRC} ${LAYOUTS_SRC} ${FONTS_SRC} main.cpp)

if(APPLE)
set(RIPES_APP_ICON "${CMAKE_CURRENT_BINARY_DIR}/logo.icns")
set(RIPES_APP_ICONSET "${CMAKE_CURRENT_BINARY_DIR}/logo.iconset")
add_custom_command(
OUTPUT ${RIPES_APP_ICON}
COMMAND ${CMAKE_COMMAND} -E rm -rf ${RIPES_APP_ICONSET}
COMMAND ${CMAKE_COMMAND} -E make_directory ${RIPES_APP_ICONSET}
COMMAND /usr/bin/sips -z 16 16 ${CMAKE_CURRENT_SOURCE_DIR}/resources/images/logo.png --out ${RIPES_APP_ICONSET}/icon_16x16.png
COMMAND /usr/bin/sips -z 32 32 ${CMAKE_CURRENT_SOURCE_DIR}/resources/images/logo.png --out ${RIPES_APP_ICONSET}/icon_16x16@2x.png
COMMAND /usr/bin/sips -z 32 32 ${CMAKE_CURRENT_SOURCE_DIR}/resources/images/logo.png --out ${RIPES_APP_ICONSET}/icon_32x32.png
COMMAND /usr/bin/sips -z 64 64 ${CMAKE_CURRENT_SOURCE_DIR}/resources/images/logo.png --out ${RIPES_APP_ICONSET}/icon_32x32@2x.png
COMMAND /usr/bin/sips -z 128 128 ${CMAKE_CURRENT_SOURCE_DIR}/resources/images/logo.png --out ${RIPES_APP_ICONSET}/icon_128x128.png
COMMAND /usr/bin/sips -z 256 256 ${CMAKE_CURRENT_SOURCE_DIR}/resources/images/logo.png --out ${RIPES_APP_ICONSET}/icon_128x128@2x.png
COMMAND /usr/bin/sips -z 256 256 ${CMAKE_CURRENT_SOURCE_DIR}/resources/images/logo.png --out ${RIPES_APP_ICONSET}/icon_256x256.png
COMMAND /usr/bin/sips -z 512 512 ${CMAKE_CURRENT_SOURCE_DIR}/resources/images/logo.png --out ${RIPES_APP_ICONSET}/icon_256x256@2x.png
COMMAND /usr/bin/sips -z 512 512 ${CMAKE_CURRENT_SOURCE_DIR}/resources/images/logo.png --out ${RIPES_APP_ICONSET}/icon_512x512.png
COMMAND /usr/bin/sips -z 1024 1024 ${CMAKE_CURRENT_SOURCE_DIR}/resources/images/logo.png --out ${RIPES_APP_ICONSET}/icon_512x512@2x.png
COMMAND /usr/bin/iconutil -c icns ${RIPES_APP_ICONSET} -o ${RIPES_APP_ICON}
COMMAND ${CMAKE_COMMAND} -E rm -rf ${RIPES_APP_ICONSET}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/resources/images/logo.png
VERBATIM
)
set_source_files_properties(${RIPES_APP_ICON} PROPERTIES
MACOSX_PACKAGE_LOCATION Resources
GENERATED TRUE)
target_sources(${APP_NAME} PRIVATE ${RIPES_APP_ICON})
set_target_properties(${APP_NAME} PROPERTIES MACOSX_BUNDLE_ICON_FILE logo.icns)
endif()

# Link Qt libraries
target_link_libraries(${APP_NAME} PUBLIC Qt6::Core Qt6::Widgets)
# Link Ripes library
Expand Down
20 changes: 6 additions & 14 deletions src/assembler/objdump.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "objdump.h"

#include "processorhandler.h"
#include <QDataStream>

namespace Ripes {
namespace Assembler {
Expand Down Expand Up @@ -30,8 +29,6 @@ QString stringifyProgram(std::weak_ptr<const Program> program,
return QString();

QString out;
auto dataStream = QDataStream(textSection->data);
std::vector<char> buffer;
const unsigned regBytes = ProcessorHandler::currentISA()->bytes();
const unsigned instrBytes = ProcessorHandler::currentISA()->instrBytes();

Expand All @@ -40,17 +37,6 @@ QString stringifyProgram(std::weak_ptr<const Program> program,

AInt addr = textSection->address;
while (addr < textSection->address + textSection->data.length()) {
/// Ensure that we always have sizeof(Instr_T) bytes in the buffer, even
/// though some of these bytes may be invalid (due to reading past the end
/// of stream). For the end-of-program edge,case, the while loop will exit
/// before we start decoding invalid data.
size_t curBufSize = buffer.size();
if (curBufSize < sizeof(Instr_T)) {
buffer.resize(sizeof(Instr_T));
dataStream.readRawData(buffer.data() + curBufSize,
sizeof(Instr_T) - curBufSize);
}

// symbol label
if (sp->symbols.count(addr)) {
const auto &symbol = sp->symbols.at(addr);
Expand All @@ -67,6 +53,12 @@ QString stringifyProgram(std::weak_ptr<const Program> program,
// Instruction address
out += indent + QString::number(addr, 16) + ":" + indent + indent;

std::vector<char> buffer(instrBytes);
const auto word = ProcessorHandler::getMemory().readMem(addr, instrBytes);
for (unsigned i = 0; i < instrBytes; ++i) {
buffer[i] = static_cast<char>((word >> (CHAR_BIT * i)) & 0xFF);
}

// Stringified instruction
auto disres = stringifier(buffer, addr);
if (disres.err.has_value()) {
Expand Down
14 changes: 13 additions & 1 deletion src/editor/codeeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,23 @@ CodeEditor::CodeEditor(QWidget *parent) : HighlightableTextEdit(parent) {

// Set font for the entire widget. calls to fontMetrics() will get the
// dimensions of the currently set font
m_font = QFont(Fonts::monospace, 11);
m_font = RipesSettings::value(RIPES_SETTING_EDITORFONT).value<QFont>();
if (m_font.family().isEmpty()) {
m_font = QFont(Fonts::monospace, 11);
}
setFont(m_font);
m_fontTimer.setSingleShot(true);
setTabStopDistance(QFontMetricsF(m_font).horizontalAdvance(' ') * 4);

connect(RipesSettings::getObserver(RIPES_SETTING_EDITORFONT),
&SettingObserver::modified, this, [this](const QVariant &value) {
m_font = value.value<QFont>();
setFont(m_font);
setTabStopDistance(QFontMetricsF(m_font).horizontalAdvance(' ') *
4);
updateSidebarWidth(0);
});

// set event filter for catching scroll events
installEventFilter(this);

Expand Down
13 changes: 8 additions & 5 deletions src/processorhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,13 +429,16 @@ AInt ProcessorHandler::_getTextStart() const {
QString ProcessorHandler::_disassembleInstr(const AInt addr) const {
if (m_program) {
const unsigned instrBytes = _currentISA()->instrBytes();
auto disRes = m_currentAssembler->disassemble(
m_currentProcessor->getMemory().readMem(addr, instrBytes),
m_program.get()->symbols, addr);

auto word = m_currentProcessor->getMemory().readMem(addr, instrBytes);

auto disRes =
m_currentAssembler->disassemble(word, m_program.get()->symbols, addr);

return disRes.repr;
} else {
return QString();
}

return QString();
}

void ProcessorHandler::syscallTrap() {
Expand Down
13 changes: 12 additions & 1 deletion src/programviewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,23 @@ ProgramViewer::ProgramViewer(QWidget *parent) : HighlightableTextEdit(parent) {

// Set font for the entire widget. calls to fontMetrics() will get the
// dimensions of the currently set font
m_font = QFont(Fonts::monospace, 11);
m_font = RipesSettings::value(RIPES_SETTING_EDITORFONT).value<QFont>();
if (m_font.family().isEmpty()) {
m_font = QFont(Fonts::monospace, 11);
}
setFont(m_font);
m_fontTimer.setSingleShot(true);

setTabStopDistance(QFontMetricsF(m_font).horizontalAdvance(' ') * 4);

connect(RipesSettings::getObserver(RIPES_SETTING_EDITORFONT),
&SettingObserver::modified, this, [this](const QVariant &value) {
m_font = value.value<QFont>();
setFont(m_font);
setTabStopDistance(QFontMetricsF(m_font).horizontalAdvance(' ') *
4);
});

setLineWrapMode(QPlainTextEdit::NoWrap);
}

Expand Down
3 changes: 0 additions & 3 deletions src/registermodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

#include "STLExtras.h"
#include "colors.h"
#include "fonts.h"
#include "processorhandler.h"

namespace Ripes {
Expand Down Expand Up @@ -121,8 +120,6 @@ QVariant RegisterModel::data(const QModelIndex &index, int role) const {
return valueData(idx);
case Qt::UserRole:
return QVariant::fromValue(m_radix);
case Qt::FontRole:
return QFont(Fonts::monospace, 11);
case Qt::ForegroundRole:
// Use the theme's link/accent color so register values stand out with
// good contrast in both light and dark color schemes.
Expand Down
41 changes: 38 additions & 3 deletions src/registerwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "ui_registerwidget.h"

#include <QClipboard>
#include <QFontMetrics>
#include <QHeaderView>
#include <QInputDialog>
#include <QMenu>
Expand All @@ -12,13 +13,36 @@
#include "processorhandler.h"
#include "radixselectorwidget.h"
#include "registermodel.h"
#include "ripessettings.h"

namespace Ripes {

RegisterWidget::RegisterWidget(const std::string_view &regFileID,
QWidget *parent)
: QWidget(parent), m_ui(new Ui::RegisterWidget), m_regFileName(regFileID) {
m_ui->setupUi(this);

connect(m_ui->radixSelector, &RadixSelectorWidget::radixChanged, this,
[this](Radix radix) {
RipesSettings::setValue(RIPES_SETTING_REGISTERDISPLAYTYPE,
QVariant::fromValue(radix));
if (m_model) {
m_model->setRadix(radix);
}
});

connect(RipesSettings::getObserver(RIPES_SETTING_REGISTERDISPLAYTYPE),
&SettingObserver::modified, this, [this](const QVariant &value) {
const auto radix = value.value<Radix>();
m_ui->radixSelector->setRadix(radix);
if (m_model) {
m_model->setRadix(radix);
}
});

connect(RipesSettings::getObserver(RIPES_SETTING_REGISTERFONT),
&SettingObserver::modified, this,
[this](const QVariant &value) { applyFont(value.value<QFont>()); });
}

RegisterWidget::~RegisterWidget() { delete m_ui; }
Expand All @@ -43,15 +67,26 @@ void RegisterWidget::initialize() {
m_ui->registerView->horizontalHeader()->setSectionResizeMode(
RegisterModel::Value, QHeaderView::Stretch);

m_ui->radixSelector->setRadix(m_model->getRadix());
applyFont(RipesSettings::value(RIPES_SETTING_REGISTERFONT).value<QFont>());

const auto radix =
RipesSettings::value(RIPES_SETTING_REGISTERDISPLAYTYPE).value<Radix>();
m_ui->radixSelector->setRadix(radix);
m_model->setRadix(radix);
connect(m_model, &RegisterModel::registerChanged, this,
&RegisterWidget::setRegisterviewCenterIndex);
connect(m_ui->radixSelector, &RadixSelectorWidget::radixChanged, m_model,
&RegisterModel::setRadix);
}

void RegisterWidget::updateView() { m_model->processorWasClocked(); }

void RegisterWidget::applyFont(const QFont &font) {
m_ui->registerView->setFont(font);
m_ui->registerView->horizontalHeader()->setFont(font);
m_ui->registerView->verticalHeader()->setFont(font);
m_ui->registerView->verticalHeader()->setDefaultSectionSize(
QFontMetrics(font).height() + 8);
}

void RegisterWidget::showContextMenu(const QPoint &pos) {
const auto index = m_ui->registerView->indexAt(pos);
if (!index.isValid())
Expand Down
2 changes: 2 additions & 0 deletions src/registerwidget.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <QFont>
#include <QWidget>

#include "processors/interface/ripesprocessor.h"
Expand All @@ -26,6 +27,7 @@ public slots:
void setRegisterviewCenterIndex(int index);

private:
void applyFont(const QFont &font);
void showContextMenu(const QPoint &pos);
Ui::RegisterWidget *m_ui = nullptr;
RegisterModel *m_model = nullptr;
Expand Down
4 changes: 4 additions & 0 deletions src/ripessettings.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "ripessettings.h"
#include "assembler/program.h"
#include "cachesim/cachesim.h"
#include "fonts.h"

#include <QCoreApplication>
#include <QEvent>
Expand Down Expand Up @@ -35,6 +36,9 @@ const std::map<QString, QVariant> s_defaultSettings = {
{RIPES_SETTING_EDITORREGS, true},
{RIPES_SETTING_EDITORCONSOLE, true},
{RIPES_SETTING_EDITORSTAGEHIGHLIGHTING, true},
{RIPES_SETTING_EDITORFONT, QFont(Fonts::monospace, 11)},
{RIPES_SETTING_REGISTERFONT, QFont(Fonts::monospace, 12)},
{RIPES_SETTING_REGISTERDISPLAYTYPE, QVariant::fromValue(Radix::Hex)},
{RIPES_SETTING_VCD_TRACE_FILE, "ripes.vcd"},
{RIPES_SETTING_VCD_TRACE, false},

Expand Down
3 changes: 3 additions & 0 deletions src/ripessettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ namespace Ripes {
#define RIPES_SETTING_EDITORREGS ("editor_regs")
#define RIPES_SETTING_EDITORCONSOLE ("editor_console")
#define RIPES_SETTING_EDITORSTAGEHIGHLIGHTING ("editor_stage_highlighting")
#define RIPES_SETTING_EDITORFONT ("editor_font")
#define RIPES_SETTING_REGISTERFONT ("register_font")
#define RIPES_SETTING_REGISTERDISPLAYTYPE ("register_display_type")

#define RIPES_SETTING_HAS_SAVEFILE ("has_savefile")
#define RIPES_SETTING_SAVEPATH ("savepath")
Expand Down
19 changes: 16 additions & 3 deletions src/savedialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "program.h"
#include "ripessettings.h"
#include <QDialog>
#include <QFileInfo>

namespace Ripes {

Expand All @@ -21,9 +22,21 @@ class SaveDialog : public QDialog {
return RipesSettings::value(RIPES_SETTING_SAVEPATH).toString();
}
QString sourcePath() {
return RipesSettings::value(RIPES_SETTING_SAVE_SOURCE).toBool()
? getPath() + (sourceType == SourceType::C ? ".c" : ".s")
: QString();
if (!RipesSettings::value(RIPES_SETTING_SAVE_SOURCE).toBool())
return QString();

QString path = getPath();
QFileInfo info(path);

if (sourceType == SourceType::C) {
if (info.suffix() != "c")
path += ".c";
} else {
if (info.suffix() != "s")
path += ".s";
}

return path;
}
QString binaryPath() {
return RipesSettings::value(RIPES_SETTING_SAVE_BINARY).toBool()
Expand Down
7 changes: 7 additions & 0 deletions src/settingsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,13 @@ QWidget *SettingsDialog::createEditorPage() {
"Show (or hide) highlighting of processor stages in the program source "
"code.");

appendToLayout(createSettingsWidgets<QPushButton, QFontDialog>(
RIPES_SETTING_EDITORFONT, "Source editor font:"),
pageLayout, "Font used by the source editor.");
appendToLayout(createSettingsWidgets<QPushButton, QFontDialog>(
RIPES_SETTING_REGISTERFONT, "Register pane font:"),
pageLayout, "Font used by the register pane.");

// ===== Source formatter
auto *formatterGroupBox = new QGroupBox("Formatter");
appendToLayout(formatterGroupBox, pageLayout);
Expand Down
Loading