summaryrefslogtreecommitdiff
path: root/source/xi_lib
diff options
context:
space:
mode:
authorPaweł Dybiec <pdybiec@stud.cs.uni.wroc.pl>2018-12-09 17:49:20 +0100
committerPaweł Dybiec <pdybiec@stud.cs.uni.wroc.pl>2018-12-09 17:49:20 +0100
commitd8e44d7e8e043eb5559ff7228f2bd6c4ecbce3f0 (patch)
treec674515acd43f2d81290fad9443d08fc75c20ff4 /source/xi_lib
parentFix topdown strategy for add (diff)
Initial code for translator
Diffstat (limited to 'source/xi_lib')
-rw-r--r--source/xi_lib/.merlin5
-rw-r--r--source/xi_lib/analysis_domain.ml4
-rw-r--r--source/xi_lib/ir.ml65
-rw-r--r--source/xi_lib/ir_utils.ml15
-rw-r--r--source/xi_lib/logger.ml6
5 files changed, 73 insertions, 22 deletions
diff --git a/source/xi_lib/.merlin b/source/xi_lib/.merlin
new file mode 100644
index 0000000..e44069f
--- /dev/null
+++ b/source/xi_lib/.merlin
@@ -0,0 +1,5 @@
+B /home/wieczyk/.opam/4.07.0/lib/ocamlgraph
+B ../../_build/default/source/xi_lib/.xi_lib.objs
+S /home/wieczyk/.opam/4.07.0/lib/ocamlgraph
+S .
+FLG -open Xi_lib -w @a-4-29-40-41-42-44-45-48-58-59-60-40 -strict-sequence -strict-formats -short-paths -keep-locs
diff --git a/source/xi_lib/analysis_domain.ml b/source/xi_lib/analysis_domain.ml
index 9f49a3e..db124e0 100644
--- a/source/xi_lib/analysis_domain.ml
+++ b/source/xi_lib/analysis_domain.ml
@@ -103,7 +103,7 @@ module ConstantFolding = struct
| Some a -> Ir_utils.string_of_expr a
let string_of_domain dom =
- let f (k,v) = Format.sprintf "%s=%s" (Ir.string_of_reg k) (string_of_el v) in
+ let f (k,v) = Format.sprintf "%s=%s" (Ir_utils.string_of_reg k) (string_of_el v) in
let seq = Ir.RegMap.to_seq dom in
let seq = Seq.map f seq in
String.concat " " @@ List.of_seq seq
@@ -132,4 +132,4 @@ module ReachabilityAnalysis = struct
type table = Ir.LabelSet.t Analysis.BlockKnowledge.table
-end \ No newline at end of file
+end
diff --git a/source/xi_lib/ir.ml b/source/xi_lib/ir.ml
index b611916..f7d2c96 100644
--- a/source/xi_lib/ir.ml
+++ b/source/xi_lib/ir.ml
@@ -1,12 +1,11 @@
type reg
+ (* rejestr tymczasowy *)
= REG_Tmp of int
+ (* rejestr sprzętowy *)
| REG_Hard of int
+ (* rejestr sprzętowy specjalnego przeznaczenia *)
| REG_Spec of int
-let string_of_reg = function
- | REG_Tmp i -> Format.sprintf "%%tmp%u" i
- | REG_Hard i -> Format.sprintf "%%hard%u" i
- | REG_Spec i -> Format.sprintf "%%spec%u" i
let is_spec_reg = function
| REG_Spec _ -> true
@@ -69,49 +68,74 @@ type cond
| COND_Le
| COND_Ge
-let string_of_cond = function
- | COND_Eq -> "eq"
- | COND_Ne -> "ne"
- | COND_Lt -> "lt"
- | COND_Gt -> "gt"
- | COND_Le -> "le"
- | COND_Ge -> "ge"
-
type instr
+ (* dodaj *)
= I_Add of reg * expr * expr
+ (* odejmij *)
| I_Sub of reg * expr * expr
+ (* podziel *)
| I_Div of reg * expr * expr
+ (* reszta z dzielenia *)
| I_Rem of reg * expr * expr
+ (* pomnóż *)
| I_Mul of reg * expr * expr
+ (* bitowy and *)
| I_And of reg * expr * expr
+ (* bitowy or *)
| I_Or of reg * expr * expr
+ (* bitowy xor *)
| I_Xor of reg * expr * expr
+ (* LoadArray(r, xs, i) oznacza załaduj i-ty element tablicy xs do rejestru r *)
| I_LoadArray of reg * expr * expr
+ (* StoreArray(xs, i, e) oznacza zapisz do i-tego elementu tablicy xs atom e *)
| I_StoreArray of expr * expr * expr
+ (* LoadMem(r, xs, i) oznacza załaduj komórkę pamięci o adresie (xs+i) do rejestru r*)
| I_LoadMem of reg * expr * expr
+ (* StoreMem(xs, i, e) oznacza zapisz do komórki pamięci o adresie (xs+i) atom e *)
| I_StoreMem of expr * expr * expr
+ (* wysokopoziomowa instrukcja: konkatenacja tablic *)
| I_Concat of reg * expr * expr
+ (* zaneguj liczbę *)
| I_Neg of reg * expr
+ (* bitowy not *)
| I_Not of reg * expr
+ (* zapisz atom do rejestru *)
| I_Move of reg * expr
+ (* wysokopoziomowa instrukcja: zapisuje do rejestru długość tablicy *)
| I_Length of reg * expr
+ (* wysokopoziomowa instrukcja: zaalokuj tablicę o określonym rozmiarze *)
| I_NewArray of reg * expr
+ (* I_Call(rs, p, xs, ms) oznacza wywołaj p z argumentami xs, wyniki
+ * funkcji znajdą się w rejestrach rs, dodatkowo zostaną zmodyfikowane rejestry ms *)
| I_Call of reg list * procid * expr list * reg list
- | I_Set of reg * cond * expr * expr
+ (* I_Set(r, cond, a, b) zapisz do rejestru r wartość boolowską warunku cond(a,b) *)
+ | I_Set of reg * cond * expr * expr
+ (* załaduj do rejestru zmienną lokalną *)
| I_LoadVar of reg * int
+ (* zapisz atom do zmiennej lokalnej *)
| I_StoreVar of int * expr
+ (* załaduj do rejestru komórkę ze stosu *)
| I_LoadStack of reg * int
+ (* zapisz do komórki na stosie atom *)
| I_StoreStack of int * expr
+ (* przydziel stos *)
| I_StackAlloc of Int32.t
+ (* zwolnij stos *)
| I_StackFree of Int32.t
+ (* meta-instrukcja, podane rejestry będą uznawane za użyte *)
| I_Use of reg list
+ (* meta-instrukcja, podane rejestry będą uznane za zmodyfikowane *)
| I_Def of reg list
type terminator =
+ (* return *)
| T_Return of expr list
+ (* T_Branch(cond, a, b, then_bb, else_bb) oznacza skok warunkowy
+ * if cond(a,b) then goto then_bb else goto else_bb *)
| T_Branch of cond * expr * expr * label * label
+ (* skok bezwarunkowy *)
| T_Jump of label
let labels_of_terminator = function
@@ -122,13 +146,13 @@ let labels_of_terminator = function
type block = instr list
module LabelGraph = Graph.Imperative.Digraph.ConcreteBidirectional(struct
-(*module LabelGraph = Mygraph.MakeBidirectional(struct *)
type t = label
let compare = compare
let hash = Hashtbl.hash
let equal a b = a = b
end)
+(* Reprezentacja ciała funkcji *)
module ControlFlowGraph = struct
type graph = LabelGraph.t
@@ -253,11 +277,17 @@ module ControlFlowGraph = struct
end
+(* Reprezentacja całej procedury *)
type procedure = Procedure of
+ (* identyfikator *)
{ procid: procid
+ (* graf sterowania *)
; cfg: ControlFlowGraph.t
+ (* rozmiar rekordu aktywacji *)
; mutable frame_size: int
+ (* ilość parametrów formalnych *)
; formal_parameters: int
+ (* funkcja do przydzielania świeżych rejestrów wewnątrz danej proceduy *)
; allocate_register: unit -> reg
}
@@ -278,11 +308,14 @@ let procid_of_procedure (Procedure {procid; _}) = procid
let frame_size_of_procedure (Procedure {frame_size; _}) = frame_size
+(* Reprezentacja programu *)
type program = Program of
+ (* lista procedur *)
{ procedures: procedure list
- ; externals: procid list
+ (* lista wszystkich symboli *)
+ ; symbols: procid list
}
let procedures_of_program (Program{procedures; _}) = procedures
-let externals_of_program (Program{externals; _}) = externals
+let symbols_of_program (Program{symbols; _}) = symbols
diff --git a/source/xi_lib/ir_utils.ml b/source/xi_lib/ir_utils.ml
index 48b59a1..b43655d 100644
--- a/source/xi_lib/ir_utils.ml
+++ b/source/xi_lib/ir_utils.ml
@@ -1,5 +1,18 @@
open Ir
+let string_of_reg = function
+ | REG_Tmp i -> Format.sprintf "%%tmp%u" i
+ | REG_Hard i -> Format.sprintf "%%hard%u" i
+ | REG_Spec i -> Format.sprintf "%%spec%u" i
+
+let string_of_cond = function
+ | COND_Eq -> "eq"
+ | COND_Ne -> "ne"
+ | COND_Lt -> "lt"
+ | COND_Gt -> "gt"
+ | COND_Le -> "le"
+ | COND_Ge -> "ge"
+
let remap_register_reg sb r =
try
Hashtbl.find sb r
@@ -665,4 +678,4 @@ let string_of_module_definition xs =
String.concat "\n" @@ List.map string_of_procedure xs
let string_of_program (Program {procedures; _}) =
- String.concat "\n" @@ List.map string_of_procedure procedures \ No newline at end of file
+ String.concat "\n" @@ List.map string_of_procedure procedures
diff --git a/source/xi_lib/logger.ml b/source/xi_lib/logger.ml
index 746bbb8..26ce286 100644
--- a/source/xi_lib/logger.ml
+++ b/source/xi_lib/logger.ml
@@ -134,7 +134,7 @@ let dump_ir_proc title irproc =
dump_string title buffer
let dump_spill_costs spill_costs =
- let f (k,v) = Format.sprintf "%s -> %u" (Ir.string_of_reg k) v in
+ let f (k,v) = Format.sprintf "%s -> %u" (Ir_utils.string_of_reg k) v in
let seq = Hashtbl.to_seq spill_costs in
let seq = Seq.map f seq in
let seq = List.of_seq seq in
@@ -142,7 +142,7 @@ let dump_spill_costs spill_costs =
dump_string "spill_costs" buf
let dump_spill_costs_f spill_costs =
- let f (k,v) = Format.sprintf "%s -> %f" (Ir.string_of_reg k) v in
+ let f (k,v) = Format.sprintf "%s -> %f" (Ir_utils.string_of_reg k) v in
let seq = Hashtbl.to_seq spill_costs in
let seq = Seq.map f seq in
let seq = List.of_seq seq in
@@ -167,4 +167,4 @@ let dump_constant_folding title cfg table =
dump_string (title ^ ".cfa.xdot") buffer
let init xilog =
- FS.init xilog \ No newline at end of file
+ FS.init xilog