RE: PicoBlaze Simulator in JavaScript
August 12, 2022 at 6:34 pm
(This post was last modified: August 12, 2022 at 6:50 pm by bennyboy.)
(August 12, 2022 at 7:26 am)FlatAssembler Wrote: @bennyboy , you say you are an experienced web developer. Could you please look into my PicoBlaze Simulator in JavaScript and tell me how I could speed it up? I cannot diagnose why it is so slow.
Yes, I think so. This is not really a web issue, though-- it would be the same in any language running under any framework.
In `assembler.js`, your main loop, "assemble", has 2 problems:
1) From an engineering perspective, it is absolutely unreadable. I've never seen that many if/else statements on a single page in my life. Let's say you have one or two mistakes in all those statements-- hell if you'll find ANYONE willing to go through that pile of spaghetti to find them.
2) From an efficiency perspective, you seem to be doing dozens (hundreds?) of conditional operations on each node. You need to use switch statements or some other type of logic to reduce unnecessary checks.
Also: you have this
Code:
if (node.children[0].getRegisterNumber(context.namedRegisters) === "none") DoErrorStuff{};
Code:
var IsRegister = node.children[0].getRegisterNumber(context.namedRegisters) !== "none"
. . .
if (!IsRegister) DoErrorStuff{}; // Use this the next 1000 times you need the same exact check