Esempio n. 1
0
void CodeGenVisitor::JIT(Expression* e) {
	StatementList* sl = new StatementList();
	sl->addStatement(new ReturnStatement(e));
	FunctionDefinition* fd = new FunctionDefinition(Type::INT, "", new ParameterList(), sl);

	value_ = 0;
	fd->accept(this);

	if (!value_) {
		delete fd;
		throw "error evaluating expression";
	}

	llvm::Function* f = dynamic_cast<llvm::Function*>(value_);

	void* fPtr = ee_->getPointerToFunction(f);

	// some casting ... because we like magic
	int (*fP)() = (int (*)())(intptr_t)fPtr;

	std::cout << "Evaluated to: " << fP() << std::endl;

	// throw it away
	f->eraseFromParent();
}
Esempio n. 2
0
int main()
{  static int *a;
  int len=0,t=0,i=0,c=0;
	scanf("%d",&t);
	while((c++)<t){
		
		scanf("%d",&len);	
		a=(int*)malloc(len*sizeof(int));
			for(i=0;i<len;i++){
				scanf("%d",&a[i]);
			}
  if (fP(a,len) !=0)
     printf("Case %d: Yes\n",c);
  else
     printf("Case %d: No\n",c);
  }
return 0;
}