- if (mainf && IFFUNC_HASBODY(mainf->type)) {
-
- pBlock *pb = newpCodeChain(NULL,'X',newpCodeCharP("; Starting pCode block"));
- addpBlock(pb);
-
- /* entry point @ start of CSEG */
- addpCode2pBlock(pb,newpCodeLabel("__sdcc_program_startup",-1));
- /* 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)));
-
- }
- }
-#endif
-
- /* 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('P'); // Last
- movepBlock2Head(code->dbName);
- movepBlock2Head('X');
- movepBlock2Head(statsg->dbName); // First
-
-
- /* print the global struct definitions */
- 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);
-
- /* PENDING: this isnt the best place but it will do */
- if (port->general.glue_up_main) {
- /* create the interrupt vector table */
- pic14createInterruptVect (vFile);
- }
-
- AnalyzepCode('*');
-
- ReuseReg(); // ReuseReg where call tree permits
-
- InlinepCode();
-
- AnalyzepCode('*');
-
- pcode_test();
-
-
- /* now put it all together into the assembler file */
- /* create the assembler file name */
-
- if ((noAssemble || options.c1mode) && fullDstFileName)
- {
- sprintf (buffer, fullDstFileName);
- }
- else
- {
- sprintf (buffer, dstFileName);
- strcat (buffer, ".asm");
- }
-
- if (!(asmFile = fopen (buffer, "w"))) {
- werror (E_FILE_OPEN_ERR, buffer);
- exit (1);
- }
-
- /* prepare statistics */
- resetpCodeStatistics ();
-
- /* initial comments */
- pic14initialComments (asmFile);
-
- /* print module name */
- fprintf (asmFile, ";\t.module %s\n", moduleName);
-
- /* Let the port generate any global directives, etc. */
- if (port->genAssemblerPreamble)
- {
- port->genAssemblerPreamble(asmFile);
- }
-
- /* Emit the __config directive */
- pic14_emitConfigWord (asmFile);
-
- /* print the global variables in this module */
- pic14printPublics (asmFile);
-
- /* print the extern variables in this module */
- pic14printExterns (asmFile);
-
- /* copy the sfr segment */
- fprintf (asmFile, "%s", iComments2);
- fprintf (asmFile, "; special function registers\n");
- fprintf (asmFile, "%s", iComments2);
- copyFile (asmFile, sfr->oFile);
-
-
- if (udata_section_name) {
- sprintf(udata_name,"%s",udata_section_name);
- } else {
- sprintf(udata_name,"data_%s",moduleName);
- }
- fprintf (asmFile, "%s", iComments2);
- fprintf (asmFile, "; udata\n");
- fprintf (asmFile, "%s", iComments2);
- fprintf (asmFile, "%s\tudata\n", udata_name);
- copyFile (asmFile, data->oFile);
-
- /* Put all variables into a cblock */
- AnalyzeBanking();
- writeUsedRegs(asmFile);
-
- /* create the overlay segments */
- fprintf (asmFile, "%s", iComments2);
- fprintf (asmFile, "; overlayable items in internal ram \n");
- fprintf (asmFile, "%s", iComments2);
- copyFile (asmFile, ovrFile);
-
-#if 0
-
- /* create the stack segment MOF */
- if (mainf && IFFUNC_HASBODY(mainf->type)) {
- fprintf (asmFile, "%s", iComments2);
- fprintf (asmFile, "; Stack segment in internal ram \n");
- fprintf (asmFile, "%s", iComments2);
- fprintf (asmFile, ";\t.area\tSSEG\t(DATA)\n"
- ";__start__stack:\n;\t.ds\t1\n\n");
- }
-
- /* create the idata segment */
- fprintf (asmFile, "%s", iComments2);
- fprintf (asmFile, "; indirectly addressable internal ram data\n");
- fprintf (asmFile, "%s", iComments2);
- copyFile (asmFile, idata->oFile);
-
- /* if external stack then reserve space of it */
- if (mainf && IFFUNC_HASBODY(mainf->type) && options.useXstack ) {
- fprintf (asmFile, "%s", iComments2);
- fprintf (asmFile, "; external stack \n");
- fprintf (asmFile, "%s", iComments2);
- fprintf (asmFile,";\t.area XSEG (XDATA)\n"); /* MOF */
- fprintf (asmFile,";\t.ds 256\n");
- }
-
- /* copy xtern ram data */
- fprintf (asmFile, "%s", iComments2);
- fprintf (asmFile, "; external ram data\n");
- fprintf (asmFile, "%s", iComments2);
- copyFile (asmFile, xdata->oFile);
-