📄 scan.c
字号:
#define CHEK if(c==';') {c=nextc(); scanb(c); return arecreg (recreg );}\ rp = resw_lookup( cp = scansym( ) ); \ if ( rp == 0 ) goto wbotch; scanb(c); if ( c == ';' ) { /* no recreg control field */ c = nextc(); scanb(c); return arecreg( recreg ); } rp = resw_lookup(cp=scansym( )); if ( rp == 0 ) goto wbotch; if (rp->type == Recoe ) { recreg = rp->value1; scanb(c); CHEK } if (rp->type == Reclk ) { recreg += rp->value1; scanb(c); if ( c == ';' ) { c = nextc(); scanb(c); return arecreg (recreg); } } error ("recovery reg field syntax error, character %c is not expected", c); return False;wbotch : error ("%s found in recovery reg field", cp ); return False;#undef CHEK}Booleanrampart ( ){ register char c; register RESERVED *rp; char *cp; int ramctrl = 0, ramcs = 0, ptr = 0;#define CHEK if(c==';') {c=nextc(); scanb(c); return ARAM;} \ rp = resw_lookup(cp=scansym( )); \ if ( rp == 0 ) goto wbotch;#define ARAM aram (ramctrl, ramcs, ptr) scanb(c); if ( c == ';' ) { /* no ramctrl field */ c = nextc(); scanb(c); return ARAM; } rp = resw_lookup(cp=scansym( )); if ( rp == 0 ) goto wbotch; if (rp->type == Ramwe ) { ramctrl = rp->value1; scanb(c); CHEK } if (rp->type == Ramcs && rp->value2 == 1 ) { ramcs = rp->value1; scanb(c); CHEK } if (rp->type == Ramcs && rp->value2 == 2 ) { ramcs += rp->value1; scanb(c); CHEK } if (rp->type == Pointer ) { if ( rp->value2 == 2 ) { error("pointer %s is not allowed here", cp); return False; } ptr = rp->value1; scanb(c); if (c == ';') { c = nextc(); scanb(c); return ARAM; } } error ("ram control field syntax error, character %c is not expected", c); return False;wbotch : error ("%s found in ram control field", cp ); return False;#undef CHEK#undef ARAM}Boolean ptrpart ( ){ register char c; register RESERVED*rp; register char *cp; int ptr = 0; int act = 0; SYMTYPE which = NEITHER; int num; char *sym;#define APTR aptr( ptr, act, which, num, sym) scanb(c); if ( c== '|' || c == '\0' ) { /* no ptr_action field */ c = nextc(); scanb(c); return APTR; } rp = resw_lookup(cp=scansym( )); if ( rp == 0 ) goto wbotch; if ( rp->type == Pointer ) { if ( rp->value2 == 1 ) { error("pointer %s is not allowed here", cp); return False; } ptr = rp->value1; scanb(c); switch (c) { case '=' : /* hold */ act = 0; break; case '!': if ( ptr == 1 || ptr == 2 || ptr == 3 || ptr == 4) { error("action is not allowed for the pointer"); return False; } act = 1; /* load */ c = nextc(); scanb(c); if ( c == '|' || c == '\0' ) return APTR; if ( curnode->jumpop == True ) { error("overlap address field with load value"); return False; } if (isdigit(c)) { which = NUMBER; num = getnum( ); scanb(c); if ( c == '+') { c = nextc(); scanb(c); if (! isdigit(c)) goto wbotch; num += getnum(); curpos--; } else { curpos--; } } else if(isalpha(c)) { which = ALPHA; sym = scansym( ); } else goto wbotch; break; case '+': if ( ptr == 6 || ptr == 7 ) { error("action is not allowed for the pointer"); return False; } act = 3; break; case '-': if ( ptr == 7 ) { error("action is not allowed for the pointer"); return False; } act = 2; break; default : error ("ptr control field syntax error, character %c is not expected", c); return False; } c = nextc(); scanb(c); if ( c == '|' || c == '\0' ) return APTR; }wbotch : error ("%s found in ptr control field", cp ); return False;#undef APTR}doramtable ( ){ register char c; register dontcare = 0; register mask = 0; RESERVED *rp; char *cp; char name[20]; char addr[13]; int i; Boolean first; int load; int func; scanb(c); cp = scansym( ); /* routine name */ cp = strcpy (name, cp); name[19] = '\0'; scanb(c); switch (c) { case 'r': addr[0] = '1'; dontcare = 1; mask = 1; break; case 'w': addr[0] = '0'; dontcare = 1; mask = 0; break; case 'x': addr[0] = 'x'; dontcare = 0; mask = 0; break; default: goto botch; } for ( i = 1; i < 12; i++ ) { nextc(); c = peekc(); switch (c) { case '0': addr[i] = '0'; dontcare = (dontcare << 1) + 1; mask = mask << 1; break; case '1': addr[i] = '1'; dontcare = (dontcare << 1) + 1; mask = (mask << 1) + 1; break; case 'x': addr[i] = 'x'; dontcare = dontcare << 1; mask = mask << 1; break; default: goto botch; } } addr[12] = '\0'; nextc(); scanb(c); rp = resw_lookup( cp = scansym( ) ); /* load ctrl */ if ( rp == 0 ) goto wbotch; if ( rp->type != Loadctrl ) goto wbotch; if ( rp->value2 != 1 ) { error("bad load control"); return; } load = rp->value1; scanb(c); rp = resw_lookup( cp = scansym( ) ); /* func ctrl */ if ( rp == 0 ) goto wbotch; if ( rp->type != Function ) goto wbotch; if ( rp->value2 == 2 ) { error("bad function control"); return; } func = rp->value1; first = True; for ( i = 0; i < NINST; i++ ) { if ( (i & dontcare ) == mask ) { if ( ram[i].addr[0] != 0 ) { error ("overlapping at ram addr %4x", i); continue; } if (first) { cp = strcpy (ram[i].name, name); cp = strcpy (ram[i].addr, addr); first = False; } else { ram[i].addr[0] = 'm'; } ram[i].entry = curaddr; ram[i].load = load; ram[i].func = func; } } return;wbotch : error ("%s found in routine pseudo_op", rp ); return;botch: error ("%c is not expected in routine pseudo_op", cp );}label(sp) SYMBOL *sp;{ if (sp->defined){ error("label %s already defined", sp->name ); return; } sp->defined = True; sp->node = curnode+1; DEBUG("Label: defining %s\n", sp->name);}Booleancpp(){ /* the scanner just saw a '#' -- treat as cpp leaving */ register char c ; char *sp; int leng; int cln; nextc(); scanb(c); cln = curlineno; curlineno = getnum( ) - 1; scanb(c); if (c != '"') { curlineno = cln; error("#-line not of form output by C preprocessor"); return False; } /* just saw the " */ c = nextc(); /* skip it */ sp = curpos; while( (c=nextc()) != '"' ); *curpos = '\0'; leng = strlen( sp ); curfilename = (char *)malloc( leng+1 ); if (curfilename == 0) { error("unable to get sufficient storage\n"); return False; } strcpy( curfilename, sp ); DEBUG("# %d \"%s\"\n", curlineno+1, curfilename); return True;} scanprog(){ /* for each line in the program text: if it is blank, continue. if it begins with a '#', its a cpp dropping look at the first symbol on the line. if it is followed by a :, its a label, so define the label and scan out the next symbol assemble the seq_state part assemble the Weitek instruction part assemble the datamuxing part assemble the recover reg ctrl part assemble the ram control part assemble the pointer actoin part */ char c; char *name; SYMBOL *sp; Boolean stopsw = False; Boolean bkptsw = False; int debugsw = 0; int foo; register RESERVED *rp; while (newline()){ if (*curpos == '#'){ cpp(); continue; }restart: scanb(c); if( c == '\0') { continue; /* blank line */ } if (c == ';') { name = 0; anext(); goto doseq; } if (!isalnum(c)) { if (c != '|') { error("character %c unexpected", c); } anext(); curnode->org_pseudo = True; continue; } name = scansym( ); scanb(c); if(c== ':') { /* what we have here is a label */ sp = lookup( name ); if (sp == 0) sp = enter( name ); label( sp ); nextc(); scanb(c); (curnode+1)->addr = curaddr; if (c == '\0') { anext(); curnode->org_pseudo = True; } goto restart; } anext(); rp = resw_lookup( name ); if (rp != 0 && rp->type == Pseudo) { /* it's a pseudo-op */ switch (rp->value1) { case 1: /*org */ scanb(c); if (!isdigit(c)) { error("expected digit; found %c", c); continue; } curnode->org_pseudo = True; foo = getnum(); if ( foo < curaddr ) { error("org %d over write lower address space", foo); continue; } curaddr = foo; break; case 2: /* sccsid */ scanb(c); asccs(curpos); curnode->addr = curaddr++; break; case 3: /* routine */ curnode->routine = True; curnode->org_pseudo = True; doramtable( ); break; } continue; } doseq: curnode->addr = curaddr++; if (seqpart(name) == False) continue; if (weitekpart( ) == False) continue; if (datapart( ) == False) continue; if (recpart( ) == False) continue; if (rampart( ) == False) continue; ptrpart( ); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -