From: Brendan Hansen Date: Wed, 4 Jan 2023 03:29:28 +0000 (-0600) Subject: fixes with disassembly view X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=510d42d7b63ce90998d6b6c9e5bc7bdec5b32347;p=onyx.git fixes with disassembly view --- diff --git a/core/memory/memory.onyx b/core/memory/memory.onyx index 1b23c8b1..a3ca6e70 100644 --- a/core/memory/memory.onyx +++ b/core/memory/memory.onyx @@ -59,7 +59,7 @@ resize_slice :: (sl: [] $T, new_size: i32, allocator := context.allocator) -> [] #overload builtin.__make_overload :: macro (_: ^[] $T, count: u32, allocator := context.allocator) -> [] T { ret := (package core.memory).make_slice(T, count, allocator); - memory.set(ret.data, 0, sizeof T * count); + (package core.memory).set(ret.data, 0, sizeof T * count); return ret; } diff --git a/interpreter/src/debug/debug_thread.c b/interpreter/src/debug/debug_thread.c index bd3994a5..02d34633 100644 --- a/interpreter/src/debug/debug_thread.c +++ b/interpreter/src/debug/debug_thread.c @@ -489,6 +489,9 @@ static DEBUG_COMMAND_HANDLER(debug_command_disassmble) { // through the first thread. ovm_program_t *prog = debug->threads[0]->ovm_state->program; + debug_loc_info_t loc_info; + u32 last_file_id = 0xffffffff; + while (addr < bh_arr_length(prog->code) && count--) { send_int(debug, 0); @@ -497,6 +500,18 @@ static DEBUG_COMMAND_HANDLER(debug_command_disassmble) { send_bytes(debug, instr_buf.data, instr_buf.length); bh_buffer_clear(&instr_buf); + debug_info_lookup_location(debug->info, addr, &loc_info); + send_int(debug, loc_info.line); + + if (loc_info.file_id != last_file_id) { + send_bool(debug, true); + send_string(debug, debug->info->files[loc_info.file_id].name); + + last_file_id = loc_info.file_id; + } else { + send_bool(debug, false); + } + addr += 1; } diff --git a/interpreter/src/vm/code_builder.c b/interpreter/src/vm/code_builder.c index bb4429a2..a00e416d 100644 --- a/interpreter/src/vm/code_builder.c +++ b/interpreter/src/vm/code_builder.c @@ -12,6 +12,10 @@ #define PUSH_VALUE(b, r) (bh_arr_push((b)->execution_stack, r)) +#define LAST_VALUE(b) bh_arr_last((b)->execution_stack) + +#define IS_TEMPORARY_VALUE(b, r) (r >= (b->param_count + b->local_count)) + static inline int NEXT_VALUE(ovm_code_builder_t *b) { #if defined(BUILDER_DEBUG) b->highest_value_number += 1; @@ -400,6 +404,21 @@ void ovm_code_builder_add_local_get(ovm_code_builder_t *builder, i32 local_idx) } void ovm_code_builder_add_local_set(ovm_code_builder_t *builder, i32 local_idx) { + // :PrimitiveOptimization + // Perform a simple optimization that an immediate temporary moved to + // a local can be optimized as an immediate loaded directly to a local. + { + ovm_instr_t *last_instr = &bh_arr_last(builder->program->code); + if (OVM_INSTR_INSTR(*last_instr) == OVMI_IMM) { + if (IS_TEMPORARY_VALUE(builder, last_instr->r) + && last_instr->r == LAST_VALUE(builder)) { + last_instr->r = local_idx; + POP_VALUE(builder); + return; + } + } + } + ovm_instr_t instr = {0}; instr.full_instr = OVM_TYPED_INSTR(OVMI_MOV, OVM_TYPE_NONE); instr.r = local_idx; // This makes the assumption that the params will be in diff --git a/interpreter/src/vm/disasm.c b/interpreter/src/vm/disasm.c index c23cc192..4292876a 100644 --- a/interpreter/src/vm/disasm.c +++ b/interpreter/src/vm/disasm.c @@ -165,8 +165,8 @@ void ovm_disassemble(ovm_program_t *program, u32 instr_addr, bh_buffer *instr_te case instr_format_idx_arr: formatted = snprintf(buf, 255, "%%%d, __global_arr_%d[%%%d]", instr->r, instr->a, instr->b); break; - case instr_format_br: formatted = snprintf(buf, 255, "%d", instr_addr + instr->a); break; - case instr_format_br_cond: formatted = snprintf(buf, 255, "%d, %%%d", instr_addr + instr->a, instr->b); break; + case instr_format_br: formatted = snprintf(buf, 255, "%d", instr_addr + instr->a + 1); break; + case instr_format_br_cond: formatted = snprintf(buf, 255, "%d, %%%d", instr_addr + instr->a + 1, instr->b); break; case instr_format_bri: formatted = snprintf(buf, 255, "ip + %%%d", instr->a); break; case instr_format_bri_cond: formatted = snprintf(buf, 255, "ip + %%%d, %%%d", instr->a, instr->b); break; diff --git a/interpreter/src/wasm/module.c b/interpreter/src/wasm/module.c index 8e469a67..0003ea89 100644 --- a/interpreter/src/wasm/module.c +++ b/interpreter/src/wasm/module.c @@ -29,6 +29,10 @@ static bool module_build(wasm_module_t *module, const wasm_byte_vec_t *binary) { // But Onyx does not do this, so I don't care at the moment. module->program->register_count = module->globaltypes.size; + #if 0 + printf("Program instruction count: %d\n", bh_arr_length(module->program->code)); + #endif + return true; } diff --git a/misc/vscode/onyx-0.1.2.vsix b/misc/vscode/onyx-0.1.2.vsix new file mode 100644 index 00000000..a40e2d7a Binary files /dev/null and b/misc/vscode/onyx-0.1.2.vsix differ diff --git a/misc/vscode/onyx-0.1.3.vsix b/misc/vscode/onyx-0.1.3.vsix new file mode 100644 index 00000000..1db3ed0d Binary files /dev/null and b/misc/vscode/onyx-0.1.3.vsix differ diff --git a/misc/vscode/out/ovmDebug.js b/misc/vscode/out/ovmDebug.js index efe9d3ec..440bd456 100644 --- a/misc/vscode/out/ovmDebug.js +++ b/misc/vscode/out/ovmDebug.js @@ -148,11 +148,7 @@ class OVMDebugSession extends debugadapter_1.LoggingDebugSession { this._variableReferences.reset(); response.body = { stackFrames: frames.map((f, i) => { - let source = new debugadapter_1.Source(this.fileNameToShortName(f.filename), this.convertDebuggerPathToClient(f.filename), undefined, undefined, "ovm-debug-src"); - if (!this._loadedSources.has(source.name)) { - this._loadedSources.set(source.name, source); - this.sendEvent(new debugadapter_1.LoadedSourceEvent("new", source)); - } + let source = this.loadSource(f.filename); let frameRef = this._frameReferences.create({ threadId: args.threadId, frameIndex: i @@ -270,14 +266,19 @@ class OVMDebugSession extends debugadapter_1.LoggingDebugSession { } disassembleRequest(response, args, request) { return __awaiter(this, void 0, void 0, function* () { - console.log(args); let addr = parseInt(args.memoryReference) + args.offset; let instrs = yield this.debugger.disassemble(addr, args.instructionCount); response.body = { instructions: instrs.map((i, index) => { + let source; + if (i.newSource != null) { + source = this.loadSource(i.newSource); + } return { address: (index + addr).toString(), - instruction: i.instr + instruction: i.instr, + line: i.line, + location: source, }; }) }; @@ -309,6 +310,14 @@ class OVMDebugSession extends debugadapter_1.LoggingDebugSession { fileNameToShortName(filename) { return filename.substring(filename.lastIndexOf("/") + 1); } + loadSource(filename) { + let source = new debugadapter_1.Source(this.fileNameToShortName(filename), this.convertDebuggerPathToClient(filename), undefined, undefined, "ovm-debug-src"); + if (!this._loadedSources.has(source.name)) { + this._loadedSources.set(source.name, source); + this.sendEvent(new debugadapter_1.LoadedSourceEvent("new", source)); + } + return source; + } } exports.OVMDebugSession = OVMDebugSession; var OVMCommand; @@ -644,7 +653,12 @@ class OVMDebugger extends EventEmitter { let result = new Array(); while (parser.parseInt32() == 0) { let instr = parser.parseString(); - result.push({ instr }); + let line = parser.parseUint32(); + let newSource = null; + if (parser.parseBool()) { + newSource = parser.parseString(); + } + result.push({ instr, line, newSource }); } this.resolvePromise(msg_id, result); break; diff --git a/misc/vscode/ovmDebug.ts b/misc/vscode/ovmDebug.ts index 940fb4f4..d0912758 100644 --- a/misc/vscode/ovmDebug.ts +++ b/misc/vscode/ovmDebug.ts @@ -220,18 +220,8 @@ export class OVMDebugSession extends LoggingDebugSession { response.body = { stackFrames: frames.map((f, i) => { - let source = new Source( - this.fileNameToShortName(f.filename), - this.convertDebuggerPathToClient(f.filename), - undefined, undefined, "ovm-debug-src" - ); - - if (!this._loadedSources.has(source.name)) { - this._loadedSources.set(source.name, source); - - this.sendEvent(new LoadedSourceEvent("new", source)); - } - + let source = this.loadSource(f.filename); + let frameRef = this._frameReferences.create({ threadId: args.threadId, frameIndex: i @@ -381,9 +371,16 @@ export class OVMDebugSession extends LoggingDebugSession { response.body = { instructions: instrs.map((i, index) => { + let source: DebugProtocol.Source | null; + if (i.newSource != null) { + source = this.loadSource(i.newSource); + } + return { - address: (index + addr - 1).toString(), + address: (index + addr).toString(), instruction: i.instr, + line: i.line, + location: source, }; }) }; @@ -421,6 +418,22 @@ export class OVMDebugSession extends LoggingDebugSession { private fileNameToShortName(filename: string): string { return filename.substring(filename.lastIndexOf("/") + 1); } + + private loadSource(filename: string): Source { + let source = new Source( + this.fileNameToShortName(filename), + this.convertDebuggerPathToClient(filename), + undefined, undefined, "ovm-debug-src" + ); + + if (!this._loadedSources.has(source.name)) { + this._loadedSources.set(source.name, source); + + this.sendEvent(new LoadedSourceEvent("new", source)); + } + + return source; + } } interface IFileLocation { @@ -456,6 +469,8 @@ interface IReadMemory { interface IDisassembledInstruction { instr: string; + line: number; + newSource?: string; } enum OVMCommand { @@ -887,7 +902,14 @@ class OVMDebugger extends EventEmitter { while (parser.parseInt32() == 0) { let instr = parser.parseString(); - result.push({ instr }); + let line = parser.parseUint32(); + + let newSource: string | null = null; + if (parser.parseBool()) { + newSource = parser.parseString(); + } + + result.push({ instr, line, newSource }); } this.resolvePromise(msg_id, result); diff --git a/misc/vscode/package.json b/misc/vscode/package.json index ba240183..6dbb9104 100644 --- a/misc/vscode/package.json +++ b/misc/vscode/package.json @@ -2,7 +2,7 @@ "name": "onyx", "displayName": "Onyx", "description": "Onyx syntax highlighting.", - "version": "0.1.1", + "version": "0.1.3", "publisher": "brendanfh", "license": "BSD-2-Clause", "engines": { diff --git a/shared/lib/linux_x86_64/lib/libovmwasm.so b/shared/lib/linux_x86_64/lib/libovmwasm.so index 3e670e14..6e2ffbb9 100755 Binary files a/shared/lib/linux_x86_64/lib/libovmwasm.so and b/shared/lib/linux_x86_64/lib/libovmwasm.so differ