X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=tools%2Fllvmc%2FConfigLexer.l;h=34b9a17de189037e5dd08050fd685b0981e0c394;hb=9ba8a76f8baaa1092d60ccfbc04e7efdc207c98f;hp=58ddd2bdbdf2d11ecbe8ce98090cb2b478242802;hpb=68fb37ad67d59051585cb7245f802f5c753c074f;p=oota-llvm.git diff --git a/tools/llvmc/ConfigLexer.l b/tools/llvmc/ConfigLexer.l index 58ddd2bdbdf..34b9a17de18 100644 --- a/tools/llvmc/ConfigLexer.l +++ b/tools/llvmc/ConfigLexer.l @@ -14,18 +14,16 @@ %option prefix="Config" -%option yylineno %option nostdinit %option never-interactive %option batch %option noyywrap -%option nodefault %option 8bit %option outfile="ConfigLexer.cpp" %option ecs -%option noreject %option noyymore -%array +%option noreject +%pointer %{ @@ -38,98 +36,166 @@ if (result == 0 ) result = YY_NULL; \ } +#define YY_FATAL_ERROR(msg) \ + { \ + assert(ConfigLexerInput != 0 && "Oops"); \ + ConfigLexerInput->error(msg); \ + } + +#define YY_DECL ConfigLexerTokens llvm::Configlex() + +#define yyterminate() { return EOFTOK; } + using namespace llvm; -/* Conversion of text ints to binary */ -static int64_t IntToVal(const char *Buffer) { - int64_t Result = 0; - for (; *Buffer; Buffer++) { - int64_t OldRes = Result; - Result *= 10; - Result += *Buffer-'0'; +inline llvm::ConfigLexerTokens +handleNameContext(llvm::ConfigLexerTokens token) { + ConfigLexerState.StringVal = yytext; + if (ConfigLexerState.in_value) + return OPTION; + return token; +} + +inline llvm::ConfigLexerTokens +handleSubstitution(llvm::ConfigLexerTokens token) { + if (ConfigLexerState.in_value) { + ConfigLexerState.StringVal = yytext; + return token; } - return Result; + YY_FATAL_ERROR("Substitition tokens not allowed in names" ); + return ERRORTOK; } -bool in_value = false; +inline llvm::ConfigLexerTokens handleValueContext(llvm::ConfigLexerTokens token) { + ConfigLexerState.StringVal = yytext; + if (ConfigLexerState.in_value) + return token; + return OPTION; +} %} -LANG lang|Lang|LANG -PREPROCESSOR preprocessor|PreProcessor|PREPROCESSOR -TRANSLATOR translator|Translator|TRANSLATOR -OPTIMIZER optimizer|Optimizer|OPTIMIZER ASSEMBLER assembler|Assembler|ASSEMBLER -LINKER linker|Linker|LINKER -NAME name|Name|NAME -NEEDED needed|Needed|NEEDED COMMAND command|Command|COMMAND +LANG lang|Lang|LANG +LIBS libs|Libs|LIBS +LINKER linker|Linker|LINKER +NAME name|Name|NAME +OPT1 opt1|Opt1|OPT1 +OPT2 opt2|Opt2|OPT2 +OPT3 opt3|Opt3|OPT3 +OPT4 opt4|Opt4|OPT4 +OPT5 opt5|Opt5|OPT5 +OPTIMIZER optimizer|Optimizer|OPTIMIZER +OUTPUT output|Output|OUTPUT PREPROCESSES preprocesses|PreProcesses|PREPROCESSES -GROKS_DASH_O groks_dash_O|Groks_Dash_O|GROKS_DASH_O -OPTIMIZES optimizes|Optimizes|OPTIMIZES -Comment \#[^\n]* -NewLine \n -White [ \t]* -Option [-A-Za-z0-9_:%+/\\|,]* -Sep \. +PREPROCESSOR preprocessor|PreProcessor|PREPROCESSOR +REQUIRED required|Required|REQUIRED +TRANSLATES translates|Translates|TRANSLATES +TRANSLATOR translator|Translator|TRANSLATOR +VERSION version|Version|VERSION + +True true|True|TRUE|on|On|ON|yes|Yes|YES +False false|False|FALSE|off|Off|OFF|no|No|NO +Bytecode bc|BC|bytecode|Bytecode|BYTECODE +Assembly asm|ASM|assembly|Assembly|ASSEMBLY + +BadSubst \%[a-zA-Z]*\% +Comment \#[^\r\n]*\r?\n +NewLine \r?\n Eq \= +EscNewLine \\\r?\n +Option [-A-Za-z0-9_:%+/\\|,][-A-Za-z0-9_:+/\\|,@]* +Sep \. String \"[^\"]*\" -Integer [-+]?[0-9]+ -True true|True|TRUE -False false|False|FALSE -On on|On|ON -Off off|Off|OFF -Yes yes|Yes|YES -No no|No|NO +White [ \t]* + %% -{NewLine} { in_value = false; ConfigLexerLine++; return EOLTOK; } -{Comment} { /* Ignore comments */ } -{White} { /* Ignore whitespace */ } - -{LANG} { if (in_value) { ConfigLexerData.StringVal = "lang"; - return OPTION; } else return LANG; } -{PREPROCESSOR} { if (in_value) { ConfigLexerData.StringVal = "preprocessor"; - return OPTION; } else return PREPROCESSOR; } -{TRANSLATOR} { if (in_value) { ConfigLexerData.StringVal = "translator"; - return OPTION; } else return TRANSLATOR; } -{OPTIMIZER} { if (in_value) { ConfigLexerData.StringVal = "optimizer"; - return OPTION; } else return OPTIMIZER; } -{ASSEMBLER} { if (in_value) { ConfigLexerData.StringVal = "assembler"; - return OPTION; } else return ASSEMBLER; } -{LINKER} { if (in_value) { ConfigLexerData.StringVal = "linker"; - return OPTION; } else return LINKER; } -{NAME} { if (in_value) { ConfigLexerData.StringVal = "name"; - return OPTION; } else return NAME; } -{NEEDED} { if (in_value) { ConfigLexerData.StringVal = "needed"; - return OPTION; } else return NEEDED; } -{COMMAND} { if (in_value) { ConfigLexerData.StringVal = "command"; - return OPTION; } else return COMMAND; } -{PREPROCESSES} { if (in_value) { ConfigLexerData.StringVal = "preprocesses"; - return OPTION; } else return PREPROCESSES; } -{GROKS_DASH_O} { if (in_value) { ConfigLexerData.StringVal = "groks_dash_O"; - return OPTION; } else return GROKS_DASH_O; } -{OPTIMIZES} { if (in_value) { ConfigLexerData.StringVal = "optimizes"; - return OPTION; } else return OPTIMIZES; } -{Sep} { if (in_value) { ConfigLexerData.StringVal = yytext; - return OPTION; } } - -@in@ { if (in_value) return IN_SUBST; else return ERRORTOK; } -@out@ { if (in_value) return OUT_SUBST; else return ERRORTOK; } -{True} { if (in_value) return TRUETOK; else return ERRORTOK; } -{On} { if (in_value) return TRUETOK; else return ERRORTOK; } -{Yes} { if (in_value) return TRUETOK; else return ERRORTOK; } -{False} { if (in_value) return FALSETOK; else return ERRORTOK; } -{Off} { if (in_value) return FALSETOK; else return ERRORTOK; } -{No} { if (in_value) return FALSETOK; else return ERRORTOK; } - -{Eq} { in_value = true; return EQUALS; } -{Option} { ConfigLexerData.StringVal = yytext; return OPTION; } -{Integer} { ConfigLexerData.IntegerVal = IntToVal(yytext); return INTEGER; } -{String} { yytext[yyleng-1] = 0; // nuke end quote - ConfigLexerData.StringVal = yytext+1; // Nuke start quote +{White} { if (ConfigLexerState.in_value) return SPACE; } + +{Comment} { /* Ignore comments */ + ConfigLexerState.in_value = false; + ConfigLexerState.lineNum++; + return EOLTOK; + } + +{EscNewLine} { ConfigLexerState.lineNum++; + /* Don't return EOLTOK! */ + } + +{NewLine} { ConfigLexerState.in_value = false; + ConfigLexerState.lineNum++; + return EOLTOK; + } + +{Eq} { ConfigLexerState.in_value = true; + return EQUALS; + } + +{Sep} { return SEPARATOR; } + +{VERSION} { return handleNameContext(VERSION_TOK); } + +{LANG} { return handleNameContext(LANG); } +{LIBS} { return handleNameContext(LIBS); } +{NAME} { return handleNameContext(NAME); } +{OPT1} { return handleNameContext(OPT1); } +{OPT2} { return handleNameContext(OPT2); } +{OPT3} { return handleNameContext(OPT3); } +{OPT4} { return handleNameContext(OPT4); } +{OPT5} { return handleNameContext(OPT5); } + +{PREPROCESSOR} { return handleNameContext(PREPROCESSOR); } +{COMMAND} { return handleNameContext(COMMAND); } +{REQUIRED} { return handleNameContext(REQUIRED); } + +{TRANSLATOR} { return handleNameContext(TRANSLATOR); } +{PREPROCESSES} { return handleNameContext(PREPROCESSES); } +{OUTPUT} { return handleNameContext(OUTPUT); } + +{OPTIMIZER} { return handleNameContext(OPTIMIZER); } +{TRANSLATES} { return handleNameContext(TRANSLATES); } + +{ASSEMBLER} { return handleNameContext(ASSEMBLER); } + +{LINKER} { return handleNameContext(LINKER); } + +%args% { return handleSubstitution(ARGS_SUBST); } +%bindir% { return handleSubstitution(BINDIR_SUBST); } +%defs% { return handleSubstitution(DEFS_SUBST); } +%in% { return handleSubstitution(IN_SUBST); } +%incls% { return handleSubstitution(INCLS_SUBST); } +%libdir% { return handleSubstitution(LIBDIR_SUBST); } +%libs% { return handleSubstitution(LIBS_SUBST); } +%llvmgccdir% { return handleSubstitution(LLVMGCCDIR_SUBST); } +%llvmgccarch% { return handleSubstitution(LLVMGCCARCH_SUBST); } +%llvmgcc% { return handleSubstitution(LLVMGCC_SUBST); } +%llvmgxx% { return handleSubstitution(LLVMGXX_SUBST); } +%llvmcc1% { return handleSubstitution(LLVMCC1_SUBST); } +%llvmcc1plus% { return handleSubstitution(LLVMCC1PLUS_SUBST); } +%opt% { return handleSubstitution(OPT_SUBST); } +%out% { return handleSubstitution(OUT_SUBST); } +%stats% { return handleSubstitution(STATS_SUBST); } +%target% { return handleSubstitution(TARGET_SUBST); } +%time% { return handleSubstitution(TIME_SUBST); } +%verbose% { return handleSubstitution(VERBOSE_SUBST); } +%fOpts% { return handleSubstitution(FOPTS_SUBST); } +%MOpts% { return handleSubstitution(MOPTS_SUBST); } +%WOpts% { return handleSubstitution(WOPTS_SUBST); } + +{Assembly} { return handleValueContext(ASSEMBLY); } +{Bytecode} { return handleValueContext(BYTECODE); } +{True} { return handleValueContext(TRUETOK); } +{False} { return handleValueContext(FALSETOK); } + +{Option} { ConfigLexerState.StringVal = yytext; return OPTION; } +{String} { ConfigLexerState.StringVal = yytext+1; // Nuke start quote + ConfigLexerState.StringVal.erase( + --ConfigLexerState.StringVal.end()); return STRING; } +{BadSubst} { YY_FATAL_ERROR("Invalid substitution token"); } %%