Model-based FPGA code defect inspection result confidence analysis method and system
By using the abstract syntax tree and CodeBERT model in the FPGA code, combined with factors such as code structure and comments, the confidence of the defect inspection results is calculated, which solves the problem of high false positive rate in static defect inspection tools and improves the accuracy and accuracy of analysis. reliability.
Patent Information
- Application Number
- CN202410603627.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-15
- Publication Date
- 2024-09-17
- Estimated Expiration
- 2044-05-15
AI Technical Summary
Existing static defect inspection tools generate a large number of false positives in FPGA codes, reducing the practicality and actual use effect of the tools.
Generate the code tree structure of the FPGA code through abstract syntax tree (AST), obtain the static analysis defect inspection results, and set up the confidence analysis model. Combined with the influence of code structure, function, class and code annotation, use the CodeBERT model for fitting. Calculate the confidence level of defect inspection results.
It improves the accuracy of defect analysis and the reliability of model judgment, reduces the false alarm rate, and enhances the practicality of static defect inspection tools.
Smart Images

Figure CN118194286B
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of FPGA code optimization, and more specifically, relates to a model-based FPGA code defect inspection result confidence analysis method and system. Background Art
[0002] It is common in today's hardware design industry to use static defect checking tools (static defect checking tools include findbugs, pmd, checkstyle, eslint, sonarqube, resharper, etc.) to assist in discovering potential vulnerabilities and code specification issues in FPGA code. Static defect checking finds security risks and non-standard code in source design code without the need for compilation, and provides a list of defect results. Software developers use some open source tools or commercial tools to check the design code, and then audit the defect results generated by the tools. Although conventional static defect checking tools can find a large number of problems that are ultimately confirmed as actual defects, they will also generate a large number of false positives, which brings great trouble to developers. The generation of a large number of false positives reduces the practicality and actual use effect of static defect checking tools in practice. Summary of the invention
[0003] In order to solve the above technical problems, the present invention proposes a model-based FPGA code defect inspection result confidence analysis method, comprising:
[0004] Generate a code tree structure of the FPGA code through an abstract syntax tree AST, and obtain a static analysis defect inspection result of the FPGA code through a static defect inspection tool, find a node related to the static analysis defect inspection result in the code tree structure, traverse up or down along the node, and obtain a defect context related to the node;
[0005] Setting a confidence analysis model for defect inspection results, and calculating the confidence of the static analysis defect results according to the defect context, wherein the confidence analysis model for the defect inspection results includes: the influence of code structure, function, class and code annotation on confidence;
[0006] The confidence analysis model of the defect inspection result is fitted to generate a final confidence analysis model of the defect inspection result, and a confidence analysis of the defect inspection result is performed by static analysis.
[0007] Furthermore, the confidence analysis model of the defect inspection result includes:
[0008] ,
[0009] in, is the confidence level of the static analysis defect results, is the influence weight of the code structure, Code structure in the context of the defect The influence function on confidence, is the influence weight of the function, Function in the defect context The influence function on confidence, is the influence weight of the class, For the defect context class The influence function on confidence, is the influence weight of the code comment, Annotate code in context of bug The influence function on the confidence.
[0010] Furthermore, the code structure in the defect context Influence function on confidence include:
[0011] ,
[0012] in, For code structure The complexity weight of For code structure The complexity of For code structure The density weight, For code structure The density of For code structure The weight of the nesting depth, For code structure The nesting depth of .
[0013] Furthermore, the function in the defect context Influence function on confidence include:
[0014] ,
[0015] in, For function Number of lines of code in For function The complexity of For function The weight of the number of lines of code in For function The complexity weight of For function The number of variables in .
[0016] Furthermore, the defect context class Influence function on confidence include:
[0017] ,
[0018] in, For Class The weight of the number of lines of code in For Class Number of lines of code in For Class The complexity weight of For Class complexity.
[0019] Further, code comments in the defect context Influence function on confidence include:
[0020] ,
[0021] in, Commenting the code The grammatical accuracy of Commenting the code The number of Commenting the code the number of rows, Commenting the code The weight of the number of rows.
[0022] Furthermore, each weight is fitted by the least squares method.
[0023] Furthermore, the confidence analysis model of the defect inspection result is a CodeBERT model, and the confidence analysis model of the defect inspection result is trained by using correct historical defect results and corresponding historical defect contexts.
[0024] The present invention also proposes a model-based FPGA code defect inspection result confidence analysis system, comprising:
[0025] A context generation module is used to generate a code tree structure of the FPGA code through an abstract syntax tree AST, and obtain a static analysis defect inspection result of the FPGA code through a static defect inspection tool, find a node related to the static analysis defect inspection result in the code tree structure, traverse up or down along the node, and obtain a defect context related to the node;
[0026] A model setting module is used to set a confidence analysis model of defect inspection results, and calculate the confidence of the static analysis defect results according to the defect context, wherein the confidence analysis model of the defect inspection results includes: the influence of code structure, function, class and code annotation on confidence;
[0027] The confidence analysis module is used to fit the confidence analysis model of the defect inspection result, generate the final confidence analysis model of the defect inspection result, and perform static analysis on the confidence analysis of the defect inspection result.
[0028] Furthermore, the confidence analysis model of the defect inspection result includes:
[0029] ,
[0030] in, is the confidence level of the static analysis defect results, is the influence weight of the code structure, Code structure in the context of the defect The influence function on confidence, is the influence weight of the function, Function in the defect context The influence function on confidence, is the influence weight of the class, For the defect context class The influence function on confidence, is the influence weight of the code comment, Annotate code in context of bug The influence function on the confidence.
[0031] Compared with the prior art, the above technical solution conceived by the present invention has the following beneficial effects:
[0032] The AST-based defect context derivation method provided by the present invention can extract complete code slices for use in neural network training.
[0033] The neural network training method based on AST defect context and historical audit results provided by the present invention can provide a high-quality training set for the neural network model and improve the accuracy of model judgment.
[0034] The model-based defect analysis confidence analysis method provided by the present invention can comprehensively consider the accuracy of the defect analysis method itself and the accuracy of the model, thereby improving the reliability of the final confidence level. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] Figure 1 is a flow chart of the method of embodiment 1 of the present invention;
[0036] Figure 2 is a system structure diagram of Embodiment 2 of the present invention;
[0037] Figure 3 is a flow chart of the method of embodiment 5 of the present invention;
[0038] Figure 4 This is a flowchart of obtaining defect context based on AST in Embodiment 5 of the present invention;
[0039] Figure 5 This is a flowchart of using historical audit results to train the CodeBERT model in Example 5 of the present invention. DETAILED DESCRIPTION
[0040] In order to better understand the above technical solution, the above technical solution will be described in detail below in conjunction with the accompanying drawings and specific implementation methods.
[0041] The method provided by the present invention can be implemented in the following terminal environment, and the terminal may include one or more of the following components: a processor, a storage medium, and a display screen. The storage medium stores at least one instruction, and the instruction is loaded and executed by the processor to implement the method described in the following embodiment.
[0042] The processor may include one or more processing cores. The processor uses various interfaces and lines to connect various parts in the entire terminal, and executes various functions of the terminal and processes data by running or executing instructions, programs, code sets or instruction sets stored in the storage medium, and calling data stored in the storage medium.
[0043] The storage medium may include a random access memory (RAM) or a read-only memory (ROM). The storage medium may be used to store instructions, programs, codes, code sets or instructions.
[0044] The display is used to show the interactive cross-section of each application.
[0045] All subscripts in the formulas of the present invention are only used to distinguish parameters and have no actual meaning.
[0046] FPGA: Field Programmable Gate Array (FPGA) is developed based on the technology of PAL, GAL, CPLD and other programmable logic devices. As a semi-custom circuit in special application integrated circuits, it not only makes up for the shortcomings of full-custom circuits, but also overcomes the shortcomings of the limited number of logic gates of the original programmable logic controller.
[0047] AST: In computer science, an Abstract Syntax Tree (AST), or simply a syntax tree, is an abstract representation of the syntax structure of source code. It represents the syntax structure of a programming language in a tree-like form, with each node on the tree representing a structure in the source code. The reason why the syntax is "abstract" is that the syntax here does not represent every detail that appears in the real syntax. For example, nested parentheses are implied in the tree structure and are not presented in the form of nodes; and conditional jump statements such as if-condition-then can be represented using nodes with three branches.
[0048] In addition, those skilled in the art can understand that the structure of the above terminal does not constitute a limitation on the terminal, and the terminal may include more or fewer components, or combine certain components, or arrange the components differently. For example, the terminal also includes components such as a radio frequency circuit, an input unit, a sensor, an audio circuit, and a power supply, which will not be described in detail here.
[0049] Example 1
[0050] like Figure 1 As shown, an embodiment of the present invention provides a model-based FPGA code defect inspection result confidence analysis method, including:
[0051] Step 101, generating a code tree structure of the FPGA code through an abstract syntax tree AST, and obtaining a static analysis defect inspection result of the FPGA code through a static defect inspection tool, finding a node related to the static analysis defect inspection result in the code tree structure, traversing upward or downward along the node, and obtaining a defect context related to the node;
[0052] Step 102, setting a confidence analysis model for defect inspection results, and calculating the confidence of the static analysis defect results according to the defect context, wherein the confidence analysis model for the defect inspection results includes: the influence of code structure, function, class and code annotation on confidence;
[0053] Specifically, the confidence analysis model of the defect inspection result includes:
[0054] ,
[0055] in, is the confidence level of the static analysis defect results, is the influence weight of the code structure, Code structure in the context of the defect The influence function on confidence, is the influence weight of the function, Function in the defect context The influence function on confidence, is the influence weight of the class, For the defect context class The influence function on confidence, is the influence weight of the code comment, Annotate code in context of bug The influence function on the confidence.
[0056] Specifically, the code structure in the defect context Influence function on confidence include:
[0057] ,
[0058] in, For code structure The complexity weight of For code structure The complexity of For code structure The density weight, For code structure The density of For code structure The weight of the nesting depth, For code structure The nesting depth of .
[0059] Specifically, the function in the defect context Influence function on confidence include:
[0060] ,
[0061] in, For function Number of lines of code in For function The complexity of For function The weight of the number of lines of code in For function The complexity weight of For function The number of variables in .
[0062] Specifically, the defect context class Influence function on confidence include:
[0063] ,
[0064] in, For Class The weight of the number of lines of code in For Class Number of lines of code in For Class The complexity weight of For Class complexity.
[0065] Specifically, code comments in the defect context Influence function on confidence include:
[0066] ,
[0067] in, Commenting the code The grammatical accuracy of Commenting the code The number of Commenting the code the number of rows, Commenting the code The weight of the number of rows.
[0068] Specifically, the confidence analysis model of the defect inspection result may also be a CodeBERT model, and the confidence analysis model of the defect inspection result may be trained by using correct historical defect results and corresponding historical defect contexts.
[0069] Step 103, fitting the confidence analysis model of the defect inspection result, generating a final confidence analysis model of the defect inspection result, and performing a static analysis of the confidence analysis of the defect inspection result.
[0070] Specifically, each weight is fitted by the least square method, thereby completing the fitting of the confidence analysis model of the defect inspection result.
[0071] Example 2
[0072] like Figure 2 As shown, the embodiment of the present invention also proposes a model-based FPGA code defect inspection result confidence analysis system, including:
[0073] A context generation module is used to generate a code tree structure of the FPGA code through an abstract syntax tree AST, and obtain a static analysis defect inspection result of the FPGA code through a static defect inspection tool, find a node related to the static analysis defect inspection result in the code tree structure, traverse up or down along the node, and obtain a defect context related to the node;
[0074] A model setting module is used to set a confidence analysis model of defect inspection results, and calculate the confidence of the static analysis defect results according to the defect context, wherein the confidence analysis model of the defect inspection results includes: the influence of code structure, function, class and code annotation on confidence;
[0075] Specifically, the confidence analysis model of the defect inspection result includes:
[0076] ,
[0077] in, is the confidence level of the static analysis defect results, is the influence weight of the code structure, Code structure in the context of the defect The influence function on confidence, is the influence weight of the function, Function in the defect context The influence function on confidence, is the influence weight of the class, For the defect context class The influence function on confidence, is the influence weight of the code comment, Annotate code in context of bug The influence function on the confidence.
[0078] Specifically, the code structure in the defect context Influence function on confidence include:
[0079] ,
[0080] in, For code structure The complexity weight of For code structure The complexity of For code structure The density weight, For code structure The density of For code structure The weight of the nesting depth, For code structure The nesting depth of .
[0081] Specifically, the function in the defect context Influence function on confidence include:
[0082] ,
[0083] in, For function Number of lines of code in For function The complexity of For function The weight of the number of lines of code in For function The complexity weight of For function The number of variables in .
[0084] Specifically, the defect context class Influence function on confidence include:
[0085] ,
[0086] in, For Class The weight of the number of lines of code in For Class Number of lines of code in For Class The complexity weight of For Class complexity.
[0087] Specifically, code comments in the defect context Influence function on confidence include:
[0088] ,
[0089] in, Commenting the code The grammatical accuracy of Commenting the code The number of Commenting the code the number of rows, Commenting the code The weight of the number of rows.
[0090] Specifically, the confidence analysis model of the defect inspection result may also be a CodeBERT model, and the confidence analysis model of the defect inspection result may be trained by using correct historical defect results and corresponding historical defect contexts.
[0091] The confidence analysis module is used to fit the confidence analysis model of the defect inspection result, generate the final confidence analysis model of the defect inspection result, and perform static analysis on the confidence analysis of the defect inspection result.
[0092] Specifically, each weight is fitted by the least square method, thereby completing the fitting of the confidence analysis model of the defect inspection result.
[0093] Example 3
[0094] The embodiment of the present invention further provides a storage medium storing a plurality of instructions, wherein the instructions are used to implement the model-based FPGA code defect inspection result confidence analysis method.
[0095] Optionally, in this embodiment, the above storage medium may be located in any computer terminal in a computer terminal group in a computer network, or in any mobile terminal in a mobile terminal group.
[0096] Optionally, in this embodiment, the storage medium is configured to store program codes for executing the following steps: Step 101, generating a code tree structure of the FPGA code through an abstract syntax tree AST, and obtaining a static analysis defect inspection result of the FPGA code through a static defect inspection tool, finding a node related to the static analysis defect inspection result in the code tree structure, traversing upward or downward along the node, and obtaining a defect context related to the node;
[0097] Step 102, setting a confidence analysis model for defect inspection results, and calculating the confidence of the static analysis defect results according to the defect context, wherein the confidence analysis model for the defect inspection results includes: the influence of code structure, function, class and code annotation on confidence;
[0098] Specifically, the confidence analysis model of the defect inspection result includes:
[0099] ,
[0100] in, is the confidence level of the static analysis defect results, is the influence weight of the code structure, Code structure in the context of the defect The influence function on confidence, is the influence weight of the function, Function in the defect context The influence function on confidence, is the influence weight of the class, For the defect context class The influence function on confidence, is the influence weight of the code comment, Annotate code in context of bug The influence function on the confidence.
[0101] Specifically, the code structure in the defect context Influence function on confidence include:
[0102] ,
[0103] in, For code structure The complexity weight of For code structure The complexity of For code structure The density weight, For code structure The density of For code structure The weight of the nesting depth, For code structure The nesting depth of .
[0104] Specifically, the function in the defect context Influence function on confidence include:
[0105] ,
[0106] in, For function Number of lines of code in For function The complexity of For function The weight of the number of lines of code in For function The complexity weight of For function The number of variables in .
[0107] Specifically, the defect context class Influence function on confidence include:
[0108] ,
[0109] in, For Class The weight of the number of lines of code in For Class Number of lines of code in For Class The complexity weight of For Class complexity.
[0110] Specifically, code comments in the defect context Influence function on confidence include:
[0111] ,
[0112] in, Commenting the code The grammatical accuracy of Commenting the code The number of Commenting the code the number of rows, Commenting the code The weight of the number of rows.
[0113] Specifically, the confidence analysis model of the defect inspection result may also be a CodeBERT model, and the confidence analysis model of the defect inspection result may be trained by using correct historical defect results and corresponding historical defect contexts.
[0114] Step 103, fitting the confidence analysis model of the defect inspection result, generating a final confidence analysis model of the defect inspection result, and performing a static analysis of the confidence analysis of the defect inspection result.
[0115] Specifically, each weight is fitted by the least square method, thereby completing the fitting of the confidence analysis model of the defect inspection result.
[0116] Example 4
[0117] An embodiment of the present invention also proposes an electronic device, including a processor and a storage medium connected to the processor, wherein the storage medium stores multiple instructions, and the instructions can be loaded and executed by the processor to enable the processor to execute a model-based FPGA code defect inspection result confidence analysis method.
[0118] Specifically, the electronic device of this embodiment may be a computer terminal, and the computer terminal may include: one or more processors, and a storage medium.
[0119] Among them, the storage medium can be used to store software programs and modules, such as a model-based FPGA code defect inspection result confidence analysis method in an embodiment of the present invention, and the corresponding program instructions / modules. The processor executes various functional applications and data processing by running the software programs and modules stored in the storage medium, that is, realizing the above-mentioned model-based FPGA code defect inspection result confidence analysis method. The storage medium may include a high-speed random storage medium, and may also include a non-volatile storage medium, such as one or more magnetic storage systems, flash memory, or other non-volatile solid-state storage media. In some instances, the storage medium may further include a storage medium remotely arranged relative to the processor, and these remote storage media may be connected to the terminal via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0120] The processor may call the information and application stored in the storage medium through the transmission system to execute the following steps: Step 101, generate a code tree structure of the FPGA code through an abstract syntax tree AST, obtain a static analysis defect inspection result of the FPGA code through a static defect inspection tool, find a node related to the static analysis defect inspection result in the code tree structure, traverse upward or downward along the node, and obtain a defect context related to the node;
[0121] Step 102, setting a confidence analysis model for defect inspection results, and calculating the confidence of the static analysis defect results according to the defect context, wherein the confidence analysis model for the defect inspection results includes: the influence of code structure, function, class and code annotation on confidence;
[0122] Specifically, the confidence analysis model of the defect inspection result includes:
[0123]
[0124] in, is the confidence level of the static analysis defect results, is the influence weight of the code structure, Code structure in the context of the defect The influence function on confidence, is the influence weight of the function, Function in the defect context The influence function on confidence, is the influence weight of the class, For the defect context class The influence function on confidence, is the influence weight of the code comment, Annotate code in context of bug The influence function on the confidence.
[0125] Specifically, the code structure in the defect context Influence function on confidence include:
[0126] ,
[0127] in, For code structure The complexity weight of For code structure The complexity of For code structure The density weight, For code structure The density of For code structure The weight of the nesting depth, For code structure The nesting depth of .
[0128] Specifically, the function in the defect context Influence function on confidence include:
[0129] ,
[0130] in, For function Number of lines of code in For function The complexity of For function The weight of the number of lines of code in For function The complexity weight of For function The number of variables in .
[0131] Specifically, the defect context class Influence function on confidence include:
[0132] ,
[0133] in, For Class The weight of the number of lines of code in For Class Number of lines of code in For Class The complexity weight of For Class complexity.
[0134] Specifically, code comments in the defect context Influence function on confidence include:
[0135] ,
[0136] in, Commenting the code The grammatical accuracy of Commenting the code The number of Commenting the code the number of rows, Commenting the code The weight of the number of rows.
[0137] Specifically, the confidence analysis model of the defect inspection result may also be a CodeBERT model, and the confidence analysis model of the defect inspection result may be trained by using correct historical defect results and corresponding historical defect contexts.
[0138] Step 103, fitting the confidence analysis model of the defect inspection result, generating a final confidence analysis model of the defect inspection result, and performing a static analysis of the confidence analysis of the defect inspection result.
[0139] Specifically, each weight is fitted by the least square method, thereby completing the fitting of the confidence analysis model of the defect inspection result.
[0140] Example 5
[0141] like Figure 3 As shown, the present invention provides a model-based FPGA code defect inspection result confidence analysis method to solve the problem that the existing static defect analysis is affected by a large number of false positives, resulting in poor actual use effect of the tool.
[0142] This method requires static analysis of defect results and defect context as required inputs, and the initial confidence based on the defect analysis method as optional input. The trained neural network model is used to perform binary classification on the defects and context, and the confidence of the defect is calculated.
[0143] Defect analysis results: Defect analysis results come from the FPGA static defect inspection tool. Each defect in the defect analysis results can be considered as the FPGA defect inspection tool's judgment result for this defect being true, so its confidence is the baseline confidence of the analysis method used by this defect inspection rule. The baseline confidence can be high or low based on different analysis methods. For example, the confidence of using structural analysis is lower than that of using formal analysis. The setting of the baseline confidence is mainly based on the analysis method and the specific defect inspection rule implementation.
[0144] Obtaining defect context: The defect report location of FPGA static defect inspection tools is generally at the location where the core problem of the defect occurs, lacking context information. In many cases, it is difficult to analyze based only on the code at the error location. Whether from the perspective of generating training sets to train neural network models or from the perspective of improving model judgment accuracy, it is necessary to obtain the context of the defect. Defect context acquisition needs to be based on AST.
[0145] like Figure 4 As shown, the process of obtaining defect context based on AST is as follows:
[0146] Statement left value and right value: In a statement such as assign a = b + c;, the left value is a, and the right value is b and c. Generally, the left value is assigned the right value, so the defect of the left value is related to the right value. When obtaining the context, all dependencies must be obtained, so recursive analysis based on the right value of the statement is required.
[0147] Arrange all statements: Considering that the order of statements is inconsistent with their order in the code file, when the defect context is finally formed, they should be rearranged based on their order in the source code file to ensure consistency.
[0148] Neural network model: Considering that the object is FPGA defect code and context, the BERT model is selected for binary classification task training. The general BERT model needs to be pre-trained in the object language to understand the semantics, but since the detection object is FPGA design code, CodeBERT can save the cost of pre-training.
[0149] The training set uses historical defects that have collected defect context information and have audit results. After traditional static defect analysis tools report defect results, manual audits are required to confirm whether the defects are valid and mark them as confirmed or false positives. The main purpose of the audit is to automatically ignore defects marked as false positives when exporting reports to ensure the accuracy of the reports. Such historical audit results can be used to train the CodeBERT model because they have already marked polarity. It only needs to extract the defect context and organize the format for training.
[0150] like Figure 5 As shown in the figure, the process of training the CodeBERT model using historical audit results is as follows:
[0151] Pre-training: BERT's pre-training tasks mainly include two types: Masked Language Model (MLM) and Next Sentence Prediction (NSP). These two pre-training tasks can help the model understand the semantics of the corresponding language. The CodeBERT model is a pre-trained model for programming languages, so choosing the CodeBERT model can save the cost of pre-training.
[0152] Confidence calculation method: When the model output is true, it means that the model judgment result is consistent with the static defect analysis result, so the confidence calculation formula is:
[0153] Confidence = (baseline confidence + model reliability * model dependence coefficient) * 100%
[0154] When the model output is false, it means that the model judgment result is opposite to the static defect analysis result, so the confidence calculation formula is:
[0155] Confidence = (baseline confidence - model reliability * model dependence coefficient) * 100%
[0156] Baseline confidence: Different defect inspection rules use different defect analysis methods. Based on the reliability of the methods, different rules will have different baseline confidences.
[0157] Model reliability: that is, the accuracy obtained by testing the test set after the model training is completed.
[0158] Model dependence coefficient: that is, 1-reference confidence.
[0159] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.
[0160] In the above embodiments of the present invention, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0161] In the several embodiments provided by the present invention, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the system embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.
[0162] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0163] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0164] If the integrated unit is implemented in the form of 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 solution of the present invention, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, read-only storage medium (ROM, Read-Only Memory), random access storage medium (RAM, Random Access Memory), mobile hard disk, magnetic disk or optical disk and other media that can store program codes.
[0165] Obviously, the above embodiments are merely examples for the purpose of clear explanation, and are not intended to limit the implementation methods. For those skilled in the art, other different forms of changes or modifications can be made based on the above description. It is not necessary and impossible to list all the implementation methods here. The obvious changes or modifications derived therefrom are still within the scope of protection of the invention.
Claims
1. A model-based FPGA code defect inspection result confidence analysis method, characterized in that: include: Generate a code tree structure of the FPGA code through an abstract syntax tree AST, and obtain a static analysis defect inspection result of the FPGA code through a static defect inspection tool, find a node related to the static analysis defect inspection result in the code tree structure, traverse up or down along the node, and obtain a defect context related to the node; Setting a confidence analysis model for defect inspection results, and calculating the confidence of the static analysis defect results according to the defect context, wherein the confidence analysis model for the defect inspection results includes: the influence of code structure, function, class and code annotation on confidence; Wherein, the confidence analysis model of the defect inspection result includes: , in, is the confidence level of the static analysis defect results, is the influence weight of the code structure, Code structure in the context of the defect The influence function on confidence, is the influence weight of the function, Function in the defect context The influence function on the confidence level, is the influence weight of the class, For the defect context class The influence function on confidence, is the influence weight of the code comment, Annotate code in context of bug The influence function on confidence; Code structure in the context of the defect Influence function on confidence include: , in, For code structure The complexity weight of For code structure The complexity of For code structure The density weight, For code structure The density of For code structure The weight of the nesting depth, For code structure The nesting depth of Function in defect context Influence function on confidence include: , in, For function Number of lines of code in For function The complexity of For function The weight of the number of lines of code in For function The complexity weight of For function The number of variables in Defect context class Influence function on confidence include: , in, For Class The weight of the number of lines of code in For Class Number of lines of code in For Class The complexity weight of For Class complexity; Code comments in the context of the defect Influence function on confidence include: , in, Commenting the code The grammatical accuracy of Commenting the code The number of Commenting the code the number of rows, Commenting the code The weight of the number of rows; The confidence analysis model of the defect inspection result is fitted to generate a final confidence analysis model of the defect inspection result, and a confidence analysis of the defect inspection result is performed by static analysis.
2. A model-based FPGA code defect inspection result confidence analysis method as claimed in claim 1, characterized in that: Each weight is fitted by the least squares method.
3. The method for analyzing the confidence of FPGA code defect inspection results based on a model as claimed in claim 1, characterized in that: The confidence analysis model of the defect inspection result is a CodeBERT model, and the confidence analysis model of the defect inspection result is trained by using correct historical defect results and corresponding historical defect contexts.
4. A model-based FPGA code defect inspection result confidence analysis system, characterized in that: include: A context generation module is used to generate a code tree structure of the FPGA code through an abstract syntax tree AST, and obtain a static analysis defect inspection result of the FPGA code through a static defect inspection tool, find a node related to the static analysis defect inspection result in the code tree structure, traverse up or down along the node, and obtain a defect context related to the node; A model setting module is used to set a confidence analysis model of defect inspection results, and calculate the confidence of the static analysis defect results according to the defect context, wherein the confidence analysis model of the defect inspection results includes: the influence of code structure, function, class and code annotation on confidence; Wherein, the confidence analysis model of the defect inspection result includes: , in, is the confidence level of the static analysis defect results, is the influence weight of the code structure, Code structure in the context of the defect The influence function on confidence, is the influence weight of the function, Function in the defect context The influence function on confidence, is the influence weight of the class, For the defect context class The influence function on confidence, is the influence weight of the code comment, Annotate code in context of bug The influence function on confidence; Code structure in the context of the defect Influence function on confidence include: , in, For code structure The complexity weight of For code structure The complexity of For code structure The density weight, For code structure The density of For code structure The weight of the nesting depth, For code structure The nesting depth of Function in defect context Influence function on confidence include: , in, For function Number of lines of code in For function The complexity of For function The weight of the number of lines of code in For function The complexity weight of For function The number of variables in Defect context class Influence function on confidence include: , in, For Class The weight of the number of lines of code in For Class Number of lines of code in For Class The complexity weight of For Class complexity; Code comments in the context of the defect Influence function on confidence include: , in, Commenting the code The grammatical accuracy of Commenting the code The number of Commenting the code the number of rows, Commenting the code The weight of the number of rows; The confidence analysis module is used to fit the confidence analysis model of the defect inspection result, generate the final confidence analysis model of the defect inspection result, and perform static analysis on the confidence analysis of the defect inspection result.
Citation Information
Patent Citations
Automated intelligent contract code defect detection system and method
CN109063477A
FPGA / IP core code rule checking method based on association rules
CN109086202A
Source code defect detection method and device
CN112579469A
Software defect prediction method based on multi-dimensional code joint graph representation
CN117215935A
Code inspection executing system for performing a code inspection of ABAP source codes
US20130014093A1
