blob: 6633156eb334b68f1b259449b76bbfd25a627948 [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
Reid Spencerec4f5882004-08-24 13:58:37 +000053handleNameContext(llvm::ConfigLexerTokens token) {
54 ConfigLexerState.StringVal = yytext;
55 if (ConfigLexerState.in_value)
Reid Spencerbae68252004-08-19 04:49:47 +000056 return OPTION;
Reid Spencerbae68252004-08-19 04:49:47 +000057 return token;
Reid Spencer68fb37a2004-08-14 09:37:15 +000058}
59
Reid Spencerbae68252004-08-19 04:49:47 +000060inline llvm::ConfigLexerTokens
61handleSubstitution(llvm::ConfigLexerTokens token) {
Reid Spencerec4f5882004-08-24 13:58:37 +000062 if (ConfigLexerState.in_value) {
63 ConfigLexerState.StringVal = yytext;
Reid Spencerbae68252004-08-19 04:49:47 +000064 return token;
Reid Spencerec4f5882004-08-24 13:58:37 +000065 }
Reid Spencerbae68252004-08-19 04:49:47 +000066 YY_FATAL_ERROR("Substitition tokens not allowed in names" );
67 return ERRORTOK;
68};
69
Reid Spencerec4f5882004-08-24 13:58:37 +000070inline llvm::ConfigLexerTokens handleValueContext(llvm::ConfigLexerTokens token) {
71 ConfigLexerState.StringVal = yytext;
Reid Spencerbae68252004-08-19 04:49:47 +000072 if (ConfigLexerState.in_value)
73 return token;
Reid Spencerec4f5882004-08-24 13:58:37 +000074 return OPTION;
Reid Spencerbae68252004-08-19 04:49:47 +000075}
Reid Spencer68fb37a2004-08-14 09:37:15 +000076
77%}
78
Reid Spencer68fb37a2004-08-14 09:37:15 +000079ASSEMBLER assembler|Assembler|ASSEMBLER
Reid Spencerbae68252004-08-19 04:49:47 +000080COMMAND command|Command|COMMAND
Reid Spencerbae68252004-08-19 04:49:47 +000081LANG lang|Lang|LANG
Reid Spencerec4f5882004-08-24 13:58:37 +000082LINKER linker|Linker|LINKER
Reid Spencer68fb37a2004-08-14 09:37:15 +000083NAME name|Name|NAME
Reid Spencerbf437722004-08-15 08:19:46 +000084OPT1 opt1|Opt1|OPT1
85OPT2 opt2|Opt2|OPT2
86OPT3 opt3|Opt3|OPT3
87OPT4 opt4|Opt4|OPT4
88OPT5 opt5|Opt5|OPT5
Reid Spencerbae68252004-08-19 04:49:47 +000089OPTIMIZER optimizer|Optimizer|OPTIMIZER
Reid Spencerec4f5882004-08-24 13:58:37 +000090OUTPUT output|Output|OUTPUT
Reid Spencerbae68252004-08-19 04:49:47 +000091PREPROCESSES preprocesses|PreProcesses|PREPROCESSES
92PREPROCESSOR preprocessor|PreProcessor|PREPROCESSOR
93REQUIRED required|Required|REQUIRED
Reid Spencerbae68252004-08-19 04:49:47 +000094TRANSLATES translates|Translates|TRANSLATES
95TRANSLATOR translator|Translator|TRANSLATOR
Reid Spencer1df71212004-08-22 18:02:13 +000096VERSION version|Version|VERSION
Reid Spencerec4f5882004-08-24 13:58:37 +000097
98True true|True|TRUE|on|On|ON|yes|Yes|YES
99False false|False|FALSE|off|Off|OFF|no|No|NO
100Bytecode bc|BC|bytecode|Bytecode|BYTECODE
101Assembly asm|ASM|assembly|Assembly|ASSEMBLY
102
103BadSubst \%[^iots][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 \"[^\"]*\"
Reid Spencerbae68252004-08-19 04:49:47 +0000111White [ \t]*
112
Reid Spencer68fb37a2004-08-14 09:37:15 +0000113
114%%
115
Reid Spencer68fb37a2004-08-14 09:37:15 +0000116{White} { /* Ignore whitespace */ }
117
Reid Spencerbae68252004-08-19 04:49:47 +0000118{Comment} { /* Ignore comments */
119 ConfigLexerState.in_value = false;
120 ConfigLexerState.lineNum++;
121 return EOLTOK;
122 }
Reid Spencer68fb37a2004-08-14 09:37:15 +0000123
Reid Spencerbae68252004-08-19 04:49:47 +0000124{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
Reid Spencer3a9b2222004-10-28 04:04:38 +0000137{VERSION} { return handleNameContext(VERSION_TOK); }
Reid Spencerbae68252004-08-19 04:49:47 +0000138
Reid Spencerec4f5882004-08-24 13:58:37 +0000139{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); }
Reid Spencerca01f9b2004-08-30 06:29:06 +0000163%defs% { return handleSubstitution(DEFS_SUBST); }
Reid Spencer53aa7932004-08-20 22:53:11 +0000164%in% { return handleSubstitution(IN_SUBST); }
Reid Spencerca01f9b2004-08-30 06:29:06 +0000165%incls% { return handleSubstitution(INCLS_SUBST); }
166%libs% { return handleSubstitution(LIBS_SUBST); }
Reid Spencer53aa7932004-08-20 22:53:11 +0000167%opt% { return handleSubstitution(OPT_SUBST); }
Reid Spencer52c2dc12004-08-29 19:26:56 +0000168%out% { return handleSubstitution(OUT_SUBST); }
169%stats% { return handleSubstitution(STATS_SUBST); }
Reid Spencer53aa7932004-08-20 22:53:11 +0000170%target% { return handleSubstitution(TARGET_SUBST); }
Reid Spencer52c2dc12004-08-29 19:26:56 +0000171%time% { return handleSubstitution(TIME_SUBST); }
172%verbose% { return handleSubstitution(VERBOSE_SUBST); }
Reid Spencerd4ff15a2004-09-14 01:59:31 +0000173%fOpts% { return handleSubstitution(FOPTS_SUBST); }
174%MOpts% { return handleSubstitution(MOPTS_SUBST); }
175%WOpts% { return handleSubstitution(WOPTS_SUBST); }
Reid Spencerbae68252004-08-19 04:49:47 +0000176{BadSubst} { YY_FATAL_ERROR("Invalid substitution token"); }
Reid Spencerec4f5882004-08-24 13:58:37 +0000177
178{Assembly} { return handleValueContext(ASSEMBLY); }
179{Bytecode} { return handleValueContext(BYTECODE); }
180{True} { return handleValueContext(TRUETOK); }
181{False} { return handleValueContext(FALSETOK); }
Reid Spencerbae68252004-08-19 04:49:47 +0000182
183{Option} { ConfigLexerState.StringVal = yytext; return OPTION; }
184{String} { ConfigLexerState.StringVal = yytext+1; // Nuke start quote
185 ConfigLexerState.StringVal.erase(
186 --ConfigLexerState.StringVal.end());
Reid Spencer68fb37a2004-08-14 09:37:15 +0000187 return STRING;
188 }
Reid Spencerbae68252004-08-19 04:49:47 +0000189{Sep} { if (ConfigLexerState.in_value) { ConfigLexerState.StringVal = yytext;
Reid Spencerbf437722004-08-15 08:19:46 +0000190 return OPTION; } }
191
Reid Spencer68fb37a2004-08-14 09:37:15 +0000192
193%%