11import 'dart:io' show Platform, File;
22
33import 'package:args/args.dart' ;
4+ import 'package:logging/logging.dart' ;
45import 'package:path/path.dart' as path;
56import 'package:river/river.dart' ;
67import 'package:river_hdl/river_hdl.dart' ;
@@ -25,11 +26,23 @@ Future<void> main(List<String> arguments) async {
2526 allowed: RiverPlatformChoice .values.map ((v) => v.name).toList (),
2627 );
2728
29+ parser.addMultiOption (
30+ 'device-option' ,
31+ help: 'Adds an option when configuring a device' ,
32+ splitCommas: false ,
33+ );
34+
2835 parser.addOption (
2936 'output' ,
3037 help: 'Sets the output path to generate the SystemVerilog to' ,
3138 );
3239
40+ parser.addOption (
41+ 'log' ,
42+ help: 'Sets the log level' ,
43+ allowed: Level .LEVELS .map ((v) => v.name.toLowerCase ()).toList (),
44+ );
45+
3346 parser.addFlag ('help' , help: 'Prints the usage' );
3447
3548 final args = parser.parse (arguments);
@@ -42,6 +55,17 @@ Future<void> main(List<String> arguments) async {
4255 return ;
4356 }
4457
58+ Logger .root.onRecord.listen ((record) {
59+ print ('${record .level .name }: ${record .time }: ${record .message }' );
60+ });
61+
62+ if (args.option ('log' ) != null ) {
63+ Logger .root.level = Level .LEVELS .firstWhere (
64+ (v) => v.name.toLowerCase () == args.option ('log' ),
65+ );
66+ Logger .root.finest ('Logging set to ${Logger .root .level }' );
67+ }
68+
4569 RiverPlatformChoice ? platformChoice;
4670 RiverSoCChoice ? socChoice;
4771
@@ -97,7 +121,53 @@ Future<void> main(List<String> arguments) async {
97121 }) ??
98122 (throw 'Invalid platform configuration' );
99123
100- final ip = RiverSoCIP ( socConfig);
124+ Logger .root. finest ( 'River SoC configured: $ socConfig ' );
101125
102- await ip.buildAndGenerateRTL (outputPath: args.option ('output' ) ?? 'output' );
126+ final ip = RiverSoCIP (
127+ socConfig,
128+ deviceOptions: Map .fromEntries (
129+ args
130+ .multiOption ('device-option' )
131+ .map ((option) {
132+ final i = option.indexOf ('.' );
133+ assert (i > 0 );
134+ return option.substring (0 , i);
135+ })
136+ .map (
137+ (key) => MapEntry (
138+ key,
139+ Map .fromEntries (
140+ args
141+ .multiOption ('device-option' )
142+ .where ((option) {
143+ final i = option.indexOf ('.' );
144+ assert (i > 0 );
145+ return option.substring (0 , i) == key;
146+ })
147+ .map ((option) {
148+ final i = option.indexOf ('.' );
149+ assert (i > 0 );
150+
151+ final entry = option.substring (i + 1 );
152+
153+ final x = entry.indexOf ('=' );
154+ assert (x > 0 );
155+
156+ return MapEntry (
157+ entry.substring (0 , x),
158+ entry.substring (x + 1 ),
159+ );
160+ }),
161+ ),
162+ ),
163+ ),
164+ ),
165+ );
166+
167+ Logger .root.finest ('River SoC module created: $ip ' );
168+
169+ await ip.buildAndGenerateRTL (
170+ logger: Logger .root,
171+ outputPath: args.option ('output' ) ?? 'output' ,
172+ );
103173}
0 commit comments