Merge pull request #44 from kernigh/kernigh-pr-as

mach/proto/as: allow more tokens
This commit is contained in:
David Given 2017-01-18 23:33:40 +01:00 committed by GitHub
commit d7df126730
4 changed files with 101 additions and 75 deletions

View file

@ -8,7 +8,21 @@
* All preprocessor based options/constants/functions * All preprocessor based options/constants/functions
*/ */
#include <stdint.h> #ifdef _include
_include <ctype.h>
_include <signal.h>
_include <stdint.h>
_include <stdio.h>
_include <stdlib.h>
_include <string.h>
#else
#include <ctype.h>
#include <signal.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#endif
/* ========== ON/OFF options (use #define in mach0.c) ========== */ /* ========== ON/OFF options (use #define in mach0.c) ========== */
@ -80,23 +94,16 @@ separate linker only possible if relocation info produced
/* ========== Machine independent type declarations ========== */ /* ========== Machine independent type declarations ========== */
#ifdef _include #ifdef _include
_include <stdlib.h> #ifdef ASLD
_include <stdio.h> _include "arch.h"
_include <string.h>
_include <ctype.h>
_include <signal.h>
#else
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <signal.h>
#endif #endif
_include "out.h"
#else
#ifdef ASLD #ifdef ASLD
#include "arch.h" #include "arch.h"
#endif #endif
#include "out.h" #include "out.h"
#endif
#if DEBUG == 0 #if DEBUG == 0
#define assert(ex) /* nothing */ #define assert(ex) /* nothing */
@ -265,6 +272,3 @@ typedef struct sect_t sect_t;
#define MACHREL_BWR (0) #define MACHREL_BWR (0)
#endif #endif
#endif #endif
extern FILE *fopen(); /* some systems don't have this in stdio.h */

View file

@ -104,21 +104,28 @@ extern struct outhead outhead;
extern int curr_token; extern int curr_token;
/* forward function declarations */ /* forward function declarations */
/* comm5.c */
int yylex(void);
void putval(int);
int getval(int);
int nextchar(void);
#ifdef ASLD #ifdef ASLD
extern char *readident(); char *readident(int);
#endif #endif
extern char *remember(); int hash(char *);
extern item_t *fb_shift(); item_t *item_search(char *);
extern item_t *fb_alloc(); void item_insert(item_t *, int);
extern item_t *item_alloc(); item_t *item_alloc(int);
extern item_t *item_search(); item_t *fb_alloc(int);
extern valu_t load(); item_t *fb_shift(int);
extern FILE *ffcreat(); /* comm7.c */
extern FILE *fftemp(); valu_t load();
char *remember();
extern void fatal(const char* s, ...); FILE *ffcreat();
extern void serror(const char* s, ...); FILE *fftemp();
extern void warning(const char* s, ...); void fatal(const char *, ...);
void serror(const char *, ...);
void warning(const char *, ...);
/* ========== Machine dependent C declarations ========== */ /* ========== Machine dependent C declarations ========== */

View file

@ -11,11 +11,18 @@
extern YYSTYPE yylval; extern YYSTYPE yylval;
void putval(); static void readcode(int);
static int induo(int);
static int inident(int);
static int innumber(int);
static int instring(int);
static int inescape(void);
static int infbsym(char *);
yylex() int
yylex(void)
{ {
register c; int c, c0, c1;
if (pass == PASS_1) { if (pass == PASS_1) {
/* scan the input file */ /* scan the input file */
@ -52,32 +59,37 @@ yylex()
/* produce the intermediate token file */ /* produce the intermediate token file */
if (c <= 0) if (c <= 0)
return(0); return(0);
if (c <= 127) if (c < 256) {
putc(c, tempfile); putc(c, tempfile);
else putc(0, tempfile);
} else {
putval(c); putval(c);
}
} else { } else {
/* read from intermediate token file */ /* read from intermediate token file */
c = getc(tempfile); c0 = getc(tempfile);
if (c == EOF) if (c0 == EOF)
return(0); return(0);
if (c > 127) { c1 = getc(tempfile);
c += 128; if (c1 == EOF)
return(0);
c = c0 + (c1 << 8);
if (c >= 256)
c = getval(c); c = getval(c);
}
} }
curr_token = c; curr_token = c;
return(c); return(c);
} }
void void
putval(c) putval(int c)
{ {
register valu_t v; register valu_t v;
register n = 0; register n = 0;
register char *p = 0; register char *p = 0;
assert(c >= 256 && c < 256+128); assert(c == (c & 0xffff));
switch (c) { switch (c) {
case CODE1: case CODE1:
n = 1; goto putnum; n = 1; goto putnum;
@ -92,9 +104,11 @@ putval(c)
break; break;
v >>= 8; v >>= 8;
} }
assert(n <= 4);
c = NUMBER0 + n; c = NUMBER0 + n;
putnum: putnum:
putc(c-128, tempfile); putc(c, tempfile);
putc(c >> 8, tempfile);
v = yylval.y_valu; v = yylval.y_valu;
while (--n >= 0) while (--n >= 0)
putc((int) (v >> (n*8)), tempfile); putc((int) (v >> (n*8)), tempfile);
@ -110,14 +124,15 @@ putval(c)
#endif #endif
case STRING: case STRING:
v = stringlen; v = stringlen;
putc(c-128, tempfile); putc(c, tempfile);
putc(c >> 8, tempfile);
for (n = 0; n < sizeof(v); n++) { for (n = 0; n < sizeof(v); n++) {
if (v == 0) if (v == 0)
break; break;
v >>= 8; v >>= 8;
} }
c = NUMBER0 + n; assert(n <= 4);
putc(c-128, tempfile); putc(n, tempfile);
v = stringlen; v = stringlen;
while (--n >= 0) while (--n >= 0)
putc((int) (v >> (n*8)), tempfile); putc((int) (v >> (n*8)), tempfile);
@ -139,12 +154,14 @@ putval(c)
n = sizeof(word_t); n = sizeof(word_t);
p = (char *) &yylval.y_word; break; p = (char *) &yylval.y_word; break;
} }
putc(c-128, tempfile); putc(c, tempfile);
putc(c >> 8, tempfile);
while (--n >= 0) while (--n >= 0)
putc(*p++, tempfile); putc(*p++, tempfile);
} }
getval(c) int
getval(int c)
{ {
register n = 0; register n = 0;
register valu_t v; register valu_t v;
@ -185,7 +202,7 @@ getval(c)
p = (char *) &yylval.y_strp; break; p = (char *) &yylval.y_strp; break;
#endif #endif
case STRING: case STRING:
getval(getc(tempfile)+128); getval(getc(tempfile)+NUMBER0);
stringlen = n = yylval.y_valu; stringlen = n = yylval.y_valu;
p = stringbuf; p = stringbuf;
p[n] = '\0'; break; p[n] = '\0'; break;
@ -209,7 +226,8 @@ getval(c)
/* ---------- lexical scan in pass 1 ---------- */ /* ---------- lexical scan in pass 1 ---------- */
nextchar() int
nextchar(void)
{ {
register c; register c;
@ -233,7 +251,8 @@ nextchar()
return(c); return(c);
} }
readcode(n) static void
readcode(int n)
{ {
register c; register c;
@ -252,8 +271,8 @@ readcode(n)
} while (--n); } while (--n);
} }
induo(c) static int
register c; induo(int c)
{ {
static short duo[] = { static short duo[] = {
('='<<8) | '=', OP_EQ, ('='<<8) | '=', OP_EQ,
@ -277,8 +296,8 @@ register c;
static char name[NAMEMAX+1]; static char name[NAMEMAX+1];
inident(c) static int
register c; inident(int c)
{ {
register char *p = name; register char *p = name;
register item_t *ip; register item_t *ip;
@ -309,8 +328,7 @@ register c;
#ifdef ASLD #ifdef ASLD
char * char *
readident(c) readident(int c)
register c;
{ {
register n = NAMEMAX; register n = NAMEMAX;
register char *p = name; register char *p = name;
@ -326,8 +344,8 @@ register c;
} }
#endif #endif
innumber(c) static int
register c; innumber(int c)
{ {
register char *p; register char *p;
register radix; register radix;
@ -373,7 +391,8 @@ register c;
return(NUMBER); return(NUMBER);
} }
instring(termc) static int
instring(int termc)
{ {
register char *p; register char *p;
register c; register c;
@ -412,7 +431,8 @@ instring(termc)
return(STRING); return(STRING);
} }
inescape() static int
inescape(void)
{ {
register c, j, r; register c, j, r;
@ -442,8 +462,8 @@ inescape()
return(c); return(c);
} }
infbsym(p) static int
register char *p; infbsym(char *p)
{ {
register lab; register lab;
register item_t *ip; register item_t *ip;
@ -469,8 +489,8 @@ ok:
return(FBSYM); return(FBSYM);
} }
hash(p) int
register char *p; hash(char *p)
{ {
register unsigned short h; register unsigned short h;
register c; register c;
@ -484,8 +504,7 @@ register char *p;
} }
item_t * item_t *
item_search(p) item_search(char *p)
char *p;
{ {
register h; register h;
register item_t *ip; register item_t *ip;
@ -503,15 +522,15 @@ done:
return(ip); return(ip);
} }
item_insert(ip, h) void
item_t *ip; item_insert(item_t *ip, int h)
{ {
ip->i_next = hashtab[h]; ip->i_next = hashtab[h];
hashtab[h] = ip; hashtab[h] = ip;
} }
item_t * item_t *
item_alloc(typ) item_alloc(int typ)
{ {
register item_t *ip; register item_t *ip;
static nleft = 0; static nleft = 0;
@ -532,8 +551,7 @@ item_alloc(typ)
} }
item_t * item_t *
fb_alloc(lab) fb_alloc(int lab)
register lab;
{ {
register item_t *ip, *p; register item_t *ip, *p;
@ -548,8 +566,7 @@ register lab;
} }
item_t * item_t *
fb_shift(lab) fb_shift(int lab)
register lab;
{ {
register item_t *ip; register item_t *ip;

View file

@ -354,8 +354,6 @@ valu_t valu;
outname.on_type = type; outname.on_type = type;
outname.on_desc = desc; outname.on_desc = desc;
outname.on_valu = valu; outname.on_valu = valu;
if (sizeof(valu) != sizeof(long))
outname.on_valu &= ~(((0xFFFFFFFF)<<(4*sizeof(valu_t)))<<(4*sizeof(valu_t)));
wr_name(&outname, 1); wr_name(&outname, 1);
} }