1: #include <stdio.h> 2: #include "def.h" 3: 4: char *typename[TYPENUM] = {"STLNVX", "IFVX", "DOVX", "IOVX", "FMTVX", 5: "COMPVX", "ASVX", "ASGOVX", "LOOPVX", "WHIVX", 6: "UNTVX", "ITERVX", "THENVX", "STOPVX", "RETVX", 7: "DUMVX", "GOVX", "BRKVX", "NXTVX", "SWCHVX", 8: "ACASVX", "ICASVX" 9: }; 10: int hascom[TYPENUM] = {2, 2, 2, 2, 2, 11: 2, 2, 2, 0, 0, 12: 0, 0, 2, 0, 0, 13: 0, 0, 0, 0, 2, 14: 2, 0 15: }; 16: 17: int nonarcs[TYPENUM] = {FIXED+3, FIXED+4, FIXED+2, FIXED+3, FIXED+2, 18: FIXED+2, FIXED+2, FIXED+2, FIXED+1, FIXED+1, 19: FIXED+1, FIXED+4, FIXED+3, FIXED, FIXED, 20: FIXED+2, FIXED+1, FIXED + 1, FIXED + 1, FIXED+3, 21: FIXED+4, FIXED+2 22: }; 23: 24: int childper[TYPENUM] = {0, 2, 1, 0, 0, 25: 0, 0, 0, 1, 1, 26: 1, 1, 1, 0, 0, 27: 1, 0, 0, 0, 1, 28: 2, 1 29: }; 30: 31: int arcsper[TYPENUM] = {1, 2, 2, 3, 0, 32: -(FIXED+1), 1, -(FIXED+1), 1, 1, 33: 1, 1, 2, 0, 0, 34: -FIXED, 1, 1, 1, -(FIXED+1), 35: 2, 1 36: }; 37: 38: VERT *arc(v,i) 39: VERT v; 40: int i; 41: { 42: ASSERT(DEFINED(v),arc); 43: ASSERT(0 <= i && i < ARCNUM(v), arc); 44: return(&graph[v][nonarcs[NTYPE(v)] + i ]); 45: } 46: 47: VERT *lchild(v,i) 48: VERT v; int i; 49: { 50: ASSERT(DEFINED(v),lchild); 51: ASSERT(0 <= i && i < childper[NTYPE(v)],lchild); 52: return(&graph[v][nonarcs[NTYPE(v)]-i-1]); 53: } 54: 55: int *vxpart(v,type,j) 56: VERT v; 57: int type,j; 58: { 59: ASSERT((NTYPE(v) == type) && (0 <= j) && (j < nonarcs[type] - FIXED), vxpart); 60: return(&graph[v][FIXED+j]); 61: } 62: 63: int *expres(v) 64: VERT v; 65: { 66: int ty; 67: ty = NTYPE(v); 68: ASSERT(ty == COMPVX || ty == ASGOVX || ty == ASVX || ty == SWCHVX || ty == ICASVX,expres); 69: return(&graph[v][FIXED]); 70: } 71: 72: int *negpart(v) 73: VERT v; 74: { 75: ASSERT(NTYPE(v) == IFVX || NTYPE(v) == ACASVX,negpart); 76: return(&graph[v][FIXED+1]); 77: } 78: 79: int *predic(v) 80: VERT v; 81: { 82: ASSERT(NTYPE(v) == IFVX || NTYPE(v) == ACASVX, predic); 83: return(&graph[v][FIXED]); 84: } 85: 86: int *level(v) 87: VERT v; 88: { 89: ASSERT(NTYPE(v) == GOVX || NTYPE(v) == BRKVX || NTYPE(v) == NXTVX, level); 90: return(&graph[v][FIXED]); 91: } 92: int *stlfmt(v,n) 93: VERT v; 94: int n; 95: { 96: ASSERT(NTYPE(v) == STLNVX || NTYPE(v) == FMTVX,stlfmt); 97: return(&graph[v][FIXED + n]); 98: } 99: 100: create(type,arcnum) 101: int type, arcnum; 102: { 103: int i, *temp, wds; 104: if (nodenum >= maxnode) 105: { 106: maxnode += 100; 107: temp=realloc(graph,maxnode*sizeof(*graph)); 108: free(graph); 109: graph=temp; 110: } 111: wds = nonarcs[type] + arcnum; 112: graph[nodenum] = galloc(sizeof(*graph) * wds); 113: for (i = 0; i < wds; i++) graph[nodenum][i] = 0; 114: NTYPE(nodenum) = type; 115: if (arcsper[type] < 0) 116: ARCNUM(nodenum) = arcnum; 117: 118: return(nodenum++); 119: }