aslcompiler.l revision 118611
1
2%{
3/******************************************************************************
4 *
5 * Module Name: aslcompiler.l - Flex input file
6 *              $Revision: $
7 *
8 *****************************************************************************/
9
10/******************************************************************************
11 *
12 * 1. Copyright Notice
13 *
14 * Some or all of this work - Copyright (c) 1999 - 2003, Intel Corp.
15 * All rights reserved.
16 *
17 * 2. License
18 *
19 * 2.1. This is your license from Intel Corp. under its intellectual property
20 * rights.  You may have additional license terms from the party that provided
21 * you this software, covering your right to use that party's intellectual
22 * property rights.
23 *
24 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
25 * copy of the source code appearing in this file ("Covered Code") an
26 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
27 * base code distributed originally by Intel ("Original Intel Code") to copy,
28 * make derivatives, distribute, use and display any portion of the Covered
29 * Code in any form, with the right to sublicense such rights; and
30 *
31 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
32 * license (with the right to sublicense), under only those claims of Intel
33 * patents that are infringed by the Original Intel Code, to make, use, sell,
34 * offer to sell, and import the Covered Code and derivative works thereof
35 * solely to the minimum extent necessary to exercise the above copyright
36 * license, and in no event shall the patent license extend to any additions
37 * to or modifications of the Original Intel Code.  No other license or right
38 * is granted directly or by implication, estoppel or otherwise;
39 *
40 * The above copyright and patent license is granted only if the following
41 * conditions are met:
42 *
43 * 3. Conditions
44 *
45 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
46 * Redistribution of source code of any substantial portion of the Covered
47 * Code or modification with rights to further distribute source must include
48 * the above Copyright Notice, the above License, this list of Conditions,
49 * and the following Disclaimer and Export Compliance provision.  In addition,
50 * Licensee must cause all Covered Code to which Licensee contributes to
51 * contain a file documenting the changes Licensee made to create that Covered
52 * Code and the date of any change.  Licensee must include in that file the
53 * documentation of any changes made by any predecessor Licensee.  Licensee
54 * must include a prominent statement that the modification is derived,
55 * directly or indirectly, from Original Intel Code.
56 *
57 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
58 * Redistribution of source code of any substantial portion of the Covered
59 * Code or modification without rights to further distribute source must
60 * include the following Disclaimer and Export Compliance provision in the
61 * documentation and/or other materials provided with distribution.  In
62 * addition, Licensee may not authorize further sublicense of source of any
63 * portion of the Covered Code, and must include terms to the effect that the
64 * license from Licensee to its licensee is limited to the intellectual
65 * property embodied in the software Licensee provides to its licensee, and
66 * not to intellectual property embodied in modifications its licensee may
67 * make.
68 *
69 * 3.3. Redistribution of Executable. Redistribution in executable form of any
70 * substantial portion of the Covered Code or modification must reproduce the
71 * above Copyright Notice, and the following Disclaimer and Export Compliance
72 * provision in the documentation and/or other materials provided with the
73 * distribution.
74 *
75 * 3.4. Intel retains all right, title, and interest in and to the Original
76 * Intel Code.
77 *
78 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
79 * Intel shall be used in advertising or otherwise to promote the sale, use or
80 * other dealings in products derived from or relating to the Covered Code
81 * without prior written authorization from Intel.
82 *
83 * 4. Disclaimer and Export Compliance
84 *
85 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
86 * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
87 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
88 * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
89 * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
90 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
91 * PARTICULAR PURPOSE.
92 *
93 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
94 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
95 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
96 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
97 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
98 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
99 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
100 * LIMITED REMEDY.
101 *
102 * 4.3. Licensee shall not export, either directly or indirectly, any of this
103 * software or system incorporating such software without first obtaining any
104 * required license or other approval from the U. S. Department of Commerce or
105 * any other agency or department of the United States Government.  In the
106 * event Licensee exports any such software from the United States or
107 * re-exports any such software from a foreign destination, Licensee shall
108 * ensure that the distribution and export/re-export of the software is in
109 * compliance with all laws, regulations, orders, or other restrictions of the
110 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
111 * any of its subsidiaries will export/re-export any technical data, process,
112 * software, or service, directly or indirectly, to any country for which the
113 * United States government or any agency thereof requires an export license,
114 * other governmental approval, or letter of assurance, without first obtaining
115 * such license, approval or letter.
116 *
117 *****************************************************************************/
118
119
120#include <stdlib.h>
121#include <string.h>
122#include "aslcompiler.h"
123#include "aslcompiler.y.h"
124YYSTYPE AslCompilerlval;
125
126/*
127 * Generation:  Use the following command line:
128 *
129 * flex.exe -PAslCompiler -i -o$(InputPath).c $(InputPath)
130 *
131 * -i: Scanner must be case-insensitive
132 */
133
134#define _COMPONENT          ACPI_COMPILER
135        ACPI_MODULE_NAME    ("aslscan")
136char
137comment (void);
138char
139comment2 (void);
140void
141count (int type);
142char
143literal (void);
144void
145copy (void);
146
147/*! [Begin] no source code translation */
148
149%}
150
151
152LeadNameChar                [A-Za-z_]
153DigitChar                   [0-9]
154HexDigitChar                [A-Fa-f0-9]
155RootChar                    [\\]
156Nothing                     []
157
158NameChar                    [A-Za-z_0-9]
159NameSeg1                    {LeadNameChar}{NameChar}
160NameSeg2                    {LeadNameChar}{NameChar}{NameChar}
161NameSeg3                    {LeadNameChar}{NameChar}{NameChar}{NameChar}
162NameSeg                     {LeadNameChar}|{NameSeg1}|{NameSeg2}|{NameSeg3}
163
164NameString                  {RootChar}|{RootChar}{NamePath}|[\^]+{NamePath}|{NonEmptyNamePath}
165NamePath                    {NonEmptyNamePath}?
166NonEmptyNamePath            {NameSeg}{NamePathTail}*
167NamePathTail                [.]{NameSeg}
168
169%%
170
171[ ]                         { count (0); }
172[\n]                        { count (0); }
173[ \t]                       { count (0); }
174
175
176"/*"                        { if (!comment ()) yyterminate (); }
177"//"                        { if (!comment2 ()) yyterminate (); }
178
179"\""                        { if (literal ()) return (PARSEOP_STRING_LITERAL); else yyterminate (); }
180
181
1820[xX]{HexDigitChar}+ |
183{DigitChar}+                { AslCompilerlval.i = UtDoConstant ((char *) AslCompilertext);
184                                count (1); return (PARSEOP_INTEGER); }
185
186"Include"                   { count (1); return (PARSEOP_INCLUDE); }
187"#include"                  { count (1); return (PARSEOP_INCLUDE_CSTYLE); }
188"#line"						{ count (1); return (PARSEOP_LINE_CSTYLE); }
189"External"                  { count (1); return (PARSEOP_EXTERNAL); }
190
191
192"Ones"                      { count (1); return (PARSEOP_ONES); }
193"One"                       { count (1); return (PARSEOP_ONE); }
194"Zero"                      { count (1); return (PARSEOP_ZERO); }
195"Revision"                  { count (1); return (PARSEOP_REVISION); }
196
197"Offset"                    { count (1); return (PARSEOP_OFFSET); }
198"AccessAs"                  { count (1); return (PARSEOP_ACCESSAS); }
199"BankField"                 { count (2); return (PARSEOP_BANKFIELD); }
200"CreateBitField"            { count (2); return (PARSEOP_CREATEBITFIELD); }
201"CreateByteField"           { count (2); return (PARSEOP_CREATEBYTEFIELD); }
202"CreateDWordField"          { count (2); return (PARSEOP_CREATEDWORDFIELD); }
203"CreateField"               { count (2); return (PARSEOP_CREATEFIELD); }
204"CreateQWordField"          { count (2); return (PARSEOP_CREATEQWORDFIELD); }
205"CreateWordField"           { count (2); return (PARSEOP_CREATEWORDFIELD); }
206"DataTableRegion"           { count (2); return (PARSEOP_DATATABLEREGION); }
207"Device"                    { count (2); return (PARSEOP_DEVICE); }
208"Event"                     { count (2); return (PARSEOP_EVENT); }
209"Field"                     { count (2); return (PARSEOP_FIELD); }
210"IndexField"                { count (2); return (PARSEOP_INDEXFIELD); }
211"Method"                    { count (2); return (PARSEOP_METHOD); }
212"Mutex"                     { count (2); return (PARSEOP_MUTEX); }
213"OperationRegion"           { count (2); return (PARSEOP_OPERATIONREGION); }
214"PowerResource"             { count (2); return (PARSEOP_POWERRESOURCE); }
215"Processor"                 { count (2); return (PARSEOP_PROCESSOR); }
216"ThermalZone"               { count (2); return (PARSEOP_THERMALZONE); }
217"Alias"                     { count (2); return (PARSEOP_ALIAS); }
218"Name"                      { count (2); return (PARSEOP_NAME); }
219"Scope"                     { count (2); return (PARSEOP_SCOPE); }
220"Break"                     { count (3); return (PARSEOP_BREAK); }
221"BreakPoint"                { count (3); return (PARSEOP_BREAKPOINT); }
222"Continue"                  { count (3); return (PARSEOP_CONTINUE); }
223"Fatal"                     { count (3); return (PARSEOP_FATAL); }
224"If"                        { count (3); return (PARSEOP_IF); }
225"Else"                      { count (3); return (PARSEOP_ELSE); }
226"ElseIf"                    { count (3); return (PARSEOP_ELSEIF); }
227"Load"                      { count (3); return (PARSEOP_LOAD); }
228"Noop"                      { count (3); return (PARSEOP_NOOP); }
229"Notify"                    { count (3); return (PARSEOP_NOTIFY); }
230"Release"                   { count (3); return (PARSEOP_RELEASE); }
231"Reset"                     { count (3); return (PARSEOP_RESET); }
232"Return"                    { count (3); return (PARSEOP_RETURN); }
233"Signal"                    { count (3); return (PARSEOP_SIGNAL); }
234"Sleep"                     { count (3); return (PARSEOP_SLEEP); }
235"Stall"                     { count (3); return (PARSEOP_STALL); }
236"Switch"                    { count (3); return (PARSEOP_SWITCH); }
237"Case"                      { count (3); return (PARSEOP_CASE); }
238"Default"                   { count (3); return (PARSEOP_DEFAULT); }
239"Unload"                    { count (3); return (PARSEOP_UNLOAD); }
240"While"                     { count (3); return (PARSEOP_WHILE); }
241
242"Acquire"                   { count (3); return (PARSEOP_ACQUIRE); }
243"Add"                       { count (3); return (PARSEOP_ADD); }
244"And"                       { count (3); return (PARSEOP_AND); }
245"Concatenate"               { count (3); return (PARSEOP_CONCATENATE); }
246"ConcatenateResTemplate"    { count (3); return (PARSEOP_CONCATENATERESTEMPLATE); }
247"CondRefOf"                 { count (3); return (PARSEOP_CONDREFOF); }
248"CopyObject"                { count (3); return (PARSEOP_COPYOBJECT); }
249"Decrement"                 { count (3); return (PARSEOP_DECREMENT); }
250"DeRefOf"                   { count (3); return (PARSEOP_DEREFOF); }
251"Divide"                    { count (3); return (PARSEOP_DIVIDE); }
252"FindSetLeftBit"            { count (3); return (PARSEOP_FINDSETLEFTBIT); }
253"FindSetRightBit"           { count (3); return (PARSEOP_FINDSETRIGHTBIT); }
254"FromBCD"                   { count (3); return (PARSEOP_FROMBCD); }
255"Increment"                 { count (3); return (PARSEOP_INCREMENT); }
256"Index"                     { count (3); return (PARSEOP_INDEX); }
257"LAnd"                      { count (3); return (PARSEOP_LAND); }
258"LEqual"                    { count (3); return (PARSEOP_LEQUAL); }
259"LGreater"                  { count (3); return (PARSEOP_LGREATER); }
260"LGreaterEqual"             { count (3); return (PARSEOP_LGREATEREQUAL); }
261"LLess"                     { count (3); return (PARSEOP_LLESS); }
262"LLessEqual"                { count (3); return (PARSEOP_LLESSEQUAL); }
263"LNot"                      { count (3); return (PARSEOP_LNOT); }
264"LNotEqual"                 { count (3); return (PARSEOP_LNOTEQUAL); }
265"LoadTable"                 { count (3); return (PARSEOP_LOADTABLE); }
266"LOr"                       { count (3); return (PARSEOP_LOR); }
267"Match"                     { count (3); return (PARSEOP_MATCH); }
268"Mid"                       { count (3); return (PARSEOP_MID); }
269"Mod"                       { count (3); return (PARSEOP_MOD); }
270"Multiply"                  { count (3); return (PARSEOP_MULTIPLY); }
271"NAnd"                      { count (3); return (PARSEOP_NAND); }
272"NOr"                       { count (3); return (PARSEOP_NOR); }
273"Not"                       { count (3); return (PARSEOP_NOT); }
274"ObjectType"                { count (3); return (PARSEOP_OBJECTTYPE); }
275"Or"                        { count (3); return (PARSEOP_OR); }
276"RefOf"                     { count (3); return (PARSEOP_REFOF); }
277"ShiftLeft"                 { count (3); return (PARSEOP_SHIFTLEFT); }
278"ShiftRight"                { count (3); return (PARSEOP_SHIFTRIGHT); }
279"SizeOf"                    { count (3); return (PARSEOP_SIZEOF); }
280"Store"                     { count (3); return (PARSEOP_STORE); }
281"Subtract"                  { count (3); return (PARSEOP_SUBTRACT); }
282"ToBCD"                     { count (3); return (PARSEOP_TOBCD); }
283"ToBuffer"                  { count (3); return (PARSEOP_TOBUFFER); }
284"ToDecimalString"           { count (3); return (PARSEOP_TODECIMALSTRING); }
285"ToHexString"               { count (3); return (PARSEOP_TOHEXSTRING); }
286"ToInteger"                 { count (3); return (PARSEOP_TOINTEGER); }
287"ToString"                  { count (3); return (PARSEOP_TOSTRING); }
288"Wait"                      { count (3); return (PARSEOP_WAIT); }
289"XOr"                       { count (3); return (PARSEOP_XOR); }
290
291"Arg0"                      { count (1); return (PARSEOP_ARG0); }
292"Arg1"                      { count (1); return (PARSEOP_ARG1); }
293"Arg2"                      { count (1); return (PARSEOP_ARG2); }
294"Arg3"                      { count (1); return (PARSEOP_ARG3); }
295"Arg4"                      { count (1); return (PARSEOP_ARG4); }
296"Arg5"                      { count (1); return (PARSEOP_ARG5); }
297"Arg6"                      { count (1); return (PARSEOP_ARG6); }
298
299"Local0"                    { count (1); return (PARSEOP_LOCAL0); }
300"Local1"                    { count (1); return (PARSEOP_LOCAL1); }
301"Local2"                    { count (1); return (PARSEOP_LOCAL2); }
302"Local3"                    { count (1); return (PARSEOP_LOCAL3); }
303"Local4"                    { count (1); return (PARSEOP_LOCAL4); }
304"Local5"                    { count (1); return (PARSEOP_LOCAL5); }
305"Local6"                    { count (1); return (PARSEOP_LOCAL6); }
306"Local7"                    { count (1); return (PARSEOP_LOCAL7); }
307
308"Debug"                     { count (1); return (PARSEOP_DEBUG); }
309
310"DefinitionBlock"           { count (1); return (PARSEOP_DEFINITIONBLOCK); }
311"Buffer"                    { count (1); return (PARSEOP_BUFFER); }
312"Package"                   { count (1); return (PARSEOP_PACKAGE); }
313
314"EISAID"                    { count (1); return (PARSEOP_EISAID); }
315"ResourceTemplate"          { count (1); return (PARSEOP_RESOURCETEMPLATE); }
316"Unicode"                   { count (1); return (PARSEOP_UNICODE); }
317"DMA"                       { count (1); return (PARSEOP_DMA); }
318"DWordIO"                   { count (1); return (PARSEOP_DWORDIO); }
319"DWordMemory"               { count (1); return (PARSEOP_DWORDMEMORY); }
320"EndDependentFn"            { count (1); return (PARSEOP_ENDDEPENDENTFN); }
321"FixedIO"                   { count (1); return (PARSEOP_FIXEDIO); }
322"Interrupt"                 { count (1); return (PARSEOP_INTERRUPT); }
323"IO"                        { count (1); return (PARSEOP_IO); }
324"IRQNoFlags"                { count (1); return (PARSEOP_IRQNOFLAGS); }
325"IRQ"                       { count (1); return (PARSEOP_IRQ); }
326"Memory24"                  { count (1); return (PARSEOP_MEMORY24); }
327"Memory32Fixed"             { count (1); return (PARSEOP_MEMORY32FIXED); }
328"Memory32"                  { count (1); return (PARSEOP_MEMORY32); }
329"QWordIO"                   { count (1); return (PARSEOP_QWORDIO); }
330"QWordMemory"               { count (1); return (PARSEOP_QWORDMEMORY); }
331"Register"                  { count (1); return (PARSEOP_REGISTER); }
332"StartDependentFn"          { count (1); return (PARSEOP_STARTDEPENDENTFN); }
333"StartDependentFnNoPri"     { count (1); return (PARSEOP_STARTDEPENDENTFN_NOPRI); }
334"VendorLong"                { count (1); return (PARSEOP_VENDORLONG); }
335"VendorShort"               { count (1); return (PARSEOP_VENDORSHORT); }
336"WordBusNumber"             { count (1); return (PARSEOP_WORDBUSNUMBER); }
337"WordIO"                    { count (1); return (PARSEOP_WORDIO); }
338
339"UnknownObj"                { count (0); return (PARSEOP_OBJECTTYPE_UNK); }
340"IntObj"                    { count (0); return (PARSEOP_OBJECTTYPE_INT); }
341"StrObj"                    { count (0); return (PARSEOP_OBJECTTYPE_STR); }
342"BuffObj"                   { count (0); return (PARSEOP_OBJECTTYPE_BUF); }
343"PkgObj"                    { count (0); return (PARSEOP_OBJECTTYPE_PKG); }
344"FieldUnitObj"              { count (0); return (PARSEOP_OBJECTTYPE_FLD); }
345"DeviceObj"                 { count (0); return (PARSEOP_OBJECTTYPE_DEV); }
346"EventObj"                  { count (0); return (PARSEOP_OBJECTTYPE_EVT); }
347"MethodObj"                 { count (0); return (PARSEOP_OBJECTTYPE_MTH); }
348"MutexObj"                  { count (0); return (PARSEOP_OBJECTTYPE_MTX); }
349"OpRegionObj"               { count (0); return (PARSEOP_OBJECTTYPE_OPR); }
350"PowerResObj"               { count (0); return (PARSEOP_OBJECTTYPE_POW); }
351"ThermalZoneObj"            { count (0); return (PARSEOP_OBJECTTYPE_THZ); }
352"BuffFieldObj"              { count (0); return (PARSEOP_OBJECTTYPE_BFF); }
353"DDBHandleObj"              { count (0); return (PARSEOP_OBJECTTYPE_DDB); }
354
355"AnyAcc"                    { count (0); return (PARSEOP_ACCESSTYPE_ANY); }
356"ByteAcc"                   { count (0); return (PARSEOP_ACCESSTYPE_BYTE); }
357"WordAcc"                   { count (0); return (PARSEOP_ACCESSTYPE_WORD); }
358"DWordAcc"                  { count (0); return (PARSEOP_ACCESSTYPE_DWORD); }
359"QWordAcc"                  { count (0); return (PARSEOP_ACCESSTYPE_QWORD); }
360"BufferAcc"                 { count (0); return (PARSEOP_ACCESSTYPE_BUF); }
361
362"Lock"                      { count (0); return (PARSEOP_LOCKRULE_LOCK); }
363"NoLock"                    { count (0); return (PARSEOP_LOCKRULE_NOLOCK); }
364
365"Preserve"                  { count (0); return (PARSEOP_UPDATERULE_PRESERVE); }
366"WriteAsOnes"               { count (0); return (PARSEOP_UPDATERULE_ONES); }
367"WriteAsZeros"              { count (0); return (PARSEOP_UPDATERULE_ZEROS); }
368
369"Serialized"                { count (0); return (PARSEOP_SERIALIZERULE_SERIAL); }
370"NotSerialized"             { count (0); return (PARSEOP_SERIALIZERULE_NOTSERIAL); }
371
372"SystemIO"                  { count (0); return (PARSEOP_REGIONSPACE_IO); }
373"SystemMemory"              { count (0); return (PARSEOP_REGIONSPACE_MEM); }
374"PCI_Config"                { count (0); return (PARSEOP_REGIONSPACE_PCI); }
375"EmbeddedControl"           { count (0); return (PARSEOP_REGIONSPACE_EC); }
376"SMBus"                     { count (0); return (PARSEOP_REGIONSPACE_SMBUS); }
377"SystemCMOS"                { count (0); return (PARSEOP_REGIONSPACE_CMOS); }
378"PciBarTarget"              { count (0); return (PARSEOP_REGIONSPACE_PCIBAR); }
379
380"FFixedHW"                  { count (0); return (PARSEOP_ADDRESSSPACE_FFIXEDHW); }
381
382"SMBQuick"                  { count (0); return (PARSEOP_ACCESSATTRIB_QUICK); }
383"SMBSendReceive"            { count (0); return (PARSEOP_ACCESSATTRIB_SND_RCV); }
384"SMBByte"                   { count (0); return (PARSEOP_ACCESSATTRIB_BYTE); }
385"SMBWord"                   { count (0); return (PARSEOP_ACCESSATTRIB_WORD); }
386"SMBBlock"                  { count (0); return (PARSEOP_ACCESSATTRIB_BLOCK); }
387"SMBProcessCall"            { count (0); return (PARSEOP_ACCESSATTRIB_WORD_CALL); }
388"SMBBlockProcessCall"       { count (0); return (PARSEOP_ACCESSATTRIB_BLOCK_CALL); }
389
390"MTR"                       { count (0); return (PARSEOP_MATCHTYPE_MTR); }
391"MEQ"                       { count (0); return (PARSEOP_MATCHTYPE_MEQ); }
392"MLE"                       { count (0); return (PARSEOP_MATCHTYPE_MLE); }
393"MLT"                       { count (0); return (PARSEOP_MATCHTYPE_MLT); }
394"MGE"                       { count (0); return (PARSEOP_MATCHTYPE_MGE); }
395"MGT"                       { count (0); return (PARSEOP_MATCHTYPE_MGT); }
396
397"Compatibility"             { count (0); return (PARSEOP_DMATYPE_COMPATIBILITY); }
398"TypeA"                     { count (0); return (PARSEOP_DMATYPE_A); }
399"TypeB"                     { count (0); return (PARSEOP_DMATYPE_B); }
400"TypeF"                     { count (0); return (PARSEOP_DMATYPE_F); }
401
402"BusMaster"                 { count (0); return (PARSEOP_BUSMASTERTYPE_MASTER); }
403"NotBusMaster"              { count (0); return (PARSEOP_BUSMASTERTYPE_NOTMASTER); }
404
405"Transfer8"                 { count (0); return (PARSEOP_XFERTYPE_8); }
406"Transfer8_16"              { count (0); return (PARSEOP_XFERTYPE_8_16); }
407"Transfer16"                { count (0); return (PARSEOP_XFERTYPE_16); }
408
409"ResourceConsumer"          { count (0); return (PARSEOP_RESOURCETYPE_CONSUMER); }
410"ResourceProducer"          { count (0); return (PARSEOP_RESOURCETYPE_PRODUCER); }
411
412"MinFixed"                  { count (0); return (PARSEOP_MINTYPE_FIXED); }
413"MinNotFixed"               { count (0); return (PARSEOP_MINTYPE_NOTFIXED); }
414
415"MaxFixed"                  { count (0); return (PARSEOP_MAXTYPE_FIXED); }
416"MaxNotFixed"               { count (0); return (PARSEOP_MAXTYPE_NOTFIXED); }
417
418"PosDecode"                 { count (0); return (PARSEOP_DECODETYPE_POS); }
419"SubDecode"                 { count (0); return (PARSEOP_DECODETYPE_SUB); }
420
421"ISAOnlyRanges"             { count (0); return (PARSEOP_RANGETYPE_ISAONLY); }
422"NonISAOnlyRanges"          { count (0); return (PARSEOP_RANGETYPE_NONISAONLY); }
423"EntireRange"               { count (0); return (PARSEOP_RANGETYPE_ENTIRE); }
424
425"Cacheable"                 { count (0); return (PARSEOP_MEMTYPE_CACHEABLE); }
426"WriteCombining"            { count (0); return (PARSEOP_MEMTYPE_WRITECOMBINING); }
427"Prefetchable"              { count (0); return (PARSEOP_MEMTYPE_PREFETCHABLE); }
428"NonCacheable"              { count (0); return (PARSEOP_MEMTYPE_NONCACHEABLE); }
429
430"ReadWrite"                 { count (0); return (PARSEOP_READWRITETYPE_BOTH); }
431"ReadOnly"                  { count (0); return (PARSEOP_READWRITETYPE_READONLY); }
432
433"Edge"                      { count (0); return (PARSEOP_INTTYPE_EDGE); }
434"Level"                     { count (0); return (PARSEOP_INTTYPE_LEVEL); }
435
436"ActiveHigh"                { count (0); return (PARSEOP_INTLEVEL_ACTIVEHIGH); }
437"ActiveLow"                 { count (0); return (PARSEOP_INTLEVEL_ACTIVELOW); }
438
439"Shared"                    { count (0); return (PARSEOP_SHARETYPE_SHARED); }
440"Exclusive"                 { count (0); return (PARSEOP_SHARETYPE_EXCLUSIVE); }
441
442"Decode10"                  { count (0); return (PARSEOP_IODECODETYPE_10); }
443"Decode16"                  { count (0); return (PARSEOP_IODECODETYPE_16); }
444
445"TypeTranslation"           { count (0); return (PARSEOP_TYPE_TRANSLATION); }
446"TypeStatic"                { count (0); return (PARSEOP_TYPE_STATIC); }
447
448"SparseTranslation"         { count (0); return (PARSEOP_TRANSLATIONTYPE_SPARSE); }
449"DenseTranslation"          { count (0); return (PARSEOP_TRANSLATIONTYPE_DENSE); }
450
451"AddressRangeMemory"        { count (0); return (PARSEOP_ADDRESSTYPE_MEMORY); }
452"AddressRangeReserved"      { count (0); return (PARSEOP_ADDRESSTYPE_RESERVED); }
453"AddressRangeNVS"           { count (0); return (PARSEOP_ADDRESSTYPE_NVS); }
454"AddressRangeACPI"          { count (0); return (PARSEOP_ADDRESSTYPE_ACPI); }
455
456
457"{"                         { count (0); return('{'); }
458"}"                         { count (0); return('}'); }
459","                         { count (0); return(','); }
460"("                         { count (0); return('('); }
461")"                         { count (0); return(')'); }
462
463
464{NameSeg}                   { char *s;
465                                count (0);
466                                s=malloc (ACPI_NAME_SIZE + 1);
467                                if (strcmp (AslCompilertext, "\\"))
468                                {
469                                    strcpy (s, "____");
470                                    ACPI_STRUPR (AslCompilertext);
471                                }
472                                memcpy (s, AslCompilertext, strlen (AslCompilertext));
473                                AslCompilerlval.s = s;
474                                DbgPrint (ASL_PARSE_OUTPUT, "NameSeg: %s\n", s);
475                                return (PARSEOP_NAMESEG); }
476
477{NameString}                { char *s;
478                                count (0);
479                                s=malloc (strlen (AslCompilertext)+1);
480                                ACPI_STRUPR (AslCompilertext);
481                                strcpy (s, AslCompilertext);
482                                s[strlen (AslCompilertext)] = 0;
483                                AslCompilerlval.s = s;
484                                DbgPrint (ASL_PARSE_OUTPUT, "NameString: %s\n", s);
485                                return (PARSEOP_NAMESTRING); }
486
487"*" |
488"/"                         { count (1);
489                                AslCompilererror ("Parse error, expecting ASL keyword or name");}
490
491.                           { count (1);
492                                sprintf (MsgBuffer,
493                                    "Invalid character (0x%2.2X), expecting ASL keyword or name",
494                                    *AslCompilertext);
495                                AslCompilererror (MsgBuffer);}
496
497<<EOF>>                     { if (AslPopInputFileStack ())
498                                yyterminate();
499                              else
500                                return (PARSEOP_INCLUDE_END);};
501
502%%
503
504/*! [End] no source code translation !*/
505
506typedef struct asl_file_node
507{
508    FILE                    *File;
509    UINT32                  CurrentLineNumber;
510    YY_BUFFER_STATE         State;
511    char                    *Filename;
512    struct asl_file_node    *Next;
513
514} ASL_FILE_NODE;
515
516ASL_FILE_NODE               *InputStack = NULL;
517
518
519/*******************************************************************************
520 *
521 * FUNCTION:    AslPopInputFileStack
522 *
523 * PARAMETERS:  None
524 *
525 * RETURN:      0 if a node was popped, -1 otherwise
526 *
527 * DESCRIPTION: Pop the top of the input file stack and point the parser to
528 *              the saved parse buffer contained in the fnode.  Also, set the
529 *              global line counters to the saved values.  This function is
530 *              called when an include file reaches EOF.
531 *
532 ******************************************************************************/
533
534int
535AslPopInputFileStack (
536    void)
537{
538    ASL_FILE_NODE           *Fnode;
539    FILE                    *InputFile = NULL;
540
541
542    Fnode = InputStack;
543    DbgPrint (ASL_PARSE_OUTPUT, "\nPop InputFile Stack, Fnode %p\n\n", Fnode);
544
545
546    if (!Fnode)
547    {
548        return -1;
549    }
550
551    /* Close the current include file */
552
553    fclose (yyin);
554
555    /* Update the top-of-stack */
556
557    InputStack = Fnode->Next;
558    InputFile = Fnode->File;
559
560    /* Reset global line counter and filename */
561
562    Gbl_Files[ASL_FILE_INPUT].Filename = Fnode->Filename;
563    Gbl_CurrentLineNumber = Fnode->CurrentLineNumber;
564
565    /* Point the parser to the popped file */
566
567    yy_delete_buffer (YY_CURRENT_BUFFER);
568    yy_switch_to_buffer (Fnode->State);
569
570    /* All done with this node */
571
572    ACPI_MEM_FREE (Fnode);
573    return 0;
574}
575
576
577/*******************************************************************************
578 *
579 * FUNCTION:    AslPushInputFileStack
580 *
581 * PARAMETERS:  InputFile           - Open file pointer
582 *              Filename            - Name of the file
583 *
584 * RETURN:      None
585 *
586 * DESCRIPTION: Push the InputFile onto the file stack, and point the parser
587 *              to this file.  Called when an include file is successfully
588 *              opened.
589 *
590 ******************************************************************************/
591
592void
593AslPushInputFileStack (
594    FILE                    *InputFile,
595    char                    *Filename)
596{
597    ASL_FILE_NODE           *Fnode;
598    YY_BUFFER_STATE         State;
599
600
601    /* Save the current state in an Fnode */
602
603    Fnode = UtLocalCalloc (sizeof (ASL_FILE_NODE));
604
605    Fnode->File                 = yyin;
606    Fnode->Next                 = InputStack;
607    Fnode->State                = YY_CURRENT_BUFFER;
608    Fnode->CurrentLineNumber    = Gbl_CurrentLineNumber;
609    Fnode->Filename             = Gbl_Files[ASL_FILE_INPUT].Filename;
610
611    /* Push it on the stack */
612
613    InputStack = Fnode;
614
615    /* Point the parser to this file */
616
617    State = yy_create_buffer (InputFile, YY_BUF_SIZE);
618    yy_switch_to_buffer (State);
619
620    DbgPrint (ASL_PARSE_OUTPUT, "\nPush InputFile Stack, returning %p\n\n", InputFile);
621
622    /* Reset the global line count and filename */
623
624    Gbl_Files[ASL_FILE_INPUT].Filename = Filename;
625    Gbl_CurrentLineNumber = 1;
626    yyin = InputFile;
627}
628
629
630/*******************************************************************************
631 *
632 * FUNCTION:    ResetCurrentLineBuffer
633 *
634 * PARAMETERS:  None
635 *
636 * RETURN:      None
637 *
638 * DESCRIPTION: Reset the Line Buffer to zero, increment global line numbers.
639 *
640 ******************************************************************************/
641
642void
643ResetCurrentLineBuffer (
644    void)
645{
646
647    if (Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Handle)
648    {
649        FlWriteFile (ASL_FILE_SOURCE_OUTPUT, Gbl_CurrentLineBuffer,
650            Gbl_LineBufPtr - Gbl_CurrentLineBuffer);
651    }
652
653    Gbl_CurrentLineOffset += Gbl_CurrentColumn;
654    Gbl_CurrentColumn = 0;
655
656    Gbl_CurrentLineNumber++;
657    Gbl_LogicalLineNumber++;
658    Gbl_LineBufPtr = Gbl_CurrentLineBuffer;
659}
660
661
662/*******************************************************************************
663 *
664 * FUNCTION:    InsertLineBuffer
665 *
666 * PARAMETERS:  SourceChar      - One char from the input ASL source file
667 *
668 * RETURN:      None
669 *
670 * DESCRIPTION: Put one character of the source file into the temp line buffer
671 *
672 ******************************************************************************/
673
674#define ASL_SPACES_PER_TAB  4
675
676void
677InsertLineBuffer (
678    int                     SourceChar)
679{
680    UINT32                  i;
681    UINT32                  Count = 1;
682
683
684    if (SourceChar == EOF)
685    {
686        return;
687    }
688
689    Gbl_InputByteCount++;
690
691    /* Handle tabs.  Convert to spaces */
692
693    if (SourceChar == '\t')
694    {
695        SourceChar = ' ';
696        Count = ASL_SPACES_PER_TAB -
697                    (Gbl_CurrentColumn & (ASL_SPACES_PER_TAB-1));
698    }
699
700
701    for (i = 0; i < Count; i++)
702    {
703        Gbl_CurrentColumn++;
704
705        /* Insert the character into the line buffer */
706
707        *Gbl_LineBufPtr = (UINT8) SourceChar;
708        Gbl_LineBufPtr++;
709
710        if (Gbl_LineBufPtr > (Gbl_CurrentLineBuffer + (ASL_LINE_BUFFER_SIZE - 1)))
711        {
712#if 0
713            /*
714             * Warning if we have split a long source line.
715             * <Probably overkill>
716             */
717            sprintf (MsgBuffer, "Max %d", ASL_LINE_BUFFER_SIZE);
718            AslCommonError (ASL_WARNING, ASL_MSG_LONG_LINE,
719                            Gbl_CurrentLineNumber, Gbl_LogicalLineNumber,
720                            Gbl_CurrentLineOffset, Gbl_CurrentColumn,
721                            Gbl_Files[ASL_FILE_INPUT].Filename, MsgBuffer);
722#endif
723
724            ResetCurrentLineBuffer ();
725        }
726        else if (SourceChar == '\n')
727        {
728            /* End of line */
729
730            ResetCurrentLineBuffer ();
731        }
732    }
733}
734
735
736/*******************************************************************************
737 *
738 * FUNCTION:    count
739 *
740 * PARAMETERS:  yytext      - Contains the matched keyword.
741 *              Type        - Keyword/Character type:
742 *                             0 = anything except a keyword
743 *                             1 = pseudo-keywords
744 *                             2 = non-executable ASL keywords
745 *                             3 = executable ASL keywords
746 *
747 * RETURN:      None
748 *
749 * DESCRIPTION: Count keywords and put them into the line buffer
750 *
751 ******************************************************************************/
752
753void
754count (
755    int                 Type)
756{
757    int                 i;
758
759
760    switch (Type)
761    {
762    case 2:
763        TotalKeywords++;
764        TotalNamedObjects++;
765        break;
766
767    case 3:
768        TotalKeywords++;
769        TotalExecutableOpcodes++;
770        break;
771    }
772
773    for (i = 0; (yytext[i] != 0) && (yytext[i] != EOF); i++)
774    {
775        InsertLineBuffer (yytext[i]);
776        *Gbl_LineBufPtr = 0;
777    }
778}
779
780
781/*******************************************************************************
782 *
783 * FUNCTION:    comment
784 *
785 * PARAMETERS:  none
786 *
787 * RETURN:      none
788 *
789 * DESCRIPTION: Process a standard comment.
790 *
791 ******************************************************************************/
792
793char
794comment (void)
795{
796    char                c;
797    char                c1 = 0;
798
799
800    InsertLineBuffer ('/');
801    InsertLineBuffer ('*');
802
803loop:
804
805    /* Eat chars until end-of-comment */
806
807    while ((c = (char) input()) != '*' && c != EOF)
808    {
809        InsertLineBuffer (c);
810        c1 = c;
811    }
812
813    if (c == EOF)
814    {
815        goto EarlyEOF;
816    }
817
818    /*
819     * Check for nested comment -- can help catch cases where a previous
820     * comment was accidently left unterminated
821     */
822    if ((c1 == '/') && (c == '*'))
823    {
824        AslCommonError (ASL_WARNING, ASL_MSG_NESTED_COMMENT,
825                        Gbl_CurrentLineNumber, Gbl_LogicalLineNumber,
826                        Gbl_InputByteCount, Gbl_CurrentColumn,
827                        Gbl_Files[ASL_FILE_INPUT].Filename, NULL);
828    }
829
830    /* Comment is closed only if the NEXT character is a slash */
831
832    InsertLineBuffer (c);
833
834    if ((c1 = (char) input()) != '/' && c1 != EOF)
835    {
836        unput(c1);
837        goto loop;
838    }
839
840    if (c1 == EOF)
841    {
842        goto EarlyEOF;
843    }
844
845    InsertLineBuffer (c1);
846    return TRUE;
847
848
849EarlyEOF:
850    /*
851     * Premature End-Of-File
852     */
853    AslCommonError (ASL_ERROR, ASL_MSG_EARLY_EOF,
854                    Gbl_CurrentLineNumber, Gbl_LogicalLineNumber,
855                    Gbl_CurrentLineOffset, Gbl_CurrentColumn,
856                    Gbl_Files[ASL_FILE_INPUT].Filename, NULL);
857    return (FALSE);
858}
859
860
861/*******************************************************************************
862 *
863 * FUNCTION:    comment
864 *
865 * PARAMETERS:  none
866 *
867 * RETURN:      none
868 *
869 * DESCRIPTION: Process a new "//" comment.
870 *
871 ******************************************************************************/
872
873char
874comment2 (void)
875{
876    char                c;
877
878
879    InsertLineBuffer ('/');
880    InsertLineBuffer ('/');
881
882    while ((c = (char) input()) != '\n' && c != EOF)
883    {
884        InsertLineBuffer (c);
885    }
886
887    if (c == EOF)
888    {
889        /*
890         * Premature End-Of-File
891         */
892        AslCommonError (ASL_ERROR, ASL_MSG_EARLY_EOF,
893                        Gbl_CurrentLineNumber, Gbl_LogicalLineNumber,
894                        Gbl_CurrentLineOffset, Gbl_CurrentColumn,
895                        Gbl_Files[ASL_FILE_INPUT].Filename, NULL);
896        return (FALSE);
897    }
898
899    InsertLineBuffer (c);
900    return (TRUE);
901}
902
903
904/*******************************************************************************
905 *
906 * FUNCTION:    literal
907 *
908 * PARAMETERS:  none
909 *
910 * RETURN:      none
911 *
912 * DESCRIPTION: Process a string literal (surrounded by quotes)
913 *
914 ******************************************************************************/
915
916#define ASL_NORMAL_CHAR         0
917#define ASL_ESCAPE_SEQUENCE     1
918#define ASL_OCTAL_CONSTANT      2
919#define ASL_HEX_CONSTANT        3
920
921char
922literal (void)
923{
924    char                *s = MsgBuffer;
925    char                *CleanString;
926    char                StringChar;
927    UINT32              State = ASL_NORMAL_CHAR;
928    UINT32              i = 0;
929    UINT8               Digit;
930    char                ConvertBuffer[4];
931
932
933    /*
934     * Eat chars until end-of-literal.
935     * NOTE:  Put back the original surrounding quotes into the
936     * source line buffer.
937     */
938    InsertLineBuffer ('\"');
939    while ((StringChar = (char) input()) != EOF)
940    {
941        InsertLineBuffer (StringChar);
942
943DoCharacter:
944
945        switch (State)
946        {
947        case ASL_NORMAL_CHAR:
948
949            switch (StringChar)
950            {
951            case '\\':
952                /*
953                 * Special handling for backslash-escape sequence.  We will
954                 * toss the backslash and translate the escape char(s).
955                 */
956                State = ASL_ESCAPE_SEQUENCE;
957                continue;
958
959            case '\"':
960
961                /* String terminator */
962
963                goto CompletedString;
964            }
965            break;
966
967
968        case ASL_ESCAPE_SEQUENCE:
969
970            State = ASL_NORMAL_CHAR;
971            switch (StringChar)
972            {
973            case 'a':
974                StringChar = 0x07;      /* BELL */
975                break;
976
977            case 'b':
978                StringChar = 0x08;      /* BACKSPACE */
979                break;
980
981            case 'f':
982                StringChar = 0x0C;      /* FORMFEED */
983                break;
984
985            case 'n':
986                StringChar = 0x0A;      /* LINEFEED */
987                break;
988
989            case 'r':
990                StringChar = 0x0D;      /* CARRIAGE RETURN*/
991                break;
992
993            case 't':
994                StringChar = 0x09;      /* HORIZONTAL TAB */
995                break;
996
997            case 'v':
998                StringChar = 0x0B;      /* VERTICAL TAB */
999                break;
1000
1001            case 'x':
1002                State = ASL_HEX_CONSTANT;
1003                i = 0;
1004                continue;
1005
1006            case '\'':                  /* Single Quote */
1007            case '\"':                  /* Double Quote */
1008            case '\\':                  /* Backslash */
1009                break;
1010
1011            default:
1012
1013                /* Check for an octal digit (0-7) */
1014
1015                if (ACPI_IS_OCTAL_DIGIT (StringChar))
1016                {
1017                    State = ASL_OCTAL_CONSTANT;
1018                    ConvertBuffer[0] = StringChar;
1019                    i = 1;
1020                    continue;
1021                }
1022
1023                /* Unknown escape sequence issue warning, but use the character */
1024
1025                AslCommonError (ASL_WARNING, ASL_MSG_INVALID_ESCAPE,
1026                                Gbl_CurrentLineNumber, Gbl_LogicalLineNumber,
1027                                Gbl_CurrentLineOffset, Gbl_CurrentColumn,
1028                                Gbl_Files[ASL_FILE_INPUT].Filename, NULL);
1029				break;
1030            }
1031            break;
1032
1033
1034        case ASL_OCTAL_CONSTANT:
1035
1036            /* Up to three octal digits allowed */
1037
1038            if (!ACPI_IS_OCTAL_DIGIT (StringChar) ||
1039                (i > 2))
1040            {
1041                /*
1042                 * Reached end of the constant.  Convert the assembled ASCII
1043                 * string and resume processing of the next character
1044                 */
1045                ConvertBuffer[i] = 0;
1046                Digit = (UINT8) ACPI_STRTOUL (ConvertBuffer, NULL, 8);
1047
1048                /* Check for NULL or non-ascii character (ignore if so) */
1049
1050                if ((Digit == 0) || (Digit > ACPI_ASCII_MAX))
1051                {
1052                    AslCommonError (ASL_WARNING, ASL_MSG_INVALID_STRING,
1053                                    Gbl_CurrentLineNumber, Gbl_LogicalLineNumber,
1054                                    Gbl_CurrentLineOffset, Gbl_CurrentColumn,
1055                                    Gbl_Files[ASL_FILE_INPUT].Filename, NULL);
1056                }
1057                else
1058                {
1059                    *s = (char) Digit;
1060                    s++;
1061                }
1062
1063                State = ASL_NORMAL_CHAR;
1064                goto DoCharacter;
1065                break;
1066            }
1067
1068            /* Append another digit of the constant */
1069
1070            ConvertBuffer[i] = StringChar;
1071            i++;
1072            continue;
1073
1074
1075        case ASL_HEX_CONSTANT:
1076
1077            /* Up to two hex digits allowed */
1078
1079            if (!ACPI_IS_XDIGIT (StringChar) ||
1080                (i > 1))
1081            {
1082                /*
1083                 * Reached end of the constant.  Convert the assembled ASCII
1084                 * string and resume processing of the next character
1085                 */
1086                ConvertBuffer[i] = 0;
1087                Digit = (UINT8) ACPI_STRTOUL (ConvertBuffer, NULL, 16);
1088
1089                /* Check for NULL or non-ascii character (ignore if so) */
1090
1091                if ((Digit == 0) || (Digit > ACPI_ASCII_MAX))
1092                {
1093                    AslCommonError (ASL_WARNING, ASL_MSG_INVALID_STRING,
1094                                    Gbl_CurrentLineNumber, Gbl_LogicalLineNumber,
1095                                    Gbl_CurrentLineOffset, Gbl_CurrentColumn,
1096                                    Gbl_Files[ASL_FILE_INPUT].Filename, NULL);
1097                }
1098                else
1099                {
1100                    *s = (char) Digit;
1101                    s++;
1102                }
1103
1104                State = ASL_NORMAL_CHAR;
1105                goto DoCharacter;
1106                break;
1107            }
1108
1109            /* Append another digit of the constant */
1110
1111            ConvertBuffer[i] = StringChar;
1112            i++;
1113            continue;
1114        }
1115
1116        /* Save the finished character */
1117
1118        *s = StringChar;
1119        s++;
1120    }
1121
1122    /*
1123     * Premature End-Of-File
1124     */
1125    AslCommonError (ASL_ERROR, ASL_MSG_EARLY_EOF,
1126                    Gbl_CurrentLineNumber, Gbl_LogicalLineNumber,
1127                    Gbl_CurrentLineOffset, Gbl_CurrentColumn,
1128                    Gbl_Files[ASL_FILE_INPUT].Filename, NULL);
1129    return (FALSE);
1130
1131
1132CompletedString:
1133    /*
1134     * Null terminate the input string and copy string to a new buffer
1135     */
1136    *s = 0;
1137
1138    CleanString = UtGetStringBuffer (strlen (MsgBuffer) + 1);
1139    if (!CleanString)
1140    {
1141        AslCommonError (ASL_ERROR, ASL_MSG_MEMORY_ALLOCATION,
1142                        Gbl_CurrentLineNumber, Gbl_LogicalLineNumber,
1143                        Gbl_CurrentLineOffset, Gbl_CurrentColumn,
1144                        Gbl_Files[ASL_FILE_INPUT].Filename, NULL);
1145        return (FALSE);
1146    }
1147
1148    ACPI_STRCPY (CleanString, MsgBuffer);
1149    AslCompilerlval.s = CleanString;
1150    return (TRUE);
1151}
1152
1153
1154