/// <summary> /// Compile routine. Used to compile the CSharp code /// </summary> /// <param name="projectDir"></param> public static void Compile(string projectDir, CompilerFlags flags) { // Obtain the source code from the project Program file. string sourceCodeText = ReadSourceFile(projectDir + "\\Program.cs"); // Parse the source code into a syntax tree. CSharpSyntaxTree syntaxTree = Parse(sourceCodeText); // Get the root node of the syntax tree CSharpSyntaxNode rootNode = syntaxTree.GetRoot(); // Generate output or serialize compile unit // if (flags.GenerateOutput) { StringBuilder sourceCode = CPPCodeGenerator.GenerateCode(rootNode); if (flags.ArduinoSketch) { System.IO.Directory.CreateDirectory(projectDir + "\\arduino\\program"); AddSketch(sourceCode, "BlinkSample", "Program", "Main"); System.IO.File.WriteAllText(projectDir + "\\arduino\\program\\program.ino", sourceCode.ToString()); } else { System.IO.Directory.CreateDirectory(projectDir + "\\src"); AddMainEntry(sourceCode, "BlinkSample", "Program", "Main"); System.IO.File.WriteAllText(projectDir + "\\src\\program.cpp", sourceCode.ToString()); } } else { rootNode.SerializeTo(System.IO.File.OpenWrite(projectDir + "\\out\\out.cu")); } }
/// <summary> /// Determines if the provided type is a C++ built-in type. /// </summary> /// <param name="typeSyntax"></param> /// <param name="generator"></param> /// <returns></returns> public static bool IsBuiltinType(TypeSyntax typeSyntax, CPPCodeGenerator generator) { string type_name = typeSyntax.Accept(generator).ToString(); return(builtinTypes.Contains(type_name)); }