Source code processing method and device, equipment and storage medium

Through the source code processing method of embedded devices, the abstract syntax tree is traversed to determine the target string and assign an index, which is replaced in the GIMPLE stage of the compiler to generate a mapping table, which solves the problem of limited resources of embedded devices and achieves efficient utilization of storage space and memory.

CN120669991APending Publication Date: 2025-09-19SHANDONG YUNHAI GUOCHUANG CLOUD COMPUTING EQUIP IND INNOVATION CENT CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510897099.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-30
Publication Date
2025-09-19

AI Technical Summary

Technical Problem

Embedded devices have limited resources during the source code compilation process, especially the large storage space and memory usage. Existing string compression algorithms are limited in effect and cannot effectively alleviate resource pressure.

Method used

By traversing the abstract syntax tree, determining the target string and assigning index information, performing string replacement in the GIMPLE phase of the compiler, generating a mapping table, and finally compiling into a binary file, the storage space occupied by the string is reduced.

Benefits of technology

Effectively reduce the storage space occupied by strings in binary files, improve storage resource utilization, reduce memory pressure, adapt to the resource requirements of embedded devices, and alleviate resource constraints.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120669991A_ABST
    Figure CN120669991A_ABST
Patent Text Reader

Abstract

The invention discloses a source code processing method and device, equipment and a storage medium, relates to the technical field of software development, is applied to embedded equipment, and comprises the following steps: traversing an abstract syntax tree corresponding to a source code to determine a target character string; the abstract syntax tree is constructed by processing source codes through a compiler; distributing index information for each target character string, and replacing the target character strings in a GIMPLE statement by using the index information in a GIMPLE stage of processing the source code by a compiler to obtain a replaced statement; a mapping table is generated based on the corresponding relation between the index information and the target character string, the replaced statement is compiled into a binary file through a compiler, and source code processing is completed. Therefore, in the source code compiling process, the index information can be distributed to the character strings, and then the index information is used for replacing the character strings; the space occupation of the character string can be reduced from the source, and the resource limitation condition of the embedded equipment is relieved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of software development, and in particular to a source code processing method, apparatus, device and storage medium. Background Art

[0002] Embedded devices often have limited resources, including limited storage space, memory, and processing power. They may be equipped with only a few megabytes (MB) to tens of MB of memory. Given these resource constraints, device software design and optimization become crucial. In embedded device software development, strings are frequently used in source code and during runtime. These strings include program constants, error messages, and log information. During the compilation process, these strings are stored in the read-only data segment of the binary file. As the code size increases or large amounts of text need to be processed, the number of strings in the binary file increases significantly, occupying a large amount of storage space.

[0003] Currently, a common method is to compress strings in binary files using string compression techniques. These algorithms identify recurring patterns in strings and use shorter codes to represent the same content, thereby reducing the storage space occupied by the strings. However, these algorithms are usually processed after the binary files are generated. Moreover, their compression effectiveness is limited, resulting in low compression rates for short strings or strings without obvious recurring patterns.

[0004] It can be seen that how to alleviate the resource pressure of embedded devices during the source code compilation process is a problem that those skilled in the art need to solve. Summary of the Invention

[0005] The purpose of the embodiments of the present invention is to provide a source code processing method, apparatus, device and storage medium, which can solve the problem of limited resources in the source code compilation process of embedded devices.

[0006] To solve the above technical problems, in a first aspect, an embodiment of the present invention provides a source code processing method applied to an embedded device, comprising:

[0007] Traverse the abstract syntax tree corresponding to the source code to determine the target string in the abstract syntax tree; the abstract syntax tree is the abstract syntax tree constructed by processing the source code through the compiler;

[0008] Assigning index information to each target string, and using the index information to replace the corresponding target string in the GIMPLE statement during the GIMPLE phase of the compiler processing the source code to obtain a replaced statement;

[0009] A mapping table is generated based on the correspondence between the index information and the target string, and the replaced statements are compiled into corresponding binary files through a compiler to complete the processing of the source code.

[0010] In some embodiments, traversing an abstract syntax tree corresponding to the source code to determine a target string in the abstract syntax tree includes:

[0011] Traverse the nodes in the abstract syntax tree corresponding to the source code to determine the current node;

