From: <ipe...@us...> - 2009-03-03 00:36:49
|
Revision: 7865 http://x10.svn.sourceforge.net/x10/?rev=7865&view=rev Author: ipeshansky Date: 2009-03-03 00:36:46 +0000 (Tue, 03 Mar 2009) Log Message: ----------- Fix XTENLANG-322 by adding an implementation of structural equality Modified Paths: -------------- trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/MessagePassingCodeGenerator.java trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/SharedVarsMethods.java trunk/x10.runtime.17/src-cpp/x10/io/NativeInputStream.cc trunk/x10.runtime.17/src-cpp/x10/io/NativeInputStream.h trunk/x10.runtime.17/src-cpp/x10/io/NativeOutputStream.cc trunk/x10.runtime.17/src-cpp/x10/io/NativeOutputStream.h trunk/x10.runtime.17/src-cpp/x10/lang/Object.h trunk/x10.runtime.17/src-cpp/x10/lang/Ref.h trunk/x10.runtime.17/src-cpp/x10/lang/String.cc trunk/x10.runtime.17/src-cpp/x10/lang/String.h trunk/x10.runtime.17/src-cpp/x10/lang/Throwable.cc trunk/x10.runtime.17/src-cpp/x10/lang/Throwable.h trunk/x10.runtime.17/src-cpp/x10/lang/ValRail.h trunk/x10.runtime.17/src-cpp/x10/lang/Value.h trunk/x10.runtime.17/src-cpp/x10aux/basic_functions.h trunk/x10.runtime.17/src-cpp/x10aux/bootstrap.h trunk/x10.runtime.17/src-cpp/x10aux/class_cast.h Modified: trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/MessagePassingCodeGenerator.java =================================================================== --- trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/MessagePassingCodeGenerator.java 2009-03-02 15:43:22 UTC (rev 7864) +++ trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/MessagePassingCodeGenerator.java 2009-03-03 00:36:46 UTC (rev 7865) @@ -33,6 +33,8 @@ import static polyglot.ext.x10cpp.visit.SharedVarsMethods.SERIALIZE_BODY_METHOD; import static polyglot.ext.x10cpp.visit.SharedVarsMethods.SERIALIZE_ID_METHOD; import static polyglot.ext.x10cpp.visit.SharedVarsMethods.STATIC_INIT; +import static polyglot.ext.x10cpp.visit.SharedVarsMethods.STRUCT_EQUALS; +import static polyglot.ext.x10cpp.visit.SharedVarsMethods.STRUCT_EQUALS_METHOD; import static polyglot.ext.x10cpp.visit.SharedVarsMethods.THIS; import static polyglot.ext.x10cpp.visit.SharedVarsMethods.VOID; import static polyglot.ext.x10cpp.visit.SharedVarsMethods.VOID_PTR; @@ -181,6 +183,7 @@ import polyglot.types.ClassType; import polyglot.types.CodeDef; import polyglot.types.CodeInstance; +import polyglot.types.FieldInstance; import polyglot.types.Flags; import polyglot.types.InitializerInstance; import polyglot.types.LocalDef; @@ -1092,12 +1095,12 @@ n.printBlock(member, sw, tr); } + X10TypeSystem xts = (X10TypeSystem) tr.typeSystem(); // generate proxy methods for an overridden method's superclass overloads if (superClass != null) { // first gather a set of all the method names in the current class ArrayList<Name> mnames = getMethodNames(members); - X10TypeSystem xts = (X10TypeSystem) tr.typeSystem(); // then, for each one for (Name mname : mnames) { // get the list of overloads that this class should expose @@ -1194,7 +1197,55 @@ } } - if (extractInits(currentClass, STATIC_INIT, VOID, members, true)) { + // Generate structEquals for values + if (xts.isValueType(currentClass)) { + h.write("public: "); + h.write("virtual "); + emitter.printType(xts.Boolean(), h); + h.write(" "+mangled_method_name(STRUCT_EQUALS_METHOD)+"("); + emitter.printType(xts.Object(), h); + h.write(" p0"); + h.write(");"); h.newline(); + + emitter.printTemplateSignature(currentClass.typeArguments(), sw); + emitter.printType(xts.Boolean(), sw); + sw.write(" " + emitter.translateType(currentClass, false) + + "::" + mangled_method_name(STRUCT_EQUALS_METHOD) + "("); + emitter.printType(xts.Object(), sw); + sw.write(" p0"); + sw.write(") {"); sw.newline(4); sw.begin(0); + sw.write("if (p0.operator->() == this) return true; // short-circuit trivial equality"); + sw.newline(); + sw.write("if (!this->" + emitter.translateType(superClass) + "::" + + mangled_method_name(STRUCT_EQUALS_METHOD) + "(p0))"); + sw.newline(4); sw.begin(0); + sw.write("return false;"); + sw.end(); sw.newline(); + emitter.printType(currentClass, sw); + sw.write(" that ="); + sw.allowBreak(4, " "); + sw.write("("); sw.begin(0); + emitter.printType(currentClass, sw); + sw.end(); sw.write(") p0;"); + sw.newline(); + for (FieldInstance fi : currentClass.fields()) { + if (fi.flags().isStatic()) + continue; + if (!xts.isValueType(fi.type())) + continue; + String name = fi.name().toString(); + sw.write("if (!"+STRUCT_EQUALS+"(this->" + mangled_field_name(name) + + ", that->" + mangled_field_name(name) + "))"); + sw.newline(4); sw.begin(0); + sw.write("return false;"); + sw.end(); sw.newline(); + } + sw.write("return true;"); + sw.end(); sw.newline(); + sw.write("}"); sw.newline(); + } + + if (extractInits(currentClass, STATIC_INIT, VOID, members, true)) { // define field that triggers initalisation-time registration of // static init function sw.write("static " + VOID_PTR + " __init__"+getUniqueId_() + Modified: trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/SharedVarsMethods.java =================================================================== --- trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/SharedVarsMethods.java 2009-03-02 15:43:22 UTC (rev 7864) +++ trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/SharedVarsMethods.java 2009-03-03 00:36:46 UTC (rev 7865) @@ -78,6 +78,8 @@ static final String DESERIALIZE_METHOD = "_deserialize"; static final String DESERIALIZER_METHOD = "_deserializer"; static final String DESERIALIZE_BODY_METHOD = "_deserialize_body"; + static final String STRUCT_EQUALS = "x10aux::struct_equals"; + static final String STRUCT_EQUALS_METHOD = "_struct_equals"; static final String VIM_MODELINE = "vim:tabstop=4:shiftwidth=4:expandtab"; Modified: trunk/x10.runtime.17/src-cpp/x10/io/NativeInputStream.cc =================================================================== --- trunk/x10.runtime.17/src-cpp/x10/io/NativeInputStream.cc 2009-03-02 15:43:22 UTC (rev 7864) +++ trunk/x10.runtime.17/src-cpp/x10/io/NativeInputStream.cc 2009-03-03 00:36:46 UTC (rev 7865) @@ -22,6 +22,15 @@ return i; } +x10_boolean NativeInputStream::_struct_equals(ref<Object> p0) { + if (p0.operator->() == this) return true; // short-circuit trivial equality + if (!this->Value::_struct_equals(p0)) + return false; +// ref<NativeInputStream> that = (ref<NativeInputStream>) p0; +// if (!struct_equals(this->FMGL(stream), that->FMGL(stream))) +// return false; + return true; +} DEFINE_RTT(NativeInputStream); Modified: trunk/x10.runtime.17/src-cpp/x10/io/NativeInputStream.h =================================================================== --- trunk/x10.runtime.17/src-cpp/x10/io/NativeInputStream.h 2009-03-02 15:43:22 UTC (rev 7864) +++ trunk/x10.runtime.17/src-cpp/x10/io/NativeInputStream.h 2009-03-03 00:36:46 UTC (rev 7865) @@ -1,7 +1,7 @@ #ifndef X10_IO_NATIVEINPUTSTREAM_H #define X10_IO_NATIVEINPUTSTREAM_H -#include <x10/lang/Ref.h> +#include <x10/lang/Value.h> namespace x10 { @@ -11,18 +11,18 @@ namespace io { - class NativeInputStream : public x10::lang::Ref { + class NativeInputStream : public x10::lang::Value { public: class RTT : public x10aux::RuntimeType { public: static RTT* const it; virtual void init() { - initParents(1,x10aux::getRTT<x10::lang::Ref>()); + initParents(1,x10aux::getRTT<x10::lang::Value>()); } virtual const char *name() const { - return "x10.io.InputStreamReader.NativeInputStream"; + return "x10.io.InputStreamReader.InputStream"; } }; @@ -49,6 +49,8 @@ x10_int off, x10_int len); + virtual x10_boolean _struct_equals(x10aux::ref<x10::lang::Object> p0); + virtual x10_int available() { return 0; } Modified: trunk/x10.runtime.17/src-cpp/x10/io/NativeOutputStream.cc =================================================================== --- trunk/x10.runtime.17/src-cpp/x10/io/NativeOutputStream.cc 2009-03-02 15:43:22 UTC (rev 7864) +++ trunk/x10.runtime.17/src-cpp/x10/io/NativeOutputStream.cc 2009-03-03 00:36:46 UTC (rev 7865) @@ -31,6 +31,16 @@ this->write((x10_int) b->operator[](off + i)); } +x10_boolean NativeOutputStream::_struct_equals(ref<Object> p0) { + if (p0.operator->() == this) return true; // short-circuit trivial equality + if (!this->Value::_struct_equals(p0)) + return false; +// ref<NativeOutputStream> that = (ref<NativeOutputStream>) p0; +// if (!struct_equals(this->FMGL(stream), that->FMGL(stream))) +// return false; + return true; +} + /* void NativeOutputStream::_printf(const char* format, ...) { va_list parms; Modified: trunk/x10.runtime.17/src-cpp/x10/io/NativeOutputStream.h =================================================================== --- trunk/x10.runtime.17/src-cpp/x10/io/NativeOutputStream.h 2009-03-02 15:43:22 UTC (rev 7864) +++ trunk/x10.runtime.17/src-cpp/x10/io/NativeOutputStream.h 2009-03-03 00:36:46 UTC (rev 7865) @@ -1,7 +1,7 @@ #ifndef X10_IO_OUTPUTSTREAM_H #define X10_IO_OUTPUTSTREAM_H -#include <x10/lang/Ref.h> +#include <x10/lang/Value.h> namespace x10 { @@ -12,18 +12,18 @@ namespace io { - class NativeOutputStream : public x10::lang::Ref { + class NativeOutputStream : public x10::lang::Value { public: class RTT : public x10aux::RuntimeType { public: static RTT* const it; virtual void init() { - initParents(1,x10aux::getRTT<x10::lang::Ref>()); + initParents(1,x10aux::getRTT<x10::lang::Value>()); } virtual const char *name() const { - return "x10.io.OutputStreamWriter.NativeOutputStream"; + return "x10.io.OutputStreamWriter.OutputStream"; } }; @@ -42,6 +42,7 @@ virtual void write(x10aux::ref<x10::lang::Rail<x10_byte> > b, x10_int off, x10_int len); virtual void write(x10aux::ref<x10::lang::ValRail<x10_byte> > b, x10_int off, x10_int len); + virtual x10_boolean _struct_equals(x10aux::ref<x10::lang::Object> p0); }; } } Modified: trunk/x10.runtime.17/src-cpp/x10/lang/Object.h =================================================================== --- trunk/x10.runtime.17/src-cpp/x10/lang/Object.h 2009-03-02 15:43:22 UTC (rev 7864) +++ trunk/x10.runtime.17/src-cpp/x10/lang/Object.h 2009-03-03 00:36:46 UTC (rev 7865) @@ -80,6 +80,12 @@ virtual x10_int hashCode() = 0; virtual x10aux::ref<String> toString() = 0; + // Needed for linking - non-values should not override + virtual x10_boolean _struct_equals(x10aux::ref<Object> other) { + if (other == x10aux::ref<Object>(this)) return true; + return false; + } + }; } Modified: trunk/x10.runtime.17/src-cpp/x10/lang/Ref.h =================================================================== --- trunk/x10.runtime.17/src-cpp/x10/lang/Ref.h 2009-03-02 15:43:22 UTC (rev 7864) +++ trunk/x10.runtime.17/src-cpp/x10/lang/Ref.h 2009-03-03 00:36:46 UTC (rev 7865) @@ -71,10 +71,16 @@ virtual x10aux::ref<String> toString(); virtual bool equals(x10aux::ref<Object> other) { - if (other==x10aux::ref<Ref>(this)) return true; + if (other == x10aux::ref<Ref>(this)) return true; return false; } + // Needed for linking - do not override + virtual x10_boolean _struct_equals(x10aux::ref<Object> other) { + if (other == x10aux::ref<Ref>(this)) return true; + return false; + } + }; } Modified: trunk/x10.runtime.17/src-cpp/x10/lang/String.cc =================================================================== --- trunk/x10.runtime.17/src-cpp/x10/lang/String.cc 2009-03-02 15:43:22 UTC (rev 7864) +++ trunk/x10.runtime.17/src-cpp/x10/lang/String.cc 2009-03-03 00:36:46 UTC (rev 7865) @@ -20,6 +20,7 @@ return x10aux::hash(reinterpret_cast<const unsigned char*>(FMGL(content)), length()); } +// TODO: merge with _struct_equals x10_boolean String::equals(ref<Object> other) { if (!x10aux::concrete_instanceof<String>(other)) return false; // now we can downcast the Object to String @@ -178,6 +179,16 @@ return format_impl(format, ref<AnyRail<ref<Object> > >(parms)); } +x10_boolean String::_struct_equals(ref<Object> p0) { + if (p0.operator->() == this) return true; // short-circuit trivial equality + if (!this->Value::_struct_equals(p0)) + return false; + ref<String> that = (ref<String>) p0; + if (strcmp(this->FMGL(content), that->FMGL(content))) + return false; + return true; +} + const serialization_id_t String::_serialization_id = DeserializationDispatcher::addDeserializer(String::_deserialize<Object>); Modified: trunk/x10.runtime.17/src-cpp/x10/lang/String.h =================================================================== --- trunk/x10.runtime.17/src-cpp/x10/lang/String.h 2009-03-02 15:43:22 UTC (rev 7864) +++ trunk/x10.runtime.17/src-cpp/x10/lang/String.h 2009-03-03 00:36:46 UTC (rev 7865) @@ -142,6 +142,8 @@ static x10aux::ref<String> format(x10aux::ref<String> format, x10aux::ref<Rail<x10aux::ref<Object> > > parms); + virtual x10_boolean _struct_equals(x10aux::ref<x10::lang::Object> p0); + String () : FMGL(content)(NULL) { } virtual ~String () { x10aux::dealloc(FMGL(content)); Modified: trunk/x10.runtime.17/src-cpp/x10/lang/Throwable.cc =================================================================== --- trunk/x10.runtime.17/src-cpp/x10/lang/Throwable.cc 2009-03-02 15:43:22 UTC (rev 7864) +++ trunk/x10.runtime.17/src-cpp/x10/lang/Throwable.cc 2009-03-03 00:36:46 UTC (rev 7865) @@ -256,6 +256,23 @@ fprintf(stderr, "\tat %s\n", (*trace)[i]->c_str()); } +x10_boolean Throwable::_struct_equals(ref<Object> p0) { + if (p0.operator->() == this) return true; // short-circuit trivial equality + if (!this->Value::_struct_equals(p0)) + return false; + ref<Throwable> that = (ref<Throwable>) p0; + if (this->FMGL(cause) != that->FMGL(cause)) + return false; + if (!x10aux::struct_equals(this->FMGL(message), that->FMGL(message))) + return false; + if (this->FMGL(trace_size) != that->FMGL(trace_size)) + return false; + for (int i = 0; i < this->FMGL(trace_size); i++) + if (this->FMGL(trace)[i] != that->FMGL(trace)[i]) + return false; + return true; +} + DEFINE_RTT(Throwable); // vim:tabstop=4:shiftwidth=4:expandtab Modified: trunk/x10.runtime.17/src-cpp/x10/lang/Throwable.h =================================================================== --- trunk/x10.runtime.17/src-cpp/x10/lang/Throwable.h 2009-03-02 15:43:22 UTC (rev 7864) +++ trunk/x10.runtime.17/src-cpp/x10/lang/Throwable.h 2009-03-03 00:36:46 UTC (rev 7865) @@ -85,6 +85,8 @@ virtual StringRail getStackTrace(); virtual void printStackTrace(); + virtual x10_boolean _struct_equals(x10aux::ref<x10::lang::Object> p0); + static const x10aux::serialization_id_t _serialization_id; virtual void _serialize_id(x10aux::serialization_buffer &buf, x10aux::addr_map &m) { Modified: trunk/x10.runtime.17/src-cpp/x10/lang/ValRail.h =================================================================== --- trunk/x10.runtime.17/src-cpp/x10/lang/ValRail.h 2009-03-02 15:43:22 UTC (rev 7864) +++ trunk/x10.runtime.17/src-cpp/x10/lang/ValRail.h 2009-03-03 00:36:46 UTC (rev 7865) @@ -110,14 +110,22 @@ return new (x10aux::alloc<Iterator>()) Iterator(this); } - virtual bool equals(x10aux::ref<Object> other) { - if (!_type()->concreteInstanceOf(other)) return false; + virtual x10_boolean _struct_equals(x10aux::ref<Object> other) { + if (other.operator->() == this) return true; // short-circuit trivial equality + if (!this->Value::_struct_equals(other)) return false; x10aux::ref<ValRail> other_rail = other; // different sizes so false - if (other_rail->FMGL(length)!=this->FMGL(length)) return false; - for (x10_int index=0 ; index<this->FMGL(length) ; ++index) { - if ((*other_rail)[index]!=this->raw()[index]) - return false; + if (other_rail->FMGL(length) != this->FMGL(length)) return false; + if (x10aux::getRTT<T>()->subtypeOf(x10aux::getRTT<Value>())) { + // Value type; structurally compare elements + for (x10_int i = 0; i < this->FMGL(length); ++i) + if (!x10aux::struct_equals((*other_rail)[i], this->raw()[i])) + return false; + } else { + // Ref type; simple reference equality + for (x10_int i = 0; i < this->FMGL(length); ++i) + if ((*other_rail)[i] != this->raw()[i]) + return false; } return true; } Modified: trunk/x10.runtime.17/src-cpp/x10/lang/Value.h =================================================================== --- trunk/x10.runtime.17/src-cpp/x10/lang/Value.h 2009-03-02 15:43:22 UTC (rev 7864) +++ trunk/x10.runtime.17/src-cpp/x10/lang/Value.h 2009-03-03 00:36:46 UTC (rev 7865) @@ -70,7 +70,13 @@ virtual x10aux::ref<String> toString(); virtual x10_boolean equals(x10aux::ref<Object> other) { - if (!x10aux::concrete_instanceof<Value>(other)) return false; + if (!x10aux::instanceof<Value>(other)) return false; + return this->_struct_equals(other); + } + + virtual x10_boolean _struct_equals(x10aux::ref<Object> other) { + if (!_type()->concreteInstanceOf(other)) + return false; // now compare fields but there aren't any return true; } Modified: trunk/x10.runtime.17/src-cpp/x10aux/basic_functions.h =================================================================== --- trunk/x10.runtime.17/src-cpp/x10aux/basic_functions.h 2009-03-02 15:43:22 UTC (rev 7864) +++ trunk/x10.runtime.17/src-cpp/x10aux/basic_functions.h 2009-03-03 00:36:46 UTC (rev 7865) @@ -84,7 +84,52 @@ static inline x10_boolean equals(const x10_char x, const x10_char y) { return x==y; } static inline x10_boolean equals(const x10_boolean x, const x10_boolean y) { return x==y; } + template<class T, class U> + static inline x10_boolean struct_equals(ref<T> x, ref<U> y) { return x->_struct_equals(y); } + template<class T> + static inline x10_boolean struct_equals(ref<T> x, x10_double y) { return false; } + template<class T> + static inline x10_boolean struct_equals(ref<T> x, x10_float y) { return false; } + template<class T> + static inline x10_boolean struct_equals(ref<T> x, x10_long y) { return false; } + template<class T> + static inline x10_boolean struct_equals(ref<T> x, x10_int y) { return false; } + template<class T> + static inline x10_boolean struct_equals(ref<T> x, x10_short y) { return false; } + template<class T> + static inline x10_boolean struct_equals(ref<T> x, x10_byte y) { return false; } + template<class T> + static inline x10_boolean struct_equals(ref<T> x, x10_char y) { return false; } + template<class T> + static inline x10_boolean struct_equals(ref<T> x, x10_boolean y) { return false; } + + template<class T> + static inline x10_boolean struct_equals(x10_double y, ref<T> x) { return false; } + template<class T> + static inline x10_boolean struct_equals(x10_float y, ref<T> x) { return false; } + template<class T> + static inline x10_boolean struct_equals(x10_long y, ref<T> x) { return false; } + template<class T> + static inline x10_boolean struct_equals(x10_int y, ref<T> x) { return false; } + template<class T> + static inline x10_boolean struct_equals(x10_short y, ref<T> x) { return false; } + template<class T> + static inline x10_boolean struct_equals(x10_byte y, ref<T> x) { return false; } + template<class T> + static inline x10_boolean struct_equals(x10_char y, ref<T> x) { return false; } + template<class T> + static inline x10_boolean struct_equals(x10_boolean y, ref<T> x) { return false; } + + static inline x10_boolean struct_equals(const x10_double x, const x10_double y) { return x==y; } + static inline x10_boolean struct_equals(const x10_float x, const x10_float y) { return x==y; } + static inline x10_boolean struct_equals(const x10_long x, const x10_long y) { return x==y; } + static inline x10_boolean struct_equals(const x10_int x, const x10_int y) { return x==y; } + static inline x10_boolean struct_equals(const x10_short x, const x10_short y) { return x==y; } + static inline x10_boolean struct_equals(const x10_byte x, const x10_byte y) { return x==y; } + static inline x10_boolean struct_equals(const x10_char x, const x10_char y) { return x==y; } + static inline x10_boolean struct_equals(const x10_boolean x, const x10_boolean y) { return x==y; } + template<class T> static inline x10_int hash_code(ref<T> x) { return x->hashCode(); } Modified: trunk/x10.runtime.17/src-cpp/x10aux/bootstrap.h =================================================================== --- trunk/x10.runtime.17/src-cpp/x10aux/bootstrap.h 2009-03-02 15:43:22 UTC (rev 7864) +++ trunk/x10.runtime.17/src-cpp/x10aux/bootstrap.h 2009-03-03 00:36:46 UTC (rev 7865) @@ -44,6 +44,9 @@ : main(main_), args(args_) { } + virtual x10_boolean _struct_equals(x10aux::ref<x10::lang::Object> p0) { + return false; // FIXME: should we be able to compare function types structurally? + } const x10aux::RuntimeType *_type() const {return x10aux::getRTT<x10::lang::VoidFun_0_0>();} @@ -62,7 +65,7 @@ try { #endif setlinebuf(stdout); - + x10aux::barrier(); // Initialise enough state to make this 'main' thread look like a normal x10 thread Modified: trunk/x10.runtime.17/src-cpp/x10aux/class_cast.h =================================================================== --- trunk/x10.runtime.17/src-cpp/x10aux/class_cast.h 2009-03-02 15:43:22 UTC (rev 7864) +++ trunk/x10.runtime.17/src-cpp/x10aux/class_cast.h 2009-03-03 00:36:46 UTC (rev 7865) @@ -156,6 +156,7 @@ ValueBox(T v_) : v(v_) { } virtual x10_int hashCode() { return x10aux::hash_code(v); } virtual x10_boolean equals(x10aux::ref<Object> other) { return x10aux::equals(v, other); } + virtual x10_boolean _struct_equals(x10aux::ref<x10::lang::Object> p0) { return x10aux::struct_equals(v, p0); } virtual ref<x10::lang::String> toString() { return x10aux::to_string(v); } }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <spa...@us...> - 2009-03-04 02:56:21
|
Revision: 7872 http://x10.svn.sourceforge.net/x10/?rev=7872&view=rev Author: sparksparkspark Date: 2009-03-04 02:56:14 +0000 (Wed, 04 Mar 2009) Log Message: ----------- Publicise place constuctor temporarily (hack until cuda runtime support is completed) Add @Cuda annotation Add cuda backend, mostly stubs for now (to use: -ext x10cuda) Some streams refactorings and improvements build.xml now builds cuda backend cpp delegate factory is refactored Modified Paths: -------------- trunk/x10.compiler.p3/src/polyglot/ext/x10/ast/X10DelFactory_c.java trunk/x10.cppbackend.17/.classpath trunk/x10.cppbackend.17/build.xml trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/ExtensionInfo.java trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/ast/X10CPPDelFactory_c.java trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/MessagePassingCodeGenerator.java trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/X10CPPTranslator.java trunk/x10.cppbackend.17/src/x10c/util/ClassifiedStream.java trunk/x10.cppbackend.17/src/x10c/util/StreamWrapper.java trunk/x10.cppbackend.17/src/x10c/util/WriterStreams.java trunk/x10.runtime.17/src-x10/x10/lang/Place.x10 Added Paths: ----------- trunk/x10.cppbackend.17/src/polyglot/ext/x10cuda/ trunk/x10.cppbackend.17/src/polyglot/ext/x10cuda/ExtensionInfo.java trunk/x10.cppbackend.17/src/polyglot/ext/x10cuda/ast/ trunk/x10.cppbackend.17/src/polyglot/ext/x10cuda/ast/X10CUDADelFactory_c.java trunk/x10.cppbackend.17/src/polyglot/ext/x10cuda/types/ trunk/x10.cppbackend.17/src/polyglot/ext/x10cuda/types/X10CUDAContext_c.java trunk/x10.cppbackend.17/src/polyglot/ext/x10cuda/types/X10CUDATypeSystem_c.java trunk/x10.cppbackend.17/src/polyglot/ext/x10cuda/visit/ trunk/x10.cppbackend.17/src/polyglot/ext/x10cuda/visit/CUDACodeGenerator.java trunk/x10.runtime.17/src-x10/x10/compiler/Cuda.x10 Modified: trunk/x10.compiler.p3/src/polyglot/ext/x10/ast/X10DelFactory_c.java =================================================================== --- trunk/x10.compiler.p3/src/polyglot/ext/x10/ast/X10DelFactory_c.java 2009-03-03 20:17:11 UTC (rev 7871) +++ trunk/x10.compiler.p3/src/polyglot/ext/x10/ast/X10DelFactory_c.java 2009-03-04 02:56:14 UTC (rev 7872) @@ -55,7 +55,7 @@ * to the X10PrettyPrinterVisitor. */ public JL delAsyncImpl() { - return new TD(); + return delNodeImpl(); } /** @@ -63,7 +63,7 @@ * to the X10PrettyPrinterVisitor. */ public JL delAtEachImpl() { - return new TD(); + return delNodeImpl(); } /** @@ -71,7 +71,7 @@ * to the X10PrettyPrinterVisitor. */ public JL delForEachImpl() { - return new TD(); + return delNodeImpl(); } /** @@ -79,7 +79,7 @@ * to the X10PrettyPrinterVisitor. */ public JL delForLoopImpl() { - return new TD(); + return delNodeImpl(); } /** @@ -87,7 +87,7 @@ * to the X10PrettyPrinterVisitor. */ public JL delFinishImpl() { - return new TD(); + return delNodeImpl(); } /** @@ -95,7 +95,7 @@ * to the X10PrettyPrinterVisitor. */ public JL delClosureImpl() { - return new TD(); + return delNodeImpl(); } /** @@ -103,7 +103,7 @@ * to the X10PrettyPrinterVisitor. */ public JL delFutureImpl() { - return new TD(); + return delNodeImpl(); } } Modified: trunk/x10.cppbackend.17/.classpath =================================================================== --- trunk/x10.cppbackend.17/.classpath 2009-03-03 20:17:11 UTC (rev 7871) +++ trunk/x10.cppbackend.17/.classpath 2009-03-04 02:56:14 UTC (rev 7872) @@ -2,10 +2,10 @@ <classpath> <classpathentry kind="src" path="src"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> - <classpathentry combineaccessrules="false" kind="src" path="/lpg.runtime.java"/> <classpathentry combineaccessrules="false" kind="src" path="/x10.compiler.p3"/> <classpathentry combineaccessrules="false" kind="src" path="/x10.common.17"/> <classpathentry combineaccessrules="false" kind="src" path="/x10.constraints"/> <classpathentry combineaccessrules="false" kind="src" path="/polyglot3"/> + <classpathentry kind="lib" path="/x10.dist/lib/lpg.jar"/> <classpathentry kind="output" path="classes"/> </classpath> Modified: trunk/x10.cppbackend.17/build.xml =================================================================== --- trunk/x10.cppbackend.17/build.xml 2009-03-03 20:17:11 UTC (rev 7871) +++ trunk/x10.cppbackend.17/build.xml 2009-03-04 02:56:14 UTC (rev 7872) @@ -43,7 +43,7 @@ </target> <target name="jar" depends="build"> <jar jarfile="${build}/${jar}"> - <fileset dir="${build}" includes="x10c/**,polyglot/ext/x10cpp/**,data/**" excludes="${jar}"/> + <fileset dir="${build}" includes="x10c/**,polyglot/ext/x10*/**,data/**" excludes="${jar}"/> </jar> </target> <target name="build" depends="init"> Modified: trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/ExtensionInfo.java =================================================================== --- trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/ExtensionInfo.java 2009-03-03 20:17:11 UTC (rev 7871) +++ trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/ExtensionInfo.java 2009-03-04 02:56:14 UTC (rev 7872) @@ -61,29 +61,30 @@ } @Override - protected void initTypeSystem() { - // Inline from superclass, replacing SourceClassResolver - try { - TopLevelResolver r = new X10CPPSourceClassResolver(compiler, this, getOptions().constructFullClasspath(), - getOptions().compile_command_line_only, - getOptions().ignore_mod_times); + protected void initTypeSystem() { + // Inline from superclass, replacing SourceClassResolver + try { + TopLevelResolver r = + new X10CPPSourceClassResolver(compiler, this, getOptions().constructFullClasspath(), + getOptions().compile_command_line_only, + getOptions().ignore_mod_times); - // Resolver to handle lookups of member classes. - if (true || TypeSystem.SERIALIZE_MEMBERS_WITH_CONTAINER) { - MemberClassResolver mcr = new MemberClassResolver(ts, r, true); - r = mcr; - } + // Resolver to handle lookups of member classes. + if (true || TypeSystem.SERIALIZE_MEMBERS_WITH_CONTAINER) { + MemberClassResolver mcr = new MemberClassResolver(ts, r, true); + r = mcr; + } - ts.initialize(r, this); - } - catch (SemanticException e) { - throw new InternalCompilerError( - "Unable to initialize type system: " + e.getMessage(), e); - } + ts.initialize(r, this); } + catch (SemanticException e) { + throw new InternalCompilerError( + "Unable to initialize type system: " + e.getMessage(), e); + } + } - // ================================= + // ================================= // X10-specific goals and scheduling // ================================= protected Scheduler createScheduler() { Modified: trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/ast/X10CPPDelFactory_c.java =================================================================== --- trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/ast/X10CPPDelFactory_c.java 2009-03-03 20:17:11 UTC (rev 7871) +++ trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/ast/X10CPPDelFactory_c.java 2009-03-04 02:56:14 UTC (rev 7872) @@ -10,36 +10,38 @@ */ package polyglot.ext.x10cpp.ast; -import polyglot.ast.Block; -import polyglot.ast.Conditional; -import polyglot.ast.ForInit; import polyglot.ast.JL; import polyglot.ast.Node; import polyglot.ext.x10.ast.X10DelFactory_c; import polyglot.ext.x10.extension.X10Del_c; import polyglot.ext.x10.extension.X10Ext; -import polyglot.ext.x10.types.X10NamedType; -import polyglot.ext.x10.types.X10TypeSystem; -import polyglot.ext.x10cpp.Configuration; +import polyglot.ext.x10.visit.X10DelegatingVisitor; import polyglot.ext.x10cpp.types.X10CPPContext_c; import polyglot.ext.x10cpp.visit.MessagePassingCodeGenerator; import polyglot.types.Context; -import polyglot.types.SemanticException; -import polyglot.types.Type; import polyglot.util.CodeWriter; import polyglot.visit.Translator; -import polyglot.visit.TypeChecker; import x10c.util.StreamWrapper; /** * @author Christian Grothoff + * @author Igor Peshansky + * @author Dave Cunningham */ public class X10CPPDelFactory_c extends X10DelFactory_c { /** - * A delegate that redirects translate to the X10PrettyPrinterVisitor. + * Used to allow subclasses to override the code generator. */ - public static class TD extends X10Del_c { + protected X10DelegatingVisitor makeCodeGenerator(CodeWriter w, Translator tr) { + return new MessagePassingCodeGenerator((StreamWrapper)w,tr); + } + + + /** + * A delegate that redirects translate to the object given by makeCodeGenerator. + */ + public class TD extends X10Del_c { public void translate(CodeWriter w, Translator tr) { if (jl() instanceof Node) { Node n = (Node) jl(); @@ -47,179 +49,16 @@ if (ext != null && ext.comment() != null) w.write(ext.comment()); } - new MessagePassingCodeGenerator((StreamWrapper)w,tr).visitAppropriate(jl()); + makeCodeGenerator(w, tr).visitAppropriate(jl()); } }; public JL delNodeImpl() { -// return new X10Del_c(); return new TD(); } - protected JL delIdImpl() { - return new TD(); - } - /** - * For each term, add the delegate that redirects translate to the - * X10PrettyPrinterVisitor. - */ - public JL delTermImpl() { - return new TD(); - } - - /** - * For each method declaration, add the delegate that redirects translate - * to the X10PrettyPrinterVisitor. - */ - public JL delMethodDeclImpl() { - return new TD(); - } - - /** - * For each constructor declaration, add the delegate that redirects translate - * to the X10PrettyPrinterVisitor. - */ - public JL delConstructorDeclImpl() { - return new TD(); - } - - /** - * For each field declaration, add the delegate that redirects translate - * to the X10PrettyPrinterVisitor. - */ - public JL delFieldDeclImpl() { - return new TD(); - } - - /** - * For ternaries, also implement a separate typeCheck method. - */ - public JL delConditionalImpl() { - return new TD() { - public Node typeCheck(TypeChecker tc) throws SemanticException { - X10TypeSystem ts = (X10TypeSystem) tc.typeSystem(); - Conditional c = (Conditional) jl(); - Type t1 = c.consequent().type(); - Type t2 = c.alternative().type(); - /* - if (t1.isNull() && t2.isNumeric()) - return c.type(ts.createNullableType(t2.position(), (X10NamedType) t2)); - if (t1.isNumeric() && t2.isNull()) - return c.type(ts.createNullableType(t1.position(), (X10NamedType) t1)); - */ - return c.typeCheck(tc); - } - }; - } - - /** - * For each canonical type node, add the delegate that redirects translate - * to the X10PrettyPrinterVisitor. - */ - public JL delCanonicalTypeNodeImpl() { - return new TD(); - } - - /** - * For each TypeDecl node, add the delegate that redirects translate - * to the X10PrettyPrinterVisitor. - */ - public JL delTypeDeclNodeImpl() { - return new TD(); - } - - /** - * For each future type node, add the delegate that redirects translate - * to the X10PrettyPrinterVisitor. - */ - public JL delFutureNodeImpl() { - return new TD(); - } - - /** - * For each import declaration, add the delegate that redirects translate - * to the X10PrettyPrinterVisitor. - */ - public JL delImportImpl() { - return new TD(); - } - - /** - * For each formal parameter, add the delegate that redirects translate - * to the X10PrettyPrinterVisitor. - */ - public JL delFormalImpl() { - return new TD(); - } - - /** - * For each local declaration, add the delegate that redirects translate - * to the X10PrettyPrinterVisitor. - */ - public JL delLocalDeclImpl() { - return new TD(); - } - - /** - * For each async, add the delegate that redirects translate - * to the X10PrettyPrinterVisitor and overrides enterScope. - */ - public JL delAsyncImpl() { - return new TD() { - public Context enterScope(Context c) { - X10CPPContext_c context = (X10CPPContext_c) super.enterScope(c); - context.setinClosure(true); - return context; - } - }; - } - - /** - * For each ateach loop, add the delegate that redirects translate - * to the X10PrettyPrinterVisitor. - */ - public JL delAtEachImpl() { - return new TD(){ - public Context enterScope(Context c) { - X10CPPContext_c context = (X10CPPContext_c) super.enterScope(c); - context.setinClosure(true); - return context; - } - }; - } - - /** - * For each foreach loop, add the delegate that redirects translate - * to the X10PrettyPrinterVisitor. - */ - public JL delForEachImpl() { - return new TD(); - } - - /** - * For each x10 for loop, add the delegate that redirects translate - * to the X10PrettyPrinterVisitor and overrides enterScope. - */ - public JL delForLoopImpl() { - return new TD() { - public Context enterScope(Context c) { - X10CPPContext_c context = (X10CPPContext_c) super.enterScope(c); - return context; - } - }; - } - - /** - * For each finish, add the delegate that redirects translate - * to the X10PrettyPrinterVisitor. - */ - public JL delFinishImpl() { - return new TD(); - } - - /** * For each closure, add the delegate that redirects translate * to the X10PrettyPrinterVisitor and overrides enterScope. */ @@ -233,57 +72,5 @@ }; } - /** - * For each catch block, add the delegate that redirects translate - * to the X10PrettyPrinterVisitor and overrides enterScope. - */ - protected JL delCatchImpl() { - return new TD() { - public Context enterScope(Context c) { - X10CPPContext_c context = (X10CPPContext_c) super.enterScope(c); - return context; - } - }; - } - - /** - * For each for loop, add the delegate that redirects translate - * to the X10PrettyPrinterVisitor and overrides enterChildScope. - */ - protected JL delForImpl() { - return new TD() { - private boolean saveMain = false; - public Context enterChildScope(Node child, Context c) { - X10CPPContext_c context = (X10CPPContext_c) super.enterChildScope(child, c); - if (child instanceof ForInit) { - if (!saveMain) - saveMain = context.isMainMethod(); - context.resetMainMethod(); // FIXME: this will be a problem if SPMD vars or Global vars are used - } else - if (child instanceof Block && saveMain) { - saveMain = false; - // FIXME: [IP] the next line is needed because otherwise the above - // leaves the outer context in the non-main state - ((X10CPPContext_c) c).setMainMethod(); - context.setMainMethod(); - } - return context; - } - }; - } - - /** - * For each future, add the delegate that redirects translate - * to the X10PrettyPrinterVisitor and overrides enterScope. - */ - public JL delFutureImpl() { - return new TD() { - public Context enterScope(Context c) { - X10CPPContext_c context = (X10CPPContext_c) super.enterScope(c); - context.setinClosure(true); - return context; - } - }; - } } Modified: trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/MessagePassingCodeGenerator.java =================================================================== --- trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/MessagePassingCodeGenerator.java 2009-03-03 20:17:11 UTC (rev 7871) +++ trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/MessagePassingCodeGenerator.java 2009-03-04 02:56:14 UTC (rev 7872) @@ -237,12 +237,12 @@ */ public class MessagePassingCodeGenerator extends X10DelegatingVisitor { - private final StreamWrapper sw; - private final Translator tr; - private XCDProcessor xcdProcessor; + protected final StreamWrapper sw; + protected final Translator tr; + protected XCDProcessor xcdProcessor; - Emitter emitter; - ASTQuery query; + protected Emitter emitter; + protected ASTQuery query; public MessagePassingCodeGenerator(StreamWrapper sw, Translator tr) { this.sw = sw; this.tr = tr; @@ -343,7 +343,7 @@ private void extractGenericStaticInits(X10ClassDef cd) { // Always write non-template static decls into the implementation file ClassifiedStream save_w = sw.currentStream(); - ClassifiedStream w = sw.getNewStream(StreamWrapper.StreamClass.CC, false); + ClassifiedStream w = sw.getNewStream(StreamWrapper.CC, false); sw.pushCurrentStream(w); String header = getHeader(cd.asType()); w.write("#include <"+header+">"); w.newline(); @@ -661,17 +661,17 @@ ClassifiedStream save_header = sw.header(); ClassifiedStream save_generic = context.templateFunctions; // Header stream - ClassifiedStream h = sw.getNewStream(StreamWrapper.StreamClass.Header, false); + ClassifiedStream h = sw.getNewStream(StreamWrapper.Header, false); // Stream for generic functions (always in the header, may be empty) - ClassifiedStream g = sw.getNewStream(StreamWrapper.StreamClass.Header, false); + ClassifiedStream g = sw.getNewStream(StreamWrapper.Header, false); context.templateFunctions = g; - StreamWrapper.StreamClass impl = StreamWrapper.StreamClass.CC; + String impl = StreamWrapper.CC; if (def.typeParameters().size() != 0) - impl = StreamWrapper.StreamClass.Header; + impl = StreamWrapper.Header; // Implementation stream (may be after the header) ClassifiedStream w = sw.getNewStream(impl, false); // Dependences guard closing stream (comes at the end of the header) - ClassifiedStream z = sw.getNewStream(StreamWrapper.StreamClass.Header, false); + ClassifiedStream z = sw.getNewStream(StreamWrapper.Header, false); sw.set(h, w); context.setinsideClosure(false); @@ -707,7 +707,7 @@ String pkg = ""; if (context.package_() != null) pkg = context.package_().fullName().toString(); - String incfile = tf.integratedOutputName(pkg, n.name().toString(), StreamWrapper.StreamClass.Closures.toString()); + String incfile = tf.integratedOutputName(pkg, n.name().toString(), StreamWrapper.Closures); w.write("#include \""+incfile+"\""); w.newline(); w.forceNewline(0); @@ -1762,28 +1762,7 @@ } } - boolean nodeHasCudaAnnotation(Node n) { - X10TypeSystem xts = (X10TypeSystem) tr.typeSystem(); - X10Ext ext = (X10Ext) n.ext(); - String annotationName = "Cudable"; - try { - Type cudable = (Type) xts.systemResolver().find(QName.make(annotationName)); - - for (X10ClassType t : ext.annotationMatching(cudable)) { - return true; - } - } catch (SemanticException e) { - return false; // Until the annotation is in the stdlib - //assert false : e; - } - - return false; - } - public void visit(Block_c b) { - if (nodeHasCudaAnnotation(b)) { - sw.write(" /*CUDABLE!*/ "); - } sw.write("{"); sw.newline(); if (b.statements().size() > 0) { @@ -2460,8 +2439,8 @@ // Prepend this stream to closures. Closures are created from the outside in. // Thus, later closures can be used by earlier ones, but not vice versa. ClassifiedStream inc_s = in_template_closure ? - sw.getNewStream(StreamWrapper.StreamClass.Header, sw.header(), false) : - sw.getNewStream(StreamWrapper.StreamClass.Closures, true); + sw.getNewStream(StreamWrapper.Header, sw.header(), false) : + sw.getNewStream(StreamWrapper.Closures, true); sw.pushCurrentStream(inc_s); StreamWrapper inc = sw; @@ -2973,8 +2952,8 @@ // Prepend this stream to closures. Closures are created from the outside in. // Thus, later closures can be used by earlier ones, but not vice versa. ClassifiedStream inc_s = in_template_closure ? - sw.getNewStream(StreamWrapper.StreamClass.Header, sw.header(), false) : - sw.getNewStream(StreamWrapper.StreamClass.Closures, true); + sw.getNewStream(StreamWrapper.Header, sw.header(), false) : + sw.getNewStream(StreamWrapper.Closures, true); sw.pushCurrentStream(inc_s); StreamWrapper inc = sw; Modified: trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/X10CPPTranslator.java =================================================================== --- trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/X10CPPTranslator.java 2009-03-03 20:17:11 UTC (rev 7871) +++ trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/X10CPPTranslator.java 2009-03-04 02:56:14 UTC (rev 7872) @@ -263,13 +263,6 @@ int outputWidth = job.compiler().outputWidth(); Collection outputFiles = job.compiler().outputFiles(); - // Find the public declarations in the file. We'll use these to - // derive the names of the target files. There will be one - // target file per public declaration. If there are no public - // declarations, we'll use the source file name to derive the - // target file name. - List exports = exports(sfn); - try { String opfPath; @@ -291,9 +284,12 @@ continue; X10ClassDecl cd = (X10ClassDecl) decl; String className = cd.classDef().name().toString(); - wstreams = new WriterStreams(className, sfn, pkg, tf, exports, job); + wstreams = new WriterStreams(className, pkg, tf, job); sw = new StreamWrapper(wstreams, outputWidth); + // [DC] TODO: This hack is to ensure the .inc is always generated. + sw.getNewStream(StreamWrapper.Closures, true); opfPath = tf.outputName(pkg, decl.name().toString()); + assert(!opfPath.endsWith("$")); if (!opfPath.endsWith("$")) outputFiles.add(opfPath); translateTopLevelDecl(sw, sfn, decl); if (i.hasNext()) @@ -324,38 +320,6 @@ } } - private void generateGlobalSwitch(StreamWrapper w) { - X10CPPContext_c context = (X10CPPContext_c) this.context(); - DelegateTargetFactory tf = (DelegateTargetFactory) this.tf; - Emitter emitter = new Emitter(this); - for (Iterator k = context.classesWithArrayCopySwitches.keySet().iterator(); k.hasNext(); ) { - ClassType ct = (ClassType) k.next(); - if (ct.isNested()) - ct = ct.container().toClass(); - String pkg = ""; - if (ct.package_() != null) { - pkg = ct.package_().fullName().toString(); - } - String header = tf.outputHeaderName(pkg, ct.name().toString()); - w.write("#include \"" + header + "\""); - w.newline(); - } - for (Iterator k = context.classesWithAsyncSwitches.keySet().iterator(); k.hasNext(); ) { - ClassType ct = (ClassType) k.next(); - if (ct.isNested()) - ct = ct.container().toClass(); - String pkg = ""; - if (ct.package_() != null) { - pkg = ct.package_().fullName().toString(); - } - String header = tf.outputHeaderName(pkg, ct.name().toString()); - w.write("#include \"" + header + "\""); - w.newline(); - } - - w.newline(); - } - /* (non-Javadoc) * @see polyglot.visit.Translator#translate(polyglot.ast.Node) */ Added: trunk/x10.cppbackend.17/src/polyglot/ext/x10cuda/ExtensionInfo.java =================================================================== --- trunk/x10.cppbackend.17/src/polyglot/ext/x10cuda/ExtensionInfo.java (rev 0) +++ trunk/x10.cppbackend.17/src/polyglot/ext/x10cuda/ExtensionInfo.java 2009-03-04 02:56:14 UTC (rev 7872) @@ -0,0 +1,33 @@ +// Licensed Materials - Property of IBM +// (C) Copyright IBM Corporation 2004,2005,2006. All Rights Reserved. +// Note to U.S. Government Users Restricted Rights: Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. +// +// --------------------------------------------------------------------------- + +package polyglot.ext.x10cuda; + +import polyglot.ast.NodeFactory; +import polyglot.ext.x10.ast.X10NodeFactory_c; +import polyglot.ext.x10cuda.ast.X10CUDADelFactory_c; +import polyglot.ext.x10cuda.types.X10CUDATypeSystem_c; +import polyglot.ext.x10cpp.ast.X10CPPExtFactory_c; +import polyglot.types.TypeSystem; + + +/** + * Extension information for x10 extension. + * @author vj -- Adapted from the Polyglot2 ExtensionsInfo for X10 1.5 + */ +public class ExtensionInfo extends polyglot.ext.x10cpp.ExtensionInfo { + + protected NodeFactory createNodeFactory() { + return new X10NodeFactory_c(this, new X10CPPExtFactory_c(), new X10CUDADelFactory_c()) { }; + } + + protected TypeSystem createTypeSystem() { + return new X10CUDATypeSystem_c(); + } + +} + +// vim:tabstop=4:shiftwidth=4:expandtab \ No newline at end of file Added: trunk/x10.cppbackend.17/src/polyglot/ext/x10cuda/ast/X10CUDADelFactory_c.java =================================================================== --- trunk/x10.cppbackend.17/src/polyglot/ext/x10cuda/ast/X10CUDADelFactory_c.java (rev 0) +++ trunk/x10.cppbackend.17/src/polyglot/ext/x10cuda/ast/X10CUDADelFactory_c.java 2009-03-04 02:56:14 UTC (rev 7872) @@ -0,0 +1,30 @@ +/* + * + * (C) Copyright IBM Corporation 2006 + * + * This file is part of X10 Language. + * + */ +/* + * Created on Oct 7, 2004 + */ +package polyglot.ext.x10cuda.ast; + +import polyglot.ext.x10.visit.X10DelegatingVisitor; +import polyglot.ext.x10cpp.ast.X10CPPDelFactory_c; +import polyglot.ext.x10cuda.visit.CUDACodeGenerator; +import polyglot.util.CodeWriter; +import polyglot.visit.Translator; +import x10c.util.StreamWrapper; + +/** + * @author Dave Cunningham + */ +public class X10CUDADelFactory_c extends X10CPPDelFactory_c { + + protected X10DelegatingVisitor makeCodeGenerator(CodeWriter w, Translator tr) { + return new CUDACodeGenerator((StreamWrapper)w,tr); + } + +} + Added: trunk/x10.cppbackend.17/src/polyglot/ext/x10cuda/types/X10CUDAContext_c.java =================================================================== --- trunk/x10.cppbackend.17/src/polyglot/ext/x10cuda/types/X10CUDAContext_c.java (rev 0) +++ trunk/x10.cppbackend.17/src/polyglot/ext/x10cuda/types/X10CUDAContext_c.java 2009-03-04 02:56:14 UTC (rev 7872) @@ -0,0 +1,49 @@ +/* + * + * (C) Copyright IBM Corporation 2006 + * + * This file is part of X10 Language. + * + */ +package polyglot.ext.x10cuda.types; + +/** + * This class extends the X10 notion of Context to keep track of + * the translation state for the C++ backend. + * + * @author Dave Cunningham + */ +import polyglot.ext.x10.ast.Closure_c; +import polyglot.ext.x10cpp.types.X10CPPContext_c; +import polyglot.types.TypeSystem; +import x10c.util.ClassifiedStream; +import x10c.util.StreamWrapper; + +public class X10CUDAContext_c extends X10CPPContext_c { + + private ClassifiedStream cudaStream = null; + + private Closure_c wrappingClosure; + + public X10CUDAContext_c(TypeSystem ts) { + super(ts); + } + + public ClassifiedStream cudaStream (StreamWrapper sw) { + if (cudaStream==null) { + cudaStream = sw.getNewStream("cu"); + } + return cudaStream; + } + + public Closure_c getWrappingClosure() { + return wrappingClosure; + } + + public void setWrappingClosure(Closure_c wrappingClosure) { + this.wrappingClosure = wrappingClosure; + } + +} + +//vim:tabstop=4:shiftwidth=4:expandtab \ No newline at end of file Added: trunk/x10.cppbackend.17/src/polyglot/ext/x10cuda/types/X10CUDATypeSystem_c.java =================================================================== --- trunk/x10.cppbackend.17/src/polyglot/ext/x10cuda/types/X10CUDATypeSystem_c.java (rev 0) +++ trunk/x10.cppbackend.17/src/polyglot/ext/x10cuda/types/X10CUDATypeSystem_c.java 2009-03-04 02:56:14 UTC (rev 7872) @@ -0,0 +1,16 @@ +/* + * Created on Feb 26, 2008 + * + * To change the template for this generated file go to + * Window - Preferences - Java - Code Generation - Code and Comments + */ +package polyglot.ext.x10cuda.types; + +import polyglot.ext.x10.types.X10TypeSystem_c; +import polyglot.types.Context; + +public class X10CUDATypeSystem_c extends X10TypeSystem_c { + public Context createContext() { + return new X10CUDAContext_c(this); + } +} \ No newline at end of file Added: trunk/x10.cppbackend.17/src/polyglot/ext/x10cuda/visit/CUDACodeGenerator.java =================================================================== --- trunk/x10.cppbackend.17/src/polyglot/ext/x10cuda/visit/CUDACodeGenerator.java (rev 0) +++ trunk/x10.cppbackend.17/src/polyglot/ext/x10cuda/visit/CUDACodeGenerator.java 2009-03-04 02:56:14 UTC (rev 7872) @@ -0,0 +1,99 @@ +/* + * + * (C) Copyright IBM Corporation 2006, 2007, 2008, 2009 + * + * This file is part of X10 Language. + * + */ + +/* + * Created on Feb 24 2009 + * + */ + +package polyglot.ext.x10cuda.visit; + +import polyglot.ast.Node; +import polyglot.ast.Block_c; +import polyglot.ext.x10.ast.Closure_c; +import polyglot.ext.x10.extension.X10Ext; +import polyglot.ext.x10.types.X10ClassType; +import polyglot.ext.x10.types.X10TypeSystem; +import polyglot.ext.x10cpp.visit.MessagePassingCodeGenerator; +import polyglot.ext.x10cuda.types.X10CUDAContext_c; +import polyglot.types.QName; +import polyglot.types.SemanticException; +import polyglot.types.Type; +import polyglot.visit.Translator; +import x10c.util.ClassifiedStream; +import x10c.util.StreamWrapper; + +/** + * Visitor that prettyprints an X10 AST to the CUDA subset of c++. + * + * @author Dave Cunningham + */ + +public class CUDACodeGenerator extends MessagePassingCodeGenerator { + + private static final String CUDA_ANNOTATION = "x10.compiler.Cuda"; + + public CUDACodeGenerator(StreamWrapper sw, Translator tr) { + super(sw,tr); + } + + + private X10CUDAContext_c context() { + return (X10CUDAContext_c) tr.context(); + } + + // defer to CUDAContext.cudaStream() + private ClassifiedStream cudaStream() { + return context().cudaStream(sw); + } + + + private boolean nodeHasCudaAnnotation(Node n) { + X10TypeSystem xts = (X10TypeSystem) tr.typeSystem(); + X10Ext ext = (X10Ext) n.ext(); + try { + Type cudable = (Type) xts.systemResolver().find(QName.make(CUDA_ANNOTATION)); + return !ext.annotationMatching(cudable).isEmpty(); + } catch (SemanticException e) { + assert false : e; + return false; // in case asserts are off + } + } + + void handleCuda(Block_c b) { + ClassifiedStream out = cudaStream(); + String kernel_name = "my_happy_kernel"; + out.write("__global__ void "+kernel_name+"() {"); out.newline(4); out.begin(0); + sw.pushCurrentStream(out); + super.visit(b); + sw.popCurrentStream(); + out.end() ; out.newline(); + out.write("}"); out.newline(); + out.forceNewline(); + out.forceNewline(); + } + + public void visit(Closure_c n) { + Closure_c last = context().getWrappingClosure(); + context().setWrappingClosure(n); + super.visit(n); + context().setWrappingClosure(last); + } + + public void visit(Block_c b) { + if (nodeHasCudaAnnotation(b)) { + sw.write("/*CUDA block*/ "); + handleCuda(b); + } + super.visit(b); + } + + +} // end of CUDACodeGenerator + +// vim:tabstop=4:shiftwidth=4:expandtab Modified: trunk/x10.cppbackend.17/src/x10c/util/ClassifiedStream.java =================================================================== --- trunk/x10.cppbackend.17/src/x10c/util/ClassifiedStream.java 2009-03-03 20:17:11 UTC (rev 7871) +++ trunk/x10.cppbackend.17/src/x10c/util/ClassifiedStream.java 2009-03-04 02:56:14 UTC (rev 7872) @@ -10,14 +10,14 @@ public class ClassifiedStream extends SimpleCodeWriter { final ByteArrayOutputStream stream; - public final StreamWrapper.StreamClass sClass; - private ClassifiedStream(ByteArrayOutputStream bs, StreamWrapper.StreamClass c, int width) { + public final String ext; + private ClassifiedStream(ByteArrayOutputStream bs, String ext, int width) { super(bs, width); stream = bs; - this.sClass = c; + this.ext = ext; } - public ClassifiedStream(StreamWrapper.StreamClass c, int width) { - this(new ByteArrayOutputStream(), c, width); + public ClassifiedStream(String ext, int width) { + this(new ByteArrayOutputStream(), ext, width); } public String contents() { output.flush(); return stream.toString(); } public void forceNewline() { pos = -1; newline(); } Modified: trunk/x10.cppbackend.17/src/x10c/util/StreamWrapper.java =================================================================== --- trunk/x10.cppbackend.17/src/x10c/util/StreamWrapper.java 2009-03-03 20:17:11 UTC (rev 7871) +++ trunk/x10.cppbackend.17/src/x10c/util/StreamWrapper.java 2009-03-04 02:56:14 UTC (rev 7872) @@ -27,12 +27,11 @@ * @author igor */ public class StreamWrapper extends SimpleCodeWriter { - - public static enum StreamClass { Header("h"), CC("cc"), Closures("inc"); - String ext; - private StreamClass(String e) { ext = e; } - public String toString() { return ext; } - } + + public static final String Header = "h"; + public static final String CC = "cc"; + public static final String Closures = "inc"; + // Desired API: getNewStream(class, pre/append), setCurrentStream, setHeader, setBody, header, body // 2 streams - header and body // Decouple stream class from stream destination file @@ -64,13 +63,13 @@ public void pushCurrentStream(ClassifiedStream s) { csStack.push(this.cs); this.cs = s; } public void popCurrentStream() { this.cs = csStack.pop(); } - public ClassifiedStream getNewStream(StreamWrapper.StreamClass sc, ClassifiedStream s, boolean prepend) { + public ClassifiedStream getNewStream(String sc, ClassifiedStream s, boolean prepend) { return ws.getNewStream(sc, s, prepend); } - public ClassifiedStream getNewStream(StreamWrapper.StreamClass sc, boolean prepend) { + public ClassifiedStream getNewStream(String sc, boolean prepend) { return ws.getNewStream(sc, prepend); } - public ClassifiedStream getNewStream(StreamWrapper.StreamClass sc) { + public ClassifiedStream getNewStream(String sc) { return getNewStream(sc, true); } Modified: trunk/x10.cppbackend.17/src/x10c/util/WriterStreams.java =================================================================== --- trunk/x10.cppbackend.17/src/x10c/util/WriterStreams.java 2009-03-03 20:17:11 UTC (rev 7871) +++ trunk/x10.cppbackend.17/src/x10c/util/WriterStreams.java 2009-03-04 02:56:14 UTC (rev 7872) @@ -6,111 +6,103 @@ import java.io.File; import java.io.IOException; import java.util.HashSet; -import java.util.List; import java.util.Map; import java.util.Set; import java.util.TreeMap; +import java.util.TreeSet; import java.util.Vector; import polyglot.ast.SourceFile; import polyglot.ext.x10cpp.visit.X10CPPTranslator.DelegateTargetFactory; import polyglot.frontend.Job; import polyglot.util.SimpleCodeWriter; -import x10c.util.StreamWrapper.StreamClass; /** * This class represents a collection of output streams. Each stream has an associated - * type, specified by StreamClass. There is one output file associated with each type. + * type, specified by the extension string. * Operations are provided to create a new stream of a given type (see getNewStream), * and to commit all streams. Committing causes the contents of all streams of a given * type to be written out to the file associated with that type, in the order in which * the streams of that type were created. * * @author nvk - * @author vj -- Moved out to its own separate class. + * @author vj -- Moved out to its own separate class + * @author igor -- completely rewritten */ public class WriterStreams { - private Map<StreamClass, SimpleCodeWriter> codeWriters; - private Map<StreamClass, File> codeFiles; + private Map<String, SimpleCodeWriter> codeWriters; private Vector<ClassifiedStream> streams; private DelegateTargetFactory targetFactory; - Job job; + private Job job; + private String pkg; + private String className; - public WriterStreams(String className, SourceFile sfn, String pkg, - DelegateTargetFactory tf, List exports, Job job) throws IOException + public WriterStreams(String className, String pkg, + DelegateTargetFactory tf, + Job job) throws IOException { streams = new Vector<ClassifiedStream>(); - codeWriters = new TreeMap<StreamClass,SimpleCodeWriter>(); - codeFiles = new TreeMap<StreamClass,File>(); + codeWriters = new TreeMap<String,SimpleCodeWriter>(); targetFactory = tf; this.job = job; - - //List exports = exports(sfn); - - for (StreamClass sc : StreamClass.values()) { - final File file = tf.integratedOutputFile(pkg, className,sfn.source(), sc.toString()); - codeFiles.put(sc, file); - } + this.pkg = pkg; + this.className = className; } /** * Write out all the streams associated with this object to their correspodnding files. * Note that all streams of the same type are written to the same file, their contents * concatenated in the order in which the streams were created, as indicated by the - * prepend argument to {@link #getNewStream(StreamClass, boolean)}. + * prepend argument to {@link #getNewStream(String, boolean)}. * @throws IOException */ public void commitStreams() throws IOException { - Set<StreamClass> nonEmpty = new HashSet<StreamClass>(); + Set<String> nonEmpty = new HashSet<String>(); for (ClassifiedStream s : streams) { - nonEmpty.add(s.sClass); + nonEmpty.add(s.ext); } - for (StreamClass sc : StreamClass.values()) { -// if (!nonEmpty.contains(sc)) + Set<String> extensions = new TreeSet<String>(); + for (ClassifiedStream s : streams) { + extensions.add(s.ext); + } + for (String ext : extensions) { +// if (!nonEmpty.contains(ext)) // continue; - final File file = codeFiles.get(sc); - codeWriters.put(sc, + final File file = targetFactory.integratedOutputFile(pkg, className, null, ext); + codeWriters.put(ext, new SimpleCodeWriter(targetFactory.outputWriter(file), job.compiler().outputWidth())); } for (ClassifiedStream s : streams) { s.flush(); - codeWriters.get(s.sClass).write(s.contents()); + codeWriters.get(s.ext).write(s.contents()); } - for (StreamClass sc : StreamClass.values()) { -// if (!nonEmpty.contains(sc)) + for (String ext : extensions) { +// if (!nonEmpty.contains(ext)) // continue; - SimpleCodeWriter w = codeWriters.get(sc); + SimpleCodeWriter w = codeWriters.get(ext); w.flush(); w.close(); } } - private File getFile(StreamClass sc) { - return codeFiles.get(sc); - } - - private File getHeader() { - return codeFiles.get(StreamClass.Header); - } - /** - * Create and return a new stream of type sc. - * @param sc - * @return a new stream of type sc + * Create and return a new stream of type ext. + * @param ext + * @return a new stream of type ext */ - ClassifiedStream getNewStream(StreamClass sc) { return getNewStream(sc, true); } + ClassifiedStream getNewStream(String ext) { return getNewStream(ext, true); } /** - * Create and return a new stream of type sc, inserting it either at the beginning + * Create and return a new stream of type ext, inserting it either at the beginning * or at the end of the stream list. - * @param sc + * @param ext * @param prepend Whether to prepend the new stream to all streams of its class (true) * or append it (false) - * @return a new stream of type sc + * @return a new stream of type ext */ - ClassifiedStream getNewStream(StreamClass sc, boolean prepend) { - ClassifiedStream cs = new ClassifiedStream(sc, job.compiler().outputWidth()); + ClassifiedStream getNewStream(String ext, boolean prepend) { + ClassifiedStream cs = new ClassifiedStream(ext, job.compiler().outputWidth()); if (prepend) { streams.add(0, cs); } else { @@ -120,15 +112,15 @@ } /** - * Create and return a new stream of type sc, inserting it either before or after + * Create and return a new stream of type ext, inserting it either before or after * a given stream s. - * @param sc + * @param ext * @param s * @param prepend Whether to prepend the new stream (true) or append it (false) - * @return a new stream of type sc + * @return a new stream of type ext */ - ClassifiedStream getNewStream(StreamClass sc, ClassifiedStream s, boolean prepend) { - ClassifiedStream cs = new ClassifiedStream(sc, job.compiler().outputWidth()); + ClassifiedStream getNewStream(String ext, ClassifiedStream s, boolean prepend) { + ClassifiedStream cs = new ClassifiedStream(ext, job.compiler().outputWidth()); int i = streams.indexOf(s); if (prepend) { streams.add(i, cs); Added: trunk/x10.runtime.17/src-x10/x10/compiler/Cuda.x10 =================================================================== --- trunk/x10.runtime.17/src-x10/x10/compiler/Cuda.x10 (rev 0) +++ trunk/x10.runtime.17/src-x10/x10/compiler/Cuda.x10 2009-03-04 02:56:14 UTC (rev 7872) @@ -0,0 +1,11 @@ +/* + * + * (C) Copyright IBM Corporation 2006-2008. + * + * This file is part of X10 Language. + * + */ + +package x10.compiler; + +public interface Cuda { }; Modified: trunk/x10.runtime.17/src-x10/x10/lang/Place.x10 =================================================================== --- trunk/x10.runtime.17/src-x10/x10/lang/Place.x10 2009-03-03 20:17:11 UTC (rev 7871) +++ trunk/x10.runtime.17/src-x10/x10/lang/Place.x10 2009-03-04 02:56:14 UTC (rev 7872) @@ -18,7 +18,7 @@ public const places = Rail.makeVal[Place](MAX_PLACES, ((id: nat) => new Place(id))); public const FIRST_PLACE = place(0); - private def this(id: nat) = property(id); + public def this(id: nat) = property(id); public static def place(id: nat): Place = places(id); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dgr...@us...> - 2009-03-04 21:46:55
|
Revision: 7873 http://x10.svn.sourceforge.net/x10/?rev=7873&view=rev Author: dgrove-oss Date: 2009-03-04 21:46:49 +0000 (Wed, 04 Mar 2009) Log Message: ----------- Import of all public domain code from the jsr166 cvs repository (pserver:ano...@ge.../export/home/jsr166/jsr166) as it existed on March 4, 2009. Added Paths: ----------- trunk/jsr166-pd/ trunk/jsr166-pd/src/ trunk/jsr166-pd/src/bug5042654/ trunk/jsr166-pd/src/bug5042654/swt/ trunk/jsr166-pd/src/dl/ trunk/jsr166-pd/src/dl/java/ trunk/jsr166-pd/src/dl/java/util/ trunk/jsr166-pd/src/dl/java/util/concurrent/ trunk/jsr166-pd/src/dl/java/util/concurrent/atomic/ trunk/jsr166-pd/src/dl/sun/ trunk/jsr166-pd/src/dl/sun/misc/ trunk/jsr166-pd/src/emulation/ trunk/jsr166-pd/src/emulation/java/ trunk/jsr166-pd/src/emulation/java/util/ trunk/jsr166-pd/src/emulation/java/util/concurrent/ trunk/jsr166-pd/src/emulation/java/util/concurrent/atomic/ trunk/jsr166-pd/src/emulation/java/util/concurrent/locks/ trunk/jsr166-pd/src/emulation/sun/ trunk/jsr166-pd/src/emulation/sun/misc/ trunk/jsr166-pd/src/extra166y/ trunk/jsr166-pd/src/extra166y/AbstractParallelAnyArray.java trunk/jsr166-pd/src/extra166y/CommonOps.java trunk/jsr166-pd/src/extra166y/Ops.java trunk/jsr166-pd/src/extra166y/PAS.java trunk/jsr166-pd/src/extra166y/ParallelArray.java trunk/jsr166-pd/src/extra166y/ParallelArrayWithBounds.java trunk/jsr166-pd/src/extra166y/ParallelArrayWithDoubleMapping.java trunk/jsr166-pd/src/extra166y/ParallelArrayWithFilter.java trunk/jsr166-pd/src/extra166y/ParallelArrayWithLongMapping.java trunk/jsr166-pd/src/extra166y/ParallelArrayWithMapping.java trunk/jsr166-pd/src/extra166y/ParallelDoubleArray.java trunk/jsr166-pd/src/extra166y/ParallelDoubleArrayWithBounds.java trunk/jsr166-pd/src/extra166y/ParallelDoubleArrayWithDoubleMapping.java trunk/jsr166-pd/src/extra166y/ParallelDoubleArrayWithFilter.java trunk/jsr166-pd/src/extra166y/ParallelDoubleArrayWithLongMapping.java trunk/jsr166-pd/src/extra166y/ParallelDoubleArrayWithMapping.java trunk/jsr166-pd/src/extra166y/ParallelLongArray.java trunk/jsr166-pd/src/extra166y/ParallelLongArrayWithBounds.java trunk/jsr166-pd/src/extra166y/ParallelLongArrayWithDoubleMapping.java trunk/jsr166-pd/src/extra166y/ParallelLongArrayWithFilter.java trunk/jsr166-pd/src/extra166y/ParallelLongArrayWithLongMapping.java trunk/jsr166-pd/src/extra166y/ParallelLongArrayWithMapping.java trunk/jsr166-pd/src/extra166y/package-info.java trunk/jsr166-pd/src/jsr166x/ trunk/jsr166-pd/src/jsr166x/ArrayDeque.java trunk/jsr166-pd/src/jsr166x/BlockingDeque.java trunk/jsr166-pd/src/jsr166x/ConcurrentLinkedDeque.java trunk/jsr166-pd/src/jsr166x/ConcurrentNavigableMap.java trunk/jsr166-pd/src/jsr166x/ConcurrentSkipListMap.java trunk/jsr166-pd/src/jsr166x/ConcurrentSkipListSet.java trunk/jsr166-pd/src/jsr166x/Deque.java trunk/jsr166-pd/src/jsr166x/LinkedBlockingDeque.java trunk/jsr166-pd/src/jsr166x/NavigableMap.java trunk/jsr166-pd/src/jsr166x/NavigableSet.java trunk/jsr166-pd/src/jsr166x/package.html trunk/jsr166-pd/src/jsr166y/ trunk/jsr166-pd/src/jsr166y/ForkJoinPool.java trunk/jsr166-pd/src/jsr166y/ForkJoinTask.java trunk/jsr166-pd/src/jsr166y/ForkJoinWorkerThread.java trunk/jsr166-pd/src/jsr166y/LinkedTransferQueue.java trunk/jsr166-pd/src/jsr166y/Phaser.java trunk/jsr166-pd/src/jsr166y/RecursiveAction.java trunk/jsr166-pd/src/jsr166y/RecursiveTask.java trunk/jsr166-pd/src/jsr166y/ThreadLocalRandom.java trunk/jsr166-pd/src/jsr166y/TransferQueue.java trunk/jsr166-pd/src/jsr166y/forkjoin/ trunk/jsr166-pd/src/jsr166y/package-info.java trunk/jsr166-pd/src/loops/ trunk/jsr166-pd/src/loops/ALoops.java trunk/jsr166-pd/src/loops/LoopHelpers.java trunk/jsr166-pd/src/loops/Mutex.java trunk/jsr166-pd/src/loops/TimeUnitLoops.java trunk/jsr166-pd/src/main/ trunk/jsr166-pd/src/main/intro.html trunk/jsr166-pd/src/main/java/ trunk/jsr166-pd/src/main/java/lang/ trunk/jsr166-pd/src/main/java/util/ trunk/jsr166-pd/src/main/java/util/AbstractQueue.java trunk/jsr166-pd/src/main/java/util/ArrayDeque.java trunk/jsr166-pd/src/main/java/util/Deque.java trunk/jsr166-pd/src/main/java/util/NavigableMap.java trunk/jsr166-pd/src/main/java/util/NavigableSet.java trunk/jsr166-pd/src/main/java/util/Queue.java trunk/jsr166-pd/src/main/java/util/concurrent/ trunk/jsr166-pd/src/main/java/util/concurrent/AbstractExecutorService.java trunk/jsr166-pd/src/main/java/util/concurrent/ArrayBlockingQueue.java trunk/jsr166-pd/src/main/java/util/concurrent/BlockingDeque.java trunk/jsr166-pd/src/main/java/util/concurrent/BlockingQueue.java trunk/jsr166-pd/src/main/java/util/concurrent/BrokenBarrierException.java trunk/jsr166-pd/src/main/java/util/concurrent/Callable.java trunk/jsr166-pd/src/main/java/util/concurrent/CancellationException.java trunk/jsr166-pd/src/main/java/util/concurrent/CompletionService.java trunk/jsr166-pd/src/main/java/util/concurrent/ConcurrentHashMap.java trunk/jsr166-pd/src/main/java/util/concurrent/ConcurrentLinkedQueue.java trunk/jsr166-pd/src/main/java/util/concurrent/ConcurrentMap.java trunk/jsr166-pd/src/main/java/util/concurrent/ConcurrentNavigableMap.java trunk/jsr166-pd/src/main/java/util/concurrent/ConcurrentSkipListMap.java trunk/jsr166-pd/src/main/java/util/concurrent/ConcurrentSkipListSet.java trunk/jsr166-pd/src/main/java/util/concurrent/CopyOnWriteArraySet.java trunk/jsr166-pd/src/main/java/util/concurrent/CountDownLatch.java trunk/jsr166-pd/src/main/java/util/concurrent/CyclicBarrier.java trunk/jsr166-pd/src/main/java/util/concurrent/DelayQueue.java trunk/jsr166-pd/src/main/java/util/concurrent/Delayed.java trunk/jsr166-pd/src/main/java/util/concurrent/Exchanger.java trunk/jsr166-pd/src/main/java/util/concurrent/ExecutionException.java trunk/jsr166-pd/src/main/java/util/concurrent/Executor.java trunk/jsr166-pd/src/main/java/util/concurrent/ExecutorCompletionService.java trunk/jsr166-pd/src/main/java/util/concurrent/ExecutorService.java trunk/jsr166-pd/src/main/java/util/concurrent/Executors.java trunk/jsr166-pd/src/main/java/util/concurrent/Future.java trunk/jsr166-pd/src/main/java/util/concurrent/FutureTask.java trunk/jsr166-pd/src/main/java/util/concurrent/LinkedBlockingDeque.java trunk/jsr166-pd/src/main/java/util/concurrent/LinkedBlockingQueue.java trunk/jsr166-pd/src/main/java/util/concurrent/PriorityBlockingQueue.java trunk/jsr166-pd/src/main/java/util/concurrent/RejectedExecutionException.java trunk/jsr166-pd/src/main/java/util/concurrent/RejectedExecutionHandler.java trunk/jsr166-pd/src/main/java/util/concurrent/RunnableFuture.java trunk/jsr166-pd/src/main/java/util/concurrent/RunnableScheduledFuture.java trunk/jsr166-pd/src/main/java/util/concurrent/ScheduledExecutorService.java trunk/jsr166-pd/src/main/java/util/concurrent/ScheduledFuture.java trunk/jsr166-pd/src/main/java/util/concurrent/ScheduledThreadPoolExecutor.java trunk/jsr166-pd/src/main/java/util/concurrent/Semaphore.java trunk/jsr166-pd/src/main/java/util/concurrent/SynchronousQueue.java trunk/jsr166-pd/src/main/java/util/concurrent/ThreadFactory.java trunk/jsr166-pd/src/main/java/util/concurrent/ThreadPoolExecutor.java trunk/jsr166-pd/src/main/java/util/concurrent/TimeUnit.java trunk/jsr166-pd/src/main/java/util/concurrent/TimeoutException.java trunk/jsr166-pd/src/main/java/util/concurrent/atomic/ trunk/jsr166-pd/src/main/java/util/concurrent/atomic/AtomicBoolean.java trunk/jsr166-pd/src/main/java/util/concurrent/atomic/AtomicInteger.java trunk/jsr166-pd/src/main/java/util/concurrent/atomic/AtomicIntegerArray.java trunk/jsr166-pd/src/main/java/util/concurrent/atomic/AtomicIntegerFieldUpdater.java trunk/jsr166-pd/src/main/java/util/concurrent/atomic/AtomicLong.java trunk/jsr166-pd/src/main/java/util/concurrent/atomic/AtomicLongArray.java trunk/jsr166-pd/src/main/java/util/concurrent/atomic/AtomicLongFieldUpdater.java trunk/jsr166-pd/src/main/java/util/concurrent/atomic/AtomicMarkableReference.java trunk/jsr166-pd/src/main/java/util/concurrent/atomic/AtomicReference.java trunk/jsr166-pd/src/main/java/util/concurrent/atomic/AtomicReferenceArray.java trunk/jsr166-pd/src/main/java/util/concurrent/atomic/AtomicReferenceFieldUpdater.java trunk/jsr166-pd/src/main/java/util/concurrent/atomic/AtomicStampedReference.java trunk/jsr166-pd/src/main/java/util/concurrent/atomic/package-info.java trunk/jsr166-pd/src/main/java/util/concurrent/locks/ trunk/jsr166-pd/src/main/java/util/concurrent/locks/AbstractOwnableSynchronizer.java trunk/jsr166-pd/src/main/java/util/concurrent/locks/AbstractQueuedLongSynchronizer.java trunk/jsr166-pd/src/main/java/util/concurrent/locks/AbstractQueuedSynchronizer.java trunk/jsr166-pd/src/main/java/util/concurrent/locks/Condition.java trunk/jsr166-pd/src/main/java/util/concurrent/locks/Lock.java trunk/jsr166-pd/src/main/java/util/concurrent/locks/LockSupport.java trunk/jsr166-pd/src/main/java/util/concurrent/locks/ReadWriteLock.java trunk/jsr166-pd/src/main/java/util/concurrent/locks/ReentrantLock.java trunk/jsr166-pd/src/main/java/util/concurrent/locks/ReentrantReadWriteLock.java trunk/jsr166-pd/src/main/java/util/concurrent/locks/package-info.java trunk/jsr166-pd/src/main/java/util/concurrent/package-info.java trunk/jsr166-pd/src/main/readme trunk/jsr166-pd/src/main/sun/ trunk/jsr166-pd/src/main/sun/misc/ Added: trunk/jsr166-pd/src/extra166y/AbstractParallelAnyArray.java =================================================================== --- trunk/jsr166-pd/src/extra166y/AbstractParallelAnyArray.java (rev 0) +++ trunk/jsr166-pd/src/extra166y/AbstractParallelAnyArray.java 2009-03-04 21:46:49 UTC (rev 7873) @@ -0,0 +1,7910 @@ +/* + * Written by Doug Lea with assistance from members of JCP JSR-166 + * Expert Group and released to the public domain, as explained at + * http://creativecommons.org/licenses/publicdomain + */ + +package extra166y; +import jsr166y.*; +import static extra166y.Ops.*; +import java.util.*; +import java.util.concurrent.atomic.*; +import java.lang.reflect.Array; + +/** + * Abstract class serving as the basis of parallel + * array classes across types. + */ +public abstract class AbstractParallelAnyArray { + /* + * This class and its subclasses (most of which are defined here + * as nested static classes) maintain the execution parameters for + * ParallelArray, ParallelDoubleArray, and ParallelLongArray + * tasks. Pap instances hold the non-operation-specific control + * and data accessors needed for a task as a whole (as opposed to + * subtasks), and also house some of the leaf methods that perform + * the actual array processing. The leaf methods are for the most + * part just plain array operations. They are boringly repetitive + * in order to flatten out and minimize inner-loop overhead, as + * well as to minimize call-chain depth. This makes it more likely + * that dynamic compilers can go the rest of the way, and hoist + * per-element method call dispatch, so we have a good chance to + * speed up processing via parallelism rather than lose due to + * dispatch and indirection overhead. The dispatching from Pap to + * FJ and back is otherwise Visitor-pattern-like, allowing the + * basic parallelism control for most FJ tasks to be centralized. + * + * Note the extensive use of raw types. Arrays and generics do not + * work together very well. It is more manageable to avoid them here, + * and let the public classes perform casts in and out to the + * processing here. Also note that the majority of code in concrete + * classes is just for managing the various flavors created using + * with* methods. + * + * Internal concrete classes are named using an + * abbreviation scheme to avoid mile-long class names: + * O, D, L for Object, Double, Long, for underlying Parallel array + * U - unfiltered + * F - filtered + * R - relation-filtered (aka index-filtered) + * OM, DM, LM - Mapped + * OC, DC, LC - combiner-mapped (aka index-mapped) + */ + + final ForkJoinPool ex; + final int origin; + int fence; + int threshold; + + AbstractParallelAnyArray(ForkJoinPool ex, int origin, int fence) { + this.ex = ex; + this.origin = origin; + this.fence = fence; + } + + // A few public methods exported across all subclasses + + /** + * Return the number of elements selected using bound or + * filter restrictions. Note that this method must evaluate + * all selectors to return its result. + * @return the number of elements + */ + public int size() { + if (!hasFilter()) + return fence - origin; + PAS.FJCountSelected f = new PAS.FJCountSelected + (this, origin, fence, null); + ex.invoke(f); + return f.count; + } + + /** + * Returns the index of some element matching bound and filter + * constraints, or -1 if none. + * @return index of matching element, or -1 if none. + */ + public int anyIndex() { + if (!hasFilter()) + return (origin < fence)? origin : -1; + AtomicInteger result = new AtomicInteger(-1); + PAS.FJSelectAny f = new PAS.FJSelectAny + (this, origin, fence, null, result); + ex.invoke(f); + return result.get(); + } + + /** + * Returns true if there are no elements + * @return true if there are no elements + */ + public boolean isEmpty() { + return anyIndex() < 0; + } + + + /** + * Returns size threshold for splitting into subtask. By + * default, uses about 8 times as many tasks as threads + */ + final int computeThreshold() { + int n = fence - origin; + int p = ex.getParallelism(); + return threshold = (p > 1) ? (1 + n / (p << 3)) : n; + } + + /** + * Returns lazily computed threshold. + */ + final int getThreshold() { + int t = threshold; + if (t == 0) + t = computeThreshold(); + return t; + } + + /** + * Access methods for ref, double, long. Checking for + * null/false return is used as a sort of type test. These + * are used to avoid duplication in non-performance-critical + * aspects of control, as well as to provide a simple default + * mechanism for extensions. + */ + Object[] ogetArray() { return null; } + double[] dgetArray() { return null; } + long[] lgetArray() { return null; } + abstract Object oget(int index); + abstract double dget(int index); + abstract long lget(int index); + boolean hasMap() { return false; } + boolean hasFilter() { return false; } + boolean isSelected(int index) { return true; } + + /* + * Leaf methods for FJ tasks. Default versions use isSelected, + * oget, dget, etc. But most are overridden in most concrete + * classes to avoid per-element dispatching. + */ + void leafApply(int lo, int hi, Procedure procedure) { + for (int i = lo; i < hi; ++i) + if (isSelected(i)) + procedure.op(oget(i)); + } + + void leafApply(int lo, int hi, DoubleProcedure procedure) { + for (int i = lo; i < hi; ++i) + if (isSelected(i)) + procedure.op(dget(i)); + } + + void leafApply(int lo, int hi, LongProcedure procedure) { + for (int i = lo; i < hi; ++i) + if (isSelected(i)) + procedure.op(lget(i)); + } + + Object leafReduce(int lo, int hi, Reducer reducer, Object base) { + boolean gotFirst = false; + Object r = base; + for (int i = lo; i < hi; ++i) { + if (isSelected(i)) { + Object x = oget(i); + if (!gotFirst) { + gotFirst = true; + r = x; + } + else + r = reducer.op(r, x); + } + } + return r; + } + + double leafReduce(int lo, int hi, DoubleReducer reducer, double base) { + boolean gotFirst = false; + double r = base; + for (int i = lo; i < hi; ++i) { + if (isSelected(i)) { + double x = dget(i); + if (!gotFirst) { + gotFirst = true; + r = x; + } + else + r = reducer.op(r, x); + } + } + return r; + } + + long leafReduce(int lo, int hi, LongReducer reducer, long base) { + boolean gotFirst = false; + long r = base; + for (int i = lo; i < hi; ++i) { + if (isSelected(i)) { + long x = lget(i); + if (!gotFirst) { + gotFirst = true; + r = x; + } + else + r = reducer.op(r, x); + } + } + return r; + } + + // copy elements, ignoring selector, but applying mapping + void leafTransfer(int lo, int hi, Object[] dest, int offset) { + for (int i = lo; i < hi; ++i) + dest[offset++] = oget(i); + } + + void leafTransfer(int lo, int hi, double[] dest, int offset) { + for (int i = lo; i < hi; ++i) + dest[offset++] = dget(i); + } + + void leafTransfer(int lo, int hi, long[] dest, int offset) { + for (int i = lo; i < hi; ++i) + dest[offset++] = lget(i); + } + + // copy elements indexed in indices[loIdx..hiIdx], ignoring + // selector, but applying mapping + void leafTransferByIndex(int[] indices, int loIdx, int hiIdx, + Object[] dest, int offset) { + for (int i = loIdx; i < hiIdx; ++i) + dest[offset++] = oget(indices[i]); + } + + void leafTransferByIndex(int[] indices, int loIdx, int hiIdx, + double[] dest, int offset) { + for (int i = loIdx; i < hiIdx; ++i) + dest[offset++] = dget(indices[i]); + } + + void leafTransferByIndex(int[] indices, int loIdx, int hiIdx, + long[] dest, int offset) { + for (int i = loIdx; i < hiIdx; ++i) + dest[offset++] = lget(indices[i]); + } + + // add indices of selected elements to index array; return #added + final int leafIndexSelected(int lo, int hi, boolean positive, + int[] indices) { + int k = 0; + for (int i = lo; i < hi; ++i) { + if (isSelected(i) == positive) + indices[lo + k++] = i; + } + return k; + } + + // move selected elements to indices starting at offset, + // return final offset + abstract int leafMoveSelected(int lo, int hi, int offset, + boolean positive); + + // move elements indexed by indices[loIdx...hiIdx] starting + // at given offset + abstract void leafMoveByIndex(int[] indices, int loIdx, + int hiIdx, int offset); + + /** + * Shared support for select/map all -- probe filter, map, and + * type to start selection driver, or do parallel mapping, or + * just copy, + */ + final Object[] allObjects(Class elementType) { + if (hasFilter()) { + if (elementType == null) { + if (!hasMap()) + elementType = ogetArray().getClass().getComponentType(); + else + elementType = Object.class; + } + PAS.FJOSelectAllDriver r = new PAS.FJOSelectAllDriver + (this, elementType); + ex.invoke(r); + return r.results; + } + else { + int n = fence - origin; + Object[] dest; + if (hasMap()) { + if (elementType == null) + dest = new Object[n]; + else + dest = (Object[])Array.newInstance(elementType, n); + ex.invoke(new PAS.FJOMap(this, origin, fence, + null, dest, -origin)); + } + else { + Object[] array = ogetArray(); + if (elementType == null) + elementType = array.getClass().getComponentType(); + dest = (Object[])Array.newInstance(elementType, n); + System.arraycopy(array, origin, dest, 0, n); + } + return dest; + } + } + + final double[] allDoubles() { + if (hasFilter()) { + PAS.FJDSelectAllDriver r = new PAS.FJDSelectAllDriver(this); + ex.invoke(r); + return r.results; + } + else { + int n = fence - origin; + double[] dest = new double[n]; + if (hasMap()) { + ex.invoke(new PAS.FJDMap(this, origin, fence, + null, dest, -origin)); + } + else { + double[] array = dgetArray(); + System.arraycopy(array, origin, dest, 0, n); + } + return dest; + } + } + + final long[] allLongs() { + if (hasFilter()) { + PAS.FJLSelectAllDriver r = new PAS.FJLSelectAllDriver(this); + ex.invoke(r); + return r.results; + } + else { + int n = fence - origin; + long[] dest = new long[n]; + if (hasMap()) { + ex.invoke(new PAS.FJLMap(this, origin, fence, + null, dest, -origin)); + } + else { + long[] array = lgetArray(); + System.arraycopy(array, origin, dest, 0, n); + } + return dest; + } + } + + // Bounds check a range + void boundsCheck(int lo, int hi) { + if (lo > hi) + throw new IllegalArgumentException(origin + " > " + fence); + if (lo < 0) + throw new ArrayIndexOutOfBoundsException(origin); + if (hi - lo > this.fence - this.origin) + throw new ArrayIndexOutOfBoundsException(fence); + } + + /* + * The following methods can be called only for classes + * supporting in-place replacements (currently, those classes + * without mappings). They are declared as no-ops here, and + * overridden only where applicable. + */ + + void leafTransform(int l, int h, Op op) {} + void leafIndexMap(int l, int h, IntToObject op) {} + void leafBinaryIndexMap(int l, int h, IntAndObjectToObject op) {} + void leafGenerate(int l, int h, Generator generator) {} + void leafFill(int l, int h, Object value) {} + void leafCombineInPlace(int lo, int hi, Object[] other, + int otherOffset, BinaryOp combiner) {} + void leafCombineInPlace(int lo, int hi, ParallelArrayWithMapping other, + int otherOffset, BinaryOp combiner) {} + + void leafTransform(int l, int h, DoubleOp op) {} + void leafIndexMap(int l, int h, IntToDouble array) {} + void leafBinaryIndexMap(int l, int h, IntAndDoubleToDouble op) {} + void leafGenerate(int l, int h, DoubleGenerator generator) {} + void leafFill(int l, int h, double value) {} + void leafCombineInPlace(int lo, int hi, double[] other, + int otherOffset, BinaryDoubleOp combiner) {} + void leafCombineInPlace(int lo, int hi, + ParallelDoubleArrayWithDoubleMapping other, + int otherOffset, BinaryDoubleOp combiner) {} + + void leafTransform(int l, int h, LongOp op) {} + void leafIndexMap(int l, int h, IntToLong array) {} + void leafBinaryIndexMap(int l, int h, IntAndLongToLong op) {} + void leafGenerate(int l, int h, LongGenerator generator) {} + void leafFill(int l, int h, long value) {} + void leafCombineInPlace(int lo, int hi, long[] other, + int otherOffset, BinaryLongOp combiner) {} + void leafCombineInPlace(int lo, int hi, + ParallelLongArrayWithLongMapping other, + int otherOffset, BinaryLongOp combiner) {} + + // Base of object ref array classes + static abstract class OPap<T> extends AbstractParallelAnyArray { + T[] array; + OPap(ForkJoinPool ex, int origin, int fence, T[] array) { + super(ex, origin, fence); + this.array = array; + } + + final Object[] ogetArray() { return this.array; } + double dget(int i) { return ((Number)oget(i)).doubleValue(); } + long lget(int i) { return ((Number)oget(i)).longValue(); } + + final void leafMoveByIndex(int[] indices, int loIdx, + int hiIdx, int offset) { + final Object[] array = this.array; + for (int i = loIdx; i < hiIdx; ++i) + array[offset++] = array[indices[i]]; + } + + final int leafMoveSelected(int lo, int hi, int offset, + boolean positive) { + final Object[] array = this.array; + for (int i = lo; i < hi; ++i) { + if (isSelected(i) == positive) + array[offset++] = array[i]; + } + return offset; + } + } + + // Base of double array classes + static abstract class DPap extends AbstractParallelAnyArray { + double[] array; + DPap(ForkJoinPool ex, int origin, int fence, double[] array) { + super(ex, origin, fence); + this.array = array; + } + + final double[] dgetArray() { return this.array; } + Object oget(int i) { return Double.valueOf(dget(i)); } + long lget(int i) { return (long)(dget(i)); } + + final void leafMoveByIndex(int[] indices, int loIdx, + int hiIdx, int offset) { + final double[] array = this.array; + for (int i = loIdx; i < hiIdx; ++i) + array[offset++] = array[indices[i]]; + } + + final int leafMoveSelected(int lo, int hi, int offset, + boolean positive) { + final double[] array = this.array; + for (int i = lo; i < hi; ++i) { + if (isSelected(i) == positive) + array[offset++] = array[i]; + } + return offset; + } + } + + // Base of long array classes + static abstract class LPap extends AbstractParallelAnyArray { + long[] array; + LPap(ForkJoinPool ex, int origin, int fence, long[] array) { + super(ex, origin, fence); + this.array = array; + } + + final long[] lgetArray() { return this.array; } + Object oget(int i) { return Long.valueOf(lget(i)); } + double dget(int i) { return (double)(lget(i)); } + + final void leafMoveByIndex(int[] indices, int loIdx, + int hiIdx, int offset) { + final long[] array = this.array; + for (int i = loIdx; i < hiIdx; ++i) + array[offset++] = array[indices[i]]; + } + + final int leafMoveSelected(int lo, int hi, int offset, + boolean positive) { + final long[] array = this.array; + for (int i = lo; i < hi; ++i) { + if (isSelected(i) == positive) + array[offset++] = array[i]; + } + return offset; + } + } + + // Plain (unfiltered, unmapped) classes + static class OUPap<T> extends ParallelArrayWithBounds<T> { + OUPap(ForkJoinPool ex, int origin, int fence, T[] array) { + super(ex, origin, fence, array); + } + + public ParallelArrayWithBounds<T> withBounds(int lo, int hi) { + boundsCheck(lo, hi); + return new OUPap<T>(ex, origin + lo, origin + hi, array); + } + + public ParallelArrayWithFilter<T> withFilter + (Predicate<? super T> selector) { + return new OFPap<T>(ex, origin, fence, array, selector); + } + + public ParallelArrayWithFilter<T> withIndexedFilter + (IntAndObjectPredicate<? super T> selector) { + return new ORPap<T>(ex, origin, fence, array, selector); + } + + public <U> ParallelArrayWithMapping<T, U> withMapping + (Op<? super T, ? extends U> op) { + return new OUOMPap<T,U>(ex, origin, fence, array, op); + } + + public ParallelArrayWithDoubleMapping<T> withMapping + (ObjectToDouble<? super T> op) { + return new OUDMPap<T>(ex, origin, fence, array, op); + } + + public ParallelArrayWithLongMapping<T> withMapping + (ObjectToLong<? super T> op) { + return new OULMPap<T>(ex, origin, fence, array, op); + } + + public <V> ParallelArrayWithMapping<T,V> withIndexedMapping + (IntAndObjectToObject<? super T, ? extends V> mapper) { + return new OUOCPap<T,V>(ex, origin, fence, array, mapper); + } + + public ParallelArrayWithDoubleMapping<T> withIndexedMapping + (IntAndObjectToDouble<? super T> mapper) { + return new OUDCPap<T>(ex, origin, fence, array, mapper); + } + + public ParallelArrayWithLongMapping<T> withIndexedMapping + (IntAndObjectToLong<? super T> mapper) { + return new OULCPap<T>(ex, origin, fence, array, mapper); + } + + public int indexOf(T target) { + AtomicInteger result = new AtomicInteger(-1); + PAS.FJOIndexOf f = new PAS.FJOIndexOf + (this, origin, fence, null, result, target); + ex.invoke(f); + return result.get(); + } + + public int binarySearch(T target) { + final Object[] a = this.array; + int lo = origin; + int hi = fence - 1; + while (lo <= hi) { + int mid = (lo + hi) >>> 1; + int c = ((Comparable)target).compareTo((Comparable)a[mid]); + if (c == 0) + return mid; + else if (c < 0) + hi = mid - 1; + else + lo = mid + 1; + } + return -1; + } + + public int binarySearch(T target, Comparator<? super T> comparator) { + Comparator cmp = comparator; + final Object[] a = this.array; + int lo = origin; + int hi = fence - 1; + while (lo <= hi) { + int mid = (lo + hi) >>> 1; + int c = cmp.compare(target, a[mid]); + if (c == 0) + return mid; + else if (c < 0) + hi = mid - 1; + else + lo = mid + 1; + } + return -1; + } + + public ParallelArrayWithBounds<T> cumulate(Reducer<T> reducer, T base) { + PAS.FJOCumulateOp op = new PAS.FJOCumulateOp(this, reducer, base); + PAS.FJOScan r = new PAS.FJOScan(null, op, origin, fence); + ex.invoke(r); + return this; + } + + public T precumulate(Reducer<T> reducer, T base) { + PAS.FJOPrecumulateOp op = new PAS.FJOPrecumulateOp + (this, reducer, base); + PAS.FJOScan r = new PAS.FJOScan(null, op, origin, fence); + ex.invoke(r); + return (T)(r.out); + } + + public ParallelArrayWithBounds<T> sort + (Comparator<? super T> cmp) { + final Object[] a = this.array; + Class tc = array.getClass().getComponentType(); + T[] ws = (T[])Array.newInstance(tc, fence); + ex.invoke(new PAS.FJOSorter + (cmp, array, ws, origin, + fence - origin, getThreshold())); + return this; + } + + public ParallelArrayWithBounds<T> sort() { + final Object[] a = this.array; + Class tc = array.getClass().getComponentType(); + if (!Comparable.class.isAssignableFrom(tc)) { + sort(CommonOps.castedComparator()); + } + else { + Comparable[] ca = (Comparable[])array; + Comparable[] ws = (Comparable[])Array.newInstance(tc, fence); + ex.invoke(new PAS.FJOCSorter + (ca, ws, origin, + fence - origin, getThreshold())); + } + return this; + } + + final void leafApply(int lo, int hi, Procedure procedure) { + final Object[] a = this.array; + for (int i = lo; i < hi; ++i) + procedure.op(a[i]); + } + + final Object leafReduce(int lo, int hi, Reducer reducer, Object base) { + if (lo >= hi) + return base; + final Object[] a = this.array; + Object r = a[lo]; + for (int i = lo+1; i < hi; ++i) + r = reducer.op(r, a[i]); + return r; + } + + final void leafTransform(int l, int h, Op op) { + final Object[] a = this.array; + for (int i = l; i < h; ++i) + a[i] = op.op(a[i]); + } + + final void leafIndexMap(int l, int h, IntToObject op) { + final Object[] a = this.array; + for (int i = l; i < h; ++i) + a[i] = op.op(i); + } + + final void leafBinaryIndexMap(int l, int h, IntAndObjectToObject op) { + final Object[] a = this.array; + for (int i = l; i < h; ++i) + a[i] = op.op(i, a[i]); + } + + final void leafGenerate(int l, int h, Generator generator) { + final Object[] a = this.array; + for (int i = l; i < h; ++i) + a[i] = generator.op(); + } + + final void leafFill(int l, int h, Object value) { + final Object[] a = this.array; + for (int i = l; i < h; ++i) + a[i] = value; + } + + final void leafCombineInPlace(int l, int h, Object[] other, + int otherOffset, BinaryOp combiner) { + final Object[] a = this.array; + int k = l + otherOffset; + for (int i = l; i < h; ++i) + a[i] = combiner.op(a[i], other[k++]); + } + + final void leafCombineInPlace(int l, int h, + ParallelArrayWithMapping other, + int otherOffset, BinaryOp combiner) { + final Object[] a = this.array; + int k = l + otherOffset; + if (other.hasFilter()) { + for (int i = l; i < h; ++i) { + if (other.isSelected(k)) + a[i] = combiner.op(a[i], other.oget(k)); + k++; + } + } + else if (other.hasMap()) { + for (int i = l; i < h; ++i) + a[i] = combiner.op(a[i], other.oget(k++)); + } + else { + Object[] b = other.array; + for (int i = l; i < h; ++i) + a[i] = combiner.op(a[i], b[k++]); + } + } + } + + static class DUPap extends ParallelDoubleArrayWithBounds { + DUPap(ForkJoinPool ex, int origin, int fence, double[] array) { + super(ex, origin, fence, array); + } + + public ParallelDoubleArrayWithBounds withBounds(int lo, int hi) { + boundsCheck(lo, hi); + return new DUPap(ex, origin + lo, origin + hi, array); + } + + public ParallelDoubleArrayWithFilter withFilter(DoublePredicate selector) { + return new DFPap(ex, origin, fence, array, selector); + } + + public ParallelDoubleArrayWithFilter withIndexedFilter + (IntAndDoublePredicate selector) { + return new DRPap(ex, origin, fence, array, selector); + } + + public <U> ParallelDoubleArrayWithMapping<U> withMapping + (DoubleToObject<? extends U> op) { + return new DUOMPap<U>(ex, origin, fence, array, op); + } + + public ParallelDoubleArrayWithDoubleMapping withMapping(DoubleOp op) { + return new DUDMPap(ex, origin, fence, array, op); + } + + public ParallelDoubleArrayWithLongMapping withMapping(DoubleToLong op) { + return new DULMPap(ex, origin, fence, array, op); + } + + public <V> ParallelDoubleArrayWithMapping<V> withIndexedMapping + (IntAndDoubleToObject<? extends V> mapper) { + return new DUOCPap<V>(ex, origin, fence, array, mapper); + } + + public ParallelDoubleArrayWithDoubleMapping withIndexedMapping + (IntAndDoubleToDouble mapper) { + return new DUDCPap(ex, origin, fence, array, mapper); + } + + public ParallelDoubleArrayWithLongMapping withIndexedMapping + (IntAndDoubleToLong mapper) { + return new DULCPap(ex, origin, fence, array, mapper); + } + + public int indexOf(double target) { + AtomicInteger result = new AtomicInteger(-1); + PAS.FJDIndexOf f = new PAS.FJDIndexOf + (this, origin, fence, null, result, target); + ex.invoke(f); + return result.get(); + } + + public int binarySearch(double target) { + final double[] a = this.array; + int lo = origin; + int hi = fence - 1; + while (lo <= hi) { + int mid = (lo + hi) >>> 1; + double m = a[mid]; + if (target == m) + return mid; + else if (target < m) + hi = mid - 1; + else + lo = mid + 1; + } + return -1; + } + + public int binarySearch(double target, DoubleComparator comparator) { + final double[] a = this.array; + int lo = origin; + int hi = fence - 1; + while (lo <= hi) { + int mid = (lo + hi) >>> 1; + int c = comparator.compare(target, a[mid]); + if (c == 0) + return mid; + else if (c < 0) + hi = mid - 1; + else + lo = mid + 1; + } + return -1; + } + + public ParallelDoubleArrayWithBounds cumulate(DoubleReducer reducer, + double base) { + PAS.FJDCumulateOp op = new PAS.FJDCumulateOp(this, reducer, base); + PAS.FJDScan r = new PAS.FJDScan(null, op, origin, fence); + ex.invoke(r); + return this; + } + + public ParallelDoubleArrayWithBounds cumulateSum() { + PAS.FJDCumulatePlusOp op = new PAS.FJDCumulatePlusOp(this); + PAS.FJDScan r = new PAS.FJDScan(null, op, origin, fence); + ex.invoke(r); + return this; + } + + public double precumulate(DoubleReducer reducer, double base) { + PAS.FJDPrecumulateOp op = new PAS.FJDPrecumulateOp(this, reducer, base); + PAS.FJDScan r = new PAS.FJDScan(null, op, origin, fence); + ex.invoke(r); + return r.out; + } + + public double precumulateSum() { + PAS.FJDPrecumulatePlusOp op = new PAS.FJDPrecumulatePlusOp(this); + PAS.FJDScan r = new PAS.FJDScan(null, op, origin, fence); + ex.invoke(r); + return r.out; + } + + public ParallelDoubleArrayWithBounds sort(DoubleComparator cmp) { + ex.invoke(new PAS.FJDSorter + (cmp, this.array, new double[fence], + origin, fence - origin, getThreshold())); + return this; + } + + public ParallelDoubleArrayWithBounds sort() { + ex.invoke(new PAS.FJDCSorter + (this.array, new double[fence], + origin, fence - origin, getThreshold())); + return this; + } + + final void leafApply(int lo, int hi, DoubleProcedure procedure) { + final double[] a = this.array; + for (int i = lo; i < hi; ++i) + procedure.op(a[i]); + } + + final double leafReduce(int lo, int hi, DoubleReducer reducer, + double base) { + if (lo >= hi) + return base; + final double[] a = this.array; + double r = a[lo]; + for (int i = lo+1; i < hi; ++i) + r = reducer.op(r, a[i]); + return r; + } + + final void leafTransform(int l, int h, DoubleOp op) { + final double[] a = this.array; + for (int i = l; i < h; ++i) + a[i] = op.op(a[i]); + } + + final void leafIndexMap(int l, int h, IntToDouble op) { + final double[] a = this.array; + for (int i = l; i < h; ++i) + a[i] = op.op(i); + } + + final void leafBinaryIndexMap(int l, int h, IntAndDoubleToDouble op) { + final double[] a = this.array; + for (int i = l; i < h; ++i) + a[i] = op.op(i, a[i]); + } + + final void leafGenerate(int l, int h, DoubleGenerator generator) { + final double[] a = this.array; + for (int i = l; i < h; ++i) + a[i] = generator.op(); + } + + final void leafFill(int l, int h, double value) { + final double[] a = this.array; + for (int i = l; i < h; ++i) + a[i] = value; + } + + final void leafCombineInPlace + (int l, int h, double[] other, + int otherOffset, BinaryDoubleOp combiner) { + final double[] a = this.array; + int k = l + otherOffset; + for (int i = l; i < h; ++i) + a[i] = combiner.op(a[i], other[k++]); + } + + final void leafCombineInPlace + (int l, int h, + ParallelDoubleArrayWithDoubleMapping other, + int otherOffset, BinaryDoubleOp combiner) { + final double[] a = this.array; + int k = l + otherOffset; + if (other.hasFilter()) { + for (int i = l; i < h; ++i) { + if (other.isSelected(k)) + a[i] = combiner.op(a[i], other.dget(k)); + k++; + } + } + else if (other.hasMap()) { + for (int i = l; i < h; ++i) + a[i] = combiner.op(a[i], other.dget(k++)); + } + else { + double[] b = other.array; + for (int i = l; i < h; ++i) + a[i] = combiner.op(a[i], b[k++]); + } + + } + } + + static class LUPap extends ParallelLongArrayWithBounds { + LUPap(ForkJoinPool ex, int origin, int fence, + long[] array) { + super(ex, origin, fence, array); + } + + public ParallelLongArrayWithBounds withBounds(int lo, int hi) { + boundsCheck(lo, hi); + return new LUPap(ex, origin + lo, origin + hi, array); + } + + public ParallelLongArrayWithFilter withFilter(LongPredicate selector) { + return new LFPap(ex, origin, fence, array, selector); + } + + public ParallelLongArrayWithFilter withIndexedFilter + (IntAndLongPredicate selector) { + return new LRPap(ex, origin, fence, array, selector); + } + + public <U> ParallelLongArrayWithMapping<U> withMapping + (LongToObject<? extends U> op) { + return new LUOMPap<U>(ex, origin, fence, array, op); + } + + public ParallelLongArrayWithLongMapping withMapping(LongOp op) { + return new LULMPap(ex, origin, fence, array, op); + } + + public ParallelLongArrayWithDoubleMapping withMapping(LongToDouble op) { + return new LUDMPap(ex, origin, fence, array, op); + } + + public <V> ParallelLongArrayWithMapping<V> withIndexedMapping + (IntAndLongToObject<? extends V> mapper) { + return new LUOCPap<V>(ex, origin, fence, array, mapper); + } + + public ParallelLongArrayWithDoubleMapping withIndexedMapping + (IntAndLongToDouble mapper) { + return new LUDCPap(ex, origin, fence, array, mapper); + } + + public ParallelLongArrayWithLongMapping withIndexedMapping + (IntAndLongToLong mapper) { + return new LULCPap(ex, origin, fence, array, mapper); + } + + public int indexOf(long target) { + AtomicInteger result = new AtomicInteger(-1); + PAS.FJLIndexOf f = new PAS.FJLIndexOf + (this, origin, fence, null, result, target); + ex.invoke(f); + return result.get(); + } + + public int binarySearch(long target) { + final long[] a = this.array; + int lo = origin; + int hi = fence - 1; + while (lo <= hi) { + int mid = (lo + hi) >>> 1; + long m = a[mid]; + if (target == m) + return mid; + else if (target < m) + hi = mid - 1; + else + lo = mid + 1; + } + return -1; + } + + public int binarySearch(long target, LongComparator comparator) { + final long[] a = this.array; + int lo = origin; + int hi = fence - 1; + while (lo <= hi) { + int mid = (lo + hi) >>> 1; + int c = comparator.compare(target, a[mid]); + if (c == 0) + return mid; + else if (c < 0) + hi = mid - 1; + else + lo = mid + 1; + } + return -1; + } + + public ParallelLongArrayWithBounds cumulate(LongReducer reducer, long base) { + PAS.FJLCumulateOp op = new PAS.FJLCumulateOp(this, reducer, base); + PAS.FJLScan r = new PAS.FJLScan(null, op, origin, fence); + ex.invoke(r); + return this; + } + + public ParallelLongArrayWithBounds cumulateSum() { + PAS.FJLCumulatePlusOp op = new PAS.FJLCumulatePlusOp(this); + PAS.FJLScan r = new PAS.FJLScan(null, op, origin, fence); + ex.invoke(r); + return this; + } + + public long precumulate(LongReducer reducer, long base) { + PAS.FJLPrecumulateOp op = new PAS.FJLPrecumulateOp + (this, reducer, base); + PAS.FJLScan r = new PAS.FJLScan(null, op, origin, fence); + ex.invoke(r); + return r.out; + } + + public long precumulateSum() { + PAS.FJLPrecumulatePlusOp op = new PAS.FJLPrecumulatePlusOp(this); + PAS.FJLScan r = new PAS.FJLScan(null, op, origin, fence); + ex.invoke(r); + return r.out; + } + + public ParallelLongArrayWithBounds sort(LongComparator cmp) { + ex.invoke(new PAS.FJLSorter + (cmp, this.array, new long[fence], + origin, fence - origin, getThreshold())); + return this; + } + + public ParallelLongArrayWithBounds sort() { + ex.invoke(new PAS.FJLCSorter + (this.array, new long[fence], + origin, fence - origin, getThreshold())); + return this; + } + + final void leafApply(int lo, int hi, LongProcedure procedure) { + final long[] a = this.array; + for (int i = lo; i < hi; ++i) + procedure.op(a[i]); + } + + final long leafReduce(int lo, int hi, LongReducer reducer, long base) { + if (lo >= hi) + return base; + final long[] a = this.array; + long r = a[lo]; + for (int i = lo+1; i < hi; ++i) + r = reducer.op(r, a[i]); + return r; + } + + final void leafTransform(int l, int h, LongOp op) { + final long[] a = this.array; + for (int i = l; i < h; ++i) + a[i] = op.op(a[i]); + } + + final void leafIndexMap(int l, int h, IntToLong op) { + final long[] a = this.array; + for (int i = l; i < h; ++i) + a[i] = op.op(i); + } + + final void leafBinaryIndexMap(int l, int h, IntAndLongToLong op) { + final long[] a = this.array; + for (int i = l; i < h; ++i) + a[i] = op.op(i, a[i]); + } + + final void leafGenerate(int l, int h, LongGenerator generator) { + final long[] a = this.array; + for (int i = l; i < h; ++i) + a[i] = generator.op(); + } + + final void leafFill(int l, int h, long value) { + final long[] a = this.array; + for (int i = l; i < h; ++i) + a[i] = value; + } + + final void leafCombineInPlace + (int l, int h, long[] other, + int otherOffset, BinaryLongOp combiner) { + final long[] a = this.array; + int k = l + otherOffset; + for (int i = l; i < h; ++i) + a[i] = combiner.op(a[i], other[k++]); + } + + final void leafCombineInPlace + (int l, int h, + ParallelLongArrayWithLongMapping other, + int otherOffset, BinaryLongOp combiner) { + final long[] a = this.array; + int k = l + otherOffset; + if (other.hasFilter()) { + for (int i = l; i < h; ++i) { + if (other.isSelected(k)) + a[i] = combiner.op(a[i], other.lget(k)); + k++; + } + } + else if (other.hasMap()) { + for (int i = l; i < h; ++i) + a[i] = combiner.op(a[i], other.lget(k++)); + } + else { + long[] b = other.array; + for (int i = l; i < h; ++i) + a[i] = combiner.op(a[i], b[k++]); + } + } + } + + // Filtered (but unmapped) classes + static final class OFPap<T> extends ParallelArrayWithFilter<T> { + final Predicate<? super T> selector; + OFPap(ForkJoinPool ex, int origin, int fence, + T[] array, + Predicate<? super T> selector) { + super(ex, origin, fence, array); + this.selector = selector; + } + + boolean hasFilter() { return true; } + boolean isSelected(int i) { return selector.op(this.array[i]); } + + public ParallelArrayWithFilter<T> withFilter + (Predicate<? super T> selector) { + return new OFPap<T>(ex, origin, fence, array, + CommonOps.andPredicate(this.selector, selector)); + } + + public ParallelArrayWithFilter<T> withIndexedFilter + (IntAndObjectPredicate<? super T> selector) { + return new ORPap<T> + (ex, origin, fence, array, + compoundIndexedSelector(this.selector, selector)); + } + + public <U> ParallelArrayWithMapping<T, U> withMapping + (Op<? super T, ? extends U> op) { + return new OFOMPap<T,U>(ex, origin, fence, array, selector, op); + } + + public ParallelArrayWithDoubleMapping<T> withMapping + (ObjectToDouble<? super T> op) { + return new OFDMPap<T>(ex, origin, fence, array, selector, op); + } + + public ParallelArrayWithLongMapping<T> withMapping + (ObjectToLong<? super T> op) { + return new OFLMPap<T>(ex, origin, fence, array, selector, op); + } + + public <V> ParallelArrayWithMapping<T,V> withIndexedMapping + (IntAndObjectToObject<? super T, ? extends V> mapper) { + return new OFOCPap<T,V>(ex, origin, fence, array, selector, mapper); + } + + public ParallelArrayWithDoubleMapping<T> withIndexedMapping + (IntAndObjectToDouble<? super T> mapper) { + return new OFDCPap<T>(ex, origin, fence, array, selector, mapper); + } + + public ParallelArrayWithLongMapping<T> withIndexedMapping + (IntAndObjectToLong<? super T> mapper) { + return new OFLCPap<T>(ex, origin, fence, array, selector, mapper); + } + + void leafApply(int lo, int hi, Procedure procedure) { + final Predicate s = selector; + final Object[] a = this.array; + for (int i = lo; i < hi; ++i) { + Object x = a[i]; + if (s.op(x)) + procedure.op(x); + } + } + + Object leafReduce(int lo, int hi, Reducer reducer, Object base) { + final Predicate s = selector; + boolean gotFirst = false; + Object r = base; + final Object[] a = this.array; + for (int i = lo; i < hi; ++i) { + Object x = a[i]; + if (s.op(x)) { + if (!gotFirst) { + gotFirst = true; + r = x; + } + else + r = reducer.op(r, x); + } + } + return r; + } + + final void leafTransform(int l, int h, Op op) { + final Object[] a = this.array; + final Predicate s = selector; + for (int i = l; i < h; ++i) { + Object x = a[i]; + if (s.op(x)) + a[i] = op.op(x); + } + } + + final void leafIndexMap(int l, int h, IntToObject op) { + final Object[] a = this.array; + final Predicate s = selector; + for (int i = l; i < h; ++i) { + Object x = a[i]; + if (s.op(x)) + a[i] = op.op(i); + } + } + + final void leafBinaryIndexMap(int l, int h, IntAndObjectToObject op) { + final Object[] a = this.array; + final Predicate s = selector; + for (int i = l; i < h; ++i) { + Object x = a[i]; + if (s.op(x)) + a[i] = op.op(i, x); + } + } + + final void leafGenerate(int l, int h, Generator generator) { + final Object[] a = this.array; + final Predicate s = selector; + for (int i = l; i < h; ++i) { + if (s.op(a[i])) + a[i] = generator.op(); + } + } + + final void leafFill(int l, int h, Object value) { + final Object[] a = this.array; + final Predicate s = selector; + for (int i = l; i < h; ++i) { + if (s.op(a[i])) + a[i] = value; + } + } + + final void leafCombineInPlace + (int l, int h, Object[] other, + int otherOffset, BinaryOp combiner) { + final Object[] a = this.array; + final Predicate s = selector; + int k = l + otherOffset; + for (int i = l; i < h; ++i) { + Object x = a[i]; + if (s.op(x)) + a[i] = combiner.op(x, other[k]); + k++; + } + } + + final void leafCombineInPlace + (int l, int h, + ParallelArrayWithMapping other, + int otherOffset, BinaryOp combiner) { + final Object[] a = this.array; + final Predicate s = selector; + int k = l + otherOffset; + if (other.hasFilter()) { + for (int i = l; i < h; ++i) { + Object x = a[i]; + if (s.op(x) && other.isSelected(k)) + a[i] = combiner.op(x, other.oget(k)); + k++; + } + } + else if (other.hasMap()) { + for (int i = l; i < h; ++i) { + Object x = a[i]; + if (s.op(x)) + a[i] = combiner.op(x, other.oget(k)); + k++; + } + } + else { + Object[] b = other.array; + for (int i = l; i < h; ++i) { + Object x = a[i]; + if (s.op(x)) + a[i] = combiner.op(x, b[k]); + k++; + } + } + } + } + + static final class DFPap extends ParallelDoubleArrayWithFilter { + final DoublePredicate selector; + DFPap(ForkJoinPool ex, int origin, int fence, + double[] array, + DoublePredicate selector) { + super(ex, origin, fence, array); + this.selector = selector; + } + + boolean hasFilter() { return true; } + boolean isSelected(int i) { return selector.op(this.array[i]); } + + public ParallelDoubleArrayWithFilter withFilter(DoublePredicate selector) { + return new DFPap(ex, origin, fence, array, + CommonOps.andPredicate(this.selector, selector)); + } + + public ParallelDoubleArrayWithFilter withIndexedFilter + (IntAndDoublePredicate selector) { + return new DRPap + (ex, origin, fence, array, + compoundIndexedSelector(this.selector, selector)); + } + + public <U> ParallelDoubleArrayWithMapping<U> withMapping + (DoubleToObject<? extends U> op) { + return new DFOMPap<U>(ex, origin, fence, array, selector, op); + } + + public ParallelDoubleArrayWithDoubleMapping withMapping(DoubleOp op) { + return new DFDMPap(ex, origin, fence, array, selector, op); + } + + public ParallelDoubleArrayWithLongMapping withMapping(DoubleToLong op) { + return new DFLMPap(ex, origin, fence, array, selector, op); + } + + public <V> ParallelDoubleArrayWithMapping<V> withIndexedMapping + (IntAndDoubleToObject<? extends V> mapper) { + return new DFOCPap<V>(ex, origin, fence, array, selector, mapper); + } + + public ParallelDoubleArrayWithDoubleMapping withIndexedMapping + (IntAndDoubleToDouble mapper) { + return new DFDCPap(ex, origin, fence, array, selector, mapper); + } + + public ParallelDoubleArrayWithLongMapping withIndexedMapping + (IntAndDoubleToLong mapper) { + return new DFLCPap(ex, origin, fence, array, selector, mapper); + } + + final void leafApply(int lo, int hi, DoubleProcedure procedure) { + final DoublePredicate s = selector; + final double[] a = this.array; + for (int i = lo; i < hi; ++i) { + double x = a[i]; + if (s.op(x)) + procedure.op(x); + } + } + + final double leafReduce(int lo, int hi, DoubleReducer reducer, double base) { + final DoublePredicate s = selector; + boolean gotFirst = false; + double r = base; + final double[] a = this.array; + for (int i = lo... [truncated message content] |
From: <ipe...@us...> - 2009-03-06 18:22:01
|
Revision: 7887 http://x10.svn.sourceforge.net/x10/?rev=7887&view=rev Author: ipeshansky Date: 2009-03-06 18:21:56 +0000 (Fri, 06 Mar 2009) Log Message: ----------- Fix XTENLANG-227. Modified Paths: -------------- trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/MessagePassingCodeGenerator.java trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/X10CPPTranslator.java trunk/x10.runtime.17/src-cpp/x10aux/basic_functions.cc trunk/x10.runtime.17/src-cpp/x10aux/basic_functions.h Modified: trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/MessagePassingCodeGenerator.java =================================================================== --- trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/MessagePassingCodeGenerator.java 2009-03-06 08:56:59 UTC (rev 7886) +++ trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/MessagePassingCodeGenerator.java 2009-03-06 18:21:56 UTC (rev 7887) @@ -2077,9 +2077,6 @@ } } - if (context.inTemplate() && mi.typeParameters().size() != 0) { - sw.write("template "); - } boolean virtual_dispatch = true; if (t.isClass()) { X10ClassType ct = (X10ClassType)t.toClass(); @@ -2096,6 +2093,10 @@ sw.write(emitter.translateType(t)); sw.write("::"); } + // [IP] FIXME: virtual_dispatch test is temporary, until xlC is upgraded to v10 + if (context.inTemplate() && mi.typeParameters().size() != 0 && virtual_dispatch) { + sw.write("template "); + } sw.write(mangled_method_name(n.name().id().toString())); emitter.printTemplateInstantiation(mi, sw); sw.write("("); Modified: trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/X10CPPTranslator.java =================================================================== --- trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/X10CPPTranslator.java 2009-03-06 08:56:59 UTC (rev 7886) +++ trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/X10CPPTranslator.java 2009-03-06 18:21:56 UTC (rev 7887) @@ -376,8 +376,6 @@ "-I"+X10LANG+"/include", // dist "-I.", "-DTRANSPORT="+TRANSPORT, - "-Wno-long-long", - "-Wno-unused-parameter", }; /** These go after the files */ public static final String[] postArgs = new String[] { @@ -529,6 +527,8 @@ private static class Cygwin_CXXCommandBuilder extends CXXCommandBuilder { /** These go before the files */ public static final String[] preArgsCygwin = new String[] { + "-Wno-long-long", + "-Wno-unused-parameter", "-msse2", "-mfpmath=sse", }; @@ -560,6 +560,8 @@ public static final boolean USE_X86 = PLATFORM.endsWith("_x86"); /** These go before the files */ public static final String[] preArgsLinux = new String[] { + "-Wno-long-long", + "-Wno-unused-parameter", "-pthread", USE_X86 ? "-msse2" : DUMMY, USE_X86 ? "-mfpmath=sse" : DUMMY, @@ -599,6 +601,8 @@ //"mpCC_r -q64 -qrtti=all" /** These go before the files */ public static final String[] preArgsAIX = new String[] { + USE_XLC ? DUMMY : "-Wno-long-long", + USE_XLC ? "-qsuppress=1540-0809" : "-Wno-unused-parameter", USE_XLC ? "-q64" : "-maix64", // Assume 64-bit USE_XLC ? "-qrtti=all" : DUMMY, //USE_XLC ? DUMMY : "-pipe", // TODO: is this needed? Modified: trunk/x10.runtime.17/src-cpp/x10aux/basic_functions.cc =================================================================== --- trunk/x10.runtime.17/src-cpp/x10aux/basic_functions.cc 2009-03-06 08:56:59 UTC (rev 7886) +++ trunk/x10.runtime.17/src-cpp/x10aux/basic_functions.cc 2009-03-06 18:21:56 UTC (rev 7887) @@ -64,11 +64,11 @@ // scientific notation int e = (int)::floor(::log(::fabs(v))/::log(10.0)); //exponent // volatile because reordering could change computed floating point value - volatile double m = v / ::pow(10, e); //mantissa + volatile double m = v / ::pow(10.0, e); //mantissa if (e < -10) { // avoid touching -Infinity m = v * 1E10; - m /= ::pow(10, e+10); + m /= ::pow(10.0, e+10); } if (e < 0) { ::snprintf(buf, sizeof(buf), "%.1f", m); Modified: trunk/x10.runtime.17/src-cpp/x10aux/basic_functions.h =================================================================== --- trunk/x10.runtime.17/src-cpp/x10aux/basic_functions.h 2009-03-06 08:56:59 UTC (rev 7886) +++ trunk/x10.runtime.17/src-cpp/x10aux/basic_functions.h 2009-03-06 18:21:56 UTC (rev 7887) @@ -152,7 +152,7 @@ - template<class T> static inline ref<x10::lang::String> to_string(ref<T> x) { + template<class T> ref<x10::lang::String> to_string(ref<T> x) { return x->toString(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ipe...@us...> - 2009-03-07 02:37:22
|
Revision: 7889 http://x10.svn.sourceforge.net/x10/?rev=7889&view=rev Author: ipeshansky Date: 2009-03-07 02:37:09 +0000 (Sat, 07 Mar 2009) Log Message: ----------- Fix XTENLANG-345 by always emitting fully qualified types Use typesystem accessors instead of string literals for known type names Don't emit "using namespace ..." directives and remove them from headers Get rid of pendingImports Use chevrons() properly Whitespace + minor readability improvements Modified Paths: -------------- trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/types/X10CPPContext_c.java trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/Emitter.java trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/MessagePassingCodeGenerator.java trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/X10CPPTranslator.java trunk/x10.runtime.17/src-cpp/x10rt17.h Modified: trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/types/X10CPPContext_c.java =================================================================== --- trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/types/X10CPPContext_c.java 2009-03-06 23:49:07 UTC (rev 7888) +++ trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/types/X10CPPContext_c.java 2009-03-07 02:37:09 UTC (rev 7889) @@ -77,8 +77,6 @@ public static String lastReturnVar; public boolean canInline; - public ArrayList pendingImports = new ArrayList(); - public static ArrayList pendingImplicitImports = new ArrayList(); public static ArrayList<ClassMember> pendingStaticDecls = new ArrayList<ClassMember>(); public static HashMap classesWithAsyncSwitches = new HashMap(); public static HashMap classesWithArrayCopySwitches = new HashMap(); Modified: trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/Emitter.java =================================================================== --- trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/Emitter.java 2009-03-06 23:49:07 UTC (rev 7888) +++ trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/Emitter.java 2009-03-07 02:37:09 UTC (rev 7889) @@ -260,6 +260,7 @@ } else { if (ct.def().isNested()) { + assert (false) : ("Nested class alert!"); Name mangled = StaticNestedClassRemover.mangleName(ct.def()); QName pkg = ct.package_() != null ? ct.package_().fullName() : null; QName full = QName.make(pkg, mangled); @@ -269,17 +270,14 @@ } } if (ct.typeArguments().size() != 0) { - name += "<"; + String args = ""; int s = ct.typeArguments().size(); for (Type t: ct.typeArguments()) { - name += translateType(t, true); // type arguments are always translated as refs - s--; - if (s > 0) - name +=", "; + args += translateType(t, true); // type arguments are always translated as refs + if (--s > 0) + args +=", "; } - if (name.endsWith(">")) - name += " "; - name += ">"; + name += chevrons(args); } } else if (type instanceof ParameterType) { name = ((ParameterType)type).name().toString(); @@ -550,15 +548,15 @@ } void printRTT(X10ClassType ct, ClassifiedStream h) { + X10TypeSystem_c xts = (X10TypeSystem_c) ct.typeSystem(); String x10name = ct.fullName().toString(); int num_parents = 1 + ct.interfaces().size(); - // h.write("class RTT : public x10aux::RuntimeType {"); h.newline(4); h.begin(0); h.write("public:"); h.newline(); h.write("static RTT * const it;"); h.newline(); h.write("virtual void init() {"); h.newline(4); h.begin(0); h.write("initParents("+num_parents); - h.write(", x10aux::getRTT" + chevrons(ct.superClass()==null ? "x10::lang::Ref" : translateType(ct.superClass())) + "()"); + h.write(", x10aux::getRTT" + chevrons(ct.superClass()==null ? translateType(xts.Ref()) : translateType(ct.superClass())) + "()"); for (Type iface : ct.interfaces()) { h.write(", x10aux::getRTT"+chevrons(translateType(iface))+"()"); } @@ -606,6 +604,7 @@ } void printInheritance(ClassDecl_c n, CodeWriter h, Translator tr) { + X10TypeSystem_c xts = (X10TypeSystem_c) tr.typeSystem(); String extends_ = n.superClass()==null ? null : translateType(n.superClass().type()); ArrayList<String> implements_ = new ArrayList<String>(); for (TypeNode tn : n.interfaces()) { @@ -621,12 +620,13 @@ // interface, since otherwise extends_ is Ref, Value, or some // user-defined type. + String x_l_Object = translateType(xts.Object()); if (extends_ == null && implements_.isEmpty()) { //Interfaces must always extend something in c++ - implements_.add("x10::lang::Object"); - } else if (extends_ != null && implements_.contains("x10::lang::Object")) { + implements_.add(x_l_Object); + } else if (extends_ != null && implements_.contains(x_l_Object)) { //Cosmetic: No point implementing Object if we're already extending something - implements_.remove("x10::lang::Object"); + implements_.remove(x_l_Object); } String prefix = ":"; @@ -831,11 +831,8 @@ w.write("const x10aux::serialization_id_t "+klass+"::"+SERIALIZATION_ID_FIELD+" = "); w.newline(4); w.write("x10aux::DeserializationDispatcher::addDeserializer("); - if (context.inTemplate()) { - w.write(klass+"::template "+DESERIALIZER_METHOD+"<Object>);"); - } else { - w.write(klass+"::"+DESERIALIZER_METHOD+"<Object>);"); - } + String template = context.inTemplate() ? "template " : ""; + w.write(klass+"::"+template+DESERIALIZER_METHOD+chevrons(translateType(ts.Object()))+");"); w.newline(); w.forceNewline(); } Modified: trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/MessagePassingCodeGenerator.java =================================================================== --- trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/MessagePassingCodeGenerator.java 2009-03-06 23:49:07 UTC (rev 7888) +++ trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/MessagePassingCodeGenerator.java 2009-03-07 02:37:09 UTC (rev 7889) @@ -697,13 +697,6 @@ w.forceNewline(0); w.forceNewline(0); - if (context.package_() != null) { - w.write("using namespace "); - w.write(Emitter.translateFQN(context.package_().fullName().toString())); - w.write(";"); - w.newline(); - } - String pkg = ""; if (context.package_() != null) pkg = context.package_().fullName().toString(); @@ -831,24 +824,6 @@ } } - ArrayList<String> nsHistory = new ArrayList<String>(); - for (Iterator is = context.pendingImports.iterator(); is.hasNext();) { - Import_c in = (Import_c) is.next(); - QName nsName = in.name(); - if (in.kind() == Import_c.CLASS) { - // [DC] couldn't we define a local typedef to represent this x10 concept? - nsName = nsName.qualifier(); - } else { - assert (in.kind() == Import_c.PACKAGE); - } - emitter.emitUniqueNS(nsName, nsHistory, h); - h.newline(); - } - context.pendingImports.clear(); // Just processed all imports - clean up - QName x10_lang = xts.Object().toClass().fullName().qualifier(); - emitter.emitUniqueNS(x10_lang, nsHistory, h); - h.newline(); - h.forceNewline(0); if (def.package_() != null) { QName pkgName = def.package_().get().fullName(); Emitter.openNamespaces(h, pkgName); @@ -1281,20 +1256,14 @@ - public void visit(PackageNode_c n) { + public void visit(PackageNode_c n) { assert (false); - sw.write(mangled_non_method_name(translateFQN(n.package_().get().fullName().toString()))); - } + sw.write(mangled_non_method_name(translateFQN(n.package_().get().fullName().toString()))); + } - public void visit(Import_c n) { + public void visit(Import_c n) { assert (false); - if (n.kind() == Import_c.CLASS || n.kind() == Import_c.PACKAGE) { - X10CPPContext_c context = (X10CPPContext_c) tr.context(); - context.pendingImports.add(n); - } - else - throw new InternalCompilerError("Unknown import kind"); - } + } private void processMain(X10ClassType container) { @@ -2273,7 +2242,8 @@ } public void visit(StringLit_c n) { - sw.write("String::Lit(\""); + X10TypeSystem_c xts = (X10TypeSystem_c) tr.typeSystem(); + sw.write(emitter.translateType(xts.String())+"::Lit(\""); sw.write(StringUtil.escape(n.stringValue())); sw.write("\")"); } @@ -2385,6 +2355,7 @@ assert (n.finallyBlock() != null); X10CPPContext_c context = (X10CPPContext_c) tr.context(); + X10TypeSystem_c xts = (X10TypeSystem_c) tr.typeSystem(); X10CPPContext_c c = (X10CPPContext_c) context.pushBlock(); c.setinClosure(true); @@ -2422,19 +2393,8 @@ String cname = getClosureName(hostClassName, id); - boolean in_template_closure = false; + final boolean in_template_closure = !freeTypeParams.isEmpty(); - StringBuffer cnamet_ = new StringBuffer(cname); - String prefix = "<"; - for (Type t : freeTypeParams) { - in_template_closure = true; - cnamet_.append(prefix + emitter.translateType(t)); - prefix = ","; - } - if (in_template_closure) cnamet_.append(" >"); - String cnamet = cnamet_.toString(); - - // create closure and packed arguments // Prepend this stream to closures. Closures are created from the outside in. @@ -2453,13 +2413,13 @@ } //String className = emitter.translateType(c.currentClass()); - String superType = "x10::lang::" + mangled_non_method_name("VoidFun_0_0"); + String superType = emitter.translateType(xts.closureBaseInterfaceDef(0, 0, true).asType()); // class header - if (!freeTypeParams.isEmpty()) + if (in_template_closure) emitter.printTemplateSignature(freeTypeParams, inc); inc.write("class "+cname+" : "); inc.begin(0); - inc.write("public x10::lang::Value, "); inc.newline(); + inc.write("public "+emitter.translateType(xts.Value())+", "); inc.newline(); inc.write("public virtual "+superType); inc.end(); inc.newline(); inc.write("{") ; inc.newline(4); inc.begin(0); inc.write("public:") ; inc.newline(); inc.forceNewline(); @@ -2510,9 +2470,9 @@ inc.newline(); inc.forceNewline(); // FIXME: this should not be needed - inc.write(make_ref("x10::lang::String")+" toString() {"); + inc.write(emitter.translateType(xts.String(), true)+" toString() {"); inc.newline(4); inc.begin(0); - inc.write("return x10::lang::String::Lit(\""+StringUtil.escape(n.position().nameAndLineString())+"\");"); + inc.write("return "+emitter.translateType(xts.String())+"::Lit(\""+StringUtil.escape(n.position().nameAndLineString())+"\");"); inc.end(); inc.newline(); inc.write("}"); inc.end(); inc.newline(); inc.forceNewline(); @@ -2532,7 +2492,7 @@ // RTT of the closure (which doesn't exist) // first get the template arguments (if any) - prefix="<"; + String prefix="<"; StringBuffer sb = new StringBuffer(); for (Type t : freeTypeParams) { sb.append(prefix+emitter.translateType(t, true)); @@ -2569,8 +2529,9 @@ public void visit(Try_c n) { X10CPPContext_c context = (X10CPPContext_c) tr.context(); - if (n.finallyBlock() != null) { - // FIXME: this doesn't work. Use closures + X10TypeSystem_c xts = (X10TypeSystem_c) tr.typeSystem(); + if (n.finallyBlock() != null) { + // FIXME: break, continue, and return don't work sw.write("{"); sw.newline(0); sw.begin(0); // Create a closure with C++ reference fields that encapsulates the finally block. @@ -2580,7 +2541,7 @@ String tempClassDef = tempClass+"def"; sw.write("struct " + tempClassDef + " {"); sw.newline(4); sw.begin(0); - String closureType = make_ref("x10::lang::" + mangled_non_method_name("VoidFun_0_0")); + String closureType = emitter.translateType(xts.closureBaseInterfaceDef(0, 0, true).asType(), true); sw.write(closureType+" _closure;"); sw.newline(); String closureName = getId(); @@ -2615,7 +2576,7 @@ // *not* an interface and thus is not virtually inheritted. If it // were, we would have to static_cast the exception to Throwable on // throw (otherwise we would need to offset by an unknown quantity). - String exception_ref = make_ref("Throwable"); + String exception_ref = emitter.translateType(xts.Throwable(), true); sw.write(exception_ref+"& " + excVar + " = ("+exception_ref+"&)" + refVar + ";"); context.setExceptionVar(excVar); for (Iterator it = n.catchBlocks().iterator(); it.hasNext(); ) { @@ -2763,14 +2724,14 @@ sw.newline(4); sw.begin(0); String name = "__i" + form.name(); - sw.write("Iterator<"); - String fType = emitter.translateType(form.type().type(), true); - sw.write(fType + (fType.endsWith(">") ? " " : "")); - sw.write(">* " + name + ";"); + sw.write(emitter.translateType(xts.Iterator(form.type().type()))); + sw.write("* " + name + ";"); sw.newline(); sw.write(name + " = &*"); // FIXME - if (!xts.typeDeepBaseEquals(form.type().type(), itType)) - sw.write("x10aux::convert_iterator<"+fType+","+emitter.translateType(itType, true)+" >"); + if (!xts.typeDeepBaseEquals(form.type().type(), itType)) { + String fType = emitter.translateType(form.type().type(), true); + sw.write("x10aux::convert_iterator"+chevrons(fType+","+emitter.translateType(itType, true))); + } sw.write("(("); n.print(n.domain(), sw, tr); sw.write(")->iterator());"); @@ -2816,55 +2777,55 @@ } - public void visit(ForEach_c n) { + public void visit(ForEach_c n) { assert (false) : ("ForEach should have been desugared earlier"); - } + } - public void visit(AtEach_c n) { + public void visit(AtEach_c n) { assert (false) : ("AtEach should have been desugared earlier"); - } + } - public void visit(Finish_c n) { + public void visit(Finish_c n) { assert (false) : ("Finish should have been desugared earlier"); - } + } - public void visit(ArrayAccess_c n) { - assert (false); - } + public void visit(ArrayAccess_c n) { + assert (false); + } - public void visit(ParExpr_c n) { - n.print(n.expr(), sw, tr); - } + public void visit(ParExpr_c n) { + n.print(n.expr(), sw, tr); + } - public void visit(Conditional_c n) { - X10CPPContext_c context = (X10CPPContext_c) tr.context(); - n.printSubExpr(n.cond(), false, sw, tr); - sw.unifiedBreak(2); - sw.write("? "); + public void visit(Conditional_c n) { + X10CPPContext_c context = (X10CPPContext_c) tr.context(); + n.printSubExpr(n.cond(), false, sw, tr); + sw.unifiedBreak(2); + sw.write("? "); sw.write("("+emitter.translateType(n.type(), true)+")("); sw.begin(0); - n.printSubExpr(n.consequent(), true, sw, tr); + n.printSubExpr(n.consequent(), true, sw, tr); sw.end(); sw.write(")"); sw.unifiedBreak(2); - sw.write(": "); + sw.write(": "); sw.write("("+emitter.translateType(n.type(), true)+")("); sw.begin(0); - n.printSubExpr(n.alternative(), true, sw, tr); + n.printSubExpr(n.alternative(), true, sw, tr); sw.end(); sw.write(")"); - } + } public void visit(Here_c n) { assert (false) : ("Here should have been desugared earlier"); } - public void visit(Async_c n) { - assert (false) : ("Async should have been desugared earlier"); - } + public void visit(Async_c n) { + assert (false) : ("Async should have been desugared earlier"); + } public void visit(X10Special_c n) { @@ -2893,21 +2854,22 @@ } - public static String getClosureName(String className, int id) { + public static String getClosureName(String className, int id) { // TODO: factor out into a constant - return className+"__closure__"+id; - } + return className+"__closure__"+id; + } - public void visit(Closure_c n) { + public void visit(Closure_c n) { - X10CPPContext_c c = (X10CPPContext_c) tr.context(); + X10CPPContext_c c = (X10CPPContext_c) tr.context(); - emitter.enterClosure(c); + emitter.enterClosure(c); - ClosureDef closureDef = n.closureDef(); - CodeInstance ci = closureDef.methodContainer().get(); - X10ClassType hostClassType = (X10ClassType) closureDef.typeContainer().get(); + ClosureDef closureDef = n.closureDef(); + CodeInstance ci = closureDef.methodContainer().get(); + X10ClassType hostClassType = (X10ClassType) closureDef.typeContainer().get(); X10ClassDef hostClassDef = hostClassType.x10Def(); + X10TypeSystem_c xts = (X10TypeSystem_c) tr.typeSystem(); List<Type> freeTypeParams = new ArrayList<Type>(); while (ci instanceof ClosureInstance) @@ -2927,13 +2889,13 @@ freeTypeParams.addAll(hostClassDef.typeParameters()); } - String hostClassName = emitter.translate_mangled_FQN(hostClassType.fullName().toString(), "_"); + String hostClassName = emitter.translate_mangled_FQN(hostClassType.fullName().toString(), "_"); - c.setinsideClosure(true); + c.setinsideClosure(true); - int id = getConstructorId(c); + int id = getConstructorId(c); - String cname = getClosureName(hostClassName, id); + String cname = getClosureName(hostClassName, id); boolean in_template_closure = false; @@ -2948,13 +2910,13 @@ String cnamet = cnamet_.toString(); - // create closure and packed arguments + // create closure and packed arguments - // Prepend this stream to closures. Closures are created from the outside in. - // Thus, later closures can be used by earlier ones, but not vice versa. - ClassifiedStream inc_s = in_template_closure ? - sw.getNewStream(StreamWrapper.Header, sw.header(), false) : - sw.getNewStream(StreamWrapper.Closures, true); + // Prepend this stream to closures. Closures are created from the outside in. + // Thus, later closures can be used by earlier ones, but not vice versa. + ClassifiedStream inc_s = in_template_closure ? + sw.getNewStream(StreamWrapper.Header, sw.header(), false) : + sw.getNewStream(StreamWrapper.Closures, true); sw.pushCurrentStream(inc_s); StreamWrapper inc = sw; @@ -2967,184 +2929,178 @@ Type retType = n.returnType().type(); //String className = emitter.translateType(c.currentClass()); - String superType = retType.isVoid() ? - "x10::lang::" + mangled_non_method_name("VoidFun_0_" + n.formals().size()) : - "x10::lang::" + mangled_non_method_name("Fun_0_" + n.formals().size()); - prefix = "<"; - for (Formal formal : n.formals()) { - superType = superType + prefix + emitter.translateType(formal.type().typeRef().get(), true); - prefix = ", "; - } - if (!retType.isVoid()) { - superType = superType + prefix + emitter.translateType(retType, true); - prefix = ", "; - } - if (!prefix.equals("<")) superType = superType +" >"; // don't emit " >" for void->void case + X10ClassType sup = (X10ClassType) xts.closureBaseInterfaceDef(0, n.formals().size(), retType.isVoid()).asType(); + List<Type> supArgs = new ArrayList<Type>(); + for (Formal formal : n.formals()) + supArgs.add(formal.type().typeRef().get()); + if (!retType.isVoid()) + supArgs.add(retType); + String superType = emitter.translateType(sup.typeArguments(supArgs)); - // class header + // class header if (!freeTypeParams.isEmpty()) emitter.printTemplateSignature(freeTypeParams, inc); - inc.write("class "+cname+" : "); inc.begin(0); - inc.write("public x10::lang::Value, "); inc.newline(); - inc.write("public virtual "+superType); inc.end(); inc.newline(); - inc.write("{") ; inc.newline(4); inc.begin(0); - inc.write("public:") ; inc.newline(); inc.forceNewline(); + inc.write("class "+cname+" : "); inc.begin(0); + inc.write("public "+emitter.translateType(xts.Value())+", "); inc.newline(); + inc.write("public virtual "+superType); inc.end(); inc.newline(); + inc.write("{") ; inc.newline(4); inc.begin(0); + inc.write("public:") ; inc.newline(); inc.forceNewline(); - inc.write("// closure body"); inc.newline(); - inc.write(emitter.translateType(retType, true)+" apply("); - prefix = ""; - for (Formal formal : n.formals()) { - inc.write(prefix); - n.print(formal, inc, tr); - prefix = ", "; - } - inc.write(") "); - n.print(n.body(), inc, tr); - inc.newline(); inc.forceNewline(); + inc.write("// closure body"); inc.newline(); + inc.write(emitter.translateType(retType, true)+" apply("); + prefix = ""; + for (Formal formal : n.formals()) { + inc.write(prefix); + n.print(formal, inc, tr); + prefix = ", "; + } + inc.write(") "); + n.print(n.body(), inc, tr); + inc.newline(); inc.forceNewline(); - inc.write("// captured environment"); inc.newline(); - emitter.printDeclarationList(inc, c, c.variables); - inc.forceNewline(); + inc.write("// captured environment"); inc.newline(); + emitter.printDeclarationList(inc, c, c.variables); + inc.forceNewline(); - inc.write("void "+SERIALIZE_ID_METHOD+"("+SERIALIZATION_BUFFER+" &buf, x10aux::addr_map& m) {"); - inc.newline(4); inc.begin(0); + inc.write("void "+SERIALIZE_ID_METHOD+"("+SERIALIZATION_BUFFER+" &buf, x10aux::addr_map& m) {"); + inc.newline(4); inc.begin(0); inc.write("buf.write(_serialization_id, m);"); inc.end(); inc.newline(); - inc.write("}"); inc.newline(); inc.forceNewline(); + inc.write("}"); inc.newline(); inc.forceNewline(); - inc.write("void "+SERIALIZE_BODY_METHOD+"("+SERIALIZATION_BUFFER+" &buf, x10aux::addr_map& m) {"); - inc.newline(4); inc.begin(0); - for (int i = 0; i < c.variables.size(); i++) { - if (i > 0) inc.newline(); - VarInstance var = (VarInstance) c.variables.get(i); - String name = var.name().toString(); - if (name.equals(THIS)) - name = SAVED_THIS; - else name = mangled_non_method_name(name); - inc.write("buf.write(" + name + ", m);"); - } - inc.end(); inc.newline(); - inc.write("}"); inc.newline(); inc.forceNewline(); + inc.write("void "+SERIALIZE_BODY_METHOD+"("+SERIALIZATION_BUFFER+" &buf, x10aux::addr_map& m) {"); + inc.newline(4); inc.begin(0); + // FIXME: factor out this loop + for (int i = 0; i < c.variables.size(); i++) { + if (i > 0) inc.newline(); + VarInstance var = (VarInstance) c.variables.get(i); + String name = var.name().toString(); + if (name.equals(THIS)) + name = SAVED_THIS; + else name = mangled_non_method_name(name); + inc.write("buf.write(" + name + ", m);"); + } + inc.end(); inc.newline(); + inc.write("}"); inc.newline(); inc.forceNewline(); - inc.write("template<class __T> static "+make_ref("__T")+" "+DESERIALIZE_METHOD+"("+SERIALIZATION_BUFFER+" &buf) {"); - inc.newline(4); inc.begin(0); - inc.write(make_ref(cnamet)+" this_ = new (x10aux::alloc"+chevrons(cnamet)+"()) "+ - cnamet+"("+SERIALIZATION_MARKER+"());"); - inc.newline(); - for (int i = 0; i < c.variables.size(); i++) { - VarInstance var = (VarInstance) c.variables.get(i); - String name = var.name().toString(); - if (name.equals(THIS)) - name = SAVED_THIS; - else name = mangled_non_method_name(name); - inc.write("this_->"+name+" = buf.read<"+emitter.translateType(var.type(), true)+" >();"); - inc.newline(); - } - inc.write("return this_;"); inc.end(); inc.newline(); - inc.write("}"); inc.newline(); inc.forceNewline(); + inc.write("template<class __T> static "+make_ref("__T")+" "+DESERIALIZE_METHOD+"("+SERIALIZATION_BUFFER+" &buf) {"); + inc.newline(4); inc.begin(0); + inc.write(make_ref(cnamet)+" this_ = new (x10aux::alloc"+chevrons(cnamet)+"()) "+ + cnamet+"("+SERIALIZATION_MARKER+"());"); + inc.newline(); + // FIXME: factor out this loop + for (int i = 0; i < c.variables.size(); i++) { + VarInstance var = (VarInstance) c.variables.get(i); + String name = var.name().toString(); + if (name.equals(THIS)) + name = SAVED_THIS; + else name = mangled_non_method_name(name); + inc.write("this_->"+name+" = buf.read<"+emitter.translateType(var.type(), true)+" >();"); + inc.newline(); + } + inc.write("return this_;"); inc.end(); inc.newline(); + inc.write("}"); inc.newline(); inc.forceNewline(); - inc.write(cname+"("+SERIALIZATION_MARKER+") { }"); - inc.newline(); inc.forceNewline(); + inc.write(cname+"("+SERIALIZATION_MARKER+") { }"); + inc.newline(); inc.forceNewline(); - inc.write(cname+"("); - for (int i = 0; i < c.variables.size(); i++) { - if (i > 0) inc.write(", "); - VarInstance var = (VarInstance) c.variables.get(i); - String name = var.name().toString(); - if (name.equals(THIS)) - name = SAVED_THIS; - else name = mangled_non_method_name(name); - inc.write(emitter.translateType(var.type(), true) + " " + name); - } - inc.write(") {"); - inc.newline(4); inc.begin(0); - for (int i = 0 ; i < c.variables.size() ; i++) { - VarInstance var = (VarInstance) c.variables.get(i); - String name = var.name().toString(); - if (name.equals(THIS)) - name = SAVED_THIS; - else name = mangled_non_method_name(name); - if (i > 0) inc.newline(); - inc.write("this->" + name + " = " + name + ";"); - } - inc.end(); inc.newline(); - inc.write("}"); inc.newline(); inc.forceNewline(); + inc.write(cname+"("); + for (int i = 0; i < c.variables.size(); i++) { + if (i > 0) inc.write(", "); + VarInstance var = (VarInstance) c.variables.get(i); + String name = var.name().toString(); + if (name.equals(THIS)) + name = SAVED_THIS; + else name = mangled_non_method_name(name); + inc.write(emitter.translateType(var.type(), true) + " " + name); + } + inc.write(") {"); + inc.newline(4); inc.begin(0); + // FIXME: factor out this loop + for (int i = 0 ; i < c.variables.size() ; i++) { + VarInstance var = (VarInstance) c.variables.get(i); + String name = var.name().toString(); + if (name.equals(THIS)) + name = SAVED_THIS; + else name = mangled_non_method_name(name); + if (i > 0) inc.newline(); + inc.write("this->" + name + " = " + name + ";"); + } + inc.end(); inc.newline(); + inc.write("}"); inc.newline(); inc.forceNewline(); - inc.write("static const x10aux::serialization_id_t "+SERIALIZATION_ID_FIELD+";"); - inc.newline(); inc.forceNewline(); + inc.write("static const x10aux::serialization_id_t "+SERIALIZATION_ID_FIELD+";"); + inc.newline(); inc.forceNewline(); - inc.write("const x10aux::RuntimeType *_type() const {"+ - " return x10aux::getRTT<"+superType+" >(); }"); - inc.newline(); - inc.write("struct RTT { static x10aux::RuntimeType * it; };"); - inc.newline(); inc.forceNewline(); + inc.write("const x10aux::RuntimeType *_type() const {"+ + " return x10aux::getRTT<"+superType+" >(); }"); + inc.newline(); + inc.write("struct RTT { static x10aux::RuntimeType * it; };"); + inc.newline(); inc.forceNewline(); - inc.write(make_ref("x10::lang::String")+" toString() {"); - inc.newline(4); inc.begin(0); - inc.write("return x10::lang::String::Lit(\""+StringUtil.escape(n.position().nameAndLineString())+"\");"); - inc.end(); inc.newline(); - inc.write("}"); - inc.end(); inc.newline(); inc.forceNewline(); + inc.write(emitter.translateType(xts.String(), true)+" toString() {"); + inc.newline(4); inc.begin(0); + inc.write("return "+emitter.translateType(xts.String())+"::Lit(\""+StringUtil.escape(n.position().nameAndLineString())+"\");"); + inc.end(); inc.newline(); + inc.write("}"); + inc.end(); inc.newline(); inc.forceNewline(); - inc.write("};"); inc.newline(); inc.forceNewline(); + inc.write("};"); inc.newline(); inc.forceNewline(); - if (in_template_closure) - emitter.printTemplateSignature(freeTypeParams, inc); - inc.write("x10aux::RuntimeType * "+cnamet+"::RTT::it = const_cast<x10aux::RuntimeType *>(x10aux::getRTT<"+superType+" >());"); - inc.newline(); inc.forceNewline(); + if (in_template_closure) + emitter.printTemplateSignature(freeTypeParams, inc); + inc.write("x10aux::RuntimeType * "+cnamet+"::RTT::it = const_cast<x10aux::RuntimeType *>(x10aux::getRTT<"+superType+" >());"); + inc.newline(); inc.forceNewline(); - if (in_template_closure) - emitter.printTemplateSignature(freeTypeParams, inc); - inc.write("const x10aux::serialization_id_t "+cnamet+"::"+SERIALIZATION_ID_FIELD+" = "); - inc.newline(4); - if (in_template_closure) { - inc.write("x10aux::DeserializationDispatcher::addDeserializer("+ - cnamet+"::template "+DESERIALIZE_METHOD+"<Object>);"); - } else { - inc.write("x10aux::DeserializationDispatcher::addDeserializer("+ - cnamet+"::"+DESERIALIZE_METHOD+"<Object>);"); - } - inc.newline(); inc.forceNewline(); + if (in_template_closure) + emitter.printTemplateSignature(freeTypeParams, inc); + inc.write("const x10aux::serialization_id_t "+cnamet+"::"+SERIALIZATION_ID_FIELD+" = "); + inc.newline(4); + String template = in_template_closure ? "template " : ""; + inc.write("x10aux::DeserializationDispatcher::addDeserializer("+ + cnamet+"::"+template+DESERIALIZE_METHOD+ + chevrons(emitter.translateType(xts.Object()))+");"); + inc.newline(); inc.forceNewline(); - if (in_template_closure) { - String guard = getHeaderGuard(cname); - inc.write("#endif // "+guard+"_CLOSURE"); inc.newline(); - } + if (in_template_closure) { + String guard = getHeaderGuard(cname); + inc.write("#endif // "+guard+"_CLOSURE"); inc.newline(); + } - sw.popCurrentStream(); + sw.popCurrentStream(); - // create closure instantiation (not in inc but where the closure was defined) - // note that we alloc using the typeof the superType but we pass in the correct size - // this is because otherwise alloc may (when debugging is on) try to examine the - // RTT of the closure (which doesn't exist) + // create closure instantiation (not in inc but where the closure was defined) + // note that we alloc using the typeof the superType but we pass in the correct size + // this is because otherwise alloc may (when debugging is on) try to examine the + // RTT of the closure (which doesn't exist) - // first get the template arguments (if any) - prefix="<"; - StringBuffer sb = new StringBuffer(); - for (Type t : freeTypeParams) { - sb.append(prefix+emitter.translateType(t, true)); - prefix = ","; - } - if (prefix.equals(",")) sb.append(">"); - String templateArgs = sb.toString(); + // first get the template arguments (if any) + prefix="<"; + StringBuffer sb = new StringBuffer(); + for (Type t : freeTypeParams) { + sb.append(prefix+emitter.translateType(t, true)); + prefix = ","; + } + if (prefix.equals(",")) sb.append(">"); + String templateArgs = sb.toString(); - sw.write(make_ref(superType)); - sw.write("(new (x10aux::alloc"+chevrons(superType)+"(sizeof("+cname+templateArgs+")))"); - sw.write(cname+templateArgs+"("); - for (int i = 0; i < c.variables.size(); i++) { - if (i > 0) sw.write(", "); - VarInstance var = (VarInstance) c.variables.get(i); - String name = var.name().toString(); - if (!name.equals(THIS)) - name = mangled_non_method_name(name); - else if (((X10CPPContext_c)c.pop()).insideClosure) // FIXME: hack - name = SAVED_THIS; - sw.write(name); - } - sw.write("))"); + sw.write(make_ref(superType)); + sw.write("(new (x10aux::alloc"+chevrons(superType)+"(sizeof("+cname+templateArgs+")))"); + sw.write(cname+templateArgs+"("); + for (int i = 0; i < c.variables.size(); i++) { + if (i > 0) sw.write(", "); + VarInstance var = (VarInstance) c.variables.get(i); + String name = var.name().toString(); + if (!name.equals(THIS)) + name = mangled_non_method_name(name); + else if (((X10CPPContext_c)c.pop()).insideClosure) // FIXME: hack + name = SAVED_THIS; + sw.write(name); + } + sw.write("))"); - c.finalizeClosureInstance(); - emitter.exitClosure(c); - } + c.finalizeClosureInstance(); + emitter.exitClosure(c); + } private void printInlinedClosureStmt(Stmt s, StreamWrapper w, String retLabel, String retVar, Closure_c closure) { Modified: trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/X10CPPTranslator.java =================================================================== --- trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/X10CPPTranslator.java 2009-03-06 23:49:07 UTC (rev 7888) +++ trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/X10CPPTranslator.java 2009-03-07 02:37:09 UTC (rev 7889) @@ -272,9 +272,6 @@ pkg = p.fullName().toString(); } - // store all explicit imports in the context - ((X10CPPContext_c)context).pendingImports.addAll(sfn.imports()); - WriterStreams wstreams = null; StreamWrapper sw = null; // Use the class name to derive a default output file name. Modified: trunk/x10.runtime.17/src-cpp/x10rt17.h =================================================================== --- trunk/x10.runtime.17/src-cpp/x10rt17.h 2009-03-06 23:49:07 UTC (rev 7888) +++ trunk/x10.runtime.17/src-cpp/x10rt17.h 2009-03-07 02:37:09 UTC (rev 7889) @@ -81,7 +81,5 @@ #include <x10/util/GrowableRail.h> -using namespace x10::lang; - #endif // vim:tabstop=4:shiftwidth=4:expandtab This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ipe...@us...> - 2009-03-07 03:29:10
|
Revision: 7890 http://x10.svn.sourceforge.net/x10/?rev=7890&view=rev Author: ipeshansky Date: 2009-03-07 03:29:06 +0000 (Sat, 07 Mar 2009) Log Message: ----------- Fix warnings - "ISO C++ forbids braced-groups within expressions" - "this decimal constant is unsigned only in ISO C90" Enable strict conformance mode when building XRX Modified Paths: -------------- trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/MessagePassingCodeGenerator.java trunk/x10.runtime.17/src-cpp/Makefile Modified: trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/MessagePassingCodeGenerator.java =================================================================== --- trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/MessagePassingCodeGenerator.java 2009-03-07 02:37:09 UTC (rev 7889) +++ trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/MessagePassingCodeGenerator.java 2009-03-07 03:29:06 UTC (rev 7890) @@ -2227,9 +2227,12 @@ String val; if (n.kind() == IntLit_c.LONG) val = Long.toString(n.value()) + "ll"; - else if (n.kind() == IntLit_c.INT) - val = Long.toString((int) n.value()); - else + else if (n.kind() == IntLit_c.INT) { + if ((n.value() & 0x80000000L) != 0) + val = Long.toString(n.value()<0 ? (-n.value() & 0xFFFFFFFFL) : n.value()) + "u"; + else + val = Long.toString((int) n.value()); + } else throw new InternalCompilerError("Unrecognized IntLit kind " + n.kind()); sw.write("("); sw.begin(0); sw.write("(" + emitter.translateType(n.type(), true) + ")"); @@ -3160,7 +3163,7 @@ args = newArgs; } - sw.write("({"); + sw.write("__extension__ ({"); sw.newline(4); sw.begin(0); String[] alt = null; if (clashes) { Modified: trunk/x10.runtime.17/src-cpp/Makefile =================================================================== --- trunk/x10.runtime.17/src-cpp/Makefile 2009-03-07 02:37:09 UTC (rev 7889) +++ trunk/x10.runtime.17/src-cpp/Makefile 2009-03-07 03:29:06 UTC (rev 7890) @@ -48,7 +48,7 @@ else - override CXXFLAGS += -ansi -pedantic -Wall -Wextra -Wno-long-long -Wno-unused-parameter -fpermissive + override CXXFLAGS += -ansi -pedantic -Wall -Wextra -Wno-long-long -Wno-unused-parameter ifeq ($(shell uname -s),Linux) override CXXFLAGS += -pthread endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <spa...@us...> - 2009-03-09 15:34:31
|
Revision: 7891 http://x10.svn.sourceforge.net/x10/?rev=7891&view=rev Author: sparksparkspark Date: 2009-03-09 15:34:04 +0000 (Mon, 09 Mar 2009) Log Message: ----------- Tweak serialization_buffer so that it can be used on the GPU More cuda backend work Removed some code that was never called Modified Paths: -------------- trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/types/X10CPPContext_c.java trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/ASTQuery.java trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/Emitter.java trunk/x10.cppbackend.17/src/polyglot/ext/x10cuda/types/X10CUDAContext_c.java trunk/x10.cppbackend.17/src/polyglot/ext/x10cuda/visit/CUDACodeGenerator.java trunk/x10.runtime.17/src-cpp/x10aux/pgas.cc trunk/x10.runtime.17/src-cpp/x10aux/serialization.h Modified: trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/types/X10CPPContext_c.java =================================================================== --- trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/types/X10CPPContext_c.java 2009-03-07 03:29:06 UTC (rev 7890) +++ trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/types/X10CPPContext_c.java 2009-03-09 15:34:04 UTC (rev 7891) @@ -96,23 +96,11 @@ X10CPPContext_c v = (X10CPPContext_c) super.push(); return v; } - - public static class Closures { - public int closureId = -1; - public int nesting = 0; - } - public Closures closures = new Closures(); - - // FIXME: should this be used instead of accessing closures directly? - public Closures getClosures() { - if (isSource()) { - System.err.println("found source context"); - return closures; - } else - return ((X10CPPContext_c) outer).getClosures(); - } - + static int closureId = -1; + public void incClosureId() { closureId++; } + public int closureId() { return closureId; } + public void saveEnvVariableInfo(String name) { VarInstance vi = findVariableInThisScope(Name.make(name)); if (vi != null) { // found declaration Modified: trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/ASTQuery.java =================================================================== --- trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/ASTQuery.java 2009-03-07 03:29:06 UTC (rev 7890) +++ trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/ASTQuery.java 2009-03-09 15:34:04 UTC (rev 7891) @@ -291,12 +291,14 @@ } static int getConstructorId(X10CPPContext_c c) { - return c.closures.closureId; + return c.closureId(); } + /* static boolean outerClosure(X10CPPContext_c c) { return c.closures.nesting == 0; } + */ static ClassType getOuterClass(X10CPPContext_c c) { ClassType currentClass = c.currentClass(); while (currentClass.isNested()) { Modified: trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/Emitter.java =================================================================== --- trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/Emitter.java 2009-03-07 03:29:06 UTC (rev 7890) +++ trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/Emitter.java 2009-03-09 15:34:04 UTC (rev 7891) @@ -740,11 +740,9 @@ } void enterClosure(X10CPPContext_c c) { - c.closures.closureId++; - c.closures.nesting++; + c.incClosureId(); } void exitClosure(X10CPPContext_c c) { - c.closures.nesting--; } void printExplicitTarget(Call_c n, Receiver target, X10CPPContext_c context, CodeWriter w) { Modified: trunk/x10.cppbackend.17/src/polyglot/ext/x10cuda/types/X10CUDAContext_c.java =================================================================== --- trunk/x10.cppbackend.17/src/polyglot/ext/x10cuda/types/X10CUDAContext_c.java 2009-03-07 03:29:06 UTC (rev 7890) +++ trunk/x10.cppbackend.17/src/polyglot/ext/x10cuda/types/X10CUDAContext_c.java 2009-03-09 15:34:04 UTC (rev 7891) @@ -20,15 +20,21 @@ import x10c.util.StreamWrapper; public class X10CUDAContext_c extends X10CPPContext_c { - - private ClassifiedStream cudaStream = null; - + + public X10CUDAContext_c(TypeSystem ts) { + super(ts); + } + private Closure_c wrappingClosure; + public Closure_c wrappingClosure() { return wrappingClosure; } + public void wrappingClosure(Closure_c v) { wrappingClosure = v; } - public X10CUDAContext_c(TypeSystem ts) { - super(ts); - } - + private boolean generatingCuda; + public boolean generatingCuda() { return generatingCuda; } + public void generatingCuda(boolean v) { generatingCuda = v; } + + private ClassifiedStream cudaStream = null; + public ClassifiedStream cudaStream (StreamWrapper sw) { if (cudaStream==null) { cudaStream = sw.getNewStream("cu"); @@ -36,14 +42,7 @@ return cudaStream; } - public Closure_c getWrappingClosure() { - return wrappingClosure; - } - - public void setWrappingClosure(Closure_c wrappingClosure) { - this.wrappingClosure = wrappingClosure; - } - + } //vim:tabstop=4:shiftwidth=4:expandtab \ No newline at end of file Modified: trunk/x10.cppbackend.17/src/polyglot/ext/x10cuda/visit/CUDACodeGenerator.java =================================================================== --- trunk/x10.cppbackend.17/src/polyglot/ext/x10cuda/visit/CUDACodeGenerator.java 2009-03-07 03:29:06 UTC (rev 7890) +++ trunk/x10.cppbackend.17/src/polyglot/ext/x10cuda/visit/CUDACodeGenerator.java 2009-03-09 15:34:04 UTC (rev 7891) @@ -13,12 +13,87 @@ package polyglot.ext.x10cuda.visit; +import polyglot.ast.ArrayAccess_c; +import polyglot.ast.ArrayInit_c; +import polyglot.ast.Assert_c; +import polyglot.ast.Assign_c; +import polyglot.ast.Binary_c; +import polyglot.ast.BooleanLit_c; +import polyglot.ast.Branch_c; +import polyglot.ast.Case_c; +import polyglot.ast.Catch_c; +import polyglot.ast.CharLit_c; +import polyglot.ast.ClassBody_c; +import polyglot.ast.Conditional_c; +import polyglot.ast.ConstructorDecl_c; +import polyglot.ast.Do_c; +import polyglot.ast.Empty_c; +import polyglot.ast.Eval_c; +import polyglot.ast.FieldDecl_c; +import polyglot.ast.Field_c; +import polyglot.ast.FloatLit_c; +import polyglot.ast.For_c; +import polyglot.ast.Formal_c; +import polyglot.ast.Id_c; +import polyglot.ast.If_c; +import polyglot.ast.Import_c; +import polyglot.ast.Initializer_c; +import polyglot.ast.IntLit_c; +import polyglot.ast.Labeled_c; +import polyglot.ast.LocalClassDecl_c; +import polyglot.ast.LocalDecl_c; +import polyglot.ast.Local_c; +import polyglot.ast.MethodDecl_c; +import polyglot.ast.New_c; import polyglot.ast.Node; import polyglot.ast.Block_c; +import polyglot.ast.NullLit_c; +import polyglot.ast.PackageNode_c; +import polyglot.ast.Return_c; +import polyglot.ast.StringLit_c; +import polyglot.ast.SwitchBlock_c; +import polyglot.ast.Switch_c; +import polyglot.ast.Throw_c; +import polyglot.ast.Try_c; +import polyglot.ast.Unary_c; +import polyglot.ast.While_c; +import polyglot.ext.x10.ast.AssignPropertyBody_c; +import polyglot.ext.x10.ast.Async_c; +import polyglot.ext.x10.ast.AtEach_c; +import polyglot.ext.x10.ast.AtExpr_c; +import polyglot.ext.x10.ast.AtStmt_c; +import polyglot.ext.x10.ast.Atomic_c; +import polyglot.ext.x10.ast.Await_c; +import polyglot.ext.x10.ast.ClosureCall_c; import polyglot.ext.x10.ast.Closure_c; +import polyglot.ext.x10.ast.ConstantDistMaker_c; +import polyglot.ext.x10.ast.Finish_c; +import polyglot.ext.x10.ast.ForEach_c; +import polyglot.ext.x10.ast.ForLoop_c; +import polyglot.ext.x10.ast.Future_c; +import polyglot.ext.x10.ast.Here_c; +import polyglot.ext.x10.ast.Next_c; +import polyglot.ext.x10.ast.ParExpr_c; +import polyglot.ext.x10.ast.PropertyDecl_c; +import polyglot.ext.x10.ast.RegionMaker_c; +import polyglot.ext.x10.ast.SettableAssign_c; +import polyglot.ext.x10.ast.StmtSeq_c; +import polyglot.ext.x10.ast.SubtypeTest_c; +import polyglot.ext.x10.ast.Tuple_c; +import polyglot.ext.x10.ast.TypeDecl_c; +import polyglot.ext.x10.ast.When_c; +import polyglot.ext.x10.ast.X10Binary_c; +import polyglot.ext.x10.ast.X10Call_c; +import polyglot.ext.x10.ast.X10CanonicalTypeNode_c; +import polyglot.ext.x10.ast.X10Cast_c; +import polyglot.ext.x10.ast.X10ClassDecl_c; +import polyglot.ext.x10.ast.X10Instanceof_c; +import polyglot.ext.x10.ast.X10Special_c; +import polyglot.ext.x10.ast.X10Unary_c; import polyglot.ext.x10.extension.X10Ext; import polyglot.ext.x10.types.X10ClassType; import polyglot.ext.x10.types.X10TypeSystem; +import polyglot.ext.x10cpp.visit.ASTQuery; import polyglot.ext.x10cpp.visit.MessagePassingCodeGenerator; import polyglot.ext.x10cuda.types.X10CUDAContext_c; import polyglot.types.QName; @@ -51,8 +126,12 @@ private ClassifiedStream cudaStream() { return context().cudaStream(sw); } + + private boolean generatingCuda() { return context().generatingCuda(); } - + private void generatingCuda(boolean v) { context().generatingCuda(v); } + + // does the block have the annotation that denotes that it should be split-compiled to cuda? private boolean nodeHasCudaAnnotation(Node n) { X10TypeSystem xts = (X10TypeSystem) tr.typeSystem(); X10Ext ext = (X10Ext) n.ext(); @@ -66,34 +145,485 @@ } void handleCuda(Block_c b) { + X10ClassType hostClassType = (X10ClassType) context().wrappingClosure().closureDef().typeContainer().get(); + String hostClassName = emitter.translate_mangled_FQN(hostClassType.fullName().toString(), "_"); + String kernel_name = getClosureName(hostClassName,context().closureId()); + sw.write("/* block split-compiled to cuda as "+kernel_name+" */ "); + ClassifiedStream out = cudaStream(); - String kernel_name = "my_happy_kernel"; - out.write("__global__ void "+kernel_name+"() {"); out.newline(4); out.begin(0); + // disable name-mangling which seems to be inconsistent across cuda versions + out.write("extern \"C\" {"); out.newline(4); out.begin(0); + + // kernel + out.write("__global__ void "+kernel_name+"(char *buf)"); out.newline(); + + // decode buffer + //out.write(" var = *(*T)buf; buf += sizeof(T);") + + // body sw.pushCurrentStream(out); super.visit(b); sw.popCurrentStream(); - out.end() ; out.newline(); - out.write("}"); out.newline(); + out.write(" // "+kernel_name); + + // end + out.end(); out.newline(); + out.write("} // extern \"C\""); out.newline(); out.forceNewline(); - out.forceNewline(); } - public void visit(Closure_c n) { - Closure_c last = context().getWrappingClosure(); - context().setWrappingClosure(n); - super.visit(n); - context().setWrappingClosure(last); - } - public void visit(Block_c b) { if (nodeHasCudaAnnotation(b)) { - sw.write("/*CUDA block*/ "); + assert !generatingCuda() : "Nesting of cuda annotation makes no sense."; + // TODO: assert the block is the body of an async + generatingCuda(true); handleCuda(b); + generatingCuda(false); } super.visit(b); } + public void visit(Closure_c n) { + Closure_c last = context().wrappingClosure(); + context().wrappingClosure(n); + super.visit(n); + context().wrappingClosure(last); + } + + public void visit(New_c n) { + assert !generatingCuda() : "New not allowed in @Cudable code."; + super.visit(n); + } + + @Override + public void createFinallyClosure(Try_c n) { + // TODO Auto-generated method stub + super.createFinallyClosure(n); + } + + + @Override + public void visit(ArrayInit_c n) { + // TODO Auto-generated method stub + super.visit(n); + } + + + @Override + public void visit(Assert_c n) { + // TODO Auto-generated method stub + super.visit(n); + } + + + @Override + public void visit(Assign_c asgn) { + // TODO Auto-generated method stub + super.visit(asgn); + } + + + @Override + public void visit(AssignPropertyBody_c n) { + // TODO Auto-generated method stub + super.visit(n); + } + + + @Override + public void visit(Await_c n) { + // TODO Auto-generated method stub + super.visit(n); + } + + + @Override + public void visit(Binary_c n) { + // TODO Auto-generated method stub + super.visit(n); + } + + + @Override + public void visit(BooleanLit_c lit) { + // TODO Auto-generated method stub + super.visit(lit); + } + + + @Override + public void visit(Branch_c br) { + // TODO Auto-generated method stub + super.visit(br); + } + + + @Override + public void visit(Case_c n) { + // TODO Auto-generated method stub + super.visit(n); + } + + + @Override + public void visit(Catch_c n) { + // TODO Auto-generated method stub + super.visit(n); + } + + + @Override + public void visit(CharLit_c lit) { + // TODO Auto-generated method stub + super.visit(lit); + } + + + @Override + public void visit(ClassBody_c n) { + // TODO Auto-generated method stub + super.visit(n); + } + + + @Override + public void visit(ClosureCall_c c) { + // TODO Auto-generated method stub + super.visit(c); + } + + + @Override + public void visit(Conditional_c n) { + // TODO Auto-generated method stub + super.visit(n); + } + + + @Override + public void visit(ConstantDistMaker_c n) { + // TODO Auto-generated method stub + super.visit(n); + } + + + @Override + public void visit(ConstructorDecl_c dec) { + // TODO Auto-generated method stub + super.visit(dec); + } + + + @Override + public void visit(Do_c n) { + // TODO Auto-generated method stub + super.visit(n); + } + + + @Override + public void visit(Empty_c n) { + // TODO Auto-generated method stub + super.visit(n); + } + + + @Override + public void visit(Eval_c n) { + // TODO Auto-generated method stub + super.visit(n); + } + + + @Override + public void visit(Field_c n) { + // TODO Auto-generated method stub + super.visit(n); + } + + + @Override + public void visit(FieldDecl_c dec) { + // TODO Auto-generated method stub + super.visit(dec); + } + + + @Override + public void visit(FloatLit_c n) { + // TODO Auto-generated method stub + super.visit(n); + } + + + @Override + public void visit(For_c n) { + // TODO Auto-generated method stub + super.visit(n); + } + + + + @Override + public void visit(ForLoop_c n) { + // TODO Auto-generated method stub + super.visit(n); + } + + + @Override + public void visit(Formal_c n) { + // TODO Auto-generated method stub + super.visit(n); + } + + + @Override + public void visit(Id_c n) { + // TODO Auto-generated method stub + super.visit(n); + } + + + @Override + public void visit(If_c n) { + // TODO Auto-generated method stub + super.visit(n); + } + + + @Override + public void visit(Import_c n) { + // TODO Auto-generated method stub + super.visit(n); + } + + + @Override + public void visit(Initializer_c n) { + // TODO Auto-generated method stub + super.visit(n); + } + + + @Override + public void visit(IntLit_c n) { + // TODO Auto-generated method stub + super.visit(n); + } + + + @Override + public void visit(Labeled_c label) { + // TODO Auto-generated method stub + super.visit(label); + } + + + @Override + public void visit(Local_c n) { + // TODO Auto-generated method stub + super.visit(n); + } + + + @Override + public void visit(LocalClassDecl_c n) { + // TODO Auto-generated method stub + super.visit(n); + } + + + @Override + public void visit(LocalDecl_c dec) { + // TODO Auto-generated method stub + super.visit(dec); + } + + + @Override + public void visit(MethodDecl_c dec) { + // TODO Auto-generated method stub + super.visit(dec); + } + + + @Override + public void visit(Node n) { + // TODO Auto-generated method stub + super.visit(n); + } + + + @Override + public void visit(NullLit_c n) { + // TODO Auto-generated method stub + super.visit(n); + } + + + @Override + public void visit(PackageNode_c n) { + // TODO Auto-generated method stub + super.visit(n); + } + + + @Override + public void visit(ParExpr_c n) { + // TODO Auto-generated method stub + super.visit(n); + } + + + @Override + public void visit(PropertyDecl_c n) { + // TODO Auto-generated method stub + super.visit(n); + } + + + @Override + public void visit(RegionMaker_c n) { + // TODO Auto-generated method stub + super.visit(n); + } + + + @Override + public void visit(Return_c ret) { + // TODO Auto-generated method stub + super.visit(ret); + } + + + @Override + public void visit(StringLit_c n) { + // TODO Auto-generated method stub + super.visit(n); + } + + + @Override + public void visit(SubtypeTest_c n) { + // TODO Auto-generated method stub + super.visit(n); + } + + + @Override + public void visit(Switch_c n) { + // TODO Auto-generated method stub + super.visit(n); + } + + + @Override + public void visit(SwitchBlock_c n) { + // TODO Auto-generated method stub + super.visit(n); + } + + + @Override + public void visit(Throw_c n) { + // TODO Auto-generated method stub + super.visit(n); + } + + + @Override + public void visit(Try_c n) { + // TODO Auto-generated method stub + super.visit(n); + } + + + @Override + public void visit(Tuple_c c) { + // TODO Auto-generated method stub + super.visit(c); + } + + + @Override + public void visit(TypeDecl_c n) { + // TODO Auto-generated method stub + super.visit(n); + } + + + @Override + public void visit(Unary_c n) { + // TODO Auto-generated method stub + super.visit(n); + } + + + @Override + public void visit(While_c n) { + // TODO Auto-generated method stub + super.visit(n); + } + + + @Override + public void visit(X10Binary_c n) { + // TODO Auto-generated method stub + super.visit(n); + } + + + @Override + public void visit(X10Call_c n) { + // TODO Auto-generated method stub + super.visit(n); + } + + + @Override + public void visit(X10CanonicalTypeNode_c n) { + // TODO Auto-generated method stub + super.visit(n); + } + + + @Override + public void visit(X10Cast_c c) { + // TODO Auto-generated method stub + super.visit(c); + } + + + @Override + public void visit(X10ClassDecl_c n) { + // TODO Auto-generated method stub + super.visit(n); + } + + + @Override + public void visit(X10Instanceof_c n) { + // TODO Auto-generated method stub + super.visit(n); + } + + + @Override + public void visit(X10Special_c n) { + // TODO Auto-generated method stub + super.visit(n); + } + + + @Override + public void visit(X10Unary_c n) { + // TODO Auto-generated method stub + super.visit(n); + } + + } // end of CUDACodeGenerator // vim:tabstop=4:shiftwidth=4:expandtab Modified: trunk/x10.runtime.17/src-cpp/x10aux/pgas.cc =================================================================== --- trunk/x10.runtime.17/src-cpp/x10aux/pgas.cc 2009-03-07 03:29:06 UTC (rev 7890) +++ trunk/x10.runtime.17/src-cpp/x10aux/pgas.cc 2009-03-09 15:34:04 UTC (rev 7891) @@ -60,8 +60,7 @@ // this one for when pgas does not use an internal thread void __x10_callback_asyncswitch(const x10_async_closure_t *cl, x10_clock_t *, int) { _X_(ANSI_PGAS"Receiving an async, deserialising..."ANSI_RESET); - x10aux::serialization_buffer buf; - buf.set(reinterpret_cast<const char*>(cl)); + x10aux::serialization_buffer buf(reinterpret_cast<const char*>(cl)); ref<VoidFun_0_0> async = x10aux::DeserializationDispatcher::create<VoidFun_0_0>(buf); _X_("The deserialised async was: "<<async->toString()->c_str()); deserialized_bytes += buf.length(); Modified: trunk/x10.runtime.17/src-cpp/x10aux/serialization.h =================================================================== --- trunk/x10.runtime.17/src-cpp/x10aux/serialization.h 2009-03-07 03:29:06 UTC (rev 7890) +++ trunk/x10.runtime.17/src-cpp/x10aux/serialization.h 2009-03-09 15:34:04 UTC (rev 7891) @@ -185,6 +185,13 @@ } public: + // we use the same buffers for serializing and deserializing so the + // const cast is necessary + // note that a serialization_buffer created this way can only be used for deserializing + serialization_buffer(const char *buffer_) + : buffer(const_cast<char*>(buffer_)), limit(NULL), cursor(buffer) + { } + serialization_buffer() : buffer(alloc(INITIAL_SIZE)), limit(buffer + INITIAL_SIZE), cursor(buffer) { } @@ -196,14 +203,6 @@ const char *get() const { return buffer; } - // we use the same buffers for serializing and deserializing so the - // const cast is necessary - void set(const char* buf) { set(const_cast<char*>(buf)); } - void set(char* buf) { - buffer = cursor = buf; - limit = NULL; - } - size_t length() { return cursor - buffer; } @@ -235,7 +234,7 @@ // default case for primitives and other things that never contain pointers template<class T> struct Read { - static T &_(serialization_buffer &buf) { + GPUSAFE static T &_(serialization_buffer &buf) { // FIXME: assumes all places are same endian T &val = *(T*) buf.cursor; buf.cursor += sizeof(T); @@ -246,14 +245,14 @@ // case for references e.g. ref<Object>, template<class T> struct Read<ref<T> > { - static ref<T> _(serialization_buffer &buf) { + GPUSAFE static ref<T> _(serialization_buffer &buf) { //dispatch because we don't know what it is _S_("Deserializing a "ANSI_SER ANSI_BOLD<<TYPENAME(T)<<ANSI_RESET" from buf: "<<&buf); return T::template _deserialize<T>(buf); } }; - template<typename T> T read() { + template<typename T> GPUSAFE T read() { return Read<T>::_(*this); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <vj...@us...> - 2009-03-12 23:13:28
|
Revision: 7913 http://x10.svn.sourceforge.net/x10/?rev=7913&view=rev Author: vj0 Date: 2009-03-12 23:13:26 +0000 (Thu, 12 Mar 2009) Log Message: ----------- Added safe annotations to get/set/apply etc methods on Array and related classes. Fixed tests in examples/Constructs/Async. Modified Paths: -------------- trunk/x10.runtime.17/src-x10/x10/array/BaseArray.x10 trunk/x10.runtime.17/src-x10/x10/array/DistArray.x10 trunk/x10.runtime.17/src-x10/x10/array/FastArray.x10 trunk/x10.runtime.17/src-x10/x10/array/LocalArray.x10 trunk/x10.runtime.17/src-x10/x10/array/MatBuilder.x10 trunk/x10.runtime.17/src-x10/x10/array/ValRow.x10 trunk/x10.runtime.17/src-x10/x10/array/VarRow.x10 trunk/x10.runtime.17/src-x10/x10/lang/Array.x10 trunk/x10.tests/examples/Constructs/Async/AsyncTest3.x10 trunk/x10.tests/examples/Constructs/Async/ClockAsyncTest.x10 Modified: trunk/x10.runtime.17/src-x10/x10/array/BaseArray.x10 =================================================================== --- trunk/x10.runtime.17/src-x10/x10/array/BaseArray.x10 2009-03-12 23:09:24 UTC (rev 7912) +++ trunk/x10.runtime.17/src-x10/x10/array/BaseArray.x10 2009-03-12 23:13:26 UTC (rev 7913) @@ -58,7 +58,13 @@ as Array[T]{rank==1 && rect && zeroBased}; // XXXX } + public static def makeVar1[T](rail: ValRail[T]): Array[T]{rank==1&&rect&&zeroBased} { + val r = Region.makeRectangular(0, rail.length-1); + return makeVar[T](r, ((p:Point)=>rail(p(0))) as Box[(Point)=>T]) + as Array[T]{rank==1 && rect && zeroBased}; // XXXX + } + // // expose these if performance demands // @@ -72,16 +78,16 @@ // high-performance methods are in subclass to facilitate inlining // - public final def apply(pt: Point(rank)): T { + public final safe def apply(pt: Point(rank)): T { if (checkPlace) checkPlace(pt); if (checkBounds) checkBounds(pt); return raw()(layout().offset(pt)); } - public final def get(pt: Point(rank)): T = apply(pt); + public final safe def get(pt: Point(rank)): T = apply(pt); // XXXX settable order - public final def set(v: T, pt: Point(rank)): T { + public final safe def set(v: T, pt: Point(rank)): T { if (checkPlace) checkPlace(pt); if (checkBounds) checkBounds(pt); raw()(layout().offset(pt)) = v; @@ -112,43 +118,43 @@ val place = (pt:Point):RuntimeException => new BadPlaceException("point " + pt + " not defined at " + here); - def checkBounds(pt: Point(rank)) { + safe def checkBounds(pt: Point(rank)) { (region as BaseRegion(rank)).check(bounds, pt); } - def checkBounds(i0: int) { + safe def checkBounds(i0: int) { (region as BaseRegion).check(bounds, i0); } - def checkBounds(i0: int, i1: int) { + safe def checkBounds(i0: int, i1: int) { (region as BaseRegion).check(bounds, i0, i1); } - def checkBounds(i0: int, i1: int, i2: int) { + safe def checkBounds(i0: int, i1: int, i2: int) { (region as BaseRegion).check(bounds, i0, i1, i2); } - def checkBounds(i0: int, i1: int, i2: int, i3: int) { + safe def checkBounds(i0: int, i1: int, i2: int, i3: int) { (region as BaseRegion).check(bounds, i0, i1, i2, i3); } - def checkPlace(pt: Point(rank)) { + safe def checkPlace(pt: Point(rank)) { (dist.get(here) as BaseRegion(rank)).check(place, pt); } - def checkPlace(i0: int) { + safe def checkPlace(i0: int) { (dist.get(here) as BaseRegion).check(place, i0); } - def checkPlace(i0: int, i1: int) { + safe def checkPlace(i0: int, i1: int) { (dist.get(here) as BaseRegion).check(place, i0, i1); } - def checkPlace(i0: int, i1: int, i2: int) { + safe def checkPlace(i0: int, i1: int, i2: int) { (dist.get(here) as BaseRegion).check(place, i0, i1, i2); } - def checkPlace(i0: int, i1: int, i2: int, i3: int) { + safe def checkPlace(i0: int, i1: int, i2: int, i3: int) { (dist.get(here) as BaseRegion).check(place, i0, i1, i2, i3); } @@ -158,16 +164,16 @@ // views // - public def restriction(r: Region(rank)): Array[T] { + public safe def restriction(r: Region(rank)): Array[T] { return restriction(dist.restriction(r)); } - public def restriction(p: Place): Array[T] { + public safe def restriction(p: Place): Array[T] { return restriction(dist.restriction(p)); } // must be internal only - assumes Dist places match - protected abstract def restriction(d: Dist): Array[T]; + protected abstract safe def restriction(d: Dist): Array[T]; // @@ -177,34 +183,34 @@ public def lift(op:(T)=>T): Array[T](dist) = Array.make[T](dist, (p:Point)=>op(this(p as Point(rank)))); - incomplete public def reduce(op:(T,T)=>T, unit:T):T; + // incomplete public def reduce(op:(T,T)=>T, unit:T):T; // // seems to be causing non-deterministic typechecking failures in // a(pt). perhaps related to XTENLANG-128 and/or XTENLANG-135 // -// public def reduce(op:(T,T)=>T, unit:T):T { -// -// // scatter -// val ps = dist.places(); -// val results = Rail.makeVal[Future[T]](ps.length, (p:nat) => { -// future (ps(p)) { -// var result: T = unit; -// val a = (this | here) as Array[T](rank); -// for (pt:Point(rank) in a) -// result = op(result, a(pt)); -// return result; -// } -// }); -// -// // gather -// var result: T = unit; -// for (var i:int=0; i<results.length; i++) -// result = op(result, results(i).force()); -// -// return result; -// } + public def reduce(op:(T,T)=>T, unit:T):T { + // scatter + val ps = dist.places(); + val results = Rail.makeVal[Future[T]](ps.length, (p:nat) => { + future(ps(p)) { + var result: T = unit; + val a = (this | here) as Array[T](rank); + for (pt:Point(rank) in a) + result = op(result, a(pt)); + return result; + } + }); + + // gather + var result: T = unit; + for (var i:int = 0; i < results.length; i++) + result = op(result, results(i).force()); + + return result; + } + // LocalArray only for now! incomplete public def scan(op:(T,T)=>T, unit:T): Array[T](dist); @@ -213,24 +219,24 @@ // ops // - public def $bar(r: Region(rank)): Array[T] = restriction(r); - public def $bar(p: Place): Array[T] = restriction(p); + public safe def $bar(r: Region(rank)): Array[T] = restriction(r); + public safe def $bar(p: Place): Array[T] = restriction(p); - incomplete public def $plus(): Array[T]; - incomplete public def $minus(): Array[T]; + incomplete public safe def $plus(): Array[T]; + incomplete public safe def $minus(): Array[T]; - incomplete public def $plus(that: Array[T]): Array[T]; - incomplete public def $minus(that: Array[T]): Array[T]; - incomplete public def $times(that: Array[T]): Array[T]; - incomplete public def $over(that: Array[T]): Array[T]; - incomplete public def $percent(that: Array[T]): Array[T]; + incomplete public safe def $plus(that: Array[T]): Array[T]; + incomplete public safe def $minus(that: Array[T]): Array[T]; + incomplete public safe def $times(that: Array[T]): Array[T]; + incomplete public safe def $over(that: Array[T]): Array[T]; + incomplete public safe def $percent(that: Array[T]): Array[T]; - incomplete public def $eq(x: Array[T]): boolean; - incomplete public def $lt(x: Array[T]): boolean; - incomplete public def $gt(x: Array[T]): boolean; - incomplete public def $le(x: Array[T]): boolean; - incomplete public def $ge(x: Array[T]): boolean; - incomplete public def $ne(x: Array[T]): boolean; + incomplete public safe def $eq(x: Array[T]): boolean; + incomplete public safe def $lt(x: Array[T]): boolean; + incomplete public safe def $gt(x: Array[T]): boolean; + incomplete public safe def $le(x: Array[T]): boolean; + incomplete public safe def $ge(x: Array[T]): boolean; + incomplete public safe def $ne(x: Array[T]): boolean; // incomplete public def sum(): T; // XTENLANG-116 Modified: trunk/x10.runtime.17/src-x10/x10/array/DistArray.x10 =================================================================== --- trunk/x10.runtime.17/src-x10/x10/array/DistArray.x10 2009-03-12 23:09:24 UTC (rev 7912) +++ trunk/x10.runtime.17/src-x10/x10/array/DistArray.x10 2009-03-12 23:13:26 UTC (rev 7913) @@ -31,25 +31,25 @@ // XXX but ref to here and rail accesses make this not so high performance // - final public def apply(i0: int): T { + final public safe def apply(i0: int): T { if (checkPlace) checkPlace(i0); if (checkBounds) checkBounds(i0); return raw()(layout().offset(i0)); } - final public def apply(i0: int, i1: int): T { + final public safe def apply(i0: int, i1: int): T { if (checkPlace) checkPlace(i0, i1); if (checkBounds) checkBounds(i0, i1); return raw()(layout().offset(i0,i1)); } - final public def apply(i0: int, i1: int, i2: int): T { + final public safe def apply(i0: int, i1: int, i2: int): T { if (checkPlace) checkPlace(i0, i1, i2); if (checkBounds) checkBounds(i0, i1, i2); return raw()(layout().offset(i0,i1,i2)); } - final public def apply(i0: int, i1: int, i2: int, i3: int): T { + final public safe def apply(i0: int, i1: int, i2: int, i3: int): T { if (checkPlace) checkPlace(i0, i1, i2, i3); if (checkBounds) checkBounds(i0, i1, i2, i3); return raw()(layout().offset(i0,i1,i2,i3)); @@ -61,28 +61,28 @@ // XXX but ref to here and rail accesses make this not so high performance // - final public def set(v: T, i0: int): T { + final public safe def set(v: T, i0: int): T { if (checkPlace) checkPlace(i0); if (checkBounds) checkBounds(i0); raw()(layout().offset(i0)) = v; return v; } - final public def set(v: T, i0: int, i1: int): T { + final public safe def set(v: T, i0: int, i1: int): T { if (checkPlace) checkPlace(i0, i1); if (checkBounds) checkBounds(i0, i1); raw()(layout().offset(i0,i1)) = v; return v; } - final public def set(v: T, i0: int, i1: int, i2: int): T { + final public safe def set(v: T, i0: int, i1: int, i2: int): T { if (checkPlace) checkPlace(i0, i1, i2); if (checkBounds) checkBounds(i0, i1, i2); raw()(layout().offset(i0,i1,i2)) = v; return v; } - final public def set(v: T, i0: int, i1: int, i2: int, i3: int): T { + final public safe def set(v: T, i0: int, i1: int, i2: int, i3: int): T { if (checkPlace) checkPlace(i0, i1, i2, i3); if (checkBounds) checkBounds(i0, i1, i2, i3); raw()(layout().offset(i0,i1,i2,i3)) = v; @@ -123,7 +123,7 @@ * restriction view */ - public def restriction(d: Dist) { + public safe def restriction(d: Dist) { if (d.constant) return new LocalArray[T](this, d as Dist{constant}); else Modified: trunk/x10.runtime.17/src-x10/x10/array/FastArray.x10 =================================================================== --- trunk/x10.runtime.17/src-x10/x10/array/FastArray.x10 2009-03-12 23:09:24 UTC (rev 7912) +++ trunk/x10.runtime.17/src-x10/x10/array/FastArray.x10 2009-03-12 23:13:26 UTC (rev 7913) @@ -36,25 +36,25 @@ val delta2: int; val delta3: int; - final public def apply(i0: int): T { + final public safe def apply(i0: int): T { var offset:int = i0; return raw(offset); } - final public def apply(i0: int, i1: int): T { + final public safe def apply(i0: int, i1: int): T { var offset:int = i0; offset = offset*delta1 + i1; return raw(offset); } - final public def apply(i0: int, i1: int, i2: int): T { + final public safe def apply(i0: int, i1: int, i2: int): T { var offset:int = i0; offset = offset*delta1 + i1; offset = offset*delta2 + i2; return raw(offset); } - final public def apply(i0: int, i1: int, i2: int, i3: int): T { + final public safe def apply(i0: int, i1: int, i2: int, i3: int): T { var offset:int = i0; offset = offset*delta1 + i1; offset = offset*delta2 + i2; @@ -66,20 +66,20 @@ // // - final public def set(v: T, i0: int): T { + final public safe def set(v: T, i0: int): T { var offset:int = i0; raw(offset) = v; return v; } - final public def set(v: T, i0: int, i1: int): T { + final public safe def set(v: T, i0: int, i1: int): T { var offset:int = i0; offset = offset*delta1 + i1; raw(offset) = v; return v; } - final public def set(v: T, i0: int, i1: int, i2: int): T { + final public safe def set(v: T, i0: int, i1: int, i2: int): T { var offset:int = i0; offset = offset*delta1 + i1; offset = offset*delta2 + i2; @@ -87,7 +87,7 @@ return v; } - final public def set(v: T, i0: int, i1: int, i2: int, i3: int): T { + final public safe def set(v: T, i0: int, i1: int, i2: int, i3: int): T { var offset:int = i0; offset = offset*delta1 + i1; offset = offset*delta2 + i2; @@ -168,7 +168,7 @@ * restriction view */ - public def restriction(d: Dist): Array[T] { + public safe def restriction(d: Dist): Array[T] { return new FastArray[T](this, d as Dist{constant}); } Modified: trunk/x10.runtime.17/src-x10/x10/array/LocalArray.x10 =================================================================== --- trunk/x10.runtime.17/src-x10/x10/array/LocalArray.x10 2009-03-12 23:09:24 UTC (rev 7912) +++ trunk/x10.runtime.17/src-x10/x10/array/LocalArray.x10 2009-03-12 23:13:26 UTC (rev 7913) @@ -29,22 +29,22 @@ // NB: local array, so don't do place checking // - final public def apply(i0: int): T { + final public safe def apply(i0: int): T { if (checkBounds) checkBounds(i0); return raw(layout.offset(i0)); } - final public def apply(i0: int, i1: int): T { + final public safe def apply(i0: int, i1: int): T { if (checkBounds) checkBounds(i0, i1); return raw(layout.offset(i0,i1)); } - final public def apply(i0: int, i1: int, i2: int): T { + final public safe def apply(i0: int, i1: int, i2: int): T { if (checkBounds) checkBounds(i0, i1, i2); return raw(layout.offset(i0,i1,i2)); } - final public def apply(i0: int, i1: int, i2: int, i3: int): T { + final public safe def apply(i0: int, i1: int, i2: int, i3: int): T { if (checkBounds) checkBounds(i0, i1, i2, i3); return raw(layout.offset(i0,i1,i2,i3)); } @@ -56,25 +56,25 @@ // NB: local array, so don't do place checking // - final public def set(v: T, i0: int): T { + final public safe def set(v: T, i0: int): T { if (checkBounds) checkBounds(i0); raw(layout.offset(i0)) = v; return v; } - final public def set(v: T, i0: int, i1: int): T { + final public safe def set(v: T, i0: int, i1: int): T { if (checkBounds) checkBounds(i0, i1); raw(layout.offset(i0,i1)) = v; return v; } - final public def set(v: T, i0: int, i1: int, i2: int): T { + final public safe def set(v: T, i0: int, i1: int, i2: int): T { if (checkBounds) checkBounds(i0, i1, i2); raw(layout.offset(i0,i1,i2)) = v; return v; } - final public def set(v: T, i0: int, i1: int, i2: int, i3: int): T { + final public safe def set(v: T, i0: int, i1: int, i2: int, i3: int): T { if (checkBounds) checkBounds(i0, i1, i2, i3); raw(layout.offset(i0,i1,i2,i3)) = v; return v; @@ -148,7 +148,7 @@ * restriction view */ - public def restriction(d: Dist): Array[T] { + public safe def restriction(d: Dist): Array[T] { return new LocalArray[T](this, d as Dist{constant}); } Modified: trunk/x10.runtime.17/src-x10/x10/array/MatBuilder.x10 =================================================================== --- trunk/x10.runtime.17/src-x10/x10/array/MatBuilder.x10 2009-03-12 23:09:24 UTC (rev 7912) +++ trunk/x10.runtime.17/src-x10/x10/array/MatBuilder.x10 2009-03-12 23:13:26 UTC (rev 7913) @@ -21,43 +21,43 @@ need(rows); } - public def add(row:Row) { + public safe def add(row:Row) { mat.add(row); } - public def add(a:(nat)=>int) { + public safe def add(a:(nat)=>int) { mat.add(new VarRow(cols, a)); } - public def set(v:int, i:int, j:int) { + public safe def set(v:int, i:int, j:int) { need(i+1); mat(i)(j) = v; } - public def setDiagonal(i:nat, j:nat, n:nat, v:(nat)=>int) { + public safe def setDiagonal(i:nat, j:nat, n:nat, v:(nat)=>int) { need(i+n); for (var k:int=0; k<n; k++) mat(i+k)(j+k) = v(k); } - public def setColumn(i:nat, j:nat, n:nat, v:(nat)=>int) { + public safe def setColumn(i:nat, j:nat, n:nat, v:(nat)=>int) { need(i+n); for (var k:int=0; k<n; k++) mat(i+k)(j) = v(k); } - public def setRow(i:nat, j:nat, n:nat, v:(nat)=>int) { + public safe def setRow(i:nat, j:nat, n:nat, v:(nat)=>int) { need(i+1); for (var k:int=0; k<n; k++) mat(i)(j+k) = v(k); } - private def need(n:int) { + private safe def need(n:int) { while (mat.size()<n) mat.add(new VarRow(cols)); } - public def toXformMat() { + public safe def toXformMat() { return new XformMat(mat.size(), cols, (i:nat,j:nat)=>mat(i)(j)); } } Modified: trunk/x10.runtime.17/src-x10/x10/array/ValRow.x10 =================================================================== --- trunk/x10.runtime.17/src-x10/x10/array/ValRow.x10 2009-03-12 23:09:24 UTC (rev 7912) +++ trunk/x10.runtime.17/src-x10/x10/array/ValRow.x10 2009-03-12 23:13:26 UTC (rev 7913) @@ -25,9 +25,9 @@ row = Rail.makeVal[int](cols, init); } - public def apply(i:nat) = row(i); + public safe def apply(i:nat) = row(i); - public def set(v:int, i:nat):int { + public safe def set(v:int, i:nat):int { throw new IllegalOperationException("ValRow.set"); } } Modified: trunk/x10.runtime.17/src-x10/x10/array/VarRow.x10 =================================================================== --- trunk/x10.runtime.17/src-x10/x10/array/VarRow.x10 2009-03-12 23:09:24 UTC (rev 7912) +++ trunk/x10.runtime.17/src-x10/x10/array/VarRow.x10 2009-03-12 23:13:26 UTC (rev 7913) @@ -17,7 +17,7 @@ row = Rail.makeVar[int](cols); } - public def apply(i:nat) = row(i); + public safe def apply(i:nat) = row(i); - public def set(v:int, i:nat) = (row(i) = v); + public safe def set(v:int, i:nat) = (row(i) = v); } Modified: trunk/x10.runtime.17/src-x10/x10/lang/Array.x10 =================================================================== --- trunk/x10.runtime.17/src-x10/x10/lang/Array.x10 2009-03-12 23:09:24 UTC (rev 7912) +++ trunk/x10.runtime.17/src-x10/x10/lang/Array.x10 2009-03-12 23:13:26 UTC (rev 7913) @@ -82,6 +82,8 @@ public static def make[T](rail: Rail[T]): Array[T]{rank==1&&rect&&zeroBased} = BaseArray.makeVar1[T](rail); + public static def make[T](rail: ValRail[T]): Array[T]{rank==1&&rect&&zeroBased} + = BaseArray.makeVar1[T](rail); public static def make[T](size: nat, init: Box[(Point)=>T]): Array[T](1) = makeVar[T](0..size-1, init) as Array[T](1); @@ -103,31 +105,31 @@ // operations // - public abstract def apply(pt: Point(rank)): T; - public abstract def apply(i0: int) {rank==1}: T; - public abstract def apply(i0: int, i1: int) {rank==2}: T; - public abstract def apply(i0: int, i1: int, i2: int) {rank==3}: T; - public abstract def apply(i0: int, i1: int, i2: int, i3:int) {rank==4}: T; + public abstract safe def apply(pt: Point(rank)): T; + public abstract safe def apply(i0: int) {rank==1}: T; + public abstract safe def apply(i0: int, i1: int) {rank==2}: T; + public abstract safe def apply(i0: int, i1: int, i2: int) {rank==3}: T; + public abstract safe def apply(i0: int, i1: int, i2: int, i3:int) {rank==4}: T; - public abstract def set(v:T, pt: Point(rank)): T; - public abstract def set(v:T, i0: int) {rank==1}: T; - public abstract def set(v:T, i0: int, i1: int) {rank==2}: T; - public abstract def set(v:T, i0: int, i1: int, i2: int) {rank==3}: T; - public abstract def set(v:T, i0: int, i1: int, i2: int, i3:int) {rank==4}: T; + public abstract safe def set(v:T, pt: Point(rank)): T; + public abstract safe def set(v:T, i0: int) {rank==1}: T; + public abstract safe def set(v:T, i0: int, i1: int) {rank==2}: T; + public abstract safe def set(v:T, i0: int, i1: int, i2: int) {rank==3}: T; + public abstract safe def set(v:T, i0: int, i1: int, i2: int, i3:int) {rank==4}: T; - public abstract def restriction(r: Region(rank)): Array[T]; - public abstract def restriction(p: Place): Array[T]; + public abstract safe def restriction(r: Region(rank)): Array[T]; + public abstract safe def restriction(p: Place): Array[T]; - public abstract def $plus(): Array[T]; - public abstract def $minus(): Array[T]; + public abstract safe def $plus(): Array[T]; + public abstract safe def $minus(): Array[T]; - public abstract def $plus(that: Array[T]): Array[T]; - public abstract def $minus(that: Array[T]): Array[T]; - public abstract def $times(that: Array[T]): Array[T]; - public abstract def $over(that: Array[T]): Array[T]; + public abstract safe def $plus(that: Array[T]): Array[T]; + public abstract safe def $minus(that: Array[T]): Array[T]; + public abstract safe def $times(that: Array[T]): Array[T]; + public abstract safe def $over(that: Array[T]): Array[T]; - public abstract def $bar(r: Region(rank)): Array[T]; - public abstract def $bar(p: Place): Array[T]; + public abstract safe def $bar(r: Region(rank)): Array[T]; + public abstract safe def $bar(p: Place): Array[T]; // @@ -155,9 +157,10 @@ // // - incomplete public static def $convert[T](r: Rail[T]): Array[T]; - incomplete public static def $convert[T](r: ValRail[T]): Array[T]; + public static def $convert[T](r: Rail[T]): Array[T] = make(r); + public static def $convert[T](r: ValRail[T]): Array[T] = make(r); + public def iterator(): Iterator[Point(rank)] = region.iterator() as Iterator[Point(rank)]; Modified: trunk/x10.tests/examples/Constructs/Async/AsyncTest3.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Async/AsyncTest3.x10 2009-03-12 23:09:24 UTC (rev 7912) +++ trunk/x10.tests/examples/Constructs/Async/AsyncTest3.x10 2009-03-12 23:13:26 UTC (rev 7913) @@ -22,40 +22,36 @@ */ public class AsyncTest3 extends x10Test { - public def run(): boolean = { + public def run() { + try { val A: Array[int] = Array.make[int](Dist.makeUnique()); chk(Place.MAX_PLACES >= 2); chk(A.dist(0) == here); chk(A.dist(1) != here); - val x: X = new X(); + val x= new X(); finish async(here) { A(0) += 1; } A(0) += 1; - - - - finish async(here) { A(1) += 1; } - A(1) += 1; // remote communication - x10.io.Console.OUT.println("1"); + finish async(here) { A(1) += 1; } + A(1) += 1; // remote communication + x10.io.Console.OUT.println("1"); finish async(here) { A(x.zero()) += 1; } A(x.zero()) += 1; + finish async(here) { A(0) += A(x.one()); } + A(0) += A(x.one());// remote communication + x10.io.Console.OUT.println("2"); - - finish async(here) { A(0) += A(x.one()); } - A(0) += A(x.one());// remote communication - x10.io.Console.OUT.println("2"); - - - chk(A(0) == 8 && A(1) == 2); - x10.io.Console.OUT.println("3"); - - + chk(A(0) == 8 && A(1) == 2); + x10.io.Console.OUT.println("3"); + return false; + } catch (z:BadPlaceException) { return true; + } } - public static def main(var args: Rail[String]): void = { + public static def main(var args: Rail[String]) { new AsyncTest3().execute(); } @@ -65,8 +61,8 @@ */ static class X { public var z: Array[int] = [ 1, 0 ]; - def zero(): int = { return z(z(z(1))); } - def one(): int = { return z(z(z(0))); } - def modify(): void = { z(0)++; } + def zero() = z(z(z(1))); + def one() = z(z(z(0))); + def modify() { z(0)++; } } } Modified: trunk/x10.tests/examples/Constructs/Async/ClockAsyncTest.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Async/ClockAsyncTest.x10 2009-03-12 23:09:24 UTC (rev 7912) +++ trunk/x10.tests/examples/Constructs/Async/ClockAsyncTest.x10 2009-03-12 23:13:26 UTC (rev 7913) @@ -8,27 +8,28 @@ import harness.x10Test; /** - * Code generation for clocked async uses "clocks" as the name of the clock - * list. - * This test will fail at runtime, because the wrong clocks variable is being used. + * Test that creating an array of clocks will not work -- you need to + * do the following instead: + val clocks = Array.make[Clock](0..5, (point)=>null); + for ((i) in 0..5) clocks(i) = Clock.make(); + * @author Tong Wen 7/2006 */ public class ClockAsyncTest extends x10Test { - public def run(): boolean = { - finish async{ - val clocks: Array[Clock] = Array.make[Clock]([0..5], ((i): Point): Clock => Clock.make()); - val i: int = 0; - async (here) clocked (clocks(i)){ - next; - } - } - return true; + public def run(): boolean = { + try { + val clocks = Array.make[Clock](0..5, (Point)=>Clock.make()); + finish async (here) clocked (clocks(0)){ + next; + } + } catch (x:ClockUseException) { + return true; } + return false; + } - - - public static def main(var args: Rail[String]): void = { - new ClockAsyncTest().execute(); - } + public static def main(var args: Rail[String]) { + new ClockAsyncTest().execute(); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ipe...@us...> - 2009-03-13 04:52:39
|
Revision: 7919 http://x10.svn.sourceforge.net/x10/?rev=7919&view=rev Author: ipeshansky Date: 2009-03-13 04:52:27 +0000 (Fri, 13 Mar 2009) Log Message: ----------- Fix handling of int and long negative literals. Promote numeric types on comparison. Modified Paths: -------------- trunk/x10.compiler.p3/src/polyglot/ext/x10/ast/X10IntLit_c.java trunk/x10.compiler.p3/src/polyglot/ext/x10/visit/X10PrettyPrinterVisitor.java trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/MessagePassingCodeGenerator.java Modified: trunk/x10.compiler.p3/src/polyglot/ext/x10/ast/X10IntLit_c.java =================================================================== --- trunk/x10.compiler.p3/src/polyglot/ext/x10/ast/X10IntLit_c.java 2009-03-12 23:31:37 UTC (rev 7918) +++ trunk/x10.compiler.p3/src/polyglot/ext/x10/ast/X10IntLit_c.java 2009-03-13 04:52:27 UTC (rev 7919) @@ -51,9 +51,6 @@ { throw new SemanticException("Integer literal " + value + " is out of range.",position()); } - if (boundary()) { - value = - (int) value; - } } X10TypeSystem xts = (X10TypeSystem) tc.typeSystem(); X10Type Type = (X10Type) (kind==INT ? xts.Int() : xts.Long()); Modified: trunk/x10.compiler.p3/src/polyglot/ext/x10/visit/X10PrettyPrinterVisitor.java =================================================================== --- trunk/x10.compiler.p3/src/polyglot/ext/x10/visit/X10PrettyPrinterVisitor.java 2009-03-12 23:31:37 UTC (rev 7918) +++ trunk/x10.compiler.p3/src/polyglot/ext/x10/visit/X10PrettyPrinterVisitor.java 2009-03-13 04:52:27 UTC (rev 7919) @@ -42,6 +42,7 @@ import polyglot.ast.Formal_c; import polyglot.ast.Import_c; import polyglot.ast.Instanceof; +import polyglot.ast.IntLit_c; import polyglot.ast.Lit; import polyglot.ast.Local; import polyglot.ast.LocalAssign_c; @@ -1199,7 +1200,7 @@ // Remove duplicates. for (ListIterator<MethodInstance> i = methods.listIterator(); i.hasNext(); ) { - MethodInstance mi = i.next(); + MethodInstance mi = i.next(); if (seen(seen, mi)) i.remove(); } @@ -2705,6 +2706,20 @@ } } + public void visit(IntLit_c n) { + String val; + if (n.kind() == IntLit_c.LONG) + val = Long.toString(n.value()) + "L"; + else if (n.kind() == IntLit_c.INT) { + if (n.value() >= 0x80000000L) + val = "0x" + Long.toHexString(n.value()); + else + val = Long.toString((int) n.value()); + } else + throw new InternalCompilerError("Unrecognized IntLit kind " + n.kind()); + w.write(val); + } + // private Stmt optionalBreak(Stmt s) { // NodeFactory nf = tr.nodeFactory(); // if (s.reachable()) Modified: trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/MessagePassingCodeGenerator.java =================================================================== --- trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/MessagePassingCodeGenerator.java 2009-03-12 23:31:37 UTC (rev 7918) +++ trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/MessagePassingCodeGenerator.java 2009-03-13 04:52:27 UTC (rev 7919) @@ -2231,20 +2231,25 @@ } public void visit(IntLit_c n) { - String val; - if (n.kind() == IntLit_c.LONG) - val = Long.toString(n.value()) + "ll"; - else if (n.kind() == IntLit_c.INT) { - if (n.value() >= 0x80000000L) - val = "0x" + Long.toHexString(n.value()).toUpperCase() + "u"; - else - val = Long.toString((int) n.value()); - } else - throw new InternalCompilerError("Unrecognized IntLit kind " + n.kind()); - sw.write("("); sw.begin(0); - sw.write("(" + emitter.translateType(n.type(), true) + ")"); - sw.write(val); - sw.end(); sw.write(")"); + String val; + if (n.kind() == IntLit_c.LONG) { + if (n.boundary()) + val = "0x" + Long.toHexString(n.value()).toUpperCase() + "llu"; + else + val = Long.toString(n.value()) + "ll"; + } else if (n.kind() == IntLit_c.INT) { + if (n.value() >= 0x80000000L) + val = "0x" + Long.toHexString(n.value()).toUpperCase() + "u"; + else if (n.boundary()) + val = "0x" + Long.toHexString(-n.value()).toUpperCase() + "u"; + else + val = Long.toString((int) n.value()); + } else + throw new InternalCompilerError("Unrecognized IntLit kind " + n.kind()); + sw.write("("); sw.begin(0); + sw.write("(" + emitter.translateType(n.type(), true) + ")"); + sw.write(val); + sw.end(); sw.write(")"); } public void visit(NullLit_c n) { @@ -3321,9 +3326,9 @@ public void visit(Unary_c n) { Unary_c.Operator operator = n.operator(); Expr expr = n.expr(); - if (operator == Unary_c.NEG && expr instanceof IntLit && ((IntLit) expr).boundary()) { - sw.write(operator.toString()); - sw.write(((IntLit) expr).positiveToString()); + if (operator == Unary_c.NEG && expr instanceof IntLit) { + IntLit_c lit = (IntLit_c) expr; + n.printSubExpr(lit.value(-lit.longValue()), true, sw, tr); } else if (operator.isPrefix()) { sw.write(operator.toString()); @@ -3349,12 +3354,22 @@ if (op == Binary.EQ || op == Binary.NE) { // FIXME: get rid of this special case sw.write("("); sw.begin(0); + Type c = l; + if (l.isNumeric() && r.isNumeric()) { + try { + c = xts.promote(l, r); + } catch (SemanticException e) { assert (false); } + } if (op == Binary.NE) sw.write("!"); sw.write(STRUCT_EQUALS+"("); sw.begin(0); + if (!xts.typeEquals(c, l)) + sw.write("(" + emitter.translateType(c) + ")"); n.print(left, sw, tr); sw.write(","); sw.allowBreak(0, " "); + if (!xts.typeEquals(c, r)) + sw.write("(" + emitter.translateType(c) + ")"); n.print(right, sw, tr); sw.end(); sw.write(")"); sw.end(); sw.write(")"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ipe...@us...> - 2009-03-14 14:31:00
|
Revision: 7926 http://x10.svn.sourceforge.net/x10/?rev=7926&view=rev Author: ipeshansky Date: 2009-03-14 14:30:36 +0000 (Sat, 14 Mar 2009) Log Message: ----------- Do not insert casts of null to parameter types Equals hack -- cast argument to Object if invoking equals on a parameter type Properly cast arguments of struct_equals Add newlines after typedef comments Specialize equals(T, Object) Check for null in struct_equals Define equals(Ref) and equals(Value) in Object; dispatch from equals(Object) Modified Paths: -------------- trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/MessagePassingCodeGenerator.java trunk/x10.runtime.17/src-cpp/x10/lang/Object.h trunk/x10.runtime.17/src-cpp/x10/lang/Rail.h trunk/x10.runtime.17/src-cpp/x10/lang/Ref.h trunk/x10.runtime.17/src-cpp/x10/lang/String.cc trunk/x10.runtime.17/src-cpp/x10/lang/String.h trunk/x10.runtime.17/src-cpp/x10/lang/ValRail.h trunk/x10.runtime.17/src-cpp/x10/lang/Value.h trunk/x10.runtime.17/src-cpp/x10aux/basic_functions.h trunk/x10.runtime.17/src-cpp/x10aux/class_cast.h trunk/x10.runtime.17/src-cpp/x10aux/iterator_utils.h Modified: trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/MessagePassingCodeGenerator.java =================================================================== --- trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/MessagePassingCodeGenerator.java 2009-03-14 14:26:10 UTC (rev 7925) +++ trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/MessagePassingCodeGenerator.java 2009-03-14 14:30:36 UTC (rev 7926) @@ -263,20 +263,21 @@ public void visit(TypeDecl_c n) { - // FIXME: I think we need to put a typedef for a TypeDecl. - // verify. [Krishna] - sw.write(" /* " + n + " *" + "/ "); + // do nothing + sw.write(" /* " + n + " *" + "/ "); + sw.newline(); } + public void visit(LocalTypeDef_c n) { + // do nothing + sw.write(" /* " + n + " *" + "/ "); + sw.newline(); + } + public void visit(X10ClassDecl_c n) { processClass(n); } - public void visit(LocalTypeDef_c n) { - // do nothing - sw.write(" /* " + n + " *" + "/ "); - } - private boolean extractGenericStaticDecls(X10ClassDef cd, ClassifiedStream w) { X10CPPContext_c context = (X10CPPContext_c) tr.context(); if (context.pendingStaticDecls.size() == 0) @@ -2000,11 +2001,19 @@ int counter = 0; for (Expr a : n.arguments()) { Type fType = mi.formalTypes().get(counter); - a = cast(a, fType); + if (!xts.typeEquals(fType, a.type()) && !(xts.isParameterType(fType) && a.type().isNull())) + a = cast(a, fType); args.add(a); counter++; } + // [IP] FIXME: accommodate the frontend hack for the equals method + if (mi.name() == Name.make("equals") && args.size() == 1 && mi.typeParameters().size() == 0 && + xts.isParameterType(mi.formalTypes().get(0))) + { + args.set(0, cast(args.get(0), xts.Object())); + } + String pat = getCppImplForDef(md); if (pat != null) { emitNativeAnnotation(pat, mi.typeParameters(), target, args); @@ -3354,7 +3363,7 @@ if (op == Binary.EQ || op == Binary.NE) { // FIXME: get rid of this special case sw.write("("); sw.begin(0); - Type c = l; + Type c = null; if (l.isNumeric() && r.isNumeric()) { try { c = xts.promote(l, r); @@ -3363,13 +3372,13 @@ if (op == Binary.NE) sw.write("!"); sw.write(STRUCT_EQUALS+"("); sw.begin(0); - if (!xts.typeEquals(c, l)) - sw.write("(" + emitter.translateType(c) + ")"); + if (c != null && !xts.isParameterType(c) && !xts.typeEquals(c, l)) + sw.write("(" + emitter.translateType(c, true) + ")"); n.print(left, sw, tr); sw.write(","); sw.allowBreak(0, " "); - if (!xts.typeEquals(c, r)) - sw.write("(" + emitter.translateType(c) + ")"); + if (c != null && !xts.isParameterType(c) && !xts.typeEquals(c, r)) + sw.write("(" + emitter.translateType(c, true) + ")"); n.print(right, sw, tr); sw.end(); sw.write(")"); sw.end(); sw.write(")"); Modified: trunk/x10.runtime.17/src-cpp/x10/lang/Object.h =================================================================== --- trunk/x10.runtime.17/src-cpp/x10/lang/Object.h 2009-03-14 14:26:10 UTC (rev 7925) +++ trunk/x10.runtime.17/src-cpp/x10/lang/Object.h 2009-03-14 14:30:36 UTC (rev 7926) @@ -12,10 +12,10 @@ namespace lang { - class String; + class Ref; + class Value; - class Object { public: @@ -76,7 +76,17 @@ return x10aux::DeserializationDispatcher::create<T>(buf); } - virtual x10_boolean equals(x10aux::ref<Object> id0) = 0; + x10_boolean equals(x10aux::ref<Object> other) { + if (x10aux::instanceof<Value>(other)) + return this->equals(x10aux::ref<Value>((Value*)other.get())); + if (x10aux::instanceof<Ref>(other)) + return this->equals(x10aux::ref<Ref>((Ref*)other.get())); + assert (false && "Unknown reference type"); + return false; + } + + virtual x10_boolean equals(x10aux::ref<Ref> other) = 0; + virtual x10_boolean equals(x10aux::ref<Value> other) = 0; virtual x10_int hashCode() = 0; virtual x10aux::ref<String> toString() = 0; Modified: trunk/x10.runtime.17/src-cpp/x10/lang/Rail.h =================================================================== --- trunk/x10.runtime.17/src-cpp/x10/lang/Rail.h 2009-03-14 14:26:10 UTC (rev 7925) +++ trunk/x10.runtime.17/src-cpp/x10/lang/Rail.h 2009-03-14 14:30:36 UTC (rev 7926) @@ -94,7 +94,7 @@ virtual x10_int hashCode() { return 0; } - virtual x10_boolean equals(x10aux::ref<Object> other) { + virtual x10_boolean equals(x10aux::ref<Ref> other) { if (!x10aux::concrete_instanceof<Iterator>(other)) return false; x10aux::ref<Iterator> other_i = other; if (other_i->rail != rail) return false; @@ -102,6 +102,10 @@ return true; } + virtual x10_boolean equals(x10aux::ref<Value> other) { + return this->Ref::equals(other); + } + virtual x10aux::ref<String> toString() { return new (x10aux::alloc<String>()) String(); } Modified: trunk/x10.runtime.17/src-cpp/x10/lang/Ref.h =================================================================== --- trunk/x10.runtime.17/src-cpp/x10/lang/Ref.h 2009-03-14 14:26:10 UTC (rev 7925) +++ trunk/x10.runtime.17/src-cpp/x10/lang/Ref.h 2009-03-14 14:30:36 UTC (rev 7926) @@ -70,11 +70,15 @@ virtual x10aux::ref<String> toString(); - virtual bool equals(x10aux::ref<Object> other) { + virtual x10_boolean equals(x10aux::ref<Ref> other) { if (other == x10aux::ref<Ref>(this)) return true; return false; } + virtual x10_boolean equals(x10aux::ref<Value> other) { + return false; + } + // Needed for linking - do not override virtual x10_boolean _struct_equals(x10aux::ref<Object> other) { if (other == x10aux::ref<Ref>(this)) return true; Modified: trunk/x10.runtime.17/src-cpp/x10/lang/String.cc =================================================================== --- trunk/x10.runtime.17/src-cpp/x10/lang/String.cc 2009-03-14 14:26:10 UTC (rev 7925) +++ trunk/x10.runtime.17/src-cpp/x10/lang/String.cc 2009-03-14 14:30:36 UTC (rev 7926) @@ -20,15 +20,6 @@ return x10aux::hash(reinterpret_cast<const unsigned char*>(FMGL(content)), length()); } -// TODO: merge with _struct_equals -x10_boolean String::equals(ref<Object> other) { - if (!x10aux::concrete_instanceof<String>(other)) return false; - // now we can downcast the Object to String - ref<String> other_str = other; - return !strcmp(FMGL(content),other_str->FMGL(content)); -} - - x10_int String::indexOf(ref<String> str, x10_int i) { const char *needle = str->FMGL(content); // TODO: bounds check Modified: trunk/x10.runtime.17/src-cpp/x10/lang/String.h =================================================================== --- trunk/x10.runtime.17/src-cpp/x10/lang/String.h 2009-03-14 14:26:10 UTC (rev 7925) +++ trunk/x10.runtime.17/src-cpp/x10/lang/String.h 2009-03-14 14:30:36 UTC (rev 7926) @@ -82,8 +82,6 @@ x10_int hashCode(); - x10_boolean equals(x10aux::ref<Object> s); - x10_int length() { return (x10_int) FMGL(content_length); } x10_int indexOf(x10aux::ref<String> s, x10_int i = 0); x10_int indexOf(x10_char c, x10_int i = 0); Modified: trunk/x10.runtime.17/src-cpp/x10/lang/ValRail.h =================================================================== --- trunk/x10.runtime.17/src-cpp/x10/lang/ValRail.h 2009-03-14 14:26:10 UTC (rev 7925) +++ trunk/x10.runtime.17/src-cpp/x10/lang/ValRail.h 2009-03-14 14:30:36 UTC (rev 7926) @@ -96,7 +96,7 @@ return new (x10aux::alloc<String>()) String(); } - virtual x10_boolean equals(x10aux::ref<Object> other) { + virtual x10_boolean equals(x10aux::ref<Ref> other) { if (!x10aux::concrete_instanceof<Iterator>(other)) return false; x10aux::ref<Iterator> other_i = other; if (other_i->rail != rail) return false; @@ -104,6 +104,10 @@ return true; } + virtual x10_boolean equals(x10aux::ref<Value> other) { + return this->Ref::equals(other); + } + }; virtual x10aux::ref<x10::lang::Iterator<T> > iterator() { Modified: trunk/x10.runtime.17/src-cpp/x10/lang/Value.h =================================================================== --- trunk/x10.runtime.17/src-cpp/x10/lang/Value.h 2009-03-14 14:26:10 UTC (rev 7925) +++ trunk/x10.runtime.17/src-cpp/x10/lang/Value.h 2009-03-14 14:30:36 UTC (rev 7926) @@ -69,11 +69,16 @@ virtual x10aux::ref<String> toString(); - virtual x10_boolean equals(x10aux::ref<Object> other) { + virtual x10_boolean equals(x10aux::ref<Value> other) { + if (other == x10aux::ref<Value>(this)) return true; if (!x10aux::instanceof<Value>(other)) return false; return this->_struct_equals(other); } + virtual x10_boolean equals(x10aux::ref<Ref> other) { + return false; + } + virtual x10_boolean _struct_equals(x10aux::ref<Object> other) { if (!_type()->concreteInstanceOf(other)) return false; Modified: trunk/x10.runtime.17/src-cpp/x10aux/basic_functions.h =================================================================== --- trunk/x10.runtime.17/src-cpp/x10aux/basic_functions.h 2009-03-14 14:26:10 UTC (rev 7925) +++ trunk/x10.runtime.17/src-cpp/x10aux/basic_functions.h 2009-03-14 14:30:36 UTC (rev 7926) @@ -39,9 +39,19 @@ } template<class T, class U> - static inline x10_boolean equals(ref<T> x, ref<U> y) { return x->equals(y); } + class Equals { + public: static inline x10_boolean _(ref<T> x, ref<U> y) { return x->equals(y); } + }; template<class T> + class Equals<T, x10::lang::Object> { + public: static inline x10_boolean _(ref<T> x, ref<x10::lang::Object> y) { return x->x10::lang::Object::equals(y); } + }; + + template<class T, class U> + static inline x10_boolean equals(ref<T> x, ref<U> y) { return Equals<T, U>::_(x, y); } + + template<class T> static inline x10_boolean equals(ref<T> x, x10_double y) { return false; } template<class T> static inline x10_boolean equals(ref<T> x, x10_float y) { return false; } @@ -85,7 +95,11 @@ static inline x10_boolean equals(const x10_boolean x, const x10_boolean y) { return x==y; } template<class T, class U> - static inline x10_boolean struct_equals(ref<T> x, ref<U> y) { return x->_struct_equals(y); } + static inline x10_boolean struct_equals(ref<T> x, ref<U> y) { + if (x.isNull()) + return y.isNull(); + return x->_struct_equals(y); + } template<class T> static inline x10_boolean struct_equals(ref<T> x, x10_double y) { return false; } Modified: trunk/x10.runtime.17/src-cpp/x10aux/class_cast.h =================================================================== --- trunk/x10.runtime.17/src-cpp/x10aux/class_cast.h 2009-03-14 14:26:10 UTC (rev 7925) +++ trunk/x10.runtime.17/src-cpp/x10aux/class_cast.h 2009-03-14 14:30:36 UTC (rev 7926) @@ -155,7 +155,8 @@ T v; ValueBox(T v_) : v(v_) { } virtual x10_int hashCode() { return x10aux::hash_code(v); } - virtual x10_boolean equals(x10aux::ref<Object> other) { return x10aux::equals(v, other); } + virtual x10_boolean equals(x10aux::ref<x10::lang::Value> other) { return x10aux::equals(v, other); } + virtual x10_boolean equals(x10aux::ref<x10::lang::Ref> other) { return false; } virtual x10_boolean _struct_equals(x10aux::ref<x10::lang::Object> p0) { return x10aux::struct_equals(v, p0); } virtual ref<x10::lang::String> toString() { return x10aux::to_string(v); } }; Modified: trunk/x10.runtime.17/src-cpp/x10aux/iterator_utils.h =================================================================== --- trunk/x10.runtime.17/src-cpp/x10aux/iterator_utils.h 2009-03-14 14:26:10 UTC (rev 7925) +++ trunk/x10.runtime.17/src-cpp/x10aux/iterator_utils.h 2009-03-14 14:30:36 UTC (rev 7926) @@ -29,8 +29,10 @@ T next() { return (T)(_from->next()); } - x10_boolean equals(ref<x10::lang::Object> o) { return _from->equals(o); } + x10_boolean equals(ref<x10::lang::Ref> o) { return _from->equals(o); } + x10_boolean equals(ref<x10::lang::Value> o) { return false; } + x10_int hashCode() { return _from->hashCode(); } ref<x10::lang::String> toString() { return _from->toString(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <spa...@us...> - 2009-03-14 18:02:41
|
Revision: 7933 http://x10.svn.sourceforge.net/x10/?rev=7933&view=rev Author: sparksparkspark Date: 2009-03-14 18:02:38 +0000 (Sat, 14 Mar 2009) Log Message: ----------- Aggressive refactoring of c++ backend: - drop dead code - consign SPMD support to svn history Add wildcard to X10Context_c.java function to suppress warning. Modified Paths: -------------- trunk/x10.compiler.p3/src/polyglot/ext/x10/types/X10Context_c.java trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/ast/X10CPPDelFactory_c.java trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/types/X10CPPContext_c.java trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/ASTQuery.java trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/Emitter.java trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/MessagePassingCodeGenerator.java trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/X10CPPTranslator.java Modified: trunk/x10.compiler.p3/src/polyglot/ext/x10/types/X10Context_c.java =================================================================== --- trunk/x10.compiler.p3/src/polyglot/ext/x10/types/X10Context_c.java 2009-03-14 17:55:47 UTC (rev 7932) +++ trunk/x10.compiler.p3/src/polyglot/ext/x10/types/X10Context_c.java 2009-03-14 18:02:38 UTC (rev 7933) @@ -342,7 +342,7 @@ /** * Gets a local or field of a particular name. */ - public VarInstance findVariableSilent(Name name) { + public VarInstance<?> findVariableSilent(Name name) { return super.findVariableSilent(name); } Modified: trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/ast/X10CPPDelFactory_c.java =================================================================== --- trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/ast/X10CPPDelFactory_c.java 2009-03-14 17:55:47 UTC (rev 7932) +++ trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/ast/X10CPPDelFactory_c.java 2009-03-14 18:02:38 UTC (rev 7933) @@ -66,7 +66,7 @@ return new TD() { public Context enterScope(Context c) { X10CPPContext_c context = (X10CPPContext_c) super.enterScope(c); - context.setinClosure(true); + context.setInClosure(); return context; } }; Modified: trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/types/X10CPPContext_c.java =================================================================== --- trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/types/X10CPPContext_c.java 2009-03-14 17:55:47 UTC (rev 7932) +++ trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/types/X10CPPContext_c.java 2009-03-14 18:02:38 UTC (rev 7933) @@ -14,6 +14,7 @@ * @author igor * @author pvarma * @author nvk + * @author Dave Cunningham * @see X10Context_c */ import static polyglot.ext.x10cpp.visit.Emitter.mangled_non_method_name; @@ -25,10 +26,10 @@ import polyglot.ast.ClassMember; import polyglot.ast.Stmt; +import polyglot.ext.x10.ast.PropertyDecl; import polyglot.ext.x10.types.X10ClassDef; import polyglot.ext.x10.types.X10Context; import polyglot.ext.x10.types.X10MethodDef; -import polyglot.types.Context_c; import polyglot.types.LocalInstance; import polyglot.types.Name; import polyglot.types.TypeSystem; @@ -37,14 +38,73 @@ public class X10CPPContext_c extends polyglot.ext.x10.types.X10Context_c implements X10Context { - public X10CPPContext_c(TypeSystem ts) { - super(ts); - finish_depth = 0; - ateach_depth = 0; - inprocess = false; - mainMethod = false; - } + // The global object is fresh for each brand new instance of the context, + // but is aliased for each clone of the context (cloned via copy()). + // The only thing that belongs in here is primitive data that needs a level + // of indirection to allow aliasing after cloning. + protected static class Global { + public int closureId; + } + protected Global g = new Global(); + + public void advanceClosureId() { g.closureId++; } + public int closureId() { return g.closureId; } + protected void resetClosureId() { g.closureId = -1; } + + protected ArrayList<ClassMember> pendingStaticDecls; + protected ArrayList<PropertyDecl> classProperties; + + public List<PropertyDecl> classProperties() { return classProperties; } + public List<ClassMember> pendingStaticDecls() { return pendingStaticDecls; } + + // Here, for each new class we reset the above structures, ready for fresh accumulation of data. + public void resetStateForClass(List<PropertyDecl> props) { + assert kind == SOURCE; + pendingStaticDecls = new ArrayList<ClassMember>(); + classProperties = new ArrayList<PropertyDecl>(props); + resetClosureId(); + } + + + private String label; + public String getLabel() { return label; } + + private Stmt stmt; + public Stmt getLabeledStatement() { return stmt; } + + public void setLabel(String label, Stmt stmt) { + this.label = label; + this.stmt = stmt; + } + + + private String excVar; + public void setExceptionVar(String var) { this.excVar = var; } + public String getExceptionVar() { return excVar; } + + // used internally, shallow + protected boolean inClosure; + public void setInClosure() { inClosure = true; } + + // used externally, deep + protected boolean insideClosure; + public boolean isInsideClosure() { return insideClosure; } + public void setInsideClosure(boolean b) { insideClosure = b; } + + + public boolean hasInits = false; + + + public ClassifiedStream templateFunctions = null; + + public ArrayList<VarInstance> variables = new ArrayList<VarInstance>(); + + + public X10CPPContext_c(TypeSystem ts) { + super(ts); + } + public boolean inTemplate() { X10ClassDef cd = (X10ClassDef)currentClassDef(); // following 2 lines are needed for constraints @@ -60,226 +120,39 @@ return (!staticMethod && genericClass) || genericMethod; } - public boolean inClosure; - public boolean insideClosure; - - public ArrayList variables = new ArrayList(); - public ArrayList SPMDVars = new ArrayList(); - public ArrayList GlobalVars = new ArrayList(); - public HashSet Unbroadcastable = new HashSet(); - - public HashMap InlineMap = new HashMap(); - public HashMap RenameMap = new HashMap(); - public HashMap duplicateId = new HashMap(); - public boolean inlining; - public static String returnLabel; - public static String returnVar; - public static String lastReturnVar; - public boolean canInline; - - public static ArrayList<ClassMember> pendingStaticDecls = new ArrayList<ClassMember>(); - public static HashMap classesWithAsyncSwitches = new HashMap(); - public static HashMap classesWithArrayCopySwitches = new HashMap(); - public ArrayList classProperties = new ArrayList(); - - public HashSet warnedAbout = new HashSet(); - - public void setinClosure(boolean b) { - inClosure = b; - } - - public void setinsideClosure(boolean b) { - insideClosure = b; - } - - protected Context_c push() { - X10CPPContext_c v = (X10CPPContext_c) super.push(); - return v; - } - - static int closureId = -1; - public void incClosureId() { closureId++; } - public int closureId() { return closureId; } public void saveEnvVariableInfo(String name) { VarInstance vi = findVariableInThisScope(Name.make(name)); if (vi != null) { // found declaration - return; // local variable + // local variable (do nothing) } else if (inClosure) { - addVar(name); - return; // local variable + addVar(name); // local variable } else { // Captured Variable ((X10CPPContext_c) outer).saveEnvVariableInfo(name); } } - public void addVar(String name) { + + private VarInstance lookup(String name) { + VarInstance vi = findVariableInThisScope(Name.make(name)); + if (vi != null) return vi; + else if (outer != null) return ((X10CPPContext_c) outer).lookup(name); + else return null; + } + + private void addVar(String name) { VarInstance vi = lookup(name); boolean contains = false; - for (int i = 0; i < variables.size(); i++) { - if (((VarInstance) variables.get(i)).name().toString().equals(vi.name().toString())) { - contains = true; - break; - } - } + for (VarInstance vi2 : variables) { + // [DC]: what is wrong with vi2.equals(vi)? + if (vi2.name().toString().equals(vi.name().toString())) { + contains = true; + break; + } + } if (!contains) variables.add(vi); } - - private boolean listContains(ArrayList list, Object val) { - for (int i = 0; i < list.size(); i++) - if (val == list.get(i)) - return true; - return false; - } - - public boolean isSPMDVar(VarInstance var) { - if (!mainMethod) - return false; // Cannot have a global outside of main - if (var instanceof LocalInstance && isInlineMapped(var)) - var = getInlineMapping(var); - if (listContains(SPMDVars, var)) - return true; - if (outer != null) - return ((X10CPPContext_c) outer).isSPMDVar(var); - return false; - } - - public void addSPMDVar(VarInstance var) { - if (isSPMDVar(var)) - return; - assert (!isSPMDVar(var)); - assert (mainMethod); - SPMDVars.add(var); - } - - public void addGlobalVar(VarInstance var, Integer id) { - if (isGlobalVar(var)) //if it is the exact same instance, then don't add. - return; - assert (mainMethod); - assert (!isGlobalVar(var)); - X10CPPContext_c outer = (X10CPPContext_c) this.outer; - // [IP] The condition below is too strict. - // We can also have global vars inside conditionals. -// assert (outer.isCode()); - assert (outer.isMainMethod()); - - // If it is a different varInstance but same name then - // rename. - if (findGlobalVarSilent(var.name().toString()) != null) { - duplicateId.put(var,id); - } - GlobalVars.add(var); - } - - public boolean isGlobalVar(VarInstance var) { - if (!mainMethod) - return false; // Cannot have a global outside of main - // TODO: should we go via the inline mapping here as well? - if (GlobalVars.contains(var)) - return true; - if (outer != null) - return ((X10CPPContext_c) outer).isGlobalVar(var); - return false; - } - - public ArrayList getGlobals() { - return GlobalVars; - } - - public VarInstance findGlobalVarSilent(String name) { - for (int i = 0; i < GlobalVars.size(); i++) { - VarInstance var = (VarInstance)GlobalVars.get(i); - if (var.name().toString().equals(name)) - return var; - } - return null; - } - - public void addUnbroadcastable(VarInstance var) { - if (isUnbroadcastable(var)) - return; - assert (mainMethod); - assert (!isUnbroadcastable(var)); - Unbroadcastable.add(var); - } - - public boolean isUnbroadcastable(VarInstance var) { - if (!mainMethod) - return false; // Cannot have a global outside of main - // TODO: should we go via the inline mapping here as well? - if (Unbroadcastable.contains(var)) - return true; - if (outer != null) - return ((X10CPPContext_c) outer).isUnbroadcastable(var); - return false; - } - - public void addInlineMapping(LocalInstance alias, LocalInstance var) { - if (isInlineMapped(alias)) - return; - assert (!isInlineMapped(alias)); - X10CPPContext_c outer = (X10CPPContext_c) this.outer; - assert (outer.isMainMethod()); - InlineMap.put(alias, var); - } - - public boolean isInlineMapped(VarInstance var) { - if (InlineMap.containsKey(var)) - return true; - if (outer != null) - return ((X10CPPContext_c) outer).isInlineMapped(var); - return false; - } - - public LocalInstance getInlineMapping(VarInstance var) { - assert (var instanceof LocalInstance); - LocalInstance result = (LocalInstance) InlineMap.get(var); - if (result == null && outer != null) { - result = ((X10CPPContext_c) outer).getInlineMapping(var); - } - return result; - } - public Object getDuplicateId(VarInstance var) { - return duplicateId.get(var); - } - - public void addRenameMapping(VarInstance var, String newName) { - assert (inlining); - List names = (List) RenameMap.get(var); - if (names == null) - RenameMap.put(var, names = new ArrayList()); - names.add(newName); - } - - public String getCurrentName(VarInstance var) { - String D = ""; - if (insideClosure && isGlobalVar(var) && getDuplicateId(var) != null) { - D = getDuplicateId(var).toString(); - } - if (!inlining) - return mangled_non_method_name(var.name().toString() + D); - List names = getRenameMapping(var); - if (names == null) - return mangled_non_method_name(var.name().toString() + D); - return mangled_non_method_name((String) names.get(names.size()-1) + D); - } - - public List getRenameMapping(VarInstance var) { - return (List) RenameMap.get(var); - } - - public void removeRenameMapping(VarInstance var) { - RenameMap.remove(var); - } - - private VarInstance lookup(String name) { - VarInstance vi = findVariableInThisScope(Name.make(name)); - if (vi != null) return vi; - else if (outer != null) return ((X10CPPContext_c) outer).lookup(name); - else return null; - } - public void finalizeClosureInstance() { // remove all from current context. Move those pertinent to an outer // closure to the outer closure. @@ -294,117 +167,16 @@ ((X10CPPContext_c) outer).saveEnvVariableInfo(v.name().toString()); } } + + + public Object copy() { X10CPPContext_c res = (X10CPPContext_c) super.copy(); - res.variables = new ArrayList(); // or whatever the initial value is + res.variables = new ArrayList<VarInstance>(); // or whatever the initial value is res.inClosure = false; - res.InlineMap = new HashMap(); return res; } - private boolean mainMethod; - - public boolean isMainMethod() { - return mainMethod; - } - - public void setMainMethod() { - mainMethod = true; - } - - public void resetMainMethod() { - mainMethod = false; - } - - private boolean asyncInlinable; - - // this variable is set, if we are inside a loop structure or - // nested asyncs, throw statement, or conditional atomics. Q: How - // to detect if there are messages that are being initiated? - // -Krishna. - public boolean inlinableAsyncsOnly() { - return asyncInlinable; - } - - public void setInlinableAsyncsOnly() { - asyncInlinable = true; - } - - public void resetInlinableAsyncsOnly() { - asyncInlinable = false; - } - - private boolean seqCode; - - public boolean noAtEachCode() { - return seqCode; - } - - public void setAtEachCode() { - seqCode = true; - } - - public void resetAtEachCode() { - seqCode = false; - } - - public static int async_depth = 0; - - public static int finish_cnt = 0; - - public int finish_depth; - - public int ateach_depth; - - public boolean inprocess; - - public static boolean inplace0; - - // I would think that we do not need static here. - // But someone is overwriting the context and I am - // ending up having wrong labels. - // -Krishna. TODO: Fixit. - public static int nextLabel; - - private String label; - - private Stmt stmt; - - public void setLabel(String label, Stmt stmt) { - this.label = label; - this.stmt = stmt; - } - - public String getLabel() { - return label; - } - - public Stmt getLabeledStatement() { - return stmt; - } - - private String excVar; - - public boolean hasInits = false; - - public void setExceptionVar(String var) { - this.excVar = var; - } - - public String getExceptionVar() { - return excVar; - } - private static int localClassDepth; - public boolean inLocalClass(){ return localClassDepth != 0; } - public void pushInLocalClass(){ localClassDepth ++ ; } - public void popInLocalClass(){ localClassDepth--; } - - private static String selfStr; - public void setSelf(String str){ selfStr = str; }; - public void resetSelf() { selfStr = null; }; - public String Self() { return selfStr; }; - - public ClassifiedStream templateFunctions = null; } //vim:tabstop=4:shiftwidth=4:expandtab Modified: trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/ASTQuery.java =================================================================== --- trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/ASTQuery.java 2009-03-14 17:55:47 UTC (rev 7932) +++ trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/ASTQuery.java 2009-03-14 18:02:38 UTC (rev 7933) @@ -63,31 +63,7 @@ public ASTQuery(Translator tr) { this.tr = tr; } - - static final HashMap<String,String> arrayRuntimeNameToType = new HashMap<String,String>(); - static { - arrayRuntimeNameToType.put("booleanArray", "boolean"); - arrayRuntimeNameToType.put("BooleanReferenceArray", "boolean"); - arrayRuntimeNameToType.put("byteArray", "byte"); - arrayRuntimeNameToType.put("ByteReferenceArray", "byte"); - arrayRuntimeNameToType.put("charArray", "char"); - arrayRuntimeNameToType.put("CharReferenceArray", "char"); - arrayRuntimeNameToType.put("shortArray", "short"); - arrayRuntimeNameToType.put("ShortReferenceArray", "short"); - arrayRuntimeNameToType.put("intArray", "int"); - arrayRuntimeNameToType.put("IntReferenceArray", "int"); - arrayRuntimeNameToType.put("longArray", "long"); - arrayRuntimeNameToType.put("LongReferenceArray", "long"); - arrayRuntimeNameToType.put("floatArray", "float"); - arrayRuntimeNameToType.put("FloatReferenceArray", "float"); - arrayRuntimeNameToType.put("doubleArray", "double"); - arrayRuntimeNameToType.put("DoubleReferenceArray", "double"); - } - boolean isMainMethod(X10CPPContext_c context) { - return context.isMainMethod() && !context.insideClosure; - } - boolean isSyntheticField(String name) { if (name.startsWith("jlc$")) return true; return false; Modified: trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/Emitter.java =================================================================== --- trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/Emitter.java 2009-03-14 17:55:47 UTC (rev 7932) +++ trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/Emitter.java 2009-03-14 18:02:38 UTC (rev 7933) @@ -310,12 +310,6 @@ VarInstance var = (VarInstance)c.variables.get(i); if (!omitType) { Type t = var.type(); - if (c.isSPMDVar(var)) { - assert (t.isClass()); - X10ClassType ct = (X10ClassType) t; - assert (ct.typeArguments().size() == 1); - t = ct.typeArguments().get(0); - } String type = translateType(t, true); w.write(type + " "); } @@ -740,7 +734,7 @@ } void enterClosure(X10CPPContext_c c) { - c.incClosureId(); + c.advanceClosureId(); } void exitClosure(X10CPPContext_c c) { } @@ -748,10 +742,10 @@ void printExplicitTarget(Call_c n, Receiver target, X10CPPContext_c context, CodeWriter w) { if (target instanceof X10Special_c && ((X10Special_c)target).kind().equals(X10Special_c.THIS) && - (context.inlining || context.insideClosure)) + context.isInsideClosure()) { w.write(SAVED_THIS); - if (context.insideClosure) + if (context.isInsideClosure()) context.saveEnvVariableInfo(THIS); } else if (target instanceof Expr) { @@ -773,36 +767,19 @@ for (int i = 0; i < vars.size(); i++) { VarInstance var = (VarInstance)vars.get(i); Type t = var.type(); - if (c.isSPMDVar(var)) { - assert (t.isClass()); - X10ClassType ct = (X10ClassType) t; - assert (ct.typeArguments().size() == 1); - t = ct.typeArguments().get(0); - } String type = translateType(t, true); if (writable && !var.name().toString().equals(THIS)) // this is a temporary ref type = type + "&"; // FIXME: Hack to get writable args in finally closures - List names = c.getRenameMapping(var); - if (names == null) { - String name = var.name().toString(); - if (saved_this_mechanism && name.equals(THIS)) { - assert (c.inlining || c.insideClosure); // FIXME: Krishna, why did you add this test? - name = SAVED_THIS; - } - else { - if (c.isGlobalVar(var) && c.getDuplicateId(var) != null) - name += c.getDuplicateId(var); - name = mangled_non_method_name(name); - } - w.write(type + " " + name + ";"); - w.newline(); - } else { - for (Iterator n = names.iterator(); n.hasNext(); ) { - String name = (String) n.next(); - w.write(type + " " + name + ";"); - w.newline(); - } + String name = var.name().toString(); + if (saved_this_mechanism && name.equals(THIS)) { + assert (c.isInsideClosure()); // FIXME: Krishna, why did you add this test? + name = SAVED_THIS; } + else { + name = mangled_non_method_name(name); + } + w.write(type + " " + name + ";"); + w.newline(); } } @@ -1038,10 +1015,7 @@ private void prettyPrint(Object o, Translator tr, CodeWriter w) { if (o instanceof Node) { Node n = (Node) o; - X10CPPContext_c context = (X10CPPContext_c) tr.context(); - ((X10CPPTranslator) tr).setContext(n.del().enterScope(context)); - n.del().translate(w, tr); - ((X10CPPTranslator) tr).setContext(context); + tr.print(null, n, w); } else if (o instanceof Type) { w.write(translateType((Type)o, true)); } else if (o != null) { Modified: trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/MessagePassingCodeGenerator.java =================================================================== --- trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/MessagePassingCodeGenerator.java 2009-03-14 17:55:47 UTC (rev 7932) +++ trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/MessagePassingCodeGenerator.java 2009-03-14 18:02:38 UTC (rev 7933) @@ -136,6 +136,7 @@ import polyglot.ext.x10.ast.LocalTypeDef_c; import polyglot.ext.x10.ast.Next_c; import polyglot.ext.x10.ast.ParExpr_c; +import polyglot.ext.x10.ast.PropertyDecl; import polyglot.ext.x10.ast.PropertyDecl_c; import polyglot.ext.x10.ast.RegionMaker_c; import polyglot.ext.x10.ast.SettableAssign_c; @@ -280,7 +281,7 @@ private boolean extractGenericStaticDecls(X10ClassDef cd, ClassifiedStream w) { X10CPPContext_c context = (X10CPPContext_c) tr.context(); - if (context.pendingStaticDecls.size() == 0) + if (context.pendingStaticDecls().size() == 0) return false; boolean hasInits = false; w.write("template <> class "); @@ -291,7 +292,7 @@ w.newline(4); w.begin(0); w.write("public:"); w.newline(); // First process all classes - for (ClassMember dec : context.pendingStaticDecls) { + for (ClassMember dec : context.pendingStaticDecls()) { if (dec instanceof ClassDecl_c) { assert false : "nested class alert! "+cd.position(); ClassDecl_c cdecl = (ClassDecl_c) dec; @@ -310,7 +311,7 @@ } } // Then process all fields and methods - for (ClassMember dec : context.pendingStaticDecls) { + for (ClassMember dec : context.pendingStaticDecls()) { if (dec instanceof FieldDecl_c) { FieldDecl_c fd = (FieldDecl_c) dec; ((X10CPPTranslator)tr).setContext(fd.enterScope(context)); // FIXME @@ -360,7 +361,7 @@ X10CPPContext_c context = (X10CPPContext_c) tr.context(); ArrayList<FieldDecl_c> inits = new ArrayList<FieldDecl_c>(); String container = translate_mangled_FQN(cd.fullName().toString())+voidTemplateInstantiation(cd.typeParameters().size()); - for (ClassMember dec : context.pendingStaticDecls) { + for (ClassMember dec : context.pendingStaticDecls()) { if (dec instanceof FieldDecl_c) { FieldDecl_c fd = (FieldDecl_c) dec; ((X10CPPTranslator)tr).setContext(fd.enterScope(context)); // FIXME @@ -422,45 +423,6 @@ } else if (dec instanceof X10ClassDecl_c) { assert (false) : ("Nested class alert!"); - X10ClassDecl_c cdecl = (X10ClassDecl_c) dec; - ((X10CPPTranslator)tr).setContext(cdecl.enterScope(context)); // FIXME - - X10ClassDef def = (X10ClassDef) cdecl.classDef(); - if (getCppRep(def) != null) { - // emit no c++ code as this is a native rep class - continue; - } - ClassifiedStream h = sw.header(); - emitter.printTemplateSignature(((X10ClassType)def.asType()).typeArguments(), h); - h.write("class "+container+"::"+Emitter.mangled_non_method_name(def.name().toString())); - h.allowBreak(0, " "); - // [DC]: the following function adds the : public B, public C etc - emitter.printInheritance(cdecl, h ,tr); - h.allowBreak(0, " "); - - context.setinsideClosure(false); - context.hasInits = false; - - assert (def.isNested()); - if (!def.flags().isStatic()) - throw new InternalCompilerError("Instance Inner classes not supported"); - - ArrayList<ClassMember> opsd = context.pendingStaticDecls; - context.pendingStaticDecls = new ArrayList<ClassMember>(); - - cdecl.print(cdecl.body(), sw, tr); - - processNestedClasses(cdecl); - - if (extractGenericStaticDecls((X10ClassDef)cdecl.classDef(), h)) { - extractGenericStaticInits((X10ClassDef)cdecl.classDef()); - } - - context.pendingStaticDecls = opsd; - - h.newline(); - - ((X10CPPTranslator)tr).setContext(context); // FIXME } } if (inits.size() > 0) { @@ -584,23 +546,6 @@ return false; } - private void processNestedClasses(X10ClassDecl_c n) { - X10CPPContext_c context = (X10CPPContext_c) tr.context(); - boolean generic = ((X10ClassDef)n.classDef()).typeParameters().size() != 0; - for (Iterator i = n.body().members().iterator(); i.hasNext(); ) { - ClassMember member = (ClassMember) i.next(); - if (member instanceof ClassDecl_c) { - X10ClassDecl_c cd = (X10ClassDecl_c) member; - if (generic && cd.flags().flags().isStatic()) { - context.pendingStaticDecls.add(cd); - continue; - } - processClass(cd); - } - } - } - - private void extractAllClassTypes(Type t, List<ClassType> types, Set<ClassType> dupes) { X10TypeSystem xts = (X10TypeSystem) t.typeSystem(); t = xts.expandMacros(t); @@ -654,8 +599,6 @@ void processClass(X10ClassDecl_c n) { X10CPPContext_c context = (X10CPPContext_c) tr.context(); - assert (!context.inLocalClass()) : ("Local classes should have been removed earlier"); - X10ClassDef def = (X10ClassDef) n.classDef(); if (getCppRep(def) != null) { @@ -682,7 +625,7 @@ ClassifiedStream z = sw.getNewStream(StreamWrapper.Header, false); sw.set(h, w); - context.setinsideClosure(false); + context.setInsideClosure(false); context.hasInits = false; // Write the header for the class @@ -842,9 +785,21 @@ w.forceNewline(0); } + /* [DC] since we don't have nested classes anymore, processClass is never called from + * inside processClass, so this stack device is no-longer needed. ArrayList<ClassMember> opsd = context.pendingStaticDecls; - context.pendingStaticDecls = new ArrayList<ClassMember>(); + assert opsd.isEmpty() : "Should not occur without nested classes"; + */ + /* + * Ideally, classProperties would be added to the child context + * that will be created for processing the classBody, but there + * is no way to do that. So instead we add and remove the properties + * in the global context, for each class. + */ + context.resetStateForClass(n.properties()); + + if (def.typeParameters().size() != 0) { // Pre-declare the void specialization for statics emitter.printTemplateSignature(((X10ClassType)def.asType()).typeArguments(), h); @@ -862,28 +817,20 @@ emitter.printHeader(n, h, tr, false); h.allowBreak(0, " "); - /* - * Ideally, classProperties would be added to the child context - * that will be created for processing the classBody, but there - * is no way to do that. So instead we add and remove the properties - * around the call to visiting the class body. - */ - context.classProperties.addAll(n.properties()); n.print(n.body(), sw, tr); - context.classProperties.clear(); ((X10CPPTranslator)tr).setContext(n.enterChildScope(n.body(), context)); // FIXME /* * TODO: [IP] Add comment about dependences between the method calls. */ - processNestedClasses(n); if (extractGenericStaticDecls(def, h)) { extractGenericStaticInits(def); } ((X10CPPTranslator)tr).setContext(context); // FIXME - context.pendingStaticDecls = opsd; + // [DC] disabled, see (commented out) definition of opsd above for details + // context.pendingStaticDecls = opsd; h.newline(); @@ -1032,11 +979,11 @@ h.write("public:"); h.newline(); emitter.printRTT(currentClass, h); sw.begin(0); - for (Iterator pi = context.classProperties.iterator(); pi.hasNext();) { - PropertyDecl_c p = (PropertyDecl_c) pi.next(); + for (PropertyDecl p : context.classProperties()) { n.print(p, sw, tr); } - context.classProperties = new ArrayList(); + // [DC] without inner classes i see no reason to reset this here + //context.classProperties = new ArrayList(); List<ClassMember> members = n.members(); if (!members.isEmpty()) { @@ -1244,7 +1191,6 @@ emitter.generateSerializationMethods(currentClass, sw); } - context.resetMainMethod(); } h.end(); @@ -1296,7 +1242,7 @@ X10MethodInstance mi = (X10MethodInstance) def.asInstance(); X10ClassType container = (X10ClassType) mi.container(); if ((container.x10Def().typeParameters().size() != 0) && flags.isStatic()) { - context.pendingStaticDecls.add(dec); + context.pendingStaticDecls().add(dec); return; } if (query.isMainMethod(dec)) @@ -1489,7 +1435,7 @@ if ((((X10ClassDef)((X10ClassType)dec.fieldDef().asInstance().container()).def()).typeParameters().size() != 0) && dec.flags().flags().isStatic()) { - context.pendingStaticDecls.add(dec); + context.pendingStaticDecls().add(dec); return; } @@ -1948,7 +1894,7 @@ Position pos = a.position(); a = nf.X10Cast(pos, nf.CanonicalTypeNode(pos, fType), a, X10Cast.ConversionType.CHECKED).type(fType); - } + } return a; } @@ -2200,9 +2146,9 @@ public void visit(Local_c n) { X10CPPContext_c c = (X10CPPContext_c) tr.context(); LocalInstance var = n.localInstance(); - if (c.insideClosure) + if (c.isInsideClosure()) c.saveEnvVariableInfo(n.name().toString()); - sw.write(c.getCurrentName(var)); + sw.write(mangled_non_method_name(var.name().toString())); } public void visit(New_c n) { @@ -2382,7 +2328,7 @@ X10TypeSystem_c xts = (X10TypeSystem_c) tr.typeSystem(); X10CPPContext_c c = (X10CPPContext_c) context.pushBlock(); - c.setinClosure(true); + c.setInClosure(); ((X10CPPTranslator)tr).setContext(c); // FIXME emitter.enterClosure(c); @@ -2411,7 +2357,7 @@ String hostClassName = emitter.translate_mangled_FQN(hostClassType.fullName().toString(), "_"); - c.setinsideClosure(true); + c.setInsideClosure(true); int id = getConstructorId(c); @@ -2861,7 +2807,7 @@ // n.qualifier()+" "+n.kind()+" "+n.position().nameAndLineString(); if (n.kind().equals(X10Special_c.THIS)) { - if (context.insideClosure) { + if (context.isInsideClosure()) { sw.write(SAVED_THIS); context.saveEnvVariableInfo(THIS); } else { @@ -2870,9 +2816,10 @@ } else if (n.kind().equals(X10Special_c.SUPER)) { sw.write(emitter.translateType(context.currentClass().superClass())); } else if (n.isSelf()) { + assert false: "I do not believe we ever visit over constraints."; // FIXME: Why are we printing the string "self"? // Confirm with Igor. [Krishna] - sw.write((context.Self() == null)? "self":context.Self()); + //sw.write((context.Self() == null)? "self":context.Self()); } else assert (false) : n.kind(); } @@ -2915,7 +2862,7 @@ String hostClassName = emitter.translate_mangled_FQN(hostClassType.fullName().toString(), "_"); - c.setinsideClosure(true); + c.setInsideClosure(true); int id = getConstructorId(c); @@ -3116,7 +3063,7 @@ String name = var.name().toString(); if (!name.equals(THIS)) name = mangled_non_method_name(name); - else if (((X10CPPContext_c)c.pop()).insideClosure) // FIXME: hack + else if (((X10CPPContext_c)c.pop()).isInsideClosure()) // FIXME: hack name = SAVED_THIS; sw.write(name); } Modified: trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/X10CPPTranslator.java =================================================================== --- trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/X10CPPTranslator.java 2009-03-14 17:55:47 UTC (rev 7932) +++ trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/X10CPPTranslator.java 2009-03-14 18:02:38 UTC (rev 7933) @@ -287,6 +287,8 @@ sw.getNewStream(StreamWrapper.Closures, true); // [IP] FIXME: This hack is to ensure the .cc is always generated. sw.getNewStream(StreamWrapper.CC, true); + // [DC] TODO: This hack is to ensure the .h is always generated. + sw.getNewStream(StreamWrapper.Header, true); opfPath = tf.outputName(pkg, decl.name().toString()); assert (!opfPath.endsWith("$")); if (!opfPath.endsWith("$")) outputFiles.add(opfPath); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ipe...@us...> - 2009-03-16 18:48:26
|
Revision: 7958 http://x10.svn.sourceforge.net/x10/?rev=7958&view=rev Author: ipeshansky Date: 2009-03-16 18:48:09 +0000 (Mon, 16 Mar 2009) Log Message: ----------- Better AIX support Modified Paths: -------------- trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/X10CPPTranslator.java trunk/x10.runtime.17/src-cpp/Makefile Modified: trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/X10CPPTranslator.java =================================================================== --- trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/X10CPPTranslator.java 2009-03-16 18:24:55 UTC (rev 7957) +++ trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/X10CPPTranslator.java 2009-03-16 18:48:09 UTC (rev 7958) @@ -542,6 +542,9 @@ assert (PLATFORM.startsWith("win32_")); } + /** Disable for now. TODO: enable */ + protected boolean gcEnabled() { return false; } + protected void addPreArgs(ArrayList<String> cxxCmd) { super.addPreArgs(cxxCmd); for (int i = 0; i < preArgsCygwin.length; i++) { @@ -603,7 +606,7 @@ /** These go before the files */ public static final String[] preArgsAIX = new String[] { USE_XLC ? DUMMY : "-Wno-long-long", - USE_XLC ? "-qsuppress=1540-0809" : "-Wno-unused-parameter", + USE_XLC ? "-qsuppress=1540-0809:1500-029" : "-Wno-unused-parameter", USE_XLC ? "-q64" : "-maix64", // Assume 64-bit USE_XLC ? "-qrtti=all" : DUMMY, //USE_XLC ? DUMMY : "-pipe", // TODO: is this needed? @@ -611,11 +614,11 @@ /** These go after the files */ public static final String[] postArgsAIX = new String[] { USE_XLC ? "-bbigtoc" : "-Wl,-bbigtoc", - USE_XLC ? DUMMY : "-Wl,-binitfini:poe_remote_main", - USE_XLC ? DUMMY : "-L/usr/lpp/ppe.poe/lib", - USE_XLC ? DUMMY : "-lmpi_r", - USE_XLC ? DUMMY : "-lvtd_r", - USE_XLC ? DUMMY : "-llapi_r", + USE_XLC || !TRANSPORT.equals("lapi") ? DUMMY : "-Wl,-binitfini:poe_remote_main", + USE_XLC || !TRANSPORT.equals("lapi") ? DUMMY : "-L/usr/lpp/ppe.poe/lib", + USE_XLC || !TRANSPORT.equals("lapi") ? DUMMY : "-lmpi_r", + USE_XLC || !TRANSPORT.equals("lapi") ? DUMMY : "-lvtd_r", + USE_XLC || !TRANSPORT.equals("lapi") ? DUMMY : "-llapi_r", }; public AIX_CXXCommandBuilder(Options options) { Modified: trunk/x10.runtime.17/src-cpp/Makefile =================================================================== --- trunk/x10.runtime.17/src-cpp/Makefile 2009-03-16 18:24:55 UTC (rev 7957) +++ trunk/x10.runtime.17/src-cpp/Makefile 2009-03-16 18:48:09 UTC (rev 7958) @@ -39,6 +39,7 @@ override CXXFLAGS += -q64 override CXXFLAGS += -O3 -qinline -qarch=pwr5 -qtune=pwr5 -qhot override CXXFLAGS += -qrtti=all + override CXXFLAGS += -qsuppress=1540-0809:1500-029 else override CXXFLAGS += -maix64 endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ipe...@us...> - 2009-03-16 18:58:14
|
Revision: 7959 http://x10.svn.sourceforge.net/x10/?rev=7959&view=rev Author: ipeshansky Date: 2009-03-16 18:58:11 +0000 (Mon, 16 Mar 2009) Log Message: ----------- Update Eclipse launch configurations Modified Paths: -------------- trunk/x10.cppbackend.17/.launchConfigs/x10cpp.launch trunk/x10.dist/.launchConfigs/x10c.launch Modified: trunk/x10.cppbackend.17/.launchConfigs/x10cpp.launch =================================================================== --- trunk/x10.cppbackend.17/.launchConfigs/x10cpp.launch 2009-03-16 18:48:09 UTC (rev 7958) +++ trunk/x10.cppbackend.17/.launchConfigs/x10cpp.launch 2009-03-16 18:58:11 UTC (rev 7959) @@ -11,7 +11,7 @@ <listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry path="3" projectName="x10.common.17" type="1"/> "/> <listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry path="3" projectName="polyglot3" type="1"/> "/> </listAttribute> -<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-ext x10cpp ${resource_loc} -sourcepath ${project_loc:x10.runtime.17}/src-x10 -noserial -assert -d out -disable CheckNativeAnnotations"/> +<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-ext x10cpp ${resource_loc} -sourcepath ${project_loc:x10.runtime.17}/src-x10 -noserial -assert -d out -disable CheckNativeAnnotations -commandlineonly ${project_loc:x10.tests}/examples/x10lib/harness/x10Test.x10"/> <stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="x10.cppbackend.17"/> <stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-ea"/> <listAttribute key="org.eclipse.debug.ui.favoriteGroups"> Modified: trunk/x10.dist/.launchConfigs/x10c.launch =================================================================== --- trunk/x10.dist/.launchConfigs/x10c.launch 2009-03-16 18:48:09 UTC (rev 7958) +++ trunk/x10.dist/.launchConfigs/x10c.launch 2009-03-16 18:58:11 UTC (rev 7959) @@ -23,7 +23,7 @@ </listAttribute> <booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="false"/> <stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="polyglot.main.Main"/> -<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-ext x10 "${resource_loc}" -sourcepath "${workspace_loc:x10.runtime.17/new}" -sourcepath "${workspace_loc:x10.dist/lib/x10.jar}" -sourcepath "${workspace_loc:x10.tests/examples/x10lib}" -noserial -assert -post "javac -source 1.5""/> +<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-ext x10 "${resource_loc}" -sourcepath "${workspace_loc:x10.runtime.17/src-x10}" -sourcepath "${workspace_loc:x10.dist}/lib/x10.jar" -sourcepath "${workspace_loc:x10.tests}/examples/x10lib" -noserial -assert -post "javac -source 1.5" -d out -disable CheckNativeAnnotations"/> <stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="x10.compiler.p3"/> <stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-ea"/> <stringAttribute key="org.eclipse.jdt.launching.WORKING_DIRECTORY" value="${container_loc}"/> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ipe...@us...> - 2009-03-17 03:46:33
|
Revision: 7969 http://x10.svn.sourceforge.net/x10/?rev=7969&view=rev Author: ipeshansky Date: 2009-03-17 03:46:16 +0000 (Tue, 17 Mar 2009) Log Message: ----------- Fix NPEs in _struct_equals and instanceof Modified Paths: -------------- trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/MessagePassingCodeGenerator.java trunk/x10.runtime.17/src-cpp/x10/io/NativeInputStream.cc trunk/x10.runtime.17/src-cpp/x10/io/NativeOutputStream.cc trunk/x10.runtime.17/src-cpp/x10/lang/String.cc trunk/x10.runtime.17/src-cpp/x10/lang/Throwable.cc trunk/x10.runtime.17/src-cpp/x10/lang/ValRail.h trunk/x10.runtime.17/src-cpp/x10aux/RTT.cc Modified: trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/MessagePassingCodeGenerator.java =================================================================== --- trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/MessagePassingCodeGenerator.java 2009-03-17 03:43:09 UTC (rev 7968) +++ trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/MessagePassingCodeGenerator.java 2009-03-17 03:46:16 UTC (rev 7969) @@ -1151,7 +1151,7 @@ emitter.printType(xts.Object(), sw); sw.write(" p0"); sw.write(") {"); sw.newline(4); sw.begin(0); - sw.write("if (p0.operator->() == this) return true; // short-circuit trivial equality"); + sw.write("if (p0.get() == this) return true; // short-circuit trivial equality"); sw.newline(); sw.write("if (!this->" + emitter.translateType(superClass) + "::" + mangled_method_name(STRUCT_EQUALS_METHOD) + "(p0))"); Modified: trunk/x10.runtime.17/src-cpp/x10/io/NativeInputStream.cc =================================================================== --- trunk/x10.runtime.17/src-cpp/x10/io/NativeInputStream.cc 2009-03-17 03:43:09 UTC (rev 7968) +++ trunk/x10.runtime.17/src-cpp/x10/io/NativeInputStream.cc 2009-03-17 03:46:16 UTC (rev 7969) @@ -23,7 +23,7 @@ } x10_boolean NativeInputStream::_struct_equals(ref<Object> p0) { - if (p0.operator->() == this) return true; // short-circuit trivial equality + if (p0.get() == this) return true; // short-circuit trivial equality if (!this->Value::_struct_equals(p0)) return false; // ref<NativeInputStream> that = (ref<NativeInputStream>) p0; Modified: trunk/x10.runtime.17/src-cpp/x10/io/NativeOutputStream.cc =================================================================== --- trunk/x10.runtime.17/src-cpp/x10/io/NativeOutputStream.cc 2009-03-17 03:43:09 UTC (rev 7968) +++ trunk/x10.runtime.17/src-cpp/x10/io/NativeOutputStream.cc 2009-03-17 03:46:16 UTC (rev 7969) @@ -32,7 +32,7 @@ } x10_boolean NativeOutputStream::_struct_equals(ref<Object> p0) { - if (p0.operator->() == this) return true; // short-circuit trivial equality + if (p0.get() == this) return true; // short-circuit trivial equality if (!this->Value::_struct_equals(p0)) return false; // ref<NativeOutputStream> that = (ref<NativeOutputStream>) p0; Modified: trunk/x10.runtime.17/src-cpp/x10/lang/String.cc =================================================================== --- trunk/x10.runtime.17/src-cpp/x10/lang/String.cc 2009-03-17 03:43:09 UTC (rev 7968) +++ trunk/x10.runtime.17/src-cpp/x10/lang/String.cc 2009-03-17 03:46:16 UTC (rev 7969) @@ -171,7 +171,7 @@ } x10_boolean String::_struct_equals(ref<Object> p0) { - if (p0.operator->() == this) return true; // short-circuit trivial equality + if (p0.get() == this) return true; // short-circuit trivial equality if (!this->Value::_struct_equals(p0)) return false; ref<String> that = (ref<String>) p0; Modified: trunk/x10.runtime.17/src-cpp/x10/lang/Throwable.cc =================================================================== --- trunk/x10.runtime.17/src-cpp/x10/lang/Throwable.cc 2009-03-17 03:43:09 UTC (rev 7968) +++ trunk/x10.runtime.17/src-cpp/x10/lang/Throwable.cc 2009-03-17 03:46:16 UTC (rev 7969) @@ -257,7 +257,7 @@ } x10_boolean Throwable::_struct_equals(ref<Object> p0) { - if (p0.operator->() == this) return true; // short-circuit trivial equality + if (p0.get() == this) return true; // short-circuit trivial equality if (!this->Value::_struct_equals(p0)) return false; ref<Throwable> that = (ref<Throwable>) p0; Modified: trunk/x10.runtime.17/src-cpp/x10/lang/ValRail.h =================================================================== --- trunk/x10.runtime.17/src-cpp/x10/lang/ValRail.h 2009-03-17 03:43:09 UTC (rev 7968) +++ trunk/x10.runtime.17/src-cpp/x10/lang/ValRail.h 2009-03-17 03:46:16 UTC (rev 7969) @@ -20,7 +20,8 @@ template<class T> class ValRail : public Value, public virtual Fun_0_1<x10_int,T>, - public x10aux::AnyRail<T> { + public x10aux::AnyRail<T> + { public: @@ -125,7 +126,7 @@ } virtual x10_boolean _struct_equals(x10aux::ref<Object> other) { - if (other.operator->() == this) return true; // short-circuit trivial equality + if (other.get() == this) return true; // short-circuit trivial equality if (!this->Value::_struct_equals(other)) return false; x10aux::ref<ValRail> other_rail = other; // different sizes so false Modified: trunk/x10.runtime.17/src-cpp/x10aux/RTT.cc =================================================================== --- trunk/x10.runtime.17/src-cpp/x10aux/RTT.cc 2009-03-17 03:43:09 UTC (rev 7968) +++ trunk/x10.runtime.17/src-cpp/x10aux/RTT.cc 2009-03-17 03:46:16 UTC (rev 7969) @@ -10,10 +10,14 @@ using namespace x10::lang; bool x10aux::RuntimeType::instanceOf (const ref<Object> &other) const { + if (other.isNull()) + return false; return other->_type()->subtypeOf(this); } bool x10aux::RuntimeType::concreteInstanceOf (const ref<Object> &other) const { + if (other.isNull()) + return false; return other->_type()->equals(this); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ipe...@us...> - 2009-03-18 03:52:32
|
Revision: 7989 http://x10.svn.sourceforge.net/x10/?rev=7989&view=rev Author: ipeshansky Date: 2009-03-18 03:52:27 +0000 (Wed, 18 Mar 2009) Log Message: ----------- Make -PRELOAD_CLASSES work again in the Java backend Modified Paths: -------------- trunk/x10.compiler.p3/data/Main.xcd trunk/x10.runtime.17/src-java/x10/runtime/impl/java/Runtime.java Modified: trunk/x10.compiler.p3/data/Main.xcd =================================================================== --- trunk/x10.compiler.p3/data/Main.xcd 2009-03-18 03:27:04 UTC (rev 7988) +++ trunk/x10.compiler.p3/data/Main.xcd 2009-03-18 03:52:27 UTC (rev 7989) @@ -15,6 +15,11 @@ // body of main activity new x10.core.fun.VoidFun_0_0() { public void apply() { + // preload classes + if (Boolean.getBoolean("x10.PRELOAD_CLASSES")) { + x10.runtime.impl.java.PreLoader.preLoad(this.getClass().getEnclosingClass(), Boolean.getBoolean("x10.PRELOAD_STRINGS")); + } + // catch and rethrow checked exceptions // (closures cannot throw checked exceptions) try { Modified: trunk/x10.runtime.17/src-java/x10/runtime/impl/java/Runtime.java =================================================================== --- trunk/x10.runtime.17/src-java/x10/runtime/impl/java/Runtime.java 2009-03-18 03:27:04 UTC (rev 7988) +++ trunk/x10.runtime.17/src-java/x10/runtime/impl/java/Runtime.java 2009-03-18 03:52:27 UTC (rev 7989) @@ -40,10 +40,7 @@ * Body of main x10 thread */ public void run() { - // preload classes - if (Boolean.getBoolean("x10.PRELOAD_CLASSES")) { - PreLoader.preLoad(this.getClass().getEnclosingClass(), Boolean.getBoolean("x10.PRELOAD_STRINGS")); - } + try { Class.forName("x10.lang.Place"); } catch (ClassNotFoundException e) { } // execute root x10 activity main(x10.core.RailFactory.<java.lang.String>makeRailFromJavaArray(args)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ipe...@us...> - 2009-03-22 05:07:29
|
Revision: 8041 http://x10.svn.sourceforge.net/x10/?rev=8041&view=rev Author: ipeshansky Date: 2009-03-22 05:07:26 +0000 (Sun, 22 Mar 2009) Log Message: ----------- Fix XTENLANG-358. Remove references to package-private classes from Dummy.x10 Modified Paths: -------------- trunk/x10.compiler.p3/src/polyglot/ext/x10/ast/X10CanonicalTypeNode_c.java trunk/x10.runtime.17/src-x10/Dummy.x10 Modified: trunk/x10.compiler.p3/src/polyglot/ext/x10/ast/X10CanonicalTypeNode_c.java =================================================================== --- trunk/x10.compiler.p3/src/polyglot/ext/x10/ast/X10CanonicalTypeNode_c.java 2009-03-22 03:59:27 UTC (rev 8040) +++ trunk/x10.compiler.p3/src/polyglot/ext/x10/ast/X10CanonicalTypeNode_c.java 2009-03-22 05:07:26 UTC (rev 8041) @@ -82,25 +82,25 @@ checkType(t); List<AnnotationNode> as = ((X10Del) this.del()).annotations(); - if (as == null || as.isEmpty()) - return this; + if (as != null && !as.isEmpty()) { - // Eh. Why not? -// if (c.inAnnotation()) { -// throw new SemanticException("Annotations not permitted within annotations.", position()); -// } + // Eh. Why not? +// if (c.inAnnotation()) { +// throw new SemanticException("Annotations not permitted within annotations.", position()); +// } - List<Type> annotationTypes = new ArrayList<Type>(); - for (AnnotationNode an : as) { + List<Type> annotationTypes = new ArrayList<Type>(); + for (AnnotationNode an : as) { Type at = an.annotationInterface(); - annotationTypes.add(at); + annotationTypes.add(at); + } + + Type newType = ts.AnnotatedType(position(), t, annotationTypes); + Ref<Type> tref = (Ref<Type>) type; + tref.update(newType); } - - Type newType = ts.AnnotatedType(position(), t, annotationTypes); - Ref<Type> tref = (Ref<Type>) type; - tref.update(newType); - - return this; + + return super.typeCheck(tc); } @Override Modified: trunk/x10.runtime.17/src-x10/Dummy.x10 =================================================================== --- trunk/x10.runtime.17/src-x10/Dummy.x10 2009-03-22 03:59:27 UTC (rev 8040) +++ trunk/x10.runtime.17/src-x10/Dummy.x10 2009-03-22 05:07:26 UTC (rev 8041) @@ -7,26 +7,15 @@ var f0 : x10.array.BaseArray[Dummy]; var f1 : x10.array.BaseDist; var f2 : x10.array.BaseRegion; - var f3 : x10.array.DistArray[Dummy]; - var f4 : x10.array.EmptyRegion; - var f5 : x10.array.FullRegion; - var f9 : x10.array.Layout; - var f10 : x10.array.LocalArray[Dummy]; var f11 : x10.array.NoSuchElementException; - var f12 : x10.array.PlaceLocal[Dummy]; var f13 : x10.array.PolyRegion; - var f14 : x10.array.PolyRegionListBuilder; var f15 : x10.array.PolyScanner; - var f16 : x10.array.RectLayout; - var f17 : x10.array.RectRegion; var f18 : x10.array.U; var f19 : x10.array.UnboundedRegionException; - var f20 : x10.array.UnionRegion; var f21 : x10.compiler.ArithmeticOps[Dummy]; var f22 : x10.compiler.ComparisonOps[Dummy]; var f23 : x10.compiler.Native; var f24 : x10.compiler.NativeRep; - var f25 : x10.compiler.Ops[Dummy,Dummy]; var f26 : x10.compiler.SetOps[Dummy]; var f27 : x10.io.ByteRailWriter; var f28 : x10.io.ByteValRailWriter; @@ -40,7 +29,6 @@ var f36 : x10.io.FileWriter; var f37 : x10.io.FilterReader; var f38 : x10.io.FilterWriter; - var f39 : x10.io.InputStreamReader; var f40 : x10.io.IOException; var f41 : x10.io.IORuntimeException; var f42 : x10.io.Marshal[Dummy]; @@ -111,22 +99,13 @@ var f107 : x10.lang.ValRail[Dummy]; var f108 : x10.lang.Value; var f109 : x10.lang._; - var f110 : x10.runtime.Activity; - var f111 : x10.runtime.ClockPhases; - var f112 : x10.runtime.ClockState; var f113 : x10.runtime.Clock_c; - var f114 : x10.runtime.FinishState; var f115 : x10.runtime.Future_c[Dummy]; var f117 : x10.runtime.InterruptedException; var f118 : x10.runtime.Lock; - var f119 : x10.runtime.ModCountDownLatch; - var f120 : x10.runtime.Monitor; var f121 : x10.runtime.NativeRuntime; - var f122 : x10.runtime.Pool; var f123 : x10.runtime.Runtime; var f128 : x10.runtime.Thread; - var f129 : x10.tuningfork.Logger; - var f130 : x10.tuningfork.LoggerFactory; var f135 : x10.util.AbstractCollection[Dummy]; var f136 : x10.util.AbstractContainer[Dummy]; var f137 : x10.util.ArrayList[Dummy]; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ipe...@us...> - 2009-03-24 03:34:29
|
Revision: 8113 http://x10.svn.sourceforge.net/x10/?rev=8113&view=rev Author: ipeshansky Date: 2009-03-24 03:34:21 +0000 (Tue, 24 Mar 2009) Log Message: ----------- Add support for compiling with ECJ Add build-xrx target to pre-build XRX in Java (fixes XTENLANG-357) Factor out number of available processors Split clean into clean-java and clean-cpp Reindent Modified Paths: -------------- trunk/x10.runtime.17/build.xml Added Paths: ----------- trunk/x10.common.17/contrib/ant/ trunk/x10.common.17/contrib/ant/Ejc.java Added: trunk/x10.common.17/contrib/ant/Ejc.java =================================================================== --- trunk/x10.common.17/contrib/ant/Ejc.java (rev 0) +++ trunk/x10.common.17/contrib/ant/Ejc.java 2009-03-24 03:34:21 UTC (rev 8113) @@ -0,0 +1,136 @@ +import java.io.File; +import java.io.IOException; +import java.util.Iterator; +import java.util.List; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.taskdefs.Javac; +import org.apache.tools.ant.taskdefs.compilers.CompilerAdapter; +public class Ejc extends Javac { + public static final String EJC_COMPILER = "org.eclipse.jdt.core.JDTCompilerAdapter"; + public Ejc() { + super(); + //System.err.println("Creating ejc task: "+getClass().getClassLoader().getResource(EJC_COMPILER.replaceAll(".","/")+".class")); + //try { + // System.err.println("Creating ejc task: "+getClass().forName(EJC_COMPILER)); + //} catch (ClassNotFoundException e) { } + } + public String getCompiler() { return EJC_COMPILER; } + // Ugly ugly hack: because ant is broken, replicate the contents of Javac.compile() + protected void compile() { + //try { + // System.err.println("Compiling: "+Class.forName(EJC_COMPILER)); + //} catch (ClassNotFoundException e) { + // System.err.println(EJC_COMPILER+" not found"); + //} + String compilerImpl = getCompiler(); + + if (compileList.length > 0) { + log("Compiling " + compileList.length + " source file" + + (compileList.length == 1 ? "" : "s") + + (getDestdir() != null ? " to " + getDestdir() : "")); + + if (listFiles) { + for (int i = 0; i < compileList.length; i++) { + String filename = compileList[i].getAbsolutePath(); + log(filename); + } + } + + CompilerAdapter adapter = null; + try { + adapter = (CompilerAdapter) getClass().forName(compilerImpl).newInstance(); + } catch (ClassNotFoundException e) { + System.err.println(EJC_COMPILER+" not found"); + throw new BuildException(e, getLocation()); + } catch (IllegalAccessException e) { + } catch (InstantiationException e) { + } + + // now we need to populate the compiler adapter + adapter.setJavac(this); + + // finally, lets execute the compiler!! + if (adapter.execute()) { + //FROM: ANT_17_BRANCH + // Success - check + List updateDirList = getUpdateDirList(); + if (updateDirList != null) { + for (Iterator i = updateDirList.iterator(); i.hasNext();) { + File file = (File) i.next(); + file.setLastModified(System.currentTimeMillis()); + } + } + //FROM: HEAD + // Success + try { + invokeGenerateMissingPackageInfoClasses(); + } catch (IOException x) { + // Should this be made a nonfatal warning? + throw new BuildException(x, getLocation()); + } + } else { + //FROM: ANT_17_BRANCH + // Fail path + setTaskSuccess(false); + String errorProperty = getErrorProperty(); + if (errorProperty != null) { + getProject().setNewProperty( + errorProperty, "true"); + } + if (failOnError) { + throw new BuildException(FAIL_MSG, getLocation()); + } else { + log(FAIL_MSG, Project.MSG_ERR); + } + } + } + } + // More stupidity: because errorProperty is private and not gettable, must use reflection + public String getErrorProperty() { + try { + java.lang.reflect.Field eP = getClass().getSuperclass().getDeclaredField("errorProperty"); + eP.setAccessible(true); + return (String) eP.get(this); + } catch (IllegalAccessException e) { + } catch (NoSuchFieldException e) { } + return null; + } + // Ditto for updateDirList + public List getUpdateDirList() { + try { + java.lang.reflect.Field uDL = getClass().getSuperclass().getDeclaredField("updateDirList"); + uDL.setAccessible(true); + return (List) uDL.get(this); + } catch (IllegalAccessException e) { + } catch (NoSuchFieldException e) { } + return null; + } + // Even more stupidity: because errorProperty is private and not settable, must use reflection + public void setTaskSuccess(boolean value) { + try { + java.lang.reflect.Field tS = getClass().getSuperclass().getDeclaredField("taskSuccess"); + tS.setAccessible(true); + tS.setBoolean(this, value); + } catch (IllegalAccessException e) { + } catch (NoSuchFieldException e) { } + } + // Finally: because generateMissingPackageInfoClasses is private, must use reflection + public void invokeGenerateMissingPackageInfoClasses() throws IOException { + try { + java.lang.reflect.Method gMPIC = getClass().getSuperclass().getDeclaredMethod("generateMissingPackageInfoClasses"); + gMPIC.setAccessible(true); + gMPIC.invoke(this, new Object[]{}); + } catch (java.lang.reflect.InvocationTargetException e) { + Throwable c = e.getCause(); + if (c instanceof IOException) throw (IOException)c; + else if (c instanceof RuntimeException) throw (RuntimeException)c; + else if (c instanceof Error) throw (Error)c; + else throw new Error(c); + } catch (IllegalAccessException e) { + } catch (NoSuchMethodException e) { } + } + // For the same reasons, need to replicate FAIL_MSG + protected static final String FAIL_MSG = + "Compile failed; see the compiler error output for details."; +} Modified: trunk/x10.runtime.17/build.xml =================================================================== --- trunk/x10.runtime.17/build.xml 2009-03-24 03:19:07 UTC (rev 8112) +++ trunk/x10.runtime.17/build.xml 2009-03-24 03:34:21 UTC (rev 8113) @@ -13,7 +13,7 @@ <property name="jar" value="x10.jar"/> <property name="bdwgc.dir" location="${basedir}/src-cpp/bdwgc"/> <property name="make.exe" value="make"/> - <property name="cvs.exe" value="cvs"/> + <property name="bash.exe" value="bash"/> <path id="project.classpath"> <path refid="mainproject.classpath"/> <path refid="x10.constraints.classpath"/> @@ -31,27 +31,55 @@ <!-- get the environment variables --> <property environment="env"/> + <!-- set up to use ECJ --> + <property name="ejc.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/> + <property name="ejc.classpath" location="${lib}/ecj.jar"/> + + <target name="init"> + <mkdir dir="${build}"/> + <javac destdir="${build}" source="1.5" target="1.5" debug="on" nowarn="on"> + <src path="${x10.common.location}/contrib/ant"/> + <include name="Ejc.java"/> + <classpath> + <path refid="project.classpath"/> + </classpath> + </javac> + <!-- Allow using the Eclipse compiler --> + <taskdef name="ejc" classname="Ejc"> + <classpath> + <pathelement location="${ejc.classpath}"/> + <pathelement location="${build}"/> + </classpath> + </taskdef> + <!-- use ECJ instead of javac (needs ecj.jar on the classpath) --> + <!--<property name="build.compiler" value="${ejc.compiler}"/>--> + </target> + <!-- Determine whether or not we should be building with GC enabled --> <condition property="bdwgc.enabled"> <!--<os family="unix" name="linux"/>--> <istrue value="false"/> </condition> <condition property="cppmake.gcarg" value="ENABLE_GC=1" else="DISABLE_GC=1"> - <isset property="bdwgc.enabled" /> + <isset property="bdwgc.enabled" /> </condition> + <target name="available-procs" unless="available.procs"> + <property name="available.procs" value="2"/> + </target> - <target name="init"> - <mkdir dir="${build}"/> - </target> - <target name="clean"> + <target name="clean" depends="clean-java,clean-cpp"/> + <target name="clean-java"> <delete dir="${build}"/> - <exec executable="${make.exe}" failonerror="true" dir ="${basedir}/src-cpp"> - <arg value="clean"/> - </exec> </target> + <target name="clean-cpp" depends="available-procs"> + <exec executable="${make.exe}" failonerror="true" dir="${basedir}/src-cpp"> + <arg value="-j${available.procs}" /> + <arg value="clean"/> + </exec> + </target> <target name="clean-bdwgc" depends="clean"> <delete dir="${bdwgc.dir}/install"/> - <exec executable="${make.exe}" failonerror="true" dir ="${bdwgc.dir}/src"> + <exec executable="${make.exe}" failonerror="true" dir="${bdwgc.dir}/src"> <arg value="distclean"/> </exec> </target> @@ -61,53 +89,102 @@ <fileset dir="${build}" includes="${jar}"/> </copy> </target> - <target name="dist-cpp" depends="build-cpp"> - <exec executable="${make.exe}" failonerror="true" dir ="${basedir}/src-cpp"> - <arg value="-j2" /> - <arg value="install" /> - <arg value="${cppmake.gcarg}" /> - </exec> + <target name="dist-cpp" depends="build-cpp,available-procs"> + <exec executable="${make.exe}" failonerror="true" dir="${basedir}/src-cpp"> + <arg value="-j${available.procs}" /> + <arg value="install" /> + <arg value="${cppmake.gcarg}" /> + </exec> </target> <target name="dist" depends="dist-java,dist-cpp" description="generate part of the distribution"> </target> - <target name="jar" depends="build-java"> + <target name="jar" depends="build-java,build-xrx"> <jar jarfile="${build}/${jar}"> <fileset dir="${build}" includes="x10/**/*.class" excludes="${jar}"/> + <fileset dir="${build}/gen" includes="x10/**/*.class" excludes="${jar}"/> <fileset dir="${basedir}/src-x10" includes="x10/**" excludes="${jar}"/> <fileset dir="${x10.constraints.location}/classes" includes="x10/constraint/**" excludes="x10/constraint/test/**"/> <fileset dir="${x10.common.location}/classes" includes="x10/**"/> </jar> </target> <target name="build-java" depends="init"> - <javac destdir="${build}" source="1.5" target="1.5" debug="on"> + <ejc destdir="${build}" source="1.5" target="1.5" debug="on" nowarn="on"> <src path="${src}"/> <classpath> <path refid="project.classpath"/> </classpath> + </ejc> + </target> + <target name="gen-xrx" depends="init"> + <echo message="Building Java sources for XRX"/> + <fileset id="xrx.files" dir="${basedir}/src-x10" includes="**/*.x10"/> + <pathconvert property="xrx.list" refid="xrx.files" dirsep="/" pathsep=" "> + <map from="${basedir}${file.separator}src-x10${file.separator}" to=""/> + </pathconvert> + <echo message="x10c -c ${xrx.list}"/> + <exec executable="${bash.exe}" failonerror="true" dir="${basedir}/src-x10"> + <arg value="-c" /> + <arg value="'${x10.dist.location}/bin/x10c' -d '${build}/gen' -J-ea -rtdev -sourcepath . -disable CheckNativeAnnotations -commandlineonly -c ${xrx.list}" /> + </exec> + </target> + <target name="build-xrx" depends="init,build-java,gen-xrx"> + <!-- + <fileset id="generated.files" dir="${build}/gen" includes="**/*.java"/> + <pathconvert property="generated.list" refid="generated.files" dirsep="/" pathsep=" "/> + <java jar="${lib}/ecj.jar" fork="true" dir="${build}/gen" failonerror="true"> + <arg value="-1.5"/> + <arg value="-nowarn"/> + <arg line="-classpath .${path.separator}.."/> + <arg line="${generated.list}"/> + </java> + --> + <!-- + <javac destdir="${build}/gen" compiler="${ejc.compiler}" source="1.5" target="1.5" debug="on" nowarn="on"> + <src path="${build}/gen"/> + <classpath> + <path refid="project.classpath"/> + <path> + <pathelement location="${build}/gen"/> + <pathelement location="${build}"/> + </path> + </classpath> </javac> + --> + <ejc destdir="${build}/gen" source="1.5" target="1.5" debug="on" nowarn="on"> + <src path="${build}/gen"/> + <classpath> + <path refid="project.classpath"/> + <path> + <pathelement location="${build}/gen"/> + <pathelement location="${build}"/> + </path> + </classpath> + </ejc> </target> - <target name="build-cpp" depends="init,dist-bdwgc"> - <exec executable="${make.exe}" failonerror="true" dir ="${basedir}/src-cpp"> - <arg value="-j2" /> - <arg value="${cppmake.gcarg}" /> - </exec> + <target name="build-cpp" depends="init,dist-bdwgc,available-procs"> + <exec executable="${make.exe}" failonerror="true" dir="${basedir}/src-cpp"> + <arg value="-j${available.procs}" /> + <arg value="${cppmake.gcarg}" /> + </exec> </target> <target name="build" depends="build-java,build-cpp"> <echo message="${ant.project.name}: ${ant.file}"/> </target> - <target name="build-bdwgc" depends="check-bdwgc,download-bdwgc" unless="bdwgc.skip.build"> + <target name="build-bdwgc" depends="check-bdwgc,download-bdwgc,available-procs" unless="bdwgc.skip.build"> <sequential> - <exec executable="${bdwgc.dir}/src/configure" dir="${bdwgc.dir}/src" failonerror="true"> - <arg value="-enable-threads=posix" /> - <arg value="--prefix=${bdwgc.dir}/install" /> - </exec> - <exec executable="${make.exe}" dir="${bdwgc.dir}/src" failonerror="true"></exec> - <exec executable="${make.exe}" dir="${bdwgc.dir}/src" failonerror="true"> - <arg value="install" /> - </exec> + <exec executable="${bdwgc.dir}/src/configure" dir="${bdwgc.dir}/src" failonerror="true"> + <arg value="-enable-threads=posix" /> + <arg value="--prefix=${bdwgc.dir}/install" /> + </exec> + <exec executable="${make.exe}" dir="${bdwgc.dir}/src" failonerror="true"> + <arg value="-j${available.procs}" /> + </exec> + <exec executable="${make.exe}" dir="${bdwgc.dir}/src" failonerror="true"> + <arg value="install" /> + </exec> </sequential> </target> @@ -123,30 +200,30 @@ <target name="download-bdwgc" depends="check-bdwgc" unless="bdwgc.skip.download"> <sequential> - <cvs cvsRoot=":pserver:ano...@bd...:/cvsroot/bdwgc" - package="bdwgc" + <cvs cvsRoot=":pserver:ano...@bd...:/cvsroot/bdwgc" + package="bdwgc" tag="gc7_1" dest="${bdwgc.dir}" - failonerror="true" - /> - <move file="${bdwgc.dir}/bdwgc" tofile="${bdwgc.dir}/src" /> + failonerror="true" + /> + <move file="${bdwgc.dir}/bdwgc" tofile="${bdwgc.dir}/src" /> </sequential> - + </target> <target name="check-bdwgc"> <sequential> <condition property="bdwgc.skip.download"> - <or> - <available file="${bdwgc.dir}/src/configure" property="bdwgc.available"/> - <isfalse value="${bdwgc.enabled}" /> - </or> + <or> + <available file="${bdwgc.dir}/src/configure" property="bdwgc.available"/> + <isfalse value="${bdwgc.enabled}" /> + </or> </condition> <condition property="bdwgc.skip.build"> - <or> - <available file="${bdwgc.dir}/install/lib/libgc.so" property="bdwgc.built"/> - <isfalse value="${bdwgc.enabled}" /> - </or> + <or> + <available file="${bdwgc.dir}/install/lib/libgc.so" property="bdwgc.built"/> + <isfalse value="${bdwgc.enabled}" /> + </or> </condition> </sequential> </target> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ipe...@us...> - 2009-03-25 12:04:47
|
Revision: 8172 http://x10.svn.sourceforge.net/x10/?rev=8172&view=rev Author: ipeshansky Date: 2009-03-25 12:04:45 +0000 (Wed, 25 Mar 2009) Log Message: ----------- Fix build order Modified Paths: -------------- trunk/x10.compiler.p3/build.xml trunk/x10.dist/build.xml Modified: trunk/x10.compiler.p3/build.xml =================================================================== --- trunk/x10.compiler.p3/build.xml 2009-03-24 20:12:28 UTC (rev 8171) +++ trunk/x10.compiler.p3/build.xml 2009-03-25 12:04:45 UTC (rev 8172) @@ -72,10 +72,6 @@ </jar> </target> <target name="prereq-jars"> - <condition property="runtime.jar.present"> - <available file="${lib}/${runtime.jar}"/> - </condition> - <fail message="Unable to find required file ${lib}/${runtime.jar}" unless="runtime.jar.present"/> <condition property="polyglot.jar.present"> <available file="${lib}/${polyglot.jar}"/> </condition> Modified: trunk/x10.dist/build.xml =================================================================== --- trunk/x10.dist/build.xml 2009-03-24 20:12:28 UTC (rev 8171) +++ trunk/x10.dist/build.xml 2009-03-25 12:04:45 UTC (rev 8172) @@ -75,7 +75,7 @@ <ant antfile="${x10.cppbackend.location}/build.xml" target="clean" inheritAll="false" dir="${x10.cppbackend.location}"/> </target> - <target name="dist-java" depends="init,build,common-jar,constraints-jar,runtime-java,compiler-jar"/> + <target name="dist-java" depends="init,build,common-jar,constraints-jar,compiler-jar,runtime-java"/> <target name="dist-cpp" depends="dist-java,cppbackend-jar,runtime-cpp"/> <target name="dist" depends="dist-java,dist-cpp"/> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ipe...@us...> - 2009-03-31 16:34:29
|
Revision: 8181 http://x10.svn.sourceforge.net/x10/?rev=8181&view=rev Author: ipeshansky Date: 2009-03-31 16:34:25 +0000 (Tue, 31 Mar 2009) Log Message: ----------- Add support for adding extra flags to xlC (to try hotfixes). Use the system "ar" instead of the whichever one happens to be on the PATH. Modified Paths: -------------- trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/X10CPPTranslator.java trunk/x10.runtime.17/src-cpp/Makefile Modified: trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/X10CPPTranslator.java =================================================================== --- trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/X10CPPTranslator.java 2009-03-30 16:15:48 UTC (rev 8180) +++ trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/X10CPPTranslator.java 2009-03-31 16:34:25 UTC (rev 8181) @@ -603,6 +603,7 @@ public static final boolean USE_XLC = System.getenv("USE_XLC")!=null; //"mpCC_r -q64 -qrtti=all -qarch=pwr5 -O3 -qtune=pwr5 -qhot -qinline" //"mpCC_r -q64 -qrtti=all" + public static final String XLC_EXTRA_FLAGS = System.getenv("XLC_EXTRA_FLAGS"); /** These go before the files */ public static final String[] preArgsAIX = new String[] { USE_XLC ? DUMMY : "-Wno-long-long", @@ -610,6 +611,7 @@ USE_XLC ? "-q64" : "-maix64", // Assume 64-bit USE_XLC ? "-qrtti=all" : DUMMY, //USE_XLC ? DUMMY : "-pipe", // TODO: is this needed? + USE_XLC && XLC_EXTRA_FLAGS!=null ? XLC_EXTRA_FLAGS : DUMMY, }; /** These go after the files */ public static final String[] postArgsAIX = new String[] { Modified: trunk/x10.runtime.17/src-cpp/Makefile =================================================================== --- trunk/x10.runtime.17/src-cpp/Makefile 2009-03-30 16:15:48 UTC (rev 8180) +++ trunk/x10.runtime.17/src-cpp/Makefile 2009-03-31 16:34:25 UTC (rev 8181) @@ -40,6 +40,10 @@ override CXXFLAGS += -O3 -qinline -qarch=pwr5 -qtune=pwr5 -qhot override CXXFLAGS += -qrtti=all override CXXFLAGS += -qsuppress=1540-0809:1500-029 + override CXXFLAGS += $(XLC_EXTRA_FLAGS) + ifeq ($(AR),ar) # use AIX default ar + AR = /usr/bin/ar + endif else override CXXFLAGS += -maix64 endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dgr...@us...> - 2009-04-13 21:59:31
|
Revision: 8210 http://x10.svn.sourceforge.net/x10/?rev=8210&view=rev Author: dgrove-oss Date: 2009-04-13 21:59:19 +0000 (Mon, 13 Apr 2009) Log Message: ----------- XTENLANG-360 Basic support for -O option to x10c/x10c++ Add support for a -O (-optimize) command line argument to x10c/x10c++ that can be used as a master switch to disable/enable other compiler flags. Currently -O simple disables place checks and causes the C++ backend's postcompiler to be invoked with -O2 -finline-functions. Add plumbing to build.xml so that if ant is invoked with -Doptimize=true, then children x10c/x10c++ will be invoked with -O and furthermore than c++ compilation of x10.runtime.17/src-cpp will be done with optimization as well. No attempt to simultaneously build optimized/unoptimized versions of XRX and have x10/x10c/x10c++ find the appropriate pre-built version of XRX based on whether or not it was invoked with -O. Leaving that as a future packaging work item to be addressed in a different issue. Modified Paths: -------------- trunk/x10.compiler.p3/src/polyglot/ext/x10/Configuration.java trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/Configuration.java trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/X10CPPTranslator.java trunk/x10.dist/bin/x10c.in trunk/x10.runtime.17/build.xml trunk/x10.runtime.17/src-cpp/Makefile Modified: trunk/x10.compiler.p3/src/polyglot/ext/x10/Configuration.java =================================================================== --- trunk/x10.compiler.p3/src/polyglot/ext/x10/Configuration.java 2009-04-13 04:37:41 UTC (rev 8209) +++ trunk/x10.compiler.p3/src/polyglot/ext/x10/Configuration.java 2009-04-13 21:59:19 UTC (rev 8210) @@ -23,7 +23,7 @@ * * @author Christian Grothoff * @author Igor Peshansky - * + * * @author barikr: added LOOP_OPTIMIZATIONS 26th Aug 2006 */ public final class Configuration extends x10.config.Configuration { @@ -41,6 +41,9 @@ public static boolean BAD_PLACE_RUNTIME_CHECK = true; private static final String BAD_PLACE_RUNTIME_CHECK_desc = "Generate runtime place checks"; + public static boolean OPTIMIZE = false; + private static final String OPTIMIZE_desc = "Generate optimized code"; + public static boolean LOOP_OPTIMIZATIONS = true; private static final String LOOP_OPTIMIZATIONS_desc = "Generate specialized Java version of for-loop X10 code"; @@ -52,7 +55,7 @@ public static String PLUGINS = ""; private static final String PLUGINS_desc = "Comma-separated list of compiler plugins to run."; - + public static String PLUGIN_COMPILER = ""; private static final String PLUGIN_COMPILER_desc = "Javac-like compiler to use to compile plugins"; Modified: trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/Configuration.java =================================================================== --- trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/Configuration.java 2009-04-13 04:37:41 UTC (rev 8209) +++ trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/Configuration.java 2009-04-13 21:59:19 UTC (rev 8210) @@ -41,6 +41,9 @@ public static boolean DISABLE_GC = false; private static final String DISABLE_GC_desc = "Disable the linking in of the BDW conservative garbage collector"; + public static boolean OPTIMIZE = true; + private static final String OPTIMIZE_desc = "Generate optimized code"; + public static String MANIFEST = null; private static final String MANIFEST_desc = "The path to the pre-built library manifest file"; Modified: trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/X10CPPTranslator.java =================================================================== --- trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/X10CPPTranslator.java 2009-04-13 04:37:41 UTC (rev 8209) +++ trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/X10CPPTranslator.java 2009-04-13 21:59:19 UTC (rev 8210) @@ -182,7 +182,7 @@ } public File integratedOutputFile(String packageName, String className, Source source, String ext) { - File outputFile = new File(outputDirectory, + File outputFile = new File(outputDirectory, integratedOutputName(packageName, className, ext)); if (source != null && outputFile.getPath().equals(source.path())) @@ -292,7 +292,7 @@ opfPath = tf.outputName(pkg, decl.name().toString()); assert (!opfPath.endsWith("$")); if (!opfPath.endsWith("$")) outputFiles.add(opfPath); - translateTopLevelDecl(sw, sfn, decl); + translateTopLevelDecl(sw, sfn, decl); if (i.hasNext()) wstreams.commitStreams(); } @@ -400,6 +400,12 @@ X10GC+"/lib/libgc.a", }; + /** These go before the files if optimize is true */ + public static final String[] preArgsOptimize = new String[] { + "-O2", + "-finline-functions", + }; + private final X10CPPCompilerOptions options; public CXXCommandBuilder(Options options) { @@ -423,6 +429,11 @@ cxxCmd.add(preArgsGC[i]); } } + if (Configuration.OPTIMIZE) { + for (String arg : preArgsOptimize) { + cxxCmd.add(arg); + } + } } /** Add the arguments that go after the output files */ Modified: trunk/x10.dist/bin/x10c.in =================================================================== --- trunk/x10.dist/bin/x10c.in 2009-04-13 04:37:41 UTC (rev 8209) +++ trunk/x10.dist/bin/x10c.in 2009-04-13 21:59:19 UTC (rev 8210) @@ -7,6 +7,7 @@ rtdev="" java_args="" args="" +optimize="" parse=true while [ -n "$1" ]; do @@ -24,6 +25,7 @@ -config) shift; config="$1.cfg";; -ext) shift; ext=$1;; -dev) dev="true";; + -O|-optimize) optimize="true";; -rtdev) rtdev="true";; -J*) java_args="${java_args} '${1##-J}'";; --) parse=;; @@ -46,6 +48,7 @@ -disable <pass> disable compiler pass <pass> valid passes are: async-elimination -dev developer mode (use unpackaged X10 libraries) + -O -optimize generate optimized code Use "x10c -- -help" to get more detailed help on compiler options EOF @@ -87,6 +90,11 @@ [ -z "$MAIN" ] && MAIN="polyglot.main.Main" +# Set flags to generate optimized code if we've been asked to do so. +if [[ "$optimize" = "true" ]]; then + args=" -BAD_PLACE_RUNTIME_CHECK=false -OPTIMIZE=true $args" +fi + if [[ "$DEXT" = "x10cpp" ]]; then # C++ backend command="\"$JAVA\" -Xmx128m $config $profile -classpath \"$classpath\" ${java_args} $MAIN $extargs $args" Modified: trunk/x10.runtime.17/build.xml =================================================================== --- trunk/x10.runtime.17/build.xml 2009-04-13 04:37:41 UTC (rev 8209) +++ trunk/x10.runtime.17/build.xml 2009-04-13 21:59:19 UTC (rev 8210) @@ -14,6 +14,7 @@ <property name="bdwgc.dir" location="${basedir}/src-cpp/bdwgc"/> <property name="make.exe" value="make"/> <property name="bash.exe" value="bash"/> + <property name="optimize" value="false" /> <path id="project.classpath"> <path refid="mainproject.classpath"/> <path refid="x10.constraints.classpath"/> @@ -63,6 +64,12 @@ <condition property="cppmake.gcarg" value="ENABLE_GC=1" else="DISABLE_GC=1"> <isset property="bdwgc.enabled" /> </condition> + <condition property="cppmake.optimize" value="OPTIMIZE=1" else=""> + <isset property="optimize" /> + </condition> + <condition property="x10c.optimize" value="-O" else=""> + <isset property="optimize" /> + </condition> <target name="available-procs" unless="available.procs"> <property name="available.procs" value="2"/> </target> @@ -94,6 +101,7 @@ <arg value="-j${available.procs}" /> <arg value="install" /> <arg value="${cppmake.gcarg}" /> + <arg value="${cppmake.optimize}" /> </exec> </target> <target name="dist" depends="dist-java,dist-cpp" description="generate part of the distribution"> @@ -136,7 +144,7 @@ <echo message="x10c -c ${xrx.list}"/> <exec executable="${bash.exe}" failonerror="true" dir="${basedir}/src-x10"> <arg value="-c" /> - <arg value="'${x10.dist.location}/bin/x10c' -d '${gen}' -J-ea -rtdev -sourcepath . -disable CheckNativeAnnotations -commandlineonly -c ${xrx.list}" /> + <arg value="'${x10.dist.location}/bin/x10c' ${x10c.optimize} -d '${gen}' -J-ea -rtdev -sourcepath . -disable CheckNativeAnnotations -commandlineonly -c ${xrx.list}" /> </exec> </target> <target name="build-xrx" depends="init,build-java,gen-xrx"> @@ -178,6 +186,7 @@ <exec executable="${make.exe}" failonerror="true" dir="${basedir}/src-cpp"> <arg value="-j${available.procs}" /> <arg value="${cppmake.gcarg}" /> + <arg value="${cppmake.optimize}" /> </exec> </target> Modified: trunk/x10.runtime.17/src-cpp/Makefile =================================================================== --- trunk/x10.runtime.17/src-cpp/Makefile 2009-04-13 04:37:41 UTC (rev 8209) +++ trunk/x10.runtime.17/src-cpp/Makefile 2009-04-13 21:59:19 UTC (rev 8210) @@ -22,6 +22,12 @@ INCLUDE_DIRS += -I$(BDWGC_INCLUDE_DIR) endif +ifdef OPTIMIZE + CXXFLAGS += -O2 -finline-functions + CFLAGS += -O2 -finline-functions + X10CPPFLAGS += -optimize +endif + ifdef ENABLE_CUDA CXXFLAGS += -DX10_USE_CUDA_HOST INCLUDE_DIRS += -I/usr/local/cuda/include @@ -160,7 +166,7 @@ gen/all-cpp-generated: $(XRXFILES) $(INSTDIR)/lib/x10cpp.jar test.o @echo "Regenerating XRX cc/h/inc files" mkdir -p gen - cd ../src-x10 && find * -name .svn -prune -o -name \*.x10 -print | xargs "$(INSTDIR)"/bin/x10c++ -d ../src-cpp/gen -J-ea -rtdev -sourcepath . -disable CheckNativeAnnotations -commandlineonly -c + cd ../src-x10 && find * -name .svn -prune -o -name \*.x10 -print | xargs "$(INSTDIR)"/bin/x10c++ $(X10CPPFLAGS) -d ../src-cpp/gen -J-ea -rtdev -sourcepath . -disable CheckNativeAnnotations -commandlineonly -c touch $@ # $(XRX_MANIFEST) is a list of all .cc files (relative to the ./gen dir) that This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ipe...@us...> - 2009-04-16 20:06:03
|
Revision: 8218 http://x10.svn.sourceforge.net/x10/?rev=8218&view=rev Author: ipeshansky Date: 2009-04-16 20:05:56 +0000 (Thu, 16 Apr 2009) Log Message: ----------- Fix code generation for classes in non-default packages. Fix C++ native annotation for Boolean.parseBoolean(). Modified Paths: -------------- trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/MessagePassingCodeGenerator.java trunk/x10.runtime.17/src-x10/x10/lang/Boolean.x10 Modified: trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/MessagePassingCodeGenerator.java =================================================================== --- trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/MessagePassingCodeGenerator.java 2009-04-15 20:09:30 UTC (rev 8217) +++ trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/MessagePassingCodeGenerator.java 2009-04-16 20:05:56 UTC (rev 8218) @@ -781,7 +781,7 @@ Emitter.openNamespaces(h, pkgName); h.newline(0); h.forceNewline(0); - Emitter.openNamespaces(w, pkgName); + emitter.emitUniqueNS(pkgName, new ArrayList<String>(), w); w.newline(0); w.forceNewline(0); } @@ -842,10 +842,6 @@ h.forceNewline(0); Emitter.closeNamespaces(h, pkgName); h.newline(0); - w.newline(0); - w.forceNewline(0); - Emitter.closeNamespaces(w, pkgName); - w.newline(0); } h.write("#endif // " + cguard); h.newline(0); h.forceNewline(0); Modified: trunk/x10.runtime.17/src-x10/x10/lang/Boolean.x10 =================================================================== --- trunk/x10.runtime.17/src-x10/x10/lang/Boolean.x10 2009-04-15 20:09:30 UTC (rev 8217) +++ trunk/x10.runtime.17/src-x10/x10/lang/Boolean.x10 2009-04-16 20:05:56 UTC (rev 8218) @@ -29,6 +29,6 @@ public native def toString(): String; @Native("java", "java.lang.Boolean.parseBoolean(#1)") - @Native("c++", "x10aux::boolean_utils::parseBoolean(#0)") + @Native("c++", "x10aux::boolean_utils::parseBoolean(#1)") public native static def parseBoolean(String): Boolean; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dgr...@us...> - 2009-04-20 16:36:25
|
Revision: 8231 http://x10.svn.sourceforge.net/x10/?rev=8231&view=rev Author: dgrove-oss Date: 2009-04-20 16:36:16 +0000 (Mon, 20 Apr 2009) Log Message: ----------- enable bdw conservative gc by default when building for linux. This works for me on several 32 and 64 bit linux machines. If there are problems, it is simple enough to back it out. Note: after updating, a complete rebuild is required. Modified Paths: -------------- trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/X10CPPTranslator.java trunk/x10.runtime.17/build.xml Modified: trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/X10CPPTranslator.java =================================================================== --- trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/X10CPPTranslator.java 2009-04-17 20:50:33 UTC (rev 8230) +++ trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/X10CPPTranslator.java 2009-04-20 16:36:16 UTC (rev 8231) @@ -592,8 +592,7 @@ assert (PLATFORM.startsWith("linux_")); } - /** Disable for now. TODO: enable */ - protected boolean gcEnabled() { return false; } + protected boolean gcEnabled() { return true; } protected void addPreArgs(ArrayList<String> cxxCmd) { super.addPreArgs(cxxCmd); Modified: trunk/x10.runtime.17/build.xml =================================================================== --- trunk/x10.runtime.17/build.xml 2009-04-17 20:50:33 UTC (rev 8230) +++ trunk/x10.runtime.17/build.xml 2009-04-20 16:36:16 UTC (rev 8231) @@ -58,8 +58,8 @@ <!-- Determine whether or not we should be building with GC enabled --> <condition property="bdwgc.enabled"> - <!--<os family="unix" name="linux"/>--> - <istrue value="false"/> + <os family="unix" name="linux"/> + <!-- <istrue value="false"/> --> </condition> <condition property="cppmake.gcarg" value="ENABLE_GC=1" else="DISABLE_GC=1"> <isset property="bdwgc.enabled" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ipe...@us...> - 2009-04-22 13:52:14
|
Revision: 8235 http://x10.svn.sourceforge.net/x10/?rev=8235&view=rev Author: ipeshansky Date: 2009-04-22 13:52:10 +0000 (Wed, 22 Apr 2009) Log Message: ----------- Update version numbers Modified Paths: -------------- trunk/x10.compiler.p3/src/polyglot/ext/x10/Version.java trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/Version.java Modified: trunk/x10.compiler.p3/src/polyglot/ext/x10/Version.java =================================================================== --- trunk/x10.compiler.p3/src/polyglot/ext/x10/Version.java 2009-04-21 20:49:16 UTC (rev 8234) +++ trunk/x10.compiler.p3/src/polyglot/ext/x10/Version.java 2009-04-22 13:52:10 UTC (rev 8235) @@ -15,5 +15,5 @@ public int major() { return 1; } public int minor() { return 7; } - public int patch_level() { return 2; } + public int patch_level() { return 4; } } Modified: trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/Version.java =================================================================== --- trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/Version.java 2009-04-21 20:49:16 UTC (rev 8234) +++ trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/Version.java 2009-04-22 13:52:10 UTC (rev 8235) @@ -12,7 +12,7 @@ public class Version extends polyglot.main.Version { public String name() { return "x10c++"; } - public int major() { return 0; } - public int minor() { return 1; } - public int patch_level() { return 0; } + public int major() { return 1; } + public int minor() { return 7; } + public int patch_level() { return 4; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ipe...@us...> - 2009-04-27 20:08:30
|
Revision: 8257 http://x10.svn.sourceforge.net/x10/?rev=8257&view=rev Author: ipeshansky Date: 2009-04-27 20:08:28 +0000 (Mon, 27 Apr 2009) Log Message: ----------- Add support for GC on Cygwin Enable GC on Cygwin by default Modified Paths: -------------- trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/X10CPPTranslator.java trunk/x10.runtime.17/build.xml Modified: trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/X10CPPTranslator.java =================================================================== --- trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/X10CPPTranslator.java 2009-04-27 19:58:32 UTC (rev 8256) +++ trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/X10CPPTranslator.java 2009-04-27 20:08:28 UTC (rev 8257) @@ -553,8 +553,7 @@ assert (PLATFORM.startsWith("win32_")); } - /** Disable for now. TODO: enable */ - protected boolean gcEnabled() { return false; } + protected boolean gcEnabled() { return true; } protected void addPreArgs(ArrayList<String> cxxCmd) { super.addPreArgs(cxxCmd); Modified: trunk/x10.runtime.17/build.xml =================================================================== --- trunk/x10.runtime.17/build.xml 2009-04-27 19:58:32 UTC (rev 8256) +++ trunk/x10.runtime.17/build.xml 2009-04-27 20:08:28 UTC (rev 8257) @@ -58,7 +58,10 @@ <!-- Determine whether or not we should be building with GC enabled --> <condition property="bdwgc.enabled"> - <os family="unix" name="linux"/> + <or> + <os family="unix" name="linux"/> + <os family="windows"/> + </or> <!-- <istrue value="false"/> --> </condition> <condition property="cppmake.gcarg" value="ENABLE_GC=1" else="DISABLE_GC=1"> @@ -78,13 +81,13 @@ <target name="clean-java"> <delete dir="${build}"/> </target> - <target name="clean-cpp" depends="available-procs"> + <target name="clean-cpp" depends="available-procs,clean-bdwgc"> <exec executable="${make.exe}" failonerror="true" dir="${basedir}/src-cpp"> <arg value="-j${available.procs}" /> <arg value="clean"/> </exec> </target> - <target name="clean-bdwgc" depends="clean"> + <target name="clean-bdwgc" if="bdwgc.enabled"> <delete dir="${bdwgc.dir}/install"/> <exec executable="${make.exe}" failonerror="true" dir="${bdwgc.dir}/src"> <arg value="distclean"/> @@ -194,11 +197,13 @@ <echo message="${ant.project.name}: ${ant.file}"/> </target> - <target name="build-bdwgc" depends="check-bdwgc,download-bdwgc,available-procs" unless="bdwgc.skip.build"> + <target name="build-bdwgc" depends="check-bdwgc,download-bdwgc,convert-bdwgc-paths,available-procs" unless="bdwgc.skip.build"> <sequential> - <exec executable="${bdwgc.dir}/src/configure" dir="${bdwgc.dir}/src" failonerror="true"> + <echo message="Installing BDWGC to ${bdwgc.platform.dir}"/> + <exec executable="${bash.exe}" dir="${bdwgc.dir}/src" failonerror="true"> + <arg value="${bdwgc.dir}/src/configure" /> <arg value="-enable-threads=posix" /> - <arg value="--prefix=${bdwgc.dir}/install" /> + <arg value="--prefix=${bdwgc.platform.dir}/install" /> </exec> <exec executable="${make.exe}" dir="${bdwgc.dir}/src" failonerror="true"> <arg value="-j${available.procs}" /> @@ -232,20 +237,37 @@ </target> + <target name="convert-bdwgc-paths-cygwin" depends="check-bdwgc" if="running.on.cygwin"> + <exec executable="cygpath" outputproperty="bdwgc.platform.dir" errorproperty="bdwgc.conversion.errors"> + <arg value="${bdwgc.dir}" /> + </exec> + </target> + <target name="convert-bdwgc-paths-other" depends="check-bdwgc" unless="running.on.cygwin"> + <property name="bdwgc.platform.dir" value="${bdwgc.dir}" /> + </target> + <target name="convert-bdwgc-paths" depends="convert-bdwgc-paths-cygwin,convert-bdwgc-paths-other" /> + <target name="check-bdwgc"> <sequential> <condition property="bdwgc.skip.download"> <or> <available file="${bdwgc.dir}/src/configure" property="bdwgc.available"/> - <isfalse value="${bdwgc.enabled}" /> + <not> + <isset property="bdwgc.enabled" /> + </not> </or> </condition> <condition property="bdwgc.skip.build"> <or> <available file="${bdwgc.dir}/install/lib/libgc.so" property="bdwgc.built"/> - <isfalse value="${bdwgc.enabled}" /> + <not> + <isset property="bdwgc.enabled" /> + </not> </or> </condition> + <condition property="running.on.cygwin"> + <os family="windows"/> + </condition> </sequential> </target> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ipe...@us...> - 2009-04-27 21:03:34
|
Revision: 8258 http://x10.svn.sourceforge.net/x10/?rev=8258&view=rev Author: ipeshansky Date: 2009-04-27 21:03:29 +0000 (Mon, 27 Apr 2009) Log Message: ----------- Fix XTENLANG-367 Modified Paths: -------------- trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/MessagePassingCodeGenerator.java Added Paths: ----------- trunk/x10.tests/examples/Issues/XTENLANG_367.x10 Modified: trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/MessagePassingCodeGenerator.java =================================================================== --- trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/MessagePassingCodeGenerator.java 2009-04-27 20:08:28 UTC (rev 8257) +++ trunk/x10.cppbackend.17/src/polyglot/ext/x10cpp/visit/MessagePassingCodeGenerator.java 2009-04-27 21:03:29 UTC (rev 8258) @@ -2359,7 +2359,6 @@ sw.end(); sw.newline(); sw.write("}"); if (n.finallyBlock() != null) { - n.printBlock(n.finallyBlock(), sw, tr); sw.end(); sw.newline(); sw.write("} catch (...) {"); sw.newline(4); sw.begin(0); @@ -2368,6 +2367,8 @@ sw.write("throw;"); sw.end(); sw.newline(); sw.write("}"); + sw.newline(); + n.printBlock(n.finallyBlock(), sw, tr); } } Added: trunk/x10.tests/examples/Issues/XTENLANG_367.x10 =================================================================== --- trunk/x10.tests/examples/Issues/XTENLANG_367.x10 (rev 0) +++ trunk/x10.tests/examples/Issues/XTENLANG_367.x10 2009-04-27 21:03:29 UTC (rev 8258) @@ -0,0 +1,31 @@ +// (C) Copyright IBM Corporation 2008 +// This file is part of X10 Test. * + +import harness.x10Test; + +/** + * @author igor 4/2009 + */ + +class XTENLANG_367 extends x10Test { + + public def run(): boolean { + var count: int = 0; + try { + try { + count++; + throw new Exception(); + } catch (e: Exception) { + count++; + } finally { + count++; + throw new RuntimeException(); + } + } catch (e: RuntimeException) { } + return count == 3; + } + + public static def main(Rail[String]) { + new XTENLANG_367().execute(); + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |