forked from M-Labs/artiq
1
0
Fork 0

Use try..finally in compiler.targets.Target.link.

This commit is contained in:
whitequark 2015-07-30 10:33:54 +03:00
parent b0185f3917
commit 1e3911ed39
1 changed files with 14 additions and 15 deletions

View File

@ -8,7 +8,7 @@ llvm.initialize_all_asmprinters()
class Target: class Target:
""" """
A description of the target environment where the binaries A description of the target environment where the binaries
generaed by the ARTIQ compiler will be deployed. generated by the ARTIQ compiler will be deployed.
:var triple: (string) :var triple: (string)
LLVM target triple, e.g. ``"or1k"`` LLVM target triple, e.g. ``"or1k"``
@ -36,21 +36,20 @@ class Target:
f.flush() f.flush()
return f return f
output_file = make_tempfile() try:
cmdline = [self.triple + "-ld", "-shared", "--eh-frame-hdr", "-init", init_fn] + \ output_file = make_tempfile()
[make_tempfile(obj).name for obj in objects] + \ cmdline = [self.triple + "-ld", "-shared", "--eh-frame-hdr", "-init", init_fn] + \
["-o", output_file.name] [make_tempfile(obj).name for obj in objects] + \
linker = subprocess.Popen(cmdline, stderr=subprocess.PIPE) ["-o", output_file.name]
stdout, stderr = linker.communicate() linker = subprocess.Popen(cmdline, stderr=subprocess.PIPE)
if linker.returncode != 0: stdout, stderr = linker.communicate()
raise Exception("Linker invocation failed: " + stderr.decode('utf-8')) if linker.returncode != 0:
raise Exception("Linker invocation failed: " + stderr.decode('utf-8'))
output = output_file.read() return output_file.read()
finally:
for f in files: for f in files:
f.close() f.close()
return output
def compile(self, module): def compile(self, module):
"""Compile the module to a relocatable object for this target.""" """Compile the module to a relocatable object for this target."""