summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Phillips <david@sighup.nz>2019-08-03 14:44:12 +1200
committerDavid Phillips <david@sighup.nz>2019-08-03 14:47:14 +1200
commit22575e056586a7810007952c717eff4e9e005bdb (patch)
tree92b7407994b7e183f4723ed80641bb75a6f2ca32
parent085145a1f49ffcae235fa559df254919366fe497 (diff)
downloadtoy-cpu-assembler-22575e056586a7810007952c717eff4e9e005bdb.tar.xz
File input and output routines away
-rw-r--r--Makefile26
-rw-r--r--asmcat.c2
-rw-r--r--assembler.c4
-rw-r--r--bincat.c8
-rw-r--r--disassembler.c6
-rw-r--r--input/input_bin.c (renamed from input_bin.c)5
-rw-r--r--input/input_bin.h (renamed from input_bin.h)2
-rw-r--r--output.h6
-rw-r--r--output/output_asm.c (renamed from output_asm.c)0
-rw-r--r--output/output_asm.h (renamed from output_asm.h)0
-rw-r--r--output/output_bin.c (renamed from output.c)2
-rw-r--r--output/output_bin.h6
12 files changed, 37 insertions, 30 deletions
diff --git a/Makefile b/Makefile
index d361fc5..b6d1e6d 100644
--- a/Makefile
+++ b/Makefile
@@ -1,14 +1,17 @@
-CFLAGS = -Wall -Wextra -Wpedantic
-
EXECUTABLES = assembler disassembler asmcat bincat
-ASM_OBJECTS = assembler.o lex.o parse.o output.o util.o
-DISASM_OBJECTS = disassembler.o input_bin.o output_asm.o util.o
-ASMCAT_OBJECTS = asmcat.o lex.o parse.o output_asm.o util.o
-BINCAT_OBJECTS = bincat.o input_bin.o output.o util.o
+ASM_OBJECTS = assembler.o lex.o parse.o output/output_bin.o util.o
+DISASM_OBJECTS = disassembler.o input/input_bin.o output/output_asm.o util.o
+ASMCAT_OBJECTS = asmcat.o lex.o parse.o output/output_asm.o util.o
+BINCAT_OBJECTS = bincat.o input/input_bin.o output/output_bin.o util.o
+
+INCLUDE += -I.
+
+CFLAGS += $(INCLUDE) -Wall -Wextra -Wpedantic
all: $(EXECUTABLES)
+# Main executables
assembler: $(ASM_OBJECTS)
disassembler: $(DISASM_OBJECTS)
@@ -17,14 +20,21 @@ asmcat: $(ASMCAT_OBJECTS)
bincat: $(BINCAT_OBJECTS)
+# Utils: FIXME lex and parse should be input?
lex.o: lex.h
parse.o: lex.h parse.h instruction.h util.h
-output.o: parse.h
-
util.o: lex.h instruction.h
+# Output modules
+output/output_bin.o: output/output_bin.h parse.h
+
+output/output_asm.o: output/output_asm.h parse.h util.h
+
+# Intput modules
+input/input_bin.o: input/input_bin.h parse.h
+
.PHONY: clean test
clean:
- rm -f $(EXECUTABLES) $(ASM_OBJECTS) $(DISASM_OBJECTS) $(ASMCAT_OBJECTS) $(BINCAT_OBJECTS)
diff --git a/asmcat.c b/asmcat.c
index 2791443..0acbfe3 100644
--- a/asmcat.c
+++ b/asmcat.c
@@ -5,7 +5,7 @@
#include "lex.h"
#include "parse.h"
#include "instruction.h"
-#include "output_asm.h"
+#include "output/output_asm.h"
void print_help(const char *argv0)
{
diff --git a/assembler.c b/assembler.c
index 36f3f03..9ffdb85 100644
--- a/assembler.c
+++ b/assembler.c
@@ -5,7 +5,7 @@
#include "lex.h"
#include "parse.h"
#include "instruction.h"
-#include "output.h"
+#include "output/output_bin.h"
void print_help(const char *argv0)
{
@@ -70,7 +70,7 @@ int main(int argc, char **argv)
/* FIXME insert optional pass for optimisation */
- if ((ret = output(fout, labels, labels_count, insts, insts_count)))
+ if ((ret = output_bin(fout, labels, labels_count, insts, insts_count)))
return error_ret && ret;
return 0;
diff --git a/bincat.c b/bincat.c
index fcda22e..bccb10d 100644
--- a/bincat.c
+++ b/bincat.c
@@ -4,8 +4,8 @@
#include "instruction.h"
#include "parse.h"
-#include "input_bin.h"
-#include "output.h"
+#include "input/input_bin.h"
+#include "output/output_bin.h"
void print_help(const char *argv0)
{
@@ -60,10 +60,10 @@ int main(int argc, char **argv)
labels = NULL;
labels_count = 0;
- if ((ret = disasm(fin, &insts, &insts_count)))
+ if ((ret = input_bin(fin, &insts, &insts_count)))
return error_ret && ret;
- if ((ret = output(fout, labels, labels_count, insts, insts_count)))
+ if ((ret = output_bin(fout, labels, labels_count, insts, insts_count)))
return error_ret && ret;
return 0;
diff --git a/disassembler.c b/disassembler.c
index 9b3d54c..8da5a38 100644
--- a/disassembler.c
+++ b/disassembler.c
@@ -4,8 +4,8 @@
#include "instruction.h"
#include "parse.h"
-#include "input_bin.h"
-#include "output_asm.h"
+#include "input/input_bin.h"
+#include "output/output_asm.h"
void print_help(const char *argv0)
{
@@ -61,7 +61,7 @@ int main(int argc, char **argv)
labels = NULL;
labels_count = 0;
- if ((ret = disasm(fin, &insts, &insts_count)))
+ if ((ret = input_bin(fin, &insts, &insts_count)))
return error_ret && ret;
if ((ret = output_asm(fout, labels, labels_count, insts, insts_count)))
diff --git a/input_bin.c b/input/input_bin.c
index c914cd1..e1c9d0d 100644
--- a/input_bin.c
+++ b/input/input_bin.c
@@ -83,9 +83,6 @@ static int add_instruction(struct instruction inst)
return 0;
}
-
-
-/* FIXME needs whatsit arguments. f, tok, tok length */
static int disasm_file(FILE *f)
{
int ret = 0;
@@ -164,7 +161,7 @@ static int disasm_file(FILE *f)
return ret;
}
-int disasm(FILE *f, struct instruction **i, size_t *i_count)
+int input_bin(FILE *f, struct instruction **i, size_t *i_count)
{
int ret = 0;
diff --git a/input_bin.h b/input/input_bin.h
index 7683835..00e296c 100644
--- a/input_bin.h
+++ b/input/input_bin.h
@@ -1,6 +1,6 @@
#ifndef INPUT_BIN_H
#define INPUT_BIN_H
-int disasm(FILE *f, struct instruction **i, size_t *i_count);
+int input_bin(FILE *f, struct instruction **i, size_t *i_count);
#endif /* INPUT_BIN_H */
diff --git a/output.h b/output.h
deleted file mode 100644
index c5edc97..0000000
--- a/output.h
+++ /dev/null
@@ -1,6 +0,0 @@
-#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/output_asm.c b/output/output_asm.c
index fd9f792..fd9f792 100644
--- a/output_asm.c
+++ b/output/output_asm.c
diff --git a/output_asm.h b/output/output_asm.h
index b4afd2a..b4afd2a 100644
--- a/output_asm.h
+++ b/output/output_asm.h
diff --git a/output.c b/output/output_bin.c
index d536b7e..1c7b961 100644
--- a/output.c
+++ b/output/output_bin.c
@@ -183,7 +183,7 @@ int output_single(FILE *f, struct label *labels, size_t labels_count, struct ins
return 0;
}
-int output(FILE *fout, struct label *labels, size_t label_count, struct instruction *insts, size_t insts_count)
+int output_bin(FILE *fout, struct label *labels, size_t label_count, struct instruction *insts, size_t insts_count)
{
size_t i = 0;
cur_byte = 0;
diff --git a/output/output_bin.h b/output/output_bin.h
new file mode 100644
index 0000000..d57326b
--- /dev/null
+++ b/output/output_bin.h
@@ -0,0 +1,6 @@
+#ifndef OUTPUT_H
+#define OUTPUT_H
+
+int output_bin(FILE *fout, struct label *labels, size_t label_count, struct instruction *insts, size_t insts_count);
+
+#endif /* OUTPUT_H */