void printIval (symbol *, sym_link *, initList *, FILE *);
extern int noAlloc;
extern set *publics;
-extern int maxInterrupts;
+extern unsigned maxInterrupts;
extern int maxRegBank;
extern symbol *mainf;
extern char *VersionString;
/* if it is a float then it gets tricky */
/* otherwise it is fairly simple */
if (!IS_FLOAT(val->type)) {
- unsigned long v = floatFromVal(val);
+ unsigned long v = (unsigned long) floatFromVal(val);
//v >>= (offset * 8);
return ( (v >> (offset * 8)) & 0xff);
static void
pic14createInterruptVect (FILE * vFile)
{
- int i = 0;
+ unsigned i = 0;
mainf = newSymbol ("main", 0);
mainf->block = 0;
}
/* if the main is only a prototype ie. no body then do nothing */
- if (!mainf->fbody)
+ if (!IFFUNC_HASBODY(mainf->type))
{
/* if ! compile only then main function should be present */
if (!options.cc_only)
/* glue - the final glue that hold the whole thing together */
/*-----------------------------------------------------------------*/
void
-pic14glue ()
+picglue ()
{
FILE *vFile;
FILE *asmFile;
FILE *ovrFile = tempfile();
int i;
+ set *s=NULL,*t=NULL;
+ char a=1,b=2,c=3;
+
+
+ addSet(&s,&a);
+ addSet(&s,&b);
+ addSet(&s,&c);
+
+ DFPRINTF((stderr,"\n\n\n******************\n\n\n"));
+ for(t=s; t; t=t->next) {
+ if(t->item)
+ DFPRINTF((stderr,"Set item %d\n",*(char *)t->item));
+ }
+
+ s =reverseSet(s);
+ for(t=s; t; t=t->next) {
+ if(t->item)
+ DFPRINTF((stderr,"Set item %d\n",*(char *)t->item));
+ }
addSetHead(&tmpfileSet,ovrFile);
+
+
+ if (mainf && IFFUNC_HASBODY(mainf->type)) {
+
+ pBlock *pb = newpCodeChain(NULL,'X',newpCodeCharP("; Starting pCode block"));
+ addpBlock(pb);
+
+ /* entry point @ start of CSEG */
+ addpCode2pBlock(pb,newpCodeLabelStr("__sdcc_program_startup"));
+ /* put in the call to main */
+ addpCode2pBlock(pb,newpCode(POC_CALL,newpCodeOp("_main",PO_STR)));
+
+ if (options.mainreturn) {
+
+ addpCode2pBlock(pb,newpCodeCharP(";\treturn from main will return to caller\n"));
+ addpCode2pBlock(pb,newpCode(POC_RETURN,NULL));
+
+ } else {
+
+ addpCode2pBlock(pb,newpCodeCharP(";\treturn from main will lock up\n"));
+ addpCode2pBlock(pb,newpCode(POC_GOTO,newpCodeOp("$",PO_STR)));
+
+ }
+ }
+
+
+ /* At this point we've got all the code in the form of pCode structures */
+ /* Now it needs to be rearranged into the order it should be placed in the */
+ /* code space */
+
+ movepBlock2Head(code->dbName); // Last
+ movepBlock2Head('X');
+ movepBlock2Head(statsg->dbName); // First
+
+
+ AnalyzepCode('*'); //code->dbName);
+#ifdef PCODE_DEBUG
+ printCallTree(stderr);
+#endif
+
/* print the global struct definitions */
if (options.debug)
cdbStructBlock (0,cdbFile);
/* Put all variables into a cblock */
- fprintf (asmFile, "\n\n\tcblock 0x13\n\n");
+ fprintf (asmFile, "\n\n\tcblock 0x20\n\n");
for(i=0; i<pic14_nRegs; i++) {
if(regspic14[i].wasUsed && (regspic14[i].offset>=0x0c) )
fprintf (asmFile, "\t%s\n",regspic14[i].name);
}
- //fprintf (asmFile, "\tr0x0C\n");
- //fprintf (asmFile, "\tr0x0D\n");
+
/* For now, create a "dpl" and a "dph" in the register space */
/* of the pic so that we can use the same calling mechanism */
fprintf (asmFile, "; dpl and dph to emulate the 8051 calling mechanism \n");
fprintf (asmFile, "%s", iComments2);
- fprintf (asmFile, "\tdph\n");
-
-
/* copy the sbit segment */
fprintf (asmFile, "%s", iComments2);
fprintf (asmFile, "%s", iComments2);
copyFile (asmFile, data->oFile);
+ fprintf (asmFile, "\tendc\n");
+
/* create the overlay segments */
fprintf (asmFile, "%s", iComments2);
copyFile (asmFile, ovrFile);
/* create the stack segment MOF */
- if (mainf && mainf->fbody) {
+ if (mainf && IFFUNC_HASBODY(mainf->type)) {
fprintf (asmFile, "%s", iComments2);
fprintf (asmFile, "; Stack segment in internal ram \n");
fprintf (asmFile, "%s", iComments2);
copyFile (asmFile, idata->oFile);
/* if external stack then reserve space of it */
- if (mainf && mainf->fbody && options.useXstack ) {
+ if (mainf && IFFUNC_HASBODY(mainf->type) && options.useXstack ) {
fprintf (asmFile, "%s", iComments2);
fprintf (asmFile, "; external stack \n");
fprintf (asmFile, "%s", iComments2);
copyFile (asmFile, xdata->oFile);
- fprintf (asmFile, "\tendc\n");
-
-
/* copy the bit segment */
fprintf (asmFile, "%s", iComments2);
fprintf (asmFile, "; bit data\n");
fprintf (asmFile, "\tORG 0\n");
/* copy the interrupt vector table */
- if (mainf && mainf->fbody) {
+ if (mainf && IFFUNC_HASBODY(mainf->type)) {
fprintf (asmFile, "%s", iComments2);
fprintf (asmFile, "; interrupt vector \n");
fprintf (asmFile, "%s", iComments2);
fprintf (asmFile, ";\t.area %s\n", port->mem.post_static_name);
fprintf (asmFile, ";\t.area %s\n", port->mem.static_name);
- if (mainf && mainf->fbody) {
+ if (mainf && IFFUNC_HASBODY(mainf->type)) {
fprintf (asmFile,"__sdcc_gsinit_startup:\n");
/* if external stack is specified then the
higher order byte of the xdatalocation is
(unsigned int)options.xdata_loc & 0xff);
}
- /* initialise the stack pointer */
- /* if the user specified a value then use it */
- if (options.stack_loc)
- fprintf(asmFile,";\tmov\tsp,#%d\n",options.stack_loc);
- else
- /* no: we have to compute it */
- if (!options.stackOnData && maxRegBank <= 3)
- fprintf(asmFile,";\tmov\tsp,#%d\n",((maxRegBank + 1) * 8) -1);
- else
- fprintf(asmFile,";\tmov\tsp,#__start__stack\n"); /* MOF */
-
- fprintf (asmFile,";\tlcall\t__sdcc_external_startup\n");
- fprintf (asmFile,";\tmov\ta,dpl\n");
- fprintf (asmFile,";\tjz\t__sdcc_init_data\n");
- fprintf (asmFile,";\tljmp\t__sdcc_program_startup\n");
- fprintf (asmFile,";__sdcc_init_data:\n");
-
}
- //copyFile (asmFile, statsg->oFile);
- copypCode(asmFile, statsg->dbName);
- if (port->general.glue_up_main && mainf && mainf->fbody)
+ if (port->general.glue_up_main && mainf && IFFUNC_HASBODY(mainf->type))
{
/* This code is generated in the post-static area.
* This area is guaranteed to follow the static area
fprintf (asmFile, "; code\n");
fprintf (asmFile, "%s", iComments2);
fprintf (asmFile, ";\t.area %s\n", port->mem.code_name);
- if (mainf && mainf->fbody) {
-
- /* entry point @ start of CSEG */
- fprintf (asmFile,"__sdcc_program_startup:\n");
-
- /* put in the call to main */
- fprintf(asmFile,"\tcall\t_main\n");
- if (options.mainreturn) {
- fprintf(asmFile,";\treturn from main ; will return to caller\n");
- fprintf(asmFile,"\treturn\n");
-
- } else {
-
- fprintf(asmFile,";\treturn from main will lock up\n");
- fprintf(asmFile,"\tgoto\t$\n");
- }
- }
-
- AnalyzepCode(code->dbName);
- pCodePeepInit();
-
- OptimizepCode(code->dbName);
//copyFile (asmFile, code->oFile);
+
+ copypCode(asmFile, statsg->dbName);
+ copypCode(asmFile, 'X');
copypCode(asmFile, code->dbName);
- printCallTree(stderr);
fprintf (asmFile,"\tend\n");