mirror of
https://github.com/revng/revng
synced 2026-06-21 14:07:57 +00:00
1d4e3169eb
The main aim of these changes is to support `ret` instructions (that are indirect jumps), so that function calls can now work properly. * Emit a dummy call to a `@newPC` function to record where a new instruction in the original assembly started, what is its PC and its size. The `Size` parameter for these function call is initially zero, and it's updated later when a new instruction is met or the current basic block is terminated. All these calls, before the final emission of the IR are removed `InstructionTranslator::removeNewPCMarkers`. * Transform translateMoveToPC into an LLVM pass (`TranslateDirectBranchesPass`). * Implement `getNextPC`, which returns the next program counter by looking for a call to `@newpc` in the current basic block, and, recursively, in all the basic blocks dominating the current one. This function is used to force exploration of the basic block coming after a direct jump, which is paritcularly useful in case of a function call. * Introduce `translateIndirectJumps`, which translates all the leftover writes to the PC, i.e. all the indirect ones, by diverting execution to a large switch statement mapping addresses in the original program to the corresponding basic blocks in the translated program. * Introduce `function_call`, a simple test for function calls. * Other minor changes and whitespace fixes.
20 lines
343 B
C
20 lines
343 B
C
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
int half(int parameter) {
|
|
return parameter / 2;
|
|
}
|
|
|
|
int root(char *buffer, size_t size) {
|
|
int result = 412;
|
|
result += half(result);
|
|
result += 81;
|
|
return result;
|
|
}
|
|
|
|
int main(int argc, char *argv[]) {
|
|
printf("%d\n", root(argv[1], strlen(argv[1])));
|
|
return EXIT_SUCCESS;
|
|
}
|