/* Display a GHDL Wavefile for debugging. Copyright (C) 2005 Tristan Gingold GHDL is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GHDL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GCC; see the file COPYING. If not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include #include #include #include #include #include "ghwlib.h" static const char *progname; void usage (void) { printf ("usage: %s [OPTIONS] FILEs...\n", progname); printf ("Options are:\n" " -t display types\n" " -h display hierarchy\n" " -T display time\n" " -s display signals (and time)\n" " -l display list of sections\n" " -v verbose\n"); } int main (int argc, char **argv) { int i; int flag_disp_types; int flag_disp_hierarchy; int flag_disp_time; int flag_disp_signals; int flag_list; int flag_verbose; int eof; enum ghw_sm_type sm; progname = argv[0]; flag_disp_types = 0; flag_disp_hierarchy = 0; flag_disp_time = 0; flag_disp_signals = 0; flag_list = 0; flag_verbose = 0; while (1) { int c; c = getopt (argc, argv, "thTslv"); if (c == -1) break; switch (c) { case 't': flag_disp_types = 1; break; case 'h': flag_disp_hierarchy = 1; break; case 'T': flag_disp_time = 1; break; case 's': flag_disp_signals = 1; flag_disp_time = 1; break; case 'l': flag_list = 1; break; case 'v': flag_verbose++; break; default: usage (); exit (2); } } if (optind >= argc) { usage (); return 1; } for (i = optind; i < argc; i++) { struct ghw_handler h; struct ghw_handler *hp = &h; hp->flag_verbose = flag_verbose; if (ghw_open (hp, argv[i]) != 0) { fprintf (stderr, "cannot open ghw file %s\n", argv[i]); return 1; } if (flag_list) { while (1) { int section; section = ghw_read_section (hp); if (section == -2) { printf ("eof of file\n"); break; } else if (section < 0) { printf ("Error in file\n"); break; } else if (section == 0) { printf ("Unknown section\n"); break; } printf ("Section %s\n", ghw_sections[section].name); if ((*ghw_sections[section].handler)(hp) < 0) break; } } else { if (ghw_read_base (hp) < 0) { fprintf (stderr, "cannot read ghw file\n"); return 2; } if (0) { int i; printf ("String table:\n"); for (i = 1; i < hp->nbr_str; i++) printf (" %s\n", hp->str_table[i]); } if (flag_disp_types) ghw_disp_types (hp); if (flag_disp_hierarchy) ghw_disp_hie (hp, hp->hie); #if 1 sm = ghw_sm_init; eof = 0; while (!eof) { switch (ghw_read_sm (hp, &sm)) { case ghw_res_snapshot: case ghw_res_cycle: if (flag_disp_time) printf ("Time is %lld fs\n", hp->snap_time); if (flag_disp_signals) ghw_disp_values (hp); break; case ghw_res_eof: eof = 1; break; default: abort (); } } #else if (ghw_read_dump (hp) < 0) { fprintf (stderr, "error in ghw dump\n"); return 3; } #endif } ghw_close (&h); } return 0; } a> 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
# Try to load JSON data from a file. If not found, use the argument as a tag name and retrieve the data from GitHub.
def getJSON(tag='all'):
   f = tag
   tag = '/'+tag
   if f == 'all':
      f = 'releases'
      tag = ''

   import json
   try:
      d = json.loads(open(f+'.json', 'r').read())
   except:
      from urllib.request import urlopen
      d = json.loads(urlopen('https://api.github.com/repos/ghdl/ghdl/releases'+tag).read())
      json.dump(d, open(f+'.json', 'w'), indent=4)
   return d

#
# Functions to print table with format `[ [], [], [], ... ]` to reStructuredText
#

# Print a row of data elements.
def printTabRow(l, r):
   printTabItem(l, r, '| ')

# Print a rule. Two characters in 'b' define the type of rule. Expected values are '+-', '+=' or '| '.
def printTabRule(l, b):
   printTabItem(l, [b[1] for x in range(len(l))], b)

# Print a full row, be it a rule or data.
# Extend the width of each field to the size specified in 'l'.
def printTabItem(l, a, b):
   for y, z in enumerate(a):
      print((b + z).ljust(l[y]+3, b[1]), end='')
   print(b[0])

# Get number of cols from number of elements in row 0.
# Compute minimum number of characters required for each col.
def getTabColLens(t):
   cl = [0 for _ in t[0]]
   for row in t:
      for y, z in enumerate(row):
         cl[y] = max(cl[y], len(z))
   return cl

# Print a table using the functions above.
# The first row contains the headers.
def printTab(t):
   clens = getTabColLens(t)

   printTabRule(clens, '+-')
   printTabRow(clens, t[0])
   printTabRule(clens, '+=')
   for x in t[1:]:
      printTabRow(clens, x)
      printTabRule(clens, '+-')
   print()

#
# Print two versions of each shield. Onee for 'html' (`image::`) and one for 'latex' (`replace::`)
#

# Strip all non-alphanumeric characters when creating the labels
def stripLabel(label):
   import re
   pattern = re.compile('[\W_]+')
   return pattern.sub('', label)

def printShieldSrc(label, alt, img, target, latex=False):
   if latex:
      i = stripLabel(label)
      if label[-6:] == '/total':
         label = label[:-6]
      print('.. |l' + i + '| replace:: `' + label + '`_')
      print('.. _' + label + ': ' + target + '\n')
   else:
      print('.. |' + label + '| image:: '+ img + '\n',
            '   :target: ' + target + '\n',
            '   :height: 22\n',
            '   :alt: ' + alt + '\n')

#
# Display better OS and Backend names than those represented in the tarball name
#

def prettyOS(i):
   if i == 'fedora28':
      return 'Fedora 28'
   elif i == 'macosx':
      return 'Max OS X'
   elif i == 'mingw32':
      return 'Windows x86 (MinGW32)'
   elif  i == 'mingw64':
      return 'Windows x86 (MinGW64)'
   elif  i == 'stretch':
      return 'Debian 9 (Stretch)'
   elif  i == 'gpl':
      return 'Debian 9 (Stretch) GPL'
   elif  i == 'ubuntu14':
      return '14.04 LTS (Trusty Tahr)'
   return i

def prettyBackend(i):
   if i == 'llvm':
      return 'LLVM'
   if i == 'llvm-3.8':
      return 'LLVM (3.8)'
   return i

#
# Get, extract and process JSON data to create the shields and table with the assets of a release
#

def createTagShields(data='latest'):
   if isinstance(data, str):
      data = getJSON(data)

   assets=[['OS', 'Backend', 'Size', 'Downloads']]
   tag = data['tag_name']
   for x in data['assets']:
      name = x['name']
      s = []

      p = 'ghdl-gpl-'+tag[1:]
      if name[0:len(p)] == p:
         s = ['gpl', 'mcode']

      p = 'ghdl-'+tag[1:]
      if name[0:len(p)] == p:
         s = name[len(p)+1:-4].split('-',1)

      if len(s) > 1:
         assets.append([
            prettyOS(s[0]),
            prettyBackend(s[1]),
            (str(round(x['size']/1024**2, 2))+' MB').rjust(8),