<commit_before>/*
 * gvlog.c - A driver for verilog compiler ivl
 * Copyright (C) 1999 <NAME> (<EMAIL>)

 *   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.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the Free Software
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>


#ifndef LIBDIR
# define LIBDIR "/usr/local/lib"
#endif
#ifndef INCLUDEDIR
# define INCLUDEDIR "/usr/local/include"
#endif

const char VERSION[] = "$Name:  $ $State: Exp $";


#define P_IF_SET(var) var.set ? var.name : ""

/* Div compiler settings */
struct compset {
  char compsw[5];
  char name[50];
  int set;
};

/* cpp include path */
struct compset cppincdir = {"-I", INCLUDEDIR, 1};

/* cpp library path */
struct compset cpplibdir ={"-L", LIBDIR, 1};

/* VPI module path */
struct compset VPImodpath = {"-f", LIBDIR "/ivl", 1};

/* ivl include path */
struct compset ivlppincdir = {"-I", "", 0};

/* ivl defines */
struct compset ivlppdefines = {"-D", "", 0};

/* ivl target setup */ 
/* Compilation target, default vvm */
typedef enum {VVM, XNF, OTHER} targettype;
struct target {
  targettype target;
  struct compset targetinfo;
};
struct target target  = {VVM, {"-t", "vvm", 0}};

/* output file */
struct compset outputfile = {"-o", "", 0};

/* topmodule name */
struct compset topmodule = {"-s", "", 0};

/* verilog files */
char verilogfiles[50] = "";


/* Temp files for storage */
char tmpPPfile[50];
char tmpCCfile[50];

/* Compilation flag info */
struct compileinfo {
  int pform;
  int execute;
  int elabnetlist;
  int debug;
};
struct compileinfo compileinfo = {0, 0, 0, 0};


void sorry(char optelem)
{
  printf("Sorry, switch -%c not implemented yet!\n", optelem);
}


targettype resolvtarget(char *target)
{
  if (strcmp(target, "vvm") == 0)
    return VVM;
  else if (strcmp(target, "xnf") == 0)
    return XNF;
  else 
    return OTHER;
}


void error_exit(void)
{
  fprintf(stderr, "verilog [-Dmacro[=defn]] [-Iincludepath] [-X] \n");
  fprintf(stderr, "[-x] [-o outputfilename] [-s topmodule] sourcefile[s]\n");
  exit(1);
}


void create_outputfilename(char *input, char *output)
{
  int dotpos=0;
  int spacepos=0;
  int i=0;

  for(i=strlen(input); i!=0; i--){
    if ((dotpos == 0) && (input[i] == '.')) dotpos = i;
    if ((spacepos == 0) && (input[i] == ' ')) spacepos = i;
  }
  
  if (dotpos == 0) {
    dotpos = strlen(input);
  }

  output = strncpy(output, &input[spacepos+1], dotpos-spacepos-1);

  return;
}


void preprocess(void)
{
  char *argument;

  argument = (char *)malloc(256);

  sprintf(argument, LIBDIR "ivl/ivlpp %s %s -L -o%s %s",
	  P_IF_SET(ivlppdefines),
	  P_IF_SET(ivlppincdir),
	  tmpPPfile,
	  verilogfiles);
  if (compileinfo.debug) {
    printf("Executing command : \n%s\n", argument);
  } else {
    if (system(argument)) {
      fprintf(stderr, "Preprocessing failed. Terminating compilation\n");
      unlink(tmpPPfile);
      free(argument);
      exit(1);
    }
  }
  
  free(argument);
  return;<commit_msg> Fix forming of ivlpp command line.<commit_after>/*
 * gvlog.c - A driver for verilog compiler ivl
 * Copyright (C) 1999 <NAME> (<EMAIL>)

 *   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.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the Free Software
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>


#ifndef LIBDIR
# define LIBDIR "/usr/local/lib"
#endif
#ifndef INCLUDEDIR
# define INCLUDEDIR "/usr/local/include"
#endif

const char VERSION[] = "$Name:  $ $State: Exp $";


#define P_IF_SET(var) var.set ? var.name : ""

/* Div compiler settings */
struct compset {
  char compsw[5];
  char name[50];
  int set;
};

/* cpp include path */
struct compset cppincdir = {"-I", INCLUDEDIR, 1};

/* cpp library path */
struct compset cpplibdir ={"-L", LIBDIR, 1};

/* VPI module path */
struct compset VPImodpath = {"-f", LIBDIR "/ivl", 1};

/* ivl include path */
struct compset ivlppincdir = {"-I", "", 0};

/* ivl defines */
struct compset ivlppdefines = {"-D", "", 0};

/* ivl target setup */ 
/* Compilation target, default vvm */
typedef enum {VVM, XNF, OTHER} targettype;
struct target {
  targettype target;
  struct compset targetinfo;
};
struct target target  = {VVM, {"-t", "vvm", 0}};

/* output file */
struct compset outputfile = {"-o", "", 0};

/* topmodule name */
struct compset topmodule = {"-s", "", 0};

/* verilog files */
char verilogfiles[50] = "";


/* Temp files for storage */
char tmpPPfile[50];
char tmpCCfile[50];

/* Compilation flag info */
struct compileinfo {
  int pform;
  int execute;
  int elabnetlist;
  int debug;
};
struct compileinfo compileinfo = {0, 0, 0, 0};


void sorry(char optelem)
{
  printf("Sorry, switch -%c not implemented yet!\n", optelem);
}


targettype resolvtarget(char *target)
{
  if (strcmp(target, "vvm") == 0)
    return VVM;
  else if (strcmp(target, "xnf") == 0)
    return XNF;
  else 
    return OTHER;
}


void error_exit(void)
{
  fprintf(stderr, "verilog [-Dmacro[=defn]] [-Iincludepath] [-X] \n");
  fprintf(stderr, "[-x] [-o outputfilename] [-s topmodule] sourcefile[s]\n");
  exit(1);
}


void create_outputfilename(char *input, char *output)
{
  int dotpos=0;
  int spacepos=0;
  int i=0;

  for(i=strlen(input); i!=0; i--){
    if ((dotpos == 0) && (input[i] == '.')) dotpos = i;
    if ((spacepos == 0) && (input[i] == ' ')) spacepos = i;
  }
  
  if (dotpos == 0) {
    dotpos = strlen(input);
  }

  output = strncpy(output, &input[spacepos+1], dotpos-spacepos-1);

  return;
}


void preprocess(void)
{
  char *argument;

  argument = (char *)malloc(256);

  sprintf(argument, LIBDIR "/ivl/ivlpp %s %s -L -o%s %s",
	  P_IF_SET(ivlppdefines),
	  P_IF_SET(ivlppincdir),
	  tmpPPfile,
	  verilogfiles);
  if (compileinfo.debug) {
    printf("Executing command : \n%s\n", argument);
  } else {
    if (system(argument)) {
      fprintf(stderr, "Preprocessing failed. Terminating compilation\n");
      unlink(tmpPPfile);
      free(argument);
      exit(1);
    }
  }
  
  free(argument);
  return;
{'fraction_non_alphanumeric': 0.15025690876267186, 'fraction_numerical': 0.013886960144424386, 'mean_word_length': 3.432, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3332210', 'n_tokens_mistral': 2628, 'n_tokens_neox': 2532, 'n_words': 805}