Changeset 197 for branches/virtcpu varint/UInstructionWriter.pas
- Timestamp:
- Sep 22, 2019, 9:31:49 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/virtcpu varint/UInstructionWriter.pas
r196 r197 6 6 7 7 uses 8 Classes, SysUtils, U Machine;8 Classes, SysUtils, UCpu; 9 9 10 10 type … … 14 14 private 15 15 public 16 Cpu: TCpu;16 Memory: Pointer; 17 17 IP: T; 18 function GetRelativeAddr(BaseIP, TargetAddr: T): T; 18 19 procedure Write(Value: T); 20 procedure WriteSigned(Value: T); 19 21 procedure WriteOpcode(Value: TOpcode); 22 procedure WriteString(Text: string); 20 23 procedure NoOperation; 21 24 procedure Load(R1, R2: Integer); … … 30 33 procedure Jump(Addr: Integer); 31 34 procedure JumpCond(Addr: Integer); 32 {$IFDEF EXT_REL_JUMP}33 35 procedure JumpRelative(R1: Integer; Addr: Integer); 34 36 procedure JumpRelativeCond(Addr: Integer); 35 {$ENDIF}36 37 procedure TestEqual(R1, R2: Integer); 37 38 procedure Increment(R: Integer); 38 39 procedure Decrement(R: Integer); 39 40 constructor Create; 41 procedure Init; 40 42 end; 41 43 … … 44 46 45 47 { TInstructionWriter } 48 49 function TInstructionWriter.GetRelativeAddr(BaseIP, TargetAddr: T): T; 50 begin 51 Result := TargetAddr - (BaseIP + 1 + T.GetByteSize); 52 end; 53 54 procedure TInstructionWriter.WriteString(Text: string); 55 var 56 I: Integer; 57 begin 58 for I := 1 to Length(Text) do 59 Write(Ord(Text[I])); 60 end; 46 61 47 62 procedure TInstructionWriter.NoOperation; … … 129 144 end; 130 145 131 {$IFDEF EXT_REL_JUMP}132 146 procedure TInstructionWriter.JumpRelative(R1: Integer; Addr: Integer); 133 147 begin … … 139 153 procedure TInstructionWriter.JumpRelativeCond(Addr: Integer); 140 154 begin 141 Write (T(opJumpRelCond));155 WriteOpcode(opJumpRelCond); 142 156 Write(Addr - IP - 1); 143 157 end; 144 {$ENDIF}145 158 146 159 procedure TInstructionWriter.Increment(R: Integer); … … 158 171 constructor TInstructionWriter.Create; 159 172 begin 173 Memory := nil; 174 Init; 175 end; 176 177 procedure TInstructionWriter.Init; 178 begin 160 179 IP := 0; 161 Cpu := nil;162 180 end; 163 181 … … 166 184 C: Integer; 167 185 begin 168 C := Value.WriteToAddr(Pointer(Native Int(Cpu.Memory) + IP));186 C := Value.WriteToAddr(Pointer(NativeUInt(Memory) + IP)); 169 187 Inc(IP, C); 170 188 end; 171 189 190 procedure TInstructionWriter.WriteSigned(Value: T); 191 var 192 C: Integer; 193 begin 194 C := Value.WriteToAddr(Pointer(NativeUInt(Memory) + IP)); 195 Inc(IP, C); 196 end; 197 172 198 procedure TInstructionWriter.WriteOpcode(Value: TOpcode); 173 199 begin
Note:
See TracChangeset
for help on using the changeset viewer.