WO2022033229A1 - Software code compiling method and system - Google Patents

Software code compiling method and system Download PDF

Info

Publication number
WO2022033229A1
WO2022033229A1 PCT/CN2021/104177 CN2021104177W WO2022033229A1 WO 2022033229 A1 WO2022033229 A1 WO 2022033229A1 CN 2021104177 W CN2021104177 W CN 2021104177W WO 2022033229 A1 WO2022033229 A1 WO 2022033229A1
Authority
WO
WIPO (PCT)
Prior art keywords
code
package
application
application package
file
Prior art date
Application number
PCT/CN2021/104177
Other languages
French (fr)
Chinese (zh)
Inventor
董逢华
江俊
胡瑞璟
何涛
Original Assignee
武汉天喻信息产业股份有限公司
武汉天喻聚联科技有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 武汉天喻信息产业股份有限公司, 武汉天喻聚联科技有限公司 filed Critical 武汉天喻信息产业股份有限公司
Publication of WO2022033229A1 publication Critical patent/WO2022033229A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/42Syntactic analysis
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/20Natural language analysis
    • G06F40/279Recognition of textual entities
    • G06F40/284Lexical analysis, e.g. tokenisation or collocates
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/30Semantic analysis
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • G06F9/45533Hypervisors; Virtual machine monitors
    • G06F9/45558Hypervisor-specific management and integration aspects

Definitions

  • the present invention relates to the technical field of computers, in particular to a software code compilation method and system.
  • security modules have the characteristics of limited resources and high performance requirements, but traditional language systems cannot meet the changing user usage scenarios of embedded modules, and cannot meet high performance with limited resources. requirements, and cannot meet the requirements that the same software code can run on different embedded modules.
  • Embodiments of the present application provide a method and system for compiling software code, which pre-compiles the code to generate a download file that is easy to parse, reduces resource requirements in embedded development, and provides guarantee for performance requirements in embedded development , and at the same time, it can meet the requirements that the downloaded file can be executed across platforms.
  • a software code compilation method includes the following steps:
  • the input code includes an application package code and a reference package code, the target code including the application package target code generated by the application package code and the reference package target code generated by the reference package code, the application package code and the application package target code both include the code corresponding to the runtime environment interface;
  • a download file is generated according to the application package bytecode file and the reference package bytecode file.
  • the receiving the input code, extracting the word stream corresponding to the input code, generating a syntax tree according to a preset grammar rule, and performing semantic analysis to obtain the target code specifically includes the following steps:
  • the method further includes the following steps:
  • the constant pool is used to store programming general characters, programming language keywords, general application programming interface keywords and runtime environment interface keywords supported by the method in terms of entries respectively;
  • the constant pool is also used to store the variables and methods declared in the header file referenced by the input code, the variables and methods in the input code in turn in units of entries when the word stream corresponding to the input code is extracted. Defined variables and custom methods are stored in the constant pool in units of entries respectively;
  • the reference package bytecode file includes a binary bytecode file and a binary output mapping file
  • the binary output mapping file includes version information corresponding to the reference package bytecode file, application identification data and all Contains description information for the method.
  • the application package bytecode file includes a method component subfile, a memory component subfile, a runtime method component subfile, and a shared interface component subfile.
  • the method component subfile of the application package bytecode file includes the bytecodes of all methods in the application package, which are arranged in sequence according to the declaration order of each method in the source code of the application package.
  • the storage location and method name of the method in the application package are recorded in the constant pool in a one-to-one correspondence;
  • the memory component subfile records the size and initial value of the global non-volatile space in the corresponding application package and the global The size of the volatile space;
  • the runtime method component subfile includes an offset value of the runtime environment interface of the corresponding application package, which is used for invoking the corresponding application package during installation, deletion, activation, and deactivation;
  • the shared interface component subfile includes the number of shared interfaces declared by the corresponding application package and the offset value of each interface method.
  • generating the download file according to the application package bytecode file and the reference package bytecode file specifically includes the following steps:
  • the method component, the memory component, the runtime method component and the shared interface component are obtained by parsing, and combined with the preset data package and application identification data, according to the preset Format to generate download files.
  • a software code compilation system comprising:
  • a software code compiling unit which is used for receiving an input code, extracting a word stream corresponding to the input code, generating a syntax tree according to a preset grammar rule, and performing semantic analysis to obtain a target code, where the input code includes an application package code and a Reference package code, the target code includes application package target code generated by the application package code and reference package target code generated by the reference package code, both the application package code and the application package target code include running The code corresponding to the time environment interface;
  • an application package generation unit which is used for generating an application package bytecode file according to the data implementing the application function in the application package target code
  • a reference package generation unit which is used to generate a reference package bytecode file according to the data that implements the interface call in the reference package target code
  • a download file generating unit configured to generate a download file according to the application package bytecode file and the reference package bytecode file.
  • the software code compiling unit is specifically used for:
  • system is configured with a constant pool
  • the constant pool is used to store the programming general characters, programming language keywords, general application programming interface keywords and runtime environment interface keywords supported by the system respectively in terms of entries;
  • the constant pool is also used to sequentially store the variables and methods declared in the header file referenced by the input code,
  • the self-defined variables and self-defined methods in the above input code are stored in the constant pool in terms of entries respectively;
  • the reference package bytecode file includes a binary bytecode file and a binary output mapping file
  • the binary output mapping file includes version information corresponding to the reference package bytecode file, application identification data and all Contains description information for the method.
  • the application package bytecode file includes a method component subfile, a memory component subfile, a runtime method component subfile, and a shared interface component subfile.
  • the method component subfile of the application package bytecode file includes the bytecodes of all methods in the application package, which are arranged in sequence according to the declaration order of each method in the source code of the application package.
  • the storage location and method name of the method in the application package are recorded in the constant pool in one-to-one correspondence;
  • the memory component subfile records the size and initial value of the global non-volatile space and the size value of the global volatile space in the corresponding application package;
  • the runtime method component subfile includes an offset value of the runtime environment interface of the corresponding application package, which is used for invoking the corresponding application package during installation, deletion, activation, and deactivation;
  • the shared interface component subfile includes the number of shared interfaces declared by the corresponding application package and the offset value of each interface method.
  • the download file generating unit is specifically configured to parse and obtain a method component, a memory component, a runtime method component and a shared interface component according to the application package bytecode file and the reference package bytecode file, And combined with the preset data package and application identification data, the download file is generated according to the preset format.
  • the present application provides a method and system for compiling software code.
  • the code is pre-compiled according to preset grammar rules, and a download file that is easy to be parsed is generated. It provides guarantees for the performance requirements of the downloaded files and meets the requirements that the downloaded files can be executed across platforms.
  • FIG. 1 is a flowchart of steps of a software code compiling method provided in Embodiment 1 of the present application;
  • FIG. 3 is a flowchart of the software code compilation system provided in Embodiment 1 of the present application when a download file is generated;
  • FIG. 4 is a schematic block diagram of the runtime of a virtual machine in the software code compilation system provided by Embodiment 1 of the present application;
  • FIG. 5 is a structural block diagram of a software code compiling system provided by Embodiment 2 of the present application.
  • Embodiments of the present invention provide a method and system for compiling software code, which pre-compiles the code according to preset grammar rules, and generates a download file that is easy to parse.
  • the performance requirements in the file are guaranteed to meet the requirements that the downloaded files can be executed across platforms.
  • a software code compilation method includes the following steps:
  • S1 Receive an input code, extract a word stream corresponding to the input code, generate a syntax tree according to a preset grammar rule, and perform semantic analysis to obtain a target code, the input code includes an application package code and a reference package code, and the target code includes the application package code.
  • the application package target code generated by the code and the reference package target code generated by the reference package code, the application package code and the application package target code include the code corresponding to the runtime environment interface;
  • an embodiment of the present invention provides a software code compilation method, and the method includes the following steps:
  • S1 Receive an input code, extract a word stream corresponding to the input code, generate a syntax tree according to a preset grammar rule, and perform semantic analysis to obtain a target code, the input code includes an application package code and a reference package code, and the target code includes the application package code.
  • the application package target code generated by the code and the reference package target code generated by the reference package code, the application package code and the application package target code include the code corresponding to the runtime environment interface;
  • the input code is first received, and the specific workflow is performed:
  • the input code includes the application package code and the reference package code
  • the target code includes the application package target code generated by the application package code and the reference package target code generated by the reference package code
  • both the application package code and the application package target code include the runtime The code corresponding to the environment interface
  • the input code is scanned according to the coding order, and the acquired words are added to the preset constant pool according to certain rules.
  • Each entry in the constant pool contains the corresponding word of the word.
  • the object code generation process is to analyze the expression level, analyze various expressions in the program, and generate corresponding bytecode expressions.
  • the source file that is, the output of the compilation of the input code, that is, the target code is the application package bytecode file and the reference package bytecode file, which implements the runtime environment interface (process, select, deselect, install, uninstall, getSccLibInterface ) applications will generate corresponding application package bytecode files, while pure method packages (no runtime environment interface) and applications with shared interfaces will generate reference package bytecode files, each source file correspondingly generates a byte code file.
  • the runtime environment interface process, select, deselect, install, uninstall, getSccLibInterface
  • the code is pre-compiled according to the preset grammar rules, and a download file that is easy to parse is generated.
  • the demand for resources is reduced, and the performance demand in the embedded development is guaranteed to meet the requirements.
  • Download files can perform cross-platform requirements.
  • the characters in (1) to (3) are added to the constant pool in order.
  • the constant pool data in this part is fixed, and then in the code
  • the characters in (4) are added to the constant pool in order during compilation.
  • the string corresponding to each member in the constant pool is unique, and the sequence ID, complete string information and verification compression value of the string are marked in the member structure, which is used for the subsequent encoding of the read string. Compare and verify.
  • API keywords can be upgraded.
  • the newly added API keywords are added to the original API keywords in the constant pool, and they are arranged in the order of upgrade.
  • the higher version of the API can be compatible with the lower version of the API. Ensure backward compatibility of compilation results before and after the upgrade.
  • the file that implements the runtime environment interface in the input code and the target code is the application package.
  • the embedded module can call the runtime environment interface of the application package to select the function of activating and running the application package. Because the firewall security requires the application package Common methods and variables in can only be accessed in the current package, and different application packages can access each other's shared interface methods;
  • the files in the input code and the object code that do not implement the runtime environment interface are reference packages.
  • the reference packages provide a mapping to the outside so that their methods can be called by different application packages.
  • the download file obtained by the embodiment of the present application needs to rely on the virtual machine system and the runtime environment system during practical application,
  • the virtual machine system is used to process the downloaded file, parse the bytecode in the downloaded file, and execute the corresponding application package code function.
  • the runtime environment system is used to manage the life cycle of the application, access the runtime environment interface of the application, and manage the firewall when the application is running.
  • each source file that implements the runtime environment interface is regarded as a package, which is instantiated as an application applet.
  • the main functions of the runtime environment interface are:
  • Firewall management to prevent applications under different packages from accessing each other.
  • the core of the virtual machine system is the virtual machine bytecode.
  • the basic principle of the virtual machine system is that the bytecode, the stack and the interpreter work together.
  • the bytecode is responsible for the implementation of the syntax operators of the program, and the stack is responsible for the parameters, variables and temporary operations.
  • the storage of numbers and other data, the interpreter parses the bytecode obtained in the program pointer, and the three together realize the expression of the programming language.
  • the runtime environment system introduces the concept of package and application, so in the download file conversion tool, the developer can input the package of the current source file and the AID of the application as required, in each embedded module system , the AIDs of packages and applications are unique, and the runtime environment system can find the corresponding application according to the AID.
  • an application package code contains code corresponding to the runtime environment interface
  • an application package target code contains code corresponding to the runtime environment interface
  • the input code includes at least one application package code, and may contain one, more or no reference package code.
  • the target code includes at least one application package object code, and may contain one, more or no reference package object code;
  • one application package code may need to use multiple reference package codes, and similarly, one application package object code may need to use multiple reference package object codes in actual application.
  • the method before receiving the input code, the method further includes the following steps:
  • the constant pool is used to store the programming general characters, programming language keywords, general application programming interface keywords and runtime environment interface keywords supported by the method in terms of entries;
  • the constant pool is also used to store the variables and methods declared in the header file referenced by the input code, the custom variables and custom methods in the input code in terms of terms, respectively, when the word stream corresponding to the input code is extracted.
  • the unit is stored in the constant pool;
  • the constant pool is the basis of lexical analysis.
  • Each ID in the constant pool represents a word in the word stream, and its basic structure is identified by the word, compressed and encoded. , word name, word length, word type, used identifier, and method offset identifier, where the word identifier represents the position of the word in the constant pool, the compression encoding is the compression encoding representing the word string, and the word name is the word.
  • the word length is the string length of the word
  • the word type indicates the function type of the word
  • the used flag indicates whether the word is called in the source program
  • the method offset flag indicates that when the word is a function, the function is in bytes.
  • the offset value in the code method component is the basis of lexical analysis.
  • the offset value specifically refers to the data storage location.
  • Newly declared words searched when parsing source files and header files including new macro definitions, header file function declarations, variable declarations, etc. Since all words in C language are the rules of first declaration and then calling, so in When searching for a statement, first check whether the statement is in the constant pool, if not, add the word to the constant pool, where the word identifier is a fixed value, indicating that the constant pool member is a string;
  • the word identifier is a fixed value, indicating that the member is a string
  • the word identifier is the ordinal position in the general keyword enumeration
  • the general keyword enumeration is arranged in the order of type, programming language keyword and operator, and the starting value of the word identifier is 128;
  • the types in point 8 above include numbers, functions, system functions, shared functions, global variables, local variables, etc., indicating the type meaning of each constant pool member;
  • the compression encoding of the constant pool member is the compression encoding of the string name of the word. For members whose word ID is less than 128, the compression encoding is 0.
  • the compression encoding of other members is a hash value of the ASCII codes of all characters of the word. operation;
  • the word name and word length of the constant pool member is the complete string description of its word
  • the word type of the constant pool member is the type represented by the word, as shown in 9 above; especially when the word is a function input by referencing the package bytecode file, its type is a shared function;
  • the used identification attribute of the constant pool member indicates whether the word is used by the source file. If it is not used, it will not be considered in the final link, which can speed up the link speed and optimize the use space;
  • the method offset identification attribute of the constant pool member indicates that when the word is a function method, the offset value of the bytecode corresponding to the function in the bytecode interval, that is, the offset position, that is, the storage location, when the function is called After finding the corresponding member through the constant pool, use the method offset value to jump.
  • the function of the constant pool is to mark the keywords supported by the current compilation environment, as well as the variables, macro definitions, and function declarations of source files and header files, which are used to read words when parsing the source file code. Semantic Analysis.
  • the word string corresponding to each member in the constant pool is unique, but because the string composition and length of the word are uncontrollable, simply using string comparison will waste performance and space. Therefore, the embodiments of the present application provide A matching method with greatly improved performance and memory overhead is proposed, which is divided into three steps. The operation process is as follows:
  • the first level is the word identification comparison, which can search for all single character words and programming language keyword words, and the word identification of these words is unique;
  • the second level is compression encoding comparison, which can search for words corresponding to all unique word identifiers in the constant pool;
  • the third level is the word name comparison, which can completely match the words in the constant pool
  • the basic order of matching is 1, 2, 3, and the third-level full string comparison is performed only when the word identifier is not unique.
  • the code compilation is parsed according to the actual coding order.
  • the specific conditions are as follows:
  • the word read in the source file is a header file
  • the runtime environment interface is used for runtime environment selection and switching. Other functions cannot call the runtime environment interface;
  • API interface that is, the general embedded module API interface function, whose implementation method declaration and order are fixed in the API interface set, and can be called in the application;
  • Reference package shared function that is, an external custom function package. This function package has its own AID and method list. After the source file is referenced, the shared function in the package can be called;
  • the constant pool word type of the runtime environment interface and API interface is a system function, and the word identifier value corresponding to each function is fixed and unique;
  • the type of the reference package function is a shared function, and the word of the source file custom function
  • the type type is an ordinary function, and its word identification value is a string type;
  • the API interface is in the order declared in the API interface set, and each function corresponds to an ID, which is used for the input of the bytecode of the system function call in the virtual machine system;
  • the above steps implement the basic compilation process of the embedded module application, and the output is the application package bytecode file.
  • the reference package bytecode file includes a binary bytecode file and a binary output mapping file
  • the binary output mapping file includes version information corresponding to the reference package bytecode file, application identification data, and description information of the included methods.
  • the application package bytecode file includes a method component subfile, a memory component subfile, a runtime method component subfile, and a shared interface component subfile.
  • sub-files do not represent the relationship between the upper and lower levels, but there are multiple parts in the application package bytecode file, namely the method component part, the memory component part, the runtime method component part and the shared interface. Component parts, here for describing aspects, are called subfiles.
  • the method component subfile of the application package bytecode file includes the bytecodes of all methods in the application package, which are arranged in order according to the declaration order of each method in the source code of the application package, and the storage location of each method in the application package and the method name are recorded in the constant pool in one-to-one correspondence;
  • the memory component subfile records the size and initial value of the global non-volatile space (NVM, Non-volatile Memory) and the size value of the global volatile space (RAM, Random Access Memory) in the corresponding application package;
  • NVM global non-volatile space
  • RAM Random Access Memory
  • the runtime method component subfile includes the offset value of the runtime environment interface of the corresponding application package, which is used for invoking the corresponding application package during installation, deletion, activation, and deactivation;
  • the shared interface component subfile includes the number of shared interfaces declared by the corresponding application package and the offset value of each interface method.
  • generating a download file according to the application package bytecode file and the reference package bytecode file specifically includes the following steps:
  • the method components, memory components, runtime method components and shared interface components are obtained by parsing, and combined with the preset data package and application identification data, the download is generated according to the preset format document.
  • the virtual machine system is implemented on the embedded module, which can download the bytecode file corresponding to the virtual machine and execute the corresponding bytecode process in the card;
  • the stack, RAM (volatile storage space), and NVM (non-volatile storage space) resources when the virtual machine is running are all uniformly addressed.
  • the address structure distribution diagram of the virtual machine system defines the resources as follows:
  • Virtual machine stack including analog registers, operation stacks and program stacks
  • RAM RAM space applied for in the application
  • Static NVM The space occupied by the application package bytecode file downloaded to the card, the global NVM resource of a given size defined by the application, and other personalized resources;
  • Dynamic NVM NVM resources dynamically applied for during application running
  • Different virtual machine system implementations can allocate the proportion of each resource according to the actual situation.
  • the runtime management system is responsible for managing the life cycle of cards and applications, application selection and firewall protection, etc., where:
  • the life cycle of an application consists of five methods corresponding to the runtime environment structure.
  • the install method is responsible for the private instantiation of the application during installation, the select method is responsible for application activation, and the process method is the entry for application processing commands, responsible for receiving and processing APDU commands, deselect
  • the method is responsible for application deactivation, the uninstall method is responsible for the private de-instantiation operation when the application is deleted, and each function corresponds to a life cycle stage of the application;
  • the application selection is executed through the logical channel management and selection file commands. These two commands are used by the runtime environment system to specify an An activated application instance in a session of a logical channel, once an instance is selected, this application instance will receive all subsequent private commands distributed to that logical channel until the application instance becomes deselected.
  • Firewalls also provide protection against incorrect code. If incorrect code is loaded onto the card, the firewall can still protect existing data from being accessed by this malicious code.
  • the runtime environment system also provides a mechanism that allows different applications to interact, that is, the shared interface mechanism.
  • the shared interface defines the set of all interface methods that can be shared in the application. These methods can be used in different contexts. (package and application) environment.
  • the input of the download file conversion tool includes the package AID of the source file and the input application package bytecode file path;
  • the output of the download file conversion tool includes a fixed format download script file
  • the basic principle is to extract the data of method components, memory components, runtime method components, and shared interface method components in the application package bytecode file, and organize it into a fixed-format download file together with the input package AID.
  • Embodiment 2 Based on the same inventive concept, the present application provides an embodiment of the system corresponding to Embodiment 1. For details, please refer to Embodiment 2
  • an embodiment of the present invention provides a software code compilation system, the system includes:
  • a software code compiling unit 1 which is used for receiving input codes, extracting word streams corresponding to the input codes, generating syntax trees according to preset grammar rules, and performing semantic analysis to obtain target codes
  • the input codes include application package codes and reference package codes
  • the target code includes the application package target code generated by the application package code and the reference package target code generated by the reference package code
  • both the application package code and the application package target code include the code corresponding to the runtime environment interface
  • An application package generation unit 2 which is used to generate an application package bytecode file according to the data that realizes the application function in the application package target code;
  • a reference package generation unit 3 which is used to generate a reference package bytecode file according to the data that realizes the interface call in the reference package target code;
  • the download file generating unit 4 is configured to generate a download file according to the application package bytecode file and the reference package bytecode file.
  • first the software code compiling unit 1 receives the input code, and performs a specific workflow:
  • the input code includes the application package code and the reference package code
  • the target code includes the application package target code generated by the application package code and the reference package target code generated by the reference package code
  • both the application package code and the application package target code include the runtime The code corresponding to the environment interface
  • the input code is scanned according to the coding order, and the acquired words are added to the preset constant pool according to certain rules.
  • Each entry in the constant pool contains the corresponding word of the word.
  • the object code generation process is to analyze the expression level, analyze various expressions in the program, and generate corresponding bytecode expressions.
  • the source file that is, the output of the compilation of the input code, that is, the target code is the application package bytecode file and the reference package bytecode file, which implements the runtime environment interface (process, select, deselect, install, uninstall, getSccLibInterface ) application will generate the corresponding application package bytecode file, while the reference package (no runtime environment interface) and the application with shared interface will generate the reference package bytecode file, each source file correspondingly generates a binary byte code file (application package bytecode file or reference package bytecode file).
  • the runtime environment interface process, select, deselect, install, uninstall, getSccLibInterface
  • the code is pre-compiled according to the preset grammar rules, and a download file that is easy to parse is generated.
  • the demand for resources is reduced, and the performance demand in the embedded development is guaranteed to meet the requirements.
  • Download files can perform cross-platform requirements.
  • the characters in (1) to (3) are added to the constant pool in order.
  • the constant pool data in this part is fixed, and then in the code
  • the characters in (4) are added to the constant pool in order during compilation.
  • the string corresponding to each member in the constant pool is unique, and the sequence ID, complete string information and verification compression value of the string are marked in the member structure, which is used for the subsequent encoding of the read string. Compare and verify.
  • API keywords can be upgraded.
  • the newly added API keywords are added to the original API keywords in the constant pool, and they are arranged in the order of upgrade.
  • the higher version of the API can be compatible with the lower version of the API. Ensure backward compatibility of compilation results before and after the upgrade.
  • the file that implements the runtime environment interface in the input code and the target code is the application package.
  • the embedded module can call the runtime environment interface of the application package to choose to activate and run the application package function. Because the firewall security requires the application package Common methods and variables in can only be accessed in the current package, and different application packages can access each other's shared interface methods;
  • the files in the input code and the object code that do not implement the runtime environment interface are reference packages.
  • the reference packages provide a mapping to the outside so that their methods can be called by different application packages.
  • the download file obtained by the embodiment of the present application needs to rely on the virtual machine system and the runtime environment system during practical application,
  • the virtual machine system is used to process the downloaded file, parse the bytecode in the downloaded file, and execute the corresponding application package code function.
  • the runtime environment system is used to manage the life cycle of the application, access the runtime environment interface of the application, and manage the firewall when the application is running.
  • each source file that implements the runtime environment interface is regarded as a package, which is instantiated as an application applet.
  • the main functions of the runtime environment system are:
  • Firewall management to prevent applications under different packages from accessing each other.
  • the core of the virtual machine system is the virtual machine bytecode.
  • the basic principle of the virtual machine system is that the bytecode, the stack and the interpreter work together.
  • the bytecode is responsible for the implementation of the syntax operators of the program, and the stack is responsible for the parameters, variables and temporary operations.
  • a download file conversion tool When generating the download file, a download file conversion tool can be used specifically, the function of which is to convert the application package bytecode file and the reference package bytecode file into a standard GP (GP, GlobalPlatform, Global Platform International Standards Organization) download script.
  • GP GlobalPlatform, Global Platform International Standards Organization
  • an application package code contains code corresponding to the runtime environment interface
  • an application package target code contains code corresponding to the runtime environment interface
  • the input code includes at least one application package code, and may contain one, more or no reference package code.
  • the target code includes at least one application package object code, and may contain one, more or no reference package object code;
  • one application package code may need to use multiple reference package codes, and similarly, one application package object code may need to use multiple reference package object codes in actual application.
  • the system is configured with a constant pool
  • the constant pool is used to store the programming general characters, programming language keywords, general application programming interface keywords and runtime environment interface keywords supported by the system in terms of entries;
  • the constant pool is also used to store the variables and methods declared in the header file referenced by the input code, the custom variables in the input code, and the custom methods in the unit of entry when the software code compilation unit extracts the word stream corresponding to the input code.
  • the entries are stored in the constant pool respectively;
  • the constant pool is the basis of lexical analysis.
  • Each ID in the constant pool represents a word in the word stream, and its basic structure is identified by the word, compressed and encoded. , word name, word length, word type, used ID, and method offset ID, where the word ID indicates the position of the word in the constant pool, the compression encoding is the compression encoding for the word string, and the word name is the word.
  • the word length is the string length of the word
  • the word type indicates the function type of the word
  • the used flag indicates whether the word is called in the source program
  • the method offset flag indicates that when the word is a function, the function is in bytes.
  • the offset value in the code method component is the basis of lexical analysis.
  • the offset value specifically refers to the data storage location.
  • the function of the constant pool is to mark the keywords supported by the current compilation environment, as well as the variables, macro definitions, and function declarations of the source file and header file, which are used to read the words when parsing the source file code. Semantic Analysis.
  • the word string corresponding to each member in the constant pool is unique, but since the string composition and length of the word are uncontrollable, simply using string comparison will waste performance and space. Therefore, the embodiments of the present application provide A matching method with greatly improved performance and memory overhead is proposed. It is divided into three steps. The operation process is as follows:
  • the first level is the word identification comparison, which can search for all single character words and programming language keyword words, and the word identification of these words is unique;
  • the second level is compression encoding comparison, which can search for words corresponding to all unique word identifiers in the constant pool;
  • the third level is the word name comparison, which can completely match the words in the constant pool
  • the basic order of matching is 1, 2, 3, and the third-level full string comparison is performed only when the word identifier is not unique.
  • the reference package bytecode file includes a binary bytecode file and a binary output mapping file
  • the binary output mapping file includes version information corresponding to the reference package bytecode file, application identification data, and description information of the included methods.
  • the application package bytecode file includes a method component subfile, a memory component subfile, a runtime method component subfile, and a shared interface component subfile.
  • sub-files do not represent the relationship between the upper and lower levels, but there are multiple parts in the application package bytecode file, namely the method component part, the memory component part, the runtime method component part and the shared interface. Component parts, here for describing aspects, are called subfiles.
  • the method component subfile of the application package bytecode file includes the bytecodes of all methods in the application package, which are arranged in order according to the declaration order of each method in the source code of the application package, and the storage location of each method in the application package and the method name are recorded in the constant pool in one-to-one correspondence;
  • the memory component subfile records the size and initial value of the global non-volatile space (NVM, Non-volatile Memory) and the size value of the global volatile space (RAM, Random Access Memory) in the corresponding application package;
  • NVM global non-volatile space
  • RAM Random Access Memory
  • the runtime method component subfile includes the offset value of the runtime environment interface of the corresponding application package, which is used for invoking the corresponding application package during installation, deletion, activation, and deactivation;
  • the shared interface component subfile includes the number of shared interfaces declared by the corresponding application package and the offset value of each interface method.
  • the download file generation unit 4 is specifically configured to parse and obtain the method component, the memory component, the runtime method component and the shared interface component according to the application package bytecode file and the reference package bytecode file, and combine the preset
  • the data package and application identification data are generated according to the preset format to download the file.

