From 9fad35bfd47ae91e964ba4030c8942412df912fa Mon Sep 17 00:00:00 2001 From: Manuel Penschuck Date: Tue, 6 Aug 2013 20:50:51 +0200 Subject: [PATCH] Small helper to generate a diamond project from a TRB3 project --- base/create_project.pl | 313 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 313 insertions(+) create mode 100755 base/create_project.pl diff --git a/base/create_project.pl b/base/create_project.pl new file mode 100755 index 0000000..31cbf6e --- /dev/null +++ b/base/create_project.pl @@ -0,0 +1,313 @@ +#!/usr/bin/env perl + +# small straight-forward program to create a diamond project based on the standard trb3 project structure +# execute the script with the current project as working directory. if existing the current project may be altered. +# take care ! + + +use strict; +use warnings; +use Data::Dumper; +use File::Copy; + +sub parsePRJ { + my $input = shift; + my $options = {}; + my @files = (); + + open FH, "<" , $input; + while (my $line = ) { + chomp $line; + if ($line =~ m/^\s*set_option -([^\s]+)\s+"?([^"]+)"?$/) { + $options->{$1} = $2; + } + + if ($line =~ m/^\s*add_file -(vhdl|verilog) (-lib "?([^"\s]+)"?|) "?([^"]+)"?$/g) { + push @files, [$3, $4]; + } + } + + close FH; + + return ($options, \@files); +} + +sub generateLDF { + my $prj_file = shift; + my $options = shift; + my $files = shift; + + my $path = '../'; + + open FH, ">", $prj_file; + + my $device = $options->{'part'} . $options->{'speed_grade'} . $options->{'package'}; + $device =~ s/_/\-/g; + + my $prj_title = $options->{'top_module'}; + $prj_title =~ s/trb3_(central|periph)_(.+)/$2/; + + my $def_impl = $options->{'top_module'}; + + my $lpf1 = $options->{'top_module'} . '_constraints.lpf'; + my $lpf2 = '../base/' . $options->{'top_module'} . '.lpf'; + + if (not (-e $lpf1) and not (-e $lpf2)) { + print "WARNING: Could not find LPF files. Searched at\n $lpf1\n $lpf2\n"; + print " Diamond will not open the project unless you at atleast one lpf\n"; + } + + print FH "\n"; + print FH "\n"; + print FH " \n"; + print FH " \n"; + print FH " \n"; + for my $filer (@{$files}) { + my $file = $filer->[1]; + my $lib = $filer->[0]; + my $suffix = $file; + my $fpath = $path . $file; + $suffix =~ s/^.*\.([^.]+)$/$1/g; + if ("vhd" eq $suffix) { + print FH " \n" + } elsif ("v" eq $suffix) { + print FH " \n" + } else { + print "WARNING: Could not determine type of input file $file. Not included!\n"; + } + } + + print FH " \n" if (-e $lpf1); + print FH " \n" if (-e $lpf2); + + + print FH " \n"; + print FH " \n"; + print FH "\n"; + + close FH; +} + +sub generateSTY { + my $file = shift; + open FH, ">", $file; + print FH < + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +STY +; + close FH; +} + +# Search project file + my @prj_files = glob('*.prj'); + die "No .prj found? Is the current working dir the project root?" if 0 == scalar @prj_files; + die "Multiple prj-files found. This is not supported by this tool." if 1 < scalar @prj_files; + my $input = shift @prj_files; + + print "NOTE: Use $input as input file\n"; + +# parse PRJ file + my ($options, $files) = parsePRJ $input; + +# create dir if necessary + mkdir 'project' unless (-e 'project'); + +# generate ldf + my $project_file = 'project/' . $options->{'top_module'} . '.ldf'; + if (-e $project_file) {move $project_file, $project_file . '.backup'}; + generateLDF $project_file, $options, $files; + print "NOTE: LDF generated\n"; + +# generate strategy file + unless (-e 'project/auto_strat.sty') { + generateSTY 'project/auto_strat.sty'; + print "NOTE: STY generated\n"; + } + +print "\nDone. Execute \n> diamond $project_file\nto open the project\n"; -- 2.43.0