def parse_constant_buffer(node: ast.ClassDef) -> pysl.ConstantBuffer:
cbuffer = pysl.ConstantBuffer()
cbuffer.set_location(node)
cbuffer.name = node.name
cbuffer.constants = []
for decl_node in node.body:
if isinstance(decl_node, ast.AnnAssign):
assignment = parse_assignment(decl_node)
constant = pysl.Constant()
constant.set_location(decl_node)
constant.name = assignment.name
if assignment.value:
try:
constant.offset = int(assignment.value)
except ValueError:
error(loc(decl_node), "Expected numberic offset as argument")
assignment.value
constant.type = str_to_pysl_type(loc(decl_node), assignment.type)
cbuffer.constants.append(constant)
else:
error(loc(decl_node), "Unrecognized node inside ConstantBuffer: {0}".format(cbuffer.name))
for d in node.decorator_list:
decorator = parse_decorator(d)
if decorator.args:
try:
cbuffer.enforced_size = int(decorator.args[0])
except ValueError:
error(loc(d), "Expected integer argument to constructor indicating enforced size(in constants), but evaluated: {0}".format(decorator.args[0]))
return cbuffer
评论列表
文章目录