Spaces:
Sleeping
Sleeping
Commit
·
d65ea20
1
Parent(s):
5a649d5
update
Browse files
main.py
CHANGED
|
@@ -28,9 +28,11 @@ def compile(compiler, flags, source):
|
|
| 28 |
|
| 29 |
# Compile the C file to an object file
|
| 30 |
result = subprocess.run(
|
| 31 |
-
[compiler, "-c", temp_c_file_name]
|
|
|
|
|
|
|
| 32 |
capture_output=True,
|
| 33 |
-
text=True
|
| 34 |
)
|
| 35 |
compile_output = result.stdout + result.stderr
|
| 36 |
|
|
@@ -49,19 +51,30 @@ def compile(compiler, flags, source):
|
|
| 49 |
)
|
| 50 |
compiled_bytes = raw_bytes_file.read()
|
| 51 |
|
| 52 |
-
|
| 53 |
-
|
|
|
|
|
|
|
| 54 |
|
| 55 |
|
| 56 |
def predict(target_bytes, source, compiler, flags):
|
| 57 |
target_bytes = bytes.fromhex(target_bytes)
|
| 58 |
compiled_bytes, compile_output = compile(compiler, flags, source)
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
|
| 67 |
def run():
|
|
|
|
| 28 |
|
| 29 |
# Compile the C file to an object file
|
| 30 |
result = subprocess.run(
|
| 31 |
+
[compiler, "-c", temp_c_file_name]
|
| 32 |
+
+ shlex.split(flags)
|
| 33 |
+
+ ["-o", temp_o_file_name],
|
| 34 |
capture_output=True,
|
| 35 |
+
text=True,
|
| 36 |
)
|
| 37 |
compile_output = result.stdout + result.stderr
|
| 38 |
|
|
|
|
| 51 |
)
|
| 52 |
compiled_bytes = raw_bytes_file.read()
|
| 53 |
|
| 54 |
+
if result.returncode == 0:
|
| 55 |
+
return compiled_bytes, compile_output
|
| 56 |
+
else:
|
| 57 |
+
return None, compile_output
|
| 58 |
|
| 59 |
|
| 60 |
def predict(target_bytes, source, compiler, flags):
|
| 61 |
target_bytes = bytes.fromhex(target_bytes)
|
| 62 |
compiled_bytes, compile_output = compile(compiler, flags, source)
|
| 63 |
+
|
| 64 |
+
if compiled_bytes is not None:
|
| 65 |
+
return (
|
| 66 |
+
hexdump(compiled_bytes, result="return"),
|
| 67 |
+
hexdump(target_bytes, result="return"),
|
| 68 |
+
editdistance.eval(compiled_bytes, target_bytes),
|
| 69 |
+
compile_output,
|
| 70 |
+
)
|
| 71 |
+
else:
|
| 72 |
+
return (
|
| 73 |
+
"Compilation failed",
|
| 74 |
+
hexdump(target_bytes, result="return"),
|
| 75 |
+
-1,
|
| 76 |
+
compile_output,
|
| 77 |
+
)
|
| 78 |
|
| 79 |
|
| 80 |
def run():
|