• Stars
    star
    49
  • Rank 565,532 (Top 12 %)
  • Language
    C++
  • Created about 7 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Parses an Arduino Sketch and converts it into valid C++ source code

Arduino Sketch preprocessor

Build Status

This repository contains the source code of the Arduino Sketch preprocessor. The main purpose of this tool is to parse an Arduino Sketch (usually made with the Arduino IDE) and convert it into a valid C++ source code.

This tool is based on the Clang/LLVM C++11 parser and provides also some useful features used in the Arduino IDE like:

  • Diagnostics output in JSON format
  • Code autocomplete suggestions output in JSON format

About the Arduino Sketch (.ino) preprocessing

The Arduino Sketch is a simplified C++ source code that can be composed by many files with the extension .ino. To convert the Sketch into a valid C++ file, a number of actions are needed:

  • If the Sketch is composed by many .ino files, those files are concatenated together into a single .ino.cpp file
  • An #include <Arduino.h> is added at the beginning of the Sketch if not already present
  • All needed libraries are detected and include paths are discovered
  • All #include directives are replaced with the actual content of the files included (this is made with a run of gcc or another command line compatible compiler with the -E flag)

and finally:

  • The resulting file is preprocessed to automatically add missing function prototypes (forward declarations)

The arduino-preprocessor tool takes care to handle this last step.

Usage

./arduino-preprocessor [-output-only-needed-prototypes]
                       [-output-code-completions=file:line:col]
                       [-output-diagnostics]
                       [-help] [-version]
                       [-debug]
                       <sketch.ino.cpp> --
                       [extra compiler options]

The only mandatory parameter is the name of the file to be processed and the terminating double dash --. Every parameter after the -- is passed as-is to the clang compiler backend.

The tool outputs the processed source code on the standard output.

For example the file t.cpp:

void a() {
  b();
}

void b() {
}

will be processed as:

$ ./arduino-preprocessor t.cpp --
#line 2 "/home/cmaglie/Workspace/arduino-preprocessor/t.cpp"
void a();
#line 6 "/home/cmaglie/Workspace/arduino-preprocessor/t.cpp"
void b();
#line 2 "/home/cmaglie/Workspace/arduino-preprocessor/t.cpp"
void a() {
  b();
}

void b() {
}

Option -output-only-needed-prototypes

Note: this option is very experimental and barely tested, use at your own risk.

By default arduino-preprocessor produces the forward prototypes of all functions, but if the option -output-only-needed-prototypes is used, the output will contains only the needed prototypes. If we look at the previous example the result will be:

$ ./arduino-preprocessor t.cpp -output-only-needed-prototypes --

#line 6 "/home/cmaglie/Workspace/arduino-preprocessor/t.cpp"
void b();
#line 2 "/home/cmaglie/Workspace/arduino-preprocessor/t.cpp"
void a() {
  b();
}

void b() {
}

Option -output-code-completions=file:line:col

