diff --git a/ass1/test.asm b/ass1/test.asm index 379ea91..c4ee2bf 100644 --- a/ass1/test.asm +++ b/ass1/test.asm @@ -1,5 +1,5 @@ -poly START 0 - LDB x1 - END poly - -x1 WORD 1 +poly START 0 + LDB x1 + END poly + +x1 WORD 1 diff --git a/ass2/.gitignore b/ass2/.gitignore index 15a6fd1..7afe718 100644 --- a/ass2/.gitignore +++ b/ass2/.gitignore @@ -1,16 +1,16 @@ -# Dune build artifacts -**/_build/ -**/_install/ - -# OCaml compiled files -*.cm[iox] -*.o -*.a -*.so -*.exe -*.cmi -*.cmo -*.cmx - -# OCaml package manager / opam +# Dune build artifacts +**/_build/ +**/_install/ + +# OCaml compiled files +*.cm[iox] +*.o +*.a +*.so +*.exe +*.cmi +*.cmo +*.cmx + +# OCaml package manager / opam *.opam.locked \ No newline at end of file diff --git a/ass2/SICocaml/readMe.txt b/ass2/SICocaml/readMe.txt index 39eada6..165cc9c 100644 --- a/ass2/SICocaml/readMe.txt +++ b/ass2/SICocaml/readMe.txt @@ -1,8 +1,8 @@ -V file-u sicxeDune se nahaja moj emulator napisan v Ocaml -Prevede se z ukazom "dune Build" -Požene se z ukazom "dune exec sicxeDune" -v main file-u spremenimo katero objektno kodo želimo naložit - ----- -Jaka Furlan +V file-u sicxeDune se nahaja moj emulator napisan v Ocaml +Prevede se z ukazom "dune Build" +Požene se z ukazom "dune exec sicxeDune" +v main file-u spremenimo katero objektno kodo želimo naložit + +---- +Jaka Furlan ---- \ No newline at end of file diff --git a/ass3/zbirnik/_build/.db b/ass3/zbirnik/_build/.db new file mode 100644 index 0000000..48d62e5 Binary files /dev/null and b/ass3/zbirnik/_build/.db differ diff --git a/ass3/zbirnik/_build/.digest-db b/ass3/zbirnik/_build/.digest-db new file mode 100644 index 0000000..b4b95df Binary files /dev/null and b/ass3/zbirnik/_build/.digest-db differ diff --git a/ass3/zbirnik/_build/.filesystem-clock b/ass3/zbirnik/_build/.filesystem-clock new file mode 100644 index 0000000..c61f4a7 --- /dev/null +++ b/ass3/zbirnik/_build/.filesystem-clock @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/ass3/zbirnik/_build/.lock b/ass3/zbirnik/_build/.lock new file mode 100644 index 0000000..e69de29 diff --git a/ass3/zbirnik/_build/default/.dune/configurator b/ass3/zbirnik/_build/default/.dune/configurator new file mode 100644 index 0000000..19708df --- /dev/null +++ b/ass3/zbirnik/_build/default/.dune/configurator @@ -0,0 +1,2 @@ +(ocamlc /usr/bin/ocamlc.opt) +(ocaml_config_vars (afl_instrument false) (architecture amd64) (asm x86_64-linux-gnu-as) (asm_cfi_supported true) (ast_impl_magic_number Caml1999M030) (ast_intf_magic_number Caml1999N030) (bytecomp_c_compiler "x86_64-linux-gnu-gcc -O2 -fno-strict-aliasing -fwrapv -pthread -fPIC -g -O2 -ffile-prefix-map=/build/ocaml-SC7b9w/ocaml-4.13.1=. -fstack-protector-strong -Wformat -Werror=format-security -D_FILE_OFFSET_BITS=64 -Wdate-time -D_FORTIFY_SOURCE=2") (bytecomp_c_libraries "-lm -lpthread") (c_compiler x86_64-linux-gnu-gcc) (ccomp_type cc) (cma_magic_number Caml1999A030) (cmi_magic_number Caml1999I030) (cmo_magic_number Caml1999O030) (cmt_magic_number Caml1999T030) (cmx_magic_number Caml1999Y030) (cmxa_magic_number Caml1999Z030) (cmxs_magic_number Caml1999D030) (default_executable_name a.out) (default_safe_string true) (exec_magic_number Caml1999X030) (ext_asm .s) (ext_dll .so) (ext_exe "") (ext_lib .a) (ext_obj .o) (flambda false) (flat_float_array true) (function_sections true) (host x86_64-pc-linux-gnu) (int_size 63) (linear_magic_number Caml1999L030) (model default) (native_c_compiler "x86_64-linux-gnu-gcc -O2 -fno-strict-aliasing -fwrapv -pthread -fPIC -g -O2 -ffile-prefix-map=/build/ocaml-SC7b9w/ocaml-4.13.1=. -fstack-protector-strong -Wformat -Werror=format-security -D_FILE_OFFSET_BITS=64 -Wdate-time -D_FORTIFY_SOURCE=2") (native_c_libraries "-lm ") (native_pack_linker "x86_64-linux-gnu-ld -r -o ") (ocamlc_cflags "-O2 -fno-strict-aliasing -fwrapv -pthread -fPIC -g -O2 -ffile-prefix-map=/build/ocaml-SC7b9w/ocaml-4.13.1=. -fstack-protector-strong -Wformat -Werror=format-security") (ocamlc_cppflags "-D_FILE_OFFSET_BITS=64 -Wdate-time -D_FORTIFY_SOURCE=2") (ocamlopt_cflags "-O2 -fno-strict-aliasing -fwrapv -pthread -fPIC -g -O2 -ffile-prefix-map=/build/ocaml-SC7b9w/ocaml-4.13.1=. -fstack-protector-strong -Wformat -Werror=format-security") (ocamlopt_cppflags "-D_FILE_OFFSET_BITS=64 -Wdate-time -D_FORTIFY_SOURCE=2") (os_type Unix) (ranlib x86_64-linux-gnu-ranlib) (safe_string true) (standard_library /usr/lib/ocaml) (standard_library_default /usr/lib/ocaml) (supports_shared_libraries true) (system linux) (systhread_supported true) (target x86_64-pc-linux-gnu) (version 4.13.1) (windows_unicode false) (with_frame_pointers false) (word_size 64)) diff --git a/ass3/zbirnik/_build/default/.dune/configurator.v2 b/ass3/zbirnik/_build/default/.dune/configurator.v2 new file mode 100644 index 0000000..6fe4a49 --- /dev/null +++ b/ass3/zbirnik/_build/default/.dune/configurator.v2 @@ -0,0 +1 @@ +((6:ocamlc19:/usr/bin/ocamlc.opt)(17:ocaml_config_vars((14:afl_instrument5:false)(12:architecture5:amd64)(3:asm19:x86_64-linux-gnu-as)(17:asm_cfi_supported4:true)(21:ast_impl_magic_number12:Caml1999M030)(21:ast_intf_magic_number12:Caml1999N030)(19:bytecomp_c_compiler241:x86_64-linux-gnu-gcc -O2 -fno-strict-aliasing -fwrapv -pthread -fPIC -g -O2 -ffile-prefix-map=/build/ocaml-SC7b9w/ocaml-4.13.1=. -fstack-protector-strong -Wformat -Werror=format-security -D_FILE_OFFSET_BITS=64 -Wdate-time -D_FORTIFY_SOURCE=2)(20:bytecomp_c_libraries14:-lm -lpthread)(10:c_compiler20:x86_64-linux-gnu-gcc)(10:ccomp_type2:cc)(16:cma_magic_number12:Caml1999A030)(16:cmi_magic_number12:Caml1999I030)(16:cmo_magic_number12:Caml1999O030)(16:cmt_magic_number12:Caml1999T030)(16:cmx_magic_number12:Caml1999Y030)(17:cmxa_magic_number12:Caml1999Z030)(17:cmxs_magic_number12:Caml1999D030)(23:default_executable_name5:a.out)(19:default_safe_string4:true)(17:exec_magic_number12:Caml1999X030)(7:ext_asm2:.s)(7:ext_dll3:.so)(7:ext_exe0:)(7:ext_lib2:.a)(7:ext_obj2:.o)(7:flambda5:false)(16:flat_float_array4:true)(17:function_sections4:true)(4:host19:x86_64-pc-linux-gnu)(8:int_size2:63)(19:linear_magic_number12:Caml1999L030)(5:model7:default)(17:native_c_compiler241:x86_64-linux-gnu-gcc -O2 -fno-strict-aliasing -fwrapv -pthread -fPIC -g -O2 -ffile-prefix-map=/build/ocaml-SC7b9w/ocaml-4.13.1=. -fstack-protector-strong -Wformat -Werror=format-security -D_FILE_OFFSET_BITS=64 -Wdate-time -D_FORTIFY_SOURCE=2)(18:native_c_libraries4:-lm )(18:native_pack_linker26:x86_64-linux-gnu-ld -r -o )(13:ocamlc_cflags165:-O2 -fno-strict-aliasing -fwrapv -pthread -fPIC -g -O2 -ffile-prefix-map=/build/ocaml-SC7b9w/ocaml-4.13.1=. -fstack-protector-strong -Wformat -Werror=format-security)(15:ocamlc_cppflags54:-D_FILE_OFFSET_BITS=64 -Wdate-time -D_FORTIFY_SOURCE=2)(15:ocamlopt_cflags165:-O2 -fno-strict-aliasing -fwrapv -pthread -fPIC -g -O2 -ffile-prefix-map=/build/ocaml-SC7b9w/ocaml-4.13.1=. -fstack-protector-strong -Wformat -Werror=format-security)(17:ocamlopt_cppflags54:-D_FILE_OFFSET_BITS=64 -Wdate-time -D_FORTIFY_SOURCE=2)(7:os_type4:Unix)(6:ranlib23:x86_64-linux-gnu-ranlib)(11:safe_string4:true)(16:standard_library14:/usr/lib/ocaml)(24:standard_library_default14:/usr/lib/ocaml)(25:supports_shared_libraries4:true)(6:system5:linux)(19:systhread_supported4:true)(6:target19:x86_64-pc-linux-gnu)(7:version6:4.13.1)(15:windows_unicode5:false)(19:with_frame_pointers5:false)(9:word_size2:64)))) \ No newline at end of file diff --git a/ass3/zbirnik/_build/default/META.zbirnik b/ass3/zbirnik/_build/default/META.zbirnik new file mode 100644 index 0000000..e69de29 diff --git a/ass3/zbirnik/_build/default/bin/.merlin-conf/exe-main b/ass3/zbirnik/_build/default/bin/.merlin-conf/exe-main new file mode 100644 index 0000000..1075694 Binary files /dev/null and b/ass3/zbirnik/_build/default/bin/.merlin-conf/exe-main differ diff --git a/ass3/zbirnik/_build/default/bin/main.ml b/ass3/zbirnik/_build/default/bin/main.ml new file mode 100644 index 0000000..1de32a2 --- /dev/null +++ b/ass3/zbirnik/_build/default/bin/main.ml @@ -0,0 +1,28 @@ +open Zbirnik.Parser +open Zbirnik.SemanticAnalyzer + + +(* Helper functions to print optional values *) +let print_opt_string = function + | Some s -> s + | None -> "" + +let print_opt_int = function + | Some n -> Printf.sprintf "%04X" n + | None -> "----" + + +(* Main function to print a list of lineSemantic *) +let print_lineSemantic_list (lines : lineSemantic list) = + List.iter (fun l -> + Printf.printf "%4d | %8s | %6s | %20s | %s | %s\n" + l.line_no + (print_opt_string l.label) + (string_of_mnemonic l.opcode) + (string_of_mnemonic_type l.mnem) + (print_opt_string l.comment) + (print_opt_int l.loc) + ) lines + + +let () = print_lineSemantic_list (checkLineSemanticOfCode (parser "../../ass1/horner.asm") ) diff --git a/ass3/zbirnik/_build/default/bin/main.mli b/ass3/zbirnik/_build/default/bin/main.mli new file mode 100644 index 0000000..335ae1f --- /dev/null +++ b/ass3/zbirnik/_build/default/bin/main.mli @@ -0,0 +1 @@ +(* Auto-generated by Dune *) \ No newline at end of file diff --git a/ass3/zbirnik/_build/default/lib/.merlin-conf/lib-zbirnik b/ass3/zbirnik/_build/default/lib/.merlin-conf/lib-zbirnik new file mode 100644 index 0000000..4ac6413 Binary files /dev/null and b/ass3/zbirnik/_build/default/lib/.merlin-conf/lib-zbirnik differ diff --git a/ass3/zbirnik/_build/default/lib/.zbirnik.objs/byte/zbirnik.cmi b/ass3/zbirnik/_build/default/lib/.zbirnik.objs/byte/zbirnik.cmi new file mode 100644 index 0000000..c139fa0 Binary files /dev/null and b/ass3/zbirnik/_build/default/lib/.zbirnik.objs/byte/zbirnik.cmi differ diff --git a/ass3/zbirnik/_build/default/lib/.zbirnik.objs/byte/zbirnik.cmo b/ass3/zbirnik/_build/default/lib/.zbirnik.objs/byte/zbirnik.cmo new file mode 100644 index 0000000..6b25557 Binary files /dev/null and b/ass3/zbirnik/_build/default/lib/.zbirnik.objs/byte/zbirnik.cmo differ diff --git a/ass3/zbirnik/_build/default/lib/.zbirnik.objs/byte/zbirnik.cmt b/ass3/zbirnik/_build/default/lib/.zbirnik.objs/byte/zbirnik.cmt new file mode 100644 index 0000000..41da20b Binary files /dev/null and b/ass3/zbirnik/_build/default/lib/.zbirnik.objs/byte/zbirnik.cmt differ diff --git a/ass3/zbirnik/_build/default/lib/.zbirnik.objs/byte/zbirnik__PrehodPrvi.cmi b/ass3/zbirnik/_build/default/lib/.zbirnik.objs/byte/zbirnik__PrehodPrvi.cmi new file mode 100644 index 0000000..89542c5 Binary files /dev/null and b/ass3/zbirnik/_build/default/lib/.zbirnik.objs/byte/zbirnik__PrehodPrvi.cmi differ diff --git a/ass3/zbirnik/_build/default/lib/.zbirnik.objs/byte/zbirnik__PrehodPrvi.cmo b/ass3/zbirnik/_build/default/lib/.zbirnik.objs/byte/zbirnik__PrehodPrvi.cmo new file mode 100644 index 0000000..104827e Binary files /dev/null and b/ass3/zbirnik/_build/default/lib/.zbirnik.objs/byte/zbirnik__PrehodPrvi.cmo differ diff --git a/ass3/zbirnik/_build/default/lib/.zbirnik.objs/byte/zbirnik__PrehodPrvi.cmt b/ass3/zbirnik/_build/default/lib/.zbirnik.objs/byte/zbirnik__PrehodPrvi.cmt new file mode 100644 index 0000000..6a64711 Binary files /dev/null and b/ass3/zbirnik/_build/default/lib/.zbirnik.objs/byte/zbirnik__PrehodPrvi.cmt differ diff --git a/ass3/zbirnik/_build/default/lib/.zbirnik.objs/native/zbirnik.cmx b/ass3/zbirnik/_build/default/lib/.zbirnik.objs/native/zbirnik.cmx new file mode 100644 index 0000000..eeb90a6 Binary files /dev/null and b/ass3/zbirnik/_build/default/lib/.zbirnik.objs/native/zbirnik.cmx differ diff --git a/ass3/zbirnik/_build/default/lib/.zbirnik.objs/native/zbirnik.o b/ass3/zbirnik/_build/default/lib/.zbirnik.objs/native/zbirnik.o new file mode 100644 index 0000000..1bea559 Binary files /dev/null and b/ass3/zbirnik/_build/default/lib/.zbirnik.objs/native/zbirnik.o differ diff --git a/ass3/zbirnik/_build/default/lib/.zbirnik.objs/native/zbirnik__PrehodPrvi.cmx b/ass3/zbirnik/_build/default/lib/.zbirnik.objs/native/zbirnik__PrehodPrvi.cmx new file mode 100644 index 0000000..00365e5 Binary files /dev/null and b/ass3/zbirnik/_build/default/lib/.zbirnik.objs/native/zbirnik__PrehodPrvi.cmx differ diff --git a/ass3/zbirnik/_build/default/lib/.zbirnik.objs/native/zbirnik__PrehodPrvi.o b/ass3/zbirnik/_build/default/lib/.zbirnik.objs/native/zbirnik__PrehodPrvi.o new file mode 100644 index 0000000..ebef95b Binary files /dev/null and b/ass3/zbirnik/_build/default/lib/.zbirnik.objs/native/zbirnik__PrehodPrvi.o differ diff --git a/ass3/zbirnik/_build/default/lib/.zbirnik.objs/zbirnik__Parser.impl.d b/ass3/zbirnik/_build/default/lib/.zbirnik.objs/zbirnik__Parser.impl.d new file mode 100644 index 0000000..fdbb0c3 --- /dev/null +++ b/ass3/zbirnik/_build/default/lib/.zbirnik.objs/zbirnik__Parser.impl.d @@ -0,0 +1 @@ +lib/parser.ml: List String diff --git a/ass3/zbirnik/_build/default/lib/.zbirnik.objs/zbirnik__PrehodPrvi.impl.all-deps b/ass3/zbirnik/_build/default/lib/.zbirnik.objs/zbirnik__PrehodPrvi.impl.all-deps new file mode 100644 index 0000000..149e1e5 --- /dev/null +++ b/ass3/zbirnik/_build/default/lib/.zbirnik.objs/zbirnik__PrehodPrvi.impl.all-deps @@ -0,0 +1,2 @@ +zbirnik__Parser +zbirnik__SemanticAnalyzer diff --git a/ass3/zbirnik/_build/default/lib/.zbirnik.objs/zbirnik__PrehodPrvi.impl.d b/ass3/zbirnik/_build/default/lib/.zbirnik.objs/zbirnik__PrehodPrvi.impl.d new file mode 100644 index 0000000..4286a26 --- /dev/null +++ b/ass3/zbirnik/_build/default/lib/.zbirnik.objs/zbirnik__PrehodPrvi.impl.d @@ -0,0 +1 @@ +lib/prehodPrvi.ml: SemanticAnalyzer diff --git a/ass3/zbirnik/_build/default/lib/parser.ml b/ass3/zbirnik/_build/default/lib/parser.ml new file mode 100644 index 0000000..e6dda10 --- /dev/null +++ b/ass3/zbirnik/_build/default/lib/parser.ml @@ -0,0 +1,88 @@ +(*sprejme .asm file in pretvori v neko interno predstavitev*) + +type line = { + line_no : int; + label : string option; + opcode : string; + operand : string list; (*list of operands*) + comment : string option; + mutable loc : int option; (* assigned in pass1 *) +} + + +let parseLine (lineNo : int) (line : string) : line option= + let trimmedLine = String.trim (line) in (*Znebimo se zacetnih in koncnih presledkov*) + (*empty line or comment line*) + if trimmedLine = "" then None + else if trimmedLine.[0] = '.' then + Some { + line_no = lineNo; + label = None; + opcode = "COMMENT"; + operand = []; + comment = Some trimmedLine ; + loc = None; + + } + + else + (*razdelimo na kodo in komentar za njo*) + let code, (comment : string option) = + match String.index_opt line '.' with + | None -> line, None + | Some i -> + (*izluščimo komentar in komentarju odstranimo predhodnje presledke*) + let c = String.sub line i (String.length line - i) |> String.trim in + (*izluščimo kodo, je pa ne trimamo, ker rabimo prvo presledek da razločimo opcode od label-a*) + let code = String.sub line 0 i in + code, Some c + in + + let tokens = + code + |> String.map (fun c -> if c = ',' then ' ' else c) (*zamenja , z ' ' da lepo parsamo npr RMO A, B*) + |> String.split_on_char ' ' + |> List.map String.trim (* removes surrounding spaces and \r *) + |> List.filter (fun s -> s <> "") in + match tokens with + | [] -> + Some{ + line_no = lineNo; + label = None; + opcode = ""; + operand = []; + comment; + loc = None; + } + | x :: xs -> + if code.[0] <> ' ' && code.[0] <> '\t' then (*pogledamo whitespace ali tab*) + (*se ne začne z presledkom ali tab -> imamo labelo*) + let label = Some x in + match xs with + (*samo labela*) + | [] -> Some{line_no = lineNo; label = label; opcode = ""; operand = []; comment = comment; loc = None} + (*labela + opcode + še nekaj*) + | opcode :: operand -> + Some{line_no = lineNo; label = label;opcode = opcode; operand = operand; comment = comment; loc = None} + else + (*nimamo labele*) + let opcode = x in + let operand = xs in + Some{line_no = lineNo; label = None; opcode = opcode; operand = operand; comment = comment; loc = None} + +(*naredi listo line-ov iz filename*) +let parser (filename : string) : line list = + let ic = open_in filename in + let rec loop line_no acc = + match input_line ic with + | line -> + begin + match parseLine line_no line with + | Some parsed_line -> loop (line_no + 1) (parsed_line :: acc) + | None -> loop (line_no + 1) acc + end + | exception End_of_file -> + close_in ic; + List.rev acc + in + loop 1 [] diff --git a/ass3/zbirnik/_build/default/lib/prehodPrvi.ml b/ass3/zbirnik/_build/default/lib/prehodPrvi.ml new file mode 100644 index 0000000..6fd2a7b --- /dev/null +++ b/ass3/zbirnik/_build/default/lib/prehodPrvi.ml @@ -0,0 +1,38 @@ +(*tukaj je vse povezano s prvim prehodom zbirnika*) +open SemanticAnalyzer + +let startAddr = ref 0 +let locctr = ref 0 + +let prviPrehod (code : lineSemantic list) = + let prviUkaz, ostaliUkazi = + match code with + | [] -> failwith "empty code" + | x :: xs -> x, xs + in + + (*if Opcode == start then*) + if prviUkaz.opcode = START then + let stAdr = get_string_from_mnemType prviUkaz.mnem in + let stAdr = match stAdr with | Some s -> s | None -> "0" in + startAddr := (int_of_string stAdr); + locctr := !startAddr; + (*TODO write line to intermediate file*) + else + (*initialize locctr to 0*) + locctr := 0 + (*while opcode != END loop*) + let rec loop ostaliUkazi = + match ostaliUkazi with + | [] -> () (*smo konec*) + | x :: _s when x.opcode = END -> () (*konec while loopa*) + | x :: xs -> match x.opcode with + | COMMENT -> loop xs (*if this is a comment line*) + | _ -> + (*if there is a symmbol in label field*) + match x.label with + | None -> () + | Some s -> () (*search simtab for s ...*) + ; + (*search opcode -> smo ze naredili v semanticni analizi, tu bomo le ustrezno povečali locctr*) + locctr := !locctr + x.len diff --git a/ass3/zbirnik/_build/default/lib/zbirnik.ml-gen b/ass3/zbirnik/_build/default/lib/zbirnik.ml-gen new file mode 100644 index 0000000..44652f1 --- /dev/null +++ b/ass3/zbirnik/_build/default/lib/zbirnik.ml-gen @@ -0,0 +1,10 @@ +(* generated by dune *) + +(** @canonical Zbirnik.Parser *) +module Parser = Zbirnik__Parser + +(** @canonical Zbirnik.PrehodPrvi *) +module PrehodPrvi = Zbirnik__PrehodPrvi + +(** @canonical Zbirnik.SemanticAnalyzer *) +module SemanticAnalyzer = Zbirnik__SemanticAnalyzer diff --git a/ass3/zbirnik/_build/default/test/.merlin-conf/exe-test_zbirnik b/ass3/zbirnik/_build/default/test/.merlin-conf/exe-test_zbirnik new file mode 100644 index 0000000..3192d4d Binary files /dev/null and b/ass3/zbirnik/_build/default/test/.merlin-conf/exe-test_zbirnik differ diff --git a/ass3/zbirnik/_build/default/test/.test_zbirnik.eobjs/byte/dune__exe__Test_zbirnik.cmi b/ass3/zbirnik/_build/default/test/.test_zbirnik.eobjs/byte/dune__exe__Test_zbirnik.cmi new file mode 100644 index 0000000..cafdeca Binary files /dev/null and b/ass3/zbirnik/_build/default/test/.test_zbirnik.eobjs/byte/dune__exe__Test_zbirnik.cmi differ diff --git a/ass3/zbirnik/_build/default/test/.test_zbirnik.eobjs/byte/dune__exe__Test_zbirnik.cmti b/ass3/zbirnik/_build/default/test/.test_zbirnik.eobjs/byte/dune__exe__Test_zbirnik.cmti new file mode 100644 index 0000000..2bf1afa Binary files /dev/null and b/ass3/zbirnik/_build/default/test/.test_zbirnik.eobjs/byte/dune__exe__Test_zbirnik.cmti differ diff --git a/ass3/zbirnik/_build/default/test/.test_zbirnik.eobjs/native/dune__exe__Test_zbirnik.cmx b/ass3/zbirnik/_build/default/test/.test_zbirnik.eobjs/native/dune__exe__Test_zbirnik.cmx new file mode 100644 index 0000000..6e09097 Binary files /dev/null and b/ass3/zbirnik/_build/default/test/.test_zbirnik.eobjs/native/dune__exe__Test_zbirnik.cmx differ diff --git a/ass3/zbirnik/_build/default/test/.test_zbirnik.eobjs/native/dune__exe__Test_zbirnik.o b/ass3/zbirnik/_build/default/test/.test_zbirnik.eobjs/native/dune__exe__Test_zbirnik.o new file mode 100644 index 0000000..1190cd7 Binary files /dev/null and b/ass3/zbirnik/_build/default/test/.test_zbirnik.eobjs/native/dune__exe__Test_zbirnik.o differ diff --git a/ass3/zbirnik/_build/default/test/test_zbirnik.exe b/ass3/zbirnik/_build/default/test/test_zbirnik.exe new file mode 100644 index 0000000..20b6459 Binary files /dev/null and b/ass3/zbirnik/_build/default/test/test_zbirnik.exe differ diff --git a/ass3/zbirnik/_build/default/test/test_zbirnik.ml b/ass3/zbirnik/_build/default/test/test_zbirnik.ml new file mode 100644 index 0000000..e69de29 diff --git a/ass3/zbirnik/_build/default/test/test_zbirnik.mli b/ass3/zbirnik/_build/default/test/test_zbirnik.mli new file mode 100644 index 0000000..335ae1f --- /dev/null +++ b/ass3/zbirnik/_build/default/test/test_zbirnik.mli @@ -0,0 +1 @@ +(* Auto-generated by Dune *) \ No newline at end of file diff --git a/ass3/zbirnik/_build/default/zbirnik.dune-package b/ass3/zbirnik/_build/default/zbirnik.dune-package new file mode 100644 index 0000000..c140ca8 --- /dev/null +++ b/ass3/zbirnik/_build/default/zbirnik.dune-package @@ -0,0 +1,4 @@ +(lang dune 3.20) +(name zbirnik) +(sections (lib .) (bin ../../bin)) +(files (lib (META dune-package opam)) (bin (zbirnik))) diff --git a/ass3/zbirnik/_build/default/zbirnik.opam b/ass3/zbirnik/_build/default/zbirnik.opam new file mode 100644 index 0000000..a43bbcb --- /dev/null +++ b/ass3/zbirnik/_build/default/zbirnik.opam @@ -0,0 +1,32 @@ +# This file is generated by dune, edit dune-project instead +opam-version: "2.0" +synopsis: "A short synopsis" +description: "A longer description" +maintainer: ["Maintainer Name "] +authors: ["Author Name "] +license: "LICENSE" +tags: ["add topics" "to describe" "your" "project"] +homepage: "https://github.com/username/reponame" +doc: "https://url/to/documentation" +bug-reports: "https://github.com/username/reponame/issues" +depends: [ + "dune" {>= "3.20"} + "ocaml" + "odoc" {with-doc} +] +build: [ + ["dune" "subst"] {dev} + [ + "dune" + "build" + "-p" + name + "-j" + jobs + "@install" + "@runtest" {with-test} + "@doc" {with-doc} + ] +] +dev-repo: "git+https://github.com/username/reponame.git" +x-maintenance-intent: ["(latest)"] diff --git a/ass3/zbirnik/_build/install/default/lib/zbirnik/META b/ass3/zbirnik/_build/install/default/lib/zbirnik/META new file mode 120000 index 0000000..96b0da8 --- /dev/null +++ b/ass3/zbirnik/_build/install/default/lib/zbirnik/META @@ -0,0 +1 @@ +../../../../default/META.zbirnik \ No newline at end of file diff --git a/ass3/zbirnik/_build/install/default/lib/zbirnik/dune-package b/ass3/zbirnik/_build/install/default/lib/zbirnik/dune-package new file mode 120000 index 0000000..9420ba5 --- /dev/null +++ b/ass3/zbirnik/_build/install/default/lib/zbirnik/dune-package @@ -0,0 +1 @@ +../../../../default/zbirnik.dune-package \ No newline at end of file diff --git a/ass3/zbirnik/_build/install/default/lib/zbirnik/opam b/ass3/zbirnik/_build/install/default/lib/zbirnik/opam new file mode 120000 index 0000000..dc8ddaf --- /dev/null +++ b/ass3/zbirnik/_build/install/default/lib/zbirnik/opam @@ -0,0 +1 @@ +../../../../default/zbirnik.opam \ No newline at end of file diff --git a/ass3/zbirnik/_build/log b/ass3/zbirnik/_build/log new file mode 100644 index 0000000..506ea19 --- /dev/null +++ b/ass3/zbirnik/_build/log @@ -0,0 +1,32 @@ +# dune build +# OCAMLPARAM: unset +# Shared cache: enabled-except-user-rules +# Shared cache location: /home/jaka/.cache/dune/db +# Workspace root: /mnt/c/Programiranje/SPO/ass3/zbirnik +# Auto-detected concurrency: 16 +# Dune context: +# { name = "default" +# ; kind = "default" +# ; profile = Dev +# ; merlin = true +# ; fdo_target_exe = None +# ; build_dir = In_build_dir "default" +# ; instrument_with = [] +# } +$ /usr/bin/ocamlc.opt -config > /tmp/dune_52f57b_output +$ (cd _build/default && /usr/bin/ocamldep.opt -modules -impl lib/semanticAnalyzer.ml) > _build/default/lib/.zbirnik.objs/zbirnik__SemanticAnalyzer.impl.d +$ (cd _build/default && /usr/bin/ocamldep.opt -modules -impl lib/prehodPrvi.ml) > _build/default/lib/.zbirnik.objs/zbirnik__PrehodPrvi.impl.d +$ (cd _build/default && /usr/bin/ocamlc.opt -w @1..3@5..28@31..39@43@46..47@49..57@61..62@67@69-40 -strict-sequence -strict-formats -short-paths -keep-locs -g -bin-annot -I lib/.zbirnik.objs/byte -no-alias-deps -opaque -open Zbirnik -o lib/.zbirnik.objs/byte/zbirnik__SemanticAnalyzer.cmo -c -impl lib/semanticAnalyzer.ml) +> File "lib/semanticAnalyzer.ml", line 280, characters 12-16: +> 280 | let getLen (mnem : mnemonic) (ext : bool) (mnemType : mnemonic_type) : int = +> ^^^^ +> Error (warning 27 [unused-var-strict]): unused variable mnem. +> File "lib/semanticAnalyzer.ml", line 280, characters 30-33: +> 280 | let getLen (mnem : mnemonic) (ext : bool) (mnemType : mnemonic_type) : int = +> ^^^ +> Error (warning 27 [unused-var-strict]): unused variable ext. +> File "lib/semanticAnalyzer.ml", line 280, characters 43-51: +> 280 | let getLen (mnem : mnemonic) (ext : bool) (mnemType : mnemonic_type) : int = +> ^^^^^^^^ +> Error (warning 27 [unused-var-strict]): unused variable mnemType. +[2] diff --git a/ass3/zbirnik/bin/dune b/ass3/zbirnik/bin/dune new file mode 100644 index 0000000..bbbd9b1 --- /dev/null +++ b/ass3/zbirnik/bin/dune @@ -0,0 +1,4 @@ +(executable + (public_name zbirnik) + (name main) + (libraries zbirnik)) diff --git a/ass3/zbirnik/bin/main.ml b/ass3/zbirnik/bin/main.ml new file mode 100644 index 0000000..1de32a2 --- /dev/null +++ b/ass3/zbirnik/bin/main.ml @@ -0,0 +1,28 @@ +open Zbirnik.Parser +open Zbirnik.SemanticAnalyzer + + +(* Helper functions to print optional values *) +let print_opt_string = function + | Some s -> s + | None -> "" + +let print_opt_int = function + | Some n -> Printf.sprintf "%04X" n + | None -> "----" + + +(* Main function to print a list of lineSemantic *) +let print_lineSemantic_list (lines : lineSemantic list) = + List.iter (fun l -> + Printf.printf "%4d | %8s | %6s | %20s | %s | %s\n" + l.line_no + (print_opt_string l.label) + (string_of_mnemonic l.opcode) + (string_of_mnemonic_type l.mnem) + (print_opt_string l.comment) + (print_opt_int l.loc) + ) lines + + +let () = print_lineSemantic_list (checkLineSemanticOfCode (parser "../../ass1/horner.asm") ) diff --git a/ass3/zbirnik/dune-project b/ass3/zbirnik/dune-project new file mode 100644 index 0000000..38a2bb2 --- /dev/null +++ b/ass3/zbirnik/dune-project @@ -0,0 +1,26 @@ +(lang dune 3.20) + +(name zbirnik) + +(generate_opam_files true) + +(source + (github username/reponame)) + +(authors "Author Name ") + +(maintainers "Maintainer Name ") + +(license LICENSE) + +(documentation https://url/to/documentation) + +(package + (name zbirnik) + (synopsis "A short synopsis") + (description "A longer description") + (depends ocaml) + (tags + ("add topics" "to describe" your project))) + +; See the complete stanza docs at https://dune.readthedocs.io/en/stable/reference/dune-project/index.html diff --git a/ass3/zbirnik/lib/dune b/ass3/zbirnik/lib/dune new file mode 100644 index 0000000..deeb942 --- /dev/null +++ b/ass3/zbirnik/lib/dune @@ -0,0 +1,3 @@ +(library + (name zbirnik) + (libraries str)) diff --git a/ass3/zbirnik/lib/parser.ml b/ass3/zbirnik/lib/parser.ml new file mode 100644 index 0000000..e6dda10 --- /dev/null +++ b/ass3/zbirnik/lib/parser.ml @@ -0,0 +1,88 @@ +(*sprejme .asm file in pretvori v neko interno predstavitev*) + +type line = { + line_no : int; + label : string option; + opcode : string; + operand : string list; (*list of operands*) + comment : string option; + mutable loc : int option; (* assigned in pass1 *) +} + + +let parseLine (lineNo : int) (line : string) : line option= + let trimmedLine = String.trim (line) in (*Znebimo se zacetnih in koncnih presledkov*) + (*empty line or comment line*) + if trimmedLine = "" then None + else if trimmedLine.[0] = '.' then + Some { + line_no = lineNo; + label = None; + opcode = "COMMENT"; + operand = []; + comment = Some trimmedLine ; + loc = None; + + } + + else + (*razdelimo na kodo in komentar za njo*) + let code, (comment : string option) = + match String.index_opt line '.' with + | None -> line, None + | Some i -> + (*izluščimo komentar in komentarju odstranimo predhodnje presledke*) + let c = String.sub line i (String.length line - i) |> String.trim in + (*izluščimo kodo, je pa ne trimamo, ker rabimo prvo presledek da razločimo opcode od label-a*) + let code = String.sub line 0 i in + code, Some c + in + + let tokens = + code + |> String.map (fun c -> if c = ',' then ' ' else c) (*zamenja , z ' ' da lepo parsamo npr RMO A, B*) + |> String.split_on_char ' ' + |> List.map String.trim (* removes surrounding spaces and \r *) + |> List.filter (fun s -> s <> "") in + match tokens with + | [] -> + Some{ + line_no = lineNo; + label = None; + opcode = ""; + operand = []; + comment; + loc = None; + } + | x :: xs -> + if code.[0] <> ' ' && code.[0] <> '\t' then (*pogledamo whitespace ali tab*) + (*se ne začne z presledkom ali tab -> imamo labelo*) + let label = Some x in + match xs with + (*samo labela*) + | [] -> Some{line_no = lineNo; label = label; opcode = ""; operand = []; comment = comment; loc = None} + (*labela + opcode + še nekaj*) + | opcode :: operand -> + Some{line_no = lineNo; label = label;opcode = opcode; operand = operand; comment = comment; loc = None} + else + (*nimamo labele*) + let opcode = x in + let operand = xs in + Some{line_no = lineNo; label = None; opcode = opcode; operand = operand; comment = comment; loc = None} + +(*naredi listo line-ov iz filename*) +let parser (filename : string) : line list = + let ic = open_in filename in + let rec loop line_no acc = + match input_line ic with + | line -> + begin + match parseLine line_no line with + | Some parsed_line -> loop (line_no + 1) (parsed_line :: acc) + | None -> loop (line_no + 1) acc + end + | exception End_of_file -> + close_in ic; + List.rev acc + in + loop 1 [] diff --git a/ass3/zbirnik/lib/prehodPrvi.ml b/ass3/zbirnik/lib/prehodPrvi.ml new file mode 100644 index 0000000..6e8f256 --- /dev/null +++ b/ass3/zbirnik/lib/prehodPrvi.ml @@ -0,0 +1,45 @@ +(*tukaj je vse povezano s prvim prehodom zbirnika*) +open SemanticAnalyzer + +let startAddr = ref 0 +let locctr = ref 0 + +let prviPrehod (code : lineSemantic list) = + let prviUkaz, ostaliUkazi = + match code with + | [] -> failwith "empty code" + | x :: xs -> x, xs + in + + (*if Opcode == start then*) + + if prviUkaz.opcode = START then + let stAdr = get_string_from_mnemType prviUkaz.mnem in + let stAdr = match stAdr with | Some s -> s | None -> "0" in + startAddr := (int_of_string stAdr); + locctr := !startAddr; + (*TODO write line to intermediate file*) + else + (*initialize locctr to 0*) + locctr := 0 + + ; + (*while opcode != END loop*) + let rec loop ostaliUkazi = + match ostaliUkazi with + | [] -> () (*smo konec*) + | x :: _ when x.opcode = END -> () (*konec while loopa*) (*TODO write last line to intermediate file, save the locctr - st addr as prg len*) + | x :: xs -> match x.opcode with + | COMMENT -> loop xs (*if this is a comment line*) + | _ -> + (*if there is a symmbol in label field*) + let s = match x.label with + | None -> () + | Some s -> () (*search simtab for s ...*) + in + (*search opcode -> smo ze naredili v semanticni analizi, tu bomo le ustrezno povečali locctr*) + locctr := !locctr + x.len; + (*TODO write line to intermediate file*) + loop xs (*read nex input line end while*) + in loop ostaliUkazi + diff --git a/ass3/zbirnik/test/dune b/ass3/zbirnik/test/dune new file mode 100644 index 0000000..19fecdb --- /dev/null +++ b/ass3/zbirnik/test/dune @@ -0,0 +1,2 @@ +(test + (name test_zbirnik)) diff --git a/ass3/zbirnik/test/test_zbirnik.ml b/ass3/zbirnik/test/test_zbirnik.ml new file mode 100644 index 0000000..e69de29 diff --git a/ass3/zbirnik/zbirnik.opam b/ass3/zbirnik/zbirnik.opam new file mode 100644 index 0000000..a43bbcb --- /dev/null +++ b/ass3/zbirnik/zbirnik.opam @@ -0,0 +1,32 @@ +# This file is generated by dune, edit dune-project instead +opam-version: "2.0" +synopsis: "A short synopsis" +description: "A longer description" +maintainer: ["Maintainer Name "] +authors: ["Author Name "] +license: "LICENSE" +tags: ["add topics" "to describe" "your" "project"] +homepage: "https://github.com/username/reponame" +doc: "https://url/to/documentation" +bug-reports: "https://github.com/username/reponame/issues" +depends: [ + "dune" {>= "3.20"} + "ocaml" + "odoc" {with-doc} +] +build: [ + ["dune" "subst"] {dev} + [ + "dune" + "build" + "-p" + name + "-j" + jobs + "@install" + "@runtest" {with-test} + "@doc" {with-doc} + ] +] +dev-repo: "git+https://github.com/username/reponame.git" +x-maintenance-intent: ["(latest)"]