All files / src/emitter index.js

100% Statements 8/8
100% Branches 2/2
100% Functions 1/1
100% Lines 8/8
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  21x 21x 21x         75x     75x                           75x 42x     33x        
// @flow
import preamble from './preamble';
import section from './section';
import OutputStream from '../utils/output-stream';
import type { ProgramType } from '../generator/flow/types';
import type { BaseOptions } from '../flow/types';
 
function emit(program: ProgramType, config: BaseOptions) {
  const stream = new OutputStream();
 
  // Write MAGIC and VERSION. This is now a valid WASM Module
  const result = stream
    .write(preamble(program.Version))
    .write(section.type(program))
    .write(section.imports(program))
    .write(section.function(program))
    .write(section.table(program))
    .write(section.memory(program))
    .write(section.globals(program))
    .write(section.exports(program))
    .write(section.start(program))
    .write(section.element(program))
    .write(section.code(program))
    .write(section.data(program));
 
  if (config.encodeNames) {
    return result.write(section.name(program));
  }
 
  return result;
}
 
export default emit;