CN113687833B - Hybrid compiling method, hybrid compiling system, compiler and storage medium - Google Patents

Hybrid compiling method, hybrid compiling system, compiler and storage medium Download PDF

Info

Publication number
CN113687833B
CN113687833B CN202110911916.2A CN202110911916A CN113687833B CN 113687833 B CN113687833 B CN 113687833B CN 202110911916 A CN202110911916 A CN 202110911916A CN 113687833 B CN113687833 B CN 113687833B
Authority
CN
China
Prior art keywords
code
generate
information
compilation
standard
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202110911916.2A
Other languages
Chinese (zh)
Other versions
CN113687833A (en
Inventor
戴正国
郭福坤
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shenzhen Inovance Technology Co Ltd
Original Assignee
Shenzhen Inovance Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shenzhen Inovance Technology Co Ltd filed Critical Shenzhen Inovance Technology Co Ltd
Priority to CN202110911916.2A priority Critical patent/CN113687833B/en
Publication of CN113687833A publication Critical patent/CN113687833A/en
Application granted granted Critical
Publication of CN113687833B publication Critical patent/CN113687833B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/51Source to source
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/42Syntactic analysis
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/42Syntactic analysis
    • G06F8/425Lexical analysis
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/43Checking; Contextual analysis
    • G06F8/436Semantic checking
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Computational Linguistics (AREA)
  • Stored Programmes (AREA)
  • Devices For Executing Special Programs (AREA)

Abstract

本发明公开了一种混合编译方法、混合编译系统、编译器及存储介质,属于语言编译技术领域。本发明通过编辑器的文本文件获取源代码,根据所述源代码进行标准修正,生成预处理代码,根据所述预处理代码进行后端分析,生成混合编译信息,根据所述混合编译信息进行机器语言转换,生成目标机器码。本发明通过对源代码进行标准修正,预处理代码满足标准规范,符合不同目标平台的代码执行需求,经过后端分析生成混合编译信息,根据混合编译信息生成目标机器码,无需目标平台辅助编译,实现适配多个目标平台的混合编译。

The present invention discloses a hybrid compilation method, a hybrid compilation system, a compiler and a storage medium, and belongs to the field of language compilation technology. The present invention obtains source code through a text file of an editor, performs standard correction according to the source code, generates preprocessing code, performs back-end analysis according to the preprocessing code, generates hybrid compilation information, performs machine language conversion according to the hybrid compilation information, and generates target machine code. The present invention performs standard correction on the source code, the preprocessing code meets the standard specification, meets the code execution requirements of different target platforms, generates hybrid compilation information through back-end analysis, generates target machine code according to the hybrid compilation information, and does not require auxiliary compilation of the target platform, so as to realize hybrid compilation adapted to multiple target platforms.

Description

混合编译方法、混合编译系统、编译器及存储介质Hybrid compilation method, hybrid compilation system, compiler and storage medium

技术领域Technical Field

本发明涉及语言编译技术领域,尤其涉及一种混合编译方法、混合编译系统、编译器及存储介质。The present invention relates to the field of language compilation technology, and in particular to a hybrid compilation method, a hybrid compilation system, a compiler and a storage medium.

背景技术Background technique

编译是指把高级语言转换为机器语言的过程,高级语言便于人编写、阅读交流及维护,机器语言是计算机能直接解读和运行的,编译器则可将高级语言源程序作为输入,翻译成目标语言机器代码的等价程序。目前,编译器需依赖目标平台的硬件及系统进行编译,无法结合其他解释执行输出的信息生成目标平台的可执行机器码,将同一份源代码进行一次编译后,只能输出一个目标平台可执行的机器码。Compilation refers to the process of converting high-level languages into machine languages. High-level languages are easy for people to write, read, communicate and maintain, while machine languages can be directly interpreted and run by computers. Compilers can take high-level language source programs as input and translate them into equivalent programs in the target language machine code. Currently, compilers rely on the hardware and system of the target platform for compilation, and cannot combine other information output by interpretation and execution to generate executable machine code for the target platform. After compiling the same source code once, only one machine code executable by the target platform can be output.

上述内容仅用于辅助理解本发明的技术方案,并不代表承认上述内容是现有技术。The above contents are only used to assist in understanding the technical solution of the present invention and do not constitute an admission that the above contents are prior art.

发明内容Summary of the invention

本发明的主要目的在于提供一种混合编译方法、混合编译系统、编译器及存储介质,旨在解决现有技术编译器依赖目标平台硬件及系统进行编译的技术问题。The main purpose of the present invention is to provide a hybrid compilation method, a hybrid compilation system, a compiler and a storage medium, aiming to solve the technical problem that the prior art compiler relies on the target platform hardware and system for compilation.

为实现上述目的,本发明提供了一种混合编译方法,所述混合编译方法包括以下步骤:To achieve the above object, the present invention provides a hybrid compilation method, which comprises the following steps:

通过编辑器的文本文件获取源代码;Get the source code through the text file of the editor;

根据所述源代码进行标准修正,生成预处理代码;Perform standard modification according to the source code to generate preprocessing code;

根据所述预处理代码进行后端分析,生成混合编译信息;Perform backend analysis according to the preprocessed code to generate mixed compilation information;

根据所述混合编译信息进行机器语言转换,生成目标机器码。Perform machine language conversion according to the mixed compilation information to generate target machine code.

可选地,所述根据所述源代码进行标准修正,生成预处理代码,包括:Optionally, performing standard correction according to the source code to generate preprocessing code includes:

根据所述源代码进行非规范变量转换,生成标准变量代码;Perform non-standard variable conversion according to the source code to generate standard variable codes;

根据所述标准变量代码进行错误检测,生成错误信息;Perform error detection according to the standard variable code and generate error information;

根据所述错误信息对所述标准地址代码进行错误修正,生成预处理代码。The standard address code is error corrected according to the error information to generate a preprocessing code.

可选地,所述根据所述源代码进行非规范变量转换,生成标准变量代码,包括:Optionally, performing non-standard variable conversion according to the source code to generate standard variable codes includes:

根据所述源代码进行指令提取,生成指令信息;Extract instructions according to the source code to generate instruction information;

根据所述指令信息对所述源代码进行非规范变量转换,生成标准变量代码。The source code is converted into non-standard variables according to the instruction information to generate standard variable codes.

可选地,所述根据所述源代码进行指令提取,生成指令信息,包括:Optionally, extracting instructions according to the source code to generate instruction information includes:

根据所述源代码进行词法解析,生成关键字信息;Performing lexical analysis according to the source code to generate keyword information;

根据所述关键字信息对所述源代码进行指令提取,生成指令信息。Instructions are extracted from the source code according to the keyword information to generate instruction information.

可选地,所述根据所述标准变量代码进行错误检测,生成错误信息,包括:Optionally, performing error detection according to the standard variable code and generating error information includes:

将所述标准变量代码写入前向声明,生成标准定义代码;Writing the standard variable code into the forward declaration to generate a standard definition code;

根据所述标准定义代码进行错误检测,生成错误信息。Error detection is performed according to the standard definition code to generate error information.

可选地,所述根据所述标准定义代码进行错误检测,生成错误信息,包括:Optionally, performing error detection according to the standard definition code and generating error information includes:

根据所述标准定义代码进行地址映射转换,生成标准地址代码;Perform address mapping conversion according to the standard definition code to generate a standard address code;

根据所述标准地址代码进行错误检测,生成错误信息。Error detection is performed according to the standard address code to generate error information.

可选地,所述根据所述预处理代码进行后端分析,生成混合编译信息,包括:Optionally, performing backend analysis according to the preprocessed code to generate hybrid compilation information includes:

根据所述预处理代码进行词法分析,生成词法信息;Performing lexical analysis according to the preprocessing code to generate lexical information;

根据所述词法信息对所述预处理代码进行语法和语义分析,生成混合编译信息。The preprocessed code is subjected to syntax and semantic analysis according to the lexical information to generate mixed compilation information.

此外,为实现上述目的,本发明还提出一种混合编译系统,所述混合编译系统实现如上文所述的混合编译方法,所述混合编译系统包括:预处理模块、分析模块及机器语言转换模块;In addition, to achieve the above object, the present invention also proposes a hybrid compilation system, the hybrid compilation system implements the hybrid compilation method as described above, the hybrid compilation system includes: a preprocessing module, an analysis module and a machine language conversion module;

所述预处理模块,用于通过编辑器的文本文件获取源代码;The preprocessing module is used to obtain source code through a text file of an editor;

所述预处理模块,还用于根据所述源代码进行标准修正,生成预处理代码;The preprocessing module is further used to perform standard correction according to the source code to generate preprocessing code;

所述分析模块,用于根据所述预处理代码进行后端分析,生成混合编译信息;The analysis module is used to perform back-end analysis according to the preprocessed code to generate mixed compilation information;

所述机器语言转换模块,用于根据所述混合编译信息进行机器语言转换,生成目标机器码。The machine language conversion module is used to perform machine language conversion according to the mixed compilation information to generate target machine code.

此外,为实现上述目的,本发明还提出一种编辑器,所述编辑器包括:存储器、处理器及存储在所述存储器上并可在所述处理器上运行的混合编译程序,所述混合编译程序配置为实现如上文所述的混合编译方法的步骤。In addition, to achieve the above objectives, the present invention also proposes an editor, which includes: a memory, a processor, and a hybrid compilation program stored in the memory and executable on the processor, wherein the hybrid compilation program is configured to implement the steps of the hybrid compilation method described above.

此外,为实现上述目的,本发明还提出一种存储介质,所述存储介质上存储有混合编译程序,所述混合编译程序被处理器执行时实现如上文所述的混合编译方法的步骤。In addition, to achieve the above objective, the present invention further proposes a storage medium, on which a hybrid compilation program is stored, and when the hybrid compilation program is executed by a processor, the steps of the hybrid compilation method described above are implemented.

本发明通过编辑器的文本文件获取源代码,根据所述源代码进行标准修正,生成预处理代码,根据所述预处理代码进行后端分析,生成混合编译信息,根据所述混合编译信息进行机器语言转换,生成目标机器码。本发明通过对源代码进行标准修正,预处理代码满足标准规范,符合不同目标平台的代码执行需求,经过后端分析生成混合编译信息,根据混合编译信息生成目标机器码,无需目标平台辅助编译,实现适配多个目标平台的混合编译。The present invention obtains source code through a text file of an editor, performs standard correction according to the source code, generates preprocessing code, performs back-end analysis according to the preprocessing code, generates mixed compilation information, performs machine language conversion according to the mixed compilation information, and generates target machine code. The present invention performs standard correction on the source code, the preprocessing code meets the standard specification, meets the code execution requirements of different target platforms, generates mixed compilation information after back-end analysis, generates target machine code according to the mixed compilation information, and does not require auxiliary compilation of the target platform, so as to achieve mixed compilation adapted to multiple target platforms.

附图说明BRIEF DESCRIPTION OF THE DRAWINGS

图1为本发明实施例方案涉及的硬件运行环境的编辑器的结构示意图;FIG1 is a schematic diagram of the structure of an editor of a hardware operating environment involved in an embodiment of the present invention;

图2为本发明混合编译方法第一实施例的流程示意图;FIG2 is a schematic diagram of a flow chart of a first embodiment of a hybrid compilation method according to the present invention;

图3为本发明混合编译方法第二实施例的流程示意图;FIG3 is a schematic diagram of a flow chart of a second embodiment of a hybrid compilation method according to the present invention;

图4为本发明混合编译系统第一实施例的结构框图。FIG. 4 is a structural block diagram of a first embodiment of a hybrid compilation system according to the present invention.

本发明目的的实现、功能特点及优点将结合实施例,参照附图做进一步说明。The realization of the purpose, functional features and advantages of the present invention will be further explained in conjunction with embodiments and with reference to the accompanying drawings.

具体实施方式Detailed ways

应当理解,此处所描述的具体实施例仅用以解释本发明,并不用于限定本发明。It should be understood that the specific embodiments described herein are only used to explain the present invention, and are not used to limit the present invention.

参照图1,图1为本发明实施例方案涉及的硬件运行环境的编辑器结构示意图。Refer to FIG. 1 , which is a schematic diagram of the editor structure of the hardware operating environment involved in the embodiment of the present invention.

如图1所示,该编辑器可以包括:处理器1001,例如中央处理器(CentralProcessing Unit,CPU),通信总线1002、用户接口1003,网络接口1004,存储器1005。其中,通信总线1002用于实现这些组件之间的连接通信。用户接口1003可以包括显示屏(Display)、输入单元比如键盘(Keyboard),可选用户接口1003还可以包括标准的有线接口、无线接口。网络接口1004可选的可以包括标准的有线接口、无线接口(如无线保真(Wireless-Fidelity,Wi-Fi)接口)。存储器1005可以是高速的随机存取存储器(RandomAccess Memory,RAM)存储器,也可以是稳定的非易失性存储器(Non-Volatile Memory,NVM),例如磁盘存储器。存储器1005可选的还可以是独立于前述处理器1001的存储装置。As shown in FIG1 , the editor may include: a processor 1001, such as a central processing unit (CPU), a communication bus 1002, a user interface 1003, a network interface 1004, and a memory 1005. The communication bus 1002 is used to realize the connection and communication between these components. The user interface 1003 may include a display screen (Display), an input unit such as a keyboard (Keyboard), and the optional user interface 1003 may also include a standard wired interface and a wireless interface. The network interface 1004 may optionally include a standard wired interface and a wireless interface (such as a wireless fidelity (Wireless-Fidelity, Wi-Fi) interface). The memory 1005 may be a high-speed random access memory (Random Access Memory, RAM) memory, or a stable non-volatile memory (Non-Volatile Memory, NVM), such as a disk memory. The memory 1005 may also be a storage device independent of the aforementioned processor 1001.

本领域技术人员可以理解,图1中示出的结构并不构成对编辑器的限定,可以包括比图示更多或更少的部件,或者组合某些部件,或者不同的部件布置。Those skilled in the art will appreciate that the structure shown in FIG. 1 does not constitute a limitation on the editor, and may include more or fewer components than shown in the figure, or a combination of certain components, or a different arrangement of components.

如图1所示,作为一种存储介质的存储器1005中可以包括操作系统、网络通信模块、用户接口模块以及混合编译程序。As shown in FIG. 1 , the memory 1005 as a storage medium may include an operating system, a network communication module, a user interface module, and a hybrid compiler.

在图1所示的编辑器中,网络接口1004主要用于与网络服务器进行数据通信;用户接口1003主要用于与用户进行数据交互;本发明编辑器中的处理器1001、存储器1005可以设置在编辑器中,所述编辑器通过处理器1001调用存储器1005中存储的混合编译程序,并执行本发明实施例提供的XX方法。In the editor shown in Figure 1, the network interface 1004 is mainly used for data communication with the network server; the user interface 1003 is mainly used for data interaction with the user; the processor 1001 and the memory 1005 in the editor of the present invention can be set in the editor, and the editor calls the mixed compilation program stored in the memory 1005 through the processor 1001, and executes the XX method provided by the embodiment of the present invention.

本发明实施例提供了一种混合编译方法,参照图2,图2为本发明一种混合编译方法第一实施例的流程示意图。An embodiment of the present invention provides a hybrid compilation method. Referring to FIG. 2 , FIG. 2 is a schematic flow chart of a first embodiment of a hybrid compilation method of the present invention.

本实施例中,所述混合编译方法包括以下步骤:In this embodiment, the hybrid compilation method includes the following steps:

步骤S10:通过编辑器的文本文件获取源代码。Step S10: Obtain source code through a text file of an editor.

需要说明的是,混合编译方法的执行主体可为混合编译系统或编译器,在进行混合编译的过程中,首先需获取源代码。源代码是程序员创建软件程序时编写程序的工具,源代码由特定的编程语言编写,并以基于文本的、人类可读的格式保存,因此源代码不能由计算机直接运行。It should be noted that the execution subject of the hybrid compilation method can be a hybrid compilation system or compiler. In the process of hybrid compilation, the source code must be obtained first. The source code is a tool for programmers to write programs when creating software programs. The source code is written in a specific programming language and saved in a text-based, human-readable format. Therefore, the source code cannot be directly run by a computer.

应当理解的是,由于计算机的工作平台即目标平台种类较多,如X86平台、ARM平台及RISC平台等,传统的编译器无法一次性将软件代码编译成符合多个目标平台的可执行的机器码,且编译过程还需依赖目标平台的硬件和系统(如目标平台的解释器),本实施例提出一种混合编译方法,通过对源代码进行标准修正,使预处理代码满足标准规范,符合不同目标平台的代码执行需求,经过后端分析生成混合编译信息,根据混合编译信息生成目标机器码,无需目标平台辅助编译,实现适配多个目标平台的混合编译。It should be understood that due to the large variety of computer working platforms, i.e., target platforms, such as X86 platform, ARM platform, and RISC platform, traditional compilers cannot compile software code into executable machine code that complies with multiple target platforms at one time, and the compilation process also needs to rely on the hardware and system of the target platform (such as the interpreter of the target platform). This embodiment proposes a hybrid compilation method, which makes standard corrections to the source code so that the preprocessed code meets the standard specifications and meets the code execution requirements of different target platforms. After back-end analysis, hybrid compilation information is generated, and target machine code is generated based on the hybrid compilation information. No target platform auxiliary compilation is required, thereby realizing hybrid compilation that adapts to multiple target platforms.

步骤S20:根据所述源代码进行标准修正,生成预处理代码。Step S20: Perform standard correction according to the source code to generate preprocessing code.

易于理解的是,根据源代码进行标准修正,生成预处理代码为混合编译的预处理过程,由预处理模块执行。为使编程代码即源代码经过一次修正后,可满足标准化规范,标准修正的标准化规范根据目标平台的编译及代码程序运行需求进行设定,如语法语义正确或无不可识别的字符等需求。对源代码进行标准修正后,可生成预处理代码,预处理代码即源代码经过预处理过后生成的代码。It is easy to understand that the preprocessing code generated by performing standard correction according to the source code is a preprocessing process of mixed compilation, which is executed by the preprocessing module. In order to make the programming code, i.e. the source code, meet the standard specifications after one correction, the standard correction standard specifications are set according to the compilation and code program running requirements of the target platform, such as the requirements of correct syntax and semantics or no unrecognizable characters. After the source code is corrected by the standard, the preprocessing code can be generated, and the preprocessing code is the code generated after the source code is preprocessed.

步骤S30:根据所述预处理代码进行后端分析,生成混合编译信息。Step S30: performing back-end analysis according to the preprocessed code to generate hybrid compilation information.

可以理解的是,后端分析过程可包括词法分析及语法语义分析,由分析模块执行,其中,分析模块可包括基于FLEX的词法分析模块和基于BISON的语法语义分析模块,词法分析可基于FLEX的词法分析模块进行相应的分析,语法语义分析可基于BISON的语法语义分析模块进行相应的分析。混合编译信息可包括指令标号、符号表以及封装库等,封装库可用于将代码文件中的符号转换成外部符号供目标机器执行重定位。It is understandable that the back-end analysis process may include lexical analysis and grammatical semantic analysis, which are performed by an analysis module, wherein the analysis module may include a lexical analysis module based on FLEX and a grammatical semantic analysis module based on BISON, and the lexical analysis may be performed based on the lexical analysis module of FLEX, and the grammatical semantic analysis may be performed based on the grammatical semantic analysis module of BISON. The mixed compilation information may include instruction labels, symbol tables, and encapsulation libraries, etc. The encapsulation library may be used to convert symbols in the code file into external symbols for the target machine to perform relocation.

步骤S40:根据所述混合编译信息进行机器语言转换,生成目标机器码。Step S40: Perform machine language conversion according to the mixed compilation information to generate target machine code.

易于理解的是,根据混合编译信息进行机器语言转换可由机器语言转换模块,机器语言转换模块可为基于LLVM的机器语言转换模块。机器语言转换模块通过应用程序接口生成不同目标平台的可执行的机器码即目标机器码,将目标机器码输出至目标平台,以使目标平台执行相关的代码程序运行。It is easy to understand that the machine language conversion according to the mixed compilation information can be performed by a machine language conversion module, and the machine language conversion module can be a machine language conversion module based on LLVM. The machine language conversion module generates executable machine codes, namely target machine codes, for different target platforms through an application program interface, and outputs the target machine codes to the target platform so that the target platform executes the relevant code program.

本实施例通过编辑器的文本文件获取源代码,根据所述源代码进行标准修正,生成预处理代码,根据所述预处理代码进行后端分析,生成混合编译信息,根据所述混合编译信息进行机器语言转换,生成目标机器码。本实施例通过对源代码进行标准修正,预处理代码满足标准规范,符合不同目标平台的代码执行需求,经过后端分析生成混合编译信息,根据混合编译信息生成目标机器码,无需目标平台辅助编译,实现适配多个目标平台的混合编译。This embodiment obtains source code through a text file of an editor, performs standard corrections according to the source code, generates preprocessing code, performs back-end analysis according to the preprocessing code, generates mixed compilation information, performs machine language conversion according to the mixed compilation information, and generates target machine code. This embodiment performs standard corrections on the source code, the preprocessing code meets the standard specifications, meets the code execution requirements of different target platforms, generates mixed compilation information after back-end analysis, generates target machine code according to the mixed compilation information, and does not require auxiliary compilation of the target platform, so as to achieve mixed compilation adapted to multiple target platforms.

参考图3,图3为本发明一种混合编译方法第二实施例的流程示意图。Refer to FIG. 3 , which is a flow chart of a second embodiment of a hybrid compilation method according to the present invention.

基于上述第一实施例,本实施例混合编译方法中所述步骤S20包括:Based on the first embodiment above, step S20 in the hybrid compilation method of this embodiment includes:

步骤S201:根据所述源代码进行词法解析,生成关键字信息。Step S201: performing lexical analysis according to the source code to generate keyword information.

需要说明的是,根据所述源代码进行词法解析,生成关键字信息是混合编译过程中第一次进行词法分析,以首先排除词法问题,避免因词法错误造成后续预处理过程无用功,影响编译效率,关键字信息通过对源代码进行扫描并词法解析获取,关键字信息可包括关键字(如include、define、undef、if、error等)及关键字位置信息。It should be noted that lexical analysis is performed according to the source code to generate keyword information. This is the first lexical analysis performed in the mixed compilation process, so as to eliminate lexical problems first and avoid that the subsequent preprocessing process is useless due to lexical errors, which affects the compilation efficiency. The keyword information is obtained by scanning the source code and performing lexical analysis. The keyword information may include keywords (such as include, define, undef, if, error, etc.) and keyword position information.

步骤S202:根据所述关键字信息对所述源代码进行指令提取,生成指令信息。Step S202: extracting instructions from the source code according to the keyword information to generate instruction information.

可以理解的是,根据关键字信息可确定关键字所在位置,根据关键字前后符号,可确定关键字所在语句为对应的指令,从而可生成指令信息,指令信息可为代码文件设定命令以使对应程序执行命令的重要信息。It can be understood that the location of the keyword can be determined based on the keyword information, and the statement where the keyword is located can be determined as the corresponding instruction based on the symbols before and after the keyword, thereby generating instruction information. The instruction information can be important information for setting commands in the code file to enable the corresponding program to execute commands.

步骤S203:根据所述指令信息对所述源代码进行非规范变量转换,生成标准变量代码。Step S203: converting non-standard variables of the source code according to the instruction information to generate standard variable codes.

应当理解的是,由于源代码以高级语言编辑,因此,源代码中可能存在非规范变量即非英文规范变量和函数,需将非规范变量转换为规范变量即转换为英文,以满足符合目标平台编译的标准规范。It should be understood that since the source code is edited in a high-level language, there may be non-standard variables, i.e., non-English standard variables and functions, in the source code. The non-standard variables need to be converted into standard variables, i.e., into English, to meet the standard specifications for compilation on the target platform.

步骤S204:根据所述标准变量代码写入前向声明,生成标准定义代码。Step S204: Write forward declaration according to the standard variable code to generate standard definition code.

易于理解的是,前向声明是基于后续机器语言转换所提供的辅助工具,通过写入前向声明,以给代码文件中的变量或函数等进行定义,从而避免机器语言转换过程无法正确识别代码文件中变量或函数等符号的意义。It is easy to understand that forward declaration is an auxiliary tool provided based on subsequent machine language conversion. By writing forward declarations, variables or functions in the code file are defined, thereby avoiding the machine language conversion process from being unable to correctly identify the meaning of symbols such as variables or functions in the code file.

步骤S205:根据所述标准定义代码进行地址映射转换,生成标准地址代码。Step S205: performing address mapping conversion according to the standard definition code to generate a standard address code.

可以理解的是,程序在执行时中央处理器接收的是逻辑地址,逻辑地址必须经过映射转变为物理地址,才能访问真正的物理内存。将标准定义代码的逻辑地址映射转变为目标平台的物理地址可包括两个步骤,首先需将标准定义代码的逻辑地址映射转变为线性地址,线性地址再经过一次映射转变为目标平台的物理地址。It is understandable that when the program is executed, the CPU receives the logical address, which must be mapped to a physical address before the real physical memory can be accessed. The mapping of the logical address of the standard definition code to the physical address of the target platform can include two steps. First, the logical address mapping of the standard definition code must be converted to a linear address, and the linear address is mapped again to the physical address of the target platform.

步骤S206:根据所述标准地址代码进行错误检测,生成错误信息。Step S206: Perform error detection according to the standard address code and generate error information.

易于理解的是,根据源代码进行标准修正的预处理过程有可能因源代码错误或其他信息生成或转换错误产生诸多问题,直接导致编译远远差于预期效果,因此,需对标准地址代码进行错误检测,错误检测可包括语法错误、类型错误及声明错误等错误形式,并根据检测的结构生成错误信息,错误信息可包括错误形式及错误位置。It is easy to understand that the preprocessing process of standard correction based on the source code may cause many problems due to source code errors or other information generation or conversion errors, which directly lead to compilation far worse than expected. Therefore, it is necessary to perform error detection on the standard address code. The error detection may include syntax errors, type errors, declaration errors and other error forms, and generate error information based on the detected structure. The error information may include the error form and error location.

步骤S207:根据所述错误信息对所述标准地址代码进行错误修正,生成预处理代码。Step S207: performing error correction on the standard address code according to the error information to generate a preprocessing code.

易于理解的是,混合编译系统可将错误信息返还给操作人员进行修改,也可以由混合编译系统扫描整体代码,结合代码文件中变量和函数等符号的意义对代码文件进行辅助修改,标准地址代码进行错误修正后可生成预处理代码,对代码文件进行辅助修改时可以标记错误位置及修改位置,也可以由操作人员检查修改内容后生成预处理代码。It is easy to understand that the hybrid compilation system can return error information to the operator for modification, or the hybrid compilation system can scan the entire code and assist in modifying the code file based on the meaning of symbols such as variables and functions in the code file. The standard address code can generate preprocessing code after error correction. When assisting in modifying the code file, the error location and modification location can be marked, and the operator can generate preprocessing code after checking the modification content.

本实施例中,所述步骤S30包括:In this embodiment, step S30 includes:

步骤S301:根据所述预处理代码进行词法分析,生成词法信息。Step S301: Perform lexical analysis according to the preprocessing code to generate lexical information.

可以理解的是,根据预处理代码进行词法分析,生成词法信息的过程可由基于FLEX的词法分析模块进行相应的分析,是混合编译过程中第二次进行词法分析,通过再次对代码文件进行词法分析,进一步减少高级语言转换为机器语言的过程中的编译错误。It can be understood that the process of generating lexical information by performing lexical analysis based on the preprocessed code can be analyzed accordingly by a lexical analysis module based on FLEX. This is the second lexical analysis in the mixed compilation process. By performing lexical analysis on the code file again, compilation errors in the process of converting high-level language to machine language can be further reduced.

步骤S302:根据所述词法信息对所述预处理代码进行语法和语义分析,生成混合编译信息。Step S302: performing syntax and semantic analysis on the preprocessed code according to the lexical information to generate mixed compilation information.

易于理解的是,根据词法信息对预处理代码进行语法和语义分析,生成混合编译信息的过程可由基于BISON的语法语义分析模块进行相应的分析,若分析词法、语法和语义中存在错误时,可生成错误报告,以重新对预处理代码进行修正,减小编译错误,且在无误后对代码文件的相关信息进行提取,以生成混合编译信息,混合编译信息可包括指令标号、符号表以及封装库等,封装库可用于将代码文件中的符号转换成外部符号供目标机器执行重定位。It is easy to understand that the process of generating mixed compilation information by performing grammatical and semantic analysis on the preprocessed code according to the lexical information can be analyzed accordingly by the grammatical and semantic analysis module based on BISON. If there are errors in the lexical, grammatical and semantic analysis, an error report can be generated to correct the preprocessed code again to reduce compilation errors. After confirming that there are no errors, the relevant information of the code file can be extracted to generate mixed compilation information. The mixed compilation information may include instruction labels, symbol tables, and encapsulation libraries. The encapsulation library can be used to convert symbols in the code file into external symbols for the target machine to perform relocation.

本实施例通过对源代码进行预处理来适配混合编译,预处理过程包括首先对源代码进行扫描并通过词法解析获取到关键字信息,根据关键字信息查找出各类型指令,其次,将代码文件中非规范变量和函数转换成标准变量,再次自动给代码文件即标准定义代码加上前向声明,以保证机器语言转换时编译正确,同时,将标准定义代码的变量逻辑地址与目标平台物理地址进行映射转换处理,最后对编译进行错误实时监测、修正与输出,得到预处理代码,对预处理过后的代码进行新的词法扫描和语法语义分析,获得混合编译信息,根据混合编译信息生成目标机器码,无需目标平台辅助编译,进一步提高了适配多个目标平台的混合编译的准确性和效率。This embodiment adapts to hybrid compilation by preprocessing the source code. The preprocessing process includes first scanning the source code and obtaining keyword information through lexical analysis, finding various types of instructions based on the keyword information, and then converting non-standard variables and functions in the code file into standard variables. The code file, i.e., the standard definition code, is automatically added with a forward declaration to ensure correct compilation during machine language conversion. At the same time, the variable logical address of the standard definition code is mapped and converted with the physical address of the target platform. Finally, the compilation is monitored, corrected and output in real time to obtain preprocessed code, and new lexical scanning and grammatical semantic analysis are performed on the preprocessed code to obtain hybrid compilation information, and target machine code is generated based on the hybrid compilation information without the need for auxiliary compilation of the target platform, thereby further improving the accuracy and efficiency of hybrid compilation adapted to multiple target platforms.

此外,本发明实施例还提出一种存储介质,所述存储介质上存储有混合编译程序,所述混合编译程序被处理器执行时实现如上文所述的混合编译方法的步骤。In addition, an embodiment of the present invention further provides a storage medium, on which a hybrid compilation program is stored. When the hybrid compilation program is executed by a processor, the steps of the hybrid compilation method described above are implemented.

由于本存储介质采用了上述所有实施例的全部技术方案,因此至少具有上述实施例的技术方案所带来的所有有益效果,在此不再一一赘述。Since the storage medium adopts all the technical solutions of all the above embodiments, it has at least all the beneficial effects brought by the technical solutions of the above embodiments, which will not be described one by one here.

参照图4,图4为本发明混合编译系统第一实施例的结构框图。Refer to FIG. 4 , which is a structural block diagram of a first embodiment of a hybrid compilation system according to the present invention.

如图4所示,本发明实施例提出的混合编译系统包括:预处理模块、分析模块及机器语言转换模块;As shown in FIG4 , the hybrid compilation system proposed in the embodiment of the present invention includes: a preprocessing module, an analysis module and a machine language conversion module;

所述预处理模块10,用于通过编辑器的文本文件获取源代码。The preprocessing module 10 is used to obtain source code through a text file of an editor.

应当理解的是,由于计算机的工作平台即目标平台种类较多,如X86平台、ARM平台及RISC平台等,传统的编译器无法一次性将软件代码编译成符合多个目标平台的可执行的机器码,且编译过程还需依赖目标平台的硬件和系统(如目标平台的解释器),本实施例提出一种混合编译方法,通过对源代码进行标准修正,使预处理代码满足标准规范,符合不同目标平台的代码执行需求,经过后端分析生成混合编译信息,根据混合编译信息生成目标机器码,无需目标平台辅助编译,实现适配多个目标平台的混合编译。It should be understood that due to the large variety of computer working platforms, i.e., target platforms, such as X86 platform, ARM platform, and RISC platform, traditional compilers cannot compile software code into executable machine code that complies with multiple target platforms at one time, and the compilation process also needs to rely on the hardware and system of the target platform (such as the interpreter of the target platform). This embodiment proposes a hybrid compilation method, which makes standard corrections to the source code so that the preprocessed code meets the standard specifications and meets the code execution requirements of different target platforms. After back-end analysis, hybrid compilation information is generated, and target machine code is generated based on the hybrid compilation information. No target platform auxiliary compilation is required, thereby realizing hybrid compilation that adapts to multiple target platforms.

所述预处理模块10,还用于根据所述源代码进行标准修正,生成预处理代码。The preprocessing module 10 is further used to perform standard correction according to the source code to generate preprocessing code.

易于理解的是,根据源代码进行标准修正,生成预处理代码为混合编译的预处理过程,由预处理模块执行。为使编程代码即源代码经过一次修正后,可满足标准化规范,标准修正的标准化规范根据目标平台的编译及代码程序运行需求进行设定,如语法语义正确或无不可识别的字符等需求。对源代码进行标准修正后,可生成预处理代码,预处理代码即源代码经过预处理过后生成的代码。It is easy to understand that the preprocessing code generated by performing standard correction according to the source code is a preprocessing process of mixed compilation, which is executed by the preprocessing module. In order to make the programming code, i.e. the source code, meet the standard specifications after one correction, the standard correction standard specifications are set according to the compilation and code program running requirements of the target platform, such as the requirements of correct syntax and semantics or no unrecognizable characters. After the source code is corrected by the standard, the preprocessing code can be generated, and the preprocessing code is the code generated after the source code is preprocessed.

所述分析模块20,用于根据所述预处理代码进行后端分析,生成混合编译信息。The analysis module 20 is used to perform backend analysis according to the preprocessed code to generate hybrid compilation information.

可以理解的是,后端分析过程可包括词法分析及语法语义分析,由分析模块执行,其中,分析模块可包括基于FLEX的词法分析模块和基于BISON的语法语义分析模块,词法分析可基于FLEX的词法分析模块进行相应的分析,语法语义分析可基于BISON的语法语义分析模块进行相应的分析。混合编译信息可包括指令标号、符号表以及封装库等,封装库可用于将代码文件中的符号转换成外部符号供目标机器执行重定位。It is understandable that the back-end analysis process may include lexical analysis and grammatical semantic analysis, which are performed by an analysis module, wherein the analysis module may include a lexical analysis module based on FLEX and a grammatical semantic analysis module based on BISON, and the lexical analysis may be performed based on the lexical analysis module of FLEX, and the grammatical semantic analysis may be performed based on the grammatical semantic analysis module of BISON. The mixed compilation information may include instruction labels, symbol tables, and encapsulation libraries, etc. The encapsulation library may be used to convert symbols in the code file into external symbols for the target machine to perform relocation.

所述机器语言转换模块30,用于根据所述混合编译信息进行机器语言转换,生成目标机器码。The machine language conversion module 30 is used to perform machine language conversion according to the mixed compilation information to generate target machine code.

易于理解的是,根据混合编译信息进行机器语言转换可由机器语言转换模块,机器语言转换模块可为基于LLVM的机器语言转换模块。机器语言转换模块通过应用程序接口生成不同目标平台的可执行的机器码即目标机器码,将目标机器码输出至目标平台,以使目标平台执行相关的代码程序运行。It is easy to understand that the machine language conversion according to the mixed compilation information can be performed by a machine language conversion module, and the machine language conversion module can be a machine language conversion module based on LLVM. The machine language conversion module generates executable machine codes, namely target machine codes, for different target platforms through an application program interface, and outputs the target machine codes to the target platform so that the target platform executes the relevant code program.

本实施例通过编辑器的文本文件获取源代码,根据所述源代码进行标准修正,生成预处理代码,根据所述预处理代码进行后端分析,生成混合编译信息,根据所述混合编译信息进行机器语言转换,生成目标机器码。本实施例通过对源代码进行标准修正,预处理代码满足标准规范,符合不同目标平台的代码执行需求,经过后端分析生成混合编译信息,根据混合编译信息生成目标机器码,无需目标平台辅助编译,实现适配多个目标平台的混合编译。This embodiment obtains source code through a text file of an editor, performs standard corrections according to the source code, generates preprocessing code, performs back-end analysis according to the preprocessing code, generates mixed compilation information, performs machine language conversion according to the mixed compilation information, and generates target machine code. This embodiment performs standard corrections on the source code, the preprocessing code meets the standard specifications, meets the code execution requirements of different target platforms, generates mixed compilation information after back-end analysis, generates target machine code according to the mixed compilation information, and does not require auxiliary compilation of the target platform, so as to achieve mixed compilation adapted to multiple target platforms.

在一实施例中,所述预处理模块10,还用于根据所述源代码进行非规范变量转换,生成标准变量代码;根据所述标准变量代码进行错误检测,生成错误信息;根据所述错误信息对所述标准地址代码进行错误修正,生成预处理代码。In one embodiment, the preprocessing module 10 is further used to perform non-standard variable conversion according to the source code to generate standard variable code; perform error detection according to the standard variable code to generate error information; perform error correction on the standard address code according to the error information to generate preprocessing code.

在一实施例中,所述预处理模块10,还用于根据所述源代码进行指令提取,生成指令信息;根据所述指令信息对所述源代码进行非规范变量转换,生成标准变量代码。In one embodiment, the preprocessing module 10 is further used to extract instructions according to the source code to generate instruction information; and perform non-standard variable conversion on the source code according to the instruction information to generate standard variable code.

在一实施例中,所述预处理模块10,还用于根据所述源代码进行词法解析,生成关键字信息;根据所述关键字信息对所述源代码进行指令提取,生成指令信息。In one embodiment, the preprocessing module 10 is further used to perform lexical analysis on the source code to generate keyword information; and extract instructions from the source code according to the keyword information to generate instruction information.

在一实施例中,所述预处理模块10,还用于根据所述标准变量代码写入前向声明,生成标准定义代码;根据所述标准定义代码进行错误检测,生成错误信息。In one embodiment, the preprocessing module 10 is further used to write a forward declaration according to the standard variable code to generate a standard definition code; perform error detection according to the standard definition code to generate error information.

在一实施例中,所述预处理模块10,还用于根据所述标准定义代码进行地址映射转换,生成标准地址代码;根据所述标准地址代码进行错误检测,生成错误信息。In one embodiment, the preprocessing module 10 is further used to perform address mapping conversion according to the standard definition code to generate a standard address code; perform error detection according to the standard address code to generate error information.

在一实施例中,所述分析模块20,还用于根据所述预处理代码进行词法分析,生成词法信息;根据所述词法信息对所述预处理代码进行语法和语义分析,生成混合编译信息。In one embodiment, the analysis module 20 is further configured to perform lexical analysis on the preprocessed code to generate lexical information; and perform syntax and semantic analysis on the preprocessed code according to the lexical information to generate mixed compilation information.

由于本混合编译系统采用了上述所有实施例的全部技术方案,因此至少具有上述实施例的技术方案所带来的所有有益效果,在此不再一一赘述。Since the hybrid compilation system adopts all the technical solutions of all the above embodiments, it has at least all the beneficial effects brought by the technical solutions of the above embodiments, which will not be described one by one here.

应当理解的是,以上仅为举例说明,对本发明的技术方案并不构成任何限定,在具体应用中,本领域的技术人员可以根据需要进行设置,本发明对此不做限制。It should be understood that the above is only an example and does not constitute any limitation on the technical solution of the present invention. In specific applications, technicians in this field can make settings as needed, and the present invention does not limit this.

需要说明的是,以上所描述的工作流程仅仅是示意性的,并不对本发明的保护范围构成限定,在实际应用中,本领域的技术人员可以根据实际的需要选择其中的部分或者全部来实现本实施例方案的目的,此处不做限制。It should be noted that the workflow described above is merely illustrative and does not limit the scope of protection of the present invention. In practical applications, technicians in this field can select part or all of them according to actual needs to achieve the purpose of the present embodiment, and no limitation is made here.

另外,未在本实施例中详尽描述的技术细节,可参见本发明任意实施例所提供的混合编译方法,此处不再赘述。In addition, for technical details not fully described in this embodiment, reference may be made to the hybrid compilation method provided in any embodiment of the present invention, and will not be repeated here.

此外,需要说明的是,在本文中,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、物品或者系统不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、物品或者系统所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括该要素的过程、方法、物品或者系统中还存在另外的相同要素。In addition, it should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or system including a series of elements includes not only those elements, but also includes other elements not explicitly listed, or also includes elements inherent to such process, method, article or system. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or system including the element.

上述本发明实施例序号仅仅为了描述,不代表实施例的优劣。The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.

通过以上的实施方式的描述,本领域的技术人员可以清楚地了解到上述实施例方法可借助软件加必需的通用硬件平台的方式来实现,当然也可以通过硬件,但很多情况下前者是更佳的实施方式。基于这样的理解,本发明的技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质(如只读存储器(Read Only Memory,ROM)/RAM、磁碟、光盘)中,包括若干指令用以使得一台终端设备(可以是手机,计算机,服务器,或者网络设备等)执行本发明各个实施例所述的方法。Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a storage medium (such as a read-only memory (ROM)/RAM, a magnetic disk, or an optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods described in each embodiment of the present invention.

以上仅为本发明的优选实施例,并非因此限制本发明的专利范围,凡是利用本发明说明书及附图内容所作的等效结构或等效流程变换,或直接或间接运用在其他相关的技术领域,均同理包括在本发明的专利保护范围内。The above are only preferred embodiments of the present invention, and are not intended to limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made using the contents of the present invention specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.

Claims (8)

1.一种混合编译方法,其特征在于,所述混合编译方法包括:1. A hybrid compilation method, characterized in that the hybrid compilation method comprises: 通过编辑器的文本文件获取源代码;Get the source code through the text file of the editor; 根据所述源代码进行标准修正,生成预处理代码;Perform standard modification according to the source code to generate preprocessing code; 根据所述预处理代码进行后端分析,生成混合编译信息,所述混合编译信息包括指令标号、符号表以及封装库,所述封装库用于将代码中的符号转换成外部符号供目标机器进行重定位;Performing back-end analysis according to the preprocessing code to generate mixed compilation information, wherein the mixed compilation information includes instruction labels, a symbol table and a package library, and the package library is used to convert symbols in the code into external symbols for relocation by the target machine; 根据所述混合编译信息进行机器语言转换,生成目标机器码,根据所述混合编译信息进行机器语言转换是由机器语言转换模块执行的,所述机器语言转换模块用于通过应用程序接口生成不同目标平台的可执行的目标机器码;Performing machine language conversion according to the mixed compilation information to generate target machine code, wherein the machine language conversion according to the mixed compilation information is performed by a machine language conversion module, and the machine language conversion module is used to generate executable target machine code for different target platforms through an application program interface; 所述根据所述源代码进行标准修正,生成预处理代码,包括:The step of performing standard modification according to the source code to generate preprocessing code comprises: 根据所述源代码进行非规范变量转换,生成标准变量代码;Perform non-standard variable conversion according to the source code to generate standard variable codes; 根据所述标准变量代码进行错误检测,生成错误信息,错误检测包括语法错误、类型错误以及声明错误,所述错误信息包括错误形式及错误位置;Perform error detection according to the standard variable code and generate error information, the error detection includes syntax error, type error and declaration error, and the error information includes error form and error location; 根据所述错误信息对所述标准变量代码进行错误修正,生成预处理代码;Perform error correction on the standard variable code according to the error information to generate a preprocessing code; 所述根据所述预处理代码进行后端分析,生成混合编译信息,包括:The performing back-end analysis according to the preprocessed code to generate mixed compilation information includes: 根据所述预处理代码进行词法分析,生成词法信息;Performing lexical analysis according to the preprocessing code to generate lexical information; 根据所述词法信息对所述预处理代码进行语法和语义分析,生成混合编译信息。The preprocessed code is subjected to syntax and semantic analysis according to the lexical information to generate mixed compilation information. 2.如权利要求1所述的混合编译方法,其特征在于,所述根据所述源代码进行非规范变量转换,生成标准变量代码,包括:2. The hybrid compilation method according to claim 1, wherein the converting non-standard variables according to the source code to generate standard variable codes comprises: 根据所述源代码进行指令提取,生成指令信息;Extract instructions according to the source code to generate instruction information; 根据所述指令信息对所述源代码进行非规范变量转换,生成标准变量代码。The source code is converted into non-standard variables according to the instruction information to generate standard variable codes. 3.如权利要求2所述的混合编译方法,其特征在于,所述根据所述源代码进行指令提取,生成指令信息,包括:3. The hybrid compilation method according to claim 2, wherein the extracting instructions according to the source code and generating instruction information comprises: 根据所述源代码进行词法解析,生成关键字信息;Performing lexical analysis according to the source code to generate keyword information; 根据所述关键字信息对所述源代码进行指令提取,生成指令信息。Instructions are extracted from the source code according to the keyword information to generate instruction information. 4.如权利要求1所述的混合编译方法,其特征在于,所述根据所述标准变量代码进行错误检测,生成错误信息,包括:4. The hybrid compilation method according to claim 1, wherein the performing error detection according to the standard variable code and generating error information comprises: 根据所述标准变量代码写入前向声明,生成标准定义代码;Write forward declarations according to the standard variable codes to generate standard definition codes; 根据所述标准定义代码进行错误检测,生成错误信息。Error detection is performed according to the standard definition code to generate error information. 5.如权利要求4所述的混合编译方法,其特征在于,所述根据所述标准定义代码进行错误检测,生成错误信息,包括:5. The hybrid compilation method according to claim 4, wherein the performing error detection according to the standard definition code and generating error information comprises: 根据所述标准定义代码进行地址映射转换,生成标准地址代码;Perform address mapping conversion according to the standard definition code to generate a standard address code; 根据所述标准地址代码进行错误检测,生成错误信息。Error detection is performed according to the standard address code to generate error information. 6.一种混合编译系统,其特征在于,所述混合编译系统实现如权利要求1至5中任一项所述的混合编译方法,所述混合编译系统包括:预处理模块、分析模块及机器语言转换模块;6. A hybrid compilation system, characterized in that the hybrid compilation system implements the hybrid compilation method according to any one of claims 1 to 5, and the hybrid compilation system comprises: a preprocessing module, an analysis module and a machine language conversion module; 所述预处理模块,用于通过编辑器的文本文件获取源代码;The preprocessing module is used to obtain source code through a text file of an editor; 所述预处理模块,还用于根据所述源代码进行标准修正,生成预处理代码;The preprocessing module is further used to perform standard correction according to the source code to generate preprocessing code; 所述分析模块,用于根据所述预处理代码进行后端分析,生成混合编译信息,所述混合编译信息包括指令标号、符号表以及封装库,所述封装库用于将代码中的符号转换成外部符号供目标机器进行重定位;The analysis module is used for performing back-end analysis according to the preprocessing code to generate mixed compilation information, wherein the mixed compilation information includes instruction labels, a symbol table and a package library, and the package library is used for converting symbols in the code into external symbols for relocation by the target machine; 所述机器语言转换模块,用于根据所述混合编译信息进行机器语言转换,生成目标机器码,根据所述混合编译信息进行机器语言转换是由机器语言转换模块执行的,所述机器语言转换模块用于通过应用程序接口生成不同目标平台的可执行的目标机器码;The machine language conversion module is used to perform machine language conversion according to the mixed compilation information to generate target machine code. The machine language conversion according to the mixed compilation information is performed by the machine language conversion module. The machine language conversion module is used to generate executable target machine code for different target platforms through an application program interface. 所述预处理模块,还用于根据所述源代码进行非规范变量转换,生成标准变量代码;根据所述标准变量代码进行错误检测,生成错误信息,错误检测包括语法错误、类型错误以及声明错误,所述错误信息包括错误形式及错误位置;根据所述错误信息对所述标准变量代码进行错误修正,生成预处理代码;The preprocessing module is further used to perform non-standard variable conversion according to the source code to generate standard variable code; perform error detection according to the standard variable code to generate error information, the error detection includes syntax error, type error and declaration error, and the error information includes error form and error position; perform error correction on the standard variable code according to the error information to generate preprocessing code; 所述分析模块,还用于根据所述预处理代码进行词法分析,生成词法信息;根据所述词法信息对所述预处理代码进行语法和语义分析,生成混合编译信息。The analysis module is further used to perform lexical analysis on the preprocessed code to generate lexical information; and perform syntax and semantic analysis on the preprocessed code according to the lexical information to generate mixed compilation information. 7.一种编辑器,其特征在于,所述编辑器包括:存储器、处理器及存储在所述存储器上并可在所述处理器上运行的混合编译程序,所述混合编译程序配置为实现如权利要求1至5任一项所述的混合编译方法。7. An editor, characterized in that the editor comprises: a memory, a processor, and a hybrid compilation program stored in the memory and executable on the processor, wherein the hybrid compilation program is configured to implement the hybrid compilation method according to any one of claims 1 to 5. 8.一种存储介质,其特征在于,所述存储介质上存储有混合编译程序,所述混合编译程序被处理器执行时实现如权利要求1至5任一项所述的混合编译方法。8. A storage medium, characterized in that a hybrid compilation program is stored on the storage medium, and when the hybrid compilation program is executed by a processor, the hybrid compilation method according to any one of claims 1 to 5 is implemented.
CN202110911916.2A 2021-08-09 2021-08-09 Hybrid compiling method, hybrid compiling system, compiler and storage medium Active CN113687833B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110911916.2A CN113687833B (en) 2021-08-09 2021-08-09 Hybrid compiling method, hybrid compiling system, compiler and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110911916.2A CN113687833B (en) 2021-08-09 2021-08-09 Hybrid compiling method, hybrid compiling system, compiler and storage medium

Publications (2)

Publication Number Publication Date
CN113687833A CN113687833A (en) 2021-11-23
CN113687833B true CN113687833B (en) 2024-06-21

Family

ID=78579410

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110911916.2A Active CN113687833B (en) 2021-08-09 2021-08-09 Hybrid compiling method, hybrid compiling system, compiler and storage medium

Country Status (1)

Country Link
CN (1) CN113687833B (en)

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114968260B (en) * 2022-06-13 2025-03-18 深圳市汇川技术股份有限公司 Hybrid precompilation method, device, electronic device and storage medium
CN115495093B (en) * 2022-11-07 2023-07-21 深圳鲲云信息科技有限公司 Hybrid compiling method and device, electronic equipment and storage medium
CN118069219A (en) * 2022-11-23 2024-05-24 深圳市汇川技术股份有限公司 Hybrid execution method, device, equipment and medium of programmable logic controller
CN118550543B (en) 2024-05-17 2025-02-25 广州云标局网络科技有限公司 A mixed language recognition method and system

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109918081A (en) * 2019-03-01 2019-06-21 中安智联未来有限公司 A kind of Compilation Method and compiler
CN110134378A (en) * 2018-02-08 2019-08-16 腾讯科技(深圳)有限公司 Application program creation method and device, computer equipment and storage medium

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101315606A (en) * 2008-05-08 2008-12-03 李湘江 Method for VB and VC program mixed compiling link
EP3607431B1 (en) * 2017-04-03 2025-05-07 Innovation First, Inc. Mixed mode programming
CN111736838B (en) * 2019-03-25 2025-02-21 华为技术有限公司 A cross-language compilation method and device

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110134378A (en) * 2018-02-08 2019-08-16 腾讯科技(深圳)有限公司 Application program creation method and device, computer equipment and storage medium
CN109918081A (en) * 2019-03-01 2019-06-21 中安智联未来有限公司 A kind of Compilation Method and compiler

Also Published As

Publication number Publication date
CN113687833A (en) 2021-11-23

Similar Documents

Publication Publication Date Title
CN113687833B (en) Hybrid compiling method, hybrid compiling system, compiler and storage medium
US7219338B2 (en) Multi-language compilation
US20060271920A1 (en) Multilingual compiler system and method
US8806452B2 (en) Transformation of computer programs and eliminating errors
CN102830975B (en) A kind of assembly language is to the code conversion method of higher level lanquage and device
CN104657189B (en) Hybrid dynamic code compiling device, method and service system
US8881123B2 (en) Enabling symbol resolution of private symbols in legacy programs and optimizing access to the private symbols
CN111913741B (en) Object interception method, device, medium and electronic equipment
US20110276950A1 (en) Name binding extensibility for typed programming language
CN103218294A (en) Debugging method for embedded system, debugging conversion device and system
CN112379917A (en) Browser compatibility improving method, device, equipment and storage medium
US7539981B2 (en) XML-based preprocessor
CN114489653A (en) Compiler-based data processing method, compiler-based data processing device and readable storage medium
CN110737431B (en) Software development method, development platform, terminal device and storage medium
CN118760437A (en) Method for translating multi-language front-end into yak bytecode of network security compiler
CN110110299B (en) Text transformation method, device and server
CN121008828A (en) Permission configuration methods and devices
CN117270962B (en) Method and device for processing coloring language, storage medium and electronic equipment
US8341607B2 (en) Condensing pattern matcher generation for intermediate language patterns
WO2025093052A1 (en) Low-code conversion method and apparatus, readable storage medium, and device
CN118733007A (en) Python-based code automatic generation and automatic checking method
CN105867992A (en) Code compiling method and device
CN111796832B (en) Hot patch file generation method, device, equipment and storage medium
CN114168189A (en) A Vue project code translation method, device and medium
CN112596737A (en) Method, system, equipment and storage medium for scanning function call relation

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant