2014-07-30 07:10:15 -05:00
|
|
|
/*
|
|
|
|
* yosys -- Yosys Open SYnthesis Suite
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Clifford Wolf <clifford@clifford.at>
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
// *** NOTE TO THE READER ***
|
|
|
|
//
|
|
|
|
// Maybe you have just opened this file in the hope to learn more about the
|
|
|
|
// Yosys API. Let me congratulate you on this great decision! ;)
|
|
|
|
//
|
|
|
|
// If you want to know how the design is represented by Yosys in the memory,
|
|
|
|
// you should read "kernel/rtlil.h".
|
|
|
|
//
|
|
|
|
// If you want to know how to register a command with Yosys, you could read
|
|
|
|
// "kernel/register.h", but it would be easier to just look at a simple
|
|
|
|
// example instead. A simple one would be "passes/cmds/log.cc".
|
2014-07-31 06:19:47 -05:00
|
|
|
//
|
|
|
|
// This header is very boring. It just defines some general things that
|
|
|
|
// belong nowhere else and includes the interesting headers.
|
2014-09-16 04:26:44 -05:00
|
|
|
//
|
|
|
|
// Find more information in the "CodingReadme" file.
|
2014-07-30 07:10:15 -05:00
|
|
|
|
|
|
|
|
|
|
|
#ifndef YOSYS_H
|
|
|
|
#define YOSYS_H
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <set>
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
2014-07-31 06:19:47 -05:00
|
|
|
#include <algorithm>
|
2014-08-16 17:56:47 -05:00
|
|
|
#include <functional>
|
2014-12-26 03:53:21 -06:00
|
|
|
#include <unordered_map>
|
|
|
|
#include <unordered_set>
|
2014-07-30 07:10:15 -05:00
|
|
|
#include <initializer_list>
|
2014-08-02 08:44:10 -05:00
|
|
|
|
2014-08-23 06:54:21 -05:00
|
|
|
#include <sstream>
|
|
|
|
#include <fstream>
|
2014-08-23 08:03:55 -05:00
|
|
|
#include <istream>
|
2014-08-23 06:54:21 -05:00
|
|
|
#include <ostream>
|
|
|
|
#include <iostream>
|
|
|
|
|
2014-08-01 12:43:28 -05:00
|
|
|
#include <stdarg.h>
|
2014-08-02 08:44:10 -05:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2014-10-17 07:01:47 -05:00
|
|
|
#include <stdint.h>
|
2014-08-02 08:44:10 -05:00
|
|
|
#include <stdio.h>
|
2014-07-30 07:10:15 -05:00
|
|
|
|
2014-10-14 18:18:31 -05:00
|
|
|
#ifndef _YOSYS_
|
2014-10-17 08:51:33 -05:00
|
|
|
# error It looks like you are trying to build Yosys without the config defines set. \
|
2014-10-14 18:18:31 -05:00
|
|
|
When building Yosys with a custom make system, make sure you set all the \
|
2014-10-17 08:51:33 -05:00
|
|
|
defines the Yosys Makefile would set for your build configuration.
|
2014-10-14 18:18:31 -05:00
|
|
|
#endif
|
|
|
|
|
2014-10-12 05:18:38 -05:00
|
|
|
#ifdef YOSYS_ENABLE_TCL
|
|
|
|
# include <tcl.h>
|
|
|
|
#endif
|
|
|
|
|
2014-10-16 11:06:54 -05:00
|
|
|
#ifdef _WIN32
|
2014-10-17 07:01:47 -05:00
|
|
|
# undef NOMINMAX
|
|
|
|
# define NOMINMAX 1
|
|
|
|
# undef YY_NO_UNISTD_H
|
|
|
|
# define YY_NO_UNISTD_H 1
|
|
|
|
|
2014-10-17 05:04:40 -05:00
|
|
|
# include <windows.h>
|
2014-10-16 11:06:54 -05:00
|
|
|
# include <io.h>
|
|
|
|
# include <direct.h>
|
|
|
|
|
|
|
|
# define strtok_r strtok_s
|
|
|
|
# define strdup _strdup
|
|
|
|
# define snprintf _snprintf
|
|
|
|
# define getcwd _getcwd
|
|
|
|
# define mkdir _mkdir
|
|
|
|
# define popen _popen
|
|
|
|
# define pclose _pclose
|
|
|
|
# define PATH_MAX MAX_PATH
|
2014-10-17 08:51:33 -05:00
|
|
|
|
|
|
|
# ifndef __MINGW32__
|
|
|
|
# define isatty _isatty
|
|
|
|
# define fileno _fileno
|
|
|
|
# endif
|
2014-10-16 11:06:54 -05:00
|
|
|
#endif
|
|
|
|
|
2014-07-31 08:02:16 -05:00
|
|
|
#define PRIVATE_NAMESPACE_BEGIN namespace {
|
|
|
|
#define PRIVATE_NAMESPACE_END }
|
2014-09-27 09:17:53 -05:00
|
|
|
#define YOSYS_NAMESPACE_BEGIN namespace Yosys {
|
|
|
|
#define YOSYS_NAMESPACE_END }
|
|
|
|
#define YOSYS_NAMESPACE_PREFIX Yosys::
|
|
|
|
#define USING_YOSYS_NAMESPACE using namespace Yosys;
|
2014-07-30 07:10:15 -05:00
|
|
|
|
2014-08-07 15:37:01 -05:00
|
|
|
#if __cplusplus >= 201103L
|
2014-11-09 03:55:04 -06:00
|
|
|
# define YS_OVERRIDE override
|
|
|
|
# define YS_FINAL final
|
2014-08-07 15:37:01 -05:00
|
|
|
#else
|
2014-11-09 03:55:04 -06:00
|
|
|
# define YS_OVERRIDE
|
|
|
|
# define YS_FINAL
|
2014-08-07 15:37:01 -05:00
|
|
|
#endif
|
|
|
|
|
2014-11-09 03:55:04 -06:00
|
|
|
#if defined(__GNUC__) || defined(__clang__)
|
|
|
|
# define YS_ATTRIBUTE(...) __attribute__((__VA_ARGS__))
|
|
|
|
# define YS_NORETURN
|
|
|
|
#elif defined(_MSC_VER)
|
|
|
|
# define YS_ATTRIBUTE(...)
|
|
|
|
# define YS_NORETURN __declspec(noreturn)
|
2014-10-16 11:06:54 -05:00
|
|
|
#else
|
2014-11-09 03:55:04 -06:00
|
|
|
# define YS_ATTRIBUTE(...)
|
|
|
|
# define YS_NORETURN
|
2014-10-14 17:56:04 -05:00
|
|
|
#endif
|
|
|
|
|
2014-07-30 07:10:15 -05:00
|
|
|
YOSYS_NAMESPACE_BEGIN
|
|
|
|
|
2014-12-26 03:53:21 -06:00
|
|
|
template <class Key, class T, class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>>
|
|
|
|
using dict = std::unordered_map<Key, T, Hash, KeyEqual>;
|
|
|
|
|
|
|
|
template <class Key, class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>>
|
|
|
|
using nodict = std::unordered_set<Key, Hash, KeyEqual>;
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
using vector = std::vector<T>;
|
|
|
|
|
2014-08-01 09:53:15 -05:00
|
|
|
namespace RTLIL {
|
2014-08-01 17:45:25 -05:00
|
|
|
struct IdString;
|
2014-12-26 03:53:21 -06:00
|
|
|
struct SigBit;
|
2014-08-01 09:53:15 -05:00
|
|
|
struct SigSpec;
|
|
|
|
struct Wire;
|
|
|
|
struct Cell;
|
|
|
|
}
|
|
|
|
|
2014-11-09 03:55:04 -06:00
|
|
|
std::string stringf(const char *fmt, ...) YS_ATTRIBUTE(format(printf, 1, 2));
|
2014-08-01 12:43:28 -05:00
|
|
|
std::string vstringf(const char *fmt, va_list ap);
|
2014-10-23 03:47:21 -05:00
|
|
|
int readsome(std::istream &f, char *s, int n);
|
2014-10-10 11:33:55 -05:00
|
|
|
std::string next_token(std::string &text, const char *sep);
|
2014-10-10 11:19:00 -05:00
|
|
|
bool patmatch(const char *pattern, const char *string);
|
2014-10-12 03:57:15 -05:00
|
|
|
int run_command(const std::string &command, std::function<void(const std::string&)> process_line = std::function<void(const std::string&)>());
|
2014-10-12 05:11:57 -05:00
|
|
|
std::string make_temp_file(std::string template_str = "/tmp/yosys_XXXXXX");
|
|
|
|
std::string make_temp_dir(std::string template_str = "/tmp/yosys_XXXXXX");
|
2014-10-17 07:01:47 -05:00
|
|
|
bool check_file_exists(std::string filename, bool is_exec = false);
|
2014-10-12 05:11:57 -05:00
|
|
|
void remove_directory(std::string dirname);
|
2014-10-10 11:19:00 -05:00
|
|
|
|
2014-10-10 09:59:44 -05:00
|
|
|
template<typename T> int GetSize(const T &obj) { return obj.size(); }
|
|
|
|
int GetSize(RTLIL::Wire *wire);
|
2014-07-30 07:10:15 -05:00
|
|
|
|
|
|
|
YOSYS_NAMESPACE_END
|
|
|
|
|
|
|
|
#include "kernel/log.h"
|
|
|
|
#include "kernel/rtlil.h"
|
|
|
|
#include "kernel/register.h"
|
|
|
|
|
|
|
|
YOSYS_NAMESPACE_BEGIN
|
|
|
|
|
2014-07-31 06:19:47 -05:00
|
|
|
void yosys_setup();
|
|
|
|
void yosys_shutdown();
|
|
|
|
|
2014-07-30 07:10:15 -05:00
|
|
|
#ifdef YOSYS_ENABLE_TCL
|
2014-07-31 06:19:47 -05:00
|
|
|
Tcl_Interp *yosys_get_tcl_interp();
|
2014-07-30 07:10:15 -05:00
|
|
|
#endif
|
|
|
|
|
2014-07-31 06:19:47 -05:00
|
|
|
extern int autoidx;
|
|
|
|
extern RTLIL::Design *yosys_design;
|
|
|
|
|
|
|
|
RTLIL::IdString new_id(std::string file, int line, std::string func);
|
|
|
|
|
|
|
|
#define NEW_ID \
|
|
|
|
YOSYS_NAMESPACE_PREFIX new_id(__FILE__, __LINE__, __FUNCTION__)
|
|
|
|
|
2014-08-03 07:59:13 -05:00
|
|
|
#define ID(_str) \
|
|
|
|
([]() { static YOSYS_NAMESPACE_PREFIX RTLIL::IdString _id(_str); return _id; })()
|
|
|
|
|
2014-07-31 06:19:47 -05:00
|
|
|
RTLIL::Design *yosys_get_design();
|
|
|
|
std::string proc_self_dirname();
|
|
|
|
std::string proc_share_dirname();
|
|
|
|
const char *create_prompt(RTLIL::Design *design, int recursion_counter);
|
|
|
|
|
|
|
|
void run_frontend(std::string filename, std::string command, RTLIL::Design *design, std::string *backend_command, std::string *from_to_label);
|
|
|
|
void run_pass(std::string command, RTLIL::Design *design);
|
|
|
|
void run_backend(std::string filename, std::string command, RTLIL::Design *design);
|
|
|
|
void shell(RTLIL::Design *design);
|
|
|
|
|
2014-07-30 07:10:15 -05:00
|
|
|
// from kernel/version_*.o (cc source generated from Makefile)
|
|
|
|
extern const char *yosys_version_str;
|
|
|
|
|
|
|
|
// from passes/cmds/design.cc
|
|
|
|
extern std::map<std::string, RTLIL::Design*> saved_designs;
|
|
|
|
extern std::vector<RTLIL::Design*> pushed_designs;
|
|
|
|
|
2014-08-22 06:58:36 -05:00
|
|
|
// from passes/cmds/pluginc.cc
|
|
|
|
extern std::map<std::string, void*> loaded_plugins;
|
|
|
|
extern std::map<std::string, std::string> loaded_plugin_aliases;
|
|
|
|
void load_plugin(std::string filename, std::vector<std::string> aliases);
|
|
|
|
|
2014-07-30 07:10:15 -05:00
|
|
|
YOSYS_NAMESPACE_END
|
|
|
|
|
|
|
|
#endif
|