Add global filename variable and handling for a filename passed on the

command line (no real command-line parsing yet).

svn path=/trunk/yasm/; revision=130
0.3
Peter Johnson 24 years ago
parent 1fa31332b6
commit 50cd4f238f
  1. 24
      frontends/yasm/yasm.c
  2. 5
      libyasm/bytecode.c
  3. 10
      libyasm/errwarn.c
  4. 5
      libyasm/errwarn.h
  5. 3
      libyasm/linemgr.h
  6. 5
      src/bytecode.c
  7. 10
      src/errwarn.c
  8. 5
      src/errwarn.h
  9. 3
      src/globals.h
  10. 3
      src/linemgr.h
  11. 24
      src/main.c

@ -1,4 +1,4 @@
/* $Id: yasm.c,v 1.4 2001/07/11 23:16:50 peter Exp $
/* $Id: yasm.c,v 1.5 2001/08/18 22:15:12 peter Exp $
* Program entry point, command line parsing
*
* Copyright (C) 2001 Peter Johnson
@ -21,19 +21,39 @@
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
extern int yydebug;
extern FILE *yyin;
extern int yyparse(void);
char *filename = (char *)NULL;
unsigned int line_number = 1;
unsigned int mode_bits = 32;
int
main (void)
main (int argc, char *argv[])
{
FILE *in;
yydebug = 1;
if(argc==2) {
in = fopen(argv[1], "rt");
if(!in) {
fprintf(stderr, "could not open file `%s'\n", argv[1]);
return EXIT_FAILURE;
}
filename = strdup(argv[1]);
yyin = in;
} else
filename = strdup("<UNKNOWN>");
yyparse();
if(filename)
free(filename);
return EXIT_SUCCESS;
}

@ -1,4 +1,4 @@
/* $Id: bytecode.c,v 1.14 2001/07/25 00:33:10 peter Exp $
/* $Id: bytecode.c,v 1.15 2001/08/18 22:15:12 peter Exp $
* Bytecode utility functions
*
* Copyright (C) 2001 Peter Johnson
@ -21,6 +21,7 @@
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "globals.h"
#include "bytecode.h"
#include "errwarn.h"
@ -232,7 +233,7 @@ BuildBC_Common (bytecode *bc)
{
bc->len = 0;
bc->filename = (char *)NULL;
bc->filename = strdup(filename);
bc->lineno = line_number;
bc->offset = 0;

@ -1,4 +1,4 @@
/* $Id: errwarn.c,v 1.17 2001/07/25 00:33:10 peter Exp $
/* $Id: errwarn.c,v 1.18 2001/08/18 22:15:12 peter Exp $
* Error and warning reporting and related functions.
*
* Copyright (C) 2001 Peter Johnson
@ -72,7 +72,8 @@ static char *err_msgs[] = {
"unexpected end of file in string",
"expression syntax error",
"floating-point constant encountered in `%s'",
"non-floating-point value encountered in `%s'"
"non-floating-point value encountered in `%s'",
"could not open file `%s'"
};
/* Warning messages. Match up with warn_num enum in errwarn.h. */
@ -275,7 +276,7 @@ void
OutputError (void)
{
if(last_err_num != ERR_NONE)
fprintf(stderr, "filename:%u: %s\n", line_number, last_err);
fprintf(stderr, "%s:%u: %s\n", filename, line_number, last_err);
last_err_num = ERR_NONE;
}
@ -284,7 +285,8 @@ void
OutputWarning (void)
{
if(last_warn_num != WARN_NONE)
fprintf(stderr, "filename:%u: warning: %s\n", line_number, last_warn);
fprintf(stderr, "%s:%u: warning: %s\n", filename, line_number,
last_warn);
last_warn_num = WARN_NONE;
}

@ -1,4 +1,4 @@
/* $Id: errwarn.h,v 1.11 2001/07/25 00:33:10 peter Exp $
/* $Id: errwarn.h,v 1.12 2001/08/18 22:15:12 peter Exp $
* Error and warning reporting and related functions header file.
*
* Copyright (C) 2001 Peter Johnson
@ -50,7 +50,8 @@ typedef enum {
ERR_STRING_EOF,
ERR_EXPR_SYNTAX,
ERR_DECLDATA_FLOAT,
ERR_DECLDATA_EXPR
ERR_DECLDATA_EXPR,
ERR_FILE_OPEN
} err_num;
/* Warning constants. Match up with warn_msgs in errwarn.c. */

