first
This commit is contained in:
parent
586a58fd94
commit
c707e3253c
53 changed files with 500 additions and 27 deletions
BIN
ass3/zbirnik/_build/.db
Normal file
BIN
ass3/zbirnik/_build/.db
Normal file
Binary file not shown.
BIN
ass3/zbirnik/_build/.digest-db
Normal file
BIN
ass3/zbirnik/_build/.digest-db
Normal file
Binary file not shown.
1
ass3/zbirnik/_build/.filesystem-clock
Normal file
1
ass3/zbirnik/_build/.filesystem-clock
Normal file
|
|
@ -0,0 +1 @@
|
|||
<dummy>
|
||||
0
ass3/zbirnik/_build/.lock
Normal file
0
ass3/zbirnik/_build/.lock
Normal file
2
ass3/zbirnik/_build/default/.dune/configurator
Normal file
2
ass3/zbirnik/_build/default/.dune/configurator
Normal file
|
|
@ -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))
|
||||
1
ass3/zbirnik/_build/default/.dune/configurator.v2
Normal file
1
ass3/zbirnik/_build/default/.dune/configurator.v2
Normal file
|
|
@ -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))))
|
||||
0
ass3/zbirnik/_build/default/META.zbirnik
Normal file
0
ass3/zbirnik/_build/default/META.zbirnik
Normal file
BIN
ass3/zbirnik/_build/default/bin/.merlin-conf/exe-main
Normal file
BIN
ass3/zbirnik/_build/default/bin/.merlin-conf/exe-main
Normal file
Binary file not shown.
28
ass3/zbirnik/_build/default/bin/main.ml
Normal file
28
ass3/zbirnik/_build/default/bin/main.ml
Normal file
|
|
@ -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") )
|
||||
1
ass3/zbirnik/_build/default/bin/main.mli
Normal file
1
ass3/zbirnik/_build/default/bin/main.mli
Normal file
|
|
@ -0,0 +1 @@
|
|||
(* Auto-generated by Dune *)
|
||||
BIN
ass3/zbirnik/_build/default/lib/.merlin-conf/lib-zbirnik
Normal file
BIN
ass3/zbirnik/_build/default/lib/.merlin-conf/lib-zbirnik
Normal file
Binary file not shown.
BIN
ass3/zbirnik/_build/default/lib/.zbirnik.objs/byte/zbirnik.cmi
Normal file
BIN
ass3/zbirnik/_build/default/lib/.zbirnik.objs/byte/zbirnik.cmi
Normal file
Binary file not shown.
BIN
ass3/zbirnik/_build/default/lib/.zbirnik.objs/byte/zbirnik.cmo
Normal file
BIN
ass3/zbirnik/_build/default/lib/.zbirnik.objs/byte/zbirnik.cmo
Normal file
Binary file not shown.
BIN
ass3/zbirnik/_build/default/lib/.zbirnik.objs/byte/zbirnik.cmt
Normal file
BIN
ass3/zbirnik/_build/default/lib/.zbirnik.objs/byte/zbirnik.cmt
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
ass3/zbirnik/_build/default/lib/.zbirnik.objs/native/zbirnik.cmx
Normal file
BIN
ass3/zbirnik/_build/default/lib/.zbirnik.objs/native/zbirnik.cmx
Normal file
Binary file not shown.
BIN
ass3/zbirnik/_build/default/lib/.zbirnik.objs/native/zbirnik.o
Normal file
BIN
ass3/zbirnik/_build/default/lib/.zbirnik.objs/native/zbirnik.o
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -0,0 +1 @@
|
|||
lib/parser.ml: List String
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
zbirnik__Parser
|
||||
zbirnik__SemanticAnalyzer
|
||||
|
|
@ -0,0 +1 @@
|
|||
lib/prehodPrvi.ml: SemanticAnalyzer
|
||||
88
ass3/zbirnik/_build/default/lib/parser.ml
Normal file
88
ass3/zbirnik/_build/default/lib/parser.ml
Normal file
|
|
@ -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 []
|
||||
38
ass3/zbirnik/_build/default/lib/prehodPrvi.ml
Normal file
38
ass3/zbirnik/_build/default/lib/prehodPrvi.ml
Normal file
|
|
@ -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
|
||||
10
ass3/zbirnik/_build/default/lib/zbirnik.ml-gen
Normal file
10
ass3/zbirnik/_build/default/lib/zbirnik.ml-gen
Normal file
|
|
@ -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
|
||||
BIN
ass3/zbirnik/_build/default/test/.merlin-conf/exe-test_zbirnik
Normal file
BIN
ass3/zbirnik/_build/default/test/.merlin-conf/exe-test_zbirnik
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
ass3/zbirnik/_build/default/test/test_zbirnik.exe
Normal file
BIN
ass3/zbirnik/_build/default/test/test_zbirnik.exe
Normal file
Binary file not shown.
0
ass3/zbirnik/_build/default/test/test_zbirnik.ml
Normal file
0
ass3/zbirnik/_build/default/test/test_zbirnik.ml
Normal file
1
ass3/zbirnik/_build/default/test/test_zbirnik.mli
Normal file
1
ass3/zbirnik/_build/default/test/test_zbirnik.mli
Normal file
|
|
@ -0,0 +1 @@
|
|||
(* Auto-generated by Dune *)
|
||||
4
ass3/zbirnik/_build/default/zbirnik.dune-package
Normal file
4
ass3/zbirnik/_build/default/zbirnik.dune-package
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
(lang dune 3.20)
|
||||
(name zbirnik)
|
||||
(sections (lib .) (bin ../../bin))
|
||||
(files (lib (META dune-package opam)) (bin (zbirnik)))
|
||||
32
ass3/zbirnik/_build/default/zbirnik.opam
Normal file
32
ass3/zbirnik/_build/default/zbirnik.opam
Normal file
|
|
@ -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 <maintainer@example.com>"]
|
||||
authors: ["Author Name <author@example.com>"]
|
||||
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)"]
|
||||
1
ass3/zbirnik/_build/install/default/lib/zbirnik/META
Symbolic link
1
ass3/zbirnik/_build/install/default/lib/zbirnik/META
Symbolic link
|
|
@ -0,0 +1 @@
|
|||
../../../../default/META.zbirnik
|
||||
1
ass3/zbirnik/_build/install/default/lib/zbirnik/dune-package
Symbolic link
1
ass3/zbirnik/_build/install/default/lib/zbirnik/dune-package
Symbolic link
|
|
@ -0,0 +1 @@
|
|||
../../../../default/zbirnik.dune-package
|
||||
1
ass3/zbirnik/_build/install/default/lib/zbirnik/opam
Symbolic link
1
ass3/zbirnik/_build/install/default/lib/zbirnik/opam
Symbolic link
|
|
@ -0,0 +1 @@
|
|||
../../../../default/zbirnik.opam
|
||||
32
ass3/zbirnik/_build/log
Normal file
32
ass3/zbirnik/_build/log
Normal file
|
|
@ -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]
|
||||
4
ass3/zbirnik/bin/dune
Normal file
4
ass3/zbirnik/bin/dune
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
(executable
|
||||
(public_name zbirnik)
|
||||
(name main)
|
||||
(libraries zbirnik))
|
||||
28
ass3/zbirnik/bin/main.ml
Normal file
28
ass3/zbirnik/bin/main.ml
Normal file
|
|
@ -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") )
|
||||
26
ass3/zbirnik/dune-project
Normal file
26
ass3/zbirnik/dune-project
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
(lang dune 3.20)
|
||||
|
||||
(name zbirnik)
|
||||
|
||||
(generate_opam_files true)
|
||||
|
||||
(source
|
||||
(github username/reponame))
|
||||
|
||||
(authors "Author Name <author@example.com>")
|
||||
|
||||
(maintainers "Maintainer Name <maintainer@example.com>")
|
||||
|
||||
(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
|
||||
3
ass3/zbirnik/lib/dune
Normal file
3
ass3/zbirnik/lib/dune
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
(library
|
||||
(name zbirnik)
|
||||
(libraries str))
|
||||
88
ass3/zbirnik/lib/parser.ml
Normal file
88
ass3/zbirnik/lib/parser.ml
Normal file
|
|
@ -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 []
|
||||
45
ass3/zbirnik/lib/prehodPrvi.ml
Normal file
45
ass3/zbirnik/lib/prehodPrvi.ml
Normal file
|
|
@ -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
|
||||
|
||||
2
ass3/zbirnik/test/dune
Normal file
2
ass3/zbirnik/test/dune
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
(test
|
||||
(name test_zbirnik))
|
||||
0
ass3/zbirnik/test/test_zbirnik.ml
Normal file
0
ass3/zbirnik/test/test_zbirnik.ml
Normal file
32
ass3/zbirnik/zbirnik.opam
Normal file
32
ass3/zbirnik/zbirnik.opam
Normal file
|
|
@ -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 <maintainer@example.com>"]
|
||||
authors: ["Author Name <author@example.com>"]
|
||||
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)"]
|
||||
Loading…
Add table
Add a link
Reference in a new issue