如何检测编译器

发布于 2024-12-25 09:04:26 字数 287 浏览 0 评论 0原文

我必须从文件加载 ROM。 Quartus 可以直接使用 .mif 文件,对于模拟器,我在 textio 的帮助下编写了(一个快速而肮脏的).mif 文件解析器。有没有办法检测合成器工具(在我的例子中是 Quartus)并仅在合成器工具未编译时生成 textio 文件加载器进程?

来源问题

I have to load ROM from file. Quartus can use .mif files directly and for the simulator I have written (a quick and dirty) .mif file parser with the help of textio. Is there a way to detect Synthesizer tools (Quartus in my case) and to generate textio file loader process only if it is not being compiled by the Synthesizer tool?

(the source question)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

吻泪 2025-01-01 09:04:26

您可以使用仅被您的特定综合工具接受的编译指示来检测综合工具。例如,您可以这样写:

constant isQuartus : std_logic := '1'
-- altera translate_off
and '0'
-- altera translate_on
;

仅当您使用 Altera 的 Quartus 综合时,该常量才为 '1'

有关各种 VHDL 元注释编译指示的更多信息,请访问:http://www.sigasi。 com/content/list-known-vhdl-metacomment-pragmas

You can detect the synthesis tool by using a pragma that is only accepted by your specific synthesis tool. For example, you can write:

constant isQuartus : std_logic := '1'
-- altera translate_off
and '0'
-- altera translate_on
;

This constant will be '1' only if you synthesize this using Altera's Quartus.

More about the various VHDL metacomment pragma's at: http://www.sigasi.com/content/list-known-vhdl-metacomment-pragmas

胡大本事 2025-01-01 09:04:26

您是否尝试从代码中推断 ROM?如果您使用 LPM 功能,一切都应该“正常工作”。

我在 Quartus 和 ModelSim 中使用 ROM 没有问题。只需使用 MegaWizard 插件为您的 ROM 创建一个自定义 VHDL 文件并将其定向到适当的初始化文件,或者直接实例化 altsyncram 组件并包含 init_file 通用文件。

然后正常编译或模拟。我使用带有初始化 ROM 的 ModelSim(Altera 版本或独立版本)运行仿真没有任何问题,并且不必编写任何初始化代码来读取 *.mif 或 *.hex 文件。

作为参考,这里是一个直接实例化的 ROM 宏功能,来自我的一些代码,可以在 ModelSim 中正确模拟(注意 init_file 通用):

-- Sine lookup table
sine_lut : altsyncram
generic map (
    clock_enable_input_a    => "BYPASS",
    clock_enable_output_a   => "BYPASS",
    init_file               => "./video/sine_rom-512x8.mif",
    intended_device_family  => "Arria GX ",
    lpm_hint                => "ENABLE_RUNTIME_MOD=NO",
    lpm_type                => "altsyncram",
    numwords_a              => 512,
    operation_mode          => "ROM",
    outdata_aclr_a          => "NONE",
    outdata_reg_a           => "UNREGISTERED",
    widthad_a               => 9,
    width_a                 => 8,
    width_byteena_a         => 1
)
port map (
    -- Read port
    clock0      => clk,
    address_a   => sine_addr,
    q_a         => sine_do
);

如果您在模拟与综合时确实需要做一些不同的事情,有几种方法可以实现它。对于简单的事情,您可以使用类似以下指令的内容:

--synthesis translate-off
<code for simulation only>
--synthesis translate-on

http://quartushelp.altera.com/11.1/master.htm#mergedProjects/hdl/vhdl/vhdl_file_dir_translate.htm?GSA_pos=5&WT.oss_r=1&WT.oss=--%20synthesis %20translate_off

你应该能够找到很多现实世界的例子这些指令是通过互联网搜索找到的,我在下面提供了一个示例(模拟时的开机重置时间比在真实硬件中运行时的时间短):

