#!/usr/local/bin/perl use strict; use Getopt::Std; use Data::Dumper qw(Dumper); my %opts; sub usage { print "Error: @_\n" if @_; print <<"EOU"; usage: $0 [options] -f \n"; -d (rtl) -o (out.dcs) -l (WORK) Parses all files listed in config file, compiles and saves a gate-level verilog description to rtldir. Saves all module instances into the import library specified with -l. EOU } my %modules; # Modules i've defined my @modules; my $config; # Config file listing all # files needed for this build my $rtldir = "rtl"; my $outfile = "out.dcs"; my $library = "WORK"; { getopt('fdlo', \%opts) or &usage(); $config = $opts{'f'}; &usage() unless $config; $rtldir = $opts{'d'} if($opts{'d'}); $outfile = $opts{'o'} if($opts{'o'}); $library = $opts{'l'} if($opts{'l'}); &usage("$rtldir: no such directory") unless -d $rtldir; &usage($!) unless open(CFG, $config); while (my $filename = ) { next if $filename =~ /^\s*\#/; chomp $filename; open(MODULE, $filename) or die "$!"; while() { chomp; if(/module\s+(\w+)\s*\(/) { $modules{$1} = { filename => $filename }; # keep an ordered list for later iterations push @modules, $1; next; } if(/^\s*([\w\_]+)\s*\w+\s*\(/) { my $instance = $1; # instantiating another module die "Trying to instantiate a module without knowledge of top-level module in $filename:$." unless grep { $_->{'filename'} eq $filename } values %modules; next unless grep {$instance eq $_} @modules; $modules{$filename}{'instances'} = [] unless $modules{$filename}{'instances'}; push @{$modules{$filename}{'instances'}}, $instance; } } close(MODULE); } close(CFG); open(OUT, ">$outfile") or die "Couldn't open $outfile for writing: $!"; if(!-d $library) { mkdir($library, 0755); } print OUT "define_design_lib $library -path $library\n"; foreach my $module (@modules) { my $ref = $modules{$module} or die "wtf..."; my $f = $ref->{'filename'}; print OUT <<"EOS"; analyze -format verilog -library $library $f elaborate -arch verilog -library $library $module -update compile -map_effort high report_area >reports/$module-area.out report_power -analysis_effort high >reports/$module-power.out report_reference >reports/$module-reference.out write -format verilog -output $rtldir/$module.v EOS } close(OUT); }