From 5d25d6f1d6bed7eda2ab6e92b81b85885b1813d0 Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 27 May 1998 00:20:31 +0000 Subject: [PATCH] * some scanner optimizes * automaticly aout2exe for go32v1 * fixed dynamiclinker option which was added at the wrong place --- compiler/link.pas | 68 +++++++------ compiler/scanner.pas | 237 ++++++++++++++++++++++++++----------------- compiler/systems.pas | 33 +++++- 3 files changed, 209 insertions(+), 129 deletions(-) diff --git a/compiler/link.pas b/compiler/link.pas index c01c004f3e..e86afacc5a 100644 --- a/compiler/link.pas +++ b/compiler/link.pas @@ -124,7 +124,7 @@ var ext : extstr; begin FSplit(s,path,name,ext); - ExeName:=Path+Name+target_os.ExeExt; + ExeName:=Path+Name+target_info.ExeExt; end; @@ -257,10 +257,7 @@ Var i : longint; prtobj,s,s2 : string; begin -{ Open linkresponse and write header } - assign(linkresponse,inputdir+LinkResName); - rewrite(linkresponse); - + WriteResponseFile:=False; { set special options for some targets } prtobj:='prt0'; case target_info.target of @@ -275,7 +272,21 @@ begin end; end; -{ Add library searchpath } +{ Fix command line options } + If not SharedLibFiles.Empty then + LinkOptions:='-dynamic-linker='+DynamicLinker+' '+LinkOptions; + if Strip then + LinkOptions:=LinkOptions+target_link.stripopt; + +{ Open linkresponse and write header } + assign(linkresponse,inputdir+LinkResName); + {$I-} + rewrite(linkresponse); + {$I+} + if ioresult<>0 then + exit; + + { Write library searchpath } S2:=LibrarySearchPath; Repeat i:=Pos(';',S2); @@ -288,7 +299,7 @@ begin until S2=''; writeln(linkresponse,target_link.inputstart); -{ add objectfiles, start with prt0 always } + { add objectfiles, start with prt0 always } if prtobj<>'' then Writeln(linkresponse,FindObjectFile(prtobj)); while not ObjectFiles.Empty do @@ -297,7 +308,8 @@ begin if s<>'' then Writeln(linkresponse,s); end; -{ Write sharedlibraries like -l } + + { Write sharedlibraries like -l } While not SharedLibFiles.Empty do begin S:=SharedLibFiles.Get; @@ -308,7 +320,7 @@ begin end; writeln(linkresponse,target_link.inputend); -{ Write staticlibraries } + { Write staticlibraries } if not StaticLibFiles.Empty then begin Writeln(LinkResponse,target_link.GroupStart); @@ -330,9 +342,8 @@ Function TLinker.MakeExecutable:boolean; var bindbin : string[80]; bindfound : boolean; - _stacksize,i, - _heapsize : longint; - s,s2 : string; + i : longint; + s : string; dummy : file; success : boolean; begin @@ -346,11 +357,6 @@ begin end; {$endif Linux} - If not SharedLibFiles.Empty then - LinkOptions:='-dynamic-linker='+DynamicLinker+' '+LinkOptions; - if Strip then - LinkOptions:=LinkOptions+target_link.stripopt; - { Write used files and libraries } WriteResponseFile; @@ -362,25 +368,20 @@ begin Replace(s,'$OPT',LinkOptions); Replace(s,'$RES',inputdir+LinkResName); success:=DoExec(FindLinker,s,true,false); - {Bind} - if target_info.target=target_os2 then + if target_link.bindbin<>'' then begin - {Calculate the stack and heap size in kilobytes, rounded upwards.} - _stacksize:=(stacksize+1023) shr 10; - {Minimum stacksize for EMX is 32K.} - if _stacksize<32 then - _stacksize:=32; - str(_stacksize,s); - _heapsize:=(heapsize+1023) shr 10; - str(_heapsize,s2); - bindbin:=FindExe('emxbind',bindfound); + s:=target_link.bindcmd; + Replace(s,'$EXE',exename); + Replace(s,'$HEAPKB',tostr((heapsize+1023) shr 10)); + Replace(s,'$STACKKB',tostr((stacksize+1023) shr 10)); + bindbin:=FindExe(target_link.bindbin,bindfound); if (not bindfound) and (not externlink) then begin - Message(exec_w_binder_not_found); + Message1(exec_w_binder_not_found,bindbin); externlink:=true; end; - DoExec(bindbin,'-k'+s+' -o '+exename+'.exe '+exename+' -aim -s'+s2,false,false); + DoExec(bindbin,s,false,false); end; {Remove ReponseFile} if (success) and (not externlink) then @@ -438,7 +439,12 @@ end; end. { $Log$ - Revision 1.10 1998-05-22 12:32:47 peter + Revision 1.11 1998-05-27 00:20:31 peter + * some scanner optimizes + * automaticly aout2exe for go32v1 + * fixed dynamiclinker option which was added at the wrong place + + Revision 1.10 1998/05/22 12:32:47 peter * fixed -L on the commandline, Dos commandline is only 128 bytes Revision 1.9 1998/05/12 10:46:59 peter diff --git a/compiler/scanner.pas b/compiler/scanner.pas index 3aba1508f8..ae97f99873 100644 --- a/compiler/scanner.pas +++ b/compiler/scanner.pas @@ -147,11 +147,11 @@ unit scanner; orgpattern, pattern : string; macrobuffer : ^tmacrobuffer; - comment_level : word; inputbuffer : pchar; inputpointer : pchar; - parse_types, { true, if type declarations are parsed } +{ parse_types, } { true, if type declarations are parsed } s_point : boolean; + comment_level, yylexcount, macropos, lastlinepos, @@ -412,8 +412,15 @@ unit scanner; readstring[i]:=c; end; { get next char } - readchar; + c:=inputpointer^; + if c=#0 then + reload + else + inc(longint(inputpointer)); end; + { was the next char a linebreak ? } + if c in [#10,#13] then + linebreak; readstring[0]:=chr(i); end; @@ -458,12 +465,16 @@ unit scanner; readnumber[i]:=c; end; { get next char } - readchar; + c:=inputpointer^; + if c=#0 then + reload + else + inc(longint(inputpointer)); end; - readnumber[0]:=chr(i); { was the next char a linebreak ? } - { if c in [#10,#13] then - linebreak; } + if c in [#10,#13] then + linebreak; + readnumber[0]:=chr(i); end; @@ -498,7 +509,14 @@ unit scanner; end; end; end; - readchar; +{ readchar; } + c:=inputpointer^; + if c=#0 then + reload + else + inc(longint(inputpointer)); + if c in [#10,#13] then + linebreak; until false; readcomment[0]:=chr(i); end; @@ -508,14 +526,15 @@ unit scanner; begin while c in [' ',#9..#13] do begin - readchar; - {c:=inputpointer^; +{ readchar; } + c:=inputpointer^; if c=#0 then reload else inc(longint(inputpointer)); if c in [#10,#13] then - linebreak; } + linebreak; + end; end; @@ -544,12 +563,15 @@ unit scanner; else found:=0; end; - readchar; - {c:=inputpointer^; +{ readchar;} + c:=inputpointer^; if c=#0 then reload else - inc(longint(inputpointer));} + inc(longint(inputpointer)); + if c in [#10,#13] then + linebreak; + until (found=2); end; @@ -570,14 +592,15 @@ unit scanner; '}' : dec_comment_level; #26 : Message(scan_f_end_of_file); end; - readchar; - {c:=inputpointer^; +{ readchar; } + c:=inputpointer^; if c=#0 then reload else - inc(longint(inputpointer));} + inc(longint(inputpointer)); + if c in [#10,#13] then + linebreak; end; - {if (c=#10) or (c=#13) then linebreak;} end; @@ -633,18 +656,20 @@ unit scanner; else found:=0; end; - readchar; - {c:=inputpointer^; +{ readchar; } + c:=inputpointer^; if c=#0 then reload else - inc(longint(inputpointer));} + inc(longint(inputpointer)); + if c in [#10,#13] then + linebreak; until (found=2); end; end; - function yylex : ttoken; + function yylex : ttoken; var y : ttoken; code : word; @@ -655,14 +680,14 @@ unit scanner; label exit_label; begin - tokenpos.line:=current_module^.current_inputfile^.line_no; - tokenpos.column:=get_current_col; - tokenpos.fileindex:=current_module^.current_index; { was the last character a point ? } { this code is needed because the scanner if there is a 1. found if } { this is a floating point number or range like 1..3 } if s_point then begin + tokenpos.line:=current_module^.current_inputfile^.line_no; + tokenpos.column:=get_current_col; + tokenpos.fileindex:=current_module^.current_index; s_point:=false; if c='.' then begin @@ -674,80 +699,87 @@ unit scanner; goto exit_label; end; + { Skip all spaces and comments } repeat case c of '{' : skipcomment; - ' ',#9..#13 : skipspace; + ' ',#9..#13 : skipspace; else break; end; until false; + { Save current token position } lasttokenpos:=longint(inputpointer); tokenpos.line:=current_module^.current_inputfile^.line_no; tokenpos.column:=get_current_col; tokenpos.fileindex:=current_module^.current_index; - { will become line:=lasttokenpos ??;} - case c of - '_','A'..'Z', - 'a'..'z' : begin - orgpattern:=readstring; - pattern:=upper(orgpattern); - if (length(pattern) in [2..id_len]) and is_keyword(y) then - yylex:=y - else - begin - { this takes some time ... } - if support_macros then - begin - mac:=pmacrosym(macros^.search(pattern)); - if assigned(mac) and (assigned(mac^.buftext)) then - begin - { don't forget the last char } - dec(longint(inputpointer)); - current_module^.current_inputfile^.bufpos:=inputpointer-inputbuffer; - { this isn't a proper way, but ... } - hp:=new(pinputfile,init('','Macro '+pattern,'')); - hp^.next:=current_module^.current_inputfile; - current_module^.current_inputfile:=hp; - status.currentsource:=current_module^.current_inputfile^.name^; - { I don't think that we should do that - because otherwise the file will be searched !! (PM) - but there is the problem of index !! } - current_module^.sourcefiles.register_file(hp); - current_module^.current_index:=hp^.ref_index; - { set an own buffer } - getmem(hp2,mac^.buflen+1); - current_module^.current_inputfile^.setbuf(hp2,mac^.buflen+1); - inputbuffer:=current_module^.current_inputfile^.buf; - { copy text } - move(mac^.buftext^,inputbuffer^,mac^.buflen); - { put end sign } - inputbuffer[mac^.buflen+1]:=#0; - { load c } - c:=inputbuffer^; - inputpointer:=inputbuffer+1; - { handle empty macros } - if c=#0 then - reload; - { play it again ... } - inc(yylexcount); - if yylexcount>16 then - Message(scan_w_macro_deep_ten); + + + { Check first for a identifier/keyword, this is 20+% faster (PFV) } + + if c in ['_','A'..'Z','a'..'z'] then + begin + orgpattern:=readstring; + pattern:=upper(orgpattern); + if (length(pattern) in [2..id_len]) and is_keyword(y) then + yylex:=y + else + begin + { this takes some time ... } + if support_macros then + begin + mac:=pmacrosym(macros^.search(pattern)); + if assigned(mac) and (assigned(mac^.buftext)) then + begin + { don't forget the last char } + dec(longint(inputpointer)); + current_module^.current_inputfile^.bufpos:=inputpointer-inputbuffer; + { this isn't a proper way, but ... } + hp:=new(pinputfile,init('','Macro '+pattern,'')); + hp^.next:=current_module^.current_inputfile; + current_module^.current_inputfile:=hp; + status.currentsource:=current_module^.current_inputfile^.name^; + { I don't think that we should do that + because otherwise the file will be searched !! (PM) + but there is the problem of index !! } + current_module^.sourcefiles.register_file(hp); + current_module^.current_index:=hp^.ref_index; + { set an own buffer } + getmem(hp2,mac^.buflen+1); + current_module^.current_inputfile^.setbuf(hp2,mac^.buflen+1); + inputbuffer:=current_module^.current_inputfile^.buf; + { copy text } + move(mac^.buftext^,inputbuffer^,mac^.buflen); + { put end sign } + inputbuffer[mac^.buflen+1]:=#0; + { load c } + c:=inputbuffer^; + inputpointer:=inputbuffer+1; + { handle empty macros } + if c=#0 then + reload; + { play it again ... } + inc(yylexcount); + if yylexcount>16 then + Message(scan_w_macro_deep_ten); {$ifdef TP} - yylex:=yylex; + yylex:=yylex; {$else} - yylex:=yylex(); + yylex:=yylex(); {$endif} - { that's all folks } - dec(yylexcount); - exit; - end; - end; - yylex:=ID; - end; - goto exit_label; - end; + { that's all folks } + dec(yylexcount); + exit; + end; + end; + yylex:=ID; + end; + goto exit_label; + end + else + begin + case c of '$' : begin pattern:=readnumber; yylex:=INTCONST; @@ -944,9 +976,8 @@ unit scanner; if c='^' then begin readchar; - c:=upcase(c); - if not(block_type=bt_type) and (c in ['A'..'Z']) then -{ if not(block_type=bt_type) and (c in [#64..#128]) then} + c:=upcase(c); + if not(block_type=bt_type) and (c in ['A'..'Z']) then begin pattern:=chr(ord(c)-64); readchar; @@ -1056,7 +1087,9 @@ unit scanner; Message(scan_f_illegal_char); end; end; - exit_label: + end; + +exit_label: end; @@ -1069,9 +1102,14 @@ unit scanner; end else readchar; - tokenpos.line:=current_module^.current_inputfile^.line_no; - tokenpos.column:=get_current_col; - tokenpos.fileindex:=current_module^.current_index; + with tokenpos do + begin + + line:=current_module^.current_inputfile^.line_no; + column:=get_current_col; + fileindex:=current_module^.current_index; + end; + case c of '{' : begin skipcomment; @@ -1137,11 +1175,15 @@ unit scanner; procedure get_cur_file_pos(var fileinfo : tfileposinfo); begin - fileinfo.line:=current_module^.current_inputfile^.line_no; + with fileinfo do + begin + line:=current_module^.current_inputfile^.line_no; {fileinfo.fileindex:=current_module^.current_inputfile^.ref_index;} { should allways be the same !! } - fileinfo.fileindex:=current_module^.current_index; - fileinfo.column:=get_current_col; + fileindex:=current_module^.current_index; + column:=get_current_col; + end; + end; procedure set_cur_file_pos(const fileinfo : tfileposinfo); @@ -1214,7 +1256,12 @@ unit scanner; end. { $Log$ - Revision 1.20 1998-05-23 01:21:30 peter + Revision 1.21 1998-05-27 00:20:32 peter + * some scanner optimizes + * automaticly aout2exe for go32v1 + * fixed dynamiclinker option which was added at the wrong place + + Revision 1.20 1998/05/23 01:21:30 peter + aktasmmode, aktoptprocessor, aktoutputformat + smartlink per module $SMARTLINK-/+ (like MMX) and moved to aktswitches + $LIBNAME to set the library name where the unit will be put in diff --git a/compiler/systems.pas b/compiler/systems.pas index 7cd658ea89..e5bdd8d644 100644 --- a/compiler/systems.pas +++ b/compiler/systems.pas @@ -78,6 +78,8 @@ unit systems; tlinkinfo = record linkbin : string[8]; linkcmd : string[50]; + bindbin : string[8]; + bindcmd : string[50]; stripopt : string[2]; libpathprefix : string[12]; libpathsuffix : string[2]; @@ -97,7 +99,8 @@ unit systems; unitext, unitlibext, asmext, - objext : string[4]; + objext, + exeext : string[4]; os : tos; link : tlink; assem : tasm; @@ -129,7 +132,7 @@ implementation staticlibext : '.A'; sourceext : '.PP'; pasext : '.PAS'; - exeext : '.EXE'; + exeext : ''; { No .exe, the linker only output a.out ! } scriptext : '.BAT'; Cprefix : '_'; newline : #13#10; @@ -327,6 +330,8 @@ implementation ( linkbin : 'ld'; linkcmd : '$OPT -o $EXE $RES'; + bindbin : ''; + bindcmd : ''; stripopt : '-s'; libpathprefix : 'SEARCH_DIR('; libpathsuffix : ')'; @@ -340,6 +345,8 @@ implementation ,( linkbin : 'ld'; linkcmd : '-oformat coff-go32 $OPT -o $EXE @$RES'; + bindbin : 'aout2exe'; + bindcmd : '$EXE'; stripopt : '-s'; libpathprefix : '-L'; libpathsuffix : ''; @@ -352,6 +359,8 @@ implementation ,( linkbin : 'ld'; linkcmd : '-oformat coff-go32-exe $OPT -o $EXE @$RES'; + bindbin : ''; + bindcmd : ''; stripopt : '-s'; libpathprefix : '-L'; libpathsuffix : ''; @@ -364,6 +373,8 @@ implementation ,( linkbin : 'ldw'; linkcmd : '$OPT -o $EXE $RES'; + bindbin : ''; + bindcmd : ''; stripopt : '-s'; libpathprefix : 'SEARCH_DIR('; libpathsuffix : ')'; @@ -376,6 +387,8 @@ implementation ,( linkbin : 'ld'; linkcmd : '-o $EXE @$RES'; + bindbin : 'emxbind'; + bindcmd : '-o $EXE.exe $EXE -k$STACKKB -aim -s$HEAPKB'; stripopt : '-s'; libpathprefix : '-L'; libpathsuffix : ''; @@ -402,6 +415,7 @@ implementation unitlibext : '.PPL'; asmext : '.S1'; objext : '.O1'; + exeext : ''; { The linker procedures a.out } os : os_GO32V1; link : link_ldgo32v1; assem : as_o @@ -417,12 +431,14 @@ implementation unitlibext : '.PPL'; asmext : '.S'; objext : '.O'; + exeext : '.EXE'; {$else UseAnsiString} smartext : '.SL'; unitext : '.PAU'; unitlibext : '.PPL'; asmext : '.SA'; objext : '.OA'; + exeext : '.EXE'; {$endif UseAnsiString} os : os_GO32V2; link : link_ldgo32v2; @@ -438,6 +454,7 @@ implementation unitlibext : '.ppl'; asmext : '.s'; objext : '.o'; + exeext : ''; os : os_Linux; link : link_ld; assem : as_o @@ -452,6 +469,7 @@ implementation unitlibext : '.ppl'; asmext : '.so2'; objext : '.oo2'; + exeext : ''; { The linker procedures a.out } os : os_OS2; link : link_ldos2; assem : as_o @@ -466,6 +484,7 @@ implementation unitlibext : '.ppl'; asmext : '.s'; objext : '.o'; + exeext : '.exe'; os : os_Win32; link : link_ldw; assem : as_o @@ -480,6 +499,7 @@ implementation unitlibext : '.ppl'; asmext : '.asm'; objext : '.o'; + exeext : ''; os : os_Amiga; link : link_ld; assem : as_o @@ -494,6 +514,7 @@ implementation unitlibext : '.ppl'; asmext : '.s'; objext : '.o'; + exeext : ''; os : os_Atari; link : link_ld; assem : as_o @@ -508,6 +529,7 @@ implementation unitlibext : '.ppl'; asmext : '.s'; objext : '.o'; + exeext : ''; os : os_Mac68k; link : link_ld; assem : as_o @@ -606,7 +628,12 @@ begin end. { $Log$ - Revision 1.12 1998-05-23 01:21:32 peter + Revision 1.13 1998-05-27 00:20:33 peter + * some scanner optimizes + * automaticly aout2exe for go32v1 + * fixed dynamiclinker option which was added at the wrong place + + Revision 1.12 1998/05/23 01:21:32 peter + aktasmmode, aktoptprocessor, aktoutputformat + smartlink per module $SMARTLINK-/+ (like MMX) and moved to aktswitches + $LIBNAME to set the library name where the unit will be put in