Created
February 27, 2019 16:28
-
-
Save Ravenslofty/2071700eb177a41bb44dbe71d148479e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- cc2/decode_mips.lua 2019-02-27 16:16:48.338797400 +0000 | |
| +++ sol/decode_mips.sol 2019-02-27 16:08:40.508730600 +0000 | |
| @@ -5,45 +5,51 @@ | |
| local mips_decode = {} | |
| +typedef decode_handler = { | |
| + shift: int?, | |
| + mask: int?, | |
| + table: [function(table, int, int, int, int, int, int) -> bool, string, string?, bool] | |
| +} | |
| + | |
| local instance = { | |
| - decode_table = {}, | |
| - gpr_declared = {}, | |
| - gpr_needs_writeback = {}, | |
| - cp0r_declared = {}, | |
| - cp0r_needs_writeback = {}, | |
| - program_counter = 0 | |
| + decode_table = {} : [decode_handler], | |
| + gpr_declared = {} : [bool], | |
| + gpr_needs_writeback = {} : [bool], | |
| + cp0r_declared = {} : [bool], | |
| + cp0r_needs_writeback = {} : [bool], | |
| + program_counter = 0 : int | |
| } | |
| -local function opcode(instruction) | |
| +local function opcode(instruction: int) -> int | |
| return band(rshift(instruction, 26), 0x3F) | |
| end | |
| -local function first_source(instruction) | |
| +local function first_source(instruction: int) -> int | |
| return band(rshift(instruction, 21), 0x1F) | |
| end | |
| -local function second_source(instruction) | |
| +local function second_source(instruction: int) -> int | |
| return band(rshift(instruction, 16), 0x1F) | |
| end | |
| -local function destination(instruction) | |
| +local function destination(instruction: int) -> int | |
| return band(rshift(instruction, 11), 0x1F) | |
| end | |
| -local function shift_amount(instruction) | |
| +local function shift_amount(instruction: int) -> int | |
| return band(rshift(instruction, 6), 0x1F) | |
| end | |
| -local function function_field(instruction) | |
| +local function function_field(instruction: int) -> int | |
| return band(rshift(instruction, 0), 0x3F) | |
| end | |
| -- Placeholder for monkey-patched function. | |
| -function instance:write_back_registers() | |
| +function instance:write_back_registers() -> string | |
| return "" | |
| end | |
| -function instance:decode_instruction(instruction) | |
| +function instance:decode_instruction(instruction: number) -> bool, string, string?, bool | |
| if instruction == 0 then | |
| return true, "", nil, false | |
| end | |
| @@ -69,11 +75,11 @@ | |
| return handler(self, opcode, first_source, second_source, destination, shift_amount, function_field) | |
| end | |
| -function instance:decode(read32) | |
| +function instance:decode(read32: function(int) -> int) -> string | |
| local keep_decoding = true | |
| local branch_delay = false | |
| local next_address = "" | |
| - local ops = {} | |
| + local ops = {} : [string] | |
| while keep_decoding do | |
| local instruction = read32(self.program_counter) | |
| @@ -120,13 +126,13 @@ | |
| local DecodeInstance = {__index = instance} | |
| -function mips_decode.new(decode_table, program_counter) | |
| +function mips_decode.new(decode_table: {decode_handler}, program_counter: uint) -> table | |
| local instance = { | |
| decode_table = decode_table, | |
| - gpr_declared = {}, | |
| - gpr_needs_writeback = {}, | |
| - cp0r_declared = {}, | |
| - cp0r_needs_writeback = {}, | |
| + gpr_declared = {} : [bool], | |
| + gpr_needs_writeback = {} : [bool], | |
| + cp0r_declared = {} : [bool], | |
| + cp0r_needs_writeback = {} : [bool], | |
| program_counter = program_counter | |
| } | |
| @@ -175,7 +181,7 @@ | |
| "ra" | |
| } | |
| -function mips_decode.register_name(register) | |
| +function mips_decode.register_name(register: number) -> string | |
| return names[register + 1] | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment