diff --git a/src/Token.cpp b/src/Token.cpp index 586585b..c3a3524 100644 --- a/src/Token.cpp +++ b/src/Token.cpp @@ -330,6 +330,9 @@ bool Token::processOperand( const Operand* operand, bool newSyntax, Token::Argum { if( 1 != countFields( fields ) ) match = false; + + if( hasModifier( WCOMP, modifiers ) && (W != fields) ) + match = false; } else if( hasModifier( DEST, modifiers ) ) { @@ -367,9 +370,12 @@ bool Token::processOperand( const Operand* operand, bool newSyntax, Token::Argum (*i).setFields( fields ); - // if flag hasn't been specified, fail + // if flag hasn't been specified, fail (a W component + // defaults to W instead) - if( hasModifier( FLAG, modifiers ) ) + if( hasModifier( WCOMP, modifiers ) ) + (*i).setFields( W ); + else if( hasModifier( FLAG, modifiers ) ) match = false; if( hasModifier( BROADCAST, modifiers ) && !activeBroadcast ) @@ -547,8 +553,9 @@ unsigned int Token::extractModifiers( const std::string& list ) else if( name == "bc" ) modifiers |= (1< +#include + +namespace +{ + std::string program(const std::string& clip) + { + return + "\t.init_vf_all\n" + "\t.init_vi_all\n" + "\t.syntax new\n" + "\t.name vsmClipImplicitW\n" + "\t--enter\n" + "\t--endenter\n" + "\tlq fA, 1(vi00)\n" + "\t" + clip + "\n" + "\tfcand vi01, 0x3f\n" + "\tisw.x vi01, 2(vi00)\n" + "\t--exit\n" + "\t--endexit\n"; + } + + ::test::RunResult compile(const std::string& clip) + { + std::vector args; + args.push_back("-o"); + args.push_back("-"); + return ::test::run_openvcl(args, program(clip)); + } +} + +TEST_CASE("openvcl: clipw without a field reads the W component") +{ + ::test::RunResult bare = compile("clipw.xyz fA, fA"); + ::test::RunResult explicitW = compile("clipw.xyz fA, fA[w]"); + + CHECK(bare.exit_code == 0); + CHECK(explicitW.exit_code == 0); + CHECK(bare.stdout_data.find("clipw.xyz VF01, VF01w") != std::string::npos); + CHECK(bare.stdout_data == explicitW.stdout_data); +} + +TEST_CASE("openvcl: clipw without a dest field or a source field is .xyz and W") +{ + ::test::RunResult bare = compile("clipw fA, fA"); + + CHECK(bare.exit_code == 0); + CHECK(bare.stdout_data.find("clipw.xyz VF01, VF01w") != std::string::npos); +} + +TEST_CASE("openvcl: clipw rejects a source field other than W") +{ + ::test::RunResult r = compile("clipw.xyz fA, fA[x]"); + + CHECK(r.exit_code != 0); + CHECK(r.stderr_data.find("Invalid argument") != std::string::npos); +}