Abstract

A software code compiling method and system, relating to the technical field of computers. The method comprises the following steps: receiving an input code, extracting a word stream corresponding to the input code, generating a grammar tree according to pre-set grammar rules, and conducting semantic analysis to obtain a target code (S1), the input code comprising an application package code and a reference package code, and the target code comprising an application package target code and a reference package target code; according to data for implementing an application function in the application package target code, generating an application package bytecode file (S2); according to data for implementing an interface call in the reference package target code, generating a reference package bytecode file (S3); according to the application package bytecode file and the reference package bytecode file, generating a download file (S4). The present method pre-compiles the code and generates the download file that facilitates parsing, thereby reducing resource demands in embedded development, ensuring that the performance requirements in embedded development are met, and meeting a requirement for the download file being executable across platforms.

Description

一种软件代码编译方法及系统Method and system for compiling software code 技术领域technical field
本发明涉及计算机技术领域,具体涉及一种软件代码编译方法及系统。The present invention relates to the technical field of computers, in particular to a software code compilation method and system.
背景技术Background technique
在嵌入式开发中,安全模块具有资源有限且对性能要求较高的特点,但是传统上的语言系统无法满足嵌入式模块多变的用户使用场景,无法在资源有限的情况下满足较高的性能要求,同时无法满足同一个软件代码在不同嵌入式模块上都能运行的要求。In embedded development, security modules have the characteristics of limited resources and high performance requirements, but traditional language systems cannot meet the changing user usage scenarios of embedded modules, and cannot meet high performance with limited resources. requirements, and cannot meet the requirements that the same software code can run on different embedded modules.
故而,为解决现有的技术问题,需要一种代码编译技术,满足当前嵌入式开发的技术需求。Therefore, in order to solve the existing technical problems, a code compilation technology is required to meet the technical requirements of current embedded development.
发明内容SUMMARY OF THE INVENTION
本申请实施例提供一种软件代码编译方法及系统,对代码进行预先编译,生成便于进行解析的下载文件,在嵌入式开发中,减少对资源的需求,为嵌入式开发中的性能需求提供保障,同时可以满足下载文件可以跨平台执行的需求。Embodiments of the present application provide a method and system for compiling software code, which pre-compiles the code to generate a download file that is easy to parse, reduces resource requirements in embedded development, and provides guarantee for performance requirements in embedded development , and at the same time, it can meet the requirements that the downloaded file can be executed across platforms.
第一方面,提供了一种软件代码编译方法,所述方法包括以下步骤:In a first aspect, a software code compilation method is provided, and the method includes the following steps:
接收输入代码,提取所述输入代码对应的单词流,根据预设的语法规则生成语法树,并进行语义分析,获得目标代码,所述输入代码包括应用包代码和引用包代码,所述目标代码包括由所述应用包代码生成的应用包目标代码和由所述引用包代码生成的引用包目标代码, 所述应用包代码以及所述应用包目标代码均包括运行时环境接口对应的代码;Receive an input code, extract the word stream corresponding to the input code, generate a syntax tree according to a preset grammar rule, and perform semantic analysis to obtain a target code, the input code includes an application package code and a reference package code, the target code including the application package target code generated by the application package code and the reference package target code generated by the reference package code, the application package code and the application package target code both include the code corresponding to the runtime environment interface;
根据所述应用包目标代码中实现应用功能的数据,生成应用包字节码文件;Generate an application package bytecode file according to the data implementing the application function in the application package target code;
根据所述引用包目标代码中实现接口调用的数据,生成引用包字节码文件;Generate a reference package bytecode file according to the data implementing the interface call in the reference package target code;
根据所述应用包字节码文件以及所述引用包字节码文件生成下载文件。A download file is generated according to the application package bytecode file and the reference package bytecode file.
具体的,所述接收输入代码,提取所述输入代码对应的单词流,根据预设的语法规则生成语法树,并进行语义分析,获得目标代码中,具体包括如下步骤:Specifically, the receiving the input code, extracting the word stream corresponding to the input code, generating a syntax tree according to a preset grammar rule, and performing semantic analysis to obtain the target code, specifically includes the following steps:
接收所述输入代码,并解析获得对应的单词流;Receive the input code, and parse to obtain the corresponding word stream;
根据预设的语法规则,识别所述单词流的语言范畴,并进行对应的语法检查,生成对应的语法树;According to preset grammar rules, identify the language category of the word stream, and perform corresponding grammar check to generate a corresponding grammar tree;
对所述语法树中的数据进行语义分析,并进行分类记录;Semantically analyze the data in the syntax tree, and classify and record;
根据分类记录后的数据生成目标代码。Generate object codes according to the classified and recorded data.
进一步的,在接收所述输入代码之前,所述方法还包括以下步骤:Further, before receiving the input code, the method further includes the following steps:
创建一常量池;Create a constant pool;
所述常量池用于分别以词条为单位存储所述方法支持的编程通用字符、编程语言关键字、通用应用程序接口关键字以及运行时环境接口关键字;The constant pool is used to store programming general characters, programming language keywords, general application programming interface keywords and runtime environment interface keywords supported by the method in terms of entries respectively;
所述常量池还用于当提取所述输入代码对应的所述单词流时,依 次以词条为单位存储所述输入代码引用的头文件中声明的变量和方法、所述输入代码中的自定义变量、自定义方法分别以词条为单位存入所述常量池中;The constant pool is also used to store the variables and methods declared in the header file referenced by the input code, the variables and methods in the input code in turn in units of entries when the word stream corresponding to the input code is extracted. Defined variables and custom methods are stored in the constant pool in units of entries respectively;
当所述单词流对应的任一所述词条已事先存在于所述常量池内时则不存入所述常量池,所述词条包含所述单词流内各单词对应的字符串名称、字符串属性以及字符串类别。When any of the entry corresponding to the word stream already exists in the constant pool, it is not stored in the constant pool, and the entry includes the string name, character string corresponding to each word in the word stream String properties and string categories.
具体的,所述引用包字节码文件包括一个二进制字节码文件以及一个二进制输出映射文件,所述二进制输出映射文件包括所述引用包字节码文件对应的版本信息、应用标识数据以及所包含的方法的描述信息。Specifically, the reference package bytecode file includes a binary bytecode file and a binary output mapping file, and the binary output mapping file includes version information corresponding to the reference package bytecode file, application identification data and all Contains description information for the method.
具体的,所述应用包字节码文件包括方法组件子文件、内存组件子文件、运行时方法组件子文件以及共享接口组件子文件。Specifically, the application package bytecode file includes a method component subfile, a memory component subfile, a runtime method component subfile, and a shared interface component subfile.
具体的,所述应用包字节码文件的方法组件子文件包括所述应用包中的所有方法的字节码,按照每个方法在所述应用包的源码中的声明顺序依次排列,各所述方法在应用包中的存储位置和方法名称均一一对应记录在所述常量池中;所述内存组件子文件记录对应的所述应用包中全局非易失空间的大小和初始值以及全局易失空间的大小值;Specifically, the method component subfile of the application package bytecode file includes the bytecodes of all methods in the application package, which are arranged in sequence according to the declaration order of each method in the source code of the application package. The storage location and method name of the method in the application package are recorded in the constant pool in a one-to-one correspondence; the memory component subfile records the size and initial value of the global non-volatile space in the corresponding application package and the global The size of the volatile space;
所述运行时方法组件子文件包括对应的所述应用包的运行时环境接口的偏移值,用于对应的应用包在安装、删除、激活、去激活时进行调用;The runtime method component subfile includes an offset value of the runtime environment interface of the corresponding application package, which is used for invoking the corresponding application package during installation, deletion, activation, and deactivation;
所述共享接口组件子文件包括对应的所述应用包声明的共享接口的个数以及每个接口方法的偏移值。The shared interface component subfile includes the number of shared interfaces declared by the corresponding application package and the offset value of each interface method.
具体的,所述根据所述应用包字节码文件以及所述引用包字节码文件生成下载文件,具体包括以下步骤:Specifically, generating the download file according to the application package bytecode file and the reference package bytecode file specifically includes the following steps:
根据所述应用包字节码文件以及所述引用包字节码文件,解析获得方法组件、内存组件、运行时方法组件以及共享接口组件,并结合预设的数据包以及应用标识数据,按照预设格式生成下载文件。According to the application package bytecode file and the reference package bytecode file, the method component, the memory component, the runtime method component and the shared interface component are obtained by parsing, and combined with the preset data package and application identification data, according to the preset Format to generate download files.
第二方面,提供了一种软件代码编译系统,所述系统包括:In a second aspect, a software code compilation system is provided, the system comprising:
软件代码编译单元,其用于接收输入代码,提取所述输入代码对应的单词流,根据预设的语法规则生成语法树,并进行语义分析,获得目标代码,所述输入代码包括应用包代码和引用包代码,所述目标代码包括由所述应用包代码生成的应用包目标代码和由所述引用包代码生成的引用包目标代码,所述应用包代码以及所述应用包目标代码均包括运行时环境接口对应的代码;A software code compiling unit, which is used for receiving an input code, extracting a word stream corresponding to the input code, generating a syntax tree according to a preset grammar rule, and performing semantic analysis to obtain a target code, where the input code includes an application package code and a Reference package code, the target code includes application package target code generated by the application package code and reference package target code generated by the reference package code, both the application package code and the application package target code include running The code corresponding to the time environment interface;
应用包生成单元,其用于根据所述应用包目标代码中实现应用功能的数据,生成应用包字节码文件;an application package generation unit, which is used for generating an application package bytecode file according to the data implementing the application function in the application package target code;
引用包生成单元,其用于根据所述引用包目标代码中实现接口调用的数据,生成引用包字节码文件;A reference package generation unit, which is used to generate a reference package bytecode file according to the data that implements the interface call in the reference package target code;
下载文件生成单元,其用于根据所述应用包字节码文件以及所述引用包字节码文件生成下载文件。A download file generating unit, configured to generate a download file according to the application package bytecode file and the reference package bytecode file.
具体的,所述软件代码编译单元具体用于:Specifically, the software code compiling unit is specifically used for:
接收所述输入代码,并解析获得对应的单词流;Receive the input code, and parse to obtain the corresponding word stream;
根据预设的语法规则,识别所述单词流的语言范畴,并进行对应的语法检查,生成对应的语法树;According to preset grammar rules, identify the language category of the word stream, and perform corresponding grammar check to generate a corresponding grammar tree;
对所述语法树中的数据进行语义分析,并进行分类记录;Semantically analyze the data in the syntax tree, and classify and record;
根据分类记录后的数据生成目标代码。Generate object codes according to the classified and recorded data.
进一步的,所述系统配置有一常量池;Further, the system is configured with a constant pool;
所述常量池用于分别以词条为单位存储所述系统支持的编程通用字符、编程语言关键字、通用应用程序接口关键字以及运行时环境接口关键字;The constant pool is used to store the programming general characters, programming language keywords, general application programming interface keywords and runtime environment interface keywords supported by the system respectively in terms of entries;
所述常量池还用于当所述软件代码编译单元提取所述输入代码对应的所述单词流时,依次以词条为单位存储所述输入代码引用的头文件中声明的变量和方法、所述输入代码中的自定义变量、自定义方法分别以词条为单位存入所述常量池中;The constant pool is also used to sequentially store the variables and methods declared in the header file referenced by the input code, The self-defined variables and self-defined methods in the above input code are stored in the constant pool in terms of entries respectively;
当所述单词流对应的任一所述词条已事先存在于所述常量池内时则不存入所述常量池,所述词条包含所述单词流内各单词对应的字符串名称、字符串属性以及字符串类别。When any of the entry corresponding to the word stream already exists in the constant pool, it is not stored in the constant pool, and the entry includes the string name, character string corresponding to each word in the word stream String properties and string categories.
具体的,所述引用包字节码文件包括一个二进制字节码文件以及一个二进制输出映射文件,所述二进制输出映射文件包括所述引用包字节码文件对应的版本信息、应用标识数据以及所包含的方法的描述信息。Specifically, the reference package bytecode file includes a binary bytecode file and a binary output mapping file, and the binary output mapping file includes version information corresponding to the reference package bytecode file, application identification data and all Contains description information for the method.
具体的,所述应用包字节码文件包括方法组件子文件、内存组件子文件、运行时方法组件子文件以及共享接口组件子文件。Specifically, the application package bytecode file includes a method component subfile, a memory component subfile, a runtime method component subfile, and a shared interface component subfile.
具体的,所述应用包字节码文件的方法组件子文件包括所述应用包中的所有方法的字节码,按照每个方法在所述应用包的源码中的声明顺序依次排列,各所述方法在应用包中的存储位置和方法名称均一 一对应记录在所述常量池中;Specifically, the method component subfile of the application package bytecode file includes the bytecodes of all methods in the application package, which are arranged in sequence according to the declaration order of each method in the source code of the application package. The storage location and method name of the method in the application package are recorded in the constant pool in one-to-one correspondence;
所述内存组件子文件记录对应的所述应用包中全局非易失空间的大小和初始值以及全局易失空间的大小值;The memory component subfile records the size and initial value of the global non-volatile space and the size value of the global volatile space in the corresponding application package;
所述运行时方法组件子文件包括对应的所述应用包的运行时环境接口的偏移值,用于对应的应用包在安装、删除、激活、去激活时进行调用;The runtime method component subfile includes an offset value of the runtime environment interface of the corresponding application package, which is used for invoking the corresponding application package during installation, deletion, activation, and deactivation;
所述共享接口组件子文件包括对应的所述应用包声明的共享接口的个数以及每个接口方法的偏移值。The shared interface component subfile includes the number of shared interfaces declared by the corresponding application package and the offset value of each interface method.
具体的,所述下载文件生成单元,其具体用于根据所述应用包字节码文件以及所述引用包字节码文件,解析获得方法组件、内存组件、运行时方法组件以及共享接口组件,并结合预设的数据包以及应用标识数据,按照预设格式生成下载文件。Specifically, the download file generating unit is specifically configured to parse and obtain a method component, a memory component, a runtime method component and a shared interface component according to the application package bytecode file and the reference package bytecode file, And combined with the preset data package and application identification data, the download file is generated according to the preset format.
本申请提供的技术方案带来的有益效果包括:The beneficial effects brought by the technical solution provided by this application include:
本申请提供了一种软件代码编译方法及系统,按照预设的语法规则对代码进行预先编译,生成便于进行解析的下载文件,在嵌入式开发中,减少对资源的需求,为嵌入式开发中的性能需求提供保障,满足下载文件可以跨平台执行的需求。The present application provides a method and system for compiling software code. The code is pre-compiled according to preset grammar rules, and a download file that is easy to be parsed is generated. It provides guarantees for the performance requirements of the downloaded files and meets the requirements that the downloaded files can be executed across platforms.
附图说明Description of drawings
为了更清楚地说明本申请实施例中的技术方案,下面将对实施例描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的 附图仅仅是本申请的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。In order to illustrate the technical solutions in the embodiments of the present application more clearly, the following briefly introduces the drawings that are used in the description of the embodiments. Obviously, the drawings in the following description are only some embodiments of the present application. For those of ordinary skill in the art, other drawings can also be obtained from these drawings without creative effort.
图1为本申请实施例一提供的软件代码编译方法的步骤流程图;1 is a flowchart of steps of a software code compiling method provided in Embodiment 1 of the present application;
图2为本申请实施例一提供的软件代码编译系统在进行代码编译时的流程框图;2 is a flowchart of the software code compiling system provided by the first embodiment of the present application when compiling code;
图3为本申请实施例一提供的软件代码编译系统在生成下载文件时的流程框图;3 is a flowchart of the software code compilation system provided in Embodiment 1 of the present application when a download file is generated;
图4为本申请实施例一提供的软件代码编译系统中虚拟机运行时的原理框图;FIG. 4 is a schematic block diagram of the runtime of a virtual machine in the software code compilation system provided by Embodiment 1 of the present application;
图5为本申请实施例二提供的软件代码编译系统的结构框图;5 is a structural block diagram of a software code compiling system provided by Embodiment 2 of the present application;
附图标记:Reference number:
1、软件代码编译单元;2、应用包生成单元;3、引用包生成单元;4、下载文件生成单元。1. Software code compilation unit; 2. Application package generation unit; 3. Reference package generation unit; 4. Download file generation unit.
具体实施方式detailed description
为使本申请实施例的目的、技术方案和优点更加清楚,下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例是本申请的一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员在没有做出创造性劳动的前提下所获得的所有其他实施例,都属于本申请保护的范围。In order to make the purposes, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments It is a part of the embodiments of this application, but not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative work shall fall within the protection scope of the present application.
以下结合附图对本发明的实施例作进一步详细说明。The embodiments of the present invention will be described in further detail below with reference to the accompanying drawings.
本发明实施例提供一种软件代码编译方法及系统,按照预设的语 法规则对代码进行预先编译,生成便于进行解析的下载文件,在嵌入式开发中,减少对资源的需求,为嵌入式开发中的性能需求提供保障,满足下载文件可以跨平台执行的需求。Embodiments of the present invention provide a method and system for compiling software code, which pre-compiles the code according to preset grammar rules, and generates a download file that is easy to parse. The performance requirements in the file are guaranteed to meet the requirements that the downloaded files can be executed across platforms.
为达到上述技术效果,本申请的总体思路如下:In order to achieve the above-mentioned technical effect, the general idea of the application is as follows:
一种软件代码编译方法,该方法包括以下步骤:A software code compilation method, the method includes the following steps:
S1、接收输入代码,提取输入代码对应的单词流,根据预设的语法规则生成语法树,并进行语义分析,获得目标代码,输入代码包括应用包代码和引用包代码,目标代码包括由应用包代码生成的应用包目标代码和由引用包代码生成的引用包目标代码,应用包代码以及应用包目标代码均包括运行时环境接口对应的代码;S1. Receive an input code, extract a word stream corresponding to the input code, generate a syntax tree according to a preset grammar rule, and perform semantic analysis to obtain a target code, the input code includes an application package code and a reference package code, and the target code includes the application package code. The application package target code generated by the code and the reference package target code generated by the reference package code, the application package code and the application package target code include the code corresponding to the runtime environment interface;
S2、根据应用包目标代码中实现应用功能的数据,生成应用包字节码文件;S2. Generate an application package bytecode file according to the data implementing the application function in the application package target code;
S3、根据引用包目标代码中实现接口调用的数据,生成引用包字节码文件;S3. Generate a reference package bytecode file according to the data in the reference package target code that implements the interface call;
S4、根据应用包字节码文件以及引用包字节码文件生成下载文件。S4. Generate a download file according to the application package bytecode file and the reference package bytecode file.
以下结合附图对本发明的实施例作进一步详细说明。The embodiments of the present invention will be described in further detail below with reference to the accompanying drawings.
实施例一Example 1
参见图1~4所示,本发明实施例提供一种软件代码编译方法,该方法包括以下步骤:Referring to FIGS. 1 to 4, an embodiment of the present invention provides a software code compilation method, and the method includes the following steps:
S1、接收输入代码,提取输入代码对应的单词流,根据预设的语法规则生成语法树,并进行语义分析,获得目标代码,输入代码包括应用包代码和引用包代码,目标代码包括由应用包代码生成的应用包目标代码和由引用包代码生成的引用包目标代码,应用包代码以及应用包目标代码均包括运行时环境接口对应的代码;S1. Receive an input code, extract a word stream corresponding to the input code, generate a syntax tree according to a preset grammar rule, and perform semantic analysis to obtain a target code, the input code includes an application package code and a reference package code, and the target code includes the application package code. The application package target code generated by the code and the reference package target code generated by the reference package code, the application package code and the application package target code include the code corresponding to the runtime environment interface;
S2、根据应用包目标代码中实现应用功能的数据,生成应用包字节码文件;S2. Generate an application package bytecode file according to the data implementing the application function in the application package target code;
S3、根据引用包目标代码中实现接口调用的数据,生成引用包字节码文件;S3. Generate a reference package bytecode file according to the data in the reference package target code that implements the interface call;
S4、根据应用包字节码文件以及引用包字节码文件生成下载文件。S4. Generate a download file according to the application package bytecode file and the reference package bytecode file.
本申请实施例中,首先接收输入代码,进行具体的工作流程:In the embodiment of the present application, the input code is first received, and the specific workflow is performed:
1)对输入代码进行词法分析,即对输入代码进行解析,获得其对应的单词流,1) Perform lexical analysis on the input code, that is, parse the input code to obtain its corresponding word stream,
2)对单词流进行语法分析,即按照预设的语法规则,从单词流中识别出对应的语法范畴,进行语法检查,并进行对应的语法检查,生成对应的语法树,2) Syntax analysis is performed on the word stream, that is, according to the preset grammar rules, the corresponding grammar category is identified from the word stream, the grammar check is performed, and the corresponding grammar check is performed to generate a corresponding grammar tree,
3)对语法分析的结果进行语义分析,生成相应的中间代码,将各种声明记录至符号表,记录声明类型,记录表达式类型等,3) Semantically analyze the results of the syntax analysis, generate the corresponding intermediate code, record various declarations to the symbol table, record the declaration type, record the expression type, etc.,
4)根据语义分析的结果进行代码生成,最终获得目标代码,4) Code generation is performed according to the result of semantic analysis, and the target code is finally obtained,
其中,输入代码包括应用包代码和引用包代码,目标代码包括由应用包代码生成的应用包目标代码和由引用包代码生成的引用包目标代码,应用包代码以及应用包目标代码均包括运行时环境接口对应的代码,The input code includes the application package code and the reference package code, the target code includes the application package target code generated by the application package code and the reference package target code generated by the reference package code, and both the application package code and the application package target code include the runtime The code corresponding to the environment interface,
实际情况下,在进行语法分析时,按照编码顺序对输入代码进行扫描,将获取到的单词按照一定的规则添加到预设的常量池,常量池中的每个词条都包含了单词对应的字符串名称、属性、类别等信息,In practice, when performing grammatical analysis, the input code is scanned according to the coding order, and the acquired words are added to the preset constant pool according to certain rules. Each entry in the constant pool contains the corresponding word of the word. String name, attribute, category and other information,
在进行语法分析时,是对全局声明层面的分析,包括全局变量、枚举类型、函数等的解析,When performing syntax analysis, it is the analysis of the global declaration level, including the analysis of global variables, enumeration types, functions, etc.
在进行语义分析时,是对语句层面的分析,分析函数中除了声明之外的其他部分代码的语法和语义,When performing semantic analysis, it is the analysis at the statement level, and the syntax and semantics of other parts of the code in the function except the declaration are analyzed.
进行目标代码的生成过程,是对表达式层面的分析,对程序中各 种表达式进行解析,生成对应的字节码表达式。The object code generation process is to analyze the expression level, analyze various expressions in the program, and generate corresponding bytecode expressions.
其中,源文件,即输入代码的编译的输出,即目标代码为应用包字节码文件和引用包字节码文件,其中实现了运行时环境接口(process、select、deselect、install、uninstall、getSccLibInterface)的应用会生成对应的应用包字节码文件,而纯方法包(无运行时环境接口)和具有共享接口的应用会生成引用包字节码文件,每一个源文件都对应生成一个字节码文件。Among them, the source file, that is, the output of the compilation of the input code, that is, the target code is the application package bytecode file and the reference package bytecode file, which implements the runtime environment interface (process, select, deselect, install, uninstall, getSccLibInterface ) applications will generate corresponding application package bytecode files, while pure method packages (no runtime environment interface) and applications with shared interfaces will generate reference package bytecode files, each source file correspondingly generates a byte code file.
本申请实施例中,按照预设的语法规则对代码进行预先编译,生成便于进行解析的下载文件,在嵌入式开发中,减少对资源的需求,为嵌入式开发中的性能需求提供保障,满足下载文件可以跨平台执行的需求。In the embodiment of the present application, the code is pre-compiled according to the preset grammar rules, and a download file that is easy to parse is generated. In the embedded development, the demand for resources is reduced, and the performance demand in the embedded development is guaranteed to meet the requirements. Download files can perform cross-platform requirements.
将对输入代码进行编译时,具体可以进行多级处理,即When compiling the input code, multi-level processing can be performed, that is,
(1)通用的单个字符(ASCII码);(1) Common single character (ASCII code);
(2)代码编码语言支持的关键字;(2) Keywords supported by the code encoding language;
(3)嵌入式模块支持的API关键字;(3) API keywords supported by embedded modules;
(4)应用自定义变量和方法;(4) Apply custom variables and methods;
(5)常用表达式;(5) Common expressions;
在具体操作时,预编译过程中,先(1)~(3)中的字符按照顺序添加到常量池,当支持的关键字和API一定时该部分的常量池数据是固定的,然后在代码编译过程中将(4)中的字符按照顺序添加到常量池中。In the specific operation, during the pre-compilation process, the characters in (1) to (3) are added to the constant pool in order. When the supported keywords and APIs are certain, the constant pool data in this part is fixed, and then in the code The characters in (4) are added to the constant pool in order during compilation.
常量池中每个成员对应的字符串都是唯一的,成员结构体中标记了该字符串的顺序ID、完整字符串信息及校验压缩值,用于后续编码时对读取的字符串进行比较和校验。The string corresponding to each member in the constant pool is unique, and the sequence ID, complete string information and verification compression value of the string are marked in the member structure, which is used for the subsequent encoding of the read string. Compare and verify.
其中,API关键字可以进行升级,升级时在常量池中将新增的API关键字添加到原有API关键字后面,按照升级的先后顺序依次排列,高版本的API可以兼容低版本的API,保证升级前后的编译结果的向 下兼容性。Among them, API keywords can be upgraded. During the upgrade, the newly added API keywords are added to the original API keywords in the constant pool, and they are arranged in the order of upgrade. The higher version of the API can be compatible with the lower version of the API. Ensure backward compatibility of compilation results before and after the upgrade.
需要说明的是,输入代码和目标代码中实现了运行时环境接口的文件是应用包,嵌入式模块可以调用应用包的运行时环境接口来选择激活、运行应用包功能,由于防火墙安全要求应用包中的常用方法和变量只能在当前包中访问,不同应用包之间可以访问对方的共享接口方法;It should be noted that the file that implements the runtime environment interface in the input code and the target code is the application package. The embedded module can call the runtime environment interface of the application package to select the function of activating and running the application package. Because the firewall security requires the application package Common methods and variables in can only be accessed in the current package, and different application packages can access each other's shared interface methods;
输入代码和目标代码中未实现运行时环境接口的文件是引用包,引用包对外提供了一个映射,使它的方法可以被不同的应用包来调用。The files in the input code and the object code that do not implement the runtime environment interface are reference packages. The reference packages provide a mapping to the outside so that their methods can be called by different application packages.
本申请实施例获得的下载文件,在实际应用时,需要依靠虚拟机系统和运行时环境系统,The download file obtained by the embodiment of the present application needs to rely on the virtual machine system and the runtime environment system during practical application,
虚拟机系统用于处理下载文件,解析下载文件中的字节码,执行对应的应用包代码功能。运行时环境系统用于管理应用的生命周期、访问应用的运行时环境接口、进行应用运行时的防火墙管理。The virtual machine system is used to process the downloaded file, parse the bytecode in the downloaded file, and execute the corresponding application package code function. The runtime environment system is used to manage the life cycle of the application, access the runtime environment interface of the application, and manage the firewall when the application is running.
在运行时环境系统中,将每个实现了运行时环境接口的源文件都做为一个包,其实例化为应用applet,运行时环境接口的主要作用为:In the runtime environment system, each source file that implements the runtime environment interface is regarded as a package, which is instantiated as an application applet. The main functions of the runtime environment interface are:
根据选择指令激活,去激活指定应用;Activate according to the selection instruction to deactivate the specified application;
将收到的指令分发给当前应用,即调用应用的入口函数;Distribute the received instruction to the current application, that is, call the entry function of the application;
防火墙管理,防止不同包下面的应用互相访问。Firewall management to prevent applications under different packages from accessing each other.
虚拟机系统,其核心是虚拟机字节码,虚拟机系统的基本原理是字节码、堆栈、解释器共同作用,字节码负责程序的语法操作符实现,堆栈负责参数,变量和临时操作数等数据的存放,解释器针对程序指针中获取的字节码进行解析,三者一起实现了编程语言的表达式。The core of the virtual machine system is the virtual machine bytecode. The basic principle of the virtual machine system is that the bytecode, the stack and the interpreter work together. The bytecode is responsible for the implementation of the syntax operators of the program, and the stack is responsible for the parameters, variables and temporary operations. The storage of numbers and other data, the interpreter parses the bytecode obtained in the program pointer, and the three together realize the expression of the programming language.
生成下载文件时,具体可以借助一个下载文件转换工具,其作用是将应用包字节码文件转换成GP下载脚本,When generating a download file, you can use a download file conversion tool, which is used to convert the application package bytecode file into a GP download script.
首先生成一个十六进制的GP文件,然后从应用包字节码文件中提取特征8中的各个组件数据,按照组件标识、长度和数据的TLV格式 依次将各组件添加到GP文件中,另外根据上述第2点描述,运行时环境系统引入了包和应用的概念,所以在下载文件转换工具中开发者可以根据要求输入当前源文件的包和应用的AID,在每个嵌入式模块系统中,包和应用的AID都是唯一的,运行时环境系统可以根据该AID查找到对应的应用。First generate a hexadecimal GP file, then extract each component data in feature 8 from the application package bytecode file, and add each component to the GP file in turn according to the component ID, length and TLV format of the data. According to the description of point 2 above, the runtime environment system introduces the concept of package and application, so in the download file conversion tool, the developer can input the package of the current source file and the AID of the application as required, in each embedded module system , the AIDs of packages and applications are unique, and the runtime environment system can find the corresponding application according to the AID.
需要说明的是,一个应用包代码含有运行时环境接口对应的代码,同样,一个应用包目标代码含有运行时环境接口对应的代码;It should be noted that an application package code contains code corresponding to the runtime environment interface, and similarly, an application package target code contains code corresponding to the runtime environment interface;
输入代码中包括至少一个应用包代码,另外可能含有一个、多个或者没有引用包代码,同样,目标代码中包括至少一个应用包目标代码,另外可能含有一个、多个或者没有引用包目标代码;The input code includes at least one application package code, and may contain one, more or no reference package code. Similarly, the target code includes at least one application package object code, and may contain one, more or no reference package object code;
一个应用包代码在实际应用时,可能需要运用多个引用包代码,同样,一个应用包目标代码在实际应用时,可能需要运用多个引用包目标代码。In actual application, one application package code may need to use multiple reference package codes, and similarly, one application package object code may need to use multiple reference package object codes in actual application.
具体的,在接收输入代码之前,方法还包括以下步骤:Specifically, before receiving the input code, the method further includes the following steps:
创建一常量池;Create a constant pool;
常量池用于分别以词条为单位存储方法支持的编程通用字符、编程语言关键字、通用应用程序接口关键字以及运行时环境接口关键字;The constant pool is used to store the programming general characters, programming language keywords, general application programming interface keywords and runtime environment interface keywords supported by the method in terms of entries;
常量池还用于当提取输入代码对应的单词流时,依次以词条为单位存储输入代码引用的头文件中声明的变量和方法、输入代码中的自定义变量、自定义方法分别以词条为单位存入常量池中;The constant pool is also used to store the variables and methods declared in the header file referenced by the input code, the custom variables and custom methods in the input code in terms of terms, respectively, when the word stream corresponding to the input code is extracted. The unit is stored in the constant pool;
当单词流对应的任一词条已事先存在于常量池内时则不存入常量池,词条包含单词流内各单词对应的字符串名称、字符串属性以及字符串类别。When any entry corresponding to the word stream already exists in the constant pool, it is not stored in the constant pool. The entry contains the string name, string attribute and string category corresponding to each word in the word stream.
需要说明的是,在进行软件代码编译时,会创建常量池,常量池是词法分析的基础,常量池中每一项ID表示单词流中的一个单词,其基本结构体由单词标识、压缩编码、单词名称、单词长度、单词类型、 已使用标识、方法偏移标识组成,其中,单词标识表示该单词在常量池中的位置,压缩编码是表示单词字符串的压缩编码,单词名称是单词的原始字符串描述,单词长度是单词的字符串长度,单词类型表示单词的函数类型,已使用标识表示该单词是否在源程序中被调用,方法偏移标识表示单词为函数时该函数在字节码方法组件中的偏移值;It should be noted that when compiling software code, a constant pool will be created. The constant pool is the basis of lexical analysis. Each ID in the constant pool represents a word in the word stream, and its basic structure is identified by the word, compressed and encoded. , word name, word length, word type, used identifier, and method offset identifier, where the word identifier represents the position of the word in the constant pool, the compression encoding is the compression encoding representing the word string, and the word name is the word The original string description, the word length is the string length of the word, the word type indicates the function type of the word, the used flag indicates whether the word is called in the source program, the method offset flag indicates that when the word is a function, the function is in bytes. The offset value in the code method component;
偏移值具体是指数据存储位置。The offset value specifically refers to the data storage location.
具体的,在实际操作时,常量池的组成:Specifically, in actual operation, the composition of the constant pool:
1、编译器所支持的编程语言通用关键字;1. Common keywords of programming languages supported by the compiler;
2、嵌入式模块应用的运行时环境接口;2. Runtime environment interface of embedded module application;
3、嵌入式模块应用的常用API接口;3. Common API interfaces for embedded module applications;
4、外部引用包中输入的共享方法接口;4. The shared method interface entered in the external reference package;
5、解析源文件和头文件时搜索到的新声明的单词,具体包括新的宏定义、头文件函数声明、变量声明等,由于c语言中所有单词都是先声明后调用的规则,所以在搜索到一个声明时先检查该声明是否在常量池中,如果不在则将该单词添加到常量池中,其中单词标识是固定值,表示是该常量池成员是字符串;5. Newly declared words searched when parsing source files and header files, including new macro definitions, header file function declarations, variable declarations, etc. Since all words in C language are the rules of first declaration and then calling, so in When searching for a statement, first check whether the statement is in the constant pool, if not, add the word to the constant pool, where the word identifier is a fixed value, indicating that the constant pool member is a string;
6、对于上述2和3点描述的常量池成员,其单词标识是固定值,表示该成员是字符串;6. For the constant pool members described in points 2 and 3 above, the word identifier is a fixed value, indicating that the member is a string;
7、对于上述第1点描述的常量池成员,其单词标识是在通用关键字枚举中的顺序位置;7. For the constant pool member described in point 1 above, the word identifier is the ordinal position in the general keyword enumeration;
8、通用关键字枚举按照类型、编程语言关键字、操作符的顺序排列,其单词标识起始数值为128;8. The general keyword enumeration is arranged in the order of type, programming language keyword and operator, and the starting value of the word identifier is 128;
9、上述第8点中的类型包括数字、函数、系统函数、共享函数、全局变量、局部变量等,标明每个常量池成员的类型含义;9. The types in point 8 above include numbers, functions, system functions, shared functions, global variables, local variables, etc., indicating the type meaning of each constant pool member;
10、对于单个字符的声明使用其对应的ASCII码作为单词标识值,其范围是0~127,对于多个字符的声明按照上述1~8的描述来定义其单 词标识值;10. For the declaration of a single character, use its corresponding ASCII code as the word identification value, and its range is 0 to 127. For the declaration of multiple characters, define its word identification value according to the descriptions of 1 to 8 above;
11、常量池成员的压缩编码是该单词字符串名称的压缩编码,对于单词标识小于128的成员其压缩编码为0,其他成员的压缩编码是该单词所有字符的ASCII码的一种哈希值运算;11. The compression encoding of the constant pool member is the compression encoding of the string name of the word. For members whose word ID is less than 128, the compression encoding is 0. The compression encoding of other members is a hash value of the ASCII codes of all characters of the word. operation;
12、常量池成员的单词名称和单词长度是其单词的完整字符串描述;12. The word name and word length of the constant pool member is the complete string description of its word;
13、常量池成员的单词类型是该单词代表的类型,如上述9所示;特别的当单词为引用包字节码文件输入的函数时,其类型为共享函数;13. The word type of the constant pool member is the type represented by the word, as shown in 9 above; especially when the word is a function input by referencing the package bytecode file, its type is a shared function;
14、常量池成员的已使用标识属性表示该单词是否被源文件使用,如果没有使用则在最终链接时不做考虑,这样可以加快链接速度,优化使用空间;14. The used identification attribute of the constant pool member indicates whether the word is used by the source file. If it is not used, it will not be considered in the final link, which can speed up the link speed and optimize the use space;
15、常量池成员的方法偏移标识属性表示该单词为函数方法时,函数对应的字节码在字节码区间中的偏移值,即偏移位置,即存储位置,当函数被调用时通过常量池查找到对应的成员后用方法偏移值进行跳转。15. The method offset identification attribute of the constant pool member indicates that when the word is a function method, the offset value of the bytecode corresponding to the function in the bytecode interval, that is, the offset position, that is, the storage location, when the function is called After finding the corresponding member through the constant pool, use the method offset value to jump.
由于存在多种API接口,故而存在一API接口集合,其内部顺序存储多种API接口。Since there are multiple API interfaces, there is an API interface set, which internally stores multiple API interfaces in sequence.
在实际操作过程中,常量池的作用是标记当前编译环境支持的关键字,以及源文件和头文件的变量、宏定义、函数声明,用于在解析源文件代码时读取单词后进行相应的语义分析。In the actual operation process, the function of the constant pool is to mark the keywords supported by the current compilation environment, as well as the variables, macro definitions, and function declarations of source files and header files, which are used to read words when parsing the source file code. Semantic Analysis.
另外,常量池中每个成员对应的单词字符串是唯一的,但是由于单词的字符串组成和长度不可控,单纯的使用字符串比较会存在性能和空间上的浪费,因此本申请实施例提供了一种性能和内存开销都有较大提升的匹配方法,具体分为3级步骤,其操作流程具体如下:In addition, the word string corresponding to each member in the constant pool is unique, but because the string composition and length of the word are uncontrollable, simply using string comparison will waste performance and space. Therefore, the embodiments of the present application provide A matching method with greatly improved performance and memory overhead is proposed, which is divided into three steps. The operation process is as follows:
第1级是单词标识比较,可以搜索出所有的单个字符单词和编程语言关键字单词,这些单词的单词标识是唯一的;The first level is the word identification comparison, which can search for all single character words and programming language keyword words, and the word identification of these words is unique;
第2级是压缩编码比较,可以搜索出常量池中所有唯一的单词标识对应的单词;The second level is compression encoding comparison, which can search for words corresponding to all unique word identifiers in the constant pool;
第3级是单词名称比较,可以完整匹配常量池中的单词;The third level is the word name comparison, which can completely match the words in the constant pool;
其中,匹配的基本顺序是1、2、3,只有当单词标识不唯一时才进行第3级的全字符串比较。Among them, the basic order of matching is 1, 2, 3, and the third-level full string comparison is performed only when the word identifier is not unique.
本申请实施例中,代码编译按照实际编码顺序来进行解析具体情况如下:In the embodiment of the present application, the code compilation is parsed according to the actual coding order. The specific conditions are as follows:
1、建立常量池表,将编程语言关键字、运行时环境系统函数、系统常用API等添加到常量池中;1. Establish a constant pool table, and add programming language keywords, runtime environment system functions, and common system APIs to the constant pool;
2、按照从上到下,从左到右的顺序读取输入的源文件;2. Read the input source file in the order from top to bottom and left to right;
3、当源文件中读取的单词为头文件时,先从源文件所在的目录中查找该头文件,如果不存在则从编译器的安装目录下查找该头文件;在头文件中从上到下获取相关单词,搜索获取的单词是否在常量池中,如果不存在则将该单词添加到常量池;3. When the word read in the source file is a header file, first look for the header file in the directory where the source file is located. If it does not exist, look for the header file from the compiler's installation directory; in the header file from above Go to the next to get the relevant word, search whether the word obtained is in the constant pool, if not, add the word to the constant pool;
4、当源文件中读取的单词为函数时,搜索该单词是否在常量池中,如果不存在则将该单词添加到常量池;4. When the word read in the source file is a function, search whether the word is in the constant pool, if not, add the word to the constant pool;
5、记录源文件中函数中第一行代码的行号,按顺序解析函数中各条语句,根据虚拟机系统中定义的虚拟机字节码生成函数语句相应的字节码,每个函数的字节码都按源文件中声明的顺序排列,形成字节码区间;5. Record the line number of the first line of code in the function in the source file, parse each statement in the function in sequence, and generate the corresponding bytecode of the function statement according to the virtual machine bytecode defined in the virtual machine system. The bytecodes are arranged in the order declared in the source file to form a bytecode range;
6、每个函数在字节码区间中的偏移值记录到该单词对应常量池成员的方法偏移标识属性中;6. The offset value of each function in the bytecode interval is recorded in the method offset identification attribute of the constant pool member corresponding to the word;
7、当解析到函数调用时先搜索该单词在常量池中的索引,如果其单词类型为系统函数,则字节码设置为系统函数调用;如果是共享函数,则搜索共享函数列表,查找该函数在共享包中的方法偏移值;如果是普通函数则直接使用常量池中方法偏移标识参数做为方法偏移 值。7. When parsing to a function call, first search the index of the word in the constant pool. If the word type is a system function, the bytecode is set to a system function call; if it is a shared function, search the shared function list to find the The method offset value of the function in the shared package; if it is a normal function, the method offset identification parameter in the constant pool is directly used as the method offset value.
具体的,编程代码中存在4种类型的基本函数:Specifically, there are 4 types of basic functions in programming code:
1)运行时环境接口,用于运行时环境选择和切换,其他函数不能调用运行时环境接口;1) The runtime environment interface is used for runtime environment selection and switching. Other functions cannot call the runtime environment interface;
2)API接口,即通用的嵌入式模块API接口函数,其实现方法声明和顺序在API接口集合中固定,应用中可以进行调用;2) API interface, that is, the general embedded module API interface function, whose implementation method declaration and order are fixed in the API interface set, and can be called in the application;
3)引用包共享函数,即外部自定义的函数包,该函数包有自己的AID和方法列表,源文件引用后可以调用该包中的共享函数;3) Reference package shared function, that is, an external custom function package. This function package has its own AID and method list. After the source file is referenced, the shared function in the package can be called;
4)源文件自定义的函数,应用可以自由调用。4) The function defined by the source file can be called freely by the application.
其中,运行时环境接口和API接口的常量池单词类型类型为系统函数,其每个函数对应的单词标识值是固定且唯一的;引用包函数的类型为共享函数,源文件自定义函数的单词类型类型为普通函数,其单词标识值都是字符串类型;Among them, the constant pool word type of the runtime environment interface and API interface is a system function, and the word identifier value corresponding to each function is fixed and unique; the type of the reference package function is a shared function, and the word of the source file custom function The type type is an ordinary function, and its word identification value is a string type;
API接口按照在API接口集合中声明的顺序,每个函数对应一个ID,用于虚拟机系统中系统函数调用字节码的输入;The API interface is in the order declared in the API interface set, and each function corresponds to an ID, which is used for the input of the bytecode of the system function call in the virtual machine system;
以上步骤就实现了嵌入式模块应用的基本编译过程,输出为应用包字节码文件。The above steps implement the basic compilation process of the embedded module application, and the output is the application package bytecode file.
具体的,引用包字节码文件包括一个二进制字节码文件以及一个二进制输出映射文件,二进制输出映射文件包括引用包字节码文件对应的版本信息、应用标识数据以及所包含的方法的描述信息。Specifically, the reference package bytecode file includes a binary bytecode file and a binary output mapping file, and the binary output mapping file includes version information corresponding to the reference package bytecode file, application identification data, and description information of the included methods. .
具体的,应用包字节码文件包括方法组件子文件、内存组件子文件、运行时方法组件子文件以及共享接口组件子文件。Specifically, the application package bytecode file includes a method component subfile, a memory component subfile, a runtime method component subfile, and a shared interface component subfile.
需要说明的是,此处的子文件,并非代表上下级的关系,而是应用包字节码文件中存在多个部分,分别是方法组件部分、内存组件部分、运行时方法组件部分以及共享接口组件部分,此处为了描述方面,称呼为子文件。It should be noted that the sub-files here do not represent the relationship between the upper and lower levels, but there are multiple parts in the application package bytecode file, namely the method component part, the memory component part, the runtime method component part and the shared interface. Component parts, here for describing aspects, are called subfiles.
其中,应用包字节码文件的方法组件子文件包括应用包中的所有方法的字节码,按照每个方法在应用包的源码中的声明顺序依次排列,各方法在应用包中的存储位置和方法名称均一一对应记录在常量池中;Among them, the method component subfile of the application package bytecode file includes the bytecodes of all methods in the application package, which are arranged in order according to the declaration order of each method in the source code of the application package, and the storage location of each method in the application package and the method name are recorded in the constant pool in one-to-one correspondence;
内存组件子文件记录对应的应用包中全局非易失空间(NVM,Non-volatile Memory)的大小和初始值以及全局易失空间(RAM,Random Access Memory)的大小值;The memory component subfile records the size and initial value of the global non-volatile space (NVM, Non-volatile Memory) and the size value of the global volatile space (RAM, Random Access Memory) in the corresponding application package;
运行时方法组件子文件包括对应的应用包的运行时环境接口的偏移值,用于对应的应用包在安装、删除、激活、去激活时进行调用;The runtime method component subfile includes the offset value of the runtime environment interface of the corresponding application package, which is used for invoking the corresponding application package during installation, deletion, activation, and deactivation;
共享接口组件子文件包括对应的应用包声明的共享接口的个数以及每个接口方法的偏移值。The shared interface component subfile includes the number of shared interfaces declared by the corresponding application package and the offset value of each interface method.
具体的,根据应用包字节码文件以及引用包字节码文件生成下载文件,具体包括以下步骤:Specifically, generating a download file according to the application package bytecode file and the reference package bytecode file specifically includes the following steps:
根据应用包字节码文件以及引用包字节码文件,解析获得方法组件、内存组件、运行时方法组件以及共享接口组件,并结合预设的数据包以及应用标识数据,按照预设格式生成下载文件。According to the application package bytecode file and the reference package bytecode file, the method components, memory components, runtime method components and shared interface components are obtained by parsing, and combined with the preset data package and application identification data, the download is generated according to the preset format document.
在此,对实际应用时的虚拟机系统进行说明:Here, the virtual machine system in practical application is described:
虚拟机系统为在嵌入式模块上实现,能够下载虚拟机对应的字节码文件,在卡内执行对应的字节码流程;The virtual machine system is implemented on the embedded module, which can download the bytecode file corresponding to the virtual machine and execute the corresponding bytecode process in the card;
虚拟机运行时的堆栈、RAM(易失性存储空间)、NVM(非易失性存储空间)资源都是统一寻址,虚拟机系统的地址结构分布图对资源的定义如下:The stack, RAM (volatile storage space), and NVM (non-volatile storage space) resources when the virtual machine is running are all uniformly addressed. The address structure distribution diagram of the virtual machine system defines the resources as follows:
虚拟机堆栈:包括模拟寄存器、操作栈和程序栈;Virtual machine stack: including analog registers, operation stacks and program stacks;
RAM:应用中申请的RAM空间;RAM: RAM space applied for in the application;
NVM资源:NVM resources:
静态NVM:应用包字节码文件下载到卡内占用的空间,应用定义 的给定大小的全局NVM资源以及其他个人化资源;Static NVM: The space occupied by the application package bytecode file downloaded to the card, the global NVM resource of a given size defined by the application, and other personalized resources;
动态NVM:应用运行过程中动态申请的NVM资源;Dynamic NVM: NVM resources dynamically applied for during application running;
不同的虚拟机系统实现可以根据实际情况进行各资源比重的分配。Different virtual machine system implementations can allocate the proportion of each resource according to the actual situation.
在此,对实际应用时的运行时环境系统进行说明:Here, the runtime environment system in actual application is explained:
运行时管理系统负责管理卡片和应用的生命周期,应用选定和防火墙保护等,其中:The runtime management system is responsible for managing the life cycle of cards and applications, application selection and firewall protection, etc., where:
应用的生命周期由5个运行时环境结构对应的方法构成,install方法负责应用安装时的私有实例化,select方法负责应用激活,process方法是应用处理命令的入口,负责接收和处理APDU命令,deselect方法负责应用去激活,uninstall方法负责应用删除时的私有去实例化操作,每个函数对应应用的一个生命周期阶段;The life cycle of an application consists of five methods corresponding to the runtime environment structure. The install method is responsible for the private instantiation of the application during installation, the select method is responsible for application activation, and the process method is the entry for application processing commands, responsible for receiving and processing APDU commands, deselect The method is responsible for application deactivation, the uninstall method is responsible for the private de-instantiation operation when the application is deleted, and each function corresponds to a life cycle stage of the application;
由于嵌入式模块上是多应用场景,所以在执行指令前必须先选定要求的应用,应用选定通过逻辑通道管理和选择文件命令来执行,这2条指令被运行时环境系统用来指明一个逻辑通道的会话中的被激活的应用实例,一旦某个实例被选定,这个应用实例将接收所有后续的分发给那个逻辑通道的私有命令,直到这个应用实例变为非选定状态。Because there are multiple application scenarios on the embedded module, the required application must be selected before executing the command. The application selection is executed through the logical channel management and selection file commands. These two commands are used by the runtime environment system to specify an An activated application instance in a session of a logical channel, once an instance is selected, this application instance will receive all subsequent private commands distributed to that logical channel until the application instance becomes deselected.
运行时环境系统的防火墙提供的保护避免了最频繁的可预见的安全隐患:导致敏感数据被泄露给其它的应用的开发者的失误和设计遗漏。一个应用能够从一个可以公开访问的接口中获得对其他源文件的访问。防火墙也提供了抵抗不正确的代码的保护。如果不正确的代码被加载到卡上,防火墙仍然能够保护那些已有数据不被这个恶意代码访问。The protection provided by the runtime environment system's firewall avoids the most frequent foreseeable security breaches: developer mistakes and design omissions that result in sensitive data being leaked to other applications. An application can gain access to other source files from a publicly accessible interface. Firewalls also provide protection against incorrect code. If incorrect code is loaded onto the card, the firewall can still protect existing data from being accessed by this malicious code.
在防火墙的基础上,运行时环境系统也提供了允许不同应用进行交互的机制,即共享接口机制,共享接口定义了该应用中所有可以被共享的接口方法的集合,这些方法可以在不同的上下文(包和应用)环境 中进行调用。On the basis of the firewall, the runtime environment system also provides a mechanism that allows different applications to interact, that is, the shared interface mechanism. The shared interface defines the set of all interface methods that can be shared in the application. These methods can be used in different contexts. (package and application) environment.
在此,对实际应用时的下载文件转换工具进行说明:Here, the download file conversion tool in practical application is described:
下载文件转换工具的输入包括源文件的包AID和输入的应用包字节码文件路径;The input of the download file conversion tool includes the package AID of the source file and the input application package bytecode file path;
下载文件转换工具的输出包括固定格式的下载脚本文件;The output of the download file conversion tool includes a fixed format download script file;
其基本原理是提取应用包字节码文件中的方法组件、内存组件、运行时方法组件、共享接口方法组件的数据,连同输入的包AID一起组织成固定格式的下载文件。The basic principle is to extract the data of method components, memory components, runtime method components, and shared interface method components in the application package bytecode file, and organize it into a fixed-format download file together with the input package AID.
基于同一发明构思,本申请提供了实施例一对应的系统的实施例,详见实施例二Based on the same inventive concept, the present application provides an embodiment of the system corresponding to Embodiment 1. For details, please refer to Embodiment 2
实施例二 Embodiment 2
参见图5所示,本发明实施例提供一种软件代码编译系统,该系统包括:Referring to Fig. 5, an embodiment of the present invention provides a software code compilation system, the system includes:
软件代码编译单元1,其用于接收输入代码,提取输入代码对应的单词流,根据预设的语法规则生成语法树,并进行语义分析,获得目标代码,输入代码包括应用包代码和引用包代码,目标代码包括由应用包代码生成的应用包目标代码和由引用包代码生成的引用包目标代码,应用包代码以及应用包目标代码均包括运行时环境接口对应的代码;A software code compiling unit 1, which is used for receiving input codes, extracting word streams corresponding to the input codes, generating syntax trees according to preset grammar rules, and performing semantic analysis to obtain target codes, and the input codes include application package codes and reference package codes , the target code includes the application package target code generated by the application package code and the reference package target code generated by the reference package code, and both the application package code and the application package target code include the code corresponding to the runtime environment interface;
应用包生成单元2,其用于根据应用包目标代码中实现应用功能的数据,生成应用包字节码文件;An application package generation unit 2, which is used to generate an application package bytecode file according to the data that realizes the application function in the application package target code;
引用包生成单元3,其用于根据引用包目标代码中实现接口调用的数据,生成引用包字节码文件;A reference package generation unit 3, which is used to generate a reference package bytecode file according to the data that realizes the interface call in the reference package target code;
下载文件生成单元4,其用于根据应用包字节码文件以及引用包字节码文件生成下载文件。The download file generating unit 4 is configured to generate a download file according to the application package bytecode file and the reference package bytecode file.
本申请实施例中,首先软件代码编译单元1接收输入代码,进行具体的工作流程:In the embodiment of the present application, first the software code compiling unit 1 receives the input code, and performs a specific workflow:
1)对输入代码进行词法分析,即对输入代码进行解析,获得其对应的单词流,1) Perform lexical analysis on the input code, that is, parse the input code to obtain its corresponding word stream,
2)对单词流进行语法分析,即按照预设的语法规则,从单词流中识别出对应的语法范畴,进行语法检查,并进行对应的语法检查,生成对应的语法树,2) Syntax analysis is performed on the word stream, that is, according to the preset grammar rules, the corresponding grammar category is identified from the word stream, the grammar check is performed, and the corresponding grammar check is performed to generate a corresponding grammar tree,
3)对语法分析的结果进行语义分析,生成相应的中间代码,将各种声明记录至符号表,记录声明类型,记录表达式类型等,3) Semantically analyze the results of the syntax analysis, generate the corresponding intermediate code, record various declarations to the symbol table, record the declaration type, record the expression type, etc.,
4)根据语义分析的结果进行代码生成,最终获得目标代码,4) Code generation is performed according to the result of semantic analysis, and the target code is finally obtained,
其中,输入代码包括应用包代码和引用包代码,目标代码包括由应用包代码生成的应用包目标代码和由引用包代码生成的引用包目标代码,应用包代码以及应用包目标代码均包括运行时环境接口对应的代码,The input code includes the application package code and the reference package code, the target code includes the application package target code generated by the application package code and the reference package target code generated by the reference package code, and both the application package code and the application package target code include the runtime The code corresponding to the environment interface,
实际情况下,在进行语法分析时,按照编码顺序对输入代码进行扫描,将获取到的单词按照一定的规则添加到预设的常量池,常量池中的每个词条都包含了单词对应的字符串名称、属性、类别等信息,In practice, when performing grammatical analysis, the input code is scanned according to the coding order, and the acquired words are added to the preset constant pool according to certain rules. Each entry in the constant pool contains the corresponding word of the word. String name, attribute, category and other information,
在进行语法分析时,是对全局声明层面的分析,包括全局变量、枚举类型、函数等的解析,When performing syntax analysis, it is the analysis of the global declaration level, including the analysis of global variables, enumeration types, functions, etc.
在进行语义分析时,是对语句层面的分析,分析函数中除了声明之外的其他部分代码的语法和语义,When performing semantic analysis, it is the analysis at the statement level, and the syntax and semantics of other parts of the code in the function except the declaration are analyzed.
进行目标代码的生成过程,是对表达式层面的分析,对程序中各种表达式进行解析,生成对应的字节码表达式。The object code generation process is to analyze the expression level, analyze various expressions in the program, and generate corresponding bytecode expressions.
其中,源文件,即输入代码的编译的输出,即目标代码为应用包字节码文件和引用包字节码文件,其中实现了运行时环境接口(process、select、deselect、install、uninstall、getSccLibInterface)的应用会生成对 应的应用包字节码文件,而引用包(无运行时环境接口)和具有共享接口的应用会生成引用包字节码文件,每一个源文件都对应生成一个二进制字节码文件(应用包字节码文件或者引用包字节码文件)。Among them, the source file, that is, the output of the compilation of the input code, that is, the target code is the application package bytecode file and the reference package bytecode file, which implements the runtime environment interface (process, select, deselect, install, uninstall, getSccLibInterface ) application will generate the corresponding application package bytecode file, while the reference package (no runtime environment interface) and the application with shared interface will generate the reference package bytecode file, each source file correspondingly generates a binary byte code file (application package bytecode file or reference package bytecode file).
本申请实施例中,按照预设的语法规则对代码进行预先编译,生成便于进行解析的下载文件,在嵌入式开发中,减少对资源的需求,为嵌入式开发中的性能需求提供保障,满足下载文件可以跨平台执行的需求。In the embodiment of the present application, the code is pre-compiled according to the preset grammar rules, and a download file that is easy to parse is generated. In the embedded development, the demand for resources is reduced, and the performance demand in the embedded development is guaranteed to meet the requirements. Download files can perform cross-platform requirements.
将对输入代码进行编译时,具体可以进行多级处理,即When compiling the input code, multi-level processing can be performed, that is,
(1)通用的单个字符(ASCII码);(1) Common single character (ASCII code);
(2)代码编码语言支持的关键字;(2) Keywords supported by the code encoding language;
(3)嵌入式模块支持的API(Application Programming Interface,应用程序接口)关键字;(3) API (Application Programming Interface) keywords supported by the embedded module;
(4)应用自定义变量和方法;(4) Apply custom variables and methods;
(5)常用表达式;(5) Common expressions;
在具体操作时,预编译过程中,先(1)~(3)中的字符按照顺序添加到常量池,当支持的关键字和API一定时该部分的常量池数据是固定的,然后在代码编译过程中将(4)中的字符按照顺序添加到常量池中。In the specific operation, during the pre-compilation process, the characters in (1) to (3) are added to the constant pool in order. When the supported keywords and APIs are certain, the constant pool data in this part is fixed, and then in the code The characters in (4) are added to the constant pool in order during compilation.
常量池中每个成员对应的字符串都是唯一的,成员结构体中标记了该字符串的顺序ID、完整字符串信息及校验压缩值,用于后续编码时对读取的字符串进行比较和校验。The string corresponding to each member in the constant pool is unique, and the sequence ID, complete string information and verification compression value of the string are marked in the member structure, which is used for the subsequent encoding of the read string. Compare and verify.
其中,API关键字可以进行升级,升级时在常量池中将新增的API关键字添加到原有API关键字后面,按照升级的先后顺序依次排列,高版本的API可以兼容低版本的API,保证升级前后的编译结果的向下兼容性。Among them, API keywords can be upgraded. During the upgrade, the newly added API keywords are added to the original API keywords in the constant pool, and they are arranged in the order of upgrade. The higher version of the API can be compatible with the lower version of the API. Ensure backward compatibility of compilation results before and after the upgrade.
需要说明的是,输入代码和目标代码中实现了运行时环境接口的文件是应用包,嵌入式模块可以调用应用包的运行时环境接口来选择 激活、运行应用包功能,由于防火墙安全要求应用包中的常用方法和变量只能在当前包中访问,不同应用包之间可以访问对方的共享接口方法;It should be noted that the file that implements the runtime environment interface in the input code and the target code is the application package. The embedded module can call the runtime environment interface of the application package to choose to activate and run the application package function. Because the firewall security requires the application package Common methods and variables in can only be accessed in the current package, and different application packages can access each other's shared interface methods;
输入代码和目标代码中未实现运行时环境接口的文件是引用包,引用包对外提供了一个映射,使它的方法可以被不同的应用包来调用。The files in the input code and the object code that do not implement the runtime environment interface are reference packages. The reference packages provide a mapping to the outside so that their methods can be called by different application packages.
本申请实施例获得的下载文件,在实际应用时,需要依靠虚拟机系统和运行时环境系统,The download file obtained by the embodiment of the present application needs to rely on the virtual machine system and the runtime environment system during practical application,
虚拟机系统用于处理下载文件,解析下载文件中的字节码,执行对应的应用包代码功能。运行时环境系统用于管理应用的生命周期、访问应用的运行时环境接口、进行应用运行时的防火墙管理。The virtual machine system is used to process the downloaded file, parse the bytecode in the downloaded file, and execute the corresponding application package code function. The runtime environment system is used to manage the life cycle of the application, access the runtime environment interface of the application, and manage the firewall when the application is running.
在运行时环境系统中,将每个实现了运行时环境接口的源文件都做为一个包,其实例化为应用applet,运行时环境系统的主要作用为:In the runtime environment system, each source file that implements the runtime environment interface is regarded as a package, which is instantiated as an application applet. The main functions of the runtime environment system are:
根据选择指令激活,去激活指定应用;Activate according to the selection instruction to deactivate the specified application;
将收到的指令分发给当前应用,即调用应用的入口函数;Distribute the received instruction to the current application, that is, call the entry function of the application;
防火墙管理,防止不同包下面的应用互相访问。Firewall management to prevent applications under different packages from accessing each other.
虚拟机系统,其核心是虚拟机字节码,虚拟机系统的基本原理是字节码、堆栈、解释器共同作用,字节码负责程序的语法操作符实现,堆栈负责参数,变量和临时操作数等数据的存放,解释器针对程序指针中获取的字节码进行解析,三者一起实现了编程语言的表达式。The core of the virtual machine system is the virtual machine bytecode. The basic principle of the virtual machine system is that the bytecode, the stack and the interpreter work together. The bytecode is responsible for the implementation of the syntax operators of the program, and the stack is responsible for the parameters, variables and temporary operations. The storage of data such as numbers, the interpreter parses the bytecode obtained from the program pointer, and the three together realize the expression of the programming language.
生成下载文件时,具体可以借助一个下载文件转换工具,其作用是将应用包字节码文件和引用包字节码文件转换成标准GP(GP,GlobalPlatform,全球平台国际标准组织)下载脚本。When generating the download file, a download file conversion tool can be used specifically, the function of which is to convert the application package bytecode file and the reference package bytecode file into a standard GP (GP, GlobalPlatform, Global Platform International Standards Organization) download script.
需要说明的是,一个应用包代码含有运行时环境接口对应的代码,同样,一个应用包目标代码含有运行时环境接口对应的代码;It should be noted that an application package code contains code corresponding to the runtime environment interface, and similarly, an application package target code contains code corresponding to the runtime environment interface;
输入代码中包括至少一个应用包代码,另外可能含有一个、多个或者没有引用包代码,同样,目标代码中包括至少一个应用包目标代 码,另外可能含有一个、多个或者没有引用包目标代码;The input code includes at least one application package code, and may contain one, more or no reference package code. Similarly, the target code includes at least one application package object code, and may contain one, more or no reference package object code;
一个应用包代码在实际应用时,可能需要运用多个引用包代码,同样,一个应用包目标代码在实际应用时,可能需要运用多个引用包目标代码。In actual application, one application package code may need to use multiple reference package codes, and similarly, one application package object code may need to use multiple reference package object codes in actual application.
具体的,系统配置有一常量池;Specifically, the system is configured with a constant pool;
常量池用于分别以词条为单位存储系统支持的编程通用字符、编程语言关键字、通用应用程序接口关键字以及运行时环境接口关键字;The constant pool is used to store the programming general characters, programming language keywords, general application programming interface keywords and runtime environment interface keywords supported by the system in terms of entries;
常量池还用于当软件代码编译单元提取输入代码对应的单词流时,依次以词条为单位存储输入代码引用的头文件中声明的变量和方法、输入代码中的自定义变量、自定义方法分别以词条为单位存入常量池中;The constant pool is also used to store the variables and methods declared in the header file referenced by the input code, the custom variables in the input code, and the custom methods in the unit of entry when the software code compilation unit extracts the word stream corresponding to the input code. The entries are stored in the constant pool respectively;
当单词流对应的任一词条已事先存在于常量池内时则不存入常量池,词条包含单词流内各单词对应的字符串名称、字符串属性以及字符串类别。When any entry corresponding to the word stream already exists in the constant pool, it is not stored in the constant pool. The entry contains the string name, string attribute and string category corresponding to each word in the word stream.
需要说明的是,在进行软件代码编译时,会创建常量池,常量池是词法分析的基础,常量池中每一项ID表示单词流中的一个单词,其基本结构体由单词标识、压缩编码、单词名称、单词长度、单词类型、已使用标识、方法偏移标识组成,其中,单词标识表示该单词在常量池中的位置,压缩编码是表示单词字符串的压缩编码,单词名称是单词的原始字符串描述,单词长度是单词的字符串长度,单词类型表示单词的函数类型,已使用标识表示该单词是否在源程序中被调用,方法偏移标识表示单词为函数时该函数在字节码方法组件中的偏移值;It should be noted that when compiling software code, a constant pool will be created. The constant pool is the basis of lexical analysis. Each ID in the constant pool represents a word in the word stream, and its basic structure is identified by the word, compressed and encoded. , word name, word length, word type, used ID, and method offset ID, where the word ID indicates the position of the word in the constant pool, the compression encoding is the compression encoding for the word string, and the word name is the word The original string description, the word length is the string length of the word, the word type indicates the function type of the word, the used flag indicates whether the word is called in the source program, the method offset flag indicates that when the word is a function, the function is in bytes. The offset value in the code method component;
偏移值具体是指数据存储位置。The offset value specifically refers to the data storage location.
在实际操作过程中,常量池的作用是标记当前编译环境支持的关键字,以及源文件和头文件的变量、宏定义、函数声明,用于在解析源文件代码时读取单词后进行相应的语义分析。In the actual operation process, the function of the constant pool is to mark the keywords supported by the current compilation environment, as well as the variables, macro definitions, and function declarations of the source file and header file, which are used to read the words when parsing the source file code. Semantic Analysis.
另外,常量池中每个成员对应的单词字符串是唯一的,但是由于单词的字符串组成和长度不可控,单纯的使用字符串比较会存在性能和空间上的浪费,因此本申请实施例提供了一种性能和内存开销都有较大提升的匹配方法,具体分为3级步骤,其操作流程具体如下:In addition, the word string corresponding to each member in the constant pool is unique, but since the string composition and length of the word are uncontrollable, simply using string comparison will waste performance and space. Therefore, the embodiments of the present application provide A matching method with greatly improved performance and memory overhead is proposed. It is divided into three steps. The operation process is as follows:
第1级是单词标识比较,可以搜索出所有的单个字符单词和编程语言关键字单词,这些单词的单词标识是唯一的;The first level is the word identification comparison, which can search for all single character words and programming language keyword words, and the word identification of these words is unique;
第2级是压缩编码比较,可以搜索出常量池中所有唯一的单词标识对应的单词;The second level is compression encoding comparison, which can search for words corresponding to all unique word identifiers in the constant pool;
第3级是单词名称比较,可以完整匹配常量池中的单词;The third level is the word name comparison, which can completely match the words in the constant pool;
其中,匹配的基本顺序是1、2、3,只有当单词标识不唯一时才进行第3级的全字符串比较。Among them, the basic order of matching is 1, 2, 3, and the third-level full string comparison is performed only when the word identifier is not unique.
具体的,引用包字节码文件包括一个二进制字节码文件以及一个二进制输出映射文件,二进制输出映射文件包括引用包字节码文件对应的版本信息、应用标识数据以及所包含的方法的描述信息。Specifically, the reference package bytecode file includes a binary bytecode file and a binary output mapping file, and the binary output mapping file includes version information corresponding to the reference package bytecode file, application identification data, and description information of the included methods. .
具体的,应用包字节码文件包括方法组件子文件、内存组件子文件、运行时方法组件子文件以及共享接口组件子文件。Specifically, the application package bytecode file includes a method component subfile, a memory component subfile, a runtime method component subfile, and a shared interface component subfile.
需要说明的是,此处的子文件,并非代表上下级的关系,而是应用包字节码文件中存在多个部分,分别是方法组件部分、内存组件部分、运行时方法组件部分以及共享接口组件部分,此处为了描述方面,称呼为子文件。It should be noted that the sub-files here do not represent the relationship between the upper and lower levels, but there are multiple parts in the application package bytecode file, namely the method component part, the memory component part, the runtime method component part and the shared interface. Component parts, here for describing aspects, are called subfiles.
其中,应用包字节码文件的方法组件子文件包括应用包中的所有方法的字节码,按照每个方法在应用包的源码中的声明顺序依次排列,各方法在应用包中的存储位置和方法名称均一一对应记录在常量池中;Among them, the method component subfile of the application package bytecode file includes the bytecodes of all methods in the application package, which are arranged in order according to the declaration order of each method in the source code of the application package, and the storage location of each method in the application package and the method name are recorded in the constant pool in one-to-one correspondence;
内存组件子文件记录对应的应用包中全局非易失空间(NVM,Non-volatile Memory)的大小和初始值以及全局易失空间(RAM, Random Access Memory)的大小值;The memory component subfile records the size and initial value of the global non-volatile space (NVM, Non-volatile Memory) and the size value of the global volatile space (RAM, Random Access Memory) in the corresponding application package;
运行时方法组件子文件包括对应的应用包的运行时环境接口的偏移值,用于对应的应用包在安装、删除、激活、去激活时进行调用;The runtime method component subfile includes the offset value of the runtime environment interface of the corresponding application package, which is used for invoking the corresponding application package during installation, deletion, activation, and deactivation;
共享接口组件子文件包括对应的应用包声明的共享接口的个数以及每个接口方法的偏移值。The shared interface component subfile includes the number of shared interfaces declared by the corresponding application package and the offset value of each interface method.
具体的,下载文件生成单元4,其具体用于根据应用包字节码文件以及引用包字节码文件,解析获得方法组件、内存组件、运行时方法组件以及共享接口组件,并结合预设的数据包以及应用标识数据,按照预设格式生成下载文件。Specifically, the download file generation unit 4 is specifically configured to parse and obtain the method component, the memory component, the runtime method component and the shared interface component according to the application package bytecode file and the reference package bytecode file, and combine the preset The data package and application identification data are generated according to the preset format to download the file.
以上所述仅是本申请的具体实施方式,使本领域技术人员能够理解或实现本申请。对这些实施例的多种修改对本领域的技术人员来说将是显而易见的,本文中所定义的一般原理可以在不脱离本申请的精神或范围的情况下,在其它实施例中实现。因此,本申请将不会被限制于本文所示的这些实施例,而是要符合与本文所申请的原理和新颖特点相一致的最宽的范围。The above descriptions are only specific embodiments of the present application, so that those skilled in the art can understand or implement the present application. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, this application is not intended to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features claimed herein.

