import * as _ from "lodash" ; import { Instruction } from "../emulation/instruction/instruction" ; import { CPU } from "../emulation/cpu" ; import { EncodedInstruction } from "./encoding" ; import { MemoryDefinition } from "./assembler" ; export class LineMap { private mapping : any = { } ; public mapLine ( address , line ) { this . mapping [ address ] = line ; } public getLineByAddress ( address ) { return _ . findLast ( this . mapping , ( line , key ) => key <= address ) ; } public getAddressByLine ( row ) { return Number ( _ . findKey ( this . mapping , ( line ) => line === row ) ) ; } } export class Program { constructor ( private _instructions , private _memoryDefinitions , private _lineMap ) { } get instructions ( ) : EncodedInstruction [ ] { return this . _instructions ; } get memoryDefinitions ( ) : MemoryDefinition [ ] { return this . _memoryDefinitions ; } public get lineMap ( ) : LineMap { return this . _lineMap ; } public getInstructionByAddress ( cpu , address ) { return this . instructions [ address ] . instantiate ( cpu ) ; } }