Changeset 138 for branches/virt simple/UMachine.pas
- Timestamp:
- Jan 4, 2018, 2:00:49 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/virt simple/UMachine.pas
r89 r138 24 24 TParamType = (ptNone, ptConst, ptRegister, ptSpecialRegister); 25 25 TCondition = (cdZero, cdNotZero, cdNegative, cdPositive); 26 TMemoryType = (mtNone, mtData); 26 27 27 28 TValue = Integer; … … 33 34 TParam = class 34 35 ParamType: TParamType; 35 Memory : Boolean;36 MemoryType: TMemoryType; 36 37 Value: TValue; 37 38 function GetString: string; 39 procedure SetParam(ParamType: TParamType; MemoryType: TMemoryType; Value: TValue); 38 40 end; 39 41 … … 51 53 procedure AddInst(Opcode: TOpcode); overload; 52 54 procedure AddInst(Opcode: TOpcode; 53 ParamType1: TParamType; Indirect1: Boolean; Value1: TValue); overload;55 ParamType1: TParamType; Indirect1: TMemoryType; Value1: TValue); overload; 54 56 procedure AddInst(Opcode: TOpcode; 55 ParamType1: TParamType; Indirect1: Boolean; Value1: TValue;56 ParamType2: TParamType; Indirect2: Boolean; Value2: TValue); overload;57 ParamType1: TParamType; Indirect1: TMemoryType; Value1: TValue; 58 ParamType2: TParamType; Indirect2: TMemoryType; Value2: TValue); overload; 57 59 end; 58 60 … … 146 148 else Result := 'S' + IntToStr(Value); 147 149 end; 148 if Memory then Result := '[' + Result + ']'; 150 if MemoryType = mtData then Result := '[' + Result + ']'; 151 end; 152 153 procedure TParam.SetParam(ParamType: TParamType; MemoryType: TMemoryType; 154 Value: TValue); 155 begin 156 Self.ParamType := ParamType; 157 Self.MemoryType := MemoryType; 158 Self.Value := Value; 149 159 end; 150 160 … … 183 193 NewInst := TInstruction.Create; 184 194 NewInst.Opcode := Opcode; 185 NewInst.Params[0].ParamType := ptNone; 186 NewInst.Params[0].Memory := False; 187 NewInst.Params[0].Value := 0; 188 NewInst.Params[1].ParamType := ptNone; 189 NewInst.Params[1].Memory := False; 190 NewInst.Params[1].Value := 0; 195 NewInst.Params[0].SetParam(ptNone, mtNone, 0); 196 NewInst.Params[1].SetParam(ptNone, mtNone, 0); 191 197 Add(NewInst); 192 198 end; 193 199 194 200 procedure TInstructions.AddInst(Opcode: TOpcode; ParamType1: TParamType; 195 Indirect1: Boolean; Value1: TValue);201 Indirect1: TMemoryType; Value1: TValue); 196 202 var 197 203 NewInst: TInstruction; … … 199 205 NewInst := TInstruction.Create; 200 206 NewInst.Opcode := Opcode; 201 NewInst.Params[0].ParamType := ParamType1; 202 NewInst.Params[0].Memory := Indirect1; 203 NewInst.Params[0].Value := Value1; 204 NewInst.Params[1].ParamType := ptNone; 205 NewInst.Params[1].Memory := False; 206 NewInst.Params[1].Value := 0; 207 NewInst.Params[0].SetParam(ParamType1, Indirect1, Value1); 208 NewInst.Params[1].SetParam(ptNone, mtNone, 0); 207 209 Add(NewInst); 208 210 end; 209 211 210 212 procedure TInstructions.AddInst(Opcode: TOpcode; 211 ParamType1: TParamType; Indirect1: Boolean; Value1: TValue;212 ParamType2: TParamType; Indirect2: Boolean; Value2: TValue);213 ParamType1: TParamType; Indirect1: TMemoryType; Value1: TValue; 214 ParamType2: TParamType; Indirect2: TMemoryType; Value2: TValue); 213 215 var 214 216 NewInst: TInstruction; … … 216 218 NewInst := TInstruction.Create; 217 219 NewInst.Opcode := Opcode; 218 NewInst.Params[0].ParamType := ParamType1; 219 NewInst.Params[0].Memory := Indirect1; 220 NewInst.Params[0].Value := Value1; 221 NewInst.Params[1].ParamType := ParamType2; 222 NewInst.Params[1].Memory := Indirect2; 223 NewInst.Params[1].Value := Value2; 220 NewInst.Params[0].SetParam(ParamType1, Indirect1, Value1); 221 NewInst.Params[1].SetParam(ParamType2, Indirect2, Value2); 224 222 Add(NewInst); 225 223 end; … … 469 467 end else if Param.ParamType = ptNone then raise Exception.Create('Read from not set parameter') 470 468 else raise Exception.Create('Unsupported parameter type ' + IntToStr(Integer(Param.ParamType))); 471 if Param.Memory then Result := Memory[Result];469 if Param.MemoryType = mtData then Result := Memory[Result]; 472 470 end; 473 471 … … 475 473 begin 476 474 if Param.ParamType = ptRegister then begin 477 if Param.Memory then Memory[Registers[Param.Value]] := Value475 if Param.MemoryType = mtData then Memory[Registers[Param.Value]] := Value 478 476 else Registers[Param.Value] := Value; 479 end else if Param.ParamType = ptConst then begin 480 if Param.Memory then Memory[Param.Value] := Value 477 end else 478 if Param.ParamType = ptConst then begin 479 if Param.MemoryType = mtData then Memory[Param.Value] := Value 481 480 else raise Exception.Create('Cannot assign to constant parameter'); 482 end else if Param.ParamType = ptSpecialRegister then begin 481 end else 482 if Param.ParamType = ptSpecialRegister then begin 483 483 if Param.Value = Integer(srIP) then begin 484 if Param.Memory then Memory[IP] := Value484 if Param.MemoryType = mtData then Memory[IP] := Value 485 485 else IP := Value; 486 486 end else if Param.Value = Integer(srSP) then begin 487 if Param.Memory then Memory[SP] := Value487 if Param.MemoryType = mtData then Memory[SP] := Value 488 488 else SP := Value; 489 489 end else raise Exception.Create('Unsupported special register ' + IntToStr(Integer(Param.Value))); 490 end else if Param.ParamType = ptNone then raise Exception.Create('Write to not set parameter') 491 else raise Exception.Create('Unsupported parameter type ' + IntToStr(Integer(Param.ParamType))); 490 end else 491 if Param.ParamType = ptNone then begin 492 raise Exception.Create('Write to not set parameter') 493 end else 494 raise Exception.Create('Unsupported parameter type ' + IntToStr(Integer(Param.ParamType))); 492 495 end; 493 496
Note:
See TracChangeset
for help on using the changeset viewer.