changes inline asm buffers from static to dynamic size
authorjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 20 May 2001 16:13:39 +0000 (16:13 +0000)
committerjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 20 May 2001 16:13:39 +0000 (16:13 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@840 4a8a32a2-be11-0410-ad9d-d568d2c75423

src/SDCC.lex
src/SDCC.y
src/SDCCglobl.h
src/SDCCval.c
src/asm.c

index bb3e7a894f56f20d3d32216dd3676f91eaa299e8..414d44a88cf142e37cb32e009dcd8df04036f4ea 100644 (file)
@@ -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) ;}
-<asm>"_endasm" { count()               ; 
-                  *asmp = '\0'                         ; 
-                  strcpy(yylval.yyinline,asmbuff)              ; 
-                  BEGIN(INITIAL)       ;
-                  return (INLINEASM)                   ; }
-<asm>.         { *asmp++ = yytext[0]   ; }
-<asm>\n        { count(); *asmp++ = '\n' ;}
+"_asm"         {  
+  count(); 
+  asmp = asmbuff = Safe_realloc (asmbuff, INITIAL_INLINEASM);
+  asmbuffSize=INITIAL_INLINEASM;
+  BEGIN(asm) ;
+}
+<asm>"_endasm" { 
+  count();
+  *asmp = '\0';
+  yylval.yyinline = Safe_calloc (1, strlen(asmbuff)+1);
+  strcpy(yylval.yyinline,asmbuff);
+  BEGIN(INITIAL);
+  return (INLINEASM);
+}
+<asm>.         { 
+  if (asmp-asmbuff >= asmbuffSize-2) {
+    // increase the buffersize with 50%
+    asmbuffSize=asmbuffSize*3/2;
+    asmbuff = Safe_realloc (asmbuff, asmbuffSize); 
+  }
+  *asmp++ = yytext[0];
+}
+<asm>\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); }
index 98b944db8b945ed14153918536b25597ec1dc461..d4ae56a960022a004268493f8669250936429500 100644 (file)
@@ -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            */
 }
 
index 6feeb11f92d74fbecc20052a007b3abc7828ec62..ac513b55d074a61533cad0ddb7962d09b9d33dfc 100644 (file)
@@ -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]  ; \
index 016aad1503f23e1d2cbfd89199ef8d83f87798be..091cd3ee314967561e643b949043ec347f70c60e 100644 (file)
@@ -1,4 +1,3 @@
-void CatchMe() {}
 /*----------------------------------------------------------------------
     SDCCval.c :- has routine to do all kinds of fun stuff with the
                 value wrapper & with initialiser lists.
index df9fb385722332842f4a497a7449e9e49c4b04ce..6e7e133263e640d2fe4b1ecd30a3f8734441bb9a 100644 (file)
--- 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);