Language compilation method, electronic device and storage medium
By obtaining and processing program primitives in the SimScript language and generating parallel simulation files, the problem that SimScript language cannot be executed in parallel is solved, and the simulation efficiency is improved.
Patent Information
- Application Number
- CN202410232108.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-02-29
- Publication Date
- 2025-04-18
- Estimated Expiration
- 2044-02-29
AI Technical Summary
The SimScript language cannot effectively support parallel execution, resulting in inefficient simulation.
By obtaining the program primitives and writing them into the SimScript main program file, a program source code file is formed, and the primitive functions are called in the SimScript language declaration, the syntax is updated to achieve parallelization expansion, and a parallel simulation file is generated.
The parallel expansion of the SimScript language has been realized, and the simulation efficiency has been improved.
Smart Images

Figure CN118192983B_ABST
Abstract
Description
Technical Field
[0001] The present application generally relates to the field of computer simulation technology. More specifically, the present application relates to a language compilation method, an electronic device and a storage medium. Background Art
[0002] SimScript is an event-driven discrete event simulation language. Its core idea is to abstract each component in the system into entities and simulate the operation of the system through the triggering of events. The code of SimScript consists of a series of event procedures, each of which defines the response that the system should make when a specific event occurs.
[0003] In order to improve the computer's running speed and the system's processing power, parallel programming is widely used in overall design and logic design, which can make more comprehensive use of computer resources and improve system efficiency. However, due to the characteristics of SimScript language scheduling events in chronological order and serial execution, the existing SimScript language cannot effectively support the parallel execution of SimScript programs. Compared with parallel simulation, serial simulation has a huge amount of calculation and consumes a lot of time, so it is difficult to improve the simulation efficiency of SimScript language.
[0004] In view of this, there is an urgent need to provide a language compilation method in order to solve the problem that the SimScript language does not support parallelism, realize the parallel expansion of the SimScript language, and improve the simulation efficiency of the SimScript language. Summary of the invention
[0005] In order to at least solve one or more of the technical problems mentioned above, the present application proposes a language compilation method, an electronic device and a storage medium in multiple aspects. The language compilation method can solve the problem that the SimScript language does not support parallelism, realize the parallel expansion of the SimScript language, and improve the simulation efficiency of the SimScript language.
[0006] In a first aspect, the present application provides a language compilation method, comprising: obtaining program primitives and writing the program primitives into a SimScript main program file; forming a program source code file based on the SimScript main program file and adding the program source code file to a compilation project; updating the SimScript language declaration to call the primitive function of the program source code file and determine the parameter passing between the program source code file and the SimScript main program, and updating the primitive syntax of the program source code file into the SimScript main program; and compiling and generating a parallel simulation file based on the SimScript main program file and the program source code file.
[0007] In some embodiments, forming a program source code file based on a SimScript main program file includes: retrieving comment identifiers in the SimScript main program file; extracting program primitives between the comment identifiers; and forming the program source code file based on the program primitives between the comment identifiers.
[0008] In some embodiments, updating a SimScript language declaration to call a primitive function of a program source code file and determining parameter passing between the program source code file and a SimScript main program includes: declaring a primitive function in a SimScript language declaration; and setting an incoming parameter instruction and an outgoing parameter instruction in the SimScript language declaration.
[0009] In some embodiments, updating the primitive syntax of the program source code file into the SimScript main program includes: updating the loop statements in the SimScript main program to parallel statements in the primitive syntax; and adding synchronization construction instructions in the primitive syntax to the SimScript main program.
[0010] In some embodiments, generating a parallel simulation file based on compiling a SimScript main program file and a program source code file includes: compiling the SimScript main program file to form a main program target code file; compiling the program source code file to form a primitive target code file; and generating a parallel simulation file based on the main program target code file and the primitive target code file.
[0011] In some embodiments, compiling the SimScript main program file includes: compiling the SimScript main program file based on a first compiler and preset compilation parameters.
[0012] In some embodiments, compiling the program source code file includes: compiling the program source code file based on a second compiler and preset compilation parameters.
[0013] In some embodiments, generating a parallel simulation file based on the main program object code file and the primitive object code file includes: linking the main program object code file and the primitive object code file to generate a parallel simulation file through a preset compilation linking option.
[0014] In a second aspect, the present application provides an electronic device, comprising: a processor; and a memory, on which a program code for language compilation is stored, and when the program code is executed by the processor, the electronic device implements the method as described above.
[0015] In a third aspect, the present application provides a non-transitory machine-readable storage medium having stored thereon a program code for language compilation, and when the program code is executed by a processor, the method as described above can be implemented.
[0016] The technical solution provided by this application may have the following beneficial effects:
[0017] The language compilation method, electronic device and storage medium provided in the present application obtain program primitives and write the program primitives into a SimScript main program file, and then form a program source code file based on the SimScript main program file and add the program source code file to the compilation project, thereby realizing priority processing of program primitives during the SimScript language compilation process and avoiding the problem of missing comments in the SimScript main program.
[0018] Furthermore, the present application can update the SimScript language declaration to call the primitive function of the program source code file and determine the parameter passing between the program source code file and the SimScript main program, and update the primitive syntax of the program source code file to the SimScript main program, and then compile and generate a parallel simulation file based on the SimScript main program file and the program source code file, thereby realizing the mixed compilation of the SimScript language and program primitives, enhancing the parallel computing support capability of the SimScript language, and realizing the automatic parallelization transformation of large-scale simulation projects.
[0019] In general, this application can solve the problem that the SimScript language does not support parallelism, realize the parallel expansion of the SimScript language, and improve the simulation efficiency of the SimScript language. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] By reading the detailed description below with reference to the accompanying drawings, the above and other purposes, features and advantages of the exemplary embodiments of the present application will become easy to understand. In the accompanying drawings, several embodiments of the present application are shown in an exemplary and non-limiting manner, and the same or corresponding reference numerals represent the same or corresponding parts, wherein:
[0021] Figure 1 An exemplary flow chart of a language compilation method according to some embodiments of the present application is shown;
[0022] Figure 2 An exemplary flow chart showing a language compilation method according to some other embodiments of the present application is shown;
[0023] Figure 3 An exemplary flow chart showing a language compilation method according to some other embodiments of the present application is shown;
[0024] Figure 4 A schematic diagram of the structure of an electronic device shown in an embodiment of the present application is shown. DETAILED DESCRIPTION
[0025] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, rather than all of the embodiments. For the simplicity and clarity of the description, the figure marks may be repeated in the drawings to indicate corresponding or similar elements when deemed appropriate. In addition, the present application sets forth many specific details in order to provide a thorough understanding of the embodiments described herein. However, it will be understood by those of ordinary skill in the art that the embodiments described herein may be practiced without these specific details. In other cases, well-known methods, processes, and components are not described in detail to avoid blurring the embodiments described herein. Moreover, the description should not be regarded as limiting the scope of the embodiments described herein. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without making creative work are within the scope of protection of the present application.
[0026] It should be understood that the possible terms "first" or "second" etc. in the claims, specifications and drawings disclosed in this application are used to distinguish different objects, rather than to describe a specific order. The terms "include" and "comprise" used in the specification and claims of this application indicate the presence of the described features, wholes, steps, operations, elements and / or components, but do not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components and / or their collections.
[0027] It should also be understood that the terms used in this application specification are only for the purpose of describing specific embodiments and are not intended to limit the present application. As used in this application specification and claims, unless the context clearly indicates otherwise, the singular forms of "a", "an" and "the" are intended to include plural forms. It should also be further understood that the term "and / or" used in this application specification and claims refers to any combination of one or more of the associated listed items and all possible combinations, and includes these combinations.
[0028] As used in this specification and claims, the term "if" may be interpreted as "when" or "upon" or "in response to determining" or "in response to detecting," depending on the context. Similarly, the phrase "if it is determined" or "if [described condition or event] is detected" may be interpreted as meaning "upon determination" or "in response to determining" or "upon detection of [described condition or event]" or "in response to detecting [described condition or event]," depending on the context.
[0029] Due to the characteristics of SimScript language scheduling events in time order and serial execution, the existing SimScript language cannot effectively support the parallel execution of SimScript programs. Compared with parallel simulation, serial simulation has a huge amount of calculation and consumes a lot of time, so it is difficult to improve the simulation efficiency of SimScript language.
[0030] In view of this, there is an urgent need to provide a language compilation method in order to solve the problem that the SimScript language does not support parallelism, realize the parallel expansion of the SimScript language, and improve the simulation efficiency of the SimScript language.
[0031] The specific implementation of the present application is described in detail below with reference to the accompanying drawings.
[0032] Figure 1 An exemplary flow chart showing the language compilation method of some embodiments of the present application is shown in Figure 1 , the language compilation method shown in the embodiment of the present application may include:
[0033] In step S101, the program primitive is obtained and written into the SimScript main program file. In the embodiment of the present application, the aforementioned program primitive refers to the primitive used to complete the control of the computer process. The so-called primitive generally refers to a program segment composed of a number of instructions, which is used to implement a specific function and cannot be interrupted during execution. In the operating system, some operations called by the process, such as queue operations, operations on semaphores, and checking and starting peripheral operations, cannot be interrupted once they begin to execute, otherwise operational errors will occur, causing system confusion. The concept of primitives originates from the instructions for calling core layer subroutines in the operating system, and always appears as a basic unit. The difference from general processes is that primitives are indivisible, and the actions in a primitive are either not done or all done.
[0034] SimScript is an event-driven discrete event simulation language. Its core idea is to abstract each component in the system into entities and simulate the operation of the system through the triggering of events. The code of SimScript consists of a series of event procedures, each of which defines the response that the system should make when a specific event occurs.
[0035] In step S102, a program source code file is formed based on the SimScript main program file and the program source code file is added to the compilation project. Since program primitives are written in the SimScript main program file, the required program primitives can be extracted from the SimScript main program file by the preset compilation framework in the embodiment of the present application to form a program source code file. Wherein, the aforementioned preset compilation framework can adopt OpenMP, and OpenMP (Open Multi-Processing) is a set of guiding compilation processing schemes (Compiler Directive) designed for multi-processor programs of shared memory parallel systems, and the programming languages supported by OpenMP include C, C++, Java and Fortran. OpenMP provides a high-level abstract description of parallel algorithms, and indicates the intention by adding a dedicated #pragma in the source code, so that the compiler can automatically parallelize the program, and add synchronization, mutual exclusion and communication where necessary. When choosing to ignore these #pragmas, or when the compiler does not support OpenMP, the program can be degenerated into a common program (generally serial), and the code can still operate normally, but it is not possible to use multithreading to accelerate program execution. In this case, the program primitive may be a C program primitive based on OpenMP, and the generated program source code file may be a C program source code file.
[0036] In step S103, the SimScript language declaration is updated, and the primitive syntax of the program source code file is updated to the SimScript main program. In the embodiment of the present application, the aforementioned SimScript language declaration refers to the declaration of variable parameters and function program segments defined in the SimScript language. By updating the SimScript language declaration to be able to call the primitive function of the program source code file and determine the parameter transfer mechanism between the program source code file and the SimScript main program, the parallel expansion of the SimScript language using the program primitive is realized.
[0037] In addition, some statements in the SimScript main program cannot be parallelized. For example, the loop body in the SimScript main program needs to be replaced by the primitive syntax of the program source code file to achieve parallel processing of the loop operation.
[0038] In step S104, a parallel simulation file is generated based on the compilation of the SimScript main program file and the program source code file. In the implementation of this application, the SimScript main program file and the program source code file are uniformly compiled to generate a final parallel executable file, ie, a parallel simulation file.
[0039] This application obtains program primitives and writes them into the SimScript main program file, and then forms a program source code file based on the SimScript main program file and adds the program source code file to the compilation project, thereby realizing the priority treatment of program primitives in the SimScript language compilation process, and avoiding the problem of missing comments in the SimScript main program. Further, this application can update the SimScript language declaration to call the primitive function of the program source code file and determine the parameter transfer between the program source code file and the SimScript main program, and update the primitive syntax of the program source code file to the SimScript main program, and then compile and generate parallel simulation files based on the SimScript main program file and the program source code file, thereby realizing the mixed compilation of SimScript language and program primitives, enhancing the parallel computing support capability of SimScript language, and realizing the automatic parallelization transformation of large-scale simulation projects. In general, this application can solve the problem that SimScript language does not support parallelism, realize the parallelization extension of SimScript language, and improve the simulation efficiency of SimScript language.
[0040] In some embodiments, the mixed processing of SimScript language and program primitives can be implemented according to the idea of extraction and replacement, mainly considering how to connect SimScript language and program primitives. Figure 2 The mixed processing of SimScript language and program primitives is explained in detail. Figure 2 An exemplary flow chart showing the language compilation method of some other embodiments of the present application is shown in Figure 2 , the language compilation method shown in the embodiment of the present application may include:
[0041] In step S201, a program source code file is formed based on the SimScript main program file. Since the project compilation tool can use "$OMP START and "$OMP END" to identify the program primitive code, and since double quotes are comment identifiers in the SimScript language, the program primitive code will not be compiled by the SimScript compiler, but will be extracted into the compilation project by, for example, the OpenMP compilation framework shown in the embodiment of the present application, and a new C program source code file will be generated accordingly.
[0042] Therefore, in the embodiment of the present application, the comment identifier in the SimScript main program file can be first retrieved, and then the program primitives between the comment identifiers can be extracted. Exemplarily, the SimScript main program file can have the following program code:
[0043] ”$OMP START
[0044] "Primitive code (C language)
[0045] ”$OMP END
[0046] Finally, a program source code file, such as a C program source code file, may be formed based on the program primitives between the comment identifiers (such as the primitive codes in the above program code).
[0047] In step S202, the SimScript language declaration is updated to call the primitive function of the program source code file and determine the parameter transfer mechanism between the program source code file and the SimScript main program. In an embodiment of the present application, the primitive function can be declared in the SimScript language declaration preamble. Specifically, the primitive function can be called using a call statement. Exemplarily, the primitive function can be an OpenMP-based primitive function, and the calling code can be exemplarily represented as follows:
[0048] define IN.ARG as an integer variable
[0049] define OUT.ARG as a 1-dim integer array
[0050] write as"Enter the input value:", /
[0051] read IN.ARG
[0052] reserve OUT.ARG(*)as 1
[0053] call sub(IN.ARG,OUT.ARG(*))
[0054] write OUT.ARG(1)as"The output value is",I 10, /
[0055] In addition, the input parameter instruction and the output parameter instruction can be set in the SimScript language declaration to enable the primitive function defined in the SimScript language declaration Preambe.sim to be called in the SimScript main program. In the embodiment of the present application, given can be used as an input parameter instruction to define the input parameter, and yielding can be used as an output parameter instruction to define the output parameter. Taking a test C language function void Test (int inarg, int outarg) as an example, the parameter transfer mechanism between the program source code file and the SimScript main program (i.e., the SimScript main program to the test C language function in the program source code file) can be expressed as:
[0056] define SUB as a nonsimscript routine
[0057] It can be seen that when the int variable in the test C language function is called, the parameter passed is an integer variable, thereby realizing the parameter passing between the SimScript main program and the program source code file. In addition, the variable types in the SimScript language and the C language have a one-to-one conversion relationship, as shown in Table 1 below:
[0058] Table 1:
[0059] C Simscript language unsigned char alpha unsigned short integer2 short signed integer2 int integer long integer long long integer float real double double char* pointer
[0060] By declaring the primitive function of the program source code file in the SimScript language declaration preamble and defining the parameter passing between the SimScript main program and the program source code file, the parallelization extension of the Simscript language is achieved using program primitives, wherein the program primitive can be a C program primitive based on OpenMP. In actual applications, the type of program primitive needs to be determined according to the actual application situation, and this application does not impose any restrictions in this regard.
[0061] In step S203, the primitive syntax of the program source code file is updated to the SimScript main program. In an embodiment of the present application, on the one hand, the loop statement in the SimScript main program can be updated to a parallel statement in the primitive syntax. Since the loop in the SimScript language can only define the end condition with while and define the loop body with do...loop, it is impossible to implement parallel processing of the loop operation. Therefore, it is necessary to use the parallel statements in the primitive syntax to replace the loop body part in the above-mentioned SimScript language. Exemplarily, it can be replaced by a for loop parallel statement, which can be expressed as:
[0062] #pragma omp parallel for schedule(static)
[0063] #pragma omp parallel for schedule(dynamic)
[0064] #pragma omp parallel for schedule(guided)
[0065] The for instruction indicates that the following loop is executed in parallel by a group of threads, while the schedule clause describes how to divide the loop iterations to a group of threads, and the parameters in brackets describe the method by which the loop iterations are divided. By adding primitive syntax such as the above parallel statements to the SimScript main program, the parallel processing of loop operations can be realized.
[0066] On the other hand, a synchronization construction instruction in the primitive syntax can be added to the SimScript main program. Due to the parallelization mechanism of the program primitive (such as the C program primitive based on OpenMP, etc.), a variable in the SimScript main program may be written multiple times by different threads, so a synchronization construction instruction is required for synchronization. Exemplarily, the synchronization construction instruction can be expressed as:
[0067] #pragma omp master or
[0068] #pragma omp critical
[0069] The code block annotated by the above statements will only be executed by one thread at a time. In the process of parallel computing, there will be no situation where multiple threads modify a variable at the same time, thus achieving variable synchronization.
[0070] In general, assuming that the program primitive is an OpenMP-based C program primitive, the mixed processing of the SimScript language and the program primitive can be implemented exemplarily by the following pseudo code:
[0071] Algorithm 1_Handling the mixed code of SimScript and C
[0072] Write the OpenMP code in the main.sim as the note
[0073] The note starts with “$OMP START” and ends with “$OMP END”
[0074] Recognize these strings and write the intermediate code to test.c
[0075] Call the makefile written before to achieve automatic compilation
[0076] It is understandable that the pseudocode for implementing the mixed processing of SimScript language and program primitives can be diverse. In practical applications, the pseudocode for implementing the mixed processing of SimScript language and program primitives needs to be determined based on the actual application situation. This application does not impose any restrictions in this regard.
[0077] In some embodiments, the SimScript main program file and the program source code file can be compiled uniformly to finally generate a parallel simulation file. Figure 3 The specific process of compiling and generating parallel simulation files based on SimScript main program files and program source code files is explained in detail. Figure 3 An exemplary flow chart showing the language compilation method of some other embodiments of the present application is shown in Figure 3 , the language compilation method shown in the embodiment of the present application may include:
[0078] In step S301, the SimScript main program file is compiled to form a main program target code file. In an embodiment of the present application, the SimScript main program file can be compiled based on a first compiler and preset compilation parameters. Wherein, assuming that the program primitive is a C program primitive based on OpenMP, the first compiler can be simc, and the SimScript main program file (main.sim) can be compiled into a main program target code file (Main.o) by the first compiler simc. Exemplarily, it can be implemented by the following code:
[0079] simc-c-fopenmp-std=c99 main.sim
[0080] Among them, -std=c99 is a preset compilation parameter. It is understandable that there are various ways to set the preset compilation parameters, and -std=c99 is only one example. In actual applications, the preset compilation parameters must be reasonably set according to the actual application situation, and this application does not make the sole limitation in this regard.
[0081] In step S302, the program source code file is compiled to form a primitive target code file. In an embodiment of the present application, the program source code file can be compiled based on the second compiler and preset compilation parameters. Wherein, assuming that the program primitive is a C program primitive based on OpenMP, the second compiler can be gcc (GNU Compiler Collection, GNU compiler suite), and the program source code file (Test.c) can be compiled into a primitive target code file (Test.o) by the second compiler gcc. Exemplarily, it can be implemented by the following code:
[0082] gcc–c–fopenmp–std=c99 test.c
[0083] Among them, -std=c99 is a preset compilation parameter. It is understandable that there are various ways to set the preset compilation parameters, and -std=c99 is only one example. In actual applications, the preset compilation parameters must be reasonably set according to the actual application situation, and this application does not make the sole limitation in this regard.
[0084] In step S303, a parallel simulation file is generated based on the main program object code file and the primitive object code file. In an embodiment of the present application, the main program object code file and the primitive object code file can be linked to generate a parallel simulation file by a preset compile link option. Among them, the preset compile link option is -fopenmp, and the parallel simulation file (main.exe) can be linked and generated by the following code implementation:
[0085] simld main.o-fopenmp libtest.a
[0086] or simld main.o-fopenmp libtest.so
[0087] or simld main.o -fopenmp -l . / -ltest
[0088] In general, assuming that the program primitive is a C program primitive based on OpenMP, compiling and generating a parallel simulation file based on a SimScript main program file and a program source code file can be implemented exemplarily by the following pseudo code:
[0089] Algorithm 2_Complile C and SimScript code separately
[0090] Use gcc and simc separately to compile main.sim and test.c
[0091] Get main.o and test.o
[0092] Link main.o and test.o with simld with lopenmp library
[0093] Get the executable file main.exe
[0094] It is understandable that the pseudocode for generating parallel simulation files based on the compilation of SimScript main program files and program source code files can be diverse. In practical applications, the pseudocode for generating parallel simulation files based on the compilation of SimScript main program files and program source code files needs to be determined according to the actual application situation. This application does not impose any restrictions in this regard.
[0095] Corresponding to the aforementioned application function implementation method embodiment, the present application also provides an electronic device for executing a language compilation method and corresponding embodiments.
[0096] Figure 4 FIG. 4 is a block diagram showing the hardware configuration of an electronic device 400 that can implement the language compilation method of an embodiment of the present application. Figure 4 As shown, the electronic device 400 may include a processor 410 and a memory 420. Figure 4In the electronic device 400, only the components related to this embodiment are shown. Therefore, it is obvious to those skilled in the art that the electronic device 400 may also include components related to this embodiment. Figure 4 The components shown in the figure are different from the common components. For example: fixed-point arithmetic units.
[0097] The electronic device 400 may correspond to a computing device having various processing functions, for example, a function for generating a neural network, training or learning a neural network, quantizing a floating-point neural network to a fixed-point neural network, or retraining a neural network. For example, the electronic device 400 may be implemented as various types of devices, such as a personal computer (PC), a server device, a mobile device, etc.
[0098] The processor 410 controls all functions of the electronic device 400. For example, the processor 410 controls all functions of the electronic device 400 by executing a program stored in the memory 420 on the electronic device 400. The processor 410 may be implemented by a central processing unit (CPU), a graphics processing unit (GPU), an application processor (AP), an artificial intelligence processor chip (IPU), etc. provided in the electronic device 400. However, the present application is not limited thereto.
[0099] In some embodiments, processor 410 may include input / output (I / O) unit 411 and computing unit 412. I / O unit 411 may be used to receive various data, such as program primitives. Exemplarily, computing unit 412 may be used to write program primitives received via I / O unit 411 into SimScript main program file, and then form program source code file based on SimScript main program file and add program source code file to compiled project, and then update SimScript language declaration to call the primitive function of program source code file and determine the parameter transfer of program source code file and SimScript main program, and update the primitive syntax of program source code file into SimScript main program, and then compile and generate parallel simulation file based on SimScript main program file and program source code file. This parallel simulation file, for example, may be output by I / O unit 411. Output data may be provided to memory 420 for other devices (not shown) to read and use, or may be directly provided to other devices for use.
[0100] The memory 420 is hardware for storing various data processed in the electronic device 400. For example, the memory 420 can store processed data and data to be processed in the electronic device 400. The memory 420 can store data sets involved in the language compilation method process that has been processed or to be processed by the processor 410, such as program primitives, etc. In addition, the memory 420 can store applications, drivers, etc. to be driven by the electronic device 400. For example: the memory 420 can store various programs related to the language compilation method to be executed by the processor 410. The memory 420 can be a DRAM, but the present application is not limited thereto. The memory 420 may include at least one of a volatile memory or a non-volatile memory. The non-volatile memory may include a read-only memory (ROM), a programmable ROM (PROM), an electrically programmable ROM (EPROM), an electrically erasable programmable ROM (EEPROM), a flash memory, a phase change RAM (PRAM), a magnetic RAM (MRAM), a resistive RAM (RRAM), a ferroelectric RAM (FRAM), etc. The volatile memory may include dynamic RAM (DRAM), static RAM (SRAM), synchronous DRAM (SDRAM), PRAM, MRAM, RRAM, ferroelectric RAM (FeRAM), etc. In an embodiment, the memory 420 may include at least one of a hard disk drive (HDD), a solid state drive (SSD), a high-density flash memory (CF), a secure digital (SD) card, a micro secure digital (Micro-SD) card, a mini secure digital (Mini-SD) card, an extreme digital (xD) card, caches, or a memory stick.
[0101] In summary, the specific functions implemented by the memory 420 and the processor 410 of the electronic device 400 provided in the implementation mode of this specification can be explained in comparison with the aforementioned implementation modes in this specification, and can achieve the technical effects of the aforementioned implementation modes, and will not be repeated here.
[0102] In this embodiment, the processor 410 can be implemented in any suitable manner. For example, the processor 410 can take the form of a microprocessor or processor and a computer-readable medium storing computer-readable program code (such as software or firmware) executable by the (micro)processor, a logic gate, a switch, an application specific integrated circuit (ASIC), a programmable logic controller, and an embedded microcontroller, etc.
[0103] It should also be understood that any module, unit, component, server, computer, terminal or device that executes instructions exemplified herein may include or otherwise access computer-readable media, such as storage media, computer storage media or data storage devices (removable and / or non-removable) such as disks, optical disks or tapes. Computer storage media may include volatile and non-volatile, removable and non-removable media implemented in any method or technology for storing information, such as computer-readable instructions, data structures, program modules or other data.
[0104] Although multiple embodiments of the present application have been shown and described herein, it is obvious to those skilled in the art that such embodiments are provided only by way of example. Those skilled in the art can think of many changes, modifications and alternatives without departing from the thought and spirit of the present application. It should be understood that in the process of practicing the present application, various alternatives to the embodiments of the present application described herein can be adopted. The attached claims are intended to limit the scope of protection of the present application, and therefore cover equivalents or alternatives within the scope of these claims.
Claims
1. A language compilation method, characterized in that: include: Obtaining a program primitive and writing the program primitive into a SimScript main program file; wherein the program primitive refers to a primitive used to complete the control of a computer process; Forming a program source code file based on the SimScript main program file and adding the program source code file to the compilation project; wherein forming the program source code file based on the SimScript main program file comprises: extracting the program primitives from the SimScript main program file to form the program source code file; Updating SimScript language declarations to call primitive functions of the program source code file and determine parameter transfer between the program source code file and a SimScript main program, and updating primitive syntax of the program source code file into the SimScript main program; and A parallel simulation file is generated based on the compilation of the SimScript main program file and the program source code file.
2. The language compiling method according to claim 1, characterized in that: The forming of a program source code file based on the SimScript main program file comprises: Retrieving a comment identifier in the SimScript main program file; extracting program primitives between the annotation identifiers; and The program source code file is formed based on the program primitives between the comment identifiers.
3. The language compiling method according to claim 1, characterized in that: The updating of the SimScript language declaration to call the primitive function of the program source code file and determining the parameter transfer between the program source code file and the SimScript main program includes: Declaring the primitive function in the SimScript language declaration; and The incoming parameter instruction and the outgoing parameter instruction are set in the SimScript language declaration.
4. The language compiling method according to claim 1, characterized in that: The updating of the primitive syntax of the program source code file into the SimScript main program includes: Updating the loop statements in the SimScript main program to parallel statements in the primitive syntax; and Add the synchronization construction instruction in the primitive syntax to the SimScript main program.
5. The language compiling method according to claim 1, characterized in that: The compiling and generating a parallel simulation file based on the SimScript main program file and the program source code file comprises: Compiling the SimScript main program file to form a main program object code file; Compiling the program source code file to form a primitive object code file; and The parallel simulation file is generated based on the main program object code file and the primitive object code file.
6. The language compiling method according to claim 5, characterized in that: The compiling of the SimScript main program file comprises: The SimScript main program file is compiled based on the first compiler and preset compilation parameters.
7. The language compiling method according to claim 6, characterized in that: The compiling of the program source code file comprises: The program source code file is compiled based on the second compiler and the preset compilation parameters.
8. The language compiling method according to claim 5, characterized in that: The generating of the parallel simulation file based on the main program target code file and the primitive target code file comprises: The main program object code file and the primitive object code file are linked to generate the parallel simulation file through preset compile link options.
9. An electronic device, characterized in that: include: processor; as well as A memory having program codes for language compilation stored thereon, wherein when the program codes are executed by the processor, the electronic device implements the method as claimed in any one of claims 1 to 8.
10. A non-transitory machine-readable storage medium having stored thereon a program code for language compilation, wherein when the program code is executed by a processor, the method according to any one of claims 1 to 8 is implemented.
Citation Information
Patent Citations
Method and device for grammar mapping from SIMSCRIPT language to C language
CN117193782A