Move error reporting and line buffer to parse.pas
end;
DataDefType = (DataDB, DataDW, DataDD);
-var
- currentLine: Integer;
- linebuf: string;
-
procedure PartsClear(var pts: Parts);
begin
pts.Kind := partsNone;
end;
end;
-procedure ErrorAtLine(msg: string);
-begin
- Writeln();
- Writeln('ERR: ', msg,' on line ', currentLine, ':');
- Writeln(linebuf);
-end;
-
-procedure WarnAtLine(msg: string);
-begin
- Writeln();
- Writeln('WARN: ', msg,' on line ', currentLine, ':');
- Writeln(linebuf);
-end;
-
constructor CompileBuffer.Init;
begin
New(data);
AddPublic(pts.args);
end
else if pts.mnemonic = 'EXTRN' then begin
- Writeln('EXTRN not yet implemented');
+ ErrorAtLine('EXTRN not yet implemented');
Halt(1);
end
else if pts.mnemonic = 'END' then begin
function MnemonicStr(const m: Mnemonic): string;
function ShortOperandStr(const ot: OperandType): string;
+procedure ErrorAtLine(msg: string);
+procedure WarnAtLine(msg: string);
procedure DieBadOperand(const a: String);
+var currentLine: Integer;
+ linebuf: string;
+
implementation
uses Compiler;
for i := 1 to Length(s) do begin
if (s[i] = 'h') OR (s[i] = 'H') then begin
if i < Length(s) then begin
- Writeln('Trailing garbage in hex literal: ', s);
+ ErrorAtLine('Trailing garbage in hex literal: ' + s);
Halt(1);
end;
hex := True;
end
else if NOT (IsHexadecimal(s[i]) OR (s[i] = '-') OR (s[i] = '.')) then begin
- Writeln('Invalid literal: ', s);
+ ErrorAtLine('Invalid literal: ' + s);
Halt(1);
end;
end;
ss := Copy(s, 1, i);
Val(ss, j, i);
if i <> 0 then begin
- Writeln('Invalid literal: ', s);
+ ErrorAtLine('Invalid literal: ' + s);
Halt(1);
end;
ParseIntLiteral := Word(j);
if FindSymbol(currentObj^.symbols, w, j) then
o.immed := j
else begin
- Writeln('Unknown symbol: ', a);
+ ErrorAtLine('Unknown symbol: ' + a);
{ DumpSymbols(currentObj^.symbols); }
Halt(1);
end;
{ First try an identifier }
l := ToUpCase(ConsumeIdentifier(a, i));
if i < Length(a) + 1 then begin
- Writeln('Malformed location? `', a, '`');
+ ErrorAtLine('Malformed location? `' + a + '`');
Halt(1);
end;
if FindSymbol(currentObj^.symbols, l, o.loc) then begin
ShortOperandStr := ShortOperands[ot];
end;
+procedure ErrorAtLine(msg: string);
+begin
+ Writeln();
+ Writeln('ERR: ', msg,' on line ', currentLine, ':');
+ Writeln(linebuf);
+end;
+
+procedure WarnAtLine(msg: string);
+begin
+ Writeln();
+ Writeln('WARN: ', msg,' on line ', currentLine, ':');
+ Writeln(linebuf);
+end;
+
procedure DieBadOperand(const a: String);
begin
- Writeln('Invalid operand: ', a);
+ ErrorAtLine('Invalid operand: ' + a);
{
Write(' possible operands: ');
for i := Low(OperandType) to High(OperandType) do
implementation
-uses Util;
+uses Parse, Util;
function GetTableEnd(const table: SymbolTable): PSymbolEntry;
var p: PSymbolEntry;
new_entry: PSymbolEntry;
begin
if FindSymbolTableEntry(table, n) <> nil then begin
- Writeln('Symbol ''', n, ''' already defined');
+ ErrorAtLine('Symbol ''' + n + ''' already defined');
Halt(1);
end;
if table.head = nil then begin