A compiling method, device and electronic equipment

By deriving and optimizing the types of unknown variables during the bytecode-to-intermediate code conversion process, the problem of large memory consumption of bytecode files is solved, improving the running speed and memory utilization efficiency of applications.

CN117785206BActive Publication Date: 2026-11-27HUAWEI TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202211157130.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-09-21
Publication Date
2026-11-27
Estimated Expiration
2042-09-21

AI Technical Summary

Technical Problem

In existing technologies, during the process of compilers converting source code into bytecode, the type inference of unknown variables leads to excessive memory usage in bytecode files, which in turn increases the memory consumption of applications on electronic devices.

Method used

During the bytecode to intermediate code conversion process, the type of unknown variables is deduced based on the type of known variables, and the deduced type information is used for intermediate code optimization instead of being written to the bytecode file, thereby avoiding an increase in the memory usage of the bytecode file.

Benefits of technology

This reduces the size of bytecode files, improving application speed and memory utilization efficiency on electronic devices.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117785206B_ABST
    Figure CN117785206B_ABST
Patent Text Reader

Abstract

The application provides a compiling method and device and an electronic device. The method comprises: obtaining bytecode corresponding to a program, the program comprising source code, the bytecode being generated according to the source code, and the bytecode comprising known variables and unknown variables; and in the process of converting the bytecode into intermediate code, the type of the unknown variables in the intermediate code is deduced according to the type of the known variables in the bytecode, so as to obtain the type of the unknown variables in the intermediate code. The compiling method provided by the application reduces the size of the bytecode file by deducing the type of the unknown variables in the process of generating the intermediate code, thereby reducing the memory space occupied by the program in the electronic device.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and more specifically, to a compilation method, apparatus, and electronic device. Background Technology

[0002] A compiler can recognize words, sentences, and various specific formats in a high-level language and convert them into binary form that a computer can recognize.

[0003] The compiler performs code compilation in three stages: front-end, middle-end, and back-end. The front-end includes lexical analysis, syntax analysis, and semantic analysis; the middle-end (optimizer side) includes generating intermediate code and optimizing the intermediate code; and the back-end is mainly used to generate target code (machine code).

[0004] In related technologies, during the process of converting source code into bytecode, the compiler front-end uses the types of known variables to deduce the types of unknown variables and stores the deduced types of unknown variables in the bytecode file. This results in an increase in the memory size of the bytecode file, which in turn increases the memory usage of the application corresponding to the bytecode file in the electronic device. Summary of the Invention

[0005] This application provides a compilation method, apparatus, and electronic device that solves the problem of large memory usage in bytecode files by inferring the type of unknown variables during the conversion of bytecode to intermediate code.

[0006] In a first aspect, this application provides a compilation method, which includes obtaining the bytecode corresponding to a program, the program including source code, the bytecode being generated from the source code, and the bytecode including known variables and unknown variables; during the conversion of bytecode to intermediate code, the types of unknown variables in the intermediate code are deduced based on the types of known variables in the bytecode, thereby obtaining the types of unknown variables in the intermediate code.

[0007] The compilation method provided in the first aspect deduces the type of unknown variables based on the type of known variables during the bytecode to intermediate code conversion process. Since the bytecode to intermediate code conversion is a runtime process, it is not written to a file. This solves the problem in related technologies where type deduction is performed during the source code to bytecode conversion process, and then the deduced variable types are stored in the bytecode file, resulting in a large bytecode file.

[0008] For example, the type of a known variable or the type of an unknown variable can include any one of number, string, Boolean, Null, Undefined, and Object.

[0009] Optionally, the type deduction of the intermediate code can be used for at least one or more operations, including increment, decrement, left shift, right shift, addition, subtraction, division, multiplication, function comparison to determine whether two values ​​are equal, negation, comparison, and accessing the type in an array.

[0010] In one possible implementation of the first aspect, the intermediate code is optimized based on the types of unknown variables in the derived intermediate code to obtain the target code. In this implementation, optimizing the intermediate code using the types of unknown variables in the derived intermediate code simplifies the resulting target code, thereby improving its execution speed on electronic devices and ultimately increasing the program's running speed.

[0011] Optionally, redundant code in the intermediate code can be removed based on the type of unknown variables in the derived intermediate code.

[0012] In one possible implementation of the first aspect, the type deduction of unknown variables during the bytecode-to-intermediate code conversion process includes: generating an initial global type table based on known variables in the bytecode, the initial global type table including the types of all determined variables; determining the initial type of known variables in the intermediate code based on the initial global type table; and deducing the type of unknown variables in the intermediate code based on the initial types of known variables in the intermediate code. In this implementation, by constructing an initial global type table, the types of known variables in the bytecode are stored in the initial global type table, facilitating the type deduction of unknown variables in the intermediate code and improving the efficiency of type deduction.

[0013] In one possible implementation of the first aspect, the abstract syntax tree (API) corresponding to the program is determined based on the source code. Based on the initial types of known variables in the intermediate code, type deduction of unknown variables in the intermediate code is performed, including: type deduction of the first unknown variable in the intermediate code based on the initial types of known variables in the intermediate code and nodes on the API; updating the initial global type table based on the type of the first unknown variable in the intermediate code; and type deduction of the second unknown variable in the intermediate code and updating the initial global type table based on the updated initial global type table and nodes on the API. In this implementation, the type deduction of the first unknown variable is performed by traversing the nodes on the API, and the deduced type is then stored in the initial global type table. When deducing the type of the second unknown variable, the updated initial global type table is called, thereby improving the efficiency of type deduction for the second unknown variable.

[0014] In one possible implementation of the first aspect, updating the initial global type table stops when the types of all unknown variables in the intermediate code are deduced. In this implementation, updating the global type table stops when the types of all unknown variables in the intermediate code are deduced, indicating that the type deduction of the unknown variables in the intermediate code has ended.

[0015] In a second aspect, a communication device is provided, which includes units for performing the steps of the first aspect or any possible implementation of the first aspect.

[0016] Thirdly, a communication device is provided, comprising at least one processor and a memory coupled together, the memory storing program instructions that, when executed by the processor, perform the method of the first aspect or any possible implementation thereof.

[0017] Fourthly, a communication device is provided, comprising at least one processor and interface circuitry, the at least one processor being configured to perform the methods described in the first aspect or any possible implementation thereof.

[0018] Fifthly, an electronic device is provided, which includes the communication device provided in the second aspect, or the electronic device includes the communication device provided in the third aspect, or the electronic device includes the communication device provided in the fourth aspect.

[0019] In a sixth aspect, a computer program product is provided, comprising a computer program that, when executed by a processor, performs the method of the first aspect or any possible implementation thereof.

[0020] In a seventh aspect, a computer-readable storage medium is provided, wherein a computer program is stored therein, which, when executed, performs the method of the first aspect or any possible implementation thereof.

[0021] Eighthly, a chip is provided, the chip comprising: a processor for calling and running a computer program from a memory, causing a communication device on which the chip is installed to perform a method for performing the first aspect above or any possible implementation of the first aspect. Attached Figure Description

[0022] Figure 1 A diagram illustrating the three stages of compilation performed by the compiler is shown;

[0023] Figure 2A schematic flowchart illustrating the generation of bytecode from source code is shown in an example of a related technology provided in this application;

[0024] Figure 3 A schematic diagram of a system architecture provided in an embodiment of this application is shown;

[0025] Figure 4 This illustration shows an application scenario provided by an embodiment of this application.

[0026] Figure 5 A schematic flowchart of the compilation method provided in an embodiment of this application is shown;

[0027] Figure 6 This illustration shows a deductive schematic flowchart of the process of generating intermediate code provided in an embodiment of this application;

[0028] Figure 7 This illustration shows a schematic diagram of the type derivation of an unknown variable provided in an embodiment of this application;

[0029] Figure 8 This illustration shows a schematic diagram of the derivation of the addition operation type provided in an embodiment of this application;

[0030] Figure 9 This application provides a schematic diagram illustrating the derivation of object operation types based on the aforementioned source code, as shown in an embodiment of this application.

[0031] Figure 10 This application provides a schematic diagram illustrating the type derivation process in an embodiment.

[0032] Figure 11 A schematic flowchart of another compilation method provided in an embodiment of this application is shown;

