⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 compile_nc_vhdl_51.pl

📁 vhdl compile and simulation
💻 PL
字号:
#!perl

###############################################################################
#
# File:
#    compile_nc_vhdl.pl
#
# Purpose:
#    A Perl program to compile NC-VHDL VHDL simulation libraries.
#
# History:
#       Name            Date            What
#       -----------------------------------------------------------------------
#       Patrick Phung   03/28/99        Created
#       Aravind         01/15/01        Modified to include coregen libraries
#       Haotoa          02/26/01        Modified to make VHDL 93 compatible
#       Aravind         04/26/01        Modified for syntax errors
#       Abhishek        10/12/01        Modified for NC-VHDL
#       Nripendra       01/15/02        Modified to run with PERL4 and PERL5
#                                       Modified Messages in print statements
#                                       Added sub deletetree/ mkdirtree
#                                       Tested on Solaris 5.7/ Win2000
#       Nripendra       02/04/02        Rectified unisim/ coregen issues
#       Nripendra       02/25/02        Rectified path argument issues
#                                       Added sub current_dir_path
#                                       Tested on Solaris 5.7/ Win2000
#       Nripendra       03/14/02        Skipped compilation of the following
#                                       xilinxcorelib files:
#                                       o lfsr_v1_0.vhd
#                                       o lfsr_v1_0_comp.vhd
#                                       Tested on Solaris 5.7
#       Brian Philofsky	12/04/02        Updated for the 5.1i and IP #1
#                                       o Removed Logiblox
#                                       o Added files to 93 compilation
#       Premduth Vidyanandan 13/01/03   Updated for Smart models and minor
#                                       cosmetics:
#                                       1. Modified the script so that it will
#                                          compile the smart model wrappers
#                                       2. Changed the path into which 
#                                          it compiles.
#                                       3. Changed all the simprims and 
#                                          unisims to simprim and unisim.
#                                      
#
###############################################################################

$XILINX = $ENV{'XILINX'};

if (! $XILINX)
{
   print "ERROR: The XILINX environment variable is not set.\n";
   exit 1;
}

# Checking the OS Type - Unix or Windows

$os_type = "unsupported";
$os_type = "unix" if ($XILINX =~ m/\//);
$os_type = "windows" if ($XILINX =~ m/\\/);

# For NT platform - translate the backslashes to forward slashes
$XILINX =~ s/\\/\//g;

if ($#ARGV == 0)
{
   $PATH = "$XILINX/vhdl";
}

elsif ($#ARGV == 1)
{
   # For NT platform - translate the backslashes to forward slashes
   $PATH_ARG = $ARGV[1];
   $PATH_ARG =~ s/\\/\//g;
#   &mkdirtree("$PATH_ARG/vhdl");

# Do not add a VHDL to the path.
   &mkdirtree("$PATH_ARG");

   $launch_dir = &current_dir_path("$os_type");

   chdir("$PATH_ARG") || 
     die "ERROR: Could not change directory to\n$PATH_ARG\n";
   $dest_path = &current_dir_path("$os_type");
   chdir("$launch_dir") || 
     die "ERROR: Could not change directory to\n$launch_dir\n";

   $PATH = "$dest_path";
}

else
{
   print "ERROR: Incorrect number of arguments at the command line\n";
   print "Usage: $0 <Library> [Output Directory]\n";
   print "Output Directory defaults to $XILINX/vhdl\n";
   exit 1;
}

if ($ARGV[0] ne 'all' &&
    $ARGV[0] ne 'simprims' &&
    $ARGV[0] ne 'simprim' &&
    # $ARGV[0] ne 'logiblox' &&
    $ARGV[0] ne 'unisims' &&
    $ARGV[0] ne 'unisim' &&
    $ARGV[0] ne 'uni' &&
    $ARGV[0] ne 'coregen' &&
    $ARGV[0] ne 'xilinxcorelib') {

   print "ERROR: Invalid Library name specified!\n";
   print "Please check/ correct the name of the Library to be compiled!\n";
   print "Usage: $0 <Library> [Output Directory]\n";
   print "Library: 'all' For compiling all the libraries\n";
   # print "Library: 'logiblox' For compiling the logiblox libraries\n";
   print "Library: 'simprims' or 'simprim' For compiling the simprim library\n";
   print "Library: 'unisims' or 'unisim' or 'uni' For compiling the unisim library\n";
   print "Library: 'coregen' or 'xilinxcorelib' For compiling the coregen libraries\n";
   exit 1;
}

if (! -d $PATH)
{
   print "ERROR: $PATH is not a directory.\n";
   exit 1;
}

if (! -r _)
{
   print "ERROR: $PATH does not have read permission.\n";
   exit 1;
}

if (! -w _)
{
   print "ERROR: $PATH does not have write permission.\n";
   exit 1;
}

if (! -x _)
{
   print "ERROR: $PATH does not have execute permission.\n";
   exit 1;
}

$warn = "Please make sure that the \"NC-VHDL\" simulator is installed properly!";

&mkdirtree("$PATH");
$PATH = "$PATH";

$cdsroot = `cds_root ncvhdl`;
chop $cdsroot;
# For NT platform - translate the backslashes to forward slashes
$cdsroot =~ s/\\/\//g;

if(-e $cdsroot)
{
    print "NC-VHDL Installation Root : $cdsroot\n";
}
else
{
    die "FATAL ERROR : Unable to locate NC-VHDL Installation\n".$warn."\n";
}

print "Creating hdl.var File..\n";
open(HDLVAR,">$PATH/hdl.var") || die "ERROR: Cannot open $PATH/hdl.var : $!\n";
   print HDLVAR "##\n## Generated by compile_nc_vhdl.pl\n";
   print HDLVAR "##\n## Defines default VHDL WORK directory\n";
   print HDLVAR "DEFINE WORK ./\n";
close(HDLVAR);

print "Creating cds.lib File..\n";

if(-e "$PATH/cds.lib")
{
   @oldcdslib = `cat $PATH/cds.lib`;
}
else{
   @oldcdslib = ("##\n## Generated by compile_nc_vhdl.pl\n",
                "##\n## Including Standard Libraries\n",
                "INCLUDE \"$cdsroot/tools/inca/files/cds.lib\"\n");
}

open(CDSLIB,">$PATH/cds.lib") || die "ERROR: Cannot open $PATH/cds.lib : $!\n";

if($ARGV[0] eq 'all')
{
   print CDSLIB "##\n## Generated by compile_nc_vhdl.pl\n".
                "##\n## Including Standard Libraries\n".
                "INCLUDE \"$cdsroot/tools/inca/files/cds.lib\"\n";

   # &deletetree("$PATH/logiblox") if (-d "$PATH/logiblox");
   # &mkdirtree("$PATH/logiblox") && die "ERROR: Unable to create Design Library : $!\n";
   # print CDSLIB "DEFINE logiblox $PATH/logiblox\n";

   &deletetree("$PATH/simprims") if (-d "$PATH/simprims");
   &mkdirtree("$PATH/simprim") && die "ERROR: Unable to create Design Library : $!\n";
   print CDSLIB "DEFINE simprim $PATH/simprim\n";

   &deletetree("$PATH/unisims") if (-d "$PATH/unisims");
   &mkdirtree("$PATH/unisim") && die "ERROR: Unable to create Design Library : $!\n";
   print CDSLIB "DEFINE unisim $PATH/unisim\n";

   &deletetree("$PATH/xilinxcorelib") if (-d "$PATH/xilinxcorelib");
   &mkdirtree("$PATH/xilinxcorelib") && die "ERROR: Unable to create Design Library : $!\n";
   print CDSLIB "DEFINE xilinxcorelib $PATH/xilinxcorelib\n";

}
else
{
   # logiblox is the default choice if none of these libraries match
   ($ARGV[0] = 'simprim') if ($ARGV[0] =~ /simprim/);
   ($ARGV[0] = 'unisim') if ($ARGV[0] =~ /uni.*/);
   ($ARGV[0] = 'xilinxcorelib') if ($ARGV[0] =~ /coregen/);
   ($ARGV[0] = 'xilinxcorelib') if ($ARGV[0] =~ /xilinxcorelib/);
   &deletetree("$PATH/$ARGV[0]") if (-d "$PATH/$ARGV[0]");
   &mkdirtree("$PATH/$ARGV[0]") && die "ERROR: Unable to create Design Library : $!\n";
   print CDSLIB grep(!/^DEFINE $ARGV[0]/,@oldcdslib);
   print CDSLIB "DEFINE $ARGV[0] $PATH/$ARGV[0]\n";
}

close(CDSLIB);

$ncvhdl = "ncvhdl -cdslib $PATH/cds.lib -hdlvar $PATH/hdl.var -mess ";

# if ($ARGV[0] eq 'all' || $ARGV[0] eq 'logiblox')
# {
   # system("$ncvhdl -work logiblox $XILINX/vhdl/src/logiblox/mvlutil.vhd") &&
       # die "ERROR: ncvhdl command failed.\n";
   # system("$ncvhdl -work logiblox $XILINX/vhdl/src/logiblox/mvlarith.vhd") &&
       # die "ERROR: ncvhdl command failed.\n";
   # system("$ncvhdl -work logiblox $XILINX/vhdl/src/logiblox/logiblox.vhd") &&
       # die "ERROR: ncvhdl command failed.\n";
# }

if ($ARGV[0] eq 'all' || $ARGV[0] eq 'simprims' || $ARGV[0] eq 'simprim')
{
   system("$ncvhdl -work simprim $XILINX/vhdl/src/simprims/simprim_Vcomponents.vhd")
       && die "ERROR: ncvhdl command failed.\n";
   system("$ncvhdl -work simprim $XILINX/vhdl/src/simprims/simprim_Vpackage.vhd")
       && die "ERROR: ncvhdl command failed.\n";
   system("$ncvhdl -work simprim $XILINX/vhdl/src/simprims/simprim_VITAL.vhd")
       && die "ERROR: ncvhdl command failed.\n";
   system("$ncvhdl -work simprim $XILINX/vhdl/src/simprims/simprim_SMODEL.vhd")
       && die "ERROR: ncvhdl command failed.\n";
}

if ($ARGV[0] eq 'all' || $ARGV[0] eq 'unisims' || $ARGV[0] eq 'unisim' || $ARGV[0] eq 'uni')
{
   system("$ncvhdl -work unisim $XILINX/vhdl/src/unisims/unisim_VCOMP.vhd")
       && die "ERROR: ncvhdl command failed.\n";
   system("$ncvhdl -work unisim $XILINX/vhdl/src/unisims/unisim_VPKG.vhd")
       && die "ERROR: ncvhdl command failed.\n";
   system("$ncvhdl -work unisim $XILINX/vhdl/src/unisims/unisim_VITAL.vhd")
       && die "ERROR: ncvhdl command failed.\n";
   system("$ncvhdl -work unisim $XILINX/vhdl/src/unisims/unisim_SMODEL.vhd")
       && die "ERROR: ncvhdl command failed.\n";
}

if ($ARGV[0] eq 'all' || $ARGV[0] eq 'xilinxcorelib')
{
   # list of vhdl 93 cores
   @vhdl93 = ('blkmemv2sp_v2_0.vhd', 'blkmemv2dp_v2_0.vhd', 'mult_gen_v6_0.vhd', 'c_counter_binary_v6_0.vhd');

   #list of files to skip
   @skiplist = ('lfsr_v1_0.vhd', 'lfsr_v1_0_comp.vhd');

   $orderFile = "$XILINX/vhdl/src/XilinxCoreLib/vhdl_analyze_order";
   unless ( -f $orderFile )
   {
      print "ERROR: Vhdl analysis order file can not be located at $orderFile. \n";
      exit 1;
   }
   open (ORDER, $orderFile) || die "ERROR: Vhdl analysis order file is not accessible.\n";

   L0: while ($f = <ORDER>)
   {
      chop $f;
      unless (($f =~ /^\#/) || ($f =~ /^\s*$/))
      {
         foreach $fskip (@skiplist)
         {
             if($f eq $fskip)
             {
                 print "Skipping $f... \n";
                 next L0;
             }
         }

         foreach $f93 (@vhdl93)
         {
             if ($f eq $f93)
             {
                 system("$ncvhdl -v93 -relax -work xilinxcorelib $XILINX/vhdl/src/XilinxCoreLib/$f")
                     && die "ERROR: ncvhdl command failed.\n";
                 next L0;
             }
         }

         system("$ncvhdl -relax -work xilinxcorelib $XILINX/vhdl/src/XilinxCoreLib/$f")
             && die "ERROR: ncvhdl command failed.\n";
      }
   }
   close ORDER;
}

print "\nInfo: Libraries compiled successfully\n\n";
print "Note for simulating with NC-VHDL/ NCSIM:\n";

print "  Append the relevant Library Defintions from the following list\n";
print "  to the cds.lib file in your project area \(the directory\n";
print "  from where you will invoke NC-VHDL/ NCSIM executables\)\n\n";

# Cat the Library Definitions from the $PATH/cds.lib file here
open (CDSFILE, "$PATH/cds.lib");
while (<CDSFILE>) {
  if (/^[dD][eE][fF][iI][nN][eE]/) {
    print;
  }
}
close CDSFILE;

print "\n\n";

################################################################################

################################################################################
#  Subroutine to perform "rm -rf" functionality
#  For PERL4 compatibility/ Platform independence (NT/UNIX)
#  usage : &deletetree("$del_dir");
#  Parameter : del_dir - path to directory or file to be removed
################################################################################

sub deletetree {

local($dir) = @_;
local($l_file) = "";
local(@allfiles) = ();
local(*THISDIR);

opendir(THISDIR, $dir);
@allfiles = grep (! /^\.\.?$/, readdir(THISDIR));
chdir($dir);
foreach $l_file(@allfiles) {
   if(-f $l_file) {
   unlink "$l_file";
   }

   if ( -d "$l_file" ) {
      &deletetree("l_file");
   }

}

closedir THISDIR;
chdir("../");
rmdir($dir);
}

################################################################################
#  Subroutine to perform "mkdir -p" functionality
#  For PERL4 compatibility/ Platform independence (NT/UNIX)
#  usage :  &mkdirtree("$dir_tree");
#  Parameter : dir_tree - directory path
################################################################################

sub mkdirtree {
local($path) = @_;
local($count) = 0;
local($start_slash) = 0;
local($prev_path) = "";

@pathlist = split(/\//,$path);

# Checks whether path is specified in the "/tmp/.." format.
# If yes, then it removes the first element "/" the pathlist.

if (substr($path,0,1) eq "/")
{
   $start_slash = 1;
   shift @pathlist;
}

foreach $file (@pathlist)
{

   if($start_slash == 1)
   {
      $file = "/$file";
      $start_slash = 0;
   }

   $file = "$file/";

   if ($count > 0)
   {
       $prev_path = "$prev_path"."$file";
   }
   else
   {
      $prev_path = $file;
   }


   if (! -d "$prev_path")
   {
      mkdir("$prev_path","0511") || die "can not create the $prev_path directory";
      chmod 0755, $prev_path;
   }

   $count++;
}

}

########################################################################
#  Subroutine to perform unix "pwd" command functionality
#  For PERL4 compatibility/ Platform independence (NT/UNIX)
#  usage :  &current_dir_path("$os_type");
#  Paramater  : os_type (platform OS - in lowercase)
########################################################################

sub current_dir_path {
local($os_type) = @_;
local($dir_path) = "";
local(*CURR_DIR);

if ($os_type eq "windows") {
  open(CURR_DIR, "cmd /d /A /c cd |");
} # For WindowsNT and Windows2000 platforms.
  # Compatibility note : for Windows98, "cmd" => "command"
  # Also, change the switches. : NOT supported currently

if ($os_type eq "unix") {
  open(CURR_DIR, "pwd |");
} # For unix

$dir_path = <CURR_DIR>;
chop($dir_path);

close(CURR_DIR);

# For NT platform - translate the backslashes to forward slashes
$dir_path =~ s/\\/\//g;
return $dir_path;
}

################################################################################
# End of Script compile_nc_vhdl.pl
###############################################################################

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -