Skip to content

Commit

Permalink
Ensured programs are not too large
Browse files Browse the repository at this point in the history
  • Loading branch information
travisby committed May 15, 2014
1 parent f63b19e commit da2569c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions data_structures/symbol_table.ml
Expand Up @@ -70,6 +70,7 @@ class symboltable =
val mutable static_pointer = 0
val heap = Hashtbl.create 2
val static = Hashtbl.create 0
method sizeof_static = Hashtbl.length static
(* add start to every value *)
method update_static_addresses start = Hashtbl.iter (fun key value -> Hashtbl.replace static key (start + value)) static
method reserve_static_space ast =
Expand Down
1 change: 1 addition & 0 deletions data_structures/symbol_table.mli
Expand Up @@ -22,4 +22,5 @@ class symboltable :
method get_heap_address : string -> int
method reserve_static_space : Ast.ast -> unit
method update_static_addresses : int -> unit
method sizeof_static : int
end
13 changes: 13 additions & 0 deletions frontend/codegen.ml
@@ -1,6 +1,8 @@
open Utils;;
open Assembly;;

exception Too_Large_Of_Program

let type_int = Ast.Int {charno=(-1); lineno=(-1)}
let type_bool = Ast.Boolean {charno=(-1); lineno=(-1)}
let type_string = Ast.String {charno=(-1); lineno=(-1)}
Expand Down Expand Up @@ -392,6 +394,17 @@ let assembly_list_of_ast ast st =
] @ [Reserved]
| _ -> raise Not_found
in
let instructions = func ast in
(* update pointers *)
st#update_static_addresses ((List.length instructions) + 1);
let static = Array.to_list (Array.make st#sizeof_static BRK) in
(* Make sure we're not too big of a program *)
if
((List.length instructions) + (List.length static) + (Array.length heap)) > max_address
then
raise Too_Large_Of_Program
else ()
;
List.iteri (fun i x -> Array.set memory i x) (func ast);
Array.to_list memory
let string_of_hex x = match x with
Expand Down

0 comments on commit da2569c

Please sign in to comment.