| 36 | } |
| 37 | |
| 38 | class CodeGenerator : public ICodeGenerator |
| 39 | { |
| 40 | private: |
| 41 | SymbolTable * symTable; |
| 42 | ILWorld * currentWorld = nullptr; |
| 43 | ComponentDefinitionIR * currentComponent = nullptr; |
| 44 | ILOperand * returnRegister = nullptr; |
| 45 | ImportExpressionSyntaxNode * currentImport = nullptr; |
| 46 | ShaderIR * currentShader = nullptr; |
| 47 | RefPtr<ILShader> compiledShader; |
| 48 | CompileResult & result; |
| 49 | List<ILOperand*> exprStack; |
| 50 | CodeWriter codeWriter; |
| 51 | ScopeDictionary<String, ILOperand*> variables; |
| 52 | Dictionary<String, RefPtr<ILType>> genericTypeMappings; |
| 53 | Dictionary<StructSyntaxNode*, RefPtr<ILStructType>> structTypes; |
| 54 | |
| 55 | void PushStack(ILOperand * op) |
| 56 | { |
| 57 | exprStack.Add(op); |
| 58 | } |
| 59 | ILOperand * PopStack() |
| 60 | { |
| 61 | auto rs = exprStack.Last(); |
| 62 | exprStack.SetSize(exprStack.Count() - 1); |
| 63 | return rs; |
| 64 | } |
| 65 | AllocVarInstruction * AllocVar(ExpressionType * etype) |
| 66 | { |
| 67 | AllocVarInstruction * varOp = 0; |
| 68 | RefPtr<ILType> type = TranslateExpressionType(etype); |
| 69 | auto arrType = dynamic_cast<ILArrayType*>(type.Ptr()); |
| 70 | |
| 71 | if (arrType) |
| 72 | { |
| 73 | varOp = codeWriter.AllocVar(arrType->BaseType, result.Program->ConstantPool->CreateConstant(arrType->ArrayLength)); |
| 74 | } |
| 75 | else |
| 76 | { |
| 77 | assert(type); |
| 78 | varOp = codeWriter.AllocVar(type, result.Program->ConstantPool->CreateConstant(0)); |
| 79 | } |
| 80 | return varOp; |
| 81 | } |
| 82 | FetchArgInstruction * FetchArg(ExpressionType * etype, int argId) |
| 83 | { |
| 84 | auto type = TranslateExpressionType(etype); |
| 85 | auto arrType = dynamic_cast<ILArrayType*>(type.Ptr()); |
| 86 | FetchArgInstruction * varOp = 0; |
| 87 | if (arrType) |
| 88 | { |
| 89 | auto baseType = arrType->BaseType.Release(); |
| 90 | varOp = codeWriter.FetchArg(baseType, argId); |
| 91 | } |
| 92 | else |
| 93 | { |
| 94 | varOp = codeWriter.FetchArg(type, argId); |
| 95 | } |
nothing calls this directly
no outgoing calls
no test coverage detected