[0012] If the current node is a string constant node, perform a string extraction operation on the current node to obtain the corresponding target string;

[0013] If the current node is not a string constant node, the process jumps to the step of traversing the nodes in the abstract syntax tree corresponding to the source code until all nodes in the abstract syntax tree have been traversed.

[0014] In some embodiments, traversing the abstract syntax tree corresponding to the source code includes:

[0015] Through the target plug-in pre-set on the compiler, the compiler's processing of the source code is monitored in real time, and when it is detected that the compiler constructs the abstract syntax tree corresponding to the source code, the abstract syntax tree is traversed.

[0016] In some embodiments, during the GIMPLE stage of the compiler processing source code, the corresponding target string in the GIMPLE statement is replaced using the index information to obtain a replaced statement, including:

[0017] When it is detected that the compiler is in the GIMPLE stage of processing the source code, GIMPLE statements corresponding to the source code in the GIMPLE stage are traversed to determine the current string;

[0018] Determine whether the current string corresponds to a string constant and obtain the corresponding judgment result;

[0019] If the judgment result indicates that the current string is a string corresponding to the string constant, the current string is replaced using the corresponding index information;

[0020] If the judgment result indicates that the current string is not a string corresponding to the string constant, the current string is ignored, and the process jumps to the step of traversing the GIMPLE statements corresponding to the source code in the GIMPLE stage;

[0021] Until all the strings in the GIMPLE statement have been traversed, a post-replacement statement is obtained after the relevant replacement operations have been performed.

[0022] In some embodiments, the method further comprises:

[0023] When the embedded device is running, based on the preset log format, the index information is used to generate log information corresponding to the source code, and the log information is stored in the preset log file so that relevant personnel can view the log information.

[0024] In some embodiments, viewing log information includes:

[0025] Based on the viewing command issued for the log information, the log information is read from the preset log file, and a mapping table corresponding to the log information is determined;

[0026] Based on the correspondence between the index information in the log information and the character strings in the mapping table, several original character strings corresponding to the log information are determined, and readable information is generated based on the several original character strings and the log information, so that the readable information can be viewed.

[0027] In some embodiments, after generating readable information based on the original character strings and log information, the method further includes:

[0028] Sending readable information to a remote console so that relevant personnel can view the readable information through the remote console;

[0029] Alternatively, the readable information is stored in a designated location so that relevant personnel can read the designated location to view the readable information.

[0030] In a second aspect, the present invention provides a source code processing apparatus, applied to an embedded device, comprising:

[0031] A string determination module is used to traverse the abstract syntax tree corresponding to the source code to determine the target string in the abstract syntax tree; the abstract syntax tree is the abstract syntax tree constructed by processing the source code through the compiler;

[0032] The string replacement module is used to assign index information to each target string and use the index information to replace the corresponding target string in the GIMPLE statement during the GIMPLE stage of the compiler processing the source code to obtain the replaced statement;

[0033] The compilation module is used to generate a mapping table based on the correspondence between the index information and the target string, and compile the replaced statements into corresponding binary files through the compiler to complete the processing of the source code.

[0034] In a third aspect, the present invention provides an electronic device, comprising:

[0035] memory for storing computer programs;

[0036] A processor is used to execute a computer program to implement the steps of the source code processing method.

[0037] In a fourth aspect, the present invention provides a computer-readable storage medium having a computer program stored thereon, which implements the steps of the above-mentioned source code processing method when executed by a processor.

[0038] It can be seen from the above technical solution that in this application, the embedded device can traverse the abstract syntax tree corresponding to the source code to determine the target string in the abstract syntax tree; the abstract syntax tree is constructed by processing the source code through the compiler; then, index information is assigned to each target string, and in the GIMPLE stage of the compiler processing the source code, the index information is used to replace the corresponding target string in the GIMPLE statement to obtain the replaced statement; then, a mapping table is generated based on the correspondence between the index information and the target string, and the replaced statement is compiled into a corresponding binary file through the compiler to complete the processing of the source code. In this way, the present application can assign index information to several strings in combination with the abstract syntax tree during the source code compilation process; then, in the GIMPLE stage of the compilation, the index information is used to replace the relevant strings; this can reduce the amount of storage space occupied by the strings in the binary file from the source code, and can more efficiently and flexibly adapt to the resource requirements of the embedded device and alleviate resource constraints. BRIEF DESCRIPTION OF THE DRAWINGS

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

