- if(initialized)
- return;
-
- initialized = 1;
-
- pic16_pc_status.r = pic16_allocProcessorRegister(IDX_STATUS,"STATUS", PO_STATUS, 0x80);
- pic16_pc_pcl.r = pic16_allocProcessorRegister(IDX_PCL,"PCL", PO_PCL, 0x80);
- pic16_pc_pclath.r = pic16_allocProcessorRegister(IDX_PCLATH,"PCLATH", PO_PCLATH, 0x80);
- pic16_pc_pclatu.r = pic16_allocProcessorRegister(IDX_PCLATU,"PCLATU", PO_PCLATU, 0x80);
- pic16_pc_intcon.r = pic16_allocProcessorRegister(IDX_INTCON,"INTCON", PO_INTCON, 0x80);
- pic16_pc_wreg.r = pic16_allocProcessorRegister(IDX_WREG,"WREG", PO_WREG, 0x80);
- pic16_pc_bsr.r = pic16_allocProcessorRegister(IDX_BSR,"BSR", PO_BSR, 0x80);
-
- pic16_pc_tosl.r = pic16_allocProcessorRegister(IDX_TOSL,"TOSL", PO_SFR_REGISTER, 0x80);
- pic16_pc_tosh.r = pic16_allocProcessorRegister(IDX_TOSH,"TOSH", PO_SFR_REGISTER, 0x80);
- pic16_pc_tosu.r = pic16_allocProcessorRegister(IDX_TOSU,"TOSU", PO_SFR_REGISTER, 0x80);
-
- pic16_pc_tblptrl.r = pic16_allocProcessorRegister(IDX_TBLPTRL,"TBLPTRL", PO_SFR_REGISTER, 0x80);
- pic16_pc_tblptrh.r = pic16_allocProcessorRegister(IDX_TBLPTRH,"TBLPTRH", PO_SFR_REGISTER, 0x80);
- pic16_pc_tblptru.r = pic16_allocProcessorRegister(IDX_TBLPTRU,"TBLPTRU", PO_SFR_REGISTER, 0x80);
- pic16_pc_tablat.r = pic16_allocProcessorRegister(IDX_TABLAT,"TABLAT", PO_SFR_REGISTER, 0x80);
-
- pic16_pc_fsr0l.r = pic16_allocProcessorRegister(IDX_FSR0L, "FSR0L", PO_FSR0, 0x80);
- pic16_pc_fsr0h.r = pic16_allocProcessorRegister(IDX_FSR0H, "FSR0H", PO_FSR0, 0x80);
- pic16_pc_fsr1l.r = pic16_allocProcessorRegister(IDX_FSR1L, "FSR1L", PO_FSR0, 0x80);
- pic16_pc_fsr1h.r = pic16_allocProcessorRegister(IDX_FSR1H, "FSR1H", PO_FSR0, 0x80);
- pic16_pc_fsr2l.r = pic16_allocProcessorRegister(IDX_FSR2L, "FSR2L", PO_FSR0, 0x80);
- pic16_pc_fsr2h.r = pic16_allocProcessorRegister(IDX_FSR2H, "FSR2H", PO_FSR0, 0x80);
-
- pic16_stackpnt_lo = &pic16_pc_fsr1l;
- pic16_stackpnt_hi = &pic16_pc_fsr1h;
- pic16_stack_postdec = &pic16_pc_postdec1;
- pic16_stack_postinc = &pic16_pc_postinc1;
- pic16_stack_preinc = &pic16_pc_preinc1;
- pic16_stack_plusw = &pic16_pc_plusw1;
-
- pic16_framepnt_lo = &pic16_pc_fsr2l;
- pic16_framepnt_hi = &pic16_pc_fsr2h;
- pic16_frame_postdec = &pic16_pc_postdec2;
- pic16_frame_postinc = &pic16_pc_postinc2;
- pic16_frame_preinc = &pic16_pc_preinc2;
- pic16_frame_plusw = &pic16_pc_plusw2;
-
- pic16_pc_indf0.r = pic16_allocProcessorRegister(IDX_INDF0,"INDF0", PO_INDF0, 0x80);
- pic16_pc_postinc0.r = pic16_allocProcessorRegister(IDX_POSTINC0, "POSTINC0", PO_INDF0, 0x80);
- pic16_pc_postdec0.r = pic16_allocProcessorRegister(IDX_POSTDEC0, "POSTDEC0", PO_INDF0, 0x80);
- pic16_pc_preinc0.r = pic16_allocProcessorRegister(IDX_PREINC0, "PREINC0", PO_INDF0, 0x80);
- pic16_pc_plusw0.r = pic16_allocProcessorRegister(IDX_PLUSW0, "PLUSW0", PO_INDF0, 0x80);
-
- pic16_pc_indf1.r = pic16_allocProcessorRegister(IDX_INDF1,"INDF1", PO_INDF0, 0x80);
- pic16_pc_postinc1.r = pic16_allocProcessorRegister(IDX_POSTINC1, "POSTINC1", PO_INDF0, 0x80);
- pic16_pc_postdec1.r = pic16_allocProcessorRegister(IDX_POSTDEC1, "POSTDEC1", PO_INDF0, 0x80);
- pic16_pc_preinc1.r = pic16_allocProcessorRegister(IDX_PREINC1, "PREINC1", PO_INDF0, 0x80);
- pic16_pc_plusw1.r = pic16_allocProcessorRegister(IDX_PLUSW1, "PLUSW1", PO_INDF0, 0x80);
-
- pic16_pc_indf2.r = pic16_allocProcessorRegister(IDX_INDF2,"INDF2", PO_INDF0, 0x80);
- pic16_pc_postinc2.r = pic16_allocProcessorRegister(IDX_POSTINC2, "POSTINC2", PO_INDF0, 0x80);
- pic16_pc_postdec2.r = pic16_allocProcessorRegister(IDX_POSTDEC2, "POSTDEC2", PO_INDF0, 0x80);
- pic16_pc_preinc2.r = pic16_allocProcessorRegister(IDX_PREINC2, "PREINC2", PO_INDF0, 0x80);
- pic16_pc_plusw2.r = pic16_allocProcessorRegister(IDX_PLUSW2, "PLUSW2", PO_INDF0, 0x80);
-
- pic16_pc_prodl.r = pic16_allocProcessorRegister(IDX_PRODL, "PRODL", PO_PRODL, 0x80);
- pic16_pc_prodh.r = pic16_allocProcessorRegister(IDX_PRODH, "PRODH", PO_PRODH, 0x80);
-
-
- pic16_pc_eecon1.r = pic16_allocProcessorRegister(IDX_EECON1, "EECON1", PO_SFR_REGISTER, 0x80);
- pic16_pc_eecon2.r = pic16_allocProcessorRegister(IDX_EECON2, "EECON2", PO_SFR_REGISTER, 0x80);
- pic16_pc_eedata.r = pic16_allocProcessorRegister(IDX_EEDATA, "EEDATA", PO_SFR_REGISTER, 0x80);
- pic16_pc_eeadr.r = pic16_allocProcessorRegister(IDX_EEADR, "EEADR", PO_SFR_REGISTER, 0x80);
-
-
- pic16_pc_status.rIdx = IDX_STATUS;
- pic16_pc_intcon.rIdx = IDX_INTCON;
- pic16_pc_pcl.rIdx = IDX_PCL;
- pic16_pc_pclath.rIdx = IDX_PCLATH;
- pic16_pc_pclatu.rIdx = IDX_PCLATU;
- pic16_pc_wreg.rIdx = IDX_WREG;
- pic16_pc_bsr.rIdx = IDX_BSR;
-
- pic16_pc_tosl.rIdx = IDX_TOSL;
- pic16_pc_tosh.rIdx = IDX_TOSH;
- pic16_pc_tosu.rIdx = IDX_TOSU;
-
- pic16_pc_tblptrl.rIdx = IDX_TBLPTRL;
- pic16_pc_tblptrh.rIdx = IDX_TBLPTRH;
- pic16_pc_tblptru.rIdx = IDX_TBLPTRU;
- pic16_pc_tablat.rIdx = IDX_TABLAT;
-
- pic16_pc_fsr0l.rIdx = IDX_FSR0L;
- pic16_pc_fsr0h.rIdx = IDX_FSR0H;
- pic16_pc_fsr1l.rIdx = IDX_FSR1L;
- pic16_pc_fsr1h.rIdx = IDX_FSR1H;
- pic16_pc_fsr2l.rIdx = IDX_FSR2L;
- pic16_pc_fsr2h.rIdx = IDX_FSR2H;
- pic16_pc_indf0.rIdx = IDX_INDF0;
- pic16_pc_postinc0.rIdx = IDX_POSTINC0;
- pic16_pc_postdec0.rIdx = IDX_POSTDEC0;
- pic16_pc_preinc0.rIdx = IDX_PREINC0;
- pic16_pc_plusw0.rIdx = IDX_PLUSW0;
- pic16_pc_indf1.rIdx = IDX_INDF1;
- pic16_pc_postinc1.rIdx = IDX_POSTINC1;
- pic16_pc_postdec1.rIdx = IDX_POSTDEC1;
- pic16_pc_preinc1.rIdx = IDX_PREINC1;
- pic16_pc_plusw1.rIdx = IDX_PLUSW1;
- pic16_pc_indf2.rIdx = IDX_INDF2;
- pic16_pc_postinc2.rIdx = IDX_POSTINC2;
- pic16_pc_postdec2.rIdx = IDX_POSTDEC2;
- pic16_pc_preinc2.rIdx = IDX_PREINC2;
- pic16_pc_plusw2.rIdx = IDX_PLUSW2;
- pic16_pc_prodl.rIdx = IDX_PRODL;
- pic16_pc_prodh.rIdx = IDX_PRODH;
-
- pic16_pc_kzero.r = pic16_allocInternalRegister(IDX_KZ,"KZ",PO_GPR_REGISTER,0);
- pic16_pc_ssave.r = pic16_allocInternalRegister(IDX_SSAVE,"SSAVE", PO_GPR_REGISTER, 0);
- pic16_pc_wsave.r = pic16_allocInternalRegister(IDX_WSAVE,"WSAVE", PO_GPR_REGISTER, 0);
-
- pic16_pc_kzero.rIdx = IDX_KZ;
- pic16_pc_wsave.rIdx = IDX_WSAVE;
- pic16_pc_ssave.rIdx = IDX_SSAVE;
-
- pic16_pc_eecon1.rIdx = IDX_EECON1;
- pic16_pc_eecon2.rIdx = IDX_EECON2;
- pic16_pc_eedata.rIdx = IDX_EEDATA;
- pic16_pc_eeadr.rIdx = IDX_EEADR;
-
-
- pic16_pc_gpsimio.r = pic16_allocProcessorRegister(IDX_GPSIMIO, "GPSIMIO", PO_GPR_REGISTER, 0x80);
- pic16_pc_gpsimio2.r = pic16_allocProcessorRegister(IDX_GPSIMIO2, "GPSIMIO2", PO_GPR_REGISTER, 0x80);
-
- pic16_pc_gpsimio.rIdx = IDX_GPSIMIO;
- pic16_pc_gpsimio2.rIdx = IDX_GPSIMIO2;
-
- /* probably should put this in a separate initialization routine */
- pb_dead_pcodes = newpBlock();
+ if(initialized)
+ return;
+
+ initialized = 1;
+
+ pic16_pc_status.r = pic16_allocProcessorRegister(IDX_STATUS,"STATUS", PO_STATUS, 0x80);
+ pic16_pc_pcl.r = pic16_allocProcessorRegister(IDX_PCL,"PCL", PO_PCL, 0x80);
+ pic16_pc_pclath.r = pic16_allocProcessorRegister(IDX_PCLATH,"PCLATH", PO_PCLATH, 0x80);
+ pic16_pc_pclatu.r = pic16_allocProcessorRegister(IDX_PCLATU,"PCLATU", PO_PCLATU, 0x80);
+ pic16_pc_intcon.r = pic16_allocProcessorRegister(IDX_INTCON,"INTCON", PO_INTCON, 0x80);
+ pic16_pc_wreg.r = pic16_allocProcessorRegister(IDX_WREG,"WREG", PO_WREG, 0x80);
+ pic16_pc_bsr.r = pic16_allocProcessorRegister(IDX_BSR,"BSR", PO_BSR, 0x80);
+
+ pic16_pc_tosl.r = pic16_allocProcessorRegister(IDX_TOSL,"TOSL", PO_SFR_REGISTER, 0x80);
+ pic16_pc_tosh.r = pic16_allocProcessorRegister(IDX_TOSH,"TOSH", PO_SFR_REGISTER, 0x80);
+ pic16_pc_tosu.r = pic16_allocProcessorRegister(IDX_TOSU,"TOSU", PO_SFR_REGISTER, 0x80);
+
+ pic16_pc_tblptrl.r = pic16_allocProcessorRegister(IDX_TBLPTRL,"TBLPTRL", PO_SFR_REGISTER, 0x80);
+ pic16_pc_tblptrh.r = pic16_allocProcessorRegister(IDX_TBLPTRH,"TBLPTRH", PO_SFR_REGISTER, 0x80);
+ pic16_pc_tblptru.r = pic16_allocProcessorRegister(IDX_TBLPTRU,"TBLPTRU", PO_SFR_REGISTER, 0x80);
+ pic16_pc_tablat.r = pic16_allocProcessorRegister(IDX_TABLAT,"TABLAT", PO_SFR_REGISTER, 0x80);
+
+ pic16_pc_fsr0l.r = pic16_allocProcessorRegister(IDX_FSR0L, "FSR0L", PO_FSR0, 0x80);
+ pic16_pc_fsr0h.r = pic16_allocProcessorRegister(IDX_FSR0H, "FSR0H", PO_FSR0, 0x80);
+ pic16_pc_fsr1l.r = pic16_allocProcessorRegister(IDX_FSR1L, "FSR1L", PO_FSR0, 0x80);
+ pic16_pc_fsr1h.r = pic16_allocProcessorRegister(IDX_FSR1H, "FSR1H", PO_FSR0, 0x80);
+ pic16_pc_fsr2l.r = pic16_allocProcessorRegister(IDX_FSR2L, "FSR2L", PO_FSR0, 0x80);
+ pic16_pc_fsr2h.r = pic16_allocProcessorRegister(IDX_FSR2H, "FSR2H", PO_FSR0, 0x80);
+
+ pic16_stackpnt_lo = &pic16_pc_fsr1l;
+ pic16_stackpnt_hi = &pic16_pc_fsr1h;
+ pic16_stack_postdec = &pic16_pc_postdec1;
+ pic16_stack_postinc = &pic16_pc_postinc1;
+ pic16_stack_preinc = &pic16_pc_preinc1;
+ pic16_stack_plusw = &pic16_pc_plusw1;
+
+ pic16_framepnt_lo = &pic16_pc_fsr2l;
+ pic16_framepnt_hi = &pic16_pc_fsr2h;
+ pic16_frame_postdec = &pic16_pc_postdec2;
+ pic16_frame_postinc = &pic16_pc_postinc2;
+ pic16_frame_preinc = &pic16_pc_preinc2;
+ pic16_frame_plusw = &pic16_pc_plusw2;
+
+ pic16_pc_indf0.r = pic16_allocProcessorRegister(IDX_INDF0,"INDF0", PO_INDF0, 0x80);
+ pic16_pc_postinc0.r = pic16_allocProcessorRegister(IDX_POSTINC0, "POSTINC0", PO_INDF0, 0x80);
+ pic16_pc_postdec0.r = pic16_allocProcessorRegister(IDX_POSTDEC0, "POSTDEC0", PO_INDF0, 0x80);
+ pic16_pc_preinc0.r = pic16_allocProcessorRegister(IDX_PREINC0, "PREINC0", PO_INDF0, 0x80);
+ pic16_pc_plusw0.r = pic16_allocProcessorRegister(IDX_PLUSW0, "PLUSW0", PO_INDF0, 0x80);
+
+ pic16_pc_indf1.r = pic16_allocProcessorRegister(IDX_INDF1,"INDF1", PO_INDF0, 0x80);
+ pic16_pc_postinc1.r = pic16_allocProcessorRegister(IDX_POSTINC1, "POSTINC1", PO_INDF0, 0x80);
+ pic16_pc_postdec1.r = pic16_allocProcessorRegister(IDX_POSTDEC1, "POSTDEC1", PO_INDF0, 0x80);
+ pic16_pc_preinc1.r = pic16_allocProcessorRegister(IDX_PREINC1, "PREINC1", PO_INDF0, 0x80);
+ pic16_pc_plusw1.r = pic16_allocProcessorRegister(IDX_PLUSW1, "PLUSW1", PO_INDF0, 0x80);
+
+ pic16_pc_indf2.r = pic16_allocProcessorRegister(IDX_INDF2,"INDF2", PO_INDF0, 0x80);
+ pic16_pc_postinc2.r = pic16_allocProcessorRegister(IDX_POSTINC2, "POSTINC2", PO_INDF0, 0x80);
+ pic16_pc_postdec2.r = pic16_allocProcessorRegister(IDX_POSTDEC2, "POSTDEC2", PO_INDF0, 0x80);
+ pic16_pc_preinc2.r = pic16_allocProcessorRegister(IDX_PREINC2, "PREINC2", PO_INDF0, 0x80);
+ pic16_pc_plusw2.r = pic16_allocProcessorRegister(IDX_PLUSW2, "PLUSW2", PO_INDF0, 0x80);
+
+ pic16_pc_prodl.r = pic16_allocProcessorRegister(IDX_PRODL, "PRODL", PO_PRODL, 0x80);
+ pic16_pc_prodh.r = pic16_allocProcessorRegister(IDX_PRODH, "PRODH", PO_PRODH, 0x80);
+
+
+ pic16_pc_eecon1.r = pic16_allocProcessorRegister(IDX_EECON1, "EECON1", PO_SFR_REGISTER, 0x80);
+ pic16_pc_eecon2.r = pic16_allocProcessorRegister(IDX_EECON2, "EECON2", PO_SFR_REGISTER, 0x80);
+ pic16_pc_eedata.r = pic16_allocProcessorRegister(IDX_EEDATA, "EEDATA", PO_SFR_REGISTER, 0x80);
+ pic16_pc_eeadr.r = pic16_allocProcessorRegister(IDX_EEADR, "EEADR", PO_SFR_REGISTER, 0x80);
+
+
+ pic16_pc_status.rIdx = IDX_STATUS;
+ pic16_pc_intcon.rIdx = IDX_INTCON;
+ pic16_pc_pcl.rIdx = IDX_PCL;
+ pic16_pc_pclath.rIdx = IDX_PCLATH;
+ pic16_pc_pclatu.rIdx = IDX_PCLATU;
+ pic16_pc_wreg.rIdx = IDX_WREG;
+ pic16_pc_bsr.rIdx = IDX_BSR;
+
+ pic16_pc_tosl.rIdx = IDX_TOSL;
+ pic16_pc_tosh.rIdx = IDX_TOSH;
+ pic16_pc_tosu.rIdx = IDX_TOSU;
+
+ pic16_pc_tblptrl.rIdx = IDX_TBLPTRL;
+ pic16_pc_tblptrh.rIdx = IDX_TBLPTRH;
+ pic16_pc_tblptru.rIdx = IDX_TBLPTRU;
+ pic16_pc_tablat.rIdx = IDX_TABLAT;
+
+ pic16_pc_fsr0l.rIdx = IDX_FSR0L;
+ pic16_pc_fsr0h.rIdx = IDX_FSR0H;
+ pic16_pc_fsr1l.rIdx = IDX_FSR1L;
+ pic16_pc_fsr1h.rIdx = IDX_FSR1H;
+ pic16_pc_fsr2l.rIdx = IDX_FSR2L;
+ pic16_pc_fsr2h.rIdx = IDX_FSR2H;
+ pic16_pc_indf0.rIdx = IDX_INDF0;
+ pic16_pc_postinc0.rIdx = IDX_POSTINC0;
+ pic16_pc_postdec0.rIdx = IDX_POSTDEC0;
+ pic16_pc_preinc0.rIdx = IDX_PREINC0;
+ pic16_pc_plusw0.rIdx = IDX_PLUSW0;
+ pic16_pc_indf1.rIdx = IDX_INDF1;
+ pic16_pc_postinc1.rIdx = IDX_POSTINC1;
+ pic16_pc_postdec1.rIdx = IDX_POSTDEC1;
+ pic16_pc_preinc1.rIdx = IDX_PREINC1;
+ pic16_pc_plusw1.rIdx = IDX_PLUSW1;
+ pic16_pc_indf2.rIdx = IDX_INDF2;
+ pic16_pc_postinc2.rIdx = IDX_POSTINC2;
+ pic16_pc_postdec2.rIdx = IDX_POSTDEC2;
+ pic16_pc_preinc2.rIdx = IDX_PREINC2;
+ pic16_pc_plusw2.rIdx = IDX_PLUSW2;
+ pic16_pc_prodl.rIdx = IDX_PRODL;
+ pic16_pc_prodh.rIdx = IDX_PRODH;
+
+ pic16_pc_kzero.r = pic16_allocInternalRegister(IDX_KZ,"KZ",PO_GPR_REGISTER,0);
+ pic16_pc_ssave.r = pic16_allocInternalRegister(IDX_SSAVE,"SSAVE", PO_GPR_REGISTER, 0);
+ pic16_pc_wsave.r = pic16_allocInternalRegister(IDX_WSAVE,"WSAVE", PO_GPR_REGISTER, 0);
+
+ pic16_pc_kzero.rIdx = IDX_KZ;
+ pic16_pc_wsave.rIdx = IDX_WSAVE;
+ pic16_pc_ssave.rIdx = IDX_SSAVE;
+
+ pic16_pc_eecon1.rIdx = IDX_EECON1;
+ pic16_pc_eecon2.rIdx = IDX_EECON2;
+ pic16_pc_eedata.rIdx = IDX_EEDATA;
+ pic16_pc_eeadr.rIdx = IDX_EEADR;
+
+
+ pic16_pc_gpsimio.r = pic16_allocProcessorRegister(IDX_GPSIMIO, "GPSIMIO", PO_GPR_REGISTER, 0x80);
+ pic16_pc_gpsimio2.r = pic16_allocProcessorRegister(IDX_GPSIMIO2, "GPSIMIO2", PO_GPR_REGISTER, 0x80);
+
+ pic16_pc_gpsimio.rIdx = IDX_GPSIMIO;
+ pic16_pc_gpsimio2.rIdx = IDX_GPSIMIO2;
+
+ /* probably should put this in a separate initialization routine */
+ pb_dead_pcodes = newpBlock();
- if(!buffer) {
- buffer = b;
- size = sizeof(b);
- use_buffer = 0; // Don't bother copying the string to the buffer.
- }
-
- if(pcop) {
-
- switch(pcop->type) {
- case PO_W:
- case PO_WREG:
- case PO_PRODL:
- case PO_PRODH:
- case PO_INDF0:
- case PO_FSR0:
- if(use_buffer) {
- SAFE_snprintf(&buffer,&size,"%s",PCOR(pcop)->r->name);
- return (buffer);
- }
- return (PCOR(pcop)->r->name);
- break;
- case PO_GPR_TEMP:
- r = pic16_regWithIdx(PCOR(pcop)->r->rIdx);
- if(use_buffer) {
- SAFE_snprintf(&buffer,&size,"%s",r->name);
- return (buffer);
- }
- return (r->name);
-
- case PO_IMMEDIATE:
- s = buffer;
- if(PCOI(pcop)->offset && PCOI(pcop)->offset<4) {
- if(PCOI(pcop)->index) {
- SAFE_snprintf(&s,&size, "%s(%s + %d)",
- immdmod[ PCOI(pcop)->offset ],
- pcop->name,
- PCOI(pcop)->index);
- } else {
- SAFE_snprintf(&s,&size,"%s(%s)",
- immdmod[ PCOI(pcop)->offset ],
- pcop->name);
- }
- } else {
- if(PCOI(pcop)->index) {
- SAFE_snprintf(&s,&size, "%s(%s + %d)",
- immdmod[ 0 ],
- pcop->name,
- PCOI(pcop)->index);
- } else {
- SAFE_snprintf(&s,&size, "%s(%s)",
- immdmod[ 0 ],
- pcop->name);
- }
- }
- return (buffer);
-
- case PO_GPR_REGISTER:
- case PO_DIR:
- s = buffer;
-// size = sizeof(buffer);
- if( PCOR(pcop)->instance) {
- SAFE_snprintf(&s,&size,"(%s + %d)",
- pcop->name,
- PCOR(pcop)->instance );
- } else {
- SAFE_snprintf(&s,&size,"%s",pcop->name);
- }
- return (buffer);
- case PO_GPR_BIT:
- s = buffer;
- if(PCORB(pcop)->subtype == PO_GPR_TEMP) {
- SAFE_snprintf(&s, &size, "%s", pcop->name);
- } else {
- if(PCORB(pcop)->pcor.instance)
- SAFE_snprintf(&s, &size, "(%s + %d)", pcop->name, PCORB(pcop)->pcor.instance);
- else
- SAFE_snprintf(&s, &size, "%s", pcop->name);
- }
-
- return (buffer);
- case PO_TWO_OPS:
- return (pic16_get_op( PCOP2(pcop)->pcopL, use_buffer ? buffer : NULL, size ));
-
- default:
- if(pcop->name) {
- if(use_buffer) {
- SAFE_snprintf(&buffer,&size,"%s",pcop->name);
- return (buffer);
- }
- return (pcop->name);
- }
-
- }
- return ("unhandled type for op1");
- }
+ if(!buffer) {
+ buffer = b;
+ size = sizeof(b);
+ use_buffer = 0; // Don't bother copying the string to the buffer.
+ }
+
+ if(pcop) {
+
+ switch(pcop->type) {
+ case PO_W:
+ case PO_WREG:
+ case PO_PRODL:
+ case PO_PRODH:
+ case PO_INDF0:
+ case PO_FSR0:
+ if(use_buffer) {
+ SAFE_snprintf(&buffer,&size,"%s",PCOR(pcop)->r->name);
+ return (buffer);
+ }
+ return (PCOR(pcop)->r->name);
+ break;
+ case PO_GPR_TEMP:
+ r = pic16_regWithIdx(PCOR(pcop)->r->rIdx);
+ if(use_buffer) {
+ SAFE_snprintf(&buffer,&size,"%s",r->name);
+ return (buffer);
+ }
+ return (r->name);
+
+ case PO_IMMEDIATE:
+ s = buffer;
+ if(PCOI(pcop)->offset && PCOI(pcop)->offset<4) {
+ if(PCOI(pcop)->index) {
+ SAFE_snprintf(&s,&size, "%s(%s + %d)",
+ immdmod[ PCOI(pcop)->offset ],
+ pcop->name,
+ PCOI(pcop)->index);
+ } else {
+ SAFE_snprintf(&s,&size,"%s(%s)",
+ immdmod[ PCOI(pcop)->offset ],
+ pcop->name);
+ }
+ } else {
+ if(PCOI(pcop)->index) {
+ SAFE_snprintf(&s,&size, "%s(%s + %d)",
+ immdmod[ 0 ],
+ pcop->name,
+ PCOI(pcop)->index);
+ } else {
+ SAFE_snprintf(&s,&size, "%s(%s)",
+ immdmod[ 0 ],
+ pcop->name);
+ }
+ }
+ return (buffer);
+
+ case PO_GPR_REGISTER:
+ case PO_DIR:
+ s = buffer;
+// size = sizeof(buffer);
+ if( PCOR(pcop)->instance) {
+ SAFE_snprintf(&s,&size,"(%s + %d)",
+ pcop->name,
+ PCOR(pcop)->instance );
+ } else {
+ SAFE_snprintf(&s,&size,"%s",pcop->name);
+ }
+ return (buffer);
+ case PO_GPR_BIT:
+ s = buffer;
+ if(PCORB(pcop)->subtype == PO_GPR_TEMP) {
+ SAFE_snprintf(&s, &size, "%s", pcop->name);
+ } else {
+ if(PCORB(pcop)->pcor.instance)
+ SAFE_snprintf(&s, &size, "(%s + %d)", pcop->name, PCORB(pcop)->pcor.instance);
+ else
+ SAFE_snprintf(&s, &size, "%s", pcop->name);
+ }
+
+ return (buffer);
+ case PO_TWO_OPS:
+ return (pic16_get_op( PCOP2(pcop)->pcopL, use_buffer ? buffer : NULL, size ));
+
+ default:
+ if(pcop->name) {
+ if(use_buffer) {
+ SAFE_snprintf(&buffer,&size,"%s",pcop->name);
+ return (buffer);
+ }
+ return (pcop->name);
+ }
+
+ }
+ return ("unhandled type for op1");
+ }
- switch(position) {
- case 1: {
- /* insert the bank switch after this pc instruction */
- pCode *pcnext = pic16_findNextInstruction(pc);
-
- pic16_pCodeInsertAfter(pc, new_pc);
- if(pcnext)pc = pcnext;
- }; break;
-
- case 0:
- /* insert the bank switch BEFORE this pc instruction */
- pic16_pCodeInsertAfter(pc->prev, new_pc);
- break;
-
- case 2: {
- symbol *tlbl;
- pCode *pcnext, *pcprev, *npci, *ppc;
- PIC_OPCODE ipci;
- int ofs1=0, ofs2=0, len=0;
-
- /* just like 0, but previous was a skip instruction,
- * so some care should be taken */
-
- pic16_labelOffset += 10000;
- tlbl = newiTempLabel(NULL);
-
- /* invert skip instruction */
- pcprev = pic16_findPrevInstruction(pc->prev);
- ipci = PCI(pcprev)->inverted_op;
- npci = pic16_newpCode(ipci, PCI(pcprev)->pcop);
-
-// fprintf(stderr, "%s:%d old OP: %d\tnew OP: %d\n", __FILE__, __LINE__, PCI(pcprev)->op, ipci);
-
- /* copy info from old pCode */
- ofs1 = ofs2 = sizeof( pCode ) + sizeof(PIC_OPCODE);
- len = sizeof(pCodeInstruction) - ofs1 - sizeof( char const * const *);
- ofs1 += strlen( PCI(pcprev)->mnemonic) + 1;
- ofs2 += strlen( PCI(npci)->mnemonic) + 1;
- memcpy(&PCI(npci)->from, &PCI(pcprev)->from, (char *)(&(PCI(npci)->pci_magic)) - (char *)(&(PCI(npci)->from)));
- PCI(npci)->op = PCI(pcprev)->inverted_op;
-
- /* unlink old pCode */
- ppc = pcprev->prev;
- ppc->next = pcprev->next;
- pcprev->next->prev = ppc;
- pic16_pCodeInsertAfter(ppc, npci);
-
- /* extra instructions to handle invertion */
- pcnext = pic16_newpCode(POC_BRA, pic16_popGetLabel(tlbl->key));
- pic16_pCodeInsertAfter(npci, pcnext);
- pic16_pCodeInsertAfter(pc->prev, new_pc);
-
- pcnext = pic16_newpCodeLabel(NULL,tlbl->key+100+pic16_labelOffset);
- pic16_pCodeInsertAfter(pc, pcnext);
- }; break;
- }
-
-
- /* Move the label, if there is one */
- if(PCI(pc)->label) {
-// fprintf(stderr, "%s:%d: moving label due to bank switch directive src= 0x%p dst= 0x%p\n",
-// __FILE__, __LINE__, pc, new_pc);
- PCAD(new_pc)->pci.label = PCI(pc)->label;
- PCI(pc)->label = NULL;
- }
+ switch(position) {
+ case 1: {
+ /* insert the bank switch after this pc instruction */
+ pCode *pcnext = pic16_findNextInstruction(pc);
+
+ pic16_pCodeInsertAfter(pc, new_pc);
+ if(pcnext)pc = pcnext;
+ }; break;
+
+ case 0:
+ /* insert the bank switch BEFORE this pc instruction */
+ pic16_pCodeInsertAfter(pc->prev, new_pc);
+ break;
+
+ case 2: {
+ symbol *tlbl;
+ pCode *pcnext, *pcprev, *npci, *ppc;
+ PIC_OPCODE ipci;
+ int ofs1=0, ofs2=0, len=0;
+
+ /* just like 0, but previous was a skip instruction,
+ * so some care should be taken */
+
+ pic16_labelOffset += 10000;
+ tlbl = newiTempLabel(NULL);
+
+ /* invert skip instruction */
+ pcprev = pic16_findPrevInstruction(pc->prev);
+ ipci = PCI(pcprev)->inverted_op;
+ npci = pic16_newpCode(ipci, PCI(pcprev)->pcop);
+
+// fprintf(stderr, "%s:%d old OP: %d\tnew OP: %d\n", __FILE__, __LINE__, PCI(pcprev)->op, ipci);
+
+ /* copy info from old pCode */
+ ofs1 = ofs2 = sizeof( pCode ) + sizeof(PIC_OPCODE);
+ len = sizeof(pCodeInstruction) - ofs1 - sizeof( char const * const *);
+ ofs1 += strlen( PCI(pcprev)->mnemonic) + 1;
+ ofs2 += strlen( PCI(npci)->mnemonic) + 1;
+ memcpy(&PCI(npci)->from, &PCI(pcprev)->from, (char *)(&(PCI(npci)->pci_magic)) - (char *)(&(PCI(npci)->from)));
+ PCI(npci)->op = PCI(pcprev)->inverted_op;
+
+ /* unlink old pCode */
+ ppc = pcprev->prev;
+ ppc->next = pcprev->next;
+ pcprev->next->prev = ppc;
+ pic16_pCodeInsertAfter(ppc, npci);
+
+ /* extra instructions to handle invertion */
+ pcnext = pic16_newpCode(POC_BRA, pic16_popGetLabel(tlbl->key));
+ pic16_pCodeInsertAfter(npci, pcnext);
+ pic16_pCodeInsertAfter(pc->prev, new_pc);
+
+ pcnext = pic16_newpCodeLabel(NULL,tlbl->key+100+pic16_labelOffset);
+ pic16_pCodeInsertAfter(pc, pcnext);
+ }; break;
+ }
+
+
+ /* Move the label, if there is one */
+ if(PCI(pc)->label) {
+// fprintf(stderr, "%s:%d: moving label due to bank switch directive src= 0x%p dst= 0x%p\n",
+// __FILE__, __LINE__, pc, new_pc);
+ PCAD(new_pc)->pci.label = PCI(pc)->label;
+ PCI(pc)->label = NULL;
+ }
- pc_next = pic16_findNextInstructionSkipJumptables (pc->next, &isJumptab);
- if (isJumptab) {
- // skip jumptable, i.e. start over with no pc_prev!
- pc_prev = NULL;
- pc = pc_next;
- continue;
- } // if
-
- /* (1) resolve chained jumps
- * Do not perform this until pattern (4) is no longer present! Otherwise we will
- * (a) leave dead code in and
- * (b) skip over the dead code with an (unneccessary) jump.
- */
- if (!matchedInvertRule && (IS_GOTO(pc) || isConditionalBranch(pc))) {
- pCodeOp *lastTargetOp = NULL;
- int newDist = resolveJumpChain (pc, &target, &lastTargetOp);
- int maxDist = MAX_DIST_BCC;
- if (PCI(pc)->op == POC_BRA) maxDist = MAX_DIST_BRA;
- if (PCI(pc)->op == POC_GOTO) maxDist = MAX_DIST_GOTO;
-
- /* be careful NOT to make the jump instruction longer (might break previously shortened jumps!) */
- if (lastTargetOp && newDist <= maxDist && lastTargetOp != PCI(pc)->pcop
- && strcmp (lastTargetOp->name, PCI(pc)->pcop->name) != 0) {
- //fprintf (stderr, "(1) ");pc->print(stderr, pc); fprintf (stderr, " --> %s\n", lastTargetOp->name);
- if (pic16_pcode_verbose) { pic16_pCodeInsertAfter (pc->prev, pic16_newpCodeCharP("(1) jump chain resolved")); }
- PCI(pc)->pcop->name = lastTargetOp->name;
- change++;
- opt_gotochain++;
- } // if
- } // if
-
-
- if (IS_GOTO(pc)) {
- int dist;
- int condBraType = isSkipOnStatus(pc_prev);
- label = PCI(pc)->pcop->name;
- dist = findpCodeLabel(pc, label, MAX_DIST_BRA, &target);
- if (dist < 0) dist = -dist;
- //fprintf (stderr, "distance: %d (", dist); pc->print(stderr, pc);fprintf (stderr, ")\n");
- isHandled = 0;
-
-
- /* (2) remove "GOTO label; label:" */
- if (isLabel (pc_next, label)) {
- //fprintf (stderr, "(2) GOTO next instruction: ");pc->print(stderr, pc);fprintf (stderr, " --> ");pc_next->print(stderr, pc_next); fprintf(stderr, "\n");
- // first remove all preceeding SKIP instructions
- while (pc_prev && isPCI_SKIP(pc_prev)) {
- // attach labels on this instruction to pc_next
- //fprintf (stderr, "(2) preceeding SKIP removed: ");pc_prev->print(stderr, pc_prev);fprintf(stderr, "\n");
- PCI(pc_next)->label = pic16_pBranchAppend (PCI(pc_prev)->label, PCI(pc_next)->label);
- PCI(pc_prev)->label = NULL;
- if (pic16_pcode_verbose) { pic16_pCodeInsertAfter (pc->prev, pic16_newpCodeCharP("(2) SKIP removed")); }
- pic16_unlinkpCode (pc_prev);
- pc_prev = pic16_findPrevInstruction (pc);
- } // while
- // now remove the redundant goto itself
- PCI(pc_next)->label = pic16_pBranchAppend (PCI(pc)->label, PCI(pc_next)->label);
- if (pic16_pcode_verbose) { pic16_pCodeInsertAfter (pc, pic16_newpCodeCharP("(2) GOTO next instruction removed")); }
- pic16_unlinkpCode (pc);
- pc = pic16_findPrevInstruction(pc_next->prev);
- isHandled = 1; // do not perform further optimizations
- opt_gotonext++;
- change++;
- } // if
-
-
- /* (3) turn BTFSx STATUS,i; GOTO label into Bcc label if possible */
- if (!isHandled && condBraType != -1 && hasNoLabel(pc)) {
- if (dist < MAX_DIST_BCC) {
- pCode *bcc = NULL;
- switch (condBraType) {
- case 0x00: bcc = pic16_newpCode (POC_BC, PCI(pc)->pcop);break;
- // no BDC on DIGIT CARRY available
- case 0x02: bcc = pic16_newpCode (POC_BZ, PCI(pc)->pcop);break;
- case 0x03: bcc = pic16_newpCode (POC_BOV, PCI(pc)->pcop);break;
- case 0x04: bcc = pic16_newpCode (POC_BN, PCI(pc)->pcop);break;
- case 0x10: bcc = pic16_newpCode (POC_BNC, PCI(pc)->pcop);break;
- // no BNDC on DIGIT CARRY available
- case 0x12: bcc = pic16_newpCode (POC_BNZ, PCI(pc)->pcop);break;
- case 0x13: bcc = pic16_newpCode (POC_BNOV, PCI(pc)->pcop);break;
- case 0x14: bcc = pic16_newpCode (POC_BNN, PCI(pc)->pcop);break;
- default:
- // no replacement possible
- bcc = NULL;
- break;
- } // switch
- if (bcc) {
- // ATTENTION: keep labels attached to BTFSx!
- // HINT: GOTO is label free (checked above)
- //fprintf (stderr, "%s:%d: (3) turning %s %s into %s %s\n", __FUNCTION__, __LINE__, PCI(pc)->mnemonic, label, PCI(bcc)->mnemonic, label);
- isHandled = 1; // do not perform further optimizations
- if (pic16_pcode_verbose) { pic16_pCodeInsertAfter(pc_prev->prev, pic16_newpCodeCharP("(3) conditional branch introduced")); }
- pic16_pCodeReplace (pc_prev, bcc);
- pc->destruct(pc);
- pc = bcc;
- opt_cond++;
- change++;
- } // if
- } else {
- //fprintf (stderr, "(%d, too far for Bcc)\n", dist);
- cond_toofar++;
- } // if
- } // if
-
- if (!isHandled) {
- // (4) eliminate the following (common) tripel:
- // <pred.>;
- // labels1: Bcc label2;
- // GOTO somewhere; ; <-- instruction referenced by pc
- // label2: <cont.>
- // and replace it by
- // labels1: B#(cc) somewhere; ; #(cc) is the negated condition cc
- // label2: <cont.>
- // ATTENTION: all labels pointing to "Bcc label2" must be attached
- // to <cont.> instead
- // ATTENTION: This optimization is only valid if <pred.> is
- // not a skip operation!
- // ATTENTION: somewhere must be within MAX_DIST_BCC bytes!
- // ATTENTION: no label may be attached to the GOTO instruction!
- if (isConditionalBranch(pc_prev)
- && (!isPCI_SKIP(pic16_findPrevInstruction(pc_prev->prev)))
- && (dist < MAX_DIST_BCC)
- && isLabel(pc_next,PCI(pc_prev)->pcop->name)
- && hasNoLabel(pc)) {
- pCode *newBcc = getNegatedBcc (pc_prev, PCI(pc)->pcop);
-
- if (newBcc) {
- //fprintf (stderr, "%s:%d: (4) turning %s %s into %s %s\n", __FUNCTION__, __LINE__, PCI(pc)->mnemonic, label, PCI(newBcc)->mnemonic, label);
- isHandled = 1; // do not perform further optimizations
- if (pic16_pcode_verbose) { pic16_pCodeInsertAfter(pc_prev->prev, pic16_newpCodeCharP("(4) conditional skipping branch inverted")); }
- pic16_pCodeReplace (pc_prev, newBcc);
- pc->destruct(pc);
- pc = newBcc;
- opt_reorder++;
- change++;
- matchedInvertRule++;
- }
- }
- }
-
- /* (5) now just turn GOTO into BRA */
- if (!isHandled && (PCI(pc)->op == POC_GOTO)) {
- if (dist < MAX_DIST_BRA) {
- pCode *newBra = pic16_newpCode (POC_BRA, PCI(pc)->pcop);
- //fprintf (stderr, "%s:%d: (5) turning %s %s into %s %s\n", __FUNCTION__, __LINE__, PCI(pc)->mnemonic, label, PCI(newBra)->mnemonic, label);
- if (pic16_pcode_verbose) { pic16_pCodeInsertAfter(pc->prev, pic16_newpCodeCharP("(5) GOTO replaced by BRA")); }
- pic16_pCodeReplace (pc, newBra);
- pc = newBra;
- opt++;
- change++;
- } else {
- //fprintf (stderr, "(%d, too far for BRA)\n", dist);
- toofar++;
- }
- } // if (!isHandled)
- } // if
-
- pc_prev = pc;
- pc = pc_next;
+ pc_next = pic16_findNextInstructionSkipJumptables (pc->next, &isJumptab);
+ if (isJumptab) {
+ // skip jumptable, i.e. start over with no pc_prev!
+ pc_prev = NULL;
+ pc = pc_next;
+ continue;
+ } // if
+
+ /* (1) resolve chained jumps
+ * Do not perform this until pattern (4) is no longer present! Otherwise we will
+ * (a) leave dead code in and
+ * (b) skip over the dead code with an (unneccessary) jump.
+ */
+ if (!matchedInvertRule && (IS_GOTO(pc) || isConditionalBranch(pc))) {
+ pCodeOp *lastTargetOp = NULL;
+ int newDist = resolveJumpChain (pc, &target, &lastTargetOp);
+ int maxDist = MAX_DIST_BCC;
+ if (PCI(pc)->op == POC_BRA) maxDist = MAX_DIST_BRA;
+ if (PCI(pc)->op == POC_GOTO) maxDist = MAX_DIST_GOTO;
+
+ /* be careful NOT to make the jump instruction longer (might break previously shortened jumps!) */
+ if (lastTargetOp && newDist <= maxDist && lastTargetOp != PCI(pc)->pcop
+ && strcmp (lastTargetOp->name, PCI(pc)->pcop->name) != 0) {
+ //fprintf (stderr, "(1) ");pc->print(stderr, pc); fprintf (stderr, " --> %s\n", lastTargetOp->name);
+ if (pic16_pcode_verbose) { pic16_pCodeInsertAfter (pc->prev, pic16_newpCodeCharP("(1) jump chain resolved")); }
+ PCI(pc)->pcop->name = lastTargetOp->name;
+ change++;
+ opt_gotochain++;
+ } // if
+ } // if
+
+
+ if (IS_GOTO(pc)) {
+ int dist;
+ int condBraType = isSkipOnStatus(pc_prev);
+ label = PCI(pc)->pcop->name;
+ dist = findpCodeLabel(pc, label, MAX_DIST_BRA, &target);
+ if (dist < 0) dist = -dist;
+ //fprintf (stderr, "distance: %d (", dist); pc->print(stderr, pc);fprintf (stderr, ")\n");
+ isHandled = 0;
+
+
+ /* (2) remove "GOTO label; label:" */
+ if (isLabel (pc_next, label)) {
+ //fprintf (stderr, "(2) GOTO next instruction: ");pc->print(stderr, pc);fprintf (stderr, " --> ");pc_next->print(stderr, pc_next); fprintf(stderr, "\n");
+ // first remove all preceeding SKIP instructions
+ while (pc_prev && isPCI_SKIP(pc_prev)) {
+ // attach labels on this instruction to pc_next
+ //fprintf (stderr, "(2) preceeding SKIP removed: ");pc_prev->print(stderr, pc_prev);fprintf(stderr, "\n");
+ PCI(pc_next)->label = pic16_pBranchAppend (PCI(pc_prev)->label, PCI(pc_next)->label);
+ PCI(pc_prev)->label = NULL;
+ if (pic16_pcode_verbose) { pic16_pCodeInsertAfter (pc->prev, pic16_newpCodeCharP("(2) SKIP removed")); }
+ pic16_unlinkpCode (pc_prev);
+ pc_prev = pic16_findPrevInstruction (pc);
+ } // while
+ // now remove the redundant goto itself
+ PCI(pc_next)->label = pic16_pBranchAppend (PCI(pc)->label, PCI(pc_next)->label);
+ if (pic16_pcode_verbose) { pic16_pCodeInsertAfter (pc, pic16_newpCodeCharP("(2) GOTO next instruction removed")); }
+ pic16_unlinkpCode (pc);
+ pc = pic16_findPrevInstruction(pc_next->prev);
+ isHandled = 1; // do not perform further optimizations
+ opt_gotonext++;
+ change++;
+ } // if
+
+
+ /* (3) turn BTFSx STATUS,i; GOTO label into Bcc label if possible */
+ if (!isHandled && condBraType != -1 && hasNoLabel(pc)) {
+ if (dist < MAX_DIST_BCC) {
+ pCode *bcc = NULL;
+ switch (condBraType) {
+ case 0x00: bcc = pic16_newpCode (POC_BC, PCI(pc)->pcop);break;
+ // no BDC on DIGIT CARRY available
+ case 0x02: bcc = pic16_newpCode (POC_BZ, PCI(pc)->pcop);break;
+ case 0x03: bcc = pic16_newpCode (POC_BOV, PCI(pc)->pcop);break;
+ case 0x04: bcc = pic16_newpCode (POC_BN, PCI(pc)->pcop);break;
+ case 0x10: bcc = pic16_newpCode (POC_BNC, PCI(pc)->pcop);break;
+ // no BNDC on DIGIT CARRY available
+ case 0x12: bcc = pic16_newpCode (POC_BNZ, PCI(pc)->pcop);break;
+ case 0x13: bcc = pic16_newpCode (POC_BNOV, PCI(pc)->pcop);break;
+ case 0x14: bcc = pic16_newpCode (POC_BNN, PCI(pc)->pcop);break;
+ default:
+ // no replacement possible
+ bcc = NULL;
+ break;
+ } // switch
+ if (bcc) {
+ // ATTENTION: keep labels attached to BTFSx!
+ // HINT: GOTO is label free (checked above)
+ //fprintf (stderr, "%s:%d: (3) turning %s %s into %s %s\n", __FUNCTION__, __LINE__, PCI(pc)->mnemonic, label, PCI(bcc)->mnemonic, label);
+ isHandled = 1; // do not perform further optimizations
+ if (pic16_pcode_verbose) { pic16_pCodeInsertAfter(pc_prev->prev, pic16_newpCodeCharP("(3) conditional branch introduced")); }
+ pic16_pCodeReplace (pc_prev, bcc);
+ pc->destruct(pc);
+ pc = bcc;
+ opt_cond++;
+ change++;
+ } // if
+ } else {
+ //fprintf (stderr, "(%d, too far for Bcc)\n", dist);
+ cond_toofar++;
+ } // if
+ } // if
+
+ if (!isHandled) {
+ // (4) eliminate the following (common) tripel:
+ // <pred.>;
+ // labels1: Bcc label2;
+ // GOTO somewhere; ; <-- instruction referenced by pc
+ // label2: <cont.>
+ // and replace it by
+ // labels1: B#(cc) somewhere; ; #(cc) is the negated condition cc
+ // label2: <cont.>
+ // ATTENTION: all labels pointing to "Bcc label2" must be attached
+ // to <cont.> instead
+ // ATTENTION: This optimization is only valid if <pred.> is
+ // not a skip operation!
+ // ATTENTION: somewhere must be within MAX_DIST_BCC bytes!
+ // ATTENTION: no label may be attached to the GOTO instruction!
+ if (isConditionalBranch(pc_prev)
+ && (!isPCI_SKIP(pic16_findPrevInstruction(pc_prev->prev)))
+ && (dist < MAX_DIST_BCC)
+ && isLabel(pc_next,PCI(pc_prev)->pcop->name)
+ && hasNoLabel(pc)) {
+ pCode *newBcc = getNegatedBcc (pc_prev, PCI(pc)->pcop);
+
+ if (newBcc) {
+ //fprintf (stderr, "%s:%d: (4) turning %s %s into %s %s\n", __FUNCTION__, __LINE__, PCI(pc)->mnemonic, label, PCI(newBcc)->mnemonic, label);
+ isHandled = 1; // do not perform further optimizations
+ if (pic16_pcode_verbose) { pic16_pCodeInsertAfter(pc_prev->prev, pic16_newpCodeCharP("(4) conditional skipping branch inverted")); }
+ pic16_pCodeReplace (pc_prev, newBcc);
+ pc->destruct(pc);
+ pc = newBcc;
+ opt_reorder++;
+ change++;
+ matchedInvertRule++;
+ }
+ }
+ }
+
+ /* (5) now just turn GOTO into BRA */
+ if (!isHandled && (PCI(pc)->op == POC_GOTO)) {
+ if (dist < MAX_DIST_BRA) {
+ pCode *newBra = pic16_newpCode (POC_BRA, PCI(pc)->pcop);
+ //fprintf (stderr, "%s:%d: (5) turning %s %s into %s %s\n", __FUNCTION__, __LINE__, PCI(pc)->mnemonic, label, PCI(newBra)->mnemonic, label);
+ if (pic16_pcode_verbose) { pic16_pCodeInsertAfter(pc->prev, pic16_newpCodeCharP("(5) GOTO replaced by BRA")); }
+ pic16_pCodeReplace (pc, newBra);
+ pc = newBra;
+ opt++;
+ change++;
+ } else {
+ //fprintf (stderr, "(%d, too far for BRA)\n", dist);
+ toofar++;
+ }
+ } // if (!isHandled)
+ } // if
+
+ pc_prev = pc;
+ pc = pc_next;
- "PO_NONE", // No operand e.g. NOP
- "PO_W", // The working register (as a destination)
- "PO_WREG", // The working register (as a file register)
- "PO_STATUS", // The 'STATUS' register
- "PO_BSR", // The 'BSR' register
- "PO_FSR0", // The "file select register" (in PIC18 family it's one
- // of three)
- "PO_INDF0", // The Indirect register
- "PO_INTCON", // Interrupt Control register
- "PO_GPR_REGISTER", // A general purpose register
- "PO_GPR_BIT", // A bit of a general purpose register
- "PO_GPR_TEMP", // A general purpose temporary register
- "PO_SFR_REGISTER", // A special function register (e.g. PORTA)
- "PO_PCL", // Program counter Low register
- "PO_PCLATH", // Program counter Latch high register
- "PO_PCLATU", // Program counter Latch upper register
- "PO_PRODL", // Product Register Low
- "PO_PRODH", // Product Register High
- "PO_LITERAL", // A constant
- "PO_REL_ADDR", // A relative address
- "PO_IMMEDIATE", // (8051 legacy)
- "PO_DIR", // Direct memory (8051 legacy)
- "PO_CRY", // bit memory (8051 legacy)
- "PO_BIT", // bit operand.
- "PO_STR", // (8051 legacy)
- "PO_LABEL",
- "PO_WILD", // Wild card operand in peep optimizer
- "PO_TWO_OPS" // combine two operands
+ "PO_NONE", // No operand e.g. NOP
+ "PO_W", // The working register (as a destination)
+ "PO_WREG", // The working register (as a file register)
+ "PO_STATUS", // The 'STATUS' register
+ "PO_BSR", // The 'BSR' register
+ "PO_FSR0", // The "file select register" (in PIC18 family it's one
+ // of three)
+ "PO_INDF0", // The Indirect register
+ "PO_INTCON", // Interrupt Control register
+ "PO_GPR_REGISTER", // A general purpose register
+ "PO_GPR_BIT", // A bit of a general purpose register
+ "PO_GPR_TEMP", // A general purpose temporary register
+ "PO_SFR_REGISTER", // A special function register (e.g. PORTA)
+ "PO_PCL", // Program counter Low register
+ "PO_PCLATH", // Program counter Latch high register
+ "PO_PCLATU", // Program counter Latch upper register
+ "PO_PRODL", // Product Register Low
+ "PO_PRODH", // Product Register High
+ "PO_LITERAL", // A constant
+ "PO_REL_ADDR", // A relative address
+ "PO_IMMEDIATE", // (8051 legacy)
+ "PO_DIR", // Direct memory (8051 legacy)
+ "PO_CRY", // bit memory (8051 legacy)
+ "PO_BIT", // bit operand.
+ "PO_STR", // (8051 legacy)
+ "PO_LABEL",
+ "PO_WILD", // Wild card operand in peep optimizer
+ "PO_TWO_OPS" // combine two operands
- {"WREG", SPO_WREG},
- {"STATUS", SPO_STATUS},
- {"PRODL", SPO_PRODL},
- {"PRODH", SPO_PRODH},
- {"INDF0", SPO_INDF0},
- {"POSTDEC0", SPO_POSTDEC0},
- {"POSTINC0", SPO_POSTINC0},
- {"PREINC0", SPO_PREINC0},
- {"PLUSW0", SPO_PLUSW0},
- {"INDF1", SPO_INDF1},
- {"POSTDEC1", SPO_POSTDEC1},
- {"POSTINC1", SPO_POSTINC1},
- {"PREINC1", SPO_PREINC1},
- {"PLUSW1", SPO_PLUSW1},
- {"INDF2", SPO_INDF2},
- {"POSTDEC2", SPO_POSTDEC2},
- {"POSTINC2", SPO_POSTINC2},
- {"PREINC2", SPO_PREINC2},
- {"PLUSW2", SPO_PLUSW2},
- {"STKPTR", SPO_STKPTR},
- {"TOSL", SPO_TOSL},
- {"TOSH", SPO_TOSH},
- {"TOSU", SPO_TOSU},
- {"BSR", SPO_BSR},
- {"FSR0L", SPO_FSR0L},
- {"FSR0H", SPO_FSR0H},
- {"FSR1L", SPO_FSR1L},
- {"FSR1H", SPO_FSR1H},
- {"FSR2L", SPO_FSR2L},
- {"FSR2H", SPO_FSR2H},
- {"PCL", SPO_PCL},
- {"PCLATH", SPO_PCLATH},
- {"PCLATU", SPO_PCLATU},
- {"TABLAT", SPO_TABLAT},
- {"TBLPTRL", SPO_TBLPTRL},
- {"TBLPTRH", SPO_TBLPTRH},
- {"TBLPTRU", SPO_TBLPTRU},
- {NULL, 0}
+ {"WREG", SPO_WREG},
+ {"STATUS", SPO_STATUS},
+ {"PRODL", SPO_PRODL},
+ {"PRODH", SPO_PRODH},
+ {"INDF0", SPO_INDF0},
+ {"POSTDEC0", SPO_POSTDEC0},
+ {"POSTINC0", SPO_POSTINC0},
+ {"PREINC0", SPO_PREINC0},
+ {"PLUSW0", SPO_PLUSW0},
+ {"INDF1", SPO_INDF1},
+ {"POSTDEC1", SPO_POSTDEC1},
+ {"POSTINC1", SPO_POSTINC1},
+ {"PREINC1", SPO_PREINC1},
+ {"PLUSW1", SPO_PLUSW1},
+ {"INDF2", SPO_INDF2},
+ {"POSTDEC2", SPO_POSTDEC2},
+ {"POSTINC2", SPO_POSTINC2},
+ {"PREINC2", SPO_PREINC2},
+ {"PLUSW2", SPO_PLUSW2},
+ {"STKPTR", SPO_STKPTR},
+ {"TOSL", SPO_TOSL},
+ {"TOSH", SPO_TOSH},
+ {"TOSU", SPO_TOSU},
+ {"BSR", SPO_BSR},
+ {"FSR0L", SPO_FSR0L},
+ {"FSR0H", SPO_FSR0H},
+ {"FSR1L", SPO_FSR1L},
+ {"FSR1H", SPO_FSR1H},
+ {"FSR2L", SPO_FSR2L},
+ {"FSR2H", SPO_FSR2H},
+ {"PCL", SPO_PCL},
+ {"PCLATH", SPO_PCLATH},
+ {"PCLATU", SPO_PCLATU},
+ {"TABLAT", SPO_TABLAT},
+ {"TBLPTRL", SPO_TBLPTRL},
+ {"TBLPTRH", SPO_TBLPTRH},
+ {"TBLPTRU", SPO_TBLPTRU},
+ {NULL, 0}