--- a/c1/DragonFly__C1CompilerBackendX86_64.st Wed Aug 10 22:35:23 2016 +0100
+++ b/c1/DragonFly__C1CompilerBackendX86_64.st Sun Aug 07 21:52:39 2016 +0100
@@ -17,7 +17,8 @@
C1CompilerBackend subclass:#C1CompilerBackendX86_64
instanceVariableNames:'method numArgs numVars module function asm prologue epilogue
- contextSetup literals literalsBaseAddr context'
+ contextSetup literals literalsBaseAddr context
+ contextFieldIndexCVars'
classVariableNames:''
poolDictionaries:'DragonFly::C1LLVMTypes LLVMIntPredicate VMData VMOffsets
VMConstants DragonFly::C1CompilerDebugFlags'
@@ -97,9 +98,12 @@
method:aMethod
method := aMethod.
numArgs := aMethod numArgs.
+ method isJavaMethod ifTrue:[
+ numArgs := (method isStatic ifTrue:[0] ifFalse:[1])
+ ].
numVars := aMethod numVars.
- "Modified: / 01-08-2016 / 20:39:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 07-08-2016 / 22:54:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!C1CompilerBackendX86_64 methodsFor:'codegen-load / store'!
@@ -158,14 +162,14 @@
loadContextVarAt: index
index <= numArgs ifTrue:[
context isNil ifTrue:[
- ^ function parameterAt: OBJFUNCArgIndexArgBase + index
+ ^ function parameterAt: OBJFUNCArgIndexArgBase + ((method isJavaMethod and: [method isStatic not]) ifTrue:[-1] ifFalse:[0]) + index.
].
].
self assert: context notNil description: 'No context!!'.
- ^ asm load: (asm gep: context at:{ 0 . TyContextFieldIndexCVars . index - 1 })
+ ^ asm load: (asm gep: context at:{ 0 . contextFieldIndexCVars . index - 1 })
"Created: / 31-07-2016 / 23:10:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 01-08-2016 / 20:56:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 07-08-2016 / 22:56:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
loadLiteral: anObject
@@ -243,10 +247,10 @@
storeContextVar: value at: index
self assert: context notNil description: 'No context!!'.
- ^ asm store: value at: (asm gep: context at:{ 0 . TyContextFieldIndexCVars . index - 1 })
+ ^ asm store: value at: (asm gep: context at:{ 0 . contextFieldIndexCVars . index - 1 })
"Created: / 31-07-2016 / 23:07:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 01-08-2016 / 20:56:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 07-08-2016 / 22:30:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
storeRetvalTemp: value
@@ -325,19 +329,39 @@
!C1CompilerBackendX86_64 methodsFor:'codegen-prologue / epilogue'!
emitContextSetup
- | flags ctx |
+ | flags arg1Index ctxSize ctxTy ctx |
contextSetup := function addBasicBlockNamed:'context-setup'.
asm continue:contextSetup.
- ctx := asm alloca:(C1LLVMTypes tyContext:(method numArgs + method numVars + method stackSize))
- as:'__context'.
+
+ arg1Index := 1.
+ ctxSize := numArgs + method numVars + method stackSize.
+
+ method isJavaMethod ifTrue:[
+ arg1Index := method isStatic ifTrue:[ 1 ] ifFalse:[ 2 ].
+ ctxTy := C1LLVMTypes tyJContext: ctxSize.
+ contextFieldIndexCVars := TyJContextFieldIndexCVars
+ ] ifFalse:[method isBlock ifTrue:[
+ ctxTy := C1LLVMTypes tyBContext: ctxSize.
+ contextFieldIndexCVars := TyBContextFieldIndexCVars
+ ] ifFalse:[
+ ctxTy := C1LLVMTypes tyMContext: ctxSize.
+ contextFieldIndexCVars := TyMContextFieldIndexCVars
+ ]].
+
+
+ (method isJavaMethod and:[ method isStatic not]) ifTrue:[
+ ctxSize := ctxSize + 1.
+ ].
+ ctxTy := (method isJavaMethod ifTrue:[ C1LLVMTypes tyJContext: ctxSize ] ifFalse:[ method isBlock ifTrue:[ C1LLVMTypes tyBContext: ctxSize ] ifFalse:[ C1LLVMTypes tyMContext: ctxSize ]]).
+ ctx := asm alloca:ctxTy as:'__context'.
"/ Nil out contents...
asm memset: ctx _: (LLVMConstant uint8: 0) _: (LLVMConstant uint64: ctx type pointee sizeInBytes) _: ctx type alignmentInBytes _: false.
flags := (method isJavaMethod ifTrue:[ __LAZYJCON ] ifFalse:[ method isBlock ifTrue:[ __LAZYBCON ] ifFalse:[ __LAZYMCON ]])
| __CANNOT_RETURN "/ For now, we don't (yet) fill setjmp() buffer
| __METHOD_VALID
- | (method numArgs bitShift:__NARG_SHIFT)
+ | ( numArgs bitShift:__NARG_SHIFT)
| (method numVars bitShift:__NVAR_SHIFT)
| (method stackSize bitShift:__NTMP_SHIFT).
asm store:(self makeSmallInteger:flags)
@@ -353,11 +377,11 @@
asm store:(asm bitcast:self loadThisContext to:LLVMType intptr pointer)
at:(asm gep:ctx at:{ 0 . TyContextFieldIndexSenderS }).
"/ Store arguments
- 1 to: numArgs do:[:i |
+ 1 to: method numArgs do:[:i |
| arg |
arg := function parameterAt: OBJFUNCArgIndexArgBase + i.
- asm store: arg at: (asm gep: ctx at:{ 0 . TyContextFieldIndexCVars . i - 1 })
+ asm store: arg at: (asm gep: ctx at:{ 0 . contextFieldIndexCVars . i + arg1Index - 2 })
].
self storeThisContext:ctx.
context := ctx.
@@ -366,7 +390,7 @@
].
"Created: / 20-04-2016 / 23:12:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 02-08-2016 / 00:09:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 07-08-2016 / 23:17:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
emitEpilogue