Menu

#113 Add support for binary constants v2

closed-accepted
None
5
2008-08-07
2008-08-05
No

Hello everybody,
the attached is my new attempt to bring binary constants to sdcc. Not that this single feature deserves all this work, but since I started...

The series is compound by 4 patches, plus the documentation updates. A brief description follows.

*** 1-use-correct-std-making-lib.patch
This is a bugfix patch. Some device libraries were built with --std-c89, but the code included c++ comments (//). Moreover, CFLAGS got lost for PIC14 when building libdev. This patch ensures that libraries using C99 features are actually built using --std-c99, and fixes the PIC14 issue.

*** 2-sdcpp-implement-sdcc-extensions-framework.patch
This patch makes the preprocessor accept -std=sdcc89 and -std=sdcc99. The effect is limited to enabling the GNU extensions.
Note that to retain some backwards compatibility we should at least enable c++ comments with --std-sdcc89, otherwise a lot of user code will be suddendly broken.

*** 3-sdcc-call-sdcpp-with-correct-std.patch
This patch makes sure sdcpp gets called with the correct -sdc=xxx switch

*** 4-sdcc-implement-binary-constants.patch
This patch finally implements binary constants. Now these are enabled only with -std-sdccxx and I also propagated the changes to the preprocessor.
One note on this: apparently I'm too dumb to understand why the preprocessor cares about constant parsing, and I haven't been able to actually test the code. Note also that even before this patch the preprocessor parsed binary constants in #if tests, regardless of the -std switch.

For what relates the documentation, the source document was written with a relatively old LyX version (1.4.5). Editing it with the latest version (1.5.6) generates a huge diff, and is probably unwanted anyway due to the bump in the required LyX version.
Since I found that the modifications required by this patch series are small, it's probably more efficient to simply ask somebody else using LyX 1.4 to apply them for me ;-)
The changes are:
In section 1.4, add the following to the list:
* in older versions, the preprocessor was always called with -std=c99 regardless of the --std-xxx setting. This is no longer true, and can cause compilation failures on code built with --std-c89 but using c99 preprocessor features, such as one-line (//) comments.
Insert a new section between 3.4 and 3.5, containing the following:
3.5 Other SDCC language extensions
3.5.1 Binary constants
SDCC supports the use of binary constants, such as 0b01100010. This feature is only enabled when the compiler is invoked using --std-sdccxx.
3.5.2 Preprocessor
When invoked with --std-sdccxx, the preprocessor uses the GNU cpp extensions.

This series applies to revision 5202. Please review this carefully before applying since I touched so many parts of the compiler I could very well have done some mistakes.

Mauro

Discussion

  • Mauro Giachero

    Mauro Giachero - 2008-08-05

    Patch series implementing binary constants

     
  • Borut Ražem

    Borut Ražem - 2008-08-05

    Logged In: YES
    user_id=568035
    Originator: NO

    Mauro,

    is it really necessary to introduce -std=sdccXX options to sdcpp? Aren't they equal to GNUC extensions, so that in case of --std-sdccXX sdcc would call sdcpp without -std=XXXX option?

    And I think that binary_constants is not needed:

    if (CLK_GNUC89 == CPP_OPTION (pfile, lang) || CLK_GNUC99 == CPP_OPTION (pfile, lang))

    could be used instead. This is actually a bug in the current sdcpp implementation, since the binary constants are not accepted if -pedantic-parse-number is defined and gcc extensions are enabled.

    If I'm right then we have just to fix a bug in sdcpp and nothing more, since sdcpp already supports binary constants.

    I already prepared the patched version. Just let me know if I missed something...

    > One note on this: apparently I'm too dumb to understand why the
    > preprocessor cares about constant parsing

    see http://sourceforge.net/tracker/index.php?func=detail&aid=982435&group_id=599&atid=100599

    Borut

     
  • Mauro Giachero

    Mauro Giachero - 2008-08-06

    Logged In: YES
    user_id=2160854
    Originator: YES

    Hello Borut,
    thank you for taking the time for reviewing that mess.

    > is it really necessary to introduce -std=sdccXX options to sdcpp? Aren't
    > they equal to GNUC extensions, so that in case of --std-sdccXX sdcc would
    > call sdcpp without -std=XXXX option?

    I don't know what's the sdcpp's behavior when called without -std. Well, I haven't looked. My fault.
    Nevertheless I thought that having some sort of parallelism between sdcc's --std-xxxx and sdcpp's -std=xxxx would be a good idea anyway.
    If you tell me that sdcpp's behavior without -std is a superset of C99, then I'm fine about omitting -std when the compiler is called with --std-sdccxx, and only specifying it as c89 or c99 when the compiler is called with --std-cx9.

    > And I think that binary_constants is not needed:
    >
    > if (CLK_GNUC89 == CPP_OPTION (pfile, lang) || CLK_GNUC99 == CPP_OPTION
    > (pfile, lang))
    >
    > could be used instead. This is actually a bug in the current sdcpp
    > implementation, since the binary constants are not accepted if
    > -pedantic-parse-number is defined and gcc extensions are enabled.

    That's fine. Some part of my brain hadn't realized that binary constants are part of the GCC extensions.

    > I already prepared the patched version. Just let me know if I missed
    > something...

    I didn't see your modified patches anywhere, so I'm going to guess.
    We're talking about modifying the patches 2, 3 and 4 this way:
    - patch 2 is removed;
    - in patch 3 {cppstd} now includes "-std=", and is set only when options.std_sdcc is not
    set;
    - in patch 4, binary_constants and all its management are removed, and the condition in
    lex.c@662 becomes the one you proposed (quoted ~17 lines above).

    Well, that's far smaller than my version ;-).

    Your proposal works fine as far as I can tell, so you have my approval.

    Also, thank you for the link. I was dumb, indeed.

    > Borut

    Mauro

     
  • Borut Ražem

    Borut Ražem - 2008-08-07

    Logged In: YES
    user_id=568035
    Originator: NO

    Hi Mauro,

    > I don't know what's the sdcpp's behavior when called without -std.

    Is the same as gcc cpp's: gcc extensions are enabled by default.

    > Nevertheless I thought that having some sort of parallelism between sdcc's
    > --std-xxxx and sdcpp's -std=xxxx would be a good idea anyway.

    I try to keep sdcc specifics in sdcpp (gcc cpp) as low as possible. Since binary constants are already supported, there is no need to introduce -sdcc=sdccXX options.

    >> if (CLK_GNUC89 == CPP_OPTION (pfile, lang) || CLK_GNUC99 == CPP_OPTION
    >> (pfile, lang))

    Even better solution:
    if (!CPP_OPTION (pfile, std))

    > I didn't see your modified patches anywhere, so I'm going to guess.

    They are on may local svn snapshot and you guess is correct.

    > Also, thank you for the link. I was dumb, indeed.

    In contrary: I would think that you are a genius if you wold foreseen the problem mentioned in the link ;-)

    Modified patch applied in svn revision #5205.

    Borut

     
  • Borut Ražem

    Borut Ražem - 2008-08-07
    • assigned_to: nobody --> borutr
    • status: open --> closed-accepted
     

Log in to post a comment.