Skip to content

Commit

Permalink
[WASM] Emit globals with a consistent format in preparation to abstra…
Browse files Browse the repository at this point in the history
…cting the code for emitting globals.

PiperOrigin-RevId: 582856281
  • Loading branch information
rluble authored and copybara-github committed Nov 16, 2023
1 parent 73b8082 commit 99d02e2
Show file tree
Hide file tree
Showing 167 changed files with 10,599 additions and 4,532 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -437,16 +437,23 @@ private void emitStaticFieldGlobals(Type type) {

if (field.isCompileTimeConstant()) {
builder.append(
format(" %s ", environment.getWasmType(field.getDescriptor().getTypeDescriptor())));
format(" %s", environment.getWasmType(field.getDescriptor().getTypeDescriptor())));
builder.indent();
builder.newLine();
ExpressionTranspiler.render(field.getInitializer(), builder, environment);
builder.unindent();
} else {
builder.append(
format(
" (mut %s) ", environment.getWasmType(field.getDescriptor().getTypeDescriptor())));
" (mut %s)", environment.getWasmType(field.getDescriptor().getTypeDescriptor())));
builder.indent();
builder.newLine();
ExpressionTranspiler.render(
field.getDescriptor().getTypeDescriptor().getDefaultValue(), builder, environment);
builder.unindent();
}

builder.newLine();
builder.append(")");
}
emitEndCodeComment(type, "static fields");
Expand Down Expand Up @@ -668,7 +675,13 @@ private void emitDispatchTablesInitialization(Library library) {

// Emit an empty itable that will be used for types that don't implement any interface.
builder.newLine();
builder.append("(global $itable.empty (ref $itable) (struct.new_default $itable))");
builder.append("(global $itable.empty (ref $itable)");
builder.indent();
builder.newLine();
builder.append("(struct.new_default $itable)");
builder.unindent();
builder.newLine();
builder.append(")");

// Populate all vtables.
library
Expand Down Expand Up @@ -725,25 +738,28 @@ private void emitItableInitialization(TypeDeclaration typeDeclaration) {
.filter(Objects::nonNull)
.forEach(
i -> {
builder.newLine();
builder.append(
format(
"(global %s (ref %s) ",
"(global %s (ref %s)",
environment.getWasmInterfaceVtableGlobalName(i, typeDeclaration),
environment.getWasmVtableTypeName(i)));
builder.indent();
initializeInterfaceVtable(wasmTypeLayout, i);
builder.newLine();
builder.unindent();
builder.newLine();
builder.append(")");
});
builder.newLine();
builder.append(
format(
"(global %s (ref %s) (struct.new %s",
"(global %s (ref %s)",
environment.getWasmItableGlobalName(typeDeclaration),
environment.getWasmItableTypeName(typeDeclaration),
environment.getWasmItableTypeName(typeDeclaration)));
builder.indent();
builder.newLine();
builder.append(format("(struct.new %s", environment.getWasmItableTypeName(typeDeclaration)));
builder.indent();
stream(itableSlots)
.forEach(
i -> {
Expand All @@ -757,9 +773,12 @@ private void emitItableInitialization(TypeDeclaration typeDeclaration) {
" (global.get %s)",
environment.getWasmInterfaceVtableGlobalName(i, typeDeclaration)));
});
builder.unindent();
builder.newLine();
builder.append("))");
builder.append(")");
builder.unindent();
builder.newLine();
builder.append(")");
emitEndCodeComment(typeDeclaration, "itable.init");
}

Expand Down Expand Up @@ -922,10 +941,14 @@ private void emitEmptyArraySingleton(ArrayTypeDescriptor arrayTypeDescriptor) {
builder.newLine();
builder.append(
format(
"(global %s (ref %s) (array.new_default %s (i32.const 0)))",
environment.getWasmEmptyArrayGlobalName(arrayTypeDescriptor),
wasmArrayTypeName,
wasmArrayTypeName));
"(global %s (ref %s)",
environment.getWasmEmptyArrayGlobalName(arrayTypeDescriptor), wasmArrayTypeName));
builder.indent();
builder.newLine();
builder.append(format("(array.new_default %s (i32.const 0))", wasmArrayTypeName));
builder.unindent();
builder.newLine();
builder.append(")");
builder.newLine();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,24 +87,48 @@
)

;;; Code for abstractinnerclass.InnerClasses [static fields]
(global $f_$initialized__abstractinnerclass_InnerClasses (mut i32) (i32.const 0))
(global $f_$class__abstractinnerclass_InnerClasses (mut (ref null $java.lang.Class)) (ref.null $java.lang.Class))
(global $f_$string_|abstractinne...|__abstractinnerclass_InnerClasses (mut (ref null $java.lang.String)) (ref.null $java.lang.String))
(global $f_$initialized__abstractinnerclass_InnerClasses (mut i32)
(i32.const 0)
)
(global $f_$class__abstractinnerclass_InnerClasses (mut (ref null $java.lang.Class))
(ref.null $java.lang.Class)
)
(global $f_$string_|abstractinne...|__abstractinnerclass_InnerClasses (mut (ref null $java.lang.String))
(ref.null $java.lang.String)
)

