From f0f5c379513ada7482aa4ead08df1043e9c7d267 Mon Sep 17 00:00:00 2001 From: David Phillips Date: Sat, 3 Aug 2019 13:41:33 +1200 Subject: Enable -Wall and -Wextra, fix warnings --- Makefile | 8 ++++++-- assembler.c | 4 ++-- disassembler.c | 4 ++-- input_bin.c | 3 +++ lex.c | 1 - output.c | 1 - output_asm.c | 2 +- parse.c | 1 - parse.h | 2 +- 9 files changed, 15 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index 843ccca..752b867 100644 --- a/Makefile +++ b/Makefile @@ -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); diff --git a/lex.c b/lex.c index 7384ca4..6fe78b3 100644 --- a/lex.c +++ b/lex.c @@ -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++) { ; diff --git a/output.c b/output.c index 047040a..d536b7e 100644 --- a/output.c +++ b/output.c @@ -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) diff --git a/parse.c b/parse.c index 5da5b61..45758c9 100644 --- a/parse.c +++ b/parse.c @@ -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; diff --git a/parse.h b/parse.h index a240313..5feb420 100644 --- a/parse.h +++ b/parse.h @@ -14,7 +14,7 @@ struct label { union immediate { const char *label; - int16_t value; + uint16_t value; }; struct r_type { -- cgit v1.1