随着软件工程技术的进步与发展,模型驱动的软件开发方法越来越广泛地应用到各个领域。由于模型驱动开发具有门槛低、效率高以及安全性高的特性,不同领域软件的开发方式也由基于代码的开发向基于模型驱动逐渐转型。然而,目前的模型驱动开发工具普遍存在难以生成高质量代码、难以对动态数据流模型进行代码生成、难以充分利用处理器并行指令的问题。为此,本文设计了从代码生成框架到模型语义转换再到处理器并行指令生成的一套解决方案。主要研究内容如下:1.提出了模型中间表示、代码中间表示和一种分层的代码生成框架。模型中间表示可以兼容相似的模型语义,同时对差异较大的模型语义也具有良好的可扩展性。代码中间表示包含模型元素和代码语句的映射信息,可以方便地从代码追溯到模型元素。模型解析层将不同建模工具构建的模型转化为统一的模型中间表示。调度转换层将模型中间表示进行代码控制流转换,并输出代码中间表示。代码优化层对代码中间表示进行多阶段的优化。代码翻译层将代码中间表示翻译为多种用途的代码。2.提出了基于分支标记的从动态数据流模型到控制流代码的调度转换方法。该方法首先通过拓扑排序获得数据流的调度顺序,然后对组件进行分支信息的逐层标记与化简,最后基于组件的调度顺序和分支标记信息动态构造代码生成位置表。实验表明,在搭建相同功能模型的情况下,采用Ptolemy-II搭建与Simulink等价的控制模型可以节省73.5%的组件个数。在针对复杂控制逻辑进行建模和代码生成时,模型搭建的效率将得到大幅提升。3.提出了面向计算密集型数据流模型的处理器并行指令生成方法。针对密集计算组件,该方法首先根据组件及端口信息寻找匹配的多种代码实现,然后通过预执行选取最优实现进行生成。针对批量计算组件,该方法结合模型数据流图,从SIMD指令集中优先选择合适的复合指令进行生成。此外,本文还提出了模型级的并行组件合并方法,进一步提升了SIMD指令的生成能力。该方法生成的代码与Simulink相比,可以提升38.9%-92.9%的运行效率。基于上述研究成果,设计并实现了相应的代码生成工具集。该工具集和本文提出的代码中间表示都已应用到华为公司的HAS Studio车控行为模型建模系统中,并已在多家车企的实际生产中得到初步应用。
With the advancement and development of software engineering technology, model-driven software development is becoming more and more widely used. Due to the low threshold, high efficiency and high security of model-driven development, the development of software in different fields is gradually transforming from code-based development to model-driven development. However, the current model-driven development tools generally have the problems of difficulty in generating high-quality code, code generation for dynamic dataflow models, and making full use of processor parallel instructions. Therefore, this paper designs a solution from code generation framework to model semantic transformation to processor parallel instruction generation. The main research contents are as follows.1. This paper proposes a model intermediate representation, a code intermediate representation and a hierarchical code generation framework. The model intermediate representation can be compatible with similar model semantics, and also has good scalability for more model semantics with large differences. The code intermediate representation contains mapping information of model elements and code statements, which can be easily traced from code to model elements. The model parsing layer transforms models built by different modeling tools into a unified model intermediate representation. The schedule transformation layer converts the model intermediate representation into a control flow code and outputs the code intermediate representation. The code optimization layer performs a multi-stage optimization on the code intermediate representation. The code translation layer translates the code intermediate representation into multi-purpose code.2. This paper proposes a branch marking-based schedule transformation method from dynamic dataflow models to control flow codes. The method first obtains the scheduling order of the dataflow by topological sorting, then marks and simplifies the branch information of the actor layer by layer, and finally constructs a code generation location table dynamically based on the schedule order of the actors and the branch marking information. Experiments show that the number of actors can be reduced by 73.5% by using Ptolemy-II to build a control model equivalent to Simulink with the same functional model. When modeling and code generation for complex control logic, the efficiency of model building will be greatly improved.3. This paper proposes a processor parallel instruction generation method for computing-intensive dataflow models. For the intensive computing actor, the method first finds the matching code implementations based on the information of actor and ports, and then selects an optimal code implementation for generation by pre-execution. For batch computing actors, the method prioritizes the selection of suitable compound instructions from the SIMD instruction set for generation based on the model dataflow graph. In addition, this paper also proposes a model-level parallel actor merging method, which further improves the SIMD instruction generation capability. The code generated by this method can improve the running efficiency by 38.9%-92.9% compared with Simulink.Based on the research of this paper, a corresponding code generation toolset is designed and implemented. Both the toolset and the code intermediate representation proposed in this paper have been applied to Huawei‘s HAS Studio vehicle control behavior modeling system, and have been initially applied in several vehicle companies.