include/stdint.h: Remove old reference to ROMCC
[coreboot.git] / util / cbfstool / fmd_scanner.l
blobbe9a5def84c5d8e7ee0201501371bb7d14ae4f11
1 /*
2  * fmd_scanner.l, scanner generator for flashmap descriptor language
3  *
4  * Copyright (C) 2015 Google, Inc.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; version 2 of the License.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  */
17 #include "fmd_parser.h"
19 #include <assert.h>
20 #include <string.h>
22 int parse_integer(char *src, int base);
23 int copy_string(const char *src);
26 %option noyywrap
27 %s FLAGS
29 MULTIPLIER [KMG]
32 [[:space:]]+                /* Eat whitespace. */
33 #.*$                        /* Eat comments. */
34 \(                          BEGIN(FLAGS); return *yytext;
35 <FLAGS>\)                   BEGIN(INITIAL); return *yytext;
36 <FLAGS>CBFS                 return FLAG_CBFS;
37 <FLAGS>PRESERVE             return FLAG_PRESERVE;
38 0{MULTIPLIER}?              |
39 [1-9][0-9]*{MULTIPLIER}?    return parse_integer(yytext, 10);
40 0[0-9]+{MULTIPLIER}?        return OCTAL;
41 0[xX][0-9a-fA-F]+{MULTIPLIER}? return parse_integer(yytext + 2, 16);
42 [^#@{}()[:space:]]*         return copy_string(yytext);
43 .                           return *yytext;
47 int parse_integer(char *src, int base)
49         char *multiplier = NULL;
50         unsigned val = strtoul(src, &multiplier, base);
52         if (*multiplier) {
53                 switch(*multiplier) {
54                 case 'K':
55                         val *= 1024;
56                         break;
57                 case 'M':
58                         val *= 1024*1024;
59                         break;
60                 case 'G':
61                         val *= 1024*1024*1024;
62                         break;
63                 default:
64                         // If we ever get here, the MULTIPLIER regex is allowing
65                         // multiplier suffixes not handled by this code.
66                         assert(false);
67                 }
68         }
70         yylval.intval = val;
71         return INTEGER;
74 int copy_string(const char *src)
76         yylval.strval = strdup(src);
77         return STRING;