Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restructure project directory #1

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
build:
@rm -f ./main
opam exec -- dune build
@cp _build/install/default/bin/cs3110_compiler ./main
@cp _build/install/default/bin/x86ISTMB ./main
@chmod u+x ./main

.PHONY: test
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# cs3110_compiler
# x86ISTMB

```shell
$ ./main -h
Expand Down
4 changes: 2 additions & 2 deletions bin/dune
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(executable
(public_name cs3110_compiler)
(public_name x86ISTMB)
(name main)
(libraries cs3110_compiler))
(libraries x86ISTMB))
21 changes: 11 additions & 10 deletions bin/main.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
open Cs3110_compiler
open X86ISTMB
open Util

let print_error = Printf.eprintf "error: %s"
Expand All @@ -25,24 +25,25 @@ let print_version () =
let test () =
let ir =
[
Ir.Assign (Ir.var 0, Ir.const 1);
Ir.Assign (Ir.var 1, Ir.const 2);
Ir.Add (Ir.var 2, Ir.var_op 0, Ir.var_op 1);
Ir.Instr.Assign (Ir.Variable.make 0, Ir.Operand.make_const 1);
Ir.Instr.Assign (Ir.Variable.make 1, Ir.Operand.make_const 2);
Ir.Instr.Add
(Ir.Variable.make 2, Ir.Operand.make_var 0, Ir.Operand.make_var 1);
]
in
let bb = Basic_block.make () in
List.iter (Basic_block.add bb) ir;
Printf.printf "%s:\n" (Basic_block.label_of bb |> Label.name_of);
List.iter (Ir.to_string >> Printf.printf " %s\n") ir
let bb = Ir.BasicBlock.make () in
List.iter (Ir.BasicBlock.add bb) ir;
Printf.printf "%s:\n" (Ir.BasicBlock.label_of bb |> Ir.Label.name_of);
List.iter (Ir.Instr.to_string >> Printf.printf " %s\n") ir

let file_driver path flags =
let source = Util.read_file path in
try
let statements = Parse_lex.lex_and_parse source in
let statements = Frontend.ParseLex.lex_and_parse source in
ignore statements;
if List.mem Cli.OnlyIR flags then test ()
else failwith "compiler not done yet"
with Parse_lex.ParseError msg -> print_error (msg ^ "\n")
with Frontend.ParseLex.ParseError msg -> print_error (msg ^ "\n")

let () =
match Sys.argv |> Cli.parse with
Expand Down
22 changes: 22 additions & 0 deletions bin/tui.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
type t =
| Error of {
prog : string;
msg : string;
}
| Help of { prog : string }
| Version of { prog : string }
| File of {
prog : string;
path : string;
}

let parse : string array -> t =
let open X86ISTMB.Util in
let parse_aux = function
| [ prog; "-h" ] | [ prog; "--help" ] -> Help { prog }
| [ prog; "-v" ] | [ prog; "--version" ] -> Version { prog }
| [ prog; "-f"; path ] -> File { prog; path }
| prog :: _ -> Error { prog; msg = "invalid arguments" }
| _ -> failwith "program invoked with empty argument array"
in
Array.to_list >> parse_aux
6 changes: 3 additions & 3 deletions dune-project
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
(lang dune 3.14)

(name cs3110_compiler)
(name x86ISTMB)

(using menhir 3.0)

(generate_opam_files true)

(source
(github ethanuppal/cs3110_compiler))
(github ethanuppal/x86ISTMB))

(authors
"Utku Melemeti"
Expand All @@ -22,7 +22,7 @@
(documentation https://github.com/ethanuppal/cs3110_compiler/wiki)

(package
(name cs3110_compiler)
(name x86ISTMB)
(synopsis "CS 3110 final project")
(depends
(ocaml
Expand Down
File renamed without changes.
File renamed without changes.
9 changes: 3 additions & 6 deletions lib/dune
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
(include_subdirs qualified)

(library
(name cs3110_compiler)
(name x86ISTMB)
(libraries batteries menhirLib))

(ocamllex lexer)

(menhir
(modules parser))

(rule
(targets project_root.ml)
(deps ../script/generate_project_root.ml)
Expand Down
File renamed without changes.
5 changes: 5 additions & 0 deletions lib/frontend/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(ocamllex lexer)

(menhir
(modules parser)
(infer false))
File renamed without changes.
File renamed without changes.
5 changes: 1 addition & 4 deletions lib/parser.mly → lib/frontend/parser.mly
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
%{
open Ast
%}

%token <int> CONST
%token <string> VAR
%token PLUS MINUS TIMES DIVIDE MOD
Expand All @@ -17,6 +13,7 @@

%type <Ast.stmt> stmt
%type <Ast.expr> expr
%type <Ast.stmt list> body_till_rbrace

%%

Expand Down
2 changes: 2 additions & 0 deletions lib/interpreter.ml → lib/interpreter/interpreter.ml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
open Frontend

type interpreter_mode =
| File
| REPL
Expand Down
2 changes: 1 addition & 1 deletion lib/interpreter.mli → lib/interpreter/interpreter.mli
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type interpreter_mode =
(** The public interface of the interpreter. *)
type t = {
dump : unit -> unit;
step : Ast.stmt -> unit;
step : Frontend.Ast.stmt -> unit;
set_mode : interpreter_mode -> unit;
}

Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/value.ml → lib/interpreter/value.ml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(** A value in the interpreter. *)
type t =
| Int of int
| FunctionValue of { body : Ast.stmt list }
| FunctionValue of { body : Frontend.Ast.stmt list }

exception
TypeError of {
Expand Down
2 changes: 1 addition & 1 deletion lib/basic_block.ml → lib/ir/basicBlock.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
type ir_array = Ir.t BatDynArray.t
type ir_array = Instr.t BatDynArray.t

type t = {
label : Label.t;
Expand Down
4 changes: 2 additions & 2 deletions lib/basic_block.mli → lib/ir/basicBlock.mli
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ val make : unit -> t
val label_of : t -> Label.t

(** [add basic_block ir] adds [ir] to the end of [basic_block]. *)
val add : t -> Ir.t -> unit
val add : t -> Instr.t -> unit

(** [to_list basic_block] are the IR operations in [basic_block] in order as a
list. *)
val to_list : t -> Ir.t list
val to_list : t -> Instr.t list
File renamed without changes.
36 changes: 0 additions & 36 deletions lib/ir.ml → lib/ir/instr.ml
Original file line number Diff line number Diff line change
@@ -1,35 +1,3 @@
module Variable : sig
(** The type of an IR variable. *)
type t

val make : int -> t

(** [to_string var] is [var] as a string. *)
val to_string : t -> string
end = struct
open Util

type t = int

let make x = x
let to_string = string_of_int >> ( ^ ) "i"
end

module Operand = struct
type t =
| Variable of Variable.t
| Constant of int

let make_var x = Variable (Variable.make x)
let make_const x = Constant x

let to_string = function
| Variable var -> Variable.to_string var
| Constant const -> string_of_int const
end

type constant = int

(* todo *)
type t =
| Assign of Variable.t * Operand.t
Expand All @@ -40,10 +8,6 @@ type t =
| Jump of Label.t
| Call of Label.t

let var = Variable.make
let var_op = Operand.make_var
let const = Operand.make_const

let to_string =
let open Printf in
function
Expand Down
File renamed without changes.
File renamed without changes.
12 changes: 12 additions & 0 deletions lib/ir/operand.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
type constant = int

type t =
| Variable of Variable.t
| Constant of constant

let make_var x = Variable (Variable.make x)
let make_const x = Constant x

let to_string = function
| Variable var -> Variable.to_string var
| Constant const -> string_of_int const
6 changes: 6 additions & 0 deletions lib/ir/variable.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
open Util

type t = int

let make x = x
let to_string = string_of_int >> ( ^ ) "i"
7 changes: 7 additions & 0 deletions lib/ir/variable.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(** The type of an IR variable. *)
type t

val make : int -> t

(** [to_string var] is [var] as a string. *)
val to_string : t -> string
2 changes: 1 addition & 1 deletion project.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pm:
netid: zmb27
publish: true
title: "x86ISTMB"
git-repo: "https://github.com/ethanuppal/cs3110_compiler"
git-repo: "https://github.com/ethanuppal/x86ISTMB"
demo-video-url: ""
desc: >
x86ISTMB (x86 Is Simple Trust Me Bro) is a fully featured optimizing compiler
Expand Down
4 changes: 2 additions & 2 deletions test/dune
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(test
(name test_cs3110_compiler)
(libraries cs3110_compiler alcotest)
(name test_x86ISTMB)
(libraries x86ISTMB alcotest)
(deps
(source_tree snapshots)))
4 changes: 2 additions & 2 deletions test/snapshot.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
open X86ISTMB
open Alcotest
open Cs3110_compiler

type transform = string -> string -> string

Expand Down Expand Up @@ -27,7 +27,7 @@ let make_test_suite (root : string) (transform : transform) : unit test =
try
let actual = transform input_path input in
(check string) "output equality" expected actual
with Parse_lex.ParseError msg -> fail msg
with Frontend.ParseLex.ParseError msg -> fail msg
in
let suite_name =
Printf.sprintf "Snapshot Test Suite (testing version %s)" version_string
Expand Down
4 changes: 2 additions & 2 deletions test/test_cs3110_compiler.ml → test/test_x86ISTMB.ml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
let interpreter_transform path input =
ignore path;
let open Cs3110_compiler in
let open X86ISTMB in
let interpreter = Interpreter.create () in
let stdout = ref "" in
let statements = Parse_lex.lex_and_parse input in
let statements = Frontend.ParseLex.lex_and_parse input in
interpreter.set_mode (Text stdout);
List.iter interpreter.step statements;
stdout
Expand Down
6 changes: 3 additions & 3 deletions cs3110_compiler.opam → x86ISTMB.opam
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ authors: [
"Ethan Uppal"
]
tags: ["cs3110" "compiler"]
homepage: "https://github.com/ethanuppal/cs3110_compiler"
homepage: "https://github.com/ethanuppal/x86ISTMB"
doc: "https://github.com/ethanuppal/cs3110_compiler/wiki"
bug-reports: "https://github.com/ethanuppal/cs3110_compiler/issues"
bug-reports: "https://github.com/ethanuppal/x86ISTMB/issues"
depends: [
"ocaml" {>= "5.1.1"}
"ocaml"
Expand All @@ -37,4 +37,4 @@ build: [
"@doc" {with-doc}
]
]
dev-repo: "git+https://github.com/ethanuppal/cs3110_compiler.git"
dev-repo: "git+https://github.com/ethanuppal/x86ISTMB.git"