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
23 %option outfile="ConfigLexer.cpp"
31 #include "ConfigLexer.h"
33 #define YY_INPUT(buf,result,max_size) \
35 assert(ConfigLexerInput != 0 && "Oops"); \
36 result = ConfigLexerInput->read(buf,max_size); \
37 if (result == 0 ) result = YY_NULL; \
40 #define YY_FATAL_ERROR(msg) \
42 assert(ConfigLexerInput != 0 && "Oops"); \
43 ConfigLexerInput->error(msg); \
46 #define YY_DECL ConfigLexerTokens llvm::Configlex()
48 #define yyterminate() { return EOFTOK; }
52 inline llvm::ConfigLexerTokens
53 handleContext(const char* tokenText, llvm::ConfigLexerTokens token) {
54 if (ConfigLexerState.in_value) {
55 ConfigLexerState.StringVal = tokenText;
61 inline llvm::ConfigLexerTokens
62 handleSubstitution(llvm::ConfigLexerTokens token) {
63 if (ConfigLexerState.in_value)
65 YY_FATAL_ERROR("Substitition tokens not allowed in names" );
69 inline llvm::ConfigLexerTokens handleBoolean(llvm::ConfigLexerTokens token) {
70 if (ConfigLexerState.in_value)
72 YY_FATAL_ERROR("Boolean values not allowed in names");
78 ASSEMBLER assembler|Assembler|ASSEMBLER
79 BadSubst \%[^iots][a-zA-Z]\%
80 COMMAND command|Command|COMMAND
81 Comment \#[^\r\n]*\r?\n
85 GROKS_DASH_O groks_dash_O|Groks_Dash_O|GROKS_DASH_O
87 LINKER linker|Linker|LINKER
94 OPTIMIZER optimizer|Optimizer|OPTIMIZER
95 OPTIMIZES optimizes|Optimizes|OPTIMIZES
96 Option [-A-Za-z0-9_:%+/\\|,][-A-Za-z0-9_:+/\\|,@]*
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
103 TRANSLATES translates|Translates|TRANSLATES
104 TRANSLATOR translator|Translator|TRANSLATOR
105 VERSION version|Version|VERSION
109 False false|False|FALSE
117 {White} { /* Ignore whitespace */ }
119 {Comment} { /* Ignore comments */
120 ConfigLexerState.in_value = false;
121 ConfigLexerState.lineNum++;
125 {EscNewLine} { ConfigLexerState.lineNum++;
126 /* Don't return EOLTOK! */
129 {NewLine} { ConfigLexerState.in_value = false;
130 ConfigLexerState.lineNum++;
134 {Eq} { ConfigLexerState.in_value = true;
138 {LANG} { return handleContext("lang",LANG); }
139 {PREPROCESSOR} { return handleContext("preprocessor",PREPROCESSOR); }
140 {TRANSLATOR} { return handleContext("translator",TRANSLATOR); }
141 {OPTIMIZER} { return handleContext("optimizer",OPTIMIZER); }
142 {ASSEMBLER} { return handleContext("assembler",ASSEMBLER); }
143 {LINKER} { return handleContext("linker",LINKER); }
144 {NAME} { return handleContext("name",NAME); }
145 {REQUIRED} { return handleContext("required",REQUIRED); }
146 {COMMAND} { return handleContext("command",COMMAND); }
147 {PREPROCESSES} { return handleContext("preprocesses",PREPROCESSES); }
148 {TRANSLATES} { return handleContext("translates",TRANSLATES); }
149 {OPTIMIZES} { return handleContext("optimizes",OPTIMIZES); }
150 {GROKS_DASH_O} { return handleContext("groks_dash_O",GROKS_DASH_O); }
151 {OUTPUT_IS_ASM} { return handleContext("output_ias_asm",OUTPUT_IS_ASM); }
152 {OPT1} { return handleContext("opt1",OPT1); }
153 {OPT2} { return handleContext("opt2",OPT2); }
154 {OPT3} { return handleContext("opt3",OPT3); }
155 {OPT4} { return handleContext("opt4",OPT4); }
156 {OPT5} { return handleContext("opt5",OPT5); }
157 {VERSION} { return handleContext("version",VERSION); }
159 %in% { return handleSubstitution(IN_SUBST); }
160 %out% { return handleSubstitution(OUT_SUBST); }
161 %time% { return handleSubstitution(TIME_SUBST); }
162 %stats% { return handleSubstitution(STATS_SUBST); }
163 %opt% { return handleSubstitution(OPT_SUBST); }
164 %target% { return handleSubstitution(TARGET_SUBST); }
165 {BadSubst} { YY_FATAL_ERROR("Invalid substitution token"); }
166 {True} { return handleBoolean(TRUETOK); }
167 {On} { return handleBoolean(TRUETOK); }
168 {Yes} { return handleBoolean(TRUETOK); }
169 {False} { return handleBoolean(FALSETOK); }
170 {Off} { return handleBoolean(FALSETOK); }
171 {No} { return handleBoolean(FALSETOK); }
173 {Option} { ConfigLexerState.StringVal = yytext; return OPTION; }
174 {String} { ConfigLexerState.StringVal = yytext+1; // Nuke start quote
175 ConfigLexerState.StringVal.erase(
176 --ConfigLexerState.StringVal.end());
179 {Sep} { if (ConfigLexerState.in_value) { ConfigLexerState.StringVal = yytext;