WASM compilation method, device, electronic device and storage medium

By identifying and merging target functions, the MAP table is generated and the corresponding files are generated using the WASM module to solve the problem of export restrictions in the WASM project. It is suitable for large projects, reducing the needs of manual writing and changes.

CN118426778BActive Publication Date: 2025-01-21司空定制家居科技有限公司
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202410380869.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-03-31
Publication Date
2025-01-21
Estimated Expiration
2044-03-31

AI Technical Summary

Technical Problem

In the prior art, the number of WASM functions exports is limited and cannot be applied to large WASM projects with complex declaration files, resulting in the need for compilation failure and manual writing changes, which increases the workload.

Method used

By identifying the target function, merging based on the return value and parameter type, generating a Map table, using the WASM module to generate JavaScript files and WebAssembly binary files, reducing the number of exported functions.

Benefits of technology

The problem of limiting the quantity of the WASM function export is suitable for large WASM projects, reducing the needs of manual writing and changing, and reducing the burden of work.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118426778B_ABST
    Figure CN118426778B_ABST
Patent Text Reader

Abstract

A WASM compilation method, device, electronic device and storage medium, relating to the technical field of computers. The WASM compilation method comprises: identifying a target function; merging the target function based on a return value and a parameter type, and generating a first Map table based on the merged result; based on the first Map table, according to the category information, using a WASM module to generate a JavaScript file for the target function and a WebAssembly binary file for the target function. The present invention can solve the technical problem that the WASM compilation method in the prior art cannot be applied to organizing large WASM projects due to the limitation on the number of WASM function exports.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to a compilation method for converting a large C++ project in the field of decoration to WASM, and in particular to a WASM compilation method, device, electronic device and storage medium. Background Art

[0002] With the promotion and development of HTML5, the browser ecosystem has been increasingly improved, and along with it, the application scenarios of WebAssembly (WASM for short) are also increasing. WASM is a virtual instruction set architecture (virtual ISA). The overall architecture includes the core ISA definition, binary encoding, definition and execution of program semantics, and application programming interfaces (WebAssembly API) for different embedded environments (such as Web). Its initial goal is to enable programs written in languages ​​such as C / C++ to run better on the Web platform at a speed close to that of native applications after compilation while ensuring safety. However, when using JavaScript (Java Script, JS for short) to access WebAssembly content, due to the limitations of WebAssembly exported projects, if there are too many exported functions, compilation failure is likely to occur. As a result, when writing large C++ projects in the field of decoration and translating them into WASM, although the existing technology provides a WASM compilation method, due to the limitation on the number of WASM function exports, the current compilation method cannot be applied to large WASM projects with complex declaration files in the field of decoration. As a result, many applications cannot be implemented and need to be manually rewritten and modified, which greatly increases the workload of programmers and decoration designers. Summary of the invention

[0003] In view of this, the present invention provides a WASM compilation method, device, electronic device and storage medium, in order to at least partially solve the above technical problems.

[0004] As a first aspect of the present invention, a WASM compilation method is provided, comprising the following steps:

[0005] Identify the target function; wherein the target function is written based on C++ language;

[0006] Merging the target functions based on return values ​​and parameter types, and generating a first Map table based on the merged result, wherein the first Map table includes at least one category information of the target function and the corresponding target function;

[0007] Based on the first Map table and according to the category information, a WASM module is used to generate a JavaScript file for the target function and a WebAssembly binary file for the target function for the target function.

[0008] The present invention merges C++ functions of the same category and compiles them based on the merged results to generate JavaScript files and WebAssembly binary files, thereby reducing the number of exported WASM functions and solving the technical problem in the prior art that the WASM compilation method cannot be used for large WASM projects due to the limited number of WASM function exports.

[0009] In one possible manner, the step of identifying the target function specifically includes:

[0010] Parse the declaration file where the target function is located to obtain description information;

[0011] The objective function is identified based on the description information.

[0012] One possible way is that, based on the first Map table and according to the category information, the step of using the WASM module to generate a JavaScript file for the target function and a WebAssembly binary file for the target function specifically includes:

[0013] Generate a C++ proxy code for the target function and a JS proxy code for the target function based on the first Map table;

