def generate_c_code(self, env, result): modules = [] self.find_referenced_modules(env, modules, {}) #code = Code.CCodeWriter(result.c_file) code = Code.CCodeWriter(StringIO()) code.h = Code.CCodeWriter(StringIO()) code.init_labels() self.generate_module_preamble(env, modules, code.h) code.putln("") code.putln("/* Implementation of %s */" % env.qualified_name) self.generate_const_definitions(env, code) self.generate_interned_name_decls(env, code) self.generate_py_string_decls(env, code) self.body.generate_function_definitions(env, code) self.generate_interned_name_table(env, code) self.generate_py_string_table(env, code) self.generate_typeobj_definitions(env, code) self.generate_method_table(env, code) self.generate_filename_init_prototype(code) self.generate_module_init_func(modules[:-1], env, code) self.generate_filename_table(code) self.generate_utility_functions(env, code) for module in modules: self.generate_declarations_for_module(module, code.h, definition=module is env) f = open_new_file(result.c_file) f.write(code.h.f.getvalue()) f.write("\n") f.write(code.f.getvalue()) f.close() result.c_file_generated = 1
def generate_h_code(self, env, result): public_vars_and_funcs = [] public_extension_types = [] for entry in env.var_entries: if entry.visibility == 'public': public_vars_and_funcs.append(entry) for entry in env.cfunc_entries: if entry.visibility == 'public': public_vars_and_funcs.append(entry) for entry in env.c_class_entries: if entry.visibility == 'public': public_extension_types.append(entry) if public_vars_and_funcs or public_extension_types: result.h_file = replace_suffix(result.c_file, ".h") result.i_file = replace_suffix(result.c_file, ".pxi") h_code = Code.CCodeWriter(open_new_file(result.h_file)) i_code = Code.PyrexCodeWriter(result.i_file) self.generate_extern_c_macro_definition(h_code) for entry in public_vars_and_funcs: h_code.putln("%s %s;" % (Naming.extern_c_macro, entry.type.declaration_code( entry.cname, dll_linkage="DL_IMPORT"))) i_code.putln("cdef extern %s" % entry.type.declaration_code(entry.cname, pyrex=1)) for entry in public_extension_types: self.generate_cclass_header_code(entry.type, h_code) self.generate_cclass_include_code(entry.type, i_code) h_code.putln("PyMODINIT_FUNC init%s(void);" % env.module_name)
def generate_c_code(self, env, result): modules = [] self.find_referenced_modules(env, modules, {}) #code = Code.CCodeWriter(result.c_file) code = Code.CCodeWriter(StringIO()) code.h = Code.CCodeWriter(StringIO()) code.init_labels() self.generate_module_preamble(env, modules, code.h) code.putln("") code.putln("/* Implementation of %s */" % env.qualified_name) self.generate_const_definitions(env, code) self.generate_interned_name_decls(env, code) self.generate_py_string_decls(env, code) self.body.generate_function_definitions(env, code) self.generate_interned_name_table(env, code) self.generate_py_string_table(env, code) self.generate_typeobj_definitions(env, code) self.generate_method_table(env, code) self.generate_filename_init_prototype(code) self.generate_module_init_func(modules[:-1], env, code) self.generate_filename_table(code) self.generate_utility_functions(env, code) for module in modules: self.generate_declarations_for_module(module, code.h, definition = module is env) f = open_new_file(result.c_file) f.write(code.h.f.getvalue()) f.write("\n") f.write(code.f.getvalue()) f.close() result.c_file_generated = 1
def generate_h_code(self, env, result): public_vars_and_funcs = [] public_extension_types = [] for entry in env.var_entries: if entry.visibility == 'public': public_vars_and_funcs.append(entry) for entry in env.cfunc_entries: if entry.visibility == 'public': public_vars_and_funcs.append(entry) for entry in env.c_class_entries: if entry.visibility == 'public': public_extension_types.append(entry) if public_vars_and_funcs or public_extension_types: result.h_file = replace_suffix(result.c_file, ".h") result.i_file = replace_suffix(result.c_file, ".pxi") h_code = Code.CCodeWriter(open_new_file(result.h_file)) i_code = Code.PyrexCodeWriter(result.i_file) self.generate_extern_c_macro_definition(h_code) for entry in public_vars_and_funcs: h_code.putln("%s %s;" % ( Naming.extern_c_macro, entry.type.declaration_code( entry.cname, dll_linkage = "DL_IMPORT"))) i_code.putln("cdef extern %s" % entry.type.declaration_code(entry.cname, pyrex = 1)) for entry in public_extension_types: self.generate_cclass_header_code(entry.type, h_code) self.generate_cclass_include_code(entry.type, i_code) h_code.putln("PyMODINIT_FUNC init%s(void);" % env.module_name)
def __init__(self, outfile_name): self.f = open_new_file(outfile_name) self.level = 0 self.bol = 1 self.marker = None self.label_counter = 1 self.error_label = None self.filename_table = {} self.filename_list = []
def open_listing_file(path, echo_to_stderr = 1): # Begin a new error listing. If path is None, no file # is opened, the error counter is just reset. global listing_file, num_errors, echo_file if path is not None: listing_file = open_new_file(path) else: listing_file = None if echo_to_stderr: echo_file = sys.stderr else: echo_file = None num_errors = 0
def __init__(self, outfile_name): self.f = open_new_file(outfile_name) self.level = 0