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,57 @@
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
+#ifndef COMPILER_H
13
+#define COMPILER_H
14
+
15
+#include <QString>
16
+#include <QTextStream>
17
+#include <QList>
18
+#include <QRegularExpression>
19
+#include <QVector>
20
+
21
+#include "instruction.h"
22
+#include "codeitem.h"
23
+#include "codesection.h"
24
+#include "ramitem.h"
25
+#include "flashitem.h"
26
+#include "data.h"
27
+#include "datalist.h"
28
+
29
+//! This class transforms a parsed code to the binary executable form
30
+class Compiler
31
+{
32
+	public:
33
+		Compiler(DataList &dataList);
34
+
35
+		void addInstruction(const Instruction &instruction);
36
+		bool compile();
37
+
38
+	private:
39
+		QList<Instruction::Arg> checkParamType(const QString &param);
40
+
41
+		bool compileRam(Data &data);
42
+		bool compileFlash(Data &data);
43
+		bool compileCode(Data &data);
44
+
45
+		bool parseParamAB(const QString &param, unsigned char &value);
46
+		bool parseParamABXY(const QString &param, unsigned char &value);
47
+		bool parseParamVal256(const QString &param, unsigned char &value);
48
+		bool parseParamAddr(const QString &param, unsigned char &valueLow, unsigned char &valueHigh);
49
+
50
+		bool isAddrLabel(const QString &param) const;
51
+		bool isAddrPartLabel(const QString &param) const;
52
+
53
+		DataList &dataList; //!< List of data for each source file
54
+		QList<Instruction> instructionList; //!< List of instructions supported by the CPU
55
+};
56
+
57
+#endif