[0040] Figure 1 A flow chart of a source code processing method disclosed in this application;

[0041] Figure 2 A flow chart of a specific source code processing method disclosed in this application;

[0042] Figure 3 This is a schematic diagram of the processing stages of a plug-in compiler disclosed in this application;

[0043] Figure 4 This is a flow chart of another specific source code processing method disclosed in this application;

[0044] Figure 5 A specific log information processing flow chart disclosed in this application;

[0045] Figure 6 This is a schematic diagram of the structure of a source code processing device disclosed in this application;

[0046] Figure 7 This application discloses a structural diagram of an electronic device. DETAILED DESCRIPTION

[0047] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of them. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making any creative efforts shall fall within the scope of protection of the present invention.

[0048] The terms "including" and "having," as used in the present description and accompanying drawings, and any variations thereof, are intended to cover non-exclusive inclusions. For example, a process, method, system, product, or apparatus comprising a series of steps or elements is not limited to the listed steps or elements and may include steps or elements that are not listed.

[0049] In order to enable those skilled in the art to better understand the present invention, the present invention will be further described in detail below with reference to the accompanying drawings and specific implementation methods.

[0050] like Figure 1 As shown, this embodiment discloses a source code processing method, which is applied to an embedded device, including:

[0051] Step S11: traverse the abstract syntax tree corresponding to the source code to determine the target string in the abstract syntax tree; the abstract syntax tree is an abstract syntax tree constructed by processing the source code through a compiler.

[0052] It is understandable that the compiler (GNU Compiler Collection, GCC) includes multiple compilation stages from source code to executable file generation, such as preprocessing, abstract syntax tree construction, generalization processing, GIMPLE (compiler intermediate representation) generation, RTL (Register Transfer Language) generation, and assembly code generation, etc., and finally generates an executable file; in this embodiment, when the compiler processes the source code and constructs the corresponding abstract syntax tree, the abstract syntax tree can be traversed to find the corresponding string constants, that is, to determine the target string; these strings can be processed subsequently.

[0053] In a specific embodiment, traversing the abstract syntax tree corresponding to the source code to determine the target string in the abstract syntax tree can include: traversing the nodes in the abstract syntax tree corresponding to the source code to determine the current node; if the current node is a string constant node, performing a string extraction operation on the current node to obtain the corresponding target string; if the current node is not a string constant node, jumping to the step of traversing the nodes in the abstract syntax tree corresponding to the source code until all nodes in the abstract syntax tree have been traversed. Specifically, in the process of traversing the abstract syntax tree corresponding to the source code, the current node in the abstract syntax tree can be determined in turn; then the type of the current node is judged. If the current node is a string constant node, a string extraction operation is performed on the current node to obtain the string content stored therein, that is, the corresponding target string; correspondingly, if the current node is not a string constant node, the next node can be traversed until all nodes in the abstract syntax tree have been traversed. By traversing the abstract syntax tree corresponding to the source code and extracting the node string content, each target string corresponding to the source code can be obtained.

[0054] In another specific embodiment, traversing the abstract syntax tree corresponding to the source code may include: monitoring the compiler's processing of the source code in real time through a target plug-in pre-installed on the compiler, and traversing the abstract syntax tree when the compiler is detected constructing the abstract syntax tree corresponding to the source code. Specifically, during the compiler's processing of the source code, corresponding plug-ins may be installed on the compiler for different processing stages to monitor the compiler's processing of the source code in real time; further, when the plug-in detects the compiler constructing the abstract syntax tree corresponding to the source code, the abstract syntax tree may be traversed to extract relevant target strings.

[0055] Step S12: assign index information to each target string, and use the index information to replace the corresponding target string in the GIMPLE statement during the GIMPLE stage of the compiler processing the source code to obtain a replaced statement.

[0056] In this embodiment, the above steps can be used to traverse the abstract syntax tree corresponding to the source code to obtain the corresponding target string; then, a unique index can be assigned to each extracted string, that is, each target string corresponds to an index information. Furthermore, during the GIMPLE stage of the compiler processing the source code, the strings in the intermediate representation GIMPLE statements can be processed; specifically, the index information corresponding to the string can be used to replace the corresponding target string in the GIMPLE statement, that is, the string in the GIMPLE statement is replaced with the corresponding index information; this can obtain an intermediate representation composed of the index information, which is recorded as the replaced statement.

