
org.robovm.compiler.llvm.Module Maven / Gradle / Ivy
The newest version!
/*
* Copyright (C) 2012 RoboVM AB
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
package org.robovm.compiler.llvm;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
import java.io.Writer;
import java.net.URL;
import java.util.Collection;
import org.apache.commons.io.IOUtils;
/**
*
* @version $Id$
*/
public class Module implements Writable{
private final Collection includes;
private final Collection globals;
private final Collection aliases;
private final Collection functions;
private final Collection functionDeclarations;
private final Collection types;
private final Collection asm;
private final Collection namedMetadata;
private final Collection unnamedMetadata;
public Module(Collection includes, Collection types,
Collection globals, Collection aliases,
Collection functionDeclarations, Collection asm,
Collection functions, Collection namedMetadata,
Collection unnamedMetadata) {
this.includes = includes;
this.types = types;
this.globals = globals;
this.aliases = aliases;
this.functionDeclarations = functionDeclarations;
this.asm = asm;
this.functions = functions;
this.namedMetadata = namedMetadata;
this.unnamedMetadata = unnamedMetadata;
}
@Override
public void write(Writer writer) throws IOException {
for (URL g : includes) {
InputStream in = null;
try {
in = g.openStream();
IOUtils.copy(in, writer, "UTF-8");
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
IOUtils.closeQuietly(in);
}
writer.write("\n");
}
writer.write("\n");
for (String s : asm) {
writer.write("module asm \"");
writer.write(s);
writer.write("\"\n");
}
writer.write("\n");
for (UserType type : types) {
writer.write(type.getAlias());
writer.write(" = type ");
type.writeDefinition(writer);
writer.write("\n");
}
writer.write("\n");
for (FunctionDeclaration fd : functionDeclarations) {
fd.write(writer);
writer.write("\n");
}
writer.write("\n");
for (Global g : globals) {
g.writeDefinition(writer);
writer.write("\n");
}
writer.write("\n");
for (Alias a : aliases) {
a.writeDefinition(writer);
writer.write("\n");
}
writer.write("\n");
for (Function f : functions) {
f.write(writer);
writer.write("\n");
}
writer.write("\n");
for (NamedMetadata md : namedMetadata) {
md.write(writer);
writer.write("\n");
}
writer.write("\n");
for (UnnamedMetadata md : unnamedMetadata) {
md.writeDefinition(writer);
writer.write("\n");
}
}
@Override
public String toString() {
return toString(this::write);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy