diff --git a/compiler/compiler.pas b/compiler/compiler.pas index a3639fc130..6462ef97cb 100644 --- a/compiler/compiler.pas +++ b/compiler/compiler.pas @@ -98,7 +98,8 @@ uses verbose,comphook,systems, cutils,cobjects,globals,options,fmodule,parser,symtable, link,import,export,tokens, - cpunode + { cpu overrides } + cpuswtch,cpunode ; function Compile(const cmd:string):longint; @@ -318,7 +319,11 @@ end; end. { $Log$ - Revision 1.11 2000-11-29 00:30:30 florian + Revision 1.12 2000-12-23 19:59:35 peter + * object to class for ow/og objects + * split objectdata from objectoutput + + Revision 1.11 2000/11/29 00:30:30 florian * unused units removed from uses clause * some changes for widestrings diff --git a/compiler/i386/ag386bin.pas b/compiler/i386/ag386bin.pas index 046a367b98..d519984134 100644 --- a/compiler/i386/ag386bin.pas +++ b/compiler/i386/ag386bin.pas @@ -29,7 +29,10 @@ unit ag386bin; interface uses - cpubase,cobjects,aasm,fmodule,finput,assemble; + cobjects, + cpubase,aasm, + fmodule,finput, + ogbase,assemble; type togtype=(og_none,og_dbg,og_coff,og_pecoff,og_elf); @@ -82,8 +85,10 @@ interface {$ifdef GDB} gdb, {$endif} - ogbase, - ogcoff,ogelf; + { binary writers } + ogcoff,ogelf + ; + {$ifdef GDB} @@ -122,7 +127,7 @@ interface { When in pass 1 then only alloc and leave } if currpass=1 then begin - objectalloc^.staballoc(hp); + objectalloc.staballoc(hp); if assigned(hp) then p[i]:='"'; exit; @@ -217,11 +222,14 @@ interface if assigned(ps) and (ps^.section=sec_none) then begin if currpass=2 then - objectoutput^.writesymbol(ps); - objectoutput^.WriteSymStabs(sec,ofs,hp,ps,nidx,nother,line,reloc) + begin + objectdata.writesymbol(ps); + objectoutput.exportsymbol(ps); + end; + objectdata.WriteSymStabs(sec,ofs,hp,ps,nidx,nother,line,reloc) end else - objectoutput^.WriteStabs(sec,ofs,hp,nidx,nother,line,reloc); + objectdata.WriteStabs(sec,ofs,hp,nidx,nother,line,reloc); if assigned(hp) then p[ii]:='"'; end; @@ -233,13 +241,13 @@ interface begin if currpass=1 then begin - objectalloc^.staballoc(nil); + objectalloc.staballoc(nil); exit; end; if (nidx=n_textline) and assigned(funcname) and (target_os.use_function_relative_addresses) then - objectoutput^.WriteStabs(sec_code,objectoutput^.sectionsize(sec_code)-funcname^.address, + objectdata.WriteStabs(sec_code,objectdata.sectionsize(sec_code)-funcname^.address, nil,nidx,0,line,false) else begin @@ -249,7 +257,7 @@ interface sec:=sec_data else sec:=sec_bss; - objectoutput^.WriteStabs(sec,objectoutput^.sectionsize(sec), + objectdata.WriteStabs(sec,objectdata.sectionsize(sec), nil,nidx,0,line,true); end; end; @@ -284,11 +292,11 @@ interface hp:=newasmsymboltype('Ltext'+ToStr(IncludeCount),AB_LOCAL,AT_FUNCTION); if currpass=1 then begin - hp^.setaddress(objectalloc^.currsec,objectalloc^.sectionsize,0); + hp^.setaddress(objectalloc.currsec,objectalloc.sectionsize,0); UsedAsmSymbolListInsert(hp); end else - objectoutput^.writesymbol(hp); + objectdata.writesymbol(hp); { emit stabs } if (infile^.path^<>'') then EmitStabs('"'+lower(BsToSlash(FixPath(infile^.path^,false)))+'",'+tostr(curr_n)+ @@ -327,18 +335,18 @@ interface if not ((cs_debuginfo in aktmoduleswitches) or (cs_gdb_lineinfo in aktglobalswitches)) then exit; - store_sec:=objectalloc^.currsec; - objectalloc^.setsection(sec_code); + store_sec:=objectalloc.currsec; + objectalloc.setsection(sec_code); hp:=newasmsymboltype('Letext',AB_LOCAL,AT_FUNCTION); if currpass=1 then begin - hp^.setaddress(objectalloc^.currsec,objectalloc^.sectionsize,0); + hp^.setaddress(objectalloc.currsec,objectalloc.sectionsize,0); UsedAsmSymbolListInsert(hp); end else - objectoutput^.writesymbol(hp); + objectdata.writesymbol(hp); EmitStabs('"",'+tostr(n_sourcefile)+',0,0,Letext'); - objectalloc^.setsection(store_sec); + objectalloc.setsection(store_sec); end; {$endif GDB} @@ -376,7 +384,7 @@ interface { always use the maximum fillsize in this pass to avoid possible short jumps to become out of range } pai_align(hp)^.fillsize:=pai_align(hp)^.aligntype; - objectalloc^.sectionalloc(pai_align(hp)^.fillsize); + objectalloc.sectionalloc(pai_align(hp)^.fillsize); end; ait_datablock : begin @@ -386,52 +394,52 @@ interface begin l:=pai_datablock(hp)^.size; if l>2 then - objectalloc^.sectionalign(4) + objectalloc.sectionalign(4) else if l>1 then - objectalloc^.sectionalign(2); - objectalloc^.sectionalloc(pai_datablock(hp)^.size); + objectalloc.sectionalign(2); + objectalloc.sectionalloc(pai_datablock(hp)^.size); end; end else begin l:=pai_datablock(hp)^.size; if l>2 then - objectalloc^.sectionalign(4) + objectalloc.sectionalign(4) else if l>1 then - objectalloc^.sectionalign(2); - objectalloc^.sectionalloc(pai_datablock(hp)^.size); + objectalloc.sectionalign(2); + objectalloc.sectionalloc(pai_datablock(hp)^.size); end; end; ait_const_32bit : - objectalloc^.sectionalloc(4); + objectalloc.sectionalloc(4); ait_const_16bit : - objectalloc^.sectionalloc(2); + objectalloc.sectionalloc(2); ait_const_8bit : - objectalloc^.sectionalloc(1); + objectalloc.sectionalloc(1); ait_real_80bit : - objectalloc^.sectionalloc(10); + objectalloc.sectionalloc(10); ait_real_64bit : - objectalloc^.sectionalloc(8); + objectalloc.sectionalloc(8); ait_real_32bit : - objectalloc^.sectionalloc(4); + objectalloc.sectionalloc(4); ait_comp_64bit : - objectalloc^.sectionalloc(8); + objectalloc.sectionalloc(8); ait_const_rva, ait_const_symbol : - objectalloc^.sectionalloc(4); + objectalloc.sectionalloc(4); ait_section: - objectalloc^.setsection(pai_section(hp)^.sec); + objectalloc.setsection(pai_section(hp)^.sec); ait_symbol : - pai_symbol(hp)^.sym^.setaddress(objectalloc^.currsec,objectalloc^.sectionsize,0); + pai_symbol(hp)^.sym^.setaddress(objectalloc.currsec,objectalloc.sectionsize,0); ait_label : - pai_label(hp)^.l^.setaddress(objectalloc^.currsec,objectalloc^.sectionsize,0); + pai_label(hp)^.l^.setaddress(objectalloc.currsec,objectalloc.sectionsize,0); ait_string : - objectalloc^.sectionalloc(pai_string(hp)^.len); + objectalloc.sectionalloc(pai_string(hp)^.len); ait_instruction : begin { reset instructions which could change in pass 2 } paicpu(hp)^.resetpass2; - objectalloc^.sectionalloc(paicpu(hp)^.Pass1(objectalloc^.sectionsize)); + objectalloc.sectionalloc(paicpu(hp)^.Pass1(objectalloc.sectionsize)); end; ait_cut : if SmartAsm then @@ -454,7 +462,7 @@ interface if ((cs_debuginfo in aktmoduleswitches) or (cs_gdb_lineinfo in aktglobalswitches)) then begin - if (objectalloc^.currsec<>sec_none) and + if (objectalloc.currsec<>sec_none) and not(hp^.typ in [ ait_label, ait_regalloc,ait_tempalloc, @@ -467,13 +475,13 @@ interface ait_align : begin { here we must determine the fillsize which is used in pass2 } - pai_align(hp)^.fillsize:=align(objectalloc^.sectionsize,pai_align(hp)^.aligntype)- - objectalloc^.sectionsize; - objectalloc^.sectionalloc(pai_align(hp)^.fillsize); + pai_align(hp)^.fillsize:=align(objectalloc.sectionsize,pai_align(hp)^.aligntype)- + objectalloc.sectionsize; + objectalloc.sectionalloc(pai_align(hp)^.fillsize); end; ait_datablock : begin - if objectalloc^.currsec<>sec_bss then + if objectalloc.currsec<>sec_bss then Message(asmw_e_alloc_data_only_in_bss); if not SmartAsm then begin @@ -488,49 +496,49 @@ interface begin l:=pai_datablock(hp)^.size; if l>2 then - objectalloc^.sectionalign(4) + objectalloc.sectionalign(4) else if l>1 then - objectalloc^.sectionalign(2); - pai_datablock(hp)^.sym^.setaddress(objectalloc^.currsec,objectalloc^.sectionsize, + objectalloc.sectionalign(2); + pai_datablock(hp)^.sym^.setaddress(objectalloc.currsec,objectalloc.sectionsize, pai_datablock(hp)^.size); - objectalloc^.sectionalloc(pai_datablock(hp)^.size); + objectalloc.sectionalloc(pai_datablock(hp)^.size); end; end else begin l:=pai_datablock(hp)^.size; if l>2 then - objectalloc^.sectionalign(4) + objectalloc.sectionalign(4) else if l>1 then - objectalloc^.sectionalign(2); - pai_datablock(hp)^.sym^.setaddress(objectalloc^.currsec,objectalloc^.sectionsize,pai_datablock(hp)^.size); - objectalloc^.sectionalloc(pai_datablock(hp)^.size); + objectalloc.sectionalign(2); + pai_datablock(hp)^.sym^.setaddress(objectalloc.currsec,objectalloc.sectionsize,pai_datablock(hp)^.size); + objectalloc.sectionalloc(pai_datablock(hp)^.size); end; UsedAsmSymbolListInsert(pai_datablock(hp)^.sym); end; ait_const_32bit : - objectalloc^.sectionalloc(4); + objectalloc.sectionalloc(4); ait_const_16bit : - objectalloc^.sectionalloc(2); + objectalloc.sectionalloc(2); ait_const_8bit : - objectalloc^.sectionalloc(1); + objectalloc.sectionalloc(1); ait_real_80bit : - objectalloc^.sectionalloc(10); + objectalloc.sectionalloc(10); ait_real_64bit : - objectalloc^.sectionalloc(8); + objectalloc.sectionalloc(8); ait_real_32bit : - objectalloc^.sectionalloc(4); + objectalloc.sectionalloc(4); ait_comp_64bit : - objectalloc^.sectionalloc(8); + objectalloc.sectionalloc(8); ait_const_rva, ait_const_symbol : begin - objectalloc^.sectionalloc(4); + objectalloc.sectionalloc(4); UsedAsmSymbolListInsert(pai_const_symbol(hp)^.sym); end; ait_section: begin - objectalloc^.setsection(pai_section(hp)^.sec); + objectalloc.setsection(pai_section(hp)^.sec); {$ifdef GDB} case pai_section(hp)^.sec of sec_code : n_line:=n_textline; @@ -562,27 +570,27 @@ interface {$endif} ait_symbol : begin - pai_symbol(hp)^.sym^.setaddress(objectalloc^.currsec,objectalloc^.sectionsize,0); + pai_symbol(hp)^.sym^.setaddress(objectalloc.currsec,objectalloc.sectionsize,0); UsedAsmSymbolListInsert(pai_symbol(hp)^.sym); end; ait_symbol_end : begin if target_info.target=target_i386_linux then begin - pai_symbol(hp)^.sym^.size:=objectalloc^.sectionsize-pai_symbol(hp)^.sym^.address; + pai_symbol(hp)^.sym^.size:=objectalloc.sectionsize-pai_symbol(hp)^.sym^.address; UsedAsmSymbolListInsert(pai_symbol(hp)^.sym); end; end; ait_label : begin - pai_label(hp)^.l^.setaddress(objectalloc^.currsec,objectalloc^.sectionsize,0); + pai_label(hp)^.l^.setaddress(objectalloc.currsec,objectalloc.sectionsize,0); UsedAsmSymbolListInsert(pai_label(hp)^.l); end; ait_string : - objectalloc^.sectionalloc(pai_string(hp)^.len); + objectalloc.sectionalloc(pai_string(hp)^.len); ait_instruction : begin - objectalloc^.sectionalloc(paicpu(hp)^.Pass1(objectalloc^.sectionsize)); + objectalloc.sectionalloc(paicpu(hp)^.Pass1(objectalloc.sectionsize)); { fixup the references } for i:=1 to paicpu(hp)^.ops do begin @@ -629,7 +637,7 @@ interface if ((cs_debuginfo in aktmoduleswitches) or (cs_gdb_lineinfo in aktglobalswitches)) then begin - if (objectoutput^.currsec<>sec_none) and + if (objectdata.currsec<>sec_none) and not(hp^.typ in [ ait_label, ait_regalloc,ait_tempalloc, @@ -640,10 +648,10 @@ interface {$endif GDB} case hp^.typ of ait_align : - objectoutput^.writebytes(pai_align(hp)^.getfillbuf^,pai_align(hp)^.fillsize); + objectdata.writebytes(pai_align(hp)^.getfillbuf^,pai_align(hp)^.fillsize); ait_section : begin - objectoutput^.defaultsection(pai_section(hp)^.sec); + objectdata.defaultsection(pai_section(hp)^.sec); {$ifdef GDB} case pai_section(hp)^.sec of sec_code : n_line:=n_textline; @@ -656,32 +664,36 @@ interface {$endif GDB} end; ait_symbol : - objectoutput^.writesymbol(pai_symbol(hp)^.sym); + begin + objectdata.writesymbol(pai_symbol(hp)^.sym); + objectoutput.exportsymbol(pai_symbol(hp)^.sym); + end; ait_datablock : begin - objectoutput^.writesymbol(pai_datablock(hp)^.sym); + objectdata.writesymbol(pai_datablock(hp)^.sym); + objectoutput.exportsymbol(pai_datablock(hp)^.sym); if SmartAsm or (not pai_datablock(hp)^.is_global) then begin l:=pai_datablock(hp)^.size; if l>2 then - objectoutput^.allocalign(4) + objectdata.allocalign(4) else if l>1 then - objectoutput^.allocalign(2); - objectoutput^.alloc(pai_datablock(hp)^.size); + objectdata.allocalign(2); + objectdata.alloc(pai_datablock(hp)^.size); end; end; ait_const_32bit : - objectoutput^.writebytes(pai_const(hp)^.value,4); + objectdata.writebytes(pai_const(hp)^.value,4); ait_const_16bit : - objectoutput^.writebytes(pai_const(hp)^.value,2); + objectdata.writebytes(pai_const(hp)^.value,2); ait_const_8bit : - objectoutput^.writebytes(pai_const(hp)^.value,1); + objectdata.writebytes(pai_const(hp)^.value,1); ait_real_80bit : - objectoutput^.writebytes(pai_real_80bit(hp)^.value,10); + objectdata.writebytes(pai_real_80bit(hp)^.value,10); ait_real_64bit : - objectoutput^.writebytes(pai_real_64bit(hp)^.value,8); + objectdata.writebytes(pai_real_64bit(hp)^.value,8); ait_real_32bit : - objectoutput^.writebytes(pai_real_32bit(hp)^.value,4); + objectdata.writebytes(pai_real_32bit(hp)^.value,4); ait_comp_64bit : begin {$ifdef FPC} @@ -689,18 +701,23 @@ interface {$else} co:=pai_comp_64bit(hp)^.value; {$endif} - objectoutput^.writebytes(co,8); + objectdata.writebytes(co,8); end; ait_string : - objectoutput^.writebytes(pai_string(hp)^.str^,pai_string(hp)^.len); + objectdata.writebytes(pai_string(hp)^.str^,pai_string(hp)^.len); ait_const_rva : - objectoutput^.writereloc(pai_const_symbol(hp)^.offset,4, + objectdata.writereloc(pai_const_symbol(hp)^.offset,4, pai_const_symbol(hp)^.sym,relative_rva); ait_const_symbol : - objectoutput^.writereloc(pai_const_symbol(hp)^.offset,4, + objectdata.writereloc(pai_const_symbol(hp)^.offset,4, pai_const_symbol(hp)^.sym,relative_false); ait_label : - objectoutput^.writesymbol(pai_label(hp)^.l); + begin + objectdata.writesymbol(pai_label(hp)^.l); + { exporting shouldn't be necessary as labels are local, + but it's better to be on the safe side (PFV) } + objectoutput.exportsymbol(pai_label(hp)^.l); + end; ait_instruction : paicpu(hp)^.Pass2; {$ifdef GDB} @@ -732,18 +749,18 @@ interface label doexit; begin - objectalloc^.resetsections; - objectalloc^.setsection(sec_code); + objectalloc.resetsections; + objectalloc.setsection(sec_code); - objectoutput^.initwriting(cut_normal); - objectoutput^.defaultsection(sec_code); + objectdata:=objectoutput.initwriting(cut_normal); + objectdata.defaultsection(sec_code); { reset the asmsymbol list } InitUsedAsmsymbolList; {$ifdef MULTIPASS} { Pass 0 } currpass:=0; - objectalloc^.setsection(sec_code); + objectalloc.setsection(sec_code); { start with list 1 } currlistidx:=1; currlist:=list[currlistidx]; @@ -760,8 +777,8 @@ interface { Pass 1 } currpass:=1; - objectalloc^.resetsections; - objectalloc^.setsection(sec_code); + objectalloc.resetsections; + objectalloc.setsection(sec_code); {$ifdef GDB} StartFileLineInfo; {$endif GDB} @@ -781,7 +798,7 @@ interface UsedAsmSymbolListCheckUndefined; { set section sizes } - objectoutput^.setsectionsizes(objectalloc^.secsize); + objectdata.setsectionsizes(objectalloc.secsize); { leave if errors have occured } if errorcount>0 then goto doexit; @@ -809,7 +826,8 @@ interface goto doexit; { write last objectfile } - objectoutput^.donewriting; + objectoutput.donewriting; + objectdata:=nil; doexit: { reset the used symbols back, must be after the .o has been @@ -825,11 +843,11 @@ interface startsec : tsection; place: tcutplace; begin - objectalloc^.resetsections; - objectalloc^.setsection(sec_code); + objectalloc.resetsections; + objectalloc.setsection(sec_code); - objectoutput^.initwriting(cut_normal); - objectoutput^.defaultsection(sec_code); + objectdata:=objectoutput.initwriting(cut_normal); + objectdata.defaultsection(sec_code); startsec:=sec_code; { start with list 1 } @@ -844,8 +862,8 @@ interface {$ifdef MULTIPASS} { Pass 0 } currpass:=0; - objectalloc^.resetsections; - objectalloc^.setsection(startsec); + objectalloc.resetsections; + objectalloc.setsection(startsec); TreePass0(hp); { leave if errors have occured } if errorcount>0 then @@ -854,8 +872,8 @@ interface { Pass 1 } currpass:=1; - objectalloc^.resetsections; - objectalloc^.setsection(startsec); + objectalloc.resetsections; + objectalloc.setsection(startsec); {$ifdef GDB} StartFileLineInfo; {$endif GDB} @@ -867,14 +885,14 @@ interface UsedAsmSymbolListCheckUndefined; { set section sizes } - objectoutput^.setsectionsizes(objectalloc^.secsize); + objectdata.setsectionsizes(objectalloc.secsize); { leave if errors have occured } if errorcount>0 then exit; { Pass 2 } currpass:=2; - objectoutput^.defaultsection(startsec); + objectdata.defaultsection(startsec); {$ifdef GDB} StartFileLineInfo; {$endif GDB} @@ -887,7 +905,8 @@ interface exit; { if not end then write the current objectfile } - objectoutput^.donewriting; + objectoutput.donewriting; + objectdata:=nil; { reset the used symbols back, must be after the .o has been written } @@ -899,7 +918,7 @@ interface break; { save section for next loop } { this leads to a problem if startsec is sec_none !! PM } - startsec:=objectalloc^.currsec; + startsec:=objectalloc.currsec; { we will start a new objectfile so reset everything } { The place can still change in the next while loop, so don't init } @@ -920,7 +939,7 @@ interface hp:=pai(hp^.next); end; - objectoutput^.initwriting(place); + objectdata:=objectoutput.initwriting(place); hp:=pai(hp^.next); @@ -973,15 +992,15 @@ interface og_none : Message(asmw_f_no_binary_writer_selected); og_coff : - objectoutput:=new(pcoffoutput,initdjgpp(smart)); + objectoutput:=tcoffoutput.createdjgpp(smart); og_pecoff : - objectoutput:=new(pcoffoutput,initwin32(smart)); + objectoutput:=tcoffoutput.createwin32(smart); og_elf : - objectoutput:=new(pelf32output,init(smart)); + objectoutput:=telf32output.create(smart); else internalerror(43243432); end; - objectalloc:=new(pobjectalloc,init); + objectalloc:=tobjectalloc.create; SmartAsm:=smart; currpass:=0; end; @@ -996,8 +1015,8 @@ interface {$ifdef MEMDEBUG} d.init('agbin'); {$endif} - dispose(objectoutput,done); - dispose(objectalloc,done); + objectoutput.free; + objectalloc.free; {$ifdef MEMDEBUG} d.done; {$endif} @@ -1006,7 +1025,11 @@ interface end. { $Log$ - Revision 1.2 2000-12-12 19:50:21 peter + Revision 1.3 2000-12-23 19:59:35 peter + * object to class for ow/og objects + * split objectdata from objectoutput + + Revision 1.2 2000/12/12 19:50:21 peter * clear usedasmsymbol at exit of writetree Revision 1.1 2000/11/30 22:18:48 florian diff --git a/compiler/i386/cpuasm.pas b/compiler/i386/cpuasm.pas index fd39b482cd..b059e44615 100644 --- a/compiler/i386/cpuasm.pas +++ b/compiler/i386/cpuasm.pas @@ -1015,7 +1015,7 @@ begin R_GS : c:=$65; R_SS : c:=$36; end; - objectoutput^.writebytes(c,1); + objectdata.writebytes(c,1); { fix the offset for GenNode } inc(InsOffset); end; @@ -1405,7 +1405,7 @@ begin ((codes[0]=#1) and ((codes[2]=#5) or (codes[2]=#7)))) then begin bytes[0]:=$66; - objectoutput^.writebytes(bytes,1); + objectdata.writebytes(bytes,1); end; repeat c:=ord(codes^); @@ -1415,7 +1415,7 @@ begin break; 1,2,3 : begin - objectoutput^.writebytes(codes^,c); + objectdata.writebytes(codes^,c); inc(codes,c); end; 4,6 : @@ -1453,7 +1453,7 @@ begin else InternalError(777004); end; - objectoutput^.writebytes(bytes,1); + objectdata.writebytes(bytes,1); end; 5,7 : begin @@ -1475,18 +1475,18 @@ begin else InternalError(777005); end; - objectoutput^.writebytes(bytes,1); + objectdata.writebytes(bytes,1); end; 8,9,10 : begin bytes[0]:=ord(codes^)+regval(oper[c-8].reg); inc(codes); - objectoutput^.writebytes(bytes,1); + objectdata.writebytes(bytes,1); end; 15 : begin bytes[0]:=0; - objectoutput^.writebytes(bytes,1); + objectdata.writebytes(bytes,1); end; 12,13,14 : begin @@ -1494,9 +1494,9 @@ begin if (currval<-128) or (currval>127) then Message2(asmw_e_value_exceeds_bounds,'signed byte',tostr(currval)); if assigned(currsym) then - objectoutput^.writereloc(currval,1,currsym,relative_false) + objectdata.writereloc(currval,1,currsym,relative_false) else - objectoutput^.writebytes(currval,1); + objectdata.writebytes(currval,1); end; 16,17,18 : begin @@ -1504,9 +1504,9 @@ begin if (currval<-256) or (currval>255) then Message2(asmw_e_value_exceeds_bounds,'byte',tostr(currval)); if assigned(currsym) then - objectoutput^.writereloc(currval,1,currsym,relative_false) + objectdata.writereloc(currval,1,currsym,relative_false) else - objectoutput^.writebytes(currval,1); + objectdata.writebytes(currval,1); end; 20,21,22 : begin @@ -1514,9 +1514,9 @@ begin if (currval<0) or (currval>255) then Message2(asmw_e_value_exceeds_bounds,'unsigned byte',tostr(currval)); if assigned(currsym) then - objectoutput^.writereloc(currval,1,currsym,relative_false) + objectdata.writereloc(currval,1,currsym,relative_false) else - objectoutput^.writebytes(currval,1); + objectdata.writebytes(currval,1); end; 24,25,26 : begin @@ -1524,25 +1524,25 @@ begin if (currval<-65536) or (currval>65535) then Message2(asmw_e_value_exceeds_bounds,'word',tostr(currval)); if assigned(currsym) then - objectoutput^.writereloc(currval,2,currsym,relative_false) + objectdata.writereloc(currval,2,currsym,relative_false) else - objectoutput^.writebytes(currval,2); + objectdata.writebytes(currval,2); end; 28,29,30 : begin getvalsym(c-28); if assigned(currsym) then - objectoutput^.writereloc(currval,4,currsym,relative_false) + objectdata.writereloc(currval,4,currsym,relative_false) else - objectoutput^.writebytes(currval,4); + objectdata.writebytes(currval,4); end; 32,33,34 : begin getvalsym(c-32); if assigned(currsym) then - objectoutput^.writereloc(currval,4,currsym,relative_false) + objectdata.writereloc(currval,4,currsym,relative_false) else - objectoutput^.writebytes(currval,4); + objectdata.writebytes(currval,4); end; 40,41,42 : begin @@ -1552,47 +1552,47 @@ begin inc(data,currsym^.address); if (data>127) or (data<-128) then Message1(asmw_e_short_jmp_out_of_range,tostr(data)); - objectoutput^.writebytes(data,1); + objectdata.writebytes(data,1); end; 52,53,54 : begin getvalsym(c-52); if assigned(currsym) then - objectoutput^.writereloc(currval,4,currsym,relative_true) + objectdata.writereloc(currval,4,currsym,relative_true) else - objectoutput^.writereloc(currval-insend,4,nil,relative_false) + objectdata.writereloc(currval-insend,4,nil,relative_false) end; 56,57,58 : begin getvalsym(c-56); if assigned(currsym) then - objectoutput^.writereloc(currval,4,currsym,relative_true) + objectdata.writereloc(currval,4,currsym,relative_true) else - objectoutput^.writereloc(currval-insend,4,nil,relative_false) + objectdata.writereloc(currval-insend,4,nil,relative_false) end; 192,193,194 : begin if NeedAddrPrefix(c-192) then begin bytes[0]:=$67; - objectoutput^.writebytes(bytes,1); + objectdata.writebytes(bytes,1); end; end; 200 : begin bytes[0]:=$67; - objectoutput^.writebytes(bytes,1); + objectdata.writebytes(bytes,1); end; 208 : begin bytes[0]:=$66; - objectoutput^.writebytes(bytes,1); + objectdata.writebytes(bytes,1); end; 216 : begin bytes[0]:=ord(codes^)+condval[condition]; inc(codes); - objectoutput^.writebytes(bytes,1); + objectdata.writebytes(bytes,1); end; 201, 202, @@ -1636,24 +1636,24 @@ begin end; s:=pb-pchar(@bytes); - objectoutput^.writebytes(bytes,s); + objectdata.writebytes(bytes,s); case ea_data.bytes of 0 : ; 1 : begin if (oper[opidx].ot and OT_MEMORY)=OT_MEMORY then - objectoutput^.writereloc(oper[opidx].ref^.offset,1,oper[opidx].ref^.symbol,relative_false) + objectdata.writereloc(oper[opidx].ref^.offset,1,oper[opidx].ref^.symbol,relative_false) else begin bytes[0]:=oper[opidx].ref^.offset; - objectoutput^.writebytes(bytes,1); + objectdata.writebytes(bytes,1); end; inc(s); end; 2,4 : begin - objectoutput^.writereloc(oper[opidx].ref^.offset,ea_data.bytes, + objectdata.writereloc(oper[opidx].ref^.offset,ea_data.bytes, oper[opidx].ref^.symbol,relative_false); inc(s,ea_data.bytes); end; @@ -1670,7 +1670,11 @@ end; end. { $Log$ - Revision 1.4 2000-12-07 17:19:45 jonas + Revision 1.5 2000-12-23 19:59:35 peter + * object to class for ow/og objects + * split objectdata from objectoutput + + Revision 1.4 2000/12/07 17:19:45 jonas * new constant handling: from now on, hex constants >$7fffffff are parsed as unsigned constants (otherwise, $80000000 got sign extended and became $ffffffff80000000), all constants in the longint range diff --git a/compiler/ogbase.pas b/compiler/ogbase.pas index d005d53539..01252fbf20 100644 --- a/compiler/ogbase.pas +++ b/compiler/ogbase.pas @@ -59,7 +59,7 @@ interface poutputsymbol = ^toutputsymbol; toutputsymbol = packed record - namestr : string[8]; { namestr or nameidx is used } + namestr : string[8]; { namestr or nameidx will be used } nameidx : longint; section : tsection; value : longint; @@ -68,14 +68,13 @@ interface size : longint; end; - poutputsection = ^toutputsection; - toutputsection = object + tobjectsection = class name : string[32]; secsymidx : longint; { index for the section in symtab } addralign : longint; { size of the data and in the file } data : PDynamicArray; - datasize : longint; + datasize : longint; datapos : longint; { size and position in memory, set by setsectionsize } memsize, @@ -84,8 +83,8 @@ interface nrelocs : longint; relochead : POutputReloc; reloctail : ^POutputReloc; - constructor init(const Aname:string;Aalign:longint;alloconly:boolean); - destructor done; + constructor create(const Aname:string;Aalign:longint;alloconly:boolean); + destructor destroy;override; function write(var d;l:longint):longint; function writestr(const s:string):longint; procedure writealign(l:longint); @@ -96,12 +95,30 @@ interface procedure addsectionreloc(ofs:longint;sec:tsection;relative:relative_type); end; - pobjectalloc = ^tobjectalloc; - tobjectalloc = object + tobjectdata = class + { section } + currsec : tsection; + sects : array[TSection] of tobjectsection; + constructor create; + destructor destroy;override; + procedure createsection(sec:tsection);virtual; + procedure defaultsection(sec:tsection); + function sectionsize(s:tsection):longint; + procedure setsectionsizes(var s:tsecsize);virtual; + procedure alloc(len:longint); + procedure allocalign(len:longint); + procedure writebytes(var data;len:longint); + procedure writereloc(data,len:longint;p:pasmsymbol;relative:relative_type);virtual;abstract; + procedure writesymbol(p:pasmsymbol);virtual;abstract; + procedure writestabs(section:tsection;offset:longint;p:pchar;nidx,nother,line:longint;reloc:boolean);virtual;abstract; + procedure writesymstabs(section:tsection;offset:longint;p:pchar;ps:pasmsymbol;nidx,nother,line:longint;reloc:boolean);virtual;abstract; + end; + + tobjectalloc = class currsec : tsection; secsize : tsecsize; - constructor init; - destructor done; + constructor create; + destructor destroy;override; procedure setsection(sec:tsection); function sectionsize:longint; procedure sectionalloc(l:longint); @@ -110,9 +127,8 @@ interface procedure resetsections; end; - pobjectoutput = ^tobjectoutput; - tobjectoutput = object - writer : pobjectwriter; + tobjectoutput = class + protected path : pathstr; ObjFile : string; { smartlinking } @@ -120,34 +136,32 @@ interface place : tcutplace; SmartFilesCount, SmartHeaderCount : longint; + { writer } + writer : tobjectwriter; { section } - currsec : tsection; - sects : array[TSection] of POutputSection; - constructor init(smart:boolean); - destructor done;virtual; + data : tobjectdata; { Writing } procedure NextSmartName; - procedure initwriting(Aplace:tcutplace);virtual; + protected + procedure writetodisk;virtual; + public + constructor create(smart:boolean); + destructor destroy;override; + function initwriting(Aplace:tcutplace):tobjectdata;virtual; procedure donewriting;virtual; - procedure createsection(sec:tsection);virtual; - procedure defaultsection(sec:tsection); - function sectionsize(s:tsection):longint; - procedure setsectionsizes(var s:tsecsize);virtual; - procedure alloc(len:longint); - procedure allocalign(len:longint); - procedure writebytes(var data;len:longint); - procedure writereloc(data,len:longint;p:pasmsymbol;relative:relative_type);virtual; - procedure writesymbol(p:pasmsymbol);virtual; - procedure writestabs(section:tsection;offset:longint;p:pchar;nidx,nother,line:longint;reloc:boolean);virtual; - procedure writesymstabs(section:tsection;offset:longint;p:pchar;ps:pasmsymbol; - nidx,nother,line:longint;reloc:boolean);virtual; + procedure exportsymbol(p:pasmsymbol); end; var - objectalloc : pobjectalloc; - objectoutput : pobjectoutput; + { current object data, used in ag386bin/cpuasm } + objectdata : tobjectdata; + { current object allocator } + objectalloc : tobjectalloc; + { current object writer used } + objectoutput : tobjectoutput; - implementation + +implementation uses comphook, @@ -158,12 +172,12 @@ interface tobjectalloc ****************************************************************************} - constructor tobjectalloc.init; + constructor tobjectalloc.create; begin end; - destructor tobjectalloc.done; + destructor tobjectalloc.destroy; begin end; @@ -211,7 +225,7 @@ interface TSectionOutput ****************************************************************************} - constructor toutputsection.init(const Aname:string;Aalign:longint;alloconly:boolean); + constructor tobjectsection.create(const Aname:string;Aalign:longint;alloconly:boolean); begin name:=Aname; secsymidx:=0; @@ -233,14 +247,14 @@ interface end; - destructor toutputsection.done; + destructor tobjectsection.destroy; begin if assigned(Data) then dispose(Data,done); end; - function toutputsection.write(var d;l:longint):longint; + function tobjectsection.write(var d;l:longint):longint; begin write:=datasize; if not assigned(Data) then @@ -250,7 +264,7 @@ interface end; - function toutputsection.writestr(const s:string):longint; + function tobjectsection.writestr(const s:string):longint; begin writestr:=datasize; if not assigned(Data) then @@ -260,7 +274,7 @@ interface end; - procedure toutputsection.writealign(l:longint); + procedure tobjectsection.writealign(l:longint); var i : longint; empty : array[0..63] of char; @@ -281,19 +295,19 @@ interface end; - function toutputsection.aligneddatasize:longint; + function tobjectsection.aligneddatasize:longint; begin aligneddatasize:=align(datasize,addralign); end; - procedure toutputsection.alignsection; + procedure tobjectsection.alignsection; begin writealign(addralign); end; - procedure toutputsection.alloc(l:longint); + procedure tobjectsection.alloc(l:longint); begin if assigned(Data) then Internalerror(3334442); @@ -301,7 +315,7 @@ interface end; - procedure toutputsection.addsymreloc(ofs:longint;p:pasmsymbol;relative:relative_type); + procedure tobjectsection.addsymreloc(ofs:longint;p:pasmsymbol;relative:relative_type); var r : POutputReloc; begin @@ -317,7 +331,7 @@ interface end; - procedure toutputsection.addsectionreloc(ofs:longint;sec:tsection;relative:relative_type); + procedure tobjectsection.addsectionreloc(ofs:longint;sec:tsection;relative:relative_type); var r : POutputReloc; begin @@ -333,11 +347,87 @@ interface end; +{**************************************************************************** + tobjectdata +****************************************************************************} + + constructor tobjectdata.create; + begin + { reset } + FillChar(Sects,sizeof(Sects),0); + end; + + + destructor tobjectdata.destroy; + var + sec : tsection; + begin + { free memory } + for sec:=low(tsection) to high(tsection) do + if assigned(sects[sec]) then + sects[sec].free; + end; + + + procedure tobjectdata.createsection(sec:tsection); + begin + sects[sec]:=tobjectsection.create(target_asm.secnames[sec],1,(sec=sec_bss)); + end; + + + function tobjectdata.sectionsize(s:tsection):longint; + begin + if assigned(sects[s]) then + sectionsize:=sects[s].datasize + else + sectionsize:=0; + end; + + + procedure tobjectdata.setsectionsizes(var s:tsecsize); + begin + end; + + + procedure tobjectdata.defaultsection(sec:tsection); + begin + currsec:=sec; + end; + + + procedure tobjectdata.writebytes(var data;len:longint); + begin + if not assigned(sects[currsec]) then + createsection(currsec); + sects[currsec].write(data,len); + end; + + + procedure tobjectdata.alloc(len:longint); + begin + if not assigned(sects[currsec]) then + createsection(currsec); + sects[currsec].alloc(len); + end; + + + procedure tobjectdata.allocalign(len:longint); + var + modulo : longint; + begin + if not assigned(sects[currsec]) then + createsection(currsec); + modulo:=sects[currsec].datasize mod len; + if modulo > 0 then + sects[currsec].alloc(len-modulo); + end; + + {**************************************************************************** tobjectoutput ****************************************************************************} - constructor tobjectoutput.init(smart:boolean); + constructor tobjectoutput.create(smart:boolean); begin SmartFilesCount:=0; SmartHeaderCount:=0; @@ -358,15 +448,16 @@ interface path:=current_module^.path^; { init writer } if objsmart and - not(cs_asm_leave in aktglobalswitches) then writer:=New(parobjectwriter,Init(current_module^.staticlibfilename^)) + not(cs_asm_leave in aktglobalswitches) then + writer:=tarobjectwriter.create(current_module^.staticlibfilename^) else - writer:=New(pobjectwriter,Init); + writer:=tobjectwriter.create; end; - destructor tobjectoutput.done; + destructor tobjectoutput.destroy; begin - Dispose(writer,done); + writer.free; end; @@ -396,117 +487,57 @@ interface end; - procedure tobjectoutput.initwriting(Aplace:tcutplace); + procedure tobjectoutput.writetodisk; + begin + end; + + + function tobjectoutput.initwriting(Aplace:tcutplace):tobjectdata; begin place:=Aplace; + { the data should be set by the real output like coffoutput } + data:=nil; + initwriting:=nil; { open the writer } if objsmart then NextSmartName; - writer^.create(objfile); - { reset } - FillChar(Sects,sizeof(Sects),0); + writer.createfile(objfile); end; procedure tobjectoutput.donewriting; - var - sec : tsection; begin - { free memory } - for sec:=low(tsection) to high(tsection) do - if assigned(sects[sec]) then - dispose(sects[sec],done); + { Only write the .o if there are no errors } + if errorcount=0 then + writetodisk; { close the writer } - writer^.close; + writer.closefile; + { free data } + data.free; + data:=nil; end; - procedure tobjectoutput.createsection(sec:tsection); + procedure tobjectoutput.exportsymbol(p:pasmsymbol); begin - sects[sec]:=new(poutputsection,init(target_asm.secnames[sec],1,(sec=sec_bss))); - end; - - - function tobjectoutput.sectionsize(s:tsection):longint; - begin - if assigned(sects[s]) then - sectionsize:=sects[s]^.datasize - else - sectionsize:=0; - end; - - - procedure tobjectoutput.setsectionsizes(var s:tsecsize); - begin - end; - - - procedure tobjectoutput.defaultsection(sec:tsection); - begin - currsec:=sec; - end; - - - procedure tobjectoutput.writebytes(var data;len:longint); - begin - if not assigned(sects[currsec]) then - createsection(currsec); - sects[currsec]^.write(data,len); - end; - - - procedure tobjectoutput.alloc(len:longint); - begin - if not assigned(sects[currsec]) then - createsection(currsec); - sects[currsec]^.alloc(len); - end; - - - procedure tobjectoutput.allocalign(len:longint); - var - modulo : longint; - begin - if not assigned(sects[currsec]) then - createsection(currsec); - modulo:=sects[currsec]^.datasize mod len; - if modulo > 0 then - sects[currsec]^.alloc(len-modulo); - end; - - - procedure tobjectoutput.writesymbol(p:pasmsymbol); - begin - Do_halt(211); - end; - - - procedure tobjectoutput.writereloc(data,len:longint;p:pasmsymbol;relative:relative_type); - begin - Do_halt(211); - end; - - - procedure tobjectoutput.writestabs(section:tsection;offset:longint;p:pchar;nidx,nother,line:longint;reloc:boolean); - begin - Do_halt(211); - end; - - - procedure tobjectoutput.writesymstabs(section:tsection;offset:longint;p:pchar;ps:pasmsymbol; - nidx,nother,line:longint;reloc:boolean); - begin - Do_halt(211); + { export globals and common symbols, this is needed + for .a files } + if p^.bind in [AB_GLOBAL,AB_COMMON] then + writer.writesym(p^.name); end; end. { $Log$ - Revision 1.2 2000-11-13 21:56:07 peter + Revision 1.3 2000-12-23 19:59:35 peter + * object to class for ow/og objects + * split objectdata from objectoutput + + Revision 1.2 2000/11/13 21:56:07 peter * removed some virtual from methods * sectionsize method implemented (fixes lineinfo stabs) Revision 1.1 2000/11/12 22:20:37 peter - * create generic toutputsection for binary writers + * create generic tobjectsection for binary writers } diff --git a/compiler/ogcoff.pas b/compiler/ogcoff.pas index d285205497..2ef93490b7 100644 --- a/compiler/ogcoff.pas +++ b/compiler/ogcoff.pas @@ -41,36 +41,44 @@ interface ogbase; type - pcoffsection = ^tcoffsection; - tcoffsection = object(toutputsection) + tcoffsection = class(tobjectsection) + public flags : cardinal; relocpos : longint; - constructor initsec(sec:TSection;AAlign,AFlags:cardinal); + constructor createsec(sec:TSection;AAlign,AFlags:cardinal); end; - pcoffoutput = ^tcoffoutput; - tcoffoutput = object(tobjectoutput) + tcoffdata = class(tobjectdata) + private win32 : boolean; + procedure reset; + public + constructor createdjgpp; + constructor createwin32; + destructor destroy;override; + procedure setsectionsizes(var s:tsecsize);override; + procedure createsection(sec:tsection);override; + procedure writereloc(data,len:longint;p:pasmsymbol;relative:relative_type);override; + procedure writesymbol(p:pasmsymbol);override; + procedure writestabs(section:tsection;offset:longint;p:pchar;nidx,nother,line:longint;reloc:boolean);override; + procedure writesymstabs(section:tsection;offset:longint;p:pchar;ps:pasmsymbol;nidx,nother,line:longint;reloc:boolean);override; strs, syms : Pdynamicarray; - initsym : longint; - constructor initdjgpp(smart:boolean); - constructor initwin32(smart:boolean); - destructor done;virtual; - procedure initwriting(Aplace:tcutplace);virtual; - procedure donewriting;virtual; - procedure setsectionsizes(var s:tsecsize);virtual; - procedure createsection(sec:tsection);virtual; - procedure writereloc(data,len:longint;p:pasmsymbol;relative:relative_type);virtual; - procedure writesymbol(p:pasmsymbol);virtual; - procedure writestabs(section:tsection;offset:longint;p:pchar;nidx,nother,line:longint;reloc:boolean);virtual; - procedure writesymstabs(section:tsection;offset:longint;p:pchar;ps:pasmsymbol; - nidx,nother,line:longint;reloc:boolean);virtual; + end; + + tcoffoutput = class(tobjectoutput) private - procedure write_relocs(s:poutputsection); + win32 : boolean; + initsym : longint; + procedure write_relocs(s:tobjectsection); procedure write_symbol(const name:string;strpos,value,section,typ,aux:longint); procedure write_symbols; - procedure writetodisk; + protected + procedure writetodisk;override; + public + constructor createdjgpp(smart:boolean); + constructor createwin32(smart:boolean); + function initwriting(Aplace:tcutplace):tobjectdata;override; end; @@ -146,44 +154,43 @@ implementation TCoffSection ****************************************************************************} - constructor tcoffsection.initsec(sec:TSection;AAlign,AFlags:cardinal); + constructor tcoffsection.createsec(sec:TSection;AAlign,AFlags:cardinal); begin - inherited init(target_asm.secnames[sec],AAlign,(sec=sec_bss)); + inherited create(target_asm.secnames[sec],AAlign,(sec=sec_bss)); Flags:=AFlags; end; {**************************************************************************** - TCoffOutput + TCoffData ****************************************************************************} - constructor tcoffoutput.initdjgpp(smart:boolean); + constructor tcoffdata.createdjgpp; begin - inherited init(smart); + inherited create; win32:=false; + reset; end; - constructor tcoffoutput.initwin32(smart:boolean); + constructor tcoffdata.createwin32; begin - inherited init(smart); + inherited create; win32:=true; + reset; end; - destructor tcoffoutput.done; + destructor tcoffdata.destroy; begin - inherited done; + inherited destroy; end; - procedure tcoffoutput.initwriting(Aplace:tcutplace); + procedure tcoffdata.reset; var s : string; begin - inherited initwriting(Aplace); - { reset } - initsym:=0; new(syms,init(symbolresize)); new(strs,init(strsresize)); { we need at least the following 3 sections } @@ -198,23 +205,12 @@ implementation writestabs(sec_none,0,nil,0,0,0,false); { write zero pchar and name together (PM) } s:=#0+SplitFileName(current_module^.mainsource^)+#0; - sects[sec_stabstr]^.write(s[1],length(s)); + sects[sec_stabstr].write(s[1],length(s)); end; end; - procedure tcoffoutput.donewriting; - begin - { Only write the .o if there are no errors } - if errorcount=0 then - writetodisk; - dispose(syms,done); - dispose(strs,done); - inherited donewriting; - end; - - - procedure tcoffoutput.createsection(sec:TSection); + procedure tcoffdata.createsection(sec:TSection); var Flags, AAlign : cardinal; @@ -263,11 +259,11 @@ implementation Flags:=$c0300040; end; end; - sects[sec]:=new(PcoffSection,InitSec(Sec,AAlign,Flags)); + sects[sec]:=tcoffSection.createsec(Sec,AAlign,Flags); end; - procedure tcoffoutput.writesymbol(p:pasmsymbol); + procedure tcoffdata.writesymbol(p:pasmsymbol); var sym : toutputsymbol; s : string; @@ -287,7 +283,7 @@ implementation if sym.bind in [AB_LOCAL,AB_GLOBAL] then begin sym.section:=p^.section; - sym.value:=p^.address+sects[sym.section]^.mempos; + sym.value:=p^.address+sects[sym.section].mempos; end; { store the symbol, but not the local ones } if (sym.bind<>AB_LOCAL) then @@ -314,14 +310,10 @@ implementation begin p^.idx:=-2; { local } end; - { make the exported syms known to the objectwriter - (needed for .a generation) } - if (sym.bind in [AB_GLOBAL,AB_COMMON]) then - writer^.writesym(p^.name); end; - procedure tcoffoutput.writereloc(data,len:longint;p:pasmsymbol;relative:relative_type); + procedure tcoffdata.writereloc(data,len:longint;p:pasmsymbol;relative:relative_type); var curraddr, symaddr : longint; @@ -331,27 +323,27 @@ implementation if assigned(p) then begin { current address } - curraddr:=sects[currsec]^.mempos+sects[currsec]^.datasize; + curraddr:=sects[currsec].mempos+sects[currsec].datasize; { real address of the symbol } symaddr:=p^.address; if p^.section<>sec_none then - inc(symaddr,sects[p^.section]^.mempos); + inc(symaddr,sects[p^.section].mempos); { no symbol relocation need inside a section } if p^.section=currsec then begin case relative of relative_false : begin - sects[currsec]^.addsectionreloc(curraddr,currsec,relative_false); + sects[currsec].addsectionreloc(curraddr,currsec,relative_false); inc(data,symaddr); end; relative_true : begin - inc(data,symaddr-len-sects[currsec]^.datasize); + inc(data,symaddr-len-sects[currsec].datasize); end; relative_rva : begin - sects[currsec]^.addsectionreloc(curraddr,currsec,relative_rva); + sects[currsec].addsectionreloc(curraddr,currsec,relative_rva); inc(data,symaddr); end; end; @@ -360,9 +352,9 @@ implementation begin writesymbol(p); if (p^.section<>sec_none) and (relative<>relative_true) then - sects[currsec]^.addsectionreloc(curraddr,p^.section,relative) + sects[currsec].addsectionreloc(curraddr,p^.section,relative) else - sects[currsec]^.addsymreloc(curraddr,p,relative); + sects[currsec].addsymreloc(curraddr,p,relative); if not win32 then {seems wrong to me (PM) } inc(data,symaddr) else @@ -373,15 +365,15 @@ implementation if win32 then dec(data,len-4) else - dec(data,len+sects[currsec]^.datasize); + dec(data,len+sects[currsec].datasize); end; end; end; - sects[currsec]^.write(data,len); + sects[currsec].write(data,len); end; - procedure tcoffoutput.writestabs(section:tsection;offset:longint;p:pchar;nidx,nother,line:longint;reloc : boolean); + procedure tcoffdata.writestabs(section:tsection;offset:longint;p:pchar;nidx,nother,line:longint;reloc : boolean); var stab : coffstab; s : tsection; @@ -396,15 +388,15 @@ implementation if s=sec_none then offset:=0 else - offset:=sects[s]^.datasize; + offset:=sects[s].datasize; end; if (s<>sec_none) then - inc(offset,sects[s]^.datapos); + inc(offset,sects[s].datapos); end; if assigned(p) and (p[0]<>#0) then begin - stab.strpos:=sects[sec_stabstr]^.datasize; - sects[sec_stabstr]^.write(p^,strlen(p)+1); + stab.strpos:=sects[sec_stabstr].datasize; + sects[sec_stabstr].write(p^,strlen(p)+1); end else stab.strpos:=0; @@ -412,22 +404,24 @@ implementation stab.ndesc:=line; stab.nother:=nother; stab.nvalue:=offset; - sects[sec_stab]^.write(stab,sizeof(stab)); + sects[sec_stab].write(stab,sizeof(stab)); { when the offset is not 0 then write a relocation, take also the hdrstab into account with the offset } - { current address } - curraddr:=sects[sec_stab]^.mempos+sects[sec_stab]^.datasize; if reloc then - if DLLSource and RelocSection then - { avoid relocation in the .stab section - because it ends up in the .reloc section instead } - sects[sec_stab]^.addsectionreloc(curraddr-4,s,relative_rva) - else - sects[sec_stab]^.addsectionreloc(curraddr-4,s,relative_false); + begin + { current address } + curraddr:=sects[sec_stab].mempos+sects[sec_stab].datasize; + if DLLSource and RelocSection then + { avoid relocation in the .stab section + because it ends up in the .reloc section instead } + sects[sec_stab].addsectionreloc(curraddr-4,s,relative_rva) + else + sects[sec_stab].addsectionreloc(curraddr-4,s,relative_false); + end; end; - procedure tcoffoutput.writesymstabs(section:tsection;offset:longint;p:pchar;ps:pasmsymbol; + procedure tcoffdata.writesymstabs(section:tsection;offset:longint;p:pchar;ps:pasmsymbol; nidx,nother,line:longint;reloc:boolean); var stab : coffstab; @@ -445,15 +439,15 @@ implementation if section=sec_none then offset:=0 else - offset:=sects[section]^.datasize; + offset:=sects[section].datasize; end; if (section<>sec_none) then - inc(offset,sects[section]^.mempos); + inc(offset,sects[section].mempos); end; if assigned(p) and (p[0]<>#0) then begin - stab.strpos:=sects[sec_stabstr]^.datasize; - sects[sec_stabstr]^.write(p^,strlen(p)+1); + stab.strpos:=sects[sec_stabstr].datasize; + sects[sec_stabstr].write(p^,strlen(p)+1); end else stab.strpos:=0; @@ -461,24 +455,24 @@ implementation stab.ndesc:=line; stab.nother:=nother; stab.nvalue:=offset; - sects[sec_stab]^.write(stab,sizeof(stab)); + sects[sec_stab].write(stab,sizeof(stab)); { when the offset is not 0 then write a relocation, take also the hdrstab into account with the offset } - { current address } - curraddr:=sects[sec_stab]^.mempos+sects[sec_stab]^.datasize; if reloc then begin + { current address } + curraddr:=sects[sec_stab].mempos+sects[sec_stab].datasize; if DLLSource and RelocSection then { avoid relocation in the .stab section because it ends up in the .reloc section instead } - sects[sec_stab]^.addsymreloc(curraddr-4,ps,relative_rva) + sects[sec_stab].addsymreloc(curraddr-4,ps,relative_rva) else - sects[sec_stab]^.addsymreloc(curraddr-4,ps,relative_false); + sects[sec_stab].addsymreloc(curraddr-4,ps,relative_false); end; end; - procedure tcoffoutput.setsectionsizes(var s:tsecsize); + procedure tcoffdata.setsectionsizes(var s:tsecsize); var mempos : longint; sec : tsection; @@ -500,35 +494,61 @@ implementation createsection(sec); if assigned(sects[sec]) then begin - sects[sec]^.memsize:=s[sec]; + sects[sec].memsize:=s[sec]; { memory position } if not win32 then begin - sects[sec]^.mempos:=mempos; - inc(mempos,align(sects[sec]^.memsize,sects[sec]^.addralign)); + sects[sec].mempos:=mempos; + inc(mempos,align(sects[sec].memsize,sects[sec].addralign)); end; end; end; end; -{*********************************************** - Writing to disk -***********************************************} +{**************************************************************************** + TCoffOutput +****************************************************************************} - procedure tcoffoutput.write_relocs(s:poutputsection); + constructor tcoffoutput.createdjgpp(smart:boolean); + begin + inherited create(smart); + win32:=false; + end; + + + constructor tcoffoutput.createwin32(smart:boolean); + begin + inherited create(smart); + win32:=true; + end; + + + function tcoffoutput.initwriting(Aplace:tcutplace):tobjectdata; + begin + inherited initwriting(Aplace); + initsym:=0; + if win32 then + data:=tcoffdata.createwin32 + else + data:=tcoffdata.createdjgpp; + initwriting:=data; + end; + + + procedure tcoffoutput.write_relocs(s:tobjectsection); var rel : coffreloc; hr,r : poutputreloc; begin - r:=s^.relochead; + r:=s.relochead; while assigned(r) do begin rel.address:=r^.address; if assigned(r^.symbol) then begin if (r^.symbol^.bind=AB_LOCAL) then - rel.sym:=2*sects[r^.symbol^.section]^.secsymidx + rel.sym:=2*data.sects[r^.symbol^.section].secsymidx else begin if r^.symbol^.idx=-1 then @@ -539,7 +559,7 @@ implementation else begin if r^.section<>sec_none then - rel.sym:=2*sects[r^.section]^.secsymidx + rel.sym:=2*data.sects[r^.section].secsymidx else rel.sym:=0; end; @@ -548,7 +568,7 @@ implementation relative_false : rel.relative:=$6; relative_rva : rel.relative:=$7; end; - writer^.write(rel,sizeof(rel)); + writer.write(rel,sizeof(rel)); { goto next and dispose this reloc } hr:=r; r:=r^.next; @@ -570,7 +590,7 @@ implementation sym.section:=section; sym.typ:=typ; sym.aux:=aux; - writer^.write(sym,sizeof(sym)); + writer.write(sym,sizeof(sym)); end; @@ -578,43 +598,45 @@ implementation var filename : string[18]; sec : tsection; - value, sectionval, i : longint; globalval : byte; secrec : coffsectionrec; sym : toutputsymbol; begin - { The `.file' record, and the file name auxiliary record } - write_symbol ('.file', -1, 0, -2, $67, 1); - fillchar(filename,sizeof(filename),0); - filename:=SplitFileName(current_module^.mainsource^); - writer^.write(filename[1],sizeof(filename)-1); - { The section records, with their auxiliaries, also store the - symbol index } - for sec:=low(tsection) to high(tsection) do - if assigned(sects[sec]) then - begin - write_symbol(target_asm.secnames[sec],-1,sects[sec]^.mempos,sects[sec]^.secsymidx,3,1); - fillchar(secrec,sizeof(secrec),0); - secrec.len:=sects[sec]^.aligneddatasize; - secrec.nrelocs:=sects[sec]^.nrelocs; - writer^.write(secrec,sizeof(secrec)); - end; - { The real symbols } - syms^.seek(0); - for i:=1 to syms^.size div sizeof(TOutputSymbol) do + with tcoffdata(data) do begin - syms^.read(sym,sizeof(TOutputSymbol)); - if sym.bind=AB_LOCAL then - globalval:=3 - else - globalval:=2; - if assigned(sects[sym.section]) then - sectionval:=sects[sym.section]^.secsymidx - else - sectionval:=0; - write_symbol(sym.namestr,sym.nameidx,sym.value,sectionval,globalval,0); + { The `.file' record, and the file name auxiliary record } + write_symbol ('.file', -1, 0, -2, $67, 1); + fillchar(filename,sizeof(filename),0); + filename:=SplitFileName(current_module^.mainsource^); + writer.write(filename[1],sizeof(filename)-1); + { The section records, with their auxiliaries, also store the + symbol index } + for sec:=low(tsection) to high(tsection) do + if assigned(sects[sec]) then + begin + write_symbol(target_asm.secnames[sec],-1,sects[sec].mempos,sects[sec].secsymidx,3,1); + fillchar(secrec,sizeof(secrec),0); + secrec.len:=sects[sec].aligneddatasize; + secrec.nrelocs:=sects[sec].nrelocs; + writer.write(secrec,sizeof(secrec)); + end; + { The real symbols } + syms^.seek(0); + for i:=1 to syms^.size div sizeof(TOutputSymbol) do + begin + syms^.read(sym,sizeof(TOutputSymbol)); + if sym.bind=AB_LOCAL then + globalval:=3 + else + globalval:=2; + if assigned(sects[sym.section]) then + sectionval:=sects[sym.section].secsymidx + else + sectionval:=0; + write_symbol(sym.namestr,sym.nameidx,sym.value,sectionval,globalval,0); + end; end; end; @@ -633,122 +655,134 @@ implementation empty : array[0..15] of byte; hp : pdynamicblock; begin - { calc amount of sections we have } - fillchar(empty,sizeof(empty),0); - nsects:=0; - initsym:=2; { 2 for the file } - secsymidx:=0; - for sec:=low(tsection) to high(tsection) do - if assigned(sects[sec]) then - begin - inc(nsects); - inc(secsymidx); - sects[sec]^.secsymidx:=secsymidx; - inc(initsym,2); { 2 for each section } - end; - { For the stab section we need an HdrSym which can now be - calculated more easily } - if assigned(sects[sec_stab]) then + with tcoffdata(data) do begin - hstab.strpos:=1; - hstab.ntype:=0; - hstab.nother:=0; - hstab.ndesc:=(sects[sec_stab]^.datasize div sizeof(coffstab))-1{+1 according to gas output PM}; - hstab.nvalue:=sects[sec_stabstr]^.datasize; - sects[sec_stab]^.data^.seek(0); - sects[sec_stab]^.data^.write(hstab,sizeof(hstab)); - end; - { Calculate the filepositions } - datapos:=sizeof(coffheader)+sizeof(coffsechdr)*nsects; - { sections first } - for sec:=low(tsection) to high(tsection) do - if assigned(sects[sec]) then - begin - sects[sec]^.datapos:=datapos; - if assigned(sects[sec]^.data) then - inc(datapos,sects[sec]^.aligneddatasize); - end; - { relocs } - gotreloc:=false; - for sec:=low(tsection) to high(tsection) do - if assigned(sects[sec]) then - begin - PCoffSection(sects[sec])^.relocpos:=datapos; - inc(datapos,10*sects[sec]^.nrelocs); - if (not gotreloc) and (sects[sec]^.nrelocs>0) then - gotreloc:=true; - end; - { symbols } - sympos:=datapos; - { COFF header } - fillchar(header,sizeof(coffheader),0); - header.mach:=$14c; - header.nsects:=nsects; - header.sympos:=sympos; - header.syms:=(syms^.size div sizeof(TOutputSymbol))+initsym; - if gotreloc then - header.flag:=$104 - else - header.flag:=$105; - writer^.write(header,sizeof(header)); - { Section headers } - for sec:=low(tsection) to high(tsection) do - if assigned(sects[sec]) then - begin - fillchar(sechdr,sizeof(sechdr),0); - move(target_asm.secnames[sec][1],sechdr.name,length(target_asm.secnames[sec])); - if not win32 then - begin - sechdr.rvaofs:=sects[sec]^.mempos; - sechdr.vsize:=sects[sec]^.mempos; - end - else - begin - if sec=sec_bss then - sechdr.vsize:=sects[sec]^.aligneddatasize; - end; - sechdr.datasize:=sects[sec]^.aligneddatasize; - if (sects[sec]^.datasize>0) and assigned(sects[sec]^.data) then - sechdr.datapos:=sects[sec]^.datapos; - sechdr.nrelocs:=sects[sec]^.nrelocs; - sechdr.relocpos:=PCoffSection(sects[sec])^.relocpos; - sechdr.flags:=PCoffSection(sects[sec])^.flags; - writer^.write(sechdr,sizeof(sechdr)); - end; - { Sections } - for sec:=low(tsection) to high(tsection) do - if assigned(sects[sec]) and - assigned(sects[sec]^.data) then - begin - sects[sec]^.alignsection; - hp:=sects[sec]^.data^.firstblock; - while assigned(hp) do + { calc amount of sections we have } + fillchar(empty,sizeof(empty),0); + nsects:=0; + initsym:=2; { 2 for the file } + secsymidx:=0; + for sec:=low(tsection) to high(tsection) do + if assigned(sects[sec]) then begin - writer^.write(hp^.data,hp^.used); - hp:=hp^.next; + inc(nsects); + inc(secsymidx); + sects[sec].secsymidx:=secsymidx; + inc(initsym,2); { 2 for each section } end; - end; - { Relocs } - for sec:=low(tsection) to high(tsection) do - if assigned(sects[sec]) then - write_relocs(sects[sec]); - { Symbols } - write_symbols; - { Strings } - i:=strs^.size+4; - writer^.write(i,4); - hp:=strs^.firstblock; - while assigned(hp) do - begin - writer^.write(hp^.data,hp^.used); - hp:=hp^.next; + { For the stab section we need an HdrSym which can now be + calculated more easily } + if assigned(sects[sec_stab]) then + begin + hstab.strpos:=1; + hstab.ntype:=0; + hstab.nother:=0; + hstab.ndesc:=(sects[sec_stab].datasize div sizeof(coffstab))-1{+1 according to gas output PM}; + hstab.nvalue:=sects[sec_stabstr].datasize; + sects[sec_stab].data^.seek(0); + sects[sec_stab].data^.write(hstab,sizeof(hstab)); + end; + { Calculate the filepositions } + datapos:=sizeof(coffheader)+sizeof(coffsechdr)*nsects; + { sections first } + for sec:=low(tsection) to high(tsection) do + if assigned(sects[sec]) then + begin + sects[sec].datapos:=datapos; + if assigned(sects[sec].data) then + inc(datapos,sects[sec].aligneddatasize); + end; + { relocs } + gotreloc:=false; + for sec:=low(tsection) to high(tsection) do + if assigned(sects[sec]) then + begin + tcoffsection(sects[sec]).relocpos:=datapos; + inc(datapos,10*sects[sec].nrelocs); + if (not gotreloc) and (sects[sec].nrelocs>0) then + gotreloc:=true; + end; + { symbols } + sympos:=datapos; + { COFF header } + fillchar(header,sizeof(coffheader),0); + header.mach:=$14c; + header.nsects:=nsects; + header.sympos:=sympos; + header.syms:=(syms^.size div sizeof(TOutputSymbol))+initsym; + if gotreloc then + header.flag:=$104 + else + header.flag:=$105; + writer.write(header,sizeof(header)); + { Section headers } + for sec:=low(tsection) to high(tsection) do + if assigned(sects[sec]) then + begin + fillchar(sechdr,sizeof(sechdr),0); + move(target_asm.secnames[sec][1],sechdr.name,length(target_asm.secnames[sec])); + if not win32 then + begin + sechdr.rvaofs:=sects[sec].mempos; + sechdr.vsize:=sects[sec].mempos; + end + else + begin + if sec=sec_bss then + sechdr.vsize:=sects[sec].aligneddatasize; + end; + sechdr.datasize:=sects[sec].aligneddatasize; + if (sects[sec].datasize>0) and assigned(sects[sec].data) then + sechdr.datapos:=sects[sec].datapos; + sechdr.nrelocs:=sects[sec].nrelocs; + sechdr.relocpos:=TCoffSection(sects[sec]).relocpos; + sechdr.flags:=TCoffSection(sects[sec]).flags; + writer.write(sechdr,sizeof(sechdr)); + end; + { Sections } + for sec:=low(tsection) to high(tsection) do + if assigned(sects[sec]) and + assigned(sects[sec].data) then + begin + sects[sec].alignsection; + hp:=sects[sec].data^.firstblock; + while assigned(hp) do + begin + writer.write(hp^.data,hp^.used); + hp:=hp^.next; + end; + end; + { Relocs } + for sec:=low(tsection) to high(tsection) do + if assigned(sects[sec]) then + write_relocs(sects[sec]); + { Symbols } + write_symbols; + { Strings } + i:=strs^.size+4; + writer.write(i,4); + hp:=strs^.firstblock; + while assigned(hp) do + begin + writer.write(hp^.data,hp^.used); + hp:=hp^.next; + end; end; end; +{**************************************************************************** + TCoffInput +****************************************************************************} + + end. { $Log$ - Revision 1.5 2000-12-21 12:06:38 jonas + Revision 1.6 2000-12-23 19:59:35 peter + * object to class for ow/og objects + * split objectdata from objectoutput + + Revision 1.5 2000/12/21 12:06:38 jonas * changed type of all "flags" variables/parameters/fields to cardinal and removed longint typecasts around constants diff --git a/compiler/ogelf.pas b/compiler/ogelf.pas index c32c689de8..73a426df97 100644 --- a/compiler/ogelf.pas +++ b/compiler/ogelf.pas @@ -41,8 +41,8 @@ interface ogbase; type - pelf32section = ^telf32section; - telf32section = object(toutputsection) + telf32section = class(tobjectsection) + public secshidx : longint; { index for the section in symtab } shstridx, shtype, @@ -51,14 +51,14 @@ interface shinfo, entsize : longint; { relocation } - relocsect : PElf32Section; - constructor initsec(sec:TSection); - constructor initname(const Aname:string;Atype,Aflags,Alink,Ainfo,Aalign,Aentsize:longint); - destructor done; + relocsect : telf32Section; + constructor createsec(sec:TSection); + constructor createname(const Aname:string;Atype,Aflags,Alink,Ainfo,Aalign,Aentsize:longint); + destructor destroy;override; end; - pelf32output = ^telf32output; - telf32output = object(tobjectoutput) + telf32data = class(tobjectdata) + public symtabsect, strtabsect, shstrtabsect, @@ -66,31 +66,35 @@ interface gotoffsect, gotsect, pltsect, - symsect : pelf32Section; + symsect : telf32Section; strs, syms : Pdynamicarray; - initsym : longint; - constructor init(smart:boolean); - destructor done;virtual; - procedure initwriting(Aplace:tcutplace);virtual; - procedure donewriting;virtual; - procedure createsection(sec:tsection);virtual; - procedure setsectionsizes(var s:tsecsize);virtual; - procedure writereloc(data,len:longint;p:pasmsymbol;relative:relative_type);virtual; - procedure writesymbol(p:pasmsymbol);virtual; - procedure writestabs(section:tsection;offset:longint;p:pchar;nidx,nother,line:longint;reloc:boolean);virtual; + constructor create; + destructor destroy;override; + procedure createsection(sec:tsection);override; + procedure setsectionsizes(var s:tsecsize);override; + procedure writereloc(data,len:longint;p:pasmsymbol;relative:relative_type);override; + procedure writesymbol(p:pasmsymbol);override; + procedure writestabs(section:tsection;offset:longint;p:pchar;nidx,nother,line:longint;reloc:boolean);override; procedure writesymstabs(section:tsection;offset:longint;p:pchar;ps:pasmsymbol; - nidx,nother,line:longint;reloc:boolean);virtual; + nidx,nother,line:longint;reloc:boolean);override; + end; + + telf32output = class(tobjectoutput) private - procedure createrelocsection(s:pelf32section); + initsym : longint; + procedure createrelocsection(s:telf32section); procedure createshstrtab; procedure createsymtab; - procedure writesectionheader(s:pelf32section); - procedure writetodisk; + procedure writesectionheader(s:telf32section); + protected + procedure writetodisk;override; + public + function initwriting(Aplace:tcutplace):tobjectdata;override; end; - implementation +implementation uses {$ifdef delphi} @@ -207,7 +211,7 @@ interface TSection ****************************************************************************} - constructor telf32section.initsec(sec:TSection); + constructor telf32section.createsec(sec:TSection); var Aflags,Atype,Aalign,Aentsize : longint; begin @@ -246,13 +250,13 @@ interface AAlign:=1; end; end; - initname(target_asm.secnames[sec],Atype,Aflags,0,0,Aalign,Aentsize); + createname(target_asm.secnames[sec],Atype,Aflags,0,0,Aalign,Aentsize); end; - constructor telf32section.initname(const Aname:string;Atype,Aflags,Alink,Ainfo,Aalign,Aentsize:longint); + constructor telf32section.createname(const Aname:string;Atype,Aflags,Alink,Ainfo,Aalign,Aentsize:longint); begin - inherited init(Aname,Aalign,(AType=SHT_NOBITS)); + inherited create(Aname,Aalign,(AType=SHT_NOBITS)); secshidx:=0; shstridx:=0; shtype:=AType; @@ -264,45 +268,32 @@ interface end; - destructor telf32section.done; + destructor telf32section.destroy; begin if assigned(relocsect) then - dispose(relocsect,done); - inherited done; + relocsect.free; + inherited destroy; end; {**************************************************************************** - TElf32Output + TElf32Data ****************************************************************************} - constructor telf32output.init(smart:boolean); - begin - inherited init(smart); - end; - - - destructor telf32output.done; - begin - inherited done; - end; - - - procedure telf32output.initwriting(Aplace:tcutplace); + constructor telf32data.create; var s : string; begin - inherited initwriting(Aplace); + inherited create; { reset } - initsym:=0; new(syms,init(symbolresize)); { default sections } - new(symtabsect,initname('.symtab',2,0,0,0,4,16)); - new(strtabsect,initname('.strtab',3,0,0,0,1,0)); - new(shstrtabsect,initname('.shstrtab',3,0,0,0,1,0)); + symtabsect:=telf32section.createname('.symtab',2,0,0,0,4,16); + strtabsect:=telf32section.createname('.strtab',3,0,0,0,1,0); + shstrtabsect:=telf32section.createname('.shstrtab',3,0,0,0,1,0); { insert the empty and filename as first in strtab } - strtabsect^.writestr(#0); - strtabsect^.writestr(SplitFileName(current_module^.mainsource^)+#0); + strtabsect.writestr(#0); + strtabsect.writestr(SplitFileName(current_module^.mainsource^)+#0); { we need at least the following sections } createsection(sec_code); createsection(sec_data); @@ -315,30 +306,28 @@ interface writestabs(sec_none,0,nil,0,0,0,false); { write zero pchar and name together (PM) } s:=#0+SplitFileName(current_module^.mainsource^)+#0; - sects[sec_stabstr]^.write(s[1],length(s)); + sects[sec_stabstr].write(s[1],length(s)); end; end; - procedure telf32output.donewriting; + destructor telf32data.destroy; begin - writetodisk; - { free memory } dispose(syms,done); - dispose(symtabsect,done); - dispose(strtabsect,done); - dispose(shstrtabsect,done); - inherited donewriting; + symtabsect.free; + strtabsect.free; + shstrtabsect.free; + inherited destroy; end; - procedure telf32output.createsection(sec:tsection); + procedure telf32data.createsection(sec:tsection); begin - sects[sec]:=new(pelf32Section,initsec(Sec)) + sects[sec]:=telf32Section.createsec(Sec); end; - procedure telf32output.writesymbol(p:pasmsymbol); + procedure telf32data.writesymbol(p:pasmsymbol); var sym : toutputsymbol; begin @@ -370,9 +359,9 @@ interface if (sym.bind<>AB_LOCAL) then begin { symbolname, write the #0 separate to overcome 255+1 char not possible } - sym.nameidx:=strtabsect^.datasize; - strtabsect^.writestr(p^.name); - strtabsect^.writestr(#0); + sym.nameidx:=strtabsect.datasize; + strtabsect.writestr(p^.name); + strtabsect.writestr(#0); { update the asmsymbol index } p^.idx:=syms^.size div sizeof(toutputsymbol); { symbol } @@ -382,14 +371,10 @@ interface begin p^.idx:=-2; { local } end; - { make the exported syms known to the objectwriter - (needed for .a generation) } - if (sym.bind in [AB_GLOBAL,AB_COMMON]) then - writer^.writesym(p^.name); end; - procedure telf32output.writereloc(data,len:longint;p:pasmsymbol;relative:relative_type); + procedure telf32data.writereloc(data,len:longint;p:pasmsymbol;relative:relative_type); var symaddr : longint; begin @@ -405,12 +390,12 @@ interface case relative of relative_false : begin - sects[currsec]^.addsectionreloc(sects[currsec]^.datasize,currsec,relative_false); + sects[currsec].addsectionreloc(sects[currsec].datasize,currsec,relative_false); inc(data,symaddr); end; relative_true : begin - inc(data,symaddr-len-sects[currsec]^.datasize); + inc(data,symaddr-len-sects[currsec].datasize); end; relative_rva : internalerror(3219583); @@ -421,25 +406,25 @@ interface writesymbol(p); if (p^.section<>sec_none) and (relative<>relative_true) then begin - sects[currsec]^.addsectionreloc(sects[currsec]^.datasize,p^.section,relative); + sects[currsec].addsectionreloc(sects[currsec].datasize,p^.section,relative); inc(data,symaddr); end else - sects[currsec]^.addsymreloc(sects[currsec]^.datasize,p,relative); + sects[currsec].addsymreloc(sects[currsec].datasize,p,relative); if relative=relative_true then begin if p^.bind=AB_EXTERNAL then dec(data,len) else - dec(data,len+sects[currsec]^.datasize); + dec(data,len+sects[currsec].datasize); end; end; end; - sects[currsec]^.write(data,len); + sects[currsec].write(data,len); end; - procedure telf32output.writestabs(section:tsection;offset:longint;p:pchar;nidx,nother,line:longint;reloc : boolean); + procedure telf32data.writestabs(section:tsection;offset:longint;p:pchar;nidx,nother,line:longint;reloc : boolean); var stab : telf32stab; s : tsection; @@ -452,28 +437,28 @@ interface if s=sec_none then offset:=0 else - offset:=sects[s]^.datasize; + offset:=sects[s].datasize; end; end; fillchar(stab,sizeof(telf32stab),0); if assigned(p) and (p[0]<>#0) then begin - stab.strpos:=sects[sec_stabstr]^.datasize; - sects[sec_stabstr]^.write(p^,strlen(p)+1); + stab.strpos:=sects[sec_stabstr].datasize; + sects[sec_stabstr].write(p^,strlen(p)+1); end; stab.ntype:=nidx; stab.ndesc:=line; stab.nother:=nother; stab.nvalue:=offset; - sects[sec_stab]^.write(stab,sizeof(stab)); + sects[sec_stab].write(stab,sizeof(stab)); { when the offset is not 0 then write a relocation, take also the hdrstab into account with the offset } if reloc then - sects[sec_stab]^.addsectionreloc(sects[sec_stab]^.datasize-4,s,relative_false); + sects[sec_stab].addsectionreloc(sects[sec_stab].datasize-4,s,relative_false); end; - procedure telf32output.writesymstabs(section:tsection;offset:longint;p:pchar;ps:pasmsymbol; + procedure telf32data.writesymstabs(section:tsection;offset:longint;p:pchar;ps:pasmsymbol; nidx,nother,line:longint;reloc:boolean); var stab : telf32stab; @@ -485,78 +470,90 @@ interface if section=sec_none then offset:=0 else - offset:=sects[section]^.datasize; + offset:=sects[section].datasize; end; end; fillchar(stab,sizeof(telf32stab),0); if assigned(p) and (p[0]<>#0) then begin - stab.strpos:=sects[sec_stabstr]^.datasize; - sects[sec_stabstr]^.write(p^,strlen(p)+1); + stab.strpos:=sects[sec_stabstr].datasize; + sects[sec_stabstr].write(p^,strlen(p)+1); end; stab.ntype:=nidx; stab.ndesc:=line; stab.nother:=nother; stab.nvalue:=offset; - sects[sec_stab]^.write(stab,sizeof(stab)); + sects[sec_stab].write(stab,sizeof(stab)); { when the offset is not 0 then write a relocation, take also the hdrstab into account with the offset } if reloc then - sects[sec_stab]^.addsymreloc(sects[sec_stab]^.datasize-4,ps,relative_false); + sects[sec_stab].addsymreloc(sects[sec_stab].datasize-4,ps,relative_false); end; - procedure telf32output.setsectionsizes(var s:tsecsize); + procedure telf32data.setsectionsizes(var s:tsecsize); begin end; -{*********************************************** - Writing to disk -***********************************************} +{**************************************************************************** + TElf32Output +****************************************************************************} - procedure telf32output.createrelocsection(s:pelf32section); + function telf32output.initwriting(Aplace:tcutplace):tobjectdata; + begin + inherited initwriting(Aplace); + initsym:=0; + data:=telf32data.create; + initwriting:=data; + end; + + + procedure telf32output.createrelocsection(s:telf32section); var rel : telf32reloc; hr,r : poutputreloc; relsym,reltyp : longint; begin - { create the reloc section } - new(s^.relocsect,initname('.rel'+s^.name,9,0,symtabsect^.secshidx,s^.secshidx,4,8)); - { add the relocations } - r:=s^.relochead; - while assigned(r) do + with telf32data(data) do begin - rel.address:=r^.address; - if assigned(r^.symbol) then + { create the reloc section } + s.relocsect:=telf32section.createname('.rel'+s.name,9,0,symtabsect.secshidx,s.secshidx,4,8); + { add the relocations } + r:=s.relochead; + while assigned(r) do begin - if (r^.symbol^.bind=AB_LOCAL) then - relsym:=sects[r^.symbol^.section]^.secsymidx - else + rel.address:=r^.address; + if assigned(r^.symbol) then begin - if r^.symbol^.idx=-1 then - internalerror(4321); - relsym:=(r^.symbol^.idx+initsym); - end; - end - else - if r^.section<>sec_none then - relsym:=sects[r^.section]^.secsymidx - else - relsym:=SHN_UNDEF; - case r^.typ of - relative_true : - reltyp:=R_386_PC32; - relative_false : - reltyp:=R_386_32; - end; - rel.info:=(relsym shl 8) or reltyp; - { write reloc } - s^.relocsect^.write(rel,sizeof(rel)); - { goto next and dispose this reloc } - hr:=r; - r:=r^.next; - dispose(hr); + if (r^.symbol^.bind=AB_LOCAL) then + relsym:=sects[r^.symbol^.section].secsymidx + else + begin + if r^.symbol^.idx=-1 then + internalerror(4321); + relsym:=(r^.symbol^.idx+initsym); + end; + end + else + if r^.section<>sec_none then + relsym:=sects[r^.section].secsymidx + else + relsym:=SHN_UNDEF; + case r^.typ of + relative_true : + reltyp:=R_386_PC32; + relative_false : + reltyp:=R_386_32; + end; + rel.info:=(relsym shl 8) or reltyp; + { write reloc } + s.relocsect.write(rel,sizeof(rel)); + { goto next and dispose this reloc } + hr:=r; + r:=r^.next; + dispose(hr); + end; end; end; @@ -569,67 +566,70 @@ interface locals, i : longint; begin - locals:=2; - { empty entry } - fillchar(elfsym,sizeof(elfsym),0); - symtabsect^.write(elfsym,sizeof(elfsym)); - { filename entry } - elfsym.st_name:=1; - elfsym.st_info:=STT_FILE; - elfsym.st_shndx:=SHN_ABS; - symtabsect^.write(elfsym,sizeof(elfsym)); - { section } - for sec:=low(tsection) to high(tsection) do - if assigned(sects[sec]) then - begin - fillchar(elfsym,sizeof(elfsym),0); - elfsym.st_name:=pelf32section(sects[sec])^.shstridx; - elfsym.st_info:=STT_SECTION; - elfsym.st_shndx:=pelf32section(sects[sec])^.secshidx; - symtabsect^.write(elfsym,sizeof(elfsym)); - inc(locals); - end; - { symbols } - syms^.seek(0); - for i:=1 to (syms^.size div sizeof(toutputsymbol)) do + with telf32data(data) do begin - syms^.read(sym,sizeof(toutputsymbol)); + locals:=2; + { empty entry } fillchar(elfsym,sizeof(elfsym),0); - elfsym.st_name:=sym.nameidx; - elfsym.st_value:=sym.value; - elfsym.st_size:=sym.size; - case sym.bind of - AB_LOCAL : - begin - elfsym.st_info:=STB_LOCAL shl 4; - inc(locals); - end; - AB_COMMON, - AB_EXTERNAL, - AB_GLOBAL : - elfsym.st_info:=STB_GLOBAL shl 4; - end; - if sym.bind<>AB_EXTERNAL then + symtabsect.write(elfsym,sizeof(elfsym)); + { filename entry } + elfsym.st_name:=1; + elfsym.st_info:=STT_FILE; + elfsym.st_shndx:=SHN_ABS; + symtabsect.write(elfsym,sizeof(elfsym)); + { section } + for sec:=low(tsection) to high(tsection) do + if assigned(sects[sec]) then + begin + fillchar(elfsym,sizeof(elfsym),0); + elfsym.st_name:=telf32section(sects[sec]).shstridx; + elfsym.st_info:=STT_SECTION; + elfsym.st_shndx:=telf32section(sects[sec]).secshidx; + symtabsect.write(elfsym,sizeof(elfsym)); + inc(locals); + end; + { symbols } + syms^.seek(0); + for i:=1 to (syms^.size div sizeof(toutputsymbol)) do begin - case sym.typ of - AT_FUNCTION : - elfsym.st_info:=elfsym.st_info or STT_FUNC; - AT_DATA : - elfsym.st_info:=elfsym.st_info or STT_OBJECT; + syms^.read(sym,sizeof(toutputsymbol)); + fillchar(elfsym,sizeof(elfsym),0); + elfsym.st_name:=sym.nameidx; + elfsym.st_value:=sym.value; + elfsym.st_size:=sym.size; + case sym.bind of + AB_LOCAL : + begin + elfsym.st_info:=STB_LOCAL shl 4; + inc(locals); + end; + AB_COMMON, + AB_EXTERNAL, + AB_GLOBAL : + elfsym.st_info:=STB_GLOBAL shl 4; end; + if sym.bind<>AB_EXTERNAL then + begin + case sym.typ of + AT_FUNCTION : + elfsym.st_info:=elfsym.st_info or STT_FUNC; + AT_DATA : + elfsym.st_info:=elfsym.st_info or STT_OBJECT; + end; + end; + if sym.bind=AB_COMMON then + elfsym.st_shndx:=SHN_COMMON + else + if assigned(sects[sym.section]) then + elfsym.st_shndx:=telf32section(sects[sym.section]).secshidx + else + elfsym.st_shndx:=SHN_UNDEF; + symtabsect.write(elfsym,sizeof(elfsym)); end; - if sym.bind=AB_COMMON then - elfsym.st_shndx:=SHN_COMMON - else - if assigned(sects[sym.section]) then - elfsym.st_shndx:=pelf32section(sects[sym.section])^.secshidx - else - elfsym.st_shndx:=SHN_UNDEF; - symtabsect^.write(elfsym,sizeof(elfsym)); + { update the .symtab section header } + symtabsect.shlink:=strtabsect.secshidx; + symtabsect.shinfo:=locals; end; - { update the .symtab section header } - symtabsect^.shlink:=strtabsect^.secshidx; - symtabsect^.shinfo:=locals; end; @@ -637,38 +637,41 @@ interface var sec : tsection; begin - with shstrtabsect^ do + with telf32data(data) do begin - writestr(#0); - symtabsect^.shstridx:=writestr('.symtab'#0); - strtabsect^.shstridx:=writestr('.strtab'#0); - shstrtabsect^.shstridx:=writestr('.shstrtab'#0); - for sec:=low(tsection) to high(tsection) do - if assigned(sects[sec]) then - begin - pelf32section(sects[sec])^.shstridx:=writestr(sects[sec]^.name+#0); - if assigned(pelf32section(sects[sec])^.relocsect) then - pelf32section(sects[sec])^.relocsect^.shstridx:=writestr(pelf32section(sects[sec])^.relocsect^.name+#0); - end; + with shstrtabsect do + begin + writestr(#0); + symtabsect.shstridx:=writestr('.symtab'#0); + strtabsect.shstridx:=writestr('.strtab'#0); + shstrtabsect.shstridx:=writestr('.shstrtab'#0); + for sec:=low(tsection) to high(tsection) do + if assigned(sects[sec]) then + begin + telf32section(sects[sec]).shstridx:=writestr(sects[sec].name+#0); + if assigned(telf32section(sects[sec]).relocsect) then + telf32section(sects[sec]).relocsect.shstridx:=writestr(telf32section(sects[sec]).relocsect.name+#0); + end; + end; end; end; - procedure telf32output.writesectionheader(s:pelf32section); + procedure telf32output.writesectionheader(s:telf32section); var sechdr : telf32sechdr; begin fillchar(sechdr,sizeof(sechdr),0); - sechdr.sh_name:=s^.shstridx; - sechdr.sh_type:=s^.shtype; - sechdr.sh_flags:=s^.shflags; - sechdr.sh_offset:=s^.datapos; - sechdr.sh_size:=s^.datasize; - sechdr.sh_link:=s^.shlink; - sechdr.sh_info:=s^.shinfo; - sechdr.sh_addralign:=s^.addralign; - sechdr.sh_entsize:=s^.entsize; - writer^.write(sechdr,sizeof(sechdr)); + sechdr.sh_name:=s.shstridx; + sechdr.sh_type:=s.shtype; + sechdr.sh_flags:=s.shflags; + sechdr.sh_offset:=s.datapos; + sechdr.sh_size:=s.datasize; + sechdr.sh_link:=s.shlink; + sechdr.sh_info:=s.shinfo; + sechdr.sh_addralign:=s.addralign; + sechdr.sh_entsize:=s.entsize; + writer.write(sechdr,sizeof(sechdr)); end; @@ -683,165 +686,171 @@ interface empty : array[0..63] of byte; hp : pdynamicblock; begin - { calc amount of sections we have } - fillchar(empty,sizeof(empty),0); - nsects:=1; - initsym:=2; - for sec:=low(tsection) to high(tsection) do - if assigned(sects[sec]) then - begin - { each section requires a symbol for relocation } - sects[sec]^.secsymidx:=initsym; - inc(initsym); - { also create the index in the section header table } - pelf32section(sects[sec])^.secshidx:=nsects; - inc(nsects); - if assigned(sects[sec]^.relochead) then - inc(nsects); - end; - { add default sections follows } - shstrtabsect^.secshidx:=nsects; - inc(nsects); - symtabsect^.secshidx:=nsects; - inc(nsects); - strtabsect^.secshidx:=nsects; - inc(nsects); - { For the stab section we need an HdrSym which can now be - calculated more easily } - if assigned(sects[sec_stab]) then + with telf32data(data) do begin - hstab.strpos:=1; - hstab.ntype:=0; - hstab.nother:=0; - hstab.ndesc:=(sects[sec_stab]^.datasize div sizeof(telf32stab))-1{+1 according to gas output PM}; - hstab.nvalue:=sects[sec_stabstr]^.datasize; - sects[sec_stab]^.data^.seek(0); - sects[sec_stab]^.data^.write(hstab,sizeof(hstab)); - end; - { Create the relocation sections } - for sec:=low(tsection) to high(tsection) do - if assigned(sects[sec]) and - (sects[sec]^.nrelocs>0) then - createrelocsection(pelf32section(sects[sec])); - { create .symtab } - createsymtab; - { create .shstrtab } - createshstrtab; - { Calculate the filepositions } - datapos:=$40; { elfheader + alignment } - { sections first } - for sec:=low(tsection) to high(tsection) do - if assigned(sects[sec]) then - begin - sects[sec]^.datapos:=datapos; - if assigned(sects[sec]^.data) then - inc(datapos,sects[sec]^.aligneddatasize); - end; - { shstrtab } - shstrtabsect^.datapos:=datapos; - inc(datapos,shstrtabsect^.aligneddatasize); - { section headers } - shoffset:=datapos; - inc(datapos,nsects*sizeof(telf32sechdr)); - { symtab } - symtabsect^.datapos:=datapos; - inc(datapos,symtabsect^.aligneddatasize); - { strtab } - strtabsect^.datapos:=datapos; - inc(datapos,align(strtabsect^.datasize,4)); - { .rel sections } - for sec:=low(tsection) to high(tsection) do - if assigned(sects[sec]) and - assigned(pelf32section(sects[sec])^.relocsect) then - begin - pelf32section(sects[sec])^.relocsect^.datapos:=datapos; - inc(datapos,pelf32section(sects[sec])^.relocsect^.aligneddatasize); - end; - { Write ELF Header } - fillchar(header,sizeof(header),0); - header.magic0123:=$464c457f; { = #127'ELF' } - header.file_class:=1; - header.data_encoding:=1; - header.file_version:=1; - header.e_type:=1; - header.e_machine:=3; - header.e_version:=1; - header.e_shoff:=shoffset; - header.e_shstrndx:=shstrtabsect^.secshidx; - header.e_shnum:=nsects; - header.e_ehsize:=sizeof(telf32header); - header.e_shentsize:=sizeof(telf32sechdr); - writer^.write(header,sizeof(header)); - writer^.write(empty,$40-sizeof(header)); { align } - { Sections } - for sec:=low(tsection) to high(tsection) do - if assigned(sects[sec]) and - assigned(sects[sec]^.data) then - begin - sects[sec]^.alignsection; - hp:=sects[sec]^.data^.firstblock; - while assigned(hp) do + { calc amount of sections we have } + fillchar(empty,sizeof(empty),0); + nsects:=1; + initsym:=2; + for sec:=low(tsection) to high(tsection) do + if assigned(sects[sec]) then begin - writer^.write(hp^.data,hp^.used); - hp:=hp^.next; + { each section requires a symbol for relocation } + sects[sec].secsymidx:=initsym; + inc(initsym); + { also create the index in the section header table } + telf32section(sects[sec]).secshidx:=nsects; + inc(nsects); + if assigned(sects[sec].relochead) then + inc(nsects); end; - end; - { .shstrtab } - shstrtabsect^.alignsection; - hp:=shstrtabsect^.data^.firstblock; - while assigned(hp) do - begin - writer^.write(hp^.data,hp^.used); - hp:=hp^.next; - end; - { section headers, start with an empty header for sh_undef } - writer^.write(empty,sizeof(telf32sechdr)); - for sec:=low(tsection) to high(tsection) do - if assigned(sects[sec]) then - begin - writesectionheader(pelf32section(sects[sec])); - if assigned(pelf32section(sects[sec])^.relocsect) then - writesectionheader(pelf32section(sects[sec])^.relocsect); - end; - writesectionheader(shstrtabsect); - writesectionheader(symtabsect); - writesectionheader(strtabsect); - { .symtab } - symtabsect^.alignsection; - hp:=symtabsect^.data^.firstblock; - while assigned(hp) do - begin - writer^.write(hp^.data,hp^.used); - hp:=hp^.next; - end; - { .strtab } - strtabsect^.writealign(4); - hp:=strtabsect^.data^.firstblock; - while assigned(hp) do - begin - writer^.write(hp^.data,hp^.used); - hp:=hp^.next; - end; - { .rel sections } - for sec:=low(tsection) to high(tsection) do - if assigned(sects[sec]) and - assigned(pelf32section(sects[sec])^.relocsect) then - begin - pelf32section(sects[sec])^.relocsect^.alignsection; - hp:=pelf32section(sects[sec])^.relocsect^.data^.firstblock; - while assigned(hp) do + { add default sections follows } + shstrtabsect.secshidx:=nsects; + inc(nsects); + symtabsect.secshidx:=nsects; + inc(nsects); + strtabsect.secshidx:=nsects; + inc(nsects); + { For the stab section we need an HdrSym which can now be + calculated more easily } + if assigned(sects[sec_stab]) then + begin + hstab.strpos:=1; + hstab.ntype:=0; + hstab.nother:=0; + hstab.ndesc:=(sects[sec_stab].datasize div sizeof(telf32stab))-1{+1 according to gas output PM}; + hstab.nvalue:=sects[sec_stabstr].datasize; + sects[sec_stab].data^.seek(0); + sects[sec_stab].data^.write(hstab,sizeof(hstab)); + end; + { Create the relocation sections } + for sec:=low(tsection) to high(tsection) do + if assigned(sects[sec]) and + (sects[sec].nrelocs>0) then + createrelocsection(telf32section(sects[sec])); + { create .symtab } + createsymtab; + { create .shstrtab } + createshstrtab; + { Calculate the filepositions } + datapos:=$40; { elfheader + alignment } + { sections first } + for sec:=low(tsection) to high(tsection) do + if assigned(sects[sec]) then begin - writer^.write(hp^.data,hp^.used); - hp:=hp^.next; + sects[sec].datapos:=datapos; + if assigned(sects[sec].data) then + inc(datapos,sects[sec].aligneddatasize); end; - end; + { shstrtab } + shstrtabsect.datapos:=datapos; + inc(datapos,shstrtabsect.aligneddatasize); + { section headers } + shoffset:=datapos; + inc(datapos,nsects*sizeof(telf32sechdr)); + { symtab } + symtabsect.datapos:=datapos; + inc(datapos,symtabsect.aligneddatasize); + { strtab } + strtabsect.datapos:=datapos; + inc(datapos,align(strtabsect.datasize,4)); + { .rel sections } + for sec:=low(tsection) to high(tsection) do + if assigned(sects[sec]) and + assigned(telf32section(sects[sec]).relocsect) then + begin + telf32section(sects[sec]).relocsect.datapos:=datapos; + inc(datapos,telf32section(sects[sec]).relocsect.aligneddatasize); + end; + { Write ELF Header } + fillchar(header,sizeof(header),0); + header.magic0123:=$464c457f; { = #127'ELF' } + header.file_class:=1; + header.data_encoding:=1; + header.file_version:=1; + header.e_type:=1; + header.e_machine:=3; + header.e_version:=1; + header.e_shoff:=shoffset; + header.e_shstrndx:=shstrtabsect.secshidx; + header.e_shnum:=nsects; + header.e_ehsize:=sizeof(telf32header); + header.e_shentsize:=sizeof(telf32sechdr); + writer.write(header,sizeof(header)); + writer.write(empty,$40-sizeof(header)); { align } + { Sections } + for sec:=low(tsection) to high(tsection) do + if assigned(sects[sec]) and + assigned(sects[sec].data) then + begin + sects[sec].alignsection; + hp:=sects[sec].data^.firstblock; + while assigned(hp) do + begin + writer.write(hp^.data,hp^.used); + hp:=hp^.next; + end; + end; + { .shstrtab } + shstrtabsect.alignsection; + hp:=shstrtabsect.data^.firstblock; + while assigned(hp) do + begin + writer.write(hp^.data,hp^.used); + hp:=hp^.next; + end; + { section headers, start with an empty header for sh_undef } + writer.write(empty,sizeof(telf32sechdr)); + for sec:=low(tsection) to high(tsection) do + if assigned(sects[sec]) then + begin + writesectionheader(telf32section(sects[sec])); + if assigned(telf32section(sects[sec]).relocsect) then + writesectionheader(telf32section(sects[sec]).relocsect); + end; + writesectionheader(shstrtabsect); + writesectionheader(symtabsect); + writesectionheader(strtabsect); + { .symtab } + symtabsect.alignsection; + hp:=symtabsect.data^.firstblock; + while assigned(hp) do + begin + writer.write(hp^.data,hp^.used); + hp:=hp^.next; + end; + { .strtab } + strtabsect.writealign(4); + hp:=strtabsect.data^.firstblock; + while assigned(hp) do + begin + writer.write(hp^.data,hp^.used); + hp:=hp^.next; + end; + { .rel sections } + for sec:=low(tsection) to high(tsection) do + if assigned(sects[sec]) and + assigned(telf32section(sects[sec]).relocsect) then + begin + telf32section(sects[sec]).relocsect.alignsection; + hp:=telf32section(sects[sec]).relocsect.data^.firstblock; + while assigned(hp) do + begin + writer.write(hp^.data,hp^.used); + hp:=hp^.next; + end; + end; + end; end; - end. { $Log$ - Revision 1.2 2000-11-12 22:45:14 peter + Revision 1.3 2000-12-23 19:59:35 peter + * object to class for ow/og objects + * split objectdata from objectoutput + + Revision 1.2 2000/11/12 22:45:14 peter * moved setting of stab hdrsym Revision 1.1 2000/11/12 22:20:37 peter diff --git a/compiler/owar.pas b/compiler/owar.pas index bee39bf3fc..9ecab364fe 100644 --- a/compiler/owar.pas +++ b/compiler/owar.pas @@ -40,14 +40,13 @@ type fmag : array[0..1] of char; end; - parobjectwriter=^tarobjectwriter; - tarobjectwriter=object(tobjectwriter) - constructor Init(const Aarfn:string); - destructor Done;virtual; - procedure create(const fn:string);virtual; - procedure close;virtual; - procedure writesym(const sym:string);virtual; - procedure write(const b;len:longint);virtual; + tarobjectwriter=class(tobjectwriter) + constructor create(const Aarfn:string); + destructor destroy;override; + procedure createfile(const fn:string);override; + procedure closefile;override; + procedure writesym(const sym:string);override; + procedure write(const b;len:longint);override; private arfn : string; arhdr : tarhdr; @@ -115,7 +114,7 @@ end; TArObjectWriter *****************************************************************************} -constructor tarobjectwriter.init(const Aarfn:string); +constructor tarobjectwriter.create(const Aarfn:string); var time : datetime; dummy : word; @@ -132,7 +131,7 @@ begin end; -destructor tarobjectwriter.done; +destructor tarobjectwriter.destroy; begin if Errorcount=0 then writear; @@ -172,7 +171,7 @@ begin end; -procedure tarobjectwriter.create(const fn:string); +procedure tarobjectwriter.createfile(const fn:string); begin objfn:=fn; objpos:=ardata^.size; @@ -180,7 +179,7 @@ begin end; -procedure tarobjectwriter.close; +procedure tarobjectwriter.closefile; begin ardata^.align(2); { fix the size in the header } @@ -282,7 +281,11 @@ end; end. { $Log$ - Revision 1.5 2000-09-24 15:06:20 peter + Revision 1.6 2000-12-23 19:59:35 peter + * object to class for ow/og objects + * split objectdata from objectoutput + + Revision 1.5 2000/09/24 15:06:20 peter * use defines.inc Revision 1.4 2000/08/19 18:44:27 peter diff --git a/compiler/owbase.pas b/compiler/owbase.pas index 7cc80b6af5..2db92868d1 100644 --- a/compiler/owbase.pas +++ b/compiler/owbase.pas @@ -27,12 +27,11 @@ unit owbase; interface type - pobjectwriter=^tobjectwriter; - tobjectwriter=object - constructor Init; - destructor Done;virtual; - procedure create(const fn:string);virtual; - procedure close;virtual; + tobjectwriter=class + constructor create; + destructor destroy;override; + procedure createfile(const fn:string);virtual; + procedure closefile;virtual; procedure writesym(const sym:string);virtual; procedure write(const b;len:longint);virtual; private @@ -53,7 +52,7 @@ uses const bufsize = 32768; -constructor tobjectwriter.init; +constructor tobjectwriter.create; begin getmem(buf,bufsize); bufidx:=0; @@ -62,15 +61,15 @@ begin end; -destructor tobjectwriter.done; +destructor tobjectwriter.destroy; begin if opened then - close; + closefile; freemem(buf,bufsize); end; -procedure tobjectwriter.create(const fn:string); +procedure tobjectwriter.createfile(const fn:string); begin assign(f,fn); {$I-} @@ -87,7 +86,7 @@ begin end; -procedure tobjectwriter.close; +procedure tobjectwriter.closefile; begin if bufidx>0 then writebuf; @@ -150,7 +149,11 @@ end; end. { $Log$ - Revision 1.4 2000-09-24 15:06:20 peter + Revision 1.5 2000-12-23 19:59:35 peter + * object to class for ow/og objects + * split objectdata from objectoutput + + Revision 1.4 2000/09/24 15:06:20 peter * use defines.inc Revision 1.3 2000/08/19 18:44:27 peter diff --git a/compiler/pstatmnt.pas b/compiler/pstatmnt.pas index 0102eaa731..15c08b1b81 100644 --- a/compiler/pstatmnt.pas +++ b/compiler/pstatmnt.pas @@ -427,13 +427,13 @@ implementation levelcount:=1; withsymtable:=new(pwithsymtable,init); withsymtable^.symsearch:=symtab^.symsearch; - withsymtable^.next:=symtablestack; - if (p.nodetype=loadn) and - (tloadnode(p).symtable=aktprocsym^.definition^.localst) then - pwithsymtable(withsymtable)^.direct_with:=true; - {symtab^.withnode:=p; not yet allocated !! } - pwithsymtable(withsymtable)^.withrefnode:=p; + if (p.nodetype=loadn) and + (tloadnode(p).symtable=aktprocsym^.definition^.localst) then + pwithsymtable(withsymtable)^.direct_with:=true; + {symtab^.withnode:=p; not yet allocated !! } + pwithsymtable(withsymtable)^.withrefnode:=p; withsymtable^.defowner:=precorddef(p.resulttype); + withsymtable^.next:=symtablestack; symtablestack:=withsymtable; end; end; @@ -1259,7 +1259,11 @@ implementation end. { $Log$ - Revision 1.17 2000-12-16 22:45:55 jonas + Revision 1.18 2000-12-23 19:59:35 peter + * object to class for ow/og objects + * split objectdata from objectoutput + + Revision 1.17 2000/12/16 22:45:55 jonas * fixed case statements with int64 values Revision 1.16 2000/11/29 00:30:37 florian