compiler/TLLVMCodeGenerator.st
changeset 16 17a2d1d9f205
parent 15 10a95d798b36
--- a/compiler/TLLVMCodeGenerator.st	Wed Sep 23 22:21:44 2015 +0100
+++ b/compiler/TLLVMCodeGenerator.st	Fri Sep 25 03:51:15 2015 +0100
@@ -1,3 +1,16 @@
+"
+    Copyright (C) 2015-now Jan Vrany
+
+    This code is not an open-source (yet). You may use this code
+    for your own experiments and projects, given that:
+
+    * all modification to the code will be sent to the
+      original author for inclusion in future releases
+    * this is not used in any commercial software
+
+    This license is provisional and may (will) change in
+    a future.
+"
 "{ Package: 'jv:tea/compiler' }"
 
 "{ NameSpace: Smalltalk }"
@@ -5,10 +18,29 @@
 TCompilerPass subclass:#TLLVMCodeGenerator
 	instanceVariableNames:'function asm'
 	classVariableNames:'SelectorSpecialCharMappingTable'
-	poolDictionaries:''
+	poolDictionaries:'LLVMAtomicOrdering LLVMAtomicRMWBinOp LLVMAttribute
+		LLVMByteOrdering LLVMCallConv LLVMDLLStorageClass
+		LLVMIntPredicate'
 	category:'Languages-Tea-Compiler-Internals'
 !
 
+!TLLVMCodeGenerator class methodsFor:'documentation'!
+
+copyright
+"
+    Copyright (C) 2015-now Jan Vrany
+
+    This code is not an open-source (yet). You may use this code
+    for your own experiments and projects, given that:
+
+    * all modification to the code will be sent to the
+      original author for inclusion in future releases
+    * this is not used in any commercial software
+
+    This license is provisional and may (will) change in
+    a future.
+"
+! !
 
 !TLLVMCodeGenerator class methodsFor:'initialization'!
 
@@ -92,13 +124,13 @@
         allocas := anRBVariableNode scope llvmAllocas.
         block := asm block.
         asm block: allocas.
-        value := asm alloca: (binding type asLLVMTypeInModule: context module)  as: binding name.
+        value := asm alloca: (binding type asLLVMTypeInModule: context llvmModule)  as: binding name.
         asm block: block.
     ].
     binding llvmValue: value.
 
     "Created: / 02-09-2015 / 08:43:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 23-09-2015 / 21:47:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 24-09-2015 / 16:18:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !TLLVMCodeGenerator methodsFor:'visitor-double dispatching'!
@@ -191,10 +223,10 @@
 !
 
 acceptLiteralNode: aLiteralNode
-    ^ aLiteralNode binding asLLVMValueInModule: context module.
+    ^ aLiteralNode binding asLLVMValueInModule: context llvmModule.
 
     "Created: / 31-08-2015 / 10:13:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 31-08-2015 / 12:20:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 24-09-2015 / 16:17:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 acceptMessageNode: aMessageNode
@@ -202,18 +234,18 @@
 
     receiver := self visitNode: aMessageNode receiver.
     arguments := aMessageNode arguments collect: [:argument | self visitNode: argument ].
-    methodFunction := aMessageNode binding asLLVMValueInModule: context module.  
+    methodFunction := aMessageNode binding asLLVMValueInModule: context llvmModule.  
 
     ^ asm call: methodFunction _: { receiver } , arguments
 
     "Created: / 31-08-2015 / 10:13:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified (format): / 15-09-2015 / 07:14:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 24-09-2015 / 16:17:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 acceptMethodNode: aMethodNode 
     | allocas entry |
 
-    function := aMethodNode binding asLLVMValueInModule: context module.
+    function := aMethodNode binding asLLVMValueInModule: context llvmModule.
     allocas := function addBasicBlockNamed: 'allocas'.
     entry := function addBasicBlockNamed: 'entry'.
     aMethodNode scope llvmAllocas: allocas.
@@ -224,7 +256,7 @@
     asm br: entry.
 
     "Created: / 31-08-2015 / 09:42:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 23-09-2015 / 22:32:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 24-09-2015 / 16:17:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 acceptOptimizedNode: anOptimizedNode 
@@ -234,9 +266,12 @@
 !
 
 acceptPragmaNode: aPragmaNode
-    self notYetImplemented
+    aPragmaNode selector = 'primitive:' ifTrue:[ 
+        self acceptPrimitiveNode: aPragmaNode  
+    ].
 
     "Created: / 31-08-2015 / 10:13:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 24-09-2015 / 18:53:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 acceptPrimitiveNode: aPragmaNode
@@ -256,13 +291,13 @@
         ].
     ].
     emitMethodNode selector:(String streamContents: [ :s | emitMethodNode arguments size timesRepeat:[s nextPutAll:'_:'] ]).
-    emitMethod := Compiler compile: emitMethodNode formattedCode forClass: UndefinedObject install: false.
+    emitMethod := Compiler compile: emitMethodNode formattedCode forClass: self class install: false.
     emitMethod
         valueWithReceiver: nil
         arguments: { asm } , ((1 to: function numArgs) collect: [ :i | function parameterAt: i ])
 
     "Created: / 22-09-2015 / 18:03:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 23-09-2015 / 06:27:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 24-09-2015 / 18:58:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 acceptReturnNode: aReturnNode