Skip to content

Commit

Permalink
Merge pull request kevinpt#4 from daniellimws/antmicro-improvements
Browse files Browse the repository at this point in the history
Merge improvements from antmicro's fork
  • Loading branch information
mithro authored Nov 19, 2020
2 parents 974bd16 + 7723180 commit 97f24de
Showing 1 changed file with 33 additions and 11 deletions.
44 changes: 33 additions & 11 deletions symbolator.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,10 @@ def __init__(self, name, fill=None, line_color=(0,0,0)):
self.name = None

class_colors = {
'clocks': sinebow.lighten(sinebow.sinebow(0), 0.75), # Red
'data': sinebow.lighten(sinebow.sinebow(0.35), 0.75), # Green
'control': sinebow.lighten(sinebow.sinebow(0.15), 0.75) # Yellow
'clocks': sinebow.lighten(sinebow.sinebow(0), 0.75), # Red
'data': sinebow.lighten(sinebow.sinebow(0.35), 0.75), # Green
'control': sinebow.lighten(sinebow.sinebow(0.15), 0.75), # Yellow
'power': sinebow.lighten(sinebow.sinebow(0.07), 0.75) # Orange
}

if self.sect_class in class_colors:
Expand Down Expand Up @@ -256,11 +257,12 @@ def draw(self, x, y, c, sym_width=None):

class HdlSymbol(object):
'''Top level symbol object'''
def __init__(self, component=None, symbols=None, symbol_spacing=10, width_steps=20):
def __init__(self, component=None, libname=None, symbols=None, symbol_spacing=10, width_steps=20):
self.symbols = symbols if symbols is not None else []
self.symbol_spacing = symbol_spacing
self.width_steps = width_steps
self.component = component
self.libname = libname



Expand All @@ -276,13 +278,19 @@ def draw(self, x, y, c):
yoff = y
for i, s in enumerate(self.symbols):
bb = s.draw(x, y + yoff, c, sym_width)

if i == 0 and self.component:
if i==0 and self.libname:
# Add libname
c.create_text((bb[0]+bb[2])/2.0,bb[1] - self.symbol_spacing, anchor='cs',
text=self.libname, font=('Helvetica', 12, 'bold'))
elif i == 0 and self.component:
# Add component name
c.create_text((bb[0]+bb[2])/2.0,bb[1] - self.symbol_spacing, anchor='cs',
text=self.component, font=('Helvetica', 14, 'bold'))
text=self.component, font=('Helvetica', 12, 'bold'))

yoff += bb[3] - bb[1] + self.symbol_spacing
if self.libname is not None:
c.create_text((bb[0]+bb[2])/2.0,bb[3] + 2 * self.symbol_spacing, anchor='cs',
text=self.component, font=('Helvetica', 12, 'bold'))



Expand Down Expand Up @@ -335,9 +343,14 @@ def make_section(sname, sect_pins, fill, extractor, no_type=False):

return sect

def make_symbol(comp, extractor, title=False, no_type=False):
def make_symbol(comp, extractor, title=False, libname="", no_type=False):
'''Create a symbol from a parsed component/module'''
vsym = HdlSymbol() if title == False else HdlSymbol(comp.name)
if libname != "":
vsym = HdlSymbol(comp.name, libname)
elif title != False:
vsym = HdlSymbol(comp.name)
else:
vsym = HdlSymbol()

color_seq = sinebow.distinct_color_sequence(0.6)

Expand Down Expand Up @@ -386,6 +399,7 @@ def parse_args():
parser.add_argument('--title', dest='title', action='store_true', default=False, help='Add component name above symbol')
parser.add_argument('--no-type', dest='no_type', action='store_true', default=False, help='Omit pin type information')
parser.add_argument('-v', '--version', dest='version', action='store_true', default=False, help='Symbolator version')
parser.add_argument('--libname', dest='libname', action='store', default='', help='Add libname above cellname, and move component name to bottom. Works only with --title')

args, unparsed = parser.parse_known_args()

Expand All @@ -404,6 +418,10 @@ def parse_args():
print('Error: Output file is required when reading from stdin')
sys.exit(1)

if args.libname != '' and not args.title:
print("Error: '--tile' is required when using libname")
sys.exit(1)

args.scale = float(args.scale)

# Remove duplicates
Expand Down Expand Up @@ -546,12 +564,16 @@ def main():
# Render every component from every file into an image
for source, components in all_components.items():
for comp, extractor in components:
comp.name = comp.name.strip('_')
reformat_array_params(comp)
if source == '<stdin>':
fname = args.output
else:
base = os.path.splitext(os.path.basename(source))[0]
fname = '{}-{}.{}'.format(base, comp.name, args.format)
fname = '{}{}.{}'.format(
args.libname + "__" if args.libname is not None or args.libname != "" else "",
comp.name,
args.format)
if args.output:
fname = os.path.join(args.output, fname)
print('Creating symbol for {} "{}"\n\t-> {}'.format(source, comp.name, fname))
Expand All @@ -563,7 +585,7 @@ def main():
nc.set_surface(surf)
nc.clear_shapes()

sym = make_symbol(comp, extractor, args.title, args.no_type)
sym = make_symbol(comp, extractor, args.title, args.libname, args.no_type)
sym.draw(0,0, nc)

nc.render(args.transparent)
Expand Down

0 comments on commit 97f24de

Please sign in to comment.