[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: fixed size stack
From: |
Akim Demaille |
Subject: |
Re: fixed size stack |
Date: |
Wed, 18 Jul 2012 09:56:46 +0200 |
Le 17 juil. 2012 à 10:00, Claudio Eterno a écrit :
> Hi folks,
> I'm writing here due to some configuration problems on bison.
> My question: I would like to use bison for an embedded application (based
> on a uC with only 16kb of ram a 256 kb of flash). Due to the limited
> resources reasons and also I know exactly the maximum size of
> the necessary stack, I don't want to occupy the memory with me unuseful
> library functions (like malloc for example). Anyway, is this possible to
> remove the alloc/malloc/realloc functions during compilation?
Hi Claudio,
A quick test seems to be conclusive. Did you experiment
differently?
$ cat /tmp/foo.y
%code
{
# include <stdio.h>
# define YYINITDEPTH 10
# define YYMAXDEPTH YYINITDEPTH
void
yyerror(const char* msg)
{
fprintf (stderr, "%s\n", msg);
}
void *malloc(size_t s)
{
(void) s;
yyerror ("called malloc");
return 0;
}
int
yylex()
{
return '1';
}
}
%%
exp: '1' | '1' exp;
%%
int
main ()
{
return !!yyparse();
}
$ bison foo.y
$ gcc-mp-4.8 -Wall -Wextra foo.tab.c
$ ./a.out
memory exhausted
$ nm a.out
0000000100002060 S _NXArgc
0000000100002068 S _NXArgv
0000000100002078 S ___progname
U ___stderrp
0000000100000000 A __mh_execute_header
0000000100002070 S _environ
U _exit
U _fprintf
U _free
0000000100001c70 T _main
0000000100001540 T _malloc
U _memcpy
0000000100002000 s _pvars
0000000100002080 S _yychar
0000000100001e7c s _yycheck
0000000100001e6a s _yydefact
0000000100001e6f s _yydefgoto
000000010000156a t _yydestruct
0000000100001510 T _yyerror
000000010000155f T _yylex
0000000100002084 S _yylval
0000000100002088 S _yynerrs
0000000100001e71 s _yypact
000000010000158f T _yyparse
0000000100001e76 s _yypgoto
0000000100001e62 s _yyr1
0000000100001e66 s _yyr2
0000000100001e80 s _yystos
0000000100001e78 s _yytable
0000000100001d60 s _yytranslate
U dyld_stub_binder
00000001000014d4 T start
$
You show read the generated code, and see, for instance,
that verbose error message for instance, do require malloc.