Check that all referenced labels exist in the assembler
This commit is contained in:
parent
087c88d8ce
commit
81ae2e72c4
|
@ -9,7 +9,9 @@ type
|
||||||
LblRec = record
|
LblRec = record
|
||||||
Addr: word;
|
Addr: word;
|
||||||
Lbl: ansistring;
|
Lbl: ansistring;
|
||||||
|
Line: integer;
|
||||||
Offset: integer;
|
Offset: integer;
|
||||||
|
Resolved: boolean;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
var
|
var
|
||||||
|
@ -17,6 +19,7 @@ var
|
||||||
Line, DatOrg: ansistring; //Line of assembly and data or org element
|
Line, DatOrg: ansistring; //Line of assembly and data or org element
|
||||||
Elem: array [0 .. 4] of ansistring; //Parsed elements
|
Elem: array [0 .. 4] of ansistring; //Parsed elements
|
||||||
Lbl, Ref: array [0 .. $ffff] of LblRec; //Label and reference tables
|
Lbl, Ref: array [0 .. $ffff] of LblRec; //Label and reference tables
|
||||||
|
AllRefsResolved: boolean; //Whether there are any references to nonexistent labels
|
||||||
Addr, BP, SP, EP: word; //Address argument and byte, start, and end pointers
|
Addr, BP, SP, EP: word; //Address argument and byte, start, and end pointers
|
||||||
Bin: array [0 .. $ffef] of byte; //Assembled binary
|
Bin: array [0 .. $ffef] of byte; //Assembled binary
|
||||||
Prog: file of byte; //Program file
|
Prog: file of byte; //Program file
|
||||||
|
@ -136,7 +139,9 @@ begin
|
||||||
//Store the reference in the table
|
//Store the reference in the table
|
||||||
Ref [Count] .Addr := BP + A;
|
Ref [Count] .Addr := BP + A;
|
||||||
Ref [Count] .Lbl := Elem [I];
|
Ref [Count] .Lbl := Elem [I];
|
||||||
|
Ref [Count] .Line := LP;
|
||||||
Ref [Count] .Offset := Offset;
|
Ref [Count] .Offset := Offset;
|
||||||
|
Ref [Count] .Resolved := false;
|
||||||
//Placeholder
|
//Placeholder
|
||||||
Addr := 0;
|
Addr := 0;
|
||||||
Offset := 0;
|
Offset := 0;
|
||||||
|
@ -222,6 +227,7 @@ begin
|
||||||
if BP + Ref [Count] .Offset <= $ffff then begin
|
if BP + Ref [Count] .Offset <= $ffff then begin
|
||||||
Bin [Ref [Count] .Addr] := (BP + Ref [Count] .Offset) shr 8;
|
Bin [Ref [Count] .Addr] := (BP + Ref [Count] .Offset) shr 8;
|
||||||
Bin [Ref [Count] .Addr + 1] := (BP + Ref [Count] .Offset) and $00ff;
|
Bin [Ref [Count] .Addr + 1] := (BP + Ref [Count] .Offset) and $00ff;
|
||||||
|
Ref [Count] .Resolved := true;
|
||||||
end
|
end
|
||||||
else RefError;
|
else RefError;
|
||||||
end
|
end
|
||||||
|
@ -373,6 +379,18 @@ begin
|
||||||
|
|
||||||
until eof ();
|
until eof ();
|
||||||
|
|
||||||
|
//Check that all references to labels were properly resolved
|
||||||
|
AllRefsResolved := true;
|
||||||
|
Count := 0;
|
||||||
|
while Ref [Count] .Lbl <> '' do begin
|
||||||
|
if Ref [Count] .Resolved = false then begin
|
||||||
|
writeln ('Error (line ', Ref [Count] .Line, '): label not found: ', Ref [Count] .Lbl);
|
||||||
|
AllRefsResolved := false;
|
||||||
|
end;
|
||||||
|
Count := Count + 1;
|
||||||
|
end;
|
||||||
|
if AllRefsResolved = false then halt;
|
||||||
|
|
||||||
//Set the end pointer and reset the byte pointer to the start of the program
|
//Set the end pointer and reset the byte pointer to the start of the program
|
||||||
EP := BP;
|
EP := BP;
|
||||||
BP := SP;
|
BP := SP;
|
||||||
|
|
Loading…
Reference in New Issue