CN117075912B - Method for program language conversion, compiling method and related equipment - Google Patents

Method for program language conversion, compiling method and related equipment Download PDF

Info

Publication number
CN117075912B
CN117075912B CN202311334874.6A CN202311334874A CN117075912B CN 117075912 B CN117075912 B CN 117075912B CN 202311334874 A CN202311334874 A CN 202311334874A CN 117075912 B CN117075912 B CN 117075912B
Authority
CN
China
Prior art keywords
language
function
template
objective function
information
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
CN202311334874.6A
Other languages
Chinese (zh)
Other versions
CN117075912A (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.)
Xinxingji Technology Co ltd
Original Assignee
Xinxingji 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 Xinxingji Technology Co ltd filed Critical Xinxingji Technology Co ltd
Priority to CN202311334874.6A priority Critical patent/CN117075912B/en
Publication of CN117075912A publication Critical patent/CN117075912A/en
Application granted granted Critical
Publication of CN117075912B publication Critical patent/CN117075912B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/42Syntactic analysis
    • G06F8/427Parsing
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/36Software reuse
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/44Encoding
    • G06F8/447Target code generation

Abstract

The application provides a method for converting a program language, a compiling method and related equipment, and information of an objective function is analyzed through a preset analysis template, wherein the objective function comprises a calling function written in a first language, an instruction used for converting an instruction written in a second language into the first language is generated according to the information of the objective function, and a wrapper function of the objective function is called according to the instruction of the first language. By utilizing the method provided by the application, the writing flow of the packaging function is simplified, and the burden of program developers is reduced.

Description

