-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwindow.cpp
133 lines (110 loc) · 3.32 KB
/
mainwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#include "mainwindow.h"
#include <QProcess>
#include <QAction>
#include <QToolButton>
#include <QPalette>
QCodeTextEdit* MainWindow::AddTab(const QString& Name, bool ReadOnly)
{
QCodeTextEdit* Text = new QCodeTextEdit(Tabs);
Text->setReadOnly(ReadOnly);
Tabs->addTab(Text,Name);
return Text;
}
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
setWindowTitle("LLVM Explorer");
Settings = new QSettings("LLVMExplorer",QSettings::IniFormat);
Tabs = new QTabWidget(this);
CreateToolbar();
setCentralWidget(Tabs);
CPPCode = AddTab("&C++");
LLVMCode = AddTab("&LLVM IR");
LLVMAPICode = AddTab("LLVM C++ &API");
resize(1024,768);
}
MainWindow::~MainWindow()
{
}
void MainWindow::CreateToolbar()
{
Toolbar = addToolBar("Actions");
QAction* Run = Toolbar->addAction("&C++ -> LLVM API");
Run->setShortcut(QKeySequence(Qt::Key_F1));
connect(Run,SIGNAL(triggered()),this,SLOT(Run()));
QAction* RunIR = Toolbar->addAction("&LLVM IR -> LLVM API");
RunIR->setShortcut(QKeySequence(Qt::Key_F2));
connect(RunIR,SIGNAL(triggered()),this,SLOT(RunIR()));
}
void MainWindow::Run()
{
QString Path = "C:\\LLVM\\bin\\";
QProcess Clang(this);
Clang.setWorkingDirectory(Path);
Clang.start("clang++",QStringList() << "-S" << "-x" << "c++" << "-emit-llvm" << "-" << "-o" << "-");
Clang.waitForStarted();
Clang.write(CPPCode->toPlainText().toLocal8Bit().constData());
Clang.write("\n\0");
Clang.closeWriteChannel();
Clang.waitForFinished();
QString ClangError(Clang.readAllStandardError());
if(ClangError.size())
{
LLVMCode->setTextColor(Qt::red);
LLVMCode->setPlainText(ClangError);
Tabs->setCurrentWidget(LLVMCode);
return;
}
else
LLVMCode->setTextColor(Qt::black);
QString BitCode(Clang.readAllStandardOutput());
LLVMCode->setPlainText(BitCode);
QProcess LLC(this);
LLC.setWorkingDirectory(Path);
LLC.start("llc",QStringList() << "-march=cpp" << "-" << "-o" << "-");
LLC.waitForStarted();
LLC.write(BitCode.toLocal8Bit().constData());
LLC.closeWriteChannel();
LLC.waitForFinished();
QString LLCError(LLC.readAllStandardError());
if(LLCError.size())
{
LLVMAPICode->setTextColor(Qt::red);
LLVMAPICode->setPlainText(LLCError);
Tabs->setCurrentWidget(LLVMAPICode);
return;
}
else
LLVMAPICode->setTextColor(Qt::black);
LLVMAPICode->setPlainText(QString(LLC.readAllStandardOutput()));
Tabs->setCurrentWidget(LLVMCode);
}
void MainWindow::RunIR()
{
QString Path = "C:\\LLVM\\bin\\";
QString BitCode = LLVMCode->toPlainText();
QProcess LLC(this);
LLC.setWorkingDirectory(Path);
LLC.start("llc",QStringList() << "-march=cpp" << "-" << "-o" << "-");
LLC.waitForStarted();
LLC.write(BitCode.toLocal8Bit().constData());
LLC.closeWriteChannel();
LLC.waitForFinished();
QString LLCError(LLC.readAllStandardError());
if(LLCError.size())
{
LLVMAPICode->setTextColor(Qt::red);
LLVMAPICode->setPlainText(LLCError);
return;
}
else
LLVMAPICode->setTextColor(Qt::black);
LLVMAPICode->setPlainText(QString(LLC.readAllStandardOutput()));
Tabs->setCurrentWidget(LLVMAPICode);
}
void MainWindow::Open()
{
}
void MainWindow::Save()
{
}