blob: 349874eebe7adc04e51dcb09de5c2d116d4fdec6 [file] [log] [blame]
Reid Spencer68fb37a2004-08-14 09:37:15 +00001/*===- 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"
Reid Spencer68fb37a2004-08-14 09:37:15 +000017%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
Reid Spencer68fb37a2004-08-14 09:37:15 +000025%option noyymore
Reid Spencerbae68252004-08-19 04:49:47 +000026%option noreject
27%pointer
Reid Spencer68fb37a2004-08-14 09:37:15 +000028
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
Reid Spencerbae68252004-08-19 04:49:47 +000040#define YY_FATAL_ERROR(msg) \
41 { \
42 assert(ConfigLexerInput != 0 && "Oops"); \
43 ConfigLexerInput->error(msg); \
44 }
45
Reid Spencerbf437722004-08-15 08:19:46 +000046#define YY_DECL ConfigLexerTokens llvm::Configlex()
47
48#define yyterminate() { return EOFTOK; }
49
Reid Spencer68fb37a2004-08-14 09:37:15 +000050using namespace llvm;
51
Reid Spencerbae68252004-08-19 04:49:47 +000052inline llvm::ConfigLexerTokens
53handleContext(const char* tokenText, llvm::ConfigLexerTokens token) {
54 if (ConfigLexerState.in_value) {
55 ConfigLexerState.StringVal = tokenText;
56 return OPTION;
Reid Spencer68fb37a2004-08-14 09:37:15 +000057 }
Reid Spencerbae68252004-08-19 04:49:47 +000058 return token;
Reid Spencer68fb37a2004-08-14 09:37:15 +000059}
60
Reid Spencerbae68252004-08-19 04:49:47 +000061inline llvm::ConfigLexerTokens
62handleSubstitution(llvm::ConfigLexerTokens token) {
63 if (ConfigLexerState.in_value)
64 return token;
65 YY_FATAL_ERROR("Substitition tokens not allowed in names" );
66 return ERRORTOK;
67};
68
69inline llvm::ConfigLexerTokens handleBoolean(llvm::ConfigLexerTokens token) {
70 if (ConfigLexerState.in_value)
71 return token;
72 YY_FATAL_ERROR("Boolean values not allowed in names");
73 return ERRORTOK;
74}
Reid Spencer68fb37a2004-08-14 09:37:15 +000075
76%}
77
Reid Spencer68fb37a2004-08-14 09:37:15 +000078ASSEMBLER assembler|Assembler|ASSEMBLER
Reid Spencer53aa7932004-08-20 22:53:11 +000079BadSubst \%[^iots][a-zA-Z]\%
Reid Spencerbae68252004-08-19 04:49:47 +000080COMMAND command|Command|COMMAND
Reid Spencer1df71212004-08-22 18:02:13 +000081Comment \#[^\r\n]*\r?\n
82NewLine \r?\n
Reid Spencerbae68252004-08-19 04:49:47 +000083Eq \=
Reid Spencer1df71212004-08-22 18:02:13 +000084EscNewLine \\\r?\n
Reid Spencerbae68252004-08-19 04:49:47 +000085GROKS_DASH_O groks_dash_O|Groks_Dash_O|GROKS_DASH_O
86LANG lang|Lang|LANG
Reid Spencer68fb37a2004-08-14 09:37:15 +000087LINKER linker|Linker|LINKER
88NAME name|Name|NAME
Reid Spencerbf437722004-08-15 08:19:46 +000089OPT1 opt1|Opt1|OPT1
90OPT2 opt2|Opt2|OPT2
91OPT3 opt3|Opt3|OPT3
92OPT4 opt4|Opt4|OPT4
93OPT5 opt5|Opt5|OPT5
Reid Spencerbae68252004-08-19 04:49:47 +000094OPTIMIZER optimizer|Optimizer|OPTIMIZER
95OPTIMIZES optimizes|Optimizes|OPTIMIZES
Reid Spencer53aa7932004-08-20 22:53:11 +000096Option [-A-Za-z0-9_:%+/\\|,][-A-Za-z0-9_:+/\\|,@]*
Reid Spencerbae68252004-08-19 04:49:47 +000097OUTPUT_IS_ASM output_is_asm|Output_Is_Asm|OUTPUT_IS_ASM
98PREPROCESSES preprocesses|PreProcesses|PREPROCESSES
99PREPROCESSOR preprocessor|PreProcessor|PREPROCESSOR
100REQUIRED required|Required|REQUIRED
Reid Spencer68fb37a2004-08-14 09:37:15 +0000101Sep \.
Reid Spencer68fb37a2004-08-14 09:37:15 +0000102String \"[^\"]*\"
Reid Spencerbae68252004-08-19 04:49:47 +0000103TRANSLATES translates|Translates|TRANSLATES
104TRANSLATOR translator|Translator|TRANSLATOR
Reid Spencer1df71212004-08-22 18:02:13 +0000105VERSION version|Version|VERSION
Reid Spencerbae68252004-08-19 04:49:47 +0000106White [ \t]*
107
Reid Spencer68fb37a2004-08-14 09:37:15 +0000108True true|True|TRUE
109False false|False|FALSE
110On on|On|ON
111Off off|Off|OFF
112Yes yes|Yes|YES
113No no|No|NO
114
115%%
116
Reid Spencer68fb37a2004-08-14 09:37:15 +0000117{White} { /* Ignore whitespace */ }
118
Reid Spencerbae68252004-08-19 04:49:47 +0000119{Comment} { /* Ignore comments */
120 ConfigLexerState.in_value = false;
121 ConfigLexerState.lineNum++;
122 return EOLTOK;
123 }
Reid Spencer68fb37a2004-08-14 09:37:15 +0000124
Reid Spencerbae68252004-08-19 04:49:47 +0000125{EscNewLine} { ConfigLexerState.lineNum++;
126 /* Don't return EOLTOK! */
127 }
128
129{NewLine} { ConfigLexerState.in_value = false;
130 ConfigLexerState.lineNum++;
131 return EOLTOK;
132 }
133
134{Eq} { ConfigLexerState.in_value = true;
135 return EQUALS;
136 }
137
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); }
Reid Spencer1df71212004-08-22 18:02:13 +0000157{VERSION} { return handleContext("version",VERSION); }
Reid Spencerbae68252004-08-19 04:49:47 +0000158
Reid Spencer53aa7932004-08-20 22:53:11 +0000159%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); }
Reid Spencerbae68252004-08-19 04:49:47 +0000165{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); }
172
173{Option} { ConfigLexerState.StringVal = yytext; return OPTION; }
174{String} { ConfigLexerState.StringVal = yytext+1; // Nuke start quote
175 ConfigLexerState.StringVal.erase(
176 --ConfigLexerState.StringVal.end());
Reid Spencer68fb37a2004-08-14 09:37:15 +0000177 return STRING;
178 }
Reid Spencerbae68252004-08-19 04:49:47 +0000179{Sep} { if (ConfigLexerState.in_value) { ConfigLexerState.StringVal = yytext;
Reid Spencerbf437722004-08-15 08:19:46 +0000180 return OPTION; } }
181
Reid Spencer68fb37a2004-08-14 09:37:15 +0000182
183%%