[0014] Based on the category information, the C++ proxy code for the target function and the JS proxy code for the target function use WASM to generate a JavaScript file for the target function and a WebAssembly binary file for the target function.

[0015] One possible approach is that the objective function includes attributes using corresponding description information;

[0016] The process of generating the C++ proxy code for the target function and the JS proxy code for the target function based on the first Map table includes:

[0017] The target function generates JS proxy code for the target function based on get and set functions.

[0018] One possible manner is that the target function includes a class using corresponding description information, and the JS proxy code is further generated based on: a second Map table and a third Map table, and the first Map table and the second Map table are generated based on the target function;

[0019] The second Map table is used for class creation;

[0020] The third Map table is used for releasing the class.

[0021] One possible way is that the JavaScript file includes the JS proxy code for the target function.

[0022] One possible manner is that the number of the category information is at least one;

[0023] In the step of using WASM to generate a JavaScript file for the target function and a binary file of WebAssembly for the target function,

[0024] Perform the following operations on the target function written in C++ language corresponding to each function type information:

[0025] Based on the C++ proxy code, the target function corresponding to the function type information is compiled using WASM.

[0026] One possible approach is that the WASM compilation method further includes:

[0027] The JavaScript file for the target function and the binary file of the WebAssembly for the target function are compressed.

[0028] One possible approach is that the WASM compilation method further includes:

[0029] The JavaScript file for the target function and the WebAssembly binary file for the target function are loaded.

[0030] As a second aspect of the present invention, a WASM compilation device is also provided, including:

[0031] An identification module, used for identifying a target function; wherein the target function is written in C++ language;

[0032] A merging module, used to merge the target functions based on return values ​​and parameter types, and generate a first Map table based on the merged result; wherein the first Map table includes at least one category information of the target function and the corresponding target function;

[0033] A generation module is used to generate a JavaScript file for the target function and a WebAssembly binary file for the target function using a WASM module for the target function based on the first Map table and according to the category information.

[0034] As a third aspect of the present invention, there is also provided an electronic device, comprising:

[0035] a memory for storing a computer program executable on the processor;

[0036] A processor, configured to execute a computer program stored in the memory to implement the WASM compilation method as described in any one of the first aspects.

[0037] As a fourth aspect of the present invention, a computer-readable medium is further provided, wherein the computer-readable medium stores a non-volatile program code that can be executed by a processor or can be executed after compilation, and the program code is used to execute the WASM compilation method as described above.

[0038] It should be understood that the second to fourth aspects of the embodiments of the present invention are consistent with the technical solutions of the first aspect of the embodiments of the present invention, and the beneficial effects achieved by each aspect and the corresponding feasible implementation methods are similar and will not be repeated herein. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for use in the embodiments are briefly introduced below. Obviously, the drawings described below are only some embodiments of the embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0040] Figure 1 This is a flowchart of a WASM compilation method according to an embodiment of the present invention;

[0041] Figure 2 It is a composition diagram of the C++ solution in the prior art of the present invention;

[0042] Figure 3 This is a flowchart of a WASM compilation method according to another embodiment of the present invention;

[0043] Figure 4 A schematic diagram of a WASM compilation method of the present invention;

[0044] Figure 5 It is a structural schematic diagram of a WASM compilation device of the present invention;

[0045] Figure 6It is a structural diagram of the electronic device of the present invention. DETAILED DESCRIPTION

[0046] In order to better understand the technical solution of the present invention, the embodiments of the present invention are described in detail below in conjunction with the accompanying drawings. It should be clear that the described embodiments are only part of the embodiments of the present invention, rather than all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the embodiments of the present invention.

[0047] The terms used in the embodiments of the present invention are only for the purpose of describing specific embodiments, and are not intended to limit the embodiments of the present invention. The singular forms "a", "said" and "the" used in the embodiments of the present invention and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings.

[0048] When writing a large computer program project in the field of decoration, the inventor found that when using JavaScript (Java Script, referred to as JS) to access WebAssembly content, due to the limitations of WebAssembly exported projects, if there are too many exported functions, compilation failure may occur. For example, a complex large-scale home improvement programming project may include dozens or even hundreds of declaration files (header files), as well as various internal function and class definitions. The compilation method in the prior art simply mechanically translates the target statement, while ignoring the various pre-defined and project settings in the declaration file (header file), resulting in compilation errors.

[0049] In view of this, please refer to Figure 1 The present invention provides a WASM compilation method, which specifically includes the following steps:

[0050] S101: Identify the target function.

[0051] Here, the objective function is written based on C++ and C# languages.

[0052] Specifically, Figure 2 This is a diagram of the C++ solution structure in the prior art. Generally speaking, a C++ solution consists of multiple projects, and each project consists of multiple declaration files and multiple implementation files.

[0053] Specifically, the target function here corresponds to the function that needs to be compiled in the end. Specifically, in the embodiment of the present invention, the description information can be obtained by analyzing the code file.

[0054] In other words, in this step, the declaration file containing the target file is first parsed to obtain description information, and the target function is identified based on the description information.

[0055] For example, use / / @class to indicate that the current class can be exported. For another example, use / / @property(get / set) to indicate that the current variable or function can be exported as a get or set property. Use / / @method to indicate a function.

[0056]

[0057] S102: Merge the target functions based on return values ​​and parameter types, and generate a first Map table based on the merged result.

[0058] Specifically, in this step, the return value type and parameter type in the C++ function are merged to generate a first Map table. Here, the first Map table includes at least one category information and a corresponding target function.

[0059] S103: Based on the first Map table and according to the category information, a WASM module is used to generate a JavaScript file for the target function and a WebAssembly binary file for the target function.

[0060] Based on S102 and S103, functions with the same return value and parameter type have been merged. At this time, compilation based on the merged functions can reduce the number of exported functions, which can solve the technical problem that the WASM compilation method in the prior art is subject to the limitation on the number of WASM function exports and is not suitable for organizing large-scale WASM projects.

[0061] Specifically, refer to Figure 3 In the aforementioned S103: based on the first Map table and according to the category information, the step of using the WASM module to generate a JavaScript file for the target function and a WebAssembly binary file for the target function for the target function specifically includes the following steps:

[0062] S103a: Generate C++ proxy code for the target function and JS proxy code for the target function based on the first Map table.

[0063] Specifically, in the embodiment provided by the present invention, in order to realize the simulation of classes, functions and properties by JS code, here, for properties, JS code uses get and set functions to realize the simulation of classes by JS code.

[0064] Generate the C++ proxy proxy.cpp as follows:

[0065]

[0066]

[0067] It can be seen that in the embodiment provided by the present invention, in the process from S103a to S103b described later, the target function generates a JS proxy code for the target function based on the get and set functions.

[0068] At the same time, in order to realize the simulation of the class, in the embodiment provided by the present invention, when the target function is exported to the JS side, a second Map table and a third Map table are also generated. Here, the second Map table is used to create the class, and the third Map table is used to release the class. The JS proxy code is generated by using the second Map and the third Map table, thereby realizing the simulation of the class on the JS side.

[0069] Generate the Javascript proxy file proxy.js as follows:

[0070]

[0071]

[0072] Regarding the simulation of the function, it is assumed here that the target function is a static function, and relevant technologies can be used to directly generate C++ proxy code for the target function and JS proxy code for the target function.

[0073] For functions within a class, use pointer functions to point to instances of the class in the C++ code.

[0074] S103b: Based on the category information, the C++ proxy code for the target function and the JS proxy code for the target function are used to generate a JavaScript file for the target function and a WebAssembly binary file for the target function using WASM.

[0075] Combined with the above, it can be known that for the compilation of C++ proxy code, here, it is assumed that in the first Map table, the number of categories after the target function is merged is multiple, and here, the following operations are performed on the target function written in C++ language corresponding to each function type information:

[0076] Based on the C++ proxy code, the target function corresponding to the function type information is compiled using WASM.

[0077]

[0078]

[0079] It is worth noting that the number of categories after the objective functions are merged is only one. Here, it also conforms to the above: the objective function written in C++ language corresponding to each function type information performs the following operations:

[0080] Based on the C++ proxy code, the logic of using WASM to compile the target function corresponding to the function type information.

[0081] Compilation method

[0082] 1) Use emcc / em++ to compile a single file into a .o file

