def cloneResultOperator(n,r): c=n.cloneNode(1) # replace Result child append the current result for d in DomUtils.childrenWithName(c,"Result"): c.removeChild(d) c.appendChild(r.cloneNode(1)) c.setAttribute('syntax','Function') c.setAttribute('exec','DOUBLE') # HACK HACK mrf attr is not in the DTD c.setAttribute('mrf',n.getAttribute('name')) c.setAttribute('name',n.getAttribute('name')+r.getAttribute('functionSuffix')) return c
def __init__(self, xmlFile): root = pcrxml.readDom(xmlFile) # put all operations in list assert root.nodeName == 'Operations' self.operations = DomUtils.childrenWithName(root,'Operation') self.automatic = [ "SameUn", "SameBin", "DiffBin","DiffUn"] self.pointCode = [ "SameUn", "SameBin", "DiffBin","DiffUn"] # already supported in generation self.supported = self.automatic + [ "Manual" ] self.onExec = ['GLOBAL', 'MRF', 'DOUBLE', 'Direct' ] self.d_outputs = [] self.foArInc=self.output("calc_fopointarrayimpl.inc") self.biInc=self.output("calc_builtinops.inc") self.pntImplH=self.output("calc_fopointimpl.h") self.pntImplH.write(""" #ifndef INCLUDED_MATHX #include "mathx.h" #define INCLUDED_MATHX #endif #ifndef INCLUDED_APPARGS #include "appargs.h" #define INCLUDED_APPARGS #endif #ifndef INCLUDED_COM_MATH #include "com_math.h" #define INCLUDED_COM_MATH #endif #ifndef INCLUDED_CSTDLIB #include <cstdlib> #define INCLUDED_CSTDLIB #endif #ifndef INCLUDED_CALC_FOPOINTSPECIAL #include "calc_fopointspecial.h" #define INCLUDED_CALC_FOPOINTSPECIAL #endif #ifndef INCLUDED_CALC_FOPOINT #include "calc_fopoint.h" #define INCLUDED_CALC_FOPOINT #endif #ifndef INCLUDED_BOOST_MATH_SPECIAL_FUNCTIONS_ROUND #include <boost/math/special_functions/round.hpp> #define INCLUDED_BOOST_MATH_SPECIAL_FUNCTIONS_ROUND #endif """) self.pntImplH.write("\nnamespace calc {") self.pntImplH.write("\nnamespace point {")
def __init__(self, e): assert e.nodeName in ['Result', 'Input'] self.d_argTypeSet = set() self.d_repeat = "false" self.d_st = "ST_NON" self.d_result = e.nodeName == 'Result' self.d_vector = 0 if not DomUtils.onlyChildWithName(e, "Field"): if DomUtils.onlyChildWithName(e, "Table"): self.d_vs = "VS_TABLE" if DomUtils.onlyChildWithName(e, "IndexTable"): self.d_vs = "VS_INDEXTABLE" if DomUtils.onlyChildWithName(e, "TimeSeries"): self.d_vs = "VS_TSS" if DomUtils.onlyChildWithName(e, "MapStack"): self.d_vs = "VS_MAPSTACK" return # from DataType's Field child element assert DomUtils.onlyChildWithName(e, "Field") f = DomUtils.onlyChildWithName(e, "Field") if e.hasAttribute("repeat"): self.d_repeat = e.getAttribute("repeat") stMap = { 'Yes': 'ST_SPATIAL', 'Non': 'ST_NONSPATIAL', 'Either': 'ST_EITHER' } self.d_st = stMap[f.getAttribute('spatial')] self.d_vs = "VS_" argTypeMap = { 'S': 'REAL4', 'D': 'REAL4', 'N': 'INT4', 'O': 'INT4', 'B': 'UINT1', 'L': 'UINT1' } for vs in DomUtils.childrenWithName(f, "DataType"): char1 = vs.getAttribute("value")[0] self.d_vs = self.d_vs + char1 self.d_argType = argTypeMap[char1] self.d_argTypeSet.add(self.d_argType) a = e.getAttribute("contextName") self.d_vector = a.find("[]") != -1 self.d_vectorName = a
def generateFunctionTable(self): def insertEntry(name): g.write('{"%s",%s},' % (name,opEnum(name))) g=self.output('calc_functiontable.h') g.write('struct FuncNameOpcode {\n'+\ ' const char *d_name;\n' +\ ' MAJOR_CODE d_op;\n' +\ '};\n' +\ 'static FuncNameOpcode funcName2OpCode[] = {' ) for n in self.operations: if (n.getAttribute('syntax') == 'Function'): insertEntry(implName(n)) if (n.getAttribute('syntax') == 'MRF'): mrf = DomUtils.childrenWithName(n,'Result') for f in mrf: assert f.hasAttribute('functionSuffix') insertEntry(implName(n)+f.getAttribute('functionSuffix')) # "",OP_ILL used as a terminate indication g.write('{"",OP_ILL}};')
def __init__(self,e): assert e.nodeName in [ 'Result','Input' ] self.d_argTypeSet = set() self.d_repeat = "false" self.d_st = "ST_NON" self.d_result = e.nodeName == 'Result' self.d_vector = 0 if not DomUtils.onlyChildWithName(e,"Field"): if DomUtils.onlyChildWithName(e,"Table"): self.d_vs="VS_TABLE" if DomUtils.onlyChildWithName(e,"IndexTable"): self.d_vs="VS_INDEXTABLE" if DomUtils.onlyChildWithName(e,"TimeSeries"): self.d_vs="VS_TSS" if DomUtils.onlyChildWithName(e,"MapStack"): self.d_vs="VS_MAPSTACK" return # from DataType's Field child element assert DomUtils.onlyChildWithName(e,"Field") f = DomUtils.onlyChildWithName(e,"Field") if e.hasAttribute("repeat"): self.d_repeat=e.getAttribute("repeat"); stMap={ 'Yes':'ST_SPATIAL','Non':'ST_NONSPATIAL','Either':'ST_EITHER'} self.d_st=stMap[f.getAttribute('spatial')] self.d_vs="VS_"; argTypeMap={ 'S':'REAL4','D':'REAL4','N':'INT4','O':'INT4','B':'UINT1','L':'UINT1'} for vs in DomUtils.childrenWithName(f,"DataType"): char1 =vs.getAttribute("value")[0] self.d_vs=self.d_vs+char1 self.d_argType = argTypeMap[char1] self.d_argTypeSet.add(self.d_argType) a=e.getAttribute("contextName") self.d_vector=a.find("[]") != -1 self.d_vectorName=a;
def generateMajor(self): class OpCode: def __init__(s,g): s.opCode=0 s.g = g; def write(s,opName,sep=","): s.g.write("%s=%d%s" % (opEnum(opName),s.opCode,sep)) s.opCode=s.opCode+1 g=self.output('major_op.h') c=OpCode(g) g.write('typedef enum MAJOR_CODE {') c.write('NOP'); for n in self.operations: if (n.getAttribute('syntax')!='MRF'): c.write(implName(n)) else: c.write(implName(n)+'_MRF') mrf = DomUtils.childrenWithName(n,'Result') for f in mrf: assert f.hasAttribute('functionSuffix') c.write(implName(n)+f.getAttribute('functionSuffix')) # OP_ILL used in conversion table c.write('ILL','} MAJOR_CODE;');
def generateOperationsInit(self): def syntax(o): return \ { 'Function' : 'FUNC','Operator':'OP','MRF':'MRF','None':'NONE' }\ [o.getAttribute('syntax')] def commutative(o): return o.getAttribute('commutative') def inputTailRepeat(o): return o.getAttribute('inputTailRepeat') # write single operator info def operator(g,n): name=n.getAttribute('name') opCode = opEnum(implName(n)) if (exec_(n) == 'MRF'): name=name+'_mrf' opCode=opEnum(name) iOpImpl="0" # # FTTB, some not implemented yet, hence if: if DomUtils.childInNameSet(n, self.supported) != None or \ exec_(n) in self.onExec: biName=implName(n) if exec_(n) == 'MRF': biName=biName+"_mrf" iOpImpl= '&builtIn_%s' % biName p=DomUtils.childInNameSet(n, self.pointCode) # mark by setting the domain arg to setPointOn setPointOn="" if p != None and p.hasAttribute("function") and name not in [ "sin", "cos", "tan" ]: setPointOn=self.domainIll(p) if implName(n) == "ifthenelse": setPointOn="noDomainIll" tail= int(inputTailRepeat(n)) if (tail > 0): assert tail <= len(DomUtils.childrenInNameSet(n,["Input"])) g.write('{IOpImpl *i= %s;' % iOpImpl) g.write(' Operator *c= new Operator(') g.write(''' "%s","%s",%s, SYNTAX_%s, EXEC_TYPE_%s, i,%s,%s);''' % (name,implName(n),opCode,syntax(n),exec_(n),commutative(n),tail)) if setPointOn != "": g.write(' c->setPointOn(%s);' % setPointOn) for f in DomUtils.childrenInNameSet(n,["Input"]): g.write(' c->pushBackInput(%s);' % pcrxml.DataType(f).arg()) for f in DomUtils.childrenInNameSet(n,["Result"]): g.write(' c->pushBackResult(%s);' % pcrxml.DataType(f).str()) g.write(' add(c);') g.write('}') def cloneResultOperator(n,r): c=n.cloneNode(1) # replace Result child append the current result for d in DomUtils.childrenWithName(c,"Result"): c.removeChild(d) c.appendChild(r.cloneNode(1)) c.setAttribute('syntax','Function') c.setAttribute('exec','DOUBLE') # HACK HACK mrf attr is not in the DTD c.setAttribute('mrf',n.getAttribute('name')) c.setAttribute('name',n.getAttribute('name')+r.getAttribute('functionSuffix')) return c g=self.output('operationsInit.inc') for n in self.operations: operator(g,n) self.operationImpl(n) if (exec_(n) == 'MRF'): oneOf = [] for r in DomUtils.childrenWithName(n,"Result"): c = cloneResultOperator(n,r) operator(g,c) self.operationImpl(c) oneOf.append(opEnum(implName(c))) assert len(oneOf)==2, " for %s len(oneOf)==%d" % (implName(n),len(oneOf)) g.write('add(%s_MRF,%s,%s);' % \ ( opEnum(implName(n)),oneOf[0],oneOf[1]))