summaryrefslogtreecommitdiffstats
path: root/src/tools/ccsc
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-02-24 18:42:24 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-02-24 18:42:24 +0000
commitf508189682b6fba62e08feeb1596f682bad5fff9 (patch)
tree28aeb0e6c19386c385c1ce5edf8a92c1bca15281 /src/tools/ccsc
downloadpiklab-f508189682b6fba62e08feeb1596f682bad5fff9.tar.gz
piklab-f508189682b6fba62e08feeb1596f682bad5fff9.zip
Added KDE3 version of PikLab
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/piklab@1095639 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'src/tools/ccsc')
-rw-r--r--src/tools/ccsc/Makefile.am8
-rw-r--r--src/tools/ccsc/ccsc.cpp106
-rw-r--r--src/tools/ccsc/ccsc.h57
-rw-r--r--src/tools/ccsc/ccsc_compile.cpp107
-rw-r--r--src/tools/ccsc/ccsc_compile.h37
-rw-r--r--src/tools/ccsc/ccsc_config.cpp9
-rw-r--r--src/tools/ccsc/ccsc_config.h25
-rw-r--r--src/tools/ccsc/gui/Makefile.am6
-rw-r--r--src/tools/ccsc/gui/ccsc_ui.cpp19
-rw-r--r--src/tools/ccsc/gui/ccsc_ui.h35
10 files changed, 409 insertions, 0 deletions
diff --git a/src/tools/ccsc/Makefile.am b/src/tools/ccsc/Makefile.am
new file mode 100644
index 0000000..e0d3844
--- /dev/null
+++ b/src/tools/ccsc/Makefile.am
@@ -0,0 +1,8 @@
+INCLUDES = -I$(top_srcdir)/src $(all_includes)
+METASOURCES = AUTO
+
+noinst_LTLIBRARIES = libccsc.la
+libccsc_la_LDFLAGS = $(all_libraries)
+libccsc_la_SOURCES = ccsc.cpp ccsc_compile.cpp ccsc_config.cpp
+
+SUBDIRS = gui \ No newline at end of file
diff --git a/src/tools/ccsc/ccsc.cpp b/src/tools/ccsc/ccsc.cpp
new file mode 100644
index 0000000..b28f29a
--- /dev/null
+++ b/src/tools/ccsc/ccsc.cpp
@@ -0,0 +1,106 @@
+/***************************************************************************
+ * Copyright (C) 2006-2007 Nicolas Hadacek <hadacek@kde.org> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ ***************************************************************************/
+#include "ccsc.h"
+
+#include <qregexp.h>
+
+#include "ccsc_compile.h"
+#include "ccsc_config.h"
+#include "devices/pic/pic/pic_memory.h"
+#include "devices/list/device_list.h"
+#include "devices/base/device_group.h"
+
+//----------------------------------------------------------------------------
+QStringList CCSC::Base::checkExecutableOptions(bool withWine) const
+{
+ QStringList args;
+ if (withWine) {
+ args += "+STDOUT";
+ args += "+FM";
+ args += static_cast<const Group *>(_group)->checkExecutableUrl().filename();
+ } else args += "+V";
+ return args;
+}
+
+PURL::Directory CCSC::Base::checkExecutableWorkingDirectory() const
+{
+ return static_cast<const Group *>(_group)->checkExecutableUrl().directory();
+}
+
+bool CCSC::Base::checkExecutableResult(bool withWine, QStringList &lines) const
+{
+ if (withWine) {
+ PURL::Url url = static_cast<const Group *>(_group)->checkExecutableUrl().toExtension("err");
+ Log::StringView sview;
+ PURL::File file(url, sview);
+ if ( !file.openForRead() ) {
+ url = static_cast<const Group *>(_group)->checkExecutableUrl().appendExtension("err");
+ file.setUrl(url);
+ if ( !file.openForRead() ) return false;
+ }
+ lines = file.readLines();
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
+CCSC::Group::Group()
+ : _checkExecTmp(_sview, ".c")
+{
+ if ( _checkExecTmp.openForWrite() ) _checkExecTmp.appendText("#include <16f877a.h>\nvoid main(void) {}\n");
+ _checkExecTmp.close();
+}
+
+QValueList<const Device::Data *> CCSC::Group::getSupportedDevices(const QString &) const
+{
+ QValueList<const Device::Data *> list;
+ QValueVector<QString> devices = Device::lister().group("pic")->supportedDevices();
+ for (uint i=0; i<devices.count(); i++) {
+ const Device::Data *data = Device::lister().data(devices[i]);
+ Pic::Architecture arch = static_cast<const Pic::Data *>(data)->architecture();
+ if ( arch==Pic::Architecture::P30F || arch==Pic::Architecture::P33F ) continue;
+ list.append(data);
+ }
+ return list;
+}
+
+Compile::Process *CCSC::Group::processFactory(const Compile::Data &data) const
+{
+ switch (data.category.type()) {
+ case Tool::Category::Compiler: return new CCSC::CompileFile;
+ default: break;
+ }
+ Q_ASSERT(false);
+ return 0;
+}
+
+Compile::Config *CCSC::Group::configFactory(::Project *project) const
+{
+ return new Config(project);
+}
+
+QString CCSC::Group::informationText() const
+{
+ return i18n("<a href=\"%1\">CCS Compiler</a> is a C compiler distributed by CCS.").arg("http://www.ccsinfo.com/content.php?page=compilers");
+}
+
+Tool::Group::BaseData CCSC::Group::baseFactory(Tool::Category category) const
+{
+ if ( category==Tool::Category::Compiler ) return BaseData(new CCSC::Base, Both);
+ return BaseData();
+}
+
+VersionData CCSC::Group::getToolchainVersion()
+{
+ if ( !Compile::Config::withWine(*this) ) {
+ QStringList lines;
+ if ( checkExecutable(Tool::Category::Compiler, lines) && lines.count()>=1 && lines[0].contains("3.") ) return VersionData(3, 0, 0);
+ }
+ return VersionData(4, 0, 0); // default
+}
diff --git a/src/tools/ccsc/ccsc.h b/src/tools/ccsc/ccsc.h
new file mode 100644
index 0000000..aef2005
--- /dev/null
+++ b/src/tools/ccsc/ccsc.h
@@ -0,0 +1,57 @@
+/***************************************************************************
+ * Copyright (C) 2006-2007 Nicolas Hadacek <hadacek@kde.org> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ ***************************************************************************/
+#ifndef CCSC_H
+#define CCSC_H
+
+#include "tools/base/tool_group.h"
+#include "common/gui/pfile_ext.h"
+
+namespace CCSC
+{
+//----------------------------------------------------------------------------
+class Base : public Tool::Base
+{
+public:
+ virtual QString baseExecutable(bool, Tool::OutputExecutableType) const { return "ccsc"; }
+
+private:
+ virtual QStringList checkExecutableOptions(bool withWine) const;
+ virtual bool checkExecutableResult(bool withWine, QStringList &lines) const;
+ virtual PURL::Directory checkExecutableWorkingDirectory() const;
+};
+
+//----------------------------------------------------------------------------
+class Group : public Tool::Group
+{
+public:
+ Group();
+ PURL::Url checkExecutableUrl() const { return _checkExecTmp.url(); }
+ virtual QString name() const { return "ccsc"; }
+ virtual QString label() const { return i18n("CCS Compiler"); }
+ virtual QString informationText() const;
+ virtual Tool::Category checkDevicesCategory() const { return Tool::Category::Nb_Types; }
+ virtual Tool::ExecutableType preferedExecutableType() const { return Tool::ExecutableType::Unix; }
+ virtual Tool::CompileType compileType() const { return Tool::SingleFile; }
+ virtual PURL::FileType implementationType(PURL::ToolType type) const { return (type==PURL::ToolType::Compiler ? PURL::CSource : PURL::Nb_FileTypes); }
+
+private:
+ Log::StringView _sview;
+ PURL::TempFile _checkExecTmp;
+
+ virtual QValueList<const Device::Data *> getSupportedDevices(const QString &s) const;
+ virtual Compile::Process *processFactory(const Compile::Data &data) const;
+ virtual Compile::Config *configFactory(::Project *project) const;
+ virtual BaseData baseFactory(Tool::Category) const;
+ virtual Tool::SourceGenerator *sourceGeneratorFactory() const { /*TODO*/ return 0; }
+ virtual VersionData getToolchainVersion();
+};
+
+} // namespace
+
+#endif
diff --git a/src/tools/ccsc/ccsc_compile.cpp b/src/tools/ccsc/ccsc_compile.cpp
new file mode 100644
index 0000000..56897e8
--- /dev/null
+++ b/src/tools/ccsc/ccsc_compile.cpp
@@ -0,0 +1,107 @@
+/***************************************************************************
+ * Copyright (C) 2006 Nicolas Hadacek <hadacek@kde.org> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ ***************************************************************************/
+#include "ccsc_compile.h"
+
+#include "ccsc.h"
+#include "common/global/pfile.h"
+#include "ccsc_config.h"
+#include "devices/list/device_list.h"
+#include "devices/pic/base/pic.h"
+
+QString CCSC::CompileFile::familyName() const
+{
+ const Pic::Data *pdata = static_cast<const Pic::Data *>(Device::lister().data(_data.device));
+ switch (pdata->architecture().type()) {
+ case Pic::Architecture::P10X: return "B";
+ case Pic::Architecture::P16X: return "M";
+ case Pic::Architecture::P17C: return "7";
+ case Pic::Architecture::P18C:
+ case Pic::Architecture::P18F:
+ case Pic::Architecture::P18J: return "H";
+ case Pic::Architecture::P24F:
+ case Pic::Architecture::P24H:
+ case Pic::Architecture::P30F:
+ case Pic::Architecture::P33F: break;
+ case Pic::Architecture::Nb_Types: break;
+ }
+ Q_ASSERT(false);
+ return QString::null;
+}
+
+QStringList CCSC::CompileFile::genericArguments(const Compile::Config &config) const
+{
+ bool isVersion3 = ( static_cast<const Group &>(Main::toolGroup()).version().majorNum()==3 );
+ QStringList args;
+ args += "+STDOUT"; // output messages on stdout
+ if ( !isVersion3 ) args += "+EA"; // show all messages and warnings
+ args += "-P"; // close compile windows after compilation done
+ if ( !isVersion3 ) args += "+DF"; // output COFF file
+ args += "+LSlst"; // normal list file
+ args += "+O8hex"; // produce 8bit Intel file
+ if ( !isVersion3 ) args += "+M"; // generate symbol file
+ args += "-J"; // do not create project file
+ args += "-A"; // do not create stat file
+ args += "+F%FAMILY";
+ if ( isVersion3 ) args += config.includeDirs(Tool::Category::Compiler, "I=\"", "\"");
+ else args += config.includeDirs(Tool::Category::Compiler, "I+=\"", "\"");
+ args += config.customOptions(Tool::Category::Compiler);
+ args += "%I";
+ return args;
+}
+
+void CCSC::CompileFile::logStderrLine(const QString &line)
+{
+ // ignore output for wine
+ if ( !Compile::Config::withWine(group()) ) parseLine(line);
+}
+
+void CCSC::CompileFile::parseLine(const QString &line)
+{
+ Log::LineType type;
+ if ( line.startsWith(">>>") ) type = Log::LineType::Warning;
+ else if ( line.startsWith("***") ) type = Log::LineType::Error;
+ else if ( line.startsWith("---") ) type = Log::LineType::Information;
+ else {
+ doLog(Log::LineType::Normal, line, QString::null, 0); // unrecognized
+ return;
+ }
+ if ( parseErrorLine(line, Compile::ParseErrorData("[*>-]+\\s\\w+\\s\\d+\\s\"([^\"]*)\"\\sLine\\s(\\d+)\\([^)]*\\):(.*)", 1, 2, 3, type)) ) return;
+ if ( parseErrorLine(line, Compile::ParseErrorData("[*>-]+\\s\"([^\"]*)\"\\sLine\\s(\\d+):\\s\\w+\\s#\\d+:(.*)", 1, 2, 3, type)) ) return;
+ doLog(type, line, QString::null, 0);
+}
+
+void CCSC::CompileFile::done(int code)
+{
+ // with wine, rely on error file
+ if ( Compile::Config::withWine(group()) ) {
+ PURL::Url url = PURL::Url(directory(), inputFilepath(0)).toExtension("err");
+ Log::StringView sview;
+ PURL::File file(url, sview);
+ if ( !file.openForRead() ) doLog(Log::LineType::Error, i18n("Could not find error file (%1).").arg(url.pretty()), QString::null, 0);
+ else {
+ QStringList lines = file.readLines();
+ for (uint i=0; i<lines.count(); i++) parseLine(lines[i]);
+ }
+ }
+ Compile::Process::done(code);
+}
+
+PURL::Url CCSC::CompileFile::url(PURL::FileType type, uint i) const
+{
+ PURL::Url url;
+ Q_ASSERT( i<_data.items.count() );
+ url = _data.items[i].url;
+ if ( type==PURL::Nb_FileTypes ) return url;
+ return url.toFileType(type);
+}
+
+QString CCSC::CompileFile::outputFiles() const
+{
+ return "PURL::Lst PURL::Hex PURL::Coff PURL::Cod sym err esym occ";
+}
diff --git a/src/tools/ccsc/ccsc_compile.h b/src/tools/ccsc/ccsc_compile.h
new file mode 100644
index 0000000..ddf8f20
--- /dev/null
+++ b/src/tools/ccsc/ccsc_compile.h
@@ -0,0 +1,37 @@
+/***************************************************************************
+ * Copyright (C) 2006 Nicolas Hadacek <hadacek@kde.org> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ ***************************************************************************/
+#ifndef CCSC_COMPILE_H
+#define CCSC_COMPILE_H
+
+#include "tools/list/compile_process.h"
+
+namespace CCSC
+{
+
+class CompileFile : public Compile::Process
+{
+Q_OBJECT
+protected:
+ virtual QString deviceName() const { return QString::null; }
+ virtual QString familyName() const;
+ virtual QStringList genericArguments(const Compile::Config &config) const;
+ virtual void logStderrLine(const QString &line);
+ virtual QString outputFiles() const;
+ virtual PURL::Url url(PURL::FileType type = PURL::Nb_FileTypes, uint i = 0) const;
+
+protected slots:
+ virtual void done(int code);
+
+private:
+ void parseLine(const QString &line);
+};
+
+} // namespace
+
+#endif
diff --git a/src/tools/ccsc/ccsc_config.cpp b/src/tools/ccsc/ccsc_config.cpp
new file mode 100644
index 0000000..333bc14
--- /dev/null
+++ b/src/tools/ccsc/ccsc_config.cpp
@@ -0,0 +1,9 @@
+/***************************************************************************
+ * Copyright (C) 2006 Nicolas Hadacek <hadacek@kde.org> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ ***************************************************************************/
+#include "ccsc_config.h"
diff --git a/src/tools/ccsc/ccsc_config.h b/src/tools/ccsc/ccsc_config.h
new file mode 100644
index 0000000..f4ddef6
--- /dev/null
+++ b/src/tools/ccsc/ccsc_config.h
@@ -0,0 +1,25 @@
+/***************************************************************************
+ * Copyright (C) 2006 Nicolas Hadacek <hadacek@kde.org> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ ***************************************************************************/
+#ifndef CCSC_CONFIG_H
+#define CCSC_CONFIG_H
+
+#include "tools/list/compile_config.h"
+
+namespace CCSC
+{
+
+class Config : public Compile::Config
+{
+public:
+ Config(Project *project) : Compile::Config(project) {}
+};
+
+} // namespace
+
+#endif
diff --git a/src/tools/ccsc/gui/Makefile.am b/src/tools/ccsc/gui/Makefile.am
new file mode 100644
index 0000000..e3703bb
--- /dev/null
+++ b/src/tools/ccsc/gui/Makefile.am
@@ -0,0 +1,6 @@
+INCLUDES = -I$(top_srcdir)/src $(all_includes)
+METASOURCES = AUTO
+
+noinst_LTLIBRARIES = libccscui.la
+libccscui_la_LDFLAGS = $(all_libraries)
+libccscui_la_SOURCES = ccsc_ui.cpp
diff --git a/src/tools/ccsc/gui/ccsc_ui.cpp b/src/tools/ccsc/gui/ccsc_ui.cpp
new file mode 100644
index 0000000..eb2a900
--- /dev/null
+++ b/src/tools/ccsc/gui/ccsc_ui.cpp
@@ -0,0 +1,19 @@
+/***************************************************************************
+ * Copyright (C) 2006 Nicolas Hadacek <hadacek@kde.org> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ ***************************************************************************/
+#include "ccsc_ui.h"
+
+//----------------------------------------------------------------------------
+CCSC::ConfigWidget::ConfigWidget(Project *project)
+ : ToolConfigWidget(project)
+{}
+
+void CCSC::ConfigWidget::initEntries()
+{
+ if ( _category!=Tool::Category::Linker ) createIncludeDirectoriesEntry();
+}
diff --git a/src/tools/ccsc/gui/ccsc_ui.h b/src/tools/ccsc/gui/ccsc_ui.h
new file mode 100644
index 0000000..356cf22
--- /dev/null
+++ b/src/tools/ccsc/gui/ccsc_ui.h
@@ -0,0 +1,35 @@
+/***************************************************************************
+ * Copyright (C) 2006 Nicolas Hadacek <hadacek@kde.org> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ ***************************************************************************/
+#ifndef CCSC_UI_H
+#define CCSC_UI_H
+
+#include "tools/gui/tool_config_widget.h"
+#include "tools/gui/tool_group_ui.h"
+
+namespace CCSC
+{
+//----------------------------------------------------------------------------
+class ConfigWidget : public ToolConfigWidget
+{
+Q_OBJECT
+public:
+ ConfigWidget(Project *project);
+ virtual void initEntries();
+};
+
+//----------------------------------------------------------------------------
+class GroupUI : public Tool::GroupUI
+{
+public:
+ virtual ToolConfigWidget *configWidgetFactory(Tool::Category, ::Project *project) const { return new ConfigWidget(project); }
+};
+
+} // namespace
+
+#endif