diff --git a/src/avra.c b/src/avra.c index 5aec61d..8c2fbc3 100644 --- a/src/avra.c +++ b/src/avra.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include "misc.h" @@ -259,7 +260,7 @@ assemble(struct prog_info *pi) int load_arg_defines(struct prog_info *pi) { - int i; + int64_t i; char *expr; char buff[256]; struct data_list *define; @@ -285,13 +286,13 @@ load_arg_defines(struct prog_info *pi) if (def_const(pi, buff, i)==False) return (False); } else { /* Pass 2 */ - int j; + int64_t j; if (get_constant(pi, buff, &j)==False) { /* Defined in Pass 1 and now missing ? */ fprintf(stderr,"Constant %s is missing in pass 2\n",buff); return (False); } if (i != j) { - fprintf(stderr,"Constant %s changed value from %d in pass1 to %d in pass 2\n",buff,j,i); + fprintf(stderr,"Constant %s changed value from %" PRId64 " in pass1 to %" PRId64 " in pass 2\n",buff,j,i); return (False); } /* OK. Definition is unchanged */ @@ -458,7 +459,7 @@ print_msg(struct prog_info *pi, int type, char *fmt, ...) int -def_const(struct prog_info *pi, const char *name, int value) +def_const(struct prog_info *pi, const char *name, int64_t value) { struct label *label; label = malloc(sizeof(struct label)); @@ -651,7 +652,7 @@ test_orglist(struct segment_info *si) /* Get the value of a label. Return FALSE if label was not found */ int -get_label(struct prog_info *pi,char *name,int *value) +get_label(struct prog_info *pi,char *name,int64_t *value) { struct label *label=search_symbol(pi,pi->first_label,name,NULL); if (label==NULL) return False; @@ -660,7 +661,7 @@ get_label(struct prog_info *pi,char *name,int *value) } int -get_constant(struct prog_info *pi,char *name,int *value) +get_constant(struct prog_info *pi,char *name,int64_t *value) { struct label *label=search_symbol(pi,pi->first_constant,name,NULL); if (label==NULL) return False; @@ -669,7 +670,7 @@ get_constant(struct prog_info *pi,char *name,int *value) } int -get_variable(struct prog_info *pi,char *name,int *value) +get_variable(struct prog_info *pi,char *name,int64_t *value) { struct label *label=search_symbol(pi,pi->first_variable,name,NULL); if (label==NULL) return False; diff --git a/src/avra.h b/src/avra.h index 363d91f..8b96a61 100644 --- a/src/avra.h +++ b/src/avra.h @@ -30,6 +30,7 @@ #include #include +#include #define IS_HOR_SPACE(x) ((x == ' ') || (x == 9)) #define IS_LABEL(x) (isalnum(x) || (x == '%') || (x == '_')) @@ -221,7 +222,7 @@ struct def { struct label { struct label *next; char *name; - int value; + int64_t value; }; struct macro { @@ -286,7 +287,7 @@ void init_segment_size(struct prog_info *pi, struct device *device); void rewind_segments(struct prog_info *pi); void advance_ip(struct segment_info *si, int offset); -int def_const(struct prog_info *pi, const char *name, int value); +int def_const(struct prog_info *pi, const char *name, int64_t value); int def_var(struct prog_info *pi, char *name, int value); int def_orglist(struct segment_info *si); int fix_orglist(struct segment_info *si); @@ -294,9 +295,9 @@ void fprint_orglist(FILE *file, struct segment_info *si, struct orglist *orglist void fprint_sef_orglist(FILE *file, struct segment_info *si); void fprint_segments(FILE *file, struct prog_info *pi); int test_orglist(struct segment_info *si); -int get_label(struct prog_info *pi,char *name,int *value); -int get_constant(struct prog_info *pi,char *name,int *value); -int get_variable(struct prog_info *pi,char *name,int *value); +int get_label(struct prog_info *pi,char *name,int64_t *value); +int get_constant(struct prog_info *pi,char *name,int64_t *value); +int get_variable(struct prog_info *pi,char *name,int64_t *value); struct label *test_label(struct prog_info *pi,char *name,char *message); struct label *test_constant(struct prog_info *pi,char *name,char *message); struct label *test_variable(struct prog_info *pi,char *name,char *message); @@ -321,15 +322,15 @@ char *get_next_token(char *scratch, int term); char *fgets_new(struct prog_info *pi, char *s, int size, FILE *stream); /* expr.c */ -int get_expr(struct prog_info *pi, char *data, int *value); -int get_symbol(struct prog_info *pi, char *label_name, int *data); +int get_expr(struct prog_info *pi, char *data, int64_t *value); +int get_symbol(struct prog_info *pi, char *label_name, int64_t *data); int par_length(char *data); /* mnemonic.c */ int parse_mnemonic(struct prog_info *pi); int get_mnemonic_type(struct prog_info *pi); int get_register(struct prog_info *pi, char *data); -int get_bitnum(struct prog_info *pi, char *data, int *ret); +int get_bitnum(struct prog_info *pi, char *data, int64_t *ret); int get_indirect(struct prog_info *pi, char *operand); int is_supported(struct prog_info *pi, char *name); int count_supported_instructions(int flags); diff --git a/src/coff.c b/src/coff.c index 657592a..7ed94e0 100644 --- a/src/coff.c +++ b/src/coff.c @@ -706,7 +706,7 @@ int stab_add_lineno(struct prog_info *pi, int LineNumber, char *pLabel, char *pFunction) { - int Address; + int64_t Address; struct lineno *pln; struct syment *pEntry; union auxent *pAux; @@ -754,7 +754,7 @@ int stab_add_lbracket(struct prog_info *pi, int Level, char *pLabel, char *pFunction) { - int Address; + int64_t Address; struct syment *pEntry; union auxent *pAux; @@ -790,7 +790,7 @@ int stab_add_rbracket(struct prog_info *pi, int Level, char *pLabel, char *pFunction) { - int Address; + int64_t Address; struct syment *pEntry; union auxent *pAux; @@ -907,7 +907,8 @@ int stab_add_function(struct prog_info *pi, char *pName, char *pLabel) { - int n, Address; + int n; + int64_t Address; unsigned short CoffType, Type; struct syment *pEntry; char *pType; @@ -991,7 +992,8 @@ int stab_add_global(struct prog_info *pi, char *pName, char *pType) { - int n, Address, IsArray, SymbolIndex; + int n, IsArray, SymbolIndex; + int64_t Address; unsigned short CoffType, Type; struct syment *pEntry; char *p; @@ -1129,7 +1131,8 @@ int stab_add_static_symbol(struct prog_info *pi, char *pName, char *pType, char *pLabel) { - int n, Address; + int n; + int64_t Address; unsigned short CoffType, Type; struct syment *pEntry; diff --git a/src/coff.h b/src/coff.h index 5db2fa4..efc4e56 100644 --- a/src/coff.h +++ b/src/coff.h @@ -123,8 +123,8 @@ struct external_scnhdr { struct lineno { union { - long l_symndx; /* symtbl index of func name */ - long l_paddr; /* paddr of line number */ + int64_t l_symndx; /* symtbl index of func name */ + int64_t l_paddr; /* paddr of line number */ } l_addr; unsigned short l_lnno; /* line number */ }; diff --git a/src/device.c b/src/device.c index 286d64f..98844cb 100644 --- a/src/device.c +++ b/src/device.c @@ -27,6 +27,7 @@ #include +#include #include #include "misc.h" @@ -189,7 +190,7 @@ struct device *get_device(struct prog_info *pi, char *name) int predef_dev(struct prog_info *pi) { - int i; + int64_t i; char temp[MAX_DEV_NAME+1]; def_dev(pi); for (i=0; (!i)||(device_list[i].name); i++) { @@ -206,13 +207,13 @@ predef_dev(struct prog_info *pi) if (def_const(pi, temp, i)==False) return (False); } else { /* Pass 2 */ - int j; + int64_t j; if (get_constant(pi, temp, &j)==False) { /* Defined in Pass 1 and now missing ? */ fprintf(stderr,"Constant %s is missing in pass 2\n",temp); return (False); } if (i != j) { - fprintf(stderr,"Constant %s changed value from %d in pass1 to %d in pass 2\n",temp,j,i); + fprintf(stderr,"Constant %s changed value from %"PRId64" in pass1 to %"PRId64" in pass 2\n",temp,j,i); return (False); } /* OK. definition is unchanged */ diff --git a/src/directiv.c b/src/directiv.c index 5627516..1ee4cd6 100644 --- a/src/directiv.c +++ b/src/directiv.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include "misc.h" @@ -157,7 +158,7 @@ parse_directive(struct prog_info *pi) { int directive, pragma; int ok = True; - int i; + int64_t i; char *next, *data, buf[140]; struct file_info *fi_bak; @@ -329,7 +330,7 @@ parse_directive(struct prog_info *pi) if (pi->list_line && pi->list_on) { fprintf(pi->list_file, " %s\n", pi->list_line); pi->list_line = NULL; - fprintf(pi->list_file, "%c:%06lx %04x\n", + fprintf(pi->list_file, "%c:%06lx %04"PRIx64"\n", pi->segment->ident, pi->segment->addr, i); } if (pi->segment == pi->eseg) { @@ -375,13 +376,13 @@ parse_directive(struct prog_info *pi) if (def_const(pi, next, i)==False) return (False); } else { /* Pass 2 */ - int j; + int64_t j; if (get_constant(pi, next, &j)==False) { /* Defined in Pass 1 and now missing ? */ print_msg(pi, MSGTYPE_ERROR, "Constant %s is missing in pass 2", next); return (False); } if (i != j) { - print_msg(pi, MSGTYPE_ERROR, "Constant %s changed value from %d in pass1 to %d in pass 2", next,j,i); + print_msg(pi, MSGTYPE_ERROR, "Constant %s changed value from %"PRId64" in pass1 to %"PRId64" in pass 2", next,j,i); return (False); } /* OK. Definition is unchanged */ @@ -556,13 +557,13 @@ parse_directive(struct prog_info *pi) if (def_const(pi, next, i)==False) return (False); } else { /* Pass 2 */ - int j; + int64_t j; if (get_constant(pi, next, &j)==False) { /* Defined in Pass 1 and now missing ? */ print_msg(pi, MSGTYPE_ERROR, "Constant %s is missing in pass 2", next); return (False); } if (i != j) { - print_msg(pi, MSGTYPE_ERROR, "Constant %s changed value from %d in pass1 to %d in pass 2", next,j,i); + print_msg(pi, MSGTYPE_ERROR, "Constant %s changed value from %"PRId64" in pass1 to %"PRId64" in pass 2", next,j,i); return (False); } /* OK. Definition is unchanged */ @@ -796,7 +797,7 @@ term_string(struct prog_info *pi, char *string) int parse_db(struct prog_info *pi, char *next) { - int i; + int64_t i; int count; char *data; char prev = 0; @@ -831,8 +832,8 @@ parse_db(struct prog_info *pi, char *next) if (!get_expr(pi, next, &i)) return (False); if ((i < -128) || (i > 255)) - print_msg(pi, MSGTYPE_WARNING, "Value %d is out of range (-128 <= k <= 255). Will be masked", i); - if (pi->list_on) fprintf(pi->list_file, "%02X", i); + print_msg(pi, MSGTYPE_WARNING, "Value %"PRId64" is out of range (-128 <= k <= 255). Will be masked", i); + if (pi->list_on) fprintf(pi->list_file, "%02"PRIX64, i); } count++; write_db(pi, (char)i, &prev, count); @@ -920,7 +921,7 @@ spool_conditional(struct prog_info *pi, int only_endif) int check_conditional(struct prog_info *pi, char *pbuff, int *current_depth, int *do_next, int only_endif) { - int i = 0; + int64_t i = 0; char *next; char linebuff[LINEBUFFER_LENGTH]; diff --git a/src/expr.c b/src/expr.c index 8d8baea..79e57e0 100644 --- a/src/expr.c +++ b/src/expr.c @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -77,7 +78,7 @@ enum { struct element { struct element *next; - int data; + int64_t data; }; char *function_list[] = { @@ -96,16 +97,16 @@ char *function_list[] = { "log2" }; -int -log_2(int value) +int64_t +log_2(int64_t value) { - int i = 0; + int64_t i = 0; while (value >>= 1) i++; return (i); } -int +int64_t get_operator(char *op) { switch (op[0]) { @@ -197,8 +198,8 @@ test_operator_at_precedence(int operator, int precedence) } -int -calc(struct prog_info *pi, int left, int operator, int right) /* TODO: Sjekk litt resultater */ +int64_t +calc(struct prog_info *pi, int64_t left, int64_t operator, int64_t right) /* TODO: Sjekk litt resultater */ { switch (operator) { case OPERATOR_MUL: @@ -250,7 +251,7 @@ calc(struct prog_info *pi, int left, int operator, int right) /* TODO: Sjekk lit } /* If found, return the ID of the internal function */ -int +int64_t get_function(char *function) { int i; @@ -271,8 +272,8 @@ get_function(char *function) return (-1); } -unsigned int -do_function(int function, int value) +uint64_t +do_function(int function, int64_t value) { switch (function) { case FUNCTION_LOW: @@ -302,7 +303,7 @@ do_function(int function, int value) int -get_symbol(struct prog_info *pi, char *label_name, int *data) +get_symbol(struct prog_info *pi, char *label_name, int64_t *data) { struct label *label; struct macro_call *macro_call; @@ -343,7 +344,7 @@ par_length(char *data) } int -get_expr(struct prog_info *pi, char *data, int *value) +get_expr(struct prog_info *pi, char *data, int64_t *value) { /* Definition */ int ok, end, i, count, first_flag, length, function; diff --git a/src/map.c b/src/map.c index c28638d..ce3fdb0 100644 --- a/src/map.c +++ b/src/map.c @@ -27,6 +27,7 @@ #include #include +#include #include "avra.h" #include "args.h" @@ -50,13 +51,13 @@ write_map_file(struct prog_info *pi) return; } for (label = pi->first_constant; label; label = label->next) - fprintf(fp,"%s%sC\t%04x\t%d\n",label->name,Space(label->name),label->value,label->value); + fprintf(fp,"%s%sC\t%04"PRIx64"\t%"PRId64"\n",label->name,Space(label->name),label->value,label->value); for (label = pi->first_variable; label; label = label->next) - fprintf(fp,"%s%sV\t%04x\t%d\n",label->name,Space(label->name),label->value,label->value); + fprintf(fp,"%s%sV\t%04"PRIx64"\t%"PRId64"\n",label->name,Space(label->name),label->value,label->value); for (label = pi->first_label; label; label = label->next) - fprintf(fp,"%s%sL\t%04x\t%d\n",label->name,Space(label->name),label->value,label->value); + fprintf(fp,"%s%sL\t%04"PRIx64"\t%"PRId64"\n",label->name,Space(label->name),label->value,label->value); fprintf(fp,"\n"); fclose(fp); diff --git a/src/mnemonic.c b/src/mnemonic.c index a51871a..8ad46a8 100644 --- a/src/mnemonic.c +++ b/src/mnemonic.c @@ -346,7 +346,7 @@ int parse_mnemonic(struct prog_info *pi) { int mnemonic; - int i; + int64_t i; int opcode = 0; int opcode2 = 0; int instruction_long = False; @@ -734,7 +734,7 @@ get_register(struct prog_info *pi, char *data) } int -get_bitnum(struct prog_info *pi, char *data, int *ret) +get_bitnum(struct prog_info *pi, char *data, int64_t *ret) { if (!get_expr(pi, data, ret)) return (False); diff --git a/tests/regression/issue53-int64-expression/test.asm b/tests/regression/issue53-int64-expression/test.asm new file mode 100644 index 0000000..4d4a155 --- /dev/null +++ b/tests/regression/issue53-int64-expression/test.asm @@ -0,0 +1,32 @@ +.device atmega168 + +.equ F_CPU = 16000000 + +.macro delay1 + .set cycles = @0 * (F_CPU / 1000000) + .dw cycles + .if cycles != 16000 + .error "error in calculation" + .endif +.endmacro + +.macro delay2 + .set cycles = (@0 * F_CPU) / 1000000 + .dw cycles + .if cycles != 16000 + .error "error in calculation" + .endif +.endmacro + +.macro delay3 + .set cycles = ( ( @0 * F_CPU ) / 1000000 ) + .dw cycles + .if cycles != 16000 + .error "error in calculation" + .endif +.endmacro + +nop +delay1 1000 +delay2 1000 +delay3 1000 diff --git a/tests/regression/issue53-int64-expression/test.hex.expected b/tests/regression/issue53-int64-expression/test.hex.expected new file mode 100644 index 0000000..9c6d6b4 --- /dev/null +++ b/tests/regression/issue53-int64-expression/test.hex.expected @@ -0,0 +1,3 @@ +:020000020000FC +:080000000000803E803E803EBE +:00000001FF