mirror of
https://github.com/netwide-assembler/nasm.git
synced 2025-04-12 18:40:23 +08:00
pragma: define a hander for generic output (and debug) pragmas
There are cases where we may want to implement generic pragmas, while still make them selective based on output and/or debug formats. Initially, use this for the prefix/suffix options. Signed-off-by: H. Peter Anvin <hpa@linux.intel.com> Cc: Chang Seok Bae <chang.seok.bae@intel.com>
This commit is contained in:
parent
41103ab431
commit
f7be8b3253
30
asm/pragma.c
30
asm/pragma.c
@ -1,6 +1,6 @@
|
||||
/* ----------------------------------------------------------------------- *
|
||||
*
|
||||
* Copyright 1996-2017 The NASM Authors - All Rights Reserved
|
||||
* Copyright 1996-2018 The NASM Authors - All Rights Reserved
|
||||
* See the file AUTHORS included with the NASM distribution for
|
||||
* the specific copyright holders.
|
||||
*
|
||||
@ -49,7 +49,7 @@
|
||||
#include "assemble.h"
|
||||
#include "error.h"
|
||||
|
||||
static enum directive_result asm_pragma(const struct pragma *pragma);
|
||||
static enum directive_result output_pragma(const struct pragma *pragma);
|
||||
static enum directive_result limit_pragma(const struct pragma *pragma);
|
||||
|
||||
/*
|
||||
@ -87,14 +87,14 @@ static enum directive_result limit_pragma(const struct pragma *pragma);
|
||||
*/
|
||||
static struct pragma_facility global_pragmas[] =
|
||||
{
|
||||
{ "asm", asm_pragma },
|
||||
{ "asm", NULL },
|
||||
{ "limit", limit_pragma },
|
||||
{ "list", NULL },
|
||||
{ "file", NULL },
|
||||
{ "input", NULL },
|
||||
|
||||
/* None of these should actually happen... */
|
||||
{ "preproc", NULL }, /* This shouldn't happen... */
|
||||
/* None of these should actually happen due to special handling */
|
||||
{ "preproc", NULL }, /* Handled in the preprocessor by necessity */
|
||||
{ "output", NULL },
|
||||
{ "debug", NULL },
|
||||
{ "ignore", NULL },
|
||||
@ -110,6 +110,7 @@ static struct pragma_facility global_pragmas[] =
|
||||
*/
|
||||
static bool search_pragma_list(const struct pragma_facility *list,
|
||||
const char *default_name,
|
||||
pragma_handler generic_handler,
|
||||
struct pragma *pragma)
|
||||
{
|
||||
const struct pragma_facility *pf;
|
||||
@ -137,6 +138,10 @@ found_it:
|
||||
else
|
||||
rv = DIRR_UNKNOWN;
|
||||
|
||||
/* Is there an additional, applicable generic handler? */
|
||||
if (rv == DIRR_UNKNOWN && generic_handler)
|
||||
rv = generic_handler(pragma);
|
||||
|
||||
switch (rv) {
|
||||
case DIRR_UNKNOWN:
|
||||
switch (pragma->opcode) {
|
||||
@ -210,15 +215,16 @@ void process_pragma(char *str)
|
||||
pragma.tail = nasm_trim_spaces(p);
|
||||
|
||||
/* Look for a global pragma namespace */
|
||||
if (search_pragma_list(global_pragmas, NULL, &pragma))
|
||||
if (search_pragma_list(global_pragmas, NULL, NULL, &pragma))
|
||||
return;
|
||||
|
||||
/* Look to see if it is an output backend pragma */
|
||||
if (search_pragma_list(ofmt->pragmas, ofmt->shortname, &pragma))
|
||||
if (search_pragma_list(ofmt->pragmas, ofmt->shortname,
|
||||
output_pragma, &pragma))
|
||||
return;
|
||||
|
||||
/* Look to see if it is a debug format pragma */
|
||||
if (search_pragma_list(dfmt->pragmas, dfmt->shortname, &pragma))
|
||||
if (search_pragma_list(dfmt->pragmas, dfmt->shortname, NULL, &pragma))
|
||||
return;
|
||||
|
||||
/*
|
||||
@ -234,9 +240,10 @@ void process_pragma(char *str)
|
||||
}
|
||||
|
||||
/*
|
||||
* Pragmas for the assembler proper
|
||||
* Generic pragmas that apply to all output backends; these are handled
|
||||
* specially so they can be made selective based on the output format.
|
||||
*/
|
||||
static enum directive_result asm_pragma(const struct pragma *pragma)
|
||||
static enum directive_result output_pragma(const struct pragma *pragma)
|
||||
{
|
||||
switch (pragma->opcode) {
|
||||
case D_PREFIX:
|
||||
@ -258,6 +265,9 @@ static enum directive_result asm_pragma(const struct pragma *pragma)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* %pragma limit to set resource limits
|
||||
*/
|
||||
static enum directive_result limit_pragma(const struct pragma *pragma)
|
||||
{
|
||||
return nasm_set_limit(pragma->opname, pragma->tail);
|
||||
|
@ -727,10 +727,11 @@ enum directive_result {
|
||||
* as part of the struct pragma.
|
||||
*/
|
||||
struct pragma;
|
||||
typedef enum directive_result (*pragma_handler)(const struct pragma *);
|
||||
|
||||
struct pragma_facility {
|
||||
const char *name;
|
||||
enum directive_result (*handler)(const struct pragma *);
|
||||
pragma_handler handler;
|
||||
};
|
||||
|
||||
/*
|
||||
|
@ -4,9 +4,9 @@
|
||||
; Test of Mach-O subsection_by_symbol
|
||||
;
|
||||
|
||||
%pragma output subsections_via_symbols
|
||||
%pragma asm gprefix _
|
||||
%pragma asm lprefix L_
|
||||
%pragma macho subsections_via_symbols
|
||||
%pragma macho gprefix _
|
||||
%pragma macho lprefix L.
|
||||
|
||||
bits 32
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user