- Timestamp:
- Sep 30, 2016, 10:47:25 PM (8 years ago)
- Location:
- branches/virt simple
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/virt simple/UCompiler.pas
r89 r90 13 13 TCompiler = class 14 14 private 15 Labels: TStringList; 15 16 function GetPart(var Text: string; Separator: string): string; 16 17 procedure ParseLine(Line: string; Instructions: TInstructions); … … 52 53 Value2: Integer; 53 54 OutValue: Integer; 55 LineLabel: string; 56 I: Integer; 54 57 begin 55 58 Line := Trim(Line); … … 57 60 if Pos(';', Line) > 0 then begin 58 61 Line := Trim(Copy(Line, 1, Pos(';', Line) - 1)); 62 end; 63 if Pos(':', Line) > 0 then begin 64 LineLabel := Trim(GetPart(Line, ':')); 65 if Labels.IndexOf(LineLabel) <> -1 then raise Exception.Create('Label ' + LineLabel + ' already defined'); 66 Labels.AddObject(LineLabel, TObject(Instructions.Count)); 59 67 end; 60 68 if Line = '' then Exit; … … 84 92 if TryStrToInt(Param1, OutValue) then begin 85 93 Value1 := OutValue; 86 end else raise Exception.Create('Unsupported parameter value ' + Param1); 94 end else begin 95 I := Labels.IndexOf(Param1); 96 if I <> -1 then Value1 := Integer(Labels.Objects[I]) 97 else raise Exception.Create('Unsupported parameter value ' + Param1); 98 end; 87 99 end; 88 100 end else ParamType1 := ptNone; … … 109 121 if TryStrToInt(Param2, OutValue) then begin 110 122 Value2 := OutValue; 111 end else raise Exception.Create('Unsupported parameter value ' + Param2); 123 end else begin 124 I := Labels.IndexOf(Param2); 125 if I <> -1 then Value2 := Integer(Labels.Objects[I]) 126 else raise Exception.Create('Unsupported parameter value ' + Param2); 127 end; 112 128 end; 113 129 end else ParamType2 := ptNone; … … 132 148 I: Integer; 133 149 begin 150 Labels.Clear; 134 151 Instructions.Clear; 135 152 for I := 0 to Lines.Count - 1 do begin … … 141 158 begin 142 159 Lines := TStringList.Create; 160 Labels := TStringList.Create; 143 161 end; 144 162 145 163 destructor TCompiler.Destroy; 146 164 begin 165 FreeAndNil(Labels); 147 166 FreeAndNil(Lines); 148 167 inherited Destroy; -
branches/virt simple/example.vasm
r89 r90 1 Start: 1 2 NOP 2 3 INC R0 … … 10 11 LD R0, 1000 11 12 SYS 2 ; Delay 1 second 12 JP 013 JP Start 13 14 LD [R4], [R3] 14 15 HALT
Note:
See TracChangeset
for help on using the changeset viewer.