Coverage for apio/scons/report_xilinx.py: 0%

20 statements  

« prev     ^ index     » next       coverage.py v7.14.3, created at 2026-06-24 03:51 +0000

1""" 

2This script is called by the `nextpnr-xilinx` tool for generating 

3a report, because it lacks the option `--report` 

4""" 

5 

6import json 

7import os 

8from pathlib import Path 

9 

10 

11# -- DEBUG: show all the env variables 

12# variables = os.environ 

13# print(f"{'VARIABLE':<30} | {'VALUE'}") 

14# print("-" * 80) 

15 

16# # Short it alfabetically 

17# for key in sorted(variables.keys()): 

18# value = variables[key] 

19# print(f"{key:<30} | {value}") 

20 

21# import sys 

22# sys.exit() 

23 

24# -- Read the ENV_BUILD_PATH variable, with the build environment folder 

25env_build_path = Path(os.environ["ENV_BUILD_PATH"]) 

26# print(f"* env_build_path: {env_build_path}") 

27 

28# -- Report file 

29report_file = env_build_path / "hardware.pnr" 

30 

31# -- Ignore pylint errores 

32# pylint: disable=self-assigning-variable 

33# pylint: disable=undefined-variable 

34# pylint: disable=invalid-name 

35 

36# -- Ignore all hte pylance and Flake8 errors related to 

37# -- ctx (that is generated dynamically when calling nextpnr-xilinx) 

38ctx = ctx # noqa: F821 # pyright: ignore[reportUndefinedVariable] 

39 

40# -- Collect total FPGA resources 

41resources_total = {} 

42 

43for bel in ctx.getBels(): 

44 bel_type = ctx.getBelType(bel) 

45 resources_total[bel_type] = resources_total.get(bel_type, 0) + 1 

46 

47# -- Actual resources used by the current design 

48resources_used = {} 

49# pyright: ignore[reportUndefinedVariable] 

50for cell_name, cell_info in ctx.cells: 

51 cell_type = str(cell_info.type) 

52 resources_used[cell_type] = resources_used.get(cell_type, 0) + 1 

53 

54# -- Build the final blank report json file 

55report = {"critical_paths": [], "fmax": {}, "utilization": {}} 

56 

57# --- Fill in the report json 

58for res, amount in resources_used.items(): 

59 cell = {"available": resources_total[res], "used": amount} 

60 report["utilization"][res] = cell 

61 # print(f"* {res}: {amount} / {resources_total[res]}") 

62 

63# -- Generate the report file 

64with open(report_file, "w", encoding="utf8") as f: 

65 json.dump(report, f, indent=4)