;;; Code for abstractinnerclass.InnerClasses.A [static fields]
(global $f_$initialized__abstractinnerclass_InnerClasses_A (mut i32) (i32.const 0))
(global $f_$class__abstractinnerclass_InnerClasses_A (mut (ref null $java.lang.Class)) (ref.null $java.lang.Class))
(global $f_$string_|abstractinne...|__abstractinnerclass_InnerClasses_A (mut (ref null $java.lang.String)) (ref.null $java.lang.String))
(global $f_$initialized__abstractinnerclass_InnerClasses_A (mut i32)
(i32.const 0)
)
(global $f_$class__abstractinnerclass_InnerClasses_A (mut (ref null $java.lang.Class))
(ref.null $java.lang.Class)
)
(global $f_$string_|abstractinne...|__abstractinnerclass_InnerClasses_A (mut (ref null $java.lang.String))
(ref.null $java.lang.String)
)

;;; Code for abstractinnerclass.InnerClasses.B [static fields]
(global $f_$initialized__abstractinnerclass_InnerClasses_B (mut i32) (i32.const 0))
(global $f_$class__abstractinnerclass_InnerClasses_B (mut (ref null $java.lang.Class)) (ref.null $java.lang.Class))
(global $f_$string_|abstractinne...|__abstractinnerclass_InnerClasses_B (mut (ref null $java.lang.String)) (ref.null $java.lang.String))
(global $f_$initialized__abstractinnerclass_InnerClasses_B (mut i32)
(i32.const 0)
)
(global $f_$class__abstractinnerclass_InnerClasses_B (mut (ref null $java.lang.Class))
(ref.null $java.lang.Class)
)
(global $f_$string_|abstractinne...|__abstractinnerclass_InnerClasses_B (mut (ref null $java.lang.String))
(ref.null $java.lang.String)
)

;;; Code for abstractinnerclass.InnerClasses.C [static fields]
(global $f_$initialized__abstractinnerclass_InnerClasses_C (mut i32) (i32.const 0))
(global $f_$class__abstractinnerclass_InnerClasses_C (mut (ref null $java.lang.Class)) (ref.null $java.lang.Class))
(global $f_$string_|abstractinne...|__abstractinnerclass_InnerClasses_C (mut (ref null $java.lang.String)) (ref.null $java.lang.String))
(global $f_$initialized__abstractinnerclass_InnerClasses_C (mut i32)
(i32.const 0)
)
(global $f_$class__abstractinnerclass_InnerClasses_C (mut (ref null $java.lang.Class))
(ref.null $java.lang.Class)
)
(global $f_$string_|abstractinne...|__abstractinnerclass_InnerClasses_C (mut (ref null $java.lang.String))
(ref.null $java.lang.String)
)

;;; Code for abstractinnerclass.InnerClasses.A [methods]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,26 @@
)))

;;; Code for abstractinterfaceimpl.MyInterface [static fields]
(global $f_$initialized__abstractinterfaceimpl_MyInterface (mut i32) (i32.const 0))
(global $f_$class__abstractinterfaceimpl_MyInterface (mut (ref null $java.lang.Class)) (ref.null $java.lang.Class))
(global $f_$string_|abstractinte...|__abstractinterfaceimpl_MyInterface (mut (ref null $java.lang.String)) (ref.null $java.lang.String))
(global $f_$initialized__abstractinterfaceimpl_MyInterface (mut i32)
(i32.const 0)
)
(global $f_$class__abstractinterfaceimpl_MyInterface (mut (ref null $java.lang.Class))
(ref.null $java.lang.Class)
)
(global $f_$string_|abstractinte...|__abstractinterfaceimpl_MyInterface (mut (ref null $java.lang.String))
(ref.null $java.lang.String)
)

;;; Code for abstractinterfaceimpl.AbstractInterfaceImpl [static fields]
(global $f_$initialized__abstractinterfaceimpl_AbstractInterfaceImpl (mut i32) (i32.const 0))
(global $f_$class__abstractinterfaceimpl_AbstractInterfaceImpl (mut (ref null $java.lang.Class)) (ref.null $java.lang.Class))
(global $f_$string_|abstractinte...|__abstractinterfaceimpl_AbstractInterfaceImpl (mut (ref null $java.lang.String)) (ref.null $java.lang.String))
(global $f_$initialized__abstractinterfaceimpl_AbstractInterfaceImpl (mut i32)
(i32.const 0)
)
(global $f_$class__abstractinterfaceimpl_AbstractInterfaceImpl (mut (ref null $java.lang.Class))
(ref.null $java.lang.Class)
)
(global $f_$string_|abstractinte...|__abstractinterfaceimpl_AbstractInterfaceImpl (mut (ref null $java.lang.String))
(ref.null $java.lang.String)
)

