scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

proc.c (1898B)


      1 static char sccsid[] = "@(#) ./as/target/i386/proc.c";
      2 
      3 #include <stdlib.h>
      4 
      5 #include "../../../inc/scc.h"
      6 #include "../../as.h"
      7 #include "../x86/proc.h"
      8 
      9 void
     10 iarch(void)
     11 {
     12 	static struct {
     13 		char *name;
     14 		char type;
     15 	} regs[] = {
     16 		"CS", AREG_CS,
     17 		"DS", AREG_DS,
     18 		"SS", AREG_SS,
     19 		"ES", AREG_ES,
     20 		"FS", AREG_FS,
     21 		"GS", AREG_GS,
     22 
     23 		"AX", AREG_AX,
     24 		"AL", AREG_AL,
     25 		"AH", AREG_AH,
     26 		"EAX", AREG_EAX,
     27 
     28 		"BC", AREG_BX,
     29 		"BL", AREG_BL,
     30 		"BH", AREG_BH,
     31 		"EBX", AREG_EBX,
     32 
     33 		"CX", AREG_CX,
     34 		"CL", AREG_CL,
     35 		"CH", AREG_CH,
     36 		"ECX", AREG_ECX,
     37 
     38 		"DX", AREG_DX,
     39 		"DL", AREG_DL,
     40 		"DH", AREG_DH,
     41 		"EDX", AREG_EDX,
     42 
     43 		"SI", AREG_SI,
     44 		"ESI", AREG_ESI,
     45 		"DI", AREG_DI,
     46 		"EDI", AREG_EDI,
     47 
     48 		"SP", AREG_SP,
     49 		"ESP", AREG_ESP,
     50 
     51 		"BP", AREG_BP,
     52 		"EBP", AREG_EBP,
     53 
     54 		"R0", AREG_R0,
     55 		"MM0", AREG_MM0,
     56 		"R1", AREG_R1,
     57 		"MM1", AREG_MM1,
     58 		"R2", AREG_R2,
     59 		"MM2", AREG_MM2,
     60 		"R3", AREG_R3,
     61 		"MM3", AREG_MM3,
     62 		"R4", AREG_R4,
     63 		"MM4", AREG_MM4,
     64 		"R5", AREG_R5,
     65 		"MM5", AREG_MM5,
     66 		"R6", AREG_R6,
     67 		"MM6", AREG_MM6,
     68 		"R7", AREG_R7,
     69 		"MM7", AREG_MM7,
     70 
     71 		"XMM0", AREG_XMM0,
     72 		"XMM1", AREG_XMM1,
     73 		"XMM2", AREG_XMM2,
     74 		"XMM3", AREG_XMM3,
     75 		"XMM4", AREG_XMM4,
     76 		"XMM5", AREG_XMM5,
     77 		"XMM6", AREG_XMM6,
     78 		"XMM7", AREG_XMM7,
     79 
     80 		"YMM0", AREG_YMM0,
     81 		"YMM1", AREG_YMM1,
     82 		"YMM2", AREG_YMM2,
     83 		"YMM3", AREG_YMM3,
     84 		"YMM4", AREG_YMM4,
     85 		"YMM5", AREG_YMM5,
     86 		"YMM6", AREG_YMM6,
     87 		"YMM7", AREG_YMM7,
     88 
     89 		"MXCSR", AREG_MXCSR,
     90 
     91 		NULL
     92 	}, *bp;
     93 
     94 	for (bp = regs; bp->name; ++bp) {
     95 		Symbol *sym = lookup(bp->name, TREG);
     96 		sym->argtype = bp->type;
     97 	}
     98 }
     99 
    100 int
    101 match(Op *op, Node **args)
    102 {
    103 	char *p;
    104 	int a, olda;
    105 
    106 	if (!op->args)
    107 		return args == NULL;
    108 
    109 	for (p = op->args; *p; ++p) {
    110 		if (*p != AREP)
    111 			a = *p;
    112 		else
    113 			--p;
    114 
    115 		switch (a) {
    116 		case AIMM8:
    117 		case AIMM16:
    118 		case AIMM32:
    119 		case AIMM64:
    120 		case AREG_AL:
    121 		case AREG_AH:
    122 		case AREG_AX:
    123 		case AREG_EAX:
    124 		default:
    125 			abort();
    126 		}
    127 	}
    128 	return 1;
    129 }