working on ass3, todo pc, nixbpe
This commit is contained in:
parent
6261d9fe37
commit
beabcde7db
15 changed files with 412 additions and 194 deletions
|
|
@ -3,8 +3,9 @@ open Simtab
|
|||
open SemanticAnalyzer
|
||||
open Encoder
|
||||
open Instruction
|
||||
open OpcodeTable
|
||||
|
||||
let drugiPrehod (ifl : lineSemantic list) (simtab : symtab) (lenProg : int) : string list =
|
||||
let drugiPrehod (ifl : lineSemantic list) (simtab : symtab) (opcodeTab : opcodeTab) (lenProg : int) : string list =
|
||||
let prviUkaz, ostaliUkazi =
|
||||
match ifl with
|
||||
| [] -> failwith "empty code"
|
||||
|
|
@ -41,29 +42,35 @@ let drugiPrehod (ifl : lineSemantic list) (simtab : symtab) (lenProg : int) : st
|
|||
| [] -> loop xs objectCodeList newStartAddress []
|
||||
| _ -> loop xs (newTextLine :: objectCodeList) newStartAddress []
|
||||
end
|
||||
| BYTE ->
|
||||
let operand = match x.mnem with | MnemonicSd s -> s | _ -> failwith "narobe mnemType za BYTE" in
|
||||
let opcode = create_opcode_byte operand in
|
||||
(*dodaj opcode v line, ce ni prostora dodaj line v file in naredi novega*)
|
||||
if List.length instructionList > 25 then (*če ratuje T zapis predolg dodamo še tole in nato nadaljujemo z novim*)
|
||||
let newTextLine = instructionList_to_objectCode (List.rev (opcode :: instructionList)) newStartAddress in (*naredimo novo T vrstico*)
|
||||
loop xs (newTextLine :: objectCodeList) newStartAddress []
|
||||
else
|
||||
loop xs objectCodeList newStartAddress (opcode :: instructionList)
|
||||
| WORD ->
|
||||
let operand = match x.mnem with | MnemonicSd s -> s | _ -> failwith "narobe mnemType za WORD" in
|
||||
let opcode = create_opcode_word operand in
|
||||
(*dodaj opcode v line, ce ni prostora dodaj line v file in naredi novega*)
|
||||
if List.length instructionList > 25 then (*če ratuje T zapis predolg dodamo še tole in nato nadaljujemo z novim*)
|
||||
let newTextLine = instructionList_to_objectCode (List.rev (opcode :: instructionList)) newStartAddress in (*naredimo novo T vrstico*)
|
||||
loop xs (newTextLine :: objectCodeList) newStartAddress []
|
||||
else
|
||||
loop xs objectCodeList newStartAddress (opcode :: instructionList)
|
||||
| _ -> (*if not comment or reserve*)
|
||||
(*if simbol na mestu opeanda*)
|
||||
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
|
||||
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
|
||||
match operand_is_symbol x with
|
||||
| None -> loop xs objectCodeList newStartAddress instructionList (*None -> ta ukaz se ne zapiše, ga skipamo*)
|
||||
| Some (_, operand, formatLen) ->
|
||||
let opcode = create_opcode simtab opcodeTab x.opcode operand formatLen x.loc in
|
||||
(*dodaj opcode v line, ce ni prostora dodaj line v file in naredi novega*)
|
||||
if List.length instructionList > 25 then (*če ratuje T zapis predolg dodamo še tole in nato nadaljujemo z novim*)
|
||||
let newTextLine = instructionList_to_objectCode (List.rev (opcode :: instructionList)) newStartAddress in (*naredimo novo T vrstico*)
|
||||
loop xs (newTextLine :: objectCodeList) newStartAddress []
|
||||
else
|
||||
loop xs objectCodeList newStartAddress (opcode :: instructionList)
|
||||
|
||||
in loop ostaliUkazi objectCodeList startAddr instructionList
|
||||
in loop ostaliUkazi objectCodeList start instructionList
|
||||
Loading…
Add table
Add a link
Reference in a new issue