working on prehod 2...
This commit is contained in:
parent
f79aa96359
commit
6261d9fe37
6 changed files with 84 additions and 27 deletions
|
|
@ -2,6 +2,7 @@
|
|||
open Simtab
|
||||
open SemanticAnalyzer
|
||||
open Encoder
|
||||
open Instruction
|
||||
|
||||
let drugiPrehod (ifl : lineSemantic list) (simtab : symtab) (lenProg : int) : string list =
|
||||
let prviUkaz, ostaliUkazi =
|
||||
|
|
@ -10,19 +11,21 @@ let drugiPrehod (ifl : lineSemantic list) (simtab : symtab) (lenProg : int) : st
|
|||
| x :: xs -> x, xs
|
||||
in
|
||||
(*if Opcode == start then*)
|
||||
let objectCodeList = (*string list ki hrani vrstice objektne kode*)
|
||||
let objectCodeList, start = (*string list ki hrani vrstice objektne kode, start se uporabi še v E zapisu*)
|
||||
if prviUkaz.opcode = START then
|
||||
getZaglavje prviUkaz lenProg
|
||||
getZaglavjeAndStart prviUkaz lenProg
|
||||
else
|
||||
failwith "prvi ukaz ni START"
|
||||
in
|
||||
let instructionList : string list = [] in (*opcodeList shranjuje kode ukazov pretvorjene v stringe, ko se napolni se appenda k objectCodeList*)
|
||||
let instructionList : string list = [] in (*instructionList shranjuje kode ukazov pretvorjene v stringe, ko se napolni se appenda k objectCodeList*)
|
||||
let rec loop (ostaliUkazi : lineSemantic list) (objectCodeList : string list) (startAddr : int) (instructionList : string list) : string list =
|
||||
match ostaliUkazi with
|
||||
| [] -> () (*smo konec*)
|
||||
| x :: _ when x.opcode = END -> () (*TODO write last text record to object programm*)
|
||||
(*TODO write end record to object program*)
|
||||
(*TODOwrite last listing line*)
|
||||
| [] -> failwith "no END mnemonic at the end of the code!"
|
||||
| x :: _ when x.opcode = END -> (*write last text record to object programm*)
|
||||
let newTextLine = instructionList_to_objectCode (List.rev instructionList) startAddr in (*naredimo novo T vrstico*)
|
||||
let endLine = getEnd start in (*naredimo End zapis*)
|
||||
let objectCodeList = List.rev (endLine :: newTextLine :: objectCodeList) in
|
||||
objectCodeList (*vrnemo celotno objektno kodo*)
|
||||
| x :: xs ->
|
||||
(*pridobi začeten naslov TEXT vrstice, če je le ta prazna*)
|
||||
let newStartAddress = match instructionList with
|
||||
|
|
@ -36,20 +39,31 @@ let drugiPrehod (ifl : lineSemantic list) (simtab : symtab) (lenProg : int) : st
|
|||
begin
|
||||
match instructionList with (*če je instructionList prazen, npr. 2 zaporedna RESB ukaza, ne dodamo te prazne T vrstice v obj kodo*)
|
||||
| [] -> loop xs objectCodeList newStartAddress []
|
||||
| ntl -> loop xs (ntl :: objectCodeList) newStartAddress []
|
||||
| _ -> loop xs (newTextLine :: objectCodeList) newStartAddress []
|
||||
end
|
||||
| _ -> (*if not comment or reserve*)
|
||||
let opcode = getOpcode x.opcode in
|
||||
(*if simbol na mestu opeanda*)
|
||||
let isSymbol, symbol = operand_is_symbol x.mnem in
|
||||
if isSymbol then
|
||||
let locSimbola = find_symbol tab symbol in
|
||||
let opcode = create_opcode x.opcode locSimbola in
|
||||
(*TODO dodaj opcode v line, ce ni prostora dodaj line v file in naredi novega*)
|
||||
()
|
||||
let isSymbol, symbol = operand_is_symbol x.mnem in
|
||||
if isSymbol then
|
||||
begin
|
||||
let locSimbola = find_symbol tab symbol in
|
||||
let opcode = create_opcode_symbol x.opcode locSimbola in
|
||||
(*dodaj opcode v line, ce ni prostora dodaj line v file in naredi novega*)
|
||||
if String.length instructionList > 25 then (*če ratuje T zapis predolg dodamo še tole in nato nadaljujemo z novim*)
|
||||
let newTextLine = instructionList_to_objectCode (List.rev instructionList) newStartAddress in (*naredimo novo T vrstico*)
|
||||
loop xs (newTextLine :: objectCodeList) newStartAddress []
|
||||
else
|
||||
let opcode = create_opcode x.opcode (int_of_string symbol) in (*symbol je tukaj kar stevilska vrednost/register*)
|
||||
(*TODO dodaj opcode v line, ce ni prostora dodaj line v file in naredi novega*)
|
||||
()
|
||||
loop xs objectCodeList newStartAddress (opcode :: instructionList)
|
||||
end
|
||||
else
|
||||
let opcode = create_opcode x.opcode x.mnem in (*symbol je tukaj kar stevilska vrednost/register*)
|
||||
(*TODO dodaj opcode v line, ce ni prostora dodaj line v file in naredi novega*)
|
||||
begin
|
||||
if String.length instructionList > 25 then (*če ratuje T zapis predolg dodamo še tole in nato nadaljujemo z novim*)
|
||||
let newTextLine = instructionList_to_objectCode (List.rev instructionList) newStartAddress in (*naredimo novo T vrstico*)
|
||||
loop xs (newTextLine :: objectCodeList) newStartAddress []
|
||||
else
|
||||
loop xs objectCodeList newStartAddress (opcode :: instructionList)
|
||||
end
|
||||
|
||||
in loop ostaliUkazi objectCodeList startAddr instructionList
|
||||
Loading…
Add table
Add a link
Reference in a new issue