[0083] em++.bat-XXX fileA.cpp-o fileA.o

[0084] 2) Use em++ to merge multiple fileX.o files into a single project.o file in a single project

[0085] em++.bat-XXX fileA.o fileB.o-project.o

[0086] 3) The final project is compiled into a result file using em++

[0087] em++.bat--post-js proxy.js-XXX projectA.o projectB.o proxy.o-ooutput.js

[0088] Based on step S103a, C++ proxy code for the target function and JS proxy code for the target function are generated. Here, the C++ proxy code for the target function and the JS proxy code for the target function are used for compilation, which reduces the number of exported functions and solves the technical problem that the WASM compilation method in the prior art is subject to the limitation on the number of WASM function exports and is not suitable for organizing large-scale WASM projects.

[0089] Based on the above examples, please refer to Figure 4 , Figure 4 A schematic diagram of a WASM compilation method flow chart provided in an embodiment of the present invention.

[0090] For a CPP (C++) solution, the description information is first exported, which specifically corresponds to the aforementioned step S101. After obtaining the description information, the exported description information needs to be optimized, which corresponds to the aforementioned step S102, that is, it is declared as a function set based on the return value type and the parameter type, and a first Map table is constructed. Then the first Map table generates a proxy code based on and corresponding to the aforementioned step S103a, that is, for attributes, get and set functions are generated for the attributes. For classes, Map charts are used here to implement class creation and class release, so as to realize the simulation of classes in JS.

[0091] Then enter step S103b. Specifically, compile the CPP solution (i.e., the parsed file) to generate an implementation file, compile the C++ proxy code for the target function of S103a to generate a C++ proxy file for the target function, and compile the C++ proxy code for the target function at the same time to generate the final compiled file, i.e., a JavaScript file for the target function and a WebAssembly binary file for the target function.

[0092] On the basis of the foregoing embodiments, in order to reduce the data volume of the file, the JavaScript file for the target function and the binary file of the WebAssembly for the target function can be compressed by using algorithms such as ZIP, LZMA, LZHAM, ORZ, etc.

[0093] At the same time, when the JavaScript file for the target function and the binary file of the WebAssembly for the target function are obtained and compressed, the web page or Node can load the JavaScript file for the target function and the binary file of the WebAssembly for the target function to load the corresponding WebAssembly instance.

[0094] That is, in the embodiment provided by the present invention, the method further includes the following steps:

[0095] The JavaScript file for the target function and the WebAssembly binary file for the target function are loaded.

[0096] Here, the terminal realizes the loading and running of WASM.

[0097] Reference Figure 5 , Figure 5A structural diagram of a WASM compilation device provided in an embodiment of the present invention includes:

[0098] An identification module, used for identifying a target function; wherein the target function is written in C++ language;

[0099] A merging module, used to merge the target functions based on return values ​​and parameter types, and generate a first Map table based on the merged result, which includes at least one category information of the first Map table function and the corresponding target function;

[0100] A generation module is used to generate a JavaScript file for the target function and a WebAssembly binary file for the target function using a WASM module for the target function based on the first Map table and according to the category information.

[0101] Figure 6 The WASM compilation device provided in the illustrated embodiment can be used to execute the embodiment of the present invention Figure 1 The technical solution of the method embodiment shown, its implementation principle and technical effects can be further referred to the relevant description in the method embodiment.

[0102] Figure 6 FIG. 1 is a schematic diagram of the structure of an electronic device according to an embodiment of the present invention. Figure 6 As shown, the electronic device may include at least one processor; and at least one memory connected to the processor in communication, wherein: the memory stores program instructions executable by the processor, and the processor calls the program instructions to execute the embodiments of the present invention. Figure 1 The WASM compilation method provided in the illustrated embodiment.

[0103] Figure 6 A block diagram of an exemplary electronic device suitable for implementing an exemplary embodiment of the present invention is shown. Figure 6 The electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.

[0104] like Figure 6 As shown, the electronic device is in the form of a general-purpose computing device. The components of the electronic device may include, but are not limited to: one or more processors 410, memory 430, and a communication bus 440 connecting different system components (including memory 430 and processor 410).

