/** * Returns the template kernels for Rootbeer added functionalites: BothNativeKernel.c and ( * CudaKernel.c xor UnixNativeKernel.c ) as a String */ private static String kernelString(final boolean unix) throws IOException { final String kernel_path = unix ? Tweaks.v().getUnixKernelPath() : Tweaks.v().getWindowsKernelPath(); String specific_kernel_code = ResourceReader.getResource(kernel_path); String both_kernel_code = ""; String both_kernel_path = Tweaks.v().getBothKernelPath(); if (both_kernel_path != null) both_kernel_code = ResourceReader.getResource(both_kernel_path); return both_kernel_code + "\n" + specific_kernel_code; }
/** * Read the next token from 'this.line' and append it to 'this.buf'. Tokens are separated by * Pattern_White_Space. Tokens may also be delimited by double or single quotes. The closing quote * must match the opening quote. If a '#' is encountered, the rest of the line is ignored, unless * it is backslash-escaped or within quotes. * * @param position the offset into the string * @return offset to the next character to read from line, or if the end of the line is reached * without scanning a valid token, -1 */ private int nextToken(int position) { position = PatternProps.skipWhiteSpace(line, position); if (position == line.length()) { return -1; } int startpos = position; char c = line.charAt(position++); char quote = 0; switch (c) { case '"': case '\'': quote = c; break; case '#': return -1; default: buf.append(c); break; } int[] posref = null; while (position < line.length()) { c = line.charAt(position); // 16-bit ok if (c == '\\') { if (posref == null) { posref = new int[1]; } posref[0] = position + 1; int c32 = Utility.unescapeAt(line, posref); if (c32 < 0) { throw new RuntimeException( "Invalid escape at " + reader.describePosition() + ':' + position); } UTF16.append(buf, c32); position = posref[0]; } else if ((quote != 0 && c == quote) || (quote == 0 && PatternProps.isWhiteSpace(c))) { return ++position; } else if (quote == 0 && c == '#') { return position; // do NOT increment } else { buf.append(c); ++position; } } if (quote != 0) { throw new RuntimeException( "Unterminated quote at " + reader.describePosition() + ':' + startpos); } return position; }
private static String garbageCollectorString() throws IOException { String path = Tweaks.v().getGarbageCollectorPath(); String ret = ResourceReader.getResource(path); ret = ret.replace("$$__device__$$", Tweaks.v().getDeviceFunctionQualifier()); ret = ret.replace("$$__global$$", Tweaks.v().getGlobalAddressSpaceQualifier()); return ret; }
private String headerString(boolean unix) throws IOException { assert (m_configuration != null); String defines = ""; if (m_configuration.getArrayChecks()) defines += "#define ARRAY_CHECKS\n"; String specific_path; if (unix) specific_path = Tweaks.v().getUnixHeaderPath(); else specific_path = Tweaks.v().getWindowsHeaderPath(); if (specific_path == null) return ""; String both_path = Tweaks.v().getBothHeaderPath(); String both_header = ""; if (both_path != null) both_header = ResourceReader.getResource(both_path); String specific_header = ResourceReader.getResource(specific_path); String barrier_path = Tweaks.v().getBarrierPath(); String barrier_code = ""; if (barrier_path != null) barrier_code = ResourceReader.getResource(barrier_path); return defines + "\n" + specific_header + "\n" + both_header + "\n" + barrier_code; }
/** Return the next token from this iterator, or null if the last token has been returned. */ public String next() throws IOException { if (done) { return null; } for (; ; ) { if (line == null) { line = reader.readLineSkippingComments(); if (line == null) { done = true; return null; } pos = 0; } buf.setLength(0); lastpos = pos; pos = nextToken(pos); if (pos < 0) { line = null; continue; } return buf.toString(); } }
/** * Return a string description of the position of the last line returned by readLine() or * readLineSkippingComments(). */ public String describePosition() { return reader.describePosition() + ':' + (lastpos + 1); }
/** * Return the one-based line number of the line of the last token returned by next(). Should only * be called after a call to next(); otherwise the return value is undefined. */ public int getLineNumber() { return reader.getLineNumber(); }