Proper 64-bit support
authorRobert Pengelly <robertapengelly@hotmail.com>
Thu, 4 Sep 2025 02:46:50 +0000 (03:46 +0100)
committerRobert Pengelly <robertapengelly@hotmail.com>
Thu, 4 Sep 2025 02:46:50 +0000 (03:46 +0100)
20 files changed:
Makefile.w32
Makefile.wat
bin.c [deleted file]
expr.c
expr.h
fixup.c
fixup.h
frag.c
frag.h
intel.c
inttypes.h [new file with mode: 0644]
kwd.c
lib.c
lib.h
listing.c
macro.c
process.c
stdint.h [new file with mode: 0644]
symbol.c
symbol.h

index 999c74cb4185335e09ec271ebe450499884bb6f6..2d9f392a144f0959af6dde8b5dfad1d56c589f03 100644 (file)
@@ -5,7 +5,7 @@ SRCDIR              ?=  $(CURDIR)
 VPATH               :=  $(SRCDIR)
 
 CC                  :=  gcc
-CFLAGS              :=  -D_FILE_OFFSET_BITS=64 -O2 -Wall -Werror -Wextra -ansi -pedantic -std=c90
+CFLAGS              :=  -D_FILE_OFFSET_BITS=64 -O2 -Wall -Werror -Wextra -DNO_LONG_LONG
 
 CSRC                :=  as.c coff.c cstr.c elks.c expr.c fixup.c frag.c hashtab.c intel.c kwd.c lex.c lib.c list.c listing.c ll.c macro.c process.c report.c section.c symbol.c vector.c
 
index acbb2ed5113a80df65d89637339f1655c4d11aa2..6912f740d0acf4cf995a366e407a3a5fd730e665 100644 (file)
@@ -10,7 +10,7 @@ all: sasm.exe
 
 sasm.exe: $(SRC)
 
-       wcl -fe=$@ $^
+       wcl -DNO_LONG_LONG -fe=$@ $^
 
 clean:
 
diff --git a/bin.c b/bin.c
deleted file mode 100644 (file)
index eecb406..0000000
--- a/bin.c
+++ /dev/null
@@ -1,81 +0,0 @@
-/******************************************************************************
- * @file            bin.c
- *****************************************************************************/
-#include    "limits.h"
-#include    "stdio.h"
-#include    "stdlib.h"
-#include    "string.h"
-
-#include    "as.h"
-#include    "fixup.h"
-#include    "frag.h"
-#include    "lib.h"
-#include    "report.h"
-#include    "section.h"
-#include    "symbol.h"
-
-static unsigned long text_size = 0, data_size = 0, bss_size = 0;
-static void *output = 0;
-
-void output_binary (FILE *fp) {
-
-    unsigned long i = 0;
-    struct frag *frag;
-    
-    section_set (text_section);
-    text_size = section_write_frag_chain (fp);
-    
-    section_set (data_section);
-    data_size = section_write_frag_chain (fp);
-    
-    section_set (bss_section);
-    
-    for (frag = current_frag_chain->first_frag; frag; frag = frag->next) {
-    
-        if (frag->fixed_size == 0) {
-            continue;
-        }
-        
-        bss_size += frag->fixed_size;
-    
-    }
-    
-    output = xmalloc (text_size + data_size);
-    section_set (text_section);
-    
-    for (frag = current_frag_chain->first_frag; frag; frag = frag->next) {
-    
-        if (frag->fixed_size == 0) {
-            continue;
-        }
-        
-        memcpy ((unsigned char *) output + i, frag->buf, frag->fixed_size);
-        i += frag->fixed_size;
-    
-    }
-    
-    section_set (data_section);
-    
-    for (frag = current_frag_chain->first_frag; frag; frag = frag->next) {
-    
-        if (frag->fixed_size == 0) {
-            continue;
-        }
-        
-        memcpy ((unsigned char *) output + i, frag->buf, frag->fixed_size);
-        i += frag->fixed_size;
-    
-    }
-    
-    if (get_error_count () > 0) {
-        exit (EXIT_FAILURE);
-    }
-    
-    if (fwrite (output, text_size + data_size, 1, fp) != 1) {
-    
-        report_at (program_name, 0, REPORT_ERROR, "failed to write data to '%s'", state->ofile);
-        exit (EXIT_FAILURE);
-    
-    }
-
-}
diff --git a/expr.c b/expr.c
index 79f7be9d3162c048297d3677c86a30c0eec07946..bcd11904f9cb361e7fa1b86897b96743d2e6bc88 100644 (file)
--- a/expr.c
+++ b/expr.c
@@ -30,7 +30,7 @@ struct expr_symbol_line {
 
 static struct expr_symbol_line *expr_symbol_lines = 0;
 
-static char *read_character (const char *start, char *p, unsigned long *ch) {
+static char *read_character (const char *start, char *p, uint64_t *ch) {
 
     if (*p == '\\') {
     
@@ -131,7 +131,7 @@ static int chrpos (char *s, int ch) {
 
 static void integer_constant (char *start, char **pp, struct expr *expr, int radix) {
 
-    long value = 0;
+    uint64_t value = 0;
     int k;
     
     while (!is_end_of_line[(int) **pp] && (k = chrpos ("0123456789abcdef", tolower ((int) **pp))) >= 0) {
@@ -757,7 +757,7 @@ struct section *read_into (char *start, char **pp, struct expr *expr, unsigned i
         enum expr_type right_op;
         
         struct section *right_section;
-        signed long offset;
+        int64_t offset;
         
         *pp += operator_size;
         right_section = read_into (start, pp, &right_expr, op_rank_table[left_op], expr_mode);
@@ -834,7 +834,7 @@ struct section *read_into (char *start, char **pp, struct expr *expr, unsigned i
                 case EXPR_TYPE_EQUAL:
                 case EXPR_TYPE_NOT_EQUAL:
                 
-                    expr->add_number = (expr->add_number == right_expr.add_number) ? ~(signed long) 0 : 0;
+                    expr->add_number = (expr->add_number == right_expr.add_number) ? ~(int64_t) 0 : 0;
                     
                     if (left_op == EXPR_TYPE_NOT_EQUAL) {
                         expr->add_number = ~expr->add_number;
@@ -844,22 +844,22 @@ struct section *read_into (char *start, char **pp, struct expr *expr, unsigned i
                 
                 case EXPR_TYPE_LESSER:
                 
-                    expr->add_number = (signed long) expr->add_number < (signed long) right_expr.add_number ? ~(signed long) 0 : 0;
+                    expr->add_number = (int64_t) expr->add_number < (int64_t) right_expr.add_number ? ~(int64_t) 0 : 0;
                     break;
                 
                 case EXPR_TYPE_LESSER_EQUAL:
                 
-                    expr->add_number = (signed long) expr->add_number <= (signed long) right_expr.add_number ? ~(signed long) 0 : 0;
+                    expr->add_number = (int64_t) expr->add_number <= (int64_t) right_expr.add_number ? ~(int64_t) 0 : 0;
                     break;
                 
                 case EXPR_TYPE_GREATER:
                 
-                    expr->add_number = (signed long) expr->add_number > (signed long) right_expr.add_number ? ~(signed long) 0 : 0;
+                    expr->add_number = (int64_t) expr->add_number > (int64_t) right_expr.add_number ? ~(int64_t) 0 : 0;
                     break;
                 
                 case EXPR_TYPE_GREATER_EQUAL:
                 
-                    expr->add_number = (signed long) expr->add_number >= (signed long) right_expr.add_number ? ~(signed long) 0 : 0;
+                    expr->add_number = (int64_t) expr->add_number >= (int64_t) right_expr.add_number ? ~(int64_t) 0 : 0;
                     break;
                 
                 case EXPR_TYPE_ADD:
@@ -904,12 +904,12 @@ struct section *read_into (char *start, char **pp, struct expr *expr, unsigned i
                 
                 case EXPR_TYPE_LEFT_SHIFT:
                 
-                    expr->add_number = (signed long) (expr->add_number) << (signed long) (right_expr.add_number);
+                    expr->add_number = (uint64_t) (expr->add_number) << (int64_t) (right_expr.add_number);
                     break;
                 
                 case EXPR_TYPE_RIGHT_SHIFT:
                 
-                    expr->add_number = (unsigned long) (expr->add_number) >> (unsigned long) (right_expr.add_number);
+                    expr->add_number = (uint64_t) (expr->add_number) >> (uint64_t) (right_expr.add_number);
                     break;
                 
                 default:
@@ -1010,7 +1010,7 @@ struct symbol *make_expr_symbol (struct expr *expr) {
 
 }
 
-signed long absolute_expression_read_into (char *start, char **pp, struct expr *expr) {
+int64_t absolute_expression_read_into (char *start, char **pp, struct expr *expr) {
 
     expression_evaluate_and_read_into (start, pp, expr);
     
@@ -1049,7 +1049,7 @@ int expr_symbol_get_filename_and_line_number (struct symbol *symbol, const char
 
 }
 
-signed long get_result_of_absolute_expression (char *start, char **pp) {
+int64_t get_result_of_absolute_expression (char *start, char **pp) {
 
     struct expr expr;
     return absolute_expression_read_into (start, pp, &expr);
@@ -1064,11 +1064,11 @@ int resolve_expression (struct expr *expr) {
     struct symbol *add_symbol = expr->add_symbol;
     struct symbol *original_add_symbol = add_symbol;
     
-    unsigned long final_value = expr->add_number;
-    unsigned long left_value, right_value;
+    uint64_t final_value = expr->add_number;
+    uint64_t left_value, right_value;
     
     struct section *left_section, *right_section;
-    signed long frag_offset;
+    int64_t frag_offset;
     
     switch (expr->type) {
     
@@ -1290,7 +1290,7 @@ int resolve_expression (struct expr *expr) {
                 case EXPR_TYPE_EQUAL:
                 case EXPR_TYPE_NOT_EQUAL:
                 
-                    left_value = ((left_value == right_value && left_section == right_section && (finalize_symbols || left_frag == right_frag) && (left_section != undefined_section || add_symbol == op_symbol)) ? ~(unsigned long) 0 : 0);
+                    left_value = ((left_value == right_value && left_section == right_section && (finalize_symbols || left_frag == right_frag) && (left_section != undefined_section || add_symbol == op_symbol)) ? ~(uint64_t) 0 : 0);
                     
                     if (expr->type == EXPR_TYPE_NOT_EQUAL) {
                         left_value = ~left_value;
@@ -1300,22 +1300,22 @@ int resolve_expression (struct expr *expr) {
                 
                 case EXPR_TYPE_LESSER:
                 
-                    left_value = (signed long) left_value < (signed long) right_value ? ~(unsigned long) 0 : 0;
+                    left_value = (int64_t) left_value < (int64_t) right_value ? ~(uint64_t) 0 : 0;
                     break;
                 
                 case EXPR_TYPE_LESSER_EQUAL:
                 
-                    left_value = (signed long) left_value <= (signed long) right_value ? ~(unsigned long) 0 : 0;
+                    left_value = (int64_t) left_value <= (int64_t) right_value ? ~(uint64_t) 0 : 0;
                     break;
                 
                 case EXPR_TYPE_GREATER:
                 
-                    left_value = (signed long) left_value > (signed long) right_value ? ~(unsigned long) 0 : 0;
+                    left_value = (int64_t) left_value > (int64_t) right_value ? ~(uint64_t) 0 : 0;
                     break;
                 
                 case EXPR_TYPE_GREATER_EQUAL:
                 
-                    left_value = (signed long) left_value >= (signed long) right_value ? ~(unsigned long) 0 : 0;
+                    left_value = (int64_t) left_value >= (int64_t) right_value ? ~(uint64_t) 0 : 0;
                     break;
                 
                 case EXPR_TYPE_ADD:
@@ -1368,12 +1368,12 @@ int resolve_expression (struct expr *expr) {
                 
                 case EXPR_TYPE_LEFT_SHIFT:
                 
-                    left_value = (unsigned long) left_value << (unsigned long) right_value;
+                    left_value = (uint64_t) left_value << (uint64_t) right_value;
                     break;
                 
                 case EXPR_TYPE_RIGHT_SHIFT:
                 
-                    left_value = (unsigned long) left_value >> (unsigned long) right_value;
+                    left_value = (uint64_t) left_value >> (uint64_t) right_value;
                     break;
                 
                 default:
diff --git a/expr.h b/expr.h
index eb99d62969894977633834e4d218a143c100eb3c..509d5716846f6a4c3063917423537fdd6f1ba971 100644 (file)
--- a/expr.h
+++ b/expr.h
@@ -4,6 +4,8 @@
 #ifndef     _EXPR_H
 #define     _EXPR_H
 
+#include    "stdint.h"
+
 enum expr_type {
 
     EXPR_TYPE_INVALID,
@@ -65,7 +67,7 @@ struct expr {
     struct symbol *add_symbol;
     struct symbol *op_symbol;
     
-    unsigned long add_number;
+    uint64_t add_number;
 
 };
 
@@ -78,8 +80,8 @@ struct section *read_into (char *start, char **pp, struct expr *expr, unsigned i
 struct symbol *make_expr_symbol (struct expr *expr);
 void expr_type_set_rank (enum expr_type expr_type, unsigned int rank);
 
-signed long absolute_expression_read_into (char *start, char **pp, struct expr *expr);
-signed long get_result_of_absolute_expression (char *start, char **pp);
+int64_t absolute_expression_read_into (char *start, char **pp, struct expr *expr);
+int64_t get_result_of_absolute_expression (char *start, char **pp);
 
 int expr_symbol_get_filename_and_line_number (struct symbol *symbol, const char **filename_p, unsigned long *line_number_p);
 int resolve_expression (struct expr *expr);
diff --git a/fixup.c b/fixup.c
index 7451b61e27ca398a232e1ae7897223ccd6a46617..303bd4ad5248111fb93fb86f03c53cc2540a5dcf 100644 (file)
--- a/fixup.c
+++ b/fixup.c
@@ -12,7 +12,7 @@
 #include    "section.h"
 #include    "symbol.h"
 
-static struct fixup *fixup_new_internal (struct frag *frag, unsigned long where, int size, struct symbol *add_symbol, struct symbol *sub_symbol, long add_number, int pcrel, int reloc_type) {
+static struct fixup *fixup_new_internal (struct frag *frag, unsigned long where, int size, struct symbol *add_symbol, struct symbol *sub_symbol, int64_t add_number, int pcrel, int reloc_type) {
 
     struct fixup *fixup = xmalloc (sizeof (*fixup));
     
@@ -38,14 +38,14 @@ static struct fixup *fixup_new_internal (struct frag *frag, unsigned long where,
 
 }
 
-struct fixup *fixup_new (struct frag *frag, unsigned long where, int size, struct symbol *add_symbol, long add_number, int pcrel, int reloc_type) {
+struct fixup *fixup_new (struct frag *frag, unsigned long where, int size, struct symbol *add_symbol, int64_t add_number, int pcrel, int reloc_type) {
     return fixup_new_internal (frag, where, size, add_symbol, 0, add_number, pcrel, reloc_type);
 }
 
 struct fixup *fixup_new_expr (struct frag *frag, unsigned long where, int size, struct expr *expr, int pcrel, int reloc_type) {
 
     struct symbol *add_symbol = 0, *sub_symbol = 0;
-    signed long add_number = 0;
+    int64_t add_number = 0;
     
     switch (expr->type) {
     
@@ -82,8 +82,8 @@ struct fixup *fixup_new_expr (struct frag *frag, unsigned long where, int size,
 }
 
 
-signed long machine_dependent_estimate_size_before_relax (struct frag *frag, struct section *section);
-signed long machine_dependent_relax_frag (struct frag *frag, struct section *section, signed long change);
+int64_t machine_dependent_estimate_size_before_relax (struct frag *frag, struct section *section);
+int64_t machine_dependent_relax_frag (struct frag *frag, struct section *section, int64_t change);
 
 void machine_dependent_finish_frag (struct frag *frag);
 
@@ -337,7 +337,7 @@ static void finish_frags_after_relaxation (struct section *section) {
             case RELAX_TYPE_ALIGN_CODE:
             case RELAX_TYPE_SPACE: {
             
-                signed long i;
+                int64_t i;
                 
                 unsigned char *p;
                 unsigned char fill;
@@ -429,15 +429,16 @@ static void adjust_reloc_symbols_of_section (struct section *section) {
 
 }
 
-signed long machine_dependent_pcrel_from (struct fixup *fixup);
+#include    "inttypes.h"
+int64_t machine_dependent_pcrel_from (struct fixup *fixup);
 
 int machine_dependent_force_relocation_local (struct fixup *fixup);
-void machine_dependent_apply_fixup (struct fixup *fixup, unsigned long value);
+void machine_dependent_apply_fixup (struct fixup *fixup, uint64_t value);
 
 static unsigned long fixup_section (struct section *section) {
 
     unsigned long section_reloc_count = 0;
-    unsigned long add_number;
+    uint64_t add_number;
     
     struct section *add_symbol_section = absolute_section;
     struct fixup *fixup;
@@ -531,15 +532,15 @@ static unsigned long fixup_section (struct section *section) {
             section_reloc_count++;
         }
         
-        if (fixup->size < sizeof (unsigned long)) {
+        if (fixup->size < sizeof (uint64_t)) {
         
-            unsigned long mask = -1;
+            uint64_t mask = -1;
             mask <<= fixup->size * 8 - !!fixup->fixup_signed;
             
             if ((add_number & mask) && (fixup->fixup_signed ? ((add_number & mask) != mask) : (-add_number & mask))) {
             
-                report_at (0, 0, REPORT_ERROR, (add_number > 1000)
-                    ? "value of %lu too large for field of %u byte%s at %#lx" : "value of %lu too large for field of %u byte%s at %#lx",
+                report_at (0, 0, REPORT_ERROR, (add_number > 1000) ?
+                    "value of %#"PRIx64"too large for field of %u byte%s at %#lx" : "value of %"PRIu64" too large for field of %u byte%s at %#lx",
                         add_number, fixup->size, ((fixup->size == 1) ? "" : "s"), fixup->frag->address + fixup->where);
             
             }
diff --git a/fixup.h b/fixup.h
index 0cf2572016946906b7188123d3b0f96c57481802..1c6bda26123a63a41af1144f5d543df8181f5b1c 100644 (file)
--- a/fixup.h
+++ b/fixup.h
@@ -19,14 +19,14 @@ struct fixup {
     unsigned int size;
     
     struct symbol *add_symbol, *sub_symbol;
-    long add_number;
+    int64_t add_number;
     
     int pcrel, reloc_type;
     struct fixup *next;
 
 };
 
-struct fixup *fixup_new (struct frag *frag, unsigned long where, int size, struct symbol *add_symbol, long add_number, int pcrel, int reloc_type);
+struct fixup *fixup_new (struct frag *frag, unsigned long where, int size, struct symbol *add_symbol, int64_t add_number, int pcrel, int reloc_type);
 struct fixup *fixup_new_expr (struct frag *frag, unsigned long where, int size, struct expr *expr, int pcrel, int reloc_type);
 
 #endif  /* _FIXUP_H */
diff --git a/frag.c b/frag.c
index a0e7581cc7922bb6e4c42d56f459fea013904e57..3493f6871d0fff78f7ba3706a85d3b812d268835 100644 (file)
--- a/frag.c
+++ b/frag.c
@@ -12,9 +12,9 @@ struct frag *frag_alloc (void) {
     return xmalloc (sizeof (struct frag));
 }
 
-int frags_is_greater_than_offset (unsigned long offset2, struct frag *frag2, unsigned long offset1, struct frag *frag1, signed long *offset_p) {
+int frags_is_greater_than_offset (uint64_t offset2, struct frag *frag2, uint64_t offset1, struct frag *frag1, int64_t *offset_p) {
 
-    signed long difference;
+    int64_t difference;
     struct frag *frag;
     
     /* Checks for something that should be impossible. */
@@ -50,9 +50,9 @@ int frags_is_greater_than_offset (unsigned long offset2, struct frag *frag2, uns
 
 }
 
-int frags_offset_is_fixed (struct frag *frag1, struct frag *frag2, signed long *offset_p) {
+int frags_offset_is_fixed (struct frag *frag1, struct frag *frag2, int64_t *offset_p) {
 
-    signed long offset = frag1->address - frag2->address;
+    int64_t offset = frag1->address - frag2->address;
     struct frag *frag;
     
     if (frag1 == frag2) {
@@ -122,7 +122,7 @@ unsigned char *finished_frag_increase_fixed_size_by_frag_offset (struct frag *fr
 
 }
 
-unsigned char *frag_alloc_space (unsigned long space) {
+unsigned char *frag_alloc_space (uint64_t space) {
 
     if (current_frag->fixed_size + space >= current_frag->size) {
     
@@ -135,7 +135,7 @@ unsigned char *frag_alloc_space (unsigned long space) {
 
 }
 
-unsigned char *frag_increase_fixed_size (unsigned long increase) {
+unsigned char *frag_increase_fixed_size (uint64_t increase) {
 
     frag_alloc_space (increase);
     
@@ -144,14 +144,14 @@ unsigned char *frag_increase_fixed_size (unsigned long increase) {
 
 }
 
-void frag_align (signed long alignment, int fill_char, signed long max_bytes_to_skip) {
+void frag_align (int64_t alignment, int fill_char, int64_t max_bytes_to_skip) {
 
     (frag_alloc_space (1 << alignment))[0] = fill_char;
     frag_set_as_variant (RELAX_TYPE_ALIGN, max_bytes_to_skip, 0, alignment, 0);
 
 }
 
-void frag_align_code (signed long alignment, signed long max_bytes_to_skip) {
+void frag_align_code (int64_t alignment, int64_t max_bytes_to_skip) {
 
     (frag_alloc_space (1 << alignment))[0] = 0x90;
     frag_set_as_variant (RELAX_TYPE_ALIGN_CODE, max_bytes_to_skip, 0, alignment, 0);
@@ -183,7 +183,7 @@ void frag_new (void) {
 
 }
 
-void frag_set_as_variant (int relax_type, int relax_subtype, struct symbol *symbol, signed long offset, unsigned long opcode_offset_in_buf) {
+void frag_set_as_variant (int relax_type, int relax_subtype, struct symbol *symbol, int64_t offset, uint64_t opcode_offset_in_buf) {
 
     current_frag->relax_type           = relax_type;
     current_frag->relax_subtype        = relax_subtype;
diff --git a/frag.h b/frag.h
index 737b8a21d3fa54c5151a4b25cfdaad248f4dfa10..9df428d58f611583fd0e3532cc8192a655543f29 100644 (file)
--- a/frag.h
+++ b/frag.h
@@ -4,6 +4,8 @@
 #ifndef     _FRAG_H
 #define     _FRAG_H
 
+#include    "stdint.h"
+
 #define     RELAX_TYPE_NONE_NEEDED                          0
 #define     RELAX_TYPE_ALIGN                                1
 #define     RELAX_TYPE_ALIGN_CODE                           2
 
 struct frag {
 
-    unsigned long fixed_size, address, size;
+    uint64_t fixed_size, address, size;
     unsigned int relax_type, relax_subtype;
     
     struct symbol *symbol;
     unsigned char *buf;
     
-    signed long offset;
-    unsigned long opcode_offset_in_buf;
+    int64_t offset;
+    uint64_t opcode_offset_in_buf;
     
     const char *filename;
     unsigned long line_number;
@@ -37,18 +39,18 @@ extern struct frag *current_frag;
 
 struct frag *frag_alloc (void);
 
-int frags_is_greater_than_offset (unsigned long offset2, struct frag *frag2, unsigned long offset1, struct frag *frag1, signed long *offset_p);
-int frags_offset_is_fixed (struct frag *frag1, struct frag *frag2, signed long *offset_p);
+int frags_is_greater_than_offset (uint64_t offset2, struct frag *frag2, uint64_t offset1, struct frag *frag1, int64_t *offset_p);
+int frags_offset_is_fixed (struct frag *frag1, struct frag *frag2, int64_t *offset_p);
 
 unsigned char *finished_frag_increase_fixed_size_by_frag_offset (struct frag *frag);
-unsigned char *frag_alloc_space (unsigned long space);
-unsigned char *frag_increase_fixed_size (unsigned long increase);
+unsigned char *frag_alloc_space (uint64_t space);
+unsigned char *frag_increase_fixed_size (uint64_t increase);
 
-void frag_align (signed long alignment, int fill_char, signed long max_bytes_to_skip);
-void frag_align_code (signed long alignment, signed long max_bytes_to_skip);
+void frag_align (int64_t alignment, int fill_char, int64_t max_bytes_to_skip);
+void frag_align_code (int64_t alignment, int64_t max_bytes_to_skip);
 
 void frag_append_1_char (unsigned char ch);
 void frag_new (void);
-void frag_set_as_variant (int relax_type, int relax_subtype, struct symbol *symbol, signed long offset, unsigned long opcode_offset_in_buf);
+void frag_set_as_variant (int relax_type, int relax_subtype, struct symbol *symbol, int64_t offset, uint64_t opcode_offset_in_buf);
 
 #endif      /* _FRAG_H */
diff --git a/intel.c b/intel.c
index f026b68064626a0369de67c76da1864ff21ff424..1b1deae7a2f606ae67b8931c827b9b0878bc9b9f 100644 (file)
--- a/intel.c
+++ b/intel.c
@@ -1583,7 +1583,7 @@ static struct {
     struct reg_entry *base_reg;
     struct reg_entry *index_reg;
     
-    signed long scale_factor;
+    int scale_factor;
     struct symbol *segment;
 
 } intel_state;
@@ -3585,7 +3585,7 @@ static void intel_fold_symbol_into_expr (struct expr *expr, struct symbol *symbo
     
     if (symbol_get_section (symbol) == absolute_section) {
     
-        signed int add_number = expr->add_number;
+        int64_t add_number = expr->add_number;
         
         *expr = *symbol_expr;
         expr->add_number += add_number;
@@ -4012,37 +4012,36 @@ static void swap_operands (void) {
 
 }
 
-static int fits_in_signed_byte (signed long number) {
+static int fits_in_signed_byte (int64_t number) {
     return ((number >= -128) && (number <= 127));
 }
 
-static int fits_in_unsigned_byte (unsigned long number) {
+static int fits_in_unsigned_byte (uint64_t number) {
     return ((number & 0xff) == number);
 }
 
-static int fits_in_signed_word (signed long number) {
+static int fits_in_signed_word (int64_t number) {
     return ((number >= -32768) && (number <= 32767));
 }
 
-static int fits_in_unsigned_word (unsigned long number) {
+static int fits_in_unsigned_word (uint64_t number) {
     return ((number & 0xffff) == number);
 }
 
-static int fits_in_signed_long (signed long number) {
-
-#if     defined (__WATCOMC__)
-    return 1;
+#if     defined (NO_LONG_LONG)
+# define    fits_in_signed_long(x)                          1
+# define    fits_in_unsigned_long(x)                        1     
 #else
+static int fits_in_signed_long (int64_t number) {
     return ((number >= -2147483647-1) && (number <= 2147483647));
-#endif
-
 }
 
-static int fits_in_unsigned_long (unsigned long number) {
+static int fits_in_unsigned_long (uint64_t number) {
     return ((number & 0xffffffff) == number);
 }
+#endif
 
-static struct operand_type smallest_imm_type (long number) {
+static struct operand_type smallest_imm_type (int64_t number) {
     
     struct operand_type type = { 0 };
     type.imm64 = 1;
@@ -4091,7 +4090,7 @@ static void optimize_size_of_disps (void) {
         
             if (instruction.disps[operand]->type == EXPR_TYPE_CONSTANT) {
             
-                signed long disp = instruction.disps[operand]->add_number;
+                int64_t disp = instruction.disps[operand]->add_number;
                 
                 if (disp == 0 && instruction.types[operand].base_index) {
                 
@@ -4105,7 +4104,7 @@ static void optimize_size_of_disps (void) {
                 
                 if (instruction.types[operand].disp32 && fits_in_unsigned_long (disp)) {
                 
-                    disp = (disp ^ ((signed long) 1 << 31)) - ((signed long) 1 << 31);
+                    disp = (disp ^ ((int64_t) 1 << 31)) - ((int64_t) 1 << 31);
                     
                     instruction.types[operand].disp64 = 0;
                     instruction.types[operand].disp32 = 1;
@@ -5438,8 +5437,8 @@ static void output_jump (void) {
     struct symbol *symbol;
     unsigned int relax_subtype;
     
-    unsigned long offset;
-    unsigned long opcode_offset_in_buf;
+    int64_t offset;
+    uint64_t opcode_offset_in_buf;
     
     unsigned int code16 = 0;
     
@@ -5506,7 +5505,7 @@ static void output_jump (void) {
 
 }
 
-void machine_dependent_number_to_chars (unsigned char *p, unsigned int number, unsigned int size);
+void machine_dependent_number_to_chars (unsigned char *p, uint64_t number, unsigned int size);
 
 static void output_call_or_jumpbyte (void) {
 
@@ -5690,7 +5689,7 @@ static void output_intersegment_jump (void) {
 
 }
 
-static long convert_number_to_size (unsigned long value, int size) {
+static uint64_t convert_number_to_size (uint64_t value, int size) {
 
     unsigned long mask;
     
@@ -5779,7 +5778,7 @@ static void output_disps (void) {
             
             if (instruction.disps[operand]->type == EXPR_TYPE_CONSTANT) {
             
-                unsigned long value = convert_number_to_size (instruction.disps[operand]->add_number, size);
+                uint64_t value = convert_number_to_size (instruction.disps[operand]->add_number, size);
                 machine_dependent_number_to_chars (frag_increase_fixed_size (size), value, size);
             
             } else {
@@ -5830,7 +5829,7 @@ static void output_imms (void) {
             
             if (instruction.imms[operand]->type == EXPR_TYPE_CONSTANT) {
             
-                unsigned long value = convert_number_to_size (instruction.imms[operand]->add_number, size);
+                uint64_t value = convert_number_to_size (instruction.imms[operand]->add_number, size);
                 machine_dependent_number_to_chars (frag_increase_fixed_size (size), value, size);
             
             } else {
@@ -6005,7 +6004,7 @@ int machine_dependent_parse_name (char **pp, struct expr *expr, char *name, char
 
 }
 
-signed long machine_dependent_estimate_size_before_relax (struct frag *frag, struct section *section) {
+int64_t machine_dependent_estimate_size_before_relax (struct frag *frag, struct section *section) {
 
     if (symbol_get_section (frag->symbol) != section) {
     
@@ -6013,7 +6012,7 @@ signed long machine_dependent_estimate_size_before_relax (struct frag *frag, str
         int size = (frag->relax_subtype & RELAX_SUBTYPE_CODE16_JUMP) ? 2 : 4;
         
         unsigned char *opcode_pos = frag->buf + frag->opcode_offset_in_buf;
-        unsigned long old_frag_fixed_size = frag->fixed_size;
+        uint64_t old_frag_fixed_size = frag->fixed_size;
         
         switch (TYPE_FROM_RELAX_SUBTYPE (frag->relax_subtype)) {
         
@@ -6090,17 +6089,16 @@ signed long machine_dependent_estimate_size_before_relax (struct frag *frag, str
 
 }
 
-signed long machine_dependent_pcrel_from (struct fixup *fixup) {
+int64_t machine_dependent_pcrel_from (struct fixup *fixup) {
     return (fixup->size + fixup->where + fixup->frag->address);
 }
 
-signed long machine_dependent_relax_frag (struct frag *frag, struct section *section, signed long change) {
+int64_t machine_dependent_relax_frag (struct frag *frag, struct section *section, int64_t change) {
 
-    unsigned long target;
+    int64_t aim, growth;
+    uint64_t target;
     
     unsigned int new_subtype;
-    signed long aim, growth;
-    
     target = frag->offset;
     
     if (frag->symbol) {
@@ -6147,7 +6145,7 @@ signed long machine_dependent_relax_frag (struct frag *frag, struct section *sec
 
 }
 
-void machine_dependent_apply_fixup (struct fixup *fixup, unsigned long value) {
+void machine_dependent_apply_fixup (struct fixup *fixup, uint64_t value) {
 
     unsigned char *p = fixup->where + fixup->frag->buf;
     
@@ -6489,7 +6487,7 @@ void machine_dependent_assemble_line (char *start, char *line) {
 
 }
 
-void machine_dependent_number_to_chars (unsigned char *p, unsigned int number, unsigned int size) {
+void machine_dependent_number_to_chars (unsigned char *p, uint64_t number, unsigned int size) {
 
     unsigned int i;
     
diff --git a/inttypes.h b/inttypes.h
new file mode 100644 (file)
index 0000000..b6faa21
--- /dev/null
@@ -0,0 +1,25 @@
+/******************************************************************************
+ * @file            inttypes.h
+ *****************************************************************************/
+#include    <limits.h>
+#include    <stdint.h>
+
+#if     defined (NO_LONG_LONG)
+# define    I64_FMT                     "l"
+#elif   defined (_MSVC_) || defined (__WIN32__)
+# define    I64_FMT                     "I64"
+#elif   defined (__PRI_64_LENGTH_MODIFIER__)                                                        /* Mac */
+# define    I64_FMT                     __PRI_64_LENGTH_MODIFIER__
+#elif   defined (SIZEOF_LONG) && SIZEOF_LONG >= 8 || ULONG_MAX > 4294967295UL
+# define    I64_FMT                     "l"
+#else
+# define    I64_FMT                     "ll"
+#endif
+
+#define     PRId64                      I64_FMT"d"
+#define     PRIi64                      I64_FMT"i"
+#define     PRIo64                      I64_FMT"o"
+#define     PRIu64                      I64_FMT"u"
+#define     PRIx64                      I64_FMT"x"
+#define     PRIX64                      I64_FMT"X"
+
diff --git a/kwd.c b/kwd.c
index 60c014b1f17d10f485a277b85c735614a4f08d69..9106e3943ea4610fe745c24f035e714b05005551 100644 (file)
--- a/kwd.c
+++ b/kwd.c
@@ -123,11 +123,11 @@ static int read_character (const char *start, char **pp, unsigned long *val) {
 
 static void align_bytes (char *start, char **pp, int first_arg_is_bytes) {
 
-    signed long alignment;
+    int64_t alignment;
     int fill_specified;
     
-    signed long fill_value = 0, max_bytes_to_skip;
-    signed long i;
+    int64_t fill_value = 0, max_bytes_to_skip;
+    int64_t i;
     
     alignment = get_result_of_absolute_expression (start, pp);
 
@@ -191,7 +191,7 @@ static void align_bytes (char *start, char **pp, int first_arg_is_bytes) {
 
 }
 
-void machine_dependent_number_to_chars (unsigned char *p, unsigned int number, unsigned int size);
+void machine_dependent_number_to_chars (unsigned char *p, uint64_t number, unsigned int size);
 
 static void handle_constant (char *start, char **pp, int size) {
 
diff --git a/lib.c b/lib.c
index 99c2b8383505a7112b14e82f319cc14ba4ff8c78..ba12335cae4df0f62610d8a603fc313f1c2b7622 100644 (file)
--- a/lib.c
+++ b/lib.c
@@ -568,10 +568,6 @@ void set_filename_and_line_number (const char *__filename, unsigned long __line_
 
 }
 
-void set_filename (const char *__filename) {
-    filename = __filename;
-}
-
 void set_line_number (unsigned long __line_number) {
     line_number = __line_number;
 }
diff --git a/lib.h b/lib.h
index 45886b856ecd6e3b78bac6dfe9eefc1578c1b9a2..bc53bb4bf99884f45b7f92097015d587ffb45edd 100644 (file)
--- a/lib.h
+++ b/lib.h
@@ -33,10 +33,8 @@ void *xrealloc (void *__ptr, unsigned long __size);
 const char *get_filename (void);
 unsigned long get_line_number (void);
 
-void set_filename (const char *__filename);
-void set_line_number (unsigned long __line_number);
-
 void get_filename_and_line_number (const char **__filename_p, unsigned long *__line_number_p);
+void set_line_number (unsigned long __line_number);
 void set_filename_and_line_number (const char *__filename, unsigned long __line_number);
 
 #endif      /* _LIB_H */
index 3102eb48fa4f87b15279d5196e347fab70378823..a8b7c8ad688f6a9aa75241722b018dd7ddbbff6f 100644 (file)
--- a/listing.c
+++ b/listing.c
@@ -132,6 +132,8 @@ void add_listing_message (char *message, const char *filename, unsigned long lin
 
 }
 
+#include    "inttypes.h"
+
 void generate_listing (void) {
 
     struct ll *ll;
@@ -186,7 +188,7 @@ void generate_listing (void) {
         }
         
         if (ll->frag) {
-            fprintf (f, "%04lX ", ll->frag->address + ll->where);
+            fprintf (f, "%04"PRIx64, ll->frag->address + ll->where);
         } else {
             fprintf (f, "     ");
         }
@@ -235,7 +237,7 @@ void generate_listing (void) {
                     continue;
                 }
                 
-                fprintf (f, "    %08lx    %s\n", symbol_get_value (symbol), symbol_get_name (symbol));
+                fprintf (f, "    %08"PRIx64"    %s\n", symbol_get_value (symbol), symbol_get_name (symbol));
             
             }
         
@@ -257,7 +259,7 @@ void generate_listing (void) {
                     continue;
                 }
                 
-                fprintf (f, "    %08lx    %s\n", symbol_get_value (symbol), symbol_get_name (symbol));
+                fprintf (f, "    %08"PRIx64"    %s\n", symbol_get_value (symbol), symbol_get_name (symbol));
             
             }
         
@@ -276,7 +278,7 @@ void generate_listing (void) {
                 }
                 
                 if (symbol_is_undefined (symbol)) {
-                    fprintf (f, "    %08lx    %s\n", symbol_get_value (symbol), symbol_get_name (symbol));
+                    fprintf (f, "    %08"PRIx64"    %s\n", symbol_get_value (symbol), symbol_get_name (symbol));
                 }
             
             }
diff --git a/macro.c b/macro.c
index 31c3741a793dbccbc5619517cb9db40b13ad645b..9225b8341a1af84772f309ab0d10f8ded8d77667 100644 (file)
--- a/macro.c
+++ b/macro.c
@@ -39,12 +39,16 @@ void add_macro (char *start, char **pp, int report_line) {
     struct hashtab_name *key;
     struct macro *m;
     
+    const char *filename;
+    unsigned long line_number;
+    get_filename_and_line_number (&filename, &line_number);
+    
     if (is_end_of_line[(int) **pp]) {
     
         if (report_line) {
-            report_line_at (get_filename (), get_line_number (), REPORT_ERROR, start, caret - 1, "no macro name give in %%define directive");
+            report_line_at (filename, line_number, REPORT_ERROR, start, caret - 1, "no macro name give in %%define directive");
         } else {
-            report_at (get_filename (), get_line_number (), REPORT_ERROR, "no macro name give in %%define directive");
+            report_at (filename, line_number, REPORT_ERROR, "no macro name give in %%define directive");
         }
         
         return;
@@ -54,9 +58,9 @@ void add_macro (char *start, char **pp, int report_line) {
     if (!(sname = symname (pp))) {
     
         if (report_line) {
-            report_line_at (get_filename (), get_line_number (), REPORT_ERROR, start, caret, "macro names must be identifiers");
+            report_line_at (filename, line_number, REPORT_ERROR, start, caret, "macro names must be identifiers");
         } else {
-            report_at (get_filename (), get_line_number (), REPORT_ERROR, "macro names must be identifiers");
+            report_at (filename, line_number, REPORT_ERROR, "macro names must be identifiers");
         }
         
         return;
@@ -66,9 +70,9 @@ void add_macro (char *start, char **pp, int report_line) {
     if (strcmp (sname, "defined") == 0) {
     
         if (report_line) {
-            report_line_at (get_filename (), get_line_number (), REPORT_ERROR, start, caret, "\"%s\" cannout be used as a macro name", sname);
+            report_line_at (filename, line_number, REPORT_ERROR, start, caret, "\"%s\" cannout be used as a macro name", sname);
         } else {
-            report_at (get_filename (), get_line_number (), REPORT_ERROR, "\"%s\" cannout be used as a macro name", sname);
+            report_at (filename, line_number, REPORT_ERROR, "\"%s\" cannout be used as a macro name", sname);
         }
         
         return;
@@ -78,9 +82,9 @@ void add_macro (char *start, char **pp, int report_line) {
     if (**pp != '(' && !isspace ((int) **pp)) {
     
         if (report_line) {
-            report_line_at (get_filename (), get_line_number (), REPORT_ERROR, start, *pp, "whitespace is required after macro name");
+            report_line_at (filename, line_number, REPORT_ERROR, start, *pp, "whitespace is required after macro name");
         } else {
-            report_at (get_filename (), get_line_number (), REPORT_ERROR, "whitespace is required after macro name");
+            report_at (filename, line_number, REPORT_ERROR, "whitespace is required after macro name");
         }
     
         return;
@@ -90,9 +94,9 @@ void add_macro (char *start, char **pp, int report_line) {
     if ((key = find_macro (sname))) {
     
         if (report_line) {
-            report_line_at (get_filename (), get_line_number (), REPORT_WARNING, start, caret, "\"%s\" redefined", sname);
+            report_line_at (filename, line_number, REPORT_WARNING, start, caret, "\"%s\" redefined", sname);
         } else {
-            report_at (get_filename (), get_line_number (), REPORT_WARNING, "\"%s\" redefined", sname);
+            report_at (filename, line_number, REPORT_WARNING, "\"%s\" redefined", sname);
         }
         
         if ((m = hashtab_get (&hashtab_macros, key))) {
@@ -140,9 +144,9 @@ void add_macro (char *start, char **pp, int report_line) {
             if (m->is_variadic) {
             
                 if (report_line) {
-                    report_line_at (get_filename (), get_line_number (), REPORT_ERROR, start, *pp, "expected ')' after '...'");
+                    report_line_at (filename, line_number, REPORT_ERROR, start, *pp, "expected ')' after '...'");
                 } else {
-                    report_at (get_filename (), get_line_number (), REPORT_ERROR, "expected ')' after '...'");
+                    report_at (filename, line_number, REPORT_ERROR, "expected ')' after '...'");
                 }
                 
                 while ((arg = vec_pop (&m->args))) {
@@ -189,9 +193,9 @@ void add_macro (char *start, char **pp, int report_line) {
                 if (**pp != ',' && **pp != ')') {
                 
                     if (report_line) {
-                        report_line_at (get_filename (), get_line_number (), REPORT_ERROR, start, *pp, "expected ',' or, ')' after parameter");
+                        report_line_at (filename, line_number, REPORT_ERROR, start, *pp, "expected ',' or, ')' after parameter");
                     } else {
-                        report_at (get_filename (), get_line_number (), REPORT_ERROR, "expected ',' or, ')' after parameter");
+                        report_at (filename, line_number, REPORT_ERROR, "expected ',' or, ')' after parameter");
                     }
                     
                     goto err;
@@ -208,9 +212,9 @@ void add_macro (char *start, char **pp, int report_line) {
             }
             
             if (report_line) {
-                report_line_at (get_filename (), get_line_number (), REPORT_ERROR, start, *pp, "expected parameter name");
+                report_line_at (filename, line_number, REPORT_ERROR, start, *pp, "expected parameter name");
             } else {
-                report_at (get_filename (), get_line_number (), REPORT_ERROR, "expected parameter name");
+                report_at (filename, line_number, REPORT_ERROR, "expected parameter name");
             }
             
             goto err;
@@ -220,9 +224,9 @@ void add_macro (char *start, char **pp, int report_line) {
         if (**pp != ')') {
         
             if (report_line) {
-                report_line_at (get_filename (), get_line_number (), REPORT_ERROR, start, *pp, "expected ')' before end of line");
+                report_line_at (filename, line_number, REPORT_ERROR, start, *pp, "expected ')' before end of line");
             } else {
-                report_at (get_filename (), get_line_number (), REPORT_ERROR, "expected ')' before end of line");
+                report_at (filename, line_number, REPORT_ERROR, "expected ')' before end of line");
             }
             
             goto err;
@@ -254,9 +258,9 @@ void add_macro (char *start, char **pp, int report_line) {
             haystack = (p + strlen (needle));
             
             if (report_line) {
-                report_line_at (get_filename (), get_line_number (), REPORT_WARNING, m->value, p, "%s can only appear in the expansion of a variadic macro", needle);
+                report_line_at (filename, line_number, REPORT_WARNING, m->value, p, "%s can only appear in the expansion of a variadic macro", needle);
             } else {
-                report_at (get_filename (), get_line_number (), REPORT_WARNING, "%s can only appear in the expansion of a variadic macro", needle);
+                report_at (filename, line_number, REPORT_WARNING, "%s can only appear in the expansion of a variadic macro", needle);
             }
         
         }
@@ -283,12 +287,16 @@ void remove_macro (char *start, char **pp, int report_line) {
     struct hashtab_name *key;
     struct macro *mp;
     
+    const char *filename;
+    unsigned long line_number;
+    get_filename_and_line_number (&filename, &line_number);
+    
     if (!(sname = symname (pp))) {
     
         if (report_line) {
-            report_line_at (get_filename (), get_line_number (), REPORT_ERROR, start, caret, "macro names must be identifiers");
+            report_line_at (filename, line_number, REPORT_ERROR, start, caret, "macro names must be identifiers");
         } else {
-            report_at (get_filename (), get_line_number (), REPORT_ERROR, "macro names must be identifiers");
+            report_at (filename, line_number, REPORT_ERROR, "macro names must be identifiers");
         }
         
         return;
@@ -310,9 +318,9 @@ void remove_macro (char *start, char **pp, int report_line) {
     if (!is_end_of_line[(int) **pp]) {
     
         if (report_line) {
-            report_line_at (get_filename (), get_line_number (), REPORT_WARNING, start, *pp, "extra tokens at end of %%undef directive");
+            report_line_at (filename, line_number, REPORT_WARNING, start, *pp, "extra tokens at end of %%undef directive");
         } else {
-            report_at (get_filename (), get_line_number (), REPORT_WARNING, "extra tokens at end of %%undef directive");
+            report_at (filename, line_number, REPORT_WARNING, "extra tokens at end of %%undef directive");
         }
     
     }
@@ -324,6 +332,10 @@ static struct vector *get_macro_args (char *start, char *macro_name, char **pp)
     static struct vector args_list = { 0 };
     char *arg, saved_ch, ch;
     
+    const char *filename;
+    unsigned long line_number;
+    get_filename_and_line_number (&filename, &line_number);
+    
     memset (&args_list, 0, sizeof (args_list));
     
     if (**pp == '(') {
@@ -367,7 +379,7 @@ static struct vector *get_macro_args (char *start, char *macro_name, char **pp)
                 if (**pp == ch) {
                     (*pp)++;
                 } else {
-                    report_line_at (get_filename (), get_line_number (), REPORT_WARNING, start, arg, "missing terminating %c character", ch);
+                    report_line_at (filename, line_number, REPORT_WARNING, start, arg, "missing terminating %c character", ch);
                 }
             
             } else {
@@ -399,7 +411,7 @@ static struct vector *get_macro_args (char *start, char *macro_name, char **pp)
         
         if (**pp != ')') {
         
-            report_line_at (get_filename (), get_line_number (), REPORT_ERROR, start, *pp, "unterminated argument list invoking macro \"%s\"", macro_name);
+            report_line_at (filename, line_number, REPORT_ERROR, start, *pp, "unterminated argument list invoking macro \"%s\"", macro_name);
             return 0;
         
         }
@@ -487,6 +499,10 @@ char *process_macro (char *start, char **pp, struct macro *m) {
     struct vector *args_list;
     char *caret;
     
+    const char *filename;
+    unsigned long line_number;
+    get_filename_and_line_number (&filename, &line_number);
+    
     if (m->nargs > 0 || m->is_variadic) {
     
         args_list = 0;
@@ -499,7 +515,7 @@ char *process_macro (char *start, char **pp, struct macro *m) {
                 char *tmp = (m->nargs == 1 ? " argument" : " arguments");
                 char *tmp2 = (args_list->length == 1 ? "only " : "");
                 
-                report_line_at (get_filename (), get_line_number (), REPORT_ERROR, start, caret, "macro \"%s\" requires %d%s, but %s%d given", m->name, m->nargs, tmp, tmp2, args_list->length);
+                report_line_at (filename, line_number, REPORT_ERROR, start, caret, "macro \"%s\" requires %d%s, but %s%d given", m->name, m->nargs, tmp, tmp2, args_list->length);
             
             } else if (args_list->length > m->nargs) {
             
@@ -508,7 +524,7 @@ char *process_macro (char *start, char **pp, struct macro *m) {
                     char *tmp = (args_list->length == 1 ? " argument" : " arguments");
                     char *tmp2 = (m->nargs == 1 ? "just " : "");
                     
-                    report_line_at (get_filename (), get_line_number (), REPORT_ERROR, start, caret, "macro \"%s\" passed %d%s, but takes %s%d", m->name, args_list->length, tmp, tmp2, m->nargs);
+                    report_line_at (filename, line_number, REPORT_ERROR, start, caret, "macro \"%s\" passed %d%s, but takes %s%d", m->name, args_list->length, tmp, tmp2, m->nargs);
                 
                 }
             
index 26a3d2c5588849d6bcf03aa8bb440c318ced1562..e2e0339bf5d2b0978cdae8f46d0d76d01893fab9 100644 (file)
--- a/process.c
+++ b/process.c
@@ -705,8 +705,7 @@ int preprocess_init (void) {
     struct list *item;
     char *opt, *nopt, *p;
     
-    set_filename (xstrdup ("<command-line>"));
-    set_line_number (1);
+    set_filename_and_line_number (xstrdup ("<command-line>"), 1);
     
     if (state->pplist) {
     
@@ -1205,12 +1204,12 @@ void process_file (const char *ifile) {
     
     if (!ifile || strcmp (ifile, "-") == 0) {
     
-        set_filename (xstrdup ("<stdin>"));
+        set_filename_and_line_number (xstrdup ("<stdin>"), 0);
         fp = stdin;
     
     } else {
     
-        set_filename (xstrdup (ifile));
+        set_filename_and_line_number (xstrdup (ifile), 0);
         
         if (!(fp = fopen (ifile, "r"))) {
         
@@ -1221,9 +1220,7 @@ void process_file (const char *ifile) {
     
     }
     
-    set_line_number (0);
     new_line_number = 1;
-    
     load_line_internal_data = load_line_create_internal_data (&new_line_number);
     
     while (!load_line (&line, &line_end, &real_line, &real_line_len, &newlines, fp, &load_line_internal_data)) {
diff --git a/stdint.h b/stdint.h
new file mode 100644 (file)
index 0000000..07b51cc
--- /dev/null
+++ b/stdint.h
@@ -0,0 +1,22 @@
+/******************************************************************************
+ * @file            stdint.h
+ *****************************************************************************/
+#ifndef     _STDINT_H_INCLUDED
+#ifndef     _STDINT_H
+
+#define     _STDINT_H_INCLUDED
+#define     _STDINT_H
+
+#include    <limits.h>
+
+#if     defined (NO_LONG_LONG) || ULONG_MAX > 4294967295UL
+typedef     signed long                 int64_t;
+typedef     unsigned long               uint64_t;
+#else
+typedef     signed long long            int64_t;
+typedef     unsigned long long          uint64_t;
+#endif
+
+#endif      /* _STDINT_H */
+#endif      /* _STDINT_H_INCLUDED */
+
index c857281a2f6f5449e4c856b863acf9655ed59d12..5fbeb32fe284f81c483dbe722ef99a3b2803e18c 100644 (file)
--- a/symbol.c
+++ b/symbol.c
@@ -265,7 +265,7 @@ char *symbol_get_name (struct symbol *symbol) {
     return symbol->name;
 }
 
-int get_symbol_snapshot (struct symbol **symbol_p, unsigned long *value_p, struct section **section_p, struct frag **frag_p) {
+int get_symbol_snapshot (struct symbol **symbol_p, uint64_t *value_p, struct section **section_p, struct frag **frag_p) {
 
     struct symbol *symbol = *symbol_p;
     struct expr *expr = symbol_get_value_expression (symbol);
@@ -374,16 +374,16 @@ unsigned long symbol_get_symbol_table_index (struct symbol *symbol) {
     return symbol->symbol_table_index;
 }
 
-unsigned long symbol_get_value (struct symbol *symbol) {
+uint64_t symbol_get_value (struct symbol *symbol) {
     return symbol_resolve_value (symbol);
 }
 
-unsigned long symbol_resolve_value (struct symbol *symbol) {
+uint64_t symbol_resolve_value (struct symbol *symbol) {
 
     struct section *final_section = symbol_get_section (symbol);
     int resolved = 0;
     
-    unsigned long final_value = 0;
+    uint64_t final_value = 0;
     
     if (symbol->resolved) {
     
@@ -405,7 +405,7 @@ unsigned long symbol_resolve_value (struct symbol *symbol) {
     } else {
     
         struct section *left_section, *right_section;
-        unsigned long left_value, right_value;
+        uint64_t left_value, right_value;
         
         int can_move_into_absolute_section;
         
@@ -630,7 +630,7 @@ unsigned long symbol_resolve_value (struct symbol *symbol) {
                     case EXPR_TYPE_EQUAL:
                     case EXPR_TYPE_NOT_EQUAL:
                     
-                        left_value = ((left_value == right_value && left_section == right_section && (left_section != undefined_section || symbol->value.add_symbol == symbol->value.op_symbol)) ? ~(signed long) 0 : 0);
+                        left_value = ((left_value == right_value && left_section == right_section && (left_section != undefined_section || symbol->value.add_symbol == symbol->value.op_symbol)) ? ~(int64_t) 0 : 0);
                         
                         if (symbol->value.type == EXPR_TYPE_NOT_EQUAL) {
                             left_value = ~left_value;
@@ -640,22 +640,22 @@ unsigned long symbol_resolve_value (struct symbol *symbol) {
                     
                     case EXPR_TYPE_LESSER:
                     
-                        left_value = left_value < right_value ? ~(signed long) 0 : 0;
+                        left_value = left_value < right_value ? ~(int64_t) 0 : 0;
                         break;
                     
                     case EXPR_TYPE_LESSER_EQUAL:
                     
-                        left_value = left_value <= right_value ? ~(signed long) 0 : 0;
+                        left_value = left_value <= right_value ? ~(int64_t) 0 : 0;
                         break;
                     
                     case EXPR_TYPE_GREATER:
                     
-                        left_value = left_value > right_value ? ~(signed long) 0 : 0;
+                        left_value = left_value > right_value ? ~(int64_t) 0 : 0;
                         break;
                     
                     case EXPR_TYPE_GREATER_EQUAL:
                     
-                        left_value = left_value >= right_value ? ~(signed long) 0 : 0;
+                        left_value = left_value >= right_value ? ~(int64_t) 0 : 0;
                         break;
                     
                     case EXPR_TYPE_ADD:
@@ -700,12 +700,12 @@ unsigned long symbol_resolve_value (struct symbol *symbol) {
                     
                     case EXPR_TYPE_LEFT_SHIFT:
                     
-                        left_value = ~(unsigned long) left_value << ~(unsigned long) right_value;
+                        left_value = ~(uint64_t) left_value << ~(uint64_t) right_value;
                         break;
                     
                     case EXPR_TYPE_RIGHT_SHIFT:
                     
-                        left_value = ~(unsigned long) left_value >> ~(unsigned long) right_value;
+                        left_value = ~(uint64_t) left_value >> ~(uint64_t) right_value;
                         break;
                     
                     default:
@@ -784,7 +784,7 @@ void symbol_set_symbol_table_index (struct symbol *symbol, unsigned long index)
     symbol->symbol_table_index = index;
 }
 
-void symbol_set_value (struct symbol *symbol, unsigned long value) {
+void symbol_set_value (struct symbol *symbol, uint64_t value) {
 
     symbol->value.type = EXPR_TYPE_CONSTANT;
     symbol->value.add_number = value;
index 9fdde013e5605692de480ca112697578e5d837e7..a494ce2f6f9c2acd58ead40a37df6e6a6bfd79b7 100644 (file)
--- a/symbol.h
+++ b/symbol.h
@@ -38,7 +38,7 @@ extern int finalize_symbols;
 struct expr *symbol_get_value_expression (struct symbol *symbol);
 
 char *symbol_get_name (struct symbol *symbol);
-int get_symbol_snapshot (struct symbol **symbol_p, unsigned long *value_p, struct section **section_p, struct frag **frag_p);
+int get_symbol_snapshot (struct symbol **symbol_p, uint64_t *value_p, struct section **section_p, struct frag **frag_p);
 
 struct frag *symbol_get_frag (struct symbol *symbol);
 struct section *symbol_get_section (struct symbol *symbol);
@@ -59,15 +59,15 @@ int symbol_uses_other_symbol (struct symbol *symbol);
 int symbol_uses_reloc_symbol (struct symbol *symbol);
 
 unsigned long symbol_get_symbol_table_index (struct symbol *symbol);
-unsigned long symbol_get_value (struct symbol *symbol);
-unsigned long symbol_resolve_value (struct symbol *symbol);
+uint64_t symbol_get_value (struct symbol *symbol);
+uint64_t symbol_resolve_value (struct symbol *symbol);
 
 void symbol_add_to_chain (struct symbol *symbol);
 void symbol_set_frag (struct symbol *symbol, struct frag *frag);
 void symbol_set_external (struct symbol *symbol);
 void symbol_set_section (struct symbol *symbol, struct section *section);
 void symbol_set_symbol_table_index (struct symbol *symbol, unsigned long index);
-void symbol_set_value (struct symbol *symbol, unsigned long value);
+void symbol_set_value (struct symbol *symbol, uint64_t value);
 void symbol_set_value_expression (struct symbol *symbol, struct expr *expr);
 
 #endif      /* _SYMBOL_H */