def compile_python_model( input_file, options={}, parameters={}, inputs={}, outputs={}, debug=False, profile=False, sn=0, ): generate_library() try: # Optimize for area parser = Parser(input_file, False, False, parameters) process = parser.parse_process() name = process.main.name + "_%u" % sn instructions = process.generate() instructions = expand_macros(instructions, parser.allocator) if "dump" in options: for i in instructions: print i debug = debug or ("debug" in options) profile = profile or ("profile" in options) model = generate_python_model( debug, input_file, name, instructions, parser.allocator, inputs, outputs, profile) return ( model, parser.allocator.input_names.values(), parser.allocator.output_names.values(), name ) except C2CHIPError as err: print "Error in file:", err.filename, "at line:", err.lineno print err.message sys.exit(-1)
def compile(c_buffer): input_file = open("main.c", 'w') input_file.write(c_buffer) input_file.close() parser = Parser("main.c", False, False, []) process = parser.parse_process() name = process.main.name instructions = process.generate() instructions = expand_macros(instructions, parser.allocator) output_file = StringIO.StringIO() inputs, outputs = generate_CHIP_area(input_file, name, instructions, output_file, parser.allocator, False) return output_file.getvalue()
def comp(input_file, options={}, parameters={}, sn=0): reuse = "no_reuse" not in options initialize_memory = "no_initialize_memory" not in options generate_library() try: # Optimize for area parser = Parser(input_file, reuse, initialize_memory, parameters) process = parser.parse_process() name = process.main.name + "_%s" % sn instructions = process.generate() instructions = expand_macros(instructions, parser.allocator) if "dump" in options: for i in instructions: print ( i.get("op", "-"), i.get("z", "-"), i.get("a", "-"), i.get("b", "-"), i.get("literal", "-"), i.get("trace"), ) output_file = name + ".v" output_file = open(output_file, "w") inputs, outputs = generate_CHIP_area( input_file, name, instructions, output_file, parser.allocator, initialize_memory, int(options.get("memory_size", 4096))) output_file.close() except C2CHIPError as err: print "Error in file:", err.filename, "at line:", err.lineno print err.message sys.exit(-1) return name, inputs, outputs, ""
def compile(c_buffer): input_file = open("main.c", 'w') input_file.write(c_buffer) input_file.close() parser = Parser("main.c", False, False, []) process = parser.parse_process() name = process.main.name instructions = process.generate() instructions = expand_macros(instructions, parser.allocator) output_file = StringIO.StringIO() inputs, outputs = generate_CHIP_area( input_file, name, instructions, output_file, parser.allocator, False) return output_file.getvalue()
def compile_python_model( input_file, options={}, parameters={}, inputs={}, outputs={}, debug=False, profile=False, sn=0, ): generate_library() try: # Optimize for area parser = Parser(input_file, False, False, parameters) process = parser.parse_process() name = process.main.name + "_%u" % sn instructions = process.generate() instructions = expand_macros(instructions, parser.allocator) if "dump" in options: for i in instructions: print i debug = debug or ("debug" in options) profile = profile or ("profile" in options) model = generate_python_model(debug, input_file, name, instructions, parser.allocator, inputs, outputs, profile) return (model, parser.allocator.input_names.values(), parser.allocator.output_names.values(), name) except C2CHIPError as err: print "Error in file:", err.filename, "at line:", err.lineno print err.message sys.exit(-1)
def _compile(chip_name, chip_id, input_file, options, parameters, reuse, initialize_memory, sn=0): if "is_asm" in options: name = chip_name + "_main" + "_%s" % sn allocator = Allocator(False) asm_program = get_instructions_from_asm(input_file, allocator, options) else: # Optimize for area parser = Parser(input_file, reuse, initialize_memory, parameters) allocator = parser.allocator process = parser.parse_process() name = chip_name + "_" + process.main.name + "_%s" % sn asm_program = process.generate() asm_program.program_instrs = expand_macros(asm_program.instructions, parser.allocator) if "dump" in options: print_instructions(sys.stdout, asm_program.instructions) if "dump_to" in options: with open(options["dump_to"], "w") as instruction_dump_file: print_instructions(instruction_dump_file, asm_program.instructions) asm_program.set_stack_size(options.get("stack_size", 300)) print "%s: used memory size: %s (stack: %s, globals: %s)" % ( chip_name, asm_program.memory_size_in_bytes, asm_program.stack_size_bytes, asm_program.globals_size_bytes) asm_program.set_names(chip_id, chip_name, name) asm_program.set_io_ports(allocator.input_names, allocator.output_names) return asm_program
def comp(input_file, options={}, parameters={}, sn=0): reuse = "no_reuse" not in options initialize_memory = "no_initialize_memory" not in options generate_library() try: # Optimize for area parser = Parser(input_file, reuse, initialize_memory, parameters) process = parser.parse_process() name = process.main.name + "_%s" % sn instructions = process.generate() instructions = expand_macros(instructions, parser.allocator) if "dump" in options: for i in instructions: print( i.get("op", "-"), i.get("z", "-"), i.get("a", "-"), i.get("b", "-"), i.get("literal", "-"), i.get("trace"), ) output_file = name + ".v" output_file = open(output_file, "w") inputs, outputs = generate_CHIP_area(input_file, name, instructions, output_file, parser.allocator, initialize_memory, options.get("memory_size", 4096)) output_file.close() except C2CHIPError as err: print "Error in file:", err.filename, "at line:", err.lineno print err.message sys.exit(-1) return name, inputs, outputs, ""
def comp(input_file, options=[]): reuse = "no_reuse" not in options initialize_memory = "no_initialize_memory" not in options try: if "speed" not in options: #Optimize for area parser = Parser(input_file, reuse, initialize_memory) process = parser.parse_process() name = process.main.name instructions = process.generate() instructions = cleanup_functions(instructions) instructions, registers = cleanup_registers( instructions, parser.allocator.all_registers) output_file = name + ".v" output_file = open(output_file, "w") inputs, outputs = generate_CHIP_area( input_file, name, instructions, output_file, registers, parser.allocator.memory_size_2, parser.allocator.memory_size_4, initialize_memory, parser.allocator.memory_content_2, parser.allocator.memory_content_4) output_file.close() else: #Optimize for speed parser = Parser(input_file, reuse, initialize_memory) process = parser.parse_process() name = process.main.name instructions = process.generate() instructions = cleanup_functions(instructions) instructions, registers = cleanup_registers( instructions, parser.allocator.all_registers) if "no_concurrent" in sys.argv: frames = [[i] for i in instructions] else: frames = parallelise(instructions) output_file = name + ".v" output_file = open(output_file, "w") inputs, outputs = generate_CHIP_speed( input_file, name, frames, output_file, registers, parser.allocator.memory_size_2, parser.allocator.memory_size_4, initialize_memory, parser.allocator.memory_content_2, parser.allocator.memory_content_4) output_file.close() except C2CHIPError as err: print "Error in file:", err.filename, "at line:", err.lineno print err.message sys.exit(-1) return name, inputs, outputs, ""
def comp(input_file, options=[]): reuse = "no_reuse" not in options initialize_memory = "no_initialize_memory" not in options try: if "speed" not in options: #Optimize for area parser = Parser(input_file, reuse, initialize_memory) process = parser.parse_process() name = process.main.name instructions = process.generate() instructions = cleanup_functions(instructions) instructions, registers = cleanup_registers(instructions, parser.allocator.all_registers) output_file = name + ".v" output_file = open(output_file, "w") inputs, outputs = generate_CHIP_area( input_file, name, instructions, output_file, registers, parser.allocator.memory_size_2, parser.allocator.memory_size_4, initialize_memory, parser.allocator.memory_content_2, parser.allocator.memory_content_4) output_file.close() else: #Optimize for speed parser = Parser(input_file, reuse, initialize_memory) process = parser.parse_process() name = process.main.name instructions = process.generate() instructions = cleanup_functions(instructions) instructions, registers = cleanup_registers(instructions, parser.allocator.all_registers) if "no_concurrent" in sys.argv: frames = [[i] for i in instructions] else: frames = parallelise(instructions) output_file = name + ".v" output_file = open(output_file, "w") inputs, outputs = generate_CHIP_speed( input_file, name, frames, output_file, registers, parser.allocator.memory_size_2, parser.allocator.memory_size_4, initialize_memory, parser.allocator.memory_content_2, parser.allocator.memory_content_4) output_file.close() generate_library() except C2CHIPError as err: print "Error in file:", err.filename, "at line:", err.lineno print err.message sys.exit(-1) return name, inputs, outputs, ""