Changeset 138


Ignore:
Timestamp:
Jan 4, 2018, 2:00:49 PM (7 years ago)
Author:
chronos
Message:
  • Modified: Preparation for support for multiple memory types.
Location:
branches/virt simple
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/virt simple/UCompiler.pas

    r90 r138  
    4747  Param2: string;
    4848  ParamType1: TParamType;
    49   Indirect1: Boolean;
     49  Indirect1: TMemoryType;
    5050  Value1: Integer;
    5151  ParamType2: TParamType;
    52   Indirect2: Boolean;
     52  Indirect2: TMemoryType;
    5353  Value2: Integer;
    5454  OutValue: Integer;
     
    7474    if Param1 <> '' then begin
    7575    if (Copy(Param1, 1, 1) = '[') and (Copy(Param1, Length(Param1), 1) = ']') then begin
    76       Indirect1 := True;
     76      Indirect1 := mtData;
    7777      Param1 := Trim(Copy(Param1, 2, Length(Param1) - 2));
    78     end else Indirect1 := False;
     78    end else Indirect1 := mtNone;
    7979    if Copy(Param1, 1, 1) = 'R' then begin
    8080      ParamType1 := ptRegister;
     
    103103    if Param2 <> '' then begin
    104104    if (Copy(Param2, 1, 1) = '[') and (Copy(Param2, Length(Param2), 1) = ']') then begin
    105       Indirect2 := True;
     105      Indirect2 := mtData;
    106106      Param2 := Trim(Copy(Param2, 2, Length(Param2) - 2));
    107     end else Indirect2 := False;
     107    end else Indirect2 := mtNone;
    108108    if Copy(Param2, 1, 1) = 'R' then begin
    109109      ParamType2 := ptRegister;
  • branches/virt simple/UFormMain.lfm

    r89 r138  
    11object Form1: TForm1
    2   Left = 383
    3   Height = 1104
    4   Top = 191
    5   Width = 1708
     2  Left = 44
     3  Height = 1023
     4  Top = 6
     5  Width = 1703
    66  Caption = 'Form1'
    7   ClientHeight = 1104
    8   ClientWidth = 1708
     7  ClientHeight = 0
     8  ClientWidth = 0
     9  DesignTimePPI = 120
    910  OnClose = FormClose
    1011  OnCreate = FormCreate
    1112  OnDestroy = FormDestroy
    1213  OnShow = FormShow
    13   LCLVersion = '1.7'
     14  LCLVersion = '1.8.0.6'
    1415  object ListViewMemory: TListView
    1516    Left = 888
     
    7778  object Label1: TLabel
    7879    Left = 888
    79     Height = 24
     80    Height = 20
    8081    Top = 9
    81     Width = 75
     82    Width = 58
    8283    Caption = 'Memory:'
    8384    ParentColor = False
     
    8586  object Label2: TLabel
    8687    Left = 1128
    87     Height = 24
     88    Height = 20
    8889    Top = 9
    89     Width = 84
     90    Width = 63
    9091    Caption = 'Registers:'
    9192    ParentColor = False
     
    9394  object Label3: TLabel
    9495    Left = 1416
    95     Height = 24
     96    Height = 20
    9697    Top = 8
    97     Width = 145
     98    Width = 111
    9899    Caption = 'Special registers:'
    99100    ParentColor = False
     
    131132  object Label4: TLabel
    132133    Left = 18
    133     Height = 24
     134    Height = 20
    134135    Top = 744
    135     Width = 66
     136    Width = 49
    136137    Caption = 'Output:'
    137138    ParentColor = False
     
    139140  object Label5: TLabel
    140141    Left = 528
    141     Height = 24
     142    Height = 20
    142143    Top = 9
    143     Width = 194
     144    Width = 152
    144145    Caption = 'Compiled source code:'
    145146    ParentColor = False
     
    157158  object Label6: TLabel
    158159    Left = 20
    159     Height = 24
     160    Height = 20
    160161    Top = 7
    161     Width = 109
     162    Width = 85
    162163    Caption = 'Source code:'
    163164    ParentColor = False
  • branches/virt simple/UMachine.pas

    r89 r138  
    2424  TParamType = (ptNone, ptConst, ptRegister, ptSpecialRegister);
    2525  TCondition = (cdZero, cdNotZero, cdNegative, cdPositive);
     26  TMemoryType = (mtNone, mtData);
    2627
    2728  TValue = Integer;
     
    3334  TParam = class
    3435    ParamType: TParamType;
    35     Memory: Boolean;
     36    MemoryType: TMemoryType;
    3637    Value: TValue;
    3738    function GetString: string;
     39    procedure SetParam(ParamType: TParamType; MemoryType: TMemoryType; Value: TValue);
    3840  end;
    3941
     
    5153    procedure AddInst(Opcode: TOpcode); overload;
    5254    procedure AddInst(Opcode: TOpcode;
    53       ParamType1: TParamType; Indirect1: Boolean; Value1: TValue);  overload;
     55      ParamType1: TParamType; Indirect1: TMemoryType; Value1: TValue);  overload;
    5456    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;
    5759  end;
    5860
     
    146148      else Result := 'S' + IntToStr(Value);
    147149  end;
    148   if Memory then Result := '[' + Result + ']';
     150  if MemoryType = mtData then Result := '[' + Result + ']';
     151end;
     152
     153procedure TParam.SetParam(ParamType: TParamType; MemoryType: TMemoryType;
     154  Value: TValue);
     155begin
     156  Self.ParamType := ParamType;
     157  Self.MemoryType := MemoryType;
     158  Self.Value := Value;
    149159end;
    150160
     
    183193  NewInst := TInstruction.Create;
    184194  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);
    191197  Add(NewInst);
    192198end;
    193199
    194200procedure TInstructions.AddInst(Opcode: TOpcode; ParamType1: TParamType;
    195   Indirect1: Boolean; Value1: TValue);
     201  Indirect1: TMemoryType; Value1: TValue);
    196202var
    197203  NewInst: TInstruction;
     
    199205  NewInst := TInstruction.Create;
    200206  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);
    207209  Add(NewInst);
    208210end;
    209211
    210212procedure 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);
    213215var
    214216  NewInst: TInstruction;
     
    216218  NewInst := TInstruction.Create;
    217219  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);
    224222  Add(NewInst);
    225223end;
     
    469467  end else if Param.ParamType = ptNone then raise Exception.Create('Read from not set parameter')
    470468  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];
    472470end;
    473471
     
    475473begin
    476474  if Param.ParamType = ptRegister then begin
    477     if Param.Memory then Memory[Registers[Param.Value]] := Value
     475    if Param.MemoryType = mtData then Memory[Registers[Param.Value]] := Value
    478476      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
    481480      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
    483483    if Param.Value = Integer(srIP) then begin
    484       if Param.Memory then Memory[IP] := Value
     484      if Param.MemoryType = mtData then Memory[IP] := Value
    485485        else IP := Value;
    486486    end else if Param.Value = Integer(srSP) then begin
    487       if Param.Memory then Memory[SP] := Value
     487      if Param.MemoryType = mtData then Memory[SP] := Value
    488488        else SP := Value;
    489489    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)));
    492495end;
    493496
  • branches/virt simple/project1.lpi

    r88 r138  
    22<CONFIG>
    33  <ProjectOptions>
    4     <Version Value="9"/>
     4    <Version Value="10"/>
    55    <General>
    66      <SessionStorage Value="InProjectDir"/>
     
    1111      <Icon Value="0"/>
    1212    </General>
    13     <VersionInfo>
    14       <StringTable ProductVersion=""/>
    15     </VersionInfo>
    1613    <BuildModes Count="1">
    1714      <Item1 Name="Default" Default="True"/>
Note: See TracChangeset for help on using the changeset viewer.