Make selecting C as input source type check CCManager status
MODIFY
src/edittab.cpp
src/edittab.cpp
#include <QMessageBox>
#include <QPushButton>
+#include "ccmanager.h"
#include "parser.h"
#include "processorhandler.h"
#include "program.h"
@@ -30,6 +31,16 @@ EditTab::EditTab(QToolBar* toolbar, QWidget* parent) : RipesTab(toolbar, parent)
connect(m_ui->assemblyedit, &CodeEditor::textChanged, this, &EditTab::assemble);
+ connect(m_ui->setAssemblyInput, &QRadioButton::toggled, this, &EditTab::sourceTypeChanged);
+ connect(m_ui->setCInput, &QRadioButton::toggled, this, &EditTab::sourceTypeChanged);
+
+ // Ensure that changes to the current compiler path will disable C input, if the compiler is invalid
+ connect(&CCManager::get(), &CCManager::ccChanged, [=](bool valid) {
+ if (!valid) {
+ m_ui->setAssemblyInput->setChecked(true);
+ }
+ });
+
enableEditor();
}
@@ -55,7 +66,6 @@ void EditTab::loadFile(const LoadFileParams& fileParams) {
}
if (success) {
- m_loadedFile = fileParams;
m_activeProgram = loadedProgram;
emitProgramChanged();
} else {
@@ -83,6 +93,23 @@ void EditTab::updateProgramViewerHighlighting() {
}
}
+void EditTab::sourceTypeChanged() {
+ if (m_ui->setAssemblyInput->isChecked()) {
+ m_currentFileType = FileType::Assembly;
+ } else if (m_ui->setCInput->isChecked()) {
+ // Ensure that we have a validated C compiler available
+ if (!CCManager::get().hasValidCC()) {
+ QMessageBox::warning(
+ this, "Error",
+ "No C compiler set.\n\nProvide the path to a valid C compiler under:\n Edit->Settings->Editor");
+ // Re-enable assembly input
+ m_ui->setAssemblyInput->setChecked(true);
+ } else {
+ m_currentFileType = FileType::C;
+ }
+ }
+}
+
void EditTab::emitProgramChanged() {
emit programChanged(&m_activeProgram);
updateProgramViewer();

MODIFY
src/edittab.h
src/edittab.h
@@ -46,6 +46,12 @@ public slots:
void emitProgramChanged();
+ /**
+ * @brief sourceTypeChanged
+ * Called whenever the user requested to change the current input type (Assembly or C)
+ */
+ void sourceTypeChanged();
+
/**
* @brief enableAssemblyInput
* Called whenever the user wants to switch from binary/ELF file input to typed assembly input
@@ -69,9 +75,10 @@ private:
Ui::EditTab* m_ui = nullptr;
std::unique_ptr<Assembler> m_assembler;
- LoadFileParams m_loadedFile;
Program m_activeProgram;
+ FileType m_currentFileType;
+
bool m_editorEnabled = true;
};
} // namespace Ripes

MODIFY
src/edittab.ui
src/edittab.ui
</property>
</spacer>
</item>
+ <item>
+ <widget class="QLabel" name="label_6">
+ <property name="text">
+ <string>Input type:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QRadioButton" name="setAssemblyInput">
+ <property name="text">
+ <string>Assembly</string>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QRadioButton" name="setCInput">
+ <property name="text">
+ <string>C</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="sourceTypeLayout"/>
+ </item>
</layout>
</item>
<item>
<widget class="QStackedWidget" name="editorStackedWidget">
<property name="currentIndex">
- <number>1</number>
+ <number>0</number>
</property>
<widget class="QWidget" name="editorPage">
<layout class="QGridLayout" name="gridLayout_3">
</item>
</layout>
</widget>
+ <widget class="QWidget" name="cSourcePage"/>
</widget>
</item>
</layout>

MODIFY
src/program.h
src/program.h
namespace Ripes {
-enum class FileType { Assembly, FlatBinary, Executable };
+enum class FileType { Assembly, C, FlatBinary, Executable };
#define TEXT_SECTION_NAME ".text"

MODIFY
src/settingsdialog.cpp
src/settingsdialog.cpp
@@ -81,14 +81,14 @@ QWidget* SettingsDialog::createEditorPage() {
auto* CCLayout = new QVBoxLayout();
CCGroupBox->setLayout(CCLayout);
auto* CCDesc = new QLabel(
- "Providing a valid C/C++ compiler enables direct editing, compilation "
- "and execution of C-language source files within Ripes.\n\n"
- "A compatible compiler may be autodetected if availabe in PATH.");
+ "Providing a compatible RISC-V C/C++ compiler enables editing, compilation "
+ "and execution of C-language programs within Ripes.\n\n"
+ "A compiler may be autodetected if availabe in PATH.");
CCDesc->setWordWrap(true);
CCLayout->addWidget(CCDesc);
auto* CCHLayout = new QHBoxLayout();
- auto [cclabel, ccpath] = createSettingsWidgets<QLineEdit>(RIPES_SETTING_CCPATH, "C/C++ compiler path:");
+ auto [cclabel, ccpath] = createSettingsWidgets<QLineEdit>(RIPES_SETTING_CCPATH, "Compiler path:");
m_ccpath = ccpath;
CCLayout->addLayout(CCHLayout);
CCHLayout->addWidget(cclabel);

Make selecting C as input source type check CCManager status