Skip to content

Commit

Permalink
Allow multiple backends
Browse files Browse the repository at this point in the history
  • Loading branch information
1whatleytay committed Feb 23, 2024
1 parent b75dfd6 commit f18b16c
Show file tree
Hide file tree
Showing 19 changed files with 647 additions and 512 deletions.
6 changes: 2 additions & 4 deletions src/components/ExportModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,8 @@
import Modal from './Modal.vue'
import { tab } from '../state/state'
import { consoleData, ConsoleType, DebugTab, openConsole, pushConsole } from '../state/console-data'
import { assembleRegions } from '../utils/mips'
import { backend, consoleData, ConsoleType, DebugTab, openConsole, pushConsole } from '../state/console-data'
import { collectLines } from '../utils/tabs'
import { selectSaveDestination } from '../utils/query/access-manager'
import { exportHexContents, exportHexRegions } from '../utils/query/serialize-files'
import { postBuildMessage } from '../utils/debug'
import { DocumentArrowUpIcon, XMarkIcon } from '@heroicons/vue/24/solid'
Expand Down Expand Up @@ -157,7 +155,7 @@ async function exportRegions() {
return
}
const result = await assembleRegions(collectLines(current.lines), current.path, state)
const result = await backend.assembleRegions(collectLines(current.lines), current.path, state)
if (result.regions) {
switch (result.regions.type) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/TabBarItems.vue
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
import { computed } from 'vue'
import { consoleData } from '../state/console-data'
import { build, pause, resume, step, rewind, stop } from '../utils/debug'
import { ExecutionModeType } from '../utils/mips'
import { ExecutionModeType } from '../utils/mips/mips'
import { tab } from '../state/state'
import {
Expand Down
12 changes: 6 additions & 6 deletions src/components/console/BitmapTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,14 @@
import { computed, onMounted, onUnmounted, reactive, ref, watch } from 'vue'
import { ArrowLeftIcon } from '@heroicons/vue/24/solid'
import { ExclamationCircleIcon, CheckCircleIcon } from '@heroicons/vue/24/outline'
import { consoleData } from '../../state/console-data'
import { ExclamationCircleIcon } from '@heroicons/vue/24/outline'
import { backend, consoleData } from '../../state/console-data'
import { settings } from '../../state/state'
import NumberField from './NumberField.vue'
import { convertFileSrc } from '@tauri-apps/api/tauri'
import { ExecutionState, lastDisplay } from '../../utils/mips'
import { displayConfig } from '../../utils/settings'
import { MipsExecution } from '../../utils/mips/mips'
const wrapper = ref(null as HTMLElement | null)
const canvas = ref(null as HTMLCanvasElement | null)
Expand Down Expand Up @@ -288,7 +288,7 @@ watch(() => consoleData.execution, checkConnected)
async function renderFrameFallback(
context: CanvasRenderingContext2D,
execution: ExecutionState
execution: MipsExecution
) {
const memory = await execution.memoryAt(0x10008000, 64 * 64 * 4)
Expand Down Expand Up @@ -352,14 +352,14 @@ async function renderFrameProtocol(context: CanvasRenderingContext2D) {
}
async function renderLastDisplay(context: CanvasRenderingContext2D) {
const last = await lastDisplay()
const last = await backend.lastDisplay()
// No data, don't render.
if (!last.data) {
return
}
await renderOrdered(
renderOrdered(
context,
last.width,
last.height,
Expand Down
13 changes: 6 additions & 7 deletions src/components/console/BreakTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,13 @@
</template>

<script setup lang="ts">
import { consoleData } from '../../state/console-data'
import { backend, consoleData } from '../../state/console-data'
import { computed, onMounted, reactive, watch } from 'vue'
import {
Breakpoints,
decodeInstruction, ExecutionModeType,
ExecutionState,
InstructionDetails
} from '../../utils/mips'
ExecutionModeType,
InstructionDetails, MipsExecution
} from '../../utils/mips/mips'
import { setRegister, stepCount } from '../../utils/debug'
import { ChevronRightIcon } from '@heroicons/vue/24/solid'
import RegisterItem from './RegisterItem.vue'
Expand Down Expand Up @@ -233,14 +232,14 @@ function instructionGroup(breakpoints: Breakpoints | null, pc: number): Instruct
}
}
async function instructionAtAddress(state: ExecutionState, address: number): Promise<InstructionDetails | null> {
async function instructionAtAddress(state: MipsExecution, address: number): Promise<InstructionDetails | null> {
const data = await state.memoryAt(address, 4)
if (data === null) {
return null
}
return await decodeInstruction(address, combine(data))
return await backend.decodeInstruction(address, combine(data))
}
interface CurrentInstructions {
Expand Down
2 changes: 1 addition & 1 deletion src/components/console/Console.vue
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ import { computed, onMounted, onUnmounted, reactive, ref, watch } from 'vue'
import { consoleData, DebugTab } from '../../state/console-data'
import { XMarkIcon } from '@heroicons/vue/24/solid'
import { ExecutionModeType } from '../../utils/mips'
import { ExecutionModeType } from '../../utils/mips/mips'
import Tab from '../Tab.vue'
import RegistersTab from './RegistersTab.vue'
import MemoryTab from './MemoryTab.vue'
Expand Down
2 changes: 1 addition & 1 deletion src/components/console/RegistersTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ import { setRegister } from '../../utils/debug'
import { Square3Stack3DIcon } from '@heroicons/vue/24/outline'
import { RegisterFormat } from '../../utils/settings'
import { Registers } from '../../utils/mips'
import { Registers } from '../../utils/mips/mips'
import RegisterItem from './RegisterItem.vue'
function buttonClasses(format: RegisterFormat) {
Expand Down
16 changes: 14 additions & 2 deletions src/state/console-data.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { reactive } from 'vue'
import { ExecutionModeType, ExecutionState, Registers } from '../utils/mips'
import { ExecutionModeType, MipsBackend, MipsExecution, Registers } from '../utils/mips/mips'
import { TauriBackend } from '../utils/mips/tauri-backend'
import { WasmBackend } from '../utils/mips/wasm-backend'

export enum DebugTab {
Registers,
Expand Down Expand Up @@ -38,7 +40,7 @@ interface ConsoleLineMeta {

interface ConsoleData {
showConsole: boolean
execution: ExecutionState | null
execution: MipsExecution | null
mode: ExecutionModeType | null
registers: Registers | null
hintPc: number | null
Expand All @@ -51,6 +53,16 @@ const editHighlight = { type: ConsoleType.Editing }
const submitHighlight = { type: ConsoleType.Submitted }
const secondaryHighlight = { type: ConsoleType.Secondary }

function createBackend(): MipsBackend {
if (window.__TAURI__) {
return new TauriBackend()
} else {
return new WasmBackend()
}
}

export const backend = createBackend()

export const consoleData = reactive({
showConsole: false,
execution: null,
Expand Down
3 changes: 1 addition & 2 deletions src/state/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import { CursorState, useTabs } from '../utils/tabs'
import { GotoMessage, useGoto } from '../utils/goto'
import { useSymbolHighlight } from '../utils/symbol-highlight'
import { ref, watch } from 'vue'
import { findToken } from '../utils/languages/suggestions'
import { InstructionLine } from '../utils/mips'
import { InstructionLine } from '../utils/mips/mips'

export const settings = useSettings()

Expand Down
19 changes: 8 additions & 11 deletions src/utils/debug.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
import { collectLines } from './tabs'
import {
backend,
consoleData,
ConsoleType,
DebugTab,
openConsole,
pushConsole,
pushConsole
} from '../state/console-data'
import {
AssemblerResult,
assembleText,
assembleWithBinary,
disassemblyDetails,
ExecutionModeType,
ExecutionResult,
ExecutionState
} from './mips'
ExecutionResult
} from './mips/mips'
import { tab, settings, buildLines } from '../state/state'

import { format } from 'date-fns'
Expand Down Expand Up @@ -148,12 +145,12 @@ export async function build() {
const {
binary,
result
} = await assembleWithBinary(collectLines(current?.lines ?? []), current?.path ?? null)
} = await backend.assembleWithBinary(collectLines(current?.lines ?? []), current?.path ?? null)

if (binary !== null) {
console.log(`setting ${binary} and ${typeof binary.buffer}`)

buildLines.value = await disassemblyDetails(binary.buffer)
buildLines.value = await backend.disassemblyDetails(binary.buffer)
}

consoleData.showConsole = true
Expand All @@ -178,7 +175,7 @@ export async function resume() {

await saveCurrentTab(PromptType.NeverPrompt)

consoleData.execution = new ExecutionState(text, path, settings.execution.timeTravel, current.profile)
consoleData.execution = await backend.createExecution(text, path, settings.execution.timeTravel, current.profile)
}

consoleData.showConsole = true
Expand Down Expand Up @@ -215,7 +212,7 @@ export async function stepCount(skip: number) {
clearDebug()
consoleData.mode = ExecutionModeType.Running

const result = await consoleData.execution.resume(skip, null)
const result = await consoleData.execution.resume(skip, null, () => {})

consoleData.showConsole = true

Expand Down
8 changes: 4 additions & 4 deletions src/utils/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {
AccessFile,
selectSaveDestination, selectOpenFile, accessWriteText, selectOpenElf
} from './query/access-manager'
import { consoleData, ConsoleType, pushConsole } from '../state/console-data'
import { assembleWithBinary, BinaryResult } from './mips'
import { backend, consoleData, ConsoleType, pushConsole } from '../state/console-data'
import { BinaryResult } from './mips/mips'
import {
closeTab,
createTab, editor,
Expand Down Expand Up @@ -173,7 +173,7 @@ export async function setupEvents() {
await listen('assemble', async () => {
const current = tab()

const result = await assembleWithBinary(collectLines(current?.lines ?? []), current?.path ?? null)
const result = await backend.assembleWithBinary(collectLines(current?.lines ?? []), current?.path ?? null)

if (result.binary) {
const name = tab()?.title
Expand All @@ -199,7 +199,7 @@ export async function setupEvents() {
if (current.profile && current.profile.kind === 'elf') {
binary = Uint8Array.from(window.atob(current.profile.elf), c => c.charCodeAt(0))
} else {
result = await assembleWithBinary(collectLines(current.lines), current.path)
result = await backend.assembleWithBinary(collectLines(current.lines), current.path)
binary = result.binary
}

Expand Down
Loading

0 comments on commit f18b16c

Please sign in to comment.