Method for program language conversion, compiling method and related equipment
Technical Field
The present disclosure relates to the field of computer technologies, and in particular, to a method for converting a program language, a compiling method, and related devices.
Background
With the template support provided in the c++ language, a compiler may instantiate it at program compilation time from a given template code and a given template argument to generate the actual code and compile it into a binary program.
In an application scenario of calling a C++ interface function by using a Tcl command, a wrapper function is needed to convert a character string input in a Tcl command line into a parameter type of the C++ interface function according to a certain format, so that the C++ interface function is transferred and called. If the input information is wrong, corresponding error reporting processing is needed. After the C++ interface function call is completed, if a return value exists, the return value needs to be converted into a corresponding character string according to a certain format, and the character string is used as an output result of a Tcl command.
However, the packing function is cumbersome to write, which increases the burden on the program developer. How to simplify the writing process of the packing function is a problem to be solved.
Disclosure of Invention
In view of the foregoing, it is an object of the present application to provide a method for converting a program language, a compiling method and related devices.
In view of the above object, the present application provides, in a first aspect, a method for program language conversion, including:
acquiring an objective function; wherein the objective function comprises a calling function written in a first language;
analyzing the objective function by using a preset analysis template to obtain information of the objective function;
generating a packaging function according to the information of the objective function; the wrapper function is used for converting instructions in a second language into calls to target functions in a first language.
Optionally, the preset analysis template includes a first analysis template, a second analysis template and a third analysis template;
the analyzing the objective function by using a preset analysis template to obtain the information of the objective function further includes:
and instantiating the first analysis template and the second analysis template by utilizing the static information of the third analysis template and the objective function so as to analyze the objective function and obtain the information of the objective function.
Optionally, the information of the objective function includes an identifier; the generating a wrapper function according to the information of the objective function further comprises:
invoking a first function in response to the number of identifiers being consistent with the number of preset identifiers; the first function is used for converting the data types supported by the first language into the data types supported by the second language.
Optionally, the information of the objective function further includes a type of parameter; the method further comprises the steps of:
calling a reflection template according to the type of the parameter; wherein the reflection template defines a data structure of the first language and a conversion rule of the input information of the second language.
Optionally, the method further comprises: and calling a registration interface provided by a second language to register the wrapper function in the program.
Optionally, the data types supported by the first language include integer, double-precision floating point type and floating point type; the data types supported by the second language include a string type.
Optionally, the first language comprises a c++ language and the second language comprises a Tcl language.
In a second aspect of the present application, a compiling method is provided, including:
acquiring source code written in a first language, wherein the source code comprises a packing function obtained by adopting the method in the first aspect;
compiling the source code into object code.
In a third aspect of the present application, there is provided a computer device comprising:
one or more processors, memory; and
one or more programs;
wherein the one or more programs are stored in the memory and executed by the one or more processors, the programs comprising instructions for performing the method according to the first aspect.
In a fourth aspect of the present application, there is provided a non-transitory computer readable storage medium containing a computer program which, when executed by one or more processors, causes the processors to perform the method according to the first aspect.
As can be seen from the foregoing, the method for converting a program language, the compiling method and the related device provided by the present application analyze information of an objective function through a preset analysis template, where the objective function includes a calling function written in a first language, so as to generate an instruction for converting an instruction written in a second language into the first language according to the information of the objective function, and call a wrapper function of the objective function according to the instruction in the first language. By utilizing the method provided by the application, the writing flow of the packaging function is simplified, and the burden of program developers is reduced.
Drawings
In order to more clearly illustrate the technical solutions of the present application or related art, the drawings that are required to be used in the description of the embodiments or related art will be briefly described below, and it is apparent that the drawings in the following description are only embodiments of the present application, and other drawings may be obtained according to these drawings without inventive effort to those of ordinary skill in the art.
Fig. 1 shows a schematic structural diagram of an electronic device according to an embodiment of the present application.
FIG. 2 shows a basic structural schematic of a simulation tool in accordance with an embodiment of the present application.
Fig. 3 shows a flowchart of a method for converting a program language according to an embodiment of the present application.
FIG. 4 shows a schematic diagram of an exemplary compiler according to an embodiment of the present application.
Fig. 5 shows a schematic diagram of an exemplary compiling method according to an embodiment of the application.
Fig. 6 shows a schematic diagram of an exemplary application scenario according to an embodiment of the present application.
Detailed Description
For the purposes of making the objects, technical solutions and advantages of the present application more apparent, the present application will be further described in detail below with reference to the accompanying drawings.
It should be noted that unless otherwise defined, technical or scientific terms used in the embodiments of the present application should be given the ordinary meaning as understood by one of ordinary skill in the art to which the present application belongs. The terms "first," "second," and the like, as used in embodiments of the present application, do not denote any order, quantity, or importance, but rather are used to distinguish one element from another. The word "comprising" or "comprises", and the like, means that elements or items preceding the word are included in the element or item listed after the word and equivalents thereof, but does not exclude other elements or items. The terms "connected" or "connected," and the like, are not limited to physical or mechanical connections, but may include electrical connections, whether direct or indirect. "upper", "lower", "left", "right", etc. are used merely to indicate relative positional relationships, which may also be changed when the absolute position of the object to be described is changed.
Fig. 1 shows a schematic structural diagram of an electronic device 100 according to an embodiment of the present application. The electronic device 100 may be, for example, a computer host. The electronic device 100 may include: processor 102, memory 104, network interface 106, peripheral interface 108, and bus 110. Wherein the processor 102, the memory 104, the network interface 106, and the peripheral interface 108 are communicatively coupled to each other within the device via a bus 110.
The processor 102 may be a central processing unit (Central Processing Unit, CPU), an image processor, a neural Network Processor (NPU), a Microcontroller (MCU), a programmable logic device, a Digital Signal Processor (DSP), an application specific integrated circuit (Application Specific Integrated Circuit, ASIC), or one or more integrated circuits. The processor 102 may be used to perform functions related to the techniques described herein. In some embodiments, processor 102 may also include multiple processors integrated as a single logical component. As shown in fig. 1, the processor 102 may include a plurality of processors 102a, 102b, and 102c.
The memory 104 may be configured to store data (e.g., instruction sets, computer code, intermediate data, etc.). For example, as shown in fig. 1, the stored data may include program instructions (e.g., program instructions for implementing the techniques of the present application) as well as data to be processed (e.g., memory 104 may store temporary code generated during compilation). The processor 102 may also access stored program instructions and data and execute the program instructions to operate on the data to be processed. The memory 104 may include volatile storage or nonvolatile storage. In some embodiments, memory 104 may include Random Access Memory (RAM), read Only Memory (ROM), optical disks, magnetic disks, hard disks, solid State Disks (SSD), flash memory, memory sticks, and the like.
The network interface 106 may be configured to provide communication with other external devices to the electronic device 100 via a network. The network may be any wired or wireless network capable of transmitting and receiving data. For example, the network may be a wired network, a local wireless network (e.g., bluetooth, wiFi, near Field Communication (NFC), etc.), a cellular network, the internet, or a combination of the foregoing. It will be appreciated that the type of network is not limited to the specific examples described above. In some embodiments, network interface 106 may include any combination of any number of Network Interface Controllers (NICs), radio frequency modules, receivers, modems, routers, gateways, adapters, cellular network chips, etc.
The peripheral interface 108 may be configured to connect the electronic apparatus 100 with one or more peripheral devices to enable information input and output. For example, the peripheral devices may include input devices such as keyboards, mice, touchpads, touch screens, microphones, various types of sensors, and output devices such as displays, speakers, vibrators, and indicators.
Bus 110 may be configured to transfer information between the various components of electronic device 100 (e.g., processor 102, memory 104, network interface 106, and peripheral interface 108), such as an internal bus (e.g., processor-memory bus), an external bus (USB port, PCI-E bus), etc.
It should be noted that although the above-described device only shows the processor 102, the memory 104, the network interface 106, the peripheral interface 108, and the bus 110, in a specific implementation, the device may also include other components necessary to achieve proper operation. Furthermore, it will be understood by those skilled in the art that the above-described apparatus may include only the components necessary to implement the embodiments of the present application, and not all the components shown in the drawings.
FIG. 2 shows a basic structural schematic of a simulation tool 200 in accordance with an embodiment of the present application.
As shown in fig. 2, the user portion is above the dashed line; below the dashed line is a simulation tool 200, the simulation tool 200 may be implemented by the apparatus 100 shown in FIG. 1. Simulation tool 200 can include a Tcl command (or graphical/window interface) module 204, computing modules (e.g., a Place computing module 206, a Route computing module 208, an Optimization computing module 210, etc.), and a database system 212. User 202 may operate simulation tool 200 by entering relevant commands in Tcl command (or graphical/window interface) module 204. In some embodiments, the simulation tool 200 may be any EDA (electronic design Automation ) software.
Tcl command module 204 functions primarily as message passing or command passing. Tcl command module 204 may read instructions entered by user 202 into simulation tool 200 and may assign and pass to the corresponding computing module to perform specific tasks based on the specific content of the instructions.
The calculation modules may be divided into, for example, a plane calculation module 206, a Route calculation module 208, an Optimization calculation module 210, and the like, according to the calculation tasks. The space calculation module 206 may be configured to calculate a reasonable placement position for all components, the Route calculation module 208 may be configured to calculate a reasonable wire connection manner between components, and the Optimization calculation module 210 may be configured to optimize the placement position and the wire connection manner between components. The computation of these computation modules may be performed, for example, in the processor 102 of fig. 1.
Database system 212 may be used to fully record, store, etc., all information (e.g., location, orientation, size, configuration, wire connection, etc.) of a chip being emulated or designed, for example, in memory 104 of fig. 1. The database system 212 may include database systems of different angles, such as database system (schematic view angle) 2122 and database system (memory angle) 2124 as shown in fig. 2, among others.
As previously described, simulation tool 200 is typically only capable of responding to and performing corresponding operations in accordance with a Tcl command. However, in many cases, the interface functions are written in C++, which requires wrapper functions to implement the invocation of the C++ interface functions by the Tcl commands.
As described in the background art, the writing of the wrapper functions is complicated, and the burden of program developers is increased. How to simplify the writing process of the packing function is a problem to be solved.
The data types supported by the c++ language may include integer, double-precision floating-point, floating-point. However, the data types supported by the Tcl language used by the Tcl command include string types. The function written in the c++ language may be a name_result_type func (int a, double b, someType C). It can be seen that the c++ function may include a plurality of data types, and when the developer writes the wrapper function, the developer needs to identify the data types in the c++ function one by one, and when the c++ function is called, relevant information (such as input parameters and output return values) are converted between types supported by the first language and the second language, and for each interface function, the wrapper function needs to be rewritten and relevant conversion logic needs to be reprocessed, and if some type of conversion logic is modified, the maintenance is difficult. Therefore, the packing function is complicated to write and maintain, which increases the burden on program developers.
In view of this, the present application provides a method for program language conversion, a compiling method and related equipment, which analyze information of an objective function through a preset analysis template, wherein the objective function includes a calling function written in a first language, so as to generate an instruction for converting an instruction written in a second language into the first language according to the information of the objective function, and call a wrapper function of the objective function according to the instruction in the first language. By utilizing the method provided by the application, the writing flow of the packaging function is simplified, and the burden of program developers is reduced.
The method for converting the program language provided by the embodiment of the application can be applied to terminal equipment, and the terminal equipment can be any one of the following: desktop computers, notebook computers, tablet computers, smart phones, and the like.
Fig. 3 shows a flowchart of a method 300 for converting a program language according to an embodiment of the present application. As shown in fig. 3, the method 300 includes:
step 302: acquiring an objective function; wherein the objective function comprises a calling function written in a first language. Wherein the first language may include the c++ language, or the like. The data types supported by the first language may include integer, double-precision floating point, etc., which are not limited in this application.
Step 304: and analyzing the objective function by using a preset analysis template to obtain the information of the objective function. The information of the objective function may include the number, type of parameters and return type of the function
As described above, in the related art, the writing of the wrapper function requires a developer to recognize the type of parameters in the c++ interface function. In order to simplify the writing work of the developer, in some embodiments, function information of the obtained objective function may be parsed by a preset parsing template.
In some embodiments, the preset parsing templates may include a first parsing template, a second parsing template, and a third parsing template. The static information of the third analysis template and the objective function can be utilized to instantiate the first analysis template and the second analysis template so as to analyze the objective function and obtain the information of the objective function. Therefore, the parameter information of the C++ function is automatically analyzed through the preset analysis template, and the identification is not needed manually, so that the analysis speed of the parameter information is increased, and the burden of a developer is reduced.
For example, a first parse template type_at may be written accepting a std:: size_ t I and a variable type template parameter package. When the input parameters are correct, a member type is generated and represents the parameter type of the designated position in the parameter package. Wherein the input I is used to represent an index of the location.
A second parsing template type sequence may be written accepting a variable type template parameter package. A member template type is contained, a std is accepted, size_t is taken as a template parameter, and a first analysis template type_at is called to generate a parameter type of a designated position.
A third parsing template function info may be written accepting a function type. A member type is contained, and the member type represents the input function type; the method also comprises a member type return_type which represents the return type of the function; the method also comprises a member type parameter_sequence which is realized by a second analysis template type_sequence and represents a parameter type package of the function; also contains a member template parameter_type, accepts a std:: size_ t I as a template parameter, and is implemented with template parameter _sequence:: template type < I >, indicating the parameter type of the specified location.
In the above template, the third parsing template function_info may be directly used to parse information such as parameters and return types of the input function by instantiating the first parsing template and the second parsing template.
It should be noted that, the preset parsing templates used in the embodiments of the present application are not limited to the first parsing template, the second parsing template, and the third parsing template, which are not limited in this application.
Step 306: generating a packaging function according to the information of the objective function; the wrapper function is used for converting instructions in a second language into calls to target functions in a first language. Wherein the second language may be Tcl language, etc. The data types supported by the second language may include a string type, etc., which is not limited in this application.
In some embodiments, macros may be used to wrap all of the wrapper function's required content for subsequent convenience in registering the wrapper function. Wherein, the macro is used for replacing all the specified identifiers which appear with defined contents according to the macro definition.
The following is a brief introduction to macros.
Macros are text substitutions of the source code in a certain order during the preprocessing stage, which occur prior to compiling steps such as c++ parsing. Taking the __ LINE __ macro as an example, when using the __ LINE __ macro, the __ LINE __ would become the LINE number for the user to call due to the text replacement nature of the macro. Therefore, the packing function is generated according to the analyzed parameter information through the macro, a developer does not need to manually write a conversion code corresponding to each parameter information according to the parameter information, and the burden of the developer is reduced.
As an alternative embodiment, the template function may also be used to wrap the content required by the wrapper function. When using a template function, __ LINE __ becomes a symbol at the function definition because the template function is a syntactic content of c++.
In some embodiments, a template may be provided for defining conversion rules for the first language and the second language. For example, conversion rules between the parameters and data types of the return type supported by the C++ language and the string type supported by the Tcl language may be defined. The template may be a reflection template region_func, which accepts a return type as a template parameter, optionally defining the required transformation function. The reflection template defines a data structure in a first language and conversion rules for input information in a second language.
For example, the macro may be a base macro xda_register_tcl_command_v_rbose, and the input information required by the base macro is: FUNCTION NAME (function_name), FUNCTION pointer (function_ptr), template NAME (reflection_traits_type) of the reflection template.
In some embodiments, the information of the objective function further includes a type of parameter. The reflection template may be invoked according to the type of parameter.
In some embodiments, the base macros may be used to generate the wrapper functions. The base macro is replaced with a namespace field_func that has a type alias function_info_t and two FUNCTIONs built in, one of which is an invoker template FUNCTION (e.g., the first FUNCTION) that makes the actual call to the function_ptr and the other is the actual wrapper FUNCTION wrapier.
Wherein function_info_t is used to simplify access to function_info < std:: remove_cv_t < std:: remove_pointer_t < std:: remove_reference_t < uncltype (function_PTR > > >).
The invoker template function is used to convert data types supported by a first language to data types supported by a second language. The template parameter list of the invoker template function is std, the parameter packet of size_t is Ints, the parameter list is Tcl_Interp, const char argv [ ], std, index_sequence < Ints … >, and the last parameter is used for deducing the parameter content of the Ints template.
In some embodiments, the second language type may be a Tcl language, and when the second language is a Tcl language, then the wrapper function is required to be consistent with the tcl_cmdproc type.
In some embodiments, when using an invoker template FUNCTION, if the return TYPE of the FUNCTION is the same as void, then std:invoke (function_PTR, REFLECT_TRAITS_TYPE < function_info_t:parameter_type < bits >: decode (argv [ bits+1 ]) …); otherwise, return value result call REFLECT_TRAITS_TYPE < function_info_t:: return_type >: encode (inter, std:: forward < function_info_t::: return_type > (result)) is also required on the above basis. Wherein, the encode and decode are the interface of the character string agreed by the reflection template REFLECT_TRAITS_TYPE and the conversion of the object of the appointed TYPE.
In some embodiments, the information of the objective function may include an identifier, and when using the wrapper function, the wrapper function may be generated using the identifier of the objective function. For example, the number of identifiers may be defined as parameter_size. It is determined whether the number of identifiers corresponds to the number of preset identifiers (parameter_size+1) (1 is required because command name occupies a PARAMETER). If so, an invoker function (e.g., the first function) is called, otherwise an error is reported. It should be noted that the third PARAMETER of the invoker function needs to pass std: < parameter_size > () to let the invoker automatically infer its template PARAMETERs. The first function is used to convert data types supported by a first language to data types supported by a second language.
On the basis of the base macro, some simplified wrapper function generating macros, such as xda_register_tcl_command, may be encapsulated, requiring only one function name. The function name of the macro can be used to obtain the function pointer without ambiguity, and the region_func:: reflectance_traits can be used as a default reflection template.
The generated wrapper function needs to be registered in the program to use the wrapper function. In some embodiments, a registration interface provided in the second language may be invoked to register the wrapper function in the program.
In some embodiments, the script may be used to parse the specified header file, parse the immediately adjacent function declaration with the contract annotation @ REGISTER TCL COMMAND, parse the relevant information such as its function type, call the appropriate wrapper function in the namespace scope to generate the macro, call the tcl_createcommand in the specified function to REGISTER the wrapper function in the corresponding namespace. The user only needs to call the appointed function name in the Tcl initialization code to correctly register all corresponding commands.
According to the method for converting the program language, information of the objective function is analyzed through the preset analysis template, wherein the objective function comprises a calling function written in a first language, an instruction for converting an instruction written in a second language into the first language is generated according to the information of the objective function, and a wrapper function of the objective function is called according to the instruction of the first language. By utilizing the method provided by the application, the writing flow of the packaging function is simplified, and the burden of program developers is reduced.
FIG. 4 shows a schematic diagram of an exemplary compiler 410 according to an embodiment of the present application. Compiler 410 may be run on simulation tool 200.
Compiler 210 may receive source code 404 (e.g., code described in the c++ language) and compile into execution code 406 (e.g., machine code, assembly code, etc.). As shown in fig. 4, compiler 410 may include front end 412, middle end 414, and back end 416.
Front end 412 may be used to analyze the lexical, grammatical, semantic of source code according to a particular source language.
After the lexical, grammatical, and semantic analysis of the source code is complete, the middle end 414 may convert the source code into an intermediate representation (or intermediate code) and may optimize the intermediate representation. Intermediate language (intermediate code) is a grammar-oriented, equivalent internal representation code that is easily translated into source code of the target program. The degree of understandability and ease of generating the execution code is intermediate between the source code and the execution code. Common intermediate codes are inverse Polish representations, quaternions, ternary and tree representations, etc. For example, the middle end 414 may remove unwanted code, remove inaccessible code, clear unused variables, and the like. The optimizations may include machine dependent optimizations and machine independent optimizations. The optimized intermediate representation may then be passed to back end 416 for further processing.
The back end 416 may further optimize the intermediate representation according to the architecture of the target processor (e.g., the processor 102 of fig. 1) and generate the execution code. Typically, the execution code is machine code.
It is to be appreciated that the structure of compiler 410 is not limited to the example of FIG. 4. For example, front end 412 and middle end 414 may be collectively referred to as the front end of a compiler.
Fig. 5 shows a schematic diagram of an exemplary compilation method 500 in accordance with an embodiment of the present application. The compilation method 500 may be implemented by the simulation tool 200 shown in FIG. 2, and more particularly, by a compiler (e.g., the compiler 410 of FIG. 4) running on the simulation tool 200. The compiling method 500 may comprise the following steps.
Step 502: compiler 410 may obtain source code written in a first language (i.e., computer code to be compiled). Wherein the source code includes wrapper functions generated according to method 300.
Step 504: compiler 410 compiles the source code into object code (i.e., execution code).
The embodiment of the application also provides computer equipment. The computer device may be the electronic device 100 of fig. 1. The electronic device 100 may include one or more processors, memory; and one or more programs; wherein the one or more programs are stored in the memory and executed by the one or more processors, the programs including instructions for performing the method 300 of any of the embodiments described above.
The present application also provides a non-transitory computer readable storage medium containing a computer program, the non-transitory computer readable storage medium storing computer instructions for causing the computer to perform the method 300 of any of the embodiments above.
The computer readable media of the present embodiments, including both permanent and non-permanent, removable and non-removable media, may be any method or technology for information storage. The information may be computer readable instructions, data structures, modules of a program, or other data. Examples of storage media for a computer include, but are not limited to, phase change memory (PRAM), static Random Access Memory (SRAM), dynamic Random Access Memory (DRAM), other types of Random Access Memory (RAM), read Only Memory (ROM), electrically Erasable Programmable Read Only Memory (EEPROM), flash memory or other memory technology, compact disc read only memory (CD-ROM), digital Versatile Discs (DVD) or other optical storage, magnetic cassettes, magnetic tape disk storage or other magnetic storage devices, or any other non-transmission medium, which can be used to store information that can be accessed by a computing device.
The storage medium of the foregoing embodiments stores computer instructions for causing the computer to perform the method 300 as described in any of the foregoing embodiments, and has the advantages of the corresponding method embodiments, which are not described herein.
Fig. 6 shows a schematic diagram of an exemplary application scenario 600 of an embodiment of the present application.
The application scenario 600 may include a terminal device 610 and a server 620. Wherein the terminal device 610 and the server 620 may be connected through a wired or wireless communication network. Terminal device 610 includes, but is not limited to, a desktop computer, a mobile phone, a mobile computer, a tablet computer, a media player, a smart wearable device, a personal digital assistant (personal digital assistant, PDA) or other electronic device capable of performing the functions described above, and the like. The server 620 may be an independent physical server, a server cluster or a distributed system formed by a plurality of physical servers, or a cloud server providing cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDNs, basic cloud computing services such as big data and artificial intelligence platforms, and the like.
The server 620 is configured to provide a service for program language conversion to a user of the terminal device 610, a client in communication with the server 620 is installed in the terminal device 610, and the user can input a section of code to be converted through the client, wherein the code to be converted is written in a second language, after clicking an input button, the client sends the code to be converted to the server 620, and the server 620 calls a wrapper function based on the code to be converted to convert the code to be converted written in the second language into a call to an objective function. Wherein the objective function is written in a first language. Server 620 may send the objective function to the client to call the objective function.
In some embodiments, the user may input a second language through the client.
In some embodiments, the user may input the target engine or target digital content authoring tool through the client, the second language being a language supported by the target engine or target digital content authoring tool.
In the above application scenario, the method for converting a program language is described as being executed on a server, but the disclosure is not limited thereto, and in other exemplary embodiments, the method for converting a program language may also be executed on a local terminal device, and when the method for converting a program language is executed on the local terminal device, a user may input a section of code to be converted through the local terminal device, where the code to be converted is written in a second language, after clicking an input button, the local terminal device sends the code to be converted to the server 620, and the server 620 calls a wrapper function based on the code to be converted to convert the code to be converted written in the second language into a call to an objective function. Wherein the objective function is written in a first language. The server 620 may send the objective function to the local terminal device to call the objective function.
It should be noted that the above application scenario is merely exemplary, and embodiments of the present application are not limited in this respect. Rather, embodiments of the present application may be applied to any scenario where applicable
Those of ordinary skill in the art will appreciate that: the discussion of any of the embodiments above is merely exemplary and is not intended to suggest that the scope of the application (including the claims) is limited to these examples; the technical features of the above embodiments or in the different embodiments may also be combined within the idea of the present application, the steps may be implemented in any order, and there are many other variations of the different aspects of the embodiments of the present application as described above, which are not provided in detail for the sake of brevity.
Additionally, well-known power/ground connections to Integrated Circuit (IC) chips and other components may or may not be shown within the provided figures, in order to simplify the illustration and discussion, and so as not to obscure the embodiments of the present application. Furthermore, the devices may be shown in block diagram form in order to avoid obscuring the embodiments of the present application, and this also takes into account the fact that specifics with respect to implementation of such block diagram devices are highly dependent upon the platform on which the embodiments of the present application are to be implemented (i.e., such specifics should be well within purview of one skilled in the art). Where specific details (e.g., circuits) are set forth in order to describe example embodiments of the application, it should be apparent to one skilled in the art that embodiments of the application can be practiced without, or with variation of, these specific details. Accordingly, the description is to be regarded as illustrative in nature and not as restrictive.
While the present application has been described in conjunction with specific embodiments thereof, many alternatives, modifications, and variations of those embodiments will be apparent to those skilled in the art in light of the foregoing description. For example, other memory architectures (e.g., dynamic RAM (DRAM)) may use the embodiments discussed.
The present embodiments are intended to embrace all such alternatives, modifications and variances which fall within the broad scope of the appended claims. Accordingly, any omissions, modifications, equivalents, improvements and/or the like which are within the spirit and principles of the embodiments are intended to be included within the scope of the present application.

Claims (10)

1. A method for program language conversion, comprising:
acquiring an objective function; wherein the objective function comprises a calling function written in a first language;
analyzing the objective function by using a preset analysis template to obtain information of the objective function; wherein the information of the objective function includes a type of parameter;
calling a first function according to the information of the target function to generate a packaging function; the wrapper function is used for converting an instruction of a second language into a call to a target function of a first language, and the first function is used for converting a data type supported by the first language into a data type supported by the second language;
the method further comprises the steps of:
calling a template according to the type of the parameter so as to convert the first language into the second language; wherein the template defines conversion rules for the first language and the second language.
2. The method of claim 1, wherein the preset parsing templates include a first parsing template, a second parsing template, and a third parsing template;
the analyzing the objective function by using a preset analysis template to obtain the information of the objective function further includes:
and instantiating the first analysis template and the second analysis template by utilizing the static information of the third analysis template and the objective function so as to analyze the objective function and obtain the information of the objective function.
3. The method of claim 1, wherein the information of the objective function includes an identifier; the generating a wrapper function according to the information of the target function and calling a first function further comprises:
and calling the first function in response to the number of identifiers being consistent with the number of preset identifiers.
4. The method of claim 1, wherein the template comprises a reflective template, the method further comprising:
invoking the reflection template according to the type of the parameter; wherein the reflection template defines a data structure of the first language and a conversion rule of the input information of the second language.
5. The method of claim 1, wherein the method further comprises:
and calling a registration interface provided by a second language to register the wrapper function in the program.
6. The method of any of claims 1-5, wherein the first language supported data types include integer, double precision floating point, floating point; the data types supported by the second language include a string type.
7. A method as recited in any of claims 1-5, wherein the first language comprises the c++ language and the second language comprises the Tcl language.
8. A compiling method, comprising:
obtaining source code written in a first language, the source code comprising a wrapper function obtained using the method of any of claims 1-7;
compiling the source code into object code.
9. A computer device, comprising:
one or more processors, memory; and
one or more programs;
wherein the one or more programs are stored in the memory and executed by the one or more processors, the programs comprising instructions for performing the method of any of claims 1-8.
10. A non-transitory computer readable storage medium containing a computer program, which when executed by one or more processors causes the processors to perform the method of any of claims 1-8.
CN202311334874.6A 2023-10-16 2023-10-16 Method for program language conversion, compiling method and related equipment Active CN117075912B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202311334874.6A CN117075912B (en) 2023-10-16 2023-10-16 Method for program language conversion, compiling method and related equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202311334874.6A CN117075912B (en) 2023-10-16 2023-10-16 Method for program language conversion, compiling method and related equipment

