Introducing sections and functions in the as target
This commit is contained in:
parent
5cc0e11bf4
commit
39cb96e9e3
27
src/code.c
27
src/code.c
@ -48,10 +48,11 @@ typedef struct _CodeVariable
|
||||
/* prototypes */
|
||||
static int _code_target_init(Code * code, char const * outfile, int optlevel);
|
||||
static int _code_target_exit(Code * code);
|
||||
static int _code_target_function(Code * code, char const * name);
|
||||
|
||||
static int _variable_add(Code * code, char const * name);
|
||||
|
||||
static int _code_add_function(Code * code, char const * name);
|
||||
static int _code_function(Code * code, char const * name);
|
||||
|
||||
|
||||
/* protected */
|
||||
@ -96,10 +97,26 @@ static int _code_target_exit(Code * code)
|
||||
}
|
||||
|
||||
|
||||
/* code_add_function */
|
||||
static int _code_add_function(Code * code, char const * name)
|
||||
/* code_target_function */
|
||||
static int _code_target_function(Code * code, char const * name)
|
||||
{
|
||||
return _variable_add(code, name);
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "DEBUG: %s()\n", __func__);
|
||||
#endif
|
||||
if(code->target->function == NULL)
|
||||
return 0;
|
||||
return code->target->function(name);
|
||||
}
|
||||
|
||||
|
||||
/* code_function */
|
||||
static int _code_function(Code * code, char const * name)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if((ret = _variable_add(code, name)) != 0)
|
||||
return ret;
|
||||
return _code_target_function(code, name);
|
||||
}
|
||||
|
||||
|
||||
@ -233,7 +250,7 @@ int code_set_identifier(Code * code, char const * name)
|
||||
switch(code->context)
|
||||
{
|
||||
case CODE_CONTEXT_FUNCTION_NAME:
|
||||
return _code_add_function(code, name);
|
||||
return _code_function(code, name);
|
||||
case CODE_CONTEXT_UNDEFINED:
|
||||
default:
|
||||
break;
|
||||
|
@ -55,6 +55,8 @@ static C99Option _as_options[ASO_COUNT + 1] =
|
||||
/* prototypes */
|
||||
static int _as_init(char const * outfile, int optlevel);
|
||||
static int _as_exit(void);
|
||||
static int _as_section(char const * name);
|
||||
static int _as_function(char const * name);
|
||||
|
||||
|
||||
/* public */
|
||||
@ -63,7 +65,9 @@ TargetPlugin target_plugin =
|
||||
{
|
||||
_as_options,
|
||||
_as_init,
|
||||
_as_exit
|
||||
_as_exit,
|
||||
_as_section,
|
||||
_as_function
|
||||
};
|
||||
|
||||
|
||||
@ -86,7 +90,7 @@ static int _as_init(char const * outfile, int optlevel)
|
||||
fprintf(stderr, "DEBUG: %s: architecture \"%s\", format \"%s\"\n",
|
||||
PACKAGE, as_get_arch(_as_as), as_get_format(_as_as));
|
||||
#endif
|
||||
if(as_open(_as_as, outfile) != 0)
|
||||
if(as_open(_as_as, outfile) != 0 || _as_section("text") != 0)
|
||||
{
|
||||
as_delete(_as_as);
|
||||
return 1;
|
||||
@ -104,3 +108,17 @@ static int _as_exit(void)
|
||||
as_delete(_as_as);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/* as_section */
|
||||
static int _as_section(char const * name)
|
||||
{
|
||||
return as_section(_as_as, name);
|
||||
}
|
||||
|
||||
|
||||
/* as_function */
|
||||
static int _as_function(char const * name)
|
||||
{
|
||||
return as_function(_as_as, name);
|
||||
}
|
||||
|
@ -30,6 +30,8 @@ typedef struct _TargetPlugin
|
||||
C99Option * options;
|
||||
int (*init)(char const * outfile, int optlevel);
|
||||
int (*exit)(void);
|
||||
int (*section)(char const * name);
|
||||
int (*function)(char const * name);
|
||||
} TargetPlugin;
|
||||
|
||||
#endif /* !_C99_TARGET_TARGET_H */
|
||||
|
Loading…
Reference in New Issue
Block a user