[0057] In a specific embodiment, in a GIMPLE phase of source code processing by a compiler, replacing a target string corresponding to a GIMPLE statement using index information to obtain a replaced statement may include: upon detecting that the compiler's source code processing process is in the GIMPLE phase, traversing the GIMPLE statements corresponding to the source code in the GIMPLE phase to determine a current string; determining whether the current string corresponds to a string constant and obtaining a corresponding determination result; if the determination result indicates that the current string is a string corresponding to the string constant, performing a replacement operation on the current string using the corresponding index information; if the determination result indicates that the current string is not a string corresponding to the string constant, ignoring the current string and jumping to the step of traversing the GIMPLE statements corresponding to the source code in the GIMPLE phase; and continuing until all strings in the GIMPLE statements have been traversed to obtain a replaced statement after performing the relevant replacement operations. Specifically, the process of replacing the string in the GIMPLE statement is to traverse the GIMPLE statement corresponding to the GIMPLE stage when it is detected that the compiler is processing the source code in the GIMPLE stage to determine whether the current string corresponds to a string constant; it is understandable that the corresponding index information has been assigned to the string corresponding to the string constant; at this time, the index information can be used to replace the current string corresponding to the string constant in the GIMPLE statement; accordingly, if the current string traversed in the GIMPLE statement does not correspond to the string constant, it means that the index information has not been assigned to the current string, then the current string is ignored and the GIMPLE statement is continued to be traversed until all the strings in the GIMPLE statement have been traversed. It is understandable that by replacing the strings in the GIMPLE statement, the space occupied by the GIMPLE statement can be greatly reduced, which can reduce the space occupied by the executable file compiled later.

[0058] Step S13: Generate a mapping table based on the correspondence between the index information and the target character string, and compile the replaced statements into corresponding binary files through a compiler to complete the processing of the source code.

[0059] In this embodiment, through the above steps, the index information can be used to replace the relevant character strings in the GIMPLE statement to obtain the corresponding replaced statement; then, the replaced statement can be compiled into a corresponding binary file (executable file) by a compiler; and a mapping table can be generated based on the correspondence between the index information and the target character strings; finally, the binary file and the corresponding mapping table are obtained, indicating that the processing of the source code is completed.

[0060] In a specific embodiment, it may also include: when the embedded device is running, based on a preset log format, using index information to generate log information corresponding to the source code, and storing the log information in a preset log file so that relevant personnel can view the log information. Specifically, when the embedded device is running, corresponding log information can be generated according to the operation of the device; because the process of processing the source code involves index information and related string replacement operations, it is necessary to generate a new format log in combination with the index information when generating the log; here, based on the pre-constructed log format, the index information involved in the source code processing process can be used to generate the log information corresponding to the source code; and the generated log information can be stored in the preset log file for unified management, which is convenient for relevant personnel to view.

[0061] In another specific embodiment, viewing log information may include: based on a viewing command issued for the log information, reading the log information from a preset log file, and determining a mapping table corresponding to the log information; based on the correspondence between the index information in the log information and the character strings in the mapping table, determining a number of original character strings corresponding to the log information, and generating readable information based on the number of original character strings and the log information, so as to view the readable information. Specifically, in the process of viewing the log information, relevant personnel may issue corresponding viewing instructions; it is understandable that the log information is generated based on the index information, and direct viewing cannot reveal relevant information about the source code; here, based on the mapping table corresponding to the log information, it is possible to determine a number of original character strings that correspond to the index information in the log information, i.e., the character strings corresponding to the source code; and then generate readable information based on the original character strings and other information in the log information. It is understandable that the readable information contains the original character strings corresponding to the index information, and the relevant character information of the corresponding source code can be directly viewed without the help of a mapping table.

