搜档网
当前位置:搜档网 › 结构化文本语言编译器的虚拟机指令设计与优化

结构化文本语言编译器的虚拟机指令设计与优化

敬请登录网站在线投稿2018年第5期

23

结构化文本语言编译器的虚拟机指令设计与优化

陈宏君,张磊

(南京南瑞继保电气有限公司,南京211102)

摘要:针对自主开发IEC61131结构化文本(ST)语言编译器的需求,设计了一套机器无关的虚拟机指令集,指令集按照数据传送二算术运算二逻辑运算二位操作二比较操作二流程控制二函数调用等类型划分,采用三地址码的四元式表示三基于该指令集,设计了结构化文本语言的IF语句二FOR语句二CASE语句二EXIT语句的指令形成算法,编译器将结构化文本语言编译为二进制指令文件三针对FOR语句提出了 向上计数 二 向下计数 二 动态确定上下限 的3种翻译模式,针对CASE语句提出了基于短路求值和跳转表混合的翻译模式,可优化FOR语句二CASE语句的指令结构三对编译形成的二进制指令,采用常量折叠计算二代数简化二临时变量消除二引用点分析等手段,进一步优化指令三实验测试结果表明,优化后的指令在嵌入式工控装置中的解释执行时提升了效率三

关键词:结构化文本;虚拟机指令;三地址码;指令优化

中图分类号:TP314 文献标识码:A

Desi g n and O p timization of Virtual M achine Instruction for Structured T ext Lan g ua g e Com p iler

Chen Hon gj un,Zhan g Lei

(NR Electric Co.,Ltd.,Nan j in g211102,China)

Abstract:In order to inde p endentl y develo p the IEC61131structured text(ST)lan g ua g e com p iler,a virtual machine instruction set irrel-evant to the machine is develo p ed,which is classified b y functions such as data transmission,arithmetic o p eration,lo g ic o p eration,bit o p-eration,com p are o p eration,p rocess control and function call,and the q uaternar y re p resentation of three-address code is ado p ted.Based on the instruction set,the instruction formin g al g orithms for IF,FOR,CASE and EXIT statements of structured text are desi g ned,and the com p iler can com p ile the lan g ua g e of the structured text into binar y instruction files.Moreover,three translation modes are p ut forward for the For statement,named Count U p , Count Down and D y namicall y Determine U pp er and Lower ,and the translation mode based on the mixture of short-circuit evaluation and j um p table are p ut forward,which can o p timize the instruction structure of FOR and CASE statements.In addition,the binar y instructions formed in com p ilation are further o p timized b y the constant foldin g o p eration,al g e-braic sim p lification,tem p orar y variable elimination,invocation p oint anal y sis and other a pp roaches.The test results show that the o p ti-mized instructions have im p roved the efficienc y of inter p retation and execution in the embedded industrial control devices.

Ke y words:structure text;virtual machine instruction;three address code;instruction o p timization

引言

IEC61131是国际电工委员会(IEC)颁布的可编程控制器(PLC)国际标准,用于规范可编程控制器编程工具和应用程序的开发,目的是便于各厂家的应用程序移植,降低用户的使用难度和维护成本[1-5]三其中IEC61131-3为软件设计提供了标准化的编程概念和编程方法,定义了指令表IL二结构化文本ST二梯形图LD二功能块图FBD二顺序功能图SFC几种语言的规范,国内外工控厂家二研究机构已经开始提供基于该标准的产品[6-8]三参考文献[9-10]介绍了嵌入式软PLC系统的架构,参考文献[11]提出一种将ST语言转换为IL指令的方法,参考文献[12]设计了ST的文法分析器,上述资料文献推进了IEC61131在国内的研究进程三ST有标准的关键字和语法结构,可用于复杂逻辑设计实现,通常有将ST语句直接编译为硬件相关的目标可执行文件或者将ST转换为C语言后再调用第三方编译的处理方法,这种方法执行效率较高,但无法满足以程序组织单元(POU)为单位的在线无扰更新的需求三在一些工控应用场合中,当装置处于运行状态时,需要能实现部分程序的下载更新和生效,不能将整个程序编译为1个目标文件,而是需要编译为与机器无关的虚拟机指令,在嵌入式装置侧的非实时任务中进行指令文件更新,在实时任务中解释执行三针对上述需求,需要定义一套指令集,开发自主编译器,本文介绍了指令集设计和对

万方数据

相关主题