본문 바로가기
컴퓨터/프로그래밍

CLing: C++ 인터프리터

by All That Guy 2016. 5. 23.


CLing: C++ 인터프리터





CERN Root 프로젝트에서 인터프리터처럼 사용할 수 있는 C++ 프로그램을 만들어서 공개하였다. 이름은 Cling. 이름에서 짐작할 수 있듯니, LLVM과 CLang의 라이브러리를 바탕으로 만들었다. 다든 표준 인터프리터에 비해 나은 점은(advantage) 마치 유닉스 쉘(윈도우에서는 파워쉘)처럼 명령어를 직접 입력해서 출력을 바로 볼 수 있고(파이썬 대화형 쉘을 생각하면 유사. 파이썬 대화형 쉘과는 다름), JIT(just-in-time)라는 컴파일러를 사용 하여 컴파일을 한다. Root 프로젝트에서 현대적이고, 고성능 C++ 인터프리터를 구축하는 게 Cling의 주요 목표여서 이를 성취하기 위한 방향으로 제작을 하였다고 한다.


설치


https://root.cern.ch/cling-build-instructions 에서 소스를 받아 설치를 할 수도 있고, https://root.cern.ch/download/cling 에서 사용하는 운영체제에 맞는 바이너리를 받아서 설치를 할 수도 있다.

설치를 한 후

$ ./cling

으로 실행을 하면 다음과 같이 나온다.


이제 CLing을 사용하면 된다.


다음은 CLing에 사용한 LLVM과 CLang에 관한 Root 프로젝트 홈페이지에 나온 설명이다.


The Low Level Virtual Machine (LLVM) is a compiler infrastructure, written in C++, which is designed for compile-time, link-time, run-time, and "idle-time" optimization of programs written in arbitrary programming languages. Originally implemented for C/C++, the language-independent design (and the success) of LLVM has since spawned a wide variety of front ends, including Objective-C, Fortran, Ada, Haskell, Java bytecode, Python, Ruby, ActionScript, GLSL, and others.


Clang is a compiler front end for the C, C++, Objective-C and Objective-C++ programming languages. It uses the Low Level Virtual Machine (LLVM) as its back end, and as such Clang is part of LLVM releases since LLVM 2.6. Its goal is to offer a replacement to the GNU Compiler Collection (GCC). Development is sponsored by Apple. Clang is available under a free software licence.