[0062] In another specific embodiment, after generating readable information based on the original character strings and log information, the method may further include: sending the readable information to a remote console so that relevant personnel can view the readable information through the remote console; or storing the readable information in a designated location so that relevant personnel can read the designated location to view the readable information. Specifically, after the embedded device generates the readable information based on the original character strings and log information, to facilitate relevant personnel to view the readable information, the readable information may be sent to the remote console for direct remote viewing by the relevant personnel; or the readable information may be stored in a designated location, and the relevant personnel may issue an instruction to read the designated location to read the corresponding stored readable information.

[0063] As can be seen from this, the present application can assign index information to several strings in conjunction with the abstract syntax tree during source code compilation. Then, during the GIMPLE phase of compilation, the index information can be used to replace the relevant strings. This can reduce the size of the read-only data segment (rodata segment) in the binary file from the source. For resource-constrained embedded devices, such as sensor nodes with only a few KB to tens of KB of flash memory space, reducing the rodata segment means that more program code or other necessary data can be stored, improving storage resource utilization. Furthermore, because indexes are used instead of strings in the compiled code, there is no need to load large numbers of strings into memory when the program is running, thereby reducing memory usage, alleviating memory pressure, and more efficiently and flexibly adapting to the resource needs of embedded devices, alleviating resource constraints.

[0064] like Figure 2 As shown, this embodiment discloses a source code processing method, which is applied to embedded devices and specifically includes:

[0065] In this embodiment, during the source code compilation process, a plug-in can register a simple callback function after the preprocessing phase to perform a preliminary string scan on the preprocessed file and record possible strings. Index allocation and replacement operations are not performed during this process. Subsequently, during the abstract syntax tree construction phase, the plug-in can traverse the abstract syntax tree and extract the corresponding strings. An index is assigned to each extracted string. An array can be used to store the correspondence between strings and indexes, facilitating subsequent search and use.

[0066] Furthermore, during the GIMPLE generation phase of the compilation process, the string constants in the GIMPLE statements can be replaced according to the previously assigned indexes, so that the replaced GIMPLE statements can be obtained; then the corresponding executable file can be compiled; at the same time, the correspondence between the stored strings and indexes can be saved to an external file to generate a mapping table. The mapping table can be in a simple text format, with each line recording a string and its corresponding index, which is convenient for subsequent use in scenarios such as log parsing. Through the above steps, the plug-in can complete the functions of string extraction, index allocation, string replacement and mapping table generation at different stages of GCC compilation. In a specific embodiment, the contents of the mapping table may be as follows:

[0067] { "0": "Hello, World",

[0068] "1": "Error: File not found",

[0069] "2": "Warning: Invalid input"};

[0070] The index information is "0, 1, 2", which correspond to different character strings respectively.

[0071] It is understandable that GCC allows plug-ins to be inserted into multiple compilation stages to customize and extend the compilation process; for example Figure 3 The main stages in GCC where plug-ins can be inserted are shown. The source code file is processed by the compiler to obtain an executable file. The process involves multiple stages where plug-ins can be inserted to customize and extend the source code compilation process.

[0072] In a specific embodiment, Figure 4 As shown, when the compiler compiles the source code, it can construct a corresponding abstract syntax tree after preprocessing. At this point, it can traverse the abstract syntax tree to determine whether each node is a string constant node. If not, it continues traversing. If so, it can extract the corresponding string. After extracting the string, it can assign index information to each string. Furthermore, when the compiler is in the intermediate representation stage, i.e., the GIMPLE stage, it can traverse the GIMPLE statements to determine whether an assignment operation needs to be performed for the string constants therein, and replace the string constants in the GIMPLE statements with the corresponding index. This process completes the compilation of the source code after traversing all GIMPLE statements and generating a mapping table representing the correspondence between index information and strings, thus ending the source code processing process.

[0073] It should be noted that the string replacement steps above can significantly reduce the size of the rodata segment. However, this presents a problem: if the replaced index is used directly, the log information will be unreadable when printed. Therefore, the log information needs to be stored in a specific format and then restored using a mapping table. Furthermore, a specific log storage format can be adopted. Specifically, the log storage format: each log entry occupies a fixed 28 bytes, with a format of an 8-byte timestamp + a string index + four 4-byte parameters. The timestamp records the time the log occurred, the string index identifies the original string corresponding to the log, and the four 4-byte parameters can store additional log-related information, such as variable values ​​and error codes. During operation of the embedded device, the log information is stored in the log file according to the above format. Since each log entry has a fixed length, subsequent log reading and processing is facilitated. To implement fixed-length logging, a suitable data structure is required to store the log information. Considering the log storage requirements, each log entry contains an 8-byte timestamp, a string index, and four 4-byte parameters, for a total of 28 bytes. The following data structure implemented in C language can be used to store log information:

