/** * Writes out the found and numbered types to ~/.rootbeer/types e.g. * * <p>19658 java.lang.AssertionError 13642 java.lang.Error 11879 java.lang.StackTraceElement[] * 9292 org.trifort.rootbeer.runtime.Sentinal 9259 org.trifort.rootbeer.runtime.RootbeerGpu 9112 * org.trifort.rootbeer.runtimegpu.GpuException 3806 java.lang.StackTraceElement 3219 * java.lang.Throwable 3213 long[] 3210 CountKernel 3186 org.trifort.rootbeer.runtime.Kernel 2818 * java.util.List 2817 java.util.Collection 2816 java.lang.Iterable 2454 java.io.Serializable 6 * int 2 boolean 1 java.lang.Object * * <p>The numbering is done in the RootbeerClassLoader fork of Soot seemingly with a increasing * counter, although it's weird that there are to be 19658 and more different types. * * @todo Is it necessary to write out this file or is it just debug output? */ private void writeTypesToFile(final List<NumberedType> types) { try { PrintWriter writer = new PrintWriter(RootbeerPaths.v().getTypeFile()); for (NumberedType type : types) writer.println(type.getNumber() + " " + type.getType().toString()); writer.flush(); writer.close(); } catch (Exception ex) { ex.printStackTrace(); } }
/** * For manually provided CUDA code it returns the file as a string. If not it converts the java * code to CUDA using Jimple as intermediary * * @return List of Strings. 1st is CUDA code for Linux, 2nd is for Windows */ private String[] makeSourceCode() throws Exception { assert (m_configuration != null); if (m_configuration.isManualCuda()) { final String cuda_code = readCode(m_configuration.getManualCudaFilename()); final String[] ret = new String[2]; ret[0] = cuda_code; ret[1] = cuda_code; return ret; } /* this gets switched to true again, if a new statement is found in * MethodJimpleValueSwitch e.g. when parsed in OpenCLMethod's or * OpenCLArrayType's Value.apply */ m_usesGarbageCollector = false; List<NumberedType> types = RootbeerClassLoader.v().getDfsInfo().getNumberedTypes(); writeTypesToFile(types); final StringBuilder unix_code = new StringBuilder(); final StringBuilder windows_code = new StringBuilder(); final String method_protos = methodPrototypesString(); final String gc_string = garbageCollectorString(); final String bodies_string = methodBodiesString(); /* true/false arguments are used to differ between unix and windows */ unix_code.append(headerString(true)); unix_code.append(method_protos); unix_code.append(gc_string); unix_code.append(bodies_string); unix_code.append(kernelString(true)); windows_code.append(headerString(false)); windows_code.append(method_protos); windows_code.append(gc_string); windows_code.append(bodies_string); windows_code.append(kernelString(false)); final String cuda_unix = setupEntryPoint(unix_code); final String cuda_windows = setupEntryPoint(windows_code); // print out code for debugging PrintWriter writer = new PrintWriter(new FileWriter(RootbeerPaths.v().getRootbeerHome() + "generated_unix.cu")); writer.println(cuda_unix); writer.flush(); writer.close(); // print out code for debugging writer = new PrintWriter( new FileWriter(RootbeerPaths.v().getRootbeerHome() + "generated_windows.cu")); writer.println(cuda_windows); writer.flush(); writer.close(); NameMangling.v().writeTypesToFile(); String[] ret = new String[2]; ret[0] = cuda_unix; ret[1] = cuda_windows; return ret; }