ejschwartz commited on
Commit
029945b
·
1 Parent(s): 330481b
Files changed (1) hide show
  1. main.py +13 -3
main.py CHANGED
@@ -23,7 +23,12 @@ def compile(compiler, flags, source):
23
  temp_o_file_name = temp_o_file.name
24
 
25
  # Compile the C file to an object file
26
- subprocess.run([compiler, "-c", temp_c_file_name] + shlex.split(flags) + ["-o", temp_o_file_name], check=True)
 
 
 
 
 
27
 
28
  # Create a temporary file for the raw bytes
29
  with tempfile.NamedTemporaryFile(suffix=".raw", delete=True) as raw_bytes_file:
@@ -45,8 +50,9 @@ def compile(compiler, flags, source):
45
 
46
 
47
  def predict(target, source, compiler, flags):
 
48
  bytes = compile(compiler, flags, source)
49
- return hexdump(bytes, result="return"), 1.0
50
 
51
 
52
  def run():
@@ -59,7 +65,11 @@ def run():
59
  gr.Textbox(label="Compiler", value="gcc"),
60
  gr.Textbox(label="Compiler Flags", value="-O2"),
61
  ],
62
- outputs=[gr.Textbox(label="Compiled bytes"), gr.Number(label="Accuracy (TBD)")],
 
 
 
 
63
  )
64
 
65
  demo.launch(server_name="0.0.0.0", server_port=7860)
 
23
  temp_o_file_name = temp_o_file.name
24
 
25
  # Compile the C file to an object file
26
+ subprocess.run(
27
+ [compiler, "-c", temp_c_file_name]
28
+ + shlex.split(flags)
29
+ + ["-o", temp_o_file_name],
30
+ check=True,
31
+ )
32
 
33
  # Create a temporary file for the raw bytes
34
  with tempfile.NamedTemporaryFile(suffix=".raw", delete=True) as raw_bytes_file:
 
50
 
51
 
52
  def predict(target, source, compiler, flags):
53
+ target = bytes.fromhex(target)
54
  bytes = compile(compiler, flags, source)
55
+ return hexdump(bytes, result="return"), hexdump(target, result="return"), 1.0
56
 
57
 
58
  def run():
 
65
  gr.Textbox(label="Compiler", value="gcc"),
66
  gr.Textbox(label="Compiler Flags", value="-O2"),
67
  ],
68
+ outputs=[
69
+ gr.Textbox(label="Compiled bytes"),
70
+ gr.Textbox(label="Target bytes"),
71
+ gr.Number(label="Accuracy (TBD)"),
72
+ ],
73
  )
74
 
75
  demo.launch(server_name="0.0.0.0", server_port=7860)