Skip to content

Commit

Permalink
make RAM display performant and usable for RAMs with many locations f…
Browse files Browse the repository at this point in the history
…illed
  • Loading branch information
tomcl committed Aug 29, 2024
1 parent 518f200 commit a3837ca
Show file tree
Hide file tree
Showing 31 changed files with 1,098 additions and 998 deletions.
1,774 changes: 891 additions & 883 deletions src/Renderer/Common/CommonTypes.fs

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions src/Renderer/Common/Optics.fs
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,13 @@ module Optics =
| None -> failwithf "%s" getFailErrorMessage),
(fun v x -> Map.add k v x)

/// Safe lens to a value associated with a key in a map.
/// If the key does not exist defaultVal is returned
let inline valueWithDefault_ (defaultVal: 'v) (k: 'k) : Lens<Map<'k,'v>, 'v> =
((Map.tryFind k)
>> function | Some v -> v
| None -> defaultVal),
(fun v x -> Map.add k v x)

/// Weak Isomorphism to an array of key-value pairs.
let array_ : Isomorphism<Map<'k,'v>, ('k * 'v)[]> =
Expand Down
1 change: 0 additions & 1 deletion src/Renderer/DrawBlock/BusWireUpdateHelpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,6 @@ let resetJumpsOrIntersections (wire: Wire) =
{wire with Segments = newSegs}

let resetJumps (model:Model) : Model =
printfn "Reseting jumps or intersections..."
(model.Wires, model.Wires)
||> Map.fold (fun wires wid wire ->
Map.add wid (resetJumpsOrIntersections wire) wires)
Expand Down
2 changes: 0 additions & 2 deletions src/Renderer/DrawBlock/RotateScale.fs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ let reSizeSymbolTopLevel
(symbolToSize: Symbol)
(otherSymbol: Symbol)
: BusWireT.Model =
printfn $"ReSizeSymbol: ToResize:{symbolToSize.Component.Label}, Other:{otherSymbol.Component.Label}"

let scaledSymbol = reSizeSymbol wModel symbolToSize otherSymbol

Expand Down Expand Up @@ -535,7 +534,6 @@ let rotateSymbolByDegree (degree: Rotation) (sym:Symbol) =
/// <returns>New rotated symbol model</returns>
let rotateBlock (compList:ComponentId list) (model:SymbolT.Model) (rotation:Rotation) =

printfn "running rotateBlock"
let SelectedSymbols = List.map (fun x -> model.Symbols |> Map.find x) compList
let UnselectedSymbols = model.Symbols |> Map.filter (fun x _ -> not (List.contains x compList))

Expand Down
4 changes: 1 addition & 3 deletions src/Renderer/DrawBlock/SymbolPortHelpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,8 @@ let updatePortPos (sym:Symbol) (pos:XYPos) (portId: string) : Symbol =
let oldMaps = sym.PortMaps
match getCloseByEdge sym pos with
| None ->
printfn "not on edge"
{sym with MovingPort = None}
| Some edge ->
printfn $"{edge}"
let newPortOrientation = oldMaps.Orientation |> Map.add portId edge
let oldEdge = oldMaps.Orientation[portId]
let newPortIdx = getPosIndex sym pos edge
Expand All @@ -238,11 +236,11 @@ let updatePortPos (sym:Symbol) (pos:XYPos) (portId: string) : Symbol =
let oldPortOrder' =
oldMaps.Order
|> Map.add oldEdge (oldMaps.Order[oldEdge] |> List.filter (fun el -> el <> portId))

let newPortIdx' =
if newPortIdx > oldPortOrder'[edge].Length then oldPortOrder'[edge].Length
else if edge = oldEdge && oldIdx < newPortIdx then newPortIdx - 1
else newPortIdx
printfn $"{(newPortIdx, newPortIdx')}"

let newPortOrder =
oldPortOrder'
Expand Down
2 changes: 0 additions & 2 deletions src/Renderer/DrawBlock/SymbolResizeHelpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ let rotateSide (rotation: Rotation) (side:Edge) :Edge =
/// rotates the portMap information left or right as per rotation
let rotatePortInfo (rotation:Rotation) (portMaps:PortMaps) : PortMaps=
//need to update portOrientation and portOrder
printfn "running rotatePortInfo"
let newPortOrientation =
portMaps.Orientation |> Map.map (fun id side -> rotateSide rotation side)

