Include peripheral symbol header file in set of compiled files
MODIFY
src/ccmanager.cpp
src/ccmanager.cpp
#include "ccmanager.h"
+#include "io/iomanager.h"
#include "loaddialog.h"
#include "processorhandler.h"
#include "ripessettings.h"
@@ -61,33 +62,49 @@ bool CCManager::trySetCC(const QString& CC) {
CCManager::CCRes CCManager::compileRaw(const QString& rawsource, QString outname, bool showProgressdiag) {
// Write program to temporary file with a .c extension
+ if (!(m_tmpSrcFile && (QFile::exists(m_tmpSrcFile->fileName())))) {
const auto tempFileTemplate =
QString(QDir::tempPath() + QDir::separator() + QCoreApplication::applicationName() + ".XXXXXX.c");
QTemporaryFile tmpSrcFile = QTemporaryFile(tempFileTemplate);
tmpSrcFile.setAutoRemove(false);
if (tmpSrcFile.open()) {
- QTextStream stream(&tmpSrcFile);
- stream << rawsource;
+ m_tmpSrcFile = std::make_unique<QFile>(tmpSrcFile.fileName());
}
- Q_ASSERT(!tmpSrcFile.fileName().isEmpty());
- return compile(tmpSrcFile.fileName(), outname, showProgressdiag);
+ }
+
+ Q_ASSERT(m_tmpSrcFile);
+ if (m_tmpSrcFile->open(QIODevice::ReadWrite | QIODevice::Truncate)) {
+ m_tmpSrcFile->write(rawsource.toUtf8());
+ m_tmpSrcFile->close();
+ }
+
+ QStringList sourceFiles;
+ sourceFiles << m_tmpSrcFile->fileName();
+
+ // Include peripheral header file, if available
+ const QString peripheralSymbolsHeader = IOManager::get().cSymbolsHeaderpath();
+ if (!peripheralSymbolsHeader.isEmpty()) {
+ sourceFiles << peripheralSymbolsHeader;
+ }
+
+ return compile(sourceFiles, outname, showProgressdiag);
}
CCManager::CCRes CCManager::compile(const QTextDocument* source, QString outname, bool showProgressdiag) {
return compileRaw(source->toPlainText(), outname, showProgressdiag);
}
-CCManager::CCRes CCManager::compile(const QString& filename, QString outname, bool showProgressdiag) {
+CCManager::CCRes CCManager::compile(const QStringList& files, QString outname, bool showProgressdiag) {
CCRes res;
if (outname.isEmpty()) {
outname = QDir::tempPath() + QDir::separator() + QCoreApplication::applicationName() + ".temp.out";
QFile::remove(outname); // Remove any previously compiled file
}
- res.inFile = filename;
+ res.inFiles = files;
res.outFile = outname;
- const auto [cc, args] = createCompileCommand(filename, outname);
+ const auto [cc, args] = createCompileCommand(files, outname);
// Run compiler
@@ -142,7 +159,8 @@ QStringList sanitizedArguments(const QString& args) {
} // namespace
-std::pair<QString, QStringList> CCManager::createCompileCommand(const QString& filename, const QString& outname) const {
+std::pair<QString, QStringList> CCManager::createCompileCommand(const QStringList& files,
+ const QString& outname) const {
const auto& currentISA = ProcessorHandler::get()->currentISA();
/**
@@ -178,7 +196,7 @@ std::pair<QString, QStringList> CCManager::createCompileCommand(const QString& f
<< "c";
// Substitute in and out files
- compileCommand << filename << "-o" << outname;
+ compileCommand << files << "-o" << outname;
// Substitute additional linker arguments
compileCommand << sanitizedArguments(RipesSettings::value(RIPES_SETTING_LDARGS).toString());

MODIFY
src/ccmanager.h
src/ccmanager.h
@@ -17,16 +17,13 @@ class CCManager : public QObject {
Q_OBJECT
public:
struct CCRes {
- QString inFile;
+ QStringList inFiles;
QString outFile;
QString errorMessage;
bool success = false;
bool aborted = false;
- void clean() {
- QFile::remove(inFile);
- QFile::remove(outFile);
- }
+ void clean() { QFile::remove(outFile); }
};
static CCManager& get() {
@@ -45,11 +42,11 @@ public:
* compiled file, such as source file, output file and compilation status. If no @p outname has been provided, the
* output file will be placed in a temporary directory.
*/
- CCRes compile(const QString& filename, QString outname = QString(), bool showProgressdiag = true);
+ CCRes compile(const QStringList& files, QString outname = QString(), bool showProgressdiag = true);
CCRes compile(const QTextDocument* source, QString outname = QString(), bool showProgressdiag = true);
CCRes compileRaw(const QString& rawsource, QString outname = QString(), bool showProgressdiag = true);
- std::pair<QString, QStringList> createCompileCommand(const QString& filename, const QString& outname) const;
+ std::pair<QString, QStringList> createCompileCommand(const QStringList& files, const QString& outname) const;
signals:
/**
@@ -85,6 +82,7 @@ private:
QProcess m_process;
bool m_errored = false;
bool m_aborted = false;
+ std::unique_ptr<QFile> m_tmpSrcFile;
};
} // namespace Ripes

MODIFY
src/io/iomanager.cpp
src/io/iomanager.cpp
@@ -136,6 +136,7 @@ void IOManager::updateSymbols() {
// Generate symbol mapping + header file
QStringList headerfile;
+ headerfile << "#pragma once";
for (const auto& p : m_peripherals) {
const QString& periphName = cName(p.first->name());
headerfile << "// *****************************************************************************";
@@ -154,13 +155,7 @@ void IOManager::updateSymbols() {
// Store header file at a temporary location
if (!(m_symbolsHeaderFile && (QFile::exists(m_symbolsHeaderFile->fileName())))) {
- const auto tempFileTemplate =
- QString(QDir::tempPath() + QDir::separator() + QCoreApplication::applicationName() + ".XXXXXX.h");
- QTemporaryFile tmpHdrFile = QTemporaryFile(tempFileTemplate);
- tmpHdrFile.setAutoRemove(false);
- if (tmpHdrFile.open()) {
- m_symbolsHeaderFile = std::make_unique<QFile>(tmpHdrFile.fileName());
- }
+ m_symbolsHeaderFile = std::make_unique<QFile>(QDir::tempPath() + QDir::separator() + "ripes_system.h");
}
if (m_symbolsHeaderFile->open(QIODevice::ReadWrite | QIODevice::Truncate)) {

MODIFY
src/settingsdialog.cpp
src/settingsdialog.cpp
@@ -247,7 +247,7 @@ void SettingsDialog::CCPathChanged(CCManager::CCRes res) {
m_ccpath->setPalette(palette);
// Update compile command preview
- auto [cstring, cargs] = CCManager::get().createCompileCommand("${input}", "${output}");
+ auto [cstring, cargs] = CCManager::get().createCompileCommand({"${input}"}, "${output}");
if (m_compileInfo) {
if (res.success) {
m_compileInfo->setText(cstring + " " + cargs.join(" "));

Include peripheral symbol header file in set of compiled files