0
0
mirror of https://github.com/netwide-assembler/nasm.git synced 2025-08-23 10:33:50 -04:00

output/outelf32.c: code style simplification

1) nasm_free is safe against NULL passed so call
   it without test

2) dwarf32_output: check for debug_immcall early
   and get out of procedure if success. This allow
   us to move code blocks left removing indents.

3) dwarf32_findfile and dwarf32_findsect: no need
   for 'else' when 'if' target is plain return.
   Move code blocks left removing indents.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
This commit is contained in:
Cyrill Gorcunov 2009-09-03 20:16:28 +04:00
parent 6ae5903676
commit 7ea1ef1c84

View File

@ -1781,18 +1781,17 @@ static void stabs32_cleanup(void)
struct linelist *ptr, *del; struct linelist *ptr, *del;
if (!stabslines) if (!stabslines)
return; return;
ptr = stabslines; ptr = stabslines;
while (ptr) { while (ptr) {
del = ptr; del = ptr;
ptr = ptr->next; ptr = ptr->next;
nasm_free(del); nasm_free(del);
} }
if (stabbuf)
nasm_free(stabbuf); nasm_free(stabbuf);
if (stabrelbuf) nasm_free(stabrelbuf);
nasm_free(stabrelbuf); nasm_free(stabstrbuf);
if (stabstrbuf)
nasm_free(stabstrbuf);
} }
/* dwarf routines */ /* dwarf routines */
@ -1831,40 +1830,42 @@ static void dwarf32_output(int type, void *param)
dwarf32_findsect(s->section); dwarf32_findsect(s->section);
/* do nothing unless line or file has changed */ /* do nothing unless line or file has changed */
if (debug_immcall) { if (!debug_immcall)
ln = currentline - dwarf_csect->line; return;
aa = s->offset - dwarf_csect->offset;
inx = dwarf_clist->line; ln = currentline - dwarf_csect->line;
plinep = dwarf_csect->psaa; aa = s->offset - dwarf_csect->offset;
/* check for file change */ inx = dwarf_clist->line;
if (!(inx == dwarf_csect->file)) { plinep = dwarf_csect->psaa;
saa_write8(plinep,DW_LNS_set_file); /* check for file change */
saa_write8(plinep,inx); if (!(inx == dwarf_csect->file)) {
dwarf_csect->file = inx; saa_write8(plinep,DW_LNS_set_file);
} saa_write8(plinep,inx);
/* check for line change */ dwarf_csect->file = inx;
if (ln) { }
/* test if in range of special op code */ /* check for line change */
maxln = line_base + line_range; if (ln) {
soc = (ln - line_base) + (line_range * aa) + opcode_base; /* test if in range of special op code */
if (ln >= line_base && ln < maxln && soc < 256) { maxln = line_base + line_range;
saa_write8(plinep,soc); soc = (ln - line_base) + (line_range * aa) + opcode_base;
} else { if (ln >= line_base && ln < maxln && soc < 256) {
if (ln) { saa_write8(plinep,soc);
saa_write8(plinep,DW_LNS_advance_line); } else {
saa_wleb128s(plinep,ln); if (ln) {
} saa_write8(plinep,DW_LNS_advance_line);
if (aa) { saa_wleb128s(plinep,ln);
saa_write8(plinep,DW_LNS_advance_pc); }
saa_wleb128u(plinep,aa); if (aa) {
} saa_write8(plinep,DW_LNS_advance_pc);
} saa_wleb128u(plinep,aa);
dwarf_csect->line = currentline; }
dwarf_csect->offset = s->offset; }
} dwarf_csect->line = currentline;
/* show change handled */ dwarf_csect->offset = s->offset;
debug_immcall = 0; }
}
/* show change handled */
debug_immcall = 0;
} }
@ -2103,27 +2104,18 @@ static void dwarf32_generate(void)
static void dwarf32_cleanup(void) static void dwarf32_cleanup(void)
{ {
if (arangesbuf) nasm_free(arangesbuf);
nasm_free(arangesbuf); nasm_free(arangesrelbuf);
if (arangesrelbuf) nasm_free(pubnamesbuf);
nasm_free(arangesrelbuf); nasm_free(infobuf);
if (pubnamesbuf) nasm_free(inforelbuf);
nasm_free(pubnamesbuf); nasm_free(abbrevbuf);
if (infobuf) nasm_free(linebuf);
nasm_free(infobuf); nasm_free(linerelbuf);
if (inforelbuf) nasm_free(framebuf);
nasm_free(inforelbuf); nasm_free(locbuf);
if (abbrevbuf)
nasm_free(abbrevbuf);
if (linebuf)
nasm_free(linebuf);
if (linerelbuf)
nasm_free(linerelbuf);
if (framebuf)
nasm_free(framebuf);
if (locbuf)
nasm_free(locbuf);
} }
static void dwarf32_findfile(const char * fname) static void dwarf32_findfile(const char * fname)
{ {
int finx; int finx;
@ -2132,33 +2124,34 @@ static void dwarf32_findfile(const char * fname)
/* return if fname is current file name */ /* return if fname is current file name */
if (dwarf_clist && !(strcmp(fname, dwarf_clist->filename))) if (dwarf_clist && !(strcmp(fname, dwarf_clist->filename)))
return; return;
/* search for match */ /* search for match */
else { match = 0;
match = 0; if (dwarf_flist) {
if (dwarf_flist) { match = dwarf_flist;
match = dwarf_flist; for (finx = 0; finx < dwarf_numfiles; finx++) {
for (finx = 0; finx < dwarf_numfiles; finx++) { if (!(strcmp(fname, match->filename))) {
if (!(strcmp(fname, match->filename))) { dwarf_clist = match;
dwarf_clist = match; return;
return;
}
} }
} }
/* add file name to end of list */
dwarf_clist = (struct linelist *)nasm_malloc(sizeof(struct linelist));
dwarf_numfiles++;
dwarf_clist->line = dwarf_numfiles;
dwarf_clist->filename = nasm_malloc(strlen(fname) + 1);
strcpy(dwarf_clist->filename,fname);
dwarf_clist->next = 0;
if (!dwarf_flist) { /* if first entry */
dwarf_flist = dwarf_elist = dwarf_clist;
dwarf_clist->last = 0;
} else { /* chain to previous entry */
dwarf_elist->next = dwarf_clist;
dwarf_elist = dwarf_clist;
}
} }
/* add file name to end of list */
dwarf_clist = (struct linelist *)nasm_malloc(sizeof(struct linelist));
dwarf_numfiles++;
dwarf_clist->line = dwarf_numfiles;
dwarf_clist->filename = nasm_malloc(strlen(fname) + 1);
strcpy(dwarf_clist->filename,fname);
dwarf_clist->next = 0;
if (!dwarf_flist) { /* if first entry */
dwarf_flist = dwarf_elist = dwarf_clist;
dwarf_clist->last = 0;
} else { /* chain to previous entry */
dwarf_elist->next = dwarf_clist;
dwarf_elist = dwarf_clist;
}
} }
static void dwarf32_findsect(const int index) static void dwarf32_findsect(const int index)
@ -2170,42 +2163,42 @@ static void dwarf32_findsect(const int index)
/* return if index is current section index */ /* return if index is current section index */
if (dwarf_csect && (dwarf_csect->section == index)) if (dwarf_csect && (dwarf_csect->section == index))
return; return;
/* search for match */
else {
match = 0;
if (dwarf_fsect) {
match = dwarf_fsect;
for (sinx = 0; sinx < dwarf_nsections; sinx++) {
if ((match->section == index)) {
dwarf_csect = match;
return;
}
match = match->next;
}
}
/* add entry to end of list */
dwarf_csect = (struct sectlist *)nasm_malloc(sizeof(struct sectlist));
dwarf_nsections++;
dwarf_csect->psaa = plinep = saa_init(1L);
dwarf_csect->line = 1;
dwarf_csect->offset = 0;
dwarf_csect->file = 1;
dwarf_csect->section = index;
dwarf_csect->next = 0;
/* set relocatable address at start of line program */
saa_write8(plinep,DW_LNS_extended_op);
saa_write8(plinep,5); /* operand length */
saa_write8(plinep,DW_LNE_set_address);
saa_write32(plinep,0); /* Start Address */
if (!dwarf_fsect) { /* if first entry */ /* search for match */
dwarf_fsect = dwarf_esect = dwarf_csect; match = 0;
dwarf_csect->last = 0; if (dwarf_fsect) {
} else { /* chain to previous entry */ match = dwarf_fsect;
dwarf_esect->next = dwarf_csect; for (sinx = 0; sinx < dwarf_nsections; sinx++) {
dwarf_esect = dwarf_csect; if ((match->section == index)) {
dwarf_csect = match;
return;
}
match = match->next;
} }
} }
/* add entry to end of list */
dwarf_csect = (struct sectlist *)nasm_malloc(sizeof(struct sectlist));
dwarf_nsections++;
dwarf_csect->psaa = plinep = saa_init(1L);
dwarf_csect->line = 1;
dwarf_csect->offset = 0;
dwarf_csect->file = 1;
dwarf_csect->section = index;
dwarf_csect->next = 0;
/* set relocatable address at start of line program */
saa_write8(plinep,DW_LNS_extended_op);
saa_write8(plinep,5); /* operand length */
saa_write8(plinep,DW_LNE_set_address);
saa_write32(plinep,0); /* Start Address */
if (!dwarf_fsect) { /* if first entry */
dwarf_fsect = dwarf_esect = dwarf_csect;
dwarf_csect->last = 0;
} else { /* chain to previous entry */
dwarf_esect->next = dwarf_csect;
dwarf_esect = dwarf_csect;
}
} }
#endif /* OF_ELF */ #endif /* OF_ELF */