-- Async. Power-on Reset, with de-assertion delay
process (clk)
begin
    if rising_edge (clk) then
        -- Create a delay at power-up
        if rst_PowerOn='1' then
            rst_pora    <= '1';
            rst_por_cnt <= (others=>'0');
        -- synthesis translate_off
        elsif rst_por_cnt(5)='1' then  -- 256 nS in simulation
            rst_pora    <= '0';
        -- synthesis translate_on
        elsif rst_por_cnt(19)='1' then -- 4ms in real hardware
            rst_pora    <= '0';
        else
            rst_por_cnt <= rst_por_cnt + 1;
        end if;
    end if;
end process;

对于更复杂的情况,请发挥您的想象力。有些人使用 C 预处理器、M4 宏语言或类似的东西作为综合/模拟之前的初步构建步骤。我有 makefile 和脚本,可将 FileName.sim.vhdl (用于模拟)转换为 FileName.vhdl (用于综合),使用一些文本实用程序对其进行处理,以根据我制定的规则注释/取消注释各种代码块,以便我可以维护两个版本都在一个文件中(想想类似于经过调整以与 VHDL 一起使用的增强型 C 预处理器)。只需做一些适合您的工作流程和团队动态/文化的事情即可。

Are you trying to infer ROMs from your code? If you're using the LPM functions, everything should "just work".

I use ROMs in Quartus and ModelSim without issue. Just create a custom VHDL file for your ROM using the MegaWizard plugin and direct it to the appropriate initialization file, or directly instantiate an altsyncram component and include the init_file generic.

Then compile or simulate as normal. I have had no problems running simulations using ModelSim (Altera version or stand-alone version) with initialized ROMs, and have not had to write any initialization code to read *.mif or *.hex files.

For reference, here is a directly instantiated ROM megafunction from a bit of my code that simulates properly in ModelSim (note the init_file generic):

-- Sine lookup table
sine_lut : altsyncram
generic map (
    clock_enable_input_a    => "BYPASS",
    clock_enable_output_a   => "BYPASS",
    init_file               => "./video/sine_rom-512x8.mif",
    intended_device_family  => "Arria GX ",
    lpm_hint                => "ENABLE_RUNTIME_MOD=NO",
    lpm_type                => "altsyncram",
    numwords_a              => 512,
    operation_mode          => "ROM",
    outdata_aclr_a          => "NONE",
    outdata_reg_a           => "UNREGISTERED",
    widthad_a               => 9,
    width_a                 => 8,
    width_byteena_a         => 1
)
port map (
    -- Read port
    clock0      => clk,
    address_a   => sine_addr,
    q_a         => sine_do
);

If you really need to do something different when simulating vs. synthesizing, there are a several ways to go about it. For simple things, you can use something like the following directives:

--synthesis translate-off
<code for simulation only>
--synthesis translate-on

http://quartushelp.altera.com/11.1/master.htm#mergedProjects/hdl/vhdl/vhdl_file_dir_translate.htm?GSA_pos=5&WT.oss_r=1&WT.oss=--%20synthesis%20translate_off

You should be able to find a lot of real-world examples of these directives via internet search, and I've included one example below (power-on reset is shorter when simulating vs. when running in real hardware):

-- Async. Power-on Reset, with de-assertion delay
process (clk)
begin
    if rising_edge (clk) then
        -- Create a delay at power-up
        if rst_PowerOn='1' then
            rst_pora    <= '1';
            rst_por_cnt <= (others=>'0');
        -- synthesis translate_off
        elsif rst_por_cnt(5)='1' then  -- 256 nS in simulation
            rst_pora    <= '0';
        -- synthesis translate_on
        elsif rst_por_cnt(19)='1' then -- 4ms in real hardware
            rst_pora    <= '0';
        else
            rst_por_cnt <= rst_por_cnt + 1;
        end if;
    end if;
end process;

For more complex situations, use your imagination. Some folks use the C pre-processor, the M4 macro language, or something similar as a preliminary build step prior to synthesis/simulation. I have makefiles and scripts that convert FileName.sim.vhdl (for simulation) into FileName.vhdl (for synthesis), processing it with some text utilities to comment/un-comment various blocks of code based on rules I crafted so I could maintain both versions in a single file (think something like an enhanced C pre-processor tweaked for use with VHDL). Just do something that fits with your workflow and team dynamics/culture.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文