first
This commit is contained in:
parent
586a58fd94
commit
c707e3253c
53 changed files with 500 additions and 27 deletions
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
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue