Initial working submission, without errors
This commit is contained in:
parent
b0154657d4
commit
051c264a23
4 changed files with 17 additions and 13 deletions
11
Dockerfile
Normal file
11
Dockerfile
Normal file
|
@ -0,0 +1,11 @@
|
|||
FROM rust AS builder
|
||||
WORKDIR /home/vili/School/Compilers/compiler-course
|
||||
COPY . .
|
||||
RUN cargo install --path .
|
||||
|
||||
FROM debian:stable-slim
|
||||
RUN apt-get update && apt-get install -y libc6 gcc && rm -rf /var/lib/apt/lists/*
|
||||
COPY --from=builder /usr/local/cargo/bin/compiler-course /usr/local/bin/compiler-course
|
||||
EXPOSE 3000
|
||||
CMD ["compiler-course"]
|
||||
|
|
@ -29,6 +29,7 @@ pub fn compile(code: &str) -> String {
|
|||
type_check(&mut ast, &mut SymTab::new_type_table());
|
||||
let ir = generate_ir(&ast);
|
||||
let assembly = generate_assembly(&ir);
|
||||
|
||||
general_purpose::STANDARD.encode(&assemble(assembly))
|
||||
}
|
||||
|
||||
|
|
|
@ -41,26 +41,21 @@ pub fn assemble(assembly: String) -> Vec<u8> {
|
|||
file.write_all(assembly.as_bytes())
|
||||
.expect("Can't write to temp file!");
|
||||
|
||||
let as_out1 = Command::new("as")
|
||||
Command::new("as")
|
||||
.args(["-g", "-o", stdlib_obj, stdlib_asm])
|
||||
.output()
|
||||
.expect("Could not run 'as' command!");
|
||||
|
||||
let as_out2 = Command::new("as")
|
||||
Command::new("as")
|
||||
.args(["-g", "-o", program_obj, program_asm])
|
||||
.output()
|
||||
.expect("Could not run 'as' command!");
|
||||
|
||||
let ld_out = Command::new("ld")
|
||||
Command::new("ld")
|
||||
.args(["-o", output_file, "-static", stdlib_obj, program_obj])
|
||||
.output()
|
||||
.expect("Could not run 'as' command!");
|
||||
|
||||
println!("{as_out1:?}");
|
||||
println!("{as_out2:?}");
|
||||
println!("{ld_out:?}");
|
||||
println!("{workdir:?}");
|
||||
|
||||
let mut file = File::open(output_file).expect("Can't open compiler output!");
|
||||
let mut output = Vec::new();
|
||||
file.read_to_end(&mut output)
|
||||
|
|
|
@ -37,11 +37,8 @@ fn handle_connection(mut stream: TcpStream) {
|
|||
let program = json_request["code"].as_str().unwrap();
|
||||
let output = compiler::compile(program);
|
||||
|
||||
let json_response = json::object! {
|
||||
"program": output,
|
||||
};
|
||||
let response = json_response.as_str().unwrap().as_bytes();
|
||||
stream.write_all(response).unwrap();
|
||||
let response = format!("{{\"program\": \"{output}\"}}");
|
||||
stream.write_all(response.as_bytes()).unwrap();
|
||||
}
|
||||
_ => panic!("Unexpected command!"),
|
||||
}
|
||||
|
|
Reference in a new issue