def visit_function(name, ctype):
  global FUNCTIONS
  if should_ignore(name):
    return

  func_ctype = ctype.base_type()

  if name in MUST_WRAP:
    will_wrap = True
  
  else:
    will_wrap = will_wrap_function(
        func_ctype.ret_type, func_ctype.param_types)
    
    if will_wrap and func_ctype.is_variadic:
      will_wrap = must_wrap(
          [func_ctype.ret_type] + func_ctype.param_types)

    if will_wrap and has_extension_attribute(ctype, "deprecated"):
      will_wrap = False

  # put this before checking for things that we should ignore
  # so that these type-based rules propagate to the dll detach
  # stuff, where type info is not known.
  C("#ifndef CAN_WRAP_", name)
  C("#   define CAN_WRAP_", name, " ", int(will_wrap))
  C("#endif")

  if not will_wrap:
    C("DETACH(", name, ")")
    return

  # we don't want to add detach wrappers to these, but we do want
  # to detach on them. This is partially doing the work of the dll
  # detach thing, but also ignoring "hidden" versions of functions
  # that we already have, e.g. logf vs. __logf. 
  if name.startswith("__"):

    # TODO: is this check needed? It screws up wrapping for
    #       block_write_begin and __block_write_begin, which have
    #       different signatures in the kernel.
    
    if True: # if name[2:] not in FUNCTIONS:
      C("#if CAN_WRAP_", name)
      C("#   ifdef DETACH_ADDR_", name)
      C("        WRAP_FOR_DETACH(", name, ")")
      C("#   else")
      C("        TYPED_DETACH(", name, ")")
      C("#   endif")
      C("#endif")
    return

  C("#if CAN_WRAP_", name)
  if has_extension_attribute(ctype, "noreturn"):
    C("    DETACH(", name,")")
  else:
    C("    WRAP_FOR_DETACH(", name,")")
  C("#endif")
def methodical_compute_word(idx, word):
    #dont want anything different for first word
    if not idx or should_ignore(word): return word

    if not idx % 3:
        return get_synonym(word)

    elif not idx % 7:
        return get_definition(word)

    return word
Beispiel #3
0
  if last_param_ctype is va_list_ctype:
    VA_LIST_FUNCS.add(name)


if "__main__" == __name__:
  import sys
  
  with open(sys.argv[1]) as lines_:
    buff = "".join(lines_)
    tokens = CTokenizer(buff)
    parser = CParser()
    parser.parse(tokens)
    va_list = None
    try:
      va_list = parser.get_type("va_list", CTypeDefinition)
      va_list = va_list.base_type()
    except:
      pass

    OUT("/* Auto-generated wrappers. */")
    OUT("#define D(...) __VA_ARGS__ ")
    OUT("")
    for var, ctype in parser.vars():
      if not should_ignore(var) and var.startswith("v"):
        visit_possible_variadic_def(var, ctype.base_type(), va_list)

    for var, ctype in parser.vars():
      if not should_ignore(var):
        visit_var_def(var, ctype)
    if last_param_ctype is va_list_ctype:
        VA_LIST_FUNCS.add(name)


if "__main__" == __name__:
    import sys

    with open(sys.argv[1]) as lines_:
        buff = "".join(lines_)
        tokens = CTokenizer(buff)
        parser = CParser()
        parser.parse(tokens)
        va_list = None
        try:
            va_list = parser.get_type("va_list", CTypeDefinition)
            va_list = va_list.base_type()
        except:
            pass

        OUT("/* Auto-generated wrappers. */")
        OUT("#define D(...) __VA_ARGS__ ")
        OUT("")
        for var, ctype in parser.vars():
            if not should_ignore(var) and var.startswith("v"):
                visit_possible_variadic_def(var, ctype.base_type(), va_list)

        for var, ctype in parser.vars():
            if not should_ignore(var):
                visit_var_def(var, ctype)
def visit_function(name, ctype):
  global FUNCTIONS
  if should_ignore(name):
    return

  func_ctype = ctype.base_type()

  will_wrap = True
  #if False:
  #  if name in MUST_WRAP:
  #    will_wrap = True
  #  
  #  else:
  #    will_wrap = will_wrap_function(
  #        func_ctype.ret_type, func_ctype.param_types)
  #    
  #      # kthread_create_on_node is an issue here...
  #      #if has_extension_attribute(ctype, "printf"):
  #      #  will_wrap = False

  if will_wrap and func_ctype.is_variadic:
    will_wrap = must_wrap(
        [func_ctype.ret_type] + func_ctype.param_types)

  if will_wrap and has_extension_attribute(ctype, "deprecated"):
    will_wrap = False

  # put this before checking for things that we should ignore
  # so that these type-based rules propagate to the dll detach
  # stuff, where type info is not known.
  C("#ifndef CAN_WRAP_", name)
  C("#   define CAN_WRAP_", name, " ", int(will_wrap))
  C("#endif")

  if not will_wrap:
    C("DETACH(", name, ")")
    return

  # we don't want to add detach wrappers to these, but we do want
  # to detach on them. This is partially doing the work of the dll
  # detach thing, but also ignoring "hidden" versions of functions
  # that we already have, e.g. logf vs. __logf. 
  if name.startswith("__") and "__libc" not in name:

    # TODO: is this check needed? It screws up wrapping for
    #       block_write_begin and __block_write_begin, which have
    #       different signatures in the kernel.
    
    if True: # if name[2:] not in FUNCTIONS:
      C("#if CAN_WRAP_", name)
      C("#   ifdef DETACH_ADDR_", name)
      C("        WRAP_FOR_DETACH(", name, ")")
      C("#   else")
      C("        TYPED_DETACH(", name, ")")
      C("#   endif")
      C("#endif")
    return

  C("#if CAN_WRAP_", name)
  if has_extension_attribute(ctype, "noreturn"):
    C("    DETACH(", name,")")
  else:
    C("    WRAP_FOR_DETACH(", name,")")
  C("#endif")