[0033] Figure 12 A schematic flowchart illustrating the optimization of intermediate code using the derived types of unknown variables provided in an embodiment of this application is shown.

[0034] Figure 13 A schematic diagram of an example structure of the electronic device 100 provided in this application is shown;

[0035] Figure 14 A schematic block diagram of a communication device 1400 provided in an embodiment of this application is shown;

[0036] Figure 15 A schematic block diagram of another example of a communication device 1500 provided in an embodiment of this application is shown;

[0037] Figure 16 A schematic diagram of the chip system is shown. Detailed Implementation

[0038] The technical solutions in the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings.

[0039] The terminology used in the following embodiments is for the purpose of describing specific embodiments only and is not intended to be limiting of this application. As used in the specification and appended claims of this application, the singular expressions “a,” “an,” “the,” “the,” “the,” and “this” are intended to also include expressions such as “one or more,” unless the context clearly indicates otherwise. It should also be understood that in the embodiments of this application, “one or more” means one or more (including two); “and / or” describes the relationship between related objects, indicating that three relationships may exist; for example, A and / or B can represent: A alone, A and B simultaneously, or B alone, where A and B can be singular or plural. The character “ / ” generally indicates that the preceding and following related objects are in an “or” relationship.

[0040] References to "one embodiment" or "some embodiments" as described in this specification mean that one or more embodiments of this application include a specific feature, structure, or characteristic described in connection with that embodiment. Therefore, the phrases "in one embodiment," "in some embodiments," "in other embodiments," "in still other embodiments," etc., appearing in different parts of this specification do not necessarily refer to the same embodiment, but rather mean "one or more, but not all, embodiments," unless otherwise specifically emphasized. The terms "comprising," "including," "having," and variations thereof mean "including but not limited to," unless otherwise specifically emphasized.

[0041] The "multiple" mentioned in the embodiments of this application refers to two or more. It should be noted that in the description of the embodiments of this application, terms such as "first" and "second" are used only for the purpose of distinguishing descriptions and should not be construed as indicating or implying relative importance, nor should they be construed as indicating or implying order.

[0042] The main process of programming software for developers consists of three stages: source code reception, compilation, and execution. Since the source code input by programmers is in a high-level language, electronic devices cannot recognize it. Therefore, in the compilation stage, a compiler is needed to convert the high-level language input by programmers, i.e., the source code, into machine-readable binary code, i.e., object code.

[0043] Figure 1 The diagram illustrates the three stages of compilation performed by the compiler, as follows: Figure 1As shown, the compiler consists of three stages: the front end, the middle end (optimizer end), and the back end. The front end includes lexical analysis, syntax analysis, and semantic analysis. The middle end (optimizer end) includes generating intermediate code and optimizing that intermediate code. The back end is primarily used to generate target code that can be run directly on the device.

[0044] Specifically, the front-end refers to the compiler's analysis and understanding of program code, which is usually only related to the language's syntax and independent of the target machine. The front-end mainly includes lexical analysis, syntax analysis, and semantic analysis.

[0045] Lexical analysis refers to the analysis of strings throughout a program. When different characters are encountered, the string transitions to different states. For example, when the lexical analyzer is scanning English letters, it is in the "identifier" state. When it encounters a "→" symbol, it switches to the "comparison operator" state. The lexical analysis process is a series of state transitions.

[0046] Syntax analysis identifies the syntactic structure of a program based on lexical analysis. The process of syntax analysis can be understood as constructing a tree. A program can be understood as a tree, which can be called an Abstract Syntax Tree (AST). An AST is a tree-like data structure used to represent the abstract syntactic structure of source code. Each node in the tree represents a structure that appears in the source code.

[0047] Semantic analysis refers to eliminating semantic ambiguity and generating attribute information that allows computers to generate target code based on this information. The results of semantic analysis are labeled as attributes on the abstract syntax tree (AST). For example, a node might be labeled with its data type as `int`. Many other attributes can also be marked on the AST, such as the source code line number and the character's position within that line. This allows for a clearer understanding of the location of errors when the compiler reports them.

[0048] The final result of a compiler's backend is the generation of object code. The compiler's backend technology is closely related to computer architecture, such as how memory space is allocated and organized during runtime; how programs start, jump, and exit; how instructions and data are passed to the CPU during execution; and how the entire process coordinates with the operating system, etc. Once a certain understanding of runtime mechanisms is achieved, the next step is to generate code that conforms to those mechanisms. Differences in CPU instruction sets, such as what instructions each register can be used for, mean that each language must generate different assembly code for each different piece of hardware.

[0049] It should be understood that, in order to reduce backend workload and improve software reusability, the Intermediate Representation (IR) mechanism is introduced. IR is a code format independent of specific hardware. Frontends in various languages ​​can first be translated into IR, and then from IR into assembly code for different hardware architectures. If there are n frontend languages ​​and m backend architectures, instead of requiring m×n translation programs, only m+n programs are needed, significantly reducing the overall workload.

[0050] The intermediate code includes High-Level Intermediate Representation (HIR) and Low-Level Intermediate Representation (LIR). Before constructing the HIR, the compiler performs some basic optimizations on the bytecode, such as method inlining and constant propagation. Before constructing the LIR, it performs other optimizations on the HIR, such as null value elimination and range check elimination, so that the HIR can achieve a more efficient code representation.

[0051] The middleware includes the generation and optimization of intermediate code. The goal of code optimization is to optimize the program's use of computer resources. Maximizing the efficiency of CPU resource utilization can improve program performance. Code optimization sometimes has other goals, such as code size, memory usage, disk access frequency, network communication frequency, etc.

[0052] For example, some code optimization scenarios include: First, algebraic optimization: when the operator is an algebraic operation, optimization can be performed based on learned data knowledge. For example, in the line of code x = x + 0, x does not change before and after the operation, so such code can be deleted. Second, constant folding: operations on constants can be calculated at compile time. For example, x = 20 × 3 can be optimized to x = 60. Third, deleting unreachable basic blocks: some code will never be activated, such as code blocks that do not need to be compiled. Fourth, deleting common subexpressions: for example, if the first line of code is x = a + b and the second line is y = a + b, then y = a + b can be used, thus reducing one calculation of a + b. This optimization is called deleting common subexpressions. Fifth, copy propagation and constant propagation: for example, if the first line of code is x = a + b, the second line is y = x, and the third line is z = 2 × y, then the third line can be replaced with z = 2x, because the value of y is equal to x. The sixth type is dead code deletion: In copy propagation, if the variable y is not used anywhere else, then the second line is line 4 and can be deleted. This optimization is called dead code deletion.

[0053] It should be understood that one optimization may lead to another. For example, if copy propagation causes y to no longer be used, then dead code removal optimization can be performed. Therefore, multiple optimizations and multiple scans are generally performed.

[0054] It should also be understood that during the aforementioned front-end compilation process, in order to avoid explicit type declarations, the compiler can automatically deduce the data type. That is, the compiler can deduce the type information of unknown type nodes based on the information of known nodes according to certain rules.

[0055] The following is combined with Figure 2 This paper provides a detailed explanation of how type inference is performed during the process of generating bytecode from source code in related technologies. Figure 2 A schematic flowchart illustrating the source code to bytecode generation process in a related art provided in this application is shown. Figure 2 As shown, the developer first manually annotates the type information in the source code. During the compilation phase, the compiler performs lexical and syntactic analysis on the source code, transforming it into an abstract syntax tree (AST). Furthermore, during the bytecode generation process by traversing the AST, the encoder derives the type information of unknown nodes based on the type information manually annotated by the developer. When all bytecode is generated, the type information of unknown nodes can be deduced. Finally, the deduced type information of unknown nodes is used for type checking to determine whether the node conforms to programming standards.

[0056] It should be understood that bytecode generation refers to generating bytecode based on an annotated abstract syntax tree, which is essentially transforming one data structure into another.

[0057] For example, the following source code and bytecode snippet will be used to specifically introduce the type inference process in related technologies.

[0058] Source code:

[0059] Function Add(a:number,b:number):number{

[0060] Var d = a + b; / / Define variable d as equal to a plus b

[0061] Var e = d + 10; / / Define variable e as equal to d plus 10

[0062] Return e; / / Return variable e

[0063] }

[0064] The bytecode converted from the above source code is as follows:

[0065] Bytecode:

