[206] | 1 | #include "stdafx.h"
|
---|
| 2 |
|
---|
[183] | 3 | #include <jenga/include/smoothie/Smoothie.h>
|
---|
| 4 |
|
---|
| 5 | #include <Compiler.h>
|
---|
| 6 |
|
---|
[3] | 7 | #include "../BasicCompiler_Common/common.h"
|
---|
| 8 | #include "Opcode.h"
|
---|
| 9 |
|
---|
| 10 | void ExtendStackTo32(int type);
|
---|
| 11 | void ExtendStackTo64(int type){
|
---|
| 12 | if(Is64Type(type)) return;
|
---|
| 13 |
|
---|
| 14 | //32ビットに拡張
|
---|
| 15 | ExtendStackTo32(type);
|
---|
| 16 |
|
---|
| 17 | //64ビットに拡張
|
---|
| 18 | if(IsSignedType(type)){
|
---|
| 19 | //符号あり
|
---|
| 20 |
|
---|
| 21 | //pop eax
|
---|
[225] | 22 | compiler.codeGenerator.op_pop(REG_EAX);
|
---|
[3] | 23 |
|
---|
| 24 | //cdq
|
---|
[225] | 25 | compiler.codeGenerator.op_cdq();
|
---|
[3] | 26 |
|
---|
| 27 | //push edx
|
---|
[225] | 28 | compiler.codeGenerator.op_push(REG_EDX);
|
---|
[3] | 29 |
|
---|
| 30 | //push eax
|
---|
[225] | 31 | compiler.codeGenerator.op_push(REG_EAX);
|
---|
[3] | 32 | }
|
---|
| 33 | else{
|
---|
| 34 | //符号なし
|
---|
| 35 |
|
---|
| 36 | //pop eax
|
---|
[225] | 37 | compiler.codeGenerator.op_pop(REG_EAX);
|
---|
[3] | 38 |
|
---|
| 39 | //push 0
|
---|
[225] | 40 | compiler.codeGenerator.op_push_V(0);
|
---|
[3] | 41 |
|
---|
| 42 | //push eax
|
---|
[225] | 43 | compiler.codeGenerator.op_push(REG_EAX);
|
---|
[3] | 44 | }
|
---|
| 45 | }
|
---|
| 46 | void ExtendStackTo32(int type){
|
---|
| 47 | if(GetTypeSize(type,-1)==sizeof(long)) return;
|
---|
| 48 |
|
---|
| 49 | if(Is64Type(type)){
|
---|
| 50 | //pop eax
|
---|
[225] | 51 | compiler.codeGenerator.op_pop(REG_EAX);
|
---|
[3] | 52 |
|
---|
| 53 | //pop edx
|
---|
[225] | 54 | compiler.codeGenerator.op_pop(REG_EDX);
|
---|
[3] | 55 |
|
---|
| 56 | //push eax
|
---|
[225] | 57 | compiler.codeGenerator.op_push(REG_EAX);
|
---|
[3] | 58 | }
|
---|
[183] | 59 | else if(type==DEF_INTEGER || (Smoothie::IsUnicode()&&type==DEF_CHAR)){
|
---|
[3] | 60 | //pop eax
|
---|
[225] | 61 | compiler.codeGenerator.op_pop(REG_EAX);
|
---|
[3] | 62 |
|
---|
| 63 | //movsx eax,ax
|
---|
[225] | 64 | compiler.codeGenerator.op_movsx_R32R16( REG_EAX );
|
---|
[3] | 65 |
|
---|
| 66 | //push eax
|
---|
[225] | 67 | compiler.codeGenerator.op_push(REG_EAX);
|
---|
[3] | 68 | }
|
---|
| 69 | else if(type==DEF_WORD){
|
---|
| 70 | //pop eax
|
---|
[225] | 71 | compiler.codeGenerator.op_pop(REG_EAX);
|
---|
[3] | 72 |
|
---|
| 73 | //and eax,0000FFFFh
|
---|
[235] | 74 | compiler.codeGenerator.op_and_RV( REG_EAX, 0x0000FFFF );
|
---|
[3] | 75 |
|
---|
| 76 | //push eax
|
---|
[225] | 77 | compiler.codeGenerator.op_push(REG_EAX);
|
---|
[3] | 78 | }
|
---|
[183] | 79 | else if(type==DEF_SBYTE || (Smoothie::IsUnicode()==false&&type==DEF_CHAR)){
|
---|
[3] | 80 | //pop eax
|
---|
[225] | 81 | compiler.codeGenerator.op_pop(REG_EAX);
|
---|
[3] | 82 |
|
---|
| 83 | //movsx eax,al
|
---|
[225] | 84 | compiler.codeGenerator.op_movsx_R32R8( REG_EAX );
|
---|
[3] | 85 |
|
---|
| 86 | //push eax
|
---|
[225] | 87 | compiler.codeGenerator.op_push(REG_EAX);
|
---|
[3] | 88 | }
|
---|
[36] | 89 | else if(type==DEF_BYTE||type==DEF_BOOLEAN){
|
---|
[3] | 90 | //pop eax
|
---|
[225] | 91 | compiler.codeGenerator.op_pop(REG_EAX);
|
---|
[3] | 92 |
|
---|
| 93 | //and eax,000000FFh
|
---|
[235] | 94 | compiler.codeGenerator.op_and_RV( REG_EAX, 0x000000FF );
|
---|
[3] | 95 |
|
---|
| 96 | //push eax
|
---|
[225] | 97 | compiler.codeGenerator.op_push(REG_EAX);
|
---|
[3] | 98 | }
|
---|
| 99 | }
|
---|
| 100 | void ExtendStackTo16(int type){
|
---|
[183] | 101 | if(type==DEF_SBYTE || (Smoothie::IsUnicode()==false&&type==DEF_CHAR)){
|
---|
[3] | 102 | //pop eax
|
---|
[225] | 103 | compiler.codeGenerator.op_pop(REG_EAX);
|
---|
[3] | 104 |
|
---|
| 105 | //movsx eax,al
|
---|
[225] | 106 | compiler.codeGenerator.op_movsx_R32R8( REG_EAX );
|
---|
[3] | 107 |
|
---|
| 108 | //push eax
|
---|
[225] | 109 | compiler.codeGenerator.op_push(REG_EAX);
|
---|
[3] | 110 | }
|
---|
| 111 | else if(type==DEF_BYTE){
|
---|
| 112 | //pop eax
|
---|
[225] | 113 | compiler.codeGenerator.op_pop(REG_EAX);
|
---|
[3] | 114 |
|
---|
| 115 | //and eax,000000FFh
|
---|
[235] | 116 | compiler.codeGenerator.op_and_RV( REG_EAX, 0x000000FF );
|
---|
[3] | 117 |
|
---|
| 118 | //push eax
|
---|
[225] | 119 | compiler.codeGenerator.op_push(REG_EAX);
|
---|
[3] | 120 | }
|
---|
| 121 | }
|
---|
| 122 | void ExtendStackTo8(int type){
|
---|
| 123 | if(Is64Type(type)){
|
---|
| 124 | //pop eax
|
---|
[225] | 125 | compiler.codeGenerator.op_pop(REG_EAX);
|
---|
[3] | 126 |
|
---|
| 127 | //pop edx
|
---|
[225] | 128 | compiler.codeGenerator.op_pop(REG_EDX);
|
---|
[3] | 129 |
|
---|
| 130 | //push eax
|
---|
[225] | 131 | compiler.codeGenerator.op_push(REG_EAX);
|
---|
[3] | 132 | }
|
---|
| 133 | }
|
---|
| 134 |
|
---|
| 135 |
|
---|
| 136 | void ChangeTypeToWhole(int OldType,int NewType){
|
---|
| 137 | if(OldType==DEF_DOUBLE){
|
---|
| 138 | if(Is64Type(NewType)){
|
---|
| 139 | //fld qword ptr[esp]
|
---|
[225] | 140 | compiler.codeGenerator.op_fld_ptr_esp(DEF_DOUBLE);
|
---|
[3] | 141 |
|
---|
| 142 | //fistp qword ptr[esp]
|
---|
[225] | 143 | compiler.codeGenerator.op_fistp_ptr_esp( sizeof(_int64) );
|
---|
[3] | 144 | }
|
---|
| 145 | else{
|
---|
| 146 | //fld qword ptr[esp]
|
---|
[225] | 147 | compiler.codeGenerator.op_fld_ptr_esp(DEF_DOUBLE);
|
---|
[3] | 148 |
|
---|
| 149 | //add esp,4
|
---|
[225] | 150 | compiler.codeGenerator.op_add_esp(4);
|
---|
[3] | 151 |
|
---|
| 152 | //fistp dword ptr[esp]
|
---|
[225] | 153 | compiler.codeGenerator.op_fistp_ptr_esp( sizeof(long) );
|
---|
[3] | 154 | }
|
---|
| 155 | }
|
---|
| 156 | else if(OldType==DEF_SINGLE){
|
---|
| 157 | if(Is64Type(NewType)){
|
---|
| 158 | //fld dword ptr[esp]
|
---|
[225] | 159 | compiler.codeGenerator.op_fld_ptr_esp(DEF_SINGLE);
|
---|
[3] | 160 |
|
---|
| 161 | //sub esp,4
|
---|
[225] | 162 | compiler.codeGenerator.op_sub_esp(4);
|
---|
[3] | 163 |
|
---|
| 164 | //fistp qword ptr[esp]
|
---|
[225] | 165 | compiler.codeGenerator.op_fistp_ptr_esp( sizeof(_int64) );
|
---|
[3] | 166 | }
|
---|
| 167 | else{
|
---|
| 168 | //fld dword ptr[esp]
|
---|
[225] | 169 | compiler.codeGenerator.op_fld_ptr_esp(DEF_SINGLE);
|
---|
[3] | 170 |
|
---|
| 171 | //fistp dword ptr[esp]
|
---|
[225] | 172 | compiler.codeGenerator.op_fistp_ptr_esp( sizeof(long) );
|
---|
[3] | 173 | }
|
---|
| 174 | }
|
---|
| 175 | else{
|
---|
| 176 | //整数から整数へ変換
|
---|
| 177 |
|
---|
| 178 | if(Is64Type(NewType)){
|
---|
| 179 | ExtendStackTo64(OldType);
|
---|
| 180 | }
|
---|
| 181 | else if(GetTypeSize(NewType,-1)==sizeof(long)){
|
---|
| 182 | ExtendStackTo32(OldType);
|
---|
| 183 | }
|
---|
| 184 | else if(GetTypeSize(NewType,-1)==sizeof(short)){
|
---|
| 185 | ExtendStackTo16(OldType);
|
---|
| 186 | }
|
---|
| 187 | else if(GetTypeSize(NewType,-1)==sizeof(char)){
|
---|
| 188 | ExtendStackTo8(OldType);
|
---|
| 189 | }
|
---|
| 190 | }
|
---|
| 191 | }
|
---|