bitcc.cxx File Reference

Command line driver for the static, whole-program BitC compiler. More...

#include <stdint.h>
#include <stdlib.h>
#include <dirent.h>
#include <errno.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <fcntl.h>
#include <signal.h>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <getopt.h>
#include <langinfo.h>
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/convenience.hpp>
#include "BoostCompat.hxx"
#include <libsherpa/util.hxx>
#include "Version.hxx"
#include "UocInfo.hxx"
#include "Options.hxx"
#include "AST.hxx"
#include "backend.hxx"
#include "Instantiate.hxx"
#include "TvPrinter.hxx"
#include "MixFix.hxx"

Go to the source code of this file.

Defines

#define BITC_COMPILER_MODE   0x1u
#define BITC_INTERPRETER_MODE   0x2u
#define BITC_CURRENT_MODE   BITC_COMPILER_MODE
#define LOPT_SHOWLEX   257
#define LOPT_SHOWPARSE   258
#define LOPT_DUMPAFTER   259
#define LOPT_SHOWPASSNMS   260
#define LOPT_NOSTDINC   261
#define LOPT_NOSTDLIB   262
#define LOPT_RAW_TVARS   263
#define LOPT_FQ_TYPES   264
#define LOPT_SA_TCC   265
#define LOPT_SHOWPASSES   266
#define LOPT_PPFQNS   267
#define LOPT_DUMPTYPES   268
#define LOPT_STOPAFTER   269
#define LOPT_PPDECORATE   270
#define LOPT_SHOW_TYPES   271
#define LOPT_XML_TYPES   272
#define LOPT_NOGC   273
#define LOPT_NOPRELUDE   274
#define LOPT_HEURISTIC   275
#define LOPT_HELP   276
#define LOPT_EMIT   277
#define LOPT_SYSTEM   278
#define LOPT_NOALLOC   279
#define LOPT_MIXDEBUG   280
#define LOPT_USAGE   281

Functions

void help ()
 Print usage information and exit.
void fatal ()
 Cease processing after fatal error.
void AddLinkArgumentForGCC (const std::string &s)
 Add an argument to be passed to the linker either before or after the generated BitC object file.
void AddCompileArgumentForGCC (const std::string &s)
 Add an argument to be passed to the compiler before or after the generated BitC C file.
BackEndFindBackEnd (const char *nm)
 Find the backend corresponding to the specified target type.
void handle_sigsegv (int param)
 Catch certain memory errors that plagued us for a while in GCPtr.
filesystem::path ResolveLibPath (std::string name)
 Resolve a library name to a path.
int main (int argc, char *argv[])

Variables

option longopts []
static bool SawFirstBitcInput = false
 Record whether we have seen any BitC input file yet.


Detailed Description

Command line driver for the static, whole-program BitC compiler.

There are three input file extensions:

.bitc - bitc interface files .bits - bitc source files .bito - bitc "object" files.

This compiler basically operates in three modes:

  1. source->object mode, in which X.bits is checked and re-emitted as X.bito, which is a legal BitC file. We pretend that such files are object files for command line handling purposes.

    This mode can be identified by the presence of the -c option on the command line. If -c is specified, no output will be emitted.

  2. As a header file synthesizer, in which an interface file is re-emitted as a C header file, allowing portions of the low-level runtime to be implemented in C.

    This usage can be identified by the presence of the -h option on the command line, but has no effect if -c is also specified.

    Note that -h is a convenience shorthand for --lang h.

  3. As a linker, in which some number of .bits and .bito files are combined to form an executable. This is actually the whole-program compiler mode.

    This mode can be identified by the absence of either the -c or the -h options on the command line.

Definition in file bitcc.cxx.


Define Documentation

#define BITC_COMPILER_MODE   0x1u

Definition at line 119 of file bitcc.cxx.

#define BITC_CURRENT_MODE   BITC_COMPILER_MODE

Definition at line 121 of file bitcc.cxx.

#define BITC_INTERPRETER_MODE   0x2u

Definition at line 120 of file bitcc.cxx.

