private static void SetCompiler(Board Board, ref CompilerSettings Options) { switch (Board) { case global::XIDE.Board.coco: case global::XIDE.Board.cocoDuino: Options.Flash = Flash.F256; Options.Chip = Chip.a3u; break; case global::XIDE.Board.Mini: case global::XIDE.Board.MiniDuino: Options.Chip = Chip.a4u; //Options.Flash = Flash.F32; Options.Flash = Flash.F128; break; case global::XIDE.Board.Ultra: Options.Flash = Flash.F128; Options.Chip = Chip.a1u; break; } switch (Board) { case global::XIDE.Board.Ultra: Options.BoardDefine = "ULTRA"; break; case global::XIDE.Board.MiniDuino: Options.BoardDefine = "MINI_DUINO"; break; case global::XIDE.Board.Mini: Options.BoardDefine = "MINI"; break; case global::XIDE.Board.cocoDuino: Options.BoardDefine = "COCO_DUINO"; break; case global::XIDE.Board.coco: Options.BoardDefine = "COCO"; break; } }
private static string GenerateMmcu(CompilerSettings Options) { string mmcu = "atxmega"; switch (Options.Flash) { case Flash.F128: mmcu += "128"; break; case Flash.F256: mmcu += "256"; break; case Flash.F32: mmcu += "32"; break; } switch (Options.Chip) { case Chip.a1u: mmcu += "a1u"; break; case Chip.a3u: mmcu += "a3u"; break; case Chip.a4u: mmcu += "a4u"; break; } return(mmcu); }
//const string[] CheckToolsPrograms = { "gcc", "objcopy" }; public static string Compile(string CompileFile, CompilerSettings Options) { //CheckTools(); string Output = ""; if (!File.Exists(Path.Combine("Tools", "libxboard.a"))) { Output += "Precompiled XBoard library not found! Compiling it first... "; Precompile(Options.Board); Output += "done\r\n"; } Output += "Compiling...\r\n"; if (!Directory.Exists("Temp")) { Directory.CreateDirectory("Temp"); } ClearDirectory("Temp"); CopyFiles(CompileFile); SetCompiler(Options.Board, ref Options); string mmcu = GenerateMmcu(Options); string gcc = InvokeGcc("-funsigned-char -funsigned-bitfields " + (Options.Optimalize == Optimalize.Size ? "-Os" : "-O3") + " -fpack-struct -fshort-enums -ffunction-sections -mshort-calls -g0 -Wall -o \"" + Path.GetFullPath(Path.Combine("Temp", "Output.o")) + "\" -Wl,-lm " + " -I \"" + Path.Combine(Path.GetFullPath("."), "Libs") + "\" -D_XBOARD_" + Options.BoardDefine + "_ " + "-Wl,--gc-sections -mmcu=" + mmcu + " \"" + Path.GetFullPath(Path.Combine("Temp", "Code.c")) + "\" " + "\"" + Path.GetFullPath(Path.Combine("Temp", "Main.c")) + "\" -L \"" + Path.GetFullPath("Tools") + "\" -lxboard"); if (File.Exists(Path.Combine("Temp", "Output.o"))) { Output += "Compilation OK. Getting binary content..."; string objcopy = InvokeObjcopy("-O binary -R .eeprom -R .fuse -R .lock -R .signature \"" + Path.GetFullPath(Path.Combine("Temp", "Output.o")) + "\" \"" + Path.GetFullPath(Path.Combine("Temp", "Flash.bin")) + "\""); if (File.Exists(Path.Combine("Temp", "Flash.bin"))) { if (Options.OutputDisassembly) { InvokeObjdump("-h -S \"" + Path.GetFullPath(Path.Combine("Temp", "Output.o")) + "\""); } Output += "\r\nBinary extracted. File size: " + new FileInfo(Path.Combine("Temp", "Flash.bin")).Length + "B"; } else { Output += "\r\nFailed getting binary image!\r\n\r\n" + objcopy; } } else { Output += "Compilation failed!\r\n"; // remove file path from the gcc output and move it by lines(Header.c) up gcc = gcc.Replace(Path.GetFullPath(Path.Combine("Temp", "Code.c")) + ":", "> "); gcc = Regex.Replace(gcc, @"\d+:\d+: error", m => { return("Line " + (Convert.ToInt32(m.Groups[0].Value.ToString().Split(':')[0]) - 3).ToString() /* + ":" + (m.Groups[0].Value.ToString().Split(':')[1]).ToString()*/); }); Output += gcc; } return(Output); }
public static void Precompile(Board Board) { // Load XML XmlTextReader xml = new XmlTextReader(Path.Combine("Tools", "Libraries.xml")); xml.ReadStartElement("Libraries"); CompilerSettings Options = new CompilerSettings(); SetCompiler(Board, ref Options); string mmcu = GenerateMmcu(Options); Dictionary <string, List <string> > Libraries = new Dictionary <string, List <string> >(); string currentLib = ""; while (xml.Read()) { switch (xml.NodeType) { case XmlNodeType.Element: if (xml.Name == "Library") { currentLib = xml.GetAttribute("Name"); Libraries.Add(currentLib, new List <string>()); } break; case XmlNodeType.Text: Libraries[currentLib].Add(xml.Value); break; } } /*while (xml.Read()) * { * MessageBox.Show(xml.ReadContentAsString()); * }*/ xml.Close(); foreach (KeyValuePair <string, List <string> > Library in Libraries) { string FileList = ""; foreach (string file in Library.Value) { FileList += "\"" + Path.GetFullPath(Path.Combine("Libs", file)) + "\" "; } InvokeGcc("-ffunction-sections -mshort-calls -g0 -Wall -o \"" + Path.GetFullPath(Path.Combine("Temp", Library.Key + ".o")) + "\" -Wl,-lm -D_XBOARD_" + Options.BoardDefine + "_ -c -Wl,--gc-sections -mmcu=" + mmcu + " " + FileList + " -I \"" + Path.GetFullPath("Libs") + "\""); } string Libs = ""; foreach (KeyValuePair <string, List <string> > Library in Libraries) { Libs += "\"" + Path.GetFullPath(Path.Combine("Temp", Library.Key + ".o")) + "\" "; } InvokeAr("rcs \"" + Path.GetFullPath(Path.Combine("Tools", "libxboard.a")) + "\" " + Libs); }
//const string[] CheckToolsPrograms = { "gcc", "objcopy" }; public static string Compile(string CompileFile, CompilerSettings Options) { //CheckTools(); string Output = ""; if (!File.Exists(Path.Combine("Tools", "libxboard.a"))) { Output += "Precompiled XBoard library not found! Compiling it first... "; Precompile(Options.Board); Output += "done\r\n"; } Output += "Compiling...\r\n"; if(!Directory.Exists("Temp")) Directory.CreateDirectory("Temp"); ClearDirectory("Temp"); CopyFiles(CompileFile); SetCompiler(Options.Board, ref Options); string mmcu = GenerateMmcu(Options); string gcc = InvokeGcc("-funsigned-char -funsigned-bitfields " + (Options.Optimalize == Optimalize.Size ? "-Os" : "-O3") + " -fpack-struct -fshort-enums -ffunction-sections -mshort-calls -g0 -Wall -o \"" + Path.GetFullPath(Path.Combine("Temp", "Output.o")) + "\" -Wl,-lm " + " -I \"" + Path.Combine(Path.GetFullPath("."), "Libs") + "\" -D_XBOARD_" + Options.BoardDefine + "_ " + "-Wl,--gc-sections -mmcu=" + mmcu + " \"" + Path.GetFullPath(Path.Combine("Temp", "Code.c")) + "\" " + "\"" + Path.GetFullPath(Path.Combine("Temp", "Main.c")) + "\" -L \"" + Path.GetFullPath("Tools") + "\" -lxboard" ); if (File.Exists(Path.Combine("Temp", "Output.o"))) { Output += "Compilation OK. Getting binary content..."; string objcopy = InvokeObjcopy("-O binary -R .eeprom -R .fuse -R .lock -R .signature \"" + Path.GetFullPath(Path.Combine("Temp", "Output.o")) + "\" \"" + Path.GetFullPath(Path.Combine("Temp", "Flash.bin")) + "\""); if (File.Exists(Path.Combine("Temp", "Flash.bin"))) { if (Options.OutputDisassembly) InvokeObjdump("-h -S \"" + Path.GetFullPath(Path.Combine("Temp", "Output.o")) + "\""); Output += "\r\nBinary extracted. File size: " + new FileInfo(Path.Combine("Temp", "Flash.bin")).Length + "B"; } else { Output += "\r\nFailed getting binary image!\r\n\r\n" + objcopy; } } else { Output += "Compilation failed!\r\n"; // remove file path from the gcc output and move it by lines(Header.c) up gcc = gcc.Replace(Path.GetFullPath(Path.Combine("Temp", "Code.c")) + ":", "> "); gcc = Regex.Replace(gcc, @"\d+:\d+: error", m => { return "Line " + (Convert.ToInt32(m.Groups[0].Value.ToString().Split(':')[0]) - 3).ToString()/* + ":" + (m.Groups[0].Value.ToString().Split(':')[1]).ToString()*/; }); Output += gcc; } return Output; }
private static string GenerateMmcu(CompilerSettings Options) { string mmcu = "atxmega"; switch (Options.Flash) { case Flash.F128: mmcu += "128"; break; case Flash.F256: mmcu += "256"; break; case Flash.F32: mmcu += "32"; break; } switch (Options.Chip) { case Chip.a1u: mmcu += "a1u"; break; case Chip.a3u: mmcu += "a3u"; break; case Chip.a4u: mmcu += "a4u"; break; } return mmcu; }
public static void Precompile(Board Board) { // Load XML XmlTextReader xml = new XmlTextReader(Path.Combine("Tools", "Libraries.xml")); xml.ReadStartElement("Libraries"); CompilerSettings Options = new CompilerSettings(); SetCompiler(Board, ref Options); string mmcu = GenerateMmcu(Options); Dictionary<string, List<string>> Libraries = new Dictionary<string, List<string>>(); string currentLib = ""; while (xml.Read()) { switch (xml.NodeType) { case XmlNodeType.Element: if (xml.Name == "Library") { currentLib = xml.GetAttribute("Name"); Libraries.Add(currentLib, new List<string>()); } break; case XmlNodeType.Text: Libraries[currentLib].Add(xml.Value); break; } } /*while (xml.Read()) { MessageBox.Show(xml.ReadContentAsString()); }*/ xml.Close(); foreach (KeyValuePair<string, List<string>> Library in Libraries) { string FileList = ""; foreach (string file in Library.Value) FileList += "\"" + Path.GetFullPath(Path.Combine("Libs", file)) + "\" "; InvokeGcc("-ffunction-sections -mshort-calls -g0 -Wall -o \"" + Path.GetFullPath(Path.Combine("Temp", Library.Key + ".o")) + "\" -Wl,-lm -D_XBOARD_" + Options.BoardDefine + "_ -c -Wl,--gc-sections -mmcu=" + mmcu + " " + FileList + " -I \"" + Path.GetFullPath("Libs") + "\""); } string Libs = ""; foreach (KeyValuePair<string, List<string>> Library in Libraries) { Libs += "\"" + Path.GetFullPath(Path.Combine("Temp", Library.Key + ".o")) + "\" "; } InvokeAr("rcs \"" + Path.GetFullPath(Path.Combine("Tools", "libxboard.a")) + "\" " + Libs); }