From a45bc0c8cdc2730ec7eeacca8d0fcd25fd5caa9f Mon Sep 17 00:00:00 2001 From: Antonio Parata Date: Wed, 14 Oct 2015 16:32:31 +0200 Subject: [PATCH] Refactored in order to be independent from the OS path separator, also added support for .net constants generation --- bindings/const_generator.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/bindings/const_generator.py b/bindings/const_generator.py index 70814ec9..e10601d2 100644 --- a/bindings/const_generator.py +++ b/bindings/const_generator.py @@ -1,9 +1,9 @@ # Unicorn Engine # By Dang Hoang Vu, 2013 from __future__ import print_function -import sys, re +import sys, re, os -INCL_DIR = '../include/unicorn/' +INCL_DIR = os.path.join('..', 'include', 'unicorn') include = [ 'arm.h', 'arm64.h', 'mips.h', 'x86.h', 'sparc.h', 'm68k.h', 'unicorn.h' ] @@ -56,6 +56,22 @@ template = { 'comment_open': '//', 'comment_close': '', }, + 'dotnet': { + 'header': "// For Unicorn Engine. AUTO-GENERATED FILE, DO NOT EDIT\n\nnamespace UnicornEngine.Const\n\nopen System\n\n[]\nmodule %s =\n", + 'footer': "\n", + 'line_format': ' let UC_%s = %s\n', + 'out_file': os.path.join('dotnet', 'Unicorn', 'Const', '%s.fs'), + # prefixes for constant filenames of all archs - case sensitive + 'arm.h': 'Arm', + 'arm64.h': 'Arm64', + 'mips.h': 'Mips', + 'x86.h': 'X86', + 'sparc.h': 'Sparc', + 'm68k.h': 'M68k', + 'unicorn.h': 'Common', + 'comment_open': '//', + 'comment_close': '', + }, } # markup for comments to be added to autogen files @@ -70,7 +86,7 @@ def gen(lang): outfile.write((templ['header'] % (prefix)).encode("utf-8")) if target == 'unicorn.h': prefix = '' - lines = open(INCL_DIR + target).readlines() + lines = open(os.path.join(INCL_DIR, target)).readlines() previous = {} count = 0