Commit 92a0a2b8 authored by Victor Yacovlev's avatar Victor Yacovlev

GUI: LLVM code generation in separate thread with message dialog

parent ca172d06
This diff is collapsed.
...@@ -1137,16 +1137,67 @@ void MainWindow::prepareInsertMenu() ...@@ -1137,16 +1137,67 @@ void MainWindow::prepareInsertMenu()
} }
} }
void MakeNativeExecutableWorker::run()
{
const AST::DataPtr ast = analizer->compiler()->abstractSyntaxTree();
QString mimeType;
generator->generateExecuable(ast, buffer, mimeType, fileSuffix);
// sleep(5);
}
void MakeNativeExecutableWorker::cancel()
{
canceledMutex.lock();
canceled = true;
canceledMutex.unlock();
}
bool MakeNativeExecutableWorker::isCanceled() const
{
bool result = false;
canceledMutex.lock();
result = canceled;
canceledMutex.unlock();
return result;
}
void MainWindow::makeNativeExecutable() void MainWindow::makeNativeExecutable()
{ {
TabWidgetElement * twe = qobject_cast<TabWidgetElement*>(tabWidget_->currentWidget()); TabWidgetElement * twe = qobject_cast<TabWidgetElement*>(tabWidget_->currentWidget());
twe->editor()->ensureAnalized(); twe->editor()->ensureAnalized();
const AST::DataPtr ast = twe->editor()->analizer()->compiler()->abstractSyntaxTree();
QString fileSuffix; MakeNativeExecutableWorker * worker = new MakeNativeExecutableWorker();
QString mimeType; connect(worker, SIGNAL(finished()), this, SLOT(saveNativeExecutable()));
QByteArray buffer; worker->analizer = twe->editor()->analizer();
twe->kumirProgram()->kumirNativeGenerator()->generateExecuable(ast, buffer, mimeType, fileSuffix); worker->generator = KumirProgram::kumirNativeGenerator();
QString fileName = twe->editor()->documentContents().sourceUrl.toLocalFile(); worker->fileName = twe->editor()->documentContents().sourceUrl.toLocalFile();
worker->canceled = false;
worker->progressDialog = new QMessageBox(
QMessageBox::NoIcon,
tr("Please wait..."),
tr("Executable file generation in progress."),
QMessageBox::Cancel,
this
);
worker->progressDialog->button(QMessageBox::Cancel)->setText(tr("Cancel"));
connect(worker->progressDialog->button(QMessageBox::Cancel), SIGNAL(clicked()),
worker, SLOT(cancel()));
worker->progressDialog->show();
worker->start(QThread::IdlePriority);
}
void MainWindow::saveNativeExecutable()
{
MakeNativeExecutableWorker * worker = qobject_cast<MakeNativeExecutableWorker*>(sender());
worker->progressDialog->close();
if (worker->isCanceled()) {
worker->progressDialog->deleteLater();
worker->deleteLater();
return;
}
QString fileName = worker->fileName;
QString fileSuffix = worker->fileSuffix;
#ifndef Q_OS_WIN32 #ifndef Q_OS_WIN32
fileSuffix = "bin"; fileSuffix = "bin";
#endif #endif
...@@ -1170,7 +1221,7 @@ void MainWindow::makeNativeExecutable() ...@@ -1170,7 +1221,7 @@ void MainWindow::makeNativeExecutable()
else { else {
initialPath = QFileInfo(lastFileName).absoluteDir().absolutePath(); initialPath = QFileInfo(lastFileName).absoluteDir().absolutePath();
} }
initialPath += "/" + suggestNewFileName(fileSuffix, twe->editor()->analizer(), initialPath); initialPath += "/" + suggestNewFileName(fileSuffix, worker->analizer, initialPath);
} }
else { else {
initialPath = fileName; initialPath = fileName;
...@@ -1192,13 +1243,15 @@ void MainWindow::makeNativeExecutable() ...@@ -1192,13 +1243,15 @@ void MainWindow::makeNativeExecutable()
m_plugin->mySettings()->setValue(Plugin::RecentFileKey, settingsEntry); m_plugin->mySettings()->setValue(Plugin::RecentFileKey, settingsEntry);
QFile f(fileName); QFile f(fileName);
if (f.open(QIODevice::WriteOnly)) { if (f.open(QIODevice::WriteOnly)) {
f.write(buffer); f.write(worker->buffer);
f.close(); f.close();
QFile::Permissions ps = f.permissions(); QFile::Permissions ps = f.permissions();
ps |= QFile::ExeGroup | QFile::ExeOwner | QFile::ExeOther; ps |= QFile::ExeGroup | QFile::ExeOwner | QFile::ExeOther;
QFile::setPermissions(fileName, ps); QFile::setPermissions(fileName, ps);
} }
} }
worker->progressDialog->deleteLater();
worker->deleteLater();
} }
bool MainWindow::saveCurrentFileAs() bool MainWindow::saveCurrentFileAs()
......
...@@ -28,6 +28,27 @@ namespace Ui { ...@@ -28,6 +28,27 @@ namespace Ui {
} }
class MakeNativeExecutableWorker
: public QThread
{
Q_OBJECT
public:
Shared::GeneratorInterface * generator;
Shared::Analizer::InstanceInterface * analizer;
QString fileName;
QString fileSuffix;
QByteArray buffer;
QMessageBox * progressDialog;
bool canceled;
mutable QMutex canceledMutex;
bool isCanceled() const;
public slots:
void cancel();
private:
void run();
};
class MainWindow : public QMainWindow class MainWindow : public QMainWindow
{ {
Q_OBJECT Q_OBJECT
...@@ -93,6 +114,7 @@ public slots: ...@@ -93,6 +114,7 @@ public slots:
void updateSettings(ExtensionSystem::SettingsPtr settings, const QStringList & keys); void updateSettings(ExtensionSystem::SettingsPtr settings, const QStringList & keys);
void updateStartPageTitle(const QString & title, const Shared::Browser::InstanceInterface * sender); void updateStartPageTitle(const QString & title, const Shared::Browser::InstanceInterface * sender);
void makeNativeExecutable(); void makeNativeExecutable();
void saveNativeExecutable();
private slots: private slots:
void loadRecentFile(); void loadRecentFile();
...@@ -123,6 +145,7 @@ private slots: ...@@ -123,6 +145,7 @@ private slots:
private: private:
void createSettingsDialog(); void createSettingsDialog();
void prepareLayoutChange(); void prepareLayoutChange();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment