Esempio n. 1
0
  def __init__(self, declaration, template_count=0):
    super(DeclarationSerializer, self).__init__()
    gu.inherit(self, declaration)

    self.template_count = template_count
    self.serializers = [ ParameterSerializer(p) for p in self.parameters ]
    self.function_name = self.function.name

    self.outtype = self.output.typename
    if self.outtype == 'void':
      self.assign = ''
      self.define_returns = ''
      self.declare_returns = ''
    else:
      self.assign = '%(typename)s %(name)s = ' % self.output.__dict__
      self.define_returns = 'return %(name)s;' % self.output.__dict__
      self.declare_returns = 'return'

    if self.has_cardinality:
      self.declare_prefix = 'template< std::uint8_t const Cardinality >\n'
      self.declare_suffix = ''
      self.define_prefix = 'template< >\n'
      self.define_suffix = '< %d >' % self.cardinality;
    elif self.has_dimension:
      self.declare_prefix = 'template< std::uint8_t const Dimension >\n'
      self.declare_suffix = ''
      self.define_prefix = 'template< >\n'
      self.define_suffix = '< %d >' % self.dimension;
    else:
      self.declare_prefix = ''
      self.declare_suffix = ''
      self.define_prefix = ''
      self.define_suffix = ''
Esempio n. 2
0
  def __init__(self, parameter, as_template=False):
    super(ParameterSerializer, self).__init__()
    gu.inherit(self, parameter)

    self.as_template = as_template

    self.uncamelname = gu.uncamel(self.name)
    self.name = self.uncamelname
Esempio n. 3
0
  def __init__(self, function):
    super(FunctionSerializer, self).__init__()
    gu.inherit(self, function)

    self.serializers = [ DeclarationSerializer(d) for d in self.declarations ]
    self.serializers += [ DeclarationSerializer(d, len(d.template_parameters)) for d in self.declarations if len(d.template_parameters) > 0 ]
    self.template_counts = set([ len(s.typenames()) for s in self.serializers ])

    self.comments = ''
Esempio n. 4
0
    def __init__(self, library, node, is_output=False):
        gu.inherit(self, node)

        self.name = gu.uncamel(self.name)
        self.is_template, self.tpl_name = library.template(self, is_output)
        self.hardcoded = None

        if self.typename.endswith("boolean"):
            self.type = "bool"

        self.typename = self.type
        self.typename = re.sub(r"(u?)int(\d+)", r"gtulu::\1int\2_t", self.typename)
        self.typename = re.sub(r"(u?)float(\d+)", r"gtulu::\1float\2_t", self.typename)
        # self.typename = re.sub(r'char const\* const\*', r'std::vector< std::string > const&', self.typename)
        # self.typename = re.sub(r'char const\*', r'std::string const&', self.typename)

        if self.typename == "char const*":
            self.typename = "std::string const&"

        if "const" not in self.typename and "*" not in self.typename and not is_output:
            self.typename = "%s const" % self.typename

        if self.is_template:
            self.typename = "gtulu::constant_base const&"
Esempio n. 5
0
  def __init__(self, library):
    super(LibrarySerializer, self).__init__()
    gu.inherit(self, library)

    self.serializers = [ FunctionSerializer(f) for f in sorted(self.functions.values(), key=lambda v: v.name) ]
Esempio n. 6
0
  def __init__(self, parameter):
    super(ParameterSerializer, self).__init__()
    gu.inherit(self, parameter)

    self.uncamelname = gu.uncamel(self.name)
    self.name = self.uncamelname
Esempio n. 7
0
  def __init__(self, function):
    super(FunctionSerializer, self).__init__()
    gu.inherit(self, function)

    self.serializers = [ DeclarationSerializer(d) for d in self.declarations ]
    self.comments = ''
Esempio n. 8
0
    def __init__(self, library, node):
        gu.inherit(self, node)

        super(Declaration, self).__init__(library.prefixes, library.suffixes)

        self.output = Parameter(library, node.children[0], True)
        self.parameters = [Parameter(library, p) for p in node.children[1:]]

        self.template_parameters = [p for p in self.parameters if p.is_template]
        self.not_template_parameters = [p for p in self.parameters if not p.is_template]

        self.has_template = len(self.template_parameters) > 0
        self.has_output = self.output.typename != "void"

        self.function = self.new_name
        if "matrix" in self.new_name:
            self.cardinality = re.search(r"_(?P<card>\d+(?:x\d+)?)(_|$)", self.new_name)
            if self.cardinality is not None:
                self.cardinality = self.cardinality.group("card")
                self.function = re.sub(r"_matrix_\d+(?:x\d+)?(?P<end>_|$)", "\g<end>", self.new_name)

                if "x" not in self.cardinality:
                    self.cardinality = self.cardinality + "x" + self.cardinality
            else:
                self.cardinality = 0

        else:
            self.cardinality = re.search(r"_(?P<card>\d+)(_|$)", self.new_name)
            if self.cardinality is not None:
                self.cardinality = self.cardinality.group("card")
                self.function = re.sub(r"_\d+(?P<end>_|$)", "\g<end>", self.new_name)
            else:
                self.cardinality = 0

        self.has_cardinality = False
        if self.cardinality > 0:
            params = [p for p in self.parameters if "*" in p.typename]
            if len(params) == 1:
                p = params[0]
                p.typename = p.typename.replace(" const*", "")

                if "x" in self.cardinality:
                    cardinality = self.cardinality.split("x")
                    p.typename = "gtulu::mat%s< %s > const&" % (self.cardinality, p.typename)

                else:
                    p.typename = "gtulu::vec%s< %s > const&" % (self.cardinality, p.typename)

                for o in self.parameters:
                    if o.typename == "bool const" and o.name == "transpose":
                        o.hardcoded = "false"

                    if o.typename == "gtulu::int32_t const" and o.name == "count":
                        o.hardcoded = "values.size()"
                        p.typename = "std::vector< %s > const&" % (p.typename.replace(" const&", ""))
                        p.name = "values"

        self.has_dimension = False
        self.dimension = re.search(r"_(?P<dim>\d+)d(_|$)", self.new_name)
        if self.dimension is not None:
            self.dimension = int(self.dimension.group("dim"))
        else:
            self.dimension = 0

        if self.dimension > 0 and "framebuffer_texture" in self.function:
            self.has_dimension = True

        self.function = re.sub(r"_\d+d(?P<end>_|$)", "\g<end>", self.function)