blob: 390045cadbcb37304e4a9c646757d6e6baac7714 [file] [log] [blame]
Chris Lattner1828ee12006-02-14 05:16:35 +00001/*===- ConfigLexer.l - Scanner for CompilerDriver Config Files -*- C++ -*--===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattnercf786592007-12-29 20:47:37 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattner1828ee12006-02-14 05:16:35 +00007//
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
49using namespace llvm;
50
51inline llvm::ConfigLexerTokens
52handleNameContext(llvm::ConfigLexerTokens token) {
53 ConfigLexerState.StringVal = yytext;
54 if (ConfigLexerState.in_value)
55 return OPTION;
56 return token;
57}
58
59inline llvm::ConfigLexerTokens
60handleSubstitution(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 Lattnerd74ea2b2006-05-24 17:04:05 +000067}
Chris Lattner1828ee12006-02-14 05:16:35 +000068
69inline 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
78ASSEMBLER assembler|Assembler|ASSEMBLER
79COMMAND command|Command|COMMAND
80LANG lang|Lang|LANG
81LIBS libs|Libs|LIBS
Chris Lattnerf87bd842007-07-05 17:27:31 +000082LINKER linker|Linker|LINKER
Chris Lattner1828ee12006-02-14 05:16:35 +000083NAME name|Name|NAME
84OPT1 opt1|Opt1|OPT1
85OPT2 opt2|Opt2|OPT2
86OPT3 opt3|Opt3|OPT3
87OPT4 opt4|Opt4|OPT4
88OPT5 opt5|Opt5|OPT5
89OPTIMIZER optimizer|Optimizer|OPTIMIZER
90OUTPUT output|Output|OUTPUT
91PREPROCESSES preprocesses|PreProcesses|PREPROCESSES
92PREPROCESSOR preprocessor|PreProcessor|PREPROCESSOR
93REQUIRED required|Required|REQUIRED
94TRANSLATES translates|Translates|TRANSLATES
95TRANSLATOR translator|Translator|TRANSLATOR
96VERSION version|Version|VERSION
97
98True true|True|TRUE|on|On|ON|yes|Yes|YES
99False false|False|FALSE|off|Off|OFF|no|No|NO
Chris Lattnerf87bd842007-07-05 17:27:31 +0000100Bitcode bc|BC|bitcode|Bitcode|BITCODE
Chris Lattner1828ee12006-02-14 05:16:35 +0000101Assembly asm|ASM|assembly|Assembly|ASSEMBLY
102
103BadSubst \%[a-zA-Z]*\%
104Comment \#[^\r\n]*\r?\n
105NewLine \r?\n
106Eq \=
107EscNewLine \\\r?\n
108Option [-A-Za-z0-9_:%+/\\|,][-A-Za-z0-9_:+/\\|,@]*
109Sep \.
110String \"[^\"]*\"
111White [ \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 Lattnerf87bd842007-07-05 17:27:31 +0000189{Bitcode} { return handleValueContext(BITCODE); }
Chris Lattner1828ee12006-02-14 05:16:35 +0000190{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%%