aboutsummaryrefslogtreecommitdiff
path: root/src/postamble.js
blob: c8fd44bdd1146a18c3b5c34064633db44bf9a239 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// === Auto-generated postamble setup entry stuff ===

Module.callMain = function callMain(args) {
  var argc = args.length+1;
  function pad() {
    for (var i = 0; i < QUANTUM_SIZE-1; i++) {
      argv.push(0);
    }
  }
  var argv = [allocate(intArrayFromString("/bin/this.program"), 'i8', ALLOC_STATIC) ];
  pad();
  for (var i = 0; i < argc-1; i = i + 1) {
    argv.push(allocate(intArrayFromString(args[i]), 'i8', ALLOC_STATIC));
    pad();
  }
  argv.push(0);
  argv = allocate(argv, 'i32', ALLOC_STATIC);

  return _main(argc, argv, 0);
}

{{GLOBAL_VARS}}

function run(args) {
  args = args || Module['arguments'];

  __globalConstructor__();

  var ret = null;
  if (Module['_main']) {
    ret = Module.callMain(args);
    __shutdownRuntime__();
  }
  return ret;
}
Module['run'] = run;

// {{PRE_RUN_ADDITIONS}}

// In a hackish way, we disable permissions until now, so setup code works, but enable them for runtime so compile code works with permissions
try {
  FS.ignorePermissions = false;
} catch(e){}

#if INVOKE_RUN
#else
Module['noInitialRun'] = true;
#endif

if (!Module['noInitialRun']) {
  run();
}

// {{POST_RUN_ADDITIONS}}