私の検証環境では、同じフィールドを持つ 3 つの異なるレジスタがload_0
ありload_1
ますload_2
。これで、レジスタごとに同じ関数が 3 回複製され、1 行だけが異なります。
duplicated_func_0() {
value = timer_regs.load_0; //This is the only different line (in duplicated_func_1 - load_1 is substituted
...
};
同じ関数を 3 回複製するよりも、変数名 (インデックスのみが異なる) にアクセスするより良い方法はありますか? このようなもの:
not_duplicated_func(index : uint) {
value = timer_regs.load_%x; //Is there a way to put the input index in the variable name instead of %x?
};
あなたが提供できるどんな助けにも感謝します。