mirror of
https://gitlab.com/qemu-project/openbios.git
synced 2024-02-13 08:34:06 +08:00
Add source file and line number tracking to forthstrap to allow the user to locate forth errors much more easily. An example of the new output is given below:
build@zeno:~/src/openbios/openbios-devel.pre$ ./config/scripts/switch-arch cross-ppc; make Configuring OpenBIOS on amd64 for cross-ppc Initializing build tree obj-ppc...ok. Creating target Makefile...ok. Creating config files...ok. Building OpenBIOS for ppc Building...error: HOSTCC host/kernel/stack.o HOSTCC forthstrap GEN bootstrap.dict bootstrap.fs:339 - foo is not defined. git-svn-id: svn://coreboot.org/openbios/trunk/openbios-devel@704 f158a5a8-5612-0410-a976-696ce0be7e32
This commit is contained in:
@@ -29,6 +29,7 @@
|
|||||||
#include "cross.h"
|
#include "cross.h"
|
||||||
#include "openbios-version.h"
|
#include "openbios-version.h"
|
||||||
|
|
||||||
|
#define MAX_PATH_LEN 256
|
||||||
|
|
||||||
#define MEMORY_SIZE (1024*1024) /* 1M ram for hosted system */
|
#define MEMORY_SIZE (1024*1024) /* 1M ram for hosted system */
|
||||||
#define DICTIONARY_SIZE (256*1024) /* 256k for the dictionary */
|
#define DICTIONARY_SIZE (256*1024) /* 256k for the dictionary */
|
||||||
@@ -44,7 +45,11 @@ static int errors = 0;
|
|||||||
static int segfault = 0;
|
static int segfault = 0;
|
||||||
static int verbose = 0;
|
static int verbose = 0;
|
||||||
|
|
||||||
static FILE *srcfiles[128];
|
#define MAX_SRC_FILES 128
|
||||||
|
|
||||||
|
static FILE *srcfiles[MAX_SRC_FILES];
|
||||||
|
static char *srcfilenames[MAX_SRC_FILES];
|
||||||
|
static int srclines[MAX_SRC_FILES];
|
||||||
static unsigned int cursrc = 0;
|
static unsigned int cursrc = 0;
|
||||||
|
|
||||||
#ifdef NATIVE_BITWIDTH_SMALLER_THAN_HOST_BITWIDTH
|
#ifdef NATIVE_BITWIDTH_SMALLER_THAN_HOST_BITWIDTH
|
||||||
@@ -292,9 +297,14 @@ static void skipws(FILE * f)
|
|||||||
while (!feof(f)) {
|
while (!feof(f)) {
|
||||||
c = getc(f);
|
c = getc(f);
|
||||||
|
|
||||||
if (c == ' ' || c == '\t' || c == '\n')
|
if (c == ' ' || c == '\t')
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
if (c == '\n') {
|
||||||
|
srclines[cursrc - 1]++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
ungetc(c, f);
|
ungetc(c, f);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -309,7 +319,7 @@ static void skipws(FILE * f)
|
|||||||
|
|
||||||
static int parse(FILE * f, char *line, char delim)
|
static int parse(FILE * f, char *line, char delim)
|
||||||
{
|
{
|
||||||
int cnt = 0, c;
|
int cnt = 0, c = 0;
|
||||||
|
|
||||||
while (!feof(f)) {
|
while (!feof(f)) {
|
||||||
c = getc(f);
|
c = getc(f);
|
||||||
@@ -317,12 +327,17 @@ static int parse(FILE * f, char *line, char delim)
|
|||||||
if (delim && c == delim)
|
if (delim && c == delim)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if ((!delim) && (c == ' ' || c == '\n' || c == '\t'))
|
if ((!delim) && (c == ' ' || c == '\t' || c == '\n'))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
line[cnt++] = c;
|
line[cnt++] = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Update current line number */
|
||||||
|
if (c == '\n') {
|
||||||
|
srclines[cursrc - 1]++;
|
||||||
|
}
|
||||||
|
|
||||||
line[cnt] = 0;
|
line[cnt] = 0;
|
||||||
|
|
||||||
return cnt;
|
return cnt;
|
||||||
@@ -442,21 +457,33 @@ static void add_includepath(char *path)
|
|||||||
|
|
||||||
static FILE *fopen_include(const char *fil)
|
static FILE *fopen_include(const char *fil)
|
||||||
{
|
{
|
||||||
#define MAX_PATH_LEN 256
|
|
||||||
char fullpath[MAX_PATH_LEN];
|
char fullpath[MAX_PATH_LEN];
|
||||||
FILE *ret;
|
FILE *ret;
|
||||||
include *incl = &includes;
|
include *incl = &includes;
|
||||||
|
|
||||||
while (incl) {
|
while (incl) {
|
||||||
snprintf(fullpath, sizeof(fullpath), "%s/%s", incl->path, fil);
|
snprintf(fullpath, sizeof(fullpath), "%s/%s", incl->path, fil);
|
||||||
|
|
||||||
ret = fopen(fullpath, "r");
|
ret = fopen(fullpath, "r");
|
||||||
if (ret != NULL)
|
if (ret != NULL) {
|
||||||
|
|
||||||
|
#ifdef CONFIG_DEBUG_INTERPRETER
|
||||||
|
printk("Including '%s'\n", name );
|
||||||
|
#endif
|
||||||
|
srcfilenames [ cursrc ] = malloc(strlen(fil) + 1);
|
||||||
|
strcpy(srcfilenames[ cursrc ], fil);
|
||||||
|
srclines [ cursrc ] = 1;
|
||||||
|
srcfiles [ cursrc++ ] = ret;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
incl = incl->next;
|
incl = incl->next;
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This is the C version of the forth interpreter
|
* This is the C version of the forth interpreter
|
||||||
*/
|
*/
|
||||||
@@ -658,7 +685,7 @@ static int interpret_source(char *fil)
|
|||||||
|
|
||||||
if (*test != 0) {
|
if (*test != 0) {
|
||||||
/* what is it?? */
|
/* what is it?? */
|
||||||
printk("%s is not defined.\n\n", tib);
|
printk("%s:%d - %s is not defined.\n\n", srcfilenames[cursrc - 1], srclines[cursrc - 1], tib);
|
||||||
errors++;
|
errors++;
|
||||||
#ifdef CONFIG_DEBUG_INTERPRETER
|
#ifdef CONFIG_DEBUG_INTERPRETER
|
||||||
continue;
|
continue;
|
||||||
@@ -680,7 +707,9 @@ static int interpret_source(char *fil)
|
|||||||
writecell(num);
|
writecell(num);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
cursrc--;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -753,7 +782,8 @@ int availchar(void)
|
|||||||
ungetc(tmp, srcfiles[cursrc-1]);
|
ungetc(tmp, srcfiles[cursrc-1]);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
fclose( srcfiles[--cursrc] );
|
|
||||||
|
fclose(srcfiles[--cursrc]);
|
||||||
|
|
||||||
return availchar();
|
return availchar();
|
||||||
}
|
}
|
||||||
@@ -770,7 +800,8 @@ int get_inputbyte( void )
|
|||||||
tmp = getc( srcfiles[cursrc-1] );
|
tmp = getc( srcfiles[cursrc-1] );
|
||||||
if (tmp != EOF)
|
if (tmp != EOF)
|
||||||
return tmp;
|
return tmp;
|
||||||
fclose( srcfiles[--cursrc] );
|
|
||||||
|
fclose(srcfiles[--cursrc]);
|
||||||
|
|
||||||
return get_inputbyte();
|
return get_inputbyte();
|
||||||
}
|
}
|
||||||
@@ -833,12 +864,14 @@ static void init_memory(void)
|
|||||||
|
|
||||||
void exception(cell no)
|
void exception(cell no)
|
||||||
{
|
{
|
||||||
|
printk("%s:%d: ", srcfilenames[cursrc - 1], srclines[cursrc - 1]);
|
||||||
|
|
||||||
switch (no) {
|
switch (no) {
|
||||||
case -19:
|
case -19:
|
||||||
printk(" undefined word.\n");
|
printk(" undefined word.\n");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
printk("\nError %" FMT_CELL_d " occured.\n", no);
|
printk("error %" FMT_CELL_d " occured.\n", no);
|
||||||
}
|
}
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@@ -847,21 +880,21 @@ void exception(cell no)
|
|||||||
void
|
void
|
||||||
include_file( const char *name )
|
include_file( const char *name )
|
||||||
{
|
{
|
||||||
FILE *file = fopen_include( name );
|
FILE *file;
|
||||||
if( !file ) {
|
|
||||||
printk("\npanic: Failed opening '%s'\n", name );
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
if( cursrc >= sizeof(srcfiles)/sizeof(srcfiles[0]) ) {
|
if( cursrc >= sizeof(srcfiles)/sizeof(srcfiles[0]) ) {
|
||||||
printk("\npanic: Maximum include depth reached!\n");
|
printk("\npanic: Maximum include depth reached!\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
#ifdef CONFIG_DEBUG_INTERPRETER
|
|
||||||
printk("Including '%s'\n", name );
|
file = fopen_include( name );
|
||||||
#endif
|
if( !file ) {
|
||||||
srcfiles[ cursrc++ ] = file;
|
printk("\npanic: Failed opening file '%s'\n", name );
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
encode_file( const char *name )
|
encode_file( const char *name )
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user