@@ -14,11 +14,12 @@ namespace klee {
1414MockBuilder::MockBuilder (const llvm::Module *initModule,
1515 std::string mockEntrypoint, std::string userEntrypoint,
1616 std::map<std::string, llvm::Type *> externals,
17- AnnotationsMap annotations )
17+ const std::string &annotationsFile )
1818 : userModule(initModule), externals(std::move(externals)),
19- annotations (std::move(annotations)),
2019 mockEntrypoint (std::move(mockEntrypoint)),
21- userEntrypoint(std::move(userEntrypoint)) {}
20+ userEntrypoint(std::move(userEntrypoint)) {
21+ annotations = parseAnnotations (annotationsFile, userModule);
22+ }
2223
2324std::unique_ptr<llvm::Module> MockBuilder::build () {
2425 initMockModule ();
@@ -41,14 +42,14 @@ void MockBuilder::initMockModule() {
4142void MockBuilder::buildMockMain () {
4243 llvm::Function *userMainFn = userModule->getFunction (userEntrypoint);
4344 if (!userMainFn) {
44- klee_error (" Entry function '%s' not found in module. " ,
45+ klee_error (" Mock: Entry function '%s' not found in module" ,
4546 userEntrypoint.c_str ());
4647 }
4748 mockModule->getOrInsertFunction (mockEntrypoint, userMainFn->getFunctionType (),
4849 userMainFn->getAttributes ());
4950 llvm::Function *mockMainFn = mockModule->getFunction (mockEntrypoint);
5051 if (!mockMainFn) {
51- klee_error (" Entry function '%s' not found in module. " ,
52+ klee_error (" Mock: Entry function '%s' not found in module" ,
5253 mockEntrypoint.c_str ());
5354 }
5455 auto globalsInitBlock =
@@ -78,7 +79,7 @@ void MockBuilder::buildExternalGlobalsDefinitions() {
7879 mockModule->getOrInsertGlobal (extName, type);
7980 auto *global = mockModule->getGlobalVariable (extName);
8081 if (!global) {
81- klee_error (" Unable to add global variable '%s' to module" ,
82+ klee_error (" Mock: Unable to add global variable '%s' to module" ,
8283 extName.c_str ());
8384 }
8485 global->setLinkage (llvm::GlobalValue::ExternalLinkage);
@@ -88,14 +89,16 @@ void MockBuilder::buildExternalGlobalsDefinitions() {
8889
8990 auto *zeroInitializer = llvm::Constant::getNullValue (it.second );
9091 if (!zeroInitializer) {
91- klee_error (" Unable to get zero initializer for '%s'" , extName.c_str ());
92+ klee_error (" Mock: Unable to get zero initializer for '%s'" ,
93+ extName.c_str ());
9294 }
9395 global->setInitializer (zeroInitializer);
9496 buildCallKleeMakeSymbolic (" klee_make_symbolic" , global, type,
9597 " external_" + extName);
9698 }
9799}
98100
101+ // TODO: discuss should we annotate not external function
99102void MockBuilder::buildExternalFunctionsDefinitions () {
100103 for (const auto &it : externals) {
101104 if (!it.second ->isFunctionTy ()) {
@@ -106,7 +109,8 @@ void MockBuilder::buildExternalFunctionsDefinitions() {
106109 mockModule->getOrInsertFunction (extName, type);
107110 llvm::Function *func = mockModule->getFunction (extName);
108111 if (!func) {
109- klee_error (" Unable to find function '%s' in module" , extName.c_str ());
112+ klee_error (" Mock: Unable to find function '%s' in module" ,
113+ extName.c_str ());
110114 }
111115 if (!func->empty ()) {
112116 continue ;
@@ -322,7 +326,7 @@ void MockBuilder::buildAnnotationForExternalFunctionReturn(
322326 switch (statement->getKind ()) {
323327 case Statement::Kind::Deref:
324328 klee_warning (" Annotation: unused Deref for return function \" %s\" " ,
325- func->getName ());
329+ func->getName (). str (). c_str () );
326330 break ;
327331 case Statement::Kind::InitNull: {
328332 if (!returnType->isPointerTy ()) {
0 commit comments