public ExpressionTarget Compile(HlCompilation compilation, HlInvocationOp expr)
        {
            if (expr.ParameterList.Length != 2)
            {
                EventManager <ErrorEvent> .SendEvent(
                    new FunctionArgumentMismatchEvent(
                        "Invalid Arguments. Expected offset_of(type, member)"
                        )
                    );
            }

            HlTypeDefinition type = compilation.TypeSystem.GetType(
                compilation.Root,
                expr.ParameterList[0].ToString()
                );

            uint   off = type.GetOffset(expr.ParameterList[1].ToString());
            string v   = compilation.GetTempVar(off);

            return(new ExpressionTarget(
                       v,
                       true,
                       compilation.TypeSystem.GetType(
                           compilation.Root,
                           HLBaseTypeNames.s_UintTypeName
                           )
                       ));
        }
        public ExpressionTarget Compile(HlCompilation compilation, HlInvocationOp expr)
        {
            if (expr.ParameterList.Length != 0)
            {
                EventManager <ErrorEvent> .SendEvent(
                    new FunctionArgumentMismatchEvent(
                        "Invalid Arguments. Expected halt()"
                        )
                    );
            }

            compilation.EmitterResult.Emit("HLT");

            return(default);
Exemple #3
0
        public ExpressionTarget Compile(HlCompilation compilation, HlInvocationOp expr)
        {
            if (expr.ParameterList.Length != 1)
            {
                EventManager <ErrorEvent> .SendEvent(
                    new FunctionArgumentMismatchEvent(
                        "Invalid Arguments. Expected interrupt(code)"
                        )
                    );
            }

            compilation.EmitterResult.Emit("INT", expr.ParameterList[0].ToString());

            return(default);
Exemple #4
0
        public ExpressionTarget Compile(HlCompilation compilation, HlInvocationOp expr)
        {
            if (expr.ParameterList.Length > 5)
            {
                EventManager <ErrorEvent> .SendEvent(
                    new FunctionArgumentMismatchEvent(
                        "Invalid Arguments. Expected:\n inl_vasm(Instruction)\n inl_vasm(Instruction, Arg0)\n inl_vasm(Instruction, Arg0, Arg1)\n inl_vasm(Instruction, Arg0, Arg1, Arg2)\n inl_vasm(Instruction, Arg0, Arg1, Arg2, Arg3)"
                        )
                    );
            }

            string[] args = expr.ParameterList.Skip(1).Select(x => x.ToString()).ToArray();
            compilation.EmitterResult.Emit(expr.ParameterList[0].ToString(), args);

            return(default);
        public ExpressionTarget Compile(HlCompilation compilation, HlInvocationOp expr)
        {
            if (expr.ParameterList.Length != 2)
            {
                EventManager <ErrorEvent> .SendEvent(
                    new FunctionArgumentMismatchEvent(
                        "Invalid Arguments. Expected static_cast(variable, type)"
                        )
                    );
            }

            return(compilation.Parse(expr.ParameterList[0]).
                   Cast(
                       compilation.TypeSystem.GetType(
                           compilation.Root,
                           expr.ParameterList[1].ToString()
                           )
                       ));
        }
        public ExpressionTarget Compile(HlCompilation compilation, HlInvocationOp expr)
        {
            ExpressionTarget t = compilation.Parse(expr.ParameterList.First());

            ExpressionTarget ret = ReferenceExpressionCompiler.Emit(
                compilation,
                t,
                new ExpressionTarget(
                    SettingsManager.GetSettings <HlCompilerSettings>().OmitTempVarInit
                                                                             ? compilation.GetTempVar()
                                                                             : compilation.GetTempVar(0),
                    true,
                    compilation.TypeSystem.GetType(
                        compilation.Root,
                        HLBaseTypeNames.s_UintTypeName
                        )
                    )
                );

            compilation.ReleaseTempVar(t.ResultAddress);

            return(ret);
        }
        public ExpressionTarget Compile(HlCompilation compilation, HlInvocationOp expr)
        {
            if (expr.ParameterList.Length != 2)
            {
                EventManager <ErrorEvent> .SendEvent(
                    new FunctionArgumentMismatchEvent(
                        "Invalid Arguments. Expected string(varname, string value)"
                        )
                    );
            }

            string varName = expr.ParameterList[0].ToString();

            string content = expr.ParameterList[1].
                             GetChildren().
                             Select(x => x.ToString()).
                             Aggregate((input, elem) => input + ' ' + elem);

            compilation.CreateVariable(
                varName,
                content,
                compilation.TypeSystem.GetType(
                    compilation.Root,
                    HLBaseTypeNames.s_StringTypeName
                    ),
                VariableDataEmitFlags.None
                );

            return(new ExpressionTarget(
                       compilation.GetFinalName(varName),
                       true,
                       compilation.TypeSystem.GetType(
                           compilation.Root,
                           HLBaseTypeNames.s_StringTypeName
                           )
                       ));
        }
Exemple #8
0
        public ExpressionTarget Compile(HlCompilation compilation, HlInvocationOp expr)
        {
            if (expr.ParameterList.Length != 1)
            {
                EventManager <ErrorEvent> .SendEvent(
                    new FunctionArgumentMismatchEvent(
                        "Invalid Arguments. Expected size_of(variable)"
                        )
                    );
            }


            if (compilation.ContainsVariable(expr.ParameterList[0].ToString()))
            {
                string v = compilation.GetTempVar(
                    compilation.GetVariable(expr.ParameterList[0].ToString()).Size
                    );

                return(new ExpressionTarget(
                           v,
                           true,
                           compilation.TypeSystem.GetType(
                               compilation.Root,
                               HLBaseTypeNames.s_UintTypeName
                               )
                           ));
            }

            if (expr.ParameterList[0] is HlMemberAccessOp mac)
            {
                ExpressionTarget lType = compilation.Parse(mac.Left);

                if (lType.ResultAddress == "%%TYPE%%")
                {
                    HlMemberDefinition member = lType.TypeDefinition.
                                                GetPrivateOrPublicMember(
                        mac.MemberName.ToString()
                        );
                    VariableData var = compilation.
                                       GetVariable(
                        lType.TypeDefinition.GetFinalMemberName(
                            member
                            )
                        );
                    string v = compilation.GetTempVar(
                        var.
                        Size
                        );

                    return(new ExpressionTarget(
                               v,
                               true,
                               compilation.TypeSystem.GetType(
                                   compilation.Root,
                                   HLBaseTypeNames.s_UintTypeName
                                   )
                               ));
                }
                else
                {
                    throw new Exception();
                }
            }

            if (compilation.TypeSystem.HasType(compilation.Root, expr.ParameterList[0].ToString()))
            {
                string v = compilation.GetTempVar(
                    compilation.TypeSystem.
                    GetType(
                        compilation.Root,
                        expr.ParameterList[0].ToString()
                        ).
                    GetSize()
                    );

                return(new ExpressionTarget(
                           v,
                           true,
                           compilation.TypeSystem.GetType(
                               compilation.Root,
                               HLBaseTypeNames.s_UintTypeName
                               )
                           ));
            }

            EventManager <ErrorEvent> .SendEvent(
                new HlVariableNotFoundEvent(
                    expr.ParameterList[0].ToString(),
                    false
                    )
                );

            return(new ExpressionTarget());
        }
Exemple #9
0
 public ExpressionTarget Compile(string func, HlCompilation compilation, HlInvocationOp expr)
 {
     return(m_Compilers[func].Compile(compilation, expr));
 }