Skip to content

Commit

Permalink
The Sfilename member of struct Srcpos shouldn't be dependent on TX86.
Browse files Browse the repository at this point in the history
Cleanup a bunch of repeated conditional code by moving it inside a helper function.
  • Loading branch information
braddr committed Jul 13, 2011
1 parent b725965 commit 3d172b8
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 70 deletions.
4 changes: 3 additions & 1 deletion src/backend/cc.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,17 +220,19 @@ typedef struct Srcpos
#define srcpos_sfile(p) (**(p).Sfilptr)
#define srcpos_name(p) (srcpos_sfile(p).SFname)
#endif
#endif
#if MARS
const char *Sfilename;
#define srcpos_name(p) ((p).SFname)
#endif
#endif
#if M_UNIX
short Sfilnum; // file number
#endif
#if SOURCE_OFFSETS
unsigned long Sfiloff; // byte offset
#endif

void print(const char *func);
} Srcpos;

#ifndef TOKEN_H
Expand Down
6 changes: 1 addition & 5 deletions src/backend/cgen.c
Original file line number Diff line number Diff line change
Expand Up @@ -463,11 +463,7 @@ code *genlinnum(code *c,Srcpos srcpos)
{ code cs;

#if 0
#if MARS
printf("genlinnum(Sfilename = %p, Slinnum = %u)\n", srcpos.Sfilename, srcpos.Slinnum);
#else
printf("genlinnum(Sfilptr = %p, Slinnum = %u)\n", srcpos.Sfilptr, srcpos.Slinnum);
#endif
srcpos.print("genlinnum");
#endif
cs.Iop = ESCAPE | ESClinnum;
cs.Iflags = 0;
Expand Down
15 changes: 4 additions & 11 deletions src/backend/cgobj.c
Original file line number Diff line number Diff line change
Expand Up @@ -801,19 +801,12 @@ void objlinnum(Srcpos srcpos,targ_size_t offset)
unsigned linnum = srcpos.Slinnum;

#if 0
#if MARS
printf("objlinnum(cseg=%d, filename=%s linnum=%u, offset=x%lx)\n",
cseg,srcpos.Sfilename ? srcpos.Sfilename : "null",linnum,offset);
#else
printf("objlinnum(cseg=%d, filptr=%p linnum=%u, offset=x%lx)\n",
cseg,srcpos.Sfilptr ? *srcpos.Sfilptr : 0,linnum,offset);
if (srcpos.Sfilptr)
{
Sfile *sf = *srcpos.Sfilptr;
printf("filename = %s\n", sf ? sf->SFname : "null");
}
#if MARS || SCPP
printf("objlinnum(cseg=%d, offset=0x%lx) ", cseg, offset);
#endif
srcpos.print("");
#endif

char linos2 = config.exe == EX_OS2 && cseg >= 0;

#if MARS
Expand Down
14 changes: 1 addition & 13 deletions src/backend/el.c
Original file line number Diff line number Diff line change
Expand Up @@ -2947,19 +2947,7 @@ void elem_print(elem *e)
elem_debug(e);
if (configv.addlinenumbers)
{
#if TX86
#if MARS
dbg_printf("fil=%p lin=%u ",e->Esrcpos.Sfilename,e->Esrcpos.Slinnum);
#elif SCPP
dbg_printf("fil=%p lin=%u ",e->Esrcpos.Sfilptr,e->Esrcpos.Slinnum);
#endif
#else
dbg_printf("fil=%d lin=%u ",((struct ELEMsrcpos *)e)->Esrcpos.Sfilnum,
((struct ELEMsrcpos *)e)->Esrcpos.Slinnum);
#endif
#if SOURCE_OFFSETS
dbg_printf("off %d ",((struct ELEMsrcpos *)e)->Esrcpos.Sfiloff);
#endif
e->Esrcpos.print("elem_print");
}
if (!PARSER)
{ dbg_printf("cnt=%d ",e->Ecount);
Expand Down
27 changes: 7 additions & 20 deletions src/backend/elfobj.c
Original file line number Diff line number Diff line change
Expand Up @@ -1244,38 +1244,25 @@ void obj_term()

void objlinnum(Srcpos srcpos, targ_size_t offset)
{
unsigned linnum = srcpos.Slinnum;
if (linnum == 0)
if (srcpos.Slinnum == 0)
return;

#if 0
#if MARS
printf("objlinnum(cseg=%d, filename=%s linnum=%u, offset=x%lx)\n",
cseg,srcpos.Sfilename ? srcpos.Sfilename : "null",linnum,offset);
#endif
#if SCPP
printf("objlinnum(cseg=%d, filptr=%p linnum=%u, offset=x%lx)\n",
cseg,srcpos.Sfilptr ? *srcpos.Sfilptr : 0,linnum,offset);
if (srcpos.Sfilptr)
{
Sfile *sf = *srcpos.Sfilptr;
printf("filename = %s\n", sf ? sf->SFname : "null");
}
#if MARS || SCPP
printf("objlinnum(cseg=%d, offset=0x%lx) ", cseg, offset);
#endif
srcpos.print("");
#endif

#if MARS
if (!srcpos.Sfilename)
return;
#endif
#if SCPP
Sfile *sf;
if (srcpos.Sfilptr)
{ sfile_debug(&srcpos_sfile(srcpos));
sf = *srcpos.Sfilptr;
}
else
if (!srcpos.Sfilptr)
return;
sfile_debug(&srcpos_sfile(srcpos));
Sfile *sf = *srcpos.Sfilptr;
#endif

size_t i;
Expand Down
27 changes: 7 additions & 20 deletions src/backend/machobj.c
Original file line number Diff line number Diff line change
Expand Up @@ -1034,38 +1034,25 @@ void obj_term()

void objlinnum(Srcpos srcpos, targ_size_t offset)
{
unsigned linnum = srcpos.Slinnum;
if (linnum == 0)
if (srcpos.Slinnum == 0)
return;

#if 0
#if MARS
printf("objlinnum(cseg=%d, filename=%s linnum=%u, offset=x%lx)\n",
cseg,srcpos.Sfilename ? srcpos.Sfilename : "null",linnum,offset);
#endif
#if SCPP
printf("objlinnum(cseg=%d, filptr=%p linnum=%u, offset=x%lx)\n",
cseg,srcpos.Sfilptr ? *srcpos.Sfilptr : 0,linnum,offset);
if (srcpos.Sfilptr)
{
Sfile *sf = *srcpos.Sfilptr;
printf("filename = %s\n", sf ? sf->SFname : "null");
}
#if MARS || SCPP
printf("objlinnum(cseg=%d, offset=x%lx) ", cseg, offset);
#endif
srcpos.print("");
#endif

#if MARS
if (!srcpos.Sfilename)
return;
#endif
#if SCPP
Sfile *sf;
if (srcpos.Sfilptr)
{ sfile_debug(&srcpos_sfile(srcpos));
sf = *srcpos.Sfilptr;
}
else
if (!srcpos.Sfilptr)
return;
sfile_debug(&srcpos_sfile(srcpos));
Sfile *sf = *srcpos.Sfilptr;
#endif

size_t i;
Expand Down
17 changes: 17 additions & 0 deletions src/backend/out.c
Original file line number Diff line number Diff line change
Expand Up @@ -1493,5 +1493,22 @@ symbol *out_readonly_sym(tym_t ty, void *p, int len)
return s;
}

void Srcpos::print(const char *func)
{
printf("%s(", func);
#if MARS
printf("Sfilename = %s", Sfilename ? Sfilename : "null");
#else
Sfile *sf = Sfilptr ? *Sfilptr : NULL;
printf("Sfilptr = %p (filename = %s)", sf, sf ? sf->SFname : "null");
#endif
printf(", Slinnum = %u", Slinnum);
#if SOURCE_OFFSETS
printf(", Sfiloff = %d", Sfiloff);
#endif
printf(")\n");
}


#endif /* !SPP */

0 comments on commit 3d172b8

Please sign in to comment.