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 |
Reid Spencer | 68fb37a | 2004-08-14 09:37:15 +0000 | [diff] [blame] | 21 | %option 8bit |
| 22 | %option outfile="ConfigLexer.cpp" |
| 23 | %option ecs |
Reid Spencer | 68fb37a | 2004-08-14 09:37:15 +0000 | [diff] [blame] | 24 | %option noyymore |
Reid Spencer | bae6825 | 2004-08-19 04:49:47 +0000 | [diff] [blame] | 25 | %option noreject |
| 26 | %pointer |
Reid Spencer | 68fb37a | 2004-08-14 09:37:15 +0000 | [diff] [blame] | 27 | |
| 28 | %{ |
| 29 | |
| 30 | #include "ConfigLexer.h" |
| 31 | |
| 32 | #define YY_INPUT(buf,result,max_size) \ |
| 33 | { \ |
| 34 | assert(ConfigLexerInput != 0 && "Oops"); \ |
| 35 | result = ConfigLexerInput->read(buf,max_size); \ |
| 36 | if (result == 0 ) result = YY_NULL; \ |
| 37 | } |
| 38 | |
Reid Spencer | bae6825 | 2004-08-19 04:49:47 +0000 | [diff] [blame] | 39 | #define YY_FATAL_ERROR(msg) \ |
| 40 | { \ |
| 41 | assert(ConfigLexerInput != 0 && "Oops"); \ |
| 42 | ConfigLexerInput->error(msg); \ |
| 43 | } |
| 44 | |
Reid Spencer | bf43772 | 2004-08-15 08:19:46 +0000 | [diff] [blame] | 45 | #define YY_DECL ConfigLexerTokens llvm::Configlex() |
| 46 | |
| 47 | #define yyterminate() { return EOFTOK; } |
| 48 | |
Reid Spencer | 68fb37a | 2004-08-14 09:37:15 +0000 | [diff] [blame] | 49 | using namespace llvm; |
| 50 | |
Reid Spencer | bae6825 | 2004-08-19 04:49:47 +0000 | [diff] [blame] | 51 | inline llvm::ConfigLexerTokens |
Reid Spencer | ec4f588 | 2004-08-24 13:58:37 +0000 | [diff] [blame] | 52 | handleNameContext(llvm::ConfigLexerTokens token) { |
| 53 | ConfigLexerState.StringVal = yytext; |
| 54 | if (ConfigLexerState.in_value) |
Reid Spencer | bae6825 | 2004-08-19 04:49:47 +0000 | [diff] [blame] | 55 | return OPTION; |
Reid Spencer | bae6825 | 2004-08-19 04:49:47 +0000 | [diff] [blame] | 56 | return token; |
Reid Spencer | 68fb37a | 2004-08-14 09:37:15 +0000 | [diff] [blame] | 57 | } |
| 58 | |
Reid Spencer | bae6825 | 2004-08-19 04:49:47 +0000 | [diff] [blame] | 59 | inline llvm::ConfigLexerTokens |
| 60 | handleSubstitution(llvm::ConfigLexerTokens token) { |
Reid Spencer | ec4f588 | 2004-08-24 13:58:37 +0000 | [diff] [blame] | 61 | if (ConfigLexerState.in_value) { |
| 62 | ConfigLexerState.StringVal = yytext; |
Reid Spencer | bae6825 | 2004-08-19 04:49:47 +0000 | [diff] [blame] | 63 | return token; |
Reid Spencer | ec4f588 | 2004-08-24 13:58:37 +0000 | [diff] [blame] | 64 | } |
Reid Spencer | bae6825 | 2004-08-19 04:49:47 +0000 | [diff] [blame] | 65 | YY_FATAL_ERROR("Substitition tokens not allowed in names" ); |
| 66 | return ERRORTOK; |
Chris Lattner | d74ea2b | 2006-05-24 17:04:05 +0000 | [diff] [blame] | 67 | } |
Reid Spencer | bae6825 | 2004-08-19 04:49:47 +0000 | [diff] [blame] | 68 | |
Reid Spencer | ec4f588 | 2004-08-24 13:58:37 +0000 | [diff] [blame] | 69 | inline llvm::ConfigLexerTokens handleValueContext(llvm::ConfigLexerTokens token) { |
| 70 | ConfigLexerState.StringVal = yytext; |
Reid Spencer | bae6825 | 2004-08-19 04:49:47 +0000 | [diff] [blame] | 71 | if (ConfigLexerState.in_value) |
| 72 | return token; |
Reid Spencer | ec4f588 | 2004-08-24 13:58:37 +0000 | [diff] [blame] | 73 | return OPTION; |
Reid Spencer | bae6825 | 2004-08-19 04:49:47 +0000 | [diff] [blame] | 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 | bae6825 | 2004-08-19 04:49:47 +0000 | [diff] [blame] | 79 | COMMAND command|Command|COMMAND |
Reid Spencer | bae6825 | 2004-08-19 04:49:47 +0000 | [diff] [blame] | 80 | LANG lang|Lang|LANG |
Reid Spencer | 90654fd | 2004-11-23 23:35:16 +0000 | [diff] [blame] | 81 | LIBS libs|Libs|LIBS |
Reid Spencer | ec4f588 | 2004-08-24 13:58:37 +0000 | [diff] [blame] | 82 | LINKER linker|Linker|LINKER |
Reid Spencer | 68fb37a | 2004-08-14 09:37:15 +0000 | [diff] [blame] | 83 | NAME name|Name|NAME |
Reid Spencer | bf43772 | 2004-08-15 08:19:46 +0000 | [diff] [blame] | 84 | OPT1 opt1|Opt1|OPT1 |
| 85 | OPT2 opt2|Opt2|OPT2 |
| 86 | OPT3 opt3|Opt3|OPT3 |
| 87 | OPT4 opt4|Opt4|OPT4 |
| 88 | OPT5 opt5|Opt5|OPT5 |
Reid Spencer | bae6825 | 2004-08-19 04:49:47 +0000 | [diff] [blame] | 89 | OPTIMIZER optimizer|Optimizer|OPTIMIZER |
Reid Spencer | ec4f588 | 2004-08-24 13:58:37 +0000 | [diff] [blame] | 90 | OUTPUT output|Output|OUTPUT |
Reid Spencer | bae6825 | 2004-08-19 04:49:47 +0000 | [diff] [blame] | 91 | PREPROCESSES preprocesses|PreProcesses|PREPROCESSES |
| 92 | PREPROCESSOR preprocessor|PreProcessor|PREPROCESSOR |
| 93 | REQUIRED required|Required|REQUIRED |
Reid Spencer | bae6825 | 2004-08-19 04:49:47 +0000 | [diff] [blame] | 94 | TRANSLATES translates|Translates|TRANSLATES |
| 95 | TRANSLATOR translator|Translator|TRANSLATOR |
Reid Spencer | 1df7121 | 2004-08-22 18:02:13 +0000 | [diff] [blame] | 96 | VERSION version|Version|VERSION |
Reid Spencer | ec4f588 | 2004-08-24 13:58:37 +0000 | [diff] [blame] | 97 | |
| 98 | True true|True|TRUE|on|On|ON|yes|Yes|YES |
| 99 | False false|False|FALSE|off|Off|OFF|no|No|NO |
| 100 | Bytecode bc|BC|bytecode|Bytecode|BYTECODE |
| 101 | Assembly asm|ASM|assembly|Assembly|ASSEMBLY |
| 102 | |
Reid Spencer | 90654fd | 2004-11-23 23:35:16 +0000 | [diff] [blame] | 103 | BadSubst \%[a-zA-Z]*\% |
Reid Spencer | ec4f588 | 2004-08-24 13:58:37 +0000 | [diff] [blame] | 104 | Comment \#[^\r\n]*\r?\n |
| 105 | NewLine \r?\n |
| 106 | Eq \= |
| 107 | EscNewLine \\\r?\n |
| 108 | Option [-A-Za-z0-9_:%+/\\|,][-A-Za-z0-9_:+/\\|,@]* |
| 109 | Sep \. |
| 110 | String \"[^\"]*\" |
Reid Spencer | bae6825 | 2004-08-19 04:49:47 +0000 | [diff] [blame] | 111 | White [ \t]* |
| 112 | |
Reid Spencer | 68fb37a | 2004-08-14 09:37:15 +0000 | [diff] [blame] | 113 | |
| 114 | %% |
| 115 | |
Reid Spencer | 90654fd | 2004-11-23 23:35:16 +0000 | [diff] [blame] | 116 | {White} { if (ConfigLexerState.in_value) return SPACE; } |
Reid Spencer | 68fb37a | 2004-08-14 09:37:15 +0000 | [diff] [blame] | 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 | |
Reid Spencer | 90654fd | 2004-11-23 23:35:16 +0000 | [diff] [blame] | 137 | {Sep} { return SEPARATOR; } |
| 138 | |
Reid Spencer | 3a9b222 | 2004-10-28 04:04:38 +0000 | [diff] [blame] | 139 | {VERSION} { return handleNameContext(VERSION_TOK); } |
Reid Spencer | bae6825 | 2004-08-19 04:49:47 +0000 | [diff] [blame] | 140 | |
Reid Spencer | ec4f588 | 2004-08-24 13:58:37 +0000 | [diff] [blame] | 141 | {LANG} { return handleNameContext(LANG); } |
Reid Spencer | 90654fd | 2004-11-23 23:35:16 +0000 | [diff] [blame] | 142 | {LIBS} { return handleNameContext(LIBS); } |
Reid Spencer | ec4f588 | 2004-08-24 13:58:37 +0000 | [diff] [blame] | 143 | {NAME} { return handleNameContext(NAME); } |
| 144 | {OPT1} { return handleNameContext(OPT1); } |
| 145 | {OPT2} { return handleNameContext(OPT2); } |
| 146 | {OPT3} { return handleNameContext(OPT3); } |
| 147 | {OPT4} { return handleNameContext(OPT4); } |
| 148 | {OPT5} { return handleNameContext(OPT5); } |
| 149 | |
| 150 | {PREPROCESSOR} { return handleNameContext(PREPROCESSOR); } |
| 151 | {COMMAND} { return handleNameContext(COMMAND); } |
| 152 | {REQUIRED} { return handleNameContext(REQUIRED); } |
| 153 | |
| 154 | {TRANSLATOR} { return handleNameContext(TRANSLATOR); } |
| 155 | {PREPROCESSES} { return handleNameContext(PREPROCESSES); } |
| 156 | {OUTPUT} { return handleNameContext(OUTPUT); } |
| 157 | |
| 158 | {OPTIMIZER} { return handleNameContext(OPTIMIZER); } |
| 159 | {TRANSLATES} { return handleNameContext(TRANSLATES); } |
| 160 | |
| 161 | {ASSEMBLER} { return handleNameContext(ASSEMBLER); } |
| 162 | |
| 163 | {LINKER} { return handleNameContext(LINKER); } |
| 164 | |
| 165 | %args% { return handleSubstitution(ARGS_SUBST); } |
Reid Spencer | cc97cfc | 2005-05-19 00:52:28 +0000 | [diff] [blame] | 166 | %bindir% { return handleSubstitution(BINDIR_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); } |
Reid Spencer | cc97cfc | 2005-05-19 00:52:28 +0000 | [diff] [blame] | 170 | %libdir% { return handleSubstitution(LIBDIR_SUBST); } |
Reid Spencer | ca01f9b | 2004-08-30 06:29:06 +0000 | [diff] [blame] | 171 | %libs% { return handleSubstitution(LIBS_SUBST); } |
Reid Spencer | cc97cfc | 2005-05-19 00:52:28 +0000 | [diff] [blame] | 172 | %llvmgccdir% { return handleSubstitution(LLVMGCCDIR_SUBST); } |
| 173 | %llvmgccarch% { return handleSubstitution(LLVMGCCARCH_SUBST); } |
| 174 | %llvmgcc% { return handleSubstitution(LLVMGCC_SUBST); } |
| 175 | %llvmgxx% { return handleSubstitution(LLVMGXX_SUBST); } |
| 176 | %llvmcc1% { return handleSubstitution(LLVMCC1_SUBST); } |
| 177 | %llvmcc1plus% { return handleSubstitution(LLVMCC1PLUS_SUBST); } |
Reid Spencer | 53aa793 | 2004-08-20 22:53:11 +0000 | [diff] [blame] | 178 | %opt% { return handleSubstitution(OPT_SUBST); } |
Reid Spencer | 52c2dc1 | 2004-08-29 19:26:56 +0000 | [diff] [blame] | 179 | %out% { return handleSubstitution(OUT_SUBST); } |
| 180 | %stats% { return handleSubstitution(STATS_SUBST); } |
Reid Spencer | 53aa793 | 2004-08-20 22:53:11 +0000 | [diff] [blame] | 181 | %target% { return handleSubstitution(TARGET_SUBST); } |
Reid Spencer | 52c2dc1 | 2004-08-29 19:26:56 +0000 | [diff] [blame] | 182 | %time% { return handleSubstitution(TIME_SUBST); } |
| 183 | %verbose% { return handleSubstitution(VERBOSE_SUBST); } |
Reid Spencer | d4ff15a | 2004-09-14 01:59:31 +0000 | [diff] [blame] | 184 | %fOpts% { return handleSubstitution(FOPTS_SUBST); } |
| 185 | %MOpts% { return handleSubstitution(MOPTS_SUBST); } |
| 186 | %WOpts% { return handleSubstitution(WOPTS_SUBST); } |
Reid Spencer | ec4f588 | 2004-08-24 13:58:37 +0000 | [diff] [blame] | 187 | |
| 188 | {Assembly} { return handleValueContext(ASSEMBLY); } |
| 189 | {Bytecode} { return handleValueContext(BYTECODE); } |
| 190 | {True} { return handleValueContext(TRUETOK); } |
| 191 | {False} { return handleValueContext(FALSETOK); } |
Reid Spencer | bae6825 | 2004-08-19 04:49:47 +0000 | [diff] [blame] | 192 | |
| 193 | {Option} { ConfigLexerState.StringVal = yytext; return OPTION; } |
| 194 | {String} { ConfigLexerState.StringVal = yytext+1; // Nuke start quote |
| 195 | ConfigLexerState.StringVal.erase( |
| 196 | --ConfigLexerState.StringVal.end()); |
Reid Spencer | 68fb37a | 2004-08-14 09:37:15 +0000 | [diff] [blame] | 197 | return STRING; |
| 198 | } |
Reid Spencer | 90654fd | 2004-11-23 23:35:16 +0000 | [diff] [blame] | 199 | {BadSubst} { YY_FATAL_ERROR("Invalid substitution token"); } |
Reid Spencer | 68fb37a | 2004-08-14 09:37:15 +0000 | [diff] [blame] | 200 | |
| 201 | %% |