Expand Down Expand Up @@ -179,7 +178,6 @@ let manualSymbolResize
(fixedCornerLoc: XYPos) // XYPos of corner opposite that which is clicked - this will not change
(mPos: XYPos) // XYPos of mouse. Symbol will be resized to make its clicked corner match this
=
printfn "running manualSymbolResize"
let symbol = model.Symbols[compId]
let symPos = get posOfSym_ symbol
let comp = symbol.Component
Expand Down
15 changes: 7 additions & 8 deletions src/Renderer/Model/ModelType.fs
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,6 @@ type Wave = {
SVG: ReactElement option
}

type WSConfig = {
LastClock: int
FirstClock: int
FontSize: int
FontWeight: int
}

let lastClock_ = Lens.create (fun a -> a.LastClock) (fun s a -> {a with LastClock = s})
let firstClock_ = Lens.create (fun a -> a.FirstClock) (fun s a -> {a with FirstClock = s})
let fontSize_ = Lens.create (fun a -> a.FontSize) (fun s a -> {a with FontSize = s})
Expand Down Expand Up @@ -276,9 +269,14 @@ type WaveSimModel = {
/// If the ram selection modal is visible.
RamModalActive: bool
/// List of RAM components on the sheet.
RamComps: FastComponent list
RamComps: FComponentId list
/// Map of which RAM components have been selected.
SelectedRams: Map<FComponentId, string>
/// If it exists this is the start location from which RAM locations are displayed.
/// It is transient.
/// The first component of the tuple is the text used to define the location.
/// The second component is the actual location.
RamStartLocation: Map<FComponentId, string * bigint>
/// String which the user is searching the list of waves by.
SearchString: string
/// What is shown in wave sim sheet detail elements
Expand Down Expand Up @@ -313,6 +311,7 @@ type WaveSimModel = {
}

let wSConfig_ = Lens.create (fun a -> a.WSConfig) (fun s a -> {a with WSConfig = s})
let ramStartLocation_ = Lens.create (fun a -> a.RamStartLocation) (fun s a -> {a with RamStartLocation = s})
let wSConfigDialog_ = Lens.create (fun a -> a.WSConfigDialog) (fun s a -> {a with WSConfigDialog = s})

type DiagEl = | Comp of Component | Conn of Connection
Expand Down
1 change: 0 additions & 1 deletion src/Renderer/Renderer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,6 @@ let keyPressListener initial =
let subContextMenuCommand dispatch =
renderer.ipcRenderer.on("context-menu-command", fun ev args ->
let arg:string = unbox args |> Array.map string |> String.concat ""
printfn "%s" arg
match arg.Split [|','|] |> Array.toList with
| [ menuType ; item ] ->
//printfn "%A" $"Renderer context menu callback: {menuType} --> {item}"
Expand Down
2 changes: 0 additions & 2 deletions src/Renderer/Simulator/CanvasStateAnalyser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,6 @@ let private getInPortRmInfo (m: MapData) (counts: Map<string,Connection list * i
| Counter w ->
let isDAndLoadDisconnected = checkAllPorts (condSelDisconnected ["D"; "LOAD"]) parentComp.InputPorts
let isEnDisconnected = checkAllPorts (condSelDisconnected ["EN"]) parentComp.InputPorts
printfn "isDandLoaddisconnected: %A" isDAndLoadDisconnected
printfn "isEndisconnected: %A" isEnDisconnected
match portName, isDAndLoadDisconnected, isEnDisconnected with
| "D", true, _ | "LOAD", true, _ -> Removable (CounterNoLoad w)
| "D", false, _ | "LOAD", false, _ -> Unremovable
Expand Down
4 changes: 2 additions & 2 deletions src/Renderer/Simulator/NumberHelpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -568,8 +568,8 @@ let emptyFastData = { Width = 0; Dat = Word 0u }
let strToBigint (str: string) : Result<bigint, string> =
let removeCommas (str: string) =
str.Replace(",", "")
let str = str.ToLower()
let str = if str.Length > 1 && str[0] = 'x' || str[0]='b' then "0" + str else str
let str = str.ToLower().Trim()
let str = if str.Length > 1 && str[0] = 'x' || str[0]='b' || str.Length = 0 then "0" + str else str
let success, n =
str
|> removeCommas
Expand Down
2 changes: 2 additions & 0 deletions src/Renderer/Simulator/Simulator.fs
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,8 @@ let mutable simCache: SimCache = simCacheInit ()
/// Used to store last canvas state and its simulation for waveform simulation
let mutable simCacheWS: SimCache = simCacheInit ()

/// Used in wave simulation to obtain the currently active FastSimulation.
/// This should exist, but if not it will contain a dummy
let getFastSim() = simCacheWS.FastSim

let cacheIsEqual (cache: SimCache) (ldcs: LoadedComponent list ) : bool=
Expand Down
3 changes: 0 additions & 3 deletions src/Renderer/Simulator/SimulatorTypes.fs
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,6 @@ let rec evalExp exp =
else
BinaryExp(l, BitAndOp, r)
| BinaryExp(exp1, BitOrOp, exp2) ->
printfn "Or Case Matched"
let left = evalExp exp1
let right = evalExp exp2

Expand Down Expand Up @@ -746,8 +745,6 @@ and reduceArithmetic expression =
else
l @ [ numDataExp ]

printfn "To Assemble: %A" (List.map expToString expressionsToAssemble)

assembleArithmetic width expressionsToAssemble

/// Raised when an Algebraic case is found in FastSim which has not been implemented,
Expand Down
1 change: 0 additions & 1 deletion src/Renderer/UI/BuildView.fs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ let viewBuild model dispatch =
Label.label [ ]
[Select.select []
[ select [(OnChange(fun option ->
printfn "Value is: %s" option.Value
Sheet (SheetT.Msg.SetDebugDevice option.Value) |> dispatch ))]

([option [Value "";Selected true;Disabled true] [str ("Select Device")]] @ [option [Value "IceStick"] [str "IceStick"]] @ [option [Value "IssieStick-v0.1"] [str "IssieStick v0.1"] ] @ [option [Value "IssieStick-v1.0"] [str "IssieStick v1.0"] ])
Expand Down
3 changes: 0 additions & 3 deletions src/Renderer/UI/CatalogueView.fs
Original file line number Diff line number Diff line change
Expand Up @@ -639,11 +639,9 @@ let rec createVerilogPopup model showExtraErrors correctedCode moduleName (origi
| Error _ -> failwithf "Writing verilog file FAILED"

let parsedCodeNearley = parseFromFile(code)
printfn $"{parsedCodeNearley}"
let output = Json.parseAs<ParserOutput> parsedCodeNearley
let result = Option.get output.Result
let fixedAST = fix result
printfn "fixed %A" fixedAST
let parsedAST = fixedAST |> Json.parseAs<VerilogInput>

let cs = SheetCreator.createSheet parsedAST project
Expand Down Expand Up @@ -768,7 +766,6 @@ let rec createVerilogPopup model showExtraErrors correctedCode moduleName (origi
|_ -> s+"\n"+linesList[v-1]
)
let fixedLine = replaceSubstringAtLocation linesList[line-1] suggestion (col-1) error.Length
printfn $"fixed: {fixedLine}"
let fixedError =
match line with
|1 -> fixedLine
Expand Down
2 changes: 0 additions & 2 deletions src/Renderer/UI/CustomCompPorts.fs
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,6 @@ let changeInstance (comp:Component) (change: PortChange) =
List.filter (fun (port:Port) -> port.PortNumber <> Some portNum) ports
|> List.sortBy (fun port -> port.PortNumber)
|> List.mapi (fun i port -> {port with PortNumber = Some i})
printfn $"deleteport:{labels.Length},{ports.Length}"
labels,ports
updateInfo dir upf comp

Expand Down Expand Up @@ -430,7 +429,6 @@ let updateInstance (newSig: Signature) (sheet:string,cid:string,oldSig:Signature
match comp.Type with
| Custom ct -> //when ct.Form = Some User ->
if oldSig = newSig then
printfn "Order matches!"
comp
elif mapPair List.sort newSig = mapPair List.sort oldSig then
printfn $"Reordering {comp.Label}"
Expand Down
3 changes: 0 additions & 3 deletions src/Renderer/UI/MenuHelpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ let makeSourceMenu

let onSelect key =
let n1,n2, mem,_ = getMemorySetup dialog 1 // current values
printfn $"Select {key}"
//dispatch <| ModelType.SetPopupDialogMemorySetup (Some(n1,n2,key,None))
dispatch <| SetPopupDialogMemorySetup (Some (n1,n2,key, match key with | FromFile name -> Some name | _ -> None))

Expand Down Expand Up @@ -1016,11 +1015,9 @@ let removeAllCustomComps (name:string) project =
comps |> List.filter (fun comp ->
match comp.Type with
|Custom c when c.Name = name ->
printfn "custom %A" c
false
|_ -> true
)
printfn "todeleteids %A" idsToBeDeleted
let newConns =
conns |> List.filter (fun conn ->
match conn.Source.HostId,conn.Target.HostId with
Expand Down
48 changes: 47 additions & 1 deletion src/Renderer/UI/ModelHelpers.fs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
module ModelHelpers
open Fulma
open Fable.React
open Fable.React.Props
open CommonTypes
open Sheet.SheetInterface
open ModelType
Expand Down Expand Up @@ -51,6 +54,7 @@ let initWSModel : WaveSimModel = {
RamModalActive = false
RamComps = []
SelectedRams = Map.empty
RamStartLocation = Map.empty
SearchString = ""
ShowComponentDetail = Set.empty
ShowSheetDetail = Set.empty
Expand Down Expand Up @@ -151,6 +155,8 @@ let getSavedWaveInfo (wsModel: WaveSimModel) : SavedWaveInfo =
SelectedFRams = Some wsModel.SelectedRams
SelectedRams = None

WSConfig = Some wsModel.WSConfig

// The following fields are from the old waveform simulator.
// They are no longer used.
ClkWidth = None
Expand All @@ -169,6 +175,7 @@ let loadWSModelFromSavedWaveInfo (swInfo: SavedWaveInfo) : WaveSimModel =
Radix = Option.defaultValue initWSModel.Radix swInfo.Radix
WaveformColumnWidth = Option.defaultValue initWSModel.WaveformColumnWidth swInfo.WaveformColumnWidth
SelectedRams = Option.defaultValue initWSModel.SelectedRams swInfo.SelectedFRams
WSConfig =Option.defaultValue initWSModel.WSConfig swInfo.WSConfig
}

//----------------------Print functions-----------------------------//
Expand Down Expand Up @@ -346,7 +353,6 @@ let execOneAsyncJobIfPossible (model: Model,cmd: Cmd<Msg>)=
| [] -> (model,cmd)
| job::_ ->
asyncJobs <- List.filter (fun job' -> job'.JobName <> job.JobName) asyncJobs
printfn $"Executing async '{job.JobName}."
job.JobWork model
|> (fun (model', cmd') -> model', Cmd.batch [cmd; cmd'])

Expand All @@ -363,6 +369,46 @@ let setModelInt (optic_: Lens<Model,int>) (dispatch: Msg -> unit) maxVal minVal
let intToSet = if intToSet > maxVal then maxVal else if intToSet < minVal then minVal else intToSet
dispatch <| UpdateModel (Optics.Optic.set optic_ intToSet)

//--------------------------------------------------------------------------------------------//
//------------------------React Input Boxes for numeric Parsing with Elmish-------------------//
//--------------------------------------------------------------------------------------------//

// Code should be refactored to use these throughout

/// Both input text and its parsed numeric value must be stored in the model.
/// The two fields contain optics used to access these items in the model
type ModelLocations = {
TextOptic_: Optics.Lens<Model,string>
ValOptic_: Lens<Model,bigint>
}

/// <summary> Display an input box which is parsed as a bigint and written back to the Model using
/// textOptic (the text) and valOptic (the value). isValid must return true for the value to be written back to
/// the model</summary>
let inputBigint
(props: IHTMLProp list)
(placeholder:string)
(locs: ModelLocations)
(isValid: bigint -> Model -> bool)
(dispatch: Msg -> unit)
(model:Model): ReactElement =

let isNowValid bigNum = isValid bigNum (Optic.set locs.ValOptic_ bigNum model)

let parseInput (text:string) =
dispatch <| UpdateModel (Optics.Optic.set locs.TextOptic_ text)
match NumberHelpers.strToBigint text with
| Ok big when isNowValid big ->
dispatch <| UpdateModel (Optic.set locs.ValOptic_ big)
| _ -> ()

Input.text [
Input.Props (props @ [OnPaste PopupHelpers.preventDefault; AutoFocus true; SpellCheck false])
Input.Placeholder placeholder
Input.DefaultValue (model |> Optics.Optic.get locs.TextOptic_)
Input.OnChange (JSHelpers.getTextEventValue >> parseInput)
]


//---------------------------------------------------------------------------------------------//
//----------------------------View level simulation interface-----------------------------------//
Expand Down
2 changes: 0 additions & 2 deletions src/Renderer/UI/SelectedComponentView.fs
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,6 @@ let makeConstantDialog (model:Model) (comp: Component) (text:string) (dispatch:
"Enter constant value in decimal, hex, or binary:"
cText
(fun txt ->
printfn $"Setting {txt}"
dispatch <| SetPopupDialogText (Some txt))

]
Expand Down Expand Up @@ -760,7 +759,6 @@ let makeBusCompareDialog (model:Model) (comp: Component) (text:string) (dispatch
"Enter bus compare value in decimal, hex, or binary:"
cText
(fun txt ->
printfn $"Setting {txt}"
dispatch <| SetPopupDialogText (Some txt))

]
Expand Down
3 changes: 0 additions & 3 deletions src/Renderer/UI/SimulationView.fs
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,6 @@ let simulationClockChangeAction dispatch simData (model': Model) =
let chunkTime = min 2000. (estimatedTime / 5.)
let chunk = int <| float steps * chunkTime / estimatedTime
if steps > 2*initChunk && estimatedTime > 500. then
printfn "test1"
dispatch <| SetPopupProgress
(Some {
Speed = float (numComps * steps) / estimatedTime
Expand Down Expand Up @@ -863,7 +862,6 @@ let tryGetSimData isWaveSim canvasState model =
simCacheWS <- simCacheInit ()
else
simCache <- simCacheInit ()
printfn $"TyyGetSimData: WS={isWaveSim}"
simulateModel isWaveSim None Constants.maxArraySize canvasState model
|> function
| Ok (simData), state ->
Expand Down Expand Up @@ -964,7 +962,6 @@ let viewSimulation canvasState model dispatch =
Button.button [
Button.Color IsSuccess
Button.OnClick (fun _ ->
printfn "did a refresh with ok"
setInputDefaultsFromInputs simData.FastSim dispatch simData.ClockTickNumber
simCache <- {simCache with RestartSim = true}
ClosePopup |> dispatch
Expand Down
4 changes: 2 additions & 2 deletions src/Renderer/UI/TruthTable/ConstraintReduceView.fs
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,9 @@ let dialogPopupNumericalConBody (cellIOs: CellIO list) existingCons infoMsg disp
match dialogData.Int, dialogData.Int2, dialogData.ConstraintErrorMsg,
dialogData.ConstraintIOSel, dialogData.ConstraintTypeSel with
| Some v, _, None, Some io, Some Equ ->
printfn "Existing %A" existingCons
//printfn "Existing %A" existingCons
let tentative = Equality {IO = io; Value = v}
printfn "Tentative: %A" (inCon2str tentative)
//printfn "Tentative: %A" (inCon2str tentative)
match validateNumericalConstraint tentative existingCons with
| Error err ->
err |> Some |> SetPopupConstraintErrorMsg |> ttDispatch
Expand Down
1 change: 0 additions & 1 deletion src/Renderer/UI/TruthTable/TruthTableView.fs
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,6 @@ let emptySelCache = {
CorrectedCanvas = ([],[])
StoredResult = Ok {
FastSim =
printfn "creating empty selcache"
FastCreate.simulationPlaceholder
Graph = Map.empty
Inputs = []
Expand Down
1 change: 1 addition & 0 deletions src/Renderer/UI/UIPopups.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ open EEExtensions
open Fulma
open Fable.React
open Fable.React.Props
open CommonTypes
open PopupHelpers
open ModelType
open ModelHelpers
Expand Down
Loading

0 comments on commit a3837ca

Please sign in to comment.