Supporting async functions

This is only an early version. 
My hand-written tests as well as some PDCurses demos are working, but there are still some not working.

This PR is mainly for code review, because I think that the approach has been determined.

A library is necessary to support manipulating async stack frames. asm.js is not supported yet, but it won't be difficult, as there are only number operations (no references to functions)

kripken/emscripten#2482

Function pointers are not supported yet.


On Tue, Jul 8, 2014 at 4:36 PM, Lu Wang <notifications@github.com> wrote:

> In lib/Transforms/NaCl/LowerEmAsyncFunctions.cpp:
>
> > +   * TODO: support all the functions with a special flag, e.g. __async
> > +   */
> > +  Function *SleepFunction = TheModule->getFunction("
> emscripten_sleep");
> > +  if (!SleepFunction) return false;
> > +
> > +  // Walk through the call graph and find all the async functions
> > +  FunctionCallInstsMap AsyncFunctionCalls;
> > +  {
> > +    std::vector<Function*> AsyncFunctionsPending;
> > +    AsyncFunctionsPending.push_back(SleepFunction);
> > +    while(!AsyncFunctionsPending.empty()) {
> > +      Function *CurFunction = AsyncFunctionsPending.back();
> > +      AsyncFunctionsPending.pop_back();
> > +
> > +      for(Value::use_iterator UI = CurFunction->use_begin(), E = CurFunction->use_end(); UI != E; ++UI) {
> > +        if(CallInst *CI = dyn_cast<CallInst>(*UI)) {
>
> Currently function pointers are not handles, and we will check that based
> on the types.
>
> E.g.
>
> void *func(void);
> ...
> (*func)(); // ⭐️
>
> ⭐️ is only considered async iff there's any async function of the type void
> (*)(void).
> I'm still implementing this feature.
>
> Otherwise I think it's irrelevant, e.g.std::cout << func. Does it make
> sens?
>
I was mainly thinking about code like this:

  p = func;
  ...
  p();

I don't think you need to handle this if you don't want to, I just want to
make sure you've considered it, and it wasn't obvious what the plan was
from scanning through the code.