blob: 4589d4821ab5cbea25d0b4a18585d883f398a69b [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 Spencer90654fd2004-11-23 23:35:16 +000082LIBS libs|Libs|LIBS
Reid Spencerec4f5882004-08-24 13:58:37 +000083LINKER linker|Linker|LINKER
Reid Spencer68fb37a2004-08-14 09:37:15 +000084NAME name|Name|NAME
Reid Spencerbf437722004-08-15 08:19:46 +000085OPT1 opt1|Opt1|OPT1
86OPT2 opt2|Opt2|OPT2
87OPT3 opt3|Opt3|OPT3
88OPT4 opt4|Opt4|OPT4
89OPT5 opt5|Opt5|OPT5
Reid Spencerbae68252004-08-19 04:49:47 +000090OPTIMIZER optimizer|Optimizer|OPTIMIZER
Reid Spencerec4f5882004-08-24 13:58:37 +000091OUTPUT output|Output|OUTPUT
Reid Spencerbae68252004-08-19 04:49:47 +000092PREPROCESSES preprocesses|PreProcesses|PREPROCESSES
93PREPROCESSOR preprocessor|PreProcessor|PREPROCESSOR
94REQUIRED required|Required|REQUIRED
Reid Spencerbae68252004-08-19 04:49:47 +000095TRANSLATES translates|Translates|TRANSLATES
96TRANSLATOR translator|Translator|TRANSLATOR
Reid Spencer1df71212004-08-22 18:02:13 +000097VERSION version|Version|VERSION
Reid Spencerec4f5882004-08-24 13:58:37 +000098
99True true|True|TRUE|on|On|ON|yes|Yes|YES
100False false|False|FALSE|off|Off|OFF|no|No|NO
101Bytecode bc|BC|bytecode|Bytecode|BYTECODE
102Assembly asm|ASM|assembly|Assembly|ASSEMBLY
103
Reid Spencer90654fd2004-11-23 23:35:16 +0000104BadSubst \%[a-zA-Z]*\%
Reid Spencerec4f5882004-08-24 13:58:37 +0000105Comment \#[^\r\n]*\r?\n
106NewLine \r?\n
107Eq \=
108EscNewLine \\\r?\n
109Option [-A-Za-z0-9_:%+/\\|,][-A-Za-z0-9_:+/\\|,@]*
110Sep \.
111String \"[^\"]*\"
Reid Spencerbae68252004-08-19 04:49:47 +0000112White [ \t]*
113
Reid Spencer68fb37a2004-08-14 09:37:15 +0000114
115%%
116
Reid Spencer90654fd2004-11-23 23:35:16 +0000117{White} { if (ConfigLexerState.in_value) return SPACE; }
Reid Spencer68fb37a2004-08-14 09:37:15 +0000118
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
Reid Spencer90654fd2004-11-23 23:35:16 +0000138{Sep} { return SEPARATOR; }
139
Reid Spencer3a9b2222004-10-28 04:04:38 +0000140{VERSION} { return handleNameContext(VERSION_TOK); }
Reid Spencerbae68252004-08-19 04:49:47 +0000141
Reid Spencerec4f5882004-08-24 13:58:37 +0000142{LANG} { return handleNameContext(LANG); }
Reid Spencer90654fd2004-11-23 23:35:16 +0000143{LIBS} { return handleNameContext(LIBS); }
Reid Spencerec4f5882004-08-24 13:58:37 +0000144{NAME} { return handleNameContext(NAME); }
145{OPT1} { return handleNameContext(OPT1); }
146{OPT2} { return handleNameContext(OPT2); }
147{OPT3} { return handleNameContext(OPT3); }
148{OPT4} { return handleNameContext(OPT4); }
149{OPT5} { return handleNameContext(OPT5); }
150
151{PREPROCESSOR} { return handleNameContext(PREPROCESSOR); }
152{COMMAND} { return handleNameContext(COMMAND); }
153{REQUIRED} { return handleNameContext(REQUIRED); }
154
155{TRANSLATOR} { return handleNameContext(TRANSLATOR); }
156{PREPROCESSES} { return handleNameContext(PREPROCESSES); }
157{OUTPUT} { return handleNameContext(OUTPUT); }
158
159{OPTIMIZER} { return handleNameContext(OPTIMIZER); }
160{TRANSLATES} { return handleNameContext(TRANSLATES); }
161
162{ASSEMBLER} { return handleNameContext(ASSEMBLER); }
163
164{LINKER} { return handleNameContext(LINKER); }
165
166%args% { return handleSubstitution(ARGS_SUBST); }
Reid Spencerca01f9b2004-08-30 06:29:06 +0000167%defs% { return handleSubstitution(DEFS_SUBST); }
Reid Spencer53aa7932004-08-20 22:53:11 +0000168%in% { return handleSubstitution(IN_SUBST); }
Reid Spencerca01f9b2004-08-30 06:29:06 +0000169%incls% { return handleSubstitution(INCLS_SUBST); }
170%libs% { return handleSubstitution(LIBS_SUBST); }
Reid Spencer53aa7932004-08-20 22:53:11 +0000171%opt% { return handleSubstitution(OPT_SUBST); }
Reid Spencer52c2dc12004-08-29 19:26:56 +0000172%out% { return handleSubstitution(OUT_SUBST); }
173%stats% { return handleSubstitution(STATS_SUBST); }
Reid Spencer53aa7932004-08-20 22:53:11 +0000174%target% { return handleSubstitution(TARGET_SUBST); }
Reid Spencer52c2dc12004-08-29 19:26:56 +0000175%time% { return handleSubstitution(TIME_SUBST); }
176%verbose% { return handleSubstitution(VERBOSE_SUBST); }
Reid Spencerd4ff15a2004-09-14 01:59:31 +0000177%fOpts% { return handleSubstitution(FOPTS_SUBST); }
178%MOpts% { return handleSubstitution(MOPTS_SUBST); }
179%WOpts% { return handleSubstitution(WOPTS_SUBST); }
Reid Spencerec4f5882004-08-24 13:58:37 +0000180
181{Assembly} { return handleValueContext(ASSEMBLY); }
182{Bytecode} { return handleValueContext(BYTECODE); }
183{True} { return handleValueContext(TRUETOK); }
184{False} { return handleValueContext(FALSETOK); }
Reid Spencerbae68252004-08-19 04:49:47 +0000185
186{Option} { ConfigLexerState.StringVal = yytext; return OPTION; }
187{String} { ConfigLexerState.StringVal = yytext+1; // Nuke start quote
188 ConfigLexerState.StringVal.erase(
189 --ConfigLexerState.StringVal.end());
Reid Spencer68fb37a2004-08-14 09:37:15 +0000190 return STRING;
191 }
Reid Spencer90654fd2004-11-23 23:35:16 +0000192{BadSubst} { YY_FATAL_ERROR("Invalid substitution token"); }
Reid Spencer68fb37a2004-08-14 09:37:15 +0000193
194%%