Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1 | %option stack |
| 2 | |
| 3 | %x comment |
| 4 | %x api_entry |
| 5 | %x api_entry2 |
| 6 | %x api_entry_param |
| 7 | %x var_type |
| 8 | |
| 9 | DIGIT [0-9] |
| 10 | ID [a-zA-Z_][a-zA-Z0-9_]* |
| 11 | |
Joe Onorato | daed524 | 2009-08-10 15:01:51 -0700 | [diff] [blame] | 12 | #include "spec.h" |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 13 | |
| 14 | int num_lines = 0; |
| 15 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 16 | VarType *currType = 0; |
| 17 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 18 | ApiEntry apis[128]; |
| 19 | int apiCount = 0; |
| 20 | |
| 21 | int typeNextState; |
| 22 | |
Alex Sakhartchouk | e7c4a75 | 2011-04-06 10:57:51 -0700 | [diff] [blame] | 23 | void checkPointerType() { |
| 24 | VarType *lastType = currType; |
| 25 | if (lastType->ptrLevel) { |
| 26 | currType = &apis[apiCount].params[apis[apiCount].paramCount]; |
| 27 | currType->type = 4; |
| 28 | sprintf(currType->typeName, "%s", "size_t"); |
| 29 | if (lastType->name[0]) { |
| 30 | sprintf(currType->name, "%s_length", lastType->name); |
| 31 | } |
| 32 | apis[apiCount].paramCount++; |
| 33 | } |
| 34 | } |
| 35 | |
Joe Onorato | daed524 | 2009-08-10 15:01:51 -0700 | [diff] [blame] | 36 | extern "C" int yylex(); |
| 37 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 38 | %% |
| 39 | |
| 40 | "/*" BEGIN(comment); |
| 41 | <comment>[^*\n]* /* eat anything that's not a '*' */ |
| 42 | <comment>"*"+[^*/\n]* /* eat up '*'s not followed by '/'s */ |
| 43 | <comment>\n ++num_lines; |
| 44 | <comment>"*"+"/" BEGIN(INITIAL); |
| 45 | |
| 46 | <*>" " //printf("found ' '\n"); |
Jason Sams | 65bdaf1 | 2011-04-26 14:50:00 -0700 | [diff] [blame^] | 47 | <*>"\t" //printf("found ' '\n"); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 48 | <*>"\n" ++num_lines; //printf("found lf \n"); |
| 49 | |
| 50 | {ID} { |
| 51 | memset(&apis[apiCount], 0, sizeof(ApiEntry)); |
| 52 | memcpy(apis[apiCount].name, yytext, yyleng); |
| 53 | BEGIN(api_entry); |
| 54 | } |
| 55 | |
| 56 | <api_entry>"{" { |
| 57 | BEGIN(api_entry2); |
| 58 | } |
| 59 | |
| 60 | <api_entry2>"sync" { |
| 61 | apis[apiCount].sync = 1; |
| 62 | } |
| 63 | |
Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 64 | <api_entry2>"handcodeApi" { |
| 65 | apis[apiCount].handcodeApi = 1; |
| 66 | } |
| 67 | |
Jason Sams | 65bdaf1 | 2011-04-26 14:50:00 -0700 | [diff] [blame^] | 68 | <api_entry2>"direct" { |
| 69 | apis[apiCount].direct = 1; |
| 70 | } |
| 71 | |
| 72 | <api_entry2>"nocontext" { |
| 73 | apis[apiCount].nocontext = 1; |
Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 74 | } |
| 75 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 76 | <api_entry2>"ret" { |
| 77 | currType = &apis[apiCount].ret; |
| 78 | typeNextState = api_entry2; |
| 79 | BEGIN(var_type); |
| 80 | } |
| 81 | |
| 82 | <api_entry2>"param" { |
| 83 | currType = &apis[apiCount].params[apis[apiCount].paramCount]; |
| 84 | apis[apiCount].paramCount++; |
| 85 | typeNextState = api_entry_param; |
| 86 | BEGIN(var_type); |
| 87 | } |
| 88 | |
| 89 | <var_type>"const" { |
| 90 | currType->isConst = 1; |
| 91 | } |
| 92 | |
| 93 | <var_type>"i8" { |
| 94 | currType->type = 1; |
| 95 | currType->bits = 8; |
| 96 | BEGIN(typeNextState); |
| 97 | } |
| 98 | |
| 99 | <var_type>"i16" { |
| 100 | currType->type = 1; |
| 101 | currType->bits = 16; |
| 102 | BEGIN(typeNextState); |
| 103 | } |
| 104 | |
| 105 | <var_type>"i32" { |
| 106 | currType->type = 1; |
| 107 | currType->bits = 32; |
| 108 | BEGIN(typeNextState); |
| 109 | } |
| 110 | |
| 111 | <var_type>"i64" { |
| 112 | currType->type = 1; |
| 113 | currType->bits = 64; |
| 114 | BEGIN(typeNextState); |
| 115 | } |
| 116 | |
| 117 | <var_type>"u8" { |
| 118 | currType->type = 2; |
| 119 | currType->bits = 8; |
| 120 | BEGIN(typeNextState); |
| 121 | } |
| 122 | |
| 123 | <var_type>"u16" { |
| 124 | currType->type = 2; |
| 125 | currType->bits = 16; |
| 126 | BEGIN(typeNextState); |
| 127 | } |
| 128 | |
| 129 | <var_type>"u32" { |
| 130 | currType->type = 2; |
| 131 | currType->bits = 32; |
| 132 | BEGIN(typeNextState); |
| 133 | } |
| 134 | |
| 135 | <var_type>"u64" { |
| 136 | currType->type = 2; |
| 137 | currType->bits = 64; |
| 138 | BEGIN(typeNextState); |
| 139 | } |
| 140 | |
| 141 | <var_type>"f" { |
| 142 | currType->type = 3; |
| 143 | currType->bits = 32; |
| 144 | BEGIN(typeNextState); |
| 145 | } |
| 146 | |
| 147 | <var_type>"d" { |
| 148 | currType->type = 3; |
| 149 | currType->bits = 64; |
| 150 | BEGIN(typeNextState); |
| 151 | } |
| 152 | |
| 153 | <var_type>{ID} { |
| 154 | currType->type = 4; |
| 155 | currType->bits = 32; |
Joe Onorato | daed524 | 2009-08-10 15:01:51 -0700 | [diff] [blame] | 156 | memcpy(currType->typeName, yytext, yyleng); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 157 | BEGIN(typeNextState); |
| 158 | } |
| 159 | |
| 160 | <api_entry_param>"*" { |
| 161 | currType->ptrLevel ++; |
| 162 | } |
| 163 | |
| 164 | <api_entry_param>{ID} { |
| 165 | memcpy(currType->name, yytext, yyleng); |
Alex Sakhartchouk | e7c4a75 | 2011-04-06 10:57:51 -0700 | [diff] [blame] | 166 | checkPointerType(); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 167 | BEGIN(api_entry2); |
| 168 | } |
| 169 | |
Jason Sams | 156cce6 | 2010-03-03 13:03:18 -0800 | [diff] [blame] | 170 | <api_entry2>"*" { |
| 171 | currType->ptrLevel ++; |
| 172 | } |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 173 | |
| 174 | <api_entry2>"}" { |
| 175 | apiCount++; |
| 176 | BEGIN(INITIAL); |
| 177 | } |
| 178 | |
| 179 | |
| 180 | %% |
| 181 | |
| 182 | |
| 183 | int yywrap() |
| 184 | { |
| 185 | return 1; |
| 186 | } |
| 187 | |