From 6965f5d1c138f1372a5f38cd4a5c5e19ccba7ecc Mon Sep 17 00:00:00 2001 From: johanknol Date: Sun, 20 May 2001 16:13:39 +0000 Subject: [PATCH] changes inline asm buffers from static to dynamic size git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@840 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- src/SDCC.lex | 42 +++++++++++++++++++++++++++++++++--------- src/SDCC.y | 2 +- src/SDCCglobl.h | 2 +- src/SDCCval.c | 1 - src/asm.c | 8 ++++++-- 5 files changed, 41 insertions(+), 14 deletions(-) diff --git a/src/SDCC.lex b/src/SDCC.lex index bb3e7a89..414d44a8 100644 --- a/src/SDCC.lex +++ b/src/SDCC.lex @@ -54,7 +54,8 @@ int yywrap YY_PROTO((void)) } #define TKEYWORD(token) return (isTargetKeyword(yytext) ? token :\ check_type(yytext)) -char asmbuff[MAX_INLINEASM] ; +char *asmbuff=NULL; +int asmbuffSize=0; char *asmp ; extern int check_type (); extern int isTargetKeyword (); @@ -82,14 +83,37 @@ struct options save_options ; %} %x asm %% -"_asm" { count(); asmp = asmbuff ;BEGIN(asm) ;} -"_endasm" { count() ; - *asmp = '\0' ; - strcpy(yylval.yyinline,asmbuff) ; - BEGIN(INITIAL) ; - return (INLINEASM) ; } -. { *asmp++ = yytext[0] ; } -\n { count(); *asmp++ = '\n' ;} +"_asm" { + count(); + asmp = asmbuff = Safe_realloc (asmbuff, INITIAL_INLINEASM); + asmbuffSize=INITIAL_INLINEASM; + BEGIN(asm) ; +} +"_endasm" { + count(); + *asmp = '\0'; + yylval.yyinline = Safe_calloc (1, strlen(asmbuff)+1); + strcpy(yylval.yyinline,asmbuff); + BEGIN(INITIAL); + return (INLINEASM); +} +. { + if (asmp-asmbuff >= asmbuffSize-2) { + // increase the buffersize with 50% + asmbuffSize=asmbuffSize*3/2; + asmbuff = Safe_realloc (asmbuff, asmbuffSize); + } + *asmp++ = yytext[0]; +} +\n { + count(); + if (asmp-asmbuff >= asmbuffSize-3) { + // increase the buffersize with 50% + asmbuffSize=asmbuffSize*3/2; + asmbuff = Safe_realloc (asmbuff, asmbuffSize); + } + *asmp++ = '\n' ; +} "/*" { comment(); } "at" { count(); TKEYWORD(AT) ; } "auto" { count(); return(AUTO); } diff --git a/src/SDCC.y b/src/SDCC.y index 98b944db..d4ae56a9 100644 --- a/src/SDCC.y +++ b/src/SDCC.y @@ -66,7 +66,7 @@ value *cenum = NULL ; /* current enumeration type chain*/ int yyint; /* integer value returned */ value *val ; /* for integer constant */ initList *ilist; /* initial list */ - char yyinline[MAX_INLINEASM]; /* inlined assembler code */ + char *yyinline; /* inlined assembler code */ ast *asts; /* expression tree */ } diff --git a/src/SDCCglobl.h b/src/SDCCglobl.h index 6feeb11f..ac513b55 100644 --- a/src/SDCCglobl.h +++ b/src/SDCCglobl.h @@ -99,7 +99,7 @@ typedef int bool; #define FALSE 0 #define MAX_TVAR 6 -#define MAX_INLINEASM 4*1024 +#define INITIAL_INLINEASM 4*1024 #define DEFPOOLSTACK(type,size) \ type *type##Pool ; \ type *type##FreeStack [size] ; \ diff --git a/src/SDCCval.c b/src/SDCCval.c index 016aad15..091cd3ee 100644 --- a/src/SDCCval.c +++ b/src/SDCCval.c @@ -1,4 +1,3 @@ -void CatchMe() {} /*---------------------------------------------------------------------- SDCCval.c :- has routine to do all kinds of fun stuff with the value wrapper & with initialiser lists. diff --git a/src/asm.c b/src/asm.c index df9fb385..6e7e1332 100644 --- a/src/asm.c +++ b/src/asm.c @@ -20,6 +20,10 @@ FileBaseName (char *fileFullName) { char *p = fileFullName; + if (!fileFullName) { + return "unknown"; + } + while (*fileFullName) { if ((*fileFullName == '/') || (*fileFullName == '\\') || (*fileFullName == ':')) @@ -179,7 +183,7 @@ tvsprintf (char *buffer, const char *format, va_list ap) // This is acheived by expanding the tokens and zero arg formats into // one big format string, which is passed to the native printf. static int count; - char newformat[MAX_INLINEASM]; + char newformat[INITIAL_INLINEASM]; char *pInto = newformat; char *p; char token[MAX_TOKEN_LEN]; @@ -261,7 +265,7 @@ void tfprintf (FILE * fp, const char *szFormat,...) { va_list ap; - char buffer[MAX_INLINEASM]; + char buffer[INITIAL_INLINEASM]; va_start (ap, szFormat); tvsprintf (buffer, szFormat, ap); -- 2.39.5