Added CodeObjectSection>>size. Polished tests a bit.
authorJan Vrany <jan.vrany@fit.cvut.cz>
Tue, 19 Jan 2016 21:50:11 +0000
changeset 10 588414eaacff
parent 9 40f9438e9de3
child 11 cfe5c9d79fbc
Added CodeObjectSection>>size. Polished tests a bit.
CompiledCodeObject.st
CompiledCodeObjectSection.st
CompiledCodeObjectTests.st
abbrev.stc
asm/AJStackAlignmentTests.st
asm/AJx86AssemblerTests.st
asm/AJx86RegisterTests.st
asm/AJx86Registers.st
jv_dragonfly.st
--- a/CompiledCodeObject.st	Tue Jan 19 16:46:20 2016 +0000
+++ b/CompiledCodeObject.st	Tue Jan 19 21:50:11 2016 +0000
@@ -193,6 +193,13 @@
     "Created: / 11-01-2016 / 09:31:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
+sectionNamed: aString
+    ^ self sections detect:[:section | section name = aString ] 
+                    ifNone:[ self error: 'No section named "', aString , '"' ]
+
+    "Created: / 19-01-2016 / 21:28:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 sections
     | numSections |
 
@@ -215,6 +222,38 @@
 
 !CompiledCodeObject methodsFor:'allocation'!
 
+allocateDataSection: dataSize named: dataName
+    "Alocates new data section for the receiver."
+
+    | failureReason |
+
+    failureReason := nil.
+%{    
+    stx_compiled_code_object code_object;
+    INT _dataSize;
+
+    if (!( __isSmallInteger( dataSize ) && ( _dataSize = __intVal( dataSize ), (_dataSize >= 0) && (_dataSize <= UINT32_MAX) ) ) ) {
+        failureReason = @symbol(BadArg1);
+        goto done;
+    }
+    if (! (__isString( dataName ))) {
+        failureReason = @symbol(BadArg2);
+        goto done;    
+    }
+    code_object = (stx_compiled_code_object)(__externalAddressVal(self));
+    if (code_object == NULL) {        
+        failureReason = @symbol(BadSelf);
+    } else {
+        stxCompiledCodeObjectAllocDataSection(code_object, _dataSize, __stringVal( dataName ));
+        RETURN ( self );
+    }
+    done:;
+%}.
+    self primitiveFailed: failureReason
+
+
+!
+
 allocateTextSection: textSize
     "Alocates new text section for the receiver. Throw an error if there's
      already a text section allocated for this object."
@@ -254,38 +293,6 @@
 
 
     "Created: / 11-01-2016 / 20:18:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-! 
-
-allocateDataSection: dataSize named: dataName
-    "Alocates new data section for the receiver."
-
-    | failureReason |
-
-    failureReason := nil.
-%{    
-    stx_compiled_code_object code_object;
-    INT _dataSize;
-
-    if (!( __isSmallInteger( dataSize ) && ( _dataSize = __intVal( dataSize ), (_dataSize >= 0) && (_dataSize <= UINT32_MAX) ) ) ) {
-        failureReason = @symbol(BadArg1);
-        goto done;
-    }
-    if (! (__isString( dataName ))) {
-        failureReason = @symbol(BadArg2);
-        goto done;    
-    }
-    code_object = (stx_compiled_code_object)(__externalAddressVal(self));
-    if (code_object == NULL) {        
-        failureReason = @symbol(BadSelf);
-    } else {
-        stxCompiledCodeObjectAllocDataSection(code_object, _dataSize, __stringVal( dataName ));
-        RETURN ( self );
-    }
-    done:;
-%}.
-    self primitiveFailed: failureReason
-
-
 ! !
 
 !CompiledCodeObject methodsFor:'initialization'!
@@ -321,7 +328,9 @@
 !CompiledCodeObject methodsFor:'private'!
 
 getSection: index
-    | name addr size format |
+    | section name size format |
+
+    section := CompiledCodeObjectSection basicNew.
 %{
     if (__isSmallInteger(index)) {
         stx_compiled_code_object code_object = (stx_compiled_code_object)(__externalAddressVal(self));
@@ -329,17 +338,16 @@
 
         code_section = stxCompiledCodeObjectGetSection ( code_object , __intVal( index ) - 1 );
         if (code_section) {
+            __externalAddressVal(section) = (OBJ)code_section->section_addr;
+            size = __MKSMALLINT ( code_section->section_size );                     
+            format = __MKSMALLINT ( code_section->section_format );
             name = __MKSTRING ( code_section->section_name );
-            size = __MKSMALLINT ( code_section->section_size );
-            __PROTECT__(name);
-            addr = __MKUINT( code_section->section_addr );
-            __UNPROTECT__(name);
-            format = __MKSMALLINT ( code_section->section_format );
         }
     }
 %}.
