asm/dasm: Improve cflags
authorMichael Buesch <mb@bu3sch.de>
Tue, 21 Sep 2010 10:31:45 +0000 (12:31 +0200)
committerMichael Buesch <mb@bu3sch.de>
Tue, 21 Sep 2010 10:31:45 +0000 (12:31 +0200)
Signed-off-by: Michael Buesch <mb@bu3sch.de>
assembler/Makefile
assembler/main.c
assembler/scanner.l
disassembler/Makefile
disassembler/main.c

index aaaf7b75e45c26aeb7d83dc5cc3c962e0a3583f9..6bc332195dfd9bbd2c0cafced8177c3ba7f34192 100644 (file)
@@ -18,8 +18,10 @@ QUIET_SPARSE = @/bin/true
 endif
 
 PREFIX         ?= /usr/local
-CFLAGS         ?= -O2 -fomit-frame-pointer -D_BSD_SOURCE -D_GNU_SOURCE
-CFLAGS         += -std=c99 -Wall -D_BSD_SOURCE -D_GNU_SOURCE
+CFLAGS         ?= -O2 -fomit-frame-pointer -pipe
+CFLAGS         += -std=gnu99 -D_GNU_SOURCE \
+                  -Wall -Wextra -Wformat=2 -Wundef -Wno-unused-parameter \
+                  -Wshadow -Wpointer-arith
 SPARSEFLAGS    = $(CFLAGS) -D__transparent_union__=__unused__ -D_STRING_ARCH_unaligned=1 \
                  -D__builtin_stpcpy=stpcpy
 LDFLAGS                += -lfl
index 8abe03c8fbbe51ac3371b0c9990ce313f6aa6dd3..ad180b274bc8ac2520718a83f7590d5a3b23011b 100644 (file)
@@ -429,7 +429,7 @@ static struct code_output * do_assemble_insn(struct assembler_context *ctx,
                                             struct instruction *insn,
                                             unsigned int opcode)
 {
-       int i;
+       unsigned int i;
        struct operlist *ol;
        int nr_oper = 0;
        uint64_t code = 0;
@@ -1017,7 +1017,7 @@ static void resolve_labels(struct assembler_context *ctx)
 {
        struct code_output *c;
        int addr;
-       int i;
+       unsigned int i;
        unsigned int current_address;
 
        /* Calculate the absolute addresses for each instruction. */
index 436d3336c05795e7f10bcb36ebb3b62a9656829c..11f38907da743740a13996007436eb4fdfb5bafe 100644 (file)
@@ -183,7 +183,7 @@ static void interpret_cppinfo(const char *str)
                goto error;
        memset(tmp, 0, sizeof(tmp));
        memcpy(tmp, str, min(sizeof(tmp) - 1,
-                            (int)(found - str)));
+                            (size_t)(found - str)));
        cur_lineinfo.lineno = strtoul(tmp, NULL, 10) - 1;
        str = found;
        str++;
@@ -200,7 +200,7 @@ static void interpret_cppinfo(const char *str)
        memset(cur_lineinfo.file, 0, sizeof(cur_lineinfo.file));
        memcpy(cur_lineinfo.file, str,
               min(sizeof(cur_lineinfo.file) - 1,
-                  (int)(found - str)));
+                  (size_t)(found - str)));
 
        return;
 error:
index bf2e19786d579be5bc72743ed23aa87694299ee4..fe59ece3be6c80572ab659e2e93fa926871a9a19 100644 (file)
@@ -14,8 +14,10 @@ QUIET_SPARSE = @/bin/true
 endif
 
 PREFIX         ?= /usr/local
-CFLAGS         ?= -O2 -fomit-frame-pointer
-CFLAGS         += -std=gnu99 -Wall -D_BSD_SOURCE -D_GNU_SOURCE
+CFLAGS         ?= -O2 -fomit-frame-pointer -pipe
+CFLAGS         += -std=gnu99 -D_GNU_SOURCE \
+                  -Wall -Wextra -Wformat=2 -Wundef -Wno-unused-parameter \
+                  -Wshadow -Wpointer-arith
 SPARSEFLAGS    = $(CFLAGS) -D__transparent_union__=__unused__ -D_STRING_ARCH_unaligned=1
 LDFLAGS                ?=
 
index 09e7643038b64f4d963bc5a9fe255269e80938ae..b73c3bf2c36ea20d0b65bdc9d9386457d5ccb154 100644 (file)
@@ -788,9 +788,9 @@ static void resolve_labels(struct disassembler_context *ctx)
 static void emit_asm(struct disassembler_context *ctx)
 {
        struct statement *stmt;
-       int first, i;
+       int first;
        int err;
-       unsigned int addr = 0;
+       unsigned int i, addr = 0;
 
        err = open_output_file();
        if (err)
@@ -808,14 +808,16 @@ static void emit_asm(struct disassembler_context *ctx)
                        first = 1;
                        for (i = 0; i < ARRAY_SIZE(stmt->u.insn.operands); i++) {
                                if (!stmt->u.insn.operands[i] &&
-                                   stmt->u.insn.is_labelref != i)
+                                   (stmt->u.insn.is_labelref < 0 ||
+                                    (unsigned int)stmt->u.insn.is_labelref != i))
                                        continue;
                                if (first)
                                        fprintf(outfile, "\t");
                                if (!first)
                                        fprintf(outfile, ", ");
                                first = 0;
-                               if (stmt->u.insn.is_labelref == i) {
+                               if (stmt->u.insn.is_labelref >= 0 &&
+                                   (unsigned int)stmt->u.insn.is_labelref == i) {
                                        fprintf(outfile, "%s",
                                                stmt->u.insn.labelref->u.label.name);
                                } else {