@@ -131,14 +131,12 @@ def __init__(self, resource, path, start, end, width):
131131 all (name and isinstance (name , str ) for name in flattened_path )):
132132 raise TypeError (f"Path must be a non-empty tuple of non-empty strings, not { path !r} " )
133133 if not isinstance (start , int ) or start < 0 :
134- raise TypeError ("Start address must be a non-negative integer, not {!r}"
135- .format (start ))
134+ raise TypeError (f"Start address must be a non-negative integer, not { start !r} " )
136135 if not isinstance (end , int ) or end <= start :
137- raise TypeError ("End address must be an integer greater than the start address, "
138- "not {!r}" . format ( end ) )
136+ raise TypeError (f "End address must be an integer greater than the start address, "
137+ f "not { end !r} " )
139138 if not isinstance (width , int ) or width < 0 :
140- raise TypeError ("Width must be a non-negative integer, not {!r}"
141- .format (width ))
139+ raise TypeError (f"Width must be a non-negative integer, not { width !r} " )
142140
143141 self ._resource = resource
144142 self ._path = tuple (path )
@@ -199,16 +197,13 @@ class MemoryMap:
199197 """
200198 def __init__ (self , * , addr_width , data_width , alignment = 0 , name = None ):
201199 if not isinstance (addr_width , int ) or addr_width <= 0 :
202- raise ValueError ("Address width must be a positive integer, not {!r}"
203- .format (addr_width ))
200+ raise ValueError (f"Address width must be a positive integer, not { addr_width !r} " )
204201 if not isinstance (data_width , int ) or data_width <= 0 :
205- raise ValueError ("Data width must be a positive integer, not {!r}"
206- .format (data_width ))
202+ raise ValueError (f"Data width must be a positive integer, not { data_width !r} " )
207203 if not isinstance (alignment , int ) or alignment < 0 :
208- raise ValueError ("Alignment must be a non-negative integer, not {!r}"
209- .format (alignment ))
204+ raise ValueError (f"Alignment must be a non-negative integer, not { alignment !r} " )
210205 if name is not None and not (isinstance (name , str ) and name ):
211- raise ValueError ("Name must be a non-empty string, not {!r}" . format ( name ) )
206+ raise ValueError (f "Name must be a non-empty string, not { name !r} " )
212207
213208 self ._addr_width = addr_width
214209 self ._data_width = data_width
@@ -267,32 +262,28 @@ def align_to(self, alignment):
267262 Implicit next address.
268263 """
269264 if not isinstance (alignment , int ) or alignment < 0 :
270- raise ValueError ("Alignment must be a non-negative integer, not {!r}"
271- .format (alignment ))
265+ raise ValueError (f"Alignment must be a non-negative integer, not { alignment !r} " )
272266 self ._next_addr = self ._align_up (self ._next_addr , max (alignment , self .alignment ))
273267 return self ._next_addr
274268
275269 def _compute_addr_range (self , addr , size , step = 1 , * , alignment ):
276270 if addr is not None :
277271 if not isinstance (addr , int ) or addr < 0 :
278- raise ValueError ("Address must be a non-negative integer, not {!r}"
279- .format (addr ))
272+ raise ValueError (f"Address must be a non-negative integer, not { addr !r} " )
280273 if addr % (1 << self .alignment ) != 0 :
281- raise ValueError ("Explicitly specified address {:#x} must be a multiple of "
282- "{:#x} bytes"
283- .format (addr , 1 << alignment ))
274+ raise ValueError (f"Explicitly specified address { addr :#x} must be a multiple of "
275+ f"{ 1 << alignment :#x} bytes" )
284276 else :
285277 addr = self ._align_up (self ._next_addr , alignment )
286278
287279 if not isinstance (size , int ) or size < 0 :
288- raise ValueError ("Size must be a non-negative integer, not {!r}"
289- .format (size ))
280+ raise ValueError (f"Size must be a non-negative integer, not { size !r} " )
290281 size = self ._align_up (max (size , 1 ), alignment )
291282
292283 if addr > (1 << self .addr_width ) or addr + size > (1 << self .addr_width ):
293- raise ValueError ("Address range {:#x}..{:#x} out of bounds for memory map spanning "
294- " range {:#x}..{:#x} ({} address bits) "
295- . format ( addr , addr + size , 0 , 1 << self .addr_width , self . addr_width ) )
284+ raise ValueError (f "Address range { addr :#x} ..{ addr + size :#x} out of bounds for "
285+ f"memory map spanning range { 0 :#x} ..{ 1 << self . addr_width :#x} "
286+ f"( { self .addr_width } address bits)" )
296287
297288 addr_range = range (addr , addr + size , step )
298289 overlaps = self ._ranges .overlaps (addr_range )
@@ -301,14 +292,14 @@ def _compute_addr_range(self, addr, size, step=1, *, alignment):
301292 for overlap in overlaps :
302293 if id (overlap ) in self ._resources :
303294 _ , _ , resource_range = self ._resources [id (overlap )]
304- overlap_descrs .append ("resource {!r} at {:#x}..{:#x} "
305- . format ( overlap , resource_range . start , resource_range .stop ) )
295+ overlap_descrs .append (f "resource { overlap !r} at { resource_range . start :#x} .."
296+ f" { resource_range .stop :#x } " )
306297 if id (overlap ) in self ._windows :
307298 _ , window_range = self ._windows [id (overlap )]
308- overlap_descrs .append ("window {!r} at {:#x}..{:#x} "
309- . format ( overlap , window_range . start , window_range .stop ) )
310- raise ValueError ("Address range {:#x}..{:#x} overlaps with {}"
311- . format ( addr , addr + size , ", " .join (overlap_descrs ) ))
299+ overlap_descrs .append (f "window { overlap !r} at { window_range . start :#x} .."
300+ f" { window_range .stop :#x } " )
301+ raise ValueError (f "Address range { addr :#x} ..{ addr + size :#x} overlaps with " +
302+ ", " .join (overlap_descrs ))
312303
313304 return addr_range
314305
@@ -355,16 +346,15 @@ def add_resource(self, resource, *, name, size, addr=None, alignment=None):
355346 this memory map.
356347 """
357348 if self ._frozen :
358- raise ValueError ("Memory map has been frozen. Cannot add resource {!r}"
359- .format (resource ))
349+ raise ValueError (f"Memory map has been frozen. Cannot add resource { resource !r} " )
360350
361351 if not isinstance (resource , wiring .Component ):
362352 raise TypeError (f"Resource must be a wiring.Component, not { resource !r} " )
363353
364354 if id (resource ) in self ._resources :
365355 _ , _ , addr_range = self ._resources [id (resource )]
366- raise ValueError ("Resource {!r} is already added at address range {:#x}..{:#x} "
367- . format ( resource , addr_range .start , addr_range .stop ) )
356+ raise ValueError (f "Resource { resource !r} is already added at address range "
357+ f" { addr_range .start :#x } .. { addr_range .stop :#x } " )
368358
369359 if not (name and isinstance (name , tuple ) and
370360 all (part and isinstance (part , str ) for part in name )):
@@ -380,8 +370,7 @@ def add_resource(self, resource, *, name, size, addr=None, alignment=None):
380370
381371 if alignment is not None :
382372 if not isinstance (alignment , int ) or alignment < 0 :
383- raise ValueError ("Alignment must be a non-negative integer, not {!r}"
384- .format (alignment ))
373+ raise ValueError (f"Alignment must be a non-negative integer, not { alignment !r} " )
385374 alignment = max (alignment , self .alignment )
386375 else :
387376 alignment = self .alignment
@@ -470,33 +459,28 @@ def add_window(self, window, *, addr=None, sparse=None):
470459 conflicts with the name of others present in this memory map.
471460 """
472461 if not isinstance (window , MemoryMap ):
473- raise TypeError ("Window must be a MemoryMap, not {!r}"
474- .format (window ))
462+ raise TypeError (f"Window must be a MemoryMap, not { window !r} " )
475463
476464 if self ._frozen :
477- raise ValueError ("Memory map has been frozen. Cannot add window {!r}"
478- .format (window ))
465+ raise ValueError (f"Memory map has been frozen. Cannot add window { window !r} " )
479466
480467 if id (window ) in self ._windows :
481468 _ , addr_range = self ._windows [id (window )]
482- raise ValueError ("Window {!r} is already added at address range {:#x}..{:#x} "
483- . format ( window , addr_range .start , addr_range .stop ) )
469+ raise ValueError (f "Window { window !r} is already added at address range "
470+ f" { addr_range .start :#x } .. { addr_range .stop :#x } " )
484471
485472 if window .data_width > self .data_width :
486- raise ValueError ("Window has data width {}, and cannot be added to a memory map "
487- "with data width {}"
488- .format (window .data_width , self .data_width ))
473+ raise ValueError (f"Window has data width { window .data_width } , and cannot be added to a "
474+ f"memory map with data width { self .data_width } " )
489475 if window .data_width != self .data_width :
490476 if sparse is None :
491- raise ValueError ("Address translation mode must be explicitly specified "
492- "when adding a window with data width {} to a memory map "
493- "with data width {}"
494- .format (window .data_width , self .data_width ))
477+ raise ValueError (f"Address translation mode must be explicitly specified when "
478+ f"adding a window with data width { window .data_width } to a "
479+ f"memory map with data width { self .data_width } " )
495480 if not sparse and self .data_width % window .data_width != 0 :
496- raise ValueError ("Dense addressing cannot be used because the memory map "
497- "data width {} is not an integer multiple of window "
498- "data width {}"
499- .format (self .data_width , window .data_width ))
481+ raise ValueError (f"Dense addressing cannot be used because the memory map "
482+ f"data width { self .data_width } is not an integer multiple of "
483+ f"window data width { window .data_width } " )
500484
501485 queries = window ._namespace .names () if window .name is None else ((window .name ,),)
502486 reasons = []
@@ -564,10 +548,10 @@ def window_patterns(self):
564548 for window , (window_start , window_stop , window_ratio ) in self .windows ():
565549 const_bits = self .addr_width - window .addr_width
566550 if const_bits > 0 :
567- const_pat = "{:0{}b}" . format ( window_start >> window .addr_width , const_bits )
551+ const_pat = f" { window_start >> window .addr_width :0{ const_bits }b } "
568552 else :
569553 const_pat = ""
570- pattern = "{}{}" . format ( const_pat , "-" * window .addr_width )
554+ pattern = const_pat + "-" * window .addr_width
571555 yield window , (pattern , window_ratio )
572556
573557 @staticmethod
0 commit comments