Created
November 2, 2018 13:01
-
-
Save zhangysh1995/2245e41d5bf272bdb3923f7cd2c051f1 to your computer and use it in GitHub Desktop.
llvmlite bacsic usage
This file contains hidden or 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
import sys | |
from llvmlite import binding as bd | |
from llvmlite import ir | |
# read bc / ir file | |
bc = sys.argv[1] | |
with open(bc, 'r', encoding="latin-1") as mybc: | |
program = mybc.read() | |
ct = bd.create_context() | |
moduleRef = bd.parse_bitcode(program, ct) | |
valueRef = moduleRef.get_function("main") | |
# creat CFG | |
graph = bd.get_function_cfg(valueRef, True) | |
# print(graph) | |
bd.view_dot_graph(graph, view= True) | |
''' | |
Add function to a module | |
''' | |
# define a type | |
int32 = ir.IntType(32) | |
# create an empty module | |
mod = ir.Module(name=__file__) | |
# create a function | |
ftype = ir.FunctionType(int32, (int32,)) | |
func = ir.Function(mod, ftype, "test") | |
for f in mod.functions: | |
print(str(f)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment