- add mostly all GCC/MSVC keywords
authorMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Tue, 4 Dec 2007 15:05:49 +0000 (15:05 +0000)
committerMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Tue, 4 Dec 2007 15:05:49 +0000 (15:05 +0000)
- add c_mode: contains current dialect/C-mode
- add command line switches to set the C mode

[r18598]

lang_features.h [new file with mode: 0644]
main.c
token.c
token_t.h
tokens.inc
tokens_preprocessor.inc

diff --git a/lang_features.h b/lang_features.h
new file mode 100644 (file)
index 0000000..cfddd86
--- /dev/null
@@ -0,0 +1,16 @@
+#ifndef LANG_FEATURES_H
+#define LANG_FEATURES_H
+
+enum lang_features {
+       _ANCIENT = 1,
+       _ANSI    = 2,
+       _C99     = 4,
+       _GNUC    = 8,
+       _MS      = 16,
+       _ALL     = 0xFF
+};
+
+/* the current C mode/dialect */
+extern unsigned int c_mode;
+
+#endif
diff --git a/main.c b/main.c
index a05fbdc..70c5ba0 100644 (file)
--- a/main.c
+++ b/main.c
@@ -22,6 +22,7 @@
 #include "type_hash.h"
 #include "parser.h"
 #include "ast2firm.h"
+#include "lang_features.h"
 #include "driver/firm_cmdline.h"
 #include "adt/error.h"
 #include "write_fluffy.h"
 #endif
 
 #ifndef LINKER
-#define LINKER       "gcc"
+#define LINKER       "gcc -m32"
 #endif
 
 #ifndef ASSEMBLER
-#define ASSEMBLER "as"
+#define ASSEMBLER "as --32"
 #endif
 
 #ifdef _WIN32
@@ -45,6 +46,9 @@
 #define pclose(file)      _pclose(file)
 #endif /* _WIN32 */
 
+/** The current c mode/dialect */
+unsigned int c_mode = _C99|_GNUC;
+
 static int            verbose;
 static bool           do_dump;
 static struct obstack cppflags_obst;