#define LOPT_DUMPAFTER   259

Definition at line 125 of file bitcc.cxx.

Referenced by main().

#define LOPT_DUMPTYPES   268

Definition at line 134 of file bitcc.cxx.

Referenced by main().

#define LOPT_EMIT   277

Definition at line 143 of file bitcc.cxx.

Referenced by main().

#define LOPT_FQ_TYPES   264

Definition at line 130 of file bitcc.cxx.

Referenced by main().

#define LOPT_HELP   276

Definition at line 142 of file bitcc.cxx.

Referenced by main().

#define LOPT_HEURISTIC   275

Definition at line 141 of file bitcc.cxx.

Referenced by main().

#define LOPT_MIXDEBUG   280

Definition at line 148 of file bitcc.cxx.

Referenced by main().

#define LOPT_NOALLOC   279

Definition at line 146 of file bitcc.cxx.

Referenced by main().

#define LOPT_NOGC   273

Definition at line 139 of file bitcc.cxx.

Referenced by main().

#define LOPT_NOPRELUDE   274

Definition at line 140 of file bitcc.cxx.

Referenced by main().

#define LOPT_NOSTDINC   261

Definition at line 127 of file bitcc.cxx.

Referenced by main().

#define LOPT_NOSTDLIB   262

Definition at line 128 of file bitcc.cxx.

Referenced by main().

#define LOPT_PPDECORATE   270

Definition at line 136 of file bitcc.cxx.

Referenced by main().

#define LOPT_PPFQNS   267

Definition at line 133 of file bitcc.cxx.

Referenced by main().

#define LOPT_RAW_TVARS   263

Definition at line 129 of file bitcc.cxx.

Referenced by main().

#define LOPT_SA_TCC   265

Definition at line 131 of file bitcc.cxx.

Referenced by main().

#define LOPT_SHOW_TYPES   271

Definition at line 137 of file bitcc.cxx.

Referenced by main().

#define LOPT_SHOWLEX   257

Definition at line 123 of file bitcc.cxx.

Referenced by main().

#define LOPT_SHOWPARSE   258

Definition at line 124 of file bitcc.cxx.

Referenced by main().

#define LOPT_SHOWPASSES   266

Definition at line 132 of file bitcc.cxx.

Referenced by main().

#define LOPT_SHOWPASSNMS   260

Definition at line 126 of file bitcc.cxx.

Referenced by main().

#define LOPT_STOPAFTER   269

Definition at line 135 of file bitcc.cxx.

Referenced by main().

#define LOPT_SYSTEM   278

Definition at line 144 of file bitcc.cxx.

Referenced by main().

#define LOPT_USAGE   281

Definition at line 149 of file bitcc.cxx.

Referenced by main().

#define LOPT_XML_TYPES   272

Definition at line 138 of file bitcc.cxx.

Referenced by main().


Function Documentation

void AddCompileArgumentForGCC ( const std::string &  s  ) 

Add an argument to be passed to the compiler before or after the generated BitC C file.

Definition at line 287 of file bitcc.cxx.

References Options::CompilePreOptionsGCC, and SawFirstBitcInput.

Referenced by main().

void AddLinkArgumentForGCC ( const std::string &  s  ) 

Add an argument to be passed to the linker either before or after the generated BitC object file.

Definition at line 275 of file bitcc.cxx.

References Options::LinkPostOptionsGCC, Options::LinkPreOptionsGCC, and SawFirstBitcInput.

Referenced by main().

void fatal (  ) 

Cease processing after fatal error.

Definition at line 257 of file bitcc.cxx.

Referenced by acyclic().

BackEnd* FindBackEnd ( const char *  nm  ) 

Find the backend corresponding to the specified target type.

Definition at line 300 of file bitcc.cxx.

References BackEnd::backends, and BackEnd::nBackEnd.

Referenced by main().

void handle_sigsegv ( int  param  ) 

Catch certain memory errors that plagued us for a while in GCPtr.

These were subsequently resolved, but reporting borkage is not a bad thing.

Definition at line 316 of file bitcc.cxx.

Referenced by main().

void help (  ) 

Print usage information and exit.

Definition at line 228 of file bitcc.cxx.

Referenced by main().

int main ( int  argc,
char *  argv[] 
)

Definition at line 365 of file bitcc.cxx.

References UocInfo::addAllCandidateEPs(), AddCompileArgumentForGCC(), AddLinkArgumentForGCC(), AUTOCONF_LIBDIR, Options::backEnd, BackEnd::backends, BITC_VERSION, BK_HDR_MODE, BK_LINKING, BK_UOC_MODE, UocInfo::CompileFromFile(), Options::CompilePreOptionsGCC, UocInfo::CreateUnifiedUoC(), OnePassInfo::descrip, PassInfo::descrip, Options::dumpAfterMidEnd, Options::dumpTypesAfterMidEnd, Options::entryPts, UocInfo::findAllDefForms(), FindBackEnd(), flags, BackEnd::flags, BackEnd::fn, Options::FQtypes, handle_sigsegv(), help(), Options::heuristicInference, if(), UocInfo::ifList, UocInfo::importInterface(), Options::inputs, Options::libDirs, Options::LinkPostOptionsGCC, loc, longopts, LOPT_DUMPAFTER, LOPT_DUMPTYPES, LOPT_EMIT, LOPT_FQ_TYPES, LOPT_HELP, LOPT_HEURISTIC, LOPT_MIXDEBUG, LOPT_NOALLOC, LOPT_NOGC, LOPT_NOPRELUDE, LOPT_NOSTDINC, LOPT_NOSTDLIB, LOPT_PPDECORATE, LOPT_PPFQNS, LOPT_RAW_TVARS, LOPT_SA_TCC, LOPT_SHOW_TYPES, LOPT_SHOWLEX, LOPT_SHOWPARSE, LOPT_SHOWPASSES, LOPT_SHOWPASSNMS, LOPT_STOPAFTER, LOPT_SYSTEM, LOPT_USAGE, LOPT_XML_TYPES, BackEnd::midfn, mixfix_init(), Options::mixfixDebug, OnePassInfo::name, PassInfo::name, BackEnd::needPass, Options::noAlloc, Options::noGC, Options::noPrelude, UocInfo::onePassInfo, Options::outputFileName, UocInfo::passInfo, BackEnd::plfn, Options::ppDecorate, Options::ppFQNS, Options::rawTvars, ResolveLibPath(), SawFirstBitcInput, UocInfo::searchPath, Options::show_usage, Options::showAllTccs, Options::showLex, Options::showParse, Options::showPasses, Options::showTypesUocs, UocInfo::srcList, Options::SystemDirs, Options::useStdInc, Options::useStdLib, Options::verbose, and Options::xmlTypesUocs.

filesystem::path ResolveLibPath ( std::string  name  ) 

Resolve a library name to a path.

This is called when we see -lname or -l name on the command line. The name will be passed as an argument here. What we need to do here is check the currently known library paths for a resolution. If we find a file matching "libname.bita" on the search path, we add it to the list of inputs.

In some cases, -lmumble will indicate simultaneously a need to add an input file named ..../libmumble.bita and also an archive library named .../libmumble.a. This arises in libbitc, for example, where some of the library is implemented in C.

Unfortunately, this means that the absence of .../libmumble.bita does not reliably indicate an error.

Definition at line 341 of file bitcc.cxx.

References boost::filesystem::is_regular_file(), and Options::libDirs.

Referenced by main().


Variable Documentation

struct option longopts[]

Definition at line 151 of file bitcc.cxx.

Referenced by main().

bool SawFirstBitcInput = false [static]

Record whether we have seen any BitC input file yet.

This determines whether a command line link argument should be presented to the linker before or after the object file comprising the BitC portion of the program.

Definition at line 270 of file bitcc.cxx.

Referenced by AddCompileArgumentForGCC(), AddLinkArgumentForGCC(), and main().


Generated on Sat Feb 4 23:59:29 2012 for BitC Compiler by  doxygen 1.4.7