Difference between revisions of "MediaWiki:Monobook.js"
Jump to navigation
Jump to search
(transformers) |
m (tab conversion and styling of tooltips) |
||
Line 11: | Line 11: | ||
function transform(i, node) { | function transform(i, node) { | ||
// Do the things to each thing. | // Do the things to each thing. | ||
− | + | var txt = node.innerHTML; | |
− | + | node.innerHTML = $.map(txt.split(/\r?\n/), | |
transform_line).join('\n'); | transform_line).join('\n'); | ||
} | } | ||
Line 67: | Line 67: | ||
var desc = { | var desc = { | ||
− | 'add': "Add add $d,$s,$t", | + | 'add': "Add: add $d,$s,$t", |
− | 'addu': "Add unsigned addu $d,$s,$t", | + | 'addu': "Add unsigned: addu $d,$s,$t", |
− | 'sub': "Subtract sub $d,$s,$t", | + | 'sub': "Subtract: sub $d,$s,$t", |
− | 'subu': "Subtract unsigned subu $d,$s,$t", | + | 'subu': "Subtract unsigned: subu $d,$s,$t", |
− | 'addi': "Add immediate addi $t,$s,C", | + | 'addi': "Add immediate: addi $t,$s,C", |
− | 'addiu': "Add immediate unsigned addiu $t,$s,C", | + | 'addiu': "Add immediate unsigned: addiu $t,$s,C", |
− | 'mult': "Multiply mult $s,$t", | + | 'mult': "Multiply: mult $s,$t", |
− | 'multu': "Multiply unsigned multu $s,$t", | + | 'multu': "Multiply unsigned: multu $s,$t", |
− | 'div': "Divide div $s, $t", | + | 'div': "Divide: div $s, $t", |
− | 'divu': "Divide unsigned divu $s, $t", | + | 'divu': "Divide unsigned: divu $s, $t", |
− | 'lw': "Load word lw $t,C($s)", | + | 'lw': "Load word: lw $t,C($s)", |
− | 'lh': "Load halfword lh $t,C($s)", | + | 'lh': "Load halfword: lh $t,C($s)", |
− | 'lhu': "Load halfword unsigned lhu $t,C($s)", | + | 'lhu': "Load halfword unsigned: lhu $t,C($s)", |
− | 'lb': "Load byte lb $t,C($s)", | + | 'lb': "Load byte: lb $t,C($s)", |
− | 'lbu': "Load byte unsigned lbu $t,C($s)", | + | 'lbu': "Load byte unsigned: lbu $t,C($s)", |
− | 'sw': "Store word sw $t,C($s)", | + | 'sw': "Store word: sw $t,C($s)", |
− | 'sh': "Store half sh $t,C($s)", | + | 'sh': "Store half: sh $t,C($s)", |
− | 'sb': "Store byte sb $t,C($s)", | + | 'sb': "Store byte: sb $t,C($s)", |
− | 'lui': "Load upper immediate lui $t,C", | + | 'lui': "Load upper immediate: lui $t,C", |
− | 'mfhi': "Move from high mfhi $d", | + | 'mfhi': "Move from high: mfhi $d", |
− | 'mflo': "Move from low mflo $d", | + | 'mflo': "Move from low: mflo $d", |
− | 'mfcZ': "Move from Control Register mfcZ $t, $d", | + | 'mfcZ': "Move from Control Register: mfcZ $t, $d", |
− | 'mtcZ': "Move to Control Register mtcZ $t, $d", | + | 'mtcZ': "Move to Control Register: mtcZ $t, $d", |
− | 'and': "And and $d,$s,$t", | + | 'and': "And: and $d,$s,$t", |
− | 'andi': "And immediate andi $t,$s,C", | + | 'andi': "And immediate: andi $t,$s,C", |
− | 'or': "Or or $d,$s,$t", | + | 'or': "Or: or $d,$s,$t", |
− | 'ori': "Or immediate ori $t,$s,C", | + | 'ori': "Or immediate: ori $t,$s,C", |
− | 'xor': "Exclusive or xor $d,$s,$t", | + | 'xor': "Exclusive or: xor $d,$s,$t", |
− | 'nor': "Nor nor $d,$s,$t", | + | 'nor': "Nor: nor $d,$s,$t", |
− | 'slt': "Set on less than slt $d,$s,$t", | + | 'slt': "Set on less than: slt $d,$s,$t", |
− | 'slti': "Set on less than immediate slti $t,$s,C", | + | 'slti': "Set on less than immediate: slti $t,$s,C", |
− | 'sll': "Shift left logical immediate sll $d,$t,shamt", | + | 'sll': "Shift left logical immediate: sll $d,$t,shamt", |
− | 'srl': "Shift right logical immediate srl $d,$t,shamt", | + | 'srl': "Shift right logical immediate: srl $d,$t,shamt", |
− | 'sra': "Shift right arithmetic immediate sra $d,$t,shamt", | + | 'sra': "Shift right arithmetic immediate: sra $d,$t,shamt", |
− | 'sllv': "Shift left logical sllv $d,$t,$s", | + | 'sllv': "Shift left logical: sllv $d,$t,$s", |
− | 'srlv': "Shift right logical srlv $d,$t,$s", | + | 'srlv': "Shift right logical: srlv $d,$t,$s", |
− | 'srav': "Shift right arithmetic srav $d,$t,$s", | + | 'srav': "Shift right arithmetic: srav $d,$t,$s", |
− | 'beq': "Branch on equal beq $s,$t,C", | + | 'beq': "Branch on equal: beq $s,$t,C", |
− | 'bne': "Branch on not equal bne $s,$t,C", | + | 'bne': "Branch on not equal: bne $s,$t,C", |
− | 'j': "Jump j C", | + | 'j': "Jump: j C", |
− | 'jr': "Jump register jr $s", | + | 'jr': "Jump register: jr $s", |
− | 'jal': "Jump and link jal C", | + | 'jal': "Jump and link: jal C", |
'nop': "No operation (do nothing)", | 'nop': "No operation (do nothing)", | ||
}; | }; |
Latest revision as of 21:10, 9 February 2016
/* Any JavaScript here will be loaded for users using the MonoBook skin */ // Comments are important. function main() { // Do the thing. $('div#mw-content-text pre').map(transform); } function transform(i, node) { // Do the things to each thing. var txt = node.innerHTML; node.innerHTML = $.map(txt.split(/\r?\n/), transform_line).join('\n'); } var assembly_line = /^([0-9A-Fa-f]{8}: [0-9A-Fa-f]{8} )(\w+)(\s.*)?$/; function transform_line(s) { var match = assembly_line.exec(s); if (match == null) { //no asm detected return s; } var prefix = match[1]; var opname = match[2]; var suffix = match[3]? match[3]: ''; var link = $("<a></a>", { href: "/wiki/R3000_instruction_set#" + opname, title: desc[opname], }).text(opname); if (opname == 'jal') { suffix = transform_call(suffix) } console.log(prefix, opname, suffix, link); return prefix + link[0].outerHTML + suffix; } var transform_call_re = /^( (?:0x ?)?)(\w{8})(.*)$/; function transform_call(s) { var match = transform_call_re.exec(s); if (match == null) { return s; } var prefix = match[1]; var addr = match[2]; var suffix = match[3]; var fname = known_functions[addr] || addr; var link = $("<a></a>", { href: "/wiki/" + fname.replace(' ', '_'), title: fname, }).text(addr); return prefix + link[0].outerHTML + suffix; } var desc = { 'add': "Add: add $d,$s,$t", 'addu': "Add unsigned: addu $d,$s,$t", 'sub': "Subtract: sub $d,$s,$t", 'subu': "Subtract unsigned: subu $d,$s,$t", 'addi': "Add immediate: addi $t,$s,C", 'addiu': "Add immediate unsigned: addiu $t,$s,C", 'mult': "Multiply: mult $s,$t", 'multu': "Multiply unsigned: multu $s,$t", 'div': "Divide: div $s, $t", 'divu': "Divide unsigned: divu $s, $t", 'lw': "Load word: lw $t,C($s)", 'lh': "Load halfword: lh $t,C($s)", 'lhu': "Load halfword unsigned: lhu $t,C($s)", 'lb': "Load byte: lb $t,C($s)", 'lbu': "Load byte unsigned: lbu $t,C($s)", 'sw': "Store word: sw $t,C($s)", 'sh': "Store half: sh $t,C($s)", 'sb': "Store byte: sb $t,C($s)", 'lui': "Load upper immediate: lui $t,C", 'mfhi': "Move from high: mfhi $d", 'mflo': "Move from low: mflo $d", 'mfcZ': "Move from Control Register: mfcZ $t, $d", 'mtcZ': "Move to Control Register: mtcZ $t, $d", 'and': "And: and $d,$s,$t", 'andi': "And immediate: andi $t,$s,C", 'or': "Or: or $d,$s,$t", 'ori': "Or immediate: ori $t,$s,C", 'xor': "Exclusive or: xor $d,$s,$t", 'nor': "Nor: nor $d,$s,$t", 'slt': "Set on less than: slt $d,$s,$t", 'slti': "Set on less than immediate: slti $t,$s,C", 'sll': "Shift left logical immediate: sll $d,$t,shamt", 'srl': "Shift right logical immediate: srl $d,$t,shamt", 'sra': "Shift right arithmetic immediate: sra $d,$t,shamt", 'sllv': "Shift left logical: sllv $d,$t,$s", 'srlv': "Shift right logical: srlv $d,$t,$s", 'srav': "Shift right arithmetic: srav $d,$t,$s", 'beq': "Branch on equal: beq $s,$t,C", 'bne': "Branch on not equal: bne $s,$t,C", 'j': "Jump: j C", 'jr': "Jump register: jr $s", 'jal': "Jump and link: jal C", 'nop': "No operation (do nothing)", }; var known_functions = {} main();