diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..84f0b97 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +*.o +gsp_gram.c +gsp_gram.h +gspa +*.exe diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..30df836 --- /dev/null +++ b/Makefile @@ -0,0 +1,32 @@ +YACC = yacc +YFLAGS = -d + +CC = gcc +CFLAGS = +LDFLAGS = +LIBS = + +EXEC = + +.PHONY: all clean +.SUFFIXES: .c .o + +OBJS = gspa.o gsp_act.o gsp_eval.o gsp_inst.o gsp_lex.o gsp_out.o gsp_pseu.o gsp_sym.o gsp_gram.o + +gspa$(EXEC): $(OBJS) + $(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS) + +gspa.o: gspa.c gsp_gram.c +gsp_lex.o: gsp_lex.c gsp_gram.c +gsp_eval.o: gsp_eval.c gsp_gram.c + +gsp_gram.c: gsp_gram.y + $(YACC) $(YFLAGS) gsp_gram.y + mv y.tab.c $@ + mv y.tab.h gsp_gram.h + +.c.o: + $(CC) $(CFLAGS) -c -o $@ $< + +clean: + rm -f gspa *.exe *.o gsp_gram.c gsp_gram.h diff --git a/gsp_act.c b/gsp_act.c index 7b45286..aa6e834 100644 --- a/gsp_act.c +++ b/gsp_act.c @@ -28,14 +28,8 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include -#ifndef lint -__RCSID("$NetBSD: gsp_act.c,v 1.6 2025/11/24 08:04:28 nia Exp $"); -#endif - #include #include -#include #include "gsp_ass.h" void diff --git a/gsp_ass.h b/gsp_ass.h index 30d30c8..a8c9bd9 100644 --- a/gsp_ass.h +++ b/gsp_ass.h @@ -31,6 +31,7 @@ #include #include #include +#include #define MAXLINE 133 @@ -141,11 +142,11 @@ void list_error(char *); void listing(void); symbol lookup(char *id, bool makeit); expr num_expr(int); -void p1err(const char *fmt, ...) __printflike(1, 2); -void perr(const char *fmt, ...) __printflike(1, 2); +void p1err(const char *fmt, ...); +void perr(const char *fmt, ...); void pseudo(int code, operand operands); void push_input(char *fn); -void putcode(u_int16_t *, int); +void putcode(uint16_t *, int); operand reg_ind(int, int); operand reg_index(int, expr); operand reg_indxy(int, char *); @@ -153,11 +154,11 @@ operand reg_op(int reg); void reset_numeric_labels(void); void set_label(char *); void set_numeric_label(int); -void start_at(u_int32_t); +void start_at(uint32_t); void statement(char *opcode, operand operands); operand string_op(char *); void ucasify(char *); -__dead void yyerror(const char *err); +void yyerror(const char *err); int yylex(void); @@ -168,12 +169,6 @@ extern unsigned lineno; extern int err_count; extern char line[], *lineptr; -#if defined(sparc) && !defined(__NetBSD__) #include -#else -#ifdef __GNUC__ -#define alloca __builtin_alloca -#endif -#endif -#define new(x) ((x) = emalloc(sizeof(*(x)))) +#define new(x) ((x) = malloc(sizeof(*(x)))) diff --git a/gsp_eval.c b/gsp_eval.c index f3af2fd..07969cb 100644 --- a/gsp_eval.c +++ b/gsp_eval.c @@ -28,11 +28,6 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include -#ifndef lint -__RCSID("$NetBSD: gsp_eval.c,v 1.5 2025/11/24 08:04:28 nia Exp $"); -#endif - #include #include "gsp_ass.h" #include "gsp_gram.h" diff --git a/gsp_gram.y b/gsp_gram.y index 737cd9b..f56487c 100644 --- a/gsp_gram.y +++ b/gsp_gram.y @@ -31,11 +31,6 @@ /* declarations */ %{ -#include -#ifndef lint -__RCSID("$NetBSD: gsp_gram.y,v 1.4 2025/11/24 08:04:28 nia Exp $"); -#endif - #include #include "gsp_ass.h" %} @@ -47,27 +42,32 @@ __RCSID("$NetBSD: gsp_gram.y,v 1.4 2025/11/24 08:04:28 nia Exp $"); operand y_opnd; } -%token LEFT_SHIFT, RIGHT_SHIFT +%token LEFT_SHIFT +%token RIGHT_SHIFT -%term ID, STRING -%term NUMBER, REGISTER -%term UMINUS +%token ID STRING +%token NUMBER REGISTER +%token UMINUS /* operator precedences - lowest to highest */ %nonassoc ':' /* concatenate y:x */ -%left LEFT_SHIFT, RIGHT_SHIFT +%left LEFT_SHIFT +%left RIGHT_SHIFT %left '^' /* EXCLUSIVE OR operator */ %left '|' /* OR operator */ %left '&' /* AND operator */ -%left '+', '-' -%left '*', '/' -%nonassoc '~', UMINUS /* NOT operator */ +%left '+' +%left '-' +%left '*' +%left '/' +%nonassoc '~' /* NOT operator */ +%nonassoc UMINUS /* NOT operator */ %start line /* types of non-terminals */ %type expr -%type operand, operands, ea +%type operand operands ea %% /* rules */ diff --git a/gsp_inst.c b/gsp_inst.c index 3dde934..b9189e7 100644 --- a/gsp_inst.c +++ b/gsp_inst.c @@ -28,11 +28,6 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include -#ifndef lint -__RCSID("$NetBSD: gsp_inst.c,v 1.12 2025/11/24 08:04:28 nia Exp $"); -#endif - #include #include #include "gsp_ass.h" @@ -40,7 +35,7 @@ __RCSID("$NetBSD: gsp_inst.c,v 1.12 2025/11/24 08:04:28 nia Exp $"); struct inst { const char *opname; - u_int16_t opcode; + uint16_t opcode; u_char class; /* instruction class + flags */ u_char optypes[4]; /* permissible operand classes */ }; @@ -253,7 +248,7 @@ struct inst instructions[] = { int check_spec(int spec, const char *valid, const char *what); void do_statement(char *opcode, operand operands); -int encode_instr(struct inst *ip, operand ops, int *spec, u_int16_t *iwords); +int encode_instr(struct inst *ip, operand ops, int *spec, uint16_t *iwords); int specifier(operand op); void @@ -271,7 +266,7 @@ do_statement(char *opcode, operand operands) unsigned nop; operand op; int spec[3]; - u_int16_t iwords[6]; + uint16_t iwords[6]; ucasify(opcode); i = 1; @@ -376,7 +371,7 @@ check_spec(int spec, const char *valid, const char *what) return p - valid; } -u_int16_t code_to_imm[] = { +uint16_t code_to_imm[] = { 0x0B20, /* ADDI */ 0, 0x0D00, /* SUBI */ @@ -392,7 +387,7 @@ u_int16_t code_to_imm[] = { }; /* Opcodes for MOVE instruction */ -u_int16_t move_opc[7][7] = { +uint16_t move_opc[7][7] = { /* Source */ /* Reg *Reg *Reg+ *-Reg *Reg.XY *Reg(n) @addr Dest */ {0x4C00,0x8400, 0x9400, 0xA400, 0, 0xB400, 0x05A0}, /* R */ @@ -405,7 +400,7 @@ u_int16_t move_opc[7][7] = { }; /* Opcodes for MOVB instruction */ -u_int16_t movb_opc[7][7] = { +uint16_t movb_opc[7][7] = { /* Source */ /* Reg *Reg *Reg+ *-Reg *Reg.XY *Reg(n) @addr Dest */ {0, 0x8E00, 0, 0, 0, 0xAE00, 0x07E0},/* R */ @@ -418,7 +413,7 @@ u_int16_t movb_opc[7][7] = { }; /* Opcodes for PIXT instruction */ -u_int16_t pixt_opc[7][7] = { +uint16_t pixt_opc[7][7] = { /* Source */ /* Reg *Reg *Reg+ *-Reg *Reg.XY *Reg(n) @addr Dest */ {0, 0xFA00, 0, 0, 0xF200, 0, 0}, /* R */ @@ -436,7 +431,7 @@ u_int16_t pixt_opc[7][7] = { || ((op)->type == EA && (op)->mode >= M_INDEX)) int -encode_instr(struct inst *ip, operand ops, int *spec, u_int16_t *iwords) +encode_instr(struct inst *ip, operand ops, int *spec, uint16_t *iwords) { int rs, rd; int opc, nw, class, flags, ms, md, off; diff --git a/gsp_lex.c b/gsp_lex.c index 39becc1..9029f96 100644 --- a/gsp_lex.c +++ b/gsp_lex.c @@ -28,11 +28,6 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include -#ifndef lint -__RCSID("$NetBSD: gsp_lex.c,v 1.10 2025/11/24 08:04:28 nia Exp $"); -#endif - #include #include #include diff --git a/gsp_out.c b/gsp_out.c index ced2b06..67db533 100644 --- a/gsp_out.c +++ b/gsp_out.c @@ -28,18 +28,12 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include -#ifndef lint -__RCSID("$NetBSD: gsp_out.c,v 1.11 2025/11/24 08:04:28 nia Exp $"); -#endif - #include #include #include -#include #include "gsp_ass.h" -u_int16_t codes[5]; +uint16_t codes[5]; unsigned ncode; unsigned code_idx; short show_pc; @@ -53,8 +47,8 @@ extern FILE *objfile, *listfile; extern char line[]; extern char *c_name; -u_int16_t c_buf[4096]; -u_int32_t c_bufptr, c_binads; +uint16_t c_buf[4096]; +uint32_t c_bufptr, c_binads; void c_checkbuf(void); void c_dumpbuf(void); @@ -69,18 +63,18 @@ struct error *error_list, *error_last; void do_list_pc(void); void do_show_val(int32_t); void listing_line(void); -void put1code(u_int16_t); +void put1code(uint16_t); void show_errors(void); void -putcode(u_int16_t *v, int n) +putcode(uint16_t *v, int n) { for( ; n > 0; --n ) put1code(*v++); } void -put1code(u_int16_t v) +put1code(uint16_t v) { if( code_idx >= 3 ) listing_line(); @@ -143,7 +137,7 @@ c_dumpbuf() } void -start_at(u_int32_t val) +start_at(uint32_t val) { if( objfile != NULL ) { if (c_name) { @@ -183,7 +177,7 @@ list_error(char *string) if( listfile == NULL ) return; l = strlen(string); - p = emalloc(sizeof(struct error) + l); + p = malloc(sizeof(struct error) + l); strcpy(p->string, string); p->next = NULL; if( error_list == NULL ) diff --git a/gsp_pseu.c b/gsp_pseu.c index 6865a5a..27598fb 100644 --- a/gsp_pseu.c +++ b/gsp_pseu.c @@ -28,11 +28,6 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include -#ifndef lint -__RCSID("$NetBSD: gsp_pseu.c,v 1.4 2025/11/24 08:04:28 nia Exp $"); -#endif - #include "gsp_ass.h" #include "gsp_code.h" @@ -44,7 +39,7 @@ pseudo(int code, operand ops) operand o; int32_t val; unsigned ln; - u_int16_t words[2]; + uint16_t words[2]; switch( code ){ case ORG: diff --git a/gsp_sym.c b/gsp_sym.c index d16047d..1e33525 100644 --- a/gsp_sym.c +++ b/gsp_sym.c @@ -28,14 +28,9 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include -#ifndef lint -__RCSID("$NetBSD: gsp_sym.c,v 1.10 2025/11/24 08:04:28 nia Exp $"); -#endif - #include #include -#include +#include #include "gsp_ass.h" #define NHASH 64 /* must be power of 2 */ @@ -62,7 +57,7 @@ lookup(char *id, bool makeit) break; if( !makeit ) return NULL; - ptr = emalloc(sizeof(struct symbol) + strlen(id)); + ptr = malloc(sizeof(struct symbol) + strlen(id)); ptr->ndefn = 0; ptr->flags = 0; ptr->value = 0; diff --git a/gspa.c b/gspa.c index 1250708..753d412 100644 --- a/gspa.c +++ b/gspa.c @@ -28,11 +28,6 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include -#ifndef lint -__RCSID("$NetBSD: gspa.c,v 1.16 2025/11/24 08:04:28 nia Exp $"); -#endif - #include #include #include @@ -42,7 +37,6 @@ __RCSID("$NetBSD: gspa.c,v 1.16 2025/11/24 08:04:28 nia Exp $"); #include #include #include -#include #include "gsp_ass.h" #include "gsp_gram.h" @@ -80,7 +74,7 @@ struct input { jmp_buf synerrjmp; void setext(char *, const char *, const char *); -__dead static void usage(void); +static void usage(void); int yyparse(void); void c_dumpbuf(void); @@ -159,7 +153,7 @@ main(int argc, char **argv) " * Do not edit manually.\n" " */\n" "#include \n" - "u_int16_t %s[] = {\n\t", c_name); + "uint16_t %s[] = {\n\t", c_name); } if (list_name) if ((listfile = fopen(list_name, "w")) == NULL)