Looking for a conditional macro processing algorithm

jwang@seas.smu.edu (Jainbai Wang)
Wed, 25 May 1994 02:20:00 GMT

          From comp.compilers

Related articles
Looking for a conditional macro processing algorithm jwang@seas.smu.edu (1994-05-25)
| List of all articles for this month |

Newsgroups: comp.compilers
From: jwang@seas.smu.edu (Jainbai Wang)
Keywords: C, macros, question
Organization: Compilers Central
Date: Wed, 25 May 1994 02:20:00 GMT

I am writing a cpp's macro processor for a special application. The
program needs to propagate C preprocessor's conditional macro to assembly
code and generate total size for defined data. For example, C definition:


                  #ifdef D
                        struct X a; /* X and Y are structs * /
                  #else
                        struct Y b;
                  # ifdef SHORT
                              short B;
                  # else
                              int B;
                  # endif
                  #endif
                  long C;


needs to be converted into:


                  IFDEF D
                      S equ sizeof(X)+sizeof(long)
                  ELSE
                  IFDEF SHORT
                      S equ sizeof(Y)+sizeof(short)+sizeof(long)
                  ELSE
                      S equ sizeof(Y)+sizeof(int)+sizeof(long)
                  ENDIF
                  ENDIF


where sizeof() represents the size of its parameter.


I wrote a decision-tree type of algorithm for it. But I feel there may
already exist algorithms and even code for this problem. Your help are
appreciated. Thanks.
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.