Introducing sections and functions in the as target

This commit is contained in:
Pierre Pronchery 2008-05-05 20:37:30 +00:00
parent 5cc0e11bf4
commit 39cb96e9e3
3 changed files with 44 additions and 7 deletions

View File

@ -48,10 +48,11 @@ typedef struct _CodeVariable
/* prototypes */ /* prototypes */
static int _code_target_init(Code * code, char const * outfile, int optlevel); static int _code_target_init(Code * code, char const * outfile, int optlevel);
static int _code_target_exit(Code * code); 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 _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 */ /* protected */
@ -96,10 +97,26 @@ static int _code_target_exit(Code * code)
} }
/* code_add_function */ /* code_target_function */
static int _code_add_function(Code * code, char const * name) 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) switch(code->context)
{ {
case CODE_CONTEXT_FUNCTION_NAME: case CODE_CONTEXT_FUNCTION_NAME:
return _code_add_function(code, name); return _code_function(code, name);
case CODE_CONTEXT_UNDEFINED: case CODE_CONTEXT_UNDEFINED:
default: default:
break; break;

View File

@ -55,6 +55,8 @@ static C99Option _as_options[ASO_COUNT + 1] =
/* prototypes */ /* prototypes */
static int _as_init(char const * outfile, int optlevel); static int _as_init(char const * outfile, int optlevel);
static int _as_exit(void); static int _as_exit(void);
static int _as_section(char const * name);
static int _as_function(char const * name);
/* public */ /* public */
@ -63,7 +65,9 @@ TargetPlugin target_plugin =
{ {
_as_options, _as_options,
_as_init, _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", fprintf(stderr, "DEBUG: %s: architecture \"%s\", format \"%s\"\n",
PACKAGE, as_get_arch(_as_as), as_get_format(_as_as)); PACKAGE, as_get_arch(_as_as), as_get_format(_as_as));
#endif #endif
if(as_open(_as_as, outfile) != 0) if(as_open(_as_as, outfile) != 0 || _as_section("text") != 0)
{ {
as_delete(_as_as); as_delete(_as_as);
return 1; return 1;
@ -104,3 +108,17 @@ static int _as_exit(void)
as_delete(_as_as); as_delete(_as_as);
return ret; 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);
}

View File

@ -30,6 +30,8 @@ typedef struct _TargetPlugin
C99Option * options; C99Option * options;
int (*init)(char const * outfile, int optlevel); int (*init)(char const * outfile, int optlevel);
int (*exit)(void); int (*exit)(void);
int (*section)(char const * name);
int (*function)(char const * name);
} TargetPlugin; } TargetPlugin;
#endif /* !_C99_TARGET_TARGET_H */ #endif /* !_C99_TARGET_TARGET_H */