[0066]

[0067]

[0068] During the source code and bytecode conversion process described above, since the types of intermediate variables are unknown, the compiler needs to deduce the types of intermediate variables based on the known types of variables during compilation, save the deduced variable types to the bytecode file, and then perform intermediate code conversion and intermediate code conversion to target code based on the bytecode file.

[0069] Alternatively, in related technologies, the type information of the derived variable is not written to a file, but is only used for type checking to determine whether the variable conforms to programming specifications, and then the derived type information is discarded.

[0070] For example, the types of a0 and a1 in the source code are known to be number. During the source code to bytecode conversion process, the types of intermediate variables v5 and v3 generated by the compiler are unknown. However, during the source code to bytecode conversion process, the compiler can deduce the type information of the intermediate variables v5 and v3 from the types of a0 and a1, and save the deduced type information of v5 and v3 in the bytecode file.

[0071] However, during the source code to bytecode conversion process, the type information of the derived intermediate variables is saved in the bytecode file. This means the bytecode file includes both known and unknown variable types. Since the type information for unknown variables is relatively large, this increases the memory footprint of the bytecode file, ultimately causing the application to consume more memory on electronic devices.

[0072] Alternatively, during the conversion from source code to bytecode, the type of the inferred unknown variable is not written to the bytecode file; it is only used for type checking to determine if the program compiles correctly. After type checking, the inferred result is not saved. Therefore, the type inference methods for unknown variables described above do not utilize the inferred unknown variable types to optimize intermediate code and do not improve application execution speed.

[0073] In view of this, this application provides a compilation method that performs type inference of unknown variables during the bytecode to intermediate code conversion process. The type information of unknown variables inferred through this implementation is not stored, thus preventing the bytecode from increasing in memory and thereby improving the running speed of the application.

[0074] Before introducing the compilation method provided in this application, we will first explain the system architecture and application scenarios to which this method is applicable. Figure 3A schematic diagram of a system architecture provided in an embodiment of this application is shown.

[0075] like Figure 3 As shown, the compilation device 320 compiles the source program 310 to obtain the compiled program result 330. The source program can be a program that performs data operations in different scenarios, including a function executed in an application, image processing, speech recognition, scientific computing, or physical modeling, etc. The compilation device 320 can be any device containing a compiler (such as GCC or LLVM).

[0076] The compiled program 330 obtained by compiling using the compilation device 320 can be applied to different systems or devices, such as... Figure 3 The electronic device 340 shown can be a terminal, such as a mobile phone terminal, tablet computer, laptop computer, augmented reality (AR) / virtual reality (VR) terminal, vehicle terminal, etc., or it can be a server or cloud, etc.

[0077] The electronic device 340 can use the computing module 350 to execute the relevant calculation process in the program compilation result 330 to obtain the corresponding processing result.

[0078] It is worth noting that the compilation device 320 can compile source programs for different goals or different tasks to obtain corresponding program compilation results 330. Then, the electronic device 340 executes the relevant calculation process in the program compilation results 330 to obtain the processing results required for different goals or different tasks.

[0079] It is worth noting that, Figure 3 This is merely a schematic diagram of a system architecture provided by an embodiment of the present invention. The positional relationships between the devices, components, modules, etc., shown in the diagram do not constitute any limitation. For example, in Figure 3 In this context, the compilation device 320 is an external device relative to the electronic device 340. In other cases, the compilation device 320 may also be placed within the electronic device 340.

[0080] Figure 4 The illustration shows an application scenario provided by an embodiment of this application. It should be understood that the compilation method 500 and method 1100 in the embodiments of this application can be applied to a specific operation of an application, such as adding to a shopping cart in a shopping application, or a voice recognition function. Figure 4 Taking speech recognition as an example, the application process of compilation method 500 and method 1100 in the embodiments of this application is described.

[0081] First, the speech recognition function 410 is defined in a high-level language (e.g., programming languages ​​such as C, C++, Java, or Python) to obtain the source program 420 corresponding to the speech recognition function 410.

