
عنوان:
Writing a C Compiler
نویسنده:
Nora Sandler
انتشارات:
No Starch Press
تاریخ انتشار:
2024
حجم:
8.9MB
معرفی کتاب:"نوشتن یک کامپایلر C: ساخت یک زبان برنامهنویسی واقعی از ابتدا، ویرایش ۱"
این کتاب یک راهنمای عملی و پر از مثال برای نظریه و عمل نوشتن یک کامپایلر C است؛ برنامهای که کد نوشتهشده توسط برنامهنویسان را به کدی تبدیل میکند که کامپیوتر بتواند بخواند.
کامپایلرها در قلب همه فعالیتهای برنامهنویسان قرار دارند، با این حال حتی توسعهدهندگان با تجربه هم ممکن است از آنها دلهره داشته باشند. برای کسانی که مشتاق درک واقعی نحوه کار کامپایلرها هستند، کتاب Writing a C Compiler این راز را برملا میکند. این کتاب شما را از طریق یک پروژه سرگرمکننده و جذاب راهنمایی میکند، جایی که خواهید آموخت چه چیزهایی برای کامپایل کردن یک زبان برنامهنویسی واقعی به کد اسمبلی لازم است.
کتاب Writing a C Compiler شما را گامبهگام در فرآیند ساخت یک کامپایلر برای زیرمجموعهای از زبان C راهنمایی میکند—بدون نیاز به تجربه قبلی در ساخت کامپایلر یا کد اسمبلی. پس از ساخت یک کامپایلر عملی برای سادهترین برنامه C، ویژگیهای جدید را فصل به فصل اضافه خواهید کرد. الگوریتمهای موجود در کتاب همگی به صورت pseudocode ارائه شدهاند، بنابراین میتوانید کامپایلر خود را با هر زبان برنامهنویسی دلخواه پیادهسازی کنید.
در این کتاب میآموزید:
- Lexing و Parsing: یاد بگیرید چگونه یک lexer و یک recursive descent parser بنویسید که کد C را به یک درخت نحوی انتزاعی تبدیل کند.
- تحلیل برنامه: کشف کنید چگونه یک برنامه را تحلیل کنید تا رفتار آن را بفهمید و خطاها را شناسایی کنید.
- تولید کد: یاد بگیرید چگونه سازههای زبان C مانند عملیات حسابی، فراخوانی توابع و دستورات جریان کنترل را به کد اسمبلی x64 ترجمه کنید.
- تکنیکهای بهینهسازی: عملکرد را با روشهایی مانند constant folding، حذف dead store و تخصیص رجیستر بهبود دهید.
کامپایلرها موجوداتی ترسناک نیستند—و با کمک این راهنمای عملی و قابل دسترس، حتی ممکن است آنها را به دوستان همیشگی خود تبدیل کنید.
فهرست مطالب
- Title Page
- Copyright
- Dedication
- About the Author and the Technical Reviewer
- Acknowledgments
- Introduction
- Part I: The Basics
- Chapter 1: A Minimal Compiler
- The Four Compiler Passes
- Hello, Assembly!
- The Compiler Driver
- The Lexer
- The Parser
- Assembly Generation
- Code Emission
- Summary
- Additional Resources
- Chapter 2: Unary Operators
- Negation and Bitwise Complement in Assembly
- The Stack
- The Lexer
- The Parser
- TACKY: A New Intermediate Representation
- Assembly Generation
- Code Emission
- Summary
- Additional Resources
- Chapter 3: Binary Operators
- The Lexer
- The Parser
- TACKY Generation
- Assembly Generation
- Code Emission
- Extra Credit: Bitwise Operators
- Summary
- Additional Resources
- Chapter 4: Logical and Relational Operators
- Short-Circuiting Operators
- The Lexer
- The Parser
- TACKY Generation
- Comparisons and Jumps in Assembly
- Assembly Generation
- Code Emission
- Summary
- Additional Resources
- Chapter 5: Local Variables
- Variables, Declarations, and Assignment
- The Lexer
- The Parser
- Semantic Analysis
- TACKY Generation
- Extra Credit: Compound Assignment, Increment, and Decrement
- Summary
- Chapter 6: If Statements and Conditional Expressions
- The Lexer
- The Parser
- Variable Resolution
- TACKY Generation
- Extra Credit: Labeled Statements and goto
- Summary
- Chapter 7: Compound Statements
- The Scoop on Scopes
- The Parser
- Variable Resolution
- TACKY Generation
- Summary
- Chapter 8: Loops
- Loops and How to Escape Them
- The Lexer
- The Parser
- Semantic Analysis
- TACKY Generation
- Extra Credit: switch Statements
- Summary
- Chapter 9: Functions
- Declaring, Defining, and Calling Functions
- Compiling Libraries
- The Lexer
- The Parser
- Semantic Analysis
- TACKY Generation
- Assembly Generation
- Code Emission
- Calling Library Functions
- Summary
- Chapter 10: File Scope Variable Declarations and Storage-Class Specifiers
- All About Declarations
- Linkage and Storage Duration in Assembly
- The Lexer
- The Parser
- Semantic Analysis
- TACKY Generation
- Assembly Generation
- Code Emission
- Summary
- Part II: Types Beyond Int
- Chapter 11: Long Integers
- Long Integers in Assembly
- The Lexer
- The Parser
- Semantic Analysis
- TACKY Generation
- Assembly Generation
- Code Emission
- Summary
- Chapter 12: Unsigned Integers
- Type Conversions, Again
- The Lexer
- The Parser
- The Type Checker
- TACKY Generation
- Unsigned Integer Operations in Assembly
- Assembly Generation
- Code Emission
- Summary
- Chapter 13: Floating-Point Numbers
- IEEE 754, What Is It Good For?
- The IEEE 754 Double-Precision Format
- Rounding Behavior
- Linking Shared Libraries
- The Lexer
- The Parser
- The Type Checker
- TACKY Generation
- Floating-Point Operations in Assembly
- Assembly Generation
- Code Emission
- Extra Credit: NaN
- Summary
- Additional Resources
- Chapter 14: Pointers
- Objects and Values
- Operations on Pointers
- The Lexer
- The Parser
- Semantic Analysis
- TACKY Generation
- Assembly Generation
- Code Emission
- Summary
- Chapter 15: Arrays and Pointer Arithmetic
- Arrays and Pointer Arithmetic
- The Lexer
- The Parser
- The Type Checker
- TACKY Generation
- Assembly Generation
- Code Emission
- Summary
- Chapter 16: Characters and Strings
- Character Traits
- String Literals
- Working with Strings in Assembly
- The Lexer
- The Parser
- The Type Checker
- TACKY Generation
- Assembly Generation
- Code Emission
- Hello Again, World!
- Summary
- Chapter 17: Supporting Dynamic Memory Allocation
- The void Type
- Memory Management with void *
- Complete and Incomplete Types
- The sizeof Operator
- The Lexer
- The Parser
- The Type Checker
- TACKY Generation
- Assembly Generation
- Summary
- Chapter 18: Structures
- Declaring Structure Types
- Operating on Structures
- Structure Layout in Memory
- The Lexer
- The Parser
- Semantic Analysis
- TACKY Generation
- Structures in the System V Calling Convention
- Assembly Generation
- Code Emission
- Extra Credit: Unions
- Summary
- Additional Resources
- Part III: Optimizations
- Chapter 19: Optimizing Tacky Programs
- Safety and Observable Behavior
- Four TACKY Optimizations
- Testing the Optimization Passes
- Wiring Up the Optimization Stage
- Constant Folding
- Control-Flow Graphs
- Unreachable Code Elimination
- A Little Bit About Data-Flow Analysis
- Copy Propagation
- Dead Store Elimination
- Summary
- Additional Resources
- Chapter 20: Register Allocation
- Register Allocation in Action
- Updating the Compiler Pipeline
- Extending the Assembly AST
- Converting TACKY to Assembly
- Register Allocation by Graph Coloring
- The Basic Register Allocator
- Instruction Fix-Up with Callee-Saved Registers
- Code Emission
- Register Coalescing
- Summary
- Additional Resources
- Next Steps
- Appendix A: Debugging Assembly Code With GDB or LLDB
- Appendix B: Assembly Generation and Code Emission Tables
- References
- Index
مشخصات
نام کتاب
Writing a C Compiler
نویسنده
Nora Sandler
انتشارات
No Starch Press
تاریخ انتشار
2024
ISBN
9781718500433
تعداد صفحات
2041
زبان
انگلیسی
فرمت
حجم
8.9MB
موضوع
programming