Skip to content

Commit 923c646

Browse files
authored
Add exception handling feature (#2083)
This only adds the feature and its flag and not the instructions yet.
1 parent 415e8b3 commit 923c646

5 files changed

Lines changed: 19 additions & 2 deletions

File tree

src/tools/tool-options.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ struct ToolOptions : public Options {
6868
.addFeature(FeatureSet::TruncSat, "nontrapping float-to-int operations")
6969
.addFeature(FeatureSet::SIMD, "SIMD operations and types")
7070
.addFeature(FeatureSet::BulkMemory, "bulk memory operations")
71+
.addFeature(FeatureSet::ExceptionHandling,
72+
"exception handling operations")
7173
.add("--no-validation",
7274
"-n",
7375
"Disables validation, assumes inputs are correct",

src/wasm-binary.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ extern const char* ExceptionHandlingFeature;
399399
extern const char* TruncSatFeature;
400400
extern const char* SignExtFeature;
401401
extern const char* SIMD128Feature;
402+
extern const char* ExceptionHandlingFeature;
402403

403404
enum Subsection {
404405
NameFunction = 1,

src/wasm-features.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ struct FeatureSet {
3131
SIMD = 1 << 3,
3232
BulkMemory = 1 << 4,
3333
SignExt = 1 << 5,
34-
All = Atomics | MutableGlobals | TruncSat | SIMD | BulkMemory | SignExt
34+
ExceptionHandling = 1 << 6,
35+
All = Atomics | MutableGlobals | TruncSat | SIMD | BulkMemory | SignExt |
36+
ExceptionHandling
3537
};
3638

3739
static std::string toString(Feature f) {
@@ -48,6 +50,8 @@ struct FeatureSet {
4850
return "bulk-memory";
4951
case SignExt:
5052
return "sign-ext";
53+
case ExceptionHandling:
54+
return "exception-handling";
5155
default:
5256
WASM_UNREACHABLE();
5357
}
@@ -64,6 +68,7 @@ struct FeatureSet {
6468
bool hasSIMD() const { return features & SIMD; }
6569
bool hasBulkMemory() const { return features & BulkMemory; }
6670
bool hasSignExt() const { return features & SignExt; }
71+
bool hasExceptionHandling() const { return features & ExceptionHandling; }
6772
bool hasAll() const { return features & All; }
6873

6974
void makeMVP() { features = MVP; }
@@ -76,6 +81,7 @@ struct FeatureSet {
7681
void setSIMD(bool v = true) { set(SIMD, v); }
7782
void setBulkMemory(bool v = true) { set(BulkMemory, v); }
7883
void setSignExt(bool v = true) { set(SignExt, v); }
84+
void setExceptionHandling(bool v = true) { set(ExceptionHandling, v); }
7985
void setAll(bool v = true) { features = v ? All : MVP; }
8086

8187
void enable(const FeatureSet& other) { features |= other.features; }
@@ -90,6 +96,9 @@ struct FeatureSet {
9096
if (hasBulkMemory()) {
9197
f(BulkMemory);
9298
}
99+
if (hasExceptionHandling()) {
100+
f(ExceptionHandling);
101+
}
93102
if (hasMutableGlobals()) {
94103
f(MutableGlobals);
95104
}

src/wasm/wasm-binary.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,8 @@ void WasmBinaryWriter::writeFeaturesSection() {
647647
return "bulk-memory";
648648
case FeatureSet::SignExt:
649649
return "sign-ext";
650+
case FeatureSet::ExceptionHandling:
651+
return "exception-handling";
650652
default:
651653
WASM_UNREACHABLE();
652654
}
@@ -2079,7 +2081,7 @@ void WasmBinaryBuilder::readFeatures(size_t payloadLen) {
20792081
} else if (name == BinaryConsts::UserSections::BulkMemoryFeature) {
20802082
wasm.features.setBulkMemory();
20812083
} else if (name == BinaryConsts::UserSections::ExceptionHandlingFeature) {
2082-
WASM_UNREACHABLE(); // TODO: exception handling
2084+
wasm.features.setExceptionHandling();
20832085
} else if (name == BinaryConsts::UserSections::TruncSatFeature) {
20842086
wasm.features.setTruncSat();
20852087
} else if (name == BinaryConsts::UserSections::SignExtFeature) {

test/unit/test_features.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ def check_sign_ext(self, module, error):
2424
def check_bulk_mem(self, module, error):
2525
self.check_feature(module, error, '--enable-bulk-memory')
2626

27+
def check_exception_handling(self, module, error):
28+
self.check_feature(module, error, '--enable-exception-handling')
29+
2730
def test_v128_signature(self):
2831
module = '''
2932
(module

0 commit comments

Comments
 (0)