summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Phillips <david@sighup.nz>2019-04-14 16:14:02 +1200
committerDavid Phillips <david@sighup.nz>2019-08-03 12:43:30 +1200
commit38e3922cf7f521d1e119cbeff8722f0d8ca4c66a (patch)
tree1700548e0456e17ff4d6468ea4115f0049cbbc1b
parentac8150b7601d9611818bb8b265a125a347a67004 (diff)
downloadtoy-cpu-assembler-38e3922cf7f521d1e119cbeff8722f0d8ca4c66a.tar.xz
Tidy assembler.c
-rw-r--r--assembler.c55
-rw-r--r--output.h6
-rw-r--r--parse.c1
3 files changed, 13 insertions, 49 deletions
diff --git a/assembler.c b/assembler.c
index eaf4d38..142870f 100644
--- a/assembler.c
+++ b/assembler.c
@@ -4,55 +4,7 @@
#include "lex.h"
#include "parse.h"
#include "instruction.h"
-
-#if 0
-/**
- * Types for intermediate storage of instructions
- */
-struct r_type {
- enum OPER operation;
- enum REG dest;
- enum REG left;
- enum REG right;
-};
-
-struct i_type { /* covers WI and NI */
- enum OPER operation;
- enum REG dest;
- enum REG left;
- int16_t immediate;
-};
-
-struct jr_type {
- enum JCOND condition;
- enum REG reg;
-};
-
-struct ji_type {
- enum JCOND condition;
- uint16_t immediate;
-};
-
-struct b_type { /* FIXME merge with ji_type? */
- enum JCOND condition;
- uint16_t immediate; /* capped to 10 bits by IS */
-};
-
-/* Union for bringing above together */
-union instruction_union {
- struct r_type r;
- struct i_type i;
- struct jr_type jr;
- struct ji_type ji;
- struct b_type b;
-};
-
-struct instruction {
- enum INST_TYPE type;
- union instruction_union i;
-};
-/**/
-#endif
+#include "output.h"
int main(int argc, char **argv)
{
@@ -83,6 +35,7 @@ int main(int argc, char **argv)
if ((tokens = lex(argv[1], fin, &tok_count)) == NULL)
return 2;
+ /* FIXME package these things into `tok_result`, `parse_result` etc */
struct instruction *insts;
size_t insts_count;
struct label *labels;
@@ -90,6 +43,10 @@ int main(int argc, char **argv)
if (ret = parse(argv[1], fin, &labels, &labels_count, tokens, tok_count, &insts, &insts_count))
return ret;
+ /* FIXME insert pass for sanity checking identifiers, sizes of values */
+
+ /* FIXME insert optional pass for optimisation */
+
if (ret = output(fout, labels, labels_count, insts, insts_count))
return ret;
diff --git a/output.h b/output.h
new file mode 100644
index 0000000..c5edc97
--- /dev/null
+++ b/output.h
@@ -0,0 +1,6 @@
+#ifndef OUTPUT_H
+#define OUTPUT_H
+
+int output(FILE *fout, struct label *labels, size_t label_count, struct instruction *insts, size_t insts_count);
+
+#endif /* OUTPUT_H */
diff --git a/parse.c b/parse.c
index f5caf4d..6be202e 100644
--- a/parse.c
+++ b/parse.c
@@ -10,6 +10,7 @@
#include "parse.h"
#include "instruction.h"
#include "tok_util.h"
+
#if 0
struct label {
char *name;