mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-09-13 11:29:20 +02:00
* synchronized with trunk
git-svn-id: branches/z80@45046 -
This commit is contained in:
commit
9c7f1a7cab
@ -36,6 +36,8 @@ Interface
|
|||||||
|
|
||||||
Type
|
Type
|
||||||
TCpuAsmOptimizer = class(TAsmOptimizer)
|
TCpuAsmOptimizer = class(TAsmOptimizer)
|
||||||
|
function CanDoJumpOpts: Boolean; override;
|
||||||
|
|
||||||
{ uses the same constructor as TAopObj }
|
{ uses the same constructor as TAopObj }
|
||||||
function RegLoadedWithNewValue(reg: tregister; hp: tai): boolean;override;
|
function RegLoadedWithNewValue(reg: tregister; hp: tai): boolean;override;
|
||||||
function InstructionLoadsFromReg(const reg: TRegister; const hp: tai): boolean;override;
|
function InstructionLoadsFromReg(const reg: TRegister; const hp: tai): boolean;override;
|
||||||
@ -70,6 +72,12 @@ Implementation
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
function TCpuAsmOptimizer.CanDoJumpOpts: Boolean;
|
||||||
|
begin
|
||||||
|
Result := true;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
function RefsEqual(const r1, r2: treference): boolean;
|
function RefsEqual(const r1, r2: treference): boolean;
|
||||||
begin
|
begin
|
||||||
refsequal :=
|
refsequal :=
|
||||||
|
@ -145,6 +145,7 @@ interface
|
|||||||
|
|
||||||
function TZ80AddNode.first_cmppointer: tnode;
|
function TZ80AddNode.first_cmppointer: tnode;
|
||||||
begin
|
begin
|
||||||
|
Writeln('TZ80AddNode.first_cmppointer');
|
||||||
result:=nil;
|
result:=nil;
|
||||||
expectloc:=LOC_JUMP;
|
expectloc:=LOC_JUMP;
|
||||||
end;
|
end;
|
||||||
|
@ -1162,7 +1162,7 @@ Begin
|
|||||||
{ Finalize units }
|
{ Finalize units }
|
||||||
FinalizeUnits;
|
FinalizeUnits;
|
||||||
|
|
||||||
{$if (defined(MSWINDOWS) and not defined(win16)) or defined(OS2)}
|
{$if defined(OS2)}
|
||||||
{ finally release the heap if possible, especially
|
{ finally release the heap if possible, especially
|
||||||
important for DLLs.
|
important for DLLs.
|
||||||
Reset the array to nil, and finally also argv itself to
|
Reset the array to nil, and finally also argv itself to
|
||||||
|
@ -23,7 +23,12 @@ interface
|
|||||||
|
|
||||||
|
|
||||||
{$ifdef FPC_HAS_FEATURE_COMMANDARGS}
|
{$ifdef FPC_HAS_FEATURE_COMMANDARGS}
|
||||||
|
{$ifdef MSWINDOWS}
|
||||||
|
{$define HAS_PARAMSTRU}
|
||||||
|
{$undef FPC_HAS_FEATURE_COMMANDARGS} // Skip the implementation of ParamStr()
|
||||||
|
{$endif MSWINDOWS}
|
||||||
Function ParamStr(Param: Longint): UnicodeString;
|
Function ParamStr(Param: Longint): UnicodeString;
|
||||||
|
{$ifdef HAS_PARAMSTRU} external name '_FPC_ParamStrU'; {$endif}
|
||||||
{$endif FPC_HAS_FEATURE_COMMANDARGS}
|
{$endif FPC_HAS_FEATURE_COMMANDARGS}
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
@ -144,8 +144,13 @@ Var
|
|||||||
{$endif FPC_HAS_FEATURE_FILEIO}
|
{$endif FPC_HAS_FEATURE_FILEIO}
|
||||||
|
|
||||||
{$ifdef FPC_HAS_FEATURE_COMMANDARGS}
|
{$ifdef FPC_HAS_FEATURE_COMMANDARGS}
|
||||||
|
{$ifdef MSWINDOWS}
|
||||||
|
{$define HAS_PARAMSTRA}
|
||||||
|
{$undef FPC_HAS_FEATURE_COMMANDARGS} // Skip the implementation of ParamStr()
|
||||||
|
{$endif MSWINDOWS}
|
||||||
{ ParamStr should return also an ansistring }
|
{ ParamStr should return also an ansistring }
|
||||||
Function ParamStr(Param : Integer) : Ansistring;
|
Function ParamStr(Param : Integer) : Ansistring;
|
||||||
|
{$ifdef HAS_PARAMSTRA} external name '_FPC_ParamStrA'; {$endif}
|
||||||
{$endif FPC_HAS_FEATURE_COMMANDARGS}
|
{$endif FPC_HAS_FEATURE_COMMANDARGS}
|
||||||
|
|
||||||
{****************************************************************************
|
{****************************************************************************
|
||||||
|
@ -246,15 +246,14 @@ type
|
|||||||
function GetStdHandle(nStdHandle:DWORD):THANDLE;
|
function GetStdHandle(nStdHandle:DWORD):THANDLE;
|
||||||
stdcall;external KernelDLL name 'GetStdHandle';
|
stdcall;external KernelDLL name 'GetStdHandle';
|
||||||
|
|
||||||
{$ifdef FPC_UNICODE_RTLx}
|
|
||||||
{ command line/environment functions }
|
{ command line/environment functions }
|
||||||
|
|
||||||
function GetCommandLine : pwidechar;
|
function GetCommandLineW : pwidechar;
|
||||||
stdcall;external KernelDLL name 'GetCommandLineW';
|
stdcall;external KernelDLL name 'GetCommandLineW';
|
||||||
{$else}
|
function GetCommandLineA : pansichar;
|
||||||
function GetCommandLine : pchar;
|
|
||||||
stdcall;external KernelDLL name 'GetCommandLineA';
|
stdcall;external KernelDLL name 'GetCommandLineA';
|
||||||
{$endif}
|
function CommandLineToArgvW(lpCmdLine: PWideChar; out pNumArgs: longint): PPWideChar;
|
||||||
|
stdcall; external 'shell32.dll' name 'CommandLineToArgvW';
|
||||||
|
|
||||||
function GetCurrentProcessId:DWORD;
|
function GetCurrentProcessId:DWORD;
|
||||||
stdcall; external KernelDLL name 'GetCurrentProcessId';
|
stdcall; external KernelDLL name 'GetCurrentProcessId';
|
||||||
@ -269,8 +268,8 @@ type
|
|||||||
stdcall;external 'kernel32' name 'ReadProcessMemory';
|
stdcall;external 'kernel32' name 'ReadProcessMemory';
|
||||||
|
|
||||||
{ module functions }
|
{ module functions }
|
||||||
function GetModuleFileName(l1:THandle;p:PChar;l2:longint):longint;
|
function GetModuleFileNameW(l1:THandle;p:PWideChar;l2:longint):longint;
|
||||||
stdcall;external KernelDLL name 'GetModuleFileNameA';
|
stdcall;external KernelDLL name 'GetModuleFileNameW';
|
||||||
|
|
||||||
function GetModuleHandle(p : PChar) : THandle;
|
function GetModuleHandle(p : PChar) : THandle;
|
||||||
stdcall;external KernelDLL name 'GetModuleHandleA';
|
stdcall;external KernelDLL name 'GetModuleHandleA';
|
||||||
@ -359,6 +358,8 @@ type
|
|||||||
stdcall; external 'oleaut32.dll' name 'SysFreeString';
|
stdcall; external 'oleaut32.dll' name 'SysFreeString';
|
||||||
function SysReAllocStringLen(var bstr:pointer;psz: pointer;
|
function SysReAllocStringLen(var bstr:pointer;psz: pointer;
|
||||||
len:dword): Integer; stdcall;external 'oleaut32.dll' name 'SysReAllocStringLen';
|
len:dword): Integer; stdcall;external 'oleaut32.dll' name 'SysReAllocStringLen';
|
||||||
|
function GlobalFree(hMem: pointer): pointer;
|
||||||
|
stdcall; external KernelDLL name 'GlobalFree';
|
||||||
{$endif WINCE}
|
{$endif WINCE}
|
||||||
|
|
||||||
Procedure Errno2InOutRes(oserror: longword);
|
Procedure Errno2InOutRes(oserror: longword);
|
||||||
|
@ -217,155 +217,87 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{*****************************************************************************
|
{*****************************************************************************
|
||||||
Parameter Handling
|
Parameter Handling
|
||||||
*****************************************************************************}
|
*****************************************************************************}
|
||||||
|
|
||||||
procedure setup_arguments;
|
var
|
||||||
var
|
argvw: PPWideChar;
|
||||||
arglen,
|
|
||||||
count : longint;
|
|
||||||
argstart,
|
|
||||||
pc,arg : pchar;
|
|
||||||
quote : Boolean;
|
|
||||||
argvlen : longint;
|
|
||||||
buf: array[0..259] of char; // need MAX_PATH bytes, not 256!
|
|
||||||
|
|
||||||
procedure allocarg(idx,len:longint);
|
procedure setup_arguments;
|
||||||
var
|
var
|
||||||
oldargvlen : longint;
|
buf: array[0..MaxPathLen] of WideChar;
|
||||||
begin
|
i, len: longint;
|
||||||
if idx>=argvlen then
|
s: ansistring;
|
||||||
begin
|
begin
|
||||||
oldargvlen:=argvlen;
|
// Get argvw
|
||||||
argvlen:=(idx+8) and (not 7);
|
argvw:=CommandLineToArgvW(GetCommandLineW, argc);
|
||||||
sysreallocmem(argv,argvlen*sizeof(pointer));
|
// Get the full module name for argvw[0]
|
||||||
fillchar(argv[oldargvlen],(argvlen-oldargvlen)*sizeof(pointer),0);
|
len:=(GetModuleFileNameW(0, @buf, Length(buf)) + 1)*SizeOf(WideChar);
|
||||||
end;
|
argvw[0]:=SysGetMem(len);
|
||||||
{ use realloc to reuse already existing memory }
|
Move(buf, argvw[0]^, len);
|
||||||
{ always allocate, even if length is zero, since }
|
// Construct the ansi argv
|
||||||
{ the arg. is still present! }
|
argv:=SysGetMem((argc + 1)*SizeOf(pointer));
|
||||||
sysreallocmem(argv[idx],len+1);
|
for i:=0 to argc - 1 do
|
||||||
end;
|
begin
|
||||||
|
// Convert argvw[i] to argv[i]
|
||||||
|
s:=ansistring(argvw[i]);
|
||||||
|
len:=Length(s) + 1;
|
||||||
|
argv[i]:=SysGetMem(len);
|
||||||
|
Move(s[1], argv[i]^, len);
|
||||||
|
end;
|
||||||
|
// argv is terminated by nil
|
||||||
|
argv[argc]:=nil;
|
||||||
|
// Get the ansi CmdLine
|
||||||
|
CmdLine:=GetCommandLineA;
|
||||||
|
end;
|
||||||
|
|
||||||
begin
|
procedure finalize_arguments;
|
||||||
{ create commandline, it starts with the executed filename which is argv[0] }
|
var
|
||||||
{ Win32 passes the command NOT via the args, but via getmodulefilename}
|
i: longint;
|
||||||
count:=0;
|
begin
|
||||||
argv:=nil;
|
// Free the module name
|
||||||
argvlen:=0;
|
SysFreeMem(argvw[0]);
|
||||||
ArgLen := GetModuleFileName(0, @buf[0], sizeof(buf));
|
// Use GlobalFree to free the buffer returned by CommandLineToArgvW
|
||||||
buf[ArgLen] := #0; // be safe
|
GlobalFree(argvw);
|
||||||
allocarg(0,arglen);
|
// Free argv
|
||||||
move(buf,argv[0]^,arglen+1);
|
for i:=0 to argc - 1 do
|
||||||
{ Setup cmdline variable }
|
SysFreeMem(argv[i]);
|
||||||
cmdline:=GetCommandLine;
|
SysFreeMem(argv);
|
||||||
{ process arguments }
|
end;
|
||||||
pc:=cmdline;
|
|
||||||
{$IfDef SYSTEM_DEBUG_STARTUP}
|
|
||||||
Writeln(stderr,'Win32 GetCommandLine is #',pc,'#');
|
|
||||||
{$EndIf }
|
|
||||||
while pc^<>#0 do
|
|
||||||
begin
|
|
||||||
{ skip leading spaces }
|
|
||||||
while pc^ in [#1..#32] do
|
|
||||||
inc(pc);
|
|
||||||
if pc^=#0 then
|
|
||||||
break;
|
|
||||||
{ calc argument length }
|
|
||||||
quote:=False;
|
|
||||||
argstart:=pc;
|
|
||||||
arglen:=0;
|
|
||||||
while (pc^<>#0) do
|
|
||||||
begin
|
|
||||||
case pc^ of
|
|
||||||
#1..#32 :
|
|
||||||
begin
|
|
||||||
if quote then
|
|
||||||
inc(arglen)
|
|
||||||
else
|
|
||||||
break;
|
|
||||||
end;
|
|
||||||
'"' :
|
|
||||||
if pc[1]<>'"' then
|
|
||||||
quote := not quote
|
|
||||||
else
|
|
||||||
inc(pc);
|
|
||||||
else
|
|
||||||
inc(arglen);
|
|
||||||
end;
|
|
||||||
inc(pc);
|
|
||||||
end;
|
|
||||||
{ copy argument }
|
|
||||||
{ Don't copy the first one, it is already there.}
|
|
||||||
If Count<>0 then
|
|
||||||
begin
|
|
||||||
allocarg(count,arglen);
|
|
||||||
quote:=False;
|
|
||||||
pc:=argstart;
|
|
||||||
arg:=argv[count];
|
|
||||||
while (pc^<>#0) do
|
|
||||||
begin
|
|
||||||
case pc^ of
|
|
||||||
#1..#32 :
|
|
||||||
begin
|
|
||||||
if quote then
|
|
||||||
begin
|
|
||||||
arg^:=pc^;
|
|
||||||
inc(arg);
|
|
||||||
end
|
|
||||||
else
|
|
||||||
break;
|
|
||||||
end;
|
|
||||||
'"' :
|
|
||||||
if pc[1]<>'"' then
|
|
||||||
quote := not quote
|
|
||||||
else
|
|
||||||
inc(pc);
|
|
||||||
else
|
|
||||||
begin
|
|
||||||
arg^:=pc^;
|
|
||||||
inc(arg);
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
inc(pc);
|
|
||||||
end;
|
|
||||||
arg^:=#0;
|
|
||||||
end;
|
|
||||||
{$IfDef SYSTEM_DEBUG_STARTUP}
|
|
||||||
Writeln(stderr,'dos arg ',count,' #',arglen,'#',argv[count],'#');
|
|
||||||
{$EndIf SYSTEM_DEBUG_STARTUP}
|
|
||||||
inc(count);
|
|
||||||
end;
|
|
||||||
{ get argc }
|
|
||||||
argc:=count;
|
|
||||||
{ free unused memory, leaving a nil entry at the end }
|
|
||||||
sysreallocmem(argv,(count+1)*sizeof(pointer));
|
|
||||||
argv[count] := nil;
|
|
||||||
end;
|
|
||||||
|
|
||||||
|
function paramcount : longint;
|
||||||
|
begin
|
||||||
|
paramcount := argc - 1;
|
||||||
|
end;
|
||||||
|
|
||||||
function paramcount : longint;
|
Function ParamStrU(l:Longint): UnicodeString; [public,alias:'_FPC_ParamStrU'];
|
||||||
begin
|
begin
|
||||||
paramcount := argc - 1;
|
if (l >= 0) and (l < argc) then
|
||||||
end;
|
Result:=argvw[l]
|
||||||
|
else
|
||||||
|
Result:='';
|
||||||
|
end;
|
||||||
|
|
||||||
function paramstr(l : longint) : string;
|
Function ParamStrA(l:Longint): AnsiString; [public,alias:'_FPC_ParamStrA'];
|
||||||
begin
|
begin
|
||||||
if (l>=0) and (l<argc) then
|
Result:=AnsiString(ParamStrU(l));
|
||||||
paramstr:=strpas(argv[l])
|
end;
|
||||||
else
|
|
||||||
paramstr:='';
|
|
||||||
end;
|
|
||||||
|
|
||||||
|
|
||||||
procedure randomize;
|
|
||||||
begin
|
|
||||||
randseed:=GetTickCount;
|
|
||||||
end;
|
|
||||||
|
|
||||||
|
Function ParamStr(l:Longint): string;
|
||||||
|
begin
|
||||||
|
if (l >= 0) and (l < argc) then
|
||||||
|
Result:=argv[l]
|
||||||
|
else
|
||||||
|
Result:='';
|
||||||
|
end;
|
||||||
|
|
||||||
|
{*****************************************************************************}
|
||||||
|
|
||||||
|
procedure randomize;
|
||||||
|
begin
|
||||||
|
randseed:=GetTickCount;
|
||||||
|
end;
|
||||||
|
|
||||||
Var
|
Var
|
||||||
DLLInitState : Longint = -1;
|
DLLInitState : Longint = -1;
|
||||||
@ -781,3 +713,9 @@ begin
|
|||||||
SysSetCtrlBreakHandler := CtrlBreakHandler;
|
SysSetCtrlBreakHandler := CtrlBreakHandler;
|
||||||
CtrlBreakHandler := Handler;
|
CtrlBreakHandler := Handler;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure WinFinalizeSystem;
|
||||||
|
begin
|
||||||
|
finalize_arguments;
|
||||||
|
end;
|
||||||
|
|
||||||
|
@ -51,6 +51,7 @@ const
|
|||||||
|
|
||||||
var
|
var
|
||||||
{ C compatible arguments }
|
{ C compatible arguments }
|
||||||
|
{ CmdLine and argv are always in the current ANSI encoding set in Windows }
|
||||||
argc : longint;
|
argc : longint;
|
||||||
argv : ppchar;
|
argv : ppchar;
|
||||||
{ Win32 Info }
|
{ Win32 Info }
|
||||||
|
@ -601,7 +601,7 @@ function CheckInitialStkLen(stklen : SizeUInt) : SizeUInt;
|
|||||||
result:=tpeheader((pointer(getmodulehandle(nil))+(tdosheader(pointer(getmodulehandle(nil))^).e_lfanew))^).SizeOfStackReserve;
|
result:=tpeheader((pointer(getmodulehandle(nil))+(tdosheader(pointer(getmodulehandle(nil))^).e_lfanew))^).SizeOfStackReserve;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
begin
|
initialization
|
||||||
{ get some helpful informations }
|
{ get some helpful informations }
|
||||||
GetStartupInfo(@startupinfo);
|
GetStartupInfo(@startupinfo);
|
||||||
{ some misc Win32 stuff }
|
{ some misc Win32 stuff }
|
||||||
@ -634,4 +634,8 @@ begin
|
|||||||
InOutRes:=0;
|
InOutRes:=0;
|
||||||
ProcessID := GetCurrentProcessID;
|
ProcessID := GetCurrentProcessID;
|
||||||
DispCallByIDProc:=@DoDispCallByIDError;
|
DispCallByIDProc:=@DoDispCallByIDError;
|
||||||
|
|
||||||
|
finalization
|
||||||
|
WinFinalizeSystem;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
@ -615,7 +615,7 @@ function CheckInitialStkLen(stklen : SizeUInt) : SizeUInt;
|
|||||||
result:=tpeheader((pointer(getmodulehandle(nil))+(tdosheader(pointer(getmodulehandle(nil))^).e_lfanew))^).SizeOfStackReserve;
|
result:=tpeheader((pointer(getmodulehandle(nil))+(tdosheader(pointer(getmodulehandle(nil))^).e_lfanew))^).SizeOfStackReserve;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
begin
|
initialization
|
||||||
{ pass dummy value }
|
{ pass dummy value }
|
||||||
StackLength := CheckInitialStkLen($1000000);
|
StackLength := CheckInitialStkLen($1000000);
|
||||||
StackBottom := StackTop - StackLength;
|
StackBottom := StackTop - StackLength;
|
||||||
@ -643,4 +643,8 @@ begin
|
|||||||
InOutRes:=0;
|
InOutRes:=0;
|
||||||
ProcessID := GetCurrentProcessID;
|
ProcessID := GetCurrentProcessID;
|
||||||
DispCallByIDProc:=@DoDispCallByIDError;
|
DispCallByIDProc:=@DoDispCallByIDError;
|
||||||
|
|
||||||
|
finalization
|
||||||
|
WinFinalizeSystem;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
Loading…
Reference in New Issue
Block a user