Consistent variable naming

This commit is contained in:
Sebastien Bourdeauducq 2014-09-13 19:32:21 +08:00
parent 71adcb74bf
commit 5c228f9114
8 changed files with 30 additions and 30 deletions

View File

@ -15,14 +15,14 @@ class Core:
self.core_com = core_com
def run(self, k_function, k_args, k_kwargs):
funcdef, rpc_map = inline(self, k_function, k_args, k_kwargs)
lower_units(funcdef, self.runtime_env.ref_period)
fold_constants(funcdef)
unroll_loops(funcdef, 50)
interleave(funcdef)
lower_time(funcdef, getattr(self.runtime_env, "initial_time", 0))
fold_constants(funcdef)
func_def, rpc_map = inline(self, k_function, k_args, k_kwargs)
lower_units(func_def, self.runtime_env.ref_period)
fold_constants(func_def)
unroll_loops(func_def, 50)
interleave(func_def)
lower_time(func_def, getattr(self.runtime_env, "initial_time", 0))
fold_constants(func_def)
binary = get_runtime_binary(self.runtime_env, funcdef)
binary = get_runtime_binary(self.runtime_env, func_def)
self.core_com.run(binary)
self.core_com.serve(rpc_map)

View File

@ -1,6 +1,6 @@
from artiq.py2llvm.module import Module
def get_runtime_binary(env, funcdef):
def get_runtime_binary(env, func_def):
module = Module(env)
module.compile_function(funcdef, dict())
module.compile_function(func_def, dict())
return module.emit_object()

View File

@ -18,8 +18,8 @@ def _gcd(a, b):
def init_module(module):
funcdef = ast.parse(inspect.getsource(_gcd)).body[0]
module.compile_function(funcdef, {"a": VInt(64), "b": VInt(64)})
func_def = ast.parse(inspect.getsource(_gcd)).body[0]
module.compile_function(func_def, {"a": VInt(64), "b": VInt(64)})
def _reduce(builder, a, b):

View File

@ -31,25 +31,25 @@ class Module:
self.finalize()
return self.env.emit_object()
def compile_function(self, funcdef, param_types):
ns = infer_types.infer_function_types(self.env, funcdef, param_types)
def compile_function(self, func_def, param_types):
ns = infer_types.infer_function_types(self.env, func_def, param_types)
retval = ns["return"]
function_type = lc.Type.function(retval.get_llvm_type(),
[ns[arg.arg].get_llvm_type() for arg in funcdef.args.args])
function = self.llvm_module.add_function(function_type, funcdef.name)
[ns[arg.arg].get_llvm_type() for arg in func_def.args.args])
function = self.llvm_module.add_function(function_type, func_def.name)
bb = function.append_basic_block("entry")
builder = lc.Builder.new(bb)
for arg_ast, arg_llvm in zip(funcdef.args.args, function.args):
for arg_ast, arg_llvm in zip(func_def.args.args, function.args):
arg_llvm.name = arg_ast.arg
for k, v in ns.items():
v.alloca(builder, k)
for arg_ast, arg_llvm in zip(funcdef.args.args, function.args):
for arg_ast, arg_llvm in zip(func_def.args.args, function.args):
ns[arg_ast.arg].auto_store(builder, arg_llvm)
visitor = ast_body.Visitor(self.env, ns, builder)
visitor.visit_statements(funcdef.body)
visitor.visit_statements(func_def.body)
if not tools.is_terminated(builder.basic_block):
if isinstance(retval, base_types.VNone):

View File

@ -109,5 +109,5 @@ def _interleave_stmts(stmts):
offset += len(new_stmts) - 1
def interleave(funcdef):
_interleave_stmts(funcdef.body)
def interleave(func_def):
_interleave_stmts(func_def.body)

View File

@ -42,9 +42,9 @@ class _TimeLowerer(ast.NodeTransformer):
return node
def lower_time(funcdef, initial_time):
_TimeLowerer().visit(funcdef)
funcdef.body.insert(0, ast.copy_location(
def lower_time(func_def, initial_time):
_TimeLowerer().visit(func_def)
func_def.body.insert(0, ast.copy_location(
ast.Assign(targets=[ast.Name("now", ast.Store())],
value=value_to_ast(int64(initial_time))),
funcdef))
func_def))

View File

@ -40,8 +40,8 @@ class _UnitsLowerer(ast.NodeTransformer):
return node
def lower_units(funcdef, ref_period):
def lower_units(func_def, ref_period):
if (not isinstance(ref_period, units.Quantity)
or ref_period.unit is not units.s_unit):
raise units.DimensionError("Reference period not expressed in seconds")
_UnitsLowerer(ref_period.amount).visit(funcdef)
_UnitsLowerer(ref_period.amount).visit(func_def)

View File

@ -78,10 +78,10 @@ class FunctionArrayTypesCase(unittest.TestCase):
class CompiledFunction:
def __init__(self, function, param_types):
module = Module()
funcdef = ast.parse(inspect.getsource(function)).body[0]
func_def = ast.parse(inspect.getsource(function)).body[0]
self.function, self.retval = module.compile_function(
funcdef, param_types)
self.argval = [param_types[arg.arg] for arg in funcdef.args.args]
func_def, param_types)
self.argval = [param_types[arg.arg] for arg in func_def.args.args]
self.ee = module.get_ee()
def __call__(self, *args):