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 |
Reid Spencer | ec4f588 | 2004-08-24 13:58:37 +0000 | [diff] [blame] | 53 | handleNameContext(llvm::ConfigLexerTokens token) { |
| 54 | ConfigLexerState.StringVal = yytext; |
| 55 | if (ConfigLexerState.in_value) |
Reid Spencer | bae6825 | 2004-08-19 04:49:47 +0000 | [diff] [blame] | 56 | return OPTION; |
Reid Spencer | bae6825 | 2004-08-19 04:49:47 +0000 | [diff] [blame] | 57 | return token; |
Reid Spencer | 68fb37a | 2004-08-14 09:37:15 +0000 | [diff] [blame] | 58 | } |
| 59 | |
Reid Spencer | bae6825 | 2004-08-19 04:49:47 +0000 | [diff] [blame] | 60 | inline llvm::ConfigLexerTokens |
| 61 | handleSubstitution(llvm::ConfigLexerTokens token) { |
Reid Spencer | ec4f588 | 2004-08-24 13:58:37 +0000 | [diff] [blame] | 62 | if (ConfigLexerState.in_value) { |
| 63 | ConfigLexerState.StringVal = yytext; |
Reid Spencer | bae6825 | 2004-08-19 04:49:47 +0000 | [diff] [blame] | 64 | return token; |
Reid Spencer | ec4f588 | 2004-08-24 13:58:37 +0000 | [diff] [blame] | 65 | } |
Reid Spencer | bae6825 | 2004-08-19 04:49:47 +0000 | [diff] [blame] | 66 | YY_FATAL_ERROR("Substitition tokens not allowed in names" ); |
| 67 | return ERRORTOK; |
| 68 | }; |
| 69 | |
Reid Spencer | ec4f588 | 2004-08-24 13:58:37 +0000 | [diff] [blame] | 70 | inline llvm::ConfigLexerTokens handleValueContext(llvm::ConfigLexerTokens token) { |
| 71 | ConfigLexerState.StringVal = yytext; |
Reid Spencer | bae6825 | 2004-08-19 04:49:47 +0000 | [diff] [blame] | 72 | if (ConfigLexerState.in_value) |
| 73 | return token; |
Reid Spencer | ec4f588 | 2004-08-24 13:58:37 +0000 | [diff] [blame] | 74 | return OPTION; |
Reid Spencer | bae6825 | 2004-08-19 04:49:47 +0000 | [diff] [blame] | 75 | } |
Reid Spencer | 68fb37a | 2004-08-14 09:37:15 +0000 | [diff] [blame] | 76 | |
| 77 | %} |
| 78 | |
Reid Spencer | 68fb37a | 2004-08-14 09:37:15 +0000 | [diff] [blame] | 79 | ASSEMBLER assembler|Assembler|ASSEMBLER |
Reid Spencer | bae6825 | 2004-08-19 04:49:47 +0000 | [diff] [blame] | 80 | COMMAND command|Command|COMMAND |
Reid Spencer | bae6825 | 2004-08-19 04:49:47 +0000 | [diff] [blame] | 81 | LANG lang|Lang|LANG |
Reid Spencer | 90654fd | 2004-11-23 23:35:16 +0000 | [diff] [blame] | 82 | LIBS libs|Libs|LIBS |
Reid Spencer | ec4f588 | 2004-08-24 13:58:37 +0000 | [diff] [blame] | 83 | LINKER linker|Linker|LINKER |
Reid Spencer | 68fb37a | 2004-08-14 09:37:15 +0000 | [diff] [blame] | 84 | NAME name|Name|NAME |
Reid Spencer | bf43772 | 2004-08-15 08:19:46 +0000 | [diff] [blame] | 85 | OPT1 opt1|Opt1|OPT1 |
| 86 | OPT2 opt2|Opt2|OPT2 |
| 87 | OPT3 opt3|Opt3|OPT3 |
| 88 | OPT4 opt4|Opt4|OPT4 |
| 89 | OPT5 opt5|Opt5|OPT5 |
Reid Spencer | bae6825 | 2004-08-19 04:49:47 +0000 | [diff] [blame] | 90 | OPTIMIZER optimizer|Optimizer|OPTIMIZER |
Reid Spencer | ec4f588 | 2004-08-24 13:58:37 +0000 | [diff] [blame] | 91 | OUTPUT output|Output|OUTPUT |
Reid Spencer | bae6825 | 2004-08-19 04:49:47 +0000 | [diff] [blame] | 92 | PREPROCESSES preprocesses|PreProcesses|PREPROCESSES |
| 93 | PREPROCESSOR preprocessor|PreProcessor|PREPROCESSOR |
| 94 | REQUIRED required|Required|REQUIRED |
Reid Spencer | bae6825 | 2004-08-19 04:49:47 +0000 | [diff] [blame] | 95 | TRANSLATES translates|Translates|TRANSLATES |
| 96 | TRANSLATOR translator|Translator|TRANSLATOR |
Reid Spencer | 1df7121 | 2004-08-22 18:02:13 +0000 | [diff] [blame] | 97 | VERSION version|Version|VERSION |
Reid Spencer | ec4f588 | 2004-08-24 13:58:37 +0000 | [diff] [blame] | 98 | |
| 99 | True true|True|TRUE|on|On|ON|yes|Yes|YES |
| 100 | False false|False|FALSE|off|Off|OFF|no|No|NO |
| 101 | Bytecode bc|BC|bytecode|Bytecode|BYTECODE |
| 102 | Assembly asm|ASM|assembly|Assembly|ASSEMBLY |
| 103 | |
Reid Spencer | 90654fd | 2004-11-23 23:35:16 +0000 | [diff] [blame] | 104 | BadSubst \%[a-zA-Z]*\% |
Reid Spencer | ec4f588 | 2004-08-24 13:58:37 +0000 | [diff] [blame] | 105 | Comment \#[^\r\n]*\r?\n |
| 106 | NewLine \r?\n |
| 107 | Eq \= |
| 108 | EscNewLine \\\r?\n |
| 109 | Option [-A-Za-z0-9_:%+/\\|,][-A-Za-z0-9_:+/\\|,@]* |
| 110 | Sep \. |
| 111 | String \"[^\"]*\" |
Reid Spencer | bae6825 | 2004-08-19 04:49:47 +0000 | [diff] [blame] | 112 | White [ \t]* |
| 113 | |
Reid Spencer | 68fb37a | 2004-08-14 09:37:15 +0000 | [diff] [blame] | 114 | |
| 115 | %% |
| 116 | |
Reid Spencer | 90654fd | 2004-11-23 23:35:16 +0000 | [diff] [blame] | 117 | {White} { if (ConfigLexerState.in_value) return SPACE; } |
Reid Spencer | 68fb37a | 2004-08-14 09:37:15 +0000 | [diff] [blame] | 118 | |
Reid Spencer | bae6825 | 2004-08-19 04:49:47 +0000 | [diff] [blame] | 119 | {Comment} { /* Ignore comments */ |
| 120 | ConfigLexerState.in_value = false; |
| 121 | ConfigLexerState.lineNum++; |
| 122 | return EOLTOK; |
| 123 | } |
Reid Spencer | 68fb37a | 2004-08-14 09:37:15 +0000 | [diff] [blame] | 124 | |
Reid Spencer | bae6825 | 2004-08-19 04:49:47 +0000 | [diff] [blame] | 125 | {EscNewLine} { ConfigLexerState.lineNum++; |
| 126 | /* Don't return EOLTOK! */ |
| 127 | } |
| 128 | |
| 129 | {NewLine} { ConfigLexerState.in_value = false; |
| 130 | ConfigLexerState.lineNum++; |
| 131 | return EOLTOK; |
| 132 | } |
| 133 | |
| 134 | {Eq} { ConfigLexerState.in_value = true; |
| 135 | return EQUALS; |
| 136 | } |
| 137 | |
Reid Spencer | 90654fd | 2004-11-23 23:35:16 +0000 | [diff] [blame] | 138 | {Sep} { return SEPARATOR; } |
| 139 | |
Reid Spencer | 3a9b222 | 2004-10-28 04:04:38 +0000 | [diff] [blame] | 140 | {VERSION} { return handleNameContext(VERSION_TOK); } |
Reid Spencer | bae6825 | 2004-08-19 04:49:47 +0000 | [diff] [blame] | 141 | |
Reid Spencer | ec4f588 | 2004-08-24 13:58:37 +0000 | [diff] [blame] | 142 | {LANG} { return handleNameContext(LANG); } |
Reid Spencer | 90654fd | 2004-11-23 23:35:16 +0000 | [diff] [blame] | 143 | {LIBS} { return handleNameContext(LIBS); } |
Reid Spencer | ec4f588 | 2004-08-24 13:58:37 +0000 | [diff] [blame] | 144 | {NAME} { return handleNameContext(NAME); } |
| 145 | {OPT1} { return handleNameContext(OPT1); } |
| 146 | {OPT2} { return handleNameContext(OPT2); } |
| 147 | {OPT3} { return handleNameContext(OPT3); } |
| 148 | {OPT4} { return handleNameContext(OPT4); } |
| 149 | {OPT5} { return handleNameContext(OPT5); } |
| 150 | |
| 151 | {PREPROCESSOR} { return handleNameContext(PREPROCESSOR); } |
| 152 | {COMMAND} { return handleNameContext(COMMAND); } |
| 153 | {REQUIRED} { return handleNameContext(REQUIRED); } |
| 154 | |
| 155 | {TRANSLATOR} { return handleNameContext(TRANSLATOR); } |
| 156 | {PREPROCESSES} { return handleNameContext(PREPROCESSES); } |
| 157 | {OUTPUT} { return handleNameContext(OUTPUT); } |
| 158 | |
| 159 | {OPTIMIZER} { return handleNameContext(OPTIMIZER); } |
| 160 | {TRANSLATES} { return handleNameContext(TRANSLATES); } |
| 161 | |
| 162 | {ASSEMBLER} { return handleNameContext(ASSEMBLER); } |
| 163 | |
| 164 | {LINKER} { return handleNameContext(LINKER); } |
| 165 | |
| 166 | %args% { return handleSubstitution(ARGS_SUBST); } |
Reid Spencer | ca01f9b | 2004-08-30 06:29:06 +0000 | [diff] [blame] | 167 | %defs% { return handleSubstitution(DEFS_SUBST); } |
Reid Spencer | 53aa793 | 2004-08-20 22:53:11 +0000 | [diff] [blame] | 168 | %in% { return handleSubstitution(IN_SUBST); } |
Reid Spencer | ca01f9b | 2004-08-30 06:29:06 +0000 | [diff] [blame] | 169 | %incls% { return handleSubstitution(INCLS_SUBST); } |
| 170 | %libs% { return handleSubstitution(LIBS_SUBST); } |
Reid Spencer | 53aa793 | 2004-08-20 22:53:11 +0000 | [diff] [blame] | 171 | %opt% { return handleSubstitution(OPT_SUBST); } |
Reid Spencer | 52c2dc1 | 2004-08-29 19:26:56 +0000 | [diff] [blame] | 172 | %out% { return handleSubstitution(OUT_SUBST); } |
| 173 | %stats% { return handleSubstitution(STATS_SUBST); } |
Reid Spencer | 53aa793 | 2004-08-20 22:53:11 +0000 | [diff] [blame] | 174 | %target% { return handleSubstitution(TARGET_SUBST); } |
Reid Spencer | 52c2dc1 | 2004-08-29 19:26:56 +0000 | [diff] [blame] | 175 | %time% { return handleSubstitution(TIME_SUBST); } |
| 176 | %verbose% { return handleSubstitution(VERBOSE_SUBST); } |
Reid Spencer | d4ff15a | 2004-09-14 01:59:31 +0000 | [diff] [blame] | 177 | %fOpts% { return handleSubstitution(FOPTS_SUBST); } |
| 178 | %MOpts% { return handleSubstitution(MOPTS_SUBST); } |
| 179 | %WOpts% { return handleSubstitution(WOPTS_SUBST); } |
Reid Spencer | ec4f588 | 2004-08-24 13:58:37 +0000 | [diff] [blame] | 180 | |
| 181 | {Assembly} { return handleValueContext(ASSEMBLY); } |
| 182 | {Bytecode} { return handleValueContext(BYTECODE); } |
| 183 | {True} { return handleValueContext(TRUETOK); } |
| 184 | {False} { return handleValueContext(FALSETOK); } |
Reid Spencer | bae6825 | 2004-08-19 04:49:47 +0000 | [diff] [blame] | 185 | |
| 186 | {Option} { ConfigLexerState.StringVal = yytext; return OPTION; } |
| 187 | {String} { ConfigLexerState.StringVal = yytext+1; // Nuke start quote |
| 188 | ConfigLexerState.StringVal.erase( |
| 189 | --ConfigLexerState.StringVal.end()); |
Reid Spencer | 68fb37a | 2004-08-14 09:37:15 +0000 | [diff] [blame] | 190 | return STRING; |
| 191 | } |
Reid Spencer | 90654fd | 2004-11-23 23:35:16 +0000 | [diff] [blame] | 192 | {BadSubst} { YY_FATAL_ERROR("Invalid substitution token"); } |
Reid Spencer | 68fb37a | 2004-08-14 09:37:15 +0000 | [diff] [blame] | 193 | |
| 194 | %% |