1 /*===- ConfigLexer.l - Scanner for CompilerDriver Config Files -*- C++ -*--===//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
10 // This file implements the flex scanner for configuration files for the
11 // llvmc CompilerDriver.
13 //===----------------------------------------------------------------------===*/
16 %option prefix="Config"
18 %option never-interactive
22 %option outfile="ConfigLexer.cpp"
30 #include "ConfigLexer.h"
32 #define YY_INPUT(buf,result,max_size) \
34 assert(ConfigLexerInput != 0 && "Oops"); \
35 result = ConfigLexerInput->read(buf,max_size); \
36 if (result == 0 ) result = YY_NULL; \
39 #define YY_FATAL_ERROR(msg) \
41 assert(ConfigLexerInput != 0 && "Oops"); \
42 ConfigLexerInput->error(msg); \
45 #define YY_DECL ConfigLexerTokens llvm::Configlex()
47 #define yyterminate() { return EOFTOK; }
51 inline llvm::ConfigLexerTokens
52 handleNameContext(llvm::ConfigLexerTokens token) {
53 ConfigLexerState.StringVal = yytext;
54 if (ConfigLexerState.in_value)
59 inline llvm::ConfigLexerTokens
60 handleSubstitution(llvm::ConfigLexerTokens token) {
61 if (ConfigLexerState.in_value) {
62 ConfigLexerState.StringVal = yytext;
65 YY_FATAL_ERROR("Substitition tokens not allowed in names" );
69 inline llvm::ConfigLexerTokens handleValueContext(llvm::ConfigLexerTokens token) {
70 ConfigLexerState.StringVal = yytext;
71 if (ConfigLexerState.in_value)
78 ASSEMBLER assembler|Assembler|ASSEMBLER
79 COMMAND command|Command|COMMAND
82 LINKER linker|Linker|LINKER
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
98 True true|True|TRUE|on|On|ON|yes|Yes|YES
99 False false|False|FALSE|off|Off|OFF|no|No|NO
100 Bitcode bc|BC|bitcode|Bitcode|BITCODE
101 Assembly asm|ASM|assembly|Assembly|ASSEMBLY
103 BadSubst \%[a-zA-Z]*\%
104 Comment \#[^\r\n]*\r?\n
108 Option [-A-Za-z0-9_:%+/\\|,][-A-Za-z0-9_:+/\\|,@]*
116 {White} { if (ConfigLexerState.in_value) return SPACE; }
118 {Comment} { /* Ignore comments */
119 ConfigLexerState.in_value = false;
120 ConfigLexerState.lineNum++;
124 {EscNewLine} { ConfigLexerState.lineNum++;
125 /* Don't return EOLTOK! */
128 {NewLine} { ConfigLexerState.in_value = false;
129 ConfigLexerState.lineNum++;
133 {Eq} { ConfigLexerState.in_value = true;
137 {Sep} { return SEPARATOR; }
139 {VERSION} { return handleNameContext(VERSION_TOK); }
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); }
150 {PREPROCESSOR} { return handleNameContext(PREPROCESSOR); }
151 {COMMAND} { return handleNameContext(COMMAND); }
152 {REQUIRED} { return handleNameContext(REQUIRED); }
154 {TRANSLATOR} { return handleNameContext(TRANSLATOR); }
155 {PREPROCESSES} { return handleNameContext(PREPROCESSES); }
156 {OUTPUT} { return handleNameContext(OUTPUT); }
158 {OPTIMIZER} { return handleNameContext(OPTIMIZER); }
159 {TRANSLATES} { return handleNameContext(TRANSLATES); }
161 {ASSEMBLER} { return handleNameContext(ASSEMBLER); }
163 {LINKER} { return handleNameContext(LINKER); }
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); }
188 {Assembly} { return handleValueContext(ASSEMBLY); }
189 {Bitcode} { return handleValueContext(BITCODE); }
190 {True} { return handleValueContext(TRUETOK); }
191 {False} { return handleValueContext(FALSETOK); }
193 {Option} { ConfigLexerState.StringVal = yytext; return OPTION; }
194 {String} { ConfigLexerState.StringVal = yytext+1; // Nuke start quote
195 ConfigLexerState.StringVal.erase(
196 --ConfigLexerState.StringVal.end());
199 {BadSubst} { YY_FATAL_ERROR("Invalid substitution token"); }