diff options
| author | David Phillips <david@sighup.nz> | 2019-08-03 13:41:33 +1200 | 
|---|---|---|
| committer | David Phillips <david@sighup.nz> | 2019-08-03 14:00:37 +1200 | 
| commit | f0f5c379513ada7482aa4ead08df1043e9c7d267 (patch) | |
| tree | ca31b963649513642d2b7dd05ef7ace19a9b48e7 | |
| parent | 28d6a88c02f10b75fb4c5cb46178d2ef71629494 (diff) | |
| download | toy-cpu-assembler-f0f5c379513ada7482aa4ead08df1043e9c7d267.tar.xz | |
Enable -Wall and -Wextra, fix warnings
| -rw-r--r-- | Makefile | 8 | ||||
| -rw-r--r-- | assembler.c | 4 | ||||
| -rw-r--r-- | disassembler.c | 4 | ||||
| -rw-r--r-- | input_bin.c | 3 | ||||
| -rw-r--r-- | lex.c | 1 | ||||
| -rw-r--r-- | output.c | 1 | ||||
| -rw-r--r-- | output_asm.c | 2 | ||||
| -rw-r--r-- | parse.c | 1 | ||||
| -rw-r--r-- | parse.h | 2 | 
9 files changed, 15 insertions, 11 deletions
@@ -1,7 +1,11 @@ +CFLAGS = -Wall -Wextra + +EXECUTABLES = assembler disassembler +  ASM_OBJECTS = lex.o parse.o output.o assembler.o util.o  DISASM_OBJECTS = disassembler.o util.o input_bin.o output_asm.o -all: assembler disassembler +all: $(EXECUTABLES)  assembler: $(ASM_OBJECTS) @@ -17,7 +21,7 @@ util.o: lex.h instruction.h  .PHONY: clean test  clean: -	- rm -f assembler disasm $(ASM_OBJECTS) +	- rm -f $(EXECUTABLES) $(ASM_OBJECTS) $(DISASM_OBJECTS)  test: all  	make -C test test diff --git a/assembler.c b/assembler.c index 685fcf6..36f3f03 100644 --- a/assembler.c +++ b/assembler.c @@ -63,14 +63,14 @@ int main(int argc, char **argv)  	size_t insts_count;  	struct label *labels;  	size_t labels_count; -	if (ret = parse(path_in, fin, &labels, &labels_count, tokens, tok_count, &insts, &insts_count)) +	if ((ret = parse(path_in, fin, &labels, &labels_count, tokens, tok_count, &insts, &insts_count)))  		return error_ret && 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)) +	if ((ret = output(fout, labels, labels_count, insts, insts_count)))  		return error_ret && ret;  	return 0; diff --git a/disassembler.c b/disassembler.c index 2ceee3f..9b3d54c 100644 --- a/disassembler.c +++ b/disassembler.c @@ -61,10 +61,10 @@ int main(int argc, char **argv)  	labels = NULL;  	labels_count = 0; -	if (ret = disasm(fin, &insts, &insts_count)) +	if ((ret = disasm(fin, &insts, &insts_count)))  		return error_ret && ret; -	if (ret = output_asm(fout, labels, labels_count, insts, insts_count)) +	if ((ret = output_asm(fout, labels, labels_count, insts, insts_count)))  		return error_ret && ret;  	return 0; diff --git a/input_bin.c b/input_bin.c index 54a99f3..c914cd1 100644 --- a/input_bin.c +++ b/input_bin.c @@ -7,6 +7,7 @@  static void disasm_rtype(uint16_t i, uint16_t unused, struct instruction *inst)  { +	(void)unused;  	inst->type = INST_TYPE_R;  	inst->inst.r.oper = GET_OPER(i);  	inst->inst.r.dest = GET_REG_DEST(i); @@ -16,6 +17,7 @@ static void disasm_rtype(uint16_t i, uint16_t unused, struct instruction *inst)  static void disasm_nitype(uint16_t i, uint16_t unused, struct instruction *inst)  { +	(void)unused;  	inst->type = INST_TYPE_NI;  	inst->inst.i.oper = GET_OPER(i);  	inst->inst.i.dest = GET_REG_DEST(i); @@ -36,6 +38,7 @@ static void disasm_witype(uint16_t i, uint16_t imm, struct instruction *inst)  static void disasm_jreg(uint16_t i, uint16_t unused, struct instruction *inst)  { +	(void)unused;  	inst->type = INST_TYPE_JR;  	inst->inst.jr.cond = GET_JB_COND(i);  	inst->inst.jr.reg = GET_JUMP_REG(i); @@ -256,7 +256,6 @@ static int lex_num(struct token *t)  static int lex_misc(struct token *t) {  	int i = 0; -	int j = 0;  	for (i = column; isalnum(buffer[i]); i++) {  		; @@ -117,7 +117,6 @@ int output_single(FILE *f, struct label *labels, size_t labels_count, struct ins  {  	int len = 0;  	uint32_t i = 0; -	uint16_t imm = 0;  	switch (inst.type) {  		case INST_TYPE_R: diff --git a/output_asm.c b/output_asm.c index b1ccfc9..fd9f792 100644 --- a/output_asm.c +++ b/output_asm.c @@ -46,7 +46,7 @@ void emit_single_ji_type(FILE *f, struct ji_type inst)  {  	const char *cond = get_asm_from_j(inst.cond); -	fprintf(f, "%s  %s\n", cond, inst.imm.value); +	fprintf(f, "%s  0x%x\n", cond, inst.imm.value);  }  void emit_single_jr_type(FILE *f, struct jr_type inst) @@ -474,7 +474,6 @@ int parse_instruction(void)  int parse(const char *filename_local, FILE* fd_local, struct label **labels_local, size_t *labels_count_local, struct token *tokens_local, size_t tokens_count_local, struct instruction **instructions, size_t *instructions_count)  {  	int ret = 0; -	size_t i = 0;  	filename = filename_local;  	fd = fd_local;  	tokens = tokens_local; @@ -14,7 +14,7 @@ struct label {  union immediate {  	const char *label; -	int16_t value; +	uint16_t value;  };  struct r_type {  | 
