zoukankan      html  css  js  c++  java
  • `define marcos usage in system verilog

    Note it is not supported in verilog

    http://en.wikipedia.org/wiki/SystemVerilog
    The preprocessor has improved `define macro-substitution capabilities, specifically substitution within literal-strings (""), as well as concatenation of multiple macro-tokens into a single word.
     

     link from 

    https://verificationacademy.com/forums/systemverilog/define-macros-usage
    http://www.verificationguild.com/modules.php?name=Forums&file=viewtopic&t=2541&view=previous 
    第三章 SystemVerilog文本值和数据类型SystemVerilog增加的类型在本章中包括以下
     
    1 `define xyz(I,R)
    2 assign abc[I].clk = R.du``I``_clk_x;
    `define xyz(I,R)
    assign abc(I).clk = ``R``.du``I``_clk_x;


    in the macro, R by itself is the argument that gets substituted. ``R`` is not needed.

    However, the argument I shows up twice in the body of the macro; first by itself, and then surrounded by ``I``. The `` is a token separator used to build identifiers and strings. Without it, the bare argument I would disappear into an identifier duI_clk_x. You want the macro

    `xyz(1,a)

    to be replaced with

    assign abc(1).clk = a.du1_clk_x;

     

    `define增强SystemVerilog中扩展了`define的功能,代替了宏定义的功能。
    3.2.1
    字符串中的宏变元替换(Macro argument substitution within strings)Verilog 的`define宏定义中可以用( ” ),则引号中的文字变成了文字型字符串。
    这就意味着,Verilog不能建立含有宏变元的字符串。
    如下例所示,不能按原本意愿展开。

    `define print(v)

    $display("variable v = %h", v)

    `print(data);

    该例中,将`print(data);展开,则为,$display(“variable v = %h”, data);。原本的意愿是,将宏定义中所有的‘v’都变成‘data’,但是,包含在双引号里的v并没有发生变化,所以在Verilog语言中不能实现以上的功能。

    SystemVerilog中能够实现宏变元的替换。应用重音符( ` )。

    举例:

    `define print(v)

    $display(`"variable v = %h`", v)

    `print(data);

    $display(“variable data = %h”, data);。

    Verilog中,若要在字符串中加入引号(单引号或双引号),则需在引号前加上字符“”。举例:$display("variable "data" = %h", data);

    当字符串中含宏变元时,只用"是不够的,则需要用`\`"。举例如下:

    `define print(v)

    $display(‘"variable ‘‘"v‘‘" = %h‘", v)

    `print(data);

    则宏展开为:

    $display("variable "data" = %h", data);

    3.2.2
    通过宏建立标识符名(Constructing identifier names from macros)SystemVerilog中可以通过( `` )将两个或更多的名字连接在一起形成新的名字。注意,重音符间无空格。

  • 相关阅读:
    string 流
    文件输入和输出
    IO类
    算法
    MySQL常用处理方法
    linux curl工具
    设计模式
    C语言编程流程
    js escape 与php escape
    js undefined易错分析
  • 原文地址:https://www.cnblogs.com/testset/p/3546073.html
Copyright © 2011-2022 走看看