Skip to content

Commit

Permalink
harmonize lib code
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Aug 10, 2011
1 parent d5c0d1d commit 656cc19
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 30 deletions.
11 changes: 8 additions & 3 deletions src/lib.h
@@ -1,6 +1,6 @@

// Compiler implementation of the D programming language
// Copyright (c) 1999-2008 by Digital Mars
// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
Expand All @@ -23,11 +23,16 @@ struct ObjSymbol
ObjModule *om;
};

#include "arraytypes.h"

typedef ArrayBase<ObjModule> ObjModules;
typedef ArrayBase<ObjSymbol> ObjSymbols;

struct Library
{
File *libfile;
Array objmodules; // ObjModule[]
Array objsymbols; // ObjSymbol[]
ObjModules objmodules; // ObjModule[]
ObjSymbols objsymbols; // ObjSymbol[]

StringTable tab;

Expand Down
20 changes: 10 additions & 10 deletions src/libelf.c
Expand Up @@ -46,7 +46,7 @@ void Library::setFilename(char *dir, char *filename)
char *arg = filename;
if (!arg || !*arg)
{ // Generate lib file name from first obj name
char *n = (char *)global.params.objfiles->data[0];
char *n = global.params.objfiles->tdata()[0];

n = FileName::name(n);
FileName *fn = FileName::forceExt(n, global.lib_ext);
Expand Down Expand Up @@ -542,7 +542,7 @@ void Library::addObject(const char *module_name, void *buf, size_t buflen)
{ reason = 12;
goto Lcorrupt; // didn't find it
}
ObjModule *om = (ObjModule *)objmodules.data[m];
ObjModule *om = objmodules.tdata()[m];
//printf("\t%x\n", (char *)om->base - (char *)buf);
if (moff + sizeof(Header) == (char *)om->base - (char *)buf)
{
Expand Down Expand Up @@ -625,7 +625,7 @@ void Library::WriteLibToBuffer(OutBuffer *libbuf)
/************* Scan Object Modules for Symbols ******************/

for (int i = 0; i < objmodules.dim; i++)
{ ObjModule *om = (ObjModule *)objmodules.data[i];
{ ObjModule *om = objmodules.tdata()[i];
if (om->scan)
{
scanObjModule(om);
Expand All @@ -638,7 +638,7 @@ void Library::WriteLibToBuffer(OutBuffer *libbuf)
*/
unsigned noffset = 0;
for (int i = 0; i < objmodules.dim; i++)
{ ObjModule *om = (ObjModule *)objmodules.data[i];
{ ObjModule *om = objmodules.tdata()[i];
size_t len = strlen(om->name);
if (len >= OBJECT_NAME_SIZE)
{
Expand All @@ -658,7 +658,7 @@ void Library::WriteLibToBuffer(OutBuffer *libbuf)
unsigned moffset = 8 + sizeof(Header) + 4;

for (int i = 0; i < objsymbols.dim; i++)
{ ObjSymbol *os = (ObjSymbol *)objsymbols.data[i];
{ ObjSymbol *os = objsymbols.tdata()[i];

moffset += 4 + strlen(os->name) + 1;
}
Expand All @@ -673,7 +673,7 @@ void Library::WriteLibToBuffer(OutBuffer *libbuf)
moffset += sizeof(Header) + noffset;

for (int i = 0; i < objmodules.dim; i++)
{ ObjModule *om = (ObjModule *)objmodules.data[i];
{ ObjModule *om = objmodules.tdata()[i];

moffset += moffset & 1;
om->offset = moffset;
Expand Down Expand Up @@ -704,14 +704,14 @@ void Library::WriteLibToBuffer(OutBuffer *libbuf)
libbuf->write(buf, 4);

for (int i = 0; i < objsymbols.dim; i++)
{ ObjSymbol *os = (ObjSymbol *)objsymbols.data[i];
{ ObjSymbol *os = objsymbols.tdata()[i];

sputl(os->om->offset, buf);
libbuf->write(buf, 4);
}

for (int i = 0; i < objsymbols.dim; i++)
{ ObjSymbol *os = (ObjSymbol *)objsymbols.data[i];
{ ObjSymbol *os = objsymbols.tdata()[i];

libbuf->writestring(os->name);
libbuf->writeByte(0);
Expand Down Expand Up @@ -740,7 +740,7 @@ void Library::WriteLibToBuffer(OutBuffer *libbuf)
libbuf->write(&h, sizeof(h));

for (int i = 0; i < objmodules.dim; i++)
{ ObjModule *om = (ObjModule *)objmodules.data[i];
{ ObjModule *om = objmodules.tdata()[i];
if (om->name_offset >= 0)
{ libbuf->writestring(om->name);
libbuf->writeByte('/');
Expand All @@ -752,7 +752,7 @@ void Library::WriteLibToBuffer(OutBuffer *libbuf)
/* Write out each of the object modules
*/
for (int i = 0; i < objmodules.dim; i++)
{ ObjModule *om = (ObjModule *)objmodules.data[i];
{ ObjModule *om = objmodules.tdata()[i];

if (libbuf->offset & 1)
libbuf->writeByte('\n'); // module alignment
Expand Down
16 changes: 8 additions & 8 deletions src/libmach.c
Expand Up @@ -57,7 +57,7 @@ void Library::setFilename(char *dir, char *filename)
char *arg = filename;
if (!arg || !*arg)
{ // Generate lib file name from first obj name
char *n = (char *)global.params.objfiles->data[0];
char *n = global.params.objfiles->tdata()[0];

n = FileName::name(n);
FileName *fn = FileName::forceExt(n, global.lib_ext);
Expand Down Expand Up @@ -479,7 +479,7 @@ void Library::addObject(const char *module_name, void *buf, size_t buflen)
{ reason = 12;
goto Lcorrupt; // didn't find it
}
ObjModule *om = (ObjModule *)objmodules.data[m];
ObjModule *om = objmodules.tdata()[m];
//printf("\tom offset = x%x\n", (char *)om->base - (char *)buf);
if (moff == (char *)om->base - (char *)buf)
{
Expand Down Expand Up @@ -562,7 +562,7 @@ void Library::WriteLibToBuffer(OutBuffer *libbuf)
/************* Scan Object Modules for Symbols ******************/

for (int i = 0; i < objmodules.dim; i++)
{ ObjModule *om = (ObjModule *)objmodules.data[i];
{ ObjModule *om = objmodules.tdata()[i];
if (om->scan)
{
scanObjModule(om);
Expand All @@ -574,7 +574,7 @@ void Library::WriteLibToBuffer(OutBuffer *libbuf)
unsigned moffset = 8 + sizeof(Header) + 4 + 4;

for (int i = 0; i < objsymbols.dim; i++)
{ ObjSymbol *os = (ObjSymbol *)objsymbols.data[i];
{ ObjSymbol *os = objsymbols.tdata()[i];

moffset += 8 + strlen(os->name) + 1;
}
Expand All @@ -588,7 +588,7 @@ void Library::WriteLibToBuffer(OutBuffer *libbuf)
#endif

for (int i = 0; i < objmodules.dim; i++)
{ ObjModule *om = (ObjModule *)objmodules.data[i];
{ ObjModule *om = objmodules.tdata()[i];

moffset += moffset & 1;
om->offset = moffset;
Expand Down Expand Up @@ -639,7 +639,7 @@ void Library::WriteLibToBuffer(OutBuffer *libbuf)

int stringoff = 0;
for (int i = 0; i < objsymbols.dim; i++)
{ ObjSymbol *os = (ObjSymbol *)objsymbols.data[i];
{ ObjSymbol *os = objsymbols.tdata()[i];

sputl(stringoff, buf);
libbuf->write(buf, 4);
Expand All @@ -654,7 +654,7 @@ void Library::WriteLibToBuffer(OutBuffer *libbuf)
libbuf->write(buf, 4);

for (int i = 0; i < objsymbols.dim; i++)
{ ObjSymbol *os = (ObjSymbol *)objsymbols.data[i];
{ ObjSymbol *os = objsymbols.tdata()[i];

libbuf->writestring(os->name);
libbuf->writeByte(0);
Expand All @@ -673,7 +673,7 @@ void Library::WriteLibToBuffer(OutBuffer *libbuf)
/* Write out each of the object modules
*/
for (int i = 0; i < objmodules.dim; i++)
{ ObjModule *om = (ObjModule *)objmodules.data[i];
{ ObjModule *om = objmodules.tdata()[i];

if (libbuf->offset & 1)
libbuf->writeByte('\n'); // module alignment
Expand Down
18 changes: 9 additions & 9 deletions src/libomf.c
Expand Up @@ -42,7 +42,7 @@ void Library::setFilename(char *dir, char *filename)
char *arg = filename;
if (!arg || !*arg)
{ // Generate lib file name from first obj name
char *n = (char *)global.params.objfiles->data[0];
char *n = global.params.objfiles->tdata()[0];

n = FileName::name(n);
FileName *fn = FileName::forceExt(n, global.lib_ext);
Expand Down Expand Up @@ -534,13 +534,13 @@ unsigned short Library::numDictPages(unsigned padding)
unsigned symSize = 0;

for (size_t i = 0; i < objsymbols.dim; i++)
{ ObjSymbol *s = (ObjSymbol *)objsymbols.data[i];
{ ObjSymbol *s = objsymbols.tdata()[i];

symSize += ( strlen(s->name) + 4 ) & ~1;
}

for (size_t i = 0; i < objmodules.dim; i++)
{ ObjModule *om = (ObjModule *)objmodules.data[i];
{ ObjModule *om = objmodules.tdata()[i];

size_t len = strlen(om->name);
if (len > 0xFF)
Expand Down Expand Up @@ -716,7 +716,7 @@ int Library::FillDict(unsigned char *bucketsP, unsigned short ndicpages)

// Add each of the module names
for (size_t i = 0; i < objmodules.dim; i++)
{ ObjModule *om = (ObjModule *)objmodules.data[i];
{ ObjModule *om = objmodules.tdata()[i];

unsigned short n = strlen( om->name );
if (n > 255)
Expand All @@ -739,11 +739,11 @@ int Library::FillDict(unsigned char *bucketsP, unsigned short ndicpages)
}

// Sort the symbols
qsort( objsymbols.data, objsymbols.dim, 4, (cmpfunc_t)NameCompare );
qsort( objsymbols.tdata(), objsymbols.dim, 4, (cmpfunc_t)NameCompare );

// Add each of the symbols
for (size_t i = 0; i < objsymbols.dim; i++)
{ ObjSymbol *os = (ObjSymbol *)objsymbols.data[i];
{ ObjSymbol *os = objsymbols.tdata()[i];

unsigned short n = strlen( os->name );
if (n > 255)
Expand Down Expand Up @@ -784,7 +784,7 @@ void Library::WriteLibToBuffer(OutBuffer *libbuf)
* to go into the dictionary
*/
for (size_t i = 0; i < objmodules.dim; i++)
{ ObjModule *om = (ObjModule *)objmodules.data[i];
{ ObjModule *om = objmodules.tdata()[i];

scanObjModule(om);
}
Expand All @@ -804,7 +804,7 @@ void Library::WriteLibToBuffer(OutBuffer *libbuf)
unsigned offset = g_page_size;

for (size_t i = 0; i < objmodules.dim; i++)
{ ObjModule *om = (ObjModule *)objmodules.data[i];
{ ObjModule *om = objmodules.tdata()[i];

unsigned page = offset / g_page_size;
if (page > 0xFFFF)
Expand Down Expand Up @@ -844,7 +844,7 @@ void Library::WriteLibToBuffer(OutBuffer *libbuf)
/* Write each object module into the library
*/
for (size_t i = 0; i < objmodules.dim; i++)
{ ObjModule *om = (ObjModule *)objmodules.data[i];
{ ObjModule *om = objmodules.tdata()[i];

unsigned page = libbuf->offset / g_page_size;
assert(page <= 0xFFFF);
Expand Down

0 comments on commit 656cc19

Please sign in to comment.