+2007-01-07 Borut Razem <borut.razem AT siol.net>
+
+ * use dynamic memory buffers instead temporary files
+ * support/Util/dbuf_string.c, support/Util/dbuf_string.h:
+ added
+ * src/Makefile.in, src/SDCC.lex, src/SDCCast.c, src/SDCCast.h,
+ src/SDCCcse.c, src/SDCCglobl.h, src/SDCCglue.c, src/SDCCglue.h,
+ src/SDCCicode.c, src/SDCCicode.h, src/SDCCmain.c, src/SDCCmem.c,
+ src/SDCCmem.h, src/SDCCpeeph.c, src/SDCCpeeph.h, src/SDCCsymt.c,
+ src/SDCCsymt.h, src/SDCCutil.c, src/asm.c, src/asm.h, src/avr/gen.c,
+ src/avr/main.c, src/ds390/gen.c, src/ds390/main.c, src/hc08/gen.c,
+ src/hc08/main.c, src/izt/gen.c, src/mcs51/gen.c, src/mcs51/main.c,
+ src/pic/device.c, src/pic/gen.c, src/pic/glue.c, src/pic/main.c,
+ src/pic/ralloc.c, src/pic16/gen.c, src/pic16/glue.c,
+ src/pic16/main.c, src/pic16/ralloc.c, src/port.h, src/src.dsp,
+ src/xa51/gen.c, src/xa51/main.c, src/z80/gen.c, src/z80/main.c,
+ support/Util/dbuf.c, support/Util/dbuf.h:
+ modified
+
2007-01-07 Maarten Brock <sourceforge.brock AT dse.nl>
* src/port.h: added TARGET_Z80_LIKE macro
CFLAGS += -DSDCC_SUB_VERSION_STR=\"$(SDCC_SUB_VERSION)\"
endif
-SLIBOBJS = SDCCerr.o NewAlloc.o MySystem.o BuildCmd.o dbuf.o findme.o
+SLIBOBJS = SDCCerr.o NewAlloc.o MySystem.o BuildCmd.o dbuf.o dbuf_string.o findme.o
OBJECTS = SDCCy.o SDCChasht.o SDCCmain.o \
SDCCsymt.o SDCCopt.o SDCCast.o SDCCmem.o SDCCval.o \
#include <ctype.h>
#include "common.h"
#include "newalloc.h"
-#include "dbuf.h"
+#include "dbuf_string.h"
#define TKEYWORD(token) return (isTargetKeyword(yytext) ? token :\
check_type())
count();
if (!options.std_sdcc && yytext[1] != '_')
{
- dbuf_append(&asmbuff, yytext, strlen(yytext));
+ dbuf_append_str(&asmbuff, yytext);
}
else
{
}
<asm>\n {
count();
- dbuf_append(&asmbuff, yytext, 1);
+ dbuf_append_char(&asmbuff, *yytext);
}
<asm>. {
- dbuf_append(&asmbuff, yytext, 1);
+ dbuf_append_char(&asmbuff, *yytext);
}
"at" { count(); TKEYWORDSDCC(AT); }
"__at" { count(); TKEYWORD(AT); }
if (dbuf.alloc == 0)
dbuf_init(&dbuf, STR_BUF_CHUNCK_LEN);
else
- dbuf_set_size(&dbuf, 0);
+ dbuf_set_length(&dbuf, 0);
- dbuf_append(&dbuf, "\"", 1);
+ dbuf_append_char(&dbuf, '"');
/* put into the buffer till we hit the first \" */
while ((ch = input()) != 0) {
case '\n':
/* if new line we have a new line break, which is illegal */
werror(W_NEWLINE_IN_STRING);
- dbuf_append(&dbuf, "\n", 1);
+ dbuf_append_char(&dbuf, '\n');
lineno = ++mylineno;
column = 0;
break;
/* if this is a quote then we have work to do */
/* find the next non whitespace character */
/* if that is a double quote then carry on */
- dbuf_append(&dbuf, "\"", 1); /* Pass end of this string or substring to evaluator */
+ dbuf_append_char(&dbuf, '"'); /* Pass end of this string or substring to evaluator */
while ((ch = input()) && (isspace(ch) || ch == '\\' || ch == '#')) {
switch (ch) {
case '\\':
const char *line;
dbuf_init(&linebuf, STR_BUF_CHUNCK_LEN);
- dbuf_append(&linebuf, "#", 1);
+ dbuf_append_char(&linebuf, '#');
while ((ch = input()) && ch != '\n') {
- buf[0] = ch;
- dbuf_append(&linebuf, buf, 1);
+ dbuf_append_char(&linebuf, (char)ch);
}
if (ch == '\n') {
break;
default:
- buf[0] = ch;
- dbuf_append(&dbuf, buf, 1); /* Put next substring introducer into output string */
+ dbuf_append_char(&dbuf, (char)ch); /* Put next substring introducer into output string */
}
}
void PA(ast *t);
int inInitMode = 0;
memmap *GcurMemmap=NULL; /* points to the memmap that's currently active */
-FILE *codeOutFile;
+struct dbuf_s *codeOutBuf;
int
ptt (ast * tree)
{
/* create the node & generate intermediate code */
GcurMemmap = code;
- codeOutFile = code->oFile;
+ codeOutBuf = &code->oBuf;
piCode = iCodeFromAst (ex);
if (fatalError)
if (staticAutos)
{
GcurMemmap = statsg;
- codeOutFile = statsg->oFile;
+ codeOutBuf = &statsg->oBuf;
eBBlockFromiCode (iCodeFromAst (decorateType (resolveSymbols (staticAutos), RESULT_TYPE_NONE)));
staticAutos = NULL;
}
/* forward declarations for global variables */
extern ast *staticAutos;
-extern FILE *codeOutFile;
+extern struct dbuf_s *codeOutBuf;
extern struct memmap *GcurMemmap;
/* forward definitions for functions */
#include "common.h"
#include "newalloc.h"
+#include "dbuf_string.h"
/*-----------------------------------------------------------------*/
{
cseDef *cdp = item;
iCodeTable *icTab;
+ struct dbuf_s dbuf;
(void) ap;
fprintf (stdout, "**null op**");
printOperand (cdp->sym, stdout);
icTab = getTableEntry (cdp->diCode->op);
- icTab->iCodePrint (stdout, cdp->diCode, icTab->printName);
+ dbuf_init (&dbuf, 1024);
+ icTab->iCodePrint (&dbuf, cdp->diCode, icTab->printName);
+ dbuf_write_and_destroy (&dbuf, stdout);
return 1;
}
void setParseWithComma (set **, const char *);
-/** Creates a temporary file a'la tmpfile which avoids the bugs
- in cygwin wrt c:\tmp.
- Scans, in order: TMP, TEMP, TMPDIR, else uses tmpfile().
-*/
-FILE *tempfile (void);
-
-/** Creates a temporary file name a'la tmpnam which avoids the bugs
- in cygwin wrt c:\tmp.
- Scans, in order: TMP, TEMP, TMPDIR, else uses tmpfile().
-*/
-char *tempfilename (void);
-
/** An assert() macro that will go out through sdcc's error
system.
*/
#include "newalloc.h"
#include <fcntl.h>
#include <sys/stat.h>
+#include "dbuf_string.h"
#ifdef _WIN32
#include <io.h>
symbol *interrupts[INTNO_MAX+1];
-void printIval (symbol *, sym_link *, initList *, FILE *);
+void printIval (symbol *, sym_link *, initList *, struct dbuf_s *);
set *publics = NULL; /* public variables */
set *externs = NULL; /* Variables that are declared as extern */
return 0;
}
-/*-----------------------------------------------------------------*/
-/* rm_tmpfiles - close and remove temporary files and delete sets */
-/*-----------------------------------------------------------------*/
-void
-rm_tmpfiles (void)
-{
- /* close temporary files */
- applyToSet (pipeSet, closePipes);
- /* close temporary files */
- deleteSet (&pipeSet);
-
- applyToSet (tmpfileSet, closeTmpFiles);
- /* remove temporary files */
- applyToSet (tmpfileNameSet, rmTmpFiles);
- /* delete temorary file sets */
- deleteSet (&tmpfileSet);
- deleteSet (&tmpfileNameSet);
-}
-
-/*-----------------------------------------------------------------*/
-/* copyFile - copies source file to destination file */
-/*-----------------------------------------------------------------*/
-void
-copyFile (FILE * dest, FILE * src)
-{
- int ch;
-
- rewind (src);
- while (!feof (src))
- if ((ch = fgetc (src)) != EOF)
- fputc (ch, dest);
-}
-
char *
aopLiteralLong (value * val, int offset, int size)
{
{
/* PENDING: special case here - should remove */
if (!strcmp (map->sname, CODE_NAME))
- tfprintf (map->oFile, "\t!areacode\n", map->sname);
+ dbuf_tprintf (&map->oBuf, "\t!areacode\n", map->sname);
else if (!strcmp (map->sname, DATA_NAME))
- tfprintf (map->oFile, "\t!areadata\n", map->sname);
+ dbuf_tprintf (&map->oBuf, "\t!areadata\n", map->sname);
else if (!strcmp (map->sname, HOME_NAME))
- tfprintf (map->oFile, "\t!areahome\n", map->sname);
+ dbuf_tprintf (&map->oBuf, "\t!areahome\n", map->sname);
else
- tfprintf (map->oFile, "\t!area\n", map->sname);
+ dbuf_tprintf (&map->oBuf, "\t!area\n", map->sname);
}
for (sym = setFirstItem (map->syms); sym;
if (!sym->level) /* global */
{
if (IS_STATIC (sym->etype))
- fprintf (map->oFile, "F%s$", moduleName); /* scope is file */
+ dbuf_printf (&map->oBuf, "F%s$", moduleName); /* scope is file */
else
- fprintf (map->oFile, "G$"); /* scope is global */
+ dbuf_printf (&map->oBuf, "G$"); /* scope is global */
}
else
{
/* symbol is local */
- fprintf (map->oFile, "L%s$", (sym->localof ? sym->localof->name : "-null-"));
+ dbuf_printf (&map->oBuf, "L%s$", (sym->localof ? sym->localof->name : "-null-"));
}
- fprintf (map->oFile, "%s$%d$%d", sym->name, sym->level, sym->block);
+ dbuf_printf (&map->oBuf, "%s$%d$%d", sym->name, sym->level, sym->block);
}
/* if it has an initial value then do it only if
if (!SPEC_ABSA (sym->etype))
{
- FILE *tmpFile = tempfile ();
- addSetHead (&tmpfileSet, tmpFile);
+ struct dbuf_s tmpBuf;
+
+ dbuf_init(&tmpBuf, 4096);
// before allocation we must parse the sym->ival tree
// but without actually generating initialization code
noAlloc++;
resolveIvalSym (sym->ival, sym->type);
- printIval (sym, sym->type, sym->ival, tmpFile);
+ printIval (sym, sym->type, sym->ival, &tmpBuf);
noAlloc--;
+ dbuf_destroy(&tmpBuf);
}
} else {
if (IS_AGGREGATE (sym->type)) {
ival = newNode ('=', newAst_VALUE (symbolVal (sym)),
decorateType (resolveSymbols (list2expr (sym->ival)), RESULT_TYPE_NONE));
}
- codeOutFile = statsg->oFile;
+ codeOutBuf = &statsg->oBuf;
if (ival) {
// set ival's lineno to where the symbol was defined
{
char *equ="=";
if (options.debug) {
- fprintf (map->oFile, " == 0x%04x\n", SPEC_ADDR (sym->etype));
+ dbuf_printf (&map->oBuf, " == 0x%04x\n", SPEC_ADDR (sym->etype));
}
if (TARGET_IS_XA51) {
if (map==sfr) {
equ="bit";
}
}
- fprintf (map->oFile, "%s\t%s\t0x%04x\n",
+ dbuf_printf (&map->oBuf, "%s\t%s\t0x%04x\n",
sym->rname, equ,
SPEC_ADDR (sym->etype));
}
}
/* allocate space */
if (options.debug) {
- fprintf (map->oFile, "==.\n");
+ dbuf_printf (&map->oBuf, "==.\n");
}
if (SPEC_ABSA (sym->etype))
{
- tfprintf (map->oFile, "\t!org\n", SPEC_ADDR (sym->etype));
+ dbuf_tprintf (&map->oBuf, "\t!org\n", SPEC_ADDR (sym->etype));
}
if (IS_STATIC (sym->etype) || sym->level)
- tfprintf (map->oFile, "!slabeldef\n", sym->rname);
+ dbuf_tprintf (&map->oBuf, "!slabeldef\n", sym->rname);
else
- tfprintf (map->oFile, "!labeldef\n", sym->rname);
- tfprintf (map->oFile, "\t!ds\n", (unsigned int) size & 0xffff);
+ dbuf_tprintf (&map->oBuf, "!labeldef\n", sym->rname);
+ dbuf_tprintf (&map->oBuf, "\t!ds\n", (unsigned int) size & 0xffff);
}
sym->ival = NULL;
}
/* printChar - formats and prints a characater string with DB */
/*-----------------------------------------------------------------*/
void
-printChar (FILE * ofile, char *s, int plen)
+printChar (struct dbuf_s * oBuf, char *s, int plen)
{
int i;
int len = plen;
{
*p = '\0';
if (p != buf)
- tfprintf (ofile, "\t!ascii\n", buf);
- tfprintf (ofile, "\t!db !constbyte\n", (unsigned char)*s);
+ dbuf_tprintf (oBuf, "\t!ascii\n", buf);
+ dbuf_tprintf (oBuf, "\t!db !constbyte\n", (unsigned char)*s);
p = buf;
}
else
if (p != buf)
{
*p = '\0';
- tfprintf (ofile, "\t!ascii\n", buf);
+ dbuf_tprintf (oBuf, "\t!ascii\n", buf);
p = buf;
}
}
while (pplen < plen)
{
- tfprintf (ofile, "\t!db !constbyte\n", 0);
+ dbuf_tprintf (oBuf, "\t!db !constbyte\n", 0);
pplen++;
}
}
/* printPointerType - generates ival for pointer type */
/*-----------------------------------------------------------------*/
void
-_printPointerType (FILE * oFile, const char *name)
+_printPointerType (struct dbuf_s * oBuf, const char *name)
{
if (options.model == MODEL_FLAT24)
{
if (port->little_endian)
- fprintf (oFile, "\t.byte %s,(%s >> 8),(%s >> 16)", name, name, name);
+ dbuf_printf (oBuf, "\t.byte %s,(%s >> 8),(%s >> 16)", name, name, name);
else
- fprintf (oFile, "\t.byte (%s >> 16),(%s >> 8),%s", name, name, name);
+ dbuf_printf (oBuf, "\t.byte (%s >> 16),(%s >> 8),%s", name, name, name);
}
else
{
if (port->little_endian)
- fprintf (oFile, "\t.byte %s,(%s >> 8)", name, name);
+ dbuf_printf (oBuf, "\t.byte %s,(%s >> 8)", name, name);
else
- fprintf (oFile, "\t.byte (%s >> 8),%s", name, name);
+ dbuf_printf (oBuf, "\t.byte (%s >> 8),%s", name, name);
}
}
/* printPointerType - generates ival for pointer type */
/*-----------------------------------------------------------------*/
void
-printPointerType (FILE * oFile, const char *name)
+printPointerType (struct dbuf_s * oBuf, const char *name)
{
- _printPointerType (oFile, name);
- fprintf (oFile, "\n");
+ _printPointerType (oBuf, name);
+ dbuf_printf (oBuf, "\n");
}
/*-----------------------------------------------------------------*/
/* printGPointerType - generates ival for generic pointer type */
/*-----------------------------------------------------------------*/
void
-printGPointerType (FILE * oFile, const char *iname, const char *oname,
+printGPointerType (struct dbuf_s * oBuf, const char *iname, const char *oname,
const unsigned int type)
{
- _printPointerType (oFile, iname);
- fprintf (oFile, ",#0x%02x\n", pointerTypeToGPByte (type, iname, oname));
+ _printPointerType (oBuf, iname);
+ dbuf_printf (oBuf, ",#0x%02x\n", pointerTypeToGPByte (type, iname, oname));
}
/*-----------------------------------------------------------------*/
/* printIvalType - generates ival for int/char */
/*-----------------------------------------------------------------*/
void
-printIvalType (symbol *sym, sym_link * type, initList * ilist, FILE * oFile)
+printIvalType (symbol *sym, sym_link * type, initList * ilist, struct dbuf_s * oBuf)
{
value *val;
switch (getSize (type)) {
case 1:
if (!val)
- tfprintf (oFile, "\t!db !constbyte\n", 0);
+ dbuf_tprintf (oBuf, "\t!db !constbyte\n", 0);
else
- tfprintf (oFile, "\t!dbs\n",
+ dbuf_tprintf (oBuf, "\t!dbs\n",
aopLiteral (val, 0));
break;
case 2:
if (port->use_dw_for_init)
- tfprintf (oFile, "\t!dws\n", aopLiteralLong (val, 0, 2));
+ dbuf_tprintf (oBuf, "\t!dws\n", aopLiteralLong (val, 0, 2));
else if (port->little_endian)
- fprintf (oFile, "\t.byte %s,%s\n", aopLiteral (val, 0), aopLiteral (val, 1));
+ dbuf_printf (oBuf, "\t.byte %s,%s\n", aopLiteral (val, 0), aopLiteral (val, 1));
else
- fprintf (oFile, "\t.byte %s,%s\n", aopLiteral (val, 1), aopLiteral (val, 0));
+ dbuf_printf (oBuf, "\t.byte %s,%s\n", aopLiteral (val, 1), aopLiteral (val, 0));
break;
case 4:
if (!val) {
- tfprintf (oFile, "\t!dw !constword\n", 0);
- tfprintf (oFile, "\t!dw !constword\n", 0);
+ dbuf_tprintf (oBuf, "\t!dw !constword\n", 0);
+ dbuf_tprintf (oBuf, "\t!dw !constword\n", 0);
}
else if (port->little_endian) {
- fprintf (oFile, "\t.byte %s,%s,%s,%s\n",
+ dbuf_printf (oBuf, "\t.byte %s,%s,%s,%s\n",
aopLiteral (val, 0), aopLiteral (val, 1),
aopLiteral (val, 2), aopLiteral (val, 3));
}
else {
- fprintf (oFile, "\t.byte %s,%s,%s,%s\n",
+ dbuf_printf (oBuf, "\t.byte %s,%s,%s,%s\n",
aopLiteral (val, 3), aopLiteral (val, 2),
aopLiteral (val, 1), aopLiteral (val, 0));
}
/*-----------------------------------------------------------------*/
/* printIvalBitFields - generate initializer for bitfields */
/*-----------------------------------------------------------------*/
-void printIvalBitFields(symbol **sym, initList **ilist, FILE * oFile)
+void printIvalBitFields(symbol **sym, initList **ilist, struct dbuf_s * oBuf)
{
value *val ;
symbol *lsym = *sym;
} while (1);
switch (size) {
case 1:
- tfprintf (oFile, "\t!db !constbyte\n",ival);
+ dbuf_tprintf (oBuf, "\t!db !constbyte\n",ival);
break;
case 2:
- tfprintf (oFile, "\t!dw !constword\n",ival);
+ dbuf_tprintf (oBuf, "\t!dw !constword\n",ival);
break;
case 4: /* EEP: why is this db and not dw? */
- tfprintf (oFile, "\t!db !constword,!constword\n",
+ dbuf_tprintf (oBuf, "\t!db !constword,!constword\n",
(ival >> 8) & 0xffff, (ival & 0xffff));
break;
}
/*-----------------------------------------------------------------*/
void
printIvalStruct (symbol * sym, sym_link * type,
- initList * ilist, FILE * oFile)
+ initList * ilist, struct dbuf_s * oBuf)
{
symbol *sflds;
initList *iloop = NULL;
}
if (SPEC_STRUCT (type)->type == UNION) {
- printIval (sym, sflds->type, iloop, oFile);
+ printIval (sym, sflds->type, iloop, oBuf);
iloop = iloop->next;
} else {
for (; sflds; sflds = sflds->next, iloop = (iloop ? iloop->next : NULL)) {
if (IS_BITFIELD(sflds->type)) {
- printIvalBitFields(&sflds,&iloop,oFile);
+ printIvalBitFields(&sflds, &iloop, oBuf);
} else {
- printIval (sym, sflds->type, iloop, oFile);
+ printIval (sym, sflds->type, iloop, oBuf);
}
}
}
/* printIvalChar - generates initital value for character array */
/*-----------------------------------------------------------------*/
int
-printIvalChar (symbol * sym, sym_link * type, initList * ilist, FILE * oFile, char *s)
+printIvalChar (symbol * sym, sym_link * type, initList * ilist, struct dbuf_s * oBuf, char *s)
{
value *val;
unsigned int size = DCL_ELEM (type);
DCL_ELEM (type) = size;
}
- printChar (oFile, SPEC_CVAL (val->etype).v_char, size);
+ printChar (oBuf, SPEC_CVAL (val->etype).v_char, size);
return 1;
}
return 0;
}
else
- printChar (oFile, s, strlen (s) + 1);
+ printChar (oBuf, s, strlen (s) + 1);
return 1;
}
/*-----------------------------------------------------------------*/
void
printIvalArray (symbol * sym, sym_link * type, initList * ilist,
- FILE * oFile)
+ struct dbuf_s * oBuf)
{
value *val;
initList *iloop;
}
if (printIvalChar (sym, type,
(ilist->type == INIT_DEEP ? ilist->init.deep : ilist),
- oFile, SPEC_CVAL (sym->etype).v_char))
+ oBuf, SPEC_CVAL (sym->etype).v_char))
return;
}
/* not the special case */
werrorfl (sym->fileDef, sym->lineDef, W_EXCESS_INITIALIZERS, "array", sym->name);
break;
}
- printIval (sym, type->next, iloop, oFile);
+ printIval (sym, type->next, iloop, oBuf);
}
}
if (size<DCL_ELEM(type)) {
size = (DCL_ELEM(type) - size) * getSize(type->next);
while (size--) {
- tfprintf (oFile, "\t!db !constbyte\n", 0);
+ dbuf_tprintf (oBuf, "\t!db !constbyte\n", 0);
}
}
} else {
/* printIvalFuncPtr - generate initial value for function pointers */
/*-----------------------------------------------------------------*/
void
-printIvalFuncPtr (sym_link * type, initList * ilist, FILE * oFile)
+printIvalFuncPtr (sym_link * type, initList * ilist, struct dbuf_s * oBuf)
{
value *val;
int dLvl = 0;
werrorfl (ilist->filename, ilist->lineno, E_INCOMPAT_TYPES);
printFromToType (val->type, type);
}
- printIvalCharPtr (NULL, type, val, oFile);
+ printIvalCharPtr (NULL, type, val, oBuf);
return;
}
/* check the types */
if ((dLvl = compareType (val->type, type->next)) <= 0)
{
- tfprintf (oFile, "\t!dw !constword\n", 0);
+ dbuf_tprintf (oBuf, "\t!dw !constword\n", 0);
return;
}
{
if (port->use_dw_for_init)
{
- tfprintf (oFile, "\t!dws\n", val->name);
+ dbuf_tprintf (oBuf, "\t!dws\n", val->name);
}
else
{
- printPointerType (oFile, val->name);
+ printPointerType (oBuf, val->name);
}
}
else if (port->use_dw_for_init)
{
- tfprintf (oFile, "\t!dws\n", val->sym->rname);
+ dbuf_tprintf (oBuf, "\t!dws\n", val->sym->rname);
}
else
{
- printPointerType (oFile, val->sym->rname);
+ printPointerType (oBuf, val->sym->rname);
}
return;
/* printIvalCharPtr - generates initial values for character pointers */
/*-----------------------------------------------------------------*/
int
-printIvalCharPtr (symbol * sym, sym_link * type, value * val, FILE * oFile)
+printIvalCharPtr (symbol * sym, sym_link * type, value * val, struct dbuf_s * oBuf)
{
int size = 0;
{
if (size == 1) /* This appears to be Z80 specific?? */
{
- tfprintf (oFile,
+ dbuf_tprintf (oBuf,
"\t!dbs\n", val->name);
}
else if (size == FPTRSIZE)
{
if (port->use_dw_for_init)
{
- tfprintf (oFile, "\t!dws\n", val->name);
+ dbuf_tprintf (oBuf, "\t!dws\n", val->name);
}
else
{
- printPointerType (oFile, val->name);
+ printPointerType (oBuf, val->name);
}
}
else if (size == GPTRSIZE)
// this is a literal string
type=CPOINTER;
}
- printGPointerType (oFile, val->name, sym->name, type);
+ printGPointerType (oBuf, val->name, sym->name, type);
}
else
{
switch (size)
{
case 1:
- tfprintf (oFile, "\t!dbs\n", aopLiteral (val, 0));
+ dbuf_tprintf (oBuf, "\t!dbs\n", aopLiteral (val, 0));
break;
case 2:
if (port->use_dw_for_init)
- tfprintf (oFile, "\t!dws\n", aopLiteralLong (val, 0, size));
+ dbuf_tprintf (oBuf, "\t!dws\n", aopLiteralLong (val, 0, size));
else if (port->little_endian)
- tfprintf (oFile, "\t.byte %s,%s\n",
+ dbuf_tprintf (oBuf, "\t.byte %s,%s\n",
aopLiteral (val, 0), aopLiteral (val, 1));
else
- tfprintf (oFile, "\t.byte %s,%s\n",
+ dbuf_tprintf (oBuf, "\t.byte %s,%s\n",
aopLiteral (val, 1), aopLiteral (val, 0));
break;
case 3:
werrorfl (sym->fileDef, sym->lineDef, E_LITERAL_GENERIC);
}
if (port->little_endian) {
- fprintf (oFile, "\t.byte %s,%s,%s\n",
+ dbuf_printf (oBuf, "\t.byte %s,%s,%s\n",
aopLiteral (val, 0),
aopLiteral (val, 1),
aopLiteral (val, 2));
} else {
- fprintf (oFile, "\t.byte %s,%s,%s\n",
+ dbuf_printf (oBuf, "\t.byte %s,%s,%s\n",
aopLiteral (val, 2),
aopLiteral (val, 1),
aopLiteral (val, 0));
werrorfl (sym->fileDef, sym->lineDef, E_LITERAL_GENERIC);
}
if (port->little_endian) {
- fprintf (oFile, "\t.byte %s,%s,%s,%s\n",
+ dbuf_printf (oBuf, "\t.byte %s,%s,%s,%s\n",
aopLiteral (val, 0),
aopLiteral (val, 1),
aopLiteral (val, 2),
aopLiteral (val, 3));
} else {
- fprintf (oFile, "\t.byte %s,%s,%s,%s\n",
+ dbuf_printf (oBuf, "\t.byte %s,%s,%s,%s\n",
aopLiteral (val, 3),
aopLiteral (val, 2),
aopLiteral (val, 1),
/* printIvalPtr - generates initial value for pointers */
/*-----------------------------------------------------------------*/
void
-printIvalPtr (symbol * sym, sym_link * type, initList * ilist, FILE * oFile)
+printIvalPtr (symbol * sym, sym_link * type, initList * ilist, struct dbuf_s * oBuf)
{
value *val;
int size;
/* function pointer */
if (IS_FUNC (type->next))
{
- printIvalFuncPtr (type, ilist, oFile);
+ printIvalFuncPtr (type, ilist, oBuf);
return;
}
/* if character pointer */
if (IS_CHAR (type->next))
- if (printIvalCharPtr (sym, type, val, oFile))
+ if (printIvalCharPtr (sym, type, val, oBuf))
return;
/* check the type */
switch (getSize (type))
{
case 1:
- tfprintf (oFile, "\t!db !constbyte\n", (unsigned int) floatFromVal (val) & 0xff);
+ dbuf_tprintf (oBuf, "\t!db !constbyte\n", (unsigned int) floatFromVal (val) & 0xff);
break;
case 2:
if (port->use_dw_for_init)
- tfprintf (oFile, "\t!dws\n", aopLiteralLong (val, 0, 2));
+ dbuf_tprintf (oBuf, "\t!dws\n", aopLiteralLong (val, 0, 2));
else if (port->little_endian)
- tfprintf (oFile, "\t.byte %s,%s\n", aopLiteral (val, 0), aopLiteral (val, 1));
+ dbuf_tprintf (oBuf, "\t.byte %s,%s\n", aopLiteral (val, 0), aopLiteral (val, 1));
else
- tfprintf (oFile, "\t.byte %s,%s\n", aopLiteral (val, 1), aopLiteral (val, 0));
+ dbuf_tprintf (oBuf, "\t.byte %s,%s\n", aopLiteral (val, 1), aopLiteral (val, 0));
break;
case 3: // how about '390??
- fprintf (oFile, "; generic printIvalPtr\n");
+ dbuf_printf (oBuf, "; generic printIvalPtr\n");
if (port->little_endian)
{
- fprintf (oFile, "\t.byte %s,%s",
+ dbuf_printf (oBuf, "\t.byte %s,%s",
aopLiteral (val, 0), aopLiteral (val, 1));
}
else
{
- fprintf (oFile, "\t.byte %s,%s",
+ dbuf_printf (oBuf, "\t.byte %s,%s",
aopLiteral (val, 1), aopLiteral (val, 0));
}
if (IS_GENPTR (val->type))
- fprintf (oFile, ",%s\n", aopLiteral (val, 2));
+ dbuf_printf (oBuf, ",%s\n", aopLiteral (val, 2));
else if (IS_PTR (val->type))
- fprintf (oFile, ",#%x\n", pointerTypeToGPByte (DCL_TYPE (val->type), NULL, NULL));
+ dbuf_printf (oBuf, ",#%x\n", pointerTypeToGPByte (DCL_TYPE (val->type), NULL, NULL));
else
- fprintf (oFile, ",%s\n", aopLiteral (val, 2));
+ dbuf_printf (oBuf, ",%s\n", aopLiteral (val, 2));
}
return;
}
if (size == 1) /* Z80 specific?? */
{
- tfprintf (oFile, "\t!dbs\n", val->name);
+ dbuf_tprintf (oBuf, "\t!dbs\n", val->name);
}
else if (size == FPTRSIZE)
{
if (port->use_dw_for_init) {
- tfprintf (oFile, "\t!dws\n", val->name);
+ dbuf_tprintf (oBuf, "\t!dws\n", val->name);
} else {
- printPointerType (oFile, val->name);
+ printPointerType (oBuf, val->name);
}
}
else if (size == GPTRSIZE)
{
- printGPointerType (oFile, val->name, sym->name,
+ printGPointerType (oBuf, val->name, sym->name,
(IS_PTR (val->type) ? DCL_TYPE (val->type) :
PTR_TYPE (SPEC_OCLS (val->etype))));
}
/* printIval - generates code for initial value */
/*-----------------------------------------------------------------*/
void
-printIval (symbol * sym, sym_link * type, initList * ilist, FILE * oFile)
+printIval (symbol * sym, sym_link * type, initList * ilist, struct dbuf_s * oBuf)
{
sym_link *itype;
/* if structure then */
if (IS_STRUCT (type))
{
- printIvalStruct (sym, type, ilist, oFile);
+ printIvalStruct (sym, type, ilist, oBuf);
return;
}
/* if this is an array */
if (IS_ARRAY (type))
{
- printIvalArray (sym, type, ilist, oFile);
+ printIvalArray (sym, type, ilist, oBuf);
return;
}
/* if this is a pointer */
if (IS_PTR (type))
{
- printIvalPtr (sym, type, ilist, oFile);
+ printIvalPtr (sym, type, ilist, oBuf);
return;
}
/* if type is SPECIFIER */
if (IS_SPEC (type))
{
- printIvalType (sym, type, ilist, oFile);
+ printIvalType (sym, type, ilist, oBuf);
return;
}
}
/* emitStaticSeg - emitcode for the static segment */
/*-----------------------------------------------------------------*/
void
-emitStaticSeg (memmap * map, FILE * out)
+emitStaticSeg (memmap * map, struct dbuf_s * oBuf)
{
symbol *sym;
if (!sym->level)
{ /* global */
if (IS_STATIC (sym->etype))
- fprintf (out, "F%s$", moduleName); /* scope is file */
+ dbuf_printf (oBuf, "F%s$", moduleName); /* scope is file */
else
- fprintf (out, "G$"); /* scope is global */
+ dbuf_printf (oBuf, "G$"); /* scope is global */
}
else
/* symbol is local */
- fprintf (out, "L%s$",
+ dbuf_printf (oBuf, "L%s$",
(sym->localof ? sym->localof->name : "-null-"));
- fprintf (out, "%s$%d$%d", sym->name, sym->level, sym->block);
+ dbuf_printf (oBuf, "%s$%d$%d", sym->name, sym->level, sym->block);
}
/* if it has an absolute address and no initializer */
if (SPEC_ABSA (sym->etype) && !sym->ival)
{
if (options.debug)
- fprintf (out, " == 0x%04x\n", SPEC_ADDR (sym->etype));
+ dbuf_printf (oBuf, " == 0x%04x\n", SPEC_ADDR (sym->etype));
- fprintf (out, "%s\t=\t0x%04x\n",
+ dbuf_printf (oBuf, "%s\t=\t0x%04x\n",
sym->rname,
SPEC_ADDR (sym->etype));
}
else
{
if (options.debug)
- fprintf (out, " == .\n");
+ dbuf_printf (oBuf, " == .\n");
/* if it has an initial value */
if (sym->ival)
{
if (SPEC_ABSA (sym->etype))
{
- tfprintf (out, "\t!org\n", SPEC_ADDR (sym->etype));
+ dbuf_tprintf (oBuf, "\t!org\n", SPEC_ADDR (sym->etype));
}
- fprintf (out, "%s:\n", sym->rname);
+ dbuf_printf (oBuf, "%s:\n", sym->rname);
noAlloc++;
resolveIvalSym (sym->ival, sym->type);
- printIval (sym, sym->type, sym->ival, out);
+ printIval (sym, sym->type, sym->ival, oBuf);
noAlloc--;
/* if sym is a simple string and sym->ival is a string,
WE don't need it anymore */
if (size==0) {
werrorfl (sym->fileDef, sym->lineDef, E_UNKNOWN_SIZE,sym->name);
}
- fprintf (out, "%s:\n", sym->rname);
+ dbuf_printf (oBuf, "%s:\n", sym->rname);
/* special case for character strings */
if (IS_ARRAY (sym->type) && IS_CHAR (sym->type->next) &&
SPEC_CVAL (sym->etype).v_char)
- printChar (out,
+ printChar (oBuf,
SPEC_CVAL (sym->etype).v_char,
size);
else
- tfprintf (out, "\t!ds\n", (unsigned int) size & 0xffff);
+ dbuf_tprintf (oBuf, "\t!ds\n", (unsigned int) size & 0xffff);
}
}
}
emitRegularMap (code, TRUE, FALSE);
if (options.const_seg) {
- tfprintf (code->oFile, "\t!area\n", options.const_seg);
+ dbuf_tprintf (&code->oBuf, "\t!area\n", options.const_seg);
}
- emitStaticSeg (statsg, code->oFile);
+ emitStaticSeg (statsg, &code->oBuf);
if (port->genXINIT) {
- tfprintf (code->oFile, "\t!area\n", xinit->sname);
- emitStaticSeg (xinit, code->oFile);
+ dbuf_tprintf (&code->oBuf, "\t!area\n", xinit->sname);
+ emitStaticSeg (xinit, &code->oBuf);
}
- tfprintf (code->oFile, "\t!area\n", c_abs->sname);
- emitStaticSeg (c_abs, code->oFile);
+ dbuf_tprintf (&code->oBuf, "\t!area\n", c_abs->sname);
+ emitStaticSeg (c_abs, &code->oBuf);
inInitMode--;
}
void
flushStatics (void)
{
- emitStaticSeg (statsg, codeOutFile);
+ emitStaticSeg (statsg, codeOutBuf);
statsg->syms = NULL;
}
/* createInterruptVect - creates the interrupt vector */
/*-----------------------------------------------------------------*/
void
-createInterruptVect (FILE * vFile)
+createInterruptVect (struct dbuf_s *vBuf)
{
mainf = newSymbol ("main", 0);
mainf->block = 0;
return;
}
- tfprintf (vFile, "\t!areacode\n", HOME_NAME);
- fprintf (vFile, "__interrupt_vect:\n");
+ dbuf_tprintf (vBuf, "\t!areacode\n", HOME_NAME);
+ dbuf_printf (vBuf, "__interrupt_vect:\n");
- if (!port->genIVT || !(port->genIVT (vFile, interrupts, maxInterrupts)))
+ if (!port->genIVT || !(port->genIVT (vBuf, interrupts, maxInterrupts)))
{
/* There's no such thing as a "generic" interrupt table header. */
wassert(0);
/* emitOverlay - will emit code for the overlay stuff */
/*-----------------------------------------------------------------*/
static void
-emitOverlay (FILE * afile)
+emitOverlay (struct dbuf_s * aBuf)
{
set *ovrset;
if (!elementsInSet (ovrSetSets))
- tfprintf (afile, "\t!area\n", port->mem.overlay_name);
+ dbuf_tprintf (aBuf, "\t!area\n", port->mem.overlay_name);
/* for each of the sets in the overlay segment do */
for (ovrset = setFirstItem (ovrSetSets); ovrset;
if (elementsInSet (ovrset))
{
/* output the area informtion */
- fprintf (afile, "\t.area\t%s\n", port->mem.overlay_name); /* MOF */
+ dbuf_printf (aBuf, "\t.area\t%s\n", port->mem.overlay_name); /* MOF */
}
for (sym = setFirstItem (ovrset); sym;
if (!sym->level)
{ /* global */
if (IS_STATIC (sym->etype))
- fprintf (afile, "F%s$", moduleName); /* scope is file */
+ dbuf_printf (aBuf, "F%s$", moduleName); /* scope is file */
else
- fprintf (afile, "G$"); /* scope is global */
+ dbuf_printf (aBuf, "G$"); /* scope is global */
}
else
/* symbol is local */
- fprintf (afile, "L%s$",
+ dbuf_printf (aBuf, "L%s$",
(sym->localof ? sym->localof->name : "-null-"));
- fprintf (afile, "%s$%d$%d", sym->name, sym->level, sym->block);
+ dbuf_printf (aBuf, "%s$%d$%d", sym->name, sym->level, sym->block);
}
/* if is has an absolute address then generate
{
if (options.debug)
- fprintf (afile, " == 0x%04x\n", SPEC_ADDR (sym->etype));
+ dbuf_printf (aBuf, " == 0x%04x\n", SPEC_ADDR (sym->etype));
- fprintf (afile, "%s\t=\t0x%04x\n",
+ dbuf_printf (aBuf, "%s\t=\t0x%04x\n",
sym->rname,
SPEC_ADDR (sym->etype));
}
werrorfl (sym->fileDef, sym->lineDef, E_UNKNOWN_SIZE);
}
if (options.debug)
- fprintf (afile, "==.\n");
+ dbuf_printf (aBuf, "==.\n");
/* allocate space */
- tfprintf (afile, "!labeldef\n", sym->rname);
- tfprintf (afile, "\t!ds\n", (unsigned int) getSize (sym->type) & 0xffff);
+ dbuf_tprintf (aBuf, "!labeldef\n", sym->rname);
+ dbuf_tprintf (aBuf, "\t!ds\n", (unsigned int) getSize (sym->type) & 0xffff);
}
}
void
glue (void)
{
- FILE *vFile;
+ struct dbuf_s vBuf;
+ struct dbuf_s ovrBuf;
FILE *asmFile;
- FILE *ovrFile = tempfile ();
char moduleBuf[PATH_MAX];
int mcs51_like;
+ dbuf_init(&vBuf, 4096);
+ dbuf_init(&ovrBuf, 4096);
+
if(port->general.glue_up_main &&
(TARGET_IS_MCS51 || TARGET_IS_DS390 || TARGET_IS_XA51 || TARGET_IS_DS400))
{
mcs51_like=0;
}
- addSetHead (&tmpfileSet, ovrFile);
/* print the global struct definitions */
if (options.debug)
cdbStructBlock (0);
- vFile = tempfile ();
/* PENDING: this isn't the best place but it will do */
if (port->general.glue_up_main)
{
/* create the interrupt vector table */
- createInterruptVect (vFile);
+ createInterruptVect (&vBuf);
}
- addSetHead (&tmpfileSet, vFile);
-
/* emit code for the all the variables declared */
emitMaps ();
/* do the overlay segments */
- emitOverlay (ovrFile);
+ emitOverlay (&ovrBuf);
outputDebugSymbols();
fprintf (asmFile, "%s", iComments2);
fprintf (asmFile, "; special function registers\n");
fprintf (asmFile, "%s", iComments2);
- copyFile (asmFile, sfr->oFile);
+ dbuf_write_and_destroy (&sfr->oBuf, asmFile);
}
if(mcs51_like)
fprintf (asmFile, "%s", iComments2);
fprintf (asmFile, "; special function bits\n");
fprintf (asmFile, "%s", iComments2);
- copyFile (asmFile, sfrbit->oFile);
-
+ dbuf_write_and_destroy (&sfrbit->oBuf, asmFile);
+
/*JCF: Create the areas for the register banks*/
if(RegBankUsed[0]||RegBankUsed[1]||RegBankUsed[2]||RegBankUsed[3])
{
fprintf (asmFile, "%s", iComments2);
fprintf (asmFile, "; %s ram data\n", mcs51_like?"internal":"");
fprintf (asmFile, "%s", iComments2);
- copyFile (asmFile, data->oFile);
+ dbuf_write_and_destroy (&data->oBuf, asmFile);
/* create the overlay segments */
fprintf (asmFile, "%s", iComments2);
fprintf (asmFile, "; overlayable items in %s ram \n", mcs51_like?"internal":"");
fprintf (asmFile, "%s", iComments2);
- copyFile (asmFile, ovrFile);
+ dbuf_write_and_destroy (&ovrBuf, asmFile);
}
/* create the stack segment MOF */
fprintf (asmFile, "%s", iComments2);
fprintf (asmFile, "; indirectly addressable internal ram data\n");
fprintf (asmFile, "%s", iComments2);
- copyFile (asmFile, idata->oFile);
+ dbuf_write_and_destroy (&idata->oBuf, asmFile);
}
/* create the absolute idata/data segment */
fprintf (asmFile, "%s", iComments2);
fprintf (asmFile, "; absolute internal ram data\n");
fprintf (asmFile, "%s", iComments2);
- copyFile (asmFile, d_abs->oFile);
- copyFile (asmFile, i_abs->oFile);
+ dbuf_write_and_destroy (&d_abs->oBuf, asmFile);
+ dbuf_write_and_destroy (&i_abs->oBuf, asmFile);
}
/* copy the bit segment */
fprintf (asmFile, "%s", iComments2);
fprintf (asmFile, "; bit data\n");
fprintf (asmFile, "%s", iComments2);
- copyFile (asmFile, bit->oFile);
+ dbuf_write_and_destroy (&bit->oBuf, asmFile);
}
/* copy paged external ram data */
fprintf (asmFile, "%s", iComments2);
fprintf (asmFile, "; paged external ram data\n");
fprintf (asmFile, "%s", iComments2);
- copyFile (asmFile, pdata->oFile);
+ dbuf_write_and_destroy (&pdata->oBuf, asmFile);
}
/* if external stack then reserve space for it */
fprintf (asmFile, "%s", iComments2);
fprintf (asmFile, "; external ram data\n");
fprintf (asmFile, "%s", iComments2);
- copyFile (asmFile, xdata->oFile);
+ dbuf_write_and_destroy (&xdata->oBuf, asmFile);
}
/* copy external initialized ram data */
fprintf (asmFile, "%s", iComments2);
fprintf (asmFile, "; external initialized ram data\n");
fprintf (asmFile, "%s", iComments2);
- copyFile (asmFile, xidata->oFile);
+ dbuf_write_and_destroy (&xidata->oBuf, asmFile);
/* If the port wants to generate any extra areas, let it do so. */
if (port->extraAreas.genExtraAreaDeclaration)
fprintf (asmFile, "%s", iComments2);
fprintf (asmFile, "; interrupt vector \n");
fprintf (asmFile, "%s", iComments2);
- copyFile (asmFile, vFile);
+ dbuf_write_and_destroy (&vBuf, asmFile);
}
/* copy global & static initialisations */
}
}
- copyFile (asmFile, statsg->oFile);
+ dbuf_write_and_destroy (&statsg->oBuf, asmFile);
if (port->general.glue_up_main && mainf && IFFUNC_HASBODY(mainf->type))
{
"; Home\n"
"%s", iComments2, iComments2);
tfprintf (asmFile, "\t!areahome\n", HOME_NAME);
- copyFile (asmFile, home->oFile);
+ dbuf_write_and_destroy (&home->oBuf, asmFile);
if (mainf && IFFUNC_HASBODY(mainf->type))
{
fprintf (asmFile, "; code\n");
fprintf (asmFile, "%s", iComments2);
tfprintf (asmFile, "\t!areacode\n", options.code_seg);
- copyFile (asmFile, code->oFile);
+ dbuf_write_and_destroy (&code->oBuf, asmFile);
if (port->genAssemblerEnd) {
port->genAssemblerEnd(asmFile);
}
fclose (asmFile);
-
- rm_tmpfiles ();
-}
-
-
-/** Creates a temporary file with unique file name
- Scans, in order:
- - TMP, TEMP, TMPDIR env. variables
- - if Un*x system: /tmp and /var/tmp
- - root directory using mkstemp() if available
- - default location using tempnam()
-*/
-static int
-tempfileandname(char *fname, size_t len)
-{
-#define TEMPLATE "sdccXXXXXX"
-#define TEMPLATE_LEN ((sizeof TEMPLATE) - 1)
-
- const char *tmpdir = NULL;
- int fd;
-
- if ((tmpdir = getenv ("TMP")) == NULL)
- if ((tmpdir = getenv ("TEMP")) == NULL)
- tmpdir = getenv ("TMPDIR");
-
-#if defined(_WIN32)
- {
- static int warning_emitted;
-
- if (tmpdir == NULL)
- {
- tmpdir = "c:\\";
- if (!warning_emitted)
- {
- fprintf (stderr, "TMP not defined in environment, using %s for temporary files\n.", tmpdir);
- warning_emitted = 1;
- }
- }
- }
-#else
- {
- /* try with /tmp and /var/tmp on Un*x systems */
- struct stat statbuf;
-
- if (tmpdir == NULL) {
- if (stat("/tmp", &statbuf) != -1)
- tmpdir = "/tmp";
- else if (stat("/var/tmp", &statbuf) != -1)
- tmpdir = "/var/tmp";
- }
- }
-#endif
-
-#ifdef HAVE_MKSTEMP
- {
- char fnamebuf[PATH_MAX];
- size_t name_len;
-
- if (fname == NULL || len == 0) {
- fname = fnamebuf;
- len = sizeof fnamebuf;
- }
-
- if (tmpdir) {
- name_len = strlen(tmpdir) + 1 + TEMPLATE_LEN;
-
- assert(name_len < len);
- if (!(name_len < len)) /* in NDEBUG is defined */
- return -1; /* buffer too small, temporary file can not be created */
-
- sprintf(fname, "%s" DIR_SEPARATOR_STRING TEMPLATE, tmpdir);
- }
- else {
- name_len = TEMPLATE_LEN;
-
- assert(name_len < len);
- if (!(name_len < len)) /* in NDEBUG is defined */
- return -1; /* buffer too small, temporary file can not be created */
-
- strcpy(fname, TEMPLATE);
- }
-
- fd = mkstemp(fname);
- }
-#else
- {
- char *name = tempnam(tmpdir, "sdcc");
-
- if (name == NULL) {
- perror("Can't create temporary file name");
- exit(1);
- }
-
- assert(strlen(name) < len);
- if (!(strlen(name) < len)) /* in NDEBUG is defined */
- return -1; /* buffer too small, temporary file can not be created */
-
- strcpy(fname, name);
-#ifdef _WIN32
- fd = open(name, O_CREAT | O_EXCL | O_RDWR, S_IREAD | S_IWRITE);
-#else
- fd = open(name, O_CREAT | O_EXCL | O_RDWR, S_IRUSR | S_IWUSR);
-#endif
- }
-#endif
-
- if (fd == -1) {
- perror("Can't create temporary file");
- exit(1);
- }
-
- return fd;
-}
-
-
-/** Create a temporary file name
-*/
-char *
-tempfilename(void)
-{
- int fd;
- static char fnamebuf[PATH_MAX];
-
- if ((fd = tempfileandname(fnamebuf, sizeof fnamebuf)) == -1) {
- fprintf(stderr, "Can't create temporary file name!");
- exit(1);
- }
-
- fd = close(fd);
- assert(fd != -1);
-
- return fnamebuf;
-}
-
-
-/** Create a temporary file and add it to tmpfileNameSet,
- so that it is removed explicitly by rm_tmpfiles()
- or implicitly at program extit.
-*/
-FILE *
-tempfile(void)
-{
- int fd;
- char *tmp;
- FILE *fp;
- char fnamebuf[PATH_MAX];
-
- if ((fd = tempfileandname(fnamebuf, sizeof fnamebuf)) == -1) {
- fprintf(stderr, "Can't create temporary file!");
- exit(1);
- }
-
- tmp = Safe_strdup(fnamebuf);
- if (tmp)
- addSetHead(&tmpfileNameSet, tmp);
-
- if ((fp = fdopen(fd, "w+b")) == NULL) {
- perror("Can't create temporary file!");
- exit(1);
- }
-
- return fp;
}
This is needed in gen.c of z80 port */
char *aopLiteral (value *, int);
void flushStatics (void);
-int printIvalCharPtr (symbol *, sym_link *, value *, FILE *);
+int printIvalCharPtr (symbol *, sym_link *, value *, struct dbuf_s *);
extern symbol *interrupts[];
extern set *publics;
-extern set *tmpfileSet;
-extern set *pipeSet;
-extern set *tmpfileNameSet;
-void rm_tmpfiles (void);
int pointerTypeToGPByte (const int p_type, const char *iname, const char *oname);
#endif
#include "common.h"
#include "newalloc.h"
#include "math.h"
+#include "dbuf_string.h"
/*-----------------------------------------------------------------*/
/* global variables */
void setOClass (sym_link * ptr, sym_link * spec);
static operand *geniCodeCast (sym_link *, operand *, bool);
-#define PRINTFUNC(x) void x (FILE *of, iCode *ic, char *s)
+#define PRINTFUNC(x) void x (struct dbuf_s *dbuf, iCode *ic, char *s)
/* forward definition of ic print functions */
PRINTFUNC (picGetValueAtAddr);
PRINTFUNC (picSetValueAtAddr);
int
printOperand (operand * op, FILE * file)
{
- sym_link *opetype;
+ struct dbuf_s dbuf;
+ int ret;
int pnl = 0;
- if (!op)
- return 1;
-
if (!file)
{
file = stdout;
pnl = 1;
}
+ dbuf_init (&dbuf, 1024);
+ ret = dbuf_printOperand(op, &dbuf);
+ dbuf_write_and_destroy (&dbuf, file);
+
+ if (pnl)
+ putc ('\n', file);
+
+ return ret;
+}
+
+int
+dbuf_printOperand (operand * op, struct dbuf_s *dbuf)
+{
+ sym_link *opetype;
+
+ if (!op)
+ return 1;
+
switch (op->type)
{
case VALUE:
opetype = getSpec (operandType (op));
if (IS_FLOAT (opetype))
- fprintf (file, "%g {", SPEC_CVAL (opetype).v_float);
+ dbuf_printf (dbuf, "%g {", SPEC_CVAL (opetype).v_float);
else if (IS_FIXED16X16 (opetype))
- fprintf (file, "%g {", doubleFromFixed16x16(SPEC_CVAL (opetype).v_fixed16x16));
+ dbuf_printf (dbuf, "%g {", doubleFromFixed16x16(SPEC_CVAL (opetype).v_fixed16x16));
else
- fprintf (file, "0x%x {", (unsigned) floatFromVal (op->operand.valOperand));
- printTypeChain (operandType (op), file);
- fprintf (file, "}");
+ dbuf_printf (dbuf, "0x%x {", (unsigned) floatFromVal (op->operand.valOperand));
+ dbuf_printTypeChain (operandType (op), dbuf);
+ dbuf_append_char (dbuf, '}');
break;
case SYMBOL:
#define REGA 1
//#if REGA /* { */
if(REGA && !getenv("PRINT_SHORT_OPERANDS")) {
- fprintf (file, "%s [k%d lr%d:%d so:%d]{ ia%d a2p%d re%d rm%d nos%d ru%d dp%d}", /*{ar%d rm%d ru%d p%d a%d u%d i%d au%d k%d ks%d}" , */
+ dbuf_printf (dbuf, "%s [k%d lr%d:%d so:%d]{ ia%d a2p%d re%d rm%d nos%d ru%d dp%d}", /*{ar%d rm%d ru%d p%d a%d u%d i%d au%d k%d ks%d}" , */
(OP_SYMBOL (op)->rname[0] ? OP_SYMBOL (op)->rname : OP_SYMBOL (op)->name),
op->key,
OP_LIVEFROM (op), OP_LIVETO (op),
OP_SYMBOL(op)->ruonly,OP_SYMBOL(op)->dptr
);
{
- fprintf (file, "{");
- printTypeChain (operandType (op), file);
+ dbuf_append_char (dbuf, '{');
+ dbuf_printTypeChain (operandType (op), dbuf);
if (SPIL_LOC (op) && IS_ITEMP (op))
- fprintf (file, "}{ sir@ %s", SPIL_LOC (op)->rname);
- fprintf (file, "}");
+ dbuf_printf (dbuf, "}{ sir@ %s", SPIL_LOC (op)->rname);
+ dbuf_append_char (dbuf, '}');
}
{
if (!OP_SYMBOL (op)->remat)
if (OP_SYMBOL (op)->usl.spillLoc)
- fprintf (file, "[%s]", (OP_SYMBOL (op)->usl.spillLoc->rname[0] ?
+ dbuf_printf (dbuf, "[%s]", (OP_SYMBOL (op)->usl.spillLoc->rname[0] ?
OP_SYMBOL (op)->usl.spillLoc->rname :
OP_SYMBOL (op)->usl.spillLoc->name));
else
- fprintf (file, "[err]");
+ dbuf_append_str (dbuf, "[err]");
else
- fprintf (file, "[remat]");
+ dbuf_append_str (dbuf, "[remat]");
}
else
{
int i;
- fprintf (file, "[");
+ dbuf_append_char (dbuf, '[');
for (i = 0; i < OP_SYMBOL (op)->nRegs; i++)
- fprintf (file, "%s ", port->getRegName (OP_SYMBOL (op)->regs[i]));
- fprintf (file, "]");
+ dbuf_printf (dbuf, "%s ", port->getRegName (OP_SYMBOL (op)->regs[i]));
+ dbuf_append_char (dbuf, ']');
}
}
//#else /* } else { */
} else {
/* (getenv("PRINT_SHORT_OPERANDS") != NULL) */
- fprintf (file, "%s ", (OP_SYMBOL (op)->rname[0] ? OP_SYMBOL (op)->rname : OP_SYMBOL (op)->name));
+ dbuf_printf (dbuf, "%s ", (OP_SYMBOL (op)->rname[0] ? OP_SYMBOL (op)->rname : OP_SYMBOL (op)->name));
if(getenv("PRINT_SHORT_OPERANDS")[0] < '1')
{
- fprintf (file, "[lr%d:%d so:%d]",
+ dbuf_printf (dbuf, "[lr%d:%d so:%d]",
OP_LIVEFROM (op), OP_LIVETO (op),
OP_SYMBOL (op)->stack);
}
if(getenv("PRINT_SHORT_OPERANDS")[0] < '2')
{
- fprintf (file, "{");
- printTypeChain (operandType (op), file);
+ dbuf_append_char (dbuf, '{');
+ dbuf_printTypeChain (operandType (op), dbuf);
if (SPIL_LOC (op) && IS_ITEMP (op))
- fprintf (file, "}{ sir@ %s", SPIL_LOC (op)->rname);
- fprintf (file, "}");
+ dbuf_printf (dbuf, "}{ sir@ %s", SPIL_LOC (op)->rname);
+ dbuf_append_char (dbuf, '}');
}
/* if assigned to registers */
{
if (!OP_SYMBOL (op)->remat)
if (OP_SYMBOL (op)->usl.spillLoc)
- fprintf (file, "[%s]", (OP_SYMBOL (op)->usl.spillLoc->rname[0] ?
+ dbuf_printf (dbuf, "[%s]", (OP_SYMBOL (op)->usl.spillLoc->rname[0] ?
OP_SYMBOL (op)->usl.spillLoc->rname :
OP_SYMBOL (op)->usl.spillLoc->name));
else
- fprintf (file, "[err]");
+ dbuf_append_str (dbuf, "[err]");
else
- fprintf (file, "[remat]");
+ dbuf_append_str (dbuf, "[remat]");
}
else
{
int i;
- fprintf (file, "[");
+ dbuf_append_char (dbuf, '[');
for (i = 0; i < OP_SYMBOL (op)->nRegs; i++)
- fprintf (file, "%s ", port->getRegName (OP_SYMBOL (op)->regs[i]));
- fprintf (file, "]");
+ dbuf_printf (dbuf, "%s ", port->getRegName (OP_SYMBOL (op)->regs[i]));
+ dbuf_append_char (dbuf, ']');
}
}
//#endif /* } */
break;
case TYPE:
- fprintf (file, "(");
- printTypeChain (op->operand.typeOperand, file);
- fprintf (file, ")");
+ dbuf_append_char (dbuf, '(');
+ dbuf_printTypeChain (op->operand.typeOperand, dbuf);
+ dbuf_append_char (dbuf, ')');
break;
}
- if (pnl)
- fprintf (file, "\n");
return 0;
}
/*-----------------------------------------------------------------*/
PRINTFUNC (picGetValueAtAddr)
{
- fprintf (of, "\t");
- printOperand (IC_RESULT (ic), of);
- fprintf (of, " = ");
- fprintf (of, "@[");
- printOperand (IC_LEFT (ic), of);
- fprintf (of, "]");
-
- fprintf (of, "\n");
+ dbuf_append_char (dbuf, '\t');
+ dbuf_printOperand (IC_RESULT (ic), dbuf);
+ dbuf_append_str (dbuf, " = ");
+ dbuf_append_str (dbuf, "@[");
+ dbuf_printOperand (IC_LEFT (ic), dbuf);
+ dbuf_append_str (dbuf, "]\n");
}
PRINTFUNC (picSetValueAtAddr)
{
- fprintf (of, "\t");
- fprintf (of, "*[");
- printOperand (IC_LEFT (ic), of);
- fprintf (of, "] = ");
- printOperand (IC_RIGHT (ic), of);
- fprintf (of, "\n");
+ dbuf_append_char (dbuf, '\t');
+ dbuf_append_str (dbuf, "*[");
+ dbuf_printOperand (IC_LEFT (ic), dbuf);
+ dbuf_append_str (dbuf, "] = ");
+ dbuf_printOperand (IC_RIGHT (ic), dbuf);
+ dbuf_append_char (dbuf, '\n');
}
PRINTFUNC (picAddrOf)
{
- fprintf (of, "\t");
- printOperand (IC_RESULT (ic), of);
+ dbuf_append_char (dbuf, '\t');
+ dbuf_printOperand (IC_RESULT (ic), dbuf);
if (IS_ITEMP (IC_LEFT (ic)))
- fprintf (of, " = ");
+ dbuf_append_str (dbuf, " = ");
else
- fprintf (of, " = &[");
- printOperand (IC_LEFT (ic), of);
+ dbuf_append_str (dbuf, " = &[");
+ dbuf_printOperand (IC_LEFT (ic), dbuf);
if (IC_RIGHT (ic))
{
if (IS_ITEMP (IC_LEFT (ic)))
- fprintf (of, " offsetAdd ");
+ dbuf_append_str (dbuf, " offsetAdd ");
else
- fprintf (of, " , ");
- printOperand (IC_RIGHT (ic), of);
+ dbuf_append_str (dbuf, " , ");
+ dbuf_printOperand (IC_RIGHT (ic), dbuf);
}
if (IS_ITEMP (IC_LEFT (ic)))
- fprintf (of, "\n");
+ dbuf_append_char (dbuf, '\n');
else
- fprintf (of, "]\n");
+ dbuf_append_str (dbuf, "]\n");
}
PRINTFUNC (picJumpTable)
{
symbol *sym;
- fprintf (of, "\t");
- fprintf (of, "%s\t", s);
- printOperand (IC_JTCOND (ic), of);
- fprintf (of, "\n");
+ dbuf_append_char (dbuf, '\t');
+ dbuf_printf (dbuf, "%s\t", s);
+ dbuf_printOperand (IC_JTCOND (ic), dbuf);
+ dbuf_append_char (dbuf, '\n');
for (sym = setFirstItem (IC_JTLABELS (ic)); sym;
sym = setNextItem (IC_JTLABELS (ic)))
- fprintf (of, "\t\t\t%s\n", sym->name);
+ dbuf_printf (dbuf, "\t\t\t%s\n", sym->name);
}
PRINTFUNC (picGeneric)
{
- fprintf (of, "\t");
- printOperand (IC_RESULT (ic), of);
- fprintf (of, " = ");
- printOperand (IC_LEFT (ic), of);
- fprintf (of, " %s ", s);
- printOperand (IC_RIGHT (ic), of);
- fprintf (of, "\n");
+ dbuf_append_char (dbuf, '\t');
+ dbuf_printOperand (IC_RESULT (ic), dbuf);
+ dbuf_append_str (dbuf, " = ");
+ dbuf_printOperand (IC_LEFT (ic), dbuf);
+ dbuf_printf (dbuf, " %s ", s);
+ dbuf_printOperand (IC_RIGHT (ic), dbuf);
+ dbuf_append_char (dbuf, '\n');
}
PRINTFUNC (picGenericOne)
{
- fprintf (of, "\t");
+ dbuf_append_char (dbuf, '\t');
if (IC_RESULT (ic))
{
- printOperand (IC_RESULT (ic), of);
- fprintf (of, " = ");
+ dbuf_printOperand (IC_RESULT (ic), dbuf);
+ dbuf_append_str (dbuf, " = ");
}
if (IC_LEFT (ic))
{
- fprintf (of, "%s ", s);
- printOperand (IC_LEFT (ic), of);
+ dbuf_printf (dbuf, "%s ", s);
+ dbuf_printOperand (IC_LEFT (ic), dbuf);
}
if (!IC_RESULT (ic) && !IC_LEFT (ic))
- fprintf (of, s);
+ dbuf_append_str (dbuf, s);
if (ic->op == SEND || ic->op == RECEIVE) {
- fprintf(of,"{argreg = %d}",ic->argreg);
+ dbuf_printf (dbuf,"{argreg = %d}",ic->argreg);
}
if (ic->op == IPUSH) {
- fprintf(of,"{parmPush = %d}",ic->parmPush);
+ dbuf_printf (dbuf,"{parmPush = %d}",ic->parmPush);
}
- fprintf (of, "\n");
+ dbuf_append_char (dbuf, '\n');
}
PRINTFUNC (picCast)
{
- fprintf (of, "\t");
- printOperand (IC_RESULT (ic), of);
- fprintf (of, " = ");
- printOperand (IC_LEFT (ic), of);
- printOperand (IC_RIGHT (ic), of);
- fprintf (of, "\n");
+ dbuf_append_char (dbuf, '\t');
+ dbuf_printOperand (IC_RESULT (ic), dbuf);
+ dbuf_append_str (dbuf, " = ");
+ dbuf_printOperand (IC_LEFT (ic), dbuf);
+ dbuf_printOperand (IC_RIGHT (ic), dbuf);
+ dbuf_append_char (dbuf, '\n');
}
PRINTFUNC (picAssign)
{
- fprintf (of, "\t");
+ dbuf_append_char (dbuf, '\t');
if (IC_RESULT (ic)->isaddr && IS_ITEMP (IC_RESULT (ic)))
- fprintf (of, "*(");
+ dbuf_append_str (dbuf, "*(");
- printOperand (IC_RESULT (ic), of);
+ dbuf_printOperand (IC_RESULT (ic), dbuf);
if (IC_RESULT (ic)->isaddr && IS_ITEMP (IC_RESULT (ic)))
- fprintf (of, ")");
+ dbuf_append_char (dbuf, ')');
- fprintf (of, " %s ", s);
- printOperand (IC_RIGHT (ic), of);
+ dbuf_printf (dbuf, " %s ", s);
+ dbuf_printOperand (IC_RIGHT (ic), dbuf);
- fprintf (of, "\n");
+ dbuf_append_char (dbuf, '\n');
}
PRINTFUNC (picLabel)
{
- fprintf (of, " %s($%d) :\n", IC_LABEL (ic)->name, IC_LABEL (ic)->key);
+ dbuf_printf (dbuf, " %s($%d) :\n", IC_LABEL (ic)->name, IC_LABEL (ic)->key);
}
PRINTFUNC (picGoto)
{
- fprintf (of, "\t");
- fprintf (of, " goto %s($%d)\n", IC_LABEL (ic)->name, IC_LABEL (ic)->key);
+ dbuf_append_char (dbuf, '\t');
+ dbuf_printf (dbuf, " goto %s($%d)\n", IC_LABEL (ic)->name, IC_LABEL (ic)->key);
}
PRINTFUNC (picIfx)
{
- fprintf (of, "\t");
- fprintf (of, "if ");
- printOperand (IC_COND (ic), of);
+ dbuf_append_char (dbuf, '\t');
+ dbuf_append_str (dbuf, "if ");
+ dbuf_printOperand (IC_COND (ic), dbuf);
if (!IC_TRUE (ic))
- fprintf (of, " == 0 goto %s($%d)\n", IC_FALSE (ic)->name, IC_FALSE (ic)->key);
+ dbuf_printf (dbuf, " == 0 goto %s($%d)\n", IC_FALSE (ic)->name, IC_FALSE (ic)->key);
else
{
- fprintf (of, " != 0 goto %s($%d)\n", IC_TRUE (ic)->name, IC_TRUE (ic)->key);
+ dbuf_printf (dbuf, " != 0 goto %s($%d)\n", IC_TRUE (ic)->name, IC_TRUE (ic)->key);
if (IC_FALSE (ic))
- fprintf (of, "\tzzgoto %s\n", IC_FALSE (ic)->name);
+ dbuf_printf (dbuf, "\tzzgoto %s\n", IC_FALSE (ic)->name);
}
}
PRINTFUNC (picInline)
{
- fprintf (of, "%s", IC_INLINE (ic));
+ dbuf_append_str (dbuf, IC_INLINE (ic));
}
PRINTFUNC (picReceive)
{
- printOperand (IC_RESULT (ic), of);
- fprintf (of, " = %s ", s);
- printOperand (IC_LEFT (ic), of);
- fprintf (of, "\n");
+ dbuf_printOperand (IC_RESULT (ic), dbuf);
+ dbuf_printf (dbuf, " = %s ", s);
+ dbuf_printOperand (IC_LEFT (ic), dbuf);
+ dbuf_append_char (dbuf, '\n');
}
PRINTFUNC (picDummyRead)
{
- fprintf (of, "\t");
- fprintf (of, "%s ", s);
- printOperand (IC_RIGHT (ic), of);
- fprintf (of, "\n");
+ dbuf_append_char (dbuf, '\t');
+ dbuf_printf (dbuf, "%s ", s);
+ dbuf_printOperand (IC_RIGHT (ic), dbuf);
+ dbuf_append_char (dbuf, '\n');
}
PRINTFUNC (picCritical)
{
- fprintf (of, "\t");
+ dbuf_append_char (dbuf, '\t');
if (IC_RESULT (ic))
- printOperand (IC_RESULT (ic), of);
+ dbuf_printOperand (IC_RESULT (ic), dbuf);
else
- fprintf (of, "(stack)");
- fprintf (of, " = %s ", s);
- fprintf (of, "\n");
+ dbuf_append_str (dbuf, "(stack)");
+ dbuf_printf (dbuf, " = %s ", s);
+ dbuf_append_char (dbuf, '\n');
}
PRINTFUNC (picEndCritical)
{
- fprintf (of, "\t");
- fprintf (of, "%s = ", s);
+ dbuf_append_char (dbuf, '\t');
+ dbuf_printf (dbuf, "%s = ", s);
if (IC_RIGHT (ic))
- printOperand (IC_RIGHT (ic), of);
+ dbuf_printOperand (IC_RIGHT (ic), dbuf);
else
- fprintf (of, "(stack)");
- fprintf (of, "\n");
+ dbuf_append_str (dbuf, "(stack)");
+ dbuf_append_char (dbuf, '\n');
}
/*-----------------------------------------------------------------*/
{
iCode *ic = item;
iCodeTable *icTab;
+ struct dbuf_s dbuf;
if (!of)
of = stdout;
fprintf (of, "%s(%d:%d:%d:%d:%d)\t",
ic->filename, ic->lineno,
ic->seq, ic->key, ic->depth, ic->supportRtn);
- icTab->iCodePrint (of, ic, icTab->printName);
+ dbuf_init (&dbuf, 1024);
+ icTab->iCodePrint (&dbuf, ic, icTab->printName);
+ dbuf_write_and_destroy (&dbuf, of);
return 1;
}
{
iCode *loop;
iCodeTable *icTab;
+ struct dbuf_s dbuf;
if (!of)
of = stdout;
loop->filename, loop->lineno,
loop->seq, loop->key, loop->depth, loop->supportRtn);
- icTab->iCodePrint (of, loop, icTab->printName);
+ dbuf_init(&dbuf, 1024);
+ icTab->iCodePrint (&dbuf, loop, icTab->printName);
+ dbuf_write_and_destroy (&dbuf, of);
}
}
}
{
int icode;
char *printName;
- void (*iCodePrint) (FILE *, iCode *, char *);
+ void (*iCodePrint) (struct dbuf_s *, iCode *, char *);
iCode *(*iCodeCopy) (iCode *);
}
iCodeTable;
sym_link *aggrToPtr (sym_link *, bool);
int aggrToPtrDclType (sym_link *, bool);
int piCode (void *, FILE *);
+int dbuf_printOperand (operand *, struct dbuf_s *);
int printOperand (operand *, FILE *);
void setOperandType (operand *, sym_link *);
bool isOperandInFarSpace (operand *);
--end;
++end;
- dbuf_init(&dbuf, 16);
-
p = src;
while (src < end)
{
+ dbuf_init(&dbuf, 16);
+
while (p < end && ',' != *p)
++p;
dbuf_append(&dbuf, src, p - src);
- addSet(dest, Safe_strdup(dbuf_c_str(&dbuf)));
- dbuf_set_size(&dbuf, 0);
+
+ /* null terminate the buffer */
+ dbuf_c_str(&dbuf);
+ addSet(dest, dbuf_detach(&dbuf));
+
src = ++p;
}
-
- dbuf_destroy(&dbuf);
}
/*-----------------------------------------------------------------*/
perror ("Preproc file not found");
exit (1);
}
- addSetHead (&pipeSet, yyin);
}
return 0;
exit (1);
}
- /* install atexit handler */
- atexit(rm_tmpfiles);
-
/* install signal handler;
it's only purpose is to call exit() to remove temp files */
if (!getenv("SDCC_LEAVE_SIGNALS"))
if (pclose(yyin))
fatalError = 1;
- deleteSetItem(&pipeSet, yyin);
if (fatalError) {
exit (1);
/*-----------------------------------------------------------------*/
#include "common.h"
+#include "dbuf_string.h"
/* memory segments */
memmap *xstack = NULL; /* xternal stack data */
map->sname = name;
map->dbName = dbName;
map->ptrType = ptrType;
- if (!(map->oFile = tempfile ()))
- {
- werror (E_TMPFILE_FAILED);
- exit (1);
- }
- addSetHead (&tmpfileSet, map->oFile);
map->syms = NULL;
+
+ dbuf_init(&map->oBuf, 4096);
+
return map;
}
/* printAllocInfoSeg- print the allocation for a given section */
/*-----------------------------------------------------------------*/
static void
-printAllocInfoSeg (memmap * map, symbol * func, FILE * of)
+printAllocInfoSeg (memmap * map, symbol * func, struct dbuf_s *oBuf)
{
symbol *sym;
if (sym->localof != func)
continue;
- fprintf (of, ";%-25s Allocated ", sym->name);
+ dbuf_printf (oBuf, ";%-25s Allocated ", sym->name);
/* if assigned to registers */
if (!sym->allocreq && sym->reqv)
sym = OP_SYMBOL (sym->reqv);
if (!sym->isspilt || sym->remat)
{
- fprintf (of, "to registers ");
+ dbuf_append_str (oBuf, "to registers ");
for (i = 0; i < 4 && sym->regs[i]; i++)
- fprintf (of, "%s ", port->getRegName (sym->regs[i]));
- fprintf (of, "\n");
+ dbuf_printf (oBuf, "%s ", port->getRegName (sym->regs[i]));
+ dbuf_append_char (oBuf, '\n');
continue;
}
else
/* if on stack */
if (sym->onStack)
{
- fprintf (of, "to stack - offset %d\n", sym->stack);
+ dbuf_printf (oBuf, "to stack - offset %d\n", sym->stack);
continue;
}
/* otherwise give rname */
- fprintf (of, "with name '%s'\n", sym->rname);
+ dbuf_printf (oBuf, "with name '%s'\n", sym->rname);
}
}
/* printAllocInfo - prints allocation information for a function */
/*-----------------------------------------------------------------*/
void
-printAllocInfo (symbol * func, FILE * of)
+printAllocInfo (symbol * func, struct dbuf_s * oBuf)
{
if (!func)
return;
- if (!of)
- of = stdout;
-
/* must be called after register allocation is complete */
- fprintf (of, ";------------------------------------------------------------\n");
- fprintf (of, ";Allocation info for local variables in function '%s'\n", func->name);
- fprintf (of, ";------------------------------------------------------------\n");
-
- printAllocInfoSeg (xstack, func, of);
- printAllocInfoSeg (istack, func, of);
- printAllocInfoSeg (code, func, of);
- printAllocInfoSeg (data, func, of);
- printAllocInfoSeg (xdata, func, of);
- printAllocInfoSeg (idata, func, of);
- printAllocInfoSeg (sfr, func, of);
- printAllocInfoSeg (sfrbit, func, of);
+ dbuf_append_str (oBuf, ";------------------------------------------------------------\n");
+ dbuf_printf (oBuf, ";Allocation info for local variables in function '%s'\n", func->name);
+ dbuf_append_str (oBuf, ";------------------------------------------------------------\n");
+
+ printAllocInfoSeg (xstack, func, oBuf);
+ printAllocInfoSeg (istack, func, oBuf);
+ printAllocInfoSeg (code, func, oBuf);
+ printAllocInfoSeg (data, func, oBuf);
+ printAllocInfoSeg (xdata, func, oBuf);
+ printAllocInfoSeg (idata, func, oBuf);
+ printAllocInfoSeg (sfr, func, oBuf);
+ printAllocInfoSeg (sfrbit, func, oBuf);
{
set *ovrset;
ovrset = setNextItem (ovrSetSets))
{
overlay->syms = ovrset;
- printAllocInfoSeg (overlay, func, of);
+ printAllocInfoSeg (overlay, func, oBuf);
}
overlay->syms = tempOverlaySyms;
}
- fprintf (of, ";------------------------------------------------------------\n");
+ dbuf_append_str (oBuf, ";------------------------------------------------------------\n");
}
#ifndef SDCCMEM_H
#define SDCCMEM_H
+#include "dbuf.h"
+
struct set;
struct value;
struct eBBlock;
unsigned bitsp:1; /* 1 = bit addressable space */
unsigned codesp:1; /* 1 = code space */
unsigned regsp:1; /* 1= sfr space */
- FILE *oFile; /* object file associated */
+ struct dbuf_s oBuf; /* object buffer associated */
struct set *syms; /* symbols defined in this segment */
}
memmap;
void overlay2Set ();
void overlay2data ();
void redoStackOffsets ();
-void printAllocInfo (struct symbol *, FILE *);
+void printAllocInfo (struct symbol *, struct dbuf_s *);
void doOverlays (struct eBBlock **, int count);
void deleteFromSeg(struct symbol *);
#endif
-------------------------------------------------------------------------*/
#include "common.h"
+#include "dbuf_string.h"
#define ISCHARDIGIT(c) isdigit((unsigned char)c)
#define ISCHARSPACE(c) isspace((unsigned char)c)
/* printLine - prints a line chain into a given file */
/*-----------------------------------------------------------------*/
void
-printLine (lineNode * head, FILE * of)
+printLine (lineNode * head, struct dbuf_s * oBuf)
{
iCode *last_ic = NULL;
bool debug_iCode_tracking = (getenv("DEBUG_ICODE_TRACKING")!=NULL);
- if (!of)
- of = stdout;
-
while (head)
{
if (head->ic!=last_ic)
if (debug_iCode_tracking)
{
if (head->ic)
- fprintf (of, "; block = %d, seq = %d\n",
+ dbuf_printf (oBuf, "; block = %d, seq = %d\n",
head->ic->block, head->ic->seq);
else
- fprintf (of, "; iCode lost\n");
+ dbuf_append_str (oBuf, "; iCode lost\n");
}
}
/* don't indent comments & labels */
if (head->line &&
(head->isComment || head->isLabel)) {
- fprintf (of, "%s\n", head->line);
+ dbuf_printf (oBuf, "%s\n", head->line);
} else {
if (head->isInline && *head->line=='#') {
// comment out preprocessor directives in inline asm
- fprintf (of, ";");
+ dbuf_append_char (oBuf, ';');
}
- fprintf (of, "\t%s\n", head->line);
+ dbuf_printf (oBuf, "\t%s\n", head->line);
}
head = head->next;
}
/* newLineNode - creates a new peep line */
/*-----------------------------------------------------------------*/
lineNode *
-newLineNode (char *line)
+newLineNode (const char *line)
{
lineNode *pl;
extern hTab *labelHash;
labelHashEntry *getLabelRef (const char *label, lineNode *head);
-void printLine (lineNode *, FILE *);
-lineNode *newLineNode (char *);
+void printLine (lineNode *, struct dbuf_s *);
+lineNode *newLineNode (const char *);
lineNode *connectLine (lineNode *, lineNode *);
void initPeepHole (void);
void peepHole (lineNode **);
#include "common.h"
#include "newalloc.h"
+#include "dbuf_string.h"
#include "SDCCsymt.h"
void
printTypeChain (sym_link * start, FILE * of)
{
+ struct dbuf_s dbuf;
int nlr = 0;
- value *args;
- sym_link * type, * search;
- STORAGE_CLASS scls;
if (!of)
{
nlr = 1;
}
+ dbuf_init (&dbuf, 1024);
+ dbuf_printTypeChain (start, &dbuf);
+ dbuf_write_and_destroy (&dbuf, of);
+
+ if (nlr)
+ putc ('\n', of);
+}
+
+void
+dbuf_printTypeChain (sym_link * start, struct dbuf_s *dbuf)
+{
+ value *args;
+ sym_link * type, * search;
+ STORAGE_CLASS scls;
+
if (start==NULL) {
- fprintf (of, "void");
+ dbuf_append_str (dbuf, "void");
return;
}
if (type==start) {
switch (scls)
{
- case S_DATA: fprintf (of, "data-"); break;
- case S_XDATA: fprintf (of, "xdata-"); break;
- case S_SFR: fprintf (of, "sfr-"); break;
- case S_SBIT: fprintf (of, "sbit-"); break;
- case S_CODE: fprintf (of, "code-"); break;
- case S_IDATA: fprintf (of, "idata-"); break;
- case S_PDATA: fprintf (of, "pdata-"); break;
- case S_LITERAL: fprintf (of, "literal-"); break;
- case S_STACK: fprintf (of, "stack-"); break;
- case S_XSTACK: fprintf (of, "xstack-"); break;
- case S_BIT: fprintf (of, "bit-"); break;
- case S_EEPROM: fprintf (of, "eeprom-"); break;
+ case S_DATA: dbuf_append_str (dbuf, "data-"); break;
+ case S_XDATA: dbuf_append_str (dbuf, "xdata-"); break;
+ case S_SFR: dbuf_append_str (dbuf, "sfr-"); break;
+ case S_SBIT: dbuf_append_str (dbuf, "sbit-"); break;
+ case S_CODE: dbuf_append_str (dbuf, "code-"); break;
+ case S_IDATA: dbuf_append_str (dbuf, "idata-"); break;
+ case S_PDATA: dbuf_append_str (dbuf, "pdata-"); break;
+ case S_LITERAL: dbuf_append_str (dbuf, "literal-"); break;
+ case S_STACK: dbuf_append_str (dbuf, "stack-"); break;
+ case S_XSTACK: dbuf_append_str (dbuf, "xstack-"); break;
+ case S_BIT: dbuf_append_str (dbuf, "bit-"); break;
+ case S_EEPROM: dbuf_append_str (dbuf, "eeprom-"); break;
default: break;
}
}
{
if (!IS_FUNC(type)) {
if (DCL_PTR_VOLATILE (type)) {
- fprintf (of, "volatile-");
+ dbuf_append_str (dbuf, "volatile-");
}
if (DCL_PTR_CONST (type)) {
- fprintf (of, "const-");
+ dbuf_append_str (dbuf, "const-");
}
}
switch (DCL_TYPE (type))
{
case FUNCTION:
- fprintf (of, "function %s %s",
+ dbuf_printf (dbuf, "function %s %s",
(IFFUNC_ISBUILTIN(type) ? "__builtin__" : " "),
(IFFUNC_ISJAVANATIVE(type) ? "_JavaNative" : " "));
- fprintf (of, "( ");
+ dbuf_append_str (dbuf, "( ");
for (args = FUNC_ARGS(type);
args;
args=args->next) {
- printTypeChain(args->type, of);
+ dbuf_printTypeChain(args->type, dbuf);
if (args->next)
- fprintf(of, ", ");
+ dbuf_append_str (dbuf, ", ");
}
- fprintf (of, ") ");
+ dbuf_append_str (dbuf, ") ");
break;
case GPOINTER:
- fprintf (of, "generic* ");
+ dbuf_append_str (dbuf, "generic* ");
break;
case CPOINTER:
- fprintf (of, "code* ");
+ dbuf_append_str (dbuf, "code* ");
break;
case FPOINTER:
- fprintf (of, "xdata* ");
+ dbuf_append_str (dbuf, "xdata* ");
break;
case EEPPOINTER:
- fprintf (of, "eeprom* ");
+ dbuf_append_str (dbuf, "eeprom* ");
break;
case POINTER:
- fprintf (of, "near* ");
+ dbuf_append_str (dbuf, "near* ");
break;
case IPOINTER:
- fprintf (of, "idata* ");
+ dbuf_append_str (dbuf, "idata* ");
break;
case PPOINTER:
- fprintf (of, "pdata* ");
+ dbuf_append_str (dbuf, "pdata* ");
break;
case UPOINTER:
- fprintf (of, "unknown* ");
+ dbuf_append_str (dbuf, "unknown* ");
break;
case ARRAY:
if (DCL_ELEM(type)) {
- fprintf (of, "[%d] ", DCL_ELEM(type));
+ dbuf_printf (dbuf, "[%d] ", DCL_ELEM(type));
} else {
- fprintf (of, "[] ");
+ dbuf_append_str (dbuf, "[] ");
}
break;
}
else
{
if (SPEC_VOLATILE (type))
- fprintf (of, "volatile-");
+ dbuf_append_str (dbuf, "volatile-");
if (SPEC_CONST (type))
- fprintf (of, "const-");
+ dbuf_append_str (dbuf, "const-");
if (SPEC_USIGN (type))
- fprintf (of, "unsigned-");
+ dbuf_append_str (dbuf, "unsigned-");
switch (SPEC_NOUN (type))
{
case V_INT:
if (IS_LONG (type))
- fprintf (of, "long-");
- fprintf (of, "int");
+ dbuf_append_str (dbuf, "long-");
+ dbuf_append_str (dbuf, "int");
break;
case V_CHAR:
- fprintf (of, "char");
+ dbuf_append_str (dbuf, "char");
break;
case V_VOID:
- fprintf (of, "void");
+ dbuf_append_str (dbuf, "void");
break;
case V_FLOAT:
- fprintf (of, "float");
+ dbuf_append_str (dbuf, "float");
break;
case V_FIXED16X16:
- fprintf (of, "fixed16x16");
+ dbuf_append_str (dbuf, "fixed16x16");
break;
case V_STRUCT:
- fprintf (of, "struct %s", SPEC_STRUCT (type)->tag);
+ dbuf_printf (dbuf, "struct %s", SPEC_STRUCT (type)->tag);
break;
case V_SBIT:
- fprintf (of, "sbit");
+ dbuf_append_str (dbuf, "sbit");
break;
case V_BIT:
- fprintf (of, "bit");
+ dbuf_append_str (dbuf, "bit");
break;
case V_BITFIELD:
- fprintf (of, "bitfield {%d,%d}", SPEC_BSTR (type), SPEC_BLEN (type));
+ dbuf_printf (dbuf, "bitfield {%d,%d}", SPEC_BSTR (type), SPEC_BLEN (type));
break;
case V_DOUBLE:
- fprintf (of, "double");
+ dbuf_append_str (dbuf, "double");
break;
default:
- fprintf (of, "unknown type");
+ dbuf_append_str (dbuf, "unknown type");
break;
}
}
search = search->next;
type = search;
if (type)
- fputc (' ', of);
+ dbuf_append_char(dbuf, ' ');
}
- if (nlr)
- fprintf (of, "\n");
}
/*--------------------------------------------------------------------*/
#define SDCC_NAME_MAX 3*SDCC_SYMNAME_MAX // big enough for _<func>_<var>_etc
#include "SDCChasht.h"
#include "SDCCglobl.h"
+#include "dbuf.h"
#define INTNO_MAX 255 /* maximum allowed interrupt number */
#define INTNO_UNSPEC (INTNO_MAX+1) /* interrupt number unspecified */
void processFuncArgs (symbol *);
int isSymbolEqual (symbol *, symbol *);
int powof2 (TYPE_TARGET_ULONG);
+void dbuf_printTypeChain (sym_link *, struct dbuf_s *);
void printTypeChain (sym_link *, FILE *);
void printTypeChainRaw (sym_link *, FILE *);
void initCSupport ();
#include "SDCCmacro.h"
#include "SDCCutil.h"
#include "newalloc.h"
+#include "dbuf_string.h"
#ifndef _WIN32
#include "findme.h"
#endif
for (item = setFirstItem(list); item != NULL; item = setNextItem(list)) {
dbuf_init(&dbuf, PATH_MAX);
+
if (pre != NULL)
- dbuf_append(&dbuf, pre, strlen(pre));
- dbuf_append(&dbuf, item, strlen(item));
+ dbuf_append_str(&dbuf, pre);
+ dbuf_append_str(&dbuf, item);
if (post != NULL)
- dbuf_append(&dbuf, post, strlen(post));
- addSet(&new_list, (void *)dbuf_c_str(&dbuf));
- dbuf_detach(&dbuf);
+ dbuf_append_str(&dbuf, post);
+
+ /* null terminate the buffer */
+ dbuf_c_str(&dbuf);
+ addSet(&new_list, dbuf_detach(&dbuf));
}
return new_list;
for (s = setFirstItem(list); s != NULL; s = setNextItem(list))
{
- dbuf_append(&dbuf, s, strlen(s));
- dbuf_append(&dbuf, " ", 1);
+ dbuf_append_str(&dbuf, s);
+ dbuf_append_char(&dbuf, ' ');
}
s = dbuf_c_str(&dbuf);
char *
get_pragma_token(const char *s, struct pragma_token_s *token)
{
- dbuf_set_size(&token->dbuf, 0);
+ dbuf_set_length(&token->dbuf, 0);
/* skip leading spaces */
while ('\n' != *s && isspace(*s))
{
while ('\0' != *s && !isspace(*s))
{
- dbuf_append(&token->dbuf, s, 1);
+ dbuf_append_char(&token->dbuf, *s);
++s;
}
*/
#include "common.h"
#include "asm.h"
+#include "dbuf_string.h"
/* A 'token' is like !blah or %24f and is under the programmers
control. */
return p;
}
-static const char *
-_findMapping (const char *szKey)
-{
- return shash_find (_h, szKey);
-}
-
-// Append a string onto another, and update the pointer to the end of
-// the new string.
-static char *
-_appendAt (char *at, char *onto, const char *sz, size_t *max)
-{
- wassert (at && onto && sz);
- strncpyz (at, sz, *max);
- *max -= strlen (at);
- return at + strlen (at);
-}
-
void
-tvsprintf (char *buffer, size_t len, const char *format, va_list ap)
+dbuf_tvprintf (struct dbuf_s *dbuf, const char *format, va_list ap)
{
// Under Linux PPC va_list is a structure instead of a primitive type,
// and doesnt like being passed around. This version turns everything
// 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 noTokens[INITIAL_INLINEASM];
- char newFormat[INITIAL_INLINEASM];
- char *pInto = noTokens;
- size_t pIntoLen = sizeof(noTokens);
- char *p;
- char token[MAX_TOKEN_LEN];
- const char *sz = format;
-
- // NULL terminate it to let strlen work.
- *pInto = '\0';
+ static int count;
+ struct dbuf_s tmpDBuf;
+ const char *noTokens;
+ char *p;
+ char token[MAX_TOKEN_LEN];
+ const char *sz = format;
+
+ dbuf_init(&tmpDBuf, INITIAL_INLINEASM);
/* First pass: expand all of the macros */
- while (pIntoLen && *sz)
+ while (*sz)
{
if (*sz == '!')
{
}
*p = '\0';
/* Now find the token in the token list */
- if ((t = _findMapping (token)))
+ if ((t = shash_find (_h, token)))
{
- pInto = _appendAt (pInto, noTokens, t, &pIntoLen);
+ dbuf_append_str(&tmpDBuf, t);
}
else
{
}
else
{
- *pInto++ = *sz++;
- pIntoLen--;
+ dbuf_append_char(&tmpDBuf, *sz++);
}
}
- if (!pIntoLen)
- {
- fprintf(stderr,
- "Internal error: tvsprintf overflowed on pass one.\n");
- // Might as well go on...
- }
-
- *pInto = '\0';
-
/* Second pass: Expand any macros that we own */
+ noTokens = dbuf_c_str(&tmpDBuf);
sz = noTokens;
- pInto = newFormat;
- pIntoLen = sizeof(newFormat);
- while (pIntoLen && *sz)
+ /* recycle tmpDBuf */
+ dbuf_init(&tmpDBuf, INITIAL_INLINEASM);
+
+ while (*sz)
{
if (*sz == '%')
{
{
case 'C':
// Code segment name.
- pInto = _appendAt (pInto, newFormat, CODE_NAME, &pIntoLen);
+ dbuf_append_str(&tmpDBuf, CODE_NAME);
sz++;
break;
+
case 'F':
// Source file name.
- pInto = _appendAt (pInto, newFormat, fullSrcFileName, &pIntoLen);
+ dbuf_append_str(&tmpDBuf, fullSrcFileName);
sz++;
break;
+
case 'N':
// Current function name.
- pInto = _appendAt (pInto, newFormat, currFunc->rname, &pIntoLen);
+ dbuf_append_str(&tmpDBuf, currFunc->rname);
sz++;
break;
+
case 'I':
- {
- // Unique ID.
- char id[20];
- SNPRINTF (id, sizeof(id), "%u", ++count);
- pInto = _appendAt (pInto, newFormat, id, &pIntoLen);
- sz++;
- break;
- }
+ // Unique ID.
+ dbuf_printf(&tmpDBuf, "%u", ++count);
+ sz++;
+ break;
+
default:
// Not one of ours. Copy until the end.
- *pInto++ = '%';
- pIntoLen--;
- while (pIntoLen && !isalpha ((unsigned char)*sz))
- {
- *pInto++ = *sz++;
- pIntoLen--;
- }
- if (pIntoLen)
- {
- *pInto++ = *sz++;
- pIntoLen--;
- }
+ dbuf_append_char(&tmpDBuf, '%');
+ while (!isalpha ((unsigned char)*sz))
+ dbuf_append_char(&tmpDBuf, *sz++);
+
+ dbuf_append_char(&tmpDBuf, *sz++);
}
}
else
{
- *pInto++ = *sz++;
- pIntoLen--;
+ dbuf_append_char(&tmpDBuf, *sz++);
}
}
- if (!pIntoLen)
- {
- fprintf(stderr,
- "Internal error: tvsprintf overflowed on pass two.\n");
- // Might as well go on...
- }
+ dbuf_free(noTokens);
- *pInto = '\0';
+ sz = dbuf_c_str(&tmpDBuf);
- // Now do the actual printing
-#if defined(HAVE_VSNPRINTF)
- {
- int wrlen;
- wrlen = vsnprintf (buffer, len, newFormat, ap);
+ dbuf_vprintf(dbuf, sz, ap);
- if (wrlen < 0 || (size_t)wrlen >= len)
- {
- fprintf(stderr, "Internal error: tvsprintf truncated.\n");
- }
- }
+ dbuf_destroy(&tmpDBuf);
+}
-#else
- vsprintf (buffer, newFormat, ap);
- if (strlen(buffer) >= len)
- {
- fprintf(stderr, "Internal error: tvsprintf overflowed.\n");
- }
-#endif
+void
+dbuf_tprintf (struct dbuf_s *dbuf, const char *szFormat,...)
+{
+ va_list ap;
+ va_start (ap, szFormat);
+ dbuf_tvprintf (dbuf, szFormat, ap);
+ va_end(ap);
}
void
-tfprintf (FILE * fp, const char *szFormat,...)
+tsprintf (char *buffer, size_t len, const char *szFormat,...)
{
va_list ap;
- char buffer[INITIAL_INLINEASM];
+ struct dbuf_s dbuf;
+ size_t copyLen;
+
+ dbuf_init(&dbuf, INITIAL_INLINEASM);
va_start (ap, szFormat);
- tvsprintf (buffer, INITIAL_INLINEASM, szFormat, ap);
+ dbuf_tvprintf (&dbuf, szFormat, ap);
va_end(ap);
- fputs (buffer, fp);
+
+ copyLen = min(len - 1, dbuf_get_length(&dbuf));
+ memcpy(buffer, dbuf_get_buf(&dbuf), copyLen);
+ buffer[copyLen] = '\0';
+ dbuf_destroy(&dbuf);
}
void
-tsprintf (char *buffer, size_t len, const char *szFormat,...)
+tfprintf (FILE *fp, const char *szFormat,...)
{
va_list ap;
+ struct dbuf_s dbuf;
+ size_t len;
+
+ dbuf_init(&dbuf, INITIAL_INLINEASM);
+
va_start (ap, szFormat);
- tvsprintf (buffer, len, szFormat, ap);
+ dbuf_tvprintf (&dbuf, szFormat, ap);
va_end(ap);
+
+ len = dbuf_get_length(&dbuf);
+ fwrite(dbuf_get_buf(&dbuf), 1, len, fp);
+ dbuf_destroy(&dbuf);
}
void
/*-----------------------------------------------------------------*/
/* printILine - return the readable i-code for this ic */
-/* */
-/* iCodePrint wants a file stream so we need a temporary file to */
-/* fool it */
/*-----------------------------------------------------------------*/
char *
printILine (iCode *ic)
{
- static char verbalICode[1024];
- FILE *tmpFile;
+ char *verbalICode;
+ struct dbuf_s tmpBuf;
iCodeTable *icTab=getTableEntry(ic->op);
- int ret;
- if (INLINEASM == ic->op)
- return "inline";
+ dbuf_init(&tmpBuf, 1024);
- tmpFile = tempfile();
- assert(NULL != tmpFile);
- if (NULL == tmpFile)
- return ""; /* return empty line if temporary file creation failed */
-
- addSetHead(&tmpfileSet, tmpFile);
-
- /* stuff the temporary file with the readable icode */
- icTab->iCodePrint(tmpFile, ic, icTab->printName);
-
- /* now swallow it */
- rewind(tmpFile);
- fgets(verbalICode, sizeof(verbalICode), tmpFile);
+ if (INLINEASM == ic->op)
+ dbuf_append (&tmpBuf, "inline", (sizeof "inline") - 1);
+ else {
+ /* stuff the temporary file with the readable icode */
+ icTab->iCodePrint(&tmpBuf, ic, icTab->printName);
+ }
- /* clean up the mess, we'll return here for all icodes!!
- * Actually the temporary file is only closed. It will be
- * removed by rm_tmpfiles().
- */
- ret = fclose(tmpFile);
- assert(!ret);
- deleteSetItem(&tmpfileSet, tmpFile);
+ /* null terminate the buffer */
+ dbuf_c_str(&tmpBuf);
+ verbalICode = dbuf_detach(&tmpBuf);
/* kill the trailing NL */
if ('\n' == verbalICode[strlen(verbalICode) - 1])
#ifndef ASM_PORT_INCLUDE
#define ASM_PORT_INCLUDE
+#include "dbuf.h"
+
void tfprintf (FILE * fp, const char *szFormat, ...);
void tsprintf (char *buffer, size_t len, const char *szFormat, ...);
-void tvsprintf (char *buffer, size_t len, const char *szFormat, va_list ap);
+void dbuf_tprintf (struct dbuf_s *dbuf, const char *szFormat, ...);
+void dbuf_tvprintf (struct dbuf_s *dbuf, const char *szFormat, va_list ap);
typedef struct
{
extern int avr_ptrRegReq;
extern int avr_nRegs;
-extern FILE *codeOutFile;
+extern struct dbuf_s *codeOutBuf;
#define RESULTONSTACK(x) \
(IC_RESULT(x) && IC_RESULT(x)->aop && \
IC_RESULT(x)->aop->type == AOP_STK )
recvCnt = 0;
/* print the allocation information */
if (allocInfo)
- printAllocInfo (currFunc, codeOutFile);
+ printAllocInfo (currFunc, codeOutBuf);
/* if debug information required */
if (options.debug && currFunc) {
debugFile->writeFunction (currFunc, lic);
peepHole (&lineHead);
/* now do the actual printing */
- printLine (lineHead, codeOutFile);
+ printLine (lineHead, codeOutBuf);
return;
}
/* Generate interrupt vector table. */
static int
-_avr_genIVT (FILE * of, symbol ** interrupts, int maxInterrupts)
+_avr_genIVT (struct dbuf_s * oBuf, symbol ** interrupts, int maxInterrupts)
{
- return TRUE;
+ return TRUE;
}
/* Indicate which extended bit operations this port supports */
#include <ctype.h>
#include "SDCCglobl.h"
#include "newalloc.h"
+#include "dbuf_string.h"
#include "common.h"
#include "main.h"
/* emitcode - writes the code into a file : for now it is simple */
/*-----------------------------------------------------------------*/
static void
-emitcode (char *inst, const char *fmt,...)
+emitcode (const char *inst, const char *fmt,...)
{
va_list ap;
- char lb[INITIAL_INLINEASM];
- char *lbp = lb;
+ struct dbuf_s dbuf;
+ const char *lbp, *lb;
+
+ dbuf_init (&dbuf, INITIAL_INLINEASM);
va_start (ap, fmt);
if (inst && *inst)
{
+ dbuf_append_str (&dbuf, inst);
+
if (fmt && *fmt)
{
- SNPRINTF (lb, sizeof(lb), "%s\t", inst);
- }
- else
- {
- SNPRINTF (lb, sizeof(lb), "%s", inst);
- }
-
- tvsprintf (lb + strlen(lb), sizeof(lb) - strlen(lb), fmt, ap);
+ dbuf_append_char (&dbuf, '\t');
+ dbuf_tvprintf (&dbuf, fmt, ap);
+ }
}
else
{
- tvsprintf (lb, sizeof(lb), fmt, ap);
+ dbuf_tvprintf (&dbuf, fmt, ap);
}
+ lbp = lb = dbuf_c_str(&dbuf);
+
while (isspace ((unsigned char)*lbp))
{
lbp++;
lineCurr->aln = ds390newAsmLineNode(_currentDPS);
lineCurr->isComment = (*lbp == ';');
va_end (ap);
+
+ dbuf_destroy(&dbuf);
}
static void
#if 1
/* print the allocation information */
if (allocInfo && currFunc)
- printAllocInfo (currFunc, codeOutFile);
+ printAllocInfo (currFunc, codeOutBuf);
#endif
/* if debug information required */
if (options.debug && currFunc)
cln = ic->lineno;
}
if (options.iCodeInAsm) {
- emitcode("", ";ic:%d: %s", ic->key, printILine(ic));
+ char *iLine = printILine(ic);
+ emitcode("", ";ic:%d: %s", ic->key, iLine);
+ dbuf_free(iLine);
}
/* if the result is marked as
spilt and rematerializable or code for
peepHole (&lineHead);
/* now do the actual printing */
- printLine (lineHead, codeOutFile);
+ printLine (lineHead, codeOutBuf);
return;
}
#include "gen.h"
#include "BuildCmd.h"
#include "MySystem.h"
+#include "dbuf_string.h"
#include "../SDCCutil.h"
#include "../SDCCglobl.h"
static char _defaultRules[] =
/* Generate interrupt vector table. */
static int
-_ds390_genIVT (FILE * of, symbol ** interrupts, int maxInterrupts)
+_ds390_genIVT (struct dbuf_s * oBuf, symbol ** interrupts, int maxInterrupts)
{
int i;
if (options.model != MODEL_FLAT24)
{
- fprintf (of, "\tljmp\t__sdcc_gsinit_startup\n");
+ dbuf_printf (oBuf, "\tljmp\t__sdcc_gsinit_startup\n");
/* now for the other interrupts */
for (i = 0; i < maxInterrupts; i++)
{
if (interrupts[i])
{
- fprintf (of, "\tljmp\t%s\n", interrupts[i]->rname);
+ dbuf_printf (oBuf, "\tljmp\t%s\n", interrupts[i]->rname);
if ( i != maxInterrupts - 1 )
- fprintf (of, "\t.ds\t5\n");
+ dbuf_printf (oBuf, "\t.ds\t5\n");
}
else
{
- fprintf (of, "\treti\n");
+ dbuf_printf (oBuf, "\treti\n");
if ( i != maxInterrupts - 1 )
- fprintf (of, "\t.ds\t7\n");
+ dbuf_printf (oBuf, "\t.ds\t7\n");
}
}
return TRUE;
}
- fprintf (of, "\tajmp\t__reset_vect\n");
+ dbuf_printf (oBuf, "\tajmp\t__reset_vect\n");
/* now for the other interrupts */
for (i = 0; i < maxInterrupts; i++)
{
if (interrupts[i])
{
- fprintf (of, "\tljmp\t%s\n\t.ds\t4\n", interrupts[i]->rname);
+ dbuf_printf (oBuf, "\tljmp\t%s\n\t.ds\t4\n", interrupts[i]->rname);
}
else
{
- fprintf (of, "\treti\n\t.ds\t7\n");
+ dbuf_printf (oBuf, "\treti\n\t.ds\t7\n");
}
}
- fprintf (of, "__reset_vect:\n\tljmp\t__sdcc_gsinit_startup\n");
+ dbuf_printf (oBuf, "__reset_vect:\n\tljmp\t__sdcc_gsinit_startup\n");
return TRUE;
}
options.cc_only =1;
}
-static int _tininative_genIVT (FILE * of, symbol ** interrupts, int maxInterrupts)
+static int _tininative_genIVT (struct dbuf_s * oBuf, symbol ** interrupts, int maxInterrupts)
{
return TRUE;
}
};
static int
-_ds400_genIVT (FILE * of, symbol ** interrupts, int maxInterrupts)
+_ds400_genIVT (struct dbuf_s * oBuf, symbol ** interrupts, int maxInterrupts)
{
- /* We can't generate a static IVT, since the boot rom creates one
- * for us in rom_init.
- *
- * we must patch it as part of the C startup.
- */
- fprintf (of, ";\tDS80C400 IVT must be generated at runtime.\n");
- fprintf (of, "\tsjmp\t__sdcc_400boot\n");
- fprintf (of, "\t.ascii\t'TINI'\t; required signature for 400 boot loader.\n");
- fprintf (of, "\t.db\t0\t; selected bank: zero *should* work...\n");
- fprintf (of, "\t__sdcc_400boot:\tljmp\t__sdcc_gsinit_startup\n");
- return TRUE;
+ /* We can't generate a static IVT, since the boot rom creates one
+ * for us in rom_init.
+ *
+ * we must patch it as part of the C startup.
+ */
+ dbuf_printf (oBuf, ";\tDS80C400 IVT must be generated at runtime.\n");
+ dbuf_printf (oBuf, "\tsjmp\t__sdcc_400boot\n");
+ dbuf_printf (oBuf, "\t.ascii\t'TINI'\t; required signature for 400 boot loader.\n");
+ dbuf_printf (oBuf, "\t.db\t0\t; selected bank: zero *should* work...\n");
+ dbuf_printf (oBuf, "\t__sdcc_400boot:\tljmp\t__sdcc_gsinit_startup\n");
+
+ return TRUE;
}
extern int hc08_ptrRegReq;
extern int hc08_nRegs;
-extern FILE *codeOutFile;
+extern struct dbuf_s *codeOutBuf;
//static void saveRBank (int, iCode *, bool);
static bool operandsEqu (operand * op1, operand * op2);
static void loadRegFromConst (regs *reg, char *c);
/* print the allocation information */
if (allocInfo && currFunc)
- printAllocInfo (currFunc, codeOutFile);
+ printAllocInfo (currFunc, codeOutBuf);
/* if debug information required */
if (options.debug && currFunc)
{
if (options.iCodeInAsm) {
char regsInUse[80];
int i;
+ char *iLine;
for (i=0; i<6; i++) {
sprintf (®sInUse[i],
"%c", ic->riu & (1<<i) ? i+'0' : '-');
}
regsInUse[i]=0;
+ iLine = printILine(ic);
emitcode("", "; [%s] ic:%d: %s", regsInUse, ic->seq, printILine(ic));
+ dbuf_free(iLine);
}
/* if the result is marked as
spilt and rematerializable or code for
peepHole (&lineHead);
/* now do the actual printing */
- printLine (lineHead, codeOutFile);
+ printLine (lineHead, codeOutBuf);
return;
}
#include "main.h"
#include "ralloc.h"
#include "gen.h"
+#include "dbuf_string.h"
#include "../SDCCutil.h"
-void copyFile(FILE *dest, FILE *src);
extern char * iComments2;
extern DEBUGFILE dwarf2DebugFile;
extern int dwarf2FinalizeFile(FILE *);
fprintf (asmFile, "%s", iComments2);
fprintf (asmFile, "; extended address mode data\n");
fprintf (asmFile, "%s", iComments2);
- copyFile (asmFile, xdata->oFile);
+ dbuf_write_and_destroy (&xdata->oBuf, asmFile);
}
/* Generate interrupt vector table. */
static int
-_hc08_genIVT (FILE * of, symbol ** interrupts, int maxInterrupts)
+_hc08_genIVT (struct dbuf_s * oBuf, symbol ** interrupts, int maxInterrupts)
{
int i;
- fprintf (of, "\t.area\tCODEIVT (ABS)\n");
- fprintf (of, "\t.org\t0x%04x\n",
+ dbuf_printf (oBuf, "\t.area\tCODEIVT (ABS)\n");
+ dbuf_printf (oBuf, "\t.org\t0x%04x\n",
(0xfffe - (maxInterrupts * 2)));
for (i=maxInterrupts;i>0;i--)
{
if (interrupts[i])
- fprintf (of, "\t.dw\t%s\n", interrupts[i]->rname);
+ dbuf_printf (oBuf, "\t.dw\t%s\n", interrupts[i]->rname);
else
- fprintf (of, "\t.dw\t0xffff\n");
+ dbuf_printf (oBuf, "\t.dw\t0xffff\n");
}
- fprintf (of, "\t.dw\t%s", "__sdcc_gs_init_startup\n");
+ dbuf_printf (oBuf, "\t.dw\t%s", "__sdcc_gs_init_startup\n");
return TRUE;
}
{
// Currently a holder function. The Z80 needs some special mangling
// for bank support.
- printLine (_G.lines.head, codeOutFile);
+ printLine (_G.lines.head, codeOutBuf);
}
void
#include "SDCCpeeph.h"
#include "ralloc.h"
#include "gen.h"
+#include "dbuf_string.h"
char *aopLiteral (value * val, int offset);
char *aopLiteralLong (value * val, int offset, int size);
"b0", "b1", "b2", "b3", "b4", "b5", "b6", "b7"
};
-extern FILE *codeOutFile;
+extern struct dbuf_s *codeOutBuf;
static void saveRBank (int, iCode *, bool);
#define RESULTONSTACK(x) \
/* emitcode - writes the code into a file : for now it is simple */
/*-----------------------------------------------------------------*/
static void
-emitcode (char *inst, const char *fmt,...)
+emitcode (const char *inst, const char *fmt,...)
{
va_list ap;
- char lb[INITIAL_INLINEASM];
- char *lbp = lb;
+ struct dbuf_s dbuf;
+ const char *lbp, *lb;
+
+ dbuf_init (&dbuf, INITIAL_INLINEASM);
va_start (ap, fmt);
if (inst && *inst)
{
+ dbuf_append_str (&dbuf, inst);
+
if (fmt && *fmt)
{
- SNPRINTF (lb, sizeof(lb), "%s\t", inst);
- }
- else
- {
- SNPRINTF (lb, sizeof(lb), "%s", inst);
+ dbuf_append_char (&dbuf, '\t');
+ dbuf_tvprintf (&dbuf, fmt, ap);
}
-
- tvsprintf (lb + strlen(lb), sizeof(lb) - strlen(lb), fmt, ap);
}
else
{
- tvsprintf (lb, sizeof(lb), fmt, ap);
+ dbuf_tvprintf (&dbuf, fmt, ap);
}
+ lbp = lb = dbuf_c_str(&dbuf);
+
while (isspace ((unsigned char)*lbp))
{
lbp++;
lineCurr->ic = _G.current_iCode;
lineCurr->isComment = (*lbp==';');
va_end (ap);
+
+ dbuf_destroy(&dbuf);
}
static void
/* print the allocation information */
if (allocInfo && currFunc)
- printAllocInfo (currFunc, codeOutFile);
+ printAllocInfo (currFunc, codeOutBuf);
/* if debug information required */
if (options.debug && currFunc)
{
if (options.iCodeInAsm) {
char regsInUse[80];
int i;
+ char *iLine;
#if 0
for (i=0; i<8; i++) {
}
#endif
}
+ iLine = printILine(ic);
emitcode("", "; [%s] ic:%d: %s", regsInUse, ic->seq, printILine(ic));
+ dbuf_free(iLine);
}
/* if the result is marked as
spilt and rematerializable or code for
peepHole (&lineHead);
/* now do the actual printing */
- printLine (lineHead, codeOutFile);
+ printLine (lineHead, codeOutBuf);
return;
}
#include "main.h"
#include "ralloc.h"
#include "gen.h"
+#include "dbuf_string.h"
#include "../SDCCutil.h"
static char _defaultRules[] =
/* Generate interrupt vector table. */
static int
-_mcs51_genIVT (FILE * of, symbol ** interrupts, int maxInterrupts)
+_mcs51_genIVT (struct dbuf_s * oBuf, symbol ** interrupts, int maxInterrupts)
{
int i;
- fprintf (of, "\tljmp\t__sdcc_gsinit_startup\n");
+ dbuf_printf (oBuf, "\tljmp\t__sdcc_gsinit_startup\n");
/* now for the other interrupts */
for (i = 0; i < maxInterrupts; i++)
{
if (interrupts[i])
{
- fprintf (of, "\tljmp\t%s\n", interrupts[i]->rname);
+ dbuf_printf (oBuf, "\tljmp\t%s\n", interrupts[i]->rname);
if ( i != maxInterrupts - 1 )
- fprintf (of, "\t.ds\t5\n");
+ dbuf_printf (oBuf, "\t.ds\t5\n");
}
else
{
- fprintf (of, "\treti\n");
+ dbuf_printf (oBuf, "\treti\n");
if ( i != maxInterrupts - 1 )
- fprintf (of, "\t.ds\t7\n");
+ dbuf_printf (oBuf, "\t.ds\t7\n");
}
}
return TRUE;
static unsigned int config2_word = DEFAULT_CONFIG2_WORD;
static memRange *rangeRAM = NULL;
-extern void emitSymbolToFile (FILE *of, const char *name, const char *section_type, int size, int addr, int useEQU, int globalize);
-
/* parse a value from the configuration file */
static int parse_config_value(char *str)
extern int pic14_ptrRegReq ;
extern int pic14_nRegs;
-extern FILE *codeOutFile;
+extern struct dbuf_s *codeOutBuf;
static void saverbank (int, iCode *,bool);
static lineNode *lineHead = NULL;
}
if (options.iCodeInAsm) {
+ char *iLine = printILine(ic);
emitpComment ("[ICODE] %s:%d: %s", ic->filename, ic->lineno, printILine (ic));
+ dbuf_free(iLine);
}
/* if the result is marked as
spilt and rematerializable or code for
peepHole (&lineHead);
}
/* now do the actual printing */
- printLine (lineHead,codeOutFile);
+ printLine (lineHead,codeOutBuf);
#ifdef PCODE_DEBUG
DFPRINTF((stderr,"printing pBlock\n\n"));
#include "gen.h"
#include "main.h"
#include "device.h"
+#include "dbuf_string.h"
#ifdef WORDS_BIGENDIAN
extern int maxRegBank;
extern symbol *mainf;
extern char *VersionString;
-extern FILE *codeOutFile;
-extern set *tmpfileSet;
-extern set *tmpfileNameSet;
+extern struct dbuf_s *codeOutBuf;
extern char *iComments1;
extern char *iComments2;
//extern void emitStaticSeg (memmap * map);
extern DEFSETFUNC (rmTmpFiles);
extern void AnalyzeBanking (void);
-extern void copyFile (FILE * dest, FILE * src);
extern void ReuseReg(void);
extern void InlinepCode(void);
extern void writeUsedRegs(FILE *);
static set *emitted = NULL;
int pic14_stringInSet(const char *str, set **world, int autoAdd);
-static void emitSymbolToFile (FILE *of, const char *name, const char *section_type, int size, int addr, int useEQU, int globalize);
+static void emitSymbol (struct dbuf_s *oBuf, const char *name, const char *section_type, int size, int addr, int useEQU, int globalize);
/*-----------------------------------------------------------------*/
/* aopLiteral - string from a literal value */
#define IS_DEFINED_HERE(sym) (!IS_EXTERN(sym->etype))
extern int IS_CONFIG_ADDRESS( int addr );
static void
-pic14_constructAbsMap (FILE *ofile)
+pic14_constructAbsMap (struct dbuf_s *oBuf)
{
memmap *maps[] = { data, sfr, NULL };
int i;
} // for i
/* now emit definitions for all absolute symbols */
- fprintf (ofile, "%s", iComments2);
- fprintf (ofile, "; absolute symbol definitions\n");
- fprintf (ofile, "%s", iComments2);
+ dbuf_printf (oBuf, "%s", iComments2);
+ dbuf_printf (oBuf, "; absolute symbol definitions\n");
+ dbuf_printf (oBuf, "%s", iComments2);
for (addr=min; addr <= max; addr++)
{
size = 1;
aliases = hTabItemWithKey (ht, addr);
if (aliases && elementsInSet(aliases)) {
- fprintf (ofile, "udata_abs_%s_%x\tudata_ovr\t0x%04x",
+ dbuf_printf (oBuf, "udata_abs_%s_%x\tudata_ovr\t0x%04x",
moduleName, addr, addr);
for (sym = setFirstItem (aliases); sym;
sym = setNextItem (aliases))
{
/* emit STATUS as well as _STATUS, required for SFRs only */
- fprintf (ofile, "\n%s", sym->name);
- fprintf (ofile, "\n%s", sym->rname);
+ dbuf_printf (oBuf, "\n%s", sym->name);
+ dbuf_printf (oBuf, "\n%s", sym->rname);
if (getSize(sym->type) > size) {
size = getSize(sym->type);
}
pic14_stringInSet(sym->rname, &emitted, 1);
}
} // for
- fprintf (ofile, "\tres\t%d\n", size);
+ dbuf_printf (oBuf, "\tres\t%d\n", size);
} // if
} // for i
* differently sized sharebanks, since STK12 will be
* required by larger devices but only up to STK03 might
* be defined using smaller devices. */
- fprintf (ofile, "\n");
+ dbuf_printf (oBuf, "\n");
shared = pic14_getSharedStack(&low, &high, &size);
if (!pic14_options.isLibrarySource)
{
pic = pic14_getPIC();
- fprintf (ofile, "\tglobal PSAVE\n");
- fprintf (ofile, "\tglobal SSAVE\n");
- fprintf (ofile, "\tglobal WSAVE\n");
+ dbuf_printf (oBuf, "\tglobal PSAVE\n");
+ dbuf_printf (oBuf, "\tglobal SSAVE\n");
+ dbuf_printf (oBuf, "\tglobal WSAVE\n");
for (i = size - 4; i >= 0; i--) {
- fprintf (ofile, "\tglobal STK%02d\n", i);
+ dbuf_printf (oBuf, "\tglobal STK%02d\n", i);
} // for i
// 16f84 has no SHAREBANK (in linkerscript) but memory aliased in two
// banks, sigh...
if (1 || !shared) {
// for single banked devices: use normal, "banked" RAM
- fprintf (ofile, "sharebank udata_ovr 0x%04X\n", low);
+ dbuf_printf (oBuf, "sharebank udata_ovr 0x%04X\n", low);
} else {
// for devices with at least two banks, require a sharebank section
- fprintf (ofile, "sharebank udata_shr\n");
+ dbuf_printf (oBuf, "sharebank udata_shr\n");
}
- fprintf (ofile, "PSAVE\tres 1\n");
- fprintf (ofile, "SSAVE\tres 1\n");
- fprintf (ofile, "WSAVE\tres 1\n"); // WSAVE *must* be in sharebank (IRQ handlers)
+ dbuf_printf (oBuf, "PSAVE\tres 1\n");
+ dbuf_printf (oBuf, "SSAVE\tres 1\n");
+ dbuf_printf (oBuf, "WSAVE\tres 1\n"); // WSAVE *must* be in sharebank (IRQ handlers)
/* fill rest of sharebank with stack STKxx .. STK00 */
for (i = size - 4; i >= 0; i--) {
- fprintf (ofile, "STK%02d\tres 1\n", i);
+ dbuf_printf (oBuf, "STK%02d\tres 1\n", i);
} // for i
} else {
/* declare STKxx as extern for all files
* except the one containing main() */
- fprintf (ofile, "\textern PSAVE\n");
- fprintf (ofile, "\textern SSAVE\n");
- fprintf (ofile, "\textern WSAVE\n");
+ dbuf_printf (oBuf, "\textern PSAVE\n");
+ dbuf_printf (oBuf, "\textern SSAVE\n");
+ dbuf_printf (oBuf, "\textern WSAVE\n");
for (i = size - 4; i >= 0; i--) {
char buffer[128];
SNPRINTF(&buffer[0], 127, "STK%02d", i);
- fprintf (ofile, "\textern %s\n", &buffer[0]);
+ dbuf_printf (oBuf, "\textern %s\n", &buffer[0]);
pic14_stringInSet(&buffer[0], &emitted, 1);
} // for i
}
/* print the area name */
if (addPublics)
- fprintf (map->oFile, ";\t.area\t%s\n", map->sname);
+ dbuf_printf (&map->oBuf, ";\t.area\t%s\n", map->sname);
for (sym = setFirstItem (map->syms); sym;
sym = setNextItem (map->syms)) {
{
if (!sym->level) /* global */
if (IS_STATIC (sym->etype))
- fprintf (map->oFile, "F%s_", moduleName); /* scope is file */
+ dbuf_printf (&map->oBuf, "F%s_", moduleName); /* scope is file */
else
- fprintf (map->oFile, "G_"); /* scope is global */
+ dbuf_printf (&map->oBuf, "G_"); /* scope is global */
else
/* symbol is local */
- fprintf (map->oFile, "L%s_", (sym->localof ? sym->localof->name : "-null-"));
- fprintf (map->oFile, "%s_%d_%d", sym->name, sym->level, sym->block);
+ dbuf_printf (&map->oBuf, "L%s_", (sym->localof ? sym->localof->name : "-null-"));
+ dbuf_printf (&map->oBuf, "%s_%d_%d", sym->name, sym->level, sym->block);
}
#endif
/* absolute symbols are handled in pic14_constructAbsMap */
if (0 && SPEC_ABSA (sym->etype))
{
//if (options.debug || sym->level == 0)
- //fprintf (map->oFile,"; == 0x%04x\n",SPEC_ADDR (sym->etype));
+ //dbuf_printf (&map->oBuf,"; == 0x%04x\n",SPEC_ADDR (sym->etype));
- fprintf (map->oFile, "%s\tEQU\t0x%04x\n",
+ dbuf_printf (&map->oBuf, "%s\tEQU\t0x%04x\n",
sym->rname,
SPEC_ADDR (sym->etype));
}
}
else
{
- emitSymbolToFile (map->oFile,
+ emitSymbol (&map->oBuf,
sym->rname,
NULL,
getSize (sym->type) & 0xffff,
if ((size = (unsigned int) getSize (sym->type) & 0xffff) > 1)
{
for (i = 1; i < size; i++)
- fprintf (map->oFile, "\t%s_%d\n", sym->rname, i);
+ dbuf_printf (&map->oBuf, "\t%s_%d\n", sym->rname, i);
}
}
*/
}
- //fprintf (map->oFile, "\t.ds\t0x%04x\n", (unsigned int)getSize (sym->type) & 0xffff);
+ //dbuf_printf (&map->oBuf, "\t.ds\t0x%04x\n", (unsigned int)getSize (sym->type) & 0xffff);
}
/* if it has a initial value then do it only if
else
ival = newNode ('=', newAst_VALUE(symbolVal (sym)),
decorateType (resolveSymbols (list2expr (sym->ival)), RESULT_TYPE_NONE));
- codeOutFile = statsg->oFile;
+ codeOutBuf = &statsg->oBuf;
GcurMemmap = statsg;
eBBlockFromiCode (iCodeFromAst (ival));
sym->ival = NULL;
{
symbol *sym;
- fprintf (map->oFile, ";\t.area\t%s\n", map->sname);
+ dbuf_printf (&map->oBuf, ";\t.area\t%s\n", map->sname);
//fprintf(stderr, "%s\n",__FUNCTION__);
if (!sym->level)
{ /* global */
if (IS_STATIC (sym->etype))
- fprintf (code->oFile, "F%s_", moduleName); /* scope is file */
+ dbuf_printf (&code->oBuf, "F%s_", moduleName); /* scope is file */
else
- fprintf (code->oFile, "G_"); /* scope is global */
+ dbuf_printf (&code->oBuf, "G_"); /* scope is global */
}
else
/* symbol is local */
- fprintf (code->oFile, "L%s_",
+ dbuf_printf (&code->oBuf, "L%s_",
(sym->localof ? sym->localof->name : "-null-"));
- fprintf (code->oFile, "%s_%d_%d", sym->name, sym->level, sym->block);
+ dbuf_printf (&code->oBuf, "%s_%d_%d", sym->name, sym->level, sym->block);
}
if (SPEC_ABSA (sym->etype))
{
if (options.debug || sym->level == 0)
- fprintf (code->oFile, " == 0x%04x\n", SPEC_ADDR (sym->etype));
+ dbuf_printf (&code->oBuf, " == 0x%04x\n", SPEC_ADDR (sym->etype));
- fprintf (code->oFile, "%s\t=\t0x%04x\n",
+ dbuf_printf (&code->oBuf, "%s\t=\t0x%04x\n",
sym->rname,
SPEC_ADDR (sym->etype));
}
else
{
if (options.debug || sym->level == 0)
- fprintf (code->oFile, " == .\n");
+ dbuf_printf (&code->oBuf, " == .\n");
/* if it has an initial value */
if (sym->ival)
{
pBlock *pb;
- fprintf (code->oFile, "%s:\n", sym->rname);
+ dbuf_printf (&code->oBuf, "%s:\n", sym->rname);
noAlloc++;
resolveIvalSym (sym->ival, sym->type);
- //printIval (sym, sym->type, sym->ival, code->oFile);
+ //printIval (sym, sym->type, sym->ival, &code->oBuf);
pb = newpCodeChain(NULL, 'P',newpCodeCharP("; Starting pCode block for Ival"));
addpBlock(pb);
addpCode2pBlock(pb,newpCodeLabel(sym->rname,-1));
{
/* allocate space */
- fprintf (code->oFile, "%s:\n", sym->rname);
+ dbuf_printf (&code->oBuf, "%s:\n", sym->rname);
/* special case for character strings */
if (IS_ARRAY (sym->type) && IS_CHAR (sym->type->next) &&
SPEC_CVAL (sym->etype).v_char)
SPEC_CVAL (sym->etype).v_char,
strlen (SPEC_CVAL (sym->etype).v_char) + 1);*/
else
- fprintf (code->oFile, "\t.ds\t0x%04x\n", (unsigned int) getSize (sym->type) & 0xffff);
+ dbuf_printf (&code->oBuf, "\t.ds\t0x%04x\n", (unsigned int) getSize (sym->type) & 0xffff);
}
}
}
static void
pic14emitMaps ()
{
- pic14_constructAbsMap (sfr->oFile);
+ pic14_constructAbsMap (&sfr->oBuf);
/* no special considerations for the following
data, idata & bit & xdata */
pic14emitRegularMap (data, TRUE, TRUE);
/* createInterruptVect - creates the interrupt vector */
/*-----------------------------------------------------------------*/
static void
-pic14createInterruptVect (FILE * vFile)
+pic14createInterruptVect (struct dbuf_s * vBuf)
{
mainf = newSymbol ("main", 0);
mainf->block = 0;
return;
}
- fprintf (vFile, "%s", iComments2);
- fprintf (vFile, "; reset vector \n");
- fprintf (vFile, "%s", iComments2);
- fprintf (vFile, "STARTUP\t%s\n", CODE_NAME); // Lkr file should place section STARTUP at address 0x0
- fprintf (vFile, "\tnop\n"); /* first location for used by incircuit debugger */
- fprintf( vFile, "\tpagesel __sdcc_gsinit_startup\n");
- fprintf (vFile, "\tgoto\t__sdcc_gsinit_startup\n");
+ dbuf_printf (vBuf, "%s", iComments2);
+ dbuf_printf (vBuf, "; reset vector \n");
+ dbuf_printf (vBuf, "%s", iComments2);
+ dbuf_printf (vBuf, "STARTUP\t%s\n", CODE_NAME); // Lkr file should place section STARTUP at address 0x0
+ dbuf_printf (vBuf, "\tnop\n"); /* first location for used by incircuit debugger */
+ dbuf_printf (vBuf, "\tpagesel __sdcc_gsinit_startup\n");
+ dbuf_printf (vBuf, "\tgoto\t__sdcc_gsinit_startup\n");
}
}
/*-------------------------------------------------------------------*/
-/* emitSymbolToFile - write a symbol definition only if it is not */
+/* emitSymbol - write a symbol definition only if it is not */
/* already present */
/*-------------------------------------------------------------------*/
+
static void
-emitSymbolToFile (FILE *of, const char *name, const char *section_type, int size, int addr, int useEQU, int globalize)
+emitSymbol (struct dbuf_s *oBuf, const char *name, const char *section_type, int size, int addr, int useEQU, int globalize)
{
static unsigned int sec_idx = 0;
/* new symbol -- define it */
//fprintf (stderr, "%s: emitting %s (%d)\n", __FUNCTION__, name, size);
if (useEQU) {
- fprintf (of, "%s\tEQU\t0x%04x\n", name, addr);
+ dbuf_printf (oBuf, "%s\tEQU\t0x%04x\n", name, addr);
} else {
/* we place each symbol into a section of its own to allow the linker
* to distribute the data into all available memory banks */
/* absolute symbols are handled in pic14_constructAbsMap */
/* do nothing */
} else {
- if (globalize) fprintf (of, "\tglobal\t%s\n", name);
- fprintf (of, "udata_%s_%u\t%s\n", moduleName,
+ if (globalize) dbuf_printf (oBuf, "\tglobal\t%s\n", name);
+ dbuf_printf (oBuf, "udata_%s_%u\t%s\n", moduleName,
sec_idx++, section_type);
- fprintf (of, "%s\tres\t%d\n", name, size);
+ dbuf_printf (oBuf, "%s\tres\t%d\n", name, size);
}
}
}
set *allregs[6] = { dynAllocRegs, dynStackRegs, dynProcessorRegs, dynDirectRegs, dynDirectBitRegs, dynInternalRegs };
regs *reg;
int i;
+ struct dbuf_s dbuf;
+ dbuf_init(&dbuf, 1024);
/* emit all registers from all possible sets */
for (i = 0; i < 6; i++) {
if (allregs[i] == NULL) continue;
if (reg->isEmitted) continue;
if (reg->wasUsed && !reg->isExtern) {
- emitSymbolToFile(afile, reg->name, "udata", reg->size, reg->isFixed ? reg->address : -1, 0, reg->isPublic);
+ emitSymbol(&dbuf, reg->name, "udata", reg->size, reg->isFixed ? reg->address : -1, 0, reg->isPublic);
}
reg->isEmitted = 1;
} // for
} // for
+ dbuf_write_and_destroy(&dbuf, afile);
}
/*-----------------------------------------------------------------*/
/* emitOverlay - will emit code for the overlay stuff */
/*-----------------------------------------------------------------*/
static void
-pic14emitOverlay (FILE * afile)
+pic14emitOverlay (struct dbuf_s * aBuf)
{
set *ovrset;
/* the hack below, fixes translates for devices which
* only have udata_shr memory */
- fprintf (afile, "%s\t%s\n",
+ dbuf_printf (aBuf, "%s\t%s\n",
(elementsInSet(ovrSetSets)?"":";"),
port->mem.overlay_name);
/* I don't think this applies to us. We are using gpasm. CRF */
- fprintf (afile, ";\t.area _DUMMY\n");
+ dbuf_printf (aBuf, ";\t.area _DUMMY\n");
/* output the area informtion */
- fprintf (afile, ";\t.area\t%s\n", port->mem.overlay_name); /* MOF */
+ dbuf_printf (aBuf, ";\t.area\t%s\n", port->mem.overlay_name); /* MOF */
}
for (sym = setFirstItem (ovrset); sym;
if (!sym->level)
{ /* global */
if (IS_STATIC (sym->etype))
- fprintf (afile, "F%s_", moduleName); /* scope is file */
+ dbuf_printf (aBuf, "F%s_", moduleName); /* scope is file */
else
- fprintf (afile, "G_"); /* scope is global */
+ dbuf_printf (aBuf, "G_"); /* scope is global */
}
else
/* symbol is local */
- fprintf (afile, "L%s_",
+ dbuf_printf (aBuf, "L%s_",
(sym->localof ? sym->localof->name : "-null-"));
- fprintf (afile, "%s_%d_%d", sym->name, sym->level, sym->block);
+ dbuf_printf (aBuf, "%s_%d_%d", sym->name, sym->level, sym->block);
}
/* if is has an absolute address then generate
{
if (options.debug || sym->level == 0)
- fprintf (afile, " == 0x%04x\n", SPEC_ADDR (sym->etype));
+ dbuf_printf (aBuf, " == 0x%04x\n", SPEC_ADDR (sym->etype));
- fprintf (afile, "%s\t=\t0x%04x\n",
+ dbuf_printf (aBuf, "%s\t=\t0x%04x\n",
sym->rname,
SPEC_ADDR (sym->etype));
}
else
{
if (options.debug || sym->level == 0)
- fprintf (afile, "==.\n");
+ dbuf_printf (aBuf, "==.\n");
/* allocate space */
- fprintf (afile, "%s:\n", sym->rname);
- fprintf (afile, "\t.ds\t0x%04x\n", (unsigned int) getSize (sym->type) & 0xffff);
+ dbuf_printf (aBuf, "%s:\n", sym->rname);
+ dbuf_printf (aBuf, "\t.ds\t0x%04x\n", (unsigned int) getSize (sym->type) & 0xffff);
}
}
picglue ()
{
char udata_name[80];
- FILE *vFile;
FILE *asmFile;
- FILE *ovrFile = tempfile();
-
- addSetHead(&tmpfileSet,ovrFile);
+ struct dbuf_s ovrBuf;
+ struct dbuf_s vBuf;
+
+ dbuf_init(&ovrBuf, 4096);
+ dbuf_init(&vBuf, 4096);
+
pCodeInitRegisters();
/* check for main() */
if (options.debug)
cdbStructBlock (0);
- vFile = tempfile();
-
- addSetHead(&tmpfileSet,vFile);
-
/* emit code for the all the variables declared */
pic14emitMaps ();
/* do the overlay segments */
- pic14emitOverlay(ovrFile);
+ pic14emitOverlay(&ovrBuf);
/* PENDING: this isnt the best place but it will do */
if (port->general.glue_up_main) {
/* create the interrupt vector table */
- pic14createInterruptVect (vFile);
+ pic14createInterruptVect (&vBuf);
}
AnalyzepCode('*');
fprintf (asmFile, "%s", iComments2);
fprintf (asmFile, "; special function registers\n");
fprintf (asmFile, "%s", iComments2);
- copyFile (asmFile, sfr->oFile);
+ dbuf_write_and_destroy (&sfr->oBuf, asmFile);
if (udata_section_name) {
fprintf (asmFile, "; udata\n");
fprintf (asmFile, "%s", iComments2);
fprintf (asmFile, "%s\tudata\n", udata_name);
- copyFile (asmFile, data->oFile);
+ dbuf_write_and_destroy(&data->oBuf, asmFile);
/* Put all variables into a cblock */
AnalyzeBanking();
fprintf (asmFile, "%s", iComments2);
fprintf (asmFile, "; overlayable items in internal ram \n");
fprintf (asmFile, "%s", iComments2);
- copyFile (asmFile, ovrFile);
+ dbuf_write_and_destroy (&ovrBuf, asmFile);
#if 0
fprintf (asmFile, "%s", iComments2);
fprintf (asmFile, "; indirectly addressable internal ram data\n");
fprintf (asmFile, "%s", iComments2);
- copyFile (asmFile, idata->oFile);
-
+ dbuf_write_and_destroy (&idata->oBuf, asmFile);
+
/* if external stack then reserve space of it */
if (mainf && IFFUNC_HASBODY(mainf->type) && options.useXstack ) {
fprintf (asmFile, "%s", iComments2);
fprintf (asmFile, "%s", iComments2);
fprintf (asmFile, "; external ram data\n");
fprintf (asmFile, "%s", iComments2);
- copyFile (asmFile, xdata->oFile);
-
+ dbuf_write_and_destroy (&xdata->oBuf, asmFile);
+
#endif
/* copy the bit segment */
fprintf (asmFile, "%s", iComments2);
fprintf (asmFile, "; bit data\n");
fprintf (asmFile, "%s", iComments2);
- copyFile (asmFile, bit->oFile);
+ dbuf_write_and_destroy (&bit->oBuf, asmFile);
/* copy the interrupt vector table */
- if (mainf && IFFUNC_HASBODY(mainf->type)) {
- copyFile (asmFile, vFile);
- }
-
+ if (mainf && IFFUNC_HASBODY(mainf->type))
+ dbuf_write_and_destroy (&vBuf, asmFile);
+ else
+ dbuf_destroy(&vBuf);
+
/* create interupt ventor handler */
pic14_emitInterruptHandler (asmFile);
fprintf (asmFile,"\tend\n");
fclose (asmFile);
-
- rm_tmpfiles();
}
#include "SDCCmacro.h"
#include "MySystem.h"
#include "glue.h"
+#include "dbuf_string.h"
#include <errno.h>
//#include "gen.h"
/* Generate interrupt vector table. */
static int
-_pic14_genIVT (FILE * of, symbol ** interrupts, int maxInterrupts)
+_pic14_genIVT (struct dbuf_s * oBuf, symbol ** interrupts, int maxInterrupts)
{
int i;
return FALSE;
}
- fprintf (of, "\t;ajmp\t__sdcc_gsinit_startup\n");
+ dbuf_printf (oBuf, "\t;ajmp\t__sdcc_gsinit_startup\n");
/* now for the other interrupts */
for (i = 0; i < maxInterrupts; i++)
{
if (interrupts[i])
{
- fprintf (of, "\t;ljmp\t%s\n\t.ds\t4\n", interrupts[i]->rname);
+ dbuf_printf (oBuf, "\t;ljmp\t%s\n\t.ds\t4\n", interrupts[i]->rname);
}
else
{
- fprintf (of, "\t;reti\n\t.ds\t7\n");
+ dbuf_printf (oBuf, "\t;reti\n\t.ds\t7\n");
}
}
static char *
debugAopGet (char *str, operand * op)
{
- if (str)
+ if (str)
debugLog (str);
printOperand (op, debugF);
extern int pic16_ptrRegReq ;
extern int pic16_nRegs;
-extern FILE *codeOutFile;
+extern struct dbuf_s *codeOutBuf;
//static void saverbank (int, iCode *,bool);
static lineNode *lineHead = NULL;
for (;;) {
oldic = ic;
-// pic16_emitpcomment("ic: %s\n", printILine(ic));
+// chat *iLine = printILine(ic);
+// pic16_emitpcomment("ic: %s\n", iLine);
+// dbuf_free(iLine);
if (ic->op == '+') {
val += (int) operandLitValue(IC_RIGHT(ic));
}
if(options.iCodeInAsm) {
- char *l;
+ char *iLine;
/* insert here code to print iCode as comment */
- l = Safe_strdup(printILine(ic));
- pic16_emitpcomment("ic:%d: %s", ic->seq, l);
+ iLine = printILine(ic);
+ pic16_emitpcomment("ic:%d: %s", ic->seq, iLine);
+ dbuf_free(iLine);
}
/* if the result is marked as
peepHole (&lineHead);
/* now do the actual printing */
- printLine (lineHead, codeOutFile);
+ printLine (lineHead, codeOutBuf);
#ifdef PCODE_DEBUG
DFPRINTF((stderr,"printing pBlock\n\n"));
#include "gen.h"
#include "device.h"
#include "main.h"
+#include "dbuf_string.h"
#include <string.h>
-#include <string.h>
-
-
extern symbol *interrupts[256];
void pic16_printIval (symbol * sym, sym_link * type, initList * ilist, char ptype, void *p);
extern int maxRegBank;
extern symbol *mainf;
extern char *VersionString;
-extern FILE *codeOutFile;
-extern set *tmpfileSet;
-extern set *tmpfileNameSet;
+extern struct dbuf_s *codeOutBuf;
extern char *iComments1;
extern char *iComments2;
extern void pic16_AnalyzeBanking (void);
extern void pic16_OptimizeJumps ();
extern void pic16_OptimizeBanksel ();
-extern void copyFile (FILE * dest, FILE * src);
extern void pic16_InlinepCode(void);
extern void pic16_writeUsedRegs(FILE *);
// fprintf(stderr, "%s:%d map name= %s\n", __FUNCTION__, __LINE__, map->sname);
if(addPublics)
- fprintf (map->oFile, ";\t.area\t%s\n", map->sname);
+ dbuf_printf (&map->oBuf, ";\t.area\t%s\n", map->sname);
/* print the area name */
for (sym = setFirstItem (map->syms); sym; sym = setNextItem (map->syms)) {
// fprintf (stderr,"; %s == 0x%04x\t\treqv= %p nRegs= %d\n",
// sym->name, SPEC_ADDR (sym->etype), sym->reqv, sym->regType);
- fprintf (map->oFile, "%s\tEQU\t0x%04x\n",
+ dbuf_printf (&map->oBuf, "%s\tEQU\t0x%04x\n",
sym->rname,
SPEC_ADDR (sym->etype));
if (IS_BITVAR (sym->etype)) {
bitvars++;
} else {
- fprintf (map->oFile, "\t%s\n", sym->rname);
+ dbuf_printf (map->oBuf, "\t%s\n", sym->rname);
if ((size = (unsigned int) getSize (sym->type) & 0xffff) > 1) {
for (i = 1; i < size; i++)
- fprintf (map->oFile, "\t%s_%d\n", sym->rname, i);
+ dbuf_printf (map->oBuf, "\t%s_%d\n", sym->rname, i);
}
}
- fprintf (map->oFile, "\t.ds\t0x%04x\n", (unsigned int)getSize (sym->type) & 0xffff);
+ dbuf_printf (map->oBuf, "\t.ds\t0x%04x\n", (unsigned int)getSize (sym->type) & 0xffff);
#endif
}
if(ival) {
setAstLineno(ival, sym->lineDef);
- codeOutFile = statsg->oFile;
+ codeOutBuf = &statsg->oBuf;
GcurMemmap = statsg;
eBBlockFromiCode (iCodeFromAst (ival));
sym->ival = NULL;
/* symbol has absolute address but no initial value */
/* allocate space */
- fprintf (code->oFile, "%s:\n", sym->rname);
+ dbuf_printf (&code->oBuf, "%s:\n", sym->rname);
/* special case for character strings */
if (IS_ARRAY (sym->type) && IS_CHAR (sym->type->next) &&
pBlock *pb;
/* symbol doesn't have absolute address but has initial value */
- fprintf (code->oFile, "%s:\n", sym->rname);
+ dbuf_printf (&code->oBuf, "%s:\n", sym->rname);
noAlloc++;
resolveIvalSym (sym->ival, sym->type);
/* symbol doesn't have absolute address and no initial value */
/* allocate space */
// fprintf(stderr, "%s:%d [3] generating init for label: %s\n", __FILE__, __LINE__, sym->rname);
- fprintf (code->oFile, "%s:\n", sym->rname);
+ dbuf_printf (&code->oBuf, "%s:\n", sym->rname);
/* special case for character strings */
if (IS_ARRAY (sym->type) && IS_CHAR (sym->type->next) &&
SPEC_CVAL (sym->etype).v_char) {
/* createInterruptVect - creates the interrupt vector */
/*-----------------------------------------------------------------*/
static void
-pic16createInterruptVect (FILE * vFile)
+pic16createInterruptVect (struct dbuf_s * vBuf)
{
/* if the main is only a prototype ie. no body then do nothing */
#if 0
#endif
#if 0
if((!pic16_options.omit_ivt) || (pic16_options.omit_ivt && pic16_options.leave_reset)) {
- fprintf (vFile, ";\t.area\t%s\n", CODE_NAME);
- fprintf(vFile, ".intvecs\tcode\t0x%06x\n", pic16_options.ivt_loc);
+ dbuf_printf (vBuf, ";\t.area\t%s\n", CODE_NAME);
+ dbuf_printf (vBuf, ".intvecs\tcode\t0x%06x\n", pic16_options.ivt_loc);
/* this is an overkill since WE are the port,
* and we know if we have a genIVT function! */
/* emitOverlay - will emit code for the overlay stuff */
/*-----------------------------------------------------------------*/
static void
-pic16emitOverlay (FILE * afile)
+pic16emitOverlay (struct dbuf_s *aBuf)
{
set *ovrset;
if (!elementsInSet (ovrSetSets))
- fprintf (afile, ";\t.area\t%s\n", port->mem.overlay_name);
+ dbuf_printf (aBuf, ";\t.area\t%s\n", port->mem.overlay_name);
/* for each of the sets in the overlay segment do */
for (ovrset = setFirstItem (ovrSetSets); ovrset;
otherwise the assembler will append each of these
declarations into one chunk and will not overlay
sad but true */
- fprintf (afile, ";\t.area _DUMMY\n");
+ dbuf_printf (aBuf, ";\t.area _DUMMY\n");
/* output the area informtion */
- fprintf (afile, ";\t.area\t%s\n", port->mem.overlay_name); /* MOF */
+ dbuf_printf (aBuf, ";\t.area\t%s\n", port->mem.overlay_name); /* MOF */
}
for (sym = setFirstItem (ovrset); sym;
{
if (options.debug || sym->level == 0)
- fprintf (afile, " == 0x%04x\n", SPEC_ADDR (sym->etype));
+ dbuf_printf (aBuf, " == 0x%04x\n", SPEC_ADDR (sym->etype));
- fprintf (afile, "%s\t=\t0x%04x\n",
+ dbuf_printf (aBuf, "%s\t=\t0x%04x\n",
sym->rname,
SPEC_ADDR (sym->etype));
}
else
{
if (options.debug || sym->level == 0)
- fprintf (afile, "==.\n");
+ dbuf_printf (aBuf, "==.\n");
/* allocate space */
- fprintf (afile, "%s:\n", sym->rname);
- fprintf (afile, "\t.ds\t0x%04x\n", (unsigned int) getSize (sym->type) & 0xffff);
+ dbuf_printf (aBuf, "%s:\n", sym->rname);
+ dbuf_printf (aBuf, "\t.ds\t0x%04x\n", (unsigned int) getSize (sym->type) & 0xffff);
}
}
void
pic16glue ()
{
- FILE *vFile;
FILE *asmFile;
- FILE *ovrFile = tempfile();
+ struct dbuf_s ovrBuf;
+ struct dbuf_s vBuf;
+
+ dbuf_init(&ovrBuf, 4096);
+ dbuf_init(&vBuf, 4096);
mainf = newSymbol ("main", 0);
mainf->block = 0;
mainf = findSymWithLevel(SymbolTab, mainf);
- addSetHead(&tmpfileSet,ovrFile);
pic16_pCodeInitRegisters();
if(pic16_options.no_crt && mainf && IFFUNC_HASBODY(mainf->type)) {
/* print the global struct definitions */
- vFile = tempfile();
/* PENDING: this isnt the best place but it will do */
if (port->general.glue_up_main) {
/* create the interrupt vector table */
- pic16createInterruptVect (vFile);
+ pic16createInterruptVect (&vBuf);
}
- addSetHead(&tmpfileSet,vFile);
-
/* emit code for the all the variables declared */
pic16emitMaps ();
/* do the overlay segments */
- pic16emitOverlay(ovrFile);
+ pic16emitOverlay(&ovrBuf);
pic16_AnalyzepCode('*');
#if 1
fprintf (asmFile, "%s", iComments2);
fprintf (asmFile, "; external ram data\n");
fprintf (asmFile, "%s", iComments2);
- copyFile (asmFile, xdata->oFile);
+ dbuf_write_and_destroy (&xdata->oBuf, asmFile);
#endif
#if 0
fprintf (asmFile, "%s", iComments2);
fprintf (asmFile, "; bit data\n");
fprintf (asmFile, "%s", iComments2);
- copyFile (asmFile, bit->oFile);
+ dbuf_write_and_destroy (&bit->oBuf, asmFile);
#endif
/* copy the interrupt vector table */
fprintf (asmFile, "\n%s", iComments2);
fprintf (asmFile, "; interrupt vector \n");
fprintf (asmFile, "%s", iComments2);
- copyFile (asmFile, vFile);
+ dbuf_write_and_destroy (&vBuf, asmFile);
}
/* copy global & static initialisations */
}
}
-// copyFile (stderr, code->oFile);
+// dbuf_write_and_destroy (&code->oBuf, stderr);
fprintf(asmFile, "; I code from now on!\n");
pic16_copypCode(asmFile, 'I');
fprintf (asmFile,"\tend\n");
fclose (asmFile);
-
- rm_tmpfiles();
}
#include "SDCCutil.h"
#include "glue.h"
#include "pcode.h"
+#include "dbuf_string.h"
static char _defaultRules[] =
/* Generate interrupt vector table. */
static int
-_pic16_genIVT (FILE * of, symbol ** interrupts, int maxInterrupts)
+_pic16_genIVT (struct dbuf_s * oBuf, symbol ** interrupts, int maxInterrupts)
{
#if 1
/* PIC18F family has only two interrupts, the high and the low
* priority interrupts, which reside at 0x0008 and 0x0018 respectively - VR */
if((!pic16_options.omit_ivt) || (pic16_options.omit_ivt && pic16_options.leave_reset)) {
- fprintf(of, "; RESET vector\n");
- fprintf(of, "\tgoto\t__sdcc_gsinit_startup\n");
+ dbuf_printf(oBuf, "; RESET vector\n");
+ dbuf_printf(oBuf, "\tgoto\t__sdcc_gsinit_startup\n");
}
if(!pic16_options.omit_ivt) {
- fprintf(of, "\tres 4\n");
+ dbuf_printf(oBuf, "\tres 4\n");
- fprintf(of, "; High priority interrupt vector 0x0008\n");
+ dbuf_printf(oBuf, "; High priority interrupt vector 0x0008\n");
if(interrupts[1]) {
- fprintf(of, "\tgoto\t%s\n", interrupts[1]->rname);
- fprintf(of, "\tres\t12\n");
+ dbuf_printf(oBuf, "\tgoto\t%s\n", interrupts[1]->rname);
+ dbuf_printf(oBuf, "\tres\t12\n");
} else {
- fprintf(of, "\tretfie\n");
- fprintf(of, "\tres\t14\n");
+ dbuf_printf(oBuf, "\tretfie\n");
+ dbuf_printf(oBuf, "\tres\t14\n");
}
- fprintf(of, "; Low priority interrupt vector 0x0018\n");
+ dbuf_printf(oBuf, "; Low priority interrupt vector 0x0018\n");
if(interrupts[2]) {
- fprintf(of, "\tgoto\t%s\n", interrupts[2]->rname);
+ dbuf_printf(oBuf, "\tgoto\t%s\n", interrupts[2]->rname);
} else {
- fprintf(of, "\tretfie\n");
+ dbuf_printf(oBuf, "\tretfie\n");
}
}
#endif
packForPush (iCode * ic, eBBlock * ebp)
{
iCode *dic;
+ char *iLine;
debugLog ("%s\n", __FUNCTION__);
if (ic->op != IPUSH || !IS_ITEMP (IC_LEFT (ic)))
#if 0
{
int n1, n2;
+ char *iLine;
n1 = bitVectnBitsOn( OP_DEFS(IC_LEFT(ic)));
n2 = bitVectnBitsOn( OP_USES(IC_LEFT(ic)));
+ iLine = printILine(ic);
debugf3("defs: %d\tuses: %d\t%s\n", n1, n2, printILine(ic));
+ dbuf_free(iLine);
debugf2("IC_LEFT(ic): from %d to %d\n", OP_LIVEFROM(IC_LEFT(ic)), OP_LIVETO(IC_LEFT(ic)));
}
#endif
and the that the definition is an assignment */
IC_LEFT (ic) = IC_RIGHT (dic);
- debugf("remiCodeFromeBBlock: %s\n", printILine(dic));
+ iLine = printILine(dic);
+ debugf("remiCodeFromeBBlock: %s\n", iLine);
+ dbuf_free(iLine);
remiCodeFromeBBlock (ebp, dic);
bitVectUnSetBit(OP_SYMBOL(IC_RESULT(dic))->defs,dic->key);
if(!pic16_ralloc_debug)return;
debugLog (" %s Symbol type: ",str);
- printTypeChain( sl, debugF);
+ printTypeChain (sl, debugF);
debugLog ("\n");
}
#include "SDCCicode.h"
#include "SDCCargs.h"
#include "SDCCpeeph.h"
+#include "dbuf.h"
#include "mcs51/peep.h"
#define TARGET_ID_MCS51 1
* it returns zero, default (8051) IVT generation code
* will be used.
*/
- int (*genIVT) (FILE * of, symbol ** intTable, int intCount);
+ int (*genIVT) (struct dbuf_s *oBuf, symbol ** intTable, int intCount);
void (*genXINIT) (FILE * of);
# End Source File\r
# Begin Source File\r
\r
+SOURCE=..\support\Util\dbuf_string.c\r
+# End Source File\r
+# Begin Source File\r
+\r
SOURCE=..\support\Util\MySystem.c\r
# End Source File\r
# Begin Source File\r
# End Source File\r
# Begin Source File\r
\r
+SOURCE=..\support\Util\dbuf_string.h\r
+# End Source File\r
+# Begin Source File\r
+\r
SOURCE=..\support\Util\MySystem.h\r
# End Source File\r
# Begin Source File\r
extern int xa51_ptrRegReq;
extern int xa51_nRegs;
-extern FILE *codeOutFile;
+extern struct dbuf_s *codeOutBuf;
static lineNode *lineHead = NULL;
static lineNode *lineCurr = NULL;
emitcode (";", "genFunction %s", sym->rname);
/* print the allocation information */
- printAllocInfo (currFunc, codeOutFile);
+ printAllocInfo (currFunc, codeOutBuf);
emitcode ("", "%s:", sym->rname);
cln = ic->lineno;
}
if (options.iCodeInAsm) {
- emitcode("", ";ic:%d: %s", ic->key, printILine(ic));
+ char *iLine = printILine(ic);
+ emitcode("", ";ic:%d: %s", ic->key, iLine);
+ dbuf_free(iLine);
}
/* if the result is marked as
peepHole (&lineHead);
/* now do the actual printing */
- printLine (lineHead, codeOutFile);
+ printLine (lineHead, codeOutBuf);
return;
}
/* Generate interrupt vector table. */
static int
-_xa51_genIVT (FILE * of, symbol ** interrupts, int maxInterrupts)
+_xa51_genIVT (struct dbuf_s * oBuf, symbol ** interrupts, int maxInterrupts)
{
return TRUE;
}
static char **_fReturn;
static char **_fTmp;
-extern FILE *codeOutFile;
+extern struct dbuf_s *codeOutBuf;
enum
{
}
static lineNode *
-_newLineNode (char *line)
+_newLineNode (const char *line)
{
lineNode *pl;
static void
_vemit2 (const char *szFormat, va_list ap)
{
- char buffer[INITIAL_INLINEASM];
+ struct dbuf_s dbuf;
+ const char *buffer;
- tvsprintf (buffer, sizeof(buffer), szFormat, ap);
+ dbuf_init(&dbuf, INITIAL_INLINEASM);
- _tidyUp (buffer);
+ dbuf_tvprintf (&dbuf, szFormat, ap);
+
+ buffer = dbuf_c_str(&dbuf);
+
+ _tidyUp ((char *)buffer);
_G.lines.current = (_G.lines.current ?
connectLine (_G.lines.current, _newLineNode (buffer)) :
(_G.lines.head = _newLineNode (buffer)));
_G.lines.current->isDebug = _G.lines.isDebug;
_G.lines.current->ic = _G.current_iCode;
_G.lines.current->isComment = (*buffer == ';');
+
+ dbuf_destroy(&dbuf);
}
static void
}
if (options.iCodeInAsm)
{
- emit2 (";ic:%d: %s", ic->key, printILine(ic));
+ char *iLine = printILine(ic);
+ emit2 (";ic:%d: %s", ic->key, iLine);
+ dbuf_free(iLine);
}
/* if the result is marked as
spilt and rematerializable or code for
/* This is unfortunate */
/* now do the actual printing */
{
- FILE *fp = codeOutFile;
- if (isInHome () && codeOutFile == code->oFile)
- codeOutFile = home->oFile;
- printLine (_G.lines.head, codeOutFile);
+ struct dbuf_s *buf = codeOutBuf;
+ if (isInHome () && codeOutBuf == &code->oBuf)
+ codeOutBuf = &home->oBuf;
+ printLine (_G.lines.head, codeOutBuf);
if (_G.flushStatics)
{
flushStatics ();
_G.flushStatics = 0;
}
- codeOutFile = fp;
+ codeOutBuf = buf;
}
freeTrace(&_G.lines.trace);
#include "MySystem.h"
#include "BuildCmd.h"
#include "SDCCutil.h"
-#include "dbuf.h"
+#include "dbuf_string.h"
static char _z80_defaultRules[] =
{
for (s = setFirstItem(libDirsSet); s != NULL; s = setNextItem(libDirsSet))
{
buildCmdLine2(path, sizeof path, "-k\"%s" DIR_SEPARATOR_STRING "{port}\" ", s);
- dbuf_append(&dbuf, path, strlen(path));
+ dbuf_append_str(&dbuf, path);
}
buildCmdLine2(path, sizeof path, "-l\"{port}.lib\"", s);
- dbuf_append(&dbuf, path, strlen(path));
+ dbuf_append_str(&dbuf, path);
setMainValue ("z80libspec", dbuf_c_str(&dbuf));
dbuf_destroy(&dbuf);
/*
dbuf.c - Dynamic buffer implementation
- version 1.1.3, December 17th, 2006
+ version 1.2.0, January 6th, 2007
- Copyright (c) 2002-2006 Borut Razem
+ Copyright (c) 2002-2007 Borut Razem
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
/*
* Assure that the buffer is large enough to hold
- * size bytes; enlarge it if necessary.
+ * current length + size bytes; enlarge it if necessary.
+ *
+ * Intended for internal use.
*/
-static int dbuf_expand(struct dbuf_s *dbuf, size_t size)
+int _dbuf_expand(struct dbuf_s *dbuf, size_t size)
{
assert(dbuf->alloc != 0);
assert(dbuf->buf != NULL);
* Set the buffer size. Buffer size can be only decreased.
*/
-int dbuf_set_size(struct dbuf_s *dbuf, size_t size)
+int dbuf_set_length(struct dbuf_s *dbuf, size_t len)
{
assert(dbuf != NULL);
assert(dbuf->alloc != 0);
- assert(size <= dbuf->len);
+ assert(len <= dbuf->len);
- if (size <= dbuf->len) {
- dbuf->len = size;
+ if (len <= dbuf->len) {
+ dbuf->len = len;
return 1;
}
* Append the buf to the end of the buffer.
*/
-int dbuf_append(struct dbuf_s *dbuf, const void *buf, size_t size)
+int dbuf_append(struct dbuf_s *dbuf, const void *buf, size_t len)
{
assert(dbuf != NULL);
assert(dbuf->alloc != 0);
assert(dbuf->buf != NULL);
- if (dbuf_expand(dbuf, size) != 0) {
- memcpy(&(((char *)dbuf->buf)[dbuf->len]), buf, size);
- dbuf->len += size;
+ if (_dbuf_expand(dbuf, len) != 0) {
+ memcpy(&(((char *)dbuf->buf)[dbuf->len]), buf, len);
+ dbuf->len += len;
return 1;
}
assert(dbuf->alloc != 0);
assert(dbuf->buf != NULL);
- dbuf_expand(dbuf, 1);
- ((char *)dbuf->buf)[dbuf->len] = '\0';
+ if (_dbuf_expand(dbuf, 1) != 0) {
+ ((char *)dbuf->buf)[dbuf->len] = '\0';
+ return dbuf->buf;
+ }
- return dbuf->buf;
+ return NULL;
}
/*
- * Get the buffer size.
+ * Get the buffer length.
*/
-size_t dbuf_get_size(struct dbuf_s *dbuf)
+size_t dbuf_get_length(struct dbuf_s *dbuf)
{
assert(dbuf != NULL);
assert(dbuf->alloc != 0);
dbuf_destroy(dbuf);
free(dbuf);
}
+
+
+/*
+ * Free detached buffer.
+ *
+ * See dbuf_detach()
+ */
+
+void dbuf_free(const void *buf)
+{
+ free((void *)buf);
+}
/*
dbuf.h - Dynamic buffer interface
- version 1.1.1, April 11th, 2003
+ version 1.2.0, January 6th, 2007
- Copyright (c) 2002-2003 Borut Razem
+ Copyright (c) 2002-2007 Borut Razem
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
struct dbuf_s {
size_t alloc; /* size of allocated buffer in bytes */
- size_t len; /* actual size of the buffer in bytes */
+ size_t len; /* actual length of the buffer in bytes */
void *buf; /* pointer to the buffer, allocated on heap */
};
extern "C" {
#endif
+int _dbuf_expand(struct dbuf_s *dbuf, size_t size);
struct dbuf_s *dbuf_new(size_t size);
int dbuf_init(struct dbuf_s *dbuf, size_t size);
-int dbuf_set_size(struct dbuf_s *dbuf, size_t size);
-int dbuf_append(struct dbuf_s *dbuf, const void *buf, size_t size);
+int dbuf_set_length(struct dbuf_s *dbuf, size_t size);
+int dbuf_append(struct dbuf_s *dbuf, const void *buf, size_t len);
const void *dbuf_get_buf(struct dbuf_s *dbuf);
-size_t dbuf_get_size(struct dbuf_s *dbuf);
+size_t dbuf_get_length(struct dbuf_s *dbuf);
const char *dbuf_c_str(struct dbuf_s *dbuf);
int dbuf_trim(struct dbuf_s *dbuf);
void *dbuf_detach(struct dbuf_s *dbuf);
void dbuf_destroy(struct dbuf_s *dbuf);
void dbuf_delete(struct dbuf_s *dbuf);
+void dbuf_free(const void *buf);
#ifdef __cplusplus
}
--- /dev/null
+/*
+ dbuf_string.c - Append formatted string to the dynamic buffer
+ version 1.0.0, January 6th, 2007
+
+ Copyright (c) 2002-2007 Borut Razem
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street - Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <assert.h>
+#include "dbuf_string.h"
+
+
+/*
+ * Append string to the end of the buffer.
+ */
+
+int
+dbuf_append_str(struct dbuf_s *dbuf, const char *str)
+{
+ assert(str != NULL);
+
+ return dbuf_append(dbuf, str, strlen(str));
+}
+
+
+/*
+ * Append single character to the end of the buffer.
+ */
+
+int
+dbuf_append_char(struct dbuf_s *dbuf, char chr)
+{
+ return dbuf_append(dbuf, &chr, 1);
+}
+
+/*
+ * Calculate length of the resulting formatted string.
+ *
+ * Borrowed from vasprintf.c
+ */
+
+static int
+calc_result_length (const char *format, va_list args)
+{
+ const char *p = format;
+ /* Add one to make sure that it is never zero, which might cause malloc
+ to return NULL. */
+ int total_width = strlen (format) + 1;
+ va_list ap;
+
+ memcpy (&ap, &args, sizeof (va_list));
+
+ while (*p != '\0')
+ {
+ if (*p++ == '%')
+ {
+ while (strchr ("-+ #0", *p))
+ ++p;
+ if (*p == '*')
+ {
+ ++p;
+ total_width += abs (va_arg (ap, int));
+ }
+ else
+ total_width += strtoul (p, (char **) &p, 10);
+ if (*p == '.')
+ {
+ ++p;
+ if (*p == '*')
+ {
+ ++p;
+ total_width += abs (va_arg (ap, int));
+ }
+ else
+ total_width += strtoul (p, (char **) &p, 10);
+ }
+ while (strchr ("hlL", *p))
+ ++p;
+ /* Should be big enough for any format specifier except %s and floats. */
+ total_width += 30;
+ switch (*p)
+ {
+ case 'd':
+ case 'i':
+ case 'o':
+ case 'u':
+ case 'x':
+ case 'X':
+ case 'c':
+ (void) va_arg (ap, int);
+ break;
+ case 'f':
+ case 'e':
+ case 'E':
+ case 'g':
+ case 'G':
+ (void) va_arg (ap, double);
+ /* Since an ieee double can have an exponent of 307, we'll
+ make the buffer wide enough to cover the gross case. */
+ total_width += 307;
+ break;
+ case 's':
+ total_width += strlen (va_arg (ap, char *));
+ break;
+ case 'p':
+ case 'n':
+ (void) va_arg (ap, char *);
+ break;
+ }
+ p++;
+ }
+ }
+
+ return total_width;
+}
+
+
+/*
+ * Append the formatted string to the end of the buffer.
+ */
+
+int
+dbuf_vprintf (struct dbuf_s *dbuf, const char *format, va_list args)
+{
+ int size = calc_result_length (format, args);
+
+ assert(dbuf != NULL);
+ assert(dbuf->alloc != 0);
+ assert(dbuf->buf != NULL);
+
+ if (_dbuf_expand(dbuf, size) != 0) {
+ int len = vsprintf(&(((char *)dbuf->buf)[dbuf->len]), format, args);
+
+ if (len >= 0) {
+ /* if written length is greater then the calculated one,
+ we have a buffer overrun! */
+ assert(len <= size);
+ dbuf->len += len;
+ }
+ return len;
+ }
+
+ return 0;
+}
+
+
+/*
+ * Append the formatted string to the end of the buffer.
+ */
+
+int
+dbuf_printf (struct dbuf_s *dbuf, const char *format, ...)
+{
+ va_list arg;
+ int len;
+
+ va_start (arg, format);
+ len = dbuf_vprintf(dbuf, format, arg);
+ va_end (arg);
+
+ return len;
+}
+
+
+/*
+ * Write dynamic buffer to the file.
+ */
+
+void
+dbuf_write (struct dbuf_s *dbuf, FILE *dest)
+{
+ fwrite(dbuf_get_buf(dbuf), 1, dbuf_get_length(dbuf), dest);
+}
+
+
+/*
+ * Write dynamic buffer to the file and destroy it.
+ */
+
+void
+dbuf_write_and_destroy (struct dbuf_s *dbuf, FILE *dest)
+{
+ dbuf_write (dbuf, dest);
+
+ dbuf_destroy(dbuf);
+}
--- /dev/null
+/*
+ dbuf_string.h - Append formatted string to the dynamic buffer
+ version 1.0.0, January 6th, 2007
+
+ Copyright (c) 2002-2007 Borut Razem
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street - Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+
+#ifndef __DBUF_STRING_H
+#define __DBUF_STRING_H
+
+#include <stdarg.h>
+#include "dbuf.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int dbuf_append_str(struct dbuf_s *dbuf, const char *str);
+int dbuf_append_char(struct dbuf_s *dbuf, char chr);
+int dbuf_vprintf(struct dbuf_s *dbuf, const char *format, va_list args);
+int dbuf_printf (struct dbuf_s *dbuf, const char *format, ...);
+void dbuf_write (struct dbuf_s *dbuf, FILE *dest);
+void dbuf_write_and_destroy (struct dbuf_s *dbuf, FILE *dest);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __DBUF_STRING_H */