This file is indexed.

/usr/bin/gvhdl is in freehdl 0.0.8-2.1ubuntu2.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
#!/usr/bin/perl
# -*- perl -*-
use Socket;
use strict; 

my $cc = "x86_64-linux-gnu-g++";
my $libtool = "libtool";
my $libtool_options = "--mode=link --tag CXX";
my $vhdl_source_name = "";
my $source = "";
my $includes = "";
my $cpplibs = "-lm FREEHDL/lib/libfreehdl-kernel.la FREEHDL/lib/libfreehdl-std.la";
my $vhdl_library = ""; # Library the design entity is compiled into
my $cpp_options = "";
my $vhdl_options = "";
my $no_cpp_compile = 0;
my $verbose = 0;
my $use_sockets = 0;
my $vhdl_libdir = "FREEHDL/share/freehdl/lib";
my $freehdl_root_path= "";

# set root path of the FreeHDL system
sub set_freehdl_root_path {
  if (not -f "/usr/bin/freehdl-v2cc") {
    $freehdl_root_path = $ENV{'FREEHDL'};
    if ($freehdl_root_path ne "") { return; }
  } else {
    $freehdl_root_path = "/usr"; return;
  }
  # if environment variable is not set then test
  # each parent directory
  my $path = "/usr/share/freehdl/lib";
  while (1) {
    # test whether $path is a valid path
    if (not -d "$path/") { die "Could not find FreeHDL root path! Please set environment FREEHDL."; }
    # is there a file named v2cc.libs in the directory?
    if (not -f "$path/v2cc.libs") { $path = $path . "/.."; next; }
    # open file and analyze content
    open INFILE, "$path/v2cc.libs" or die "Could not read $path/v2cc.libs\n";
    my $text = ""; 
    while (<INFILE>) { 
      s/\n//g;
      $text = $text . " " . $_; 
    }
    my $found = 1;
    if ($text !~ /std\s*:\s*std/i) { $found = 0; }
    if ($text !~ /ieee\s*:\s*ieee/i) { $found = 0; }
    close(INFILE);
    # return result if freehdl root path was found
    if ($found == 1) { 
      $freehdl_root_path = $path;
      return;
    }
    # try next path
    $path = $path . "/..";
  }
};


sub update {
  $_ = $_[0];
  s/FREEHDL/$freehdl_root_path/g;
  return $_;
}


sub execute_cmd {
  my $cmd = $_[0];
  my $label_text = $_[1];
  my $out_file = $_[2];
  open(COMMAND, "$cmd 2>&1 |");
  while (<COMMAND>) {
    print $out_file, "$label_text$_";
  }
  return close(COMMAND)? 0 : 256;
}


