"const"-ipation fixes from Trevor Woerner

This commit is contained in:
H. Peter Anvin 2002-09-12 02:23:54 +00:00
parent 3ab3f41305
commit bfebdb0a07
16 changed files with 57 additions and 54 deletions

View File

@ -89,8 +89,8 @@ static efunc errfunc;
static struct ofmt *outfmt;
static ListGen *list;
static long calcsize (long, long, int, insn *, char *);
static void gencode (long, long, int, insn *, char *, long);
static long calcsize (long, long, int, insn *, const char *);
static void gencode (long, long, int, insn *, const char *, long);
static int regval (operand *o);
static int matches (struct itemplate *, insn *);
static ea * process_ea (operand *, ea *, int, int, int);
@ -101,7 +101,7 @@ static int chsize (operand *, int);
* in order to pass a copy of the data off to the listing file
* generator at the same time.
*/
static void out (long offset, long segto, void *data, unsigned long type,
static void out (long offset, long segto, const void *data, unsigned long type,
long segment, long wrt)
{
long lineno;
@ -152,7 +152,7 @@ static void out (long offset, long segto, void *data, unsigned long type,
}
static int jmp_match (long segment, long offset, int bits,
insn *ins, char *code)
insn *ins, const char *code)
{ long isize;
unsigned char c = code[0];
@ -349,7 +349,7 @@ long assemble (long segment, long offset, int bits, unsigned long cp,
if (m == 100) /* matches! */
{
char *codes = temp->code;
const char *codes = temp->code;
long insn_size = calcsize(segment, offset, bits,
instruction, codes);
itimes = instruction->times;
@ -527,7 +527,7 @@ long insn_size (long segment, long offset, int bits, unsigned long cp,
if (m == 100) {
/* we've matched an instruction. */
long isize;
char * codes = temp->code;
const char * codes = temp->code;
int j;
isize = calcsize(segment, offset, bits, instruction, codes);
@ -570,7 +570,7 @@ static int is_sbyte (insn *ins, int op, int size)
}
static long calcsize (long segment, long offset, int bits,
insn *ins, char *codes)
insn *ins, const char *codes)
{
long length = 0;
unsigned char c;
@ -682,7 +682,7 @@ static long calcsize (long segment, long offset, int bits,
}
static void gencode (long segment, long offset, int bits,
insn *ins, char *codes, long insn_end)
insn *ins, const char *codes, long insn_end)
{
static char condval[] = { /* conditional opcodes */
0x7, 0x3, 0x2, 0x6, 0x2, 0x4, 0xF, 0xD, 0xC, 0xE, 0x6, 0x2,

View File

@ -90,7 +90,7 @@ static int whichreg(long regflags, int regval)
return 0;
}
static char *whichcond(int condval)
static const char *whichcond(int condval)
{
static int conds[] = {
C_O, C_NO, C_C, C_NC, C_Z, C_NZ, C_NA, C_A,

View File

@ -120,7 +120,7 @@ static void list_out (long offset, char *str)
strcat(listdata, str);
}
static void list_output (long offset, void *data, unsigned long type)
static void list_output (long offset, const void *data, unsigned long type)
{
unsigned long typ, size;
@ -132,7 +132,7 @@ static void list_output (long offset, void *data, unsigned long type)
if (typ == OUT_RAWDATA)
{
unsigned char *p = data;
unsigned char const *p = data;
char q[3];
while (size--)
{

6
nasm.h
View File

@ -147,7 +147,7 @@ typedef struct {
* work with when doing things like uplevel(LIST_TIMES) or
* uplevel(LIST_INCBIN).
*/
void (*output) (long, void *, unsigned long);
void (*output) (long, const void *, unsigned long);
/*
* Called to send a text line to the listing generator. The
@ -565,7 +565,7 @@ struct ofmt {
* and user-level equivalents for any format-specific
* directives).
*/
char **stdmac;
const char **stdmac;
/*
* This procedure is called at the start of an output session.
@ -594,7 +594,7 @@ struct ofmt {
* The `type' argument specifies the type of output data, and
* usually the size as well: its contents are described below.
*/
void (*output) (long segto, void *data, unsigned long type,
void (*output) (long segto, const void *data, unsigned long type,
long segment, long wrt);
/*

View File

@ -473,9 +473,9 @@ void *saa_wstruct (struct SAA *s)
return p;
}
void saa_wbytes (struct SAA *s, void *data, long len)
void saa_wbytes (struct SAA *s, const void *data, long len)
{
char *d = data;
const char *d = data;
while (len > 0) {
long l = s->end->length - s->end->posn;
@ -1008,7 +1008,7 @@ long reloc_wrt (expr *vect)
/*
* Binary search.
*/
int bsi (char *string, char **array, int size)
int bsi (char *string, const char **array, int size)
{
int i = -1, j = size; /* always, i < index < j */
while (j-i >= 2) {
@ -1092,20 +1092,24 @@ char *nasm_strcat(char *one, char *two)
return rslt;
}
void null_debug_routine(void)
{
}
void null_debug_init(struct ofmt *of, void *id, FILE *fp, efunc error ) {}
void null_debug_linenum(const char *filename, long linenumber, long segto) {}
void null_debug_deflabel(char *name, long segment, long offset, int is_global, char *special) {}
void null_debug_routine(const char *directive, const char *params) {}
void null_debug_typevalue(long type) {}
void null_debug_output(int type, void *param) {}
void null_debug_cleanup(void){}
struct dfmt null_debug_form = {
"Null debug format",
"null",
null_debug_init,
null_debug_linenum,
null_debug_deflabel,
null_debug_routine,
null_debug_routine,
null_debug_routine,
null_debug_routine,
null_debug_routine,
null_debug_routine,
null_debug_routine,
null_debug_typevalue,
null_debug_output,
null_debug_cleanup
};
struct dfmt *null_debug_arr[2] = { &null_debug_form, NULL };

View File

@ -197,7 +197,7 @@ struct SAA {
struct SAA *saa_init (long elem_len); /* 1 == byte */
void saa_free (struct SAA *);
void *saa_wstruct (struct SAA *); /* return a structure of elem_len */
void saa_wbytes (struct SAA *, void *, long); /* write arbitrary bytes */
void saa_wbytes (struct SAA *, const void *, long); /* write arbitrary bytes */
void saa_rewind (struct SAA *); /* for reading from beginning */
void *saa_rstruct (struct SAA *); /* return NULL on EOA */
void *saa_rbytes (struct SAA *, long *); /* return 0 on EOA */
@ -234,7 +234,7 @@ long reloc_wrt(expr *);
* matching `string', or <0 if no match. `array' is taken to
* contain `size' elements.
*/
int bsi (char *string, char **array, int size);
int bsi (char *string, const char **array, int size);
char *src_set_fname(char *newname);
@ -252,7 +252,7 @@ void nasm_quote(char **str);
char *nasm_strcat(char *one, char *two);
void nasmlib_cleanup(void);
void null_debug_routine(void);
void null_debug_routine(const char *directive, const char *params);
extern struct dfmt null_debug_form;
extern struct dfmt *null_debug_arr[2];
#endif

View File

@ -103,7 +103,7 @@ static int is_pic;
static void aout_write(void);
static void aout_write_relocs(struct Reloc *);
static void aout_write_syms(void);
static void aout_sect_write(struct Section *, unsigned char *, unsigned long);
static void aout_sect_write(struct Section *, const unsigned char *, unsigned long);
static void aout_pad_sections(void);
static void aout_fixup_relocs(struct Section *);
@ -546,7 +546,7 @@ static long aout_add_gotoff_reloc (struct Section *sect, long segment,
return offset - asym->value;
}
static void aout_out (long segto, void *data, unsigned long type,
static void aout_out (long segto, const void *data, unsigned long type,
long segment, long wrt)
{
struct Section *s;
@ -854,7 +854,7 @@ static void aout_write_syms (void)
}
static void aout_sect_write (struct Section *sect,
unsigned char *data, unsigned long len)
const unsigned char *data, unsigned long len)
{
saa_wbytes (sect->data, data, len);
sect->len += len;

View File

@ -78,7 +78,7 @@ static efunc error;
static void as86_write(void);
static void as86_write_section (struct Section *, int);
static int as86_add_string (char *name);
static void as86_sect_write(struct Section *, unsigned char *, unsigned long);
static void as86_sect_write(struct Section *, const unsigned char *, unsigned long);
static void as86_init(FILE *fp, efunc errfunc, ldfunc ldef, evalfunc eval)
{
@ -244,7 +244,7 @@ static void as86_add_piece (struct Section *sect, int type, long offset,
p->number = raa_read (bsym, segment), p->type = 2;
}
static void as86_out (long segto, void *data, unsigned long type,
static void as86_out (long segto, const void *data, unsigned long type,
long segment, long wrt)
{
struct Section *s;
@ -524,7 +524,7 @@ static void as86_write_section (struct Section *sect, int index)
}
static void as86_sect_write (struct Section *sect,
unsigned char *data, unsigned long len)
const unsigned char *data, unsigned long len)
{
saa_wbytes (sect->data, data, len);
sect->datalen += len;
@ -553,7 +553,7 @@ static void as86_filename (char *inname, char *outname, efunc error)
standard_extension (inname, outname, ".o", error);
}
static char *as86_stdmac[] = {
static const char *as86_stdmac[] = {
"%define __SECT__ [section .text]",
"%macro __NASM_CDecl__ 1",
"%endmacro",

View File

@ -314,7 +314,7 @@ static void bin_cleanup (int debuginfo)
}
}
static void bin_out (long segto, void *data, unsigned long type,
static void bin_out (long segto, const void *data, unsigned long type,
long segment, long wrt)
{
unsigned char *p, mydata[4];
@ -381,7 +381,6 @@ static void bin_out (long segto, void *data, unsigned long type,
} else if ((type & OUT_TYPMASK) == OUT_RAWDATA) {
type &= OUT_SIZMASK;
p = data;
if (s) {
saa_wbytes (s->contents, data, type);
s->length += type;

View File

@ -121,7 +121,7 @@ static struct SAA *strs;
static unsigned long strslen;
static void coff_gen_init(FILE *, efunc);
static void coff_sect_write (struct Section *, unsigned char *,
static void coff_sect_write (struct Section *, const unsigned char *,
unsigned long);
static void coff_write (void);
static void coff_section_header (char *, long, long, long, long, int, long);
@ -420,7 +420,7 @@ static long coff_add_reloc (struct Section *sect, long segment,
return 0;
}
static void coff_out (long segto, void *data, unsigned long type,
static void coff_out (long segto, const void *data, unsigned long type,
long segment, long wrt)
{
struct Section *s;
@ -529,7 +529,7 @@ static void coff_out (long segto, void *data, unsigned long type,
}
static void coff_sect_write (struct Section *sect,
unsigned char *data, unsigned long len)
const unsigned char *data, unsigned long len)
{
saa_wbytes (sect->data, data, len);
sect->len += len;

View File

@ -133,7 +133,7 @@ static int elf_nsect;
static long elf_foffs;
static void elf_write(void);
static void elf_sect_write(struct Section *, unsigned char *, unsigned long);
static void elf_sect_write(struct Section *, const unsigned char *, unsigned long);
static void elf_section_header (int, int, int, void *, int, long,
int, int, int, int);
static void elf_write_sections (void);
@ -665,7 +665,7 @@ static long elf_add_gsym_reloc (struct Section *sect,
return offset - sym->value;
}
static void elf_out (long segto, void *data, unsigned long type,
static void elf_out (long segto, const void *data, unsigned long type,
long segment, long wrt)
{
struct Section *s;
@ -1093,7 +1093,7 @@ static void elf_write_sections (void)
}
static void elf_sect_write (struct Section *sect,
unsigned char *data, unsigned long len)
const unsigned char *data, unsigned long len)
{
saa_wbytes (sect->data, data, len);
sect->len += len;

View File

@ -367,10 +367,10 @@ static void ieee_deflabel (char *name, long segment,
/*
* Put data out
*/
static void ieee_out (long segto, void *data, unsigned long type,
static void ieee_out (long segto, const void *data, unsigned long type,
long segment, long wrt) {
unsigned long size, realtype;
unsigned char *ucdata;
const unsigned char *ucdata;
long ldata;
struct ieeeSection *seg;

View File

@ -988,11 +988,11 @@ fprintf(stderr, " obj_deflabel: %s, seg=%ld, off=%ld, is_global=%d, %s\n",
static void obj_write_fixup (ObjRecord *orp, int bytes,
int segrel, long seg, long wrt, struct Segment *segto);
static void obj_out (long segto, void *data, unsigned long type,
static void obj_out (long segto, const void *data, unsigned long type,
long segment, long wrt)
{
unsigned long size, realtype;
unsigned char *ucdata;
const unsigned char *ucdata;
long ldata;
struct Segment *seg;
ObjRecord *orp;

View File

@ -421,7 +421,7 @@ static void rdf2_deflabel(char *name, long segment, long offset,
}
}
static void membufwrite(int segment, void * data, int bytes)
static void membufwrite(int segment, const void * data, int bytes)
{
int i;
char buf[4], * b;
@ -457,7 +457,7 @@ static int getsegmentlength(int segment)
return segments[i].seglength;
}
static void rdf2_out (long segto, void *data, unsigned long type,
static void rdf2_out (long segto, const void *data, unsigned long type,
long segment, long wrt)
{
long bytes = type & OUT_SIZMASK;
@ -693,7 +693,7 @@ static void rdf2_filename (char *inname, char *outname, efunc error) {
standard_extension(inname,outname,".rdf",error);
}
static char *rdf2_stdmac[] = {
static const char *rdf2_stdmac[] = {
"%define __SECT__ [section .text]",
"%imacro library 1+.nolist",
"[library %1]",

View File

@ -402,7 +402,7 @@ static const char **stdmacpos;
* The extra standard macros that come from the object format, if
* any.
*/
static char **extrastdmac = NULL;
static const char **extrastdmac = NULL;
int any_extrastdmac;
/*
@ -4438,7 +4438,7 @@ pp_pre_undefine(char *definition)
}
void
pp_extra_stdmac(char **macros)
pp_extra_stdmac(const char **macros)
{
extrastdmac = macros;
}

View File

@ -13,7 +13,7 @@ void pp_include_path (char *);
void pp_pre_include (char *);
void pp_pre_define (char *);
void pp_pre_undefine (char *);
void pp_extra_stdmac (char **);
void pp_extra_stdmac (const char **);
extern Preproc nasmpp;