mirror of
https://github.com/netwide-assembler/nasm.git
synced 2024-11-27 08:10:07 +08:00
srcfile: simplify and make most functions inline
Simplify the srcfile subsystem by making it official that any pointer passed to src_get() needs to have been obtained from the srcfile subsystem itself. Move a lot of the srcfile operations into inline code; often they amount to a single machine instruction... Signed-off-by: H. Peter Anvin <hpa@zytor.com>
This commit is contained in:
parent
1aa794527f
commit
026b62f264
@ -44,8 +44,7 @@
|
|||||||
#include "hashtbl.h"
|
#include "hashtbl.h"
|
||||||
#include "srcfile.h"
|
#include "srcfile.h"
|
||||||
|
|
||||||
static const char *file_name = NULL;
|
struct src_location _src_here;
|
||||||
static int32_t line_number = 0;
|
|
||||||
|
|
||||||
static struct hash_table filename_hash;
|
static struct hash_table filename_hash;
|
||||||
|
|
||||||
@ -79,45 +78,23 @@ const char *src_set_fname(const char *newname)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
oldname = file_name;
|
oldname = _src_here.filename;
|
||||||
file_name = newname;
|
_src_here.filename = newname;
|
||||||
return oldname;
|
return oldname;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t src_set_linnum(int32_t newline)
|
|
||||||
{
|
|
||||||
int32_t oldline = line_number;
|
|
||||||
line_number = newline;
|
|
||||||
return oldline;
|
|
||||||
}
|
|
||||||
|
|
||||||
void src_set(int32_t line, const char *fname)
|
void src_set(int32_t line, const char *fname)
|
||||||
{
|
{
|
||||||
src_set_fname(fname);
|
src_set_fname(fname);
|
||||||
src_set_linnum(line);
|
src_set_linnum(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *src_get_fname(void)
|
struct src_location src_update(struct src_location whence)
|
||||||
{
|
{
|
||||||
return file_name;
|
struct src_location oldhere = _src_here;
|
||||||
}
|
|
||||||
|
src_set_fname(whence.filename);
|
||||||
int32_t src_get_linnum(void)
|
src_set_linnum(whence.lineno);
|
||||||
{
|
|
||||||
return line_number;
|
return oldhere;
|
||||||
}
|
|
||||||
|
|
||||||
int32_t src_get(int32_t *xline, const char **xname)
|
|
||||||
{
|
|
||||||
const char *xn = *xname;
|
|
||||||
int32_t xl = *xline;
|
|
||||||
|
|
||||||
*xline = line_number;
|
|
||||||
*xname = file_name;
|
|
||||||
|
|
||||||
/* XXX: Is the strcmp() really needed here? */
|
|
||||||
if (!file_name || !xn || (xn != file_name && strcmp(xn, file_name)))
|
|
||||||
return -2;
|
|
||||||
else
|
|
||||||
return line_number - xl;
|
|
||||||
}
|
}
|
||||||
|
@ -39,20 +39,64 @@
|
|||||||
|
|
||||||
#include "compiler.h"
|
#include "compiler.h"
|
||||||
|
|
||||||
|
struct src_location {
|
||||||
|
const char *filename;
|
||||||
|
int32_t lineno;
|
||||||
|
};
|
||||||
|
extern struct src_location _src_here;
|
||||||
|
|
||||||
void src_init(void);
|
void src_init(void);
|
||||||
void src_free(void);
|
void src_free(void);
|
||||||
const char *src_set_fname(const char *newname);
|
const char *src_set_fname(const char *newname);
|
||||||
const char *src_get_fname(void);
|
static inline const char *src_get_fname(void)
|
||||||
int32_t src_set_linnum(int32_t newline);
|
{
|
||||||
int32_t src_get_linnum(void);
|
return _src_here.filename;
|
||||||
|
}
|
||||||
|
static inline int32_t src_set_linnum(int32_t newline)
|
||||||
|
{
|
||||||
|
int32_t oldline = _src_here.lineno;
|
||||||
|
_src_here.lineno = newline;
|
||||||
|
return oldline;
|
||||||
|
}
|
||||||
|
static inline int32_t src_get_linnum(void)
|
||||||
|
{
|
||||||
|
return _src_here.lineno;
|
||||||
|
}
|
||||||
/* Can be used when there is no need for the old information */
|
/* Can be used when there is no need for the old information */
|
||||||
void src_set(int32_t line, const char *filename);
|
void src_set(int32_t line, const char *filename);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* src_get gets both the source file name and line.
|
* src_get gets both the source file name and line.
|
||||||
* It is also used if you maintain private status about the source location
|
* It is also used if you maintain private status about the source location
|
||||||
* It return 0 if the information was the same as the last time you
|
* It return 0 if the information was the same as the last time you
|
||||||
* checked, -2 if the name changed and (new-old) if just the line changed.
|
* checked, -2 if the name changed and (new-old) if just the line changed.
|
||||||
|
*
|
||||||
|
* xname must point to a filename string previously returned from any
|
||||||
|
* function of this subsystem or be NULL; another string value will
|
||||||
|
* not work.
|
||||||
*/
|
*/
|
||||||
int32_t src_get(int32_t *xline, const char **xname);
|
static inline int32_t src_get(int32_t *xline, const char **xname)
|
||||||
|
{
|
||||||
|
const char *xn = *xname;
|
||||||
|
int32_t xl = *xline;
|
||||||
|
|
||||||
|
*xline = _src_here.lineno;
|
||||||
|
*xname = _src_here.filename;
|
||||||
|
|
||||||
|
/* The return value is expected to be optimized out almost everywhere */
|
||||||
|
if (!xn || xn != _src_here.filename)
|
||||||
|
return -2;
|
||||||
|
else
|
||||||
|
return _src_here.lineno - xl;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns and sets/returns the current information as a structure.
|
||||||
|
*/
|
||||||
|
static inline struct src_location src_where(void)
|
||||||
|
{
|
||||||
|
return _src_here;
|
||||||
|
}
|
||||||
|
struct src_location src_update(struct src_location);
|
||||||
|
|
||||||
#endif /* ASM_SRCFILE_H */
|
#endif /* ASM_SRCFILE_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user