Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Windows compatibility #134

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion codegen/x86_64.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import operator
import json
import os
import io

instruction_set = read_instruction_set()
for instruction in instruction_set:
Expand Down Expand Up @@ -951,7 +952,7 @@ def is_label_branch(instruction_form):

def main(package_root="."):
for group, instruction_names in six.iteritems(instruction_groups):
with open(os.path.join(package_root, "peachpy", "x86_64", group + ".py"), "w") as out:
with io.open(os.path.join(package_root, "peachpy", "x86_64", group + ".py"), "w", encoding="utf-8") as out:
with CodeWriter() as code:
code.line("# This file is auto-generated by /codegen/x86_64.py")
code.line("# Instruction data is based on package opcodes %s" % opcodes.__version__)
Expand Down
3 changes: 2 additions & 1 deletion peachpy/arm/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# See license.rst for the full text of the license.

from __future__ import print_function
import io
import time

import peachpy.arm.instructions
Expand Down Expand Up @@ -117,7 +118,7 @@ def __exit__(self, exc_type, exc_value, traceback):
self.determine_live_registers(exclude_parameter_loads=True)

if self.dump_intermediate_assembly:
with open('%s.S' % self.symbol_name, "w") as intermediate_assembly_file:
with io.open('%s.S' % self.symbol_name, "w", encoding="utf-8") as intermediate_assembly_file:
for instruction in self.instructions:
if isinstance(instruction, Instruction):
consumed_registers = ", ".join(sorted(map(str, list(instruction.get_input_registers_list()))))
Expand Down
6 changes: 5 additions & 1 deletion peachpy/writer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# This file is part of PeachPy package and is licensed under the Simplified BSD license.
# See license.rst for the full text of the license.

import io

active_writers = []


Expand All @@ -15,7 +17,7 @@ def __init__(self, output_path):
def __enter__(self):
global active_writers
active_writers.append(self)
self.output_file = open(self.output_path, "w")
self.output_file = io.open(self.output_path, "w", encoding="utf-8")
return self

def __exit__(self, exc_type, exc_value, traceback):
Expand All @@ -27,6 +29,7 @@ def __exit__(self, exc_type, exc_value, traceback):
self.output_file = None
else:
import os
self.output_file.close()
os.unlink(self.output_file.name)
self.output_file = None
raise
Expand Down Expand Up @@ -110,6 +113,7 @@ def __exit__(self, exc_type, exc_value, traceback):
self.output_file = None
else:
import os
self.output_file.close()
os.unlink(self.output_file.name)
self.output_file = None
raise
Expand Down
5 changes: 3 additions & 2 deletions peachpy/x86_64/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from __future__ import absolute_import

import io

from peachpy import *
from peachpy.x86_64 import *
Expand Down Expand Up @@ -251,7 +252,7 @@ def main():
if options.dependencies_makefile_path:
dependencies_makefile_path = options.dependencies_makefile_path
if options.rtl_dump:
peachpy.x86_64.options.rtl_dump_file = open(options.rtl_dump, "w")
peachpy.x86_64.options.rtl_dump_file = io.open(options.rtl_dump, "w", encoding="utf-8")
if options.c_header_file:
writers.append(CHeaderWriter(options.c_header_file, options.input[0]))
if options.json_metadata_file:
Expand All @@ -275,7 +276,7 @@ def main():

dependencies = list(sorted(module_files))
dependencies.insert(0, options.input[0])
with open(dependencies_makefile_path, "w") as dependencies_makefile:
with io.open(dependencies_makefile_path, "w", encoding="utf-8") as dependencies_makefile:
dependencies_makefile.write(options.output + ": \\\n " + " \\\n ".join(dependencies) + "\n")

if __name__ == "__main__":
Expand Down