Spaces:
Sleeping
Sleeping
Commit
·
20b2b87
1
Parent(s):
20f12de
update
Browse files
main.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
from hexdump2 import hexdump
|
2 |
import gradio as gr
|
|
|
3 |
import subprocess
|
4 |
import tempfile
|
5 |
|
@@ -12,7 +13,7 @@ Currently unhandled features:
|
|
12 |
"""
|
13 |
|
14 |
|
15 |
-
def compile(source):
|
16 |
# Create a temporary file for the C source code
|
17 |
with tempfile.NamedTemporaryFile(suffix=".c", delete=False) as temp_c_file:
|
18 |
temp_c_file.write(source.encode())
|
@@ -23,7 +24,7 @@ def compile(source):
|
|
23 |
temp_o_file_name = temp_o_file.name
|
24 |
|
25 |
# Compile the C file to an object file
|
26 |
-
subprocess.run([
|
27 |
|
28 |
# Create a temporary file for the raw bytes
|
29 |
with tempfile.NamedTemporaryFile(suffix=".raw", delete=True) as raw_bytes_file:
|
@@ -43,8 +44,8 @@ def compile(source):
|
|
43 |
return compiled_bytes
|
44 |
|
45 |
|
46 |
-
def predict(target, source):
|
47 |
-
bytes = compile(source)
|
48 |
return hexdump(bytes), 1.0
|
49 |
|
50 |
|
|
|
1 |
from hexdump2 import hexdump
|
2 |
import gradio as gr
|
3 |
+
import shlex
|
4 |
import subprocess
|
5 |
import tempfile
|
6 |
|
|
|
13 |
"""
|
14 |
|
15 |
|
16 |
+
def compile(compiler, flags, source):
|
17 |
# Create a temporary file for the C source code
|
18 |
with tempfile.NamedTemporaryFile(suffix=".c", delete=False) as temp_c_file:
|
19 |
temp_c_file.write(source.encode())
|
|
|
24 |
temp_o_file_name = temp_o_file.name
|
25 |
|
26 |
# Compile the C file to an object file
|
27 |
+
subprocess.run([compiler, "-c", temp_c_file_name] + shlex.split(flags) + ["-o", temp_o_file_name], check=True)
|
28 |
|
29 |
# Create a temporary file for the raw bytes
|
30 |
with tempfile.NamedTemporaryFile(suffix=".raw", delete=True) as raw_bytes_file:
|
|
|
44 |
return compiled_bytes
|
45 |
|
46 |
|
47 |
+
def predict(target, source, compiler, flags):
|
48 |
+
bytes = compile(compiler, flags, source)
|
49 |
return hexdump(bytes), 1.0
|
50 |
|
51 |
|