Skip to content

Commit 8cfd6bc

Browse files
committed
feat: wasi compilation
1 parent 87e8ae3 commit 8cfd6bc

File tree

10 files changed

+64
-10
lines changed

10 files changed

+64
-10
lines changed

antlr/antlr4-cpp-runtime-4.7.2-source/runtime/src/Parser.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,9 @@ const atn::ATN& Parser::getATNWithBypassAlts() {
218218
if (serializedAtn.empty()) {
219219
throw UnsupportedOperationException("The current parser does not support an ATN with bypass alternatives.");
220220
}
221-
221+
#if !defined(__wasi__)
222222
std::lock_guard<std::mutex> lck(_mutex);
223-
223+
#endif
224224
// XXX: using the entire serialized ATN as key into the map is a big resource waste.
225225
// How large can that thing become?
226226
if (bypassAltsAtnCache.find(serializedAtn) == bypassAltsAtnCache.end())
@@ -553,8 +553,9 @@ std::vector<std::string> Parser::getRuleInvocationStack(RuleContext *p) {
553553
std::vector<std::string> Parser::getDFAStrings() {
554554
atn::ParserATNSimulator *simulator = getInterpreter<atn::ParserATNSimulator>();
555555
if (!simulator->decisionToDFA.empty()) {
556+
#if !defined(__wasi__)
556557
std::lock_guard<std::mutex> lck(_mutex);
557-
558+
#endif
558559
std::vector<std::string> s;
559560
for (size_t d = 0; d < simulator->decisionToDFA.size(); d++) {
560561
dfa::DFA &dfa = simulator->decisionToDFA[d];
@@ -568,7 +569,9 @@ std::vector<std::string> Parser::getDFAStrings() {
568569
void Parser::dumpDFA() {
569570
atn::ParserATNSimulator *simulator = getInterpreter<atn::ParserATNSimulator>();
570571
if (!simulator->decisionToDFA.empty()) {
572+
#if !defined(__wasi__)
571573
std::lock_guard<std::mutex> lck(_mutex);
574+
#endif
572575
bool seenOne = false;
573576
for (size_t d = 0; d < simulator->decisionToDFA.size(); d++) {
574577
dfa::DFA &dfa = simulator->decisionToDFA[d];
@@ -645,4 +648,3 @@ void Parser::InitializeInstanceFields() {
645648
_tracer = nullptr;
646649
_ctx = nullptr;
647650
}
648-

antlr/antlr4-cpp-runtime-4.7.2-source/runtime/src/Recognizer.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ dfa::Vocabulary const& Recognizer::getVocabulary() const {
3838
std::map<std::string, size_t> Recognizer::getTokenTypeMap() {
3939
const dfa::Vocabulary& vocabulary = getVocabulary();
4040

41+
#if !defined(__wasi__)
4142
std::lock_guard<std::mutex> lck(_mutex);
43+
#endif
4244
std::map<std::string, size_t> result;
4345
auto iterator = _tokenTypeMapCache.find(&vocabulary);
4446
if (iterator != _tokenTypeMapCache.end()) {
@@ -68,7 +70,9 @@ std::map<std::string, size_t> Recognizer::getRuleIndexMap() {
6870
throw "The current recognizer does not provide a list of rule names.";
6971
}
7072

73+
#if !defined(__wasi__)
7174
std::lock_guard<std::mutex> lck(_mutex);
75+
#endif
7276
std::map<std::string, size_t> result;
7377
auto iterator = _ruleIndexMapCache.find(ruleNames);
7478
if (iterator != _ruleIndexMapCache.end()) {
@@ -164,4 +168,3 @@ void Recognizer::InitializeInstanceFields() {
164168
_stateNumber = ATNState::INVALID_STATE_NUMBER;
165169
_interpreter = nullptr;
166170
}
167-

antlr/antlr4-cpp-runtime-4.7.2-source/runtime/src/Recognizer.h

+2
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,9 @@ namespace antlr4 {
147147
atn::ATNSimulator *_interpreter; // Set and deleted in descendants (or the profiler).
148148

149149
// Mutex to manage synchronized access for multithreading.
150+
#if !defined(__wasi__)
150151
std::mutex _mutex;
152+
#endif
151153

152154
private:
153155
static std::map<const dfa::Vocabulary*, std::map<std::string, size_t>> _tokenTypeMapCache;

antlr/antlr4-cpp-runtime-4.7.2-source/runtime/src/atn/ATN.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ misc::IntervalSet ATN::nextTokens(ATNState *s, RuleContext *ctx) const {
8989

9090
misc::IntervalSet const& ATN::nextTokens(ATNState *s) const {
9191
if (!s->_nextTokenUpdated) {
92+
#if !defined(__wasi__)
9293
std::unique_lock<std::mutex> lock { _mutex };
94+
#endif
9395
if (!s->_nextTokenUpdated) {
9496
s->_nextTokenWithinRule = nextTokens(s, nullptr);
9597
s->_nextTokenUpdated = true;
@@ -206,4 +208,3 @@ std::string ATN::toString() const {
206208

207209
return ss.str();
208210
}
209-

antlr/antlr4-cpp-runtime-4.7.2-source/runtime/src/atn/ATN.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ namespace atn {
105105
std::string toString() const;
106106

107107
private:
108-
mutable std::mutex _mutex;
108+
#if !defined(__wasi__)
109+
mutable std::mutex _mutex;
110+
#endif
109111
};
110112

111113
} // namespace atn

antlr/antlr4-cpp-runtime-4.7.2-source/runtime/src/support/CPPUtils.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -211,30 +211,37 @@ namespace antlrcpp {
211211
//----------------- SingleWriteMultipleRead --------------------------------------------------------------------------
212212

213213
void SingleWriteMultipleReadLock::readLock() {
214+
#if !defined(__wasi__)
214215
std::unique_lock<std::mutex> lock(_mutex);
215216
while (_waitingWriters != 0)
216217
_readerGate.wait(lock);
217218
++_activeReaders;
218219
lock.unlock();
220+
#endif
219221
}
220222

221223
void SingleWriteMultipleReadLock::readUnlock() {
224+
#if !defined(__wasi__)
222225
std::unique_lock<std::mutex> lock(_mutex);
223226
--_activeReaders;
224227
lock.unlock();
225228
_writerGate.notify_one();
229+
#endif
226230
}
227231

228232
void SingleWriteMultipleReadLock::writeLock() {
233+
#if !defined(__wasi__)
229234
std::unique_lock<std::mutex> lock(_mutex);
230235
++_waitingWriters;
231236
while (_activeReaders != 0 || _activeWriters != 0)
232237
_writerGate.wait(lock);
233238
++_activeWriters;
234239
lock.unlock();
240+
#endif
235241
}
236242

237243
void SingleWriteMultipleReadLock::writeUnlock() {
244+
#if !defined(__wasi__)
238245
std::unique_lock<std::mutex> lock(_mutex);
239246
--_waitingWriters;
240247
--_activeWriters;
@@ -243,6 +250,7 @@ namespace antlrcpp {
243250
else
244251
_readerGate.notify_all();
245252
lock.unlock();
253+
#endif
246254
}
247255

248256
} // namespace antlrcpp

antlr/antlr4-cpp-runtime-4.7.2-source/runtime/src/support/CPPUtils.h

+2
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,12 @@ namespace antlrcpp {
6666
void writeUnlock();
6767

6868
private:
69+
#if !defined(__wasi__)
6970
std::condition_variable _readerGate;
7071
std::condition_variable _writerGate;
7172

7273
std::mutex _mutex;
74+
#endif
7375
size_t _activeReaders = 0;
7476
size_t _waitingWriters = 0;
7577
size_t _activeWriters = 0;

src/libs/lua/src/ldo.c

+12-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
#include "lprefix.h"
1111

1212

13+
#if !defined(__wasi__)
1314
#include <setjmp.h>
15+
#endif
1416
#include <stdlib.h>
1517
#include <string.h>
1618

@@ -52,7 +54,15 @@
5254
*/
5355
#if !defined(LUAI_THROW) /* { */
5456

55-
#if defined(__cplusplus) && !defined(LUA_USE_LONGJMP) /* { */
57+
#if defined(__wasi__) /* { */
58+
59+
#define LUAI_THROW(L,c) { abort(); }
60+
#define LUAI_TRY(L,c,a) { a }
61+
#define luai_jmpbuf int /* dummy variable */
62+
63+
#else /* }{ */
64+
65+
#if (defined(__cplusplus) && !defined(LUA_USE_LONGJMP)) /* { */
5666

5767
/* C++ exceptions */
5868
#define LUAI_THROW(L,c) throw(c)
@@ -78,6 +88,7 @@
7888

7989
#endif /* } */
8090

91+
#endif /* } */
8192

8293

8394
/* chain list of long jump buffers */

src/libs/lua/src/loslib.c

+9-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include "lauxlib.h"
2222
#include "lualib.h"
2323

24-
2524
/*
2625
** {==================================================================
2726
** List of valid conversion specifiers for the 'strftime' function;
@@ -126,12 +125,21 @@ static time_t l_checktime (lua_State *L, int arg) {
126125

127126
#else /* }{ */
128127

128+
#if defined(__wasi__) /* { */
129+
130+
#define LUA_TMPNAMBUFSIZE 32
131+
#define lua_tmpnam(b,e) e = 1;
132+
133+
#else /* }{ */
134+
129135
/* ISO C definitions */
130136
#define LUA_TMPNAMBUFSIZE L_tmpnam
131137
#define lua_tmpnam(b,e) { e = (tmpnam(b) == NULL); }
132138

133139
#endif /* } */
134140

141+
#endif /* } */
142+
135143
#endif /* } */
136144
/* }================================================================== */
137145

src/silice.cpp

+16-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ int main(int argc, char **argv)
5555
{
5656
try {
5757

58-
const std::string version_string = std::string(" 1.0.10") + " " + c_GitHash;
58+
const std::string version_string = std::string(" 1.0.11") + " " + c_GitHash;
5959
// ^ ^ ^
6060
// | | |
6161
// | | \_ increments with features in wip/draft (x.x.x)
@@ -100,6 +100,7 @@ int main(int argc, char **argv)
100100
g_SplitInouts = splitInouts.getValue();
101101

102102
SiliceCompiler compiler;
103+
103104
compiler.run(
104105
source.getValue(),
105106
output.getValue(),
@@ -125,3 +126,17 @@ int main(int argc, char **argv)
125126
}
126127

127128
// -------------------------------------------------
129+
130+
#if defined(__wasi__)
131+
132+
// well ...
133+
extern "C" {
134+
void * __cxa_allocate_exception(size_t /*thrown_size*/) { abort(); }
135+
void __cxa_throw(void */*thrown_object*/, std::type_info */*tinfo*/, void (*/*dest*/)(void *)) { abort(); }
136+
int system( const char* ) {}
137+
clock_t clock() { return 0; }
138+
FILE *tmpfile() { return NULL; }
139+
int __cxa_thread_atexit(void*, void*, void*) {}
140+
}
141+
142+
#endif

0 commit comments

Comments
 (0)