Chris Lattner | 1828ee1 | 2006-02-14 05:16:35 +0000 | [diff] [blame] | 1 | /*===- ConfigLexer.l - Scanner for CompilerDriver Config Files -*- C++ -*--===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | cf78659 | 2007-12-29 20:47:37 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Chris Lattner | 1828ee1 | 2006-02-14 05:16:35 +0000 | [diff] [blame] | 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" |
| 17 | %option nostdinit |
| 18 | %option never-interactive |
| 19 | %option batch |
| 20 | %option noyywrap |
| 21 | %option 8bit |
| 22 | %option outfile="ConfigLexer.cpp" |
| 23 | %option ecs |
| 24 | %option noyymore |
| 25 | %option noreject |
| 26 | %pointer |
| 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 | |
| 39 | #define YY_FATAL_ERROR(msg) \ |
| 40 | { \ |
| 41 | assert(ConfigLexerInput != 0 && "Oops"); \ |
| 42 | ConfigLexerInput->error(msg); \ |
| 43 | } |
| 44 | |
| 45 | #define YY_DECL ConfigLexerTokens llvm::Configlex() |
| 46 | |
| 47 | #define yyterminate() { return EOFTOK; } |
| 48 | |
| 49 | using namespace llvm; |
| 50 | |
| 51 | inline llvm::ConfigLexerTokens |
| 52 | handleNameContext(llvm::ConfigLexerTokens token) { |
| 53 | ConfigLexerState.StringVal = yytext; |
| 54 | if (ConfigLexerState.in_value) |
| 55 | return OPTION; |
| 56 | return token; |
| 57 | } |
| 58 | |
| 59 | inline llvm::ConfigLexerTokens |
| 60 | handleSubstitution(llvm::ConfigLexerTokens token) { |
| 61 | if (ConfigLexerState.in_value) { |
| 62 | ConfigLexerState.StringVal = yytext; |
| 63 | return token; |
| 64 | } |
| 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 | } |
Chris Lattner | 1828ee1 | 2006-02-14 05:16:35 +0000 | [diff] [blame] | 68 | |
| 69 | inline llvm::ConfigLexerTokens handleValueContext(llvm::ConfigLexerTokens token) { |
| 70 | ConfigLexerState.StringVal = yytext; |
| 71 | if (ConfigLexerState.in_value) |
| 72 | return token; |
| 73 | return OPTION; |
| 74 | } |
| 75 | |
| 76 | %} |
| 77 | |
| 78 | ASSEMBLER assembler|Assembler|ASSEMBLER |
| 79 | COMMAND command|Command|COMMAND |
| 80 | LANG lang|Lang|LANG |
| 81 | LIBS libs|Libs|LIBS |
Chris Lattner | f87bd84 | 2007-07-05 17:27:31 +0000 | [diff] [blame] | 82 | LINKER linker|Linker|LINKER |
Chris Lattner | 1828ee1 | 2006-02-14 05:16:35 +0000 | [diff] [blame] | 83 | NAME name|Name|NAME |
| 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 |
| 89 | OPTIMIZER optimizer|Optimizer|OPTIMIZER |
| 90 | OUTPUT output|Output|OUTPUT |
| 91 | PREPROCESSES preprocesses|PreProcesses|PREPROCESSES |
| 92 | PREPROCESSOR preprocessor|PreProcessor|PREPROCESSOR |
| 93 | REQUIRED required|Required|REQUIRED |
| 94 | TRANSLATES translates|Translates|TRANSLATES |
| 95 | TRANSLATOR translator|Translator|TRANSLATOR |
| 96 | VERSION version|Version|VERSION |
| 97 | |
| 98 | True true|True|TRUE|on|On|ON|yes|Yes|YES |
| 99 | False false|False|FALSE|off|Off|OFF|no|No|NO |
Chris Lattner | f87bd84 | 2007-07-05 17:27:31 +0000 | [diff] [blame] | 100 | Bitcode bc|BC|bitcode|Bitcode|BITCODE |
Chris Lattner | 1828ee1 | 2006-02-14 05:16:35 +0000 | [diff] [blame] | 101 | Assembly asm|ASM|assembly|Assembly|ASSEMBLY |
| 102 | |
| 103 | BadSubst \%[a-zA-Z]*\% |
| 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 \"[^\"]*\" |
| 111 | White [ \t]* |
| 112 | |
| 113 | |
| 114 | %% |
| 115 | |
| 116 | {White} { if (ConfigLexerState.in_value) return SPACE; } |
| 117 | |
| 118 | {Comment} { /* Ignore comments */ |
| 119 | ConfigLexerState.in_value = false; |
| 120 | ConfigLexerState.lineNum++; |
| 121 | return EOLTOK; |
| 122 | } |
| 123 | |
| 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 | {Sep} { return SEPARATOR; } |
| 138 | |
| 139 | {VERSION} { return handleNameContext(VERSION_TOK); } |
| 140 | |
| 141 | {LANG} { return handleNameContext(LANG); } |
| 142 | {LIBS} { return handleNameContext(LIBS); } |
| 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); } |
| 166 | %bindir% { return handleSubstitution(BINDIR_SUBST); } |
| 167 | %defs% { return handleSubstitution(DEFS_SUBST); } |
| 168 | %in% { return handleSubstitution(IN_SUBST); } |
| 169 | %incls% { return handleSubstitution(INCLS_SUBST); } |
| 170 | %libdir% { return handleSubstitution(LIBDIR_SUBST); } |
| 171 | %libs% { return handleSubstitution(LIBS_SUBST); } |
| 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); } |
| 178 | %opt% { return handleSubstitution(OPT_SUBST); } |
| 179 | %out% { return handleSubstitution(OUT_SUBST); } |
| 180 | %stats% { return handleSubstitution(STATS_SUBST); } |
| 181 | %target% { return handleSubstitution(TARGET_SUBST); } |
| 182 | %time% { return handleSubstitution(TIME_SUBST); } |
| 183 | %verbose% { return handleSubstitution(VERBOSE_SUBST); } |
| 184 | %fOpts% { return handleSubstitution(FOPTS_SUBST); } |
| 185 | %MOpts% { return handleSubstitution(MOPTS_SUBST); } |
| 186 | %WOpts% { return handleSubstitution(WOPTS_SUBST); } |
| 187 | |
| 188 | {Assembly} { return handleValueContext(ASSEMBLY); } |
Chris Lattner | f87bd84 | 2007-07-05 17:27:31 +0000 | [diff] [blame] | 189 | {Bitcode} { return handleValueContext(BITCODE); } |
Chris Lattner | 1828ee1 | 2006-02-14 05:16:35 +0000 | [diff] [blame] | 190 | {True} { return handleValueContext(TRUETOK); } |
| 191 | {False} { return handleValueContext(FALSETOK); } |
| 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()); |
| 197 | return STRING; |
| 198 | } |
| 199 | {BadSubst} { YY_FATAL_ERROR("Invalid substitution token"); } |
| 200 | |
| 201 | %% |