-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvariable.ts
84 lines (74 loc) · 2.54 KB
/
variable.ts
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
import * as proto from '../cxxrtl/proto';
import { MemoryRangeDesignation, MemoryRowDesignation, ScalarDesignation } from './sample';
import { Location } from './source';
export abstract class Variable {
constructor(
readonly fullName: string[],
readonly location: Location | null,
readonly lsbAt: number,
readonly width: number,
) {}
static fromCXXRTL(cxxrtlName: string, cxxrtlDesc: proto.ItemDescription): Variable {
const fullName = cxxrtlName.split(' ');
if (cxxrtlDesc.type === 'node') {
return new ScalarVariable(
fullName,
Location.fromCXXRTL(cxxrtlDesc.src),
cxxrtlDesc.lsb_at,
cxxrtlDesc.width,
);
} else if (cxxrtlDesc.type === 'memory') {
return new MemoryVariable(
fullName,
Location.fromCXXRTL(cxxrtlDesc.src),
cxxrtlDesc.lsb_at,
cxxrtlDesc.width,
cxxrtlDesc.zero_at,
cxxrtlDesc.depth,
);
} else {
throw new Error(`Unknown item type in ${cxxrtlDesc}`);
}
}
get name(): string {
return this.fullName.at(-1)!;
}
get scopeFullName(): string[] {
return this.fullName.slice(0, -1);
}
get cxxrtlIdentifier(): string {
return this.fullName.join(' ');
}
get wcpIdentifier(): string {
return this.fullName.join(' ');
}
}
export class ScalarVariable extends Variable {
designation(): ScalarDesignation {
return new ScalarDesignation(this);
}
}
export class MemoryVariable extends Variable {
constructor(
fullName: string[],
location: Location | null,
lsbAt: number,
width: number,
readonly zeroAt: number,
readonly depth: number,
) {
super(fullName, location, lsbAt, width);
}
designation(index: number): MemoryRowDesignation;
designation(first: number, last: number): MemoryRangeDesignation;
designation(): MemoryRangeDesignation;
designation(firstOrIndex?: number, last?: number): MemoryRowDesignation | MemoryRangeDesignation {
if (firstOrIndex !== undefined && last === undefined) {
return new MemoryRowDesignation(this, firstOrIndex);
} else if (firstOrIndex !== undefined && last !== undefined) {
return new MemoryRangeDesignation(this, firstOrIndex, last);
} else {
return new MemoryRangeDesignation(this, 0, this.depth - 1);
}
}
}