bool RSExportReduce::analyzeTranslationUnit() {

  RSContext &RSC = *getRSContext();
  clang::Preprocessor &PP = RSC.getPreprocessor();

  StateOfAnalyzeTranslationUnit S(
      RSC, PP, RSC.getASTContext(),
      [&PP, this] (const char *Key, const std::string &Name) {
        std::ostringstream Description;
        Description
            << Key << " " << Name << "()"
            << " for '#pragma rs " << KeyReduce << "(" << mNameReduce << ")'"
            << " (" << mLocation.printToString(PP.getSourceManager()) << ")";
        return Description.str();
      });

  S.FnInitializer  = lookupFunction(S, KeyInitializer,  mNameInitializer);
  S.FnAccumulator  = lookupFunction(S, KeyAccumulator,  mNameAccumulator);
  S.FnCombiner     = lookupFunction(S, KeyCombiner,     mNameCombiner);
  S.FnOutConverter = lookupFunction(S, KeyOutConverter, mNameOutConverter);
  S.FnHalter       = lookupFunction(S, KeyHalter,       mNameHalter);

  if (!S.Ok)
    return false;

  analyzeInitializer(S);
  analyzeAccumulator(S);
  analyzeCombiner(S);
  analyzeOutConverter(S);
  analyzeHalter(S);
  analyzeResultType(S);

  return S.Ok;
}
Esempio n. 2
0
void DebugInfo::recordPerfMap(TCRange range, const Func* func,
                              bool exit, bool inPrologue) {
  if (!m_perfMap) return;
  if (RuntimeOption::EvalProfileBC) return;
  std::string name = lookupFunction(func, exit, inPrologue, true);
  fprintf(m_perfMap, "%lx %x %s\n",
    reinterpret_cast<uintptr_t>(range.begin()),
    range.size(),
    name.c_str());
  fflush(m_perfMap);
}
Esempio n. 3
0
void GetOrdinal(Json::Value& config, Ord* setting)
{
	if (config.isNull())
		return;

	Ord value;
	if (config.isString())
		value = lookupFunction(config.asString());
	else
		value = (Ord) config.asInt();

	*setting = value;
}
Esempio n. 4
0
static llvm::Value* getFunc(void* func, const char* name) {
    llvm::Function* f = lookupFunction(name);
    ASSERT(f, "%s", name);
    g.func_addr_registry.registerFunction(name, func, 0, f);
    return embedConstantPtr(func, f->getType());
}
Esempio n. 5
0
void initGlobalFuncs(GlobalState& g) {
    g.llvm_opaque_type = llvm::StructType::create(g.context, "opaque");

    g.llvm_functionmetadata_type_ptr = lookupFunction("createFunctionFromMetadata")->arg_begin()->getType();
    g.llvm_module_type_ptr = g.stdlib_module->getTypeByName("class.pyston::BoxedModule")->getPointerTo();
    assert(g.llvm_module_type_ptr);
    g.llvm_bool_type_ptr = lookupFunction("boxBool")->getReturnType();

    g.llvm_value_type_ptr = lookupFunction("getattr")->getReturnType();
    g.llvm_value_type = g.llvm_value_type_ptr->getSequentialElementType();
    g.llvm_value_type_ptr_ptr = g.llvm_value_type_ptr->getPointerTo();
    // g.llvm_class_type_ptr = llvm::cast<llvm::StructType>(g.llvm_value_type)->getElementType(0);
    // g.llvm_class_type = g.llvm_class_type_ptr->getSequentialElementType();
    g.llvm_class_type = g.stdlib_module->getTypeByName("class.pyston::BoxedClass");
    assert(g.llvm_class_type);
    g.llvm_class_type_ptr = g.llvm_class_type->getPointerTo();

    g.llvm_boxedstring_type_ptr = g.stdlib_module->getTypeByName("class.pyston::BoxedString");
    assert(g.llvm_boxedstring_type_ptr);
    g.llvm_boxedstring_type_ptr = g.llvm_boxedstring_type_ptr->getPointerTo();

    g.llvm_dict_type_ptr = g.stdlib_module->getTypeByName("class.pyston::BoxedDict");
    assert(g.llvm_dict_type_ptr);
    g.llvm_dict_type_ptr = g.llvm_dict_type_ptr->getPointerTo();

    g.llvm_aststmt_type_ptr = g.stdlib_module->getTypeByName("class.pyston::AST_stmt");
    assert(g.llvm_aststmt_type_ptr);
    g.llvm_aststmt_type_ptr = g.llvm_aststmt_type_ptr->getPointerTo();

    g.llvm_astexpr_type_ptr = g.stdlib_module->getTypeByName("class.pyston::AST_expr");
    assert(g.llvm_astexpr_type_ptr);
    g.llvm_astexpr_type_ptr = g.llvm_astexpr_type_ptr->getPointerTo();

    // The LLVM vector type for the arguments that we pass to runtimeCall and related functions.
    // It will be a pointer to a type named something like class.std::vector or
    // class.std::vector.##. We can figure out exactly what it is by looking at the last
    // argument of runtimeCall.
    g.vector_ptr = (--lookupFunction("runtimeCall")->getArgumentList().end())->getType();

    g.llvm_closure_type_ptr = g.stdlib_module->getTypeByName("class.pyston::BoxedClosure")->getPointerTo();
    assert(g.llvm_closure_type_ptr);

    g.llvm_generator_type_ptr = g.stdlib_module->getTypeByName("class.pyston::BoxedGenerator")->getPointerTo();
    assert(g.llvm_generator_type_ptr);

    g.llvm_excinfo_type = g.stdlib_module->getTypeByName("struct.pyston::ExcInfo");
    assert(g.llvm_excinfo_type);

    g.llvm_frame_info_type = g.stdlib_module->getTypeByName("struct.pyston::FrameInfo");
    assert(g.llvm_frame_info_type);

#define GET(N) g.funcs.N = getFunc((void*)N, STRINGIFY(N))

    g.funcs.printf = addFunc((void*)printf, g.i8_ptr, true);
    g.funcs.my_assert = getFunc((void*)my_assert, "my_assert");
    g.funcs.malloc = addFunc((void*)malloc, g.i8_ptr, g.i64);
    g.funcs.free = addFunc((void*)free, g.void_, g.i8_ptr);

    g.funcs.allowGLReadPreemption = getFunc((void*)threading::allowGLReadPreemption, "allowGLReadPreemption");

    GET(softspace);

    GET(createFunctionFromMetadata);
    GET(getFunctionMetadata);
    GET(createUserClass);
    GET(boxInt);
    GET(unboxInt);
    GET(boxFloat);
    GET(unboxFloat);
    GET(boxInstanceMethod);
    GET(boxBool);
    GET(unboxBool);
    GET(createTuple);
    GET(createList);
    GET(createDict);
    GET(createSlice);
    GET(createClosure);
    GET(createGenerator);
    GET(createSet);
    GET(initFrame);
    GET(deinitFrame);

    GET(getattr);
    GET(getattr_capi);
    GET(setattr);
    GET(delattr);
    GET(getitem);
    GET(getitem_capi);
    GET(setitem);
    GET(delitem);
    GET(getGlobal);
    GET(delGlobal);
    GET(setGlobal);
    GET(binop);
    GET(compare);
    GET(augbinop);
    GET(nonzero);
    GET(unboxedLen);
    GET(getclsattr);
    GET(unaryop);
    GET(import);
    GET(importFrom);
    GET(importStar);
    GET(repr);
    GET(exceptionMatches);
    GET(yield);
    GET(getiterHelper);
    GET(hasnext);
    GET(apply_slice);

    GET(unpackIntoArray);
    GET(raiseAttributeError);
    GET(raiseAttributeErrorStr);
    GET(raiseAttributeErrorCapi);
    GET(raiseAttributeErrorStrCapi);
    GET(raiseIndexErrorStr);
    GET(raiseIndexErrorStrCapi);
    GET(raiseNotIterableError);
    GET(assertNameDefined);
    GET(assertFailDerefNameDefined);
    GET(assertFail);
    GET(printExprHelper);
    GET(printHelper);

    GET(listAppendInternal);
    GET(getSysStdout);

    GET(exec);
    GET(boxedLocalsSet);
    GET(boxedLocalsGet);
    GET(boxedLocalsDel);

    g.funcs.runtimeCall.cxx_val = getFunc((void*)runtimeCall, "runtimeCall");
    g.funcs.runtimeCall0.cxx_val = addFunc((void*)runtimeCall, g.llvm_value_type_ptr, g.llvm_value_type_ptr, g.i32);
    g.funcs.runtimeCall1.cxx_val
        = addFunc((void*)runtimeCall, g.llvm_value_type_ptr, g.llvm_value_type_ptr, g.i32, g.llvm_value_type_ptr);
    g.funcs.runtimeCall2.cxx_val = addFunc((void*)runtimeCall, g.llvm_value_type_ptr, g.llvm_value_type_ptr, g.i32,
                                           g.llvm_value_type_ptr, g.llvm_value_type_ptr);
    g.funcs.runtimeCall3.cxx_val = addFunc((void*)runtimeCall, g.llvm_value_type_ptr, g.llvm_value_type_ptr, g.i32,
                                           g.llvm_value_type_ptr, g.llvm_value_type_ptr, g.llvm_value_type_ptr);
    g.funcs.runtimeCallN.cxx_val
        = addFunc((void*)runtimeCall, g.llvm_value_type_ptr, g.llvm_value_type_ptr, g.i32, g.llvm_value_type_ptr,
                  g.llvm_value_type_ptr, g.llvm_value_type_ptr, g.llvm_value_type_ptr->getPointerTo());

    g.funcs.runtimeCall.capi_val = getFunc((void*)runtimeCallCapi, "runtimeCallCapi");
    g.funcs.runtimeCall0.capi_val
        = addFunc((void*)runtimeCallCapi, g.llvm_value_type_ptr, g.llvm_value_type_ptr, g.i32);
    g.funcs.runtimeCall1.capi_val
        = addFunc((void*)runtimeCallCapi, g.llvm_value_type_ptr, g.llvm_value_type_ptr, g.i32, g.llvm_value_type_ptr);
    g.funcs.runtimeCall2.capi_val = addFunc((void*)runtimeCallCapi, g.llvm_value_type_ptr, g.llvm_value_type_ptr, g.i32,
                                            g.llvm_value_type_ptr, g.llvm_value_type_ptr);
    g.funcs.runtimeCall3.capi_val = addFunc((void*)runtimeCallCapi, g.llvm_value_type_ptr, g.llvm_value_type_ptr, g.i32,
                                            g.llvm_value_type_ptr, g.llvm_value_type_ptr, g.llvm_value_type_ptr);
    g.funcs.runtimeCallN.capi_val
        = addFunc((void*)runtimeCallCapi, g.llvm_value_type_ptr, g.llvm_value_type_ptr, g.i32, g.llvm_value_type_ptr,
                  g.llvm_value_type_ptr, g.llvm_value_type_ptr, g.llvm_value_type_ptr->getPointerTo());


    g.funcs.callattr.cxx_val = getFunc((void*)callattr, "callattr");
    g.funcs.callattr0.cxx_val
        = addFunc((void*)callattr, g.llvm_value_type_ptr, g.llvm_value_type_ptr, g.llvm_boxedstring_type_ptr, g.i64);
    g.funcs.callattr1.cxx_val = addFunc((void*)callattr, g.llvm_value_type_ptr, g.llvm_value_type_ptr,
                                        g.llvm_boxedstring_type_ptr, g.i64, g.llvm_value_type_ptr);
    g.funcs.callattr2.cxx_val
        = addFunc((void*)callattr, g.llvm_value_type_ptr, g.llvm_value_type_ptr, g.llvm_boxedstring_type_ptr, g.i64,
                  g.llvm_value_type_ptr, g.llvm_value_type_ptr);
    g.funcs.callattr3.cxx_val
        = addFunc((void*)callattr, g.llvm_value_type_ptr, g.llvm_value_type_ptr, g.llvm_boxedstring_type_ptr, g.i64,
                  g.llvm_value_type_ptr, g.llvm_value_type_ptr, g.llvm_value_type_ptr);
    g.funcs.callattrN.cxx_val = addFunc(
        (void*)callattr, g.llvm_value_type_ptr, g.llvm_value_type_ptr, g.llvm_boxedstring_type_ptr, g.i64,
        g.llvm_value_type_ptr, g.llvm_value_type_ptr, g.llvm_value_type_ptr, g.llvm_value_type_ptr->getPointerTo());


    g.funcs.callattr.capi_val = getFunc((void*)callattrCapi, "callattrCapi");
    g.funcs.callattr0.capi_val = addFunc((void*)callattrCapi, g.llvm_value_type_ptr, g.llvm_value_type_ptr,
                                         g.llvm_boxedstring_type_ptr, g.i64);
    g.funcs.callattr1.capi_val = addFunc((void*)callattrCapi, g.llvm_value_type_ptr, g.llvm_value_type_ptr,
                                         g.llvm_boxedstring_type_ptr, g.i64, g.llvm_value_type_ptr);
    g.funcs.callattr2.capi_val
        = addFunc((void*)callattrCapi, g.llvm_value_type_ptr, g.llvm_value_type_ptr, g.llvm_boxedstring_type_ptr, g.i64,
                  g.llvm_value_type_ptr, g.llvm_value_type_ptr);
    g.funcs.callattr3.capi_val
        = addFunc((void*)callattrCapi, g.llvm_value_type_ptr, g.llvm_value_type_ptr, g.llvm_boxedstring_type_ptr, g.i64,
                  g.llvm_value_type_ptr, g.llvm_value_type_ptr, g.llvm_value_type_ptr);
    g.funcs.callattrN.capi_val = addFunc(
        (void*)callattrCapi, g.llvm_value_type_ptr, g.llvm_value_type_ptr, g.llvm_boxedstring_type_ptr, g.i64,
        g.llvm_value_type_ptr, g.llvm_value_type_ptr, g.llvm_value_type_ptr, g.llvm_value_type_ptr->getPointerTo());

    g.funcs.reoptCompiledFunc = addFunc((void*)reoptCompiledFunc, g.i8_ptr, g.i8_ptr);
    g.funcs.compilePartialFunc = addFunc((void*)compilePartialFunc, g.i8_ptr, g.i8_ptr);

    g.funcs.__cxa_end_catch = addFunc((void*)__cxa_end_catch, g.void_);
    GET(raise0);
    GET(raise0_capi);
    GET(raise3);
    GET(raise3_capi);
    GET(PyErr_Fetch);
    GET(PyErr_NormalizeException);
    GET(PyErr_Restore);
    GET(caughtCapiException);
    GET(reraiseCapiExcAsCxx);
    GET(deopt);

    GET(div_float_float);
    GET(floordiv_float_float);
    GET(mod_float_float);
    GET(pow_float_float);

    GET(dump);
}
Esempio n. 6
0
void initGlobalFuncs(GlobalState& g) {
    g.llvm_opaque_type = llvm::StructType::create(g.context, "opaque");

    g.llvm_clfunction_type_ptr = lookupFunction("boxCLFunction")->arg_begin()->getType();
    g.llvm_module_type_ptr = g.stdlib_module->getTypeByName("class.pyston::BoxedModule")->getPointerTo();
    assert(g.llvm_module_type_ptr);
    g.llvm_bool_type_ptr = lookupFunction("boxBool")->getReturnType();

    g.llvm_value_type_ptr = lookupFunction("getattr")->getReturnType();
    g.llvm_value_type = g.llvm_value_type_ptr->getSequentialElementType();
    g.llvm_value_type_ptr_ptr = g.llvm_value_type_ptr->getPointerTo();
    // g.llvm_class_type_ptr = llvm::cast<llvm::StructType>(g.llvm_value_type)->getElementType(0);
    // g.llvm_class_type = g.llvm_class_type_ptr->getSequentialElementType();
    g.llvm_class_type = g.stdlib_module->getTypeByName("class.pyston::BoxedClass");
    assert(g.llvm_class_type);
    g.llvm_class_type_ptr = g.llvm_class_type->getPointerTo();

    g.llvm_str_type_ptr = lookupFunction("boxStringPtr")->arg_begin()->getType();

    // The LLVM vector type for the arguments that we pass to runtimeCall and related functions.
    // It will be a pointer to a type named something like class.std::vector or
    // class.std::vector.##. We can figure out exactly what it is by looking at the last
    // argument of runtimeCall.
    g.vector_ptr = (--lookupFunction("runtimeCall")->getArgumentList().end())->getType();

    g.llvm_closure_type_ptr = g.stdlib_module->getTypeByName("class.pyston::BoxedClosure")->getPointerTo();
    assert(g.llvm_closure_type_ptr);

    g.llvm_generator_type_ptr = g.stdlib_module->getTypeByName("class.pyston::BoxedGenerator")->getPointerTo();
    assert(g.llvm_generator_type_ptr);

#define GET(N) g.funcs.N = getFunc((void*)N, STRINGIFY(N))

    g.funcs.printf = addFunc((void*)printf, g.i8_ptr, true);
    g.funcs.my_assert = getFunc((void*)my_assert, "my_assert");
    g.funcs.malloc = addFunc((void*)malloc, g.i8_ptr, g.i64);
    g.funcs.free = addFunc((void*)free, g.void_, g.i8_ptr);

    g.funcs.allowGLReadPreemption = addFunc((void*)threading::allowGLReadPreemption, g.void_);

    GET(boxCLFunction);
    GET(unboxCLFunction);
    GET(createUserClass);
    GET(boxInt);
    GET(unboxInt);
    GET(boxFloat);
    GET(unboxFloat);
    GET(boxStringPtr);
    GET(boxInstanceMethod);
    GET(boxBool);
    GET(unboxBool);
    GET(createTuple);
    GET(createList);
    GET(createDict);
    GET(createSlice);
    GET(createClosure);
    GET(createGenerator);
    GET(createLong);
    GET(createSet);

    GET(getattr);
    GET(setattr);
    GET(delattr);
    GET(getitem);
    GET(setitem);
    GET(delitem);
    GET(getGlobal);
    GET(delGlobal);
    GET(binop);
    GET(compare);
    GET(augbinop);
    GET(nonzero);
    GET(print);
    GET(unboxedLen);
    GET(getclsattr);
    GET(unaryop);
    GET(import);
    GET(importFrom);
    GET(importStar);
    GET(repr);
    GET(isinstance);
    GET(yield);

    GET(checkUnpackingLength);
    GET(raiseAttributeError);
    GET(raiseAttributeErrorStr);
    GET(raiseNotIterableError);
    GET(assertNameDefined);
    GET(assertFail);

    GET(printFloat);
    GET(listAppendInternal);

    g.funcs.runtimeCall = getFunc((void*)runtimeCall, "runtimeCall");
    g.funcs.runtimeCall0 = addFunc((void*)runtimeCall, g.llvm_value_type_ptr, g.llvm_value_type_ptr, g.i32);
    g.funcs.runtimeCall1
        = addFunc((void*)runtimeCall, g.llvm_value_type_ptr, g.llvm_value_type_ptr, g.i32, g.llvm_value_type_ptr);
    g.funcs.runtimeCall2 = addFunc((void*)runtimeCall, g.llvm_value_type_ptr, g.llvm_value_type_ptr, g.i32,
                                   g.llvm_value_type_ptr, g.llvm_value_type_ptr);
    g.funcs.runtimeCall3 = addFunc((void*)runtimeCall, g.llvm_value_type_ptr, g.llvm_value_type_ptr, g.i32,
                                   g.llvm_value_type_ptr, g.llvm_value_type_ptr, g.llvm_value_type_ptr);

    g.funcs.callattr = getFunc((void*)callattr, "callattr");
    g.funcs.callattr0
        = addFunc((void*)callattr, g.llvm_value_type_ptr, g.llvm_value_type_ptr, g.llvm_str_type_ptr, g.i1, g.i32);
    g.funcs.callattr1 = addFunc((void*)callattr, g.llvm_value_type_ptr, g.llvm_value_type_ptr, g.llvm_str_type_ptr,
                                g.i1, g.i32, g.llvm_value_type_ptr);
    g.funcs.callattr2 = addFunc((void*)callattr, g.llvm_value_type_ptr, g.llvm_value_type_ptr, g.llvm_str_type_ptr,
                                g.i1, g.i32, g.llvm_value_type_ptr, g.llvm_value_type_ptr);
    g.funcs.callattr3 = addFunc((void*)callattr, g.llvm_value_type_ptr, g.llvm_value_type_ptr, g.llvm_str_type_ptr,
                                g.i1, g.i32, g.llvm_value_type_ptr, g.llvm_value_type_ptr, g.llvm_value_type_ptr);

    g.funcs.reoptCompiledFunc = addFunc((void*)reoptCompiledFunc, g.i8_ptr, g.i8_ptr);
    g.funcs.compilePartialFunc = addFunc((void*)compilePartialFunc, g.i8_ptr, g.i8_ptr);

    GET(__cxa_begin_catch);
    g.funcs.__cxa_end_catch = addFunc((void*)__cxa_end_catch, g.void_);
    GET(raise0);
    GET(raise3);

    GET(div_float_float);
    GET(mod_float_float);
    GET(pow_float_float);
}
Esempio n. 7
0
DwarfChunk* DwarfInfo::addTracelet(TCRange range,
                                   folly::Optional<std::string> name,
                                   const Func *func,
                                   PC instr,
                                   bool exit,
                                   bool inPrologue) {
  DwarfChunk* chunk = nullptr;
  FunctionInfo* f = new FunctionInfo(range, exit);
  const Unit* unit = func ? func->unit(): nullptr;
  if (name) {
    f->name = *name;
  } else {
    assert(func != nullptr);
    f->name = lookupFunction(func, exit, inPrologue, true);
    auto names = func->localNames();
    for (int i = 0; i < func->numNamedLocals(); i++) {
      f->m_namedLocals.push_back(names[i]->toCppString());
    }
  }
  f->file = lookupFile(unit);

  TCA start = range.begin();
  const TCA end = range.end();

  Lock lock(s_lock);
  auto const it = m_functions.lower_bound(range.begin());
  auto const fi = it->second;
  if (it != m_functions.end() && fi->name == f->name &&
      fi->file == f->file &&
      start > fi->range.begin() &&
      end > fi->range.end()) {
    // XXX: verify that overlapping address come from jmp fixups
    start = fi->range.end();
    fi->range.extend(end);
    m_functions[end] = fi;
    m_functions.erase(it);
    delete f;
    f = m_functions[end];
    assert(f->m_chunk != nullptr);
    f->m_chunk->clearSynced();
    f->clearPerfSynced();
  } else {
    m_functions[end] = f;
  }

  addLineEntries(TCRange(start, end, range.isAcold()), unit, instr, f);

  if (f->m_chunk == nullptr) {
    if (m_dwarfChunks.size() == 0 || m_dwarfChunks[0] == nullptr) {
      // new chunk of base size
      chunk = new DwarfChunk();
      m_dwarfChunks.push_back(chunk);
    } else if (m_dwarfChunks[0]->m_functions.size()
                 < RuntimeOption::EvalGdbSyncChunks) {
      // reuse first chunk
      chunk = m_dwarfChunks[0];
      chunk->clearSynced();
    } else {
      // compact chunks
      compactChunks();
      m_dwarfChunks[0] = chunk = new DwarfChunk();
    }
    chunk->m_functions.push_back(f);
    f->m_chunk = chunk;
  }

#ifdef USE_ELF_WRITER
  if (f->m_chunk->m_functions.size() >= RuntimeOption::EvalGdbSyncChunks) {
    ElfWriter e = ElfWriter(f->m_chunk);
  }
#endif

  return f->m_chunk;
}
Esempio n. 8
0
File: token.c Progetto: brennie/sexc
void nextToken(FILE *input)
{
	char buffer[FN_NAME_MAX + 1];
	int c;	

	for (c = fgetc(input); IS_WHITESPACE(c); c = fgetc(input));
	
	if (c == EOF)
	{
#ifdef DEBUG
		printf("Got EOF\n");
#endif
		die("EOF Reached");
	}
	
	if (c == '(')
	{	
		lookahead.type = BEGIN;

#ifdef DEBUG
		printf("Got (\n");
#endif
	}
	else if (c == ')')
	{
		lookahead.type = END;

#ifdef DEBUG
		printf("Got )\n");
#endif
	}
	else if (IS_SIGN_PREFIX(c) && isdigit(fpeek(input)) || isdigit(c))
	{
		ungetc(c, input);

		lookahead.type = VALUE;

		fscanf(input, "%lf", &lookahead.value.number);

#ifdef DEBUG
		printf("Got number %f\n", lookahead.value.number);
#endif	
	}
	else
	{
		unsigned pos = 1;
		int index;

		lookahead.type = FUNCTION;

		buffer[0] = c & 0xFF;
			
		memset(buffer + 1, '\0', FN_NAME_MAX);
						
		c = fgetc(input);
		while (!IS_SPECIAL(c) && pos < FN_NAME_MAX)
		{
			buffer[pos++] = c & 0xFF;
			
			c = fgetc(input);
		}
		
		if (pos == FN_NAME_MAX && !IS_SPECIAL(c))
			die("token too long");

		ungetc(c, input);
			
		index = lookupFunction(buffer);

		if (index < 0)
			die("function not found");
		else
			lookahead.value.fnIndex = index;

#ifdef DEBUG
		printf("Got function: %d:%s\n", lookahead.value.fnIndex, buffer);
#endif

	}

}
Esempio n. 9
0
void initGlobalFuncs(GlobalState& g) {
    g.llvm_opaque_type = llvm::StructType::create(g.context, "opaque");

    g.llvm_clfunction_type_ptr = lookupFunction("boxCLFunction")->arg_begin()->getType();
    g.llvm_module_type_ptr = g.stdlib_module->getTypeByName("class.pyston::BoxedModule")->getPointerTo();
    assert(g.llvm_module_type_ptr);
    g.llvm_bool_type_ptr = lookupFunction("boxBool")->getReturnType();

    g.llvm_value_type_ptr = lookupFunction("getattr")->getReturnType();
    g.llvm_value_type = g.llvm_value_type_ptr->getSequentialElementType();
    // g.llvm_class_type_ptr = llvm::cast<llvm::StructType>(g.llvm_value_type)->getElementType(0);
    // g.llvm_class_type = g.llvm_class_type_ptr->getSequentialElementType();
    g.llvm_class_type = g.stdlib_module->getTypeByName("class.pyston::BoxedClass");
    assert(g.llvm_class_type);
    g.llvm_class_type_ptr = g.llvm_class_type->getPointerTo();

    g.llvm_flavor_type = g.stdlib_module->getTypeByName("class.pyston::ObjectFlavor");
    assert(g.llvm_flavor_type);
    g.llvm_flavor_type_ptr = g.llvm_flavor_type->getPointerTo();

    g.llvm_str_type_ptr = lookupFunction("boxStringPtr")->arg_begin()->getType();

    auto vector_type = g.stdlib_module->getTypeByName("class.std::vector");
    assert(vector_type);
    g.vector_ptr = vector_type->getPointerTo();

    g.llvm_closure_type_ptr = g.stdlib_module->getTypeByName("class.pyston::BoxedClosure")->getPointerTo();
    assert(g.llvm_closure_type_ptr);

#define GET(N) g.funcs.N = getFunc((void*)N, STRINGIFY(N))

    g.funcs.printf = addFunc((void*)printf, g.i8_ptr, true);
    g.funcs.my_assert = getFunc((void*)my_assert, "my_assert");
    g.funcs.malloc = addFunc((void*)malloc, g.i8_ptr, g.i64);
    g.funcs.free = addFunc((void*)free, g.void_, g.i8_ptr);

    g.funcs.allowGLReadPreemption = addFunc((void*)threading::allowGLReadPreemption, g.void_);

    GET(boxCLFunction);
    GET(unboxCLFunction);
    GET(createUserClass);
    GET(boxInt);
    GET(unboxInt);
    GET(boxFloat);
    GET(unboxFloat);
    GET(boxStringPtr);
    GET(boxInstanceMethod);
    GET(boxBool);
    GET(unboxBool);
    GET(createTuple);
    GET(createList);
    GET(createDict);
    GET(createSlice);
    GET(createClosure);

    GET(getattr);
    GET(setattr);
    GET(getitem);
    GET(setitem);
    GET(delitem);
    GET(getGlobal);
    GET(binop);
    GET(compare);
    GET(augbinop);
    GET(nonzero);
    GET(print);
    GET(unboxedLen);
    GET(getclsattr);
    GET(unaryop);
    GET(import);
    GET(repr);
    GET(isinstance);

    GET(checkUnpackingLength);
    GET(raiseAttributeError);
    GET(raiseAttributeErrorStr);
    GET(raiseNotIterableError);
    GET(assertNameDefined);
    GET(assertFail);

    GET(printFloat);
    GET(listAppendInternal);

    g.funcs.runtimeCall = getFunc((void*)runtimeCall, "runtimeCall");
    g.funcs.runtimeCall0 = addFunc((void*)runtimeCall, g.llvm_value_type_ptr, g.llvm_value_type_ptr, g.i32);
    g.funcs.runtimeCall1
        = addFunc((void*)runtimeCall, g.llvm_value_type_ptr, g.llvm_value_type_ptr, g.i32, g.llvm_value_type_ptr);
    g.funcs.runtimeCall2 = addFunc((void*)runtimeCall, g.llvm_value_type_ptr, g.llvm_value_type_ptr, g.i32,
                                   g.llvm_value_type_ptr, g.llvm_value_type_ptr);
    g.funcs.runtimeCall3 = addFunc((void*)runtimeCall, g.llvm_value_type_ptr, g.llvm_value_type_ptr, g.i32,
                                   g.llvm_value_type_ptr, g.llvm_value_type_ptr, g.llvm_value_type_ptr);

    g.funcs.callattr = getFunc((void*)callattr, "callattr");
    g.funcs.callattr0
        = addFunc((void*)callattr, g.llvm_value_type_ptr, g.llvm_value_type_ptr, g.llvm_str_type_ptr, g.i1, g.i32);
    g.funcs.callattr1 = addFunc((void*)callattr, g.llvm_value_type_ptr, g.llvm_value_type_ptr, g.llvm_str_type_ptr,
                                g.i1, g.i32, g.llvm_value_type_ptr);
    g.funcs.callattr2 = addFunc((void*)callattr, g.llvm_value_type_ptr, g.llvm_value_type_ptr, g.llvm_str_type_ptr,
                                g.i1, g.i32, g.llvm_value_type_ptr, g.llvm_value_type_ptr);
    g.funcs.callattr3 = addFunc((void*)callattr, g.llvm_value_type_ptr, g.llvm_value_type_ptr, g.llvm_str_type_ptr,
                                g.i1, g.i32, g.llvm_value_type_ptr, g.llvm_value_type_ptr, g.llvm_value_type_ptr);

    g.funcs.reoptCompiledFunc = addFunc((void*)reoptCompiledFunc, g.i8_ptr, g.i8_ptr);
    g.funcs.compilePartialFunc = addFunc((void*)compilePartialFunc, g.i8_ptr, g.i8_ptr);

    GET(__cxa_begin_catch);
    g.funcs.__cxa_end_catch = addFunc((void*)__cxa_end_catch, g.void_);
    g.funcs.__cxa_allocate_exception = addFunc((void*)__cxa_allocate_exception, g.i8_ptr, g.i64);
    g.funcs.__cxa_throw = addFunc((void*)__cxa_throw, g.void_, g.i8_ptr, g.i8_ptr, g.i8_ptr);

    g.funcs.div_i64_i64 = getFunc((void*)div_i64_i64, "div_i64_i64");
    g.funcs.mod_i64_i64 = getFunc((void*)mod_i64_i64, "mod_i64_i64");
    g.funcs.pow_i64_i64 = getFunc((void*)pow_i64_i64, "pow_i64_i64");

    GET(div_float_float);
    GET(mod_float_float);
    GET(pow_float_float);
}