58ddd2bdbdf2d11ecbe8ce98090cb2b478242802
[oota-llvm.git] / tools / llvmc / ConfigLexer.l
1 /*===- 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
41 using namespace llvm;
42
43 /* Conversion of text ints to binary */
44 static int64_t IntToVal(const char *Buffer) {
45   int64_t Result = 0;
46   for (; *Buffer; Buffer++) {
47     int64_t OldRes = Result;
48     Result *= 10;
49     Result += *Buffer-'0';
50   }
51   return Result;
52 }
53
54 bool in_value = false;
55
56 %}
57
58 LANG            lang|Lang|LANG
59 PREPROCESSOR    preprocessor|PreProcessor|PREPROCESSOR
60 TRANSLATOR      translator|Translator|TRANSLATOR
61 OPTIMIZER       optimizer|Optimizer|OPTIMIZER
62 ASSEMBLER       assembler|Assembler|ASSEMBLER
63 LINKER          linker|Linker|LINKER
64 NAME            name|Name|NAME
65 NEEDED          needed|Needed|NEEDED
66 COMMAND         command|Command|COMMAND
67 PREPROCESSES    preprocesses|PreProcesses|PREPROCESSES
68 GROKS_DASH_O    groks_dash_O|Groks_Dash_O|GROKS_DASH_O
69 OPTIMIZES       optimizes|Optimizes|OPTIMIZES
70 Comment         \#[^\n]*
71 NewLine         \n
72 White           [ \t]*
73 Option          [-A-Za-z0-9_:%+/\\|,]*
74 Sep             \.
75 Eq              \=
76 String          \"[^\"]*\"
77 Integer         [-+]?[0-9]+
78 True            true|True|TRUE
79 False           false|False|FALSE
80 On              on|On|ON
81 Off             off|Off|OFF
82 Yes             yes|Yes|YES
83 No              no|No|NO
84
85 %%
86
87 {NewLine}       { in_value = false; ConfigLexerLine++; return EOLTOK; }
88 {Comment}       { /* Ignore comments */ }
89 {White}         { /* Ignore whitespace */ }
90
91 {LANG}          { if (in_value) { ConfigLexerData.StringVal = "lang"; 
92                     return OPTION;  } else return LANG; }
93 {PREPROCESSOR}  { if (in_value) { ConfigLexerData.StringVal = "preprocessor";
94                     return OPTION; } else return PREPROCESSOR; }
95 {TRANSLATOR}    { if (in_value) { ConfigLexerData.StringVal = "translator";
96                     return OPTION; } else return TRANSLATOR; }
97 {OPTIMIZER}     { if (in_value) { ConfigLexerData.StringVal = "optimizer";
98                     return OPTION; } else return OPTIMIZER; }
99 {ASSEMBLER}     { if (in_value) { ConfigLexerData.StringVal = "assembler";
100                     return OPTION; } else return ASSEMBLER; }
101 {LINKER}        { if (in_value) { ConfigLexerData.StringVal = "linker";
102                     return OPTION; } else return LINKER; }
103 {NAME}          { if (in_value) { ConfigLexerData.StringVal = "name";
104                     return OPTION; } else return NAME; }
105 {NEEDED}        { if (in_value) { ConfigLexerData.StringVal = "needed";
106                     return OPTION; } else return NEEDED; }
107 {COMMAND}       { if (in_value) { ConfigLexerData.StringVal = "command";
108                     return OPTION; } else return COMMAND; }
109 {PREPROCESSES}  { if (in_value) { ConfigLexerData.StringVal = "preprocesses";
110                     return OPTION; } else return PREPROCESSES; }
111 {GROKS_DASH_O}  { if (in_value) { ConfigLexerData.StringVal = "groks_dash_O";
112                     return OPTION; } else return GROKS_DASH_O; }
113 {OPTIMIZES}     { if (in_value) { ConfigLexerData.StringVal = "optimizes";
114                     return OPTION; } else return OPTIMIZES; }
115 {Sep}           { if (in_value) { ConfigLexerData.StringVal = yytext;
116                     return OPTION; } }
117
118 @in@            { if (in_value) return IN_SUBST; else return ERRORTOK;  }
119 @out@           { if (in_value) return OUT_SUBST; else return ERRORTOK; }
120 {True}          { if (in_value) return TRUETOK; else return ERRORTOK; }
121 {On}            { if (in_value) return TRUETOK; else return ERRORTOK; }
122 {Yes}           { if (in_value) return TRUETOK; else return ERRORTOK; }
123 {False}         { if (in_value) return FALSETOK; else return ERRORTOK; }
124 {Off}           { if (in_value) return FALSETOK; else return ERRORTOK; }
125 {No}            { if (in_value) return FALSETOK; else return ERRORTOK; }
126
127 {Eq}            { in_value = true; return EQUALS; }
128 {Option}        { ConfigLexerData.StringVal = yytext; return OPTION; }
129 {Integer}       { ConfigLexerData.IntegerVal = IntToVal(yytext); return INTEGER; }
130 {String}        { yytext[yyleng-1] = 0;          // nuke end quote
131                   ConfigLexerData.StringVal = yytext+1;  // Nuke start quote
132                   return STRING;
133                 }
134
135 %%