unsigned maxInterrupts = 6;
int allocInfo = 1;
symbol *mainf;
-extern char *VersionString;
+set *pipeSet = NULL; /* set of pipes */
set *tmpfileSet = NULL; /* set of tmp file created by the compiler */
set *tmpfileNameSet = NULL; /* All are unlinked at close. */
+/*-----------------------------------------------------------------*/
+/* closePipes - closes all pipes created by the compiler */
+/*-----------------------------------------------------------------*/
+DEFSETFUNC (closePipes)
+{
+ FILE *pfile = item;
+ int ret;
+
+ if (pfile) {
+ ret = pclose (pfile);
+ assert(ret != -1);
+ }
+
+ return 0;
+}
+
/*-----------------------------------------------------------------*/
/* closeTmpFiles - closes all tmp files created by the compiler */
/* because of BRAIN DEAD MS/DOS & CYGNUS Libraries */
DEFSETFUNC (closeTmpFiles)
{
FILE *tfile = item;
+ int ret;
- if (tfile)
- fclose (tfile);
+ if (tfile) {
+ ret = fclose (tfile);
+ assert(ret == 0);
+ }
return 0;
}
DEFSETFUNC (rmTmpFiles)
{
char *name = item;
+ int ret;
- if (name)
- {
- unlink (name);
+ if (name) {
+ ret = unlink (name);
+ assert(ret == 0);
Safe_free (name);
- }
+ }
+
return 0;
}
rm_tmpfiles (void)
{
/* close temporary files */
+ applyToSet (pipeSet, closePipes);
+ /* close temporary files */
+ deleteSet (&pipeSet);
+
applyToSet (tmpfileSet, closeTmpFiles);
/* remove temporary files */
applyToSet (tmpfileNameSet, rmTmpFiles);
continue;
/* print extra debug info if required */
- if (options.debug) {
- cdbSymbol (sym, cdbFile, FALSE, FALSE);
- if (!sym->level) /* global */
- if (IS_STATIC (sym->etype))
- fprintf (map->oFile, "F%s$", moduleName); /* scope is file */
+ if (options.debug)
+ {
+ if (!sym->level) /* global */
+ {
+ if (IS_STATIC (sym->etype))
+ fprintf (map->oFile, "F%s$", moduleName); /* scope is file */
+ else
+ fprintf (map->oFile, "G$"); /* scope is global */
+ }
else
- fprintf (map->oFile, "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);
- }
+ {
+ /* 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);
+ }
/* if it has an initial value then do it only if
it is a global variable */
if (sym->ival && sym->level == 0) {
if (SPEC_OCLS(sym->etype)==xidata) {
- // create a new "XINIT (CODE)" symbol, that will be emitted later
+ /* create a new "XINIT (CODE)" symbol, that will be emitted later
+ in the static seg */
newSym=copySymbol (sym);
SPEC_OCLS(newSym->etype)=xinit;
SNPRINTF (newSym->name, sizeof(newSym->name), "__xinit_%s", sym->name);
/* address of symbol */
if (IS_AST_SYM_VALUE (expr->left)) {
val = copyValue (AST_VALUE (expr->left));
- val->type = newLink ();
+ val->type = newLink (DECLARATOR);
if (SPEC_SCLS (expr->left->etype) == S_CODE) {
DCL_TYPE (val->type) = CPOINTER;
DCL_PTR_CONST (val->type) = port->mem.code_ro;
IS_ARRAY(expr->right->ftype)) {
val = copyValue (AST_VALUE (expr->right));
- val->type = newLink ();
+ val->type = newLink (DECLARATOR);
if (SPEC_SCLS (expr->right->etype) == S_CODE) {
DCL_TYPE (val->type) = CPOINTER;
DCL_PTR_CONST (val->type) = port->mem.code_ro;
void
_printPointerType (FILE * oFile, const char *name)
{
- /* if (TARGET_IS_DS390) */
if (options.model == MODEL_FLAT24)
{
fprintf (oFile, "\t.byte %s,(%s >> 8),(%s >> 16)", name, name, name);
if (ilist->type == INIT_DEEP)
ilist = ilist->init.deep;
- if (!IS_AGGREGATE(sym->type) && getNelements(type, ilist)>1) {
- werror (W_EXCESS_INITIALIZERS, "scalar", sym->name, sym->lineDef);
- }
-
if (!(val = list2val (ilist))) {
// assuming a warning has been thrown
val=constVal("0");
FILE * oFile)
{
initList *iloop;
- int lcnt = 0, size = 0;
- sym_link *last_type;
+ int size = 0;
/* take care of the special case */
/* array of characters can be init */
return;
}
- iloop = ilist->init.deep;
- lcnt = DCL_ELEM (type);
- for (last_type = type->next; last_type && DCL_ELEM (last_type); last_type = last_type->next)
- lcnt *= DCL_ELEM (last_type);
-
- for (;;)
+ for (iloop=ilist->init.deep; iloop; iloop=iloop->next)
{
- size++;
printIval (sym, type->next, iloop, oFile);
- iloop = (iloop ? iloop->next : NULL);
-
-
- /* if not array limits given & we */
- /* are out of initialisers then */
- if (!DCL_ELEM (type) && !iloop)
- break;
-
- /* no of elements given and we */
- /* have generated for all of them */
- if (!--lcnt) {
- /* if initializers left */
- if (iloop) {
- werror (W_EXCESS_INITIALIZERS, "array", sym->name, sym->lineDef);
- }
+
+ if (++size > DCL_ELEM(type)) {
+ werror (W_EXCESS_INITIALIZERS, "array", sym->name, sym->lineDef);
break;
}
}
-
- /* if we have not been given a size */
- if (!DCL_ELEM (type))
+
+ if (DCL_ELEM(type)) {
+ // pad with zeros if needed
+ if (size<DCL_ELEM(type)) {
+ size = (DCL_ELEM(type) - size) * getSize(type->next);
+ while (size--) {
+ tfprintf (oFile, "\t!db !constbyte\n", 0);
+ }
+ }
+ } else {
+ // we have not been given a size, but we now know it
DCL_ELEM (type) = size;
+ }
return;
}
void
printIval (symbol * sym, sym_link * type, initList * ilist, FILE * oFile)
{
+ sym_link *itype;
+
if (!ilist)
return;
return;
}
- /* if this is a pointer */
- if (IS_PTR (type))
+ /* if this is an array */
+ if (IS_ARRAY (type))
{
- printIvalPtr (sym, type, ilist, oFile);
+ printIvalArray (sym, type, ilist, oFile);
return;
}
- /* if this is an array */
- if (IS_ARRAY (type))
+ // not an aggregate, ilist must be a node
+ if (ilist->type!=INIT_NODE) {
+ // or a 1-element list
+ if (ilist->init.deep->next) {
+ werror (W_EXCESS_INITIALIZERS, "scalar",
+ sym->name, sym->lineDef);
+ } else {
+ ilist=ilist->init.deep;
+ }
+ }
+
+ // and the type must match
+ itype=ilist->init.node->ftype;
+
+ if (compareType(type, itype)==0) {
+ // special case for literal strings
+ if (IS_ARRAY (itype) && IS_CHAR (getSpec(itype)) &&
+ // which are really code pointers
+ IS_PTR(type) && DCL_TYPE(type)==CPOINTER) {
+ // no sweat
+ } else {
+ werror (E_TYPE_MISMATCH, "assignment", " ");
+ printFromToType(itype, type);
+ }
+ }
+
+ /* if this is a pointer */
+ if (IS_PTR (type))
{
- printIvalArray (sym, type, ilist, oFile);
+ printIvalPtr (sym, type, ilist, oFile);
return;
}
/* print extra debug info if required */
if (options.debug) {
- cdbSymbol (sym, cdbFile, FALSE, FALSE);
+
if (!sym->level)
{ /* global */
if (IS_STATIC (sym->etype))
resolveIvalSym (sym->ival);
printIval (sym, sym->type, sym->ival, out);
noAlloc--;
- // if sym->ival is a string, WE don't need it anymore
- if (IS_AST_SYM_VALUE(list2expr(sym->ival)) &&
+ /* if sym is a simple string and sym->ival is a string,
+ WE don't need it anymore */
+ if (IS_ARRAY(sym->type) && IS_CHAR(sym->type->next) &&
+ IS_AST_SYM_VALUE(list2expr(sym->ival)) &&
list2val(sym->ival)->sym->isstrlit) {
freeStringSymbol(list2val(sym->ival)->sym);
}
time_t t;
time (&t);
fprintf (afile, "%s", iComments1);
- fprintf (afile, "; Version %s %s\n", VersionString, asctime (localtime (&t)));
+ fprintf (afile, "; Version " SDCC_VERSION_STR " %s\n", asctime (localtime (&t)));
fprintf (afile, "%s", iComments2);
}
/* print extra debug info if required */
if (options.debug)
{
- cdbSymbol (sym, cdbFile, FALSE, FALSE);
-
if (!sym->level)
{ /* global */
if (IS_STATIC (sym->etype))
}
}
+
+/*-----------------------------------------------------------------*/
+/* spacesToUnderscores - replace spaces with underscores */
+/*-----------------------------------------------------------------*/
+static char *
+spacesToUnderscores (char *dest, const char *src, size_t len)
+{
+ int i;
+ char *p;
+
+ assert(dest != NULL);
+ assert(src != NULL);
+ assert(len > 0);
+
+ --len;
+ for (p = dest, i = 0; *src != '\0' && i < len; ++src, ++i) {
+ *p++ = isspace(*src) ? '_' : *src;
+ }
+ *p = '\0';
+
+ return dest;
+}
+
+
/*-----------------------------------------------------------------*/
/* glue - the final glue that hold the whole thing together */
/*-----------------------------------------------------------------*/
FILE *vFile;
FILE *asmFile;
FILE *ovrFile = tempfile ();
+ char moduleBuf[PATH_MAX];
+ int mcs51_like;
+
+ if(port->general.glue_up_main &&
+ (TARGET_IS_MCS51 || TARGET_IS_DS390 || TARGET_IS_XA51 || TARGET_IS_DS400))
+ {
+ mcs51_like=1; /*So it has bits, sfr, sbits, data, idata, etc...*/
+ }
+ else
+ {
+ mcs51_like=0;
+ }
addSetHead (&tmpfileSet, ovrFile);
/* print the global struct definitions */
if (options.debug)
- cdbStructBlock (0, cdbFile);
+ cdbStructBlock (0);
vFile = tempfile ();
/* PENDING: this isnt the best place but it will do */
/* do the overlay segments */
emitOverlay (ovrFile);
+ outputDebugSymbols();
+
/* now put it all together into the assembler file */
/* create the assembler file name */
initialComments (asmFile);
/* print module name */
- tfprintf (asmFile, "\t!module\n", moduleName);
+ tfprintf (asmFile, "\t!module\n",
+ spacesToUnderscores (moduleBuf, moduleName, sizeof moduleBuf));
+ if(mcs51_like)
+ {
+ fprintf (asmFile, "\t.optsdcc -m%s", port->target);
+
+ switch(options.model)
+ {
+ case MODEL_SMALL: fprintf (asmFile, " --model-small"); break;
+ case MODEL_COMPACT: fprintf (asmFile, " --model-compact"); break;
+ case MODEL_MEDIUM: fprintf (asmFile, " --model-medium"); break;
+ case MODEL_LARGE: fprintf (asmFile, " --model-large"); break;
+ case MODEL_FLAT24: fprintf (asmFile, " --model-flat24"); break;
+ case MODEL_PAGE0: fprintf (asmFile, " --model-page0"); break;
+ default: break;
+ }
+ /*if(options.stackAuto) fprintf (asmFile, " --stack-auto");*/
+ if(options.useXstack) fprintf (asmFile, " --xstack");
+ /*if(options.intlong_rent) fprintf (asmFile, " --int-long-rent");*/
+ /*if(options.float_rent) fprintf (asmFile, " --float-rent");*/
+ if(options.noRegParams) fprintf (asmFile, " --no-reg-params");
+ if(options.parms_in_bank1) fprintf (asmFile, " --parms-in-bank1");
+ fprintf (asmFile, "\n");
+ }
+ else if(TARGET_IS_Z80 || TARGET_IS_GBZ80 )
+ {
+ fprintf (asmFile, "\t.optsdcc -m%s\n", port->target);
+ }
+
tfprintf (asmFile, "\t!fileprelude\n");
/* Let the port generate any global directives, etc. */
if (port->assembler.externGlobal)
printExterns (asmFile);
- /* copy the sfr segment */
- fprintf (asmFile, "%s", iComments2);
- fprintf (asmFile, "; special function registers\n");
- fprintf (asmFile, "%s", iComments2);
- copyFile (asmFile, sfr->oFile);
+ if(mcs51_like)
+ {
+ /* copy the sfr segment */
+ fprintf (asmFile, "%s", iComments2);
+ fprintf (asmFile, "; special function registers\n");
+ fprintf (asmFile, "%s", iComments2);
+ copyFile (asmFile, sfr->oFile);
- /* copy the sbit segment */
- fprintf (asmFile, "%s", iComments2);
- fprintf (asmFile, "; special function bits \n");
- fprintf (asmFile, "%s", iComments2);
- copyFile (asmFile, sfrbit->oFile);
+ /* copy the sbit segment */
+ fprintf (asmFile, "%s", iComments2);
+ fprintf (asmFile, "; special function bits \n");
+ fprintf (asmFile, "%s", iComments2);
+ copyFile (asmFile, sfrbit->oFile);
- /*JCF: Create the areas for the register banks*/
- if(port->general.glue_up_main &&
- (TARGET_IS_MCS51 || TARGET_IS_DS390 || TARGET_IS_XA51))
- {
+ /*JCF: Create the areas for the register banks*/
if(RegBankUsed[0]||RegBankUsed[1]||RegBankUsed[2]||RegBankUsed[3])
{
fprintf (asmFile, "%s", iComments2);
/* copy the data segment */
fprintf (asmFile, "%s", iComments2);
- fprintf (asmFile, "; internal ram data\n");
+ fprintf (asmFile, "; %s ram data\n", mcs51_like?"internal":"");
fprintf (asmFile, "%s", iComments2);
copyFile (asmFile, data->oFile);
/* create the overlay segments */
if (overlay) {
fprintf (asmFile, "%s", iComments2);
- fprintf (asmFile, "; overlayable items in internal ram \n");
+ fprintf (asmFile, "; overlayable items in %s ram \n", mcs51_like?"internal":"");
fprintf (asmFile, "%s", iComments2);
copyFile (asmFile, ovrFile);
}
}
/* create the idata segment */
- if (idata) {
+ if ( (idata) && (mcs51_like) ) {
fprintf (asmFile, "%s", iComments2);
fprintf (asmFile, "; indirectly addressable internal ram data\n");
fprintf (asmFile, "%s", iComments2);
}
/* copy the bit segment */
- fprintf (asmFile, "%s", iComments2);
- fprintf (asmFile, "; bit data\n");
- fprintf (asmFile, "%s", iComments2);
- copyFile (asmFile, bit->oFile);
+ if (mcs51_like) {
+ fprintf (asmFile, "%s", iComments2);
+ fprintf (asmFile, "; bit data\n");
+ fprintf (asmFile, "%s", iComments2);
+ copyFile (asmFile, bit->oFile);
+ }
/* if external stack then reserve space of it */
if (mainf && IFFUNC_HASBODY(mainf->type) && options.useXstack)
/* copy xtern ram data */
- fprintf (asmFile, "%s", iComments2);
- fprintf (asmFile, "; external ram data\n");
- fprintf (asmFile, "%s", iComments2);
- copyFile (asmFile, xdata->oFile);
+ if (mcs51_like) {
+ fprintf (asmFile, "%s", iComments2);
+ fprintf (asmFile, "; external ram data\n");
+ fprintf (asmFile, "%s", iComments2);
+ copyFile (asmFile, xdata->oFile);
+ }
/* copy xternal initialized ram data */
fprintf (asmFile, "%s", iComments2);
fprintf (asmFile, "%s", iComments2);
copyFile (asmFile, xidata->oFile);
+ /* If the port wants to generate any extra areas, let it do so. */
+ if (port->extraAreas.genExtraAreaDeclaration)
+ {
+ port->extraAreas.genExtraAreaDeclaration(asmFile,
+ mainf && IFFUNC_HASBODY(mainf->type));
+ }
+
/* copy the interrupt vector table */
if (mainf && IFFUNC_HASBODY(mainf->type))
{
(unsigned int) options.xdata_loc & 0xff);
}
- /* initialise the stack pointer. JCF: aslink takes care of the location */
- fprintf (asmFile, "\tmov\tsp,#__start__stack - 1\n"); /* MOF */
+ // This should probably be a port option, but I'm being lazy.
+ // on the 400, the firmware boot loader gives us a valid stack
+ // (see '400 data sheet pg. 85 (TINI400 ROM Initialization code)
+ if (!TARGET_IS_DS400)
+ {
+ /* initialise the stack pointer. JCF: aslink takes care of the location */
+ fprintf (asmFile, "\tmov\tsp,#__start__stack - 1\n"); /* MOF */
+ }
fprintf (asmFile, "\tlcall\t__sdcc_external_startup\n");
fprintf (asmFile, "\tmov\ta,dpl\n");
if ((tmpdir = getenv ("TEMP")) == NULL)
tmpdir = getenv ("TMPDIR");
-#ifndef _WIN32
+#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 /usr/tmp and /tmp on Un*x systems */
struct stat statbuf;
char fnamebuf[PATH_MAX];
if ((fd = tempfileandname(fnamebuf, sizeof fnamebuf)) == -1) {
- fprintf(stderr, "Can't create temporary file name!");
+ fprintf(stderr, "Can't create temporary file!");
exit(1);
}
addSetHead(&tmpfileNameSet, tmp);
if ((fp = fdopen(fd, "w+b")) == NULL) {
- perror("Can't create temporary file name!");
+ perror("Can't create temporary file!");
exit(1);
}