import binascii

def generate_golden_vectors():
    test_cases = [
        # 1. Standard Check (ASCII "123456789")
        b"123456789",
        # 2. Empty (Initial state check)
        b"",
        # 3. Single Bytes
        b"\x00",
        b"\xFF",
        b"A",
        # 4. Short Sequences
        b"CRC",
        b"Hello",
        # 5. Patterns
        bytes(range(256)),  # 00-FF
        b"\xAA" * 16,       # Alternating 1010...
        b"\x55" * 16,       # Alternating 0101...
        # 6. Random-ish
        b"\xde\xad\xbe\xef",
        b"The quick brown fox jumps over the lazy dog",
    ]

    print("// Golden Vectors (Generated by Python binascii.crc32)")
    print(f"localparam NUM_TESTS = {len(test_cases)};")
    print("reg [31:0] expected_crc [0:NUM_TESTS-1];")
    # We need a flat array for data bytes, and a way to know length/offset for each test
    # Or simpler: we can just hardcode the test sequences in the testbench logic 
    # based on these values.
    # Let's output arrays for data and length.
    
    # Calculate total bytes needed
    total_bytes = sum(len(tc) for tc in test_cases)
    print(f"localparam TOTAL_BYTES = {total_bytes};")
    print("reg [7:0] test_data [0:TOTAL_BYTES-1];")
    print("reg [31:0] test_len [0:NUM_TESTS-1];")
    print("reg [31:0] test_start_idx [0:NUM_TESTS-1];")
    
    print("\ninitial begin")
    current_idx = 0
    for i, data in enumerate(test_cases):
        crc = binascii.crc32(data) & 0xffffffff
        print(f"    // Test {i}: '{data[:20]!r}...' -> 0x{crc:08X}")
        print(f"    expected_crc[{i}] = 32'h{crc:08X};")
        print(f"    test_len[{i}] = {len(data)};")
        print(f"    test_start_idx[{i}] = {current_idx};")
        for b in data:
            print(f"    test_data[{current_idx}] = 8'h{b:02X};", end="")
            current_idx += 1
        print("")
    print("end")

if __name__ == "__main__":
    generate_golden_vectors()