Publications (2)

Publication Number Publication Date
CN117075912A CN117075912A (en) 2023-11-17
CN117075912B true CN117075912B (en) 2023-12-26

Family

ID=88713727

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202311334874.6A Active CN117075912B (en) 2023-10-16 2023-10-16 Method for program language conversion, compiling method and related equipment

Country Status (1)

Country Link
CN (1) CN117075912B (en)

Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102929682A (en) * 2012-12-06 2013-02-13 盛科网络(苏州)有限公司 Preprocessing method and device for automatically extending TCL (Tool Command Language)
CN108182069A (en) * 2017-12-28 2018-06-19 深圳市创梦天地科技股份有限公司 Programming language transformation method, terminal device and computer-readable medium
CN113821195A (en) * 2021-09-10 2021-12-21 北京鲸鲮信息系统技术有限公司 Method, device and equipment for generating executable program of target language
CN114588638A (en) * 2022-01-26 2022-06-07 成都幻想美人鱼科技有限公司 Method for developing game based on Lua language and program development device
CN115145575A (en) * 2022-06-14 2022-10-04 网易有道信息技术(北京)有限公司 High-level language parsing method, equipment and computer readable storage medium
CN116028028A (en) * 2022-11-10 2023-04-28 北京百度网讯科技有限公司 Request function generation method, device, equipment and storage medium
CN116126705A (en) * 2023-01-06 2023-05-16 南京航空航天大学 Method for dynamically analyzing memory security of program containing specific statement
CN116302218A (en) * 2023-03-15 2023-06-23 北京百度网讯科技有限公司 Function information adding method, device, equipment and storage medium
CN116841559A (en) * 2023-07-13 2023-10-03 中国工商银行股份有限公司 Transcoding method, device, apparatus, medium and program product

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8806452B2 (en) * 2011-11-10 2014-08-12 International Business Machines Corporation Transformation of computer programs and eliminating errors

Patent Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102929682A (en) * 2012-12-06 2013-02-13 盛科网络(苏州)有限公司 Preprocessing method and device for automatically extending TCL (Tool Command Language)
CN108182069A (en) * 2017-12-28 2018-06-19 深圳市创梦天地科技股份有限公司 Programming language transformation method, terminal device and computer-readable medium
CN113821195A (en) * 2021-09-10 2021-12-21 北京鲸鲮信息系统技术有限公司 Method, device and equipment for generating executable program of target language
CN114588638A (en) * 2022-01-26 2022-06-07 成都幻想美人鱼科技有限公司 Method for developing game based on Lua language and program development device
CN115145575A (en) * 2022-06-14 2022-10-04 网易有道信息技术(北京)有限公司 High-level language parsing method, equipment and computer readable storage medium
CN116028028A (en) * 2022-11-10 2023-04-28 北京百度网讯科技有限公司 Request function generation method, device, equipment and storage medium
CN116126705A (en) * 2023-01-06 2023-05-16 南京航空航天大学 Method for dynamically analyzing memory security of program containing specific statement
CN116302218A (en) * 2023-03-15 2023-06-23 北京百度网讯科技有限公司 Function information adding method, device, equipment and storage medium
CN116841559A (en) * 2023-07-13 2023-10-03 中国工商银行股份有限公司 Transcoding method, device, apparatus, medium and program product