[0074] struct {

[0075] time_t timestamp; / / 8-byte timestamp

[0076] int string_index; / / string index

[0077] int params[4]; / / 4 4-byte parameters

[0078] } LogEntry;

[0079] The time_t type is typically 8 bytes and is used to store the number of seconds from a fixed time point (such as January 1, 1970) to the current time, serving as the log timestamp. string_index is an integer representing the index of a string within the log. The params array stores four 4-byte parameters and can be used to pass additional information. In a specific embodiment, the log storage format may be as shown in Table 1 below.

[0080] Table 1

[0081]

[0082] Furthermore, when the log needs to be viewed, the log information recorded in the above steps needs to be restored; specifically, the stored log information needs to be restored to the original string form according to the corresponding mapping table. Figure 5 As shown, first open the log file and the corresponding mapping table file; read the mapping table into the memory, and read each log record from the log file in sequence, parse out the timestamp, string index and parameters, etc.; then find the corresponding original string in the mapping table according to the string index. The log restoration is then performed to combine the timestamp, original string and parameters into readable log information, which can be output to the console or stored in other files for relevant personnel to view. It should be pointed out that in a specific embodiment, the strings recorded after preliminary string scanning of the preprocessed file can be combined with the mapping table during the subsequent log restoration to determine the original string corresponding to the index information in the log information, to ensure that the readable information finally restored matches the string information after source code preprocessing, thereby ensuring the reliability of the log information.

[0083] It can be seen that the present application can assign index information to several strings in combination with the abstract syntax tree during the source code compilation process; then, in the GIMPLE stage of compilation, the index information is used to replace the relevant strings; this can reduce the amount of storage space occupied by strings in binary files from the source; and, based on the correspondence between indexes and strings, log information is generated in a fixed format, avoiding string splicing and processing operations, which can improve the processing speed of embedded devices; at the same time, the generated log information is smaller in data volume than the log data corresponding to the original string, which can reduce data transmission time and alleviate the communication pressure of embedded devices.

[0084] like Figure 6 As shown, this embodiment discloses a source code processing device, which is applied to an embedded device, including:

[0085] The string determination module 11 is used to traverse the abstract syntax tree corresponding to the source code to determine the target string in the abstract syntax tree; the abstract syntax tree is the abstract syntax tree constructed by processing the source code through the compiler;

[0086] The string replacement module 12 is used to assign index information to each target string and use the index information to replace the corresponding target string in the GIMPLE statement during the GIMPLE stage of the compiler processing the source code to obtain a replaced statement;

[0087] The compiling module 13 is used to generate a mapping table based on the correspondence between the index information and the target character string, and compile the replaced statements into corresponding binary files through a compiler to complete the processing of the source code.

[0088] It can be seen from this that the present application can assign index information to several strings in combination with the abstract syntax tree during the source code compilation process; and then use the index information to replace the relevant strings in the GIMPLE stage of the compilation; this can reduce the amount of storage space occupied by strings in the binary file from the source, and can more efficiently and flexibly adapt to the resource requirements of embedded devices and alleviate resource constraints.

[0089] In a specific embodiment, the character string determination module 11 may include:

[0090] The first traversal unit is used to traverse the nodes in the abstract syntax tree corresponding to the source code to determine the current node;

[0091] A string extraction unit, configured to perform a string extraction operation on the current node to obtain a corresponding target string when the current node is a string constant node;

[0092] The first jump unit is configured to jump to the step of traversing the nodes in the abstract syntax tree corresponding to the source code if the current node is not a string constant node, until all nodes in the abstract syntax tree have been traversed.

[0093] In a specific embodiment, the character string determination module 11 may include:

[0094] The monitoring unit is used to monitor the compiler's processing of the source code in real time through a target plug-in pre-set on the compiler, and traverse the abstract syntax tree when it is detected that the compiler constructs the abstract syntax tree corresponding to the source code.

[0095] In a specific embodiment, the string replacement module 12 may include:

[0096] The second traversal unit is configured to detect that the compiler is in the GIMPLE stage of processing the source code, and traverse the GIMPLE statements corresponding to the source code in the GIMPLE stage to determine the current string;

[0097] A judgment unit, used to judge whether the current string corresponds to a string constant and obtain a corresponding judgment result;

[0098] A string replacement unit, configured to replace the current string using the corresponding index information when the judgment result indicates that the current string is a string corresponding to the string constant;

[0099] The second jump unit is used to ignore the current string when the judgment result indicates that the current string is not a string corresponding to the string constant, and jump to the step of traversing the GIMPLE statements corresponding to the source code in the GIMPLE stage; until all strings in the GIMPLE statements have been traversed and a replaced statement after performing the relevant replacement operation is obtained.

[0100] In a specific embodiment, the apparatus may further include:

[0101] The log storage module is used to generate log information corresponding to the source code based on the preset log format and index information when the embedded device is running, and store the log information in a preset log file so that relevant personnel can view the log information.

[0102] In another specific embodiment, the log storage module may include:

[0103] a mapping table determining unit, configured to read the log information from a preset log file based on a viewing command issued for the log information, and determine a mapping table corresponding to the log information;

[0104] The readable information generating unit is used to determine several original strings corresponding to the log information based on the correspondence between the index information in the log information and the strings in the mapping table, and generate readable information based on the several original strings and the log information so as to view the readable information.

[0105] In another specific embodiment, the apparatus may further include:

[0106] A readable information sending unit, used for sending the readable information to a remote console so that relevant personnel can view the readable information through the remote console;

[0107] The readable information storage unit is used to store the readable information in a designated location so that relevant personnel can read the designated location to view the readable information.

[0108] Furthermore, the embodiment of the present application also discloses an electronic device, Figure 7 This is a block diagram of an electronic device according to an exemplary embodiment. The content of the diagram should not be construed as limiting the scope of use of this application. The electronic device may include at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input / output interface 25, and a communication bus 26. The memory 22 is used to store a computer program, which is loaded and executed by the processor 21 to implement the relevant steps of the source code processing method disclosed in any of the aforementioned embodiments. Furthermore, the electronic device in this embodiment may be a computer.

[0109] In this embodiment, the power supply 23 is used to provide operating voltage for various hardware devices on the electronic device; the communication interface 24 can create a data transmission channel between the electronic device and external devices. The communication protocol it follows is any communication protocol that can be applied to the technical solution of this application and is not specifically limited here; the input and output interface 25 is used to obtain external input data or output data to the outside world. Its specific interface type can be selected according to specific application needs and is not specifically limited here.

[0110] In addition, the memory 22, as a carrier for resource storage, can be a read-only memory, random access memory, disk or CD, etc. The resources stored thereon can include an operating system 221, a computer program 222, etc., and the storage method can be temporary storage or permanent storage.

[0111] The operating system 221 is used to manage and control the hardware devices on the electronic device, as well as the computer program 222, which can be Windows Server, NetWare, Unix, Linux, etc. In addition to including a computer program capable of implementing the source code processing method executed by the electronic device disclosed in any of the aforementioned embodiments, the computer program 222 can further include a computer program capable of implementing other specific tasks.

[0112] Furthermore, this application also discloses a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, the aforementioned source code processing method is implemented. The specific steps of this method can be referred to the corresponding contents disclosed in the aforementioned embodiments and will not be repeated here.

[0113] Furthermore, the present application discloses a computer program product, including a computer program / instruction, which implements the aforementioned disclosed source code processing method when executed by a processor.

[0114] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from the other embodiments. Reference can be made to the descriptions of the identical or similar parts between the various embodiments. For the devices disclosed in the embodiments, since they correspond to the methods disclosed in the embodiments, the descriptions are relatively simple, and the relevant parts can be referred to the descriptions of the methods.

[0115] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the above description has generally described the components and steps of each example according to their functions. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0116] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein may be implemented directly using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in random access memory (RAM), internal memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.

[0117] Finally, it should be noted that, in this document, relational terms such as first and second, etc., are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of additional identical elements in the process, method, article, or device comprising the element.

[0118] The above is a detailed introduction to the technical solution provided by the present application. Specific examples are used herein to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea. At the same time, for those skilled in the art, according to the ideas of the present application, there may be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.

Claims

1. A source code processing method, characterized in that: Applications in embedded devices, including: Traversing an abstract syntax tree corresponding to the source code to determine a target string in the abstract syntax tree; the abstract syntax tree is an abstract syntax tree constructed by processing the source code through a compiler; Assigning index information to each target string, and using the index information to replace the corresponding target string in the GIMPLE statement during the GIMPLE phase of the compiler processing the source code to obtain a replaced statement; A mapping table is generated based on the corresponding relationship between the index information and the target character string, and the replaced statement is compiled into a corresponding binary file by the compiler to complete the processing of the source code.

2. The source code processing method according to claim 1, wherein: The traversing the abstract syntax tree corresponding to the source code to determine the target string in the abstract syntax tree includes: Traverse the nodes in the abstract syntax tree corresponding to the source code to determine the current node; If the current node is a string constant node, performing a string extraction operation on the current node to obtain a corresponding target string; If the current node is not a string constant node, the process jumps to the step of traversing the nodes in the abstract syntax tree corresponding to the source code until all nodes in the abstract syntax tree have been traversed.

3. The source code processing method according to claim 1, wherein: The traversing of the abstract syntax tree corresponding to the source code includes: The target plug-in pre-set on the compiler is used to monitor the compiler's processing of the source code in real time, and when it is detected that the compiler constructs an abstract syntax tree corresponding to the source code, the abstract syntax tree is traversed.

4. The source code processing method according to claim 3, characterized in that: The step of replacing a corresponding target string in a GIMPLE statement using the index information during the GIMPLE phase of the compiler processing the source code to obtain a replaced statement includes: When it is detected that the compiler is in a GIMPLE phase in processing the source code, traversing GIMPLE statements corresponding to the source code in the GIMPLE phase to determine a current string; Determine whether the current character string corresponds to a character string constant, and obtain a corresponding determination result; If the judgment result indicates that the current character string is a character string corresponding to the character string constant, performing a replacement operation on the current character string using the corresponding index information; If the judgment result indicates that the current string is not a string corresponding to the string constant, the current string is ignored, and the process jumps to the step of traversing the GIMPLE statements corresponding to the source code in the GIMPLE stage; Until all the character strings in the GIMPLE statement have been traversed, a replacement statement after performing the relevant replacement operations is obtained.

5. The source code processing method according to any one of claims 1 to 4, characterized in that: Also includes: When the embedded device is running, based on a preset log format, the index information is used to generate log information corresponding to the source code, and the log information is stored in a preset log file so that relevant personnel can view the log information.

6. The source code processing method according to claim 5, characterized in that: The checking of the log information includes: Based on the viewing command issued for the log information, read the log information from the preset log file, and determine the mapping table corresponding to the log information; Based on the correspondence between the index information in the log information and the character strings in the mapping table, several original character strings corresponding to the log information are determined, and readable information is generated based on the several original character strings and the log information so as to view the readable information.

7. The source code processing method according to claim 6, characterized in that: After generating readable information based on the plurality of original character strings and the log information, the method further includes: sending the readable information to a remote console so that relevant personnel can view the readable information through the remote console; Alternatively, the readable information is stored in a designated location so that relevant personnel can read the designated location to view the readable information.

8. A source code processing device, characterized in that: Applications in embedded devices, including: a string determination module, configured to traverse an abstract syntax tree corresponding to a source code to determine a target string in the abstract syntax tree; the abstract syntax tree is an abstract syntax tree constructed by processing the source code through a compiler; a string replacement module, configured to assign index information to each target string, and, during the GIMPLE phase of the compiler processing the source code, to replace the corresponding target string in the GIMPLE statement using the index information to obtain a replaced statement; A compilation module is used to generate a mapping table based on the correspondence between the index information and the target character string, and compile the replaced statement into a corresponding binary file through the compiler to complete the processing of the source code.

9. An electronic device, characterized in that: include: memory for storing computer programs; A processor, configured to execute the computer program to implement the steps of the source code processing method according to any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, which, when executed by a processor, implements the steps of the source code processing method according to any one of claims 1 to 7.