Claims (14)

  1. 一种软件代码编译方法,其特征在于,所述方法包括以下步骤:A method for compiling software code, characterized in that the method comprises the following steps:
    接收输入代码,提取所述输入代码对应的单词流,根据预设的语法规则生成语法树,并进行语义分析,获得目标代码,所述输入代码包括应用包代码和引用包代码,所述目标代码包括由所述应用包代码生成的应用包目标代码和由所述引用包代码生成的引用包目标代码,所述应用包代码以及所述应用包目标代码均包括运行时环境接口对应的代码;Receive an input code, extract the word stream corresponding to the input code, generate a syntax tree according to a preset grammar rule, and perform semantic analysis to obtain a target code, the input code includes an application package code and a reference package code, the target code including the application package target code generated by the application package code and the reference package target code generated by the reference package code, the application package code and the application package target code both include the code corresponding to the runtime environment interface;
    根据所述应用包目标代码中实现应用功能的数据,生成应用包字节码文件;Generate an application package bytecode file according to the data implementing the application function in the application package target code;
    根据所述引用包目标代码中实现接口调用的数据,生成引用包字节码文件;Generate a reference package bytecode file according to the data implementing the interface call in the reference package target code;
    根据所述应用包字节码文件以及所述引用包字节码文件生成下载文件。A download file is generated according to the application package bytecode file and the reference package bytecode file.
  2. 如权利要求1所述的软件代码编译方法,其特征在于,所述接收输入代码,提取所述输入代码对应的单词流,根据预设的语法规则生成语法树,并进行语义分析,获得目标代码中,具体包括如下步骤:The software code compiling method according to claim 1, characterized in that, the input code is received, the word stream corresponding to the input code is extracted, a syntax tree is generated according to a preset syntax rule, and semantic analysis is performed to obtain the target code , including the following steps:
    接收所述输入代码,并解析获得对应的单词流;Receive the input code, and parse to obtain the corresponding word stream;
    根据预设的语法规则,识别所述单词流的语言范畴,并进行对应的语法检查,生成对应的语法树;According to preset grammar rules, identify the language category of the word stream, and perform corresponding grammar check to generate a corresponding grammar tree;
    对所述语法树中的数据进行语义分析,并进行分类记录;Semantically analyze the data in the syntax tree, and classify and record;
    根据分类记录后的数据生成目标代码。Generate object codes according to the classified and recorded data.
  3. 如权利要求1所述的软件代码编译方法,其特征在于,在接收所述输入代码之前,所述方法还包括以下步骤:The method for compiling software code according to claim 1, wherein before receiving the input code, the method further comprises the following steps:
    创建一常量池;Create a constant pool;
    所述常量池用于分别以词条为单位存储所述方法支持的编程通用 字符、编程语言关键字、通用应用程序接口关键字以及运行时环境接口关键字;The constant pool is used to store programming general characters, programming language keywords, general application programming interface keywords and runtime environment interface keywords supported by the method in terms of entries respectively;
    所述常量池还用于当提取所述输入代码对应的所述单词流时,依次以词条为单位存储所述输入代码引用的头文件中声明的变量和方法、所述输入代码中的自定义变量、自定义方法分别以词条为单位存入所述常量池中;The constant pool is also used to store the variables and methods declared in the header file referenced by the input code, the variables and methods in the input code in turn in units of entries when the word stream corresponding to the input code is extracted. Defined variables and custom methods are stored in the constant pool in units of entries respectively;
    当所述单词流对应的任一所述词条已事先存在于所述常量池内时则不存入所述常量池,所述词条包含所述单词流内各单词对应的字符串名称、字符串属性以及字符串类别。When any of the entry corresponding to the word stream already exists in the constant pool, it is not stored in the constant pool, and the entry includes the string name, character string corresponding to each word in the word stream String properties and string categories.
  4. 如权利要求1所述的软件代码编译方法,其特征在于:software code compiling method as claimed in claim 1, is characterized in that:
    所述引用包字节码文件包括一个二进制字节码文件以及一个二进制输出映射文件,所述二进制输出映射文件包括所述引用包字节码文件对应的版本信息、应用标识数据以及所包含的方法的描述信息。The reference package bytecode file includes a binary bytecode file and a binary output mapping file, and the binary output mapping file includes version information corresponding to the reference package bytecode file, application identification data, and included methods. description information.
  5. 如权利要求3所述的软件代码编译方法,其特征在于:software code compiling method as claimed in claim 3, is characterized in that:
    所述应用包字节码文件包括方法组件子文件、内存组件子文件、运行时方法组件子文件以及共享接口组件子文件。The application package bytecode file includes a method component subfile, a memory component subfile, a runtime method component subfile, and a shared interface component subfile.
  6. 如权利要求5所述的软件代码编译方法,其特征在于:software code compiling method as claimed in claim 5, is characterized in that:
    所述应用包字节码文件的方法组件子文件包括所述应用包中的所有方法的字节码,按照每个方法在所述应用包的源码中的声明顺序依次排列,各所述方法在应用包中的存储位置和方法名称均一一对应记录在所述常量池中;所述内存组件子文件记录对应的所述应用包中全局非易失空间的大小和初始值以及全局易失空间的大小值;The method component subfile of the application package bytecode file includes the bytecodes of all methods in the application package, and is arranged in sequence according to the declaration order of each method in the source code of the application package, and each method is described in The storage locations and method names in the application package are recorded in the constant pool in a one-to-one correspondence; the memory component subfile records the size and initial value of the global non-volatile space and the global volatile space in the corresponding application package size value;
    所述运行时方法组件子文件包括对应的所述应用包的运行时环境接口的偏移值,用于对应的应用包在安装、删除、激活、去激活时进行调用;The runtime method component subfile includes an offset value of the runtime environment interface of the corresponding application package, which is used for invoking the corresponding application package during installation, deletion, activation, and deactivation;
    所述共享接口组件子文件包括对应的所述应用包声明的共享接口 的个数以及每个接口方法的偏移值。The shared interface component subfile includes the number of shared interfaces declared by the corresponding application package and the offset value of each interface method.
  7. 如权利要求1所述的软件代码编译方法,其特征在于,所述根据所述应用包字节码文件以及所述引用包字节码文件生成下载文件,具体包括以下步骤:The software code compiling method according to claim 1, wherein the generating a download file according to the application package bytecode file and the reference package bytecode file specifically includes the following steps:
    根据所述应用包字节码文件以及所述引用包字节码文件,解析获得方法组件、内存组件、运行时方法组件以及共享接口组件,并结合预设的数据包以及应用标识数据,按照预设格式生成下载文件。According to the application package bytecode file and the reference package bytecode file, the method component, the memory component, the runtime method component and the shared interface component are obtained by parsing, and combined with the preset data package and application identification data, according to the preset Format to generate download files.
  8. 一种软件代码编译系统,其特征在于,所述系统包括:A software code compilation system, characterized in that the system comprises:
    软件代码编译单元,其用于接收输入代码,提取所述输入代码对应的单词流,根据预设的语法规则生成语法树,并进行语义分析,获得目标代码,所述输入代码包括应用包代码和引用包代码,所述目标代码包括由所述应用包代码生成的应用包目标代码和由所述引用包代码生成的引用包目标代码,所述应用包代码以及所述应用包目标代码均包括运行时环境接口对应的代码;A software code compiling unit, which is used for receiving an input code, extracting a word stream corresponding to the input code, generating a syntax tree according to a preset grammar rule, and performing semantic analysis to obtain a target code, and the input code includes an application package code and Reference package code, the target code includes application package target code generated by the application package code and reference package target code generated by the reference package code, both the application package code and the application package target code include running The code corresponding to the time environment interface;
    应用包生成单元,其用于根据所述应用包目标代码中实现应用功能的数据,生成应用包字节码文件;an application package generation unit, which is used for generating an application package bytecode file according to the data implementing the application function in the application package target code;
    引用包生成单元,其用于根据所述引用包目标代码中实现接口调用的数据,生成引用包字节码文件;A reference package generation unit, which is used to generate a reference package bytecode file according to the data that implements the interface call in the reference package target code;
    下载文件生成单元,其用于根据所述应用包字节码文件以及所述引用包字节码文件生成下载文件。A download file generating unit, configured to generate a download file according to the application package bytecode file and the reference package bytecode file.
  9. 如权利要求8所述的软件代码编译系统,其特征在于,所述软件代码编译单元具体用于:The software code compiling system according to claim 8, wherein the software code compiling unit is specifically used for:
    接收所述输入代码,并解析获得对应的单词流;Receive the input code, and parse to obtain the corresponding word stream;
    根据预设的语法规则,识别所述单词流的语言范畴,并进行对应的语法检查,生成对应的语法树;According to preset grammar rules, identify the language category of the word stream, and perform corresponding grammar check to generate a corresponding grammar tree;
    对所述语法树中的数据进行语义分析,并进行分类记录;Semantically analyze the data in the syntax tree, and classify and record;
    根据分类记录后的数据生成目标代码。Generate object codes according to the classified and recorded data.
  10. 如权利要求8所述的软件代码编译系统,其特征在于:The software code compiling system of claim 8, wherein:
    所述系统配置有一常量池;The system is configured with a constant pool;
    所述常量池用于分别以词条为单位存储所述系统支持的编程通用字符、编程语言关键字、通用应用程序接口关键字以及运行时环境接口关键字;The constant pool is used to store the programming general characters, programming language keywords, general application programming interface keywords and runtime environment interface keywords supported by the system respectively in terms of entries;
    所述常量池还用于当所述软件代码编译单元提取所述输入代码对应的所述单词流时,依次以词条为单位存储所述输入代码引用的头文件中声明的变量和方法、所述输入代码中的自定义变量、自定义方法分别以词条为单位存入所述常量池中;The constant pool is also used to sequentially store the variables and methods declared in the header file referenced by the input code, The self-defined variables and self-defined methods in the input code are respectively stored in the constant pool in terms of entries;
    当所述单词流对应的任一所述词条已事先存在于所述常量池内时则不存入所述常量池,所述词条包含所述单词流内各单词对应的字符串名称、字符串属性以及字符串类别。When any of the entry corresponding to the word stream already exists in the constant pool, it is not stored in the constant pool, and the entry includes the string name, character string corresponding to each word in the word stream String properties and string categories.
  11. 如权利要求8所述的软件代码编译系统,其特征在于:The software code compiling system of claim 8, wherein:
    所述引用包字节码文件包括一个二进制字节码文件以及一个二进制输出映射文件,所述二进制输出映射文件包括所述引用包字节码文件对应的版本信息、应用标识数据以及所包含的方法的描述信息。The reference package bytecode file includes a binary bytecode file and a binary output mapping file, and the binary output mapping file includes version information corresponding to the reference package bytecode file, application identification data, and included methods. description information.
  12. 如权利要求10所述的软件代码编译系统,其特征在于:The software code compiling system of claim 10, wherein:
    所述应用包字节码文件包括方法组件子文件、内存组件子文件、运行时方法组件子文件以及共享接口组件子文件。The application package bytecode file includes a method component subfile, a memory component subfile, a runtime method component subfile, and a shared interface component subfile.
  13. 如权利要求12所述的软件代码编译系统,其特征在于:The software code compiling system of claim 12, wherein:
    所述应用包字节码文件的方法组件子文件包括所述应用包中的所有方法的字节码,按照每个方法在所述应用包的源码中的声明顺序依次排列,各所述方法在应用包中的存储位置和方法名称均一一对应记录在所述常量池中;The method component subfile of the application package bytecode file includes the bytecodes of all methods in the application package, and is arranged in sequence according to the declaration order of each method in the source code of the application package, and each method is described in The storage locations and method names in the application package are recorded in the constant pool in a one-to-one correspondence;
    所述内存组件子文件记录对应的所述应用包中全局非易失性存储 空间的大小和初始值以及全局易失性存储空间的大小值;The memory component subfile records the size and initial value of the global non-volatile storage space and the size value of the global volatile storage space in the corresponding application package;
    所述运行时方法组件子文件包括对应的所述应用包的运行时环境接口的偏移值,用于对应的应用包在安装、删除、激活、去激活时进行调用;The runtime method component subfile includes an offset value of the runtime environment interface of the corresponding application package, which is used for invoking the corresponding application package during installation, deletion, activation, and deactivation;
    所述共享接口组件子文件包括对应的所述应用包声明的共享接口的个数以及每个接口方法的偏移值。The shared interface component subfile includes the number of shared interfaces declared by the corresponding application package and the offset value of each interface method.
  14. 如权利要求12所述的软件代码编译系统,其特征在于:The software code compiling system of claim 12, wherein:
    所述下载文件生成单元,其具体用于根据所述应用包字节码文件以及所述引用包字节码文件,解析获得方法组件、内存组件、运行时方法组件以及共享接口组件,并结合预设的数据包以及应用标识数据,按照预设格式生成下载文件。The download file generation unit is specifically configured to parse and obtain the method component, the memory component, the runtime method component and the shared interface component according to the application package bytecode file and the reference package bytecode file, and combine the pre- According to the preset data package and application identification data, the download file is generated according to the preset format.
