This is super ugly, but it's necessary to get Chisel3 to compile. Note that this still fails simulations in Chisel3, so it might be wrong.