ref: 8df711f4d80aa9402bf9d7aa5e5603e0032c248d
parent: 1734378ecd88d19b9345de63466e57d8db6d70a9
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Fri Jan 4 10:17:28 EST 2019
[as] Remove support for myro As is going to generate only a binary dump of the output.
--- a/src/as/Makefile
+++ b/src/as/Makefile
@@ -10,7 +10,6 @@
ins.o \
parser.o \
expr.o \
- myro.o \
TARGET = $(LIBEXEC)/as-amd64 \
$(LIBEXEC)/as-i386 \
--- a/src/as/as.h
+++ b/src/as/as.h
@@ -188,15 +188,6 @@
/* ins.c */
extern char *tobytes(TUINT v, int n, int inc);
-/* format.c */
-extern void writeout(char *name);
-extern void reloc(Symbol *sym,
- unsigned flags,
- unsigned size,
- unsigned nbits,
- unsigned shift);
-
-
/*
* Definition of global variables
*/
--- a/src/as/deps.mk
+++ b/src/as/deps.mk
@@ -6,9 +6,6 @@
main.o: $(INCDIR)/scc/scc/arg.h
main.o: $(INCDIR)/scc/scc/scc.h
main.o: as.h
-myro.o: $(INCDIR)/scc/scc/myro.h
-myro.o: $(INCDIR)/scc/scc/scc.h
-myro.o: as.h
parser.o: $(INCDIR)/scc/scc/cstd.h
parser.o: $(INCDIR)/scc/scc/scc.h
parser.o: as.h
--- a/src/as/ins.c
+++ b/src/as/ins.c
@@ -16,6 +16,15 @@
TYPE,
};
+static void
+reloc(Symbol *sym,
+ unsigned flags,
+ unsigned size,
+ unsigned nbits,
+ unsigned shift)
+{
+}
+
char *
tobytes(TUINT v, int nbytes, int inc)
{
--- a/src/as/main.c
+++ b/src/as/main.c
@@ -1,5 +1,6 @@
static char sccsid[] = "@(#) ./as/main.c";
+#include <errno.h>
#include <ctype.h>
#include <setjmp.h>
#include <stdio.h>
@@ -14,6 +15,29 @@
char *outfile, *infile;
int endpass;
+static void
+writeout(char *fname)
+{
+ Section *sp;
+ FILE *fp;
+
+ if ((fp = fopen(fname, "wb")) == NULL)
+ goto error;
+
+ for (sp = seclist; sp; sp = sp->next) {
+ if (!sp->mem)
+ continue;
+ fwrite(sp->mem, sp->max - sp->base, 1, fp);
+ }
+
+ if (fclose(fp))
+ goto error;
+ return;
+
+error:
+ fprintf(stderr, "as: %s: %s\n", fname, strerror(errno));
+ exit(EXIT_FAILURE);
+}
static void
cleanup(void)
--- a/src/as/myro.c
+++ /dev/null
@@ -1,204 +1,0 @@
-static char sccsid[] = "@(#) ./as/myro.c";
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <scc/scc.h>
-#include <scc/myro.h>
-#include "as.h"
-
-#define FORMAT "z80-scc"
-
-static Reloc *relocs;
-static size_t relcap, relsiz;
-
-static size_t
-writestrings(FILE *fp)
-{
- int type;
- size_t off = 0;
- size_t len;
- Symbol *sym;
- Section *sp;
- String *str;
-
- fwrite(FORMAT, sizeof(FORMAT), 1, fp);
- off = sizeof(FORMAT);
-
- for (sym = symlist; sym; sym = sym->next) {
- if (sym->flags & FREG)
- continue;
- str = &sym->name;
- len = strlen(str->buf) + 1;
- fwrite(str->buf, len, 1, fp);
- str->offset = off;
- off += len;
- }
-
- return off;
-}
-
-static unsigned
-getsecflags(Section *sp)
-{
- unsigned flags = 0;
-
- if (sp->flags & SREAD)
- flags |= MYROSEC_READ;
- if (sp->flags & SWRITE)
- flags |= MYROSEC_WRITE;
- if (sp->flags & SFILE)
- flags |= MYROSEC_FILE;
- if (sp->flags & SEXEC)
- flags |= MYROSEC_EXEC;
- if (sp->flags & SLOAD)
- flags |= MYROSEC_LOAD;
- if (sp->flags & SABS)
- flags |= MYROSEC_ABS;
- return flags;
-}
-
-static size_t
-writesections(FILE *fp)
-{
- Section *sp;
- size_t off = 0;
- struct myrosect sect;
- unsigned id = 0;;
-
- for (sp = seclist; sp; sp = sp->next) {
- if (id == MYROMAXSEC)
- die("too many sections for a myro file");
- sp->id = id++;
- sect.name = sp->sym->name.offset;
- sect.flags = getsecflags(sp);
- sect.fill = sp->fill;
- sect.aligment = sp->aligment;
- sect.offset = off;
- sect.len = sp->max - sp->base;
- off += wrmyrosec(fp, §);
- }
-
- return off;
-}
-
-static unsigned
-getsymflags(Symbol *sym)
-{
- unsigned flags = 0;
-
- if (sym->flags & FCOMMON)
- flags |= MYROSYM_COMMON;
- if (sym->flags & FEXTERN)
- flags |= MYROSYM_EXTERN;
- if (!(sym->flags & FDEF))
- flags |= MYROSYM_UNDEF;
- return flags;
-}
-
-static size_t
-writesymbols(FILE *fp)
-{
- Symbol *sym;
- size_t off = 0;
- struct myrosym symbol;
-
- for (sym = symlist; sym; sym = sym->next) {
- if (sym->flags & (FREG|FSECT))
- continue;
- symbol.name = sym->name.offset;
- symbol.type = -1;
- symbol.section = sym->section->id;
- symbol.flags = getsymflags(sym);
- symbol.offset = sym->value;
- symbol.len = sym->size;
- off += wrmyrosym(fp, &symbol);
- }
-
- return off;
-}
-
-static size_t
-writerelocs(FILE *fp)
-{
- Reloc *bp, *lim;
- size_t off = 0;
- struct myrorel reloc;
-
- lim = &relocs[relsiz];
- for (bp = relocs; bp < lim; ++bp) {
- reloc.id = 0;
- reloc.flags = bp->flags;
- reloc.size = bp->size;
- reloc.nbits = bp->nbits;
- reloc.shift = bp->shift;
- reloc.offset = bp->offset;
- off += wrmyrorel(fp, &reloc);
- }
- return off;
-}
-
-static void
-writedata(FILE *fp)
-{
- Section *sp;
-
- for (sp = seclist; sp; sp = sp->next) {
- if (!sp->mem)
- continue;
- fwrite(sp->mem, sp->max - sp->base, 1, fp);
- }
-}
-
-void
-writeout(char *name)
-{
- FILE *fp;
- struct myrohdr hdr = { .magic = MYROMAGIC };
-
- if ((fp = fopen(name, "wb")) == NULL)
- die("error opening output file '%s'\n", name);
-
- wrmyrohdr(fp, &hdr);
- hdr.strsize = writestrings(fp);
- hdr.secsize = writesections(fp);
- hdr.symsize = writesymbols(fp);
- hdr.relsize = writerelocs(fp);
- writedata(fp);
-
- fseek(fp, 0, SEEK_SET);
- wrmyrohdr(fp, &hdr);
-
- if (fclose(fp))
- die("error writing the output file");
-}
-
-void
-reloc(Symbol *sym,
- unsigned flags, unsigned size, unsigned nbits, unsigned shift)
-{
- size_t tmp;
- Reloc *p;
-
- if (pass == 1)
- return;
-
- if (relcap == relsiz) {
- tmp = ((relcap + 1) * 3) / 2;
- if ((p = realloc(relocs, tmp * sizeof(Reloc))) == NULL) {
- tmp = relcap + 1;
- p = xrealloc(relocs, tmp * sizeof(Reloc));
- }
- relcap = tmp;
- relocs = p;
- }
-
- p = &relocs[relsiz++];
- p->sym = sym;
- p->flags = flags;
- p->size = size;
- p->nbits = nbits;
- p->shift = shift;
- p->offset = cursec->pc - cursec->base;
-}