mirror of
https://github.com/YosysHQ/yosys
synced 2025-04-23 09:05:32 +00:00
Changed backend-api from FILE to std::ostream
This commit is contained in:
parent
fff12c719f
commit
5dce303a2a
16 changed files with 710 additions and 725 deletions
|
@ -210,20 +210,14 @@ void log_dump_val_worker(RTLIL::SigSpec v) {
|
|||
|
||||
const char *log_signal(const RTLIL::SigSpec &sig, bool autoint)
|
||||
{
|
||||
char *ptr;
|
||||
size_t size;
|
||||
|
||||
FILE *f = open_memstream(&ptr, &size);
|
||||
ILANG_BACKEND::dump_sigspec(f, sig, autoint);
|
||||
fputc(0, f);
|
||||
fclose(f);
|
||||
std::stringstream buf;
|
||||
ILANG_BACKEND::dump_sigspec(buf, sig, autoint);
|
||||
|
||||
if (string_buf_size < 100)
|
||||
string_buf_size++;
|
||||
else
|
||||
string_buf.pop_front();
|
||||
string_buf.push_back(ptr);
|
||||
free(ptr);
|
||||
string_buf.push_back(buf.str());
|
||||
|
||||
return string_buf.back().c_str();
|
||||
}
|
||||
|
@ -239,16 +233,9 @@ const char *log_id(RTLIL::IdString str)
|
|||
|
||||
void log_cell(RTLIL::Cell *cell, std::string indent)
|
||||
{
|
||||
char *ptr;
|
||||
size_t size;
|
||||
|
||||
FILE *f = open_memstream(&ptr, &size);
|
||||
ILANG_BACKEND::dump_cell(f, indent, cell);
|
||||
fputc(0, f);
|
||||
fclose(f);
|
||||
|
||||
log("%s", ptr);
|
||||
free(ptr);
|
||||
std::stringstream buf;
|
||||
ILANG_BACKEND::dump_cell(buf, indent, cell);
|
||||
log("%s", buf.str().c_str());
|
||||
}
|
||||
|
||||
// ---------------------------------------------------
|
||||
|
|
|
@ -423,15 +423,15 @@ Backend::~Backend()
|
|||
|
||||
void Backend::execute(std::vector<std::string> args, RTLIL::Design *design)
|
||||
{
|
||||
FILE *f = NULL;
|
||||
std::ostream *f = NULL;
|
||||
auto state = pre_execute();
|
||||
execute(f, std::string(), args, design);
|
||||
post_execute(state);
|
||||
if (f != stdout)
|
||||
fclose(f);
|
||||
if (f != &std::cout)
|
||||
delete f;
|
||||
}
|
||||
|
||||
void Backend::extra_args(FILE *&f, std::string &filename, std::vector<std::string> args, size_t argidx)
|
||||
void Backend::extra_args(std::ostream *&f, std::string &filename, std::vector<std::string> args, size_t argidx)
|
||||
{
|
||||
bool called_with_fp = f != NULL;
|
||||
|
||||
|
@ -446,14 +446,18 @@ void Backend::extra_args(FILE *&f, std::string &filename, std::vector<std::strin
|
|||
|
||||
if (arg == "-") {
|
||||
filename = "<stdout>";
|
||||
f = stdout;
|
||||
f = &std::cout;
|
||||
continue;
|
||||
}
|
||||
|
||||
filename = arg;
|
||||
f = fopen(filename.c_str(), "w");
|
||||
if (f == NULL)
|
||||
std::ofstream *ff = new std::ofstream;
|
||||
ff->open(filename.c_str(), std::ofstream::trunc);
|
||||
if (ff->fail()) {
|
||||
delete ff;
|
||||
log_cmd_error("Can't open output file `%s' for writing: %s\n", filename.c_str(), strerror(errno));
|
||||
}
|
||||
f = ff;
|
||||
}
|
||||
|
||||
if (called_with_fp)
|
||||
|
@ -463,11 +467,11 @@ void Backend::extra_args(FILE *&f, std::string &filename, std::vector<std::strin
|
|||
|
||||
if (f == NULL) {
|
||||
filename = "<stdout>";
|
||||
f = stdout;
|
||||
f = &std::cout;
|
||||
}
|
||||
}
|
||||
|
||||
void Backend::backend_call(RTLIL::Design *design, FILE *f, std::string filename, std::string command)
|
||||
void Backend::backend_call(RTLIL::Design *design, std::ostream *f, std::string filename, std::string command)
|
||||
{
|
||||
std::vector<std::string> args;
|
||||
char *s = strdup(command.c_str());
|
||||
|
@ -477,7 +481,7 @@ void Backend::backend_call(RTLIL::Design *design, FILE *f, std::string filename,
|
|||
backend_call(design, f, filename, args);
|
||||
}
|
||||
|
||||
void Backend::backend_call(RTLIL::Design *design, FILE *f, std::string filename, std::vector<std::string> args)
|
||||
void Backend::backend_call(RTLIL::Design *design, std::ostream *f, std::string filename, std::vector<std::string> args)
|
||||
{
|
||||
if (args.size() == 0)
|
||||
return;
|
||||
|
@ -491,9 +495,9 @@ void Backend::backend_call(RTLIL::Design *design, FILE *f, std::string filename,
|
|||
backend_register[args[0]]->execute(f, filename, args, design);
|
||||
backend_register[args[0]]->post_execute(state);
|
||||
} else if (filename == "-") {
|
||||
FILE *f_stdout = stdout; // workaround for OpenBSD 'stdout' implementation
|
||||
std::ostream *f_cout = &std::cout;
|
||||
auto state = backend_register[args[0]]->pre_execute();
|
||||
backend_register[args[0]]->execute(f_stdout, "<stdout>", args, design);
|
||||
backend_register[args[0]]->execute(f_cout, "<stdout>", args, design);
|
||||
backend_register[args[0]]->post_execute(state);
|
||||
} else {
|
||||
if (!filename.empty())
|
||||
|
|
|
@ -17,15 +17,11 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include "kernel/yosys.h"
|
||||
|
||||
#ifndef REGISTER_H
|
||||
#define REGISTER_H
|
||||
|
||||
#include "kernel/yosys.h"
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
YOSYS_NAMESPACE_BEGIN
|
||||
|
||||
struct Pass
|
||||
|
@ -94,12 +90,12 @@ struct Backend : Pass
|
|||
virtual void run_register();
|
||||
virtual ~Backend();
|
||||
virtual void execute(std::vector<std::string> args, RTLIL::Design *design) OVERRIDE FINAL;
|
||||
virtual void execute(FILE *&f, std::string filename, std::vector<std::string> args, RTLIL::Design *design) = 0;
|
||||
virtual void execute(std::ostream *&f, std::string filename, std::vector<std::string> args, RTLIL::Design *design) = 0;
|
||||
|
||||
void extra_args(FILE *&f, std::string &filename, std::vector<std::string> args, size_t argidx);
|
||||
void extra_args(std::ostream *&f, std::string &filename, std::vector<std::string> args, size_t argidx);
|
||||
|
||||
static void backend_call(RTLIL::Design *design, FILE *f, std::string filename, std::string command);
|
||||
static void backend_call(RTLIL::Design *design, FILE *f, std::string filename, std::vector<std::string> args);
|
||||
static void backend_call(RTLIL::Design *design, std::ostream *f, std::string filename, std::string command);
|
||||
static void backend_call(RTLIL::Design *design, std::ostream *f, std::string filename, std::vector<std::string> args);
|
||||
};
|
||||
|
||||
// implemented in passes/cmds/select.cc
|
||||
|
|
|
@ -412,17 +412,12 @@ namespace {
|
|||
|
||||
void error(int linenr)
|
||||
{
|
||||
char *ptr;
|
||||
size_t size;
|
||||
|
||||
FILE *f = open_memstream(&ptr, &size);
|
||||
ILANG_BACKEND::dump_cell(f, " ", cell);
|
||||
fputc(0, f);
|
||||
fclose(f);
|
||||
std::stringstream buf;
|
||||
ILANG_BACKEND::dump_cell(buf, " ", cell);
|
||||
|
||||
log_error("Found error in internal cell %s%s%s (%s) at %s:%d:\n%s",
|
||||
module ? module->name.c_str() : "", module ? "." : "",
|
||||
cell->name.c_str(), cell->type.c_str(), __FILE__, linenr, ptr);
|
||||
cell->name.c_str(), cell->type.c_str(), __FILE__, linenr, buf.str().c_str());
|
||||
}
|
||||
|
||||
int param(const char *name)
|
||||
|
|
|
@ -45,6 +45,11 @@
|
|||
#include <functional>
|
||||
#include <initializer_list>
|
||||
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <ostream>
|
||||
#include <iostream>
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue