Transaction Sınıfı
Gün 6: Bitirme Projesi - Bölüm 1 | ALU transaction paketi: constraint'ler ve metodlar
Kaynak Kod
// =============================================================================
// GUN 6 - Konu 2: Transaction (Islem) Paketi Sinifi
// =============================================================================
class ALU_Transaction;
// Islem kodlari (DUT ile uyumlu)
typedef enum logic [2:0] {
OP_ADD = 3'b000,
OP_SUB = 3'b001,
OP_AND = 3'b010,
OP_OR = 3'b011,
OP_XOR = 3'b100,
OP_NOT = 3'b101,
OP_SHL = 3'b110,
OP_SHR = 3'b111
} opcode_e;
// Rastgele giris degiskenleri
rand opcode_e opcode;
rand logic [7:0] operand_a;
rand logic [7:0] operand_b;
// Cikis degiskenleri (DUT'tan okunacak)
logic [15:0] result;
logic [3:0] flags;
logic out_valid;
// Meta veriler
int id;
static int count = 0;
// --- Kisitlamalar ---
constraint c_opcode_dist {
opcode dist {
OP_ADD := 20,
OP_SUB := 20,
OP_AND := 10,
OP_OR := 10,
OP_XOR := 10,
OP_NOT := 10,
OP_SHL := 10,
OP_SHR := 10
};
}
constraint c_corner_cases {
operand_a dist {
0 := 10,
[1:254] :/ 70,
255 := 10,
8'h80 := 10
};
operand_b dist {
0 := 10,
[1:254] :/ 70,
255 := 10,
8'h80 := 10
};
}
// Shift isleminde B sadece 0-7
constraint c_shift_range {
(opcode inside {OP_SHL, OP_SHR}) -> operand_b inside {[0:7]};
}
function new();
this.id = count++;
endfunction
function void display(string prefix = "");
$display(" %sTXN#%03d | %s | A=0x%02h | B=0x%02h | Res=0x%04h | Flags=%04b | V=%0b",
prefix, id, opcode.name(), operand_a, operand_b, result, flags, out_valid);
endfunction
function ALU_Transaction copy();
ALU_Transaction t = new();
t.opcode = this.opcode;
t.operand_a = this.operand_a;
t.operand_b = this.operand_b;
t.result = this.result;
t.flags = this.flags;
t.out_valid = this.out_valid;
t.id = this.id;
return t;
endfunction
endclass