/* * Usage: showexports libName type-expression * Example: showexports libaldor.al 'List(Integer)' */ int main(int argc, char *argv[]) { osInit(); sxiInit(); keyInit(); ssymInit(); dbInit(); stabInitGlobal(); tfInit(); foamInit(); optInit(); tinferInit(); pathInit(); sposInit(); ablogInit(); comsgInit(); macexInitFile(); comsgInit(); scobindInitFile(); stabInitFile(); fileAddLibraryDirectory("."); String archive = argv[1]; String expression = argv[2]; scmdHandleLibrary("LIB", archive); AbSyn ab = shexpParse(expression); Stab stab = stabFile(); Syme syme = stabGetArchive(symInternConst("LIB")); AbSyn arAbSyn = abNewId(sposNone, symInternConst("LIB")); stabImportTForm(stab, tiGetTForm(stab, arAbSyn)); abPutUse(ab, AB_Use_Value); scopeBind(stab, ab); typeInfer(stab, ab); TForm tf = tiGetTForm(stab, ab); SymeList list = tfStabGetDomImports(stab, tf); for (; list != listNil(Syme); list = cdr(list)) { Syme syme = car(list); aprintf("%s %d %d %s\n", symeString(syme), symeDefnNum(syme), symeConstNum(syme), tfPretty(symeType(syme))); } scobindFiniFile(); stabFiniFile(); comsgFini(); macexFiniFile(); }
/* * This function may be invoked during genfoam as well as during * the optimisation phases. During genfoam we never want to change * the const number associated with a given syme: if we try to do * so, it means that the syme is conditional with more than one * implementation and isn't "const". During optimisation however, * we must allow the const num to be modified. * * unique => changing const num means clobber it * ~unique => changing const num works */ void genSetConstNum(Syme syme, int defineIdx, UShort index, Bool unique) { Length dindex = symeDefnNum(syme); ULong cnum = symeConstNum(syme); /* 0 <= cnum <= 0xffff */ /* Old way */ assert(dindex < gen0SymeTableC); /* * Conditional symes with multiple implementations are not * const. We detect this here if we see a syme whose const * num is already set and isn't `index', and `unique' is * true. Conditional symes with one possible implementation * are okay: if the type checker allowed the call then we * can inline it. */ if (unique && (cnum >= 0) && (cnum <= 0x3fff) && (cnum != index)) { /* * Conditional syme with multiple implementations. * We have to record the fact that we have stomped * on the stored const num otherwise the next time * we got here we would think the syme was okay. */ symeClrConstNum(syme); symeSetMultiCond(syme); gen0SymeTableV[dindex] = (Syme)NULL; } else if (!symeIsMultiCond(syme)) { symeSetConstNum(syme, (int) index); gen0SymeTableV[dindex] = syme; } /* New way */ #if 0 SImpl nimpl; if (defineIdx != -1) { gen0DefSymeTableV[defineIdx] = syme; } if (symeImpl(syme)) { implSetConstNum(symeImpl(syme), defineIdx, index); } #endif }
void otTransferFoamInfoToSyme(Syme syme, Foam unit) { Foam def, prog; int cNum = symeConstNum(syme); if (symeConstLib(syme) == NULL && cNum != SYME_NUMBER_UNASSIGNED) { def = unit->foamUnit.defs->foamDDef.argv[cNum]; prog = def->foamDef.rhs; if (foamTag(prog) == FOAM_Prog && foamProgHasNoEnvUse(prog)) otSymeConstSetEnvIndep(syme); else otSymeConstClrEnvIndep(syme); } }
Bool genHasConstNum(Syme syme) { Length dindex; if (symeExtension(syme)) syme = symeExtension(syme); if (symeHasConstNum(syme) && symeConstLib(syme) != NULL) return true; dindex = symeDefnNum(syme); if (0 < dindex && dindex < gen0SymeTableC && gen0SymeTableV[dindex]) { symeSetConstNum(syme, symeConstNum(gen0SymeTableV[dindex])); symeSetHashNum(syme, symeHashNum(gen0SymeTableV[dindex])); symeSetDVMark(syme, symeDVMark(gen0SymeTableV[dindex])); } return symeHasConstNum(syme); }
/* * This is a debugging function which allows the contents * of gen0SymeTable to be seen. This table provides a mapping * between constant numbers and definition numbers. */ void symeTablePrintDb(void) { int i; Syme syme; for (i = 0;i < gen0SymeTableC;i++) { syme = gen0SymeTableV[i]; if (syme) { AInt c = (AInt)-1; AInt d = symeDefnNum(syme); if (symeHasConstNum(syme)) c = symeConstNum(syme); (void)fprintf(dbOut, "[%2d]: ", i); (void)fprintf(dbOut, " (Const %2d, ", (int)c); (void)fprintf(dbOut, " Defn %2d) ", (int)d); symePrintDb(syme); } } }
UShort genGetConstNum(Syme syme) { return symeConstNum(syme); }
/* * Usage: showexports libName type-expression * Example: showexports libaldor.al 'List(Integer)' */ int main(int argc, char *argv[]) { osInit(); sxiInit(); keyInit(); ssymInit(); dbInit(); stabInitGlobal(); tfInit(); foamInit(); optInit(); tinferInit(); pathInit(); sposInit(); ablogInit(); comsgInit(); macexInitFile(); comsgInit(); scobindInitFile(); stabInitFile(); fileAddLibraryDirectory("."); String archive = argv[1]; String expression = argv[2]; scmdHandleLibrary("LIB", archive); AbSyn ab = shexpParse(expression); Stab stab = stabFile(); Syme syme = stabGetArchive(symInternConst("LIB")); AbSyn arAbSyn = abNewId(sposNone, symInternConst("LIB")); AbSyn boolean = abNewId(sposNone, symInternConst("Boolean")); stabImportTForm(stab, tiGetTForm(stab, arAbSyn)); stabImportTForm(stab, tiGetTForm(stab, boolean)); abPutUse(ab, AB_Use_Value); scopeBind(stab, ab); typeInfer(stab, ab); TForm tf = tiGetTForm(stab, ab); aprintf("Type: %s Cat: %d\n", tfPretty(tf), tfSatCat(tf)); if (tfSatDom(tf)) { SymeList list = tfGetCatExports(tf); aprintf("Category\n"); for (; list != listNil(Syme); list = cdr(list)) { Syme syme = car(list); aprintf("%5s %3d %s %pAbSynList\n", symeString(syme), symeHasDefault(syme), tfPretty(symeType(syme)), symeCondition(syme)); } } else { aprintf(">>> Exports\n"); SymeList list = tfStabGetDomImports(stab, tf); for (; list != listNil(Syme); list = cdr(list)) { Syme syme = car(list); aprintf("%s %d %d %s\n", symeString(syme), symeDefnNum(syme), symeConstNum(syme), tfPretty(symeType(syme))); } TQualList tqList; aprintf(">>> Cascades\n"); tqList = tfGetDomCascades(tf); for (; tqList != listNil(TQual); tqList = cdr(tqList)) { TQual tq = car(tqList); aprintf("--> %s\n", tfPretty(tqBase(tq))); } } scobindFiniFile(); stabFiniFile(); comsgFini(); macexFiniFile(); }