Monday, February 1, 2010

A study on genericizer in GCC

The need for genericizer in GCC depends on how well GENERIC can be made to match up with the source language that is supported in GCC front-end.

I.e. In GCC, if the parser for a language uses GENERIC as intermediate language representation, then a genericizer is not required. If the parser language uses any other intermediate language representation, then a genericizer is required to convert that intermediate language representation to GENERIC.

Note: Any intermediate language representation that seems appropriate for a language can be used. [Ref: Page 93 of GCC Internals for GCC version 4.4.0].


Hence there are following two cases:
  • Case1: Parser uses GENERIC as intermediate language representation
  • Case2: Parser uses any other intermediate language representation


Case1: Parser uses GENERIC as intermediate language representation


In this case, the language parser uses GENERIC and some language specific trees as intermediate language representation. [Ref: Page 93 of GCC Internals for GCC version 4.4.0]. The Gimplifier (which belongs to 'language-independent portions of the compiler') is called directly for the GENERIC representation generated by the parser.

The language specific trees which is generated along with the GENERIC by the parser would be converted into GIMPLE as follows [Ref: Page 201 of GCC Internals for GCC version 4.4.0]:

  1. Convert the language specific trees to GENERIC. And then provide the GENERIC to the Gimplifier to generate GIMPLE.
  2. Convert the language specific trees to GIMPLE straightly.
The above two tasks would be done by the gimplifier hooks [Ref: Page 199 of GCC Internals for GCC version 4.4.0]. Gimplifier hooks are the one that are used to over-ride the standard functions of Gimplifier. This over-riding of standard functions is required because of language specific trees generated as intermediate represenation by parser.

Example:

For C, the language specific trees are converted into GIMPLE straightly (without converting into GENERIC) by the gimplifier hooks [Ref: Page 201of GCC Internals for GCC version 4.4.0].



Case2: Parser uses any other intermediate language representation



In this case, the language parser uses its own intermediate language representation [Ref: Page 93 of GCC Internals for GCC version 4.4.0]. And for this intermediate language representation to be used by Gimplifier (which belongs to 'language-independent portions of the compiler'), it should be converted to GENERIC. For this we require a 'Genericizer'. Genericizer converts the intermediate language representation generated by the parser to the GENERIC form. Hence the genericizer would be the language dependent portion of the compiler.

Thus generated GENERIC is given to the gimplifier.

Example:

Monday, December 28, 2009

Conditional inclusion of header files

Ram (one of my peers, name changed) complained that he was unable to create an object of class (say clsX).

We have the practise of having our class declarations in header files. So the declaration of the class clsX was in X.h file.

To define an object of class clsX in a soure file, Ram had included the header file X.h in the source file. Despite that he was unable to define the object of class clsX. He got compiler error for the same.

Ram complained Ravi (one of my peers, name changed) that he was unable to create an object of class clsX. Ravi is the one who wrote the class clsX.

Ravi worked on it to provide the following report:
  1. I am not sure about why this problem is occurring, but it seems to be because of some issue with C++ compilers, as mentioned in these two posts I found for the error C2143 -
    1. http://sabbour.wordpress.com/2006/12/30/error-c2143-syntax-error-missing-before/
    2. http://www-subatech.in2p3.fr/~photons/subatech/soft/carnac/CPP-INC-1.shtml
  2. I tried moving the class declaration to the source file, and then removed the header file inclusion. The problem was resolved, which means the contents of the header file 'clsX.h' do not have any syntax error.
  3. I removed the inclusion of the header file 'clsX.h' and instead used a forward declaration as follows, and this solution worked fine.
  4. Please use a forward declaration for the class clsTable, as mentioned in point 3 above, to continue your analysis. I shall look into the problem further to ascertain the root cause.
I decided to have a hand on the problem under discussion. By seeing the compiler error, I got that the declaration of the class clsX didn't reach the source file despite the inclusion of header file X.h.

We use preprocessor directives to conditionally include a header file content into other source file. This is to avoid the duplication of declarations.

On checking the macro that is used along with the preprocessor directives in X.h, I found that the macro used is already defined in some other header file (say Y.h). The header file Y.h is already included in the source file in which X.h is also included. Because of which the macro defined in Y.h eliminated the inclusion of X.h contents.

I.e.

Y.h
 #ifndef _Y_H
 #define _Y_H
 ...
 ...
 #endif

X.h
 #ifndef _Y_H
 #define _Y_H
 declaration of class clsX
 #endif

Z.c
 #include "../Y/Y.h"
 #include "../X/X.h"
 define object of class clsX

Here you can see that the contents of header file X.h (I.e. declaration of class clsX), won't be included. This is because the contents of header file X.h would be included in file Z.c only if the macro _Y_H is not defined before. But macro _Y_H is already defined in Z.c by the inclusion of header file Y.h.

I pointed out the mistake of using the same macro for two header files which solved the problem.

Monday, November 30, 2009

Sharing files/folders to Windows clients from linux (Ubuntu)

Right click the folder that needs to be shared. Select the option 'Sharing Options'. The file manager window gets open.



Enable 'Share this folder'. On doing so, if the sharing service is not installed the following window will appear.



Press the button "Install service". It will install the SMB service.



After successful installation, it will ask to retsart your session.



Press the button "Restart session".

And now add a SMB user. To do so, open the terminal in Ubuntu and type the following command.

 sudo smbpasswd -a username

This will ask for the new SMB password for the username given. Provide the SMB password. After successful addition of SMB user, the shared folder can be accessed from the windows client using the username and password created.