This repository has been archived on 2022-12-27. You can view files and clone it, but cannot push or open issues or pull requests.
compilateurMIPS/ast.ml

130 lines
2.1 KiB
OCaml
Raw Normal View History

2022-12-08 21:30:39 +01:00
type type_t =
2022-12-10 16:49:51 +01:00
| Magic_t
2022-12-09 22:20:05 +01:00
| Void_t
2022-12-08 21:30:39 +01:00
| Int_t
| Bool_t
2022-12-11 03:35:52 +01:00
| Str_t
2022-12-09 14:45:59 +01:00
| Func_t of type_t * type_t list
2022-12-08 19:55:22 +01:00
2022-12-06 20:39:15 +01:00
module Syntax = struct
2022-12-08 19:55:22 +01:00
type ident = string
2022-12-08 21:30:39 +01:00
type value =
2022-12-09 22:20:05 +01:00
| Void
2022-12-08 21:30:39 +01:00
| Int of int
| Bool of bool
2022-12-11 03:35:52 +01:00
| Str of string
2022-12-08 19:55:22 +01:00
2022-12-06 20:39:15 +01:00
type expr =
2022-12-08 19:55:22 +01:00
| Val of
{ value : value
; pos : Lexing.position
}
| Var of
{ name : ident
; pos : Lexing.position
}
2022-12-09 14:45:59 +01:00
| Call of
{ func : ident
; args : expr list
; pos : Lexing.position
}
2022-12-08 19:55:22 +01:00
type instr =
| Decl of
{ name : ident
; type_t : type_t
2022-12-06 22:22:48 +01:00
; pos : Lexing.position
}
2022-12-08 19:55:22 +01:00
| Assign of
{ var : ident
; expr : expr
; pos : Lexing.position
}
| Do of
{ expr : expr
; pos : Lexing.position
}
| Cond of
{ expr : expr
; if_b : block
; else_b : block
; pos : Lexing.position
}
2022-12-13 17:10:14 +01:00
| Loop of
{ expr : expr
; block : block
; pos : Lexing.position
}
2022-12-09 14:14:33 +01:00
| Return of
{ expr : expr
; pos : Lexing.position
}
2022-12-08 19:55:22 +01:00
and block = instr list
2022-12-10 13:49:05 +01:00
type arg =
| Arg of
{ type_t : type_t
; name : ident
}
type args = arg list
type def =
| Func of
{ func : ident
; type_t : type_t
2022-12-10 13:49:05 +01:00
; args : args
; code : block
; pos : Lexing.position
}
type prog = def list
2022-12-06 20:39:15 +01:00
end
2022-12-10 17:51:31 +01:00
module type Parameters = sig
type value
end
module V1 = struct
type value =
| Void
| Int of int
| Bool of bool
2022-12-11 03:35:52 +01:00
| Str of string
2022-12-10 17:51:31 +01:00
end
2022-12-08 21:30:39 +01:00
2022-12-10 17:51:31 +01:00
module V2 = struct
2022-12-08 21:30:39 +01:00
type value =
2022-12-09 22:20:05 +01:00
| Void
2022-12-08 21:30:39 +01:00
| Int of int
| Bool of bool
2022-12-11 03:35:52 +01:00
| Data of string
2022-12-10 17:51:31 +01:00
end
module IR (P : Parameters) = struct
type ident = string
2022-12-08 19:55:22 +01:00
type expr =
2022-12-10 17:51:31 +01:00
| Val of P.value
2022-12-08 19:55:22 +01:00
| Var of ident
2022-12-09 14:45:59 +01:00
| Call of ident * expr list
2022-12-08 19:55:22 +01:00
type instr =
| Decl of ident
| Assign of ident * expr
| Do of expr
| Cond of expr * block * block
2022-12-13 17:10:14 +01:00
| Loop of expr * block
2022-12-09 14:14:33 +01:00
| Return of expr
2022-12-08 19:55:22 +01:00
and block = instr list
type def = Func of ident * ident list * block
type prog = def list
2022-12-06 20:39:15 +01:00
end
2022-12-10 17:51:31 +01:00
module IR1 = IR (V1)
module IR2 = IR (V2)