Removed compatbility.{h,cc}: Not using open_memstream/fmemopen anymore
authorClifford Wolf <clifford@clifford.at>
Sat, 23 Aug 2014 13:14:58 +0000 (15:14 +0200)
committerClifford Wolf <clifford@clifford.at>
Sat, 23 Aug 2014 13:14:58 +0000 (15:14 +0200)
Makefile
frontends/verilog/verilog_frontend.cc
kernel/compatibility.cc [deleted file]
kernel/compatibility.h [deleted file]
kernel/log.cc
kernel/log.h
kernel/register.cc
kernel/yosys.h

index ca595d9cd1c362410aa28a6e0ee7f034802064a0..3275706317b7424e7ed0db25d3a002ce6c5d7046 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -133,8 +133,7 @@ Q =
 S =
 endif
 
-OBJS += kernel/driver.o kernel/register.o kernel/rtlil.o kernel/log.o kernel/calc.o
-OBJS += kernel/compatibility.o kernel/yosys.o
+OBJS += kernel/driver.o kernel/register.o kernel/rtlil.o kernel/log.o kernel/calc.o kernel/yosys.o
 
 OBJS += libs/bigint/BigIntegerAlgorithms.o libs/bigint/BigInteger.o libs/bigint/BigIntegerUtils.o
 OBJS += libs/bigint/BigUnsigned.o libs/bigint/BigUnsignedInABase.o
index c63fbb08a66783a3fba7d0af5889c8aa65b3125b..c6d4a0b7907365e2e9b90541d46b93df35fcfc5c 100644 (file)
  */
 
 #include "verilog_frontend.h"
-#include "kernel/compatibility.h"
-#include "kernel/register.h"
-#include "kernel/log.h"
+#include "kernel/yosys.h"
 #include "libs/sha1/sha1.h"
-#include <sstream>
 #include <stdarg.h>
 
 YOSYS_NAMESPACE_BEGIN
diff --git a/kernel/compatibility.cc b/kernel/compatibility.cc
deleted file mode 100644 (file)
index 4c4cbd6..0000000
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- *  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.
- *
- */
-
-/**
- *  POSIX.2008 fake implementation for pre-POSIX.2008 systems. (OSX, BSD, MINGW, CYGWIN, older Linux &c.)
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-
-#if !(_XOPEN_SOURCE >= 700 || _POSIX_C_SOURCE >= 200809L || defined(EMSCRIPTEN))
-
-typedef struct memstream {
-       off_t pos;
-       off_t size;
-       char * buffer;
-       char ** bufp;
-       size_t * sizep;
-       bool realloc;
-} memstream_t;
-
-static int memstream_read (void * cookie, char * buf, int size)
-{
-       memstream_t * mem = (memstream_t *) cookie;
-       off_t available = mem->size - mem->pos;
-       if (available < 0)
-               available = 0;
-       if (size > available)
-               size = available;
-       memcpy(buf, mem->buffer + mem->pos, size);
-       mem->pos += size;
-       return size;
-}
-
-static int memstream_write (void * cookie, const char * buf, int size)
-{
-       memstream_t * mem = (memstream_t *) cookie;
-       off_t available = mem->size - mem->pos;
-       if (size > available) {
-               if (mem->realloc) {
-                       mem->buffer = (char *) realloc(mem->buffer, mem->pos + size + 1);
-                       memset(mem->buffer + mem->size, 0, mem->pos + size + 1 - mem->size);
-                       mem->size = mem->pos + size;
-                       if (mem->bufp)
-                               *(mem->bufp) = mem->buffer;
-                       if (mem->sizep)
-                               *(mem->sizep) = mem->size;
-               } else {
-                       size = available;
-               }
-       }
-       memcpy(mem->buffer + mem->pos, buf, sizeof(char) * size);
-       mem->pos += size;
-       return size;
-}
-
-static fpos_t memstream_seek (void * cookie, fpos_t offset, int whence)
-{
-       memstream_t * mem = (memstream_t *) cookie;
-       switch (whence) {
-       case SEEK_SET:
-               if (offset < 0)
-                       goto error_inval;
-               mem->pos = offset;
-               return 0;
-       case SEEK_CUR:
-               if (mem->pos + offset < 0)
-                       goto error_inval;
-               mem->pos += offset;
-               return 0;
-       case SEEK_END:
-               if (mem->size + offset < 0)
-                       goto error_inval;
-               mem->pos = mem->size + offset;
-               break;
-       default:
-               goto error_inval;
-       }
-       return mem->pos;
-error_inval:
-       errno = EINVAL;
-       return -1;
-}
-
-static int memstream_close (void * cookie)
-{
-       memstream_t * mem = (memstream_t *) cookie;
-       if (mem->bufp)
-               *(mem->bufp) = mem->buffer;
-       if (mem->sizep)
-               *(mem->sizep) = mem->size;
-       free(cookie);
-       return 0;
-}
-
-FILE * compat_fmemopen (void * buf, size_t size, const char * mode)
-{
-       memstream_t * mem = (memstream_t *) malloc(sizeof(memstream_t));
-       memset(mem, 0, sizeof(memstream_t));
-       mem->size = size;
-       mem->buffer = (char *) buf;
-       (void) mode;
-       return funopen(mem, memstream_read, memstream_write, memstream_seek, memstream_close);
-}
-
-FILE * compat_open_memstream (char ** bufp, size_t * sizep)
-{
-       memstream_t * mem = (memstream_t *) malloc(sizeof(memstream_t));
-       memset(mem, 0, sizeof(memstream_t));
-       mem->bufp = bufp;
-       mem->sizep = sizep;
-       mem->realloc = true;
-       return funopen(mem, memstream_read, memstream_write, memstream_seek, memstream_close);
-}
-
-#endif /* !(_XOPEN_SOURCE >= 700 || _POSIX_C_SOURCE >= 200809L) */
-
diff --git a/kernel/compatibility.h b/kernel/compatibility.h
deleted file mode 100644 (file)
index c7603c8..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- *  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.
- *
- */
-
-#ifndef COMPATIBILITY_H
-#define COMPATIBILITY_H
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#if !(_XOPEN_SOURCE >= 700 || _POSIX_C_SOURCE >= 200809L)
-
-#define open_memstream compat_open_memstream
-#define fmemopen compat_fmemopen
-
-FILE * compat_open_memstream (char ** bufp, size_t * sizep);
-FILE * compat_fmemopen (void * buf, size_t size, const char * mode);
-
-#endif /* !(_XOPEN_SOURCE >= 700 || _POSIX_C_SOURCE >= 200809L) */
-
-#endif /* COMPATIBILITY_H */
-
index 2b4b5db5bf9d5ea17c5193203ef2162606ab29a2..1b0eb6649f1616260c01636cd558ddbfd5fd4ee9 100644 (file)
@@ -32,6 +32,7 @@
 YOSYS_NAMESPACE_BEGIN
 
 std::vector<FILE*> log_files;
