| 106 | }; |
| 107 | |
| 108 | asmjit::CCFunc *JitCompiler::Codegen() |
| 109 | { |
| 110 | Setup(); |
| 111 | |
| 112 | int lastLine = -1; |
| 113 | |
| 114 | pc = sfunc->Code; |
| 115 | auto end = pc + sfunc->CodeSize; |
| 116 | while (pc != end) |
| 117 | { |
| 118 | int i = (int)(ptrdiff_t)(pc - sfunc->Code); |
| 119 | op = pc->op; |
| 120 | |
| 121 | int curLine = sfunc->PCToLine(pc); |
| 122 | if (curLine != lastLine) |
| 123 | { |
| 124 | lastLine = curLine; |
| 125 | |
| 126 | auto label = cc.newLabel(); |
| 127 | cc.bind(label); |
| 128 | |
| 129 | JitLineInfo info; |
| 130 | info.Label = label; |
| 131 | info.LineNumber = curLine; |
| 132 | LineInfo.Push(info); |
| 133 | } |
| 134 | |
| 135 | if (op != OP_PARAM && op != OP_PARAMI && op != OP_VTBL) |
| 136 | { |
| 137 | FString lineinfo; |
| 138 | lineinfo.Format("; line %d: %02x%02x%02x%02x %s", curLine, pc->op, pc->a, pc->b, pc->c, OpNames[op]); |
| 139 | cc.comment("", 0); |
| 140 | cc.comment(lineinfo.GetChars(), lineinfo.Len()); |
| 141 | } |
| 142 | |
| 143 | labels[i].cursor = cc.getCursor(); |
| 144 | ResetTemp(); |
| 145 | EmitOpcode(); |
| 146 | |
| 147 | pc++; |
| 148 | } |
| 149 | |
| 150 | BindLabels(); |
| 151 | |
| 152 | cc.endFunc(); |
| 153 | cc.finalize(); |
| 154 | |
| 155 | auto code = cc.getCode (); |
| 156 | for (unsigned int j = 0; j < LineInfo.Size (); j++) |
| 157 | { |
| 158 | auto info = LineInfo[j]; |
| 159 | |
| 160 | if (!code->isLabelValid (info.Label)) |
| 161 | { |
| 162 | continue; |
| 163 | } |
| 164 | |
| 165 | info.InstructionIndex = code->getLabelOffset (info.Label); |