From 5388f68437e0bb9f41cb62347a71de25b6b34f4d Mon Sep 17 00:00:00 2001 From: Jakob Stoklund Olesen Date: Tue, 5 Apr 2016 15:28:08 -0700 Subject: [PATCH] Give instructions a CamelCase name. This will be used as the instruction name in Rust code. By making this a property of the instruction, it can be changed by the user if desired. --- meta/cretonne/__init__.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/meta/cretonne/__init__.py b/meta/cretonne/__init__.py index a5ebb50f04..ff03ed198c 100644 --- a/meta/cretonne/__init__.py +++ b/meta/cretonne/__init__.py @@ -5,6 +5,13 @@ This module provides classes and functions used to describe Cretonne instructions. """ +import re + +camel_re = re.compile('(^|_)([a-z])') +def camel_case(s): + """Convert the string s to CamelCase""" + return camel_re.sub(lambda m: m.group(2).upper(), s) + # Concrete types. # # Instances (i8, i32, ...) are provided in the cretonne.types module. @@ -243,6 +250,7 @@ class Instruction(object): def __init__(self, name, doc, ins=(), outs=(), **kwargs): self.name = name + self.camel_name = camel_case(name) self.__doc__ = doc self.ins = self._to_operand_tuple(ins) self.outs = self._to_operand_tuple(outs)