1
0
Fork 0
mirror of https://github.com/pnx/m16vm synced 2026-06-16 03:44:55 +02:00

moving as/error.c code to lib to have the functions reusable.

This commit is contained in:
Henrik Hautakoski 2018-12-21 00:03:47 +01:00
parent 04689fc69a
commit 6422bcca8a
No known key found for this signature in database
GPG key ID: 839F3A7EAFAEAFAA
7 changed files with 91 additions and 24 deletions

View file

@ -24,15 +24,16 @@ PROGRAMS = m16vm m16as
all: $(PROGRAMS)
m16vm : vm/vm.o vm/cpu.o vm/mm.o vm/instr_decode.o vm/syscall.o vm/program.o
m16vm : vm/vm.o vm/cpu.o vm/mm.o vm/instr_decode.o \
vm/syscall.o vm/program.o lib/libm16.a
$(LD) $(LDFLAGS) -o $@ $^
m16as : as/as.o as/parser.o as/lexer.o \
as/codegen.o as/error.o as/symtab.o \
as/ast.o lib/libm16.a
as/codegen.o as/symtab.o \
as/ast.o as/asm_error.o lib/libm16.a
$(LD) $(LDFLAGS) -o $@ $^
lib/libm16.a : lib/vector.o
lib/libm16.a : lib/vector.o lib/error.o
$(AR) rcs $@ $^
clean :

35
as/asm_error.c Normal file
View file

@ -0,0 +1,35 @@
/* asm_error.c
*
* Copyright (C) 2018 Henrik Hautakoski <henrik.hautakoski@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#include <stdio.h>
#include <stdarg.h>
#include "error.h"
#include "asm_error.h"
void asm_warn(int lineno, const char *message, ...) {
fprintf(stderr, "Line %i: ", lineno);
warn(message);
}
int asm_error(int lineno, const char *message, ...) {
fprintf(stderr, "Line %i: ", lineno);
return error(message);
}

29
as/asm_error.h Normal file
View file

@ -0,0 +1,29 @@
/* asm_error.h
*
* Copyright (C) 2018 Henrik Hautakoski <henrik.hautakoski@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#ifndef ASM_ERROR_H
#define ASM_ERROR_H
#include <error.h>
void asm_warn(int lineno, const char *message, ...);
int asm_error(int lineno, const char *message, ...);
#endif /* ASM_ERROR_H */

View file

@ -1,7 +1,7 @@
#include <stdio.h>
#include <string.h>
#include "error.h"
#include "asm_error.h"
#include "lexer.h"
/**

View file

@ -20,7 +20,7 @@
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include "error.h"
#include "asm_error.h"
#include "codegen.h"
#include "ast.h"
#include "lexer.h"

View file

@ -21,26 +21,28 @@
#include <stdarg.h>
#include "error.h"
void asm_warn(int lineno, const char *fmt, ...) {
static inline void _write(FILE *fd, const char *prefix, const char *fmt, va_list list) {
va_list vl;
fprintf(stderr, "Line %i: Warning: ", lineno);
va_start(vl, fmt);
vfprintf(stderr, fmt, vl);
va_end(vl);
fprintf(stderr, "\n");
char buf[4096];
vsnprintf(buf, sizeof(buf), fmt, list);
fprintf(stderr, "%s: %s\n", prefix, buf);
}
int asm_error(int lineno, const char *fmt, ...) {
void warn(const char *message, ...) {
va_list vl;
fprintf(stderr, "Line %i: Error: ", lineno);
va_start(vl, fmt);
vfprintf(stderr, fmt, vl);
va_start(vl, message);
_write(stderr, "warning", message, vl);
va_end(vl);
fprintf(stderr, "\n");
}
int error(const char *message, ...) {
va_list vl;
va_start(vl, message);
_write(stderr, "error", message, vl);
va_end(vl);
return -1;
}

View file

@ -17,11 +17,11 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#ifndef ASM_ERROR_H
#define ASM_ERROR_H
#ifndef M16_ERROR_H
#define M16_ERROR_H
void asm_warn(int lineno, const char *fmt, ...);
void warn(const char *message, ...);
int asm_error(int lineno, const char *fmt, ...);
int error(const char *message, ...);
#endif /* ASM_ERROR_H */
#endif /* M16_ERROR_H */