[0105] Communication bus 440 represents one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, a processor or a local bus using any of a variety of bus structures. For example, these architectures include but are not limited to Industry Standard Architecture (ISA) bus, Micro Channel Architecture (MCA) bus, Enhanced ISA bus, Video Electronics Standards Association (VESA) local bus and Peripheral Component Interconnection (PCI) bus.

[0106] Electronic devices typically include a variety of computer system readable media. These media can be any available media that can be accessed by the electronic device, including volatile and non-volatile media, removable and non-removable media.

[0107] The memory 430 may include a computer system readable medium in the form of a volatile memory, such as a random access memory (RAM) and / or a cache memory. The electronic device may further include other removable / non-removable, volatile / non-volatile computer system storage media. The memory 430 may include at least one program product having a set (e.g., at least one) of program modules that are configured to perform the functions of the various embodiments of the embodiments of the present invention.

[0108] A program / utility having a set (at least one) of program modules may be stored in memory 430, such program modules including, but not limited to, an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment. The program modules generally perform the functions and / or methods of the embodiments described in the embodiments of the present invention.

[0109] The processor 410 executes various functional applications and data processing by running the programs stored in the memory 430, such as implementing the embodiments of the present invention. Figure 1 The WASM compilation method provided in the illustrated embodiment.

[0110] An embodiment of the present invention provides a non-transitory computer-readable storage medium, wherein the non-transitory computer-readable storage medium stores computer instructions, wherein the computer instructions enable the computer to execute an embodiment of the present invention. Figure 1The WASM compilation method provided in the illustrated embodiment.

[0111] The above-mentioned computer-readable storage medium can adopt any combination of one or more computer-readable media. The computer-readable medium can be a computer-readable signal medium or a computer-readable storage medium. The computer-readable storage medium can be, for example, - but not limited to - an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples (non-exhaustive list) of computer-readable storage media include: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM) or flash memory, an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this document, a computer-readable storage medium can be any tangible medium containing or storing a program, which can be used by an instruction execution system, a device or a device or used in combination with it.

[0112] Computer-readable signal media may include a data signal propagated in baseband or as part of a carrier wave, which carries a computer-readable program code. Such propagated data signals may take a variety of forms, including, but not limited to, electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than a computer-readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.

[0113] Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.

[0114] The computer program code for performing the operation of the embodiments of the present invention can be written in one or more programming languages ​​or a combination thereof, including object-oriented programming languages, such as Java, Smalltalk, C++, and conventional procedural programming languages, such as "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as an independent software package, partially on the user's computer, partially on the remote computer, or completely on the remote computer or server. In the case of a remote computer, the remote computer can be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computer (e.g., using an Internet service provider to connect through the Internet).

[0115] The above describes specific embodiments of the present invention. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the accompanying drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0116] In the description of the embodiments of the present invention, the description with reference to the terms "one embodiment", "some embodiments", "example", "specific example", or "some examples" etc. means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the embodiments of the present invention. In the embodiments of the present invention, the schematic representations of the above terms do not necessarily refer to the same embodiments or examples. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner. In addition, those skilled in the art may combine and combine the different embodiments or examples described in the embodiments of the present invention and the features of the different embodiments or examples, without contradiction.

[0117] In addition, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one of the features. In the description of the embodiments of the present invention, the meaning of "plurality" is at least two, such as two, three, etc., unless otherwise clearly and specifically defined.

[0118] Any process or method description in a flowchart or otherwise described herein may be understood to represent a module, fragment or portion of code comprising one or more executable instructions for implementing the steps of a custom logical function or process, and the scope of the preferred implementation of the embodiments of the present invention includes alternative implementations in which functions may not be performed in the order shown or discussed, including performing functions in a substantially simultaneous manner or in reverse order depending on the functions involved, which should be understood by technicians in the technical field to which the embodiments of the present invention belong.

[0119] The word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining" or "in response to detecting", depending on the context. Similarly, the phrases "if it is determined" or "if (stated condition or event) is detected" may be interpreted as "when it is determined" or "in response to determining" or "when detecting (stated condition or event)" or "in response to detecting (stated condition or event)", depending on the context.