[0082] Compile device 440 (i.e. Figure 3 The compilation device 320 in this application executes the compilation method 500 or method 1100 in the embodiments of this application to compile the source program and obtain the program compilation result 450 (i.e., Figure 3 The program compilation result 430 is then optimized to obtain a hardware machine language 460 executable on hardware (e.g., CPU or GPU).

[0083] Using electronic devices 430 (e.g.) Figure 3 The compilation device 340 in the middle runs hardware machine language 460 to perform the corresponding operation and obtain speech recognition results 470.

[0084] It should be understood that, Figure 4 In this context, the compilation device 440 is an external device relative to the electronic device 430. In other cases, the compilation device 440 may also be placed within the electronic device 430.

[0085] The compilation method of the compiler provided in this application is described in detail below. The execution entity of this method can be an electronic device, a compiler within an electronic device, or a chip within an electronic device. Figure 5 A schematic flowchart of the compilation method provided in an embodiment of this application is shown. Figure 5 As shown, the method 500 includes S510-S520.

[0086] S510. Obtain the bytecode corresponding to the program. The program includes source code, and the bytecode is generated based on the source code. The bytecode includes known variables and unknown variables.

[0087] It should be understood that a program is a collection of commands written in a computer language to achieve a specific goal or solve a specific problem.

[0088] In the embodiments of this application, when an electronic device needs to perform one or more operations, it first needs to obtain a set of programs of computer instructions designed in sequence. That is, performing an operation can be understood as performing the program corresponding to that operation.

[0089] It should also be understood that the program includes source code, which refers to an uncompiled text file written according to a certain programming language specification; it is a series of human-readable computer language instructions. However, source code is generally not recognizable by electronic devices. Electronic devices can only recognize the source code when it is translated into computer-executable binary instructions.

[0090] In other words, source code needs to be generated into target code before it can be recognized by a computer. Therefore, in the process of generating target code, it first needs to be converted into bytecode files.

[0091] Therefore, when an electronic device needs to perform a certain operation, it first needs to obtain the bytecode corresponding to that operation. It should be understood that bytecode can also be understood as a bytecode file.

[0092] It should be noted that, in the embodiments of this application, the bytecode file obtained by the electronic device includes known variables and unknown variables. In other words, the types of known variables in the bytecode file are known, while the types of unknown variables are unknown. That is, the bytecode file includes the type information of known variables but does not include the type information of unknown variables.

[0093] For details on the process of converting source code to bytecode, please refer to the descriptions of the relevant technologies mentioned above, which will not be repeated here.

[0094] In some possible implementations, the bytecode described above is compiled by a compilation device from the source code. This compilation device and the electronic device can be independent devices, meaning that the compilation device and the electronic device are different physical devices.

[0095] In some other possible implementations, the compilation device can also be integrated into the electronic device, i.e., the electronic device includes the compilation device.

[0096] S520. During the conversion from bytecode to intermediate code, the types of unknown variables in the intermediate code are deduced based on the types of known variables in the bytecode, thus obtaining the types of unknown variables in the intermediate code.

[0097] In this embodiment, to reduce the size of the bytecode file, the bytecode file obtained by the electronic device does not include the types of unknown variables. However, the type of each variable in the intermediate code needs to be known; that is, the intermediate code also needs to include the types of unknown variables. Therefore, during the conversion from bytecode to intermediate code, it is necessary to deduce the types of unknown variables in the intermediate code based on the types of known variables in the bytecode.

[0098] Furthermore, since the conversion from bytecode to intermediate code is a runtime process, the types of the inferred unknown variables are not saved, meaning they are not written to the bytecode file. In other words, the bytecode file does not include the types of unknown variables, thus solving the problem in related technologies where type inference is performed during the source code to bytecode conversion process, and then the inferred variable types are saved in the bytecode file, resulting in a large bytecode file and reducing the memory consumption of electronic devices.

[0099] In some embodiments, during the process of converting bytecode into intermediate code, an initial global type table is generated based on known variables in the bytecode. This initial global type table includes the types of all known variables.

[0100] For example, if the variables are known to be variable a and variable b in the bytecode, then the initial global type table includes the types of variable a and variable b.

[0101] Optionally, during the bytecode to intermediate code conversion process, an initial global type table can be generated using the RuntimeLinker (the linker at program runtime) in the electronic device.

[0102] Then, based on this initial global type table, the electronic device determines the initial type of known variables in the intermediate code.

[0103] For example, during the bytecode to intermediate code conversion process, the electronic device calls the information of known variables in the initial global type table and marks the type information of the known variables on the known variables in the intermediate code.

[0104] Finally, based on the initial type of the known variables, the type of the unknown variables in the intermediate code is deduced.

[0105] In one possible implementation, the compiler can determine the abstract syntax tree corresponding to the program based on the source code. Then, during the process of the electronic device inferring the type of unknown variables in the intermediate code based on the initial type of known variables, the type of the first unknown variable in the intermediate code can be inferred based on the initial type of known variables in the intermediate code and the nodes on the abstract syntax tree; the initial global type table is updated based on the type of the first unknown variable in the intermediate code; and the type of the second unknown variable in the intermediate code and the initial global type table are updated based on the updated initial global type table and the nodes on the abstract syntax tree.

[0106] It should be understood that the first unknown variable can be any one of the unknown variables in the intermediate code. The second unknown variable can also be understood as any one of the unknown variables in the intermediate code, but the first and second unknown variables refer to different variables.

[0107] Specifically, the electronic device can deduce the type of the first unknown variable in the intermediate code based on the initial types of known variables in the intermediate code and the nodes on the abstract syntax tree. Then, it updates the initial global type table based on the deduced type of the first unknown variable, meaning the updated initial global type table includes the type of the first unknown variable. Next, based on the updated initial global type table and the nodes on the abstract syntax tree, it deduces the type of the second unknown variable in the intermediate code, and updates the initial global type table based on the deduced type of the second unknown variable, meaning the updated initial global type table includes not only the types of the first unknown variable but also the types of the second unknown variable. After the type of the second unknown variable updates the initial global type table, it deduces the type of the third unknown variable in the intermediate code based on the updated initial global type table and the nodes on the abstract syntax tree, and updates the initial global type table based on the deduced type of the third unknown variable, meaning the updated initial global type table includes not only the types of the first unknown variable, but also the types of the second and third unknown variables. This process is repeated, traversing the nodes on the abstract syntax tree to deduce the types of other unknown variables and update the initial global type table.

[0108] It should be understood that in this implementation, by constructing an initial global type table, the types of known variables in the bytecode are stored in the initial global type table, and the initial global type table is continuously updated based on the inferred variable types. Then, during the conversion from bytecode to intermediate code, the updated initial global type table is continuously called, which facilitates the type inference of unknown variables in the intermediate code and improves the efficiency of type inference.

[0109] For example, the following is combined with Figure 6 This application provides a detailed explanation of how the type of unknown variables is deduced during the process of generating intermediate code from bytecode.

[0110] Figure 6 This application provides an embodiment of a deductive flowchart illustrating the process of generating intermediate code, such as... Figure 6 As shown, the compiler first performs lexical analysis, syntax analysis, and semantic analysis on the source code written by the developer to generate an annotated abstract syntax tree. Then, it generates bytecode based on the annotated abstract syntax tree and saves the existing type information of the source code in the bytecode file.

[0111] Optionally, the Runtime Linker in the compiler first generates an initial global type table based on the known variables in the source code (or bytecode) and the types of the known variables.

[0112] It should be understood that the initial global type table refers to the global types that the compiler can use during the compilation of the entire source code. This initial global type table can include known variables in the source code and their types. As the initial global type table is continuously updated, the updated table can also include the first unknown variable and its type.

[0113] For example, in the source code described above, the known variables are a and b, and it is known that the types of variables a and b are number. Therefore, the generated initial global type table includes variables a and b as number.

[0114] It should also be understood that the global type table not only includes the known types of variables marked on the initial source code, but also, in this embodiment, the type of the first unknown variable in the intermediate code is deduced based on the initial type of the known variables in the intermediate code and the nodes on the abstract syntax tree. Therefore, the global type table also includes the deduced type of the first unknown variable.

[0115] Therefore, this global type table changes dynamically in real time until all bytecode is used to generate intermediate code, and the type of each variable in the intermediate code is known.

[0116] For example, if the source code above includes an unknown variable 'e', ​​then variable 'e' can be understood as the first unknown variable. In this embodiment, variable 'e' can be deduced to be of type 'number' based on the known variables 'a' and 'b', and then added to the initial global type table as 'number'. That is, the global type table also includes information that variable 'e' is of type 'number'.

[0117] In this embodiment of the application, the initial type information of known variables in the intermediate code can be determined based on the initial global type table.

[0118] Specifically, during the process of generating intermediate code from bytecode files, the compiler calls the global type table generated by the Runtime Linker to obtain variables with initial types from the global type table. Then, it marks the initial type of the variable on the corresponding node in the intermediate code, generating a variable as shown below. Figure 6 The HIR initial type file shown contains the initial type information for known variables in the intermediate code.

[0119] Then, during the process of converting bytecode into intermediate code, the electronic device deduces the type of unknown variables in the intermediate code based on the initial type of known variables in the intermediate code.

[0120] Finally, the derived types of unknown variables are used to update the initial type file of the HIR, ultimately obtaining the types of variables on all nodes.

[0121] Optionally, in this embodiment, the global variable table can also be updated based on the variable types derived during the intermediate code conversion process. Then, the compiler calls the variable type information in the global variable table in real time during the bytecode to intermediate code conversion process until there is no newly added variable type information in the global variable table.

[0122] As can be seen, unlike related technologies, the embodiments of this application perform type deduction of unknown variables during the process of the compiler generating intermediate code from bytecode files. Since the execution process of the intermediate code is not written to the file, it does not occupy bytecode memory.

[0123] The following is combined Figure 5 and Figure 6 The flowchart shown, along with the aforementioned source code and bytecode, illustrates the process of type inference in the conversion of bytecode to intermediate code in this application. Figure 7 This illustration shows a schematic diagram illustrating the type derivation of an unknown variable provided in an embodiment of this application. For example... Figure 7 As shown, node 0 is the root node, which includes node 1 (constant list node) and node 2 (parameter list node). The parameter list node includes node 3 (parameter) and node 4 (parameter). The constant list includes node 6 (constant). Node 5 represents the sum of the parameters of node 3 and node 4, and node 7 represents the sum of the parameters of node 5 and node 6. Finally, node 8 returns the value of node 7.

[0124] Node 5 represents a+b. Nodes 3 and 4 are the data stream inputs to node 5, and both data stream inputs are of type number. Based on the operation rules, we can deduce that the type of node 5 is number. Similarly, nodes 5 and 6 are the data stream inputs to node 7. Node 5 represents a+b, and node 6 is the constant 10. Therefore, node 7 represents a+b+10. Since the type of node 5 is number and node 6 is a constant, we can deduce that the type of node 7 is number.

[0125] It should be understood that in this example, the initial global type table includes the variable types of nodes 3 and 4, and the unknown variable type derived from node 5 can be understood as the first unknown variable type. After the first unknown variable type is derived, the first unknown variable type is stored in the initial global type table.

[0126] Combination Figure 7 To further explain the global variable table mentioned above, for Figure 7In the example shown, the initially generated global variable table contains the types of variables a and b. Based on variables a and b, the type of node 5 can be deduced to be number. Therefore, the corresponding number type of node 5 will also be stored in the global variable table. Suppose that node 5 needs to be traversed during intermediate type derivation, then node 5 can be used as a known variable type of number. Similarly, the variable type determined when traversing node 7 will also be stored in the initial global variable table and called as a known variable type.

[0127] It should be understood that, Figure 7 In the addition operation shown, both variables 'a' and 'b' are of type 'number'. Of course, 'a' and 'b' can also be of other types. For example, Figure 8 This application provides a schematic diagram illustrating the derivation of addition operation types in an embodiment, as shown below. Figure 8 As shown, when both constants c and d are number, the variable after addition is also of type number. When at least one of variables a and b is string, the variable after addition is of type string.

[0128] It should be understood that the above embodiments take addition as an example. Of course, variable type deduction can also be used for increment, decrement, left shift, right shift, addition, subtraction, division, multiplication, function to determine whether two values ​​are equal, negation, comparison, and accessing the type in an array, etc.

[0129] The following examples, from Examples 1 to Examples 6, illustrate type deduction under other operations.

[0130] For example, if we define the variable `num` as 1 and the variable `tmp` as `number10`, then after performing increment, decrement, left shift, right shift, subtraction, division, and multiplication operations on variables `num` and `tmp`, the return value will still be of type `number`.

[0131] Example 1:

[0132] var num:number = 1;

[0133] var tmp:number = 10;

[0134] num++; / / Increment operator, returns a number.

[0135] num--; / / Decrement operator, returns a number.

[0136] num = num << 1; / / Left shift operation, returns a number.

[0137] num = num >> 1; / / Right shift operation, returns a number.

[0138] var test = num / tmp; / / Returns a number.

[0139] var test = num - tmp; / / Returns a number.

[0140] var test = num * tmp; / / Returns a number.

[0141] Optionally, the above type derivation process also applies to the following functions:

[0142] Example 2

[0143]

[0144] It should be understood that in the above embodiment of the function determining whether two values ​​are equal, the return value of true or false is of type boolean.

[0145] Example 3

[0146] var tmp = true;

[0147] tmp = !tmp; This is the negation operation, and the return type is boolean.

[0148] Example 4

[0149]

[0150]

[0151] Example 5

[0152]

[0153] Example 6, when the source code is:

[0154]

[0155] Figure 9 This application provides an embodiment of an illustration illustrating the derivation of object operation types based on the aforementioned source code, as shown below. Figure 9As shown, loadobjbyname contains two inputs: an instance of Student (stu) and an attribute of the class Student (name). From the source code above, we know that the type of the instance of Student (stu) is string, and the type of the attribute of the class Student (name) is string. Therefore, we can deduce that the type of the ldobjbyname node is string.

[0156] Of course, other operational rules can also be applied to type deduction, and the examples in this application do not constitute a limitation on the operations applicable to type deduction.

[0157] In some possible implementations, the type information of unknown variables in the intermediate code is gradually determined during the bytecode to intermediate code conversion process. Specifically, the electronic device continuously traverses each node on the intermediate code, performing type inference for each unknown node until the types of all nodes in the intermediate code are known.

[0158] For example, Figure 10 This application provides a type derivation diagram, as illustrated in the embodiments below. Figure 10 As shown, when the electronic device derives the type of an unknown variable based on the types of known variables, it first traverses from the root node 0, then traverses the parameter list node 2, which includes parameters 3 and 4. Next, it traverses from parameter 3 to node 5. Since the inputs to node 5 are parameters 3 and 4, and both parameters 3 and 4 are of type number, node 5 is also of type number according to the operation rules. After traversing node 5, it traverses node 7. Since the inputs to node 7 are node 5 and node 55, and since node 55 has not been traversed, its type is unknown. Therefore, it restarts traversing from the root node 0, first traversing the parameter list node 22, which includes parameters 33 and 44, then traversing from parameter 33 to node 55. Since the inputs to node 55 are parameters 33 and 44, and both parameters 33 and 44 are of type number, node 55 is also of type number. Since node 7 has already been visited when traversing from the root node 0, we can start traversing from the newly added node 5 as the root node. After traversing node 5, we traverse node 7. Since the input of node 7 is node 5 and node 55, and both node 5 and node 55 are of type number, we can deduce that the initial value of node 7 is also number, and we return the return value of node 7 at node 8. Thus, Figure 10 Each node in the array has been traversed, and the variable type on each node has been determined.

[0159] The compilation method provided in this application involves deriving the type of unknown variables during the conversion of bytecode to intermediate code in an electronic device. Since the conversion from bytecode to intermediate code is an ongoing process, the derived types of unknown variables are not saved, i.e., they are not written to the bytecode file. In other words, the bytecode file does not include the types of unknown variables, thus solving the problem in related technologies where type deduction is performed during the source code to bytecode conversion, and then the derived variable types are saved in the bytecode file, resulting in a large bytecode file. This reduces the memory consumption of the electronic device.

[0160] In another approach using related technologies, during the source code to bytecode conversion, the type of unknown variables is deduced from the types of known variables. Although the deduced type information is not stored in the bytecode file, it is only used for type checking during programming to ensure compliance with coding standards. Furthermore, the deduced type is deleted after type checking. Therefore, the deduced type does not speed up application execution.

[0161] Therefore, this application also provides another compilation method, which optimizes the intermediate code by utilizing the types of inferred unknown variables during the bytecode to intermediate code conversion process. This results in faster execution of the target code on electronic devices after the intermediate code is converted, ultimately accelerating the application's running speed on electronic devices. The following is combined with... Figure 11 Another compilation method provided in this application will be explained in detail. Figure 11 A schematic flowchart of another compilation method provided in an embodiment of this application is shown, such as... Figure 11 As shown, the method 1100 includes S1110-S1130:

[0162] S1110. Obtain the bytecode corresponding to the program. The program includes source code, and the bytecode is generated based on the source code. The bytecode includes known variables and unknown variables.

[0163] S1120. During the conversion from bytecode to intermediate code, the types of unknown variables in the intermediate code are deduced based on the types of known variables in the bytecode, thus obtaining the types of unknown variables in the intermediate code.

[0164] In the embodiments of this application, S1110-S1120 can be referred to the description of S510-S520 above, and will not be repeated here.

[0165] S1130. Optimize the intermediate code based on the types of unknown variables in the derived intermediate code to obtain the target code.

[0166] In this embodiment of the application, the electronic device can also use the derived type of the unknown variable to optimize the intermediate code, so that the intermediate code is simplified to obtain the target code.

[0167] It should be understood that target code refers to code that can be directly executed on electronic devices, that is, code that electronic devices can recognize.

[0168] It should also be understood that when the type of an unknown variable is known, calculations can be performed directly using the derived type. Instead, the intermediate code needs to assume multiple uncertainties regarding the type of the unknown variable, and then, during the bytecode-to-intermediate code conversion, it needs to store multiple lines of code matching these uncertainties, resulting in redundant code in the intermediate code.

[0169] As can be seen, based on the compilation method provided in this application, the types of unknown variables in the derived intermediate code can be used to optimize the intermediate code, which can simplify the target code and improve the execution speed of the target code on electronic devices, thereby improving the program's running speed.

[0170] In one possible implementation, the electronic device can delete redundant code in the intermediate code based on the type of unknown variables in the derived intermediate code, thereby optimizing the intermediate code and finally obtaining the optimized target code.

[0171] For example, the following is combined with Figure 12 This application provides a detailed explanation of how it utilizes the derived types of unknown variables to optimize intermediate code.

[0172] Figure 12 This illustration shows a schematic flowchart of an embodiment of the present application for optimizing intermediate code using the types of derived unknown variables, as provided in the example. Figure 12 As shown, the compiler first performs lexical analysis, syntax analysis, and semantic analysis on the source code written by the developer to generate an annotated abstract syntax tree. Then, it generates bytecode based on the annotated abstract syntax tree and saves the existing type information of the source code in the bytecode file.

[0173] During the process of the compiler converting bytecode into intermediate code, the Runtime Linker in the compiler first generates an initial global type table based on the known variables in the bytecode and the types of those known variables.

[0174] It should be understood that this initial global type table refers to the global types that the compiler can use during the compilation of the entire source code. This initial global type table can include the parameters of the source code and their types, as well as the return values ​​of the source code and their types.

[0175] In one possible implementation, the compiler, during the process of generating intermediate code from bytecode, calls the initial global type table generated by the Runtime Linker, retrieves variables with initial types from the initial global type table, and then marks the initial type of the variable on the corresponding node in the intermediate code, such as... Figure 12 The example shows the initial type file for the intermediate code. Then, during the bytecode to intermediate code conversion process, the electronic device, based on the initial type file, deduces the types of unknown variables based on the types of known variables. The derived types of unknown variables are then used to update the initial type file of the HIR, ultimately obtaining the types of variables on all nodes.

[0176] Finally, the intermediate code is optimized based on the types of unknown variables derived from HIR, thereby removing redundant code and simplifying the intermediate code. The target code generated from the intermediate code is also simplified, ultimately making the target code run faster on electronic devices and improving the user experience.

[0177] For example, for ease of understanding, the above... Figure 7 For example, the process of optimizing intermediate code using the derived type of unknown variables in this application embodiment is illustrated. When the electronic device traverses to node 5, since the input of node 5 is node 3 and node 4, and the parameter type of node 3 and node 4 is known to be number, it can be deduced that the parameter type of node 5 is number. Then the electronic device traverses node 7, the input of node 7 is node 5 and node 6, and since node 6 is known to be number, then node 7 is also number. However, assuming that the variable type of node 5 is not derived during the intermediate code conversion process, that is, node 5 is a node of unknown type, then when traversing node 7, the electronic device will assume several cases. The first is that node 5 is number, then the output of node 7 is the sum of node 5 and node 6, and the output type is number; the second is that node 5 is string, then when performing addition operation at node 7, the number type at node 6 is first converted to string, and then the string type at node 5 and the string type at node 6 are added together.

[0178] In summary, when the variable type derived during the intermediate code conversion process, i.e. the variable type at node 5 is known to be number, it can simplify various hypothetical scenarios of the intermediate code. When the intermediate code is simplified, the converted target code will also be simplified, thereby making the electronic device execute the target code faster, which in turn makes the application run faster on the electronic device.

[0179] In other embodiments of this application, the bytecode file obtained in step S1110 of method 1100 may also include type information of unknown variables. In this case, the electronic device can directly generate intermediate code using the bytecode without needing to deduce the types of unknown variables during the intermediate code generation process. Then, after generating the intermediate code from the bytecode, the electronic device optimizes the intermediate code using the type information of the unknown variables stored in the bytecode. Although this implementation consumes the memory of the electronic device, it can also make the electronic device run applications faster.

[0180] The above combination Figures 3-12 An embodiment of the compilation method provided in this application has been described. The electronic device provided in this application is described below.

[0181] Figure 13 The diagram shown is a schematic representation of the structure of an electronic device 100 provided in this application. Figure 13 As shown, the electronic device 100 may include a processor 310, an external memory interface 320, an internal memory 321, a universal serial bus (USB) interface 330, an antenna 1, an antenna 2, a mobile communication module 350, a wireless communication module 360, an audio module 370, a speaker 370A, a receiver 370B, a microphone 370C, a headphone jack 370D, a sensor module 380, a compiler 340, etc.

[0182] It is understood that the structures illustrated in the embodiments of this application do not constitute a specific limitation on the electronic device 100. In other embodiments of this application, the electronic device 100 may include more or fewer components than illustrated, or combine some components, or split some components, or have different component arrangements. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.

[0183] Processor 310 may include one or more processing units, such as: application processor (AP), modem processor, graphics processing unit (GPU), image signal processor (ISP), controller, memory, video codec, digital signal processor (DSP), baseband processor, and / or neural network processing unit (NPU), etc. The different processing units may be independent devices or integrated into one or more processors.

[0184] The processor 310 may also include a memory for storing instructions and data. In some embodiments, the memory in the processor 310 is a cache memory. This memory can store instructions or data that the processor 310 has just used or that are used repeatedly. If the processor 310 needs to use the instruction or data again, it can retrieve it directly from the memory. This avoids repeated accesses, reduces the waiting time of the processor 310, and thus improves the efficiency of the system.

[0185] The wireless communication function of electronic device 100 can be implemented through antenna 1, antenna 2, mobile communication module 350, wireless communication module 360, modem processor and baseband processor, etc.

[0186] Antenna 1 and antenna 2 are used to transmit and receive electromagnetic wave signals. Each antenna in electronic device 100 can be used to cover one or more communication frequency bands. Different antennas can also be multiplexed to improve antenna utilization. For example, antenna 1 can be multiplexed as a diversity antenna for a wireless local area network. In some other embodiments, the antennas can be used in conjunction with tuning switches.

[0187] The mobile communication module 350 can provide solutions for wireless communication, including 2G / 3G / 4G / 5G, applied to the electronic device 100. The mobile communication module 350 may include at least one filter, switch, power amplifier, low noise amplifier (LNA), etc. The mobile communication module 350 can receive electromagnetic waves via antenna 1, and perform filtering, amplification, and other processing on the received electromagnetic waves before transmitting them to a modem processor for demodulation. The mobile communication module 350 can also amplify the signal modulated by the modem processor and convert it into electromagnetic waves for radiation via antenna 1. In some embodiments, at least some functional modules of the mobile communication module 350 may be housed in the processor 310. In some embodiments, at least some functional modules of the mobile communication module 350 and at least some modules of the processor 310 may be housed in the same device.

[0188] The wireless communication module 360 ​​can provide solutions for wireless communication applications on the electronic device 100, including wireless local area networks (WLAN), such as wireless fidelity (Wi-Fi), Bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), and infrared (IR) technologies. The wireless communication module 360 ​​can be one or more devices integrating at least one communication processing module. The wireless communication module 360 ​​receives electromagnetic waves via antenna 2, performs frequency modulation and filtering of the electromagnetic wave signal, and sends the processed signal to processor 310. The wireless communication module 360 ​​can also receive signals to be transmitted from processor 310, perform frequency modulation and amplification, and convert them into electromagnetic waves for radiation via antenna 2.

[0189] In some embodiments, antenna 1 of electronic device 100 is coupled to mobile communication module 350, and antenna 2 is coupled to wireless communication module 360, enabling electronic device 100 to communicate with networks and other devices via wireless communication technology. The wireless communication technology may include Global System for Mobile Communications (GSM), General Packet Radio Service (GPRS), Code Division Multiple Access (CDMA), Wideband Code Division Multiple Access (WCDMA), Time-Division Code Division Multiple Access (TD-SCDMA), LTE, BT, GNSS, WLAN, NFC, FM, and / or IR technology, etc. The GNSS may include Global Positioning System (GPS), Global Navigation Satellite System (GLONASS), BeiDou Navigation Satellite System (BDS), Quasi-Zenith Satellite System (QZSS), and / or satellite-based augmentation systems (SBAS).

[0190] Electronic device 100 implements display functions through a GPU, display screen 394, and application processor. The GPU is a microprocessor for image processing, connecting the display screen 394 and the application processor. The GPU is used to perform mathematical and geometric calculations and for graphics rendering. Processor 310 may include one or more GPUs, which execute program instructions to generate or modify display information.

[0191] The display screen 394 is used to display images, videos, etc. The display screen 394 includes a display panel. The display panel may be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode (AMOLED), a flexible light-emitting diode (FLED), a miniature LED, a microLED, a quantum dot light-emitting diode (QLED), etc. In some embodiments, the electronic device 100 may include one or N displays 394, where N is a positive integer greater than 1.

[0192] Electronic device 100 can perform shooting functions through ISP, camera 393, video codec, GPU, display 394 and application processor.

[0193] The ISP (Image Signal Processor) is used to process data fed back from the camera 393. For example, when taking a picture, the shutter is opened, and light is transmitted through the lens to the camera's photosensitive element. The light signal is converted into an electrical signal, and the camera's photosensitive element transmits the electrical signal to the ISP for processing, transforming it into an image visible to the naked eye. The ISP can also perform algorithmic optimization of image noise, brightness, and skin tone. The ISP can also optimize parameters such as exposure and color temperature of the shooting scene. In some embodiments, the ISP can be set in the camera 393.

[0194] Camera 393 is used to capture still images or videos. An object is projected onto a photosensitive element by generating an optical image through the lens. The photosensitive element can be a charge-coupled device (CCD) or a complementary metal-oxide-semiconductor (CMOS) phototransistor. The photosensitive element converts the light signal into an electrical signal, which is then passed to an ISP for conversion into a digital image signal. The ISP outputs the digital image signal to a DSP for processing. The DSP converts the digital image signal into image signals in standard RGB, YUV, or other formats. In some embodiments, the electronic device 100 may include one or N cameras 393, where N is a positive integer greater than 1.

[0195] Digital signal processors (DSPs) are used to process digital signals. Besides digital image signals, they can also process other digital signals. For example, when electronic device 100 is selecting a frequency, the DSP is used to perform Fourier transforms on the frequency energy.

[0196] Video codecs are used to compress or decompress digital video. Electronic device 100 may support one or more video codecs. Thus, electronic device 100 can play or record videos in various encoding formats, such as Moving Picture Experts Group (MPEG) 1, MPEG2, MPEG3, MPEG4, etc.

[0197] The external storage interface 320 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the electronic device 100. The external memory card communicates with the processor 310 through the external storage interface 320 to perform data storage functions. For example, music, video, and other files can be saved on the external memory card.

[0198] Internal memory 321 can be used to store computer executable program code, which includes instructions. Processor 310 executes various functional applications and data processing of electronic device 100 by running the instructions stored in internal memory 321. Internal memory 321 may include a program storage area and a data storage area. The program storage area may store the operating system, at least one application program required for a function (such as sound playback, image playback, etc.), etc. The data storage area may store data created during the use of electronic device 100 (such as audio data, phonebook, etc.). Furthermore, internal memory 321 may include high-speed random access memory and may also include non-volatile memory, such as at least one disk storage device, flash memory device, universal flash storage (UFS), etc.

[0199] Electronic device 100 can implement audio functions, such as music playback and recording, through audio module 370, speaker 370A, receiver 370B, microphone 370C, headphone jack 370D, and application processor.

[0200] The audio module 370 is used to convert digital audio information into analog audio signal output, and also to convert analog audio input into digital audio signal. The audio module 370 can also be used for encoding and decoding audio signals. In some embodiments, the audio module 370 may be located in the processor 310, or some functional modules of the audio module 370 may be located in the processor 310.

[0201] The speaker 370A, also known as a "loudspeaker," is used to convert audio electrical signals into sound signals. The electronic device 100 can listen to music or make hands-free calls through the speaker 370A.

[0202] The receiver 370B, also known as the "earpiece," is used to convert audio electrical signals into sound signals. When the electronic device 100 answers a phone call or voice message, the receiver 370B can be brought close to the listener's ear to hear the voice.

[0203] Microphone 370C, also known as a "microphone" or "voice transducer," is used to convert sound signals into electrical signals. When making a phone call or sending a voice message, the user can speak by bringing their mouth close to microphone 370C, inputting the sound signal into microphone 370C. Electronic device 100 may have at least one microphone 370C. In some embodiments, electronic device 100 may have two microphones 370C, which, in addition to collecting sound signals, can also perform noise reduction. In other embodiments, electronic device 100 may also have three, four, or more microphones 370C, which can collect sound signals, reduce noise, identify the sound source, and perform directional recording, etc.

[0204] The 370D headphone jack is used to connect wired headphones. The 370D headphone jack can be a USB 330 interface or a 3.5mm Open Mobile Terminal Platform (OMTP) standard interface, a CTIA (Cellular Telecommunications Industry Association of the USA) standard interface.

[0205] The sensor module 380 may include pressure sensors, gyroscope sensors, barometric pressure sensors, magnetic sensors, accelerometers, distance sensors, proximity sensors, fingerprint sensors, temperature sensors, touch sensors, ambient light sensors, bone conduction sensors, etc.

[0206] The compiler 340 is used to execute instructions for the compiler to perform the compilation method steps in any of the embodiments provided in this application.

[0207] Of course, the electronic device 100 may also include a charging management module, a power management module, a battery, buttons, indicators, and one or more SIM card interfaces, etc., and this application embodiment does not impose any restrictions on this.

[0208] It is understood that the structures illustrated in the embodiments of this application do not constitute a specific limitation on the electronic device 100. In other embodiments of this application, the electronic device 100 may include more or fewer components than illustrated, or combine some components, or split some components, or have different component arrangements. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.

[0209] It should be understood that the specific process of the electronic device 100 performing the above-mentioned corresponding steps is described in the relevant descriptions of the electronic device execution steps in the various embodiments described above. For the sake of brevity, it will not be repeated here.

[0210] This embodiment can also divide the electronic device into functional modules according to the above method. For example, it can be divided into functional modules corresponding to each function, or two or more functions can be integrated into one processing module. The integrated module can be implemented in hardware. It should be noted that the module division in this embodiment is illustrative and only represents one logical functional division; other division methods may be used in actual implementation.

[0211] It should be noted that the relevant content of each step involved in the above method embodiments can be referenced from the functional description of the corresponding functional module, and will not be repeated here.

[0212] The electronic device provided in this application embodiment is used to execute any of the compilation methods provided in the above-described method embodiments, and therefore can achieve the same effect as the above-described implementation method. When using integrated units, the terminal device may include a processing module, a storage module, and a communication module. The processing module can be used to control and manage the actions of the terminal device. For example, it can be used to support the terminal device in executing the steps executed by the processing unit. The storage module can be used to support the storage of program code and data, etc. The communication module can be used to support communication between the terminal device and other devices.

[0213] The processing module can be a processor or a controller. It can implement or execute various exemplary logic blocks, modules, and circuits described in conjunction with the disclosure of this application. The processor can also be a combination of functions that implement computing capabilities, such as a combination of one or more microprocessors, a combination of digital signal processing (DSP) and a microprocessor, etc. The storage module can be a memory. The communication module can specifically be a radio frequency circuit, a Bluetooth chip, a Wi-Fi chip, or other devices that interact with other electronic devices.

[0214] For example, Figure 14A schematic block diagram of a communication device 1400 provided in an embodiment of this application is shown. The communication device 1400 may correspond to the electronic devices described in the various embodiments of methods 500 to 1100, or may be applied to a chip or component of an electronic device. Furthermore, each module or unit in the communication device 1400 is used to execute the various actions or processing procedures performed by the electronic devices described in the various embodiments of methods 500 to 1100.

[0215] like Figure 14 As shown, the communication device 1400 includes a transceiver unit 1410 and a processing unit 1420. The transceiver unit 1410 is used to perform specific signal transmission and reception under the drive of the processing unit 1420.

[0216] In some embodiments:

[0217] The transceiver unit 1410 is used to obtain the bytecode corresponding to the program. The program includes source code, and the bytecode is generated based on the source code. The bytecode includes known variables and unknown variables.

[0218] Processing unit 1420 is used to deduce the type of unknown variables in the intermediate code based on the type of known variables in the bytecode during the conversion from bytecode to intermediate code, thereby obtaining the type of unknown variables in the intermediate code.

[0219] The communication device provided in this application deduces the type of unknown variables in the intermediate code based on the type of known variables in the bytecode during the bytecode to intermediate code conversion process. The type deduction during the intermediate code conversion process does not occupy the memory of the bytecode file, thereby reducing the memory occupied by the bytecode file.

[0220] Optionally, the processing unit 1420 is also used to optimize the intermediate code according to the type of unknown variables in the derived intermediate code to obtain the target code.

[0221] For example, processing unit 1420 can delete redundant code in the intermediate code based on the type of unknown variables in the derived intermediate code.

[0222] Optionally, the processing unit 1420 is further configured to generate an initial global type table based on known variables in the bytecode, the initial global type table including the types of all determined variables; determine the initial type of known variables in the intermediate code based on the initial global type table; and deduce the type of unknown variables in the intermediate code based on the initial type of known variables in the intermediate code.

[0223] Optionally, the processing unit 1420 is further configured to determine the abstract syntax tree corresponding to the program based on the source code; perform type deduction of the first unknown variable in the intermediate code based on the initial type of the known variable in the intermediate code and the node on the abstract syntax tree; update the initial global type table based on the type of the first unknown variable in the intermediate code; and perform type deduction of the second unknown variable in the intermediate code and update the initial global type table based on the updated initial global type table and the node on the abstract syntax tree.

[0224] Optionally, the processing unit 1420 is also configured to stop updating the initial global type table when the types of all unknown variables in the intermediate code are derived.

[0225] Furthermore, the communication device 1400 may also include a storage unit, and the transceiver unit 1410 may be a transceiver, an input / output interface, or an interface circuit. The storage unit is used to store instructions executed by the transceiver unit 1410 and the processing unit 1420. The transceiver unit 1410, the processing unit 1420, and the storage unit are coupled to each other. The storage unit stores instructions, the processing unit 1420 executes the instructions stored in the storage unit, and the transceiver unit 1410 performs specific signal transmission and reception under the drive of the processing unit 1420.

[0226] It should be understood that the specific process by which each unit in the communication device 1400 performs the corresponding steps described above is described in conjunction with methods 500 to 1100 above. Figure 5 and Figure 11 For the sake of brevity, the description of the terminal device in the relevant embodiments is omitted here.

[0227] It should be understood that the transceiver unit 1410 may be a transceiver, an input / output interface, or an interface circuit. The storage unit may be a memory. The processing unit 1420 may be implemented by a processor. Figure 15 A schematic block diagram of another example communication device 1500 provided in an embodiment of this application is shown. For example... Figure 15 As shown, the communication device 1500 may include a processor 1510, a memory 1520, and a transceiver 1530.

[0228] Figure 14 The communication device 1400 shown or Figure 15 The communication device 1500 shown is capable of implementing the steps performed by the electronic device in the various embodiments of methods 500 to 1100 described above. Similar descriptions can be found in the descriptions of the corresponding methods described above. To avoid repetition, they will not be repeated here.

[0229] It should also be understood that Figure 14 The communication device 1400 shown or Figure 15 The communication device 1500 shown can be an electronic device.

[0230] This application also provides a chip system, such as... Figure 16 As shown, the chip system includes at least one processor 1601 and at least one interface circuit 1602. The processor 1601 and the interface circuit 1602 are interconnected via lines. For example, the interface circuit 1602 can be used to receive signals from other devices (e.g., the memory of the aforementioned electronic device). As another example, the interface circuit 1602 can be used to send signals to other devices (e.g., the processor 1601). Exemplarily, the interface circuit 1602 can read instructions stored in the memory and send those instructions to the processor 1601. When the instructions are executed by the processor 1601, the electronic device can perform the various steps performed by any of the electronic devices in the above embodiments. Of course, the chip system may also include other discrete components, which are not specifically limited in this application embodiment.

[0231] It should also be understood that the division of units in the above device is merely a logical functional division. In actual implementation, they can be fully or partially integrated into a single physical entity, or they can be physically separated. Furthermore, all units in the device can be implemented entirely through software calls from processing elements; all units can be implemented entirely in hardware; or some units can be implemented through software calls from processing elements, while others are implemented in hardware. For example, each unit can be a separate processing element, or it can be integrated into a chip within the device. Alternatively, it can be stored as a program in memory, and its function can be called and executed by a processing element within the device. Here, the processing element can also be called a processor, which can be an integrated circuit with signal processing capabilities. In the implementation process, each step of the above method or each of the above units can be implemented through integrated logic circuits in the processor element or through software calls from processing elements. In one example, a unit in any of the above devices can be one or more integrated circuits configured to implement the above methods, such as one or more application-specific integrated circuits (ASICs), or one or more digital signal processors (DSPs), or one or more field-programmable gate arrays (FPGAs), or a combination of at least two of these forms of integrated circuits. As another example, when a unit in the device can be implemented in the form of a processing element scheduler, the processing element can be a general-purpose processor, such as a central processing unit (CPU) or other processor capable of calling programs. Furthermore, these units can be integrated together to implement a system-on-a-chip (SOC).

[0232] This application also provides an apparatus included in an electronic device, which has the function of implementing the behavior of the electronic device in any of the above embodiments. This function can be implemented by hardware or by hardware executing corresponding software. The hardware or software includes at least one module or unit corresponding to the above function.

[0233] This application also provides an electronic device that includes the apparatus provided in the embodiments of this application described above.

[0234] This application also provides a computer-readable storage medium for storing computer program code, the computer program including instructions for executing the steps of the compilation method performed by the electronic device in any of the embodiments provided in this application. The readable medium may be a read-only memory (ROM) or a random access memory (RAM), and this application does not limit this.

[0235] This application also provides a computer program product including instructions that, when executed, cause an electronic device to perform the steps performed by the electronic device in any of the above embodiments.

[0236] This application also provides a chip comprising a processing unit and a communication unit. The processing unit may be, for example, a processor, and the communication unit may be, for example, an input / output interface, pins, or circuitry. The processing unit can execute computer instructions to cause an electronic device to perform any of the compilation methods provided in the embodiments of this application described above.

[0237] Optionally, the computer instructions are stored in a storage unit.

[0238] Optionally, the storage unit can be an internal storage unit within the chip, such as a register or cache. Alternatively, it can be an external storage unit located within the terminal, such as a ROM or other types of static storage devices capable of storing static information and instructions, like random access RAM. The processor mentioned above can be a CPU, microprocessor, ASIC, or one or more integrated circuits used to control the execution of a program for the aforementioned electronic device projection display method. The processing unit and the storage unit can be decoupled and located on different physical devices, connected via wired or wireless means to implement their respective functions, thus supporting the system chip in implementing the various functions described in the above embodiments. Alternatively, the processing unit and the memory can also be coupled to the same device.

[0239] In this embodiment, the electronic device, apparatus, computer-readable storage medium, computer program product or chip are all used to execute the corresponding methods provided above. Therefore, the beneficial effects that can be achieved can be referred to the beneficial effects of the corresponding methods provided above, and will not be repeated here.

[0240] It is understood that the aforementioned electronic devices, etc., include hardware structures and / or software modules corresponding to the execution of each function in order to achieve the above-mentioned functions. Those skilled in the art should readily recognize that, based on the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein, the embodiments of this application can be implemented in hardware or a combination of hardware and computer software. Whether a function is executed by hardware or by computer software driving hardware depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of the embodiments of this application.

[0241] This application embodiment can divide the above-mentioned electronic device into functional modules according to the method example described above. For example, each function can be divided into its own functional module, or two or more functions can be integrated into one processing module. The integrated module can be implemented in hardware or as a software functional module. It should be noted that the module division in this application embodiment is illustrative and only represents one logical functional division. In actual implementation, there may be other division methods.

[0242] Through the above description of the embodiments, those skilled in the art will clearly understand that, for the sake of convenience and brevity, only the division of the above functional modules is used as an example. In practical applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. The specific working process of the system, device, and unit described above can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.

[0243] In the embodiments of this application, the functional units can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0244] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solutions of the embodiments of this application, essentially, or the parts that contribute to the prior art, or all or part of the technical solutions, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) or processor to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as flash memory, portable hard disk, read-only memory, random access memory, magnetic disk, or optical disk.

