Source code

Revision control

Other Tools

1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2
* vim: set ts=8 sts=2 et sw=2 tw=80:
3
*
4
* Copyright 2014 Mozilla Foundation
5
*
6
* Licensed under the Apache License, Version 2.0 (the "License");
7
* you may not use this file except in compliance with the License.
8
* You may obtain a copy of the License at
9
*
11
*
12
* Unless required by applicable law or agreed to in writing, software
13
* distributed under the License is distributed on an "AS IS" BASIS,
14
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
* See the License for the specific language governing permissions and
16
* limitations under the License.
17
*/
18
19
#ifndef wasm_AsmJS_h
20
#define wasm_AsmJS_h
21
22
#include "mozilla/Attributes.h" // MOZ_MUST_USE
23
#include "mozilla/Utf8.h" // mozilla::Utf8Unit
24
25
#include <stdint.h> // uint32_t
26
27
#include "jstypes.h" // JS_PUBLIC_API
28
#include "js/CallArgs.h" // JSNative
29
30
struct JS_PUBLIC_API JSContext;
31
class JS_PUBLIC_API JSFunction;
32
33
namespace JS {
34
35
class JS_PUBLIC_API Value;
36
37
template <typename T>
38
class Handle;
39
40
} // namespace JS
41
42
namespace js {
43
44
namespace frontend {
45
46
class ParseContext;
47
class ParseNode;
48
49
template <class ParseHandler, typename CharT>
50
class Parser;
51
class FullParseHandler;
52
53
} // namespace frontend
54
55
template <typename Unit>
56
using AsmJSParser = frontend::Parser<frontend::FullParseHandler, Unit>;
57
58
// This function takes over parsing of a function starting with "use asm". The
59
// return value indicates whether an error was reported which the caller should
60
// propagate. If no error was reported, the function may still fail to validate
61
// as asm.js. In this case, the parser.tokenStream has been advanced an
62
// indeterminate amount and the entire function should be reparsed from the
63
// beginning.
64
65
extern MOZ_MUST_USE bool CompileAsmJS(JSContext* cx,
66
AsmJSParser<mozilla::Utf8Unit>& parser,
67
frontend::ParseNode* stmtList,
68
bool* validated);
69
70
extern MOZ_MUST_USE bool CompileAsmJS(JSContext* cx,
71
AsmJSParser<char16_t>& parser,
72
frontend::ParseNode* stmtList,
73
bool* validated);
74
75
// asm.js module/export queries:
76
77
extern bool IsAsmJSModuleNative(JSNative native);
78
79
extern bool IsAsmJSModule(JSFunction* fun);
80
81
extern bool IsAsmJSFunction(JSFunction* fun);
82
83
extern bool IsAsmJSStrictModeModuleOrFunction(JSFunction* fun);
84
85
extern bool InstantiateAsmJS(JSContext* cx, unsigned argc, JS::Value* vp);
86
87
// asm.js testing natives:
88
89
extern bool IsAsmJSCompilationAvailable(JSContext* cx, unsigned argc,
90
JS::Value* vp);
91
92
extern bool IsAsmJSModule(JSContext* cx, unsigned argc, JS::Value* vp);
93
94
extern bool IsAsmJSFunction(JSContext* cx, unsigned argc, JS::Value* vp);
95
96
// asm.js toString/toSource support:
97
98
extern JSString* AsmJSFunctionToString(JSContext* cx,
99
JS::Handle<JSFunction*> fun);
100
101
extern JSString* AsmJSModuleToString(JSContext* cx, JS::Handle<JSFunction*> fun,
102
bool isToSource);
103
104
// asm.js heap:
105
106
extern bool IsValidAsmJSHeapLength(uint32_t length);
107
108
} // namespace js
109
110
#endif // wasm_AsmJS_h