Convert Figma logo to code with AI

drh logolcc

The lcc retargetable ANSI C compiler

2,000
436
2,000
39

Top Related Projects

6,127

A Small C Compiler

1,947

Unofficial mirror of mob development branch

10,422

A Compiler Writing Journey

Quick Overview

LCC is a retargetable compiler for ANSI C. It generates code for ALPHA, SPARC, MIPS R3000, and x86 architectures. LCC is designed to be small, fast, and easy to port to new architectures, making it suitable for teaching and research purposes.

Pros

  • Highly portable and easy to retarget to new architectures
  • Small and fast compiler, suitable for embedded systems and educational purposes
  • Well-documented with a book explaining its design and implementation
  • Open-source and freely available for use and modification

Cons

  • Limited optimization capabilities compared to modern compilers
  • Does not support the latest C language standards (e.g., C11, C17)
  • Not actively maintained, with the last major update in 2015
  • Limited support for advanced features like inline assembly or platform-specific extensions

Code Examples

LCC is a compiler, not a code library, so code examples are not applicable in this context.

Getting Started

To get started with LCC:

  1. Clone the repository:

    git clone https://github.com/drh/lcc.git
    
  2. Navigate to the LCC directory:

    cd lcc
    
  3. Build LCC for your target architecture (e.g., x86):

    make all HOSTFILE=etc/linux.c TARGETOS=linux TARGETARCH=x86
    
  4. Use LCC to compile C programs:

    ./lcc -o output_file input_file.c
    

Note: Detailed instructions for building and using LCC on different platforms can be found in the repository's documentation.

Competitor Comparisons

6,127

A Small C Compiler

Pros of 8cc

  • More active development with recent updates
  • Supports a wider range of C11 features
  • Better documentation and examples for users

Cons of 8cc

  • Larger codebase, potentially more complex to understand
  • Less portable, primarily focused on x86-64 architecture
  • May be overkill for simple compiler learning projects

Code Comparison

8cc (main.c):

static void parse_args(int argc, char **argv) {
  for (int i = 1; i < argc; i++) {
    if (!strcmp(argv[i], "-o"))
      outfile = argv[++i];
    else if (!strcmp(argv[i], "-S"))
      dumpasm = true;
    else if (!strcmp(argv[i], "-c"))
      dumpobj = true;
    else
      infile = argv[i];
  }
}

lcc (main.c):

for (i = 1; i < argc; i++)
    if (strcmp(argv[i], "-v") == 0)
        verbose++;
    else if (strcmp(argv[i], "-d") == 0)
        dflag++;
    else if (strcmp(argv[i], "-Wf") == 0 && i + 1 < argc)
        fprintf(stderr, "%s: ignored -Wf %s\n", progname, argv[++i]);
    else if (*argv[i] != '-' && *argv[i] != '@')
        files++;

Both compilers use similar command-line argument parsing approaches, but 8cc's implementation appears more concise and focused on specific compiler options. LCC's code shows a broader range of flags and includes error handling for unsupported options.

1,947

Unofficial mirror of mob development branch

Pros of TinyCC

  • Smaller footprint and faster compilation times
  • Supports more recent C language features (e.g., C99, some C11)
  • Active development and maintenance

Cons of TinyCC

  • Less mature and potentially less stable than LCC
  • More limited platform support compared to LCC
  • May produce less optimized code in some cases

Code Comparison

TinyCC example:

#include <tcclib.h>

int main()
{
    tcc_printf("Hello, World!\n");
    return 0;
}

LCC example:

#include <stdio.h>

int main()
{
    printf("Hello, World!\n");
    return 0;
}

The main difference in these examples is the use of tcc_printf in TinyCC, which is a built-in function provided by the TinyCC library. LCC uses the standard C library printf function.

TinyCC is designed for quick compilation and small executable size, making it suitable for embedded systems and rapid development. LCC, on the other hand, focuses on portability and generating efficient code for multiple architectures.

Both compilers have their strengths and are valuable tools depending on the specific requirements of a project.

10,422

A Compiler Writing Journey

Pros of acwj

  • More beginner-friendly with step-by-step tutorials
  • Focuses on modern C programming practices
  • Actively maintained with recent updates

Cons of acwj

  • Less comprehensive compiler implementation
  • Limited target architectures (primarily x86-64)
  • Smaller community and less widespread adoption

Code Comparison

acwj (main.c):

#include "defs.h"
#define extern_
#include "data.h"
#undef extern_
#include "decl.h"
#include <errno.h>

// Compiler setup and top-level execution
int main(int argc, char *argv[]) {
  // Initialization code
}

lcc (main.c):

#include "c.h"

static void compile(char *);

int main(int argc, char *argv[]) {
	int i;
	
	init(argc, argv);
	for (i = 1; i < argc; i++)
		if (strcmp(argv[i], "-v") == 0)
			verbose++;
		else if (strcmp(argv[i], "-d") == 0)
			dflag++;
		else if (strncmp(argv[i], "-l", 2) == 0)
			;
		else if (argv[i][0] == '-' && argv[i][1] != 'l')
			opt(argv[i]);
		else
			compile(argv[i]);
	return errcnt > 0;
}

The acwj code focuses on a modular structure with separate header files, while lcc's main function includes more direct command-line argument handling and compilation initiation.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

This hierarchy is the distribution for lcc version 4.2.

lcc version 3.x is described in the book "A Retargetable C Compiler: Design and Implementation" (Addison-Wesley, 1995, ISBN 0-8053-1670-1). There are significant differences between 3.x and 4.x, most notably in the intermediate code. For details, see http://storage.webhop.net/documents/interface4.pdf.

VERSION 4.2 IS INCOMPATIBLE WITH EARLIER VERSIONS OF LCC. DO NOT UNLOAD THIS DISTRIBUTION ON TOP OF A 3.X DISTRIBUTION.

LCC is a C89 ("ANSI C") compiler designed to be highly retargetable.

LOG describes the changes since the last release.

CPYRIGHT describes the conditions under you can use, copy, modify, and distribute lcc or works derived from lcc.

doc/install.html is an HTML file that gives a complete description of the distribution and installation instructions.

Chris Fraser / cwf@aya.yale.edu David Hanson / drh@drhanson.net $Revision$ $Date$