Browse code

Add source code of the assembler compiler

Pawel Jablonski authored on 14/12/2022 19:04:16
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,87 @@
1
+/*
2
+ * Author: Pawel Jablonski
3
+ * E-mail: pj@xirx.net
4
+ * WWW: xirx.net
5
+ * GIT: git.xirx.net
6
+ *
7
+ * License: You can use this code however you like
8
+ * but leave information about the original author.
9
+ * Code is free for non-commercial and commercial use.
10
+ */
11
+
12
+#include <QCoreApplication>
13
+#include <QTextStream>
14
+
15
+#include "asm.h"
16
+
17
+/**
18
+ * Print an exit message and the usage prompt if needed
19
+ *
20
+ * @param message Message to print
21
+ * @param showUsage Show or not the usage prompt
22
+ */
23
+static void printExitMessage(const QString &message, const bool showUsage = false)
24
+{
25
+	QTextStream out(stdout);
26
+
27
+	out << message << "\n\n";
28
+
29
+	if(showUsage)
30
+	{
31
+		out << "Run as ROM build:\n";
32
+		out << "  asm rom [input_file] [output_bin] [output_map]\n\n";
33
+		out << "Run as APP build:\n";
34
+		out << "  asm app [input_file] [output_bin]\n\n";
35
+	}
36
+}
37
+
38
+/**
39
+ * Main entry function of the application
40
+ *
41
+ * @param argc Arguments count
42
+ * @param argv Arguments list stored in an array
43
+ */
44
+int main(int argc, char *argv[])
45
+{
46
+	QString inputFile;
47
+	QString outputFile;
48
+	QString outputMapFile;
49
+
50
+	// Prepare the assembler
51
+	Asm assembler = Asm();
52
+
53
+	if(argc >= 2)
54
+	{
55
+		if(!QString(argv[1]).compare("rom", Qt::CaseInsensitive))
56
+		{
57
+			if(argc == 5)
58
+			{
59
+				inputFile = QString(argv[2]);
60
+				outputFile = QString(argv[3]);
61
+				outputMapFile = QString(argv[4]);
62
+
63
+				// Compile the kernel
64
+				return(assembler.compileRom(inputFile, outputFile, outputMapFile));
65
+			}
66
+		}
67
+		else if(!QString(argv[1]).compare("app", Qt::CaseInsensitive))
68
+		{
69
+			if(argc == 4)
70
+			{
71
+				inputFile = QString(argv[2]);
72
+				outputFile = QString(argv[3]);
73
+
74
+				// Compile the application
75
+				return(assembler.compileApp(inputFile, outputFile));
76
+			}
77
+		}
78
+		else
79
+		{
80
+			printExitMessage(QString("ERROR: Unknow compilation mode"), true);
81
+			return(-1);
82
+		}
83
+	}
84
+
85
+	printExitMessage(QString("ERROR: Bad number of arguments"), true);
86
+	return(-1);
87
+}