C// transpiler to C

This is a transpiler for my C// programming language, which is an extremely simplified version of C which I used to demonstrate an optimization for pass-by-value semantics. See also the language specification and the paper.

Contents

Dependencies

This is a program that's written in Java, and generates C code. Therefore, to properly use it, you'll need both an implementation of Java and some C compiler. The compiled Java code is included, so if you're not modifying the program, you'll just need a JVM, not the full development kit. The original version of the program was compiled in Java 1.6, and has also been tested (and seems to work) in Java 8; the newer version was compiled by Java 8 targeting 1.6 (but I haven't tested it in 1.6).

This program used jflex to generate the lexer, and CUP to generate the parser. The output of jflex is included, so it's not needed unless you're modifying the lexer. The version of CUP that I originally used has been included as a jar file. (See below for the license.)

I've only tested this program on Mac OS X, but it should at least in theory work on any modern operating system. The makefile and testing scripts assume a Unix-like system (i.e., not Windows, but it's possible WSL and/or Cygwin will work).

The download is available as a gzipped tar file (.tgz), so you'll need a program that can open tar files. (From the command line, tar zxf cdivdiv.tgz; on Mac, you can just double-click it and it'll extract the files.)

Compiling and testing the transpiler

The compiled .class files are already included, so you shouldn't need to compile anything. However, if you do want to recompile it, just type make at the command line.

You can run the tests by typing ./do-test (when in the cdivdiv directory), or run a specific test by typing ./do-test name-of-file (without the .cdd extension). This will put the generated C code and the output in test-output (for the version with the optimizations) and test-output-unopt (for the version without the optimization). It will also automatically diff the two files, and also diff them with test-output-expected/*.txt if the file exists.

do-test assumes that you have a compiler called "gcc". To use a different compiler, set the CC environment variable to your preferred compiler.

Running the transpiler

To run the transpiler, type

java -classpath java-cup-11a.jar:. ParserDriver input-file.cdd output-file-unopt.c output-file.c

This will generate two output files: the first one does not include the optimizations discussed in my paper, and the second one does. Only one of these output files should be passed to the C compiler.

When compiling the C code, the file cdd_runtime.h should be available in the same directory or in a path provided to -I, and cdd_runtime.c should be included in the final executable. For example, the following command is used by do-test to compile the tests:

gcc -I. -o test-output/test test-output/test.c cdd_runtime.c

Known issues

CUP license

This program includes CUP, which is available from http://www2.cs.tum.edu/projects/cup/index.php, and has the following license:

Copyright 1996-2015 by Scott Hudson, Frank Flannery, C. Scott Ananian, Michael Petter

Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both the copyright notice and this permission notice and warranty disclaimer appear in supporting documentation, and that the names of the authors or their employers not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission.

The authors and their employers disclaim all warranties with regard to this software, including all implied warranties of merchantability and fitness. In no event shall the authors or their employers be liable for any special, 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.

Download

Download cdivdiv.tgz (updated version) (175K): has a few bugfixes and more tests (more info)

Download cdivdiv-2022-06-30.tgz (169K): original code, but the directory structure, makefile, and testing scripts have been updated