Exemple #1
0
        public static string WritePlatformInvokeMethod(this PlatformInvokeMethod platformInvoke,
                                                       ClosureEntities crRuntime)
        {
            var methodId = Import(platformInvoke.LibraryName,
                                  platformInvoke.MethodName,
                                  platformInvoke.CallingConvention,
                                  platformInvoke.EntryPoint);

            var codeOutput = new CodeOutput();

            codeOutput.AppendFormat(platformInvoke.WritePInvokeDefinition(methodId));
            codeOutput.BlankLine();
            codeOutput.Append(platformInvoke.Method.WriteHeaderMethod(crRuntime, false));

            // write PInvoke implementation
            codeOutput.BracketOpen();

            var argumentsCall = platformInvoke.Method.GetParameters()
                                .Select(CallMarshallerFactory.CreateMarshaller)
                                .Each(marshaller => { codeOutput.Append(marshaller.GetTransformationCode()); })
                                .Once(marshallers => { codeOutput.BlankLine(); })
                                .Select(p => p.GetParameterString())
                                .Join(", ");

            if (!platformInvoke.Method.GetReturnType().IsVoid())
            {
                codeOutput.Append("return ");
            }
            codeOutput.AppendFormat("{0}({1});", methodId, argumentsCall);
            codeOutput.BracketClose();

            return(codeOutput.ToString());
        }
Exemple #2
0
        public static string WriteCode(CilMethodInterpreter interpreter, TypeDescriptionTable typeTable,
                                       ClosureEntities crRuntime)
        {
            var operations = interpreter.MidRepresentation.LocalOperations;
            var headerSb   = new CodeOutput();

            CppWriteSignature.WriteSignature(headerSb, interpreter, crRuntime);

            var bodySb      = ComputeBodySb(operations, interpreter.MidRepresentation.Vars, typeTable, interpreter, crRuntime);
            var variablesSb = ComputeVariableSb(interpreter.MidRepresentation, interpreter, crRuntime);
            var finalSb     = new CodeOutput();

            finalSb.Append(headerSb.ToString())
            .BracketOpen()
            .Append(variablesSb.ToString())
            .Append(bodySb.ToString())
            .BracketClose();

            return(finalSb.ToString());
        }
        public string BuildStringTable()
        {
            var sb = new CodeOutput();

            sb.BlankLine()
            .Append("System_Void buildStringTable()")
            .BracketOpen();

            var stringDataBuilder = new List <string>();

            var jump = 0;

            foreach (var strItem in _table)
            {
                sb.AppendFormat("_AddJumpAndLength({0}, {1});\n", jump, strItem.Length);
                var itemTextData = TextData(strItem);
                AddTextToStringTable(stringDataBuilder, itemTextData, strItem);

                jump += strItem.Length + 1;
            }


            sb.BracketClose(true)
            .Append(" // buildStringTable\n");

            var stringTableContent = string.Join(", " + Environment.NewLine, stringDataBuilder);
            var length             = jump == 0 ? 1 : jump;

            sb.BlankLine()
            .AppendFormat("const System_Char _stringTable[{0}] =", length)
            .BracketOpen();
            sb.Append(jump == 0 ? "0" : stringTableContent);
            sb.BracketClose(true)
            .Append("; // _stringTable\n");

            return(sb.ToString());
        }
 public static void ToFile(this CodeOutput text, string fileName)
 {
     File.WriteAllText(fileName, text.ToString());
 }