[opengtl-commits] [510] * structures that aren't returned are allocated on the stack |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/opengtl-commits Archives
]
Revision: 510
Author: cyrille
Date: 2008-12-01 23:38:29 +0100 (Mon, 01 Dec 2008)
Log Message:
-----------
* structures that aren't returned are allocated on the stack
* parameter entry can be of rgb type (vector of three floats)
Modified Paths:
--------------
trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.cpp
trunk/OpenGTL/OpenGTL/GTLCore/CMakeLists.txt
trunk/OpenGTL/OpenGTL/GTLCore/Debug.cpp
trunk/OpenGTL/OpenGTL/GTLCore/Debug.h
trunk/OpenGTL/OpenGTL/GTLCore/Metadata/ParameterEntry.cpp
trunk/OpenGTL/OpenGTL/GTLCore/ModuleData_p.cpp
trunk/OpenGTL/OpenGTL/GTLCore/ModuleData_p.h
trunk/OpenGTL/OpenGTL/GTLCore/Value.cpp
trunk/OpenGTL/OpenGTL/GTLCore/Value.h
trunk/OpenGTL/OpenGTL/GTLCore/VariableNG_p.cpp
trunk/OpenGTL/OpenGTL/GTLCore/VariableNG_p.h
Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.cpp 2008-11-30 09:40:32 UTC (rev 509)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.cpp 2008-12-01 22:38:29 UTC (rev 510)
@@ -200,6 +200,7 @@
void VariableAccessorExpression::markAsReturnExpression()
{
+ m_variable->setAllocatedInMemory( true );
}
bool VariableAccessorExpression::allocatedInMemory() const
Modified: trunk/OpenGTL/OpenGTL/GTLCore/CMakeLists.txt
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/CMakeLists.txt 2008-11-30 09:40:32 UTC (rev 509)
+++ trunk/OpenGTL/OpenGTL/GTLCore/CMakeLists.txt 2008-12-01 22:38:29 UTC (rev 510)
@@ -1,7 +1,7 @@
add_subdirectory(tests)
# Find llvm jit, interpreter and native
-FIND_LLVM_LIBS( ${LLVM_CONFIG_EXECUTABLE} "native bitwriter linker bitreader jit interpreter support ipo cbackend" LLVM_LIBS LLVM_NATIVE_OBJECTS )
+FIND_LLVM_LIBS( ${LLVM_CONFIG_EXECUTABLE} "native bitwriter linker bitreader jit interpreter support ipo" LLVM_LIBS LLVM_NATIVE_OBJECTS )
include_directories( ${LLVM_INCLUDE_DIR} )
Modified: trunk/OpenGTL/OpenGTL/GTLCore/Debug.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Debug.cpp 2008-11-30 09:40:32 UTC (rev 509)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Debug.cpp 2008-12-01 22:38:29 UTC (rev 510)
@@ -34,6 +34,7 @@
#include "Token_p.h"
#include "Type.h"
#include "Type_p.h"
+#include "Value.h"
using namespace GTLCore;
@@ -324,6 +325,36 @@
}
return ostr;
}
+ std::ostream& operator<< (std::ostream& ostr, const Value& value)
+ {
+ ostr << *value.type() << ": ";
+ switch( value.type()->dataType() )
+ {
+ case Type::BOOLEAN:
+ ostr << value.asBoolean();
+ break;
+ case Type::FLOAT:
+ ostr << value.asFloat();
+ break;
+ case Type::INTEGER32:
+ ostr << value.asInt32();
+ break;
+ case Type::UNSIGNED_INTEGER32:
+ ostr << value.asUnsignedInt32();
+ break;
+ case Type::ARRAY:
+ ostr << "[ ";
+ foreach( const Value& val, *value.asArray() )
+ {
+ ostr << val << ", ";
+ }
+ ostr << " ]";
+ break;
+ default:
+ ostr << " unknown";
+ }
+ return ostr;
+ }
}
Modified: trunk/OpenGTL/OpenGTL/GTLCore/Debug.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Debug.h 2008-11-30 09:40:32 UTC (rev 509)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Debug.h 2008-12-01 22:38:29 UTC (rev 510)
@@ -44,6 +44,7 @@
class ScopedName;
class Type;
class Token;
+ class Value;
std::ostream& operator<< (std::ostream& ostr, const ExpressionResult& expressionResult);
std::ostream& operator<< (std::ostream& ostr, const PixelDescription& pixelDescription);
@@ -51,6 +52,7 @@
std::ostream& operator<< (std::ostream& ostr, const ScopedName& name);
std::ostream& operator<< (std::ostream& ostr, const Type& type);
std::ostream& operator<< (std::ostream& ostr, const Token& token);
+ std::ostream& operator<< (std::ostream& ostr, const Value& value);
}
Modified: trunk/OpenGTL/OpenGTL/GTLCore/Metadata/ParameterEntry.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Metadata/ParameterEntry.cpp 2008-11-30 09:40:32 UTC (rev 509)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Metadata/ParameterEntry.cpp 2008-12-01 22:38:29 UTC (rev 510)
@@ -51,7 +51,9 @@
} else if( v->text() == "float" ) {
d->type = Type::Float;
} else if( v->text() == "curve" ) {
- d->type = TypeManager::getVector( Type::Float, 2 );
+ d->type = TypeManager::getArray( TypeManager::getVector( Type::Float, 2 ) );
+ } else if( v->text() == "rgb" ) {
+ d->type = TypeManager::getVector( Type::Float, 3 );
}
}
// DefaultValue
@@ -127,44 +129,20 @@
} else if( d->type == Type::Float )
{
d->defaultValue.setFloat( 0.5 );
+ } else if( d->type == TypeManager::getArray( TypeManager::getVector( Type::Float, 2 ) ) )
+ {
+ std::vector< GTLCore::Value > v1; v1.push_back( 0.0f ); v1.push_back( 0.0f );
+ std::vector< GTLCore::Value > v2; v2.push_back( 1.0f ); v2.push_back( 1.0f );
+ std::vector< GTLCore::Value > v3; v3.push_back( v1 ); v3.push_back( v2 );
+ d->defaultValue.setArray( v3 );
+ } else if( d->type == TypeManager::getVector( Type::Float, 3 ) )
+ {
+ std::vector< GTLCore::Value > v1; v1.push_back( 0.0f ); v1.push_back( 0.0f ); v1.push_back( 0.0f );
+ d->defaultValue.setArray( v1 );
}
}
}
-#if 0
-
-ParameterEntry::ParameterEntry( const GTLCore::String& _name, int _minimumValue, int _maximumValue, int _defaultValue ) : Entry( _name ), d(new Private)
-{
- d->minimumValue.setInt32( _minimumValue );
- d->maximumValue.setInt32( _maximumValue );
- d->defaultValue.setInt32( _defaultValue );
-}
-
-ParameterEntry::ParameterEntry( const GTLCore::String& _name, float _minimumValue, float _maximumValue, float _defaultValue ) : Entry( _name ), d(new Private)
-{
- d->type = GTLCore::Type::Float;
- d->minimumValue.setFloat( _minimumValue );
- d->maximumValue.setFloat( _maximumValue );
- d->defaultValue.setFloat( _defaultValue );
-}
-
-ParameterEntry::ParameterEntry( const GTLCore::String& _name, const GTLCore::Value& _defaultValue ) : Entry( _name ), d(new Private)
-{
- d->type = _defaultValue.type();
- d->defaultValue = _defaultValue;
- if( d->type == Type::Integer32 )
- {
- d->minimumValue.setInt32( 0 );
- d->maximumValue.setInt32( 100 );
- } else if( d->type == Type::Float )
- {
- d->minimumValue.setFloat( 0.0 );
- d->maximumValue.setFloat( 1.0 );
- }
-}
-
-#endif
-
ParameterEntry::~ParameterEntry()
{
delete d;
@@ -190,6 +168,11 @@
return d->type;
}
+const GTLCore::String& ParameterEntry::description() const
+{
+ return d->description;
+}
+
const ParameterEntry* ParameterEntry::asParameterEntry() const
{
return this;
Modified: trunk/OpenGTL/OpenGTL/GTLCore/ModuleData_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/ModuleData_p.cpp 2008-11-30 09:40:32 UTC (rev 509)
+++ trunk/OpenGTL/OpenGTL/GTLCore/ModuleData_p.cpp 2008-12-01 22:38:29 UTC (rev 510)
@@ -103,40 +103,6 @@
return functions;
}
-GTLCore::String ModuleData::asCCode() const
-{
- llvm::TargetMachine* ctarget = 0;
- std::string cId = "c";
- for( llvm::TargetMachineRegistry::iterator it = llvm::TargetMachineRegistry::begin();
- it != llvm::TargetMachineRegistry::end(); ++it)
- {
- GTL_DEBUG( it->Name );
- if( it->Name == cId )
- {
- ctarget = it->CtorFn(*m_llvmModule, "");
- break;
- }
- }
-
- GTL_ASSERT(ctarget);
- GTL_ASSERT(ctarget->WantsWholeFile());
-
- llvm::PassManager PM;
- PM.add(new llvm::TargetData(*ctarget->getTargetData()));
- PM.add(llvm::createVerifierPass());
-
- GTLCore::String str;
- llvm::raw_string_ostream os(str);
-
- // Ask the target to add backend passes as necessary.
- bool succ = ctarget->addPassesToEmitWholeFile( PM, os, llvm::TargetMachine::AssemblyFile, false);
- GTL_ASSERT(not succ);
- UNUSED(succ);
- PM.run(*m_llvmModule);
-
- return str;
-}
-
void ModuleData::linkWith( const llvm::Module* _module )
{
foreach( const llvm::Module* mod, m_linkModuleWith )
Modified: trunk/OpenGTL/OpenGTL/GTLCore/ModuleData_p.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/ModuleData_p.h 2008-11-30 09:40:32 UTC (rev 509)
+++ trunk/OpenGTL/OpenGTL/GTLCore/ModuleData_p.h 2008-12-01 22:38:29 UTC (rev 510)
@@ -58,10 +58,6 @@
const llvm::Module* llvmLinkedModule() const { return m_llvmLinkedModule; }
TypeManager* typeManager() { return m_typeManager; }
const TypeManager* typeManager() const { return m_typeManager; }
- /**
- * @return a string containing the module compiled as C
- */
- GTLCore::String asCCode() const;
private:
llvm::Module* m_llvmModule;
llvm::Module* m_llvmLinkedModule;
Modified: trunk/OpenGTL/OpenGTL/GTLCore/Value.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Value.cpp 2008-11-30 09:40:32 UTC (rev 509)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Value.cpp 2008-12-01 22:38:29 UTC (rev 510)
@@ -73,12 +73,57 @@
Value::Value(const Value& rhs) : d(new Private(*rhs.d))
{
+ if( d->type->dataType() == Type::ARRAY )
+ {
+ d->value.array = new std::vector< Value >( *rhs.d->value.array );
+ }
}
+
Value Value::operator=(const Value& rhs)
{
*d = *rhs.d;
+ if( d->type->dataType() == Type::ARRAY )
+ {
+ d->value.array = new std::vector< Value >( *rhs.d->value.array );
+ }
return *this;
}
+
+bool Value::operator==(const Value& rhs) const
+{
+ if( d->type == rhs.d->type )
+ {
+ switch( d->type->dataType())
+ {
+ case Type::BOOLEAN:
+ return d->value.b == rhs.d->value.b;
+ case Type::FLOAT:
+ return d->value.f == rhs.d->value.f;
+ case Type::INTEGER32:
+ return d->value.i == rhs.d->value.i;
+ case Type::UNSIGNED_INTEGER32:
+ return d->value.ui == rhs.d->value.ui;
+ case Type::ARRAY:
+ {
+ if( d->value.array->size() == rhs.d->value.array->size() )
+ {
+ for( std::size_t i = 0; i < d->value.array->size(); ++i)
+ {
+ if( not( (*d->value.array)[i] == (*rhs.d->value.array)[i] ) )
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+ }
+ default:
+ return false;
+ }
+ }
+ return false;
+}
+
Value::~Value()
{
if( d->type->dataType() == Type::ARRAY )
@@ -150,3 +195,13 @@
return 0;
}
}
+
+void Value::setArray( const std::vector< Value >& _array )
+{
+ if( d->type->dataType() == Type::ARRAY )
+ {
+ delete d->value.array;
+ }
+ d->value.array = new std::vector< Value >( _array );
+ d->type = TypeManager::getArray( _array[0].type() );
+}
Modified: trunk/OpenGTL/OpenGTL/GTLCore/Value.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Value.h 2008-11-30 09:40:32 UTC (rev 509)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Value.h 2008-12-01 22:38:29 UTC (rev 510)
@@ -40,6 +40,8 @@
Value operator=(const Value& rhs);
~Value();
public:
+ bool operator==(const Value& rhs) const;
+ public:
/**
* @return the value as a float
*/
@@ -69,6 +71,10 @@
*/
const std::vector< Value >* asArray() const;
/**
+ * @return the value as an array, or 0 if not an array
+ */
+ void setArray( const std::vector< Value >& _array );
+ /**
* @return the type of the value.
*/
const Type* type() const;
Modified: trunk/OpenGTL/OpenGTL/GTLCore/VariableNG_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/VariableNG_p.cpp 2008-11-30 09:40:32 UTC (rev 509)
+++ trunk/OpenGTL/OpenGTL/GTLCore/VariableNG_p.cpp 2008-12-01 22:38:29 UTC (rev 510)
@@ -57,7 +57,7 @@
d->visitor = Visitor::getVisitorFor( _type );
d->pointer = 0;
d->constantPointer = false;
- d->allocatedInMemory = ( _type->dataType() == Type::ARRAY or _type->dataType() == Type::STRUCTURE );
+ d->allocatedInMemory = false;
d->dependant = _dependant;
#ifndef NDEBUG
d->dependantWasChangedToConst = false;
@@ -175,6 +175,15 @@
return d->allocatedInMemory;
}
+void VariableNG::setAllocatedInMemory( bool _allocated )
+{
+ if( d->type->dataType() == Type::ARRAY or d->type->dataType() == Type::STRUCTURE )
+ {
+ d->allocatedInMemory = _allocated;
+ }
+}
+
+
bool VariableNG::constantPointer() const
{
return d->constantPointer;
Modified: trunk/OpenGTL/OpenGTL/GTLCore/VariableNG_p.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/VariableNG_p.h 2008-11-30 09:40:32 UTC (rev 509)
+++ trunk/OpenGTL/OpenGTL/GTLCore/VariableNG_p.h 2008-12-01 22:38:29 UTC (rev 510)
@@ -99,6 +99,10 @@
*/
bool allocatedInMemory() const;
/**
+ * Make the variable allocated in memory if the type is structure or array
+ */
+ void setAllocatedInMemory( bool _allocated );
+ /**
* @return true if the pointer is constant (which means it can't be replaced)
*/
bool constantPointer() const;