@ -1,4 +1,4 @@
/* $Id: linemgr.h,v 1.3 2001/06/28 21:22:01 peter Exp $
/* $Id: linemgr.h,v 1.4 2001/08/18 22:15:12 peter Exp $
* Globals header file
*
* Copyright (C) 2001 Peter Johnson
@ -22,6 +22,7 @@
#ifndef YASM_GLOBALS_H
#define YASM_GLOBALS_H
extern char *filename;
extern unsigned int line_number;
extern unsigned int mode_bits;
extern struct symrec_s *locallabel_base;

@ -1,4 +1,4 @@
/* $Id: bytecode.c,v 1.14 2001/07/25 00:33:10 peter Exp $
/* $Id: bytecode.c,v 1.15 2001/08/18 22:15:12 peter Exp $
* Bytecode utility functions
*
* Copyright (C) 2001 Peter Johnson
@ -21,6 +21,7 @@
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "globals.h"
#include "bytecode.h"
#include "errwarn.h"
@ -232,7 +233,7 @@ BuildBC_Common (bytecode *bc)
{
bc->len = 0;
bc->filename = (char *)NULL;
bc->filename = strdup(filename);
bc->lineno = line_number;
bc->offset = 0;

@ -1,4 +1,4 @@
/* $Id: errwarn.c,v 1.17 2001/07/25 00:33:10 peter Exp $
/* $Id: errwarn.c,v 1.18 2001/08/18 22:15:12 peter Exp $
* Error and warning reporting and related functions.
*
* Copyright (C) 2001 Peter Johnson
@ -72,7 +72,8 @@ static char *err_msgs[] = {
"unexpected end of file in string",
"expression syntax error",
"floating-point constant encountered in `%s'",
"non-floating-point value encountered in `%s'"
"non-floating-point value encountered in `%s'",
"could not open file `%s'"
};
/* Warning messages. Match up with warn_num enum in errwarn.h. */
@ -275,7 +276,7 @@ void
OutputError (void)
{
if(last_err_num != ERR_NONE)
fprintf(stderr, "filename:%u: %s\n", line_number, last_err);
fprintf(stderr, "%s:%u: %s\n", filename, line_number, last_err);
last_err_num = ERR_NONE;
}
@ -284,7 +285,8 @@ void
OutputWarning (void)
{
if(last_warn_num != WARN_NONE)
fprintf(stderr, "filename:%u: warning: %s\n", line_number, last_warn);
fprintf(stderr, "%s:%u: warning: %s\n", filename, line_number,
last_warn);
last_warn_num = WARN_NONE;
}

@ -1,4 +1,4 @@
/* $Id: errwarn.h,v 1.11 2001/07/25 00:33:10 peter Exp $
/* $Id: errwarn.h,v 1.12 2001/08/18 22:15:12 peter Exp $
* Error and warning reporting and related functions header file.
*
* Copyright (C) 2001 Peter Johnson
@ -50,7 +50,8 @@ typedef enum {
ERR_STRING_EOF,
ERR_EXPR_SYNTAX,
ERR_DECLDATA_FLOAT,
ERR_DECLDATA_EXPR
ERR_DECLDATA_EXPR,
ERR_FILE_OPEN
} err_num;
/* Warning constants. Match up with warn_msgs in errwarn.c. */

@ -1,4 +1,4 @@
/* $Id: globals.h,v 1.3 2001/06/28 21:22:01 peter Exp $
/* $Id: globals.h,v 1.4 2001/08/18 22:15:12 peter Exp $
* Globals header file
*
* Copyright (C) 2001 Peter Johnson
@ -22,6 +22,7 @@
#ifndef YASM_GLOBALS_H
#define YASM_GLOBALS_H
extern char *filename;
extern unsigned int line_number;
extern unsigned int mode_bits;
extern struct symrec_s *locallabel_base;

@ -1,4 +1,4 @@
/* $Id: linemgr.h,v 1.3 2001/06/28 21:22:01 peter Exp $
/* $Id: linemgr.h,v 1.4 2001/08/18 22:15:12 peter Exp $
* Globals header file
*
* Copyright (C) 2001 Peter Johnson
@ -22,6 +22,7 @@
#ifndef YASM_GLOBALS_H
#define YASM_GLOBALS_H
extern char *filename;
extern unsigned int line_number;
extern unsigned int mode_bits;
extern struct symrec_s *locallabel_base;

@ -1,4 +1,4 @@
/* $Id: main.c,v 1.4 2001/07/11 23:16:50 peter Exp $
/* $Id: main.c,v 1.5 2001/08/18 22:15:12 peter Exp $
* Program entry point, command line parsing
*
* Copyright (C) 2001 Peter Johnson
@ -21,19 +21,39 @@
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
extern int yydebug;
extern FILE *yyin;
extern int yyparse(void);
char *filename = (char *)NULL;
unsigned int line_number = 1;
unsigned int mode_bits = 32;
int
main (void)
main (int argc, char *argv[])
{
FILE *in;
yydebug = 1;
if(argc==2) {
in = fopen(argv[1], "rt");
if(!in) {
fprintf(stderr, "could not open file `%s'\n", argv[1]);
return EXIT_FAILURE;
}
filename = strdup(argv[1]);
yyin = in;
} else
filename = strdup("<UNKNOWN>");
yyparse();
if(filename)
free(filename);
return EXIT_SUCCESS;
}

Loading…
Cancel
Save