diff --git a/compiler/cacerts/full/pom.xml b/compiler/cacerts/full/pom.xml
index 1fa821b01..4e4c0379c 100755
--- a/compiler/cacerts/full/pom.xml
+++ b/compiler/cacerts/full/pom.xml
@@ -5,7 +5,7 @@
com.mobidevelop.robovm
robovm-cacerts-parent
- 2.3.17-SNAPSHOT
+ 2.3.19-SNAPSHOT
robovm-cacerts-full
diff --git a/compiler/cacerts/pom.xml b/compiler/cacerts/pom.xml
index 494480108..71ed9c9d5 100755
--- a/compiler/cacerts/pom.xml
+++ b/compiler/cacerts/pom.xml
@@ -5,7 +5,7 @@
com.mobidevelop.robovm
robovm-compiler-parent
- 2.3.17-SNAPSHOT
+ 2.3.19-SNAPSHOT
robovm-cacerts-parent
diff --git a/compiler/cocoatouch/pom.xml b/compiler/cocoatouch/pom.xml
index 42f294228..de399066f 100755
--- a/compiler/cocoatouch/pom.xml
+++ b/compiler/cocoatouch/pom.xml
@@ -5,7 +5,7 @@
com.mobidevelop.robovm
robovm-compiler-parent
- 2.3.17-SNAPSHOT
+ 2.3.19-SNAPSHOT
robovm-cocoatouch
diff --git a/compiler/compiler/pom.xml b/compiler/compiler/pom.xml
index fde771b68..324a31b89 100755
--- a/compiler/compiler/pom.xml
+++ b/compiler/compiler/pom.xml
@@ -5,7 +5,7 @@
com.mobidevelop.robovm
robovm-compiler-parent
- 2.3.17-SNAPSHOT
+ 2.3.19-SNAPSHOT
robovm-compiler
diff --git a/compiler/compiler/src/main/java/org/robovm/compiler/AppCompiler.java b/compiler/compiler/src/main/java/org/robovm/compiler/AppCompiler.java
index 1a2f4546c..1698e9ec9 100755
--- a/compiler/compiler/src/main/java/org/robovm/compiler/AppCompiler.java
+++ b/compiler/compiler/src/main/java/org/robovm/compiler/AppCompiler.java
@@ -28,10 +28,7 @@
import org.robovm.compiler.config.Config.TreeShakerMode;
import org.robovm.compiler.config.StripArchivesConfig.StripArchivesBuilder;
import org.robovm.compiler.log.ConsoleLogger;
-import org.robovm.compiler.plugin.LaunchPlugin;
-import org.robovm.compiler.plugin.Plugin;
-import org.robovm.compiler.plugin.PluginArgument;
-import org.robovm.compiler.plugin.TargetPlugin;
+import org.robovm.compiler.plugin.*;
import org.robovm.compiler.target.ConsoleTarget;
import org.robovm.compiler.target.LaunchParameters;
import org.robovm.compiler.target.ios.*;
@@ -439,6 +436,11 @@ public void failure(Clazz clazz, Throwable t) {
dependencyGraph.add(clazz, rootClasses.contains(clazz), forceLinkMethods);
linkClasses.add(clazz);
+ // notify plugins
+ for (CompilerPlugin plugin : config.getCompilerPlugins()) {
+ plugin.afterClassDependenciesResolved(config, clazz);
+ }
+
if (compileDependencies) {
addMetaInfImplementations(config.getClazzes(), clazz, linkClasses, compileQueue);
}
diff --git a/compiler/compiler/src/main/java/org/robovm/compiler/ClassCompiler.java b/compiler/compiler/src/main/java/org/robovm/compiler/ClassCompiler.java
index 2669072b5..0745bc76a 100755
--- a/compiler/compiler/src/main/java/org/robovm/compiler/ClassCompiler.java
+++ b/compiler/compiler/src/main/java/org/robovm/compiler/ClassCompiler.java
@@ -25,7 +25,6 @@
import org.robovm.compiler.clazz.MethodInfo;
import org.robovm.compiler.config.Arch;
import org.robovm.compiler.config.Config;
-import org.robovm.compiler.config.Environment;
import org.robovm.compiler.config.OS;
import org.robovm.compiler.llvm.Alias;
import org.robovm.compiler.llvm.AliasRef;
@@ -228,7 +227,7 @@ public class ClassCompiler {
private final TrampolineCompiler trampolineResolver;
private final ObjCMemberPlugin.MethodCompiler objcMethodCompiler;
- private final ByteArrayOutputStream output = new ByteArrayOutputStream(256 * 1024);
+ private final ByteArrayOutputStream output = new ByteArrayOutputStream(4 * 1024 * 1024);
public ClassCompiler(Config config) {
this.config = config;
diff --git a/compiler/compiler/src/main/java/org/robovm/compiler/Linker.java b/compiler/compiler/src/main/java/org/robovm/compiler/Linker.java
index 3282edc0e..71bd6d37b 100755
--- a/compiler/compiler/src/main/java/org/robovm/compiler/Linker.java
+++ b/compiler/compiler/src/main/java/org/robovm/compiler/Linker.java
@@ -446,7 +446,10 @@ public void link(Set classes) throws IOException {
}
}
- config.getTarget().build(objectFiles);
+ File binaryFile = config.getTarget().build(objectFiles);
+ for (CompilerPlugin plugin : config.getCompilerPlugins()) {
+ plugin.afterLinker(config, binaryFile);
+ }
}
private void generateMachineCode(final Config config, ModuleBuilder[] mbs,
diff --git a/compiler/compiler/src/main/java/org/robovm/compiler/clazz/AbstractPath.java b/compiler/compiler/src/main/java/org/robovm/compiler/clazz/AbstractPath.java
index a86991991..37482e371 100755
--- a/compiler/compiler/src/main/java/org/robovm/compiler/clazz/AbstractPath.java
+++ b/compiler/compiler/src/main/java/org/robovm/compiler/clazz/AbstractPath.java
@@ -31,9 +31,9 @@ public abstract class AbstractPath implements Path {
protected final Clazzes clazzes;
protected final int index;
protected Set clazzSet = null;
- protected Set packageSet = null;
- protected boolean inBootclasspath = false;
- protected Map generatedClasses = new HashMap();
+ protected boolean disposed = false;
+ protected boolean inBootclasspath;
+ protected Map generatedClasses = new HashMap<>();
protected final File generatedClassDir;
AbstractPath(File file, Clazzes clazzes, int index, boolean inBootclasspath) {
@@ -57,6 +57,8 @@ public File getFile() {
}
public Set listClasses() {
+ if (disposed)
+ throw new IllegalStateException("Path was disposed!");
if (clazzSet == null) {
clazzSet = doListClasses();
}
@@ -119,5 +121,11 @@ public boolean equals(Object obj) {
public String toString() {
return file.toString();
}
-
+
+ @Override
+ public void disposeBuildData() {
+ disposed = true;
+ clazzSet = null;
+ generatedClasses = null;
+ }
}
diff --git a/compiler/compiler/src/main/java/org/robovm/compiler/clazz/Clazz.java b/compiler/compiler/src/main/java/org/robovm/compiler/clazz/Clazz.java
index 0064cf258..582791f4e 100755
--- a/compiler/compiler/src/main/java/org/robovm/compiler/clazz/Clazz.java
+++ b/compiler/compiler/src/main/java/org/robovm/compiler/clazz/Clazz.java
@@ -18,6 +18,7 @@
import org.apache.commons.io.IOUtils;
import soot.SootClass;
+import soot.SootMethod;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
@@ -205,4 +206,18 @@ public int compareTo(Clazz o) {
public String toString() {
return className;
}
+
+ /**
+ * Drops Soot object and releases all its resolved bodies
+ */
+ public void shrinkSoot() {
+ if (sootClass != null) {
+ // dropping all bodies
+ for (SootMethod m: sootClass.getMethods()) {
+ if (m.hasActiveBody())
+ m.releaseActiveBody();
+ }
+ sootClass = null;
+ }
+ }
}
diff --git a/compiler/compiler/src/main/java/org/robovm/compiler/clazz/ClazzInfo.java b/compiler/compiler/src/main/java/org/robovm/compiler/clazz/ClazzInfo.java
index 761136952..bf106fc39 100755
--- a/compiler/compiler/src/main/java/org/robovm/compiler/clazz/ClazzInfo.java
+++ b/compiler/compiler/src/main/java/org/robovm/compiler/clazz/ClazzInfo.java
@@ -43,13 +43,13 @@ public class ClazzInfo implements Serializable {
private String name;
private String internalName;
private String superclassName;
- private final List interfaceNames = new ArrayList();
- private final List methods = new ArrayList();
- private final Set catchNames = new HashSet();
- private Map dependencies = new HashMap();
- private final Set checkcasts = new HashSet();
- private final Set instanceofs = new HashSet();
- private final Set invokes = new HashSet();
+ private final List interfaceNames = new ArrayList<>();
+ private final List methods = new ArrayList<>();
+ private final Set catchNames = new HashSet<>();
+ private Map dependencies = new HashMap<>();
+ private final Set checkcasts = new HashSet<>();
+ private final Set instanceofs = new HashSet<>();
+ private final Set invokes = new HashSet<>();
private boolean isStruct;
private boolean isEnum;
@@ -190,7 +190,7 @@ public void setInterfaceNames(List interfaceNames) {
}
public List getInterfaces() {
- List result = new ArrayList();
+ List result = new ArrayList<>();
for (String ifname : interfaceNames) {
result.add(loadClazzInfo(ifname));
}
@@ -207,7 +207,7 @@ public void setCatchNames(Set catchNames) {
}
public List getCatches() {
- List result = new ArrayList();
+ List result = new ArrayList<>();
for (String n : catchNames) {
result.add(loadClazzInfo(n));
}
@@ -268,11 +268,11 @@ public void addSuperMethodDependency(String owner, String name, String desc, boo
}
public void clearDependencies() {
- dependencies = new HashMap();
+ dependencies = new HashMap<>();
}
public Set getDependencies() {
- return new HashSet(dependencies.values());
+ return new HashSet<>(dependencies.values());
}
public Set getAllDependencies() {
@@ -360,4 +360,10 @@ public boolean equals(Object obj) {
}
return true;
}
+
+ public void dropDependencyData() {
+ for (MethodInfo mi : getMethods())
+ mi.dropDependencyData();
+ dependencies = null;
+ }
}
diff --git a/compiler/compiler/src/main/java/org/robovm/compiler/clazz/Clazzes.java b/compiler/compiler/src/main/java/org/robovm/compiler/clazz/Clazzes.java
index 135986b3b..04294e285 100755
--- a/compiler/compiler/src/main/java/org/robovm/compiler/clazz/Clazzes.java
+++ b/compiler/compiler/src/main/java/org/robovm/compiler/clazz/Clazzes.java
@@ -40,17 +40,21 @@
*/
public class Clazzes {
private final Config config;
- private final List bootclasspathPaths = new ArrayList();
- private final List classpathPaths = new ArrayList();
- private final List paths = new ArrayList();
- private final Map cache = new HashMap();
- private final List allClasses = new ArrayList();
+ private final List bootclasspathPaths = new ArrayList<>();
+ private final List classpathPaths = new ArrayList<>();
+ private final List paths = new ArrayList<>();
+ private final Map cache = new HashMap<>();
+ private final List allClasses = new ArrayList<>();
private boolean sootInitialized = false;
+ // disposed state
+ private boolean sootDisposed = false;
+ private boolean contentDisposed = false;
+
public Clazzes(Config config, List bootclasspath, List classpath) throws IOException {
this.config = config;
- Set seen = new HashSet();
+ Set seen = new HashSet<>();
addPaths(bootclasspath, bootclasspathPaths, seen, true);
addPaths(classpath, classpathPaths, seen, false);
paths.addAll(bootclasspathPaths);
@@ -123,6 +127,7 @@ private boolean isEmpty(File dir) {
}
private void populateCache() {
+ requiresContent();
for (Path p : paths) {
for (Clazz clazz : p.listClasses()) {
if (!cache.containsKey(clazz.getInternalName())) {
@@ -134,6 +139,7 @@ private void populateCache() {
}
public Clazz load(String internalName) {
+ requiresContent();
Clazz clazz = cache.get(internalName);
if (clazz == null) {
// Could be a generated class
@@ -175,10 +181,12 @@ public List getPaths() {
}
public List listClasses() {
+ requiresContent();
return Collections.unmodifiableList(allClasses);
}
SootClass getSootClass(Clazz clazz) {
+ requiresSoot();
if (!sootInitialized) {
initializeSoot(this);
sootInitialized = true;
@@ -210,6 +218,42 @@ private static String getSootClasspath(Clazzes clazzes) {
return sb.toString();
}
+ /**
+ * sanity: checks if soot was disposed
+ */
+ private void requiresSoot() {
+ if (sootDisposed)
+ throw new IllegalStateException("Soot has been disposed !");
+ }
+
+ /**
+ * releases soot resources, singletons once these are not required anymore to reduce memory pressure
+ * after this point soot is not usable anymore
+ */
+ public void disposeSoot() {
+ requiresSoot();
+ soot.G.reset();
+ sootDisposed = true;
+ }
+
+
+ private void requiresContent() {
+ if (contentDisposed)
+ throw new IllegalStateException("Content has been disposed !");
+ }
+
+ /**
+ * drops caches and all classes data. after this point this data is not accessible
+ */
+ public void disposeData() {
+ requiresContent();
+ cache.clear();
+ allClasses.clear();
+ for (Path p : paths)
+ p.disposeBuildData();
+ contentDisposed = true;
+ }
+
private static void initializeSoot(Clazzes clazzes) {
soot.G.reset();
Options.v().set_output_format(Options.output_format_jimple);
diff --git a/compiler/compiler/src/main/java/org/robovm/compiler/clazz/MethodInfo.java b/compiler/compiler/src/main/java/org/robovm/compiler/clazz/MethodInfo.java
index 78e367f7b..6476556f9 100755
--- a/compiler/compiler/src/main/java/org/robovm/compiler/clazz/MethodInfo.java
+++ b/compiler/compiler/src/main/java/org/robovm/compiler/clazz/MethodInfo.java
@@ -204,6 +204,10 @@ public boolean equals(Object obj) {
return true;
}
+ public void dropDependencyData() {
+ dependencies = null;
+ }
+
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this);
diff --git a/compiler/compiler/src/main/java/org/robovm/compiler/clazz/Path.java b/compiler/compiler/src/main/java/org/robovm/compiler/clazz/Path.java
index 0145a2980..b22ed2da7 100755
--- a/compiler/compiler/src/main/java/org/robovm/compiler/clazz/Path.java
+++ b/compiler/compiler/src/main/java/org/robovm/compiler/clazz/Path.java
@@ -58,4 +58,9 @@ public interface Path {
boolean contains(String file);
InputStream open(String file) throws IOException;
+
+ /**
+ * Dispose any cached data to reduce memory footprint
+ */
+ void disposeBuildData();
}
diff --git a/compiler/compiler/src/main/java/org/robovm/compiler/config/Config.java b/compiler/compiler/src/main/java/org/robovm/compiler/config/Config.java
index 06b40df68..76dbf3633 100755
--- a/compiler/compiler/src/main/java/org/robovm/compiler/config/Config.java
+++ b/compiler/compiler/src/main/java/org/robovm/compiler/config/Config.java
@@ -32,11 +32,7 @@
import org.robovm.compiler.config.tools.Tools;
import org.robovm.compiler.llvm.DataLayout;
import org.robovm.compiler.log.Logger;
-import org.robovm.compiler.plugin.CompilerPlugin;
-import org.robovm.compiler.plugin.LaunchPlugin;
-import org.robovm.compiler.plugin.Plugin;
-import org.robovm.compiler.plugin.PluginArgument;
-import org.robovm.compiler.plugin.TargetPlugin;
+import org.robovm.compiler.plugin.*;
import org.robovm.compiler.plugin.annotation.AnnotationImplPlugin;
import org.robovm.compiler.plugin.debug.DebugInformationPlugin;
import org.robovm.compiler.plugin.debug.DebuggerLaunchPlugin;
@@ -259,7 +255,8 @@ protected Config(UUID uuid) {
new ByteBufferJava9ApiPlugin(),
new LambdaPlugin(),
new DebugInformationPlugin(),
- new DebuggerLaunchPlugin()
+ new DebuggerLaunchPlugin(),
+ new BuildGarbageCollectorPlugin()
));
this.loadPluginsFromClassPath();
}
@@ -404,6 +401,8 @@ public StripArchivesConfig getStripArchivesConfig() {
}
public DependencyGraph getDependencyGraph() {
+ if (dependencyGraph == null)
+ throw new IllegalStateException(".dependencyGraph has been disposed!");
return dependencyGraph;
}
@@ -504,14 +503,29 @@ public File getOsArchDepLibDir() {
}
public Clazzes getClazzes() {
+ if (clazzes == null)
+ throw new IllegalStateException(".clazzes has been disposed!");
return clazzes;
}
+ public void disposeBuildData() {
+ // not null clazzes as some data like allPath is required post-build (e.g. to stripArchives)
+ clazzes.disposeData();
+ dependencyGraph = null;
+ vtableCache = null;
+ itableCache = null;
+ marshalerLookup = null;
+ }
+
public VTable.Cache getVTableCache() {
+ if (vtableCache == null)
+ throw new IllegalStateException(".vtableCache has been disposed!");
return vtableCache;
}
public ITable.Cache getITableCache() {
+ if (itableCache == null)
+ throw new IllegalStateException(".itableCache has been disposed!");
return itableCache;
}
diff --git a/compiler/compiler/src/main/java/org/robovm/compiler/llvm/Alias.java b/compiler/compiler/src/main/java/org/robovm/compiler/llvm/Alias.java
index 7ef42a061..ee72ae6cc 100755
--- a/compiler/compiler/src/main/java/org/robovm/compiler/llvm/Alias.java
+++ b/compiler/compiler/src/main/java/org/robovm/compiler/llvm/Alias.java
@@ -17,11 +17,14 @@
package org.robovm.compiler.llvm;
+import java.io.IOException;
+import java.io.Writer;
+
/**
*
* @version $Id$
*/
-public class Alias {
+public class Alias implements Writable{
private final String name;
private final Linkage linkage;
private final Constant value;
@@ -48,22 +51,29 @@ public Type getType() {
return value.getType();
}
- public String getDefinition() {
- StringBuilder sb = new StringBuilder();
- sb.append("@\"");
- sb.append(name);
- sb.append("\" = ");
+ public void writeDefinition(Writer writer) throws IOException {
+ writer.write("@\"");
+ writer.write(name);
+ writer.write("\" = ");
if (linkage != null) {
- sb.append(linkage);
- sb.append(' ');
+ writer.write(linkage.toString());
+ writer.write(' ');
}
- sb.append("alias ");
- sb.append(value.getType());
- sb.append(' ');
- sb.append(value);
- return sb.toString();
+ writer.write("alias ");
+ value.getType().write(writer);
+ writer.write(' ');
+ value.write(writer);
}
-
+
+ public String getDefinition() {
+ return toString(this::writeDefinition);
+ }
+
+ @Override
+ public void write(Writer writer) throws IOException {
+ throw new IllegalStateException("writeDefinition to be used");
+ }
+
@Override
public String toString() {
return name;
diff --git a/compiler/compiler/src/main/java/org/robovm/compiler/llvm/AliasRef.java b/compiler/compiler/src/main/java/org/robovm/compiler/llvm/AliasRef.java
index 0abe8509b..312dd8361 100755
--- a/compiler/compiler/src/main/java/org/robovm/compiler/llvm/AliasRef.java
+++ b/compiler/compiler/src/main/java/org/robovm/compiler/llvm/AliasRef.java
@@ -17,6 +17,9 @@
package org.robovm.compiler.llvm;
+import java.io.IOException;
+import java.io.Writer;
+
/**
*
* @version $Id$
@@ -84,4 +87,9 @@ public boolean equals(Object obj) {
public String toString() {
return "@\"" + name + "\"";
}
+
+ @Override
+ public void write(Writer writer) throws IOException {
+ writer.write(toString());
+ }
}
diff --git a/compiler/compiler/src/main/java/org/robovm/compiler/llvm/Alloca.java b/compiler/compiler/src/main/java/org/robovm/compiler/llvm/Alloca.java
index ac82b3fe5..57df62366 100755
--- a/compiler/compiler/src/main/java/org/robovm/compiler/llvm/Alloca.java
+++ b/compiler/compiler/src/main/java/org/robovm/compiler/llvm/Alloca.java
@@ -16,6 +16,8 @@
*/
package org.robovm.compiler.llvm;
+import java.io.IOException;
+import java.io.Writer;
import java.util.Collections;
import java.util.Set;
@@ -45,8 +47,14 @@ public Type getType() {
return type;
}
+ @Override
+ public void write(Writer writer) throws IOException {
+ writer.append(result.toString()).append(" = alloca ");
+ type.write(writer);
+ }
+
@Override
public String toString() {
- return result + " = alloca " + type;
+ return toString(this::write);
}
}
diff --git a/compiler/compiler/src/main/java/org/robovm/compiler/llvm/Argument.java b/compiler/compiler/src/main/java/org/robovm/compiler/llvm/Argument.java
index 28d04f463..f02442482 100755
--- a/compiler/compiler/src/main/java/org/robovm/compiler/llvm/Argument.java
+++ b/compiler/compiler/src/main/java/org/robovm/compiler/llvm/Argument.java
@@ -16,13 +16,15 @@
*/
package org.robovm.compiler.llvm;
+import java.io.IOException;
+import java.io.Writer;
import java.util.Arrays;
/**
*
* @version $Id$
*/
-public class Argument {
+public class Argument implements Writable {
private final Value value;
private final ParameterAttribute[] attributes;
@@ -78,13 +80,16 @@ public boolean equals(Object obj) {
}
@Override
- public String toString() {
- StringBuilder sb = new StringBuilder();
+ public void write(Writer writer) throws IOException {
for (ParameterAttribute attribute : attributes) {
- sb.append(attribute);
- sb.append(' ');
+ writer.write(attribute.toString());
+ writer.write(' ');
}
- sb.append(value);
- return sb.toString();
+ value.write(writer);
+ }
+
+ @Override
+ public String toString() {
+ return toString(this::write);
}
}
diff --git a/compiler/compiler/src/main/java/org/robovm/compiler/llvm/ArrayConstant.java b/compiler/compiler/src/main/java/org/robovm/compiler/llvm/ArrayConstant.java
index bac7a2750..4dce5bc1d 100755
--- a/compiler/compiler/src/main/java/org/robovm/compiler/llvm/ArrayConstant.java
+++ b/compiler/compiler/src/main/java/org/robovm/compiler/llvm/ArrayConstant.java
@@ -16,6 +16,9 @@
*/
package org.robovm.compiler.llvm;
+import java.io.IOException;
+import java.io.Writer;
+
/**
*
* @version $Id$
@@ -35,18 +38,22 @@ public Type getType() {
}
@Override
- public String toString() {
- StringBuilder sb = new StringBuilder();
- sb.append('[');
+ public void write(Writer writer) throws IOException {
+ writer.write('[');
for (int i = 0; i < values.length; i++) {
if (i > 0) {
- sb.append(", ");
+ writer.write(", ");
}
- sb.append(values[i].getType());
- sb.append(' ');
- sb.append(values[i]);
+ values[i].getType().write(writer);
+ writer.write(' ');
+ values[i].write(writer);
}
- sb.append(']');
- return sb.toString();
+ writer.write(']');
+
+ }
+
+ @Override
+ public String toString() {
+ return toString(this::write);
}
}
diff --git a/compiler/compiler/src/main/java/org/robovm/compiler/llvm/ArrayType.java b/compiler/compiler/src/main/java/org/robovm/compiler/llvm/ArrayType.java
index 2d36c8c92..1f09755fe 100755
--- a/compiler/compiler/src/main/java/org/robovm/compiler/llvm/ArrayType.java
+++ b/compiler/compiler/src/main/java/org/robovm/compiler/llvm/ArrayType.java
@@ -16,6 +16,9 @@
*/
package org.robovm.compiler.llvm;
+import java.io.IOException;
+import java.io.Writer;
+
/**
*
* @version $Id$
@@ -53,10 +56,17 @@ public Type getTypeAt(int index) {
public int getTypeCount() {
return (int) size;
}
-
+
+ @Override
+ public void writeDefinition(Writer writer) throws IOException {
+ writer.append('[').append(Long.toString(size)).append(" x ");
+ elementType.write(writer);
+ writer.write("]");
+ }
+
@Override
public String getDefinition() {
- return "[" + size + " x " + elementType + "]";
+ return toString(this::writeDefinition);
}
@Override
diff --git a/compiler/compiler/src/main/java/org/robovm/compiler/llvm/BasicBlock.java b/compiler/compiler/src/main/java/org/robovm/compiler/llvm/BasicBlock.java
index f798e4221..422dff94c 100755
--- a/compiler/compiler/src/main/java/org/robovm/compiler/llvm/BasicBlock.java
+++ b/compiler/compiler/src/main/java/org/robovm/compiler/llvm/BasicBlock.java
@@ -16,6 +16,8 @@
*/
package org.robovm.compiler.llvm;
+import java.io.IOException;
+import java.io.Writer;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
@@ -25,7 +27,7 @@
*
* @version $Id$
*/
-public class BasicBlock {
+public class BasicBlock implements Writable {
private final Function function;
private final Label label;
private final List instructions = new ArrayList();
@@ -99,24 +101,27 @@ public Instruction last() {
}
return instructions.get(instructions.size() - 1);
}
-
+
@Override
- public String toString() {
- StringBuilder sb = new StringBuilder();
- sb.append(getName());
- sb.append(":\n");
+ public void write(Writer writer) throws IOException {
+ writer.write(getName());
+ writer.write(":\n");
for (Instruction instruction : instructions) {
- sb.append(" ");
- sb.append(instruction.toString());
+ writer.write(" ");
+ instruction.write(writer);
List metadata = instruction.getMetadata();
if (!metadata.isEmpty()) {
for (Metadata md : metadata) {
- sb.append(", ");
- sb.append(md.toString());
+ writer.write(", ");
+ md.write(writer);
}
}
- sb.append('\n');
+ writer.write('\n');
}
- return sb.toString();
+ }
+
+ @Override
+ public String toString() {
+ return toString(this::write);
}
}
diff --git a/compiler/compiler/src/main/java/org/robovm/compiler/llvm/BooleanConstant.java b/compiler/compiler/src/main/java/org/robovm/compiler/llvm/BooleanConstant.java
index 9251b45b7..6deeab2e9 100755
--- a/compiler/compiler/src/main/java/org/robovm/compiler/llvm/BooleanConstant.java
+++ b/compiler/compiler/src/main/java/org/robovm/compiler/llvm/BooleanConstant.java
@@ -16,6 +16,9 @@
*/
package org.robovm.compiler.llvm;
+import java.io.IOException;
+import java.io.Writer;
+
/**
*
* @version $Id$
@@ -40,4 +43,9 @@ public Type getType() {
public String toString() {
return String.valueOf(value);
}
+
+ @Override
+ public void write(Writer writer) throws IOException {
+ writer.write(toString());
+ }
}
diff --git a/compiler/compiler/src/main/java/org/robovm/compiler/llvm/Br.java b/compiler/compiler/src/main/java/org/robovm/compiler/llvm/Br.java
index 6bd746049..3040cab8a 100755
--- a/compiler/compiler/src/main/java/org/robovm/compiler/llvm/Br.java
+++ b/compiler/compiler/src/main/java/org/robovm/compiler/llvm/Br.java
@@ -16,6 +16,8 @@
*/
package org.robovm.compiler.llvm;
+import java.io.IOException;
+import java.io.Writer;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
@@ -61,12 +63,20 @@ public Set getBranchTargets() {
}
return result;
}
-
+
@Override
- public String toString() {
+ public void write(Writer writer) throws IOException {
if (cond != null) {
- return "br i1 " + cond + ", label %" + destTrue.getName() + ", label %" + destFalse.getName();
+ writer.write("br i1 ");
+ cond.write(writer);
+ writer.append(", label %").append(destTrue.getName()).append(", label %").append(destFalse.getName());
+ } else {
+ writer.append("br label %").append(destTrue.getName());
}
- return "br label %" + destTrue.getName();
+ }
+
+ @Override
+ public String toString() {
+ return toString(this::write);
}
}
diff --git a/compiler/compiler/src/main/java/org/robovm/compiler/llvm/ByteArrayConstant.java b/compiler/compiler/src/main/java/org/robovm/compiler/llvm/ByteArrayConstant.java
index 066f682d9..3e15dcae8 100755
--- a/compiler/compiler/src/main/java/org/robovm/compiler/llvm/ByteArrayConstant.java
+++ b/compiler/compiler/src/main/java/org/robovm/compiler/llvm/ByteArrayConstant.java
@@ -15,6 +15,9 @@
*/
package org.robovm.compiler.llvm;
+import java.io.IOException;
+import java.io.Writer;
+
/**
* Straight forward implementation of byte array constant to reduce amount of memory
* required to do same foe ArrayConstant
@@ -35,17 +38,20 @@ public Type getType() {
}
@Override
- public String toString() {
- StringBuilder sb = new StringBuilder();
- sb.append('[');
+ public void write(Writer writer) throws IOException {
+ writer.write('[');
for (int i = 0; i < values.length; i++) {
if (i > 0) {
- sb.append(", ");
+ writer.write(", ");
}
- sb.append("i8 ");
- sb.append(values[i]);
+ writer.write("i8 ");
+ writer.write(Byte.toString(values[i]));
}
- sb.append(']');
- return sb.toString();
+ writer.write(']');
+ }
+
+ @Override
+ public String toString() {
+ return toString(this::write);
}
}
diff --git a/compiler/compiler/src/main/java/org/robovm/compiler/llvm/ConstantGetelementptr.java b/compiler/compiler/src/main/java/org/robovm/compiler/llvm/ConstantGetelementptr.java
index e4c465c60..744fe05e0 100755
--- a/compiler/compiler/src/main/java/org/robovm/compiler/llvm/ConstantGetelementptr.java
+++ b/compiler/compiler/src/main/java/org/robovm/compiler/llvm/ConstantGetelementptr.java
@@ -16,6 +16,9 @@
*/
package org.robovm.compiler.llvm;
+import java.io.IOException;
+import java.io.Writer;
+
/**
*
* @version $Id$
@@ -48,17 +51,20 @@ public Type getType() {
}
@Override
- public String toString() {
- StringBuilder sb = new StringBuilder();
- sb.append("getelementptr (");
- sb.append(cst.getType());
- sb.append(' ');
- sb.append(cst);
- for (int i = 0; i < idx.length; i++) {
- sb.append(", i32 ");
- sb.append(idx[i]);
+ public void write(Writer writer) throws IOException {
+ writer.write("getelementptr (");
+ cst.getType().write(writer);
+ writer.write(' ');
+ cst.write(writer);
+ for (int j : idx) {
+ writer.write(", i32 ");
+ writer.write(Integer.toString(j));
}
- sb.append(")");
- return sb.toString();
+ writer.write(')');
+ }
+
+ @Override
+ public String toString() {
+ return toString(this::write);
}
}
diff --git a/compiler/compiler/src/main/java/org/robovm/compiler/llvm/ConversionConstant.java b/compiler/compiler/src/main/java/org/robovm/compiler/llvm/ConversionConstant.java
index 42efb3d5d..6b8a503d2 100755
--- a/compiler/compiler/src/main/java/org/robovm/compiler/llvm/ConversionConstant.java
+++ b/compiler/compiler/src/main/java/org/robovm/compiler/llvm/ConversionConstant.java
@@ -16,6 +16,9 @@
*/
package org.robovm.compiler.llvm;
+import java.io.IOException;
+import java.io.Writer;
+
/**
*
* @version $Id$
@@ -36,8 +39,20 @@ public Type getType() {
return type;
}
+ @Override
+ public void write(Writer writer) throws IOException {
+ writer.write(name);
+ writer.write(" (");
+ cst.getType().write(writer);
+ writer.write(' ');
+ cst.write(writer);
+ writer.write(" to ");
+ type.write(writer);
+ writer.write(')');
+ }
+
@Override
public String toString() {
- return name + " (" + cst.getType() + " " + cst + " to " + type + ")";
+ return toString(this::write);
}
}
diff --git a/compiler/compiler/src/main/java/org/robovm/compiler/llvm/ConversionInstruction.java b/compiler/compiler/src/main/java/org/robovm/compiler/llvm/ConversionInstruction.java
index b8f00d294..de21ebfd5 100755
--- a/compiler/compiler/src/main/java/org/robovm/compiler/llvm/ConversionInstruction.java
+++ b/compiler/compiler/src/main/java/org/robovm/compiler/llvm/ConversionInstruction.java
@@ -16,6 +16,9 @@
*/
package org.robovm.compiler.llvm;
+import java.io.IOException;
+import java.io.Writer;
+
/**
*
* @version $Id$
@@ -29,9 +32,19 @@ protected ConversionInstruction(String name, Variable result, Value op, Type typ
this.name = name;
this.type = type;
}
-
+
+ @Override
+ public void write(Writer writer) throws IOException {
+ writer.append(result.toString()).append(" = ").append(name).append(' ');
+ op.getType().write(writer);
+ writer.write(' ');
+ op.write(writer);
+ writer.write(" to ");
+ type.write(writer);
+ }
+
@Override
public String toString() {
- return result + " = " + name + " " + op.getType() + " " + op + " to " + type;
+ return toString(this::write);
}
}
diff --git a/compiler/compiler/src/main/java/org/robovm/compiler/llvm/DebugMetadata.java b/compiler/compiler/src/main/java/org/robovm/compiler/llvm/DebugMetadata.java
index 6544eeec2..e8b8b0802 100755
--- a/compiler/compiler/src/main/java/org/robovm/compiler/llvm/DebugMetadata.java
+++ b/compiler/compiler/src/main/java/org/robovm/compiler/llvm/DebugMetadata.java
@@ -16,6 +16,9 @@
*/
package org.robovm.compiler.llvm;
+import java.io.IOException;
+import java.io.Writer;
+
/**
* {@link Metadata} used to attach debug info to instructions.
*/
@@ -26,9 +29,14 @@ public DebugMetadata(MetadataNode value) {
this.value = value;
}
+ @Override
+ public void write(Writer writer) throws IOException {
+ writer.write( "!dbg ");
+ value.write(writer);
+ }
+
@Override
public String toString() {
- return "!dbg " + value;
+ return toString(this::write);
}
-
}
diff --git a/compiler/compiler/src/main/java/org/robovm/compiler/llvm/Fcmp.java b/compiler/compiler/src/main/java/org/robovm/compiler/llvm/Fcmp.java
index 3b3d76d0c..5f0e972ae 100755
--- a/compiler/compiler/src/main/java/org/robovm/compiler/llvm/Fcmp.java
+++ b/compiler/compiler/src/main/java/org/robovm/compiler/llvm/Fcmp.java
@@ -16,6 +16,9 @@
*/
package org.robovm.compiler.llvm;
+import java.io.IOException;
+import java.io.Writer;
+
/**
*
* @version $Id$
@@ -40,9 +43,19 @@ public Fcmp(Variable result, Condition cond, Value op1, Value op2) {
}
this.cond = cond;
}
-
+
+ @Override
+ public void write(Writer writer) throws IOException {
+ writer.append(result.toString()).append(" = fcmp ").append(cond.toString()).append(' ');
+ op1.getType().write(writer);
+ writer.write(' ');
+ op1.write(writer);
+ writer.write(", ");
+ op2.write(writer);
+ }
+
@Override
public String toString() {
- return result + " = fcmp " + cond + " " + op1.getType() + " " + op1 + ", " + op2;
+ return toString(this::write);
}
}
diff --git a/compiler/compiler/src/main/java/org/robovm/compiler/llvm/Fence.java b/compiler/compiler/src/main/java/org/robovm/compiler/llvm/Fence.java
index f24248813..d33a2be56 100755
--- a/compiler/compiler/src/main/java/org/robovm/compiler/llvm/Fence.java
+++ b/compiler/compiler/src/main/java/org/robovm/compiler/llvm/Fence.java
@@ -16,6 +16,9 @@
*/
package org.robovm.compiler.llvm;
+import java.io.IOException;
+import java.io.Writer;
+
/**
* @author niklas
*
@@ -32,4 +35,8 @@ public String toString() {
return "fence " + ordering;
}
+ @Override
+ public void write(Writer writer) throws IOException {
+ writer.write(toString());
+ }
}
diff --git a/compiler/compiler/src/main/java/org/robovm/compiler/llvm/FloatingPointBinaryInstruction.java b/compiler/compiler/src/main/java/org/robovm/compiler/llvm/FloatingPointBinaryInstruction.java
index 43ed448cb..f18abe710 100755
--- a/compiler/compiler/src/main/java/org/robovm/compiler/llvm/FloatingPointBinaryInstruction.java
+++ b/compiler/compiler/src/main/java/org/robovm/compiler/llvm/FloatingPointBinaryInstruction.java
@@ -17,6 +17,9 @@
package org.robovm.compiler.llvm;
+import java.io.IOException;
+import java.io.Writer;
+
/**
*
* @version $Id$
@@ -34,9 +37,19 @@ protected FloatingPointBinaryInstruction(String name, Variable result, Value op1
}
this.name = name;
}
-
+
+ @Override
+ public void write(Writer writer) throws IOException {
+ writer.append(result.toString()).append(" = ").append(name).append(' ');
+ op1.getType().write(writer);
+ writer.write(' ');
+ op1.write(writer);
+ writer.write(", ");
+ op2.write(writer);
+ }
+
@Override
public String toString() {
- return result + " = " + name + " " + op1.getType() + " " + op1 + ", " + op2;
+ return toString(this::write);
}
}
diff --git a/compiler/compiler/src/main/java/org/robovm/compiler/llvm/FloatingPointConstant.java b/compiler/compiler/src/main/java/org/robovm/compiler/llvm/FloatingPointConstant.java
index 22b0d03ac..d1372f714 100755
--- a/compiler/compiler/src/main/java/org/robovm/compiler/llvm/FloatingPointConstant.java
+++ b/compiler/compiler/src/main/java/org/robovm/compiler/llvm/FloatingPointConstant.java
@@ -16,6 +16,9 @@
*/
package org.robovm.compiler.llvm;
+import java.io.IOException;
+import java.io.Writer;
+
/**
*
* @version $Id$
@@ -25,15 +28,15 @@ public class FloatingPointConstant extends Constant {
private final Object value;
public FloatingPointConstant(float value) {
- this(new Float(value), Type.FLOAT);
+ this(value, Type.FLOAT);
}
public FloatingPointConstant(double value) {
- this(new Double(value), Type.DOUBLE);
+ this(value, Type.DOUBLE);
}
public FloatingPointConstant(double value, FloatingPointType type) {
- this.value = new Double(value);
+ this.value = value;
this.type = type;
}
@@ -90,4 +93,9 @@ public String toString() {
return "bitcast (i64 " + Double.doubleToLongBits(d) + " to double)";
}
}
+
+ @Override
+ public void write(Writer writer) throws IOException {
+ writer.write(toString());
+ }
}
diff --git a/compiler/compiler/src/main/java/org/robovm/compiler/llvm/Function.java b/compiler/compiler/src/main/java/org/robovm/compiler/llvm/Function.java
index 0cf9e89dc..f870370e8 100755
--- a/compiler/compiler/src/main/java/org/robovm/compiler/llvm/Function.java
+++ b/compiler/compiler/src/main/java/org/robovm/compiler/llvm/Function.java
@@ -28,7 +28,7 @@
*
* @version $Id$
*/
-public class Function {
+public class Function implements Writable {
private final String name;
private final Linkage linkage;
private final FunctionAttribute[] attributes;
@@ -178,6 +178,7 @@ public String getSignature() {
return sig;
}
+ @Override
public void write(Writer writer) throws IOException {
Type returnType = type.getReturnType();
Type[] parameterTypes = type.getParameterTypes();
@@ -186,7 +187,7 @@ public void write(Writer writer) throws IOException {
writer.write(linkage.toString());
writer.write(' ');
}
- writer.write(returnType.toString());
+ returnType.write(writer);
writer.write(" @\"");
writer.write(name);
writer.write("\"(");
@@ -194,7 +195,7 @@ public void write(Writer writer) throws IOException {
if (i > 0) {
writer.write(", ");
}
- writer.write(parameterTypes[i].toString());
+ parameterTypes[i].write(writer);
if (parameterAttributes[i] != null) {
for (ParameterAttribute attrib : parameterAttributes[i]) {
writer.write(' ');
@@ -221,19 +222,13 @@ public void write(Writer writer) throws IOException {
}
writer.write(" {\n");
for (BasicBlock bb : basicBlockList) {
- writer.write(bb.toString());
+ bb.write(writer);
}
writer.write("}\n");
}
@Override
public String toString() {
- StringWriter sw = new StringWriter();
- try {
- write(sw);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- return sw.toString();
+ return toString(this::write);
}
}
diff --git a/compiler/compiler/src/main/java/org/robovm/compiler/llvm/FunctionCallInstruction.java b/compiler/compiler/src/main/java/org/robovm/compiler/llvm/FunctionCallInstruction.java
index 72c385a6e..d989732e0 100755
--- a/compiler/compiler/src/main/java/org/robovm/compiler/llvm/FunctionCallInstruction.java
+++ b/compiler/compiler/src/main/java/org/robovm/compiler/llvm/FunctionCallInstruction.java
@@ -16,6 +16,8 @@
*/
package org.robovm.compiler.llvm;
+import java.io.IOException;
+import java.io.Writer;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
@@ -134,28 +136,34 @@ public boolean equals(Object obj) {
}
@Override
- public String toString() {
- StringBuilder sb = new StringBuilder();
+ public void write(Writer writer) throws IOException {
if (result != null) {
- sb.append(result.toString());
- sb.append(" = ");
+ writer.write(result.toString());
+ writer.write(" = ");
}
- sb.append(name);
- sb.append(' ');
+ writer.write(name);
+ writer.write(' ');
FunctionType ftype = (FunctionType) function.getType();
- sb.append(ftype.isVarargs() ? ftype.getDefinition() : ftype.getReturnType().toString());
- sb.append(" ");
- sb.append(function.toString());
- sb.append('(');
+ if (ftype.isVarargs())
+ ftype.writeDefinition(writer);
+ else
+ ftype.getReturnType().write(writer);
+ writer.write(' ');
+ function.write(writer);
+ writer.write('(');
for (int i = 0; i < args.length; i++) {
if (i > 0) {
- sb.append(", ");
+ writer.write(", ");
}
- sb.append(args[i].getType());
- sb.append(' ');
- sb.append(args[i]);
+ args[i].getType().write(writer);
+ writer.write(' ');
+ args[i].write(writer);
}
- sb.append(')');
- return sb.toString();
+ writer.write(')');
+ }
+
+ @Override
+ public String toString() {
+ return toString(this::write);
}
}
diff --git a/compiler/compiler/src/main/java/org/robovm/compiler/llvm/FunctionDeclaration.java b/compiler/compiler/src/main/java/org/robovm/compiler/llvm/FunctionDeclaration.java
index 706e49faf..6889c1fbf 100755
--- a/compiler/compiler/src/main/java/org/robovm/compiler/llvm/FunctionDeclaration.java
+++ b/compiler/compiler/src/main/java/org/robovm/compiler/llvm/FunctionDeclaration.java
@@ -17,11 +17,14 @@
package org.robovm.compiler.llvm;
+import java.io.IOException;
+import java.io.Writer;
+
/**
*
* @version $Id$
*/
-public class FunctionDeclaration {
+public class FunctionDeclaration implements Writable{
private final String name;
private final FunctionType type;
@@ -45,27 +48,30 @@ public FunctionType getType() {
public FunctionRef ref() {
return new FunctionRef(name, type);
}
-
+
@Override
- public String toString() {
+ public void write(Writer writer) throws IOException {
Type returnType = type.getReturnType();
Type[] parameterTypes = type.getParameterTypes();
- StringBuilder sb = new StringBuilder();
- sb.append("declare ");
- sb.append(returnType.toString());
- sb.append(" @\"");
- sb.append(name);
- sb.append("\"(");
+ writer.write("declare ");
+ returnType.write(writer);
+ writer.write(" @\"");
+ writer.write(name);
+ writer.write("\"(");
for (int i = 0; i < parameterTypes.length; i++) {
if (i > 0) {
- sb.append(", ");
+ writer.write(", ");
}
- sb.append(parameterTypes[i].toString());
+ parameterTypes[i].write(writer);
}
if (type.isVarargs()) {
- sb.append(", ...");
+ writer.write(", ...");
}
- sb.append(")");
- return sb.toString();
+ writer.write(')');
+ }
+
+ @Override
+ public String toString() {
+ return toString(this::write);
}
}
diff --git a/compiler/compiler/src/main/java/org/robovm/compiler/llvm/FunctionRef.java b/compiler/compiler/src/main/java/org/robovm/compiler/llvm/FunctionRef.java
index dfdd47854..49c2f54a7 100755
--- a/compiler/compiler/src/main/java/org/robovm/compiler/llvm/FunctionRef.java
+++ b/compiler/compiler/src/main/java/org/robovm/compiler/llvm/FunctionRef.java
@@ -17,6 +17,9 @@
package org.robovm.compiler.llvm;
+import java.io.IOException;
+import java.io.Writer;
+
/**
*
* @version $Id$
@@ -46,4 +49,9 @@ public FunctionType getType() {
public String toString() {
return "@\"" + name + "\"";
}
+
+ @Override
+ public void write(Writer writer) throws IOException {
+ writer.write(toString());
+ }
}
diff --git a/compiler/compiler/src/main/java/org/robovm/compiler/llvm/FunctionType.java b/compiler/compiler/src/main/java/org/robovm/compiler/llvm/FunctionType.java
index 97ef75e31..e353b0e9f 100755
--- a/compiler/compiler/src/main/java/org/robovm/compiler/llvm/FunctionType.java
+++ b/compiler/compiler/src/main/java/org/robovm/compiler/llvm/FunctionType.java
@@ -16,6 +16,8 @@
*/
package org.robovm.compiler.llvm;
+import java.io.IOException;
+import java.io.Writer;
import java.util.Arrays;
@@ -66,26 +68,29 @@ public boolean isVarargs() {
public Type[] getParameterTypes() {
return parameterTypes;
}
-
+
@Override
- public String getDefinition() {
- StringBuilder sb = new StringBuilder();
- sb.append(returnType.toString());
- sb.append(" (");
+ public void writeDefinition(Writer writer) throws IOException {
+ returnType.write(writer);
+ writer.write(" (");
for (int i = 0; i < parameterTypes.length; i++) {
if (i > 0) {
- sb.append(", ");
+ writer.write(", ");
}
- sb.append(parameterTypes[i].toString());
+ parameterTypes[i].write(writer);
}
if (varargs) {
if (parameterTypes.length > 0) {
- sb.append(", ");
+ writer.write(", ");
}
- sb.append("...");
+ writer.write("...");
}
- sb.append(")*");
- return sb.toString();
+ writer.write(")*");
+ }
+
+ @Override
+ public String getDefinition() {
+ return toString(this::writeDefinition);
}
@Override
diff --git a/compiler/compiler/src/main/java/org/robovm/compiler/llvm/Getelementptr.java b/compiler/compiler/src/main/java/org/robovm/compiler/llvm/Getelementptr.java
index ef6aa50f1..2e08d94e8 100755
--- a/compiler/compiler/src/main/java/org/robovm/compiler/llvm/Getelementptr.java
+++ b/compiler/compiler/src/main/java/org/robovm/compiler/llvm/Getelementptr.java
@@ -16,6 +16,8 @@
*/
package org.robovm.compiler.llvm;
+import java.io.IOException;
+import java.io.Writer;
import java.util.Collections;
import java.util.Set;
@@ -73,21 +75,24 @@ public Set getReadsFrom() {
}
return super.getReadsFrom();
}
-
+
@Override
- public String toString() {
- StringBuilder sb = new StringBuilder();
- sb.append(result);
- sb.append(" = getelementptr ");
- sb.append(ptr.getType());
- sb.append(' ');
- sb.append(ptr);
- for (int i = 0; i < idx.length; i++) {
- sb.append(", ");
- sb.append(idx[i].getType());
- sb.append(" ");
- sb.append(idx[i]);
+ public void write(Writer writer) throws IOException {
+ writer.write(result.toString());
+ writer.write(" = getelementptr ");
+ ptr.getType().write(writer);
+ writer.write(' ');
+ ptr.write(writer);
+ for (Value value : idx) {
+ writer.write(", ");
+ value.getType().write(writer);
+ writer.write(" ");
+ value.write(writer);
}
- return sb.toString();
+ }
+
+ @Override
+ public String toString() {
+ return toString(this::write);
}
}
diff --git a/compiler/compiler/src/main/java/org/robovm/compiler/llvm/Global.java b/compiler/compiler/src/main/java/org/robovm/compiler/llvm/Global.java
index baf06285f..4a33bf614 100755
--- a/compiler/compiler/src/main/java/org/robovm/compiler/llvm/Global.java
+++ b/compiler/compiler/src/main/java/org/robovm/compiler/llvm/Global.java
@@ -17,11 +17,14 @@
package org.robovm.compiler.llvm;
+import java.io.IOException;
+import java.io.Writer;
+
/**
*
* @version $Id$
*/
-public class Global {
+public class Global implements Writable {
private final String name;
private final Linkage linkage;
private final Constant value;
@@ -86,34 +89,41 @@ public String getName() {
public PointerType getType() {
return new PointerType(type);
}
-
- public String getDefinition() {
- StringBuilder sb = new StringBuilder();
- sb.append("@\"");
- sb.append(name);
- sb.append("\" = ");
+
+ public void writeDefinition(Writer writer) throws IOException {
+ writer.write("@\"");
+ writer.write(name);
+ writer.write("\" = ");
if (linkage != null) {
- sb.append(linkage);
- sb.append(' ');
+ writer.write(linkage.toString());
+ writer.write(' ');
}
if (constant) {
- sb.append("constant ");
+ writer.write("constant ");
} else {
- sb.append("global ");
+ writer.write("global ");
}
- sb.append(type);
+ type.write(writer);
if (value != null) {
- sb.append(' ');
- sb.append(value);
+ writer.write(' ');
+ value.write(writer);
}
if (section != null) {
- sb.append(", section \"");
- sb.append(section);
- sb.append('"');
+ writer.write(", section \"");
+ writer.write(section);
+ writer.write('"');
}
- return sb.toString();
}
-
+
+ public String getDefinition() {
+ return toString(this::writeDefinition);
+ }
+
+ @Override
+ public void write(Writer writer) throws IOException {
+ throw new IllegalStateException("writeDefinition to be called!");
+ }
+
@Override
public String toString() {
return "@\"" + name + "\"";
diff --git a/compiler/compiler/src/main/java/org/robovm/compiler/llvm/GlobalRef.java b/compiler/compiler/src/main/java/org/robovm/compiler/llvm/GlobalRef.java
index 1b6b4c41c..e0d76a933 100755
--- a/compiler/compiler/src/main/java/org/robovm/compiler/llvm/GlobalRef.java
+++ b/compiler/compiler/src/main/java/org/robovm/compiler/llvm/GlobalRef.java
@@ -17,6 +17,9 @@
package org.robovm.compiler.llvm;
+import java.io.IOException;
+import java.io.Writer;
+
/**
*
* @version $Id$
@@ -84,4 +87,9 @@ public boolean equals(Object obj) {
public String toString() {
return "@\"" + name + "\"";
}
+
+ @Override
+ public void write(Writer writer) throws IOException {
+ writer.write(toString());
+ }
}
diff --git a/compiler/compiler/src/main/java/org/robovm/compiler/llvm/Icmp.java b/compiler/compiler/src/main/java/org/robovm/compiler/llvm/Icmp.java
index da5ce83c6..f6e3fc01d 100755
--- a/compiler/compiler/src/main/java/org/robovm/compiler/llvm/Icmp.java
+++ b/compiler/compiler/src/main/java/org/robovm/compiler/llvm/Icmp.java
@@ -16,6 +16,9 @@
*/
package org.robovm.compiler.llvm;
+import java.io.IOException;
+import java.io.Writer;
+
/**
*
* @version $Id$
@@ -40,8 +43,18 @@ public Icmp(Variable result, Condition cond, Value op1, Value op2) {
this.cond = cond;
}
+ @Override
+ public void write(Writer writer) throws IOException {
+ writer.append(result.toString()).append(" = icmp ").append(cond.toString()).append(' ');
+ op1.getType().write(writer);
+ writer.write(' ');
+ op1.write(writer);
+ writer.write(", ");
+ op2.write(writer);
+ }
+
@Override
public String toString() {
- return result + " = icmp " + cond + " " + op1.getType() + " " + op1 + ", " + op2;
+ return toString(this::write);
}
}
diff --git a/compiler/compiler/src/main/java/org/robovm/compiler/llvm/Instruction.java b/compiler/compiler/src/main/java/org/robovm/compiler/llvm/Instruction.java
index f5574fa4e..425ab5908 100755
--- a/compiler/compiler/src/main/java/org/robovm/compiler/llvm/Instruction.java
+++ b/compiler/compiler/src/main/java/org/robovm/compiler/llvm/Instruction.java
@@ -25,7 +25,7 @@
*
* @version $Id$
*/
-public abstract class Instruction {
+public abstract class Instruction implements Writable{
BasicBlock basicBlock;
private List metadata;
private List