Spaces:
Sleeping
Sleeping
Commit
·
0814e7f
1
Parent(s):
90372e8
Try to compile
Browse files
main.py
CHANGED
|
@@ -8,7 +8,7 @@ EXAMPLE_CODE = open("/workspace/psychec/test.c", "r").read()
|
|
| 8 |
def run_psychec(c_code: str):
|
| 9 |
"""Run PsycheC type inference on the provided C code."""
|
| 10 |
if not c_code.strip():
|
| 11 |
-
return "Please provide some C code.", "", ""
|
| 12 |
|
| 13 |
with tempfile.TemporaryDirectory() as tmpdir:
|
| 14 |
input_file = Path(tmpdir) / "input.c"
|
|
@@ -33,12 +33,30 @@ def run_psychec(c_code: str):
|
|
| 33 |
if not log_output.strip():
|
| 34 |
log_output = "Type inference completed successfully." if result.returncode == 0 else "Type inference failed."
|
| 35 |
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
except subprocess.TimeoutExpired:
|
| 39 |
-
return "Error: Type inference timed out after 30 seconds.", "", ""
|
| 40 |
except Exception as e:
|
| 41 |
-
return f"Error: {e}", "", ""
|
| 42 |
|
| 43 |
def create_demo():
|
| 44 |
with gr.Blocks(title="PsycheC Type Inference") as demo:
|
|
@@ -67,11 +85,12 @@ def create_demo():
|
|
| 67 |
header_output = gr.Code(label="Generated Header (_gen.h)", language="c", lines=10)
|
| 68 |
fixed_output = gr.Code(label="Fixed C File (_fixed.c)", language="c", lines=10)
|
| 69 |
log_output = gr.Textbox(label="Output Log", lines=1)
|
|
|
|
| 70 |
|
| 71 |
run_btn.click(
|
| 72 |
fn=run_psychec,
|
| 73 |
inputs=[code_input],
|
| 74 |
-
outputs=[log_output, header_output, fixed_output]
|
| 75 |
)
|
| 76 |
|
| 77 |
gr.Markdown(
|
|
|
|
| 8 |
def run_psychec(c_code: str):
|
| 9 |
"""Run PsycheC type inference on the provided C code."""
|
| 10 |
if not c_code.strip():
|
| 11 |
+
return "Please provide some C code.", "", "", ""
|
| 12 |
|
| 13 |
with tempfile.TemporaryDirectory() as tmpdir:
|
| 14 |
input_file = Path(tmpdir) / "input.c"
|
|
|
|
| 33 |
if not log_output.strip():
|
| 34 |
log_output = "Type inference completed successfully." if result.returncode == 0 else "Type inference failed."
|
| 35 |
|
| 36 |
+
compile_status = ""
|
| 37 |
+
if fixed_c.exists():
|
| 38 |
+
try:
|
| 39 |
+
compile_result = subprocess.run(
|
| 40 |
+
["cc", "-c", str(fixed_c)],
|
| 41 |
+
capture_output=True,
|
| 42 |
+
text=True,
|
| 43 |
+
cwd=tmpdir
|
| 44 |
+
)
|
| 45 |
+
if compile_result.returncode == 0:
|
| 46 |
+
compile_status = "Compilation successful."
|
| 47 |
+
else:
|
| 48 |
+
compile_status = f"Compilation failed: {compile_result.stderr.strip()}"
|
| 49 |
+
except Exception as e:
|
| 50 |
+
compile_status = f"Compilation error: {e}"
|
| 51 |
+
else:
|
| 52 |
+
compile_status = "No fixed file to compile."
|
| 53 |
+
|
| 54 |
+
return log_output, header_content, fixed_content, compile_status
|
| 55 |
|
| 56 |
except subprocess.TimeoutExpired:
|
| 57 |
+
return "Error: Type inference timed out after 30 seconds.", "", "", ""
|
| 58 |
except Exception as e:
|
| 59 |
+
return f"Error: {e}", "", "", ""
|
| 60 |
|
| 61 |
def create_demo():
|
| 62 |
with gr.Blocks(title="PsycheC Type Inference") as demo:
|
|
|
|
| 85 |
header_output = gr.Code(label="Generated Header (_gen.h)", language="c", lines=10)
|
| 86 |
fixed_output = gr.Code(label="Fixed C File (_fixed.c)", language="c", lines=10)
|
| 87 |
log_output = gr.Textbox(label="Output Log", lines=1)
|
| 88 |
+
compile_output = gr.Textbox(label="Compilation Status", lines=5)
|
| 89 |
|
| 90 |
run_btn.click(
|
| 91 |
fn=run_psychec,
|
| 92 |
inputs=[code_input],
|
| 93 |
+
outputs=[log_output, header_output, fixed_output, compile_output]
|
| 94 |
)
|
| 95 |
|
| 96 |
gr.Markdown(
|