;;; Code for abstractinterfaceimpl.MyInterface [methods]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,51 +134,90 @@
)

;;; Code for abstractmethodoverridedefault.AbstractMethodOverrideDefault.C [itable.init]
(global $abstractmethodoverridedefault.AbstractMethodOverrideDefault.I.vtable@$abstractmethodoverridedefault.AbstractMethodOverrideDefault.C (ref $abstractmethodoverridedefault.AbstractMethodOverrideDefault.I.vtable)

(global $abstractmethodoverridedefault.AbstractMethodOverrideDefault.I.vtable@$abstractmethodoverridedefault.AbstractMethodOverrideDefault.C (ref $abstractmethodoverridedefault.AbstractMethodOverrideDefault.I.vtable)
(struct.new $abstractmethodoverridedefault.AbstractMethodOverrideDefault.I.vtable
(ref.func $m_bar__void@abstractmethodoverridedefault.AbstractMethodOverrideDefault.C)
(ref.func $m_foo__void@abstractmethodoverridedefault.AbstractMethodOverrideDefault.C)
)
)
(global $abstractmethodoverridedefault.AbstractMethodOverrideDefault.C.itable (ref $abstractmethodoverridedefault.AbstractMethodOverrideDefault.C.itable)
(struct.new $abstractmethodoverridedefault.AbstractMethodOverrideDefault.C.itable
(global.get $abstractmethodoverridedefault.AbstractMethodOverrideDefault.I.vtable@$abstractmethodoverridedefault.AbstractMethodOverrideDefault.C)
(ref.null struct)
(ref.null struct)
(ref.null struct)
(ref.null struct)
(ref.null struct)
(ref.null struct)
)
(global $abstractmethodoverridedefault.AbstractMethodOverrideDefault.C.itable (ref $abstractmethodoverridedefault.AbstractMethodOverrideDefault.C.itable) (struct.new $abstractmethodoverridedefault.AbstractMethodOverrideDefault.C.itable
(global.get $abstractmethodoverridedefault.AbstractMethodOverrideDefault.I.vtable@$abstractmethodoverridedefault.AbstractMethodOverrideDefault.C)
(ref.null struct)
(ref.null struct)
(ref.null struct)
(ref.null struct)
(ref.null struct)
(ref.null struct)
))
)

;;; Code for abstractmethodoverridedefault.AbstractMethodOverrideDefault [static fields]
(global $f_$initialized__abstractmethodoverridedefault_AbstractMethodOverrideDefault (mut i32) (i32.const 0))
(global $f_$class__abstractmethodoverridedefault_AbstractMethodOverrideDefault (mut (ref null $java.lang.Class)) (ref.null $java.lang.Class))
(global $f_$string_|abstractmeth...|__abstractmethodoverridedefault_AbstractMethodOverrideDefault (mut (ref null $java.lang.String)) (ref.null $java.lang.String))
(global $f_$initialized__abstractmethodoverridedefault_AbstractMethodOverrideDefault (mut i32)
(i32.const 0)
)
(global $f_$class__abstractmethodoverridedefault_AbstractMethodOverrideDefault (mut (ref null $java.lang.Class))
(ref.null $java.lang.Class)
)
(global $f_$string_|abstractmeth...|__abstractmethodoverridedefault_AbstractMethodOverrideDefault (mut (ref null $java.lang.String))
(ref.null $java.lang.String)
)

;;; Code for abstractmethodoverridedefault.AbstractMethodOverrideDefault.I [static fields]
(global $f_$initialized__abstractmethodoverridedefault_AbstractMethodOverrideDefault_I (mut i32) (i32.const 0))
(global $f_$class__abstractmethodoverridedefault_AbstractMethodOverrideDefault_I (mut (ref null $java.lang.Class)) (ref.null $java.lang.Class))
(global $f_$string_|abstractmeth...|__abstractmethodoverridedefault_AbstractMethodOverrideDefault_I (mut (ref null $java.lang.String)) (ref.null $java.lang.String))
(global $f_$initialized__abstractmethodoverridedefault_AbstractMethodOverrideDefault_I (mut i32)
(i32.const 0)
)
(global $f_$class__abstractmethodoverridedefault_AbstractMethodOverrideDefault_I (mut (ref null $java.lang.Class))
(ref.null $java.lang.Class)
)
(global $f_$string_|abstractmeth...|__abstractmethodoverridedefault_AbstractMethodOverrideDefault_I (mut (ref null $java.lang.String))
(ref.null $java.lang.String)
)

;;; Code for abstractmethodoverridedefault.AbstractMethodOverrideDefault.J [static fields]
(global $f_$initialized__abstractmethodoverridedefault_AbstractMethodOverrideDefault_J (mut i32) (i32.const 0))
(global $f_$class__abstractmethodoverridedefault_AbstractMethodOverrideDefault_J (mut (ref null $java.lang.Class)) (ref.null $java.lang.Class))
(global $f_$string_|abstractmeth...|__abstractmethodoverridedefault_AbstractMethodOverrideDefault_J (mut (ref null $java.lang.String)) (ref.null $java.lang.String))
(global $f_$initialized__abstractmethodoverridedefault_AbstractMethodOverrideDefault_J (mut i32)
(i32.const 0)
)
(global $f_$class__abstractmethodoverridedefault_AbstractMethodOverrideDefault_J (mut (ref null $java.lang.Class))
(ref.null $java.lang.Class)
)
(global $f_$string_|abstractmeth...|__abstractmethodoverridedefault_AbstractMethodOverrideDefault_J (mut (ref null $java.lang.String))
(ref.null $java.lang.String)
)

;;; Code for abstractmethodoverridedefault.AbstractMethodOverrideDefault.A [static fields]
(global $f_$initialized__abstractmethodoverridedefault_AbstractMethodOverrideDefault_A (mut i32) (i32.const 0))
(global $f_$class__abstractmethodoverridedefault_AbstractMethodOverrideDefault_A (mut (ref null $java.lang.Class)) (ref.null $java.lang.Class))
(global $f_$string_|abstractmeth...|__abstractmethodoverridedefault_AbstractMethodOverrideDefault_A (mut (ref null $java.lang.String)) (ref.null $java.lang.String))
(global $f_$initialized__abstractmethodoverridedefault_AbstractMethodOverrideDefault_A (mut i32)
(i32.const 0)
)
(global $f_$class__abstractmethodoverridedefault_AbstractMethodOverrideDefault_A (mut (ref null $java.lang.Class))
(ref.null $java.lang.Class)
)
(global $f_$string_|abstractmeth...|__abstractmethodoverridedefault_AbstractMethodOverrideDefault_A (mut (ref null $java.lang.String))
(ref.null $java.lang.String)
)

;;; Code for abstractmethodoverridedefault.AbstractMethodOverrideDefault.B [static fields]
(global $f_$initialized__abstractmethodoverridedefault_AbstractMethodOverrideDefault_B (mut i32) (i32.const 0))
(global $f_$class__abstractmethodoverridedefault_AbstractMethodOverrideDefault_B (mut (ref null $java.lang.Class)) (ref.null $java.lang.Class))
(global $f_$string_|abstractmeth...|__abstractmethodoverridedefault_AbstractMethodOverrideDefault_B (mut (ref null $java.lang.String)) (ref.null $java.lang.String))
(global $f_$initialized__abstractmethodoverridedefault_AbstractMethodOverrideDefault_B (mut i32)
(i32.const 0)
)
(global $f_$class__abstractmethodoverridedefault_AbstractMethodOverrideDefault_B (mut (ref null $java.lang.Class))
(ref.null $java.lang.Class)
)
(global $f_$string_|abstractmeth...|__abstractmethodoverridedefault_AbstractMethodOverrideDefault_B (mut (ref null $java.lang.String))
(ref.null $java.lang.String)
)

;;; Code for abstractmethodoverridedefault.AbstractMethodOverrideDefault.C [static fields]
(global $f_$initialized__abstractmethodoverridedefault_AbstractMethodOverrideDefault_C (mut i32) (i32.const 0))
(global $f_$class__abstractmethodoverridedefault_AbstractMethodOverrideDefault_C (mut (ref null $java.lang.Class)) (ref.null $java.lang.Class))
(global $f_$string_|abstractmeth...|__abstractmethodoverridedefault_AbstractMethodOverrideDefault_C (mut (ref null $java.lang.String)) (ref.null $java.lang.String))
(global $f_$initialized__abstractmethodoverridedefault_AbstractMethodOverrideDefault_C (mut i32)
(i32.const 0)
)
(global $f_$class__abstractmethodoverridedefault_AbstractMethodOverrideDefault_C (mut (ref null $java.lang.Class))
(ref.null $java.lang.Class)
)
(global $f_$string_|abstractmeth...|__abstractmethodoverridedefault_AbstractMethodOverrideDefault_C (mut (ref null $java.lang.String))
(ref.null $java.lang.String)
)

;;; Code for abstractmethodoverridedefault.AbstractMethodOverrideDefault.I [methods]

Expand Down
Loading

0 comments on commit 99d02e2

Please sign in to comment.