@@ -333,6 +337,14 @@ int main(int argc, char **argv)
                        mode = CompileAssemble;
                } else if(strcmp(arg, "-S") == 0) {
                        mode = Compile;
+               } else if(strcmp(arg, "--gcc") == 0) {
+                       c_mode |= _GNUC;
+               } else if(strcmp(arg, "--no-gcc") == 0) {
+                       c_mode &= ~_GNUC;
+               } else if(strcmp(arg, "--ms") == 0) {
+                       c_mode |= _MS;
+               } else if(strcmp(arg, "--no-ms") == 0) {
+                       c_mode &= ~_MS;
                } else if(strcmp(arg, "--lextest") == 0) {
                        mode = LexTest;
                } else if(strcmp(arg, "--print-ast") == 0) {
diff --git a/token.c b/token.c
index d567124..3a30ddd 100644 (file)
--- a/token.c
+++ b/token.c
@@ -6,6 +6,7 @@
 #include <stdio.h>
 
 #include "symbol.h"
+#include "lang_features.h"
 #include "adt/array.h"
 
 static symbol_t *token_symbols[T_LAST_TOKEN];
@@ -18,11 +19,13 @@ void init_tokens(void)
 
        memset(token_symbols, 0, T_LAST_TOKEN * sizeof(token_symbols[0]));
 
-#define T(x,str,val)                                               \
-       assert(T_##x >= 0 && T_##x < T_LAST_TOKEN);                    \
-       symbol               = symbol_table_insert(str);               \
-       symbol->ID           = T_##x;                                  \
-       token_symbols[T_##x] = symbol;
+#define T(mode,x,str,val)                                          \
+       if (c_mode & (mode)) {                                         \
+               assert(T_##x >= 0 && T_##x < T_LAST_TOKEN);                \
+               symbol               = symbol_table_insert(str);           \
+               symbol->ID           = T_##x;                              \
+               token_symbols[T_##x] = symbol;                             \
+       }
 
 #define TS(x,str,val)                                              \
        assert(T_##x >= 0 && T_##x < T_LAST_TOKEN);                    \
@@ -34,7 +37,7 @@ void init_tokens(void)
 #undef TS
 #undef T
 
-#define T(x,str,val)                                               \
+#define T(mode,x,str,val)                                          \
        assert(TP_##x >= 0 && TP_##x < TP_LAST_TOKEN);                 \
        symbol               = symbol_table_insert(str);               \
        symbol->pp_ID        = TP_##x;
index 822d666..317cc3b 100644 (file)
--- a/token_t.h
+++ b/token_t.h
@@ -8,7 +8,7 @@
 #include "type.h"
 
 typedef enum {
-#define T(x,str,val) T_##x val,
+#define T(mode,x,str,val) T_##x val,
 #define TS(x,str,val) T_##x val,
 #include "tokens.inc"
 #undef TS
@@ -19,7 +19,7 @@ typedef enum {
 } token_type_t;
 
 typedef enum {
-#define T(x,str,val) TP_##x val,
+#define T(mode,x,str,val) TP_##x val,
 #define TS(x,str,val) TP_##x val,
 #include "tokens_preprocessor.inc"
 #undef TS
index 8cb02b7..e01ffd4 100644 (file)
@@ -8,140 +8,196 @@ TS(FLOATINGPOINT,       "floatingpoint number",)
 TS(STRING_LITERAL,      "string literal",)
 TS(WIDE_STRING_LITERAL, "wide string literal",)
 
-#define S(x)   T(x,#x,)
-S(auto)
-S(break)
-S(case)
-S(char)
-S(continue)
-S(default)
-S(do)
-S(double)
-S(else)
-S(enum)
-S(extern)
-S(float)
-S(for)
-S(goto)
-S(if)
-S(int)
-S(long)
-S(register)
-S(return)
-S(short)
-S(signed)
-S(sizeof)
-S(static)
-S(struct)
-S(switch)
-S(typedef)
-S(union)
-S(unsigned)
-S(void)
-S(while)
-S(_Bool)
-S(_Complex)
-S(_Imaginary)
-S(__thread)
-S(__extension__)
-S(__attribute__)
-S(__builtin_classify_type)
-S(__builtin_va_list)
-S(__builtin_expect)
-S(__builtin_offsetof)
-S(__builtin_va_arg)
-S(__builtin_va_end)
-S(__builtin_alloca)
-S(__builtin_nanf)
-S(__builtin_nan)
-S(__builtin_nand)
-S(__builtin_isgreater)
-S(__builtin_isgreaterequal)
-S(__builtin_isless)
-S(__builtin_islessequal)
-S(__builtin_islessgreater)
-S(__builtin_isunordered)
-S(__PRETTY_FUNCTION__)
-S(__FUNCTION__)
-S(__func__)
-S(__alignof__)
-S(__real__)
-S(__imag__)
+#define S(mode,x)   T(mode,x,#x,)
+S(_ALL, auto)
+S(_ALL, break)
+S(_ALL, case)
+S(_ALL, char)
+S(_ALL, continue)
+S(_ALL, default)
+S(_ALL, do)
+S(_ALL, double)
+S(_ALL, else)
+S(_ALL, enum)
+S(_ALL, extern)
+S(_ALL, float)
+S(_ALL, for)
+S(_ALL, goto)
+S(_ALL, if)
+S(_ALL, int)
+S(_ALL, long)
+S(_ALL, register)
+S(_ALL, return)
+S(_ALL, short)
+S(_ANSI|_C99, signed)
+S(_ALL, sizeof)
+S(_ALL, static)
+S(_ALL, struct)
+S(_ALL, switch)
+S(_ALL, typedef)
+S(_ALL, union)
+S(_ALL, unsigned)
+S(_ALL, void)
+S(_ALL, while)
+
+S(_C99|_GNUC, _Bool)
+S(_C99|_GNUC, _Complex)
+S(_C99|_GNUC, _Imaginary)
+S(_GNUC, __thread)
+S(_GNUC, __extension__)
+S(_GNUC, __builtin_classify_type)
+S(_GNUC, __builtin_va_list)
+S(_GNUC, __builtin_expect)
+S(_GNUC, __builtin_offsetof)
+S(_GNUC, __builtin_va_arg)
+S(_GNUC, __builtin_va_end)
+S(_GNUC, __builtin_alloca)
+S(_GNUC, __builtin_nanf)
+S(_GNUC, __builtin_nan)
+S(_GNUC, __builtin_nand)
+S(_GNUC, __builtin_isgreater)
+S(_GNUC, __builtin_isgreaterequal)
+S(_GNUC, __builtin_isless)
+S(_GNUC, __builtin_islessequal)
+S(_GNUC, __builtin_islessgreater)
+S(_GNUC, __builtin_isunordered)
+S(_C99, __PRETTY_FUNCTION__)
+S(_ALL, __FUNCTION__)
+S(_C99, __func__)
+S(_C99, __alignof__)
 #undef S
 
-T(const,                  "__const",)
-T(_const,                 "const",                  = T_const)
-T(restrict,               "__restrict",)
-T(_restrict,              "restrict",               = T_restrict)
-T(asm,                    "asm",)
-T(__asm__,                "__asm__",                = T_asm)
-T(volatile,               "volatile",)
-T(__volatile__,           "__volatile__",           = T_volatile)
-T(inline,                 "inline",)
-T(__inline,               "__inline",               = T_inline)
-T(__inline__,             "__inline__",             = T_inline)
-T(typeof,                 "typeof",)
-T(__typeof__,             "__typeof__",             = T_typeof)
-T(__builtin_va_start,     "__builtin_va_start",)
-T(__builtin_stdarg_start, "__builtin_stdarg_start", = T___builtin_va_start)
+T(_GNUC,      real,           "__real__",)
+T(_GNUC,      _real,          "__real",                 = T_real)
+T(_GNUC,      imag,           "__imag__",)
+T(_GNUC,      _imag,          "__imag",                 = T_imag)
+T(_GNUC|_MS,  __alignof,      "__alignof",              = T___alignof__)
+T(_MS,        _alignof,       "_alignof",               = T___alignof__)
+T(_ANSI|_C99, const,          "const",)
+T(_GNUC,      _const,         "__const",                = T_const)
+T(_GNUC|_MS,  restrict,       "__restrict",)
+T(_GNUC,      _restrict_,     "__restrict__",           = T_restrict)
+T(_C99,       _restrict,      "restrict",               = T_restrict)
+T(_ALL,       asm,            "asm",)
+T(_GNUC,      __asm__,        "__asm__",                = T_asm)
+T(_ANSI|_C99, volatile,       "volatile",)
+T(_GNUC,      __volatile__,   "__volatile__",           = T_volatile)
+T(_C99,       inline,         "inline",)
+T(_GNUC|_MS,  __inline,       "__inline",               = T_inline)
+T(_GNUC,      __inline__,     "__inline__",             = T_inline)
+T(_GNUC,      typeof,         "typeof",)
+T(_GNUC,      __typeof,       "__typeof",               = T_typeof)
+T(_GNUC,      __typeof__,     "__typeof__",             = T_typeof)
+T(_GNUC,      attribute,      "__attribute",)
+T(_GNUC,      __attribute__,  "__attribute__",          = T_attribute)
+
+T(_GNUC,     __builtin_va_start,     "__builtin_va_start",)
+T(_GNUC,     __builtin_stdarg_start, "__builtin_stdarg_start", = T___builtin_va_start)
+
+T(_MS,       near,            "_near",)
+T(_MS,       _near,           "__near",                  = T_near)
+T(_MS,       far,             "_far",)
+T(_MS,       _far,            "__far",                   = T_far)
+T(_MS,      _asm,             "_asm",                    = T_asm)
+T(_MS,      __asm,            "__asm",                   = T_asm)
+T(_MS,      cdecl,            "cdecl",)
+T(_MS,      _cdecl,           "_cdecl",                  = T_cdecl)
+T(_MS,      __cdecl,          "__cdecl",                 = T_cdecl)
+T(_MS,      stdcall,          "_stdcall",)
+T(_MS,      __stdcall,        "__stdcall",               = T_stdcall)
+T(_MS,      fastcall,         "_fastcall",)
+T(_MS,      __fastcall,       "__fastcall",              = T_fastcall)
+T(_MS,      thiscall,         "_thiscall",)
+T(_MS,      __thiscall,       "__thiscall",              = T_thiscall)
+T(_MS,      forceinline,      "_forceinline",)
+T(_MS,      __forceinline,    "__forceinline",           = T_forceinline)
+T(_MS,      unaligned,        "_unaligned",)
+T(_MS,      __unaligned,      "__unaligned",             = T_unaligned)
+T(_MS,      assume,           "_assume",)
+T(_MS,      __assume,         "__assume",                = T_assume)
+T(_MS,      try,              "_try",)
+T(_MS,      __try,            "__try",                   = T_try)
+T(_MS,      finally,          "_finally",)
+T(_MS,      __finally,        "__finally",               = T_finally)
+T(_MS,      leave,            "_leave",)
+T(_MS,      __leave,          "__leave",                 = T_leave)
+T(_MS,      except,           "_except",)
+T(_MS,      __except,         "__except",                = T_except)
+T(_MS,      declspec,         "_declspec",)
+T(_MS,      __declspec,       "__declspec",              = T_declspec)
+T(_MS,      based,            "_based",)
+T(_MS,      __based,          "__based",                 = T_based)
 
-T(MINUSGREATER,             "->",)
-T(PLUSPLUS,                 "++",)
-T(MINUSMINUS,               "--",)
-T(LESSLESS,                 "<<",)
-T(GREATERGREATER,           ">>",)
-T(LESSEQUAL,                "<=",)
-T(GREATEREQUAL,             ">=",)
-T(EQUALEQUAL,               "==",)
-T(EXCLAMATIONMARKEQUAL,     "!=",)
-T(ANDAND,                   "&&",)
-T(PIPEPIPE,                 "||",)
-T(DOTDOTDOT,                "...",)
-T(ASTERISKEQUAL,            "*=",)
-T(SLASHEQUAL,               "/=",)
-T(PERCENTEQUAL,             "%=",)
-T(PLUSEQUAL,                "+=",)
-T(MINUSEQUAL,               "-=",)
-T(LESSLESSEQUAL,            "<<=",)
-T(GREATERGREATEREQUAL,      ">>=",)
-T(ANDEQUAL,                 "&=",)
-T(CARETEQUAL,               "^=",)
-T(PIPEEQUAL,                "|=",)
-T(HASHHASH,                 "##",)
+T(_MS,      int8,             "_int8",)
+T(_MS,      __int8,           "__int8",                  = T_int8)
+T(_MS,      int16,            "_int16",)
+T(_MS,      __int16,          "__int16",                 = T_int16)
+T(_MS,      int32,            "_int32",)
+T(_MS,      __int32,          "__int32",                 = T_int32)
+T(_MS,      int64,            "_int64",)
+T(_MS,      __int64,          "__int64",                 = T_int64)
+
+#define _T(x,str,val) T(_ALL,x,str,val)
+
+_T(MINUSGREATER,             "->",)
+_T(PLUSPLUS,                 "++",)
+_T(MINUSMINUS,               "--",)
+_T(LESSLESS,                 "<<",)
+_T(GREATERGREATER,           ">>",)
+_T(LESSEQUAL,                "<=",)
+_T(GREATEREQUAL,             ">=",)
+_T(EQUALEQUAL,               "==",)
+_T(EXCLAMATIONMARKEQUAL,     "!=",)
+_T(ANDAND,                   "&&",)
+_T(PIPEPIPE,                 "||",)
+_T(DOTDOTDOT,                "...",)
+_T(ASTERISKEQUAL,            "*=",)
+_T(SLASHEQUAL,               "/=",)
+_T(PERCENTEQUAL,             "%=",)
+_T(PLUSEQUAL,                "+=",)
+_T(MINUSEQUAL,               "-=",)
+_T(LESSLESSEQUAL,            "<<=",)
+_T(GREATERGREATEREQUAL,      ">>=",)
+_T(ANDEQUAL,                 "&=",)
+_T(CARETEQUAL,               "^=",)
+_T(PIPEEQUAL,                "|=",)
+_T(HASHHASH,                 "##",)
 
 #define T_LAST_TOKEN  (T_HASHHASH+1)
 
-T(LESSCOLON,                "<:",   = '[')
-T(COLONGREATER,             ":>",   = ']')
-T(LESSPERCENT,              "<%",   = '{')
-T(PERCENTGREATER,           "%>",   = '}')
-T(PERCENTCOLON,             "%:",   = '#')
-T(PERCENTCOLONPERCENTCOLON, "%:%:", = T_HASHHASH)
+_T(LESSCOLON,                "<:",   = '[')
+_T(COLONGREATER,             ":>",   = ']')
+_T(LESSPERCENT,              "<%",   = '{')
+_T(PERCENTGREATER,           "%>",   = '}')
+_T(PERCENTCOLON,             "%:",   = '#')
+_T(PERCENTCOLONPERCENTCOLON, "%:%:", = T_HASHHASH)
+
+_T(RBRACK,          "[", = '[')
+_T(LBRACK,          "]", = ']')
+_T(LBRACE,          "(", = '(')
+_T(RBRACE,          ")", = ')')
+_T(RCURLY,          "{", = '{')
+_T(LCURLY,          "}", = '}')
+_T(DOT,             ".", = '.')
+_T(AND,             "&", = '&')
+_T(ASTERISK,        "*", = '*')
+_T(PLUS,            "+", = '+')
+_T(MINUS,           "-", = '-')
+_T(TILDE,           "~", = '~')
+_T(EXCLAMATIONMARK, "!", = '!')
+_T(SLASH,           "/", = '/')
+_T(PERCENT,         "%", = '%')
+_T(LESS,            "<", = '<')
+_T(GREATER,         ">", = '>')
+_T(CARET,           "^", = '^')
+_T(PIPE,            "|", = '|')
+_T(QUESTIONMARK,    "?", = '?')
+_T(COLON,           ":", = ':')
+_T(SEMICOLON,       ";", = ';')
+_T(EQUAL,           "=", = '=')
+_T(COMMA,           ",", = ',')
+_T(HASH,            "#", = '#')
 
-T(RBRACK,          "[", = '[')
-T(LBRACK,          "]", = ']')
-T(LBRACE,          "(", = '(')
-T(RBRACE,          ")", = ')')
-T(RCURLY,          "{", = '{')
-T(LCURLY,          "}", = '}')
-T(DOT,             ".", = '.')
-T(AND,             "&", = '&')
-T(ASTERISK,        "*", = '*')
-T(PLUS,            "+", = '+')
-T(MINUS,           "-", = '-')
-T(TILDE,           "~", = '~')
-T(EXCLAMATIONMARK, "!", = '!')
-T(SLASH,           "/", = '/')
-T(PERCENT,         "%", = '%')
-T(LESS,            "<", = '<')
-T(GREATER,         ">", = '>')
-T(CARET,           "^", = '^')
-T(PIPE,            "|", = '|')
-T(QUESTIONMARK,    "?", = '?')
-T(COLON,           ":", = ':')
-T(SEMICOLON,       ";", = ';')
-T(EQUAL,           "=", = '=')
-T(COMMA,           ",", = ',')
-T(HASH,            "#", = '#')
+#undef _T
 
 TS(NEWLINE,        "newline", = '\n')
index fc8def9..e2ab81d 100644 (file)
@@ -1,4 +1,4 @@
-#define S(x)   T(x,#x,)
+#define S(x)   T(_ALL,x,#x,)
 
 S(if)
 S(else)