blob: c0f42a3d903214b7b306f7a7e0eda7c0b9f11290 [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"
17%option yylineno
18%option nostdinit
19%option never-interactive
20%option batch
21%option noyywrap
22%option nodefault
23%option 8bit
24%option outfile="ConfigLexer.cpp"
25%option ecs
26%option noreject
27%option noyymore
28%array
29
30%{
31
32#include "ConfigLexer.h"
33
34#define YY_INPUT(buf,result,max_size) \
35 { \
36 assert(ConfigLexerInput != 0 && "Oops"); \
37 result = ConfigLexerInput->read(buf,max_size); \
38 if (result == 0 ) result = YY_NULL; \
39 }
40
Reid Spencerbf437722004-08-15 08:19:46 +000041#define YY_DECL ConfigLexerTokens llvm::Configlex()
42
43#define yyterminate() { return EOFTOK; }
44
Reid Spencer68fb37a2004-08-14 09:37:15 +000045using namespace llvm;
46
47/* Conversion of text ints to binary */
48static int64_t IntToVal(const char *Buffer) {
49 int64_t Result = 0;
50 for (; *Buffer; Buffer++) {
51 int64_t OldRes = Result;
52 Result *= 10;
53 Result += *Buffer-'0';
54 }
55 return Result;
56}
57
58bool in_value = false;
59
60%}
61
62LANG lang|Lang|LANG
63PREPROCESSOR preprocessor|PreProcessor|PREPROCESSOR
64TRANSLATOR translator|Translator|TRANSLATOR
65OPTIMIZER optimizer|Optimizer|OPTIMIZER
66ASSEMBLER assembler|Assembler|ASSEMBLER
67LINKER linker|Linker|LINKER
68NAME name|Name|NAME
Reid Spencerbf437722004-08-15 08:19:46 +000069REQUIRED required|Required|REQUIRED
Reid Spencer68fb37a2004-08-14 09:37:15 +000070COMMAND command|Command|COMMAND
71PREPROCESSES preprocesses|PreProcesses|PREPROCESSES
72GROKS_DASH_O groks_dash_O|Groks_Dash_O|GROKS_DASH_O
Reid Spencerbf437722004-08-15 08:19:46 +000073GROKS_O10N groks_optimization|Groks_Optimization|GROKS_OPTIMIZATION
Reid Spencer68fb37a2004-08-14 09:37:15 +000074OPTIMIZES optimizes|Optimizes|OPTIMIZES
Reid Spencerbf437722004-08-15 08:19:46 +000075OPT1 opt1|Opt1|OPT1
76OPT2 opt2|Opt2|OPT2
77OPT3 opt3|Opt3|OPT3
78OPT4 opt4|Opt4|OPT4
79OPT5 opt5|Opt5|OPT5
Reid Spencer68fb37a2004-08-14 09:37:15 +000080Comment \#[^\n]*
81NewLine \n
82White [ \t]*
83Option [-A-Za-z0-9_:%+/\\|,]*
84Sep \.
85Eq \=
86String \"[^\"]*\"
87Integer [-+]?[0-9]+
88True true|True|TRUE
89False false|False|FALSE
90On on|On|ON
91Off off|Off|OFF
92Yes yes|Yes|YES
93No no|No|NO
94
95%%
96
Reid Spencerbf437722004-08-15 08:19:46 +000097{NewLine} { in_value = false; return EOLTOK; }
98{Eq} { in_value = true; return EQUALS; }
Reid Spencer68fb37a2004-08-14 09:37:15 +000099{Comment} { /* Ignore comments */ }
100{White} { /* Ignore whitespace */ }
101
102{LANG} { if (in_value) { ConfigLexerData.StringVal = "lang";
103 return OPTION; } else return LANG; }
104{PREPROCESSOR} { if (in_value) { ConfigLexerData.StringVal = "preprocessor";
105 return OPTION; } else return PREPROCESSOR; }
106{TRANSLATOR} { if (in_value) { ConfigLexerData.StringVal = "translator";
107 return OPTION; } else return TRANSLATOR; }
108{OPTIMIZER} { if (in_value) { ConfigLexerData.StringVal = "optimizer";
109 return OPTION; } else return OPTIMIZER; }
110{ASSEMBLER} { if (in_value) { ConfigLexerData.StringVal = "assembler";
111 return OPTION; } else return ASSEMBLER; }
112{LINKER} { if (in_value) { ConfigLexerData.StringVal = "linker";
113 return OPTION; } else return LINKER; }
114{NAME} { if (in_value) { ConfigLexerData.StringVal = "name";
115 return OPTION; } else return NAME; }
Reid Spencerbf437722004-08-15 08:19:46 +0000116{REQUIRED} { if (in_value) { ConfigLexerData.StringVal = "required";
117 return OPTION; } else return REQUIRED; }
Reid Spencer68fb37a2004-08-14 09:37:15 +0000118{COMMAND} { if (in_value) { ConfigLexerData.StringVal = "command";
119 return OPTION; } else return COMMAND; }
120{PREPROCESSES} { if (in_value) { ConfigLexerData.StringVal = "preprocesses";
121 return OPTION; } else return PREPROCESSES; }
122{GROKS_DASH_O} { if (in_value) { ConfigLexerData.StringVal = "groks_dash_O";
123 return OPTION; } else return GROKS_DASH_O; }
Reid Spencerbf437722004-08-15 08:19:46 +0000124{GROKS_O10N} { if (in_value) { ConfigLexerData.StringVal =
125 "groks_optimization"; return OPTION; }
126 else return GROKS_O10N; }
Reid Spencer68fb37a2004-08-14 09:37:15 +0000127{OPTIMIZES} { if (in_value) { ConfigLexerData.StringVal = "optimizes";
128 return OPTION; } else return OPTIMIZES; }
Reid Spencerbf437722004-08-15 08:19:46 +0000129{OPT1} { if (in_value) { ConfigLexerData.StringVal = "opt1";
130 return OPTION; } else return OPT1; }
131{OPT2} { if (in_value) { ConfigLexerData.StringVal = "opt2";
132 return OPTION; } else return OPT2; }
133{OPT3} { if (in_value) { ConfigLexerData.StringVal = "opt3";
134 return OPTION; } else return OPT3; }
135{OPT4} { if (in_value) { ConfigLexerData.StringVal = "opt4";
136 return OPTION; } else return OPT4; }
137{OPT5} { if (in_value) { ConfigLexerData.StringVal = "opt5";
138 return OPTION; } else return OPT5; }
Reid Spencer68fb37a2004-08-14 09:37:15 +0000139@in@ { if (in_value) return IN_SUBST; else return ERRORTOK; }
140@out@ { if (in_value) return OUT_SUBST; else return ERRORTOK; }
141{True} { if (in_value) return TRUETOK; else return ERRORTOK; }
142{On} { if (in_value) return TRUETOK; else return ERRORTOK; }
143{Yes} { if (in_value) return TRUETOK; else return ERRORTOK; }
144{False} { if (in_value) return FALSETOK; else return ERRORTOK; }
145{Off} { if (in_value) return FALSETOK; else return ERRORTOK; }
146{No} { if (in_value) return FALSETOK; else return ERRORTOK; }
147
Reid Spencer68fb37a2004-08-14 09:37:15 +0000148{Option} { ConfigLexerData.StringVal = yytext; return OPTION; }
149{Integer} { ConfigLexerData.IntegerVal = IntToVal(yytext); return INTEGER; }
150{String} { yytext[yyleng-1] = 0; // nuke end quote
151 ConfigLexerData.StringVal = yytext+1; // Nuke start quote
152 return STRING;
153 }
Reid Spencerbf437722004-08-15 08:19:46 +0000154{Sep} { if (in_value) { ConfigLexerData.StringVal = yytext;
155 return OPTION; } }
156
Reid Spencer68fb37a2004-08-14 09:37:15 +0000157
158%%