Ceed Ceed A Tiny Compiler with ELF & PE Target

Introduction


I have always been interested in compilers but never got a chance to build one. I recently got some time and decided to learn compiler development. I started to look for an example compiler that meets following criteria:

  • Minimalistic – Quick walk-through and reading
  • Documented – Easier to understand
  • Complete – Produces executables without external tools
  • Uses Lex & Yacc – Many books available on building parsers

I didn’t find a good example that meets these requirements and can used as a starting point to bootstrap knowledge of compiler construction. I decided to develop a compiler, primarily for learning and later on, to create an example, that serves as a resource for others who are interested in learning compiler development.

Ceed (pronounced as seed) is an open source (BSD style license) compiler that compiles a high level language to x86 machine code and packages it in an executable binary. It supports 32-bit Linux and Windows and can generate output file in either ELF or PE format. Complete code for Ceed is around 1400 lines of Flex/Bison/C code excluding comments.

(more…)

Read More

Building Azure cloud service without Visual Studio

Introduction


I have mostly worked in systems technologies, building things like operating system, hypervisor, networking protocols and other virtualization related technologies. I love building system software due to simplicity of the overall software stack, programming languages (C and assembly) and tools to build this software. During my work on Windows Network Controller, I spent some time building WCF services in C#. I really liked coding in C# as it is a very well designed high level language and makes coding some of things much faster. However, at times I felt lost in the myriad of abstractions, frameworks and tools. Fortunately, for the service I was building, all the framework details were handled by a core framework team, and that allowed me to focus on writing the core business logic for my service without getting bogged down in all the other details. Even though I was able to build my service faster; I continued to feel lost at the magic, framework components performed; to do things like cross machine API invocation, associated security handling etc. (more…)

Read More

Syntactical twists of C (*p != *p)

[Moved an old post from 2006 to my new blog]

Few days back one of my colleague asked me to debug a problem. She wrote a program and it was crashing in strcpy. I looked at the the code and it looked just fine to me. I thought lets debug it to see whats going on. I started the debug session, variables were pointing to the right data, the stack was fine and she was copying a fixed string to a big enough buffer. I stepped over strcpy and bammm…access violation. Weird huh…For a second i thought how can a simple code like this crash. It was time to dig into the disassembly to see what exactly is going on. But before we do that, lets take a look at two C functions below: (more…)

Read More

Calling conventions in Windows on x86

[Moved an old post from 2006 to my new blog]

It is 2 AM in the night and i don’t feel like sleeping so i thought why not i start my blog and here i am with my first blog entry ever.

People who do programming on Windows in C/C++, might wonder sometime, what is the __cdecl or __stdcall in front of a function declaration? These compiler specific prefixes are basically a way to tell the compiler, how to push the function arguments on the stack and how to pop them off the stack. These prefix defines the contract between Caller (the one who calls a function) and Callee (the called function) for argument passing. This contact is known as Calling convention. Usually we should need only one calling convention for argument passing but Windows compilers provide more than one convention because of historical and performance reasons. The three calling conventions available on windows are:

  1. __cdecl (more…)

Read More