[0120] It should be noted that the terminals involved in the embodiments of the present invention may include but are not limited to personal computers (PCs), personal digital assistants (PDAs), wireless handheld devices, tablet computers, mobile phones, MP3 players, MP4 players, etc.

[0121] In the several embodiments provided in the embodiments of the present invention, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0122] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of hardware plus software functional units.

[0123] The above-mentioned integrated unit implemented in the form of a software functional unit can be stored in a computer-readable storage medium. The above-mentioned software functional unit is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) or a processor (Processor) to perform some steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, ROM), random access memory (Random Access Memory, RAM), disk or optical disk and other media that can store program codes.

[0124] The above description is only a preferred embodiment of the embodiment of the present invention and is not intended to limit the embodiment of the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the embodiment of the present invention should be included in the scope of protection of the embodiment of the present invention.

Claims

1. A WASM compilation method, characterized in that: include: Identifying the target function specifically includes: parsing the declaration file where the target function is located to obtain description information; based on the description information, identifying the target function; wherein the target function is written based on C++ language; Merging the target functions based on return values ​​and parameter types, and generating a first Map table based on the merged result, wherein the first Map table includes at least one category information of the target function and the corresponding target function; Based on the first Map table and in accordance with the category information, a WASM module is used to generate a JavaScript file for the target function and a binary file of WebAssembly for the target function for the target function, specifically including: generating a C++ proxy code for the target function and a JS proxy code for the target function based on the first Map table; based on the category information, the C++ proxy code for the target function, and the JS proxy code for the target function, a JavaScript file for the target function and a binary file of WebAssembly for the target function are generated for the target function using WASM, wherein the description information includes attributes, the target function generates a JS proxy code for the target function based on get and set functions, and / or the description information includes classes, the JS proxy code is generated based on the second Map table and the third Map table, the first Map table and the second Map table are generated based on the target function, the second Map table is used for class creation, and the third Map table is used for class release.

2. The WASM compilation method according to claim 1, characterized in that: The JavaScript file includes the JS proxy code for the target function; and / or the number of the category information is at least one; and / or In the step of using WASM to generate a JavaScript file for the target function and a WebAssembly binary file for the target function, the following operation is performed on the target function written in C++ language corresponding to each function type information: based on the C++ proxy code, the target function corresponding to the function type information is compiled using WASM.

3. The WASM compilation method according to claim 1 or 2, characterized in that: The WASM compilation method further includes: The JavaScript file for the target function and the binary file of the WebAssembly for the target function are compressed.

4. The WASM compilation method according to claim 3, characterized in that: The WASM compilation method further includes: The JavaScript file for the target function and the WebAssembly binary file for the target function are loaded.

5. A WASM compilation device, characterized in that: include: The identification module is used to identify the target function, and the steps specifically include: parsing the declaration file where the target function is located to obtain description information; based on the description information, identifying the target function; wherein the target function is written based on the C++ language; A merging module, used to merge the target functions based on return values ​​and parameter types, and generate a first Map table based on the merged result, wherein the first Map table includes at least one category information of the target function and the corresponding target function; A generation module is used to generate a JavaScript file for the target function and a binary file of WebAssembly for the target function using a WASM module based on the first Map table and according to the category information, the steps specifically comprising: generating a C++ proxy code for the target function and a JS proxy code for the target function based on the first Map table; generating a JavaScript file for the target function and a binary file of WebAssembly for the target function using WASM based on the category information, the C++ proxy code for the target function, and the JS proxy code for the target function, wherein the description information includes attributes, the target function generates a JS proxy code for the target function based on get and set functions, and / or the description information includes classes, the JS proxy code is generated based on a second Map table and a third Map table, the first Map table and the second Map table are generated based on the target function, the second Map table is used for class creation, and the third Map table is used for class release.

6. An electronic device, characterized in that: include: a memory for storing a computer program executable on the processor; A processor, configured to execute a computer program stored in the memory to implement the WASM compilation method according to any one of claims 1 to 4.

7. A storage medium, characterized in that: The storage medium stores non-volatile program code that can be executed by a processor or can be executed after compilation, and the program code is used to execute the WASM compilation method according to any one of claims 1 to 4.

Citation Information

Patent Citations

  • Compiling method, compiler and Wasm virtual machine

    CN115495086A