-    (name notNil and:[ addr notNil and:[ size notNil ]]) ifTrue:[ 
-        ^ CompiledCodeObjectSection basicNew setObject: self name: name address: addr size: size format: format
+    (name notNil and:[ size notNil and:[ format notNil]]) ifTrue:[ 
+        section setObject: self name: name size: size format: format.
+        ^ section
     ].
     self primitiveFailed.
 
@@ -359,3 +367,10 @@
     "Created: / 07-12-2015 / 16:36:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
+!CompiledCodeObject class methodsFor:'documentation'!
+
+version_HG
+
+    ^ '$Changeset: <not expanded> $'
+! !
+
--- a/CompiledCodeObjectSection.st	Tue Jan 19 16:46:20 2016 +0000
+++ b/CompiledCodeObjectSection.st	Tue Jan 19 21:50:11 2016 +0000
@@ -16,10 +16,22 @@
 ExternalBytes subclass:#CompiledCodeObjectSection
 	instanceVariableNames:'object name format'
 	classVariableNames:''
-	poolDictionaries:'CompiledCodeObjectSectionType'
+	poolDictionaries:'CompiledCodeObjectSectionFormat'
 	category:'System-Compiler-Interface'
 !
 
+!CompiledCodeObjectSection primitiveDefinitions!
+%{
+
+/*
+ * includes, defines, structure definitions
+ * and typedefs come here.
+ */
+#include "../librun/mcompiler.h"
+
+%}
+! !
+
 !CompiledCodeObjectSection class methodsFor:'documentation'!
 
 copyright
@@ -38,22 +50,22 @@
 
 !CompiledCodeObjectSection methodsFor:'accessing'!
 
+format
+    ^ format
+!
+
 name
     ^ name
 !
 
 object
     ^ object
-!
-
-format
-    ^ format
 ! !
 
 !CompiledCodeObjectSection methodsFor:'initialization'!
 
-setObject: obj name: nm address: addr size: sz format: t
-    self setAddress: addr size: sz.
+setObject: obj name: nm size: sz format: t
+    self setSize: sz.
     object := obj.
     name := nm.
     format := t
@@ -66,7 +78,7 @@
 inspector2TabAssembly
     <inspector2Tab>
 
-    format ~~ SectionTypeText ifTrue:[ ^ nil ].
+    format ~~ SectionFormatText ifTrue:[ ^ nil ].
     (Smalltalk at: #UDIS86) isNil ifTrue:[ 
         "/ Try to load the package...
         [ Smalltalk loadPackage: 'jv:dragonfly/udis86sx' ] on: Error do:[ ^ nil ].
@@ -115,6 +127,35 @@
     "Modified: / 11-01-2016 / 21:42:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
+!CompiledCodeObjectSection methodsFor:'queries'!
+
+size
+    "Return logical size. For size in bytes, use #sizeInBytes"
+
+%{  
+    if ( __isSmallInteger( __INST(size) ) && __isSmallInteger( __INST(format) ) ) {
+        INT sz = __intVal( __INST(size) );
+        switch ( __intVal(__INST(format) ) ) {
+        case SectionFormatOBJVector:
+            RETURN ( __MKSMALLINT( sz / sizeof(OBJ) ) );
+        case SectionFormatINTVector:
+            RETURN ( __MKSMALLINT( sz / sizeof(INT) ) );
+        case SectionFormatILCVector:
+#           ifdef __SUPPORT_DIRECT_ILC
+                RETURN ( __MKSMALLINT( sz / sizeof(struct inlineCacheForDirectCall)  ) );
+#           else
+                RETURN ( __MKSMALLINT( sz / sizeof(struct inlineCache) ) );
+#           endif
+        default:
+            RETURN ( __MKSMALLINT( sz ) );        
+        }  
+    }
+%}.    
+    self primitiveFailed
+
+    "Created: / 19-01-2016 / 21:21:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
 !CompiledCodeObjectSection class methodsFor:'documentation'!
 
 version_HG
--- a/CompiledCodeObjectTests.st	Tue Jan 19 16:46:20 2016 +0000
+++ b/CompiledCodeObjectTests.st	Tue Jan 19 21:50:11 2016 +0000
@@ -70,27 +70,40 @@
 !CompiledCodeObjectTests methodsFor:'tests'!
 
 test_01
-    | object |
+    | object section |
     self ensureCompiled: #methodWithConstant.
     object := (self class >> #methodWithConstant) codeObject.
     self assert: object compiledCode == (self class >> #methodWithConstant).
     self assert: object sections size == 2. "/ No literals no ILC's, only code and special cells
-    self assert: object sections first name = '.text'.
-    self assert: object sections first format = SectionFormatText.
-    self assert: object sections second name = '.stx.codeobj.specialcells'.
-    self assert: object sections second format = SectionTypeINTVector.
+
+    section := object sectionNamed: '.text'.
+    self assert: section format = SectionFormatText.
 
+    section := object sectionNamed: '.stx.codeobj.specialcells'. 
+    self assert: section format = SectionFormatINTVector.
+    self assert: section size == 1.
 
     self ensureCompiled: #methodWithLiteral.
     object := (self class >> #methodWithLiteral) codeObject.
     self assert: object sections size == 3. "/ No ILC's but literals, code and special cells
 
+    section := object sectionNamed: '.text'.
+    section := object sectionNamed: '.stx.codeobj.specialcells'. 
+    section := object sectionNamed: '.stx.codeobj.literals'. 
+    self assert: section format = SectionFormatOBJVector.
+    self assert: section size == 1.
 
     self ensureCompiled: #methodWithSend.
+    object := (self class >> #methodWithSend) codeObject.
     self assert: object sections size == 3. "/ No literals but ILC, code and special cells
+    section := object sectionNamed: '.text'.
+    section := object sectionNamed: '.stx.codeobj.specialcells'. 
+    section := object sectionNamed: '.stx.codeobj.ilcs'. 
+    self assert: section format = SectionFormatILCVector.
+    self assert: section size == 1.
 
     "Created: / 06-12-2015 / 00:15:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 11-01-2016 / 09:54:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified (format): / 19-01-2016 / 21:39:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !CompiledCodeObjectTests methodsFor:'utilities'!
--- a/abbrev.stc	Tue Jan 19 16:46:20 2016 +0000
+++ b/abbrev.stc	Tue Jan 19 21:50:11 2016 +0000
@@ -2,7 +2,7 @@
 # this file is needed for stc to be able to compile modules independently.
 # it provides information about a classes filename, category and especially namespace.
 CompiledCodeObject CompiledCodeObject jv:dragonfly 'System-Compiler-Interface' 0
-CompiledCodeObjectSectionType CompiledCodeObjectSectionType jv:dragonfly 'System-Compiler-Interface' 0
+CompiledCodeObjectSectionFormat CompiledCodeObjectSectionFormat jv:dragonfly 'System-Compiler-Interface' 0
 jv_dragonfly jv_dragonfly jv:dragonfly '* Projects & Packages *' 3
 CompiledCodeObjectSection CompiledCodeObjectSection jv:dragonfly 'System-Compiler-Interface' 0
 CompiledCodeObjectTests CompiledCodeObjectTests jv:dragonfly 'System-Compiler-Interface' 1
--- a/asm/AJStackAlignmentTests.st	Tue Jan 19 16:46:20 2016 +0000
+++ b/asm/AJStackAlignmentTests.st	Tue Jan 19 21:50:11 2016 +0000
@@ -9,9 +9,6 @@
 	category:'AsmJit-Tests'
 !
 
-AJStackAlignmentTests comment:''
-!
-
 !AJStackAlignmentTests methodsFor:'tests'!
 
 testJumps
--- a/asm/AJx86AssemblerTests.st	Tue Jan 19 16:46:20 2016 +0000
+++ b/asm/AJx86AssemblerTests.st	Tue Jan 19 21:50:11 2016 +0000
@@ -9,9 +9,6 @@
 	category:'AsmJit-Tests'
 !
 
-AJx86AssemblerTests comment:''
-!
-
 !AJx86AssemblerTests methodsFor:'running'!
 
 setUp
--- a/asm/AJx86RegisterTests.st	Tue Jan 19 16:46:20 2016 +0000
+++ b/asm/AJx86RegisterTests.st	Tue Jan 19 21:50:11 2016 +0000
@@ -9,9 +9,6 @@
 	category:'AsmJit-Tests'
 !
 
-AJx86RegisterTests comment:''
-!
-
 !AJx86RegisterTests methodsFor:'as yet unclassified'!
 
 testAsHighByte
--- a/asm/AJx86Registers.st	Tue Jan 19 16:46:20 2016 +0000
+++ b/asm/AJx86Registers.st	Tue Jan 19 21:50:11 2016 +0000
@@ -18,6 +18,7 @@
 AJx86Registers comment:'I am a SHaredPool which initializes all the registers needed by the Assmbler.'
 !
 
+
 !AJx86Registers class methodsFor:'initialization'!
 
 initialize
@@ -876,5 +877,12 @@
     s nextPut: $"
 ! !
 
+!AJx86Registers class methodsFor:'documentation'!
+
+version_HG
+
+    ^ '$Changeset: <not expanded> $'
+! !
+
 
 AJx86Registers initialize!
--- a/jv_dragonfly.st	Tue Jan 19 16:46:20 2016 +0000
+++ b/jv_dragonfly.st	Tue Jan 19 21:50:11 2016 +0000
@@ -12,6 +12,15 @@
 
 !jv_dragonfly class methodsFor:'description'!
 
+excludedFromPreRequisites
+    "list packages which are to be explicitely excluded from the automatic constructed
+     prerequisites list. If empty, everything that is found along the inheritance of any of
+     my classes is considered to be a prerequisite package."
+
+    ^ #(
+    )
+!
+
 mandatoryPreRequisites
     "list packages which are mandatory as a prerequisite.
      This are packages containing superclasses of my classes and classes which