Output code completions for the specified file at the specified line in JSON format. file should be specified with full path (as reported in the #line directives of the processed output).

line and col are 1-based indexes (so the first column/line is 1 and not 0)

Example:

$ ./arduino-preprocessor t.cpp -output-code-completions=/home/cmaglie/Workspace/arduino-preprocessor/t.cpp:3:1 --
[...big json output follows...]

The processed source will not be part of the output when this option is enabled.

Option -output-diagnostics

Output diagnostics (errors and warnings) in JSON format. The processed source will not be part of the output if this option is enabled.

Option -debug

This option enable debugging output during the processing of the Sketch and a lot of debugging messages are printed. This option should be used when a problem is found to understand what's happening and to produce a better bug-report when filing an issue.

Option -version

Prints the version of the tool

Option -help

Prints a short help

Credits

This tool use code from the following projects:

More Repositories

1

Arduino

Arduino IDE 1.x
Java
13,961
star
2

arduino-cli

Arduino command line tool
Go
4,158
star
3

arduino-ide

Arduino IDE 2.x
TypeScript
2,016
star
4

ArduinoCore-avr

The Official Arduino AVR core
C
1,141
star
5

arduino-pro-ide

The Arduino IDE for advanced users and developers. Experimental alpha version.
883
star
6

arduino-builder

A command line tool for compiling Arduino sketches
Go
451
star
7

ArduinoCore-samd

Arduino Core for SAMD21 CPU
C
449
star
8

arduino-create-agent

The Arduino Create Agent
Go
403
star
9

ArduinoCore-arc32

C
322
star
10

ArduinoCore-mbed

C
307
star
11

ArduinoTensorFlowLiteTutorials

Jupyter Notebook
244
star
12

library-registry

Arduino Library Manager list
207
star
13

lab-micropython-editor

Arduino Lab for MicroPython is an Integrated Development Environment (IDE) for MicroPython.
JavaScript
185
star
14

ArduinoCore-API

Hardware independent layer of the Arduino cores defining the official API
C++
173
star
15

reference-en

Editable source for the Arduino Reference
160
star
16

openwrt-yun

A custom version of OpenWrt, targeted to the Arduino Yรบn
C
146
star
17

toolchain-avr

The AVR toolchain used by the Arduino IDE
Shell
136
star
18

setup-protoc

GitHub Action to setup the protoc compiler for protocol buffers
TypeScript
126
star
19

nina-fw

Firmware for u-blox NINA W102 WiFi/BT module
C
122
star
20

docs-content

Arduino documentation (docs.arduino.cc)
Python
113
star
21

arduino-language-server

An Arduino Language Server based on Clangd to Arduino code autocompletion
Go
109
star
22

OpenOCD

Fork of OpenOCD
C
108
star
23

ArduinoCore-megaavr

Arduino Core for the ATMEGA4809 CPU
C++
100
star
24

linino

C
99
star
25

arduino-lint

Tool to check for problems with Arduino projects
Go
96
star
26

wifishield

Arduino Wifi Shield
C
92
star
27

ArduinoCore-nRF528x-mbedos

[Archived] Arduino core supporting mbed-enabled boards
C
86
star
28

setup-task

GitHub Actions action to make Task available for use in your workflow
TypeScript
85
star
29

ArduinoCore-renesas

C
83
star
30

arduino-examples

Arduino IDE bundled examples
Shell
81
star
31

setup-arduino-cli

GitHub Action to setup Arduino CLI
TypeScript
74
star
32

YunBridge

Python
72
star
33

ArduinoCore-sam

HTML
70
star
34

BtSerial

A Bluetooth Serial library for Processing for Android
Java
69
star
35

ArduinoCloudProviderExamples

Examples of how to connect various Arduino boards to cloud providers.
C
69
star
36

tutorials

C++
69
star
37

ArduinoAI

Arduino AI content / demos
JavaScript
66
star
38

openwrt-packages-yun

Makefile
65
star
39

compile-sketches

GitHub Actions action that checks whether Arduino sketches compile and produces a report of data from the compilations
Python
57
star
40

AIoT-Dev-Summit-2019

C++
55
star
41

YunWebUI

Arduino/Genuino Yรบn or Yรบn Shield Web panel
JavaScript
51
star
42

RXTX

Arduino version of RXTX
Shell
49
star
43

Arduino-Science-Journal-Android

Use the sensors in your mobile devices to perform science experiments. Science doesnโ€™t just happen in the classroom or labโ€”tools like Science Journal let you see how the world works with just your phone.
Java
48
star
44

language

This repository serves a central entry point to discussions concerning the Arduino Language.
47
star
45

arduino-fwuploader

A Command Line Tool made to update the firmware and/or add SSL certificates for any Arduino board equipped with WINC or NINA Wi-Fi module.
Go
46
star
46

nicla-sense-me-fw

Arduino Nicla Sense ME resources (libraries, bootloader, host pc utilities)
C
43
star
47

arduino-lint-action

GitHub Actions action to check Arduino projects for problems
TypeScript
42
star
48

summer-of-code

Arduino @ Google Summer of Code
40
star
49

go-apt-client

Go
39
star
50

ArduinoCore-primo

Arduino core for nrf52 cpu
C
38
star
51

arduino-iot-js

Arduino IoT Cloud - Javascript SDK
JavaScript
37
star
52

ArduinoISP

C
36
star
53

arduino-connector

Connector to the Arduino Create Cloud and IoT platform
Go
36
star
54

TFTP-Bootloader

An unfinished TFTP bootloader for Arduino Ethernet
C
35
star
55

avrdude-build-script

avrdude build scripts for Arduino/Genuino
Shell
34
star
56

EduIntro

Arduino library aimed at making super-fast introductory workshops to Arduino. Based on the idea of having components as objects in the code.
C++
34
star
57

actions

Collection of custom Github actions
Python
34
star
58

arduino-create-agent-js-client

JS module providing discovery of the Arduino Create Plugin and communication with it
JavaScript
33
star
59

mcuboot-arduino-stm32h7

C
26
star
60

arduino-usb-scanner

Tool that scans the USB bus autodetecting Arduino boards and their serial port names
25
star
61

arduino-iot-cloud-py

Arduino IoT Cloud Python Client.
Python
24
star
62

dfu-utils-cross

scripts to compile (and cross-compile from a Linux machine) dfu-utils package for Linux (x86_64, x86, arm), OSX and Windows.
C
23
star
63

mkrwan1300-fw

C++
22
star
64

vscode-arduino-tools

Arduino Language Server extension for VS Code
TypeScript
22
star
65

Arduino-Science-Journal-iOS

Use the sensors in your mobile devices to perform science experiments. Science doesnโ€™t just happen in the classroom or labโ€”tools like Science Journal let you see how the world works with just your phone.
Swift
22
star
66

rp2040tools

Go
21
star
67

iot-client-py

Python client for Arduino IoT API
Python
21
star
68

arduino-cli-example

C++
21
star
69

uno-r4-library-compatibility

21
star
70

iot-client-js

Javascript client for Arduino IoT API
JavaScript
21
star
71

Tests

Arduino
20
star
72

HMC5983

Proof of concept of an Arduino library for Honeywell's HMC5983 magnetic sensor.
C++
20
star
73

uno-r4-wifi-usb-bridge

C++
20
star
74

arduino-flash-tools

Arduino Tools for Create
C
20
star
75

iot-client-go

Go client for Arduino IoT API
Go
20
star
76

ArduinoModule-CMSIS-Atmel

Atmel Smart ARM devices CMSIS module for Arduino IDE
C
20
star
77

serial-discovery

An Arduino IDE pluggable-discovery for Serial ports
Go
19
star
78

ethernet-bootloader

TFTP Bootloader for the Arduino Ethernet Board
C
19
star
79

astyle

Scripts and patches used to build astyle, a code formatter used by the Arduino IDE
Shell
18
star
80

mdns-discovery

mdns (bonjour) pluggable discovery
Go
16
star
81

cpp-test-action

A GitHub Actions action for testing C/C++ projects
16
star
82

arduinoOTA

Go
15
star
83

livecast

Code for the examples presented at the Arduino Livecasts
C++
15
star
84

openwrt-yun-1505

Updated build system for OpenWrt - Yun family boards
C
14
star
85

reference-pt

Portuguese version of the Arduino Reference
14
star
86

WiFi101-FirmwareUpdater-Plugin

WiFi101 Firmware Updater Tool for Arduino IDE
Java
13
star
87

lab-micropython-installer

This repository hosts the entire code of the Arduino MicroPython Installer tool
C
13
star
88

report-size-deltas

GitHub Actions action that comments on pull requests with a report of change in memory usage of Arduino sketches
Python
13
star
89

the-things-conference

C
12
star
90

reference-fr

12
star
91

arduino-cloud-cli

Go
12
star
92

season-of-docs

Arduino and Google's Season of Docs 2019
12
star
93

ctags

A mix of ctags and anjuta-tags for the perfect C++ ctags
C
12
star
94

libraries-repository-engine

Arduino Library Manager index manager
Go
11
star
95

lede-yun

C
11
star
96

cloud-examples

Examples for Arduino Cloud
JavaScript
11
star
97

serial-monitor

Arduino pluggable monitor for serial ports
Go
11
star
98

tooling-project-assets

A collection of reusable assets for Arduino tooling projects
Python
11
star
99

reference-es

10
star
100

arduino-iot-google-sheet-script

A script to integration Arduino IoT Cloud with Google Sheet to automatically save historical data about your sensors
JavaScript
10
star