Skip to content

Commit

Permalink
more obj refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Jul 14, 2012
1 parent b9afb03 commit 3dd6ca5
Show file tree
Hide file tree
Showing 16 changed files with 2,871 additions and 369 deletions.
2 changes: 0 additions & 2 deletions src/backend/cc.h
Expand Up @@ -717,9 +717,7 @@ typedef struct FUNC_S
// of SCftexpspec explicit specializations
Funcsym *Fsurrogatesym; // Fsurrogate: surrogate cast function

#if TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_OPENBSD || TARGET_SOLARIS
char *Fredirect; // redirect function name to this name in object
#endif
} func_t;

#define func_calloc() ((func_t *) mem_fcalloc(sizeof(func_t)))
Expand Down
22 changes: 21 additions & 1 deletion src/backend/cgobj.c
Expand Up @@ -554,8 +554,10 @@ int Obj::data_readonly(char *p, int len)
* csegname code segment name (can be NULL)
*/

void Obj::init(Outbuffer *objbuf, const char *filename, const char *csegname)
Obj *Obj::init(Outbuffer *objbuf, const char *filename, const char *csegname)
{
Obj *mobj = new Obj();

memset(&obj,0,sizeof(obj));

obj.buf = objbuf;
Expand Down Expand Up @@ -649,6 +651,8 @@ void Obj::init(Outbuffer *objbuf, const char *filename, const char *csegname)
ledata_new(cseg,0); // so ledata is never NULL
if (config.fulltypes) // if full typing information
cv_init(); // initialize debug output code

return mobj;
}

/**************************
Expand Down Expand Up @@ -2365,6 +2369,22 @@ int Obj::data_start(Symbol *sdata, targ_size_t datasize, int seg)
return seg;
}

void Obj::func_start(Symbol *sfunc)
{
//printf("Obj::func_start(%s)\n",sfunc->Sident);
symbol_debug(sfunc);
sfunc->Sseg = cseg; // current code seg
sfunc->Soffset = Coffset; // offset of start of function
}

/*******************************
* Update function info after codgen
*/

void Obj::func_term(Symbol *sfunc)
{
}

/********************************
* Output a public definition.
* Input:
Expand Down
51 changes: 23 additions & 28 deletions src/backend/code.h
Expand Up @@ -985,16 +985,21 @@ void cgsched_block(block *b);
// Generalize the Windows platform concept of CODE,DATA,UDATA,etc
// into multiple segments

#if OMFOBJ
struct Ledatarec; // OMF
struct linnum_data; // Elf, Mach


struct Ledatarec;
typedef unsigned int IDXSTR;
typedef unsigned int IDXSEC;
typedef unsigned int IDXSYM;

struct seg_data
{
int SDseg; // index into SegData[]
targ_size_t SDoffset; // starting offset for data
int SDalignment; // power of 2

#if OMFOBJ
bool isfarseg;
int segidx; // internal object file segment number
int lnameidx; // lname idx of segment name
Expand All @@ -1003,37 +1008,13 @@ struct seg_data
targ_size_t origsize; // original size
long seek; // seek position in output file
Ledatarec *ledata; // current one we're filling in
};

//extern targ_size_t Coffset;

#endif

#if ELFOBJ || MACHOBJ

typedef unsigned int IDXSTR;
typedef unsigned int IDXSEC;
typedef unsigned int IDXSYM;

struct linnum_data
{
const char *filename;
unsigned filenumber; // corresponding file number for DW_LNS_set_file

unsigned linoff_count;
unsigned linoff_max;
unsigned (*linoff)[2]; // [0] = line number, [1] = offset
};

struct seg_data
{
int SDseg; // segment index into SegData[]
#if 1 //ELFOBJ || MACHOBJ
IDXSEC SDshtidx; // section header table index
targ_size_t SDoffset; // starting offset for data
Outbuffer *SDbuf; // buffer to hold data
Outbuffer *SDrel; // buffer to hold relocation info
int SDalignment; // power of 2
#if ELFOBJ
#if 1 //ELFOBJ
IDXSYM SDsymidx; // each section is in the symbol table
IDXSEC SDrelidx; // section header for relocation info
targ_size_t SDrelmaxoff; // maximum offset encountered
Expand All @@ -1050,9 +1031,23 @@ struct seg_data
linnum_data *SDlinnum_data; // array of line number / offset data

int isCode();
#endif
};



#if 1 //ELFOBJ || MACHOBJ

struct linnum_data
{
const char *filename;
unsigned filenumber; // corresponding file number for DW_LNS_set_file

unsigned linoff_count;
unsigned linoff_max;
unsigned (*linoff)[2]; // [0] = line number, [1] = offset
};

#endif

extern seg_data **SegData;
Expand Down
4 changes: 3 additions & 1 deletion src/backend/elfobj.c
Expand Up @@ -631,9 +631,10 @@ int Obj::data_readonly(char *p, int len)
* Called before any other obj_xxx routines
*/

void Obj::init(Outbuffer *objbuf, const char *filename, const char *csegname)
Obj *Obj::init(Outbuffer *objbuf, const char *filename, const char *csegname)
{
//printf("Obj::init()\n");
ElfObj *obj = new ElfObj();

cseg = CODE;
fobjbuf = objbuf;
Expand Down Expand Up @@ -804,6 +805,7 @@ void Obj::init(Outbuffer *objbuf, const char *filename, const char *csegname)

if (config.fulltypes)
dwarf_initfile(filename);
return obj;
}

/**************************
Expand Down
6 changes: 5 additions & 1 deletion src/backend/machobj.c
Expand Up @@ -426,9 +426,11 @@ int Obj::data_readonly(char *p, int len)
* Called before any other obj_xxx routines
*/

void Obj::init(Outbuffer *objbuf, const char *filename, const char *csegname)
Obj *Obj::init(Outbuffer *objbuf, const char *filename, const char *csegname)
{
//printf("Obj::init()\n");
MachObj *obj = new MachObj();

cseg = CODE;
fobjbuf = objbuf;

Expand Down Expand Up @@ -496,6 +498,8 @@ void Obj::init(Outbuffer *objbuf, const char *filename, const char *csegname)

if (config.fulltypes)
dwarf_initfile(filename);

return obj;
}

/**************************
Expand Down

0 comments on commit 3dd6ca5

Please sign in to comment.