Created
April 5, 2012 16:57
-
-
Save m4rw3r/2312504 to your computer and use it in GitHub Desktop.
This file contains 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
ins NOP() | |
{ | |
/* Empty */ | |
} | |
ins END() | |
{ | |
goto end_eval; | |
} | |
/* TODO: arithmetic variants which alert on overflow? */ | |
/* TODO: Float operations (double) */ | |
/* Immediates (constant 2nd parameters) */ | |
ins ADDI(variable, variable, const int) | |
{ | |
$2.asI = $1.asI + $3; | |
} | |
ins SLTI(variable, variable, const int) | |
{ | |
$2.asI = $1.asI < (int64_t) $3; | |
} | |
/* Unsigned comparison */ | |
ins SLTIU(variable, variable, const uint) | |
{ | |
$2.asI = $1.asU < (uint64_t) $3; | |
} | |
ins ANDI(variable, variable, const uint) | |
{ | |
$2.asU = $1.asU & (uint64_t) $3; | |
} | |
ins ORI(variable, variable, const uint) | |
{ | |
$2.asU = $1.asU | (uint64_t) $3; | |
} | |
ins XORI(variable, variable, const uint) | |
{ | |
$2.asU = $1.asU ^ (uint64_t) $3; | |
} | |
ins LUI(variable, undef, const uint) | |
{ | |
$1.asU = ((uint64_t) $3) << (uint64_t) 32; | |
} | |
/* Arithmetic */ | |
ins ADD(variable, variable, variable) | |
{ | |
$3.asI = $1.asI + $2.asI; | |
} | |
ins SUB(variable, variable, variable) | |
{ | |
$3.asI = $1.asI - $2.asI; | |
} | |
ins SLT(variable, variable, variable) | |
{ | |
$1.asI = $2.asI < $3.asI; | |
} | |
/* Unsigned comparison */ | |
ins SLTU(variable, variable, variable) | |
{ | |
$1.asI = $2.asU < $3.asU; | |
} | |
ins AND(variable, variable, variable) | |
{ | |
$1.asU = $2.asU & $3.asU; | |
} | |
ins OR(variable, variable, variable) | |
{ | |
$1.asU = $2.asU | $3.asU; | |
} | |
ins XOR(variable, variable, variable) | |
{ | |
$1.asU = $2.asU ^ $3.asU; | |
} | |
ins NOR(variable, variable, variable) | |
{ | |
$1.asU = ~($2.asU | $3.asU); | |
} | |
ins SLL(variable, variable, uint) | |
{ | |
$1.asU = $2.asU << $3; | |
} | |
ins SRL(variable, variable, uint) | |
{ | |
$1.asU = $2.asU >> $3; | |
} | |
ins SRA(variable, variable, int) | |
{ | |
/* TODO: Hopefully this will result in arithmetic shift, implementation dependent */ | |
$1.asI = $2.asI >> $3; | |
} | |
ins SLLV(variable, variable, variable) | |
{ | |
$1.asU = $2.asU << $3.asU; | |
} | |
ins SRLV(variable, variable, variable) | |
{ | |
$1.asU = $2.asU >> $3.asU; | |
} | |
ins SRAV(variable, variable, variable) | |
{ | |
/* TODO: Hopefully this will result in arithmetic shift, implementation dependent */ | |
$1.asI = $2.asI >> $3.asI; | |
} | |
ins JMP(undef, undef, const int) | |
{ | |
assert($3 != 0); | |
instr += $3; | |
continue; | |
} | |
/* TODO: Add the Jump and Link? (ie. store the previous address in some register)? */ | |
/* TODO: Needed? The variables does not know how the instructions are arranged at the moment */ | |
ins JMPR(variable) | |
{ | |
assert($1.asI != 0); | |
instr += $1.asI; | |
continue; | |
} | |
ins BEQ(variable, variable, const int) | |
{ | |
if($1.asI == $2.asI) { | |
assert($3 != 0); | |
instr += $3; | |
continue; | |
} | |
} | |
ins BNE(variable, variable, const int) | |
{ | |
if($1.asI != $2.asI) { | |
assert($3 != 0); | |
instr += $3; | |
continue; | |
} | |
} | |
ins BLTZ(variable, undef, const int) | |
{ | |
if($1.asI < 0) { | |
assert($3 != 0); | |
instr += $3; | |
continue; | |
} | |
} | |
ins BGTZ(variable, undef, const int) | |
{ | |
if($1.asI > 0) { | |
assert($3 != 0); | |
instr += $3; | |
continue; | |
} | |
} | |
ins BLEZ(variable, undef, const int) | |
{ | |
if($1.asI <= 0) { | |
assert($3 != 0); | |
instr += $3; | |
continue; | |
} | |
} | |
ins BGEZ(variable, undef, const int) | |
{ | |
if($1.asI >= 0) { | |
assert($3 != 0); | |
instr += $3; | |
continue; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment