Skip to content

Commit

Permalink
WIP: loading external fnc from linked bytecode
Browse files Browse the repository at this point in the history
  • Loading branch information
examon committed Oct 19, 2018
1 parent 40705cb commit 747eba5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
20 changes: 18 additions & 2 deletions apex/apex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,9 @@ bool APEXPass::runOnModule(Module &M) {
// Create exit call instruction.
Value *exit_arg_val = ConstantInt::get(Type::getInt32Ty(M.getContext()), 9);
ArrayRef<Value *> exit_params = makeArrayRef(exit_arg_val);
// CallInst::Create build call instruction to @exit_fcn that has @exit_params.
// Empty string "" means that the @exit_call_inst will not have return variable.
// CallInst::Create build call instruction to @exit_fcn that has
// @exit_params. Empty string "" means that the @exit_call_inst will not
// have return variable.
// @exit_call_inst is inserted BEFORE @chosen_instruction.
CallInst *exit_call_inst =
CallInst::Create(exit_fcn, exit_params, "", chosen_instruction);
Expand All @@ -140,6 +141,21 @@ bool APEXPass::runOnModule(Module &M) {
}
logPrintFlat("- exit call instruction created: ");
exit_call_inst->dump();

// TODO: Test externally linked code.
// TODO: Getting: LLVM ERROR: Program used external function
// 'libprint' which could not be resolved!

logPrint("\nWIP: Testing lib loadout.");
Constant *_lib_print = M.getOrInsertFunction(
"libprint", Type::getVoidTy(M.getContext()), (Type *)0);
Function *lib_print_fcn = cast<Function>(_lib_print);
logPrint("- libprint() from lib:");
lib_print_fcn->dump();
Instruction *lib_print_call_inst =
CallInst::Create(lib_print_fcn, "", chosen_instruction);
logPrintFlat("- call instruction to libprint(): ");
lib_print_call_inst->dump();
}

logPrintUnderline("\nFinal Module Dump:");
Expand Down
4 changes: 2 additions & 2 deletions c-code/lib.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <stdio.h>

void print()
void libprint(void)
{
printf("PRINT() from LIB\n");
printf("LIBPRINT() from LIB\n");
}

0 comments on commit 747eba5

Please sign in to comment.