Module numbering method based on incremental compilation, electronic device, and medium
Patent Information
- Application Number
- CN202611391987.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-09-09
- Publication Date
- 2026-10-13
AI Technical Summary
[0015]本发明通过建立模块的唯一标识与编号之间的持久化映射关系,使编号分配不再依赖于编译顺序,而是以模块自身固有的唯一标识为依据,由于该标识在多次编译之间保持不变,已存在的模块始终能够获得与其历史编译相同的编号,从根本上保证了模块编号的稳定性。存储于编译结果中的编号因此无需变更,已编译的编译结果可以被安全复用,从而避免因编号变化引发的大量不必要的重编译,显著提高了增量编译的复用率和编译效率。同时,该方案实现简单,仅需通过唯一标识查询映射关系即可完成编号分配,且编号相比于冗长的唯一标识具有更短的存储长度和更快的比较速度,能够提升运行时的模块定位效率。
Smart Images

Figure CN122902973A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of hardware description language compiler technology, and in particular to a module numbering method, electronic device, and medium based on incremental compilation. Background Technology
[0002] In incremental compilation scenarios using hardware description language compilers, certain business scenarios during program runtime require locating specific modules. For example, debugging, performance analysis, and error localization all necessitate quickly and accurately identifying the target module. Therefore, each module is typically assigned a number during compilation, replacing lengthy unique identifiers. This allows for rapid location of the specific module relevant to the business scenario at runtime. These module numbers are usually determined during the compilation phase and stored in the compilation results. Typically, the compiler assigns module numbers based on the input order of the compiled files and the order in which modules appear within a single file. Specifically, numbers can be assigned sequentially, starting from 0 and incrementing accordingly. Existing numbering schemes are simple to implement and efficient, requiring only a single sequential traversal to number all modules, effectively meeting the module localization needs of typical compilation scenarios.
[0003] However, the aforementioned sequential numbering scheme has significant drawbacks in incremental compilation scenarios. The core idea of incremental compilation is to reuse the results of the previous compilation to avoid recompiling unchanged modules, thereby shortening compilation time. This requires module numbers to remain stable across multiple compilations. However, with the traditional sequential numbering scheme, when a user modifies the design between compilations—whether adding or deleting modules, or adjusting the input order of compilation files or the arrangement of modules within the file—the order of many modules changes, consequently altering their numbers. Since module numbers are stored in the compilation results, a change in number means that previously reusable compilation results will become unusable due to number mismatches, triggering numerous unnecessary recompilations and severely reducing the reusability and efficiency of incremental compilation. Therefore, ensuring the stability of module numbers across multiple compilations in incremental compilation scenarios to improve module reusability and reduce recompilation rates has become a pressing technical problem. Summary of the Invention
[0004] The purpose of this invention is to provide a module numbering method, electronic device, and medium based on incremental compilation, which ensures the stability of the numbering across multiple compilations in incremental compilation scenarios, improves the module reuse rate, and reduces the recompilation rate.
[0005] According to a first aspect of the present invention, a module numbering method based on incremental compilation, an electronic device, and a medium are provided, comprising:
[0006] Establish a mapping database, which is used to store the correspondence between the unique identifier of a module and its module number;
[0007] During the initial compilation, module numbers are assigned to each module according to the preset compilation order. The mapping relationship between the unique identifier of each module and the corresponding assigned module number is stored in the mapping database, and the maximum number value currently assigned is recorded.
[0008] During non-initial compilations, the mapping database is loaded, and the modules involved in the current compilation are traversed. For each traversed module, the following operations are performed:
[0009] Use the unique identifier of this module as the key to query whether a corresponding historical module number exists in the mapping database;
[0010] If it exists, the historical module number is assigned to that module;
[0011] If it does not exist, assign a number to the module and update the mapping relationship between the module's unique identifier and the number to the mapping database.
[0012] According to a second aspect of the present invention, an electronic device is provided, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, the instructions being configured to perform the method described in the first aspect of the present invention.
[0013] According to a third aspect of the present invention, a computer-readable storage medium is provided, storing computer-executable instructions for performing the method described in the first aspect of the present invention.
[0014] Compared with existing technologies, this invention has significant advantages and beneficial effects. Through the above technical solution, the module numbering method, electronic device, and medium provided by this invention based on incremental compilation achieve considerable technological advancement and practicality, and have broad industrial application value. It has at least the following beneficial effects:
[0015] This invention establishes a persistent mapping between a module's unique identifier and its assigned number. This eliminates the dependency on compilation order in number allocation, instead basing it on the module's inherent unique identifier. Since this identifier remains unchanged across multiple compilations, existing modules always receive the same number as their historical compilations, fundamentally ensuring the stability of module numbering. The number stored in the compilation result therefore does not need to be changed, and already compiled results can be safely reused. This avoids numerous unnecessary recompilations caused by number changes, significantly improving the reusability and efficiency of incremental compilation. Furthermore, this scheme is simple to implement, requiring only a lookup of the mapping relationship using the unique identifier to complete number allocation. Compared to lengthy unique identifiers, the assigned number has a shorter storage length and faster comparison speed, improving runtime module location efficiency. Attached Figure Description
[0016] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0017] Figure 1 A flowchart of a module numbering method based on incremental compilation provided in an embodiment of the present invention;
[0018] Figure 2 This is a schematic diagram of the electronic device structure provided in an embodiment of the present invention;
[0019] Figure 3 This is a schematic diagram of a computer-readable storage medium structure provided in an embodiment of the present invention. Detailed Implementation
[0020] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0021] This invention provides a module numbering method based on incremental compilation, such as... Figure 1 As shown, it includes:
[0022] Step S1: Establish a mapping database, which is used to store the correspondence between the unique identifier of a module and the module number.
[0023] It should be noted that the mapping database refers to a data storage area used to store the correspondence between the unique identifier of a module and its module number. Its physical form can be a file, a lightweight database, or other data structure with persistent storage capabilities, and is not limited to a specific type of database system. The module number refers to the identifier assigned to each module, used for indexing and locating the module during compilation and runtime. The storage length of the number is much shorter than that of the globally unique name.
[0024] Step S2: During the initial compilation, assign module numbers to each module according to the preset compilation order, store the mapping relationship between the unique identifier of each module and the corresponding assigned module number in the mapping database, and record the maximum number value currently assigned.
[0025] It should be noted that the initial compilation refers to the first full compilation performed for the current design project, at which point the mapping database contains no historical data. The preset compilation order is the input order of the compilation files and the order in which modules appear in a single file; the compiler processes each module sequentially according to this order. The currently assigned maximum module number refers to the maximum value among all module numbers assigned during this compilation process.
[0026] Step S3: When not compiling for the first time, load the mapping database, traverse the modules involved in the current compilation, and for each traversed module, perform the following operations: use the module's unique identifier as the key to query whether there is a corresponding historical module number in the mapping database; if it exists, assign the historical module number to the module; if it does not exist, assign a number to the module and update the mapping relationship between the module's unique identifier and the number to the mapping database.
[0027] It should be noted that "non-initial compilation" refers to any compilation performed after the initial compilation, including incremental compilation scenarios. The modules involved in the current compilation refer to the set of modules that need to be processed during this compilation process. This set includes newly added modules, modified modules, and modules that, although unchanged, need to be identified by their dependency relationships, etc. Historical module numbers refer to the numbers that have been assigned to the module in previous compilations and are stored in the mapping database.
[0028] Steps S1-S3 establish a persistent mapping between the module's unique identifier and its number, ensuring that number allocation is no longer dependent on the compilation order but based on the module's inherent unique identifier. Since this identifier remains unchanged across multiple compilations, existing modules always receive the same number as their historical compilations, fundamentally guaranteeing the stability of module numbers. The number stored in the compilation result therefore does not need to be changed, and already compiled results can be safely reused, avoiding numerous unnecessary recompilations caused by number changes and significantly improving the reuse rate and compilation efficiency of incremental compilation. Furthermore, the storage length of the number is much shorter than that of the globally unique name, and comparisons between numbers are numerical comparisons, which are more efficient than string comparisons, significantly improving module location efficiency during compilation and runtime.
[0029] In step S3, assigning a number to each newly added module encountered during the traversal can be achieved through the following two implementation methods:
[0030] Implementation Method 1
[0031] As one embodiment, in step S3, assigning a number to the module includes:
[0032] Step S31: For each newly added module that needs to be assigned a number, perform the following operations in sequence: obtain the current maximum number value M, assign M+1 as the number to the newly added module, and update the maximum number value to M+1.
[0033] It should be noted that step S31 defines the first specific implementation method for assigning numbers to each newly added module that needs to be assigned a number. Each newly added module that needs to be assigned a number refers to a module determined to have no historical module number. Sequential execution indicates that for multiple newly added modules, number assignment is performed one by one according to the traversal order. The current maximum number value M is obtained, where M is the maximum number value recorded in the mapping database when assigning the current newly added module. This value is dynamically updated as the newly added modules are assigned sequentially. Assigning M+1 as the number to the current newly added module clarifies the increment rule, that is, the newly added module always obtains a number by adding 1 to the current maximum number. Updating the maximum number value to M+1 ensures that subsequent newly added modules can continue to increment based on the updated maximum value. In this method, the numbers of deleted modules are not reused, the already assigned maximum number value continues to increment unidirectionally, and the newly added module always obtains a new number larger than any historical number.
[0034] Implementation method one adopts a simple and direct numbering method. New modules are added sequentially from the current maximum number, which ensures the continuity of the numbering and the efficiency of the allocation process. There is no need to maintain a complex data structure. Only one variable is needed to record the current maximum value to complete the numbering of all new modules. It is suitable for application scenarios with high requirements for implementation simplicity and infrequent addition and deletion of modules.
[0035] Implementation Method 2
[0036] As one embodiment, in step S3, assigning a number to the module includes:
[0037] Step C31: Traverse the modules that appear in the current compilation, identify the modules that exist in the mapping database but do not appear in the current compilation as deleted modules, and mark the module number corresponding to the deleted module as an empty number.
[0038] Step C32: For each newly added module that needs to be assigned a number, obtain the number vacancy and assign the number vacancy to the currently added module.
[0039] It should be noted that steps C31-C32 define a second specific implementation method for assigning numbers to newly added modules that need to be assigned numbers, namely, the insertion strategy. The modules appearing in the current compilation refer to all modules actually existing in this compilation. When using the insertion strategy in step C31, the modules appearing in the current compilation are first traversed, and modules that exist in the mapping database but do not appear in the current compilation are identified as deleted modules. This identification method is applicable to scenarios where modules are deleted during incremental compilation. When a module exists in a historical compilation but no longer appears in the current compilation, it can be determined that the module has been deleted, and its previously occupied number is no longer used by any module, becoming a number vacancy that can be reused by subsequently added modules. Step C32 ensures that newly added modules have priority in obtaining the released number vacancy.
[0040] Implementation method two, while ensuring the stability of the numbering, further introduces a numbering slot reuse mechanism. By reallocating the numbering slots released by deleted modules to newly added modules, the problem of unlimited expansion of module numbers with increasing compilation counts is effectively suppressed, keeping the numbering values compact at all times.
[0041] As an example, based on implementation method two, step S3, which involves assigning a number to the module, further includes: step C10, storing all the number vacancy slots in a vacancy queue, and when there is a new module that needs to be assigned a number, taking a number vacancy slot from the vacancy queue and assigning it to the new module.
[0042] It should be noted that step C10 further defines the specific implementation of the insertion strategy. The empty slot queue refers to a data structure used to store numbered empty slots. The numbered empty slots in this queue originate from the numbers released by the deleted modules marked in step C31. Storing all numbered empty slots in the empty slot queue centrally manages the scattered numbered empty slots. Priority indicates that the usage priority of numbered empty slots is higher than the allocation from the maximum number value onwards; that is, as long as there are available empty slots in the empty slot queue, the new module first obtains a number from the queue.
[0043] Step C10 centrally manages numbered vacant spaces through a vacant space queue, making the storage and allocation process of numbered vacant spaces more orderly and efficient. The explicit strategy of prioritizing the use of vacant spaces ensures the priority of number reuse and minimizes number expansion.
[0044] As one embodiment, the numbered empty slots in the empty slot queue are arranged in ascending order of numerical value. In step C10, the step of preferentially retrieving numbered empty slots from the empty slot queue includes:
[0045] Step C101: Take the empty slot with the smallest number from the empty slot queue and assign it to the newly added module, and then delete the empty slot from the empty slot queue.
[0046] Step C102: If the empty queue is empty, then allocate a new module number incrementally after the maximum number value.
[0047] It should be noted that steps C101-C102 further refine the management of the empty slot queue and the empty slot allocation strategy. The numbering of empty slots in the empty slot queue in ascending order defines the queue's ordered nature. Allocating the smallest available slot from the queue to the newly added module clarifies the allocation strategy: always assigning the smallest available slot helps maintain a compact numbering space. If the empty slot queue is empty, the allocation of new module numbers incrementally from the largest number provides a fallback mechanism. When no available slots are available, the allocation reverts to incrementally assigning numbers from the largest number, ensuring that the newly added module can obtain a number under any circumstances.
[0048] The scheme described in steps C101-C102 maintains the most compact numbering space by arranging the empty slot queue in ascending order of numerical value and always allocating the smallest available slot, thus avoiding numbering fragmentation. Simultaneously, the rollback mechanism ensures that numbering allocation can be completed smoothly under any circumstances, enhancing the robustness of the scheme.
[0049] As one embodiment, the module is the smallest compilation unit in a hardware description language compiler, and the smallest compilation unit is a design unit that can be independently declared at the top level of the compilation unit.
[0050] It should be noted that the smallest compilation unit in a hardware description language compiler defines a module as the smallest processing granularity during compilation. Design units that can be independently declared at the top level of the compilation unit further clarify the technical characteristics of this smallest compilation unit, namely, a syntactic structure that can exist and be declared independently within the top-level scope of the compilation unit. For example, in the SystemVerilog compiler, such design units include module, interface, program, and package; other hardware description languages also have corresponding design unit concepts, which will not be elaborated upon here.
[0051] As one embodiment, the unique identifier of the module is its globally unique name. It should be noted that a globally unique name refers to a name that can uniquely identify a module throughout the entire design project. Hardware description language compilers typically employ a hierarchical naming convention, such as including the complete instantiation path of the module from the top-level design (e.g., Top.Sub), ensuring that modules with the same name at different levels or in different files can be distinguished. This name is determined by the module's position in the design. Unlike a number, the name is an inherent, user-oriented identifier for the module and does not change between multiple compilations. A number, on the other hand, is an identifier assigned by the compiler for efficient indexing and can change due to changes in the compilation order in traditional schemes. The above definition clearly states that the unique identifier of a module is its globally unique name, which remains unchanged across multiple compilations, providing a fundamental guarantee for the stability of the numbering.
[0052] As one embodiment, the method further includes:
[0053] Step S10: In the initial compilation, the compilation result files generated by each module are associated with and stored with the corresponding module number.
[0054] Step S20: In non-initial compilation, if the current module is assigned a historical module number and does not need to be recompiled, then the associated compilation result file is obtained and reused according to the historical module number; if the current module is assigned a historical module number but needs to be recompiled, then a new compilation result file is generated and replaced with the compilation result file associated with the historical module number; if the current module is assigned a new module number, then a new compilation result file is generated and stored in association with the new module number.
[0055] It should be noted that steps S10-S20 define the association and reuse mechanism between module numbers and compilation result files. A compilation result file refers to the object file (e.g., a .o file) generated after a module is compiled, which stores the compilation results of that module. Associating the compilation result files generated by each module with their corresponding module numbers establishes a correspondence between the numbers and the compilation result files, allowing the corresponding compilation result file to be indexed by its number. In non-initial compilations, three scenarios are distinguished: Scenario 1: The current module is assigned a historical module number and does not need to be recompiled (i.e., the module content has not changed), in which case the associated historical compilation result file is directly obtained and reused based on the number. Scenario 2: The current module is assigned a historical module number but needs to be recompiled (i.e., the module content has changed), in which case a new compilation result file is generated to replace the historical compilation result file associated with that number, while the number remains unchanged and the file content is updated. Scenario 3: The current module is assigned a new module number (i.e., a new module is added), in which case a new compilation result file is generated and associated with that new module number.
[0056] The solution in steps S10-S20 establishes a relationship between the number and the compilation result file, directly converting the stability of the number into the reusability of the compilation result. If the number remains unchanged, the compilation result can be safely reused; if the number changes, it must be recompiled. This solution clarifies the core role of the number as an index for the compilation result, extending the technical solution of this invention from ensuring number stability to improving compilation efficiency with stable numbers, forming a complete technical closed loop. Simultaneously, the coverage of scenarios where the number remains unchanged but the content changes ensures that even if a module needs to be recompiled, its number remains unchanged, avoiding changes in the number due to recompilation that could affect the reuse of other modules, further guaranteeing the overall efficiency of incremental compilation.
[0057] It should be noted that some exemplary embodiments are described as processes or methods depicted as flowcharts. Although the flowcharts describe the steps as sequential processes, many of these steps can be performed in parallel, concurrently, or simultaneously. Furthermore, the order of the steps can be rearranged. A process can be terminated when its operation is complete, but it may also have additional steps not included in the figures. A process can correspond to a method, function, procedure, subroutine, subroutine, etc.
[0058] This invention also provides an electronic device, such as... Figure 2 As shown, it includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, the instructions being configured to perform the method described in the embodiments of the present invention.
[0059] For example, the electronic device may be a mobile electronic device or a non-mobile electronic device. Further, a mobile electronic device may be any one of a mobile phone, tablet computer, laptop computer, PDA, in-vehicle electronic device, wearable device, ultra-mobile personal computer (UMPC), netbook, or personal digital assistant (PDA); a non-mobile electronic device includes any one of a server, network attached storage (NAS), personal computer (PC), television (TV), ATM, or self-service machine.
[0060] This invention also provides a computer-readable storage medium, such as... Figure 3 As shown, computer-executable instructions are stored thereon, which are used to execute the methods described in the embodiments of the present invention.
[0061] Examples of computer-readable storage media include: computer read-only memory (ROM), random access memory (RAM), erasable programmable read-only memory (EPROM), compact disc read-only memory (CD-ROM), flash memory, magnetic disk, optical disk, portable computer disk, hard disk and / or solid-state drive, etc.
[0062] The above description is merely a preferred embodiment of the present invention and is not intended to limit the present invention in any way. Although the present invention has been disclosed above with reference to preferred embodiments, it is not intended to limit the present invention. Any person skilled in the art can make some modifications or alterations to the above-disclosed technical content to create equivalent embodiments without departing from the scope of the present invention. Any simple modifications, equivalent changes, and alterations made to the above embodiments based on the technical essence of the present invention without departing from the scope of the present invention shall still fall within the scope of the present invention.
Claims
1. A module numbering method based on incremental compilation, characterized in that, include: Establish a mapping database, which is used to store the correspondence between the unique identifier of a module and its module number; During the initial compilation, module numbers are assigned to each module according to the preset compilation order. The mapping relationship between the unique identifier of each module and the corresponding assigned module number is stored in the mapping database, and the maximum number value currently assigned is recorded. During non-initial compilations, the mapping database is loaded, and the modules involved in the current compilation are traversed. For each traversed module, the following operations are performed: Use the unique identifier of this module as the key to query whether a corresponding historical module number exists in the mapping database; If it exists, the historical module number is assigned to that module; If it does not exist, assign a number to the module and update the mapping relationship between the module's unique identifier and the number to the mapping database.
2. The method according to claim 1, characterized in that, Assigning a number to the module includes: for each newly added module that needs to be assigned a number, performing the following operations in sequence: obtaining the current maximum number value M, assigning M+1 as the number to the newly added module, and updating the maximum number value to M+1.
3. The method according to claim 1, characterized in that, The assignment of a number to this module includes: Traverse the modules that appear in the current compilation, identify the modules that exist in the mapping database but do not appear in the current compilation as deleted modules, and mark the module numbers corresponding to the deleted modules as empty slots; For each newly added module that needs to be assigned a number, obtain the number vacancy and assign the number vacancy to the newly added module.
4. The method according to claim 3, characterized in that, It also includes: storing all the numbered vacant slots into a vacant slot queue, and when there is a new module that needs to be assigned a number, taking the numbered vacant slot from the vacant slot queue first and assigning it to the new module.
5. The method according to claim 4, characterized in that, The empty slots in the empty slot queue are arranged in ascending order of their numerical values. The step of prioritizing the removal of an empty slot from the empty slot queue is as follows: the empty slot with the smallest numerical value is taken from the empty slot queue and assigned to the newly added module, and that empty slot is deleted from the empty slot queue; if the empty slot queue is empty, new module numbers are assigned incrementally from the largest number value.
6. The method according to claim 1, characterized in that, The module is the smallest compilation unit in a hardware description language compiler, and the smallest compilation unit is a design unit that can be independently declared at the top level of the compilation unit.
7. The method according to claim 1, characterized in that, The unique identifier of the module is its globally unique name.
8. The method according to claim 1, characterized in that, During the initial compilation, the compiled result files generated by each module are associated with and stored along with their corresponding module numbers. During subsequent compilations, if the current module is assigned a historical module number and does not require recompilation, the associated compiled result file is obtained and reused based on the historical module number. If the current module is assigned a historical module number but requires recompilation, a new compiled result file is generated and replaced with the compiled result file associated with the historical module number. If the current module is assigned a new module number, a new compiled result file is generated and associated with the new module number.
9. An electronic device, characterized in that, include: At least one processor; And, a memory communicatively connected to the at least one processor; The memory stores instructions that are executed by the at least one processor, the instructions being configured to perform the method as described in any one of claims 1-8.
10. A computer-readable storage medium, characterized in that, The device stores computer-executable instructions for performing the method as described in any one of claims 1-8.