You are on page 1of 2

import uvm_pkg::*;

`include "uvm_macros.svh"

class instruction extends uvm_sequence_item;


typedef enum {PUSH_A,PUSH_B,ADD,SUB,MUL,DIV,POP_C} inst_t;
rand inst_t inst;

`uvm_object_utils_begin(instruction)
`uvm_field_enum(inst_t,inst, UVM_ALL_ON)
`uvm_object_utils_end

function new (string name = "instruction");


super.new(name);
endfunction

endclass

class producer extends uvm_component;


uvm_blocking_put_port#(instruction) tlm_put;

`uvm_component_utils(producer)

function new(string name = "producer", uvm_component parent = null);


super.new(name, parent);
tlm_put = new("tlm_put", this);
endfunction

task run_phase(uvm_phase phase);


super.run_phase(phase);
for(int i = 0; i < 10; i++)
begin
instruction ints;
#10;
ints = new();
if(ints.randomize()) begin
`uvm_info("producer", $sformatf("sending %s",ints.inst.name()),
UVM_MEDIUM)
tlm_put.put(ints);
end
end
endtask

endclass

class consumer extends uvm_component;


uvm_blocking_put_imp #(instruction, consumer) tlm_imp;

`uvm_component_utils(consumer)

function new(string name = "consumer", uvm_component parent = null);


super.new(name, parent);
tlm_imp = new("tlm_imp", this);
endfunction

virtual task put(instruction t);


`uvm_info("consumer", $sformatf("receiving %s",t.inst.name()), UVM_NONE)
endtask

endclass

class env extends uvm_env;


producer pro;
consumer con;
`uvm_component_utils(env)

function new(string name = "env", uvm_component parent = null);


super.new(name, parent);
endfunction

function void build_phase(uvm_phase phase);


super.build_phase(phase);
pro = producer::type_id::create("pro", this);
con = consumer::type_id::create("con", this);
endfunction

function void connect_phase(uvm_phase phase);


super.connect_phase(phase);
pro.tlm_put.connect(con.tlm_imp);
endfunction
endclass

class test extends uvm_test;


env env_o;
`uvm_component_utils(test)

function new(string name = "test", uvm_component parent = null);


super.new(name, parent);
endfunction

function void build_phase(uvm_phase phase);


super.build_phase(phase);
env_o = env::type_id::create("env_o", this);
endfunction

task run_phase(uvm_phase phase);


phase.raise_objection(this);
#1000;
phase.drop_objection(this);
endtask
endclass

module tb_top;
initial begin
run_test("test");
end
endmodule

You might also like