summaryrefslogtreecommitdiff
path: root/source/compiler
diff options
context:
space:
mode:
authorRobert Moore <Robert.Moore@intel.com>2012-03-28 14:18:42 -0700
committerRobert Moore <Robert.Moore@intel.com>2012-03-28 14:18:42 -0700
commit35f1292815ca3c315222ebac0c91c2bf0e495eee (patch)
treebdd9af568c6203cf1b75dee94c14f8eb451d72ec /source/compiler
parentb95bbfbb76da28dba54fd7120a71c1ee34388dad (diff)
iASL: Implement #line directive in compiler lexer.
Move main compiler support for #line from the parser to the lexer. This simplifies the implementation, and allows #line to appear within any ASL statement (the entire line where #line appears is simply removed from the input after the new line number is set.)
Diffstat (limited to 'source/compiler')
-rw-r--r--source/compiler/aslcompiler.h4
-rw-r--r--source/compiler/aslcompiler.l76
-rw-r--r--source/compiler/aslcompiler.y29
-rw-r--r--source/compiler/aslfiles.c14
-rw-r--r--source/compiler/prscan.c27
5 files changed, 110 insertions, 40 deletions
diff --git a/source/compiler/aslcompiler.h b/source/compiler/aslcompiler.h
index ddcab1f71..7ab276c51 100644
--- a/source/compiler/aslcompiler.h
+++ b/source/compiler/aslcompiler.h
@@ -717,11 +717,11 @@ FlPrintFile (
void
FlSetLineNumber (
- ACPI_PARSE_OBJECT *Op);
+ UINT32 LineNumber);
void
FlSetFilename (
- ACPI_PARSE_OBJECT *Op);
+ char *Filename);
ACPI_STATUS
FlOpenInputFile (
diff --git a/source/compiler/aslcompiler.l b/source/compiler/aslcompiler.l
index f70c98fef..824edf42d 100644
--- a/source/compiler/aslcompiler.l
+++ b/source/compiler/aslcompiler.l
@@ -134,6 +134,8 @@ YYSTYPE AslCompilerlval;
/* Local prototypes */
+void
+AslDoLineDirective (char *Line);
char
comment (void);
char
@@ -189,7 +191,7 @@ NamePathTail [.]{NameSeg}
"Include" { count (1); return (PARSEOP_INCLUDE); }
"#include" { count (1); return (PARSEOP_INCLUDE_CSTYLE); }
-"#line" { count (1); return (PARSEOP_LINE_CSTYLE); }
+"#line" { count (1); AslDoLineDirective ((char *) AslCompilertext);}
"External" { count (1); return (PARSEOP_EXTERNAL); }
/****************************************************************************
@@ -721,6 +723,76 @@ ASL_FILE_NODE *InputStack = NULL;
/*******************************************************************************
*
+ * FUNCTION: AslDoLineDirective
+ *
+ * PARAMETERS: Line - Current input line
+ *
+ * RETURN: Updates global line number and filename
+ *
+ * DESCRIPTION: Handle #line directives emitted by the preprocessor.
+ *
+ * The #line directive is emitted by the preprocesser, and is used to
+ * pass through line numbers from the original source code file to the
+ * preprocessor output file (.i). This allows any compiler-generated
+ * error messages to be displayed with the correct line number.
+ *
+ ******************************************************************************/
+
+void
+AslDoLineDirective (
+ char *Line)
+{
+ char c;
+ char *Token;
+ UINT32 LineNumber;
+ char *Filename;
+
+
+ /* Eat the entire line that contains the #line directive */
+
+ ResetCurrentLineBuffer ();
+ while ((c = (char) input()) != '\n' && c != EOF)
+ {
+ InsertLineBuffer (c);
+ }
+ InsertLineBuffer (0);
+
+ /* First argument is the actual line number */
+
+ Token = strtok (Gbl_CurrentLineBuffer, " ");
+ if (!Token)
+ {
+ goto ResetAndExit;
+ }
+
+ /* Convert line number. (-1) to handle _this_ line */
+
+ LineNumber = (UINT32) UtDoConstant (Token);
+ LineNumber--;
+ FlSetLineNumber (LineNumber);
+ printf ("#line %6s %6u", Token, LineNumber);
+
+ /* Second argument is the optional filename */
+
+ Token = strtok (NULL, " \"");
+ if (Token)
+ {
+ printf (" Filename: %s", Token);
+ Filename = ACPI_ALLOCATE_ZEROED (strlen (Token) + 1);
+ strcpy (Filename, Token);
+ FlSetFilename (Filename);
+ }
+
+ /* Third argument is not supported */
+
+ResetAndExit:
+ printf ("\n");
+ ResetCurrentLineBuffer ();
+}
+
+
+/*******************************************************************************
+ *
* FUNCTION: AslPopInputFileStack
*
* PARAMETERS: None
@@ -1223,7 +1295,7 @@ DoCharacter:
Gbl_CurrentLineNumber, Gbl_LogicalLineNumber,
Gbl_CurrentLineOffset, Gbl_CurrentColumn,
Gbl_Files[ASL_FILE_INPUT].Filename, NULL);
- break;
+ break;
}
break;
diff --git a/source/compiler/aslcompiler.y b/source/compiler/aslcompiler.y
index 3f844e54e..8bc42141b 100644
--- a/source/compiler/aslcompiler.y
+++ b/source/compiler/aslcompiler.y
@@ -182,7 +182,7 @@ void * AslLocalAllocate (unsigned int Size);
* These shift/reduce conflicts are expected. There should be zero
* reduce/reduce conflicts.
*/
-%expect 87
+%expect 86
/******************************************************************************
*
@@ -578,7 +578,6 @@ void * AslLocalAllocate (unsigned int Size);
%type <n> FieldUnitList
%type <n> IncludeCStyleTerm
%type <n> IncludeTerm
-%type <n> LineTerm
%type <n> OffsetTerm
%type <n> OptionalAccessAttribTerm
@@ -832,7 +831,6 @@ void * AslLocalAllocate (unsigned int Size);
%type <n> OptionalEndian
%type <n> OptionalFlowControl
%type <n> OptionalIoRestriction
-%type <n> OptionalLineList
%type <n> OptionalListString
%type <n> OptionalMaxType
%type <n> OptionalMemType
@@ -882,17 +880,10 @@ void * AslLocalAllocate (unsigned int Size);
* to handle output from preprocessors
*/
ASLCode
- : OptionalLineList DefinitionBlockTerm
+ : DefinitionBlockTerm
| error {YYABORT; $$ = NULL;}
;
-OptionalLineList
- : {$$ = NULL;}
- | LineTerm
- | OptionalLineList LineTerm
- ;
-
-
/*
* Blocks, Data, and Opcodes
*/
@@ -948,7 +939,6 @@ Term
CompilerDirective
: IncludeTerm {}
| IncludeCStyleTerm {$$ = NULL;}
- | LineTerm {$$ = NULL;}
| ExternalTerm {}
;
@@ -1247,21 +1237,6 @@ IncludeCStyleTerm
String {FlOpenIncludeFile ($2);}
;
-/*
- * The #line directive is emitted by the preprocesser, and is used to
- * pass through line numbers from the original source code file to the
- * preprocessor output file (.i). This allows any compiler-generated
- * error messages to be displayed with the correct line number.
- */
-LineTerm
- : PARSEOP_LINE_CSTYLE
- Integer {FlSetLineNumber ($2);}
- | PARSEOP_LINE_CSTYLE
- Integer String {FlSetLineNumber ($2); FlSetFilename ($3);}
- | PARSEOP_LINE_CSTYLE
- Integer String Integer {FlSetLineNumber ($2); FlSetFilename ($3);}
- ;
-
ExternalTerm
: PARSEOP_EXTERNAL '('
NameString
diff --git a/source/compiler/aslfiles.c b/source/compiler/aslfiles.c
index 1bc7ad25a..00fdff208 100644
--- a/source/compiler/aslfiles.c
+++ b/source/compiler/aslfiles.c
@@ -460,14 +460,14 @@ FlCloseFile (
void
FlSetLineNumber (
- ACPI_PARSE_OBJECT *Op)
+ UINT32 LineNumber)
{
DbgPrint (ASL_PARSE_OUTPUT, "\n#line: New line number %u (old %u)\n",
- (UINT32) Op->Asl.Value.Integer, Gbl_LogicalLineNumber);
+ LineNumber, Gbl_LogicalLineNumber);
- Gbl_CurrentLineNumber = (UINT32) Op->Asl.Value.Integer;
- Gbl_LogicalLineNumber = (UINT32) Op->Asl.Value.Integer;
+ Gbl_CurrentLineNumber = LineNumber;
+ Gbl_LogicalLineNumber = LineNumber;
}
@@ -485,13 +485,13 @@ FlSetLineNumber (
void
FlSetFilename (
- ACPI_PARSE_OBJECT *Op)
+ char *Filename)
{
DbgPrint (ASL_PARSE_OUTPUT, "\n#line: New filename %s (old %s)\n",
- Op->Asl.Value.String, Gbl_Files[ASL_FILE_INPUT].Filename);
+ Filename, Gbl_Files[ASL_FILE_INPUT].Filename);
- Gbl_Files[ASL_FILE_INPUT].Filename = Op->Asl.Value.String;
+ Gbl_Files[ASL_FILE_INPUT].Filename = Filename;
}
diff --git a/source/compiler/prscan.c b/source/compiler/prscan.c
index 5c8ca199a..e98e18603 100644
--- a/source/compiler/prscan.c
+++ b/source/compiler/prscan.c
@@ -732,6 +732,31 @@ PrDoDirective (
PrOpenIncludeFile (Token);
break;
+ case PR_DIRECTIVE_LINE:
+ TokenOffset = Token - Gbl_MainTokenBuffer;
+
+ Status = PrResolveIntegerExpression (
+ &Gbl_CurrentLineBuffer[TokenOffset-1], &Value);
+ if (ACPI_FAILURE (Status))
+ {
+ return;
+ }
+
+ DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID
+ "User #line invocation %s\n", Gbl_CurrentLineNumber,
+ Token);
+
+ /* Update local line numbers */
+
+ Gbl_CurrentLineNumber = (UINT32) Value;
+ Gbl_PreviousLineNumber = 0;
+
+ /* Emit #line into the preprocessor file */
+
+ FlPrintFile (ASL_FILE_PREPROCESSOR, "#line %u \"%s\"\n",
+ Gbl_CurrentLineNumber, Gbl_Files[ASL_FILE_INPUT].Filename);
+ break;
+
case PR_DIRECTIVE_PRAGMA:
/* Only "#pragma message" supported at this time */
@@ -764,8 +789,6 @@ PrDoDirective (
THIS_TOKEN_OFFSET (Token));
break;
- case PR_DIRECTIVE_LINE:
- /* TBD: set line number -- or, do this in main compiler */
default:
/* Should never get here */
DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID