2323 LocalVariablesEnv ,
2424)
2525from .filters import FILTERS , ram_var
26- from .models import BuildConfig
26+ from .models import BuildConfig , Metadata
2727from .parser import (
2828 MlogError ,
2929 check_unsaved_variables ,
@@ -157,6 +157,8 @@ def build(
157157 include_memory = True
158158 include_debugger = True
159159
160+ meta = Metadata ()
161+
160162 config = BuildConfig .load (yaml_path )
161163
162164 if cpu_config_name :
@@ -183,6 +185,8 @@ def build(
183185 yaml_path .parent / "generated_config.mlog" ,
184186 ** config_args ,
185187 )
188+
189+ meta .uart_fifo_capacity = int (config_args ["UART_FIFO_CAPACITY" ])
186190 else :
187191 if include_memory :
188192 raise ValueError (
@@ -386,6 +390,7 @@ def add_with_label(block: Block, **labels: Unpack[Labels]):
386390 uart_links = list [ProcessorLink ]()
387391 for x in lenrange (5 , 4 , 2 ):
388392 for y in lenrange (18 , - 4 , - 2 ):
393+ meta .uarts .append ((x , y ))
389394 add_peripheral (simple_block (Content .MEMORY_BANK , x , y ))
390395 uart_links .append (ProcessorLink (x , y , "" ))
391396
@@ -407,6 +412,10 @@ def add_with_label(block: Block, **labels: Unpack[Labels]):
407412 incr_link = ProcessorLink (9 , 17 , "" )
408413 config_link = ProcessorLink (9 , 16 , "" )
409414
415+ meta .registers = (registers_link .x , registers_link .y )
416+ meta .csrs = (csrs_link .x , csrs_link .y )
417+ meta .config = (config_link .x , config_link .y )
418+
410419 add_with_label (
411420 simple_block (Content .MESSAGE , 11 , 19 ),
412421 left = "REGISTERS" ,
@@ -433,6 +442,11 @@ def add_with_label(block: Block, **labels: Unpack[Labels]):
433442 pause_switch_link = ProcessorLink (11 , 17 , "" )
434443 single_step_switch_link = ProcessorLink (11 , 16 , "" )
435444
445+ meta .error_output = (error_output_link .x , error_output_link .y )
446+ meta .power_switch = (power_switch_link .x , power_switch_link .y )
447+ meta .pause_switch = (pause_switch_link .x , pause_switch_link .y )
448+ meta .single_step_switch = (single_step_switch_link .x , single_step_switch_link .y )
449+
436450 add_peripheral (ram_schem , 13 , 16 )
437451 add_peripheral (ram_schem , 12 , 17 )
438452 add_peripheral (ram_schem , 13 , 17 )
@@ -474,6 +488,10 @@ def add_with_label(block: Block, **labels: Unpack[Labels]):
474488 controller_link = ProcessorLink (16 , 0 , "" )
475489
476490 if include_cpu :
491+ meta .cpu = (controller_link .x , controller_link .y )
492+ meta .cpu_width = width
493+ meta .cpu_height = height
494+
477495 schem .add_block (
478496 Block (
479497 block = Content .WORLD_PROCESSOR ,
@@ -545,19 +563,26 @@ def add_with_label(block: Block, **labels: Unpack[Labels]):
545563 else :
546564 data = bytes ()
547565
566+ base_x = config_link .x + config_args ["MEMORY_X_OFFSET" ]
548567 base_y = config_link .y + config_args ["MEMORY_Y_OFFSET" ]
549- for y in lenrange (
550- 0 ,
551- config_args ["PROGRAM_ROM_ROWS" ]
552- + config_args ["DATA_ROM_ROWS" ]
553- + config_args ["RAM_ROWS" ]
554- + config_args ["ICACHE_ROWS" ],
555- ):
556- for x in lenrange (
557- config_link .x + config_args ["MEMORY_X_OFFSET" ],
558- config_args ["MEMORY_WIDTH" ],
559- ):
560- if y < config_args ["PROGRAM_ROM_ROWS" ] + config_args ["DATA_ROM_ROWS" ]:
568+
569+ memory_width = config_args ["MEMORY_WIDTH" ]
570+ rom_height = config_args ["PROGRAM_ROM_ROWS" ] + config_args ["DATA_ROM_ROWS" ]
571+ memory_height = (
572+ rom_height + config_args ["RAM_ROWS" ] + config_args ["ICACHE_ROWS" ]
573+ )
574+
575+ meta .memory = (base_x , base_y )
576+ meta .memory_width = memory_width
577+ meta .memory_height = memory_height
578+
579+ meta .rom_processors = memory_width * rom_height
580+ meta .ram_processors = memory_width * config_args ["RAM_ROWS" ]
581+ meta .icache_processors = memory_width * config_args ["ICACHE_ROWS" ]
582+
583+ for y in lenrange (0 , memory_height ):
584+ for x in lenrange (base_x , memory_width ):
585+ if y < rom_height :
561586 if i < len (data ):
562587 payload = "" .join (chr (174 + c ) for c in data [i : i + 16384 ])
563588 i += 16384
@@ -617,8 +642,15 @@ def add_with_label(block: Block, **labels: Unpack[Labels]):
617642 )
618643
619644 if schem .tiles :
645+ _ , _ , x_offset , y_offset = schem .get_dimensions (offsets = True )
646+ schem .tags ["mlogv32_metadata" ] = meta .model_dump_json (
647+ exclude_defaults = True ,
648+ context = {"offsets" : (x_offset , y_offset )},
649+ )
650+
620651 w , h = schem .get_dimensions ()
621652 print (f"Schematic size: { w } x{ h } " )
653+
622654 if output :
623655 print (f"Writing schematic to file: { output } " )
624656 schem .write_file (str (output ))
0 commit comments