Skip to content

Commit

Permalink
run tiger programs immediately after compilation (#22)
Browse files Browse the repository at this point in the history
Co-authored-by: gildarov <gildarov@ozon.ru>
  • Loading branch information
threadedstream and threadedstream committed Aug 1, 2022
1 parent 6f89b9d commit 6676a3f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
14 changes: 6 additions & 8 deletions compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,12 @@ build_ocaml_compiler() {


test_single_case() {
./bin/compiler test/$1 && \

opt -f -S llvm_byte_code/test/$1.ll -o llvm_byte_code/test/$1-opt.ll -Oz && \
llc llvm_byte_code/test/$1-opt.ll && \

clang llvm_byte_code/test/$1-opt.s src/bindings.c -o run_prog && \

./run_prog
arg=$1
prog_loc="llvm_byte_code/test/${arg}"
IFS='.' read -a split <<< "$prog_loc"
prog_name="${split[0]}"
./bin/compiler test/$1 && \
./${prog_name}x
}

build_ocaml_compiler && run_all_test_cases
21 changes: 15 additions & 6 deletions src/semant.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
open Translate
open Llvm

open Sys
open StringLabels

module E = Env
module T = Types
module A = Absyn
Expand Down Expand Up @@ -672,7 +674,7 @@ let rec trans_dec (
in
tr_exp exp

let trans_prog ((my_exp: A.exp), (output_name: string)) =
let trans_prog ((my_exp: A.exp), (output_name: string)) =
let build_external_func = function
| (_, Env.FunEntry {formals; result; label}) -> Translate.build_external_func (S.name label) formals result
| _ -> ()
Expand All @@ -690,7 +692,14 @@ let trans_prog ((my_exp: A.exp), (output_name: string)) =
ignore(trans_exp (Env.base_venv, Env.base_tenv, main_level, my_exp, outermost_break_block));
Translate.build_return_main();
(* dump_module Translate.the_module; *)
print_module ("llvm_byte_code/"^ output_name ^ ".ll") Translate.the_module;



let output_file_name = "llvm_byte_code/"^ output_name in
let output_name_no_ext = List.nth (StringLabels.split_on_char ~sep:'.' output_file_name) 0 in
print_module (output_file_name ^ ".ll") Translate.the_module;
let pipe_thru_opt_cmd = "opt -f -S "^ output_file_name ^ ".ll -o "^ output_file_name ^ "-opt.ll -Oz" in
let pipe_thru_llc_cmd = "llc " ^ output_file_name ^ "-opt.ll" in
let pipe_thru_clang_cmd = "clang " ^ output_file_name ^ "-opt.s src/bindings.c -o " ^ output_name_no_ext in
let run_prog_cmd = "./" ^ output_name_no_ext in
Sys.command pipe_thru_opt_cmd;
Sys.command pipe_thru_llc_cmd;
Sys.command pipe_thru_clang_cmd;
Sys.command run_prog_cmd;

0 comments on commit 6676a3f

Please sign in to comment.