-
-
Notifications
You must be signed in to change notification settings - Fork 276
/
main.cpp
114 lines (98 loc) · 3.19 KB
/
main.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
#include <QApplication>
#include <QCommandLineParser>
#include <QFileInfo>
#include <QMessageBox>
#include <QResource>
#include <QTimer>
#include <iostream>
#include "src/cli/clioptions.h"
#include "src/cli/clirunner.h"
#include "src/mainwindow.h"
using namespace std;
void initParser(QCommandLineParser &parser, Ripes::CLIModeOptions &options) {
QString helpText =
"The command line interface allows for assembling/compiling/executing a "
"\n"
"program on an arbitrary processor model and subsequent reporting of \n"
"execution telemetry.\nCommand line mode is enabled when the '--mode "
"sh' argument is provided.";
helpText.prepend("Ripes command line interface.\n");
parser.setApplicationDescription(helpText);
QCommandLineOption modeOption("mode", "Ripes mode [gui, cli]", "mode", "gui");
parser.addOption(modeOption);
Ripes::addCLIOptions(parser, options);
}
enum CommandLineParseResult {
CommandLineError,
CommandLineHelpRequested,
CommandLineGUI,
CommandLineCLI
};
CommandLineParseResult parseCommandLine(QCommandLineParser &parser,
QString &errorMessage) {
const QCommandLineOption helpOption = parser.addHelpOption();
if (!parser.parse(QCoreApplication::arguments())) {
errorMessage = parser.errorText();
return CommandLineError;
}
if (parser.isSet(helpOption))
return CommandLineHelpRequested;
if (parser.value("mode") == "gui")
return CommandLineGUI;
else if (parser.value("mode") == "cli")
return CommandLineCLI;
else {
errorMessage = "Invalid mode: " + parser.value("mode");
return CommandLineError;
}
}
int guiMode(QApplication &app) {
Ripes::MainWindow m;
#ifdef Q_OS_WASM
// In the WASM build, we'll just want a full-screen application that can't be
// dragged or resized by the user.
m.setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
#endif
// The following sequence of events manages to successfully start the
// application as maximized, with the processor at a reasonable size. This has
// been found to be specially a problem on windows.
m.resize(800, 600);
m.showMaximized();
m.setWindowState(Qt::WindowMaximized);
QTimer::singleShot(100, &m, [&m] { m.fitToView(); });
return app.exec();
}
int CLIMode(QCommandLineParser &parser, Ripes::CLIModeOptions &options) {
QString err;
if (!Ripes::parseCLIOptions(parser, err, options)) {
std::cerr << "ERROR: " << err.toStdString() << std::endl;
parser.showHelp();
return 0;
}
return Ripes::CLIRunner(options).run();
}
int main(int argc, char **argv) {
Q_INIT_RESOURCE(icons);
Q_INIT_RESOURCE(examples);
Q_INIT_RESOURCE(layouts);
Q_INIT_RESOURCE(fonts);
QApplication app(argc, argv);
QCoreApplication::setApplicationName("Ripes");
QCommandLineParser parser;
Ripes::CLIModeOptions options;
initParser(parser, options);
QString err;
switch (parseCommandLine(parser, err)) {
case CommandLineError:
std::cerr << "ERROR: " << err.toStdString() << std::endl;
parser.showHelp();
return 0;
case CommandLineHelpRequested:
parser.showHelp();
return 0;
case CommandLineGUI:
return guiMode(app);
case CommandLineCLI:
return CLIMode(parser, options);
}
}