-
-
Notifications
You must be signed in to change notification settings - Fork 264
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wasm gc: support writing debug info, support it in disassembler
- Loading branch information
1 parent
7aec076
commit c2eb11e
Showing
9 changed files
with
368 additions
and
10 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
core/src/main/java/org/teavm/backend/wasm/WasmDebugInfoLevel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright 2024 Alexey Andreev. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.teavm.backend.wasm; | ||
|
||
public enum WasmDebugInfoLevel { | ||
NONE, | ||
DEOBFUSCATION, | ||
FULL | ||
} |
21 changes: 21 additions & 0 deletions
21
core/src/main/java/org/teavm/backend/wasm/WasmDebugInfoLocation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Copyright 2024 Alexey Andreev. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.teavm.backend.wasm; | ||
|
||
public enum WasmDebugInfoLocation { | ||
EMBEDDED, | ||
EXTERNAL | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
core/src/main/java/org/teavm/backend/wasm/debug/ExternalDebugFile.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright 2024 Alexey Andreev. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.teavm.backend.wasm.debug; | ||
|
||
import java.util.List; | ||
import org.teavm.backend.wasm.model.WasmCustomSection; | ||
import org.teavm.backend.wasm.render.WasmBinaryWriter; | ||
|
||
public final class ExternalDebugFile { | ||
private ExternalDebugFile() { | ||
} | ||
|
||
public static byte[] write(List<WasmCustomSection> sections) { | ||
if (sections.isEmpty()) { | ||
return null; | ||
} | ||
var writer = new WasmBinaryWriter(); | ||
writer.writeInt32(0x67626474); | ||
writer.writeInt32(1); | ||
for (var section : sections) { | ||
var data = section.getData(); | ||
writer.writeAsciiString(section.getName()); | ||
writer.writeLEB(data.length); | ||
writer.writeBytes(data); | ||
} | ||
return writer.getData(); | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
core/src/main/java/org/teavm/backend/wasm/debug/GCDebugInfoBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* Copyright 2024 Alexey Andreev. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.teavm.backend.wasm.debug; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import org.teavm.backend.wasm.model.WasmCustomSection; | ||
|
||
public class GCDebugInfoBuilder { | ||
private DebugStringsBuilder strings; | ||
private DebugFilesBuilder files; | ||
private DebugPackagesBuilder packages; | ||
private DebugClassesBuilder classes; | ||
private DebugMethodsBuilder methods; | ||
private DebugLinesBuilder lines; | ||
|
||
public GCDebugInfoBuilder() { | ||
strings = new DebugStringsBuilder(); | ||
files = new DebugFilesBuilder(strings); | ||
packages = new DebugPackagesBuilder(strings); | ||
classes = new DebugClassesBuilder(packages, strings); | ||
methods = new DebugMethodsBuilder(classes, strings); | ||
lines = new DebugLinesBuilder(files, methods); | ||
} | ||
|
||
public DebugStrings strings() { | ||
return strings; | ||
} | ||
|
||
public DebugFiles files() { | ||
return files; | ||
} | ||
|
||
public DebugPackages packages() { | ||
return packages; | ||
} | ||
|
||
public DebugClasses classes() { | ||
return classes; | ||
} | ||
|
||
public DebugMethods methods() { | ||
return methods; | ||
} | ||
|
||
public DebugLines lines() { | ||
return lines; | ||
} | ||
|
||
public List<WasmCustomSection> build() { | ||
var result = new ArrayList<WasmCustomSection>(); | ||
addSection(result, strings); | ||
addSection(result, files); | ||
addSection(result, packages); | ||
addSection(result, classes); | ||
addSection(result, methods); | ||
addSection(result, lines); | ||
return result; | ||
} | ||
|
||
private void addSection(List<WasmCustomSection> sections, DebugSectionBuilder builder) { | ||
if (builder.isEmpty()) { | ||
return; | ||
} | ||
sections.add(new WasmCustomSection(builder.name(), builder.build())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.