我想创建一个只能在build_phase()期间调用的函数。 (在其他阶段进行调用会产生致命错误。)
如何找出我所在的uvm_phase?
答案 0 :(得分:4)
您在中的阶段由* _phase方法的阶段参数表示。没有单个状态表示当前状态,因为UVM具有可以同时活动的许多可能的相域。因此,在调用它时,您必须将阶段传递给函数:
function void my_function(uvm_phase phase);
if (!phase.is(uvm_build_phase::get()) `uvm_fatal(...);
endfunction
或者,如果此函数是从uvm_component派生的类的方法,则可以覆盖phase_started方法
class my_component extends uvm_component;
protected uvm_phase m_current_phase
function void phase_started(uvm_phase phase);
super.phase_started(phase);
m_current_phase = phase;
endfunction : phase_started
function void my_function(..);
if (!m_current_phase.is(uvm_build_phase::get()) `uvm_fatal(...);
endfunction
答案 1 :(得分:1)
class test extends uvm_test;
function void print_cur_phase();
m_current_phase.print();
endfunction // print_cur_phase
function void build_phase(uvm_phase phase);
print_cur_phase();
endfunction // build_phase
task run_phase(uvm_phase phase);
print_cur_phase();
endtask
// ...
endclass
中有一个名为# Gems
gem 'ckeditor', github: 'galetahub/ckeditor'
gem 'mini_magick'
gem 'carrierwave'
gem 'cloudinary'
# Uploader
class CkeditorPictureUploader < CarrierWave::Uploader::Base
include Ckeditor::Backend::CarrierWave
include Cloudinary::CarrierWave
include CarrierWave::MiniMagick
[:extract_content_type, :set_size, :read_dimensions].each do |method|
define_method :"#{method}_with_cloudinary" do
send(:"#{method}_without_cloudinary") if self.file.is_a?(CarrierWave::SanitizedFile)
{}
end
alias_method_chain method, :cloudinary
end
# ckeditor/config.js
// The location of an external file browser, that should be launched when "Browse Server" button is pressed.
config.filebrowserBrowseUrl = "/ckeditor/attachment_files";
// The location of an external file browser, that should be launched when "Browse Server" button is pressed in the Flash dialog.
config.filebrowserFlashBrowseUrl = "/ckeditor/attachment_files";
// The location of a script that handles file uploads in the Flash dialog.
config.filebrowserFlashUploadUrl = "/ckeditor/attachment_files";
// The location of an external file browser, that should be launched when "Browse Server" button is pressed in the Link tab of Image dialog.
config.filebrowserImageBrowseLinkUrl = "/ckeditor/pictures";
// The location of an external file browser, that should be launched when "Browse Server" button is pressed in the Image dialog.
config.filebrowserImageBrowseUrl = "/ckeditor/pictures";
// The location of a script that handles file uploads in the Image dialog.
config.filebrowserImageUploadUrl = "/ckeditor/pictures";
// The location of a script that handles file uploads.
config.filebrowserUploadUrl = "/ckeditor/attachment_files";
config.allowedContent = true;
# In the forms:
<%= f.cktext_area :body, class: 'form-control ckeditor' %>
的字段,其中包含最近执行的阶段。该字段在技术上不是标准API的一部分,但评论显示开发人员正在考虑为其添加一个访问器:
def public_id
return model.user.id
end
最便携的方法是定义你自己的变量,就像戴夫在答案中所表达的那样。
答案 2 :(得分:1)
uvm_component :: new检查build_phase完成后是否创建了组件(删除了错误消息):
begin
uvm_phase bld;
uvm_domain common;
common = uvm_domain::get_common_domain();
bld = common.find(uvm_build_phase::get());
if (bld == null)
uvm_report_fatal(...);
if (bld.get_state() == UVM_PHASE_DONE) begin
uvm_report_fatal(...);
end
end
这使用公共域和uvm_build_phase的单例getter,因此您不需要在本地手动跟踪任何阶段启动/状态,并且可以在调用函数时检查这些。