More constification, mostly of struct dfmt

Make struct dfmt and the struct dfmt arrays const across the board,
and make them static whereever possible.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
This commit is contained in:
H. Peter Anvin 2016-02-18 02:16:36 -08:00
parent f0ea3d7c2b
commit 7e3b12d6da
12 changed files with 44 additions and 37 deletions

2
nasm.h
View File

@ -683,7 +683,7 @@ struct ofmt {
/*
* this is a pointer to the first element of the debug information
*/
struct dfmt **debug_formats;
const struct dfmt * const *debug_formats;
/*
* the default debugging format if -F is not specified

View File

@ -77,7 +77,7 @@ void null_debug_cleanup(void)
{
}
struct dfmt null_debug_form = {
const struct dfmt null_debug_form = {
"Null debug format",
"null",
null_debug_init,
@ -89,4 +89,4 @@ struct dfmt null_debug_form = {
null_debug_cleanup
};
struct dfmt *null_debug_arr[2] = { &null_debug_form, NULL };
const struct dfmt * const null_debug_arr[2] = { &null_debug_form, NULL };

View File

@ -1190,11 +1190,11 @@ const struct ofmt of_coff = {
#endif
extern struct dfmt df_cv8;
extern const struct dfmt df_cv8;
#ifdef OF_WIN32
struct dfmt *win32_debug_arr[2] = { &df_cv8, NULL };
static const struct dfmt * const win32_debug_arr[2] = { &df_cv8, NULL };
const struct ofmt of_win32 = {
"Microsoft Win32 (i386) object files",
@ -1220,7 +1220,7 @@ const struct ofmt of_win32 = {
#ifdef OF_WIN64
struct dfmt *win64_debug_arr[2] = { &df_cv8, NULL };
static const struct dfmt * const win64_debug_arr[2] = { &df_cv8, NULL };
const struct ofmt of_win64 = {
"Microsoft Win64 (x86-64) object files",

View File

@ -242,7 +242,7 @@ static void dbgdbg_typevalue(int32_t type)
fprintf(ofile, "new type: %s(%"PRIX32")\n",
types[TYM_TYPE(type) >> 3], TYM_ELEMENTS(type));
}
static struct dfmt debug_debug_form = {
static const struct dfmt debug_debug_form = {
"Trace of all info passed to debug stage",
"debug",
dbgdbg_init,
@ -254,7 +254,7 @@ static struct dfmt debug_debug_form = {
dbgdbg_cleanup,
};
static struct dfmt *debug_debug_arr[3] = {
static const struct dfmt * const debug_debug_arr[3] = {
&debug_debug_form,
&null_debug_form,
NULL

View File

@ -152,8 +152,8 @@ static int arangeslen, arangesrellen, pubnameslen, infolen, inforellen,
abbrevlen, linelen, linerellen, framelen, loclen;
static int32_t dwarf_infosym, dwarf_abbrevsym, dwarf_linesym;
static struct dfmt df_dwarf;
static struct dfmt df_stabs;
static const struct dfmt df_dwarf;
static const struct dfmt df_stabs;
static struct elf_symbol *lastsym;
/* common debugging routines */
@ -1335,7 +1335,7 @@ static int elf_set_info(enum geninfo type, char **val)
(void)val;
return 0;
}
static struct dfmt df_dwarf = {
static const struct dfmt df_dwarf = {
"ELF32 (i386) dwarf debug format for Linux/Unix",
"dwarf",
dwarf_init,
@ -1346,7 +1346,7 @@ static struct dfmt df_dwarf = {
dwarf_output,
dwarf_cleanup
};
static struct dfmt df_stabs = {
static const struct dfmt df_stabs = {
"ELF32 (i386) stabs debug format for Linux/Unix",
"stabs",
null_debug_init,
@ -1358,7 +1358,8 @@ static struct dfmt df_stabs = {
stabs_cleanup
};
struct dfmt *elf32_debugs_arr[3] = { &df_dwarf, &df_stabs, NULL };
static const struct dfmt * const elf32_debugs_arr[3] =
{ &df_dwarf, &df_stabs, NULL };
const struct ofmt of_elf32 = {
"ELF32 (i386) object files (e.g. Linux)",

View File

@ -154,8 +154,8 @@ static int arangeslen, arangesrellen, pubnameslen, infolen, inforellen,
static int64_t dwarf_infosym, dwarf_abbrevsym, dwarf_linesym;
static struct dfmt df_dwarf;
static struct dfmt df_stabs;
static const struct dfmt df_dwarf;
static const struct dfmt df_stabs;
static struct elf_symbol *lastsym;
/* common debugging routines */
@ -1425,7 +1425,7 @@ static int elf_set_info(enum geninfo type, char **val)
(void)val;
return 0;
}
static struct dfmt df_dwarf = {
static const struct dfmt df_dwarf = {
"ELF64 (x86-64) dwarf debug format for Linux/Unix",
"dwarf",
dwarf_init,
@ -1436,7 +1436,7 @@ static struct dfmt df_dwarf = {
dwarf_output,
dwarf_cleanup
};
static struct dfmt df_stabs = {
static const struct dfmt df_stabs = {
"ELF64 (x86-64) stabs debug format for Linux/Unix",
"stabs",
null_debug_init,
@ -1448,7 +1448,8 @@ static struct dfmt df_stabs = {
stabs_cleanup
};
struct dfmt *elf64_debugs_arr[3] = { &df_dwarf, &df_stabs, NULL };
static const struct dfmt * const elf64_debugs_arr[3] =
{ &df_dwarf, &df_stabs, NULL };
const struct ofmt of_elf64 = {
"ELF64 (x86_64) object files (e.g. Linux)",

View File

@ -154,8 +154,8 @@ static int arangeslen, arangesrellen, pubnameslen, infolen, inforellen,
static int32_t dwarf_infosym, dwarf_abbrevsym, dwarf_linesym;
static struct dfmt df_dwarf;
static struct dfmt df_stabs;
static const struct dfmt df_dwarf;
static const struct dfmt df_stabs;
static struct elf_symbol *lastsym;
/* common debugging routines */
@ -1385,7 +1385,7 @@ static int elf_set_info(enum geninfo type, char **val)
(void)val;
return 0;
}
static struct dfmt df_dwarf = {
static const struct dfmt df_dwarf = {
"ELFX32 (x86-64) dwarf debug format for Linux/Unix",
"dwarf",
dwarf_init,
@ -1396,7 +1396,7 @@ static struct dfmt df_dwarf = {
dwarf_output,
dwarf_cleanup
};
static struct dfmt df_stabs = {
static const struct dfmt df_stabs = {
"ELFX32 (x86-64) stabs debug format for Linux/Unix",
"stabs",
null_debug_init,
@ -1408,7 +1408,8 @@ static struct dfmt df_stabs = {
stabs_cleanup
};
struct dfmt *elfx32_debugs_arr[3] = { &df_dwarf, &df_stabs, NULL };
static const struct dfmt * const elfx32_debugs_arr[3] =
{ &df_dwarf, &df_stabs, NULL };
const struct ofmt of_elfx32 = {
"ELFX32 (x86_64) object files (e.g. Linux)",

View File

@ -47,9 +47,11 @@
#define BUILD_DRIVERS_ARRAY
#include "output/outform.h"
const struct ofmt *ofmt_find(char *name, const struct ofmt_alias **ofmt_alias)
const struct ofmt *ofmt_find(const char *name,
const struct ofmt_alias **ofmt_alias)
{
const struct ofmt **ofp, *of;
const struct ofmt * const *ofp;
const struct ofmt *of;
unsigned int i;
*ofmt_alias = NULL;
@ -72,9 +74,10 @@ const struct ofmt *ofmt_find(char *name, const struct ofmt_alias **ofmt_alias)
return NULL;
}
struct dfmt *dfmt_find(const struct ofmt *ofmt, char *name)
const struct dfmt *dfmt_find(const struct ofmt *ofmt, const char *name)
{
struct dfmt **dfp, *df;
const struct dfmt * const *dfp;
const struct dfmt *df;
for (dfp = ofmt->debug_formats; (df = *dfp); dfp++) {
if (!nasm_stricmp(name, df->shortname))
@ -85,7 +88,7 @@ struct dfmt *dfmt_find(const struct ofmt *ofmt, char *name)
void ofmt_list(const struct ofmt *deffmt, FILE * fp)
{
const struct ofmt **ofp, *of;
const struct ofmt * const *ofp, *of;
unsigned int i;
/* primary targets first */
@ -107,7 +110,8 @@ void ofmt_list(const struct ofmt *deffmt, FILE * fp)
void dfmt_list(const struct ofmt *ofmt, FILE *fp)
{
struct dfmt **dfp, *df;
const struct dfmt * const *dfp;
const struct dfmt *df;
for (dfp = ofmt->debug_formats; (df = *dfp); dfp++) {
fprintf(fp, " %c %-10s%s\n",

View File

@ -288,7 +288,7 @@ extern const struct ofmt of_dbg;
* drivers array based on the above defines
*/
static const struct ofmt *drivers[] = {
static const struct ofmt * const drivers[] = {
#ifdef OF_BIN
&of_bin,
&of_ith,
@ -370,8 +370,8 @@ static const struct ofmt_alias ofmt_aliases[] = {
#endif /* BUILD_DRIVERS_ARRAY */
const struct ofmt *ofmt_find(char *name, const struct ofmt_alias **ofmt_alias);
struct dfmt *dfmt_find(const struct ofmt *, char *);
const struct ofmt *ofmt_find(const char *name, const struct ofmt_alias **ofmt_alias);
const struct dfmt *dfmt_find(const struct ofmt *, const char *);
void ofmt_list(const struct ofmt *, FILE *);
void dfmt_list(const struct ofmt *ofmt, FILE * fp);
extern struct dfmt null_debug_form;

View File

@ -1497,7 +1497,7 @@ static void dbgls_output(int output_type, void *param)
(void)output_type;
(void)param;
}
static struct dfmt ladsoft_debug_form = {
static const struct dfmt ladsoft_debug_form = {
"LADsoft Debug Records",
"ladsoft",
dbgls_init,
@ -1508,7 +1508,7 @@ static struct dfmt ladsoft_debug_form = {
dbgls_output,
dbgls_cleanup,
};
static struct dfmt *ladsoft_debug_arr[3] = {
static const struct dfmt *ladsoft_debug_arr[3] = {
&ladsoft_debug_form,
&null_debug_form,
NULL

View File

@ -53,7 +53,7 @@ void null_debug_directive(const char *directive, const char *params);
void null_debug_typevalue(int32_t type);
void null_debug_output(int type, void *param);
void null_debug_cleanup(void);
extern struct dfmt *null_debug_arr[2];
extern const struct dfmt * const null_debug_arr[2];
#endif /* NASM_OUTLIB_H */

View File

@ -2605,7 +2605,7 @@ static void dbgbi_output(int output_type, void *param)
(void)output_type;
(void)param;
}
static struct dfmt borland_debug_form = {
static const struct dfmt borland_debug_form = {
"Borland Debug Records",
"borland",
dbgbi_init,
@ -2617,7 +2617,7 @@ static struct dfmt borland_debug_form = {
dbgbi_cleanup,
};
static struct dfmt *borland_debug_arr[3] = {
static const struct dfmt *borland_debug_arr[3] = {
&borland_debug_form,
&null_debug_form,
NULL