Convert llvmc to use the lib/System interface instead of directly
[oota-llvm.git] / tools / llvmc / ConfigLexer.l
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"
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
25 %option noyymore
26 %option noreject
27 %pointer
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
40 #define YY_FATAL_ERROR(msg) \
41   { \
42     assert(ConfigLexerInput != 0 && "Oops"); \
43     ConfigLexerInput->error(msg); \
44   }
45
46 #define YY_DECL ConfigLexerTokens llvm::Configlex()
47
48 #define yyterminate() { return EOFTOK; }
49
50 using namespace llvm;
51
52 inline llvm::ConfigLexerTokens 
53 handleNameContext(llvm::ConfigLexerTokens token) {
54   ConfigLexerState.StringVal = yytext;
55   if (ConfigLexerState.in_value)
56     return OPTION;
57   return token;
58 }
59
60 inline llvm::ConfigLexerTokens 
61 handleSubstitution(llvm::ConfigLexerTokens token) {
62   if (ConfigLexerState.in_value) {
63     ConfigLexerState.StringVal = yytext;
64     return token;
65   }
66   YY_FATAL_ERROR("Substitition tokens not allowed in names" ); 
67   return ERRORTOK;
68 };
69
70 inline llvm::ConfigLexerTokens handleValueContext(llvm::ConfigLexerTokens token) {
71   ConfigLexerState.StringVal = yytext;
72   if (ConfigLexerState.in_value)
73     return token;
74   return OPTION;
75 }
76
77 %}
78
79 ASSEMBLER       assembler|Assembler|ASSEMBLER
80 COMMAND         command|Command|COMMAND
81 LANG            lang|Lang|LANG
82 LINKER          linker|Linker|LINKER
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
100 Bytecode        bc|BC|bytecode|Bytecode|BYTECODE
101 Assembly        asm|ASM|assembly|Assembly|ASSEMBLY
102
103 BadSubst        \%[^iots][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}         { /* Ignore whitespace */ }
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 {VERSION}       { return handleNameContext(VERSION); }
138
139 {LANG}          { return handleNameContext(LANG); }
140 {NAME}          { return handleNameContext(NAME); }
141 {OPT1}          { return handleNameContext(OPT1); }
142 {OPT2}          { return handleNameContext(OPT2); }
143 {OPT3}          { return handleNameContext(OPT3); }
144 {OPT4}          { return handleNameContext(OPT4); }
145 {OPT5}          { return handleNameContext(OPT5); }
146
147 {PREPROCESSOR}  { return handleNameContext(PREPROCESSOR); }
148 {COMMAND}       { return handleNameContext(COMMAND); }
149 {REQUIRED}      { return handleNameContext(REQUIRED); }
150
151 {TRANSLATOR}    { return handleNameContext(TRANSLATOR); }
152 {PREPROCESSES}  { return handleNameContext(PREPROCESSES); }
153 {OUTPUT}        { return handleNameContext(OUTPUT); }
154
155 {OPTIMIZER}     { return handleNameContext(OPTIMIZER); }
156 {TRANSLATES}    { return handleNameContext(TRANSLATES); }
157
158 {ASSEMBLER}     { return handleNameContext(ASSEMBLER); }
159
160 {LINKER}        { return handleNameContext(LINKER); }
161
162 %args%          { return handleSubstitution(ARGS_SUBST); }
163 %force%         { return handleSubstitution(FORCE_SUBST); }
164 %in%            { return handleSubstitution(IN_SUBST); }
165 %opt%           { return handleSubstitution(OPT_SUBST); }
166 %out%           { return handleSubstitution(OUT_SUBST); }
167 %stats%         { return handleSubstitution(STATS_SUBST); }
168 %target%        { return handleSubstitution(TARGET_SUBST); }
169 %time%          { return handleSubstitution(TIME_SUBST); }
170 %verbose%       { return handleSubstitution(VERBOSE_SUBST); }
171 {BadSubst}      { YY_FATAL_ERROR("Invalid substitution token"); }
172
173 {Assembly}      { return handleValueContext(ASSEMBLY); }
174 {Bytecode}      { return handleValueContext(BYTECODE); }
175 {True}          { return handleValueContext(TRUETOK); }
176 {False}         { return handleValueContext(FALSETOK); }
177
178 {Option}        { ConfigLexerState.StringVal = yytext; return OPTION; }
179 {String}        { ConfigLexerState.StringVal = yytext+1;  // Nuke start quote
180                   ConfigLexerState.StringVal.erase(
181                   --ConfigLexerState.StringVal.end());
182                   return STRING;
183                 }
184 {Sep}           { if (ConfigLexerState.in_value) { ConfigLexerState.StringVal = yytext;
185                     return OPTION; } }
186
187
188 %%