+std::vector<std::ostream*> log_streams;
 FILE *log_errfile = NULL;
 SHA1 *log_hasher = NULL;
 
@@ -92,10 +93,16 @@ void logv(const char *format, va_list ap)
 
                for (auto f : log_files)
                        fputs(time_str.c_str(), f);
+
+               for (auto f : log_streams)
+                       *f << time_str;
        }
 
        for (auto f : log_files)
                fputs(str.c_str(), f);
+
+       for (auto f : log_streams)
+               *f << str;
 }
 
 void logv_header(const char *format, va_list ap)
@@ -202,6 +209,9 @@ void log_flush()
 {
        for (auto f : log_files)
                fflush(f);
+
+       for (auto f : log_streams)
+               f->flush();
 }
 
 void log_dump_val_worker(RTLIL::SigSpec v) {
index b1c44b46b6fd4b82b3a53b892d595df612b62b36..e2b4db87b5e668d639d67babc57e7cb50bad4eff 100644 (file)
@@ -35,6 +35,7 @@ YOSYS_NAMESPACE_BEGIN
 struct log_cmd_error_expection { };
 
 extern std::vector<FILE*> log_files;
+extern std::vector<std::ostream*> log_streams;
 extern FILE *log_errfile;
 extern class SHA1 *log_hasher;
 
index 5f4e71d1f52ae3ba4565a02b95251d1f72c1481a..a53bd84c7e1ab6940d4f00eefb59b46f70e9d738 100644 (file)
@@ -612,15 +612,11 @@ struct HelpPass : public Pass {
                                FILE *f = fopen("command-reference-manual.tex", "wt");
                                fprintf(f, "%% Generated using the yosys 'help -write-tex-command-reference-manual' command.\n\n");
                                for (auto &it : pass_register) {
-                                       size_t memsize;
-                                       char *memptr;
-                                       FILE *memf = open_memstream(&memptr, &memsize);
-                                       log_files.push_back(memf);
+                                       std::ostringstream buf;
+                                       log_streams.push_back(&buf);
                                        it.second->help();
-                                       log_files.pop_back();
-                                       fclose(memf);
-                                       write_tex(f, it.first, it.second->short_help, memptr);
-                                       free(memptr);
+                                       log_streams.pop_back();
+                                       write_tex(f, it.first, it.second->short_help, buf.str());
                                }
                                fclose(f);
                        }
@@ -628,15 +624,11 @@ struct HelpPass : public Pass {
                        else if (args[1] == "-write-web-command-reference-manual") {
                                FILE *f = fopen("templates/cmd_index.in", "wt");
                                for (auto &it : pass_register) {
-                                       size_t memsize;
-                                       char *memptr;
-                                       FILE *memf = open_memstream(&memptr, &memsize);
-                                       log_files.push_back(memf);
+                                       std::ostringstream buf;
+                                       log_streams.push_back(&buf);
                                        it.second->help();
-                                       log_files.pop_back();
-                                       fclose(memf);
-                                       write_html(f, it.first, it.second->short_help, memptr);
-                                       free(memptr);
+                                       log_streams.pop_back();
+                                       write_html(f, it.first, it.second->short_help, buf.str());
                                }
                                fclose(f);
                        }
index 87c99d1f6f51b9064b10d33af4f530373222c1c7..9a4826caa13170fac9e0f0e5cc833f1f3ac16431 100644 (file)
@@ -98,7 +98,6 @@ YOSYS_NAMESPACE_END
 #include "kernel/log.h"
 #include "kernel/rtlil.h"
 #include "kernel/register.h"
-#include "kernel/compatibility.h"
 
 YOSYS_NAMESPACE_BEGIN