You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
648 B
31 lines
648 B
/* from http://blog.llvm.org/2010/01/address-of-label-and-indirect-branches.html
|
|
*/
|
|
|
|
static int fn(const char* opcodes) {
|
|
static const void* codetable[] = {&&RETURN, &&INCREMENT, &&DECREMENT,
|
|
&&DOUBLE, &&SWAPWORD};
|
|
int result = 0;
|
|
|
|
goto* codetable[*(opcodes++)];
|
|
RETURN:
|
|
return result;
|
|
INCREMENT:
|
|
result++;
|
|
goto* codetable[*(opcodes++)];
|
|
DECREMENT:
|
|
result--;
|
|
goto* codetable[*(opcodes++)];
|
|
DOUBLE:
|
|
result <<= 1;
|
|
goto* codetable[*(opcodes++)];
|
|
SWAPWORD:
|
|
result = (result << 16) | (result >> 16);
|
|
goto* codetable[*(opcodes++)];
|
|
}
|
|
|
|
int main() {
|
|
char opcodes[10];
|
|
|
|
return fn(opcodes);
|
|
}
|