PCT/CN2021/104177 2020-08-12 2021-07-02 Software code compiling method and system WO2022033229A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202010815520.3 2020-08-12
CN202010815520.3A CN112052006B (en) 2020-08-12 2020-08-12 Software code compiling method and system

Publications (1)

Publication Number Publication Date
WO2022033229A1 true WO2022033229A1 (en) 2022-02-17

Family

ID=73601687

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2021/104177 WO2022033229A1 (en) 2020-08-12 2021-07-02 Software code compiling method and system

Country Status (2)

Country Link
CN (1) CN112052006B (en)
WO (1) WO2022033229A1 (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115826991A (en) * 2023-02-14 2023-03-21 江西曼荼罗软件有限公司 Software script generation method, system, computer and readable storage medium

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112052006B (en) * 2020-08-12 2021-06-15 武汉天喻信息产业股份有限公司 Software code compiling method and system
CN113568620B (en) * 2021-06-16 2023-08-22 杭州华橙软件技术有限公司 Code file processing method, device, equipment and medium

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1790268A (en) * 2004-12-14 2006-06-21 艾克斯麦提克方案私人有限公司 Compile time linking via hashing technique
US20120222021A1 (en) * 2008-01-09 2012-08-30 Kan Zhao Method and System for presenting and analyzing software source code through intermediate representation
CN110162306A (en) * 2018-02-14 2019-08-23 阿里巴巴集团控股有限公司 The just-ahead-of-time compilation method and apparatus of system
CN111240982A (en) * 2020-01-09 2020-06-05 华东师范大学 Static analysis method for source code
CN111381817A (en) * 2020-03-25 2020-07-07 北京字节跳动网络技术有限公司 Method, device, medium and electronic equipment for realizing cross-platform multi-language development
CN112052006A (en) * 2020-08-12 2020-12-08 武汉天喻信息产业股份有限公司 Software code compiling method and system

Family Cites Families (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1306400C (en) * 2004-05-20 2007-03-21 北京大学 Binary system software member and its manufacturing method
CN100339831C (en) * 2005-12-14 2007-09-26 浙江大学 Virtual machine compiling system implementation method applied in Java operation system
CN101408849A (en) * 2008-12-01 2009-04-15 中国科学技术大学 Method and system for compiling and executing TTCN-3 language
CN103123590A (en) * 2011-11-18 2013-05-29 中国科学院沈阳计算技术研究所有限公司 Compiling method from intermediate language (IL) program to C language program of instruction list
CN102880452A (en) * 2012-02-01 2013-01-16 日照市国软软件有限公司 Programming language capable of cross-language reusing
CN104182267B (en) * 2013-05-21 2019-10-25 南京中兴新软件有限责任公司 Compilation Method, means of interpretation, device and user equipment
CN104239115A (en) * 2014-07-24 2014-12-24 汕头大学 Programming language compiling method of PLC (Programmable Logic Controller)

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1790268A (en) * 2004-12-14 2006-06-21 艾克斯麦提克方案私人有限公司 Compile time linking via hashing technique
US20120222021A1 (en) * 2008-01-09 2012-08-30 Kan Zhao Method and System for presenting and analyzing software source code through intermediate representation
CN110162306A (en) * 2018-02-14 2019-08-23 阿里巴巴集团控股有限公司 The just-ahead-of-time compilation method and apparatus of system
CN111240982A (en) * 2020-01-09 2020-06-05 华东师范大学 Static analysis method for source code
CN111381817A (en) * 2020-03-25 2020-07-07 北京字节跳动网络技术有限公司 Method, device, medium and electronic equipment for realizing cross-platform multi-language development
CN112052006A (en) * 2020-08-12 2020-12-08 武汉天喻信息产业股份有限公司 Software code compiling method and system

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115826991A (en) * 2023-02-14 2023-03-21 江西曼荼罗软件有限公司 Software script generation method, system, computer and readable storage medium

Also Published As

Publication number Publication date
CN112052006B (en) 2021-06-15
CN112052006A (en) 2020-12-08

Similar Documents

Publication Publication Date Title
WO2022033229A1 (en) Software code compiling method and system
TWI730654B (en) Method and device for deploying and executing smart contract
CN111770113B (en) Method for executing intelligent contract, block chain node and node equipment
US20200379738A1 (en) Extending a virtual machine instruction set architecture
CN106462425B (en) Method and system for using complex constants
CN107041158B (en) Restrictive access control for modular reflection
JP3689368B2 (en) Method of loading an application into a multi-application embedded system with data processing resources, corresponding system and execution method
US8863079B2 (en) Efficient and expansive conversions between reference and primitive
US11599346B2 (en) Accessing a migrated member in an updated type
US8850414B2 (en) Direct access of language metadata
US9417931B2 (en) Unified metadata for external components
US20040268301A1 (en) Adding new compiler methods to an integrated development environment
US10853096B2 (en) Container-based language runtime loading an isolated method
US8141035B2 (en) Method for accessing internal states of objects in object oriented programming
WO2024045382A1 (en) Implementation of reflective mechanism in blockchain
CN111522558B (en) Method, device, system and readable medium for dynamically configuring rules based on Java
US6898786B1 (en) Javascript interpreter engine written in Java
US10394610B2 (en) Managing split packages in a module system
US7036120B2 (en) Two tier clusters for representation of objects in Java programming environments
US11288045B1 (en) Object creation from structured data using indirect constructor invocation
CN113703779B (en) Cross-platform multi-language compiling method and ultra-light Internet of things virtual machine
CN115309405B (en) Code link optimization method
CN115269058B (en) WPF resource loading method and device
CN113703779A (en) Cross-platform multi-language compiling method and ultra-light Internet of things virtual machine
CN114253523A (en) Method and device for reading bare device, computer device and medium

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 21855282

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

32PN Ep: public notification in the ep bulletin as address of the adressee cannot be established

Free format text: NOTING OF LOSS OF RIGHTS PURSUANT TO RULE 112(1) EPC (EPO FORM 1205A DATED 06.07.2023)

122 Ep: pct application non-entry in european phase

Ref document number: 21855282

Country of ref document: EP

Kind code of ref document: A1