-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathriver_hdlgen.dart
More file actions
176 lines (147 loc) · 4.83 KB
/
river_hdlgen.dart
File metadata and controls
176 lines (147 loc) · 4.83 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import 'dart:io' show Platform, File;
import 'package:args/args.dart';
import 'package:logging/logging.dart';
import 'package:path/path.dart' as path;
import 'package:river/river.dart';
import 'package:river_hdl/river_hdl.dart';
Future<void> main(List<String> arguments) async {
var parser = ArgParser();
parser.addOption(
'soc',
help: 'Sets the SoC to generate',
allowed: RiverSoCChoice.values.map((v) => v.name).toList(),
);
parser.addMultiOption(
'soc-option',
help: 'Adds an option when configuring the SoC',
splitCommas: false,
);
parser.addOption(
'platform',
help: 'Sets the platform to generate',
allowed: RiverPlatformChoice.values.map((v) => v.name).toList(),
);
parser.addMultiOption(
'device-option',
help: 'Adds an option when configuring a device',
splitCommas: false,
);
parser.addOption(
'output',
help: 'Sets the output path to generate the SystemVerilog to',
);
parser.addOption(
'log',
help: 'Sets the log level',
allowed: Level.LEVELS.map((v) => v.name.toLowerCase()).toList(),
);
parser.addFlag('help', help: 'Prints the usage');
final args = parser.parse(arguments);
if (args.flag('help')) {
print('Usage: ${path.basename(Platform.script.toFilePath())}');
print('');
print('Options:');
print(parser.usage);
return;
}
Logger.root.onRecord.listen((record) {
print('${record.level.name}: ${record.time}: ${record.message}');
});
if (args.option('log') != null) {
Logger.root.level = Level.LEVELS.firstWhere(
(v) => v.name.toLowerCase() == args.option('log'),
);
Logger.root.finest('Logging set to ${Logger.root.level}');
}
RiverPlatformChoice? platformChoice;
RiverSoCChoice? socChoice;
if (args.option('platform') == null && args.option('soc') == null) {
print('Missing platform or soc option');
return;
} else if (args.option('platform') != null && args.option('soc') == null) {
platformChoice = RiverPlatformChoice.getChoice(args.option('platform')!);
if (platformChoice == null) {
print('Invalid argument for platform option');
return;
}
socChoice = platformChoice!.soc;
} else if (args.option('platform') == null && args.option('soc') != null) {
socChoice = RiverSoCChoice.getChoice(args.option('soc')!);
if (socChoice == null) {
print('Invalid argument for soc option');
return Future.value();
}
} else {
platformChoice = RiverPlatformChoice.getChoice(args.option('platform')!);
socChoice = RiverSoCChoice.getChoice(args.option('soc')!);
if (platformChoice?.soc != socChoice) {
print(
"Platform's SoC and the value given for \"--soc\" do not align, unable to handle...",
);
return Future.value();
}
}
if (platformChoice == null) {
print('Platform is not set, unable to handle...');
return;
}
final platform = platformChoice ?? (throw 'Bad state, platform is not set');
final soc = socChoice ?? (throw 'Bad state, soc is not set');
final socConfig =
soc.configure({
...Map.fromEntries(
args.multiOption('soc-option').map((entry) {
final i = entry.indexOf('=');
assert(i > 0);
return MapEntry(entry.substring(0, i), entry.substring(i + 1));
}),
),
'platform': platform.name,
}) ??
(throw 'Invalid platform configuration');
Logger.root.finest('River SoC configured: $socConfig');
List<String> staticInstructions = [];
final ip = RiverSoCIP(
socConfig,
deviceOptions: Map.fromEntries(
args
.multiOption('device-option')
.map((option) {
final i = option.indexOf('.');
assert(i > 0);
return option.substring(0, i);
})
.map(
(key) => MapEntry(
key,
Map.fromEntries(
args
.multiOption('device-option')
.where((option) {
final i = option.indexOf('.');
assert(i > 0);
return option.substring(0, i) == key;
})
.map((option) {
final i = option.indexOf('.');
assert(i > 0);
final entry = option.substring(i + 1);
final x = entry.indexOf('=');
assert(x > 0);
return MapEntry(
entry.substring(0, x),
entry.substring(x + 1),
);
}),
),
),
),
),
staticInstructions: staticInstructions,
);
Logger.root.finest('River SoC module created: $ip');
await ip.buildAndGenerateRTL(
logger: Logger.root,
outputPath: args.option('output') ?? 'output',
);
}