C: workaround for regression in MSVC compiler

This commit is contained in:
Alexey Andreev 2020-11-27 18:54:24 +03:00
parent a8641de39b
commit 969ad17b6a
4 changed files with 7 additions and 5 deletions

View File

@ -609,6 +609,7 @@ public class CTarget implements TeaVMTarget, TeaVMCHost {
if (!incremental) { if (!incremental) {
headerWriter.println("extern TeaVM_String* teavm_stringPool[];"); headerWriter.println("extern TeaVM_String* teavm_stringPool[];");
headerWriter.println("#define TEAVM_GET_STRING(i) teavm_stringPool[i]"); headerWriter.println("#define TEAVM_GET_STRING(i) teavm_stringPool[i]");
headerWriter.println("#define TEAVM_GET_STRING_ADDRESS(i) (teavm_stringPool + i)");
includes.includePath("strings.h"); includes.includePath("strings.h");
includes.includePath("stringhash.h"); includes.includePath("stringhash.h");

View File

@ -219,7 +219,7 @@ public class CallSiteGenerator {
} }
private String getStringExpr(String s) { private String getStringExpr(String s) {
return s != null ? "&TEAVM_GET_STRING(" + context.getStringPool().getStringIndex(s) + ")" : "NULL"; return s != null ? "TEAVM_GET_STRING_ADDRESS(" + context.getStringPool().getStringIndex(s) + ")" : "NULL";
} }
static class HandlerContainer { static class HandlerContainer {

View File

@ -837,7 +837,8 @@ public class ClassGenerator {
String metadataName = nameOfType(type); String metadataName = nameOfType(type);
String nameRef = metadataName != null String nameRef = metadataName != null
? "(TeaVM_Object**) &TEAVM_GET_STRING(" + context.getStringPool().getStringIndex(metadataName) + ")" ? "(TeaVM_Object**) TEAVM_GET_STRING_ADDRESS("
+ context.getStringPool().getStringIndex(metadataName) + ")"
: "NULL"; : "NULL";
String superTypeFunction = context.getNames().forSupertypeFunction(type); String superTypeFunction = context.getNames().forSupertypeFunction(type);
@ -854,7 +855,7 @@ public class ClassGenerator {
simpleName = "NULL"; simpleName = "NULL";
} else { } else {
int simpleNameIndex = context.getStringPool().getStringIndex(simpleName); int simpleNameIndex = context.getStringPool().getStringIndex(simpleName);
simpleName = "(TeaVM_Object**) &TEAVM_GET_STRING(" + simpleNameIndex + ")"; simpleName = "(TeaVM_Object**) TEAVM_GET_STRING_ADDRESS(" + simpleNameIndex + ")";
} }
includes.includePath("strings.h"); includes.includePath("strings.h");

View File

@ -65,7 +65,7 @@ class MetadataCIntrinsic implements Generator {
} else if (value instanceof String) { } else if (value instanceof String) {
int stringIndex = context.stringPool().getStringIndex((String) value); int stringIndex = context.stringPool().getStringIndex((String) value);
context.includes().includePath("strings.h"); context.includes().includePath("strings.h");
context.writerBefore().print("(TeaVM_Object**) &TEAVM_GET_STRING(" + stringIndex + ")"); context.writerBefore().print("(TeaVM_Object**) TEAVM_GET_STRING_ADDRESS(" + stringIndex + ")");
} else if (value instanceof Boolean) { } else if (value instanceof Boolean) {
context.writerBefore().print((Boolean) value ? "1" : "0"); context.writerBefore().print((Boolean) value ? "1" : "0");
} else if (value instanceof Integer) { } else if (value instanceof Integer) {
@ -238,7 +238,7 @@ class MetadataCIntrinsic implements Generator {
if (key == null) { if (key == null) {
context.writerBefore().print("{ NULL, NULL }"); context.writerBefore().print("{ NULL, NULL }");
} else { } else {
context.writerBefore().print("{ &TEAVM_GET_STRING(" context.writerBefore().print("{ TEAVM_GET_STRING_ADDRESS("
+ context.stringPool().getStringIndex(key) + "), "); + context.stringPool().getStringIndex(key) + "), ");
writeValue(context, resourceMap.get(key)); writeValue(context, resourceMap.get(key));
context.writerBefore().print("}"); context.writerBefore().print("}");