Licheam / assign2

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

对bitcode文件中的函数调用指令

  • 打印被调用函数的名称和行号
  • 函数指针
    • 计算出可能调用的函数不考虑当函数指针被Store到memory中的情况

output format:

${line} : ${func_name1}, ${func_name2}

${line} is unique in output.

Given the test file:

#include <stdio.h>

int add(int a, int b) {
    return a+b;
}

int sub(int a, int b) {
    return a-b;
}

int foo(int a, int b, int (*a_fptr)(int, int)) {
    return a_fptr(a, b);
}


int main() {
    int (*a_fptr)(int, int) = add;
    int (*s_fptr)(int, int) = sub;
    int (*t_fptr)(int, int) = 0;

    char x;
    int op1, op2;
    fprintf(stderr, "Please input num1 +/- num2 \n");

    fscanf(stdin, "%d %c %d", &op1, &x, &op2);
    if (x == '+') {
        t_fptr = a_fptr;
    }
    if (x == '-') {
        t_fptr = s_fptr;
    }
    if (t_fptr != NULL) {
        unsigned result = foo(op1, op2, t_fptr);
        fprintf (stderr, "Result is %d \n", result);
    } else {
        fprintf (stderr, "Unrecoganised operation %c", x);
    }
    return 0;
}

The output should be :

12 : add, sub
23 : fprintf
25 : fscanf
36 : foo
37 : fprintf
39 : fprintf

About


Languages

Language:C 53.2%Language:C++ 37.2%Language:CMake 9.6%