# The main program
sub main {
  # determine root path of freehdl installation
  set_freehdl_root_path;
  print "gvhdl: FreeHDL root path is '$freehdl_root_path'.\n";
  $includes = "-I $freehdl_root_path/include";
  my $MSTREAM;
  my $ESTREAM;
  my $PROGRESS_BAR;
  open(MSTREAM, ">&STDOUT");
  open(ESTREAM, ">&STDERR");
  open(PROGRESS_BAR, ">/dev/null");
  
  $cpplibs = update($cpplibs);
  $libtool = update($libtool);
  $vhdl_libdir = update($vhdl_libdir);

  my $arg_index = 0;
  my $do_link = 1;
  my $create_simulator = 1;
  my @source_files;
  my $object_files;
  while ($arg_index < scalar(@ARGV)) {
    my $argument = $ARGV[$arg_index];
    if ($argument =~ /^\-l/) {
      die "gvhdl: Missing argument for '-l'!\n" if (++$arg_index >= scalar(@ARGV));
      $vhdl_library = "-l " . $ARGV[$arg_index];
    } elsif ($argument =~ /^\-C/) {
      $cc = $ARGV[++$arg_index];
    } elsif ($argument =~ /^\-FHDLgui/) {
      # gvhdl will communiate with is caller via 2 sockets. The socket
      # file names are generated from the base string passed over as a
      # argument to option FHDLgui. The actual file names are derived
      # by appending channel number 0 or 4 to the base name. Channel 0
      # is used for printing messages generated during code
      # generation/compilation/linking while channel 4 is used to
      # print progress information.
      my $socket_base_name = $ARGV[++$arg_index];

      my $socket_name = $socket_base_name . "0";
      socket(MSTREAM, PF_UNIX, SOCK_STREAM, 0)  || die "socket: $!";
      connect(MSTREAM, sockaddr_un($socket_name)) || die "connect: $!";
      $ESTREAM = $MSTREAM;

      my $socket_name = $socket_base_name . "4";
      socket(PROGRESS_BAR, PF_UNIX, SOCK_STREAM, 0)  || die "socket: $!";
      connect(PROGRESS_BAR, sockaddr_un($socket_name)) || die "connect: $!";

      $use_sockets = 1;

    } elsif ($argument =~ /^\-L/) {
      $vhdl_libdir .= " -L " . $ARGV[++$arg_index];
    } elsif ($argument =~ /^\-R/) {
      $vhdl_options = $vhdl_options . " -R";
    } elsif ($argument =~ /^\-g/) {
      $vhdl_options = $vhdl_options . " -g";
      $cpp_options = $cpp_options . " -g";
    } elsif ($argument =~ /^\-c/) {
      $do_link = 0;
      $create_simulator = 0;
      $cpp_options = $cpp_options . " -c";
    } elsif ($argument =~ /^\-G/) {
      $cpp_options = $cpp_options . " -g";
    } elsif ($argument =~ /^\-v/) {
      $verbose = 1;
    } elsif ($argument =~ /^\-V/) {
      $vhdl_options = $vhdl_options . " -v";
    } elsif ($argument =~ /^\-D/) {
      $vhdl_options = $vhdl_options . " -D";
    } elsif ($argument =~ /^\--relaxed-component-visibility/) {
      $vhdl_options = $vhdl_options . " --relaxed-component-visibility";
    } elsif ($argument =~ /^\--libieee/) {
	$cpplibs .= " " . update ("FREEHDL/lib/freehdl/libieee.la");
    } elsif ($argument =~ /^\-/) {
      $cpp_options = $cpp_options . " " . $argument;
    } else {
      push @source_files, $argument;
    }
    ++$arg_index;
  }


  my $steps = scalar(@source_files);
  if ($no_cpp_compile == 0) { $steps *= 2; }
  if ($do_link == 1) { $steps += 1; }
  $steps = int(99 / $steps);
  my $progress_value = 0;

  ##############################################################
  # Create name for main file
  ##############################################################
  my $main_file_name;
  my $main_vhdl_file;
  if ($create_simulator == 1) {
    $_ = $source_files [0];
    if ($_ =~ /\.vhdl$/) { $main_vhdl_file = $_; }
    s/\.[^\.]*$/\._main_/i;
    $main_file_name = $_;
  }

  ##############################################################
  # process each source file 
  ##############################################################
  foreach $vhdl_source_name (@source_files) {
    # skip object (*.o) files
    if ($vhdl_source_name =~ /\.o$/) { 
      $object_files = $object_files . " " . $vhdl_source_name;
      next;
    }
    # skip object (*.a) files
    if ($vhdl_source_name =~ /\.a$/) { 
      $object_files = $object_files . " " . $vhdl_source_name;
      next;
    }
    ##############################################################
    # Comiling vhdl -> cc
    ##############################################################
    $_ = $vhdl_source_name;
    s/\.[^\.]*$/\.cc/i;
    my $out_file_name = $_;
  
    my $cmd;
    if ($create_simulator == 1 && 
	$main_vhdl_file == $vhdl_source_name) {
      $cmd = "$freehdl_root_path/bin/freehdl-v2cc -m $main_file_name.cc -L $vhdl_libdir $vhdl_library $vhdl_options -o $out_file_name $vhdl_source_name";
    } else {
      $cmd = "$freehdl_root_path/bin/freehdl-v2cc -L $vhdl_libdir $vhdl_library $vhdl_options -o $out_file_name $vhdl_source_name";
    }
    print MSTREAM "gvhdl: executing '$cmd'\n";
    if (execute_cmd ($cmd, "", $MSTREAM)/256 != 0) {
      print ESTREAM "gvhdl: Compilation failed!\n";
      print PROGRESS_BAR "99";
      die;
    }

    $progress_value = int($progress_value + $steps);
    print PROGRESS_BAR $progress_value;

    ##############################################################
    # Comiling cc -> o
    ##############################################################
    $_ = $out_file_name;
    s/\.[^\.]*$/\.o/i;
    $object_files .= " " . $_;
    
    if ($no_cpp_compile == 0) {
      my $cmd = "$cc $cpp_options $includes -c $out_file_name";
      print MSTREAM "gvhdl:\n";
      print MSTREAM "gvhdl: ================================\n";
      print MSTREAM "gvhdl: Compiling '$out_file_name'...\n";
      print MSTREAM "gvhdl: ================================\n";
      print MSTREAM "gvhdl: $cmd\n";
      if (execute_cmd ($cmd, "c++: ", $MSTREAM)/256 != 0) {
	print ESTREAM "gvhdl: Compilation failed!\n";
	print PROGRESS_BAR "99";
	die;
      }

      $progress_value = int($progress_value + $steps);
      print PROGRESS_BAR $progress_value;
    }
  }

  ##############################################################
  # Comiling main cc file -> o
  ##############################################################
  if ($create_simulator == 1) {
    my $out_file_name = $main_file_name . ".cc";
    my $cmd = "$cc $cpp_options $includes -c $out_file_name";
    print MSTREAM "gvhdl:\n";
    print MSTREAM "gvhdl: ================================\n";
    print MSTREAM "gvhdl: Compiling simulator main file '$out_file_name'...\n";
    print MSTREAM "gvhdl: ================================\n";
    print MSTREAM "gvhdl: $cmd\n";
    if (execute_cmd ($cmd, "c++: ", $MSTREAM)/256 != 0) {
      print ESTREAM "gvhdl: Compilation failed!\n";
      print PROGRESS_BAR "99";
      die;
    }
    
    $progress_value = int($progress_value + $steps);
    print PROGRESS_BAR $progress_value;
  }

  ##############################################################
  # link
  ##############################################################
  if ($do_link == 1) {
    $_ = $source_files[0];
    s/\.[^\.]*$//i;
    my $target_name = $_;

    my $cmd = "$libtool $libtool_options $cc $cpp_options $main_file_name.o $object_files $cpplibs -o $target_name";
    print MSTREAM "gvhdl: Linking simulator '$target_name'...\n";
    print MSTREAM "gvhdl: $cmd\n";
    if (execute_cmd ($cmd, "linker: ", $MSTREAM)/256 != 0) {
      print ESTREAM "gvhdl: Linking failed!\n"; 
      die;
    }
    print MSTREAM "gvhdl: ================================\n";
    print MSTREAM "gvhdl: Simulator '$target_name' created.\n";
    print MSTREAM "gvhdl: ================================\n";

    print PROGRESS_BAR "99";
    rmdir ".libs";
  }
}


&main;