diff --git a/src/code.c b/src/code.c index 380c4d0..3ae8b7b 100644 --- a/src/code.c +++ b/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; diff --git a/src/target/as.c b/src/target/as.c index b66c8ac..9854187 100644 --- a/src/target/as.c +++ b/src/target/as.c @@ -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); +} diff --git a/src/target/target.h b/src/target/target.h index 57a09fe..37ce503 100644 --- a/src/target/target.h +++ b/src/target/target.h @@ -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 */