OpenCores
URL https://opencores.org/ocsvn/thor/thor/trunk

Subversion Repositories thor

[/] [thor/] [trunk/] [FT64v5/] [software/] [AS64/] [source/] [token.cpp] - Diff between revs 50 and 54

Show entire file | Details | Blame | View Log

Rev 50 Rev 54
Line 25... Line 25...
//
//
#include "stdafx.h"
#include "stdafx.h"
 
 
char *pinptr;
char *pinptr;
char lastid[500];
char lastid[500];
 
char laststr[500];
char lastch;
char lastch;
Int128 last_icon;
Int128 last_icon;
Int128 ival;
Int128 ival;
double rval;
double rval;
 
 
int my_isspace(char ch)
int my_isspace(char ch)
{
{
    if (ch==' ' || ch=='\t' || ch=='\r')
    if (ch==' ' || ch=='\t' || ch=='\r')
        return 1;
        return (1);
    return 0;
    return (0);
}
}
int isspaceOrDot(char ch)
int isspaceOrDot(char ch)
{
{
        return my_isspace(ch) || ch=='.';
        ch &= 0x7f;
 
        return (my_isspace(ch) || ch=='.');
}
}
 
 
int isFirstIdentChar(char ch)
int isFirstIdentChar(char ch)
{
{
    return isalpha(ch) || ch=='_';
        ch &= 0x7f;
 
  return (isalpha(ch) || ch=='_');
}
}
 
 
int isIdentChar(char ch)
int isIdentChar(char ch)
{
{
    return isalnum(ch) || ch=='_';
        ch &= 0x7f;
 
        return (isalnum(ch) || ch=='_');
}
}
 
 
int need(int tk)
int need(int tk)
{
{
    if (tk != token) {
    if (tk != token) {
Line 299... Line 303...
    }
    }
    else
    else
        return 0;
        return 0;
}
}
 
 
 
void getString()
 
{
 
        int nn;
 
 
 
        nn = 0;
 
        while (*inptr && *inptr != '"' && *inptr != '\n' && nn < sizeof(laststr) - 2) {
 
                laststr[nn] = *inptr;
 
                nn++;
 
                inptr++;
 
        }
 
        inptr++;
 
        laststr[nn] = '\0';
 
}
 
 
static char *pseudos[] = {
static char *pseudos[] = {
    "align", "code", "data", "tls", "rodata",
    "align", "code", "data", "tls", "rodata", "file",
    "fill", "org", "byte", "message",(char *)NULL
    "fill", "org", "byte", "message",(char *)NULL
};
};
static int pseudoTokens[] = {
static int pseudoTokens[] = {
    tk_align, tk_code, tk_data, tk_tls, tk_rodata,
    tk_align, tk_code, tk_data, tk_tls, tk_rodata, tk_file,
    tk_fill, tk_org, tk_db, tk_message, tk_none
    tk_fill, tk_org, tk_db, tk_message, tk_none
};
};
 
 
int isPseudoOp()
int isPseudoOp()
{
{
Line 316... Line 334...
    char *p = inptr;
    char *p = inptr;
    int nn = 0;
    int nn = 0;
 
 
    if (*p=='.') p++;
    if (*p=='.') p++;
    if (!isFirstIdentChar(*p))
    if (!isFirstIdentChar(*p))
        return 0;
    return (0);
    while(isIdentChar(*p)) {
    while(isIdentChar(*p)) {
        buf[nn] = tolower(*p);
        buf[nn] = tolower(*p);
        p++;
        p++;
        nn++;
        nn++;
    }
    }
    buf[nn] = '\0';
    buf[nn] = '\0';
    for (nn = 0; nn < 8; nn++) {
  for (nn = 0; nn < 9; nn++) {
        if (strcmp(buf, pseudos[nn])==0) {
        if (strcmp(buf, pseudos[nn])==0) {
            //inptr = p;
            //inptr = p;
            //token = pseudoTokens[nn];
            //token = pseudoTokens[nn];
            return 1;
      return (1);
        }
        }
    }
    }
    return 0;
  return (0);
}
}
 
 
void prevToken()
void prevToken()
{
{
    inptr = pinptr;
    inptr = pinptr;
}
}
 
 
int NextToken()
int NextToken()
{
{
 
        char ch;
 
        char *p;
 
 
    pinptr = inptr;
    pinptr = inptr;
    do {
    do {
        if (*inptr=='\0')
        if (*inptr=='\0')
           return token = tk_eof;
           return token = tk_eof;
        SkipSpaces();                      // skip over leading spaces
        SkipSpaces();                      // skip over leading spaces
        if (*inptr==';') {                 // comment ?
        if (*inptr==';') {                 // comment ?
            ScanToEOL();
            ScanToEOL();
            continue;
            continue;
        }
        }
        if (isdigit(*inptr)) {
                                ch = *inptr & 0x7f;
 
        if (isdigit(ch)) {
           getnum();
           getnum();
           return token;
           return token;
        }
        }
        switch(*inptr) {
        switch(*inptr) {
 
                                case '"':
 
                                        inptr++;
 
                                        getString();
 
                                        return (token = tk_strconst);
        case '.': if (isPseudoOp()) { inptr++; continue; }
        case '.': if (isPseudoOp()) { inptr++; continue; }
                  else if (getIdentifier()) { return token = tk_id; }
                  else if (getIdentifier()) { return (token = tk_id); }
                  else { inptr++; continue; }
                  else { inptr++; continue; }
        case '\n': inptr++; return token = tk_eol;
        case '\n': inptr++; return token = tk_eol;
        case '$': inptr++; getbase(16); return token = tk_icon;
        case '$': inptr++; getbase(16); return token = tk_icon;
        case '%': inptr++; getbase(2); return token = tk_icon;
        case '%': inptr++; getbase(2); return token = tk_icon;
        case ',': inptr++; return token = ',';
        case ',': inptr++; return token = ',';
Line 1437... Line 1463...
                                         (isspace(inptr[4])||inptr[4]=='.')) {
                                         (isspace(inptr[4])||inptr[4]=='.')) {
                                         inptr += 4;
                                         inptr += 4;
                                         return token = tk_ftoi;
                                         return token = tk_ftoi;
                                 }
                                 }
                         }
                         }
 
                         if ((inptr[1] == 'i' || inptr[1] == 'I') &&
 
                                 (inptr[2] == 'l' || inptr[2] == 'L') &&
 
                                 (inptr[3] == 'e' || inptr[3] == 'E') &&
 
                                 (isspace(inptr[4]) || inptr[4] == ':')) {
 
                                 inptr += 4;
 
                                 return (token = tk_file);
 
                         }
 
 
             break;
             break;
 
 
        // gran
        // gran
        case 'g': case 'G':
        case 'g': case 'G':
             if ((inptr[1]=='r' || inptr[1]=='R') &&
             if ((inptr[1]=='r' || inptr[1]=='R') &&
Line 2034... Line 2068...
                    inptr += 5;
                    inptr += 5;
                    return token = tk_mark2;
                    return token = tk_mark2;
                }
                }
                        }
                        }
            if ((inptr[1]=='a' || inptr[1]=='A') &&
            if ((inptr[1]=='a' || inptr[1]=='A') &&
                (inptr[2]=='r' || inptr[2]=='R') &&
                (inptr[2]=='c' || inptr[2]=='C') &&
                (inptr[3]=='c' || inptr[3]=='C') &&
                (inptr[3]=='r' || inptr[3]=='R') &&
                (inptr[4]=='o' || inptr[4]=='O') &&
                (inptr[4]=='o' || inptr[4]=='O') &&
                isspace(inptr[5])) {
                isspace(inptr[5])) {
                inptr += 5;
                inptr += 5;
                return token = tk_macro;
                return (token = tk_macro);
            }
            }
            break;
            break;
 
 
        // not neg nop
        // not neg nop
        case 'n': case 'N':
        case 'n': case 'N':
Line 2964... Line 2998...
                }
                }
            }
            }
        }
        }
        // The text wasn't recognized as any of the above tokens. So try for an
        // The text wasn't recognized as any of the above tokens. So try for an
        // identifier name.
        // identifier name.
 
                                p = inptr;
        if (getIdentifier()) {
        if (getIdentifier()) {
            return token = tk_id;
                                        SYM *sym;
 
                                        char *q;
 
                                        if (sym = find_symbol(lastid)) {
 
                                                if (sym->isMacro) {
 
                                                        Arglist args;
 
                                                        args.Get();
 
                                                        q = sym->macro->SubArgs(&args);
 
                                                        Macro::Substitute(q, inptr-p);
 
                                                        inptr = p;
 
                                                        continue;
 
                                                }
 
                                        }
 
            return (token = tk_id);
        }
        }
        inptr++;
        inptr++;
    } while (*inptr);
    } while (*inptr);
    return token = tk_eof;
    return (token = tk_eof);
}
}
 
 
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// Return the register number or -1 if not a register.
// Return the register number or -1 if not a register.
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.