[0245] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any changes or substitutions within the technical scope disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.

Claims

1. A compilation method, characterized in that, The method includes: Obtain the bytecode corresponding to the program, wherein the program includes source code, the bytecode is generated based on the source code, and the bytecode includes known variables and unknown variables; During the process of converting bytecode to intermediate code, an initial global type table is generated based on the known variables in the bytecode. The initial global type table includes the types of all known variables. Based on the initial global type table, determine the initial type of the known variables in the intermediate code; Based on the initial type of the known variables in the intermediate code, the type of the unknown variables in the intermediate code is deduced to obtain the type of the unknown variables in the intermediate code.

2. The method according to claim 1, characterized in that, The method further includes: The intermediate code is optimized based on the types of unknown variables in the derived intermediate code to obtain the target code.

3. The method according to claim 2, characterized in that, The optimization of the intermediate code based on the types of unknown variables in the derived intermediate code to obtain the target code includes: Based on the types of unknown variables in the derived intermediate code, redundant code in the intermediate code is deleted to obtain the target code.

4. The method according to any one of claims 1-3, characterized in that, The method further includes: Determine the abstract syntax tree corresponding to the program based on the source code; The step of deriving the type of unknown variables in the intermediate code based on the initial type of known variables in the intermediate code includes: Based on the initial type of the known variables in the intermediate code and the nodes on the abstract syntax tree, the type of the first unknown variable in the intermediate code is deduced. The initial global type table is updated based on the type of the first unknown variable in the intermediate code; Based on the updated initial global type table and the nodes on the abstract syntax tree, the type deduction of the second unknown variable in the intermediate code and the update of the initial global type table are performed.

5. The method according to claim 4, characterized in that, The method further includes: Stop updating the initial global type table when the types of all unknown variables in the intermediate code are derived.

6. The method according to claim 5, characterized in that, The variable type includes any one of number, string, Boolean, Null, Undefined, and Object.

7. A communication device, characterized in that, The apparatus includes a unit for performing the steps of the method as described in any one of claims 1 to 6.

8. An electronic device, characterized in that, The electronic device includes a processor and a memory, the memory being used to store instructions, and the processor being used to read the instructions to perform the method as described in any one of claims 1 to 6.

9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program, the computer program including program instructions that, when executed by a processor, cause the processor to perform the method as described in any one of claims 1 to 6.

10. A chip, characterized in that, include: A processor for retrieving and running a computer program from memory, causing a communication device on which the chip is mounted to perform the method as described in any one of claims 1 to 6.