mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-25 12:32:07 +00:00
Add support for including files in linkerscript
Files can now be included with the following syntax:
INCLUDE "path.link"
The maximum include depth is 5.
Fixed linkerscript parser and lexer error messages so that they are more
informative (show file and line of the error).
Man page updated.
Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
This commit is contained in:
@@ -23,7 +23,7 @@
|
||||
int yylex();
|
||||
void yyerror(char *);
|
||||
|
||||
static int nline = 1;
|
||||
extern int yylineno;
|
||||
%}
|
||||
|
||||
%union { int i; char s[512]; }
|
||||
@@ -37,6 +37,8 @@ static int nline = 1;
|
||||
%token COMMAND_ALIGN
|
||||
%token COMMAND_ORG
|
||||
|
||||
%token COMMAND_INCLUDE
|
||||
|
||||
%token NEWLINE
|
||||
|
||||
%start lines
|
||||
@@ -49,8 +51,8 @@ lines:
|
||||
;
|
||||
|
||||
line:
|
||||
/* empty */ { nline++; }
|
||||
| statement { nline++; }
|
||||
/* empty */
|
||||
| statement
|
||||
;
|
||||
|
||||
statement:
|
||||
@@ -59,11 +61,11 @@ statement:
|
||||
script_SetCurrentSectionType($1, 0);
|
||||
}
|
||||
| SECTION_NONBANKED INTEGER {
|
||||
errx(1, "%d:Trying to assign a bank to a non-banked section.\n", nline);
|
||||
script_fatalerror("Trying to assign a bank to a non-banked section.\n");
|
||||
}
|
||||
|
||||
| SECTION_BANKED {
|
||||
errx(1, "%d:Banked section without assigned bank.\n", nline);
|
||||
script_fatalerror("Banked section without assigned bank.\n");
|
||||
}
|
||||
| SECTION_BANKED INTEGER {
|
||||
script_SetCurrentSectionType($1, $2);
|
||||
@@ -74,13 +76,13 @@ statement:
|
||||
script_SetAlignment($2);
|
||||
}
|
||||
| COMMAND_ALIGN {
|
||||
errx(1, "%d:ALIGN keyword needs an argument.\n", nline);
|
||||
script_fatalerror("ALIGN keyword needs an argument.\n");
|
||||
}
|
||||
| COMMAND_ORG INTEGER {
|
||||
script_SetAddress($2);
|
||||
}
|
||||
| COMMAND_ORG {
|
||||
errx(1, "%d:ORG keyword needs an argument.\n", nline);
|
||||
script_fatalerror("ORG keyword needs an argument.\n");
|
||||
}
|
||||
|
||||
/* Section name */
|
||||
@@ -88,6 +90,11 @@ statement:
|
||||
script_OutputSection($1);
|
||||
}
|
||||
|
||||
/* Include file */
|
||||
| COMMAND_INCLUDE STRING {
|
||||
script_IncludeFile($2);
|
||||
}
|
||||
|
||||
/* End */
|
||||
;
|
||||
|
||||
@@ -96,33 +103,18 @@ statement:
|
||||
extern int yylex();
|
||||
extern int yyparse();
|
||||
|
||||
extern FILE *yyin;
|
||||
|
||||
int yywrap (void)
|
||||
int yywrap(void)
|
||||
{
|
||||
return 1;
|
||||
if (script_IncludeDepthGet() == 0)
|
||||
return 1;
|
||||
|
||||
script_IncludePop();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void yyerror(char *s)
|
||||
{
|
||||
errx(1, "%d:Linkerscript parse error: \"%s\"\n", nline, s);
|
||||
}
|
||||
|
||||
void script_Parse(const char *path)
|
||||
{
|
||||
script_InitSections();
|
||||
|
||||
FILE *f = fopen(path, "r");
|
||||
|
||||
if (!f)
|
||||
errx(1, "Error opening file! \"%s\"\n", path);
|
||||
|
||||
yyin = f;
|
||||
|
||||
do {
|
||||
yyparse();
|
||||
} while (!feof(yyin));
|
||||
|
||||
fclose(f);
|
||||
script_fatalerror("Linkerscript parse error: \"%s\"\n", s);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user