Skip to content

Commit 8907c03

Browse files
alexbenkeyyuri91
authored andcommitted
added __preexecutor_print_case to print msg + value from preexecutor
1 parent 136834f commit 8907c03

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

llvm/lib/CheerpWriter/PreExecute.cpp

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,38 @@ static GenericValue pre_execute_typed_ptrcast(FunctionType* FT, ArrayRef<Generic
494494
return Args[0];
495495
}
496496

497+
static GenericValue pre_execute_print_value_handler(FunctionType *FT,
498+
ArrayRef<GenericValue> Args, AttributeList Attrs)
499+
500+
{
501+
ExecutionEngine *currentEE = PreExecute::currentPreExecutePass->currentEE;
502+
const char* msg = reinterpret_cast <char*>(currentEE->GVTORP(Args[0]));
503+
504+
llvm::errs() << msg;
505+
506+
for (int i = 1; i < Args.size(); ++i){
507+
Type* valueType = FT->getParamType(i);
508+
509+
if (valueType->isDoubleTy()){
510+
llvm::errs() << " " << llvm::format("%.10f", Args[i].DoubleVal);
511+
}
512+
else if (valueType->isFloatTy()){
513+
llvm::errs() << " " << llvm::format("%.10f", Args[i].FloatVal);
514+
}
515+
else if (valueType->isIntegerTy()){
516+
llvm::errs() << " " << Args[i].IntVal.getSExtValue();
517+
}
518+
else if (valueType->isPointerTy()){
519+
llvm::errs() << " " << reinterpret_cast<char *>(currentEE->GVTORP(Args[i]));
520+
}
521+
else if (valueType)
522+
llvm::errs() << " incompatible value type";
523+
}
524+
525+
llvm::errs() << "\n";
526+
return GenericValue(0);
527+
}
528+
497529
static GenericValue assertEqualImpl(FunctionType *FT,
498530
ArrayRef<GenericValue> Args, AttributeList Attrs)
499531
{
@@ -561,8 +593,10 @@ static void* LazyFunctionCreator(const std::string& funcName)
561593
return (void*)(void(*)())pre_execute_smax;
562594
if (strncmp(funcName.c_str(), "llvm.abs.", strlen("llvm.abs."))==0)
563595
return (void*)(void(*)())pre_execute_abs;
564-
if (strcmp(funcName.c_str(), "assertEqualImpl") == 0)
596+
if (strcmp(funcName.c_str(), "assertEqualImpl")==0)
565597
return (void*)(void(*)())assertEqualImpl;
598+
if (funcName.find("__preexecute_print_case") != std::string::npos)
599+
return (void*)(void(*)())pre_execute_print_value_handler;
566600
if (strcmp(funcName.c_str(), "llvm.dbg.value") == 0)
567601
return (void*)(void(*)())emptyFunction;
568602

0 commit comments

Comments
 (0)