Reid Spencer | 68fb37a | 2004-08-14 09:37:15 +0000 | [diff] [blame] | 1 | /*===- ConfigLexer.l - Scanner for CompilerDriver Config Files -*- C++ -*--===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by Reid Spencer and is distributed under the |
| 6 | // University of Illinois Open Source License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the flex scanner for configuration files for the |
| 11 | // llvmc CompilerDriver. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===*/ |
| 14 | |
| 15 | |
| 16 | %option prefix="Config" |
Reid Spencer | 68fb37a | 2004-08-14 09:37:15 +0000 | [diff] [blame] | 17 | %option nostdinit |
| 18 | %option never-interactive |
| 19 | %option batch |
| 20 | %option noyywrap |
| 21 | %option nodefault |
| 22 | %option 8bit |
| 23 | %option outfile="ConfigLexer.cpp" |
| 24 | %option ecs |
Reid Spencer | 68fb37a | 2004-08-14 09:37:15 +0000 | [diff] [blame] | 25 | %option noyymore |
Reid Spencer | bae6825 | 2004-08-19 04:49:47 +0000 | [diff] [blame] | 26 | %option noreject |
| 27 | %pointer |
Reid Spencer | 68fb37a | 2004-08-14 09:37:15 +0000 | [diff] [blame] | 28 | |
| 29 | %{ |
| 30 | |
| 31 | #include "ConfigLexer.h" |
| 32 | |
| 33 | #define YY_INPUT(buf,result,max_size) \ |
| 34 | { \ |
| 35 | assert(ConfigLexerInput != 0 && "Oops"); \ |
| 36 | result = ConfigLexerInput->read(buf,max_size); \ |
| 37 | if (result == 0 ) result = YY_NULL; \ |
| 38 | } |
| 39 | |
Reid Spencer | bae6825 | 2004-08-19 04:49:47 +0000 | [diff] [blame] | 40 | #define YY_FATAL_ERROR(msg) \ |
| 41 | { \ |
| 42 | assert(ConfigLexerInput != 0 && "Oops"); \ |
| 43 | ConfigLexerInput->error(msg); \ |
| 44 | } |
| 45 | |
Reid Spencer | bf43772 | 2004-08-15 08:19:46 +0000 | [diff] [blame] | 46 | #define YY_DECL ConfigLexerTokens llvm::Configlex() |
| 47 | |
| 48 | #define yyterminate() { return EOFTOK; } |
| 49 | |
Reid Spencer | 68fb37a | 2004-08-14 09:37:15 +0000 | [diff] [blame] | 50 | using namespace llvm; |
| 51 | |
Reid Spencer | bae6825 | 2004-08-19 04:49:47 +0000 | [diff] [blame] | 52 | inline llvm::ConfigLexerTokens |
| 53 | handleContext(const char* tokenText, llvm::ConfigLexerTokens token) { |
| 54 | if (ConfigLexerState.in_value) { |
| 55 | ConfigLexerState.StringVal = tokenText; |
| 56 | return OPTION; |
Reid Spencer | 68fb37a | 2004-08-14 09:37:15 +0000 | [diff] [blame] | 57 | } |
Reid Spencer | bae6825 | 2004-08-19 04:49:47 +0000 | [diff] [blame] | 58 | return token; |
Reid Spencer | 68fb37a | 2004-08-14 09:37:15 +0000 | [diff] [blame] | 59 | } |
| 60 | |
Reid Spencer | bae6825 | 2004-08-19 04:49:47 +0000 | [diff] [blame] | 61 | inline llvm::ConfigLexerTokens |
| 62 | handleSubstitution(llvm::ConfigLexerTokens token) { |
| 63 | if (ConfigLexerState.in_value) |
| 64 | return token; |
| 65 | YY_FATAL_ERROR("Substitition tokens not allowed in names" ); |
| 66 | return ERRORTOK; |
| 67 | }; |
| 68 | |
| 69 | inline llvm::ConfigLexerTokens handleBoolean(llvm::ConfigLexerTokens token) { |
| 70 | if (ConfigLexerState.in_value) |
| 71 | return token; |
| 72 | YY_FATAL_ERROR("Boolean values not allowed in names"); |
| 73 | return ERRORTOK; |
| 74 | } |
Reid Spencer | 68fb37a | 2004-08-14 09:37:15 +0000 | [diff] [blame] | 75 | |
| 76 | %} |
| 77 | |
Reid Spencer | 68fb37a | 2004-08-14 09:37:15 +0000 | [diff] [blame] | 78 | ASSEMBLER assembler|Assembler|ASSEMBLER |
Reid Spencer | 53aa793 | 2004-08-20 22:53:11 +0000 | [diff] [blame^] | 79 | BadSubst \%[^iots][a-zA-Z]\% |
Reid Spencer | bae6825 | 2004-08-19 04:49:47 +0000 | [diff] [blame] | 80 | COMMAND command|Command|COMMAND |
| 81 | Comment \#[^\n]*\n |
| 82 | NewLine \n |
| 83 | Eq \= |
| 84 | EscNewLine \\\n |
| 85 | GROKS_DASH_O groks_dash_O|Groks_Dash_O|GROKS_DASH_O |
| 86 | LANG lang|Lang|LANG |
Reid Spencer | 68fb37a | 2004-08-14 09:37:15 +0000 | [diff] [blame] | 87 | LINKER linker|Linker|LINKER |
| 88 | NAME name|Name|NAME |
Reid Spencer | bf43772 | 2004-08-15 08:19:46 +0000 | [diff] [blame] | 89 | OPT1 opt1|Opt1|OPT1 |
| 90 | OPT2 opt2|Opt2|OPT2 |
| 91 | OPT3 opt3|Opt3|OPT3 |
| 92 | OPT4 opt4|Opt4|OPT4 |
| 93 | OPT5 opt5|Opt5|OPT5 |
Reid Spencer | bae6825 | 2004-08-19 04:49:47 +0000 | [diff] [blame] | 94 | OPTIMIZER optimizer|Optimizer|OPTIMIZER |
| 95 | OPTIMIZES optimizes|Optimizes|OPTIMIZES |
Reid Spencer | 53aa793 | 2004-08-20 22:53:11 +0000 | [diff] [blame^] | 96 | Option [-A-Za-z0-9_:%+/\\|,][-A-Za-z0-9_:+/\\|,@]* |
Reid Spencer | bae6825 | 2004-08-19 04:49:47 +0000 | [diff] [blame] | 97 | OUTPUT_IS_ASM output_is_asm|Output_Is_Asm|OUTPUT_IS_ASM |
| 98 | PREPROCESSES preprocesses|PreProcesses|PREPROCESSES |
| 99 | PREPROCESSOR preprocessor|PreProcessor|PREPROCESSOR |
| 100 | REQUIRED required|Required|REQUIRED |
Reid Spencer | 68fb37a | 2004-08-14 09:37:15 +0000 | [diff] [blame] | 101 | Sep \. |
Reid Spencer | 68fb37a | 2004-08-14 09:37:15 +0000 | [diff] [blame] | 102 | String \"[^\"]*\" |
Reid Spencer | bae6825 | 2004-08-19 04:49:47 +0000 | [diff] [blame] | 103 | TRANSLATES translates|Translates|TRANSLATES |
| 104 | TRANSLATOR translator|Translator|TRANSLATOR |
| 105 | White [ \t]* |
| 106 | |
Reid Spencer | 68fb37a | 2004-08-14 09:37:15 +0000 | [diff] [blame] | 107 | True true|True|TRUE |
| 108 | False false|False|FALSE |
| 109 | On on|On|ON |
| 110 | Off off|Off|OFF |
| 111 | Yes yes|Yes|YES |
| 112 | No no|No|NO |
| 113 | |
| 114 | %% |
| 115 | |
Reid Spencer | 68fb37a | 2004-08-14 09:37:15 +0000 | [diff] [blame] | 116 | {White} { /* Ignore whitespace */ } |
| 117 | |
Reid Spencer | bae6825 | 2004-08-19 04:49:47 +0000 | [diff] [blame] | 118 | {Comment} { /* Ignore comments */ |
| 119 | ConfigLexerState.in_value = false; |
| 120 | ConfigLexerState.lineNum++; |
| 121 | return EOLTOK; |
| 122 | } |
Reid Spencer | 68fb37a | 2004-08-14 09:37:15 +0000 | [diff] [blame] | 123 | |
Reid Spencer | bae6825 | 2004-08-19 04:49:47 +0000 | [diff] [blame] | 124 | {EscNewLine} { ConfigLexerState.lineNum++; |
| 125 | /* Don't return EOLTOK! */ |
| 126 | } |
| 127 | |
| 128 | {NewLine} { ConfigLexerState.in_value = false; |
| 129 | ConfigLexerState.lineNum++; |
| 130 | return EOLTOK; |
| 131 | } |
| 132 | |
| 133 | {Eq} { ConfigLexerState.in_value = true; |
| 134 | return EQUALS; |
| 135 | } |
| 136 | |
| 137 | {LANG} { return handleContext("lang",LANG); } |
| 138 | {PREPROCESSOR} { return handleContext("preprocessor",PREPROCESSOR); } |
| 139 | {TRANSLATOR} { return handleContext("translator",TRANSLATOR); } |
| 140 | {OPTIMIZER} { return handleContext("optimizer",OPTIMIZER); } |
| 141 | {ASSEMBLER} { return handleContext("assembler",ASSEMBLER); } |
| 142 | {LINKER} { return handleContext("linker",LINKER); } |
| 143 | {NAME} { return handleContext("name",NAME); } |
| 144 | {REQUIRED} { return handleContext("required",REQUIRED); } |
| 145 | {COMMAND} { return handleContext("command",COMMAND); } |
| 146 | {PREPROCESSES} { return handleContext("preprocesses",PREPROCESSES); } |
| 147 | {TRANSLATES} { return handleContext("translates",TRANSLATES); } |
| 148 | {OPTIMIZES} { return handleContext("optimizes",OPTIMIZES); } |
| 149 | {GROKS_DASH_O} { return handleContext("groks_dash_O",GROKS_DASH_O); } |
| 150 | {OUTPUT_IS_ASM} { return handleContext("output_ias_asm",OUTPUT_IS_ASM); } |
| 151 | {OPT1} { return handleContext("opt1",OPT1); } |
| 152 | {OPT2} { return handleContext("opt2",OPT2); } |
| 153 | {OPT3} { return handleContext("opt3",OPT3); } |
| 154 | {OPT4} { return handleContext("opt4",OPT4); } |
| 155 | {OPT5} { return handleContext("opt5",OPT5); } |
| 156 | |
Reid Spencer | 53aa793 | 2004-08-20 22:53:11 +0000 | [diff] [blame^] | 157 | %in% { return handleSubstitution(IN_SUBST); } |
| 158 | %out% { return handleSubstitution(OUT_SUBST); } |
| 159 | %time% { return handleSubstitution(TIME_SUBST); } |
| 160 | %stats% { return handleSubstitution(STATS_SUBST); } |
| 161 | %opt% { return handleSubstitution(OPT_SUBST); } |
| 162 | %target% { return handleSubstitution(TARGET_SUBST); } |
Reid Spencer | bae6825 | 2004-08-19 04:49:47 +0000 | [diff] [blame] | 163 | {BadSubst} { YY_FATAL_ERROR("Invalid substitution token"); } |
| 164 | {True} { return handleBoolean(TRUETOK); } |
| 165 | {On} { return handleBoolean(TRUETOK); } |
| 166 | {Yes} { return handleBoolean(TRUETOK); } |
| 167 | {False} { return handleBoolean(FALSETOK); } |
| 168 | {Off} { return handleBoolean(FALSETOK); } |
| 169 | {No} { return handleBoolean(FALSETOK); } |
| 170 | |
| 171 | {Option} { ConfigLexerState.StringVal = yytext; return OPTION; } |
| 172 | {String} { ConfigLexerState.StringVal = yytext+1; // Nuke start quote |
| 173 | ConfigLexerState.StringVal.erase( |
| 174 | --ConfigLexerState.StringVal.end()); |
Reid Spencer | 68fb37a | 2004-08-14 09:37:15 +0000 | [diff] [blame] | 175 | return STRING; |
| 176 | } |
Reid Spencer | bae6825 | 2004-08-19 04:49:47 +0000 | [diff] [blame] | 177 | {Sep} { if (ConfigLexerState.in_value) { ConfigLexerState.StringVal = yytext; |
Reid Spencer | bf43772 | 2004-08-15 08:19:46 +0000 | [diff] [blame] | 178 | return OPTION; } } |
| 179 | |
Reid Spencer | 68fb37a | 2004-08-14 09:37:15 +0000 | [diff] [blame] | 180 | |
| 181 | %% |