From 0157e235e45eb95ba2cb37577ee206652c3b3323 Mon Sep 17 00:00:00 2001 From: Paul Mathieu Date: Thu, 18 Feb 2021 21:20:35 -0800 Subject: [PATCH] Add support for char litterals and << Also streamline cc.py to do it all: - cpp - cc - as LD is still a separate step --- tools/cc.ebnf | 3 +- tools/cc.py | 109 +++++++++++++++++++++++++++++++++++--------------- 2 files changed, 78 insertions(+), 34 deletions(-) diff --git a/tools/cc.ebnf b/tools/cc.ebnf index a3ba3d6..52f29d9 100644 --- a/tools/cc.ebnf +++ b/tools/cc.ebnf @@ -123,7 +123,7 @@ initializer_list: "{" [init_list_field ("," init_list_field)* ","? ] "}" label: IDENTIFIER -litteral: SIGNED_NUMBER | ESCAPED_STRING | HEX_LITTERAL +litteral: SIGNED_NUMBER | ESCAPED_STRING | HEX_LITTERAL | CHARACTER field: IDENTIFIER identifier: IDENTIFIER ?symbol: IDENTIFIER @@ -145,6 +145,7 @@ struct_field: type IDENTIFIER sized_array* ";" IDENTIFIER: /[_a-zA-Z]\w*/ COMMENT: /\/\/.*/ HEX_LITTERAL: /0x[a-fA-F0-9]+/ +CHARACTER: /'[^']'/ %import common.WS diff --git a/tools/cc.py b/tools/cc.py index b315b1f..dc3b3a1 100644 --- a/tools/cc.py +++ b/tools/cc.py @@ -1,11 +1,18 @@ +import argparse import collections import contextlib +import importlib +import io import re +import subprocess import sys import lark +asmod = importlib.import_module("as") + GRAMMAR_FILE = '/home/paulmathieu/vhdl/bin/cc.ebnf' +CPP = ('cpp', '-P') class Scope: @@ -91,7 +98,7 @@ class RegBank: if not self.available: assert self.vars, "nothing to clean, no more regs :/" # storing one random var - var = self.vars.keys()[0] + var = list(self.vars.keys())[0] self.evict(var) return self.available.pop(0) @@ -267,6 +274,7 @@ class CcTransform(lark.visitors.Transformer): mul = _binary_op(lambda a, b: a*b) shl = _binary_op(lambda a, b: a<