new_contents:
function Bit#(n) removeDontCares(Bit#(n) num);
    Bit#(n) res = 0;
    for(Integer i = 0; i < valueOf(n); i = i + 1)
        res[i] = (num[i] == 1'b1) ? 1'b1 : 1'b0;
    return res;
endfunction

function String toHex(Bit#(n) num)
provisos (
    Div#(n   , 4, ndig),
    Mul#(ndig, 4, nadj),
    Add#(pad , n, nadj)
);
    String dig[16] = {"0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"};
    Bit#(nadj) numadj = extend(removeDontCares(num));
    String res = "";
    for(Integer i = valueOf(nadj) - 1; i >= 0; i = i - 4) begin
        Bit#(4) dign = numadj[i:i-3];
        res = res + dig[dign];
    end
    return res;
endfunction

message:
Implement toHex supporting don't-care bits

Previously, don't-care bits would trigger an infinite loop during the elaboration phase.

license: mit

repos: thotypous/altsourceprobe


old_contents:
import Ethernet::*;

(* always_ready, always_enabled *)
interface DE5Pins;
   method Action osc_50(Bit#(1) b3d, Bit#(1) b4a, Bit#(1) b4d, Bit#(1) b7a, Bit#(1) b7d, Bit#(1) b8a, Bit#(1) b8d);
   method Action sfp(Bit#(1) refclk);
   method Action buttons(Bit#(4) v);
//   method Bit#(4) serial_tx_data;
//   method Action serial_rx(Bit#(4) data);
   interface SFPCtrl#(4) sfpctrl;
//   method Bit#(1) led0;
//   method Bit#(1) led1;
//   method Bit#(1) led2;
   method Bit#(1) led3;
   method Bit#(4) led_bracket;
   interface Clock deleteme_unused_clock;
   interface Clock deleteme_unused_clock2;
   interface Clock deleteme_unused_clock3;
   interface Reset deleteme_unused_reset;
endinterface

new_contents:
import Ethernet::*;

(* always_ready, always_enabled *)
interface DE5Pins;
   method Action osc_50(Bit#(1) b3d, Bit#(1) b4a, Bit#(1) b4d, Bit#(1) b7a, Bit#(1) b7d, Bit#(1) b8a, Bit#(1) b8d);
   method Action sfp(Bit#(1) refclk);
   method Action buttons(Bit#(4) v);
//   method Bit#(4) serial_tx_data;
//   method Action serial_rx(Bit#(4) data);
   interface SFPCtrl#(4) sfpctrl;
   method Bit#(1) led0;
//   method Bit#(1) led1;
//   method Bit#(1) led2;
   method Bit#(1) led3;
   method Bit#(4) led_bracket;
`ifndef BSIM
   interface Clock deleteme_unused_clock;
   interface Clock deleteme_unused_clock2;
   interface Clock deleteme_unused_clock3;
   interface Reset deleteme_unused_reset;
   `endif
endinterface

subject: Fix "Attempt to use this undetermined clock" Error