How do C/C++ compilers work?

后端 未结 10 1670
旧时难觅i
旧时难觅i 2020-12-12 13:02

After over a decade of C/C++ coding, I\'ve noticed the following pattern - very good programmers tend to have detailed knowledge of the innards of the compiler.

I\'

相关标签:
10条回答
  • 2020-12-12 13:33
    • GCC Internals Manual.
    • CPP Internals Manual
    • LLVM Documentation
    0 讨论(0)
  • 2020-12-12 13:33

    Depending on what you exactly want to know, you should have a look at pipes&filter pattern, because as far as I know this (or something similar) is used in a lot of compilers in the last years.

    When my compiler knowledge is not too outdated it works like this:

    Parse sourcecode into symbolic representation

    Clean up symbolic representation, do some normalization

    Optimization of the symbolic tree based on certain rules

    write out executable code based on symbolic tree

    Of course dependencies etc. have to be resolved too.

    And of course having a look at gcc or javac sourcecode may help in getting more detailed understanding.

    0 讨论(0)
  • 2020-12-12 13:39

    http://se-radio.net/podcast/2007-07/episode-61-internals-gcc

    0 讨论(0)
  • 2020-12-12 13:41

    Start with the dragon book....(stress more on code optimization and code generation)

    Go onto write a toy compiler for an educational programming language like Decaf or Cool.., you may use parser generators (lex and yacc) for your front end(to make life easier and focus on more imp stuff)....

    Then read gcc internals book along with browsing gcc source code.

    0 讨论(0)
  • 2020-12-12 13:42

    As noted by Pete Eddy, Jack Crenshaw's tutorial is excellent for newbies. But if you want to see how to a real, production C compiler works—one which was designed by brilliant engineers instead of created by throwing code at the wall until something stuck—get yourself a copy of Fraser and Hanson's A Retargetable C Compiler: Design and Implementation, which contains the source code to the very clean lcc compiler. Explanations of the design and implementation are mixed in with the code. It is not a first book for a beginner, but it will repay careful study, and you can get a used copy for $35.

    For a longer blurb about lcc, see Compile C Faster on Linux.

    The lcc web page also has links to a number of good textbooks. I don't know of an intro text that I really like, however.

    P.S. Sorry you got ripped off at Uni.

    0 讨论(0)
  • 2020-12-12 13:44

    see Fabrice Bellard's otcc source code

    http://bellard.org/otcc/

    0 讨论(0)
提交回复
热议问题