ejschwartz commited on
Commit
ce7ca57
·
1 Parent(s): 3c8598e

Try to fix errors

Browse files
Files changed (1) hide show
  1. main.py +35 -41
main.py CHANGED
@@ -65,39 +65,35 @@ def compile(compiler, flags, source):
65
  )
66
  compile_output = result.stdout + result.stderr
67
 
68
- # Create a temporary file for the raw bytes
69
- with tempfile.NamedTemporaryFile(suffix=".raw", delete=True) as raw_bytes_file:
70
- subprocess.run(
71
- [
72
- "objcopy",
73
- "--only-section",
74
- ".text",
75
- # XXX in reality we should probably look at the sections
76
- "--only-section",
77
- ".text.*",
78
- "-O",
79
- "binary",
80
- temp_o_file_name,
81
- raw_bytes_file.name,
82
- ]
83
- )
84
- compiled_bytes = raw_bytes_file.read()
85
-
86
- # Disassemble the object file
87
- disassembly = subprocess.run(
88
- ["objdump", "-dr", temp_o_file_name], capture_output=True, text=True
89
- ).stdout
90
- disassembly = trim_objdump(disassembly)
91
-
92
- # Relocs
93
- # relocs = subprocess.run(
94
- # ["objdump", "-r", temp_o_file_name],
95
- # capture_output=True,
96
- # text=True
97
- # ).stdout
98
- # relocs = trim(relocs, 3)
99
 
100
- json_relocs = subprocess.run(
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
101
  [
102
  "llvm-readobj-19",
103
  "--elf-output-style=JSON",
@@ -106,17 +102,15 @@ def compile(compiler, flags, source):
106
  ],
107
  capture_output=True,
108
  text=True,
109
- ).stdout
110
- json_relocs = json.loads(json_relocs)
111
- json_relocs = json_relocs[0]["Relocations"]
112
- json_relocs = [r["Relocation"] for d in json_relocs for r in d["Relocs"]]
113
- # Filter out .text
114
- json_relocs = [r for r in json_relocs if r["Symbol"]["Name"] != ".text"]
115
-
116
- if result.returncode == 0:
117
  return json_relocs, compiled_bytes, compile_output, disassembly
118
  else:
119
- return None, None, compile_output, disassembly
120
 
121
 
122
  def _reloc_type2size(s):
 
65
  )
66
  compile_output = result.stdout + result.stderr
67
 
68
+ if result.returncode == 0:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
 
70
+ # Create a temporary file for the raw bytes
71
+ with tempfile.NamedTemporaryFile(suffix=".raw", delete=True) as raw_bytes_file:
72
+ subprocess.run(
73
+ [
74
+ "objcopy",
75
+ "--only-section",
76
+ ".text",
77
+ # XXX in reality we should probably look at the sections
78
+ "--only-section",
79
+ ".text.*",
80
+ "-O",
81
+ "binary",
82
+ temp_o_file_name,
83
+ raw_bytes_file.name,
84
+ ]
85
+ )
86
+ compiled_bytes = raw_bytes_file.read()
87
+
88
+ # Disassemble the object file
89
+ disassembly = subprocess.run(
90
+ ["objdump", "-dr", temp_o_file_name], capture_output=True, text=True
91
+ ).stdout
92
+ disassembly = trim_objdump(disassembly)
93
+
94
+
95
+ # Relocs
96
+ json_relocs = subprocess.run(
97
  [
98
  "llvm-readobj-19",
99
  "--elf-output-style=JSON",
 
102
  ],
103
  capture_output=True,
104
  text=True,
105
+ ).stdout
106
+ json_relocs = json.loads(json_relocs)
107
+ json_relocs = json_relocs[0]["Relocations"]
108
+ json_relocs = [r["Relocation"] for d in json_relocs for r in d["Relocs"]]
109
+ # Filter out .text
110
+ json_relocs = [r for r in json_relocs if r["Symbol"]["Name"] != ".text"]
 
 
111
  return json_relocs, compiled_bytes, compile_output, disassembly
112
  else:
113
+ return None, None, compile_output, None
114
 
115
 
116
  def _reloc_type2size(s):