Commit fc19af69 authored by Zachary Parks's avatar Zachary Parks
Browse files

Python API changes to allow variables in IRGenerator declarations



Signed-off-by: default avatarZachary Parks <1zp@ornl.gov>
parent 1c531f68
from _pyxacc import * from _pyxacc import *
import os, time, json import os, time, json
import platform import platform
import sys import sys, re
import sysconfig import sysconfig
import argparse import argparse
import inspect import inspect
...@@ -163,6 +163,9 @@ class DecoratorFunction(ABC): ...@@ -163,6 +163,9 @@ class DecoratorFunction(ABC):
self.__dict__.update(kwargs) self.__dict__.update(kwargs)
self.accelerator = None self.accelerator = None
self.src = '\n'.join(inspect.getsource(self.function).split('\n')[1:]) self.src = '\n'.join(inspect.getsource(self.function).split('\n')[1:])
self.processVariables()
compiler = getCompiler('xacc-py') compiler = getCompiler('xacc-py')
if self.accelerator == None: if self.accelerator == None:
if 'accelerator' in self.kwargs: if 'accelerator' in self.kwargs:
...@@ -186,7 +189,19 @@ class DecoratorFunction(ABC): ...@@ -186,7 +189,19 @@ class DecoratorFunction(ABC):
def overrideAccelerator(self, acc): def overrideAccelerator(self, acc):
self.accelerator = acc self.accelerator = acc
def processVariables(self):
g = re.findall('=(\w+)', self.src)
frame = inspect.currentframe()
for thing in g:
if thing in frame.f_back.f_locals['f'].__globals__:
if isinstance(frame.f_back.f_locals['f'].__globals__[thing], str):
real = "'" + frame.f_back.f_locals['f'].__globals__[thing] + "'"
else:
real = str(frame.f_back.f_locals['f'].__globals__[thing])
self.src = self.src.replace('='+thing, '='+real)
del frame
def nParameters(self): def nParameters(self):
return self.getFunction().nParameters() return self.getFunction().nParameters()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment