From 0603295822a8d19e5cec0832c583711ee1cc0634 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Sat, 27 Jul 2013 21:35:22 -0500 Subject: [PATCH] Added EmitParamInt to VMFunctionBuilder --- src/zscript/vmbuilder.cpp | 22 ++++++++++++++++++++++ src/zscript/vmbuilder.h | 1 + 2 files changed, 23 insertions(+) diff --git a/src/zscript/vmbuilder.cpp b/src/zscript/vmbuilder.cpp index c87ff636a..4a3462c4f 100644 --- a/src/zscript/vmbuilder.cpp +++ b/src/zscript/vmbuilder.cpp @@ -468,6 +468,28 @@ size_t VMFunctionBuilder::Emit(int opcode, int opabc) return Code.Push(op); } +//========================================================================== +// +// VMFunctionBuilder :: EmitParamInt +// +// Passes a constant integer parameter, using either PARAMI and an immediate +// value or PARAM and a constant register, as appropriate. +// +//========================================================================== + +size_t VMFunctionBuilder::EmitParamInt(int value) +{ + // Immediates for PARAMI must fit in 24 bits. + if (((value << 8) >> 8) == value) + { + return Emit(OP_PARAMI, value); + } + else + { + return Emit(OP_PARAM, 0, REGT_INT | REGT_KONST, GetConstantInt(value)); + } +} + //========================================================================== // // VMFunctionBuilder :: EmitLoadInt diff --git a/src/zscript/vmbuilder.h b/src/zscript/vmbuilder.h index 7587d1b20..c15f65739 100644 --- a/src/zscript/vmbuilder.h +++ b/src/zscript/vmbuilder.h @@ -36,6 +36,7 @@ public: size_t Emit(int opcode, int opa, int opb, int opc); size_t Emit(int opcode, int opa, VM_SHALF opbc); size_t Emit(int opcode, int opabc); + size_t EmitParamInt(int value); size_t EmitLoadInt(int regnum, int value); size_t EmitRetInt(int retnum, bool final, int value);