Non-Patent Citations (3)

* Cited by examiner, † Cited by third party
Title
CoDeSys编程语言之间的转换转化;徐海龙;《科技创新与生产力》(第8期);98-100 *
Re-engineering C++ component models via automatic program transformation;R.L. Akers 等;《12th Working Conference on Reverse Engineering》;1-9 *
函数式程序模板元编程的元建模实现方法;祝义 等;《计算机工程与应用》;第54卷(第7期);1-10 *

Also Published As

Publication number Publication date
CN117075912A (en) 2023-11-17

Similar Documents

Publication Publication Date Title
KR101645052B1 (en) Debugging pipeline
US10613844B2 (en) Using comments of a program to provide optimizations
CN114780100B (en) Compiling method, electronic device and storage medium
US9405652B2 (en) Regular expression support in instrumentation languages using kernel-mode executable code
US9875088B2 (en) Optimized compiling of a template function
WO2022068556A1 (en) Code translation method and apparatus, and device
CN114579452A (en) Interface influence detection method and related equipment
CN116228515B (en) Hardware acceleration system, method and related device
CN111880801A (en) Application program dynamic method and device and electronic equipment
CN117075912B (en) Method for program language conversion, compiling method and related equipment
US11182272B2 (en) Application state monitoring
CN115686467A (en) Type inference in dynamic languages
CN112232003B (en) Method for simulating design, electronic device and storage medium
CN114174983B (en) Method and system for optimized automatic verification of advanced constructs
CN114443042A (en) Service arrangement execution method based on rule engine and related equipment
CN110737431A (en) Software development method, development platform, terminal device and storage medium
CN111782196A (en) MVP architecture-based development method and device
US11630655B2 (en) Merging data structure definitions
CN117234466B (en) Enterprise management software development method, system, equipment and storage medium
CN114090007A (en) Multi-language text generation method, terminal and storage medium suitable for development language
CN117130677A (en) Script conversion method and related equipment
CN115033217A (en) Function conversion method, function conversion device, electronic equipment and storage medium
Vallejo Mancero et al. Design and evaluation of a heuristic optimization tool based on evolutionary grammars using PSoCs
CN113791769A (en) Data value taking method and device for complex structure and electronic equipment
CN114327469A (en) Code analysis method, device, equipment and medium

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