2

I am learning compilers and want to make changes of my own to GCC parser and lexer. Is there any testing tool or some another way available which let me change gcc code and test it accordingly.

I tried changing the lexical analysis file but now I am stuck because I don't know how to compile these files. I tried the compilation using other GCC compiler but show errors. I even tried configure and make but doing this with every change does not seems efficient.

The purpose of these changes is just learning and I have to consider GCC only as this is the only compiler my instructor allowed.

anuj pradhan
  • 2,777
  • 4
  • 26
  • 31
  • @KarolyHorvath Here Permanent means that I want to use my changes made to Lexical Analyzer of GCC. – anuj pradhan Nov 20 '14 at 08:08
  • Yes, but what do you mean by "permanent"? Did the lexical analyzer *change itself back*? – Sneftel Nov 20 '14 at 08:12
  • @KarolyHorvath I made an edit. I think this would explain better. Previous was ambiguous. My Mistake!! – anuj pradhan Nov 20 '14 at 08:17
  • You'd probably better off learning compilers by hacking a simpler compiler than gcc, such as Small C or Tiny C. See also http://stackoverflow.com/questions/2349468/starting-off-a-simple-the-simplest-perhaps-c-compiler. – lhf Nov 20 '14 at 14:03

2 Answers2

4

I even tried configure and make but doing that wit every change is not at all efficient.

That is exactly what you should be doing. (Well, you don't need to re-configure after every change, just run make again.) However, by default GCC configures itself in bootstrap mode, which means not only does your host compiler compile GCC, that compiled GCC then compiles GCC again (and again). That is overkill for your purposes, and you can prevent that from happening by adding --disable-bootstrap to the configuration options.

Another option that can help significantly reduce build times is enabling only the languages you're interested in. Since you're experimenting, you'll likely be very happy if you create something that works for C or for C++, even if for some obscure reason Java happens to break. Testing other languages becomes relevant when you make your changes available for a larger audience, but that isn't the case just yet. The configuration option that covers this is --enable-languages=c,c++.

Most of the configuration options are documented on the Installing GCC: Configuration page. Throroughly testing your changes is documented on the Contributing to GCC page, but that's likely something for later: you should know how to make your own simpler tests pass, by simply trying code that makes use of your new feature.

  • Thanks :) This looks good. I already used --enable-language=c,c++ .Could you mention some link where similar help can be found. Not necessarily for make but regarding availability of various features in GCC. Example, lexical analyser is present in lex.c or parser is present in some file say parser.c. – anuj pradhan Nov 20 '14 at 09:28
  • @anujpradhan Sure, added two links. –  Nov 20 '14 at 09:32
  • I just spent 10 minutes saying the same thing (bootstrap) with more words and less information ;-). – Peter - Reinstate Monica Nov 20 '14 at 09:38
1

You make changes (which are made "permanent" by saving the files you modify), compile the code, and run the test suite.

You typically write additional tests or remove those that are invalidated by your changes and that's it.

If your changes don't contribute anything "positive" to the compiler upstream will probably never accept them, and the only "permanence" you can get is the modifications in your local copy.

rubenvb
  • 74,642
  • 33
  • 187
  • 332
  • I tried building it again using configure and make. That seems to be inefficient with every change. – anuj pradhan Nov 20 '14 at 08:19
  • 2
    Well, GCC is a huge codebase. Rebuilds will be long. Note that the `configure` step shouldn't strictly be necessary, but the GCC build system is quite a mess (eh, complicated) that I can't tell you what would require a reconfigure and what not. – rubenvb Nov 20 '14 at 08:20