From 4d8f33d9944b937a9f1ff14b875b9084167eda94 Mon Sep 17 00:00:00 2001 From: "Alexey Andreev konsoletyper@gmail.com" Date: Mon, 14 May 2018 01:15:29 +0300 Subject: [PATCH] C backend: few fixes for MVSC --- core/src/main/java/org/teavm/backend/c/CTarget.java | 10 +++++++--- core/src/main/resources/org/teavm/backend/c/runtime.c | 4 ++-- .../src/main/java/org/teavm/junit/CRunStrategy.java | 9 +-------- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/core/src/main/java/org/teavm/backend/c/CTarget.java b/core/src/main/java/org/teavm/backend/c/CTarget.java index d5793dafe..d254fa977 100644 --- a/core/src/main/java/org/teavm/backend/c/CTarget.java +++ b/core/src/main/java/org/teavm/backend/c/CTarget.java @@ -35,6 +35,7 @@ import org.teavm.ast.decompilation.Decompiler; import org.teavm.backend.c.analyze.CDependencyListener; import org.teavm.backend.c.generate.BufferedCodeWriter; import org.teavm.backend.c.generate.ClassGenerator; +import org.teavm.backend.c.generate.CodeGeneratorUtil; import org.teavm.backend.c.generate.CodeWriter; import org.teavm.backend.c.generate.GenerationContext; import org.teavm.backend.c.generate.NameProvider; @@ -416,7 +417,9 @@ public class CTarget implements TeaVMTarget, TeaVMCHost { private void generateVirtualTableHeaders(GenerationContext context, CodeWriter writer, Set types) { String classClassName = context.getNames().forClassInstance(ValueType.object("java.lang.Class")); - writer.println("int32_t classHeader = PACK_CLASS(&" + classClassName + ") | " + RuntimeObject.GC_MARKED + ";"); + writer.print("int32_t classHeader = PACK_CLASS(&" + classClassName + ") | "); + CodeGeneratorUtil.writeValue(writer, context, RuntimeObject.GC_MARKED); + writer.println(";"); for (ValueType type : types) { if (!ClassGenerator.needsVirtualTable(context.getCharacteristics(), type)) { @@ -430,8 +433,9 @@ public class CTarget implements TeaVMTarget, TeaVMCHost { private void generateStringPoolHeaders(GenerationContext context, CodeWriter writer) { String stringClassName = context.getNames().forClassInstance(ValueType.object("java.lang.String")); - writer.println("int32_t stringHeader = PACK_CLASS(&" + stringClassName + ") | " - + RuntimeObject.GC_MARKED + ";"); + writer.print("int32_t stringHeader = PACK_CLASS(&" + stringClassName + ") | "); + CodeGeneratorUtil.writeValue(writer, context, RuntimeObject.GC_MARKED); + writer.println(";"); int size = context.getStringPool().getStrings().size(); writer.println("for (int i = 0; i < " + size + "; ++i) {").indent(); diff --git a/core/src/main/resources/org/teavm/backend/c/runtime.c b/core/src/main/resources/org/teavm/backend/c/runtime.c index d024a30f5..ce78b44fd 100644 --- a/core/src/main/resources/org/teavm/backend/c/runtime.c +++ b/core/src/main/resources/org/teavm/backend/c/runtime.c @@ -81,7 +81,7 @@ static inline void* checkcast(void*, int32_t (*)(JavaClass*)); #define STRUCTURE_ADD(structure, address, offset) (((structure*) (address)) + offset) #define TEAVM_STRING(length, hash, s) { \ - .characters = (JavaArray*) & (struct { JavaArray hdr; char16_t data[length]; }) { \ + .characters = (JavaArray*) & (struct { JavaArray hdr; char16_t data[(length) + 1]; }) { \ .hdr = { .size = length }, \ .data = s \ }, \ @@ -89,7 +89,7 @@ static inline void* checkcast(void*, int32_t (*)(JavaClass*)); } #define TEAVM_STRING_FROM_CODES(length, hash, ...) { \ - .characters = (JavaArray*) & (struct { JavaArray hdr; char16_t data[length]; }) { \ + .characters = (JavaArray*) & (struct { JavaArray hdr; char16_t data[(length) + 1]; }) { \ .hdr = { .size = length }, \ .data = { __VA_ARGS__ } \ }, \ diff --git a/tools/junit/src/main/java/org/teavm/junit/CRunStrategy.java b/tools/junit/src/main/java/org/teavm/junit/CRunStrategy.java index 98b3ea5b8..5d63ff529 100644 --- a/tools/junit/src/main/java/org/teavm/junit/CRunStrategy.java +++ b/tools/junit/src/main/java/org/teavm/junit/CRunStrategy.java @@ -92,14 +92,7 @@ class CRunStrategy implements TestRunStrategy { throws IOException, InterruptedException { String[] parts = compilerCommand.split(" +"); for (int i = 0; i < parts.length; ++i) { - switch (parts[i]) { - case "@IN": - parts[i] = inputFile.getPath(); - break; - case "@OUT": - parts[i] = outputFile.getPath(); - break; - } + parts[i] = parts[i].replace("@IN", inputFile.getPath()).replace("@OUT", outputFile.getPath()); } return runProcess(new ProcessBuilder(parts).start(), output); }