story · 2020年08月27日

做EDA工具的深度用户之extend proc

来自微信公众号 “数字芯片实验室”

define\_proc\_attributes和parse\_proc\_arguments命令能够扩展tcl语言中proc的功能,创建和Synopsys命令一样具有help和属性的命令。

创建一个新的proc时,它具有以下固有属性:

•可以使用info body命令查看proc的内容

•proc可以被修改

•可以使用proc名称的缩写

•被放置在Procedures command group

通过使用define\_proc\_attributes命令, 可以

•指定命令的help文本

•指定参数规则

•是否禁止查看和修改

•是否禁止名称缩写

•指定command group

define\_proc\_attributes

使用define\_proc\_attributes命令来定义和更改proc的属性。其语法如下:

define_proc_attributes proc_name
[-info info_text]
[-define_args arg_defs]
[-command_group group_name]
[-hide_body]
[-hidden]
[-permanent]
[-dont_abbrev]

proc\_name 指定proc的名称

-info info\_text 指定与help命令或者-help选项一起使用的help文本

-define\_args arg\_defs 指定proc参数的help文本及其属性

-permanent 防止修改proc

-dont\_abbrev 无论sh\_command\_abbrev\_mode变量设置什么,都防止使用proc的名称缩写

可以使用-define\_args选项为该proc的参数指定help文本,并定义参数的数据类型和属性。

-define\_args的参数是列表的列表。每个列表元素指定proc参数的属性

每个列表元素具有以下格式:

arg_name option_help value_help data_type attributes

arg\_name 指定proc参数的名称

option\_help 参数的简短描述

value\_help 参数值的简短描述

data\_type 指定参数的数据类型

attributes 指定参数的其他属性

define\_proc\_attributes Command Example

proc plus {a b}
 {
 return [expr $a + $b]
 } 
 define_proc_attributes plus \ 
 -info "Add two numbers" \ 
 -define_args {
 {a "first addend" a stringrequired} \ 
 {b "second addend" b stringrequired} }

dc_shell> help  plus
plus                 # Add two numbers
 
dc_shell> help -verbose plus
Usage: plus # Add two numbers
a (first addend)
b (second addend)

dc_shell > plus 5 6
11

parse\_proc\_arguments

parse\_proc\_arguments命令可解析传递给proc的使用define\_proc\_attributes命令定义的参数。

通常,parse\_proc\_arguments是proc中第一个调用的命令来验证参数。不能在proc外使用parse\_proc\_arguments命令。

parse\_proc\_arguments的语法是

parse_proc_arguments -args arg_list result_array

-args arg\_list 指定传递给proc的参数列表。

result\_array 指定数组存储解析的参数。

proc plus { args }  ## 关键字 args 表示可变个数的参数
{parse_proc_arguments -args $args results    ## 将参数保存到数组中,数组名为 results,数组元素名字是参数名,元素值是参数值 
foreach argname [array names results] 
{
echo " $results($argname)"}
} 
define_proc_attributes plus \
-info "echo two numbers" \
-define_args {
{a "first addend" a string required} \
{b "second addend" b string required} }

plus显示了parse\_proc\_arguments的使用。plus接受各种类型的参数,然后打印出来。

dc_shell> plus  a b
a  b

另外可以通过

info body procedure\_name

info args procedure\_name

proc\_body procedure\_name

proc\_args procedure\_name

分别打印出proc的主体和参数

如果不使用parse\_proc\_arguments命令,则proc将无法响应-help选项。 但是,始终可以使用help命令。

本文转载自公众号:芯片数字实验室
原文链接:https://mp.weixin.qq.com/s/IjdR9MCGzcUs-1ndKRtgGw
未经作者同意,请勿转载!

推荐阅读

想了解更多内容,欢迎关注芯片数字实验室专栏,由于工具,你可以专注在更重要的事情上。
推荐阅读
关注数
12263
内容数
192
前瞻性的眼光,和持之以恒的学习~
目录
极术微信服务号
关注极术微信号
实时接收点赞提醒和评论通知
安谋科技学堂公众号
关注安谋科技学堂
实时获取安谋科技及 Arm 教学资源
安谋科技招聘公众号
关注安谋科技招聘
实时获取安谋科技中国职位信息