aboutsummaryrefslogtreecommitdiff
path: root/tccgen.c
diff options
context:
space:
mode:
authorKirill Smelkov <kirr@navytux.spb.ru>2012-11-15 03:31:49 +0400
committerKirill Smelkov <kirr@navytux.spb.ru>2012-11-16 10:22:14 +0400
commitb2a02961b4407ca76db5a66ca5ae855cbfba4e8e (patch)
tree3c0d00665fab9e4b352fcf5b1ad32063d955afb7 /tccgen.c
parente79c3533ecefd004daad8a27333582b2dad7f0b0 (diff)
downloadtinycc-b2a02961b4407ca76db5a66ca5ae855cbfba4e8e.tar.gz
tinycc-b2a02961b4407ca76db5a66ca5ae855cbfba4e8e.tar.bz2
Add support for __builtin_frame_address(level)
Continuing d6072d37 (Add __builtin_frame_address(0)) implement __builtin_frame_address for levels greater than zero, in order for tinycc to be able to compile its own lib/bcheck.c after cffb7af9 (lib/bcheck: Prevent __bound_local_new / __bound_local_delete from being miscompiled). I'm new to the internals, and used the most simple way to do it. Generated code is not very good for levels >= 2, compare gcc tcc level=0 mov %ebp,%eax lea 0x0(%ebp),%eax level=1 mov 0x0(%ebp),%eax mov 0x0(%ebp),%eax level=2 mov 0x0(%ebp),%eax mov 0x0(%ebp),%eax mov (%eax),%eax mov %eax,-0x10(%ebp) mov -0x10(%ebp),%eax mov (%eax),%eax level=3 mov 0x0(%ebp),%eax mov 0x0(%ebp),%eax mov (%eax),%eax mov (%eax),%ecx mov (%eax),%eax mov (%ecx),%eax But this is still an improvement and for bcheck we need level=1 for which the code is good. For the tests I had to force gcc use -O0 to not inline the functions. And -fno-omit-frame-pointer just in case. If someone knows how to improve the generated code - help is appreciated. Thanks, Kirill Cc: Michael Matz <matz@suse.de> Cc: Shinichiro Hamaji <shinichiro.hamaji@gmail.com>
Diffstat (limited to 'tccgen.c')
-rw-r--r--tccgen.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/tccgen.c b/tccgen.c
index f183913..f79da36 100644
--- a/tccgen.c
+++ b/tccgen.c
@@ -3665,20 +3665,23 @@ ST_FUNC void unary(void)
break;
case TOK_builtin_frame_address:
{
+ int level;
CType type;
next();
skip('(');
- if (tok != TOK_CINT) {
- tcc_error("__builtin_frame_address only takes integers");
- }
- if (tokc.i != 0) {
- tcc_error("TCC only supports __builtin_frame_address(0)");
+ if (tok != TOK_CINT || tokc.i < 0) {
+ tcc_error("__builtin_frame_address only takes positive integers");
}
+ level = tokc.i;
next();
skip(')');
type.t = VT_VOID;
mk_pointer(&type);
- vset(&type, VT_LOCAL, 0);
+ vset(&type, VT_LOCAL, 0); /* local frame */
+ while (level--) {
+ mk_pointer(&vtop->type);
+ indir(); /* -> parent frame */
+ }
}
break;
#ifdef TCC_TARGET_X86_64