-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathVarDeclaration.pas
More file actions
128 lines (116 loc) · 2.73 KB
/
Copy pathVarDeclaration.pas
File metadata and controls
128 lines (116 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
unit VarDeclaration;
interface
uses
Classes, Types, CodeElement, DataType, Operations, WriterIntf;
type
TVarDeclaration = class(TCodeElement)
private
FDataType: TDataType;
FParamIndex: Integer;
FDefaultValue: string;
FID: string;
FIsConstant: Boolean;
public
constructor Create(AName: string; AType: TDataType);
function GetAccessIdentifier(): string;
procedure GetDCPUSource(AWriter: IWriter); override;
function IsParameter(): Boolean;
function IsLocal(): Boolean;
property DataType: TDataType read FDataType;
property ParamIndex: Integer read FParamIndex write FParamIndex;
property DefaultValue: string read FDefaultValue write FDefaultValue;
property IsConst: Boolean read FIsConstant write FIsConstant;
end;
implementation
uses
SysUtils;
{ TVarDeclaration }
constructor TVarDeclaration.Create(AName: string; AType: TDataType);
begin
inherited Create(AName);
FDataType := AType;
FParamIndex := 0;
FDefaultValue := '0x0';
FID := GetUniqueID();
end;
function TVarDeclaration.GetAccessIdentifier: string;
var
LMod: Integer;
begin
Result := '';
if IsParameter then
begin
case FParamIndex of
1:
begin
Result := 'a';
end;
2:
begin
Result := 'b';
end;
3:
begin
Result := 'c';
end;
else
LMod := FParamIndex-3 + 1;//+1 because otherwhise we hit the index for the return address on the stack;
Result := 'j';
if LMod > 0 then
begin
Result := Result + ' + ' + IntToSTr(LMod);
end;
end;
end
else
begin
if IsLocal then
begin
LMod := Abs(FParamIndex+1);
Result := 'j';
if LMod > 0 then
begin
Result := Result + ' + ' + IntToStr(LMod);
end;
end
else
begin
Result := Name + FID;
end;
end;
end;
procedure TVarDeclaration.GetDCPUSource;
var
i, LSize: Integer;
LLine: string;
begin
AWriter.AddMapping(Self);
LLine := ':' + GetAccessIdentifier() + ' dat ';
if DataType.RawType = rtArray then
begin
LSize := DataType.GetRamWordSize();
AWriter.Write(':' + GetAccessIdentifier() + 'length dat 0x' + IntToHex(LSize, 4));
for i := 0 to LSize - 1 do
begin
LLine := LLine + '0x0';
if i < LSize - 1 then
begin
LLine := LLine + ', ';
end;
end;
end
else
begin
LLine := LLine + FDefaultValue;
end;
AWriter.Write(LLine);
end;
function TVarDeclaration.IsLocal: Boolean;
begin
Result := FParamIndex < 0;
end;
function TVarDeclaration.IsParameter: Boolean;
begin
Result := FParamIndex > 0;
end;
end.