use precompiled standard library (not really a linker)
This commit is contained in:
parent
5ce5bc44b8
commit
91cb059f38
8 changed files with 105 additions and 22 deletions
|
|
@ -86,6 +86,12 @@ begin
|
|||
countIns(1);
|
||||
end;
|
||||
|
||||
procedure emitInclude(s:string);
|
||||
begin
|
||||
writeln(outfile, '%include "',s,'"');
|
||||
emitIns('.CPOOL');
|
||||
end;
|
||||
|
||||
procedure emitPrologue;
|
||||
begin
|
||||
writeln(outfile, #9, '.ORG ', startAddress);
|
||||
|
|
@ -95,12 +101,21 @@ begin
|
|||
emitIns2Int('.WORD', defaultHeapSize);
|
||||
emitLabelRaw('_STACK_SZ_PTR');
|
||||
emitIns2Int('.WORD', defaultStackSize);
|
||||
emitIns2Int('.WORD', 0);
|
||||
emitLabelRaw('_MAIN_PTR');
|
||||
emitIns2('.WORD', '_MAIN');
|
||||
emitIns2('LOADCP','_END'); (* end of program is start of heap *)
|
||||
emitIns2('LOADCP', '_MEM_INIT'); (* MEM_INIT initializes heap and sets FP/RP *)
|
||||
(* since RP is not initialized yet, we cannot use CALL
|
||||
and MEM_INIT jumps to _MAIN after it is done *)
|
||||
emitIns('JUMP');
|
||||
emitIns2('BRANCH','@+2'); (* NOP, to make alignment explicit *)
|
||||
emitIns('.CPOOL'); (* header/prologue + 2 constants is 32 bytes *)
|
||||
|
||||
if useStdlib then
|
||||
begin
|
||||
writeln(outfile, '%include "stdlib.lsym"');
|
||||
writeln(outfile, '%incbin "stdlib.lib"');
|
||||
end;
|
||||
end;
|
||||
|
||||
function bytes2words(size:integer):integer;
|
||||
|
|
@ -274,12 +289,6 @@ begin
|
|||
end;
|
||||
end;
|
||||
|
||||
procedure emitInclude(s:string);
|
||||
begin
|
||||
writeln(outfile, '%include "',s,'"');
|
||||
emitIns('.CPOOL');
|
||||
end;
|
||||
|
||||
procedure emitUnitEpilogue;
|
||||
begin
|
||||
emitIns('.CPOOL');
|
||||
|
|
@ -307,10 +316,6 @@ begin
|
|||
else
|
||||
emitInclude('coreloader.lsym');
|
||||
|
||||
emitInclude('float32.lib');
|
||||
emitInclude('runtime.lib');
|
||||
emitInclude('stdlib.lib');
|
||||
|
||||
rewindStringList(usedUnits);
|
||||
while nextStringListItem(usedUnits, unitName) do
|
||||
emitInclude(unitName + UnitSuffix2);
|
||||
|
|
|
|||
|
|
@ -9,7 +9,8 @@ var
|
|||
outfile:TextFile;
|
||||
infile:TextFile;
|
||||
lineno:integer;
|
||||
|
||||
infilePath,outfilePath:string;
|
||||
|
||||
procedure errorExit2(reason:string;arg:string); forward;
|
||||
|
||||
{$I 'platfile+.pas'}
|
||||
|
|
@ -78,6 +79,17 @@ begin
|
|||
clean := (not strcontains( name, '_')) and (name[1] <> '=');
|
||||
end;
|
||||
|
||||
procedure removeLeadingZeroes(var s:string);
|
||||
begin
|
||||
while length(s) > 1 do
|
||||
begin
|
||||
if s[1] = '0' then
|
||||
delete(s,1,1)
|
||||
else
|
||||
break;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure processFile(inpath,outpath:string);
|
||||
var line:string;
|
||||
addr,name:string;
|
||||
|
|
@ -94,6 +106,8 @@ begin
|
|||
begin
|
||||
readln(infile, line);
|
||||
splitLine(line, addr, name, clean);
|
||||
removeLeadingZeroes(addr);
|
||||
|
||||
if clean then
|
||||
writeln(outfile, #9, '.EQU ', name, ' $', addr);
|
||||
end;
|
||||
|
|
@ -104,7 +118,13 @@ end;
|
|||
begin
|
||||
if ParamCount > 0 then
|
||||
begin
|
||||
processFile(ParamStr(1), getOutfileName(ParamStr(1)));
|
||||
infilePath := ParamStr(1);
|
||||
outfilePath := getOutfileName(infilePath);
|
||||
|
||||
if ParamCount > 1 then
|
||||
outfilePath := ParamStr(2);
|
||||
|
||||
processFile(infilePath, outfilePath);
|
||||
end
|
||||
else
|
||||
writeln('No file name given.');
|
||||
|
|
|
|||
|
|
@ -9,9 +9,10 @@ fpc -gl lsymgen.pas
|
|||
sasm ..\lib\coreloader.s
|
||||
lsymgen ..\lib\coreloader.sym
|
||||
py pcomp.py -n ..\lib\stdlib.pas
|
||||
libgen ..\lib\stdlib.s
|
||||
libgen ..\lib\runtime.s
|
||||
libgen ..\lib\float32.s
|
||||
sasm ..\lib\stdlibwrap.s ..\lib\stdlib.lib
|
||||
lsymgen ..\lib\stdlibwrap.sym ..\lib\stdlib.lsym
|
||||
|
||||
rem exit /b
|
||||
|
||||
py pcomp.py sasm.pas
|
||||
py pcomp.py pcomp.pas
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue