@ -5,43 +5,28 @@ from amaranth import *
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					from amaranth.asserts import *
 
					 
					 
					 
					from amaranth.asserts import *
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					from power_fv import pfv
 
					 
					 
					 
					from power_fv import pfv
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					from power_fv.checks import *
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					from power_fv.tb import Testbench
 
					 
					 
					 
					from power_fv.tb import Testbench
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					from power_fv.build import SymbiYosysPlatform
 
					 
					 
					 
					from power_fv.build import SymbiYosysPlatform
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					from _wrapper import MicrowattWrapper
 
					 
					 
					 
					from _wrapper import MicrowattWrapper
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					class SmokeCheck(Elaboratable):
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    def __init__(self, mode="bmc"):
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        self.mode = mode
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        self.pre  = Signal()
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        self.post = Signal()
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        self.pfv  = pfv.Interface()
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    def elaborate(self, platform):
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        m = Module()
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        if self.mode == "bmc":
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					            with m.If(self.pre):
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					                m.d.comb += Assume(self.pfv.stb)
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        if self.mode == "cover":
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					            m.d.comb += Cover(self.pfv.stb)
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        return m
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					if __name__ == "__main__":
 
					 
					 
					 
					if __name__ == "__main__":
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    parser = argparse.ArgumentParser()
 
					 
					 
					 
					    parser = argparse.ArgumentParser()
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					    parser.add_argument("check", help="check", type=str, choices=("unique"))
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    parser.add_argument("--mode", help="mode", type=str, choices=("cover", "bmc"), default="bmc")
 
					 
					 
					 
					    parser.add_argument("--mode", help="mode", type=str, choices=("cover", "bmc"), default="bmc")
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    parser.add_argument("--pre",  help="pre-condition step, in clock cycles (default: 10)",  type=int, default=10)
 
					 
					 
					 
					    parser.add_argument("--pre",  help="pre-condition step, in clock cycles (default: 15)",  type=int, default=15)
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					    parser.add_argument("--post", help="post-condition step, in clock cycles (default: 10)", type=int, default=10)
 
					 
					 
					 
					    parser.add_argument("--post", help="post-condition step, in clock cycles (default: 15)", type=int, default=15)
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    args = parser.parse_args()
 
					 
					 
					 
					    args = parser.parse_args()
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    microwatt   = MicrowattWrapper()
 
					 
					 
					 
					    check = None
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					    smoke_check = SmokeCheck(mode=args.mode)
 
					 
					 
					 
					    if args.check == "unique":
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					    smoke_tb    = Testbench(smoke_check, microwatt, t_pre=args.pre, t_post=args.post)
 
					 
					 
					 
					        check = UniquenessCheck() if args.mode == "bmc" else UniquenessCover()
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					    cpu       = MicrowattWrapper()
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					    testbench = Testbench(check, cpu, t_pre=args.pre, t_post=args.post)
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    platform  = SymbiYosysPlatform()
 
					 
					 
					 
					    platform  = SymbiYosysPlatform()
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    microwatt_files = [
 
					 
					 
					 
					    microwatt_files = [
 
				
			 
			
		
	
	
		
		
			
				
					
						
							
								 
							 
						
						
							
								 
							 
						
						
					 
					 
					@ -77,6 +62,9 @@ if __name__ == "__main__":
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        "utils.vhdl",
 
					 
					 
					 
					        "utils.vhdl",
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        "wishbone_types.vhdl",
 
					 
					 
					 
					        "wishbone_types.vhdl",
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        "writeback.vhdl",
 
					 
					 
					 
					        "writeback.vhdl",
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					        "powerfv_types.vhdl",
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					        "powerfv.vhdl",
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    ]
 
					 
					 
					 
					    ]
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    for filename in microwatt_files:
 
					 
					 
					 
					    for filename in microwatt_files:
 
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -85,8 +73,11 @@ if __name__ == "__main__":
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    platform.add_file("microwatt_top.vhdl", open(os.path.join(os.curdir, "microwatt_top.vhdl"), "r"))
 
					 
					 
					 
					    platform.add_file("microwatt_top.vhdl", open(os.path.join(os.curdir, "microwatt_top.vhdl"), "r"))
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    platform.build(smoke_tb, name="smoke_tb", build_dir="build/smoke",
 
					 
					 
					 
					    platform.build(testbench,
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					        ghdl_opts="--std=08 --no-formal",
 
					 
					 
					 
					        name      = f"{args.check}_{args.mode}_tb",
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					        build_dir = f"build/{args.check}_{args.mode}",
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					        mode      = args.mode,
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					        ghdl_opts = "--std=08 --no-formal",
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        # TODO: investigate why combinatorial loops appear with `prep -flatten -nordff`
 
					 
					 
					 
					        # TODO: investigate why combinatorial loops appear with `prep -flatten -nordff`
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        prep_opts="-nordff",
 
					 
					 
					 
					        prep_opts = "-nordff",
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					    )
 
					 
					 
					 
					    )