What is a Compiler?
In simple terms, a compiler is a program that translates "one language (usually a high-level language)" into "another language (usually a low-level language)." The main workflow of a modern compiler: source code preprocessor compiler object code linker executables
- Chinese name
- translater
- Foreign name
- Compiler
- nickname
- decoder
- expression
- Source code preprocessor compiler object code
- Presenter
- Grace Hope
- Presentation time
- Late 1950s
- Applied discipline
- computer
- Scope of application
- Computer, microcontroller, programming language
- In simple terms, a compiler is a program that translates "one language (usually a high-level language)" into "another language (usually a low-level language)." The main workflow of a modern compiler: source code preprocessor compiler object code linker executables
- High-level computer language is easy for people to write, read, communicate and maintain. Machine language can be directly interpreted and run by a computer. The compiler takes assembly or high-level computer language source programs as input and translates them into equivalent programs of target language machine code. The source code is generally a high-level language, such as Pascal, C, C ++, Java, Chinese programming, or assembly language, and the target is the object code of the machine language (sometimes called the machine code) Machine code).
- For high-level languages such as C # and VB, the function completed by the compiler at this time is to compile the source code (SourceCode) into the byte code (ByteCode) of the general intermediate language (MSIL / CIL). In the last run, the machine code (NativeCode) that can be directly calculated by the CPU is finally converted by the conversion of the common language runtime library.
How the compiler works
- Compiling [1] is from source code (usually a high-level language) to being directly
- translater
- A typical compiler output is an object file consisting of the name and address of an entry point, and machine code for external calls (to function calls that are not in this object file). A set of object files need not be generated by the same compiler, but the compiler used must use the same output format, can be linked together and generate an EXE that can be directly executed by the user,
- So the files on our computer are all compiled files.
Compiler Type
- Compile
- translater
Compiler processor
- The function is to complete the source program by substituting into predefined program blocks.
Compiler front end
- The front end is mainly responsible for parsing the input source code.
- title
Compiler backend
- The compiler backend is mainly responsible for analyzing and optimizing the intermediate code (Intermediat
- Generally speaking, all compiler analysis, optimization, and modification can be divided into two categories: intra-procedural or inter-procedural. Obviously, the analysis between functions is more accurate and optimized, but it takes longer to complete.
Compiler code analysis
- translater
- translater
- Common compilation analysis includes function call tree (Control tree), control flow graph (Control flow graph), and variable definition-use, use-define chain (define-use / use-define or ud / du chain) ), Variable alias analysis (alias analysis), pointer analysis (pointer analysis), data dependence analysis (data dependence analysis), etc.
- Program analysis
- translater
- The generation of machine code is the process of converting the intermediate code into machine instructions after optimization and modification. Modern compilers mainly adopt the strategy of generating assembly code instead of directly generating binary object code. Even in the code generation phase, advanced compilers still have to do a lot of analysis, optimization, and deformation. For example, how to allocate registers (register allocatioin), how to choose the appropriate machine instruction (instruction selection), how to combine several lines of code into one sentence, and so on.
Compiler working methods
- The compiler first performs parsing, which means separating those strings.
- Then carry out semantic analysis, which is to clarify the meaning of each grammatical unit analyzed by grammatical analysis.
- The final result is an object file, also known as an obj file.
- Then go through the linker to generate the final EXE file.
- Sometimes it is necessary to link object files generated by multiple files to generate the final code. This process is called cross-linking.
Compiler compiler optimization
- Applications are complex because they have the ability to handle multiple problems and related data sets. In fact, a complex application is like paste together with many different functions. Most of the complexity in the source files comes from handling initialization and problem setup code. Although these files usually occupy a large part of the source files and are very difficult, they basically do not cost CPU execution cycles.
- Despite the above, most Makefiles have only one set of compiler options to compile all files in the project. Therefore, standard optimization methods simply increase the strength of the optimization options, generally from O 2 to O 3. In this way, a lot of effort is needed to debug, determine which files cannot be optimized, and establish special make rules for these files.
- A simpler but more effective method is to run the original code through a performance analyzer to generate a list of source files that consume 85 to 95% of the CPU. Usually, these files account for only about 1% of all files. If developers immediately established their own rules for each file in the list, they would be in a more flexible and effective position. In this way, changing the optimization will only cause a small part of the file to be recompiled. Furthermore, since time is not wasted optimizing time-consuming functions, recompiling all files will be greatly accelerated. [2]
Compiler comparison
- Many people divide high-level programming languages into two categories: compiled languages and literal languages. In reality, however, most of these languages can be implemented in both compiled and literal versions, and the classification actually reflects the common implementation of that language. (However, some transliteration languages are difficult to implement with compilation. For example, those that allow online code changes.)
Compiler history
- 20th Century 5
- translater
- Finite Automation and Regular Expression are closely related to context-free grammar, and they correspond to Chomsky's type 3 grammar. Their research began at about the same time as Chomsky's, and led to the symbolic way of representing words in programming languages.
- People then deepened their approach to generating valid object code. This was the original compiler, and they have been used to this day. People often call it the Optimization Technique, but because it never really gets the optimized target code, it only improves its effectiveness, so it should actually be called the Code Improvement Technique. ).
- When the analysis of the problem became easier to understand, people spent a lot of effort on developing programs to study this part of the compiler's automatic construction. These programs were originally called Compiler-compiler, but more precisely Parser Generator, because they can only handle part of the compilation automatically. The most famous of these programs is Yacc (Yet Another Compiler-compiler), which was written by Steve Johnson for Unix systems in 1975. Similarly, the study of finite state automata has also developed a tool called a Scanner Generator. Lex (simultaneously with Yacc, developed by Mike Lesk for Unix systems) is one of the best.
- In the late 1970s and early 1980s, a large number of projects focused on generating automation in other parts of the compiler, including code generation. These attempts have been unsuccessful, presumably because the operation is too complicated and people do not know much about it.
- Recent developments in compiler design include: First, the compiler includes applications for more complex algorithms that are used to infer or simplify information in the program; this has been combined with the development of more complex programming languages. Among them is a unified algorithm for Hindley-Milner type checking for functional language compilation. Secondly, the compiler has increasingly become part of the window-based Interactive Development Environment (IDE), which includes editors, linkers, debuggers, and project management programs. There are not many such IDE standards, but the development of standard window environments has become the direction. On the other hand, despite extensive research in the field of compilation principles, the basic compiler design principles have not changed much in the last 20 years, and it is rapidly becoming the central link in computer science courses.
- In the 1990s, many free compilers and compiler development tools were developed as part of the GNU project or other open source projects. These tools can be used to compile all computer programming languages. Some of these projects are considered high-quality, and anyone who is interested in modern compilation theory can easily get their free source code.
- Around 1999, SGI announced the source code of their industrialized parallel optimization compiler Pro64, which was later used as a research platform by multiple compiler research groups around the world and named Open64. Open64 has a good design structure, comprehensive analysis and optimization, and is an ideal platform for advanced research on compilers.
- Compiler-specific terms: [1] [1]
|
|
|
|
|
|
|
|
|
|
|
|
|
|