MCPcopy Create free account
hub / github.com/agraef/pure-lang / LoadBitcode

Method LoadBitcode

pure/interpreter.cc:2374–2527  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2372}
2373
2374bool interpreter::LoadBitcode(bool priv, const char *name, string *msg)
2375{
2376 using namespace llvm;
2377 string modname = strip_modname(name);
2378 bool loaded = loaded_bcs.find(modname) != loaded_bcs.end();
2379 bool declared = loaded &&
2380 loaded_bcs[modname].declared(*symtab.current_namespace);
2381 if (loaded) {
2382 // Module already loaded. Do some consistency checks.
2383 if (declared &&
2384 loaded_bcs[modname].priv[*symtab.current_namespace] != priv) {
2385 string scope = (!priv)?"private":"public";
2386 if (msg)
2387 *msg = "Module was previously '" + scope + "' in this namespace";
2388 bc_errmsg(name, msg);
2389 return false;
2390 }
2391 // Check whether there's anything to do.
2392 if (declared) return true;
2393 }
2394 MemoryBuffer *buf = get_membuf(name, msg);
2395 if (!buf) {
2396 bc_errmsg(name, msg);
2397 return false;
2398 }
2399 Module *M = ParseBitcodeFile(buf,
2400#ifdef LLVM26
2401 getGlobalContext(),
2402#endif
2403 msg);
2404 delete buf;
2405 if (!M) {
2406 bc_errmsg(name, msg);
2407 return false;
2408 }
2409 // Check the target layout and triple of the module against our target and
2410 // give diagnostics in case of a mismatch. NOTE: Currently we ignore
2411 // mismatches in the target triple and just assume that bitcode files are ok
2412 // if the data layouts match. Not sure whether this assumption is always
2413 // valid.
2414 string layout = JIT->getTargetData()->getStringRepresentation(),
2415 triple = HOST;
2416 // We only give diagnostics on first load, to prevent a cascade of error
2417 // messages.
2418#if 0
2419 if (!loaded && !M->getTargetTriple().empty() &&
2420 M->getTargetTriple() != triple) {
2421 if (msg)
2422 *msg = "Mismatch in target architecture '"+M->getTargetTriple()+"'";
2423 bc_errmsg(name, msg);
2424 return false;
2425 }
2426#endif
2427 if (!loaded && !M->getDataLayout().empty() && M->getDataLayout() != layout) {
2428 // Clang 2.9 has some minor mismatches with the JIT data layout (bug?),
2429 // which are irrelevant for our purposes, so for the time being we just
2430 // check endianness and pointer sizes here.
2431 const TargetData &jit_dl = *JIT->getTargetData(), mod_dl = TargetData(M);

Callers

nothing calls this directly

Calls 12

strip_modnameFunction · 0.85
bc_errmsgFunction · 0.85
get_membufFunction · 0.85
ParseBitcodeFileFunction · 0.85
strip_filenameFunction · 0.85
declaredMethod · 0.80
findMethod · 0.45
endMethod · 0.45
runMethod · 0.45
symMethod · 0.45
dumpMethod · 0